• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
7  * Copyright (C) 2000 Silicon Graphics, Inc.
8  * Modified for further R[236]000 support by Paul M. Antoine, 1996.
9  * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
10  * Copyright (C) 2000, 07 MIPS Technologies, Inc.
11  * Copyright (C) 2003, 2004  Maciej W. Rozycki
12  */
13 #ifndef _ASM_MIPSREGS_H
14 #define _ASM_MIPSREGS_H
15 
16 #include <linux/linkage.h>
17 #include <asm/hazards.h>
18 #include <asm/war.h>
19 
20 /*
21  * The following macros are especially useful for __asm__
22  * inline assembler.
23  */
24 #ifndef __STR
25 #define __STR(x) #x
26 #endif
27 #ifndef STR
28 #define STR(x) __STR(x)
29 #endif
30 
31 /*
32  *  Configure language
33  */
34 #ifdef __ASSEMBLY__
35 #define _ULCAST_
36 #else
37 #define _ULCAST_ (unsigned long)
38 #endif
39 
40 /*
41  * Coprocessor 0 register names
42  */
43 #define CP0_INDEX $0
44 #define CP0_RANDOM $1
45 #define CP0_ENTRYLO0 $2
46 #define CP0_ENTRYLO1 $3
47 #define CP0_CONF $3
48 #define CP0_CONTEXT $4
49 #define CP0_PAGEMASK $5
50 #define CP0_WIRED $6
51 #define CP0_INFO $7
52 #define CP0_BADVADDR $8
53 #define CP0_COUNT $9
54 #define CP0_ENTRYHI $10
55 #define CP0_COMPARE $11
56 #define CP0_STATUS $12
57 #define CP0_CAUSE $13
58 #define CP0_EPC $14
59 #define CP0_PRID $15
60 #define CP0_CONFIG $16
61 #define CP0_LLADDR $17
62 #define CP0_WATCHLO $18
63 #define CP0_WATCHHI $19
64 #define CP0_XCONTEXT $20
65 #define CP0_FRAMEMASK $21
66 #define CP0_DIAGNOSTIC $22
67 #define CP0_DEBUG $23
68 #define CP0_DEPC $24
69 #define CP0_PERFORMANCE $25
70 #define CP0_ECC $26
71 #define CP0_CACHEERR $27
72 #define CP0_TAGLO $28
73 #define CP0_TAGHI $29
74 #define CP0_ERROREPC $30
75 #define CP0_DESAVE $31
76 
77 /*
78  * R4640/R4650 cp0 register names.  These registers are listed
79  * here only for completeness; without MMU these CPUs are not useable
80  * by Linux.  A future ELKS port might take make Linux run on them
81  * though ...
82  */
83 #define CP0_IBASE $0
84 #define CP0_IBOUND $1
85 #define CP0_DBASE $2
86 #define CP0_DBOUND $3
87 #define CP0_CALG $17
88 #define CP0_IWATCH $18
89 #define CP0_DWATCH $19
90 
91 /*
92  * Coprocessor 0 Set 1 register names
93  */
94 #define CP0_S1_DERRADDR0  $26
95 #define CP0_S1_DERRADDR1  $27
96 #define CP0_S1_INTCONTROL $20
97 
98 /*
99  * Coprocessor 0 Set 2 register names
100  */
101 #define CP0_S2_SRSCTL	  $12	/* MIPSR2 */
102 
103 /*
104  * Coprocessor 0 Set 3 register names
105  */
106 #define CP0_S3_SRSMAP	  $12	/* MIPSR2 */
107 
108 /*
109  *  TX39 Series
110  */
111 #define CP0_TX39_CACHE	$7
112 
113 /*
114  * Coprocessor 1 (FPU) register names
115  */
116 #define CP1_REVISION   $0
117 #define CP1_STATUS     $31
118 
119 /*
120  * FPU Status Register Values
121  */
122 /*
123  * Status Register Values
124  */
125 
126 #define FPU_CSR_FLUSH	0x01000000	/* flush denormalised results to 0 */
127 #define FPU_CSR_COND	0x00800000	/* $fcc0 */
128 #define FPU_CSR_COND0	0x00800000	/* $fcc0 */
129 #define FPU_CSR_COND1	0x02000000	/* $fcc1 */
130 #define FPU_CSR_COND2	0x04000000	/* $fcc2 */
131 #define FPU_CSR_COND3	0x08000000	/* $fcc3 */
132 #define FPU_CSR_COND4	0x10000000	/* $fcc4 */
133 #define FPU_CSR_COND5	0x20000000	/* $fcc5 */
134 #define FPU_CSR_COND6	0x40000000	/* $fcc6 */
135 #define FPU_CSR_COND7	0x80000000	/* $fcc7 */
136 
137 /*
138  * Bits 18 - 20 of the FPU Status Register will be read as 0,
139  * and should be written as zero.
140  */
141 #define FPU_CSR_RSVD	0x001c0000
142 /* ... but FPU2 uses that bits */
143 #define FPU_CSR_NAN2008 0x00040000
144 #define FPU_CSR_ABS2008 0x00080000
145 #define FPU_CSR_MAC2008 0x00100000
146 
147 #define FPU_CSR_DEFAULT 0x00000000
148 
149 /*
150  * X the exception cause indicator
151  * E the exception enable
152  * S the sticky/flag bit
153 */
154 #define FPU_CSR_ALL_X	0x0003f000
155 #define FPU_CSR_UNI_X	0x00020000
156 #define FPU_CSR_INV_X	0x00010000
157 #define FPU_CSR_DIV_X	0x00008000
158 #define FPU_CSR_OVF_X	0x00004000
159 #define FPU_CSR_UDF_X	0x00002000
160 #define FPU_CSR_INE_X	0x00001000
161 
162 #define FPU_CSR_ALL_E	0x00000f80
163 #define FPU_CSR_INV_E	0x00000800
164 #define FPU_CSR_DIV_E	0x00000400
165 #define FPU_CSR_OVF_E	0x00000200
166 #define FPU_CSR_UDF_E	0x00000100
167 #define FPU_CSR_INE_E	0x00000080
168 
169 #define FPU_CSR_ALL_S	0x0000007c
170 #define FPU_CSR_INV_S	0x00000040
171 #define FPU_CSR_DIV_S	0x00000020
172 #define FPU_CSR_OVF_S	0x00000010
173 #define FPU_CSR_UDF_S	0x00000008
174 #define FPU_CSR_INE_S	0x00000004
175 
176 /* Bits 0 and 1 of FPU Status Register specify the rounding mode */
177 #define FPU_CSR_RM	0x00000003
178 #define FPU_CSR_RN	0x0	/* nearest */
179 #define FPU_CSR_RZ	0x1	/* towards zero */
180 #define FPU_CSR_RU	0x2	/* towards +Infinity */
181 #define FPU_CSR_RD	0x3	/* towards -Infinity */
182 
183 
184 /*
185  * Values for PageMask register
186  */
187 #ifdef CONFIG_CPU_VR41XX
188 
189 /* Why doesn't stupidity hurt ... */
190 
191 #define PM_1K		0x00000000
192 #define PM_4K		0x00001800
193 #define PM_16K		0x00007800
194 #define PM_64K		0x0001f800
195 #define PM_256K		0x0007f800
196 
197 #else
198 
199 #define PM_4K		0x00000000
200 #define PM_8K		0x00002000
201 #define PM_16K		0x00006000
202 #define PM_32K		0x0000e000
203 #define PM_64K		0x0001e000
204 #define PM_128K		0x0003e000
205 #define PM_256K		0x0007e000
206 #define PM_512K		0x000fe000
207 #define PM_1M		0x001fe000
208 #define PM_2M		0x003fe000
209 #define PM_4M		0x007fe000
210 #define PM_8M		0x00ffe000
211 #define PM_16M		0x01ffe000
212 #define PM_32M		0x03ffe000
213 #define PM_64M		0x07ffe000
214 #define PM_256M		0x1fffe000
215 #define PM_1G		0x7fffe000
216 
217 #endif
218 
219 /*
220  * Default page size for a given kernel configuration
221  */
222 #ifdef CONFIG_PAGE_SIZE_4KB
223 #define PM_DEFAULT_MASK PM_4K
224 #elif defined(CONFIG_PAGE_SIZE_8KB)
225 #define PM_DEFAULT_MASK PM_8K
226 #elif defined(CONFIG_PAGE_SIZE_16KB)
227 #define PM_DEFAULT_MASK PM_16K
228 #elif defined(CONFIG_PAGE_SIZE_32KB)
229 #define PM_DEFAULT_MASK PM_32K
230 #elif defined(CONFIG_PAGE_SIZE_64KB)
231 #define PM_DEFAULT_MASK PM_64K
232 #else
233 #error Bad page size configuration!
234 #endif
235 
236 /*
237  * Default huge tlb size for a given kernel configuration
238  */
239 #ifdef CONFIG_PAGE_SIZE_4KB
240 #define PM_HUGE_MASK	PM_1M
241 #elif defined(CONFIG_PAGE_SIZE_8KB)
242 #define PM_HUGE_MASK	PM_4M
243 #elif defined(CONFIG_PAGE_SIZE_16KB)
244 #define PM_HUGE_MASK	PM_16M
245 #elif defined(CONFIG_PAGE_SIZE_32KB)
246 #define PM_HUGE_MASK	PM_64M
247 #elif defined(CONFIG_PAGE_SIZE_64KB)
248 #define PM_HUGE_MASK	PM_256M
249 #elif defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
250 #error Bad page size configuration for hugetlbfs!
251 #endif
252 
253 /*
254  * Values used for computation of new tlb entries
255  */
256 #define PL_4K		12
257 #define PL_16K		14
258 #define PL_64K		16
259 #define PL_256K		18
260 #define PL_1M		20
261 #define PL_4M		22
262 #define PL_16M		24
263 #define PL_64M		26
264 #define PL_256M		28
265 
266 /*
267  * PageGrain bits
268  */
269 #define PG_RIE		(_ULCAST_(1) <<	 31)
270 #define PG_XIE		(_ULCAST_(1) <<	 30)
271 #define PG_ELPA		(_ULCAST_(1) <<	 29)
272 #define PG_ESP		(_ULCAST_(1) <<	 28)
273 #define PG_IEC          (_ULCAST_(1) <<  27)
274 #define PG_MCCAUSE      (_ULCAST_(0x1f) << 0)
275 
276 /*
277  * R4x00 interrupt enable / cause bits
278  */
279 #define IE_SW0		(_ULCAST_(1) <<	 8)
280 #define IE_SW1		(_ULCAST_(1) <<	 9)
281 #define IE_IRQ0		(_ULCAST_(1) << 10)
282 #define IE_IRQ1		(_ULCAST_(1) << 11)
283 #define IE_IRQ2		(_ULCAST_(1) << 12)
284 #define IE_IRQ3		(_ULCAST_(1) << 13)
285 #define IE_IRQ4		(_ULCAST_(1) << 14)
286 #define IE_IRQ5		(_ULCAST_(1) << 15)
287 
288 /*
289  * R4x00 interrupt cause bits
290  */
291 #define C_SW0		(_ULCAST_(1) <<	 8)
292 #define C_SW1		(_ULCAST_(1) <<	 9)
293 #define C_IRQ0		(_ULCAST_(1) << 10)
294 #define C_IRQ1		(_ULCAST_(1) << 11)
295 #define C_IRQ2		(_ULCAST_(1) << 12)
296 #define C_IRQ3		(_ULCAST_(1) << 13)
297 #define C_IRQ4		(_ULCAST_(1) << 14)
298 #define C_IRQ5		(_ULCAST_(1) << 15)
299 
300 /*
301  * Bitfields in the R4xx0 cp0 status register
302  */
303 #define ST0_IE			0x00000001
304 #define ST0_EXL			0x00000002
305 #define ST0_ERL			0x00000004
306 #define ST0_KSU			0x00000018
307 #  define KSU_USER		0x00000010
308 #  define KSU_SUPERVISOR	0x00000008
309 #  define KSU_KERNEL		0x00000000
310 #define ST0_UX			0x00000020
311 #define ST0_SX			0x00000040
312 #define ST0_KX			0x00000080
313 #define ST0_DE			0x00010000
314 #define ST0_CE			0x00020000
315 
316 /*
317  * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
318  * cacheops in userspace.  This bit exists only on RM7000 and RM9000
319  * processors.
320  */
321 #define ST0_CO			0x08000000
322 
323 /*
324  * Bitfields in the R[23]000 cp0 status register.
325  */
326 #define ST0_IEC			0x00000001
327 #define ST0_KUC			0x00000002
328 #define ST0_IEP			0x00000004
329 #define ST0_KUP			0x00000008
330 #define ST0_IEO			0x00000010
331 #define ST0_KUO			0x00000020
332 /* bits 6 & 7 are reserved on R[23]000 */
333 #define ST0_ISC			0x00010000
334 #define ST0_SWC			0x00020000
335 #define ST0_CM			0x00080000
336 
337 /*
338  * Bits specific to the R4640/R4650
339  */
340 #define ST0_UM			(_ULCAST_(1) <<	 4)
341 #define ST0_IL			(_ULCAST_(1) << 23)
342 #define ST0_DL			(_ULCAST_(1) << 24)
343 
344 /*
345  * Enable the MIPS MDMX and DSP ASEs
346  */
347 #define ST0_MX			0x01000000
348 
349 /*
350  * Bitfields in the TX39 family CP0 Configuration Register 3
351  */
352 #define TX39_CONF_ICS_SHIFT	19
353 #define TX39_CONF_ICS_MASK	0x00380000
354 #define TX39_CONF_ICS_1KB	0x00000000
355 #define TX39_CONF_ICS_2KB	0x00080000
356 #define TX39_CONF_ICS_4KB	0x00100000
357 #define TX39_CONF_ICS_8KB	0x00180000
358 #define TX39_CONF_ICS_16KB	0x00200000
359 
360 #define TX39_CONF_DCS_SHIFT	16
361 #define TX39_CONF_DCS_MASK	0x00070000
362 #define TX39_CONF_DCS_1KB	0x00000000
363 #define TX39_CONF_DCS_2KB	0x00010000
364 #define TX39_CONF_DCS_4KB	0x00020000
365 #define TX39_CONF_DCS_8KB	0x00030000
366 #define TX39_CONF_DCS_16KB	0x00040000
367 
368 #define TX39_CONF_CWFON		0x00004000
369 #define TX39_CONF_WBON		0x00002000
370 #define TX39_CONF_RF_SHIFT	10
371 #define TX39_CONF_RF_MASK	0x00000c00
372 #define TX39_CONF_DOZE		0x00000200
373 #define TX39_CONF_HALT		0x00000100
374 #define TX39_CONF_LOCK		0x00000080
375 #define TX39_CONF_ICE		0x00000020
376 #define TX39_CONF_DCE		0x00000010
377 #define TX39_CONF_IRSIZE_SHIFT	2
378 #define TX39_CONF_IRSIZE_MASK	0x0000000c
379 #define TX39_CONF_DRSIZE_SHIFT	0
380 #define TX39_CONF_DRSIZE_MASK	0x00000003
381 
382 /*
383  * Status register bits available in all MIPS CPUs.
384  */
385 #define ST0_IM			0x0000ff00
386 #define	 STATUSB_IP0		8
387 #define	 STATUSF_IP0		(_ULCAST_(1) <<	 8)
388 #define	 STATUSB_IP1		9
389 #define	 STATUSF_IP1		(_ULCAST_(1) <<	 9)
390 #define	 STATUSB_IP2		10
391 #define	 STATUSF_IP2		(_ULCAST_(1) << 10)
392 #define	 STATUSB_IP3		11
393 #define	 STATUSF_IP3		(_ULCAST_(1) << 11)
394 #define	 STATUSB_IP4		12
395 #define	 STATUSF_IP4		(_ULCAST_(1) << 12)
396 #define	 STATUSB_IP5		13
397 #define	 STATUSF_IP5		(_ULCAST_(1) << 13)
398 #define	 STATUSB_IP6		14
399 #define	 STATUSF_IP6		(_ULCAST_(1) << 14)
400 #define	 STATUSB_IP7		15
401 #define	 STATUSF_IP7		(_ULCAST_(1) << 15)
402 #define	 STATUSB_IP8		0
403 #define	 STATUSF_IP8		(_ULCAST_(1) <<	 0)
404 #define	 STATUSB_IP9		1
405 #define	 STATUSF_IP9		(_ULCAST_(1) <<	 1)
406 #define	 STATUSB_IP10		2
407 #define	 STATUSF_IP10		(_ULCAST_(1) <<	 2)
408 #define	 STATUSB_IP11		3
409 #define	 STATUSF_IP11		(_ULCAST_(1) <<	 3)
410 #define	 STATUSB_IP12		4
411 #define	 STATUSF_IP12		(_ULCAST_(1) <<	 4)
412 #define	 STATUSB_IP13		5
413 #define	 STATUSF_IP13		(_ULCAST_(1) <<	 5)
414 #define	 STATUSB_IP14		6
415 #define	 STATUSF_IP14		(_ULCAST_(1) <<	 6)
416 #define	 STATUSB_IP15		7
417 #define	 STATUSF_IP15		(_ULCAST_(1) <<	 7)
418 #define ST0_CH			0x00040000
419 #define ST0_NMI			0x00080000
420 #define ST0_SR			0x00100000
421 #define ST0_TS			0x00200000
422 #define ST0_BEV			0x00400000
423 #define ST0_RE			0x02000000
424 #define ST0_FR			0x04000000
425 #define _ST0_FR                 (26)
426 #define ST0_CU			0xf0000000
427 #define ST0_CU0			0x10000000
428 #define ST0_CU1			0x20000000
429 #define ST0_CU2			0x40000000
430 #define ST0_CU3			0x80000000
431 #define ST0_XX			0x80000000	/* MIPS IV naming */
432 
433 /*
434  * Bitfields and bit numbers in the coprocessor 0 IntCtl register. (MIPSR2)
435  *
436  * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
437  */
438 #define INTCTLB_IPPCI		26
439 #define INTCTLF_IPPCI		(_ULCAST_(7) << INTCTLB_IPPCI)
440 #define INTCTLB_IPTI		29
441 #define INTCTLF_IPTI		(_ULCAST_(7) << INTCTLB_IPTI)
442 
443 /*
444  * Bitfields and bit numbers in the coprocessor 0 cause register.
445  *
446  * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
447  */
448 #define	 CAUSEB_EXCCODE		2
449 #define	 CAUSEF_EXCCODE		(_ULCAST_(31)  <<  2)
450 #define	 CAUSEB_IP		8
451 #define	 CAUSEF_IP		(_ULCAST_(255) <<  8)
452 #define	 CAUSEB_IP0		8
453 #define	 CAUSEF_IP0		(_ULCAST_(1)   <<  8)
454 #define	 CAUSEB_IP1		9
455 #define	 CAUSEF_IP1		(_ULCAST_(1)   <<  9)
456 #define	 CAUSEB_IP2		10
457 #define	 CAUSEF_IP2		(_ULCAST_(1)   << 10)
458 #define	 CAUSEB_IP3		11
459 #define	 CAUSEF_IP3		(_ULCAST_(1)   << 11)
460 #define	 CAUSEB_IP4		12
461 #define	 CAUSEF_IP4		(_ULCAST_(1)   << 12)
462 #define	 CAUSEB_IP5		13
463 #define	 CAUSEF_IP5		(_ULCAST_(1)   << 13)
464 #define	 CAUSEB_IP6		14
465 #define	 CAUSEF_IP6		(_ULCAST_(1)   << 14)
466 #define	 CAUSEB_IP7		15
467 #define	 CAUSEF_IP7		(_ULCAST_(1)   << 15)
468 #define	 CAUSEB_IV		23
469 #define	 CAUSEF_IV		(_ULCAST_(1)   << 23)
470 #define	 CAUSEB_PCI		26
471 #define	 CAUSEF_PCI		(_ULCAST_(1)   << 26)
472 #define	 CAUSEB_CE		28
473 #define	 CAUSEF_CE		(_ULCAST_(3)   << 28)
474 #define	 CAUSEB_TI		30
475 #define	 CAUSEF_TI		(_ULCAST_(1)   << 30)
476 #define	 CAUSEB_BD		31
477 #define	 CAUSEF_BD		(_ULCAST_(1)   << 31)
478 
479 /*
480  * Bits in the coprocessor 0 config register.
481  */
482 /* Generic bits.  */
483 #define CONF_CM_CACHABLE_NO_WA		0
484 #define CONF_CM_CACHABLE_WA		1
485 #define CONF_CM_UNCACHED		2
486 #define CONF_CM_CACHABLE_NONCOHERENT	3
487 #define CONF_CM_CACHABLE_CE		4
488 #define CONF_CM_CACHABLE_COW		5
489 #define CONF_CM_CACHABLE_CUW		6
490 #define CONF_CM_CACHABLE_ACCELERATED	7
491 #define CONF_CM_CMASK			7
492 #define CONF_BE			(_ULCAST_(1) << 15)
493 
494 /* Bits common to various processors.  */
495 #define CONF_CU			(_ULCAST_(1) <<	 3)
496 #define CONF_DB			(_ULCAST_(1) <<	 4)
497 #define CONF_IB			(_ULCAST_(1) <<	 5)
498 #define CONF_DC			(_ULCAST_(7) <<	 6)
499 #define CONF_IC			(_ULCAST_(7) <<	 9)
500 #define CONF_EB			(_ULCAST_(1) << 13)
501 #define CONF_EM			(_ULCAST_(1) << 14)
502 #define CONF_SM			(_ULCAST_(1) << 16)
503 #define CONF_SC			(_ULCAST_(1) << 17)
504 #define CONF_EW			(_ULCAST_(3) << 18)
505 #define CONF_EP			(_ULCAST_(15)<< 24)
506 #define CONF_EC			(_ULCAST_(7) << 28)
507 #define CONF_CM			(_ULCAST_(1) << 31)
508 
509 /* Bits specific to the R4xx0.	*/
510 #define R4K_CONF_SW		(_ULCAST_(1) << 20)
511 #define R4K_CONF_SS		(_ULCAST_(1) << 21)
512 #define R4K_CONF_SB		(_ULCAST_(3) << 22)
513 
514 /* Bits specific to the R5000.	*/
515 #define R5K_CONF_SE		(_ULCAST_(1) << 12)
516 #define R5K_CONF_SS		(_ULCAST_(3) << 20)
517 
518 /* Bits specific to the RM7000.	 */
519 #define RM7K_CONF_SE		(_ULCAST_(1) <<	 3)
520 #define RM7K_CONF_TE		(_ULCAST_(1) << 12)
521 #define RM7K_CONF_CLK		(_ULCAST_(1) << 16)
522 #define RM7K_CONF_TC		(_ULCAST_(1) << 17)
523 #define RM7K_CONF_SI		(_ULCAST_(3) << 20)
524 #define RM7K_CONF_SC		(_ULCAST_(1) << 31)
525 
526 /* Bits specific to the R10000.	 */
527 #define R10K_CONF_DN		(_ULCAST_(3) <<	 3)
528 #define R10K_CONF_CT		(_ULCAST_(1) <<	 5)
529 #define R10K_CONF_PE		(_ULCAST_(1) <<	 6)
530 #define R10K_CONF_PM		(_ULCAST_(3) <<	 7)
531 #define R10K_CONF_EC		(_ULCAST_(15)<<	 9)
532 #define R10K_CONF_SB		(_ULCAST_(1) << 13)
533 #define R10K_CONF_SK		(_ULCAST_(1) << 14)
534 #define R10K_CONF_SS		(_ULCAST_(7) << 16)
535 #define R10K_CONF_SC		(_ULCAST_(7) << 19)
536 #define R10K_CONF_DC		(_ULCAST_(7) << 26)
537 #define R10K_CONF_IC		(_ULCAST_(7) << 29)
538 
539 /* Bits specific to the VR41xx.	 */
540 #define VR41_CONF_CS		(_ULCAST_(1) << 12)
541 #define VR41_CONF_P4K		(_ULCAST_(1) << 13)
542 #define VR41_CONF_BP		(_ULCAST_(1) << 16)
543 #define VR41_CONF_M16		(_ULCAST_(1) << 20)
544 #define VR41_CONF_AD		(_ULCAST_(1) << 23)
545 
546 /* Bits specific to the R30xx.	*/
547 #define R30XX_CONF_FDM		(_ULCAST_(1) << 19)
548 #define R30XX_CONF_REV		(_ULCAST_(1) << 22)
549 #define R30XX_CONF_AC		(_ULCAST_(1) << 23)
550 #define R30XX_CONF_RF		(_ULCAST_(1) << 24)
551 #define R30XX_CONF_HALT		(_ULCAST_(1) << 25)
552 #define R30XX_CONF_FPINT	(_ULCAST_(7) << 26)
553 #define R30XX_CONF_DBR		(_ULCAST_(1) << 29)
554 #define R30XX_CONF_SB		(_ULCAST_(1) << 30)
555 #define R30XX_CONF_LOCK		(_ULCAST_(1) << 31)
556 
557 /* Bits specific to the TX49.  */
558 #define TX49_CONF_DC		(_ULCAST_(1) << 16)
559 #define TX49_CONF_IC		(_ULCAST_(1) << 17)  /* conflict with CONF_SC */
560 #define TX49_CONF_HALT		(_ULCAST_(1) << 18)
561 #define TX49_CONF_CWFON		(_ULCAST_(1) << 27)
562 
563 /* Bits specific to the MIPS32/64 PRA.	*/
564 #define MIPS_CONF_MT		(_ULCAST_(7) <<	 7)
565 #define MIPS_CONF_AR		(_ULCAST_(7) << 10)
566 #define MIPS_CONF_AT		(_ULCAST_(3) << 13)
567 #define MIPS_CONF_M		(_ULCAST_(1) << 31)
568 
569 /*
570  * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
571  */
572 #define MIPS_CONF1_FP		(_ULCAST_(1) <<	 0)
573 #define MIPS_CONF1_EP		(_ULCAST_(1) <<	 1)
574 #define MIPS_CONF1_CA		(_ULCAST_(1) <<	 2)
575 #define MIPS_CONF1_WR		(_ULCAST_(1) <<	 3)
576 #define MIPS_CONF1_PC		(_ULCAST_(1) <<	 4)
577 #define MIPS_CONF1_MD		(_ULCAST_(1) <<	 5)
578 #define MIPS_CONF1_C2		(_ULCAST_(1) <<	 6)
579 #define MIPS_CONF1_DA		(_ULCAST_(7) <<	 7)
580 #define MIPS_CONF1_DL		(_ULCAST_(7) << 10)
581 #define MIPS_CONF1_DS		(_ULCAST_(7) << 13)
582 #define MIPS_CONF1_IA		(_ULCAST_(7) << 16)
583 #define MIPS_CONF1_IL		(_ULCAST_(7) << 19)
584 #define MIPS_CONF1_IS		(_ULCAST_(7) << 22)
585 #define MIPS_CONF1_TLBS_SHIFT   (25)
586 #define MIPS_CONF1_TLBS_SIZE    (6)
587 #define MIPS_CONF1_TLBS         (_ULCAST_(63)<< MIPS_CONF1_TLBS_SHIFT)
588 
589 #define MIPS_CONF2_SA		(_ULCAST_(15)<<	 0)
590 #define MIPS_CONF2_SL		(_ULCAST_(15)<<	 4)
591 #define MIPS_CONF2_SS		(_ULCAST_(15)<<	 8)
592 #define MIPS_CONF2_SU		(_ULCAST_(15)<< 12)
593 #define MIPS_CONF2_TA		(_ULCAST_(15)<< 16)
594 #define MIPS_CONF2_TL		(_ULCAST_(15)<< 20)
595 #define MIPS_CONF2_TS		(_ULCAST_(15)<< 24)
596 #define MIPS_CONF2_TU		(_ULCAST_(7) << 28)
597 
598 #define MIPS_CONF3_TL		(_ULCAST_(1) <<	 0)
599 #define MIPS_CONF3_SM		(_ULCAST_(1) <<	 1)
600 #define MIPS_CONF3_MT		(_ULCAST_(1) <<	 2)
601 #define MIPS_CONF3_CDMM		(_ULCAST_(1) <<	 3)
602 #define MIPS_CONF3_SP		(_ULCAST_(1) <<	 4)
603 #define MIPS_CONF3_VINT		(_ULCAST_(1) <<	 5)
604 #define MIPS_CONF3_VEIC		(_ULCAST_(1) <<	 6)
605 #define MIPS_CONF3_LPA		(_ULCAST_(1) <<	 7)
606 #define MIPS_CONF3_ITL		(_ULCAST_(1) <<	 8)
607 #define MIPS_CONF3_CTXTC	(_ULCAST_(1) <<	 9)
608 #define MIPS_CONF3_DSP		(_ULCAST_(1) << 10)
609 #define MIPS_CONF3_DSP2P	(_ULCAST_(1) << 11)
610 #define MIPS_CONF3_RXI		(_ULCAST_(1) << 12)
611 #define MIPS_CONF3_ULRI		(_ULCAST_(1) << 13)
612 #define MIPS_CONF3_ISA		(_ULCAST_(3) << 14)
613 #define MIPS_CONF3_ISA_OE	(_ULCAST_(1) << 16)
614 #define MIPS_CONF3_MCU		(_ULCAST_(1) << 17)
615 #define MIPS_CONF3_MMAR		(_ULCAST_(7) << 18)
616 #define MIPS_CONF3_IPLW		(_ULCAST_(3) << 21)
617 #define MIPS_CONF3_VZ		(_ULCAST_(1) << 23)
618 #define MIPS_CONF3_PW		(_ULCAST_(1) << 24)
619 #define MIPS_CONF3_SC		(_ULCAST_(1) << 25)
620 #define MIPS_CONF3_BI		(_ULCAST_(1) << 26)
621 #define MIPS_CONF3_BP		(_ULCAST_(1) << 27)
622 #define MIPS_CONF3_MSA		(_ULCAST_(1) << 28)
623 #define MIPS_CONF3_CMGCR	(_ULCAST_(1) << 29)
624 #define MIPS_CONF3_BPG		(_ULCAST_(1) << 30)
625 
626 #define MIPS_CONF4_MMUSIZEEXT_SHIFT	(0)
627 #define MIPS_CONF4_MMUSIZEEXT	(_ULCAST_(255) << 0)
628 #define MIPS_CONF4_FTLBSETS_SHIFT	(0)
629 #define MIPS_CONF4_FTLBSETS	(_ULCAST_(15) << MIPS_CONF4_FTLBSETS_SHIFT)
630 #define MIPS_CONF4_FTLBWAYS_SHIFT	(4)
631 #define MIPS_CONF4_FTLBWAYS	(_ULCAST_(15) << MIPS_CONF4_FTLBWAYS_SHIFT)
632 #define MIPS_CONF4_FTLBPAGESIZE_SHIFT	(8)
633 #define MIPS_CONF4_FTLBPAGESIZE	(_ULCAST_(31) << MIPS_CONF4_FTLBPAGESIZE_SHIFT)
634 #define MIPS_CONF4_MMUEXTDEF	(_ULCAST_(3) << 14)
635 #define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
636 
637 #define MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT	(_ULCAST_(2) << 14)
638 #define MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT	(_ULCAST_(3) << 14)
639 #define MIPS_CONF4_KSCREXIST	(_ULCAST_(255) << 16)
640 #define MIPS_CONF4_VTLBSIZEEXT_SHIFT	(24)
641 #define MIPS_CONF4_VTLBSIZEEXT	(_ULCAST_(15) << MIPS_CONF4_VTLBSIZEEXT_SHIFT)
642 #define MIPS_CONF4_AE		(_ULCAST_(1) << 28)
643 #define MIPS_CONF4_IE           (_ULCAST_(3) << 29)
644 #define MIPS_CONF4_TLBINV       (_ULCAST_(2) << 29)
645 #define MIPS_CONF4_TLBINV_FULL  (_ULCAST_(1) << 29)
646 
647 #define MIPS_CONF5_NF		(_ULCAST_(1) << 0)
648 #define MIPS_CONF5_UFR		(_ULCAST_(1) << 2)
649 #define MIPS_CONF5_MRP          (_ULCAST_(1) << 3)
650 #define MIPS_CONF5_VC           (_ULCAST_(1) << 7)
651 #define MIPS_CONF5_FRE          (_ULCAST_(1) << 8)
652 #define MIPS_CONF5_UFE          (_ULCAST_(1) << 9)
653 #define MIPS_CONF5_L2C          (_ULCAST_(1) << 10)
654 #define MIPS_CONF5_MSAEN	(_ULCAST_(1) << 27)
655 #define MIPS_CONF5_EVA          (_ULCAST_(1) << 28)
656 #define MIPS_CONF5_CV		(_ULCAST_(1) << 29)
657 #define MIPS_CONF5_K		(_ULCAST_(1) << 30)
658 
659 #define MIPS_CONF6_JRCD		(_ULCAST_(1) << 0)
660 #define MIPS_CONF6_JRCP		(_ULCAST_(1) << 1)
661 #define MIPS_CONF6_SYND		(_ULCAST_(1) << 13)
662 #define MIPS_CONF6_SPCD		(_ULCAST_(1) << 14)
663 #define MIPS_CONF6_FTLBEN       (_ULCAST_(1) << 15)
664 
665 #define MIPS_CONF7_WII		(_ULCAST_(1) << 31)
666 #define MIPS_CONF7_AR		(_ULCAST_(1) << 16)
667 #define MIPS_CONF7_IAR		(_ULCAST_(1) << 10)
668 #define MIPS_CONF7_RPS		(_ULCAST_(1) << 2)
669 
670 /*  EntryHI bit definition */
671 #define MIPS_EHINV		(_ULCAST_(1) << 10)
672 
673 /*  HTW PTWCTL base definition - not yet for HUGE pages */
674 #define HTW_PWCTL_BASE          (_ULCAST_(7) << 26) /* XK+XS+XU */
675 
676 /*
677  * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
678  */
679 #define MIPS_FPIR_S		(_ULCAST_(1) << 16)
680 #define MIPS_FPIR_D		(_ULCAST_(1) << 17)
681 #define MIPS_FPIR_PS		(_ULCAST_(1) << 18)
682 #define MIPS_FPIR_3D		(_ULCAST_(1) << 19)
683 #define MIPS_FPIR_W		(_ULCAST_(1) << 20)
684 #define MIPS_FPIR_L		(_ULCAST_(1) << 21)
685 #define MIPS_FPIR_F64		(_ULCAST_(1) << 22)
686 /* additional bits in MIPS32/64 coprocessor 2 (FPU) */
687 #define MIPS_FPIR_HAS2008       (_ULCAST_(1) << 23)
688 #define MIPS_FPIR_FC            (_ULCAST_(1) << 24)
689 #define MIPS_FPIR_FREP          (_ULCAST_(1) << 29)
690 
691 /*
692  * Bits in the MIPS32 Memory Segmentation registers.
693  */
694 #define MIPS_SEGCFG_PA_SHIFT	9
695 #define MIPS_SEGCFG_PA		(_ULCAST_(127) << MIPS_SEGCFG_PA_SHIFT)
696 #define MIPS_SEGCFG_AM_SHIFT	4
697 #define MIPS_SEGCFG_AM		(_ULCAST_(7) << MIPS_SEGCFG_AM_SHIFT)
698 #define MIPS_SEGCFG_EU_SHIFT	3
699 #define MIPS_SEGCFG_EU		(_ULCAST_(1) << MIPS_SEGCFG_EU_SHIFT)
700 #define MIPS_SEGCFG_C_SHIFT	0
701 #define MIPS_SEGCFG_C		(_ULCAST_(7) << MIPS_SEGCFG_C_SHIFT)
702 
703 #define MIPS_SEGCFG_UUSK	_ULCAST_(7)
704 #define MIPS_SEGCFG_USK		_ULCAST_(5)
705 #define MIPS_SEGCFG_MUSUK	_ULCAST_(4)
706 #define MIPS_SEGCFG_MUSK	_ULCAST_(3)
707 #define MIPS_SEGCFG_MSK		_ULCAST_(2)
708 #define MIPS_SEGCFG_MK		_ULCAST_(1)
709 #define MIPS_SEGCFG_UK		_ULCAST_(0)
710 
711 /* ebase register bit definition */
712 #define MIPS_EBASE_WG           (_ULCAST_(1) << 11)
713 
714 /* MAAR bits definitions */
715 #define MIPS_MAAR_V             (_ULCAST_(1))
716 #define MIPS_MAAR_S             (_ULCAST_(1) << 1)
717 #define MIPS_MAAR_HI_V          (_ULCAST_(1) << 31)
718 
719 #define MIPS_MAAR_MAX           64
720 
721 #define MIPS_PWFIELD_BDI_SHIFT  32
722 #define MIPS_PWFIELD_BDI_MASK   0x3f00000000UL
723 #define MIPS_PWFIELD_GDI_SHIFT	24
724 #define MIPS_PWFIELD_GDI_MASK	0x3f000000
725 #define MIPS_PWFIELD_UDI_SHIFT	18
726 #define MIPS_PWFIELD_UDI_MASK	0x00fc0000
727 #define MIPS_PWFIELD_MDI_SHIFT	12
728 #define MIPS_PWFIELD_MDI_MASK	0x0003f000
729 #define MIPS_PWFIELD_PTI_SHIFT	6
730 #define MIPS_PWFIELD_PTI_MASK	0x00000fc0
731 #define MIPS_PWFIELD_PTEI_SHIFT	0
732 #define MIPS_PWFIELD_PTEI_MASK	0x0000003f
733 
734 #define MIPS_PWSIZE_BDW_SHIFT   32
735 #define MIPS_PWSIZE_BDW_MASK    0x3f00000000UL
736 #define MIPS_PWSIZE_PS          0x40000000
737 #define MIPS_PWSIZE_GDW_SHIFT	24
738 #define MIPS_PWSIZE_GDW_MASK	0x3f000000
739 #define MIPS_PWSIZE_UDW_SHIFT	18
740 #define MIPS_PWSIZE_UDW_MASK	0x00fc0000
741 #define MIPS_PWSIZE_MDW_SHIFT	12
742 #define MIPS_PWSIZE_MDW_MASK	0x0003f000
743 #define MIPS_PWSIZE_PTW_SHIFT	6
744 #define MIPS_PWSIZE_PTW_MASK	0x00000fc0
745 #define MIPS_PWSIZE_PTEW_SHIFT	0
746 #define MIPS_PWSIZE_PTEW_MASK	0x0000003f
747 
748 #define MIPS_PWCTL_PWEN_SHIFT	31
749 #define MIPS_PWCTL_PWEN_MASK	0x80000000
750 #define MIPS_PWCTL_DPH_SHIFT	7
751 #define MIPS_PWCTL_DPH_MASK	0x00000080
752 #define MIPS_PWCTL_HUGEPG_SHIFT	6
753 #define MIPS_PWCTL_HUGEPG_MASK	0x00000060
754 #define MIPS_PWCTL_PSN_SHIFT	0
755 #define MIPS_PWCTL_PSN_MASK	0x0000003f
756 
757 #define MIPS_GNR_VPID_SHIFT     (0)
758 #define MIPS_GNR_VPID           (_ULCAST_(7) << MIPS_GNR_VPID_SHIFT)
759 #define MIPS_GNR_CORE_SHIFT     (8)
760 #define MIPS_GNR_CORE           (_ULCAST_(15) << MIPS_GNR_CORE_SHIFT)
761 #define MIPS_GNR_CLUSTER_SHIFT  (16)
762 #define MIPS_GNR_CLUSTER        (_ULCAST_(15) << MIPS_GNR_CLUSTER_SHIFT)
763 
764 #ifndef __ASSEMBLY__
765 
766 /*
767  * Macros for handling the ISA mode bit for microMIPS.
768  */
769 #define get_isa16_mode(x)		((x) & 0x1)
770 #define msk_isa16_mode(x)		((x) & ~0x1)
771 #define set_isa16_mode(x)		do { (x) |= 0x1; } while(0)
772 
773 /*
774  * microMIPS instructions can be 16-bit or 32-bit in length. This
775  * returns a 1 if the instruction is 16-bit and a 0 if 32-bit.
776  */
mm_insn_16bit(u16 insn)777 static inline int mm_insn_16bit(u16 insn)
778 {
779 	u16 opcode = (insn >> 10) & 0x7;
780 
781 	return (opcode >= 1 && opcode <= 3) ? 1 : 0;
782 }
783 
784 /*
785  * Functions to access the R10000 performance counters.	 These are basically
786  * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
787  * performance counter number encoded into bits 1 ... 5 of the instruction.
788  * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
789  * disassembler these will look like an access to sel 0 or 1.
790  */
791 #define read_r10k_perf_cntr(counter)				\
792 ({								\
793 	unsigned int __res;					\
794 	__asm__ __volatile__(					\
795 	"mfpc\t%0, %1"						\
796 	: "=r" (__res)						\
797 	: "i" (counter));					\
798 								\
799 	__res;							\
800 })
801 
802 #define write_r10k_perf_cntr(counter,val)			\
803 do {								\
804 	__asm__ __volatile__(					\
805 	"mtpc\t%0, %1"						\
806 	:							\
807 	: "r" (val), "i" (counter));				\
808 } while (0)
809 
810 #define read_r10k_perf_event(counter)				\
811 ({								\
812 	unsigned int __res;					\
813 	__asm__ __volatile__(					\
814 	"mfps\t%0, %1"						\
815 	: "=r" (__res)						\
816 	: "i" (counter));					\
817 								\
818 	__res;							\
819 })
820 
821 #define write_r10k_perf_cntl(counter,val)			\
822 do {								\
823 	__asm__ __volatile__(					\
824 	"mtps\t%0, %1"						\
825 	:							\
826 	: "r" (val), "i" (counter));				\
827 } while (0)
828 
829 
830 /*
831  * Macros to access the system control coprocessor
832  */
833 
834 #define __read_32bit_c0_register(source, sel)				\
835 ({ int __res;								\
836 	if (sel == 0)							\
837 		__asm__ __volatile__(					\
838 			"mfc0\t%0, " #source "\n\t"			\
839 			: "=r" (__res));				\
840 	else								\
841 		__asm__ __volatile__(					\
842 			".set\tmips32\n\t"				\
843 			"mfc0\t%0, " #source ", " #sel "\n\t"		\
844 			".set\tmips0\n\t"				\
845 			: "=r" (__res));				\
846 	__res;								\
847 })
848 
849 #define __read_64bit_c0_register(source, sel)				\
850 ({ unsigned long long __res;						\
851 	if (sizeof(unsigned long) == 4)					\
852 		__res = __read_64bit_c0_split(source, sel);		\
853 	else if (sel == 0)						\
854 		__asm__ __volatile__(					\
855 			".set\tmips3\n\t"				\
856 			"dmfc0\t%0, " #source "\n\t"			\
857 			".set\tmips0"					\
858 			: "=r" (__res));				\
859 	else								\
860 		__asm__ __volatile__(					\
861 			".set\tmips64\n\t"				\
862 			"dmfc0\t%0, " #source ", " #sel "\n\t"		\
863 			".set\tmips0"					\
864 			: "=r" (__res));				\
865 	__res;								\
866 })
867 
868 #define __write_32bit_c0_register(register, sel, value)			\
869 do {									\
870 	if (sel == 0)							\
871 		__asm__ __volatile__(					\
872 			"mtc0\t%z0, " #register "\n\t"			\
873 			: : "Jr" ((unsigned int)(value)));		\
874 	else								\
875 		__asm__ __volatile__(					\
876 			".set\tmips32\n\t"				\
877 			"mtc0\t%z0, " #register ", " #sel "\n\t"	\
878 			".set\tmips0"					\
879 			: : "Jr" ((unsigned int)(value)));		\
880 } while (0)
881 
882 #define __write_64bit_c0_register(register, sel, value)			\
883 do {									\
884 	if (sizeof(unsigned long) == 4)					\
885 		__write_64bit_c0_split(register, sel, value);		\
886 	else if (sel == 0)						\
887 		__asm__ __volatile__(					\
888 			".set\tmips3\n\t"				\
889 			"dmtc0\t%z0, " #register "\n\t"			\
890 			".set\tmips0"					\
891 			: : "Jr" (value));				\
892 	else								\
893 		__asm__ __volatile__(					\
894 			".set\tmips64\n\t"				\
895 			"dmtc0\t%z0, " #register ", " #sel "\n\t"	\
896 			".set\tmips0"					\
897 			: : "Jr" (value));				\
898 } while (0)
899 
900 #define __read_ulong_c0_register(reg, sel)				\
901 	((sizeof(unsigned long) == 4) ?					\
902 	(unsigned long) __read_32bit_c0_register(reg, sel) :		\
903 	(unsigned long) __read_64bit_c0_register(reg, sel))
904 
905 #define __write_ulong_c0_register(reg, sel, val)			\
906 do {									\
907 	if (sizeof(unsigned long) == 4)					\
908 		__write_32bit_c0_register(reg, sel, val);		\
909 	else								\
910 		__write_64bit_c0_register(reg, sel, val);		\
911 } while (0)
912 
913 /*
914  * On RM7000/RM9000 these are uses to access cop0 set 1 registers
915  */
916 #define __read_32bit_c0_ctrl_register(source)				\
917 ({ int __res;								\
918 	__asm__ __volatile__(						\
919 		"cfc0\t%0, " #source "\n\t"				\
920 		: "=r" (__res));					\
921 	__res;								\
922 })
923 
924 #define __write_32bit_c0_ctrl_register(register, value)			\
925 do {									\
926 	__asm__ __volatile__(						\
927 		"ctc0\t%z0, " #register "\n\t"				\
928 		: : "Jr" ((unsigned int)(value)));			\
929 } while (0)
930 
931 /*
932  * These versions are only needed for systems with more than 38 bits of
933  * physical address space running the 32-bit kernel.  That's none atm :-)
934  */
935 #define __read_64bit_c0_split(source, sel)				\
936 ({									\
937 	unsigned long long __val;					\
938 	unsigned long __flags;						\
939 									\
940 	local_irq_save(__flags);					\
941 	if (sel == 0)							\
942 		__asm__ __volatile__(					\
943 			".set\tmips64\n\t"				\
944 			"dmfc0\t%M0, " #source "\n\t"			\
945 			"dsll\t%L0, %M0, 32\n\t"			\
946 			"dsra\t%M0, %M0, 32\n\t"			\
947 			"dsra\t%L0, %L0, 32\n\t"			\
948 			".set\tmips0"					\
949 			: "=r" (__val));				\
950 	else								\
951 		__asm__ __volatile__(					\
952 			".set\tmips64\n\t"				\
953 			"dmfc0\t%M0, " #source ", " #sel "\n\t"		\
954 			"dsll\t%L0, %M0, 32\n\t"			\
955 			"dsra\t%M0, %M0, 32\n\t"			\
956 			"dsra\t%L0, %L0, 32\n\t"			\
957 			".set\tmips0"					\
958 			: "=r" (__val));				\
959 	local_irq_restore(__flags);					\
960 									\
961 	__val;								\
962 })
963 
964 #define __write_64bit_c0_split(source, sel, val)			\
965 do {									\
966 	unsigned long __flags;						\
967 									\
968 	local_irq_save(__flags);					\
969 	if (sel == 0)							\
970 		__asm__ __volatile__(					\
971 			".set\tmips64\n\t"				\
972 			"dsll\t%L0, %L0, 32\n\t"			\
973 			"dsrl\t%L0, %L0, 32\n\t"			\
974 			"dsll\t%M0, %M0, 32\n\t"			\
975 			"or\t%L0, %L0, %M0\n\t"				\
976 			"dmtc0\t%L0, " #source "\n\t"			\
977 			".set\tmips0"					\
978 			: : "r" (val));					\
979 	else								\
980 		__asm__ __volatile__(					\
981 			".set\tmips64\n\t"				\
982 			"dsll\t%L0, %L0, 32\n\t"			\
983 			"dsrl\t%L0, %L0, 32\n\t"			\
984 			"dsll\t%M0, %M0, 32\n\t"			\
985 			"or\t%L0, %L0, %M0\n\t"				\
986 			"dmtc0\t%L0, " #source ", " #sel "\n\t"		\
987 			".set\tmips0"					\
988 			: : "r" (val));					\
989 	local_irq_restore(__flags);					\
990 } while (0)
991 
992 #define read_c0_index()		__read_32bit_c0_register($0, 0)
993 #define write_c0_index(val)	__write_32bit_c0_register($0, 0, val)
994 
995 #define read_c0_random()	__read_32bit_c0_register($1, 0)
996 #define write_c0_random(val)	__write_32bit_c0_register($1, 0, val)
997 
998 #define read_c0_entrylo0()	__read_ulong_c0_register($2, 0)
999 #define write_c0_entrylo0(val)	__write_ulong_c0_register($2, 0, val)
1000 
1001 #define read_c0_entrylo1()	__read_ulong_c0_register($3, 0)
1002 #define write_c0_entrylo1(val)	__write_ulong_c0_register($3, 0, val)
1003 
1004 #define read_c0_gnr()           __read_32bit_c0_register($3, 1)
1005 
1006 #define read_c0_conf()		__read_32bit_c0_register($3, 0)
1007 #define write_c0_conf(val)	__write_32bit_c0_register($3, 0, val)
1008 
1009 #define read_c0_context()	__read_ulong_c0_register($4, 0)
1010 #define write_c0_context(val)	__write_ulong_c0_register($4, 0, val)
1011 
1012 #define read_c0_userlocal()	__read_ulong_c0_register($4, 2)
1013 #define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
1014 
1015 #define read_c0_pagemask()	__read_32bit_c0_register($5, 0)
1016 #define write_c0_pagemask(val)	__write_32bit_c0_register($5, 0, val)
1017 
1018 #define read_c0_pagegrain()	__read_32bit_c0_register($5, 1)
1019 #define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
1020 
1021 #define read_c0_wired()		__read_32bit_c0_register($6, 0)
1022 #define write_c0_wired(val)	__write_32bit_c0_register($6, 0, val)
1023 
1024 #define read_c0_info()		__read_32bit_c0_register($7, 0)
1025 
1026 #define read_c0_cache()		__read_32bit_c0_register($7, 0) /* TX39xx */
1027 #define write_c0_cache(val)	__write_32bit_c0_register($7, 0, val)
1028 
1029 #define read_c0_badvaddr()	__read_ulong_c0_register($8, 0)
1030 #define write_c0_badvaddr(val)	__write_ulong_c0_register($8, 0, val)
1031 
1032 #define read_c0_count()		__read_32bit_c0_register($9, 0)
1033 #define write_c0_count(val)	__write_32bit_c0_register($9, 0, val)
1034 
1035 #define read_c0_count2()	__read_32bit_c0_register($9, 6) /* pnx8550 */
1036 #define write_c0_count2(val)	__write_32bit_c0_register($9, 6, val)
1037 
1038 #define read_c0_count3()	__read_32bit_c0_register($9, 7) /* pnx8550 */
1039 #define write_c0_count3(val)	__write_32bit_c0_register($9, 7, val)
1040 
1041 #define read_c0_entryhi()	__read_ulong_c0_register($10, 0)
1042 #define write_c0_entryhi(val)	__write_ulong_c0_register($10, 0, val)
1043 
1044 #define read_c0_compare()	__read_32bit_c0_register($11, 0)
1045 #define write_c0_compare(val)	__write_32bit_c0_register($11, 0, val)
1046 
1047 #define read_c0_compare2()	__read_32bit_c0_register($11, 6) /* pnx8550 */
1048 #define write_c0_compare2(val)	__write_32bit_c0_register($11, 6, val)
1049 
1050 #define read_c0_compare3()	__read_32bit_c0_register($11, 7) /* pnx8550 */
1051 #define write_c0_compare3(val)	__write_32bit_c0_register($11, 7, val)
1052 
1053 #define read_c0_status()	__read_32bit_c0_register($12, 0)
1054 #ifdef CONFIG_MIPS_MT_SMTC
1055 #define write_c0_status(val)						\
1056 do {									\
1057 	__write_32bit_c0_register($12, 0, val);				\
1058 	__ehb();							\
1059 } while (0)
1060 #else
1061 /*
1062  * Legacy non-SMTC code, which may be hazardous
1063  * but which might not support EHB
1064  */
1065 #define write_c0_status(val)	__write_32bit_c0_register($12, 0, val)
1066 #endif /* CONFIG_MIPS_MT_SMTC */
1067 
1068 #define read_c0_cause()		__read_32bit_c0_register($13, 0)
1069 #define write_c0_cause(val)	__write_32bit_c0_register($13, 0, val)
1070 
1071 #define read_c0_epc()		__read_ulong_c0_register($14, 0)
1072 #define write_c0_epc(val)	__write_ulong_c0_register($14, 0, val)
1073 
1074 #define read_c0_prid()		__read_32bit_c0_register($15, 0)
1075 #define read_c0_cmgcrbase()     __read_ulong_c0_register($15, 3)
1076 #define read_c0_bevva()         __read_ulong_c0_register($15, 4)
1077 
1078 #define read_c0_config()	__read_32bit_c0_register($16, 0)
1079 #define read_c0_config1()	__read_32bit_c0_register($16, 1)
1080 #define read_c0_config2()	__read_32bit_c0_register($16, 2)
1081 #define read_c0_config3()	__read_32bit_c0_register($16, 3)
1082 #define read_c0_config4()	__read_32bit_c0_register($16, 4)
1083 #define read_c0_config5()	__read_32bit_c0_register($16, 5)
1084 #define read_c0_config6()	__read_32bit_c0_register($16, 6)
1085 #define read_c0_config7()	__read_32bit_c0_register($16, 7)
1086 #define write_c0_config(val)	__write_32bit_c0_register($16, 0, val)
1087 #define write_c0_config1(val)	__write_32bit_c0_register($16, 1, val)
1088 #define write_c0_config2(val)	__write_32bit_c0_register($16, 2, val)
1089 #define write_c0_config3(val)	__write_32bit_c0_register($16, 3, val)
1090 #define write_c0_config4(val)	__write_32bit_c0_register($16, 4, val)
1091 #define write_c0_config5(val)	__write_32bit_c0_register($16, 5, val)
1092 #define write_c0_config6(val)	__write_32bit_c0_register($16, 6, val)
1093 #define write_c0_config7(val)	__write_32bit_c0_register($16, 7, val)
1094 
1095 #define read_c0_lladdr()        __read_ulong_c0_register($17, 0)
1096 #define write_c0_lladdr(val)    __write_ulong_c0_register($17, 0, val)
1097 /*
1098  * MAAR registers
1099  */
1100 #define read_c0_maar()          __read_ulong_c0_register($17, 1)
1101 #define write_c0_maar(val)      __write_ulong_c0_register($17, 1, val)
1102 #define read_c0_maarindex()     __read_32bit_c0_register($17, 2)
1103 #define write_c0_maarindex(val) __write_32bit_c0_register($17, 2, val)
1104 
1105 /*
1106  * The WatchLo register.  There may be up to 8 of them.
1107  */
1108 #define read_c0_watchlo0()	__read_ulong_c0_register($18, 0)
1109 #define read_c0_watchlo1()	__read_ulong_c0_register($18, 1)
1110 #define read_c0_watchlo2()	__read_ulong_c0_register($18, 2)
1111 #define read_c0_watchlo3()	__read_ulong_c0_register($18, 3)
1112 #define read_c0_watchlo4()	__read_ulong_c0_register($18, 4)
1113 #define read_c0_watchlo5()	__read_ulong_c0_register($18, 5)
1114 #define read_c0_watchlo6()	__read_ulong_c0_register($18, 6)
1115 #define read_c0_watchlo7()	__read_ulong_c0_register($18, 7)
1116 #define write_c0_watchlo0(val)	__write_ulong_c0_register($18, 0, val)
1117 #define write_c0_watchlo1(val)	__write_ulong_c0_register($18, 1, val)
1118 #define write_c0_watchlo2(val)	__write_ulong_c0_register($18, 2, val)
1119 #define write_c0_watchlo3(val)	__write_ulong_c0_register($18, 3, val)
1120 #define write_c0_watchlo4(val)	__write_ulong_c0_register($18, 4, val)
1121 #define write_c0_watchlo5(val)	__write_ulong_c0_register($18, 5, val)
1122 #define write_c0_watchlo6(val)	__write_ulong_c0_register($18, 6, val)
1123 #define write_c0_watchlo7(val)	__write_ulong_c0_register($18, 7, val)
1124 
1125 /*
1126  * The WatchHi register.  There may be up to 8 of them.
1127  */
1128 #define read_c0_watchhi0()	__read_32bit_c0_register($19, 0)
1129 #define read_c0_watchhi1()	__read_32bit_c0_register($19, 1)
1130 #define read_c0_watchhi2()	__read_32bit_c0_register($19, 2)
1131 #define read_c0_watchhi3()	__read_32bit_c0_register($19, 3)
1132 #define read_c0_watchhi4()	__read_32bit_c0_register($19, 4)
1133 #define read_c0_watchhi5()	__read_32bit_c0_register($19, 5)
1134 #define read_c0_watchhi6()	__read_32bit_c0_register($19, 6)
1135 #define read_c0_watchhi7()	__read_32bit_c0_register($19, 7)
1136 
1137 #define write_c0_watchhi0(val)	__write_32bit_c0_register($19, 0, val)
1138 #define write_c0_watchhi1(val)	__write_32bit_c0_register($19, 1, val)
1139 #define write_c0_watchhi2(val)	__write_32bit_c0_register($19, 2, val)
1140 #define write_c0_watchhi3(val)	__write_32bit_c0_register($19, 3, val)
1141 #define write_c0_watchhi4(val)	__write_32bit_c0_register($19, 4, val)
1142 #define write_c0_watchhi5(val)	__write_32bit_c0_register($19, 5, val)
1143 #define write_c0_watchhi6(val)	__write_32bit_c0_register($19, 6, val)
1144 #define write_c0_watchhi7(val)	__write_32bit_c0_register($19, 7, val)
1145 
1146 #define read_c0_xcontext()	__read_ulong_c0_register($20, 0)
1147 #define write_c0_xcontext(val)	__write_ulong_c0_register($20, 0, val)
1148 
1149 #define read_c0_intcontrol()	__read_32bit_c0_ctrl_register($20)
1150 #define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
1151 
1152 #define read_c0_framemask()	__read_32bit_c0_register($21, 0)
1153 #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
1154 
1155 #define read_c0_diag()		__read_32bit_c0_register($22, 0)
1156 #define write_c0_diag(val)	__write_32bit_c0_register($22, 0, val)
1157 
1158 #define read_c0_diag1()		__read_32bit_c0_register($22, 1)
1159 #define write_c0_diag1(val)	__write_32bit_c0_register($22, 1, val)
1160 
1161 #define read_c0_diag2()		__read_32bit_c0_register($22, 2)
1162 #define write_c0_diag2(val)	__write_32bit_c0_register($22, 2, val)
1163 
1164 #define read_c0_diag3()		__read_32bit_c0_register($22, 3)
1165 #define write_c0_diag3(val)	__write_32bit_c0_register($22, 3, val)
1166 
1167 #define read_c0_diag4()		__read_32bit_c0_register($22, 4)
1168 #define write_c0_diag4(val)	__write_32bit_c0_register($22, 4, val)
1169 
1170 #define read_c0_diag5()		__read_32bit_c0_register($22, 5)
1171 #define write_c0_diag5(val)	__write_32bit_c0_register($22, 5, val)
1172 
1173 #define read_c0_debug()		__read_32bit_c0_register($23, 0)
1174 #define write_c0_debug(val)	__write_32bit_c0_register($23, 0, val)
1175 
1176 #define read_c0_depc()		__read_ulong_c0_register($24, 0)
1177 #define write_c0_depc(val)	__write_ulong_c0_register($24, 0, val)
1178 
1179 /*
1180  * MIPS32 / MIPS64 performance counters
1181  */
1182 #define read_c0_perfctrl0()	__read_32bit_c0_register($25, 0)
1183 #define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
1184 #define read_c0_perfcntr0()	__read_32bit_c0_register($25, 1)
1185 #define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
1186 #define read_c0_perfcntr0_64()	__read_64bit_c0_register($25, 1)
1187 #define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
1188 #define read_c0_perfctrl1()	__read_32bit_c0_register($25, 2)
1189 #define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
1190 #define read_c0_perfcntr1()	__read_32bit_c0_register($25, 3)
1191 #define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
1192 #define read_c0_perfcntr1_64()	__read_64bit_c0_register($25, 3)
1193 #define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
1194 #define read_c0_perfctrl2()	__read_32bit_c0_register($25, 4)
1195 #define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
1196 #define read_c0_perfcntr2()	__read_32bit_c0_register($25, 5)
1197 #define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
1198 #define read_c0_perfcntr2_64()	__read_64bit_c0_register($25, 5)
1199 #define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
1200 #define read_c0_perfctrl3()	__read_32bit_c0_register($25, 6)
1201 #define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
1202 #define read_c0_perfcntr3()	__read_32bit_c0_register($25, 7)
1203 #define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
1204 #define read_c0_perfcntr3_64()	__read_64bit_c0_register($25, 7)
1205 #define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
1206 
1207 #define read_c0_ecc()		__read_32bit_c0_register($26, 0)
1208 #define write_c0_ecc(val)	__write_32bit_c0_register($26, 0, val)
1209 
1210 #define read_c0_derraddr0()	__read_ulong_c0_register($26, 1)
1211 #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
1212 
1213 #define read_c0_cacheerr()	__read_32bit_c0_register($27, 0)
1214 
1215 #define read_c0_derraddr1()	__read_ulong_c0_register($27, 1)
1216 #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
1217 
1218 #define read_c0_taglo()		__read_32bit_c0_register($28, 0)
1219 #define write_c0_taglo(val)	__write_32bit_c0_register($28, 0, val)
1220 
1221 #define read_c0_dtaglo()	__read_32bit_c0_register($28, 2)
1222 #define write_c0_dtaglo(val)	__write_32bit_c0_register($28, 2, val)
1223 
1224 #define read_c0_ddatalo()	__read_32bit_c0_register($28, 3)
1225 #define write_c0_ddatalo(val)	__write_32bit_c0_register($28, 3, val)
1226 
1227 #define read_c0_staglo()	__read_32bit_c0_register($28, 4)
1228 #define write_c0_staglo(val)	__write_32bit_c0_register($28, 4, val)
1229 
1230 #define read_c0_taghi()		__read_32bit_c0_register($29, 0)
1231 #define write_c0_taghi(val)	__write_32bit_c0_register($29, 0, val)
1232 
1233 #define read_c0_errorepc()	__read_ulong_c0_register($30, 0)
1234 #define write_c0_errorepc(val)	__write_ulong_c0_register($30, 0, val)
1235 
1236 /* MIPSR2 */
1237 #define read_c0_hwrena()	__read_32bit_c0_register($7, 0)
1238 #define write_c0_hwrena(val)	__write_32bit_c0_register($7, 0, val)
1239 
1240 #define read_c0_intctl()	__read_32bit_c0_register($12, 1)
1241 #define write_c0_intctl(val)	__write_32bit_c0_register($12, 1, val)
1242 
1243 #define read_c0_srsctl()	__read_32bit_c0_register($12, 2)
1244 #define write_c0_srsctl(val)	__write_32bit_c0_register($12, 2, val)
1245 
1246 #define read_c0_srsmap()	__read_32bit_c0_register($12, 3)
1247 #define write_c0_srsmap(val)	__write_32bit_c0_register($12, 3, val)
1248 
1249 #ifdef CONFIG_CPU_MIPS64_R6
1250 #define read_c0_ebase()         __read_ulong_c0_register($15, 1)
1251 #define write_c0_ebase(val)     __write_ulong_c0_register($15, 1, val)
1252 #else
1253 #define read_c0_ebase()		__read_32bit_c0_register($15, 1)
1254 #define write_c0_ebase(val)	__write_32bit_c0_register($15, 1, val)
1255 #endif
1256 
1257 /* MIPSR3 */
1258 #define read_c0_segctl0()	__read_32bit_c0_register($5, 2)
1259 #define write_c0_segctl0(val)	__write_32bit_c0_register($5, 2, val)
1260 
1261 #define read_c0_segctl1()	__read_32bit_c0_register($5, 3)
1262 #define write_c0_segctl1(val)	__write_32bit_c0_register($5, 3, val)
1263 
1264 #define read_c0_segctl2()	__read_32bit_c0_register($5, 4)
1265 #define write_c0_segctl2(val)	__write_32bit_c0_register($5, 4, val)
1266 
1267 /* Hardware Page Table Walker */
1268 #define read_c0_pwbase()	__read_ulong_c0_register($5, 5)
1269 #define write_c0_pwbase(val)	__write_ulong_c0_register($5, 5, val)
1270 
1271 #define read_c0_pwfield()	__read_ulong_c0_register($5, 6)
1272 #define write_c0_pwfield(val)	__write_ulong_c0_register($5, 6, val)
1273 
1274 #define read_c0_pwsize()	__read_ulong_c0_register($5, 7)
1275 #define write_c0_pwsize(val)	__write_ulong_c0_register($5, 7, val)
1276 
1277 #define read_c0_pwctl()		__read_32bit_c0_register($6, 6)
1278 #define write_c0_pwctl(val)	__write_32bit_c0_register($6, 6, val)
1279 
1280 /* Cavium OCTEON (cnMIPS) */
1281 #define read_c0_cvmcount()	__read_ulong_c0_register($9, 6)
1282 #define write_c0_cvmcount(val)	__write_ulong_c0_register($9, 6, val)
1283 
1284 #define read_c0_cvmctl()	__read_64bit_c0_register($9, 7)
1285 #define write_c0_cvmctl(val)	__write_64bit_c0_register($9, 7, val)
1286 
1287 #define read_c0_cvmmemctl()	__read_64bit_c0_register($11, 7)
1288 #define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
1289 /*
1290  * The cacheerr registers are not standardized.	 On OCTEON, they are
1291  * 64 bits wide.
1292  */
1293 #define read_octeon_c0_icacheerr()	__read_64bit_c0_register($27, 0)
1294 #define write_octeon_c0_icacheerr(val)	__write_64bit_c0_register($27, 0, val)
1295 
1296 #define read_octeon_c0_dcacheerr()	__read_64bit_c0_register($27, 1)
1297 #define write_octeon_c0_dcacheerr(val)	__write_64bit_c0_register($27, 1, val)
1298 
1299 /* BMIPS3300 */
1300 #define read_c0_brcm_config_0()		__read_32bit_c0_register($22, 0)
1301 #define write_c0_brcm_config_0(val)	__write_32bit_c0_register($22, 0, val)
1302 
1303 #define read_c0_brcm_bus_pll()		__read_32bit_c0_register($22, 4)
1304 #define write_c0_brcm_bus_pll(val)	__write_32bit_c0_register($22, 4, val)
1305 
1306 #define read_c0_brcm_reset()		__read_32bit_c0_register($22, 5)
1307 #define write_c0_brcm_reset(val)	__write_32bit_c0_register($22, 5, val)
1308 
1309 /* BMIPS43xx */
1310 #define read_c0_brcm_cmt_intr()		__read_32bit_c0_register($22, 1)
1311 #define write_c0_brcm_cmt_intr(val)	__write_32bit_c0_register($22, 1, val)
1312 
1313 #define read_c0_brcm_cmt_ctrl()		__read_32bit_c0_register($22, 2)
1314 #define write_c0_brcm_cmt_ctrl(val)	__write_32bit_c0_register($22, 2, val)
1315 
1316 #define read_c0_brcm_cmt_local()	__read_32bit_c0_register($22, 3)
1317 #define write_c0_brcm_cmt_local(val)	__write_32bit_c0_register($22, 3, val)
1318 
1319 #define read_c0_brcm_config_1()		__read_32bit_c0_register($22, 5)
1320 #define write_c0_brcm_config_1(val)	__write_32bit_c0_register($22, 5, val)
1321 
1322 #define read_c0_brcm_cbr()		__read_32bit_c0_register($22, 6)
1323 #define write_c0_brcm_cbr(val)		__write_32bit_c0_register($22, 6, val)
1324 
1325 /* BMIPS5000 */
1326 #define read_c0_brcm_config()		__read_32bit_c0_register($22, 0)
1327 #define write_c0_brcm_config(val)	__write_32bit_c0_register($22, 0, val)
1328 
1329 #define read_c0_brcm_mode()		__read_32bit_c0_register($22, 1)
1330 #define write_c0_brcm_mode(val)		__write_32bit_c0_register($22, 1, val)
1331 
1332 #define read_c0_brcm_action()		__read_32bit_c0_register($22, 2)
1333 #define write_c0_brcm_action(val)	__write_32bit_c0_register($22, 2, val)
1334 
1335 #define read_c0_brcm_edsp()		__read_32bit_c0_register($22, 3)
1336 #define write_c0_brcm_edsp(val)		__write_32bit_c0_register($22, 3, val)
1337 
1338 #define read_c0_brcm_bootvec()		__read_32bit_c0_register($22, 4)
1339 #define write_c0_brcm_bootvec(val)	__write_32bit_c0_register($22, 4, val)
1340 
1341 #define read_c0_brcm_sleepcount()	__read_32bit_c0_register($22, 7)
1342 #define write_c0_brcm_sleepcount(val)	__write_32bit_c0_register($22, 7, val)
1343 
1344 /*
1345  * Macros to access the floating point coprocessor control registers
1346  */
1347 #define _read_32bit_cp1_register(source, gas_hardfloat)			\
1348 ({									\
1349 	int __res;							\
1350 									\
1351 	__asm__ __volatile__(						\
1352 	"	.set	push					\n"	\
1353 	"	.set	reorder					\n"	\
1354 	"	# gas fails to assemble cfc1 for some archs,	\n"	\
1355 	"	# like Octeon.					\n"	\
1356 	"	.set	mips1					\n"	\
1357 	"       "STR(gas_hardfloat)"                            \n"     \
1358 	"	cfc1	%0,"STR(source)"			\n"	\
1359 	"	.set	pop					\n"	\
1360 	: "=r" (__res));						\
1361 	__res;								\
1362 })
1363 
1364 #ifdef GAS_HAS_SET_HARDFLOAT
1365 #define read_32bit_cp1_register(source)                                 \
1366        _read_32bit_cp1_register(source, .set hardfloat)
1367 #else
1368 #define read_32bit_cp1_register(source)                                 \
1369        _read_32bit_cp1_register(source, )
1370 #endif
1371 
1372 #define _write_32bit_cp1_register(dest, value , gas_hardfloat)          \
1373 ({									\
1374 	__asm__ __volatile__(						\
1375 	"	.set	push					\n"	\
1376 	"	.set	reorder					\n"	\
1377 	"	# gas fails to assemble cfc1 for some archs,	\n"	\
1378 	"	# like Octeon.					\n"	\
1379 	"	.set	mips1					\n"	\
1380 	"       "STR(gas_hardfloat)"                            \n"     \
1381 	"       ctc1    %0,"STR(dest)"                          \n"     \
1382 	"	.set	pop					\n"	\
1383 	:: "r" (value));                                                \
1384 })
1385 
1386 #ifdef GAS_HAS_SET_HARDFLOAT
1387 #define write_32bit_cp1_register(dest, value)                           \
1388        _write_32bit_cp1_register(dest, value, .set hardfloat)
1389 #else
1390 #define write_32bit_cp1_register(dest, value)                           \
1391        _write_32bit_cp1_register(dest, value, )
1392 #endif
1393 
1394 #ifndef CONFIG_CPU_MIPSR6
1395 /*
1396  * Macros to access the DSP ASE registers
1397  */
1398 #ifdef HAVE_AS_DSP
1399 #define rddsp(mask)							\
1400 ({									\
1401 	unsigned int __dspctl;						\
1402 									\
1403 	__asm__ __volatile__(						\
1404 	"	.set push					\n"	\
1405 	"	.set dsp					\n"	\
1406 	"	rddsp	%0, %x1					\n"	\
1407 	"	.set pop					\n"	\
1408 	: "=r" (__dspctl)						\
1409 	: "i" (mask));							\
1410 	__dspctl;							\
1411 })
1412 
1413 #define wrdsp(val, mask)						\
1414 do {									\
1415 	__asm__ __volatile__(						\
1416 	"	.set push					\n"	\
1417 	"	.set dsp					\n"	\
1418 	"	wrdsp	%0, %x1					\n"	\
1419 	"	.set pop					\n"	\
1420 	:								\
1421 	: "r" (val), "i" (mask));					\
1422 } while (0)
1423 
1424 #define mflo0()								\
1425 ({									\
1426 	long mflo0;							\
1427 	__asm__(							\
1428 	"	.set push					\n"	\
1429 	"	.set dsp					\n"	\
1430 	"	mflo %0, $ac0					\n"	\
1431 	"	.set pop					\n" 	\
1432 	: "=r" (mflo0)); 						\
1433 	mflo0;								\
1434 })
1435 
1436 #define mflo1()								\
1437 ({									\
1438 	long mflo1;							\
1439 	__asm__(							\
1440 	"	.set push					\n"	\
1441 	"	.set dsp					\n"	\
1442 	"	mflo %0, $ac1					\n"	\
1443 	"	.set pop					\n" 	\
1444 	: "=r" (mflo1)); 						\
1445 	mflo1;								\
1446 })
1447 
1448 #define mflo2()								\
1449 ({									\
1450 	long mflo2;							\
1451 	__asm__(							\
1452 	"	.set push					\n"	\
1453 	"	.set dsp					\n"	\
1454 	"	mflo %0, $ac2					\n"	\
1455 	"	.set pop					\n" 	\
1456 	: "=r" (mflo2)); 						\
1457 	mflo2;								\
1458 })
1459 
1460 #define mflo3()								\
1461 ({									\
1462 	long mflo3;							\
1463 	__asm__(							\
1464 	"	.set push					\n"	\
1465 	"	.set dsp					\n"	\
1466 	"	mflo %0, $ac3					\n"	\
1467 	"	.set pop					\n" 	\
1468 	: "=r" (mflo3)); 						\
1469 	mflo3;								\
1470 })
1471 
1472 #define mfhi0()								\
1473 ({									\
1474 	long mfhi0;							\
1475 	__asm__(							\
1476 	"	.set push					\n"	\
1477 	"	.set dsp					\n"	\
1478 	"	mfhi %0, $ac0					\n"	\
1479 	"	.set pop					\n" 	\
1480 	: "=r" (mfhi0)); 						\
1481 	mfhi0;								\
1482 })
1483 
1484 #define mfhi1()								\
1485 ({									\
1486 	long mfhi1;							\
1487 	__asm__(							\
1488 	"	.set push					\n"	\
1489 	"	.set dsp					\n"	\
1490 	"	mfhi %0, $ac1					\n"	\
1491 	"	.set pop					\n" 	\
1492 	: "=r" (mfhi1)); 						\
1493 	mfhi1;								\
1494 })
1495 
1496 #define mfhi2()								\
1497 ({									\
1498 	long mfhi2;							\
1499 	__asm__(							\
1500 	"	.set push					\n"	\
1501 	"	.set dsp					\n"	\
1502 	"	mfhi %0, $ac2					\n"	\
1503 	"	.set pop					\n" 	\
1504 	: "=r" (mfhi2)); 						\
1505 	mfhi2;								\
1506 })
1507 
1508 #define mfhi3()								\
1509 ({									\
1510 	long mfhi3;							\
1511 	__asm__(							\
1512 	"	.set push					\n"	\
1513 	"	.set dsp					\n"	\
1514 	"	mfhi %0, $ac3					\n"	\
1515 	"	.set pop					\n" 	\
1516 	: "=r" (mfhi3)); 						\
1517 	mfhi3;								\
1518 })
1519 
1520 
1521 #define mtlo0(x)							\
1522 ({									\
1523 	__asm__(							\
1524 	"	.set push					\n"	\
1525 	"	.set dsp					\n"	\
1526 	"	mtlo %0, $ac0					\n"	\
1527 	"	.set pop					\n"	\
1528 	:								\
1529 	: "r" (x));							\
1530 })
1531 
1532 #define mtlo1(x)							\
1533 ({									\
1534 	__asm__(							\
1535 	"	.set push					\n"	\
1536 	"	.set dsp					\n"	\
1537 	"	mtlo %0, $ac1					\n"	\
1538 	"	.set pop					\n"	\
1539 	:								\
1540 	: "r" (x));							\
1541 })
1542 
1543 #define mtlo2(x)							\
1544 ({									\
1545 	__asm__(							\
1546 	"	.set push					\n"	\
1547 	"	.set dsp					\n"	\
1548 	"	mtlo %0, $ac2					\n"	\
1549 	"	.set pop					\n"	\
1550 	:								\
1551 	: "r" (x));							\
1552 })
1553 
1554 #define mtlo3(x)							\
1555 ({									\
1556 	__asm__(							\
1557 	"	.set push					\n"	\
1558 	"	.set dsp					\n"	\
1559 	"	mtlo %0, $ac3					\n"	\
1560 	"	.set pop					\n"	\
1561 	:								\
1562 	: "r" (x));							\
1563 })
1564 
1565 #define mthi0(x)							\
1566 ({									\
1567 	__asm__(							\
1568 	"	.set push					\n"	\
1569 	"	.set dsp					\n"	\
1570 	"	mthi %0, $ac0					\n"	\
1571 	"	.set pop					\n"	\
1572 	:								\
1573 	: "r" (x));							\
1574 })
1575 
1576 #define mthi1(x)							\
1577 ({									\
1578 	__asm__(							\
1579 	"	.set push					\n"	\
1580 	"	.set dsp					\n"	\
1581 	"	mthi %0, $ac1					\n"	\
1582 	"	.set pop					\n"	\
1583 	:								\
1584 	: "r" (x));							\
1585 })
1586 
1587 #define mthi2(x)							\
1588 ({									\
1589 	__asm__(							\
1590 	"	.set push					\n"	\
1591 	"	.set dsp					\n"	\
1592 	"	mthi %0, $ac2					\n"	\
1593 	"	.set pop					\n"	\
1594 	:								\
1595 	: "r" (x));							\
1596 })
1597 
1598 #define mthi3(x)							\
1599 ({									\
1600 	__asm__(							\
1601 	"	.set push					\n"	\
1602 	"	.set dsp					\n"	\
1603 	"	mthi %0, $ac3					\n"	\
1604 	"	.set pop					\n"	\
1605 	:								\
1606 	: "r" (x));							\
1607 })
1608 
1609 #else
1610 
1611 #ifdef CONFIG_CPU_MICROMIPS
1612 #define rddsp(mask)							\
1613 ({									\
1614 	unsigned int __res;						\
1615 									\
1616 	__asm__ __volatile__(						\
1617 	"	.set	push					\n"	\
1618 	"	.set	noat					\n"	\
1619 	"	# rddsp $1, %x1					\n"	\
1620 	"	.hword	((0x0020067c | (%x1 << 14)) >> 16)	\n"	\
1621 	"	.hword	((0x0020067c | (%x1 << 14)) & 0xffff)	\n"	\
1622 	"	move	%0, $1					\n"	\
1623 	"	.set	pop					\n"	\
1624 	: "=r" (__res)							\
1625 	: "i" (mask));							\
1626 	__res;								\
1627 })
1628 
1629 #define wrdsp(val, mask)						\
1630 do {									\
1631 	__asm__ __volatile__(						\
1632 	"	.set	push					\n"	\
1633 	"	.set	noat					\n"	\
1634 	"	move	$1, %0					\n"	\
1635 	"	# wrdsp $1, %x1					\n"	\
1636 	"	.hword	((0x0020167c | (%x1 << 14)) >> 16)	\n"	\
1637 	"	.hword	((0x0020167c | (%x1 << 14)) & 0xffff)	\n"	\
1638 	"	.set	pop					\n"	\
1639 	:								\
1640 	: "r" (val), "i" (mask));					\
1641 } while (0)
1642 
1643 #define _umips_dsp_mfxxx(ins)						\
1644 ({									\
1645 	unsigned long __treg;						\
1646 									\
1647 	__asm__ __volatile__(						\
1648 	"	.set	push					\n"	\
1649 	"	.set	noat					\n"	\
1650 	"	.hword	0x0001					\n"	\
1651 	"	.hword	%x1					\n"	\
1652 	"	move	%0, $1					\n"	\
1653 	"	.set	pop					\n"	\
1654 	: "=r" (__treg)							\
1655 	: "i" (ins));							\
1656 	__treg;								\
1657 })
1658 
1659 #define _umips_dsp_mtxxx(val, ins)					\
1660 do {									\
1661 	__asm__ __volatile__(						\
1662 	"	.set	push					\n"	\
1663 	"	.set	noat					\n"	\
1664 	"	move	$1, %0					\n"	\
1665 	"	.hword	0x0001					\n"	\
1666 	"	.hword	%x1					\n"	\
1667 	"	.set	pop					\n"	\
1668 	:								\
1669 	: "r" (val), "i" (ins));					\
1670 } while (0)
1671 
1672 #define _umips_dsp_mflo(reg) _umips_dsp_mfxxx((reg << 14) | 0x107c)
1673 #define _umips_dsp_mfhi(reg) _umips_dsp_mfxxx((reg << 14) | 0x007c)
1674 
1675 #define _umips_dsp_mtlo(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x307c))
1676 #define _umips_dsp_mthi(val, reg) _umips_dsp_mtxxx(val, ((reg << 14) | 0x207c))
1677 
1678 #define mflo0() _umips_dsp_mflo(0)
1679 #define mflo1() _umips_dsp_mflo(1)
1680 #define mflo2() _umips_dsp_mflo(2)
1681 #define mflo3() _umips_dsp_mflo(3)
1682 
1683 #define mfhi0() _umips_dsp_mfhi(0)
1684 #define mfhi1() _umips_dsp_mfhi(1)
1685 #define mfhi2() _umips_dsp_mfhi(2)
1686 #define mfhi3() _umips_dsp_mfhi(3)
1687 
1688 #define mtlo0(x) _umips_dsp_mtlo(x, 0)
1689 #define mtlo1(x) _umips_dsp_mtlo(x, 1)
1690 #define mtlo2(x) _umips_dsp_mtlo(x, 2)
1691 #define mtlo3(x) _umips_dsp_mtlo(x, 3)
1692 
1693 #define mthi0(x) _umips_dsp_mthi(x, 0)
1694 #define mthi1(x) _umips_dsp_mthi(x, 1)
1695 #define mthi2(x) _umips_dsp_mthi(x, 2)
1696 #define mthi3(x) _umips_dsp_mthi(x, 3)
1697 
1698 #else  /* !CONFIG_CPU_MICROMIPS */
1699 #define rddsp(mask)							\
1700 ({									\
1701 	unsigned int __res;						\
1702 									\
1703 	__asm__ __volatile__(						\
1704 	"	.set	push				\n"		\
1705 	"	.set	noat				\n"		\
1706 	"	# rddsp $1, %x1				\n"		\
1707 	"	.word	0x7c000cb8 | (%x1 << 16)	\n"		\
1708 	"	move	%0, $1				\n"		\
1709 	"	.set	pop				\n"		\
1710 	: "=r" (__res)							\
1711 	: "i" (mask));							\
1712 	__res;								\
1713 })
1714 
1715 #define wrdsp(val, mask)						\
1716 do {									\
1717 	__asm__ __volatile__(						\
1718 	"	.set	push					\n"	\
1719 	"	.set	noat					\n"	\
1720 	"	move	$1, %0					\n"	\
1721 	"	# wrdsp $1, %x1					\n"	\
1722 	"	.word	0x7c2004f8 | (%x1 << 11)		\n"	\
1723 	"	.set	pop					\n"	\
1724         :								\
1725 	: "r" (val), "i" (mask));					\
1726 } while (0)
1727 
1728 #define _dsp_mfxxx(ins)							\
1729 ({									\
1730 	unsigned long __treg;						\
1731 									\
1732 	__asm__ __volatile__(						\
1733 	"	.set	push					\n"	\
1734 	"	.set	noat					\n"	\
1735 	"	.word	(0x00000810 | %1)			\n"	\
1736 	"	move	%0, $1					\n"	\
1737 	"	.set	pop					\n"	\
1738 	: "=r" (__treg)							\
1739 	: "i" (ins));							\
1740 	__treg;								\
1741 })
1742 
1743 #define _dsp_mtxxx(val, ins)						\
1744 do {									\
1745 	__asm__ __volatile__(						\
1746 	"	.set	push					\n"	\
1747 	"	.set	noat					\n"	\
1748 	"	move	$1, %0					\n"	\
1749 	"	.word	(0x00200011 | %1)			\n"	\
1750 	"	.set	pop					\n"	\
1751 	:								\
1752 	: "r" (val), "i" (ins));					\
1753 } while (0)
1754 
1755 #define _dsp_mflo(reg) _dsp_mfxxx((reg << 21) | 0x0002)
1756 #define _dsp_mfhi(reg) _dsp_mfxxx((reg << 21) | 0x0000)
1757 
1758 #define _dsp_mtlo(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0002))
1759 #define _dsp_mthi(val, reg) _dsp_mtxxx(val, ((reg << 11) | 0x0000))
1760 
1761 #define mflo0() _dsp_mflo(0)
1762 #define mflo1() _dsp_mflo(1)
1763 #define mflo2() _dsp_mflo(2)
1764 #define mflo3() _dsp_mflo(3)
1765 
1766 #define mfhi0() _dsp_mfhi(0)
1767 #define mfhi1() _dsp_mfhi(1)
1768 #define mfhi2() _dsp_mfhi(2)
1769 #define mfhi3() _dsp_mfhi(3)
1770 
1771 #define mtlo0(x) _dsp_mtlo(x, 0)
1772 #define mtlo1(x) _dsp_mtlo(x, 1)
1773 #define mtlo2(x) _dsp_mtlo(x, 2)
1774 #define mtlo3(x) _dsp_mtlo(x, 3)
1775 
1776 #define mthi0(x) _dsp_mthi(x, 0)
1777 #define mthi1(x) _dsp_mthi(x, 1)
1778 #define mthi2(x) _dsp_mthi(x, 2)
1779 #define mthi3(x) _dsp_mthi(x, 3)
1780 
1781 #endif /* CONFIG_CPU_MICROMIPS */
1782 #endif
1783 #endif /* CONFIG_CPU_MIPSR6 */
1784 
1785 /*
1786  * TLB operations.
1787  *
1788  * It is responsibility of the caller to take care of any TLB hazards.
1789  */
tlb_probe(void)1790 static inline void tlb_probe(void)
1791 {
1792 	__asm__ __volatile__(
1793 		".set noreorder\n\t"
1794 		"tlbp\n\t"
1795 		".set reorder");
1796 }
1797 
tlb_read(void)1798 static inline void tlb_read(void)
1799 {
1800 #if MIPS34K_MISSED_ITLB_WAR
1801 	int res = 0;
1802 
1803 	__asm__ __volatile__(
1804 	"	.set	push					\n"
1805 	"	.set	noreorder				\n"
1806 	"	.set	noat					\n"
1807 	"	.set	mips32r2				\n"
1808 	"	.word	0x41610001		# dvpe $1	\n"
1809 	"	move	%0, $1					\n"
1810 	"	ehb						\n"
1811 	"	.set	pop					\n"
1812 	: "=r" (res));
1813 
1814 	instruction_hazard();
1815 #endif
1816 
1817 	__asm__ __volatile__(
1818 		".set noreorder\n\t"
1819 		"tlbr\n\t"
1820 		".set reorder");
1821 
1822 #if MIPS34K_MISSED_ITLB_WAR
1823 	if ((res & _ULCAST_(1)))
1824 		__asm__ __volatile__(
1825 		"	.set	push				\n"
1826 		"	.set	noreorder			\n"
1827 		"	.set	noat				\n"
1828 		"	.set	mips32r2			\n"
1829 		"	.word	0x41600021	# evpe		\n"
1830 		"	ehb					\n"
1831 		"	.set	pop				\n");
1832 #endif
1833 }
1834 
tlb_write_indexed(void)1835 static inline void tlb_write_indexed(void)
1836 {
1837 	__asm__ __volatile__(
1838 		".set noreorder\n\t"
1839 		"tlbwi\n\t"
1840 		".set reorder");
1841 }
1842 
tlb_write_random(void)1843 static inline void tlb_write_random(void)
1844 {
1845 	__asm__ __volatile__(
1846 		".set noreorder\n\t"
1847 		"tlbwr\n\t"
1848 		".set reorder");
1849 }
1850 
tlbinvf(void)1851 static inline void tlbinvf(void)
1852 {
1853 	__asm__ __volatile__(
1854 		".word 0x42000004");
1855 }
1856 
1857 /*
1858  * Manipulate bits in a c0 register.
1859  */
1860 #ifndef CONFIG_MIPS_MT_SMTC
1861 /*
1862  * SMTC Linux requires shutting-down microthread scheduling
1863  * during CP0 register read-modify-write sequences.
1864  */
1865 #define __BUILD_SET_C0(name)					\
1866 static inline unsigned int					\
1867 set_c0_##name(unsigned int set)					\
1868 {								\
1869 	unsigned int res, new;					\
1870 								\
1871 	res = read_c0_##name();					\
1872 	new = res | set;					\
1873 	write_c0_##name(new);					\
1874 								\
1875 	return res;						\
1876 }								\
1877 								\
1878 static inline unsigned int					\
1879 clear_c0_##name(unsigned int clear)				\
1880 {								\
1881 	unsigned int res, new;					\
1882 								\
1883 	res = read_c0_##name();					\
1884 	new = res & ~clear;					\
1885 	write_c0_##name(new);					\
1886 								\
1887 	return res;						\
1888 }								\
1889 								\
1890 static inline unsigned int					\
1891 change_c0_##name(unsigned int change, unsigned int val)		\
1892 {								\
1893 	unsigned int res, new;					\
1894 								\
1895 	res = read_c0_##name();					\
1896 	new = res & ~change;					\
1897 	new |= (val & change);					\
1898 	write_c0_##name(new);					\
1899 								\
1900 	return res;						\
1901 }
1902 
1903 #else /* SMTC versions that manage MT scheduling */
1904 
1905 #include <linux/irqflags.h>
1906 
1907 /*
1908  * This is a duplicate of dmt() in mipsmtregs.h to avoid problems with
1909  * header file recursion.
1910  */
__dmt(void)1911 static inline unsigned int __dmt(void)
1912 {
1913 	int res;
1914 
1915 	__asm__ __volatile__(
1916 	"	.set	push						\n"
1917 	"	.set	mips32r2					\n"
1918 	"	.set	noat						\n"
1919 	"	.word	0x41610BC1			# dmt $1	\n"
1920 	"	ehb							\n"
1921 	"	move	%0, $1						\n"
1922 	"	.set	pop						\n"
1923 	: "=r" (res));
1924 
1925 	instruction_hazard();
1926 
1927 	return res;
1928 }
1929 
1930 #define __VPECONTROL_TE_SHIFT	15
1931 #define __VPECONTROL_TE		(1UL << __VPECONTROL_TE_SHIFT)
1932 
1933 #define __EMT_ENABLE		__VPECONTROL_TE
1934 
__emt(unsigned int previous)1935 static inline void __emt(unsigned int previous)
1936 {
1937 	if ((previous & __EMT_ENABLE))
1938 		__asm__ __volatile__(
1939 		"	.set	mips32r2				\n"
1940 		"	.word	0x41600be1		# emt		\n"
1941 		"	ehb						\n"
1942 		"	.set	mips0					\n");
1943 }
1944 
__ehb(void)1945 static inline void __ehb(void)
1946 {
1947 	__asm__ __volatile__(
1948 	"	.set	mips32r2					\n"
1949 	"       ehb                                                     \n"
1950 	"       .set    mips0                                           \n");
1951 }
1952 
1953 /*
1954  * Note that local_irq_save/restore affect TC-specific IXMT state,
1955  * not Status.IE as in non-SMTC kernel.
1956  */
1957 
1958 #define __BUILD_SET_C0(name)					\
1959 static inline unsigned int					\
1960 set_c0_##name(unsigned int set)					\
1961 {								\
1962 	unsigned int res;					\
1963 	unsigned int new;					\
1964 	unsigned int omt;					\
1965 	unsigned long flags;					\
1966 								\
1967 	local_irq_save(flags);					\
1968 	omt = __dmt();						\
1969 	res = read_c0_##name();					\
1970 	new = res | set;					\
1971 	write_c0_##name(new);					\
1972 	__emt(omt);						\
1973 	local_irq_restore(flags);				\
1974 								\
1975 	return res;						\
1976 }								\
1977 								\
1978 static inline unsigned int					\
1979 clear_c0_##name(unsigned int clear)				\
1980 {								\
1981 	unsigned int res;					\
1982 	unsigned int new;					\
1983 	unsigned int omt;					\
1984 	unsigned long flags;					\
1985 								\
1986 	local_irq_save(flags);					\
1987 	omt = __dmt();						\
1988 	res = read_c0_##name();					\
1989 	new = res & ~clear;					\
1990 	write_c0_##name(new);					\
1991 	__emt(omt);						\
1992 	local_irq_restore(flags);				\
1993 								\
1994 	return res;						\
1995 }								\
1996 								\
1997 static inline unsigned int					\
1998 change_c0_##name(unsigned int change, unsigned int newbits)	\
1999 {								\
2000 	unsigned int res;					\
2001 	unsigned int new;					\
2002 	unsigned int omt;					\
2003 	unsigned long flags;					\
2004 								\
2005 	local_irq_save(flags);					\
2006 								\
2007 	omt = __dmt();						\
2008 	res = read_c0_##name();					\
2009 	new = res & ~change;					\
2010 	new |= (newbits & change);				\
2011 	write_c0_##name(new);					\
2012 	__emt(omt);						\
2013 	local_irq_restore(flags);				\
2014 								\
2015 	return res;						\
2016 }
2017 #endif
2018 
2019 __BUILD_SET_C0(status)
2020 __BUILD_SET_C0(cause)
2021 __BUILD_SET_C0(config)
2022 __BUILD_SET_C0(config5)
2023 __BUILD_SET_C0(intcontrol)
2024 __BUILD_SET_C0(intctl)
2025 __BUILD_SET_C0(srsmap)
2026 __BUILD_SET_C0(brcm_config_0)
2027 __BUILD_SET_C0(brcm_bus_pll)
2028 __BUILD_SET_C0(brcm_reset)
2029 __BUILD_SET_C0(brcm_cmt_intr)
2030 __BUILD_SET_C0(brcm_cmt_ctrl)
2031 __BUILD_SET_C0(brcm_config)
2032 __BUILD_SET_C0(brcm_mode)
2033 
2034 #endif /* !__ASSEMBLY__ */
2035 
2036 #endif /* _ASM_MIPSREGS_H */
2037