blob: b4d10e938d216278d224b75b8b28a5502d8963e8 [file] [log] [blame]
developere0cea0f2021-12-16 16:08:26 +08001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_MIPSREGS_H
3#define _ASM_MIPSREGS_H
4
5//#include <linux/linkage.h>
6//#include <asm/hazards.h>
7#define CONFIG_PAGE_SIZE_4KB
8/*
9 * The following macros are especially useful for __asm__
10 * inline assembler.
11 */
12#ifndef __STR
13#define __STR(x) #x
14#endif
15#ifndef STR
16#define STR(x) __STR(x)
17#endif
18
19/*
20 * Configure language
21 */
22#ifdef __ASSEMBLY__
23#define _ULCAST_
24#else
25#define _ULCAST_ (unsigned long)
26#endif
27
28/*
29 * Coprocessor 0 register names
30 */
31#define CP0_INDEX $0
32#define CP0_RANDOM $1
33#define CP0_ENTRYLO0 $2
34#define CP0_ENTRYLO1 $3
35#define CP0_CONF $3
36#define CP0_CONTEXT $4
37#define CP0_PAGEMASK $5
38#define CP0_WIRED $6
39#define CP0_INFO $7
40#define CP0_BADVADDR $8
41#define CP0_COUNT $9
42#define CP0_ENTRYHI $10
43#define CP0_COMPARE $11
44#define CP0_STATUS $12
45#define CP0_CAUSE $13
46#define CP0_EPC $14
47#define CP0_PRID $15
48#define CP0_CONFIG $16
49#define CP0_LLADDR $17
50#define CP0_WATCHLO $18
51#define CP0_WATCHHI $19
52#define CP0_XCONTEXT $20
53#define CP0_FRAMEMASK $21
54#define CP0_DIAGNOSTIC $22
55#define CP0_DEBUG $23
56#define CP0_DEPC $24
57#define CP0_PERFORMANCE $25
58#define CP0_ECC $26
59#define CP0_CACHEERR $27
60#define CP0_TAGLO $28
61#define CP0_TAGHI $29
62#define CP0_ERROREPC $30
63#define CP0_DESAVE $31
64
65/*
66 * R4640/R4650 cp0 register names. These registers are listed
67 * here only for completeness; without MMU these CPUs are not useable
68 * by Linux. A future ELKS port might take make Linux run on them
69 * though ...
70 */
71#define CP0_IBASE $0
72#define CP0_IBOUND $1
73#define CP0_DBASE $2
74#define CP0_DBOUND $3
75#define CP0_CALG $17
76#define CP0_IWATCH $18
77#define CP0_DWATCH $19
78
79/*
80 * Coprocessor 0 Set 1 register names
81 */
82#define CP0_S1_DERRADDR0 $26
83#define CP0_S1_DERRADDR1 $27
84#define CP0_S1_INTCONTROL $20
85
86/*
87 * Coprocessor 0 Set 2 register names
88 */
89#define CP0_S2_SRSCTL $12 /* MIPSR2 */
90
91/*
92 * Coprocessor 0 Set 3 register names
93 */
94#define CP0_S3_SRSMAP $12 /* MIPSR2 */
95
96/*
97 * TX39 Series
98 */
99#define CP0_TX39_CACHE $7
100
101/*
102 * Coprocessor 1 (FPU) register names
103 */
104#define CP1_REVISION $0
105#define CP1_STATUS $31
106
107/*
108 * FPU Status Register Values
109 */
110/*
111 * Status Register Values
112 */
113
114#define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
115#define FPU_CSR_COND 0x00800000 /* $fcc0 */
116#define FPU_CSR_COND0 0x00800000 /* $fcc0 */
117#define FPU_CSR_COND1 0x02000000 /* $fcc1 */
118#define FPU_CSR_COND2 0x04000000 /* $fcc2 */
119#define FPU_CSR_COND3 0x08000000 /* $fcc3 */
120#define FPU_CSR_COND4 0x10000000 /* $fcc4 */
121#define FPU_CSR_COND5 0x20000000 /* $fcc5 */
122#define FPU_CSR_COND6 0x40000000 /* $fcc6 */
123#define FPU_CSR_COND7 0x80000000 /* $fcc7 */
124
125/*
126 * X the exception cause indicator
127 * E the exception enable
128 * S the sticky/flag bit
129*/
130#define FPU_CSR_ALL_X 0x0003f000
131#define FPU_CSR_UNI_X 0x00020000
132#define FPU_CSR_INV_X 0x00010000
133#define FPU_CSR_DIV_X 0x00008000
134#define FPU_CSR_OVF_X 0x00004000
135#define FPU_CSR_UDF_X 0x00002000
136#define FPU_CSR_INE_X 0x00001000
137
138#define FPU_CSR_ALL_E 0x00000f80
139#define FPU_CSR_INV_E 0x00000800
140#define FPU_CSR_DIV_E 0x00000400
141#define FPU_CSR_OVF_E 0x00000200
142#define FPU_CSR_UDF_E 0x00000100
143#define FPU_CSR_INE_E 0x00000080
144
145#define FPU_CSR_ALL_S 0x0000007c
146#define FPU_CSR_INV_S 0x00000040
147#define FPU_CSR_DIV_S 0x00000020
148#define FPU_CSR_OVF_S 0x00000010
149#define FPU_CSR_UDF_S 0x00000008
150#define FPU_CSR_INE_S 0x00000004
151
152/* rounding mode */
153#define FPU_CSR_RN 0x0 /* nearest */
154#define FPU_CSR_RZ 0x1 /* towards zero */
155#define FPU_CSR_RU 0x2 /* towards +Infinity */
156#define FPU_CSR_RD 0x3 /* towards -Infinity */
157
158
159/*
160 * Values for PageMask register
161 */
162#ifdef CONFIG_CPU_VR41XX
163
164/* Why doesn't stupidity hurt ... */
165
166#define PM_1K 0x00000000
167#define PM_4K 0x00001800
168#define PM_16K 0x00007800
169#define PM_64K 0x0001f800
170#define PM_256K 0x0007f800
171
172#else
173
174#define PM_4K 0x00000000
175#define PM_16K 0x00006000
176#define PM_64K 0x0001e000
177#define PM_256K 0x0007e000
178#define PM_1M 0x001fe000
179#define PM_4M 0x007fe000
180#define PM_16M 0x01ffe000
181#define PM_64M 0x07ffe000
182#define PM_256M 0x1fffe000
183
184#endif
185
186/*
187 * Default page size for a given kernel configuration
188 */
189#ifdef CONFIG_PAGE_SIZE_4KB
190#define PM_DEFAULT_MASK PM_4K
191#elif defined(CONFIG_PAGE_SIZE_16KB)
192#define PM_DEFAULT_MASK PM_16K
193#elif defined(CONFIG_PAGE_SIZE_64KB)
194#define PM_DEFAULT_MASK PM_64K
195#else
196#error Bad page size configuration!
197#endif
198
199
200/*
201 * Values used for computation of new tlb entries
202 */
203#define PL_4K 12
204#define PL_16K 14
205#define PL_64K 16
206#define PL_256K 18
207#define PL_1M 20
208#define PL_4M 22
209#define PL_16M 24
210#define PL_64M 26
211#define PL_256M 28
212
213/*
214 * R4x00 interrupt enable / cause bits
215 */
216#define IE_SW0 (_ULCAST_(1) << 8)
217#define IE_SW1 (_ULCAST_(1) << 9)
218#define IE_IRQ0 (_ULCAST_(1) << 10)
219#define IE_IRQ1 (_ULCAST_(1) << 11)
220#define IE_IRQ2 (_ULCAST_(1) << 12)
221#define IE_IRQ3 (_ULCAST_(1) << 13)
222#define IE_IRQ4 (_ULCAST_(1) << 14)
223#define IE_IRQ5 (_ULCAST_(1) << 15)
224
225/*
226 * R4x00 interrupt cause bits
227 */
228#define C_SW0 (_ULCAST_(1) << 8)
229#define C_SW1 (_ULCAST_(1) << 9)
230#define C_IRQ0 (_ULCAST_(1) << 10)
231#define C_IRQ1 (_ULCAST_(1) << 11)
232#define C_IRQ2 (_ULCAST_(1) << 12)
233#define C_IRQ3 (_ULCAST_(1) << 13)
234#define C_IRQ4 (_ULCAST_(1) << 14)
235#define C_IRQ5 (_ULCAST_(1) << 15)
236
237/*
238 * Bitfields in the R4xx0 cp0 status register
239 */
240#define ST0_IE 0x00000001
241#define ST0_EXL 0x00000002
242#define ST0_ERL 0x00000004
243#define ST0_KSU 0x00000018
244# define KSU_USER 0x00000010
245# define KSU_SUPERVISOR 0x00000008
246# define KSU_KERNEL 0x00000000
247#define ST0_UX 0x00000020
248#define ST0_SX 0x00000040
249#define ST0_KX 0x00000080
250#define ST0_DE 0x00010000
251#define ST0_CE 0x00020000
252
253/*
254 * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
255 * cacheops in userspace. This bit exists only on RM7000 and RM9000
256 * processors.
257 */
258#define ST0_CO 0x08000000
259
260/*
261 * Bitfields in the R[23]000 cp0 status register.
262 */
263#define ST0_IEC 0x00000001
264#define ST0_KUC 0x00000002
265#define ST0_IEP 0x00000004
266#define ST0_KUP 0x00000008
267#define ST0_IEO 0x00000010
268#define ST0_KUO 0x00000020
269/* bits 6 & 7 are reserved on R[23]000 */
270#define ST0_ISC 0x00010000
271#define ST0_SWC 0x00020000
272#define ST0_CM 0x00080000
273
274/*
275 * Bits specific to the R4640/R4650
276 */
277#define ST0_UM (_ULCAST_(1) << 4)
278#define ST0_IL (_ULCAST_(1) << 23)
279#define ST0_DL (_ULCAST_(1) << 24)
280
281/*
282 * Enable the MIPS MDMX and DSP ASEs
283 */
284#define ST0_MX 0x01000000
285
286/*
287 * Bitfields in the TX39 family CP0 Configuration Register 3
288 */
289#define TX39_CONF_ICS_SHIFT 19
290#define TX39_CONF_ICS_MASK 0x00380000
291#define TX39_CONF_ICS_1KB 0x00000000
292#define TX39_CONF_ICS_2KB 0x00080000
293#define TX39_CONF_ICS_4KB 0x00100000
294#define TX39_CONF_ICS_8KB 0x00180000
295#define TX39_CONF_ICS_16KB 0x00200000
296
297#define TX39_CONF_DCS_SHIFT 16
298#define TX39_CONF_DCS_MASK 0x00070000
299#define TX39_CONF_DCS_1KB 0x00000000
300#define TX39_CONF_DCS_2KB 0x00010000
301#define TX39_CONF_DCS_4KB 0x00020000
302#define TX39_CONF_DCS_8KB 0x00030000
303#define TX39_CONF_DCS_16KB 0x00040000
304
305#define TX39_CONF_CWFON 0x00004000
306#define TX39_CONF_WBON 0x00002000
307#define TX39_CONF_RF_SHIFT 10
308#define TX39_CONF_RF_MASK 0x00000c00
309#define TX39_CONF_DOZE 0x00000200
310#define TX39_CONF_HALT 0x00000100
311#define TX39_CONF_LOCK 0x00000080
312#define TX39_CONF_ICE 0x00000020
313#define TX39_CONF_DCE 0x00000010
314#define TX39_CONF_IRSIZE_SHIFT 2
315#define TX39_CONF_IRSIZE_MASK 0x0000000c
316#define TX39_CONF_DRSIZE_SHIFT 0
317#define TX39_CONF_DRSIZE_MASK 0x00000003
318
319/*
320 * Status register bits available in all MIPS CPUs.
321 */
322#define ST0_IM 0x0000ff00
323#define STATUSB_IP0 8
324#define STATUSF_IP0 (_ULCAST_(1) << 8)
325#define STATUSB_IP1 9
326#define STATUSF_IP1 (_ULCAST_(1) << 9)
327#define STATUSB_IP2 10
328#define STATUSF_IP2 (_ULCAST_(1) << 10)
329#define STATUSB_IP3 11
330#define STATUSF_IP3 (_ULCAST_(1) << 11)
331#define STATUSB_IP4 12
332#define STATUSF_IP4 (_ULCAST_(1) << 12)
333#define STATUSB_IP5 13
334#define STATUSF_IP5 (_ULCAST_(1) << 13)
335#define STATUSB_IP6 14
336#define STATUSF_IP6 (_ULCAST_(1) << 14)
337#define STATUSB_IP7 15
338#define STATUSF_IP7 (_ULCAST_(1) << 15)
339#define STATUSB_IP8 0
340#define STATUSF_IP8 (_ULCAST_(1) << 0)
341#define STATUSB_IP9 1
342#define STATUSF_IP9 (_ULCAST_(1) << 1)
343#define STATUSB_IP10 2
344#define STATUSF_IP10 (_ULCAST_(1) << 2)
345#define STATUSB_IP11 3
346#define STATUSF_IP11 (_ULCAST_(1) << 3)
347#define STATUSB_IP12 4
348#define STATUSF_IP12 (_ULCAST_(1) << 4)
349#define STATUSB_IP13 5
350#define STATUSF_IP13 (_ULCAST_(1) << 5)
351#define STATUSB_IP14 6
352#define STATUSF_IP14 (_ULCAST_(1) << 6)
353#define STATUSB_IP15 7
354#define STATUSF_IP15 (_ULCAST_(1) << 7)
355#define ST0_CH 0x00040000
356#define ST0_SR 0x00100000
357#define ST0_TS 0x00200000
358#define ST0_BEV 0x00400000
359#define ST0_RE 0x02000000
360#define ST0_FR 0x04000000
361#define ST0_CU 0xf0000000
362#define ST0_CU0 0x10000000
363#define ST0_CU1 0x20000000
364#define ST0_CU2 0x40000000
365#define ST0_CU3 0x80000000
366#define ST0_XX 0x80000000 /* MIPS IV naming */
367
368/*
369 * Bitfields and bit numbers in the coprocessor 0 cause register.
370 *
371 * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
372 */
373#define CAUSEB_EXCCODE 2
374#define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
375#define CAUSEB_IP 8
376#define CAUSEF_IP (_ULCAST_(255) << 8)
377#define CAUSEB_IP0 8
378#define CAUSEF_IP0 (_ULCAST_(1) << 8)
379#define CAUSEB_IP1 9
380#define CAUSEF_IP1 (_ULCAST_(1) << 9)
381#define CAUSEB_IP2 10
382#define CAUSEF_IP2 (_ULCAST_(1) << 10)
383#define CAUSEB_IP3 11
384#define CAUSEF_IP3 (_ULCAST_(1) << 11)
385#define CAUSEB_IP4 12
386#define CAUSEF_IP4 (_ULCAST_(1) << 12)
387#define CAUSEB_IP5 13
388#define CAUSEF_IP5 (_ULCAST_(1) << 13)
389#define CAUSEB_IP6 14
390#define CAUSEF_IP6 (_ULCAST_(1) << 14)
391#define CAUSEB_IP7 15
392#define CAUSEF_IP7 (_ULCAST_(1) << 15)
393#define CAUSEB_IV 23
394#define CAUSEF_IV (_ULCAST_(1) << 23)
395#define CAUSEB_CE 28
396#define CAUSEF_CE (_ULCAST_(3) << 28)
397#define CAUSEB_BD 31
398#define CAUSEF_BD (_ULCAST_(1) << 31)
399
400/*
401 * Bits in the coprocessor 0 config register.
402 */
403/* Generic bits. */
404#define CONF_CM_CACHABLE_NO_WA 0
405#define CONF_CM_CACHABLE_WA 1
406#define CONF_CM_UNCACHED 2
407#define CONF_CM_CACHABLE_NONCOHERENT 3
408#define CONF_CM_CACHABLE_CE 4
409#define CONF_CM_CACHABLE_COW 5
410#define CONF_CM_CACHABLE_CUW 6
411#define CONF_CM_CACHABLE_ACCELERATED 7
412#define CONF_CM_CMASK 7
413#define CONF_BE (_ULCAST_(1) << 15)
414
415/* Bits common to various processors. */
416#define CONF_CU (_ULCAST_(1) << 3)
417#define CONF_DB (_ULCAST_(1) << 4)
418#define CONF_IB (_ULCAST_(1) << 5)
419#define CONF_DC (_ULCAST_(7) << 6)
420#define CONF_IC (_ULCAST_(7) << 9)
421#define CONF_EB (_ULCAST_(1) << 13)
422#define CONF_EM (_ULCAST_(1) << 14)
423#define CONF_SM (_ULCAST_(1) << 16)
424#define CONF_SC (_ULCAST_(1) << 17)
425#define CONF_EW (_ULCAST_(3) << 18)
426#define CONF_EP (_ULCAST_(15)<< 24)
427#define CONF_EC (_ULCAST_(7) << 28)
428#define CONF_CM (_ULCAST_(1) << 31)
429
430/* Bits specific to the R4xx0. */
431#define R4K_CONF_SW (_ULCAST_(1) << 20)
432#define R4K_CONF_SS (_ULCAST_(1) << 21)
433#define R4K_CONF_SB (_ULCAST_(3) << 22)
434
435/* Bits specific to the R5000. */
436#define R5K_CONF_SE (_ULCAST_(1) << 12)
437#define R5K_CONF_SS (_ULCAST_(3) << 20)
438
439/* Bits specific to the RM7000. */
440#define RM7K_CONF_SE (_ULCAST_(1) << 3)
441#define RM7K_CONF_TE (_ULCAST_(1) << 12)
442#define RM7K_CONF_CLK (_ULCAST_(1) << 16)
443#define RM7K_CONF_TC (_ULCAST_(1) << 17)
444#define RM7K_CONF_SI (_ULCAST_(3) << 20)
445#define RM7K_CONF_SC (_ULCAST_(1) << 31)
446
447/* Bits specific to the R10000. */
448#define R10K_CONF_DN (_ULCAST_(3) << 3)
449#define R10K_CONF_CT (_ULCAST_(1) << 5)
450#define R10K_CONF_PE (_ULCAST_(1) << 6)
451#define R10K_CONF_PM (_ULCAST_(3) << 7)
452#define R10K_CONF_EC (_ULCAST_(15)<< 9)
453#define R10K_CONF_SB (_ULCAST_(1) << 13)
454#define R10K_CONF_SK (_ULCAST_(1) << 14)
455#define R10K_CONF_SS (_ULCAST_(7) << 16)
456#define R10K_CONF_SC (_ULCAST_(7) << 19)
457#define R10K_CONF_DC (_ULCAST_(7) << 26)
458#define R10K_CONF_IC (_ULCAST_(7) << 29)
459
460/* Bits specific to the VR41xx. */
461#define VR41_CONF_CS (_ULCAST_(1) << 12)
462#define VR41_CONF_P4K (_ULCAST_(1) << 13)
463#define VR41_CONF_BP (_ULCAST_(1) << 16)
464#define VR41_CONF_M16 (_ULCAST_(1) << 20)
465#define VR41_CONF_AD (_ULCAST_(1) << 23)
466
467/* Bits specific to the R30xx. */
468#define R30XX_CONF_FDM (_ULCAST_(1) << 19)
469#define R30XX_CONF_REV (_ULCAST_(1) << 22)
470#define R30XX_CONF_AC (_ULCAST_(1) << 23)
471#define R30XX_CONF_RF (_ULCAST_(1) << 24)
472#define R30XX_CONF_HALT (_ULCAST_(1) << 25)
473#define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
474#define R30XX_CONF_DBR (_ULCAST_(1) << 29)
475#define R30XX_CONF_SB (_ULCAST_(1) << 30)
476#define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
477
478/* Bits specific to the TX49. */
479#define TX49_CONF_DC (_ULCAST_(1) << 16)
480#define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
481#define TX49_CONF_HALT (_ULCAST_(1) << 18)
482#define TX49_CONF_CWFON (_ULCAST_(1) << 27)
483
484/* Bits specific to the MIPS32/64 PRA. */
485#define MIPS_CONF_MT (_ULCAST_(7) << 7)
486#define MIPS_CONF_AR (_ULCAST_(7) << 10)
487#define MIPS_CONF_AT (_ULCAST_(3) << 13)
488#define MIPS_CONF_M (_ULCAST_(1) << 31)
489
490/*
491 * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
492 */
493#define MIPS_CONF1_FP (_ULCAST_(1) << 0)
494#define MIPS_CONF1_EP (_ULCAST_(1) << 1)
495#define MIPS_CONF1_CA (_ULCAST_(1) << 2)
496#define MIPS_CONF1_WR (_ULCAST_(1) << 3)
497#define MIPS_CONF1_PC (_ULCAST_(1) << 4)
498#define MIPS_CONF1_MD (_ULCAST_(1) << 5)
499#define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
500#define MIPS_CONF1_DA (_ULCAST_(7) << 7)
501#define MIPS_CONF1_DL (_ULCAST_(7) << 10)
502#define MIPS_CONF1_DS (_ULCAST_(7) << 13)
503#define MIPS_CONF1_IA (_ULCAST_(7) << 16)
504#define MIPS_CONF1_IL (_ULCAST_(7) << 19)
505#define MIPS_CONF1_IS (_ULCAST_(7) << 22)
506#define MIPS_CONF1_TLBS (_ULCAST_(63)<< 25)
507
508#define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
509#define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
510#define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
511#define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
512#define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
513#define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
514#define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
515#define MIPS_CONF2_TU (_ULCAST_(7) << 28)
516
517#define MIPS_CONF3_TL (_ULCAST_(1) << 0)
518#define MIPS_CONF3_SM (_ULCAST_(1) << 1)
519#define MIPS_CONF3_MT (_ULCAST_(1) << 2)
520#define MIPS_CONF3_SP (_ULCAST_(1) << 4)
521#define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
522#define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
523#define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
524#define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
525
526/*
527 * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
528 */
529#define MIPS_FPIR_S (_ULCAST_(1) << 16)
530#define MIPS_FPIR_D (_ULCAST_(1) << 17)
531#define MIPS_FPIR_PS (_ULCAST_(1) << 18)
532#define MIPS_FPIR_3D (_ULCAST_(1) << 19)
533#define MIPS_FPIR_W (_ULCAST_(1) << 20)
534#define MIPS_FPIR_L (_ULCAST_(1) << 21)
535#define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
536
537#ifndef __ASSEMBLY__
538
539/*
540 * Functions to access the R10000 performance counters. These are basically
541 * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
542 * performance counter number encoded into bits 1 ... 5 of the instruction.
543 * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
544 * disassembler these will look like an access to sel 0 or 1.
545 */
546#define read_r10k_perf_cntr(counter) \
547({ \
548 unsigned int __res; \
549 __asm__ __volatile__( \
550 "mfpc\t%0, %1" \
551 : "=r" (__res) \
552 : "i" (counter)); \
553 \
554 __res; \
555})
556
557#define write_r10k_perf_cntr(counter,val) \
558do { \
559 __asm__ __volatile__( \
560 "mtpc\t%0, %1" \
561 : \
562 : "r" (val), "i" (counter)); \
563} while (0)
564
565#define read_r10k_perf_event(counter) \
566({ \
567 unsigned int __res; \
568 __asm__ __volatile__( \
569 "mfps\t%0, %1" \
570 : "=r" (__res) \
571 : "i" (counter)); \
572 \
573 __res; \
574})
575
576#define write_r10k_perf_cntl(counter,val) \
577do { \
578 __asm__ __volatile__( \
579 "mtps\t%0, %1" \
580 : \
581 : "r" (val), "i" (counter)); \
582} while (0)
583
584
585/*
586 * Macros to access the system control coprocessor
587 */
588
589#define __read_32bit_c0_register(source, sel) \
590({ int __res; \
591 if (sel == 0) \
592 __asm__ __volatile__( \
593 "mfc0\t%0, " #source "\n\t" \
594 : "=r" (__res)); \
595 else \
596 __asm__ __volatile__( \
597 ".set\tmips32\n\t" \
598 "mfc0\t%0, " #source ", " #sel "\n\t" \
599 ".set\tmips0\n\t" \
600 : "=r" (__res)); \
601 __res; \
602})
603
604#define __read_64bit_c0_register(source, sel) \
605({ unsigned long long __res; \
606 if (sizeof(unsigned long) == 4) \
607 __res = __read_64bit_c0_split(source, sel); \
608 else if (sel == 0) \
609 __asm__ __volatile__( \
610 ".set\tmips3\n\t" \
611 "dmfc0\t%0, " #source "\n\t" \
612 ".set\tmips0" \
613 : "=r" (__res)); \
614 else \
615 __asm__ __volatile__( \
616 ".set\tmips64\n\t" \
617 "dmfc0\t%0, " #source ", " #sel "\n\t" \
618 ".set\tmips0" \
619 : "=r" (__res)); \
620 __res; \
621})
622
623#define __write_32bit_c0_register(register, sel, value) \
624do { \
625 if (sel == 0) \
626 __asm__ __volatile__( \
627 "mtc0\t%z0, " #register "\n\t" \
628 : : "Jr" ((unsigned int)(value))); \
629 else \
630 __asm__ __volatile__( \
631 ".set\tmips32\n\t" \
632 "mtc0\t%z0, " #register ", " #sel "\n\t" \
633 ".set\tmips0" \
634 : : "Jr" ((unsigned int)(value))); \
635} while (0)
636
637#define __write_64bit_c0_register(register, sel, value) \
638do { \
639 if (sizeof(unsigned long) == 4) \
640 __write_64bit_c0_split(register, sel, value); \
641 else if (sel == 0) \
642 __asm__ __volatile__( \
643 ".set\tmips3\n\t" \
644 "dmtc0\t%z0, " #register "\n\t" \
645 ".set\tmips0" \
646 : : "Jr" (value)); \
647 else \
648 __asm__ __volatile__( \
649 ".set\tmips64\n\t" \
650 "dmtc0\t%z0, " #register ", " #sel "\n\t" \
651 ".set\tmips0" \
652 : : "Jr" (value)); \
653} while (0)
654
655#define __read_ulong_c0_register(reg, sel) \
656 ((sizeof(unsigned long) == 4) ? \
657 (unsigned long) __read_32bit_c0_register(reg, sel) : \
658 (unsigned long) __read_64bit_c0_register(reg, sel))
659
660#define __write_ulong_c0_register(reg, sel, val) \
661do { \
662 if (sizeof(unsigned long) == 4) \
663 __write_32bit_c0_register(reg, sel, val); \
664 else \
665 __write_64bit_c0_register(reg, sel, val); \
666} while (0)
667
668/*
669 * On RM7000/RM9000 these are uses to access cop0 set 1 registers
670 */
671#define __read_32bit_c0_ctrl_register(source) \
672({ int __res; \
673 __asm__ __volatile__( \
674 "cfc0\t%0, " #source "\n\t" \
675 : "=r" (__res)); \
676 __res; \
677})
678
679#define __write_32bit_c0_ctrl_register(register, value) \
680do { \
681 __asm__ __volatile__( \
682 "ctc0\t%z0, " #register "\n\t" \
683 : : "Jr" ((unsigned int)(value))); \
684} while (0)
685
686/*
687 * These versions are only needed for systems with more than 38 bits of
688 * physical address space running the 32-bit kernel. That's none atm :-)
689 */
690#define __read_64bit_c0_split(source, sel) \
691({ \
692 unsigned long long val; \
693 unsigned long flags; \
694 \
695 local_irq_save(flags); \
696 if (sel == 0) \
697 __asm__ __volatile__( \
698 ".set\tmips64\n\t" \
699 "dmfc0\t%M0, " #source "\n\t" \
700 "dsll\t%L0, %M0, 32\n\t" \
701 "dsrl\t%M0, %M0, 32\n\t" \
702 "dsrl\t%L0, %L0, 32\n\t" \
703 ".set\tmips0" \
704 : "=r" (val)); \
705 else \
706 __asm__ __volatile__( \
707 ".set\tmips64\n\t" \
708 "dmfc0\t%M0, " #source ", " #sel "\n\t" \
709 "dsll\t%L0, %M0, 32\n\t" \
710 "dsrl\t%M0, %M0, 32\n\t" \
711 "dsrl\t%L0, %L0, 32\n\t" \
712 ".set\tmips0" \
713 : "=r" (val)); \
714 local_irq_restore(flags); \
715 \
716 val; \
717})
718
719#define __write_64bit_c0_split(source, sel, val) \
720do { \
721 unsigned long flags; \
722 \
723 local_irq_save(flags); \
724 if (sel == 0) \
725 __asm__ __volatile__( \
726 ".set\tmips64\n\t" \
727 "dsll\t%L0, %L0, 32\n\t" \
728 "dsrl\t%L0, %L0, 32\n\t" \
729 "dsll\t%M0, %M0, 32\n\t" \
730 "or\t%L0, %L0, %M0\n\t" \
731 "dmtc0\t%L0, " #source "\n\t" \
732 ".set\tmips0" \
733 : : "r" (val)); \
734 else \
735 __asm__ __volatile__( \
736 ".set\tmips64\n\t" \
737 "dsll\t%L0, %L0, 32\n\t" \
738 "dsrl\t%L0, %L0, 32\n\t" \
739 "dsll\t%M0, %M0, 32\n\t" \
740 "or\t%L0, %L0, %M0\n\t" \
741 "dmtc0\t%L0, " #source ", " #sel "\n\t" \
742 ".set\tmips0" \
743 : : "r" (val)); \
744 local_irq_restore(flags); \
745} while (0)
746
747#define read_c0_index() __read_32bit_c0_register($0, 0)
748#define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
749
750#define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
751#define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
752
753#define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
754#define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
755
756#define read_c0_conf() __read_32bit_c0_register($3, 0)
757#define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
758
759#define read_c0_context() __read_ulong_c0_register($4, 0)
760#define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
761
762#define read_c0_pagemask() __read_32bit_c0_register($5, 0)
763#define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
764
765#define read_c0_wired() __read_32bit_c0_register($6, 0)
766#define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
767
768#define read_c0_info() __read_32bit_c0_register($7, 0)
769
770#define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
771#define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
772
773#define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
774#define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
775
776#define read_c0_count() __read_32bit_c0_register($9, 0)
777#define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
778
779#define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
780#define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
781
782#define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
783#define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
784
785#define read_c0_entryhi() __read_ulong_c0_register($10, 0)
786#define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
787
788#define read_c0_compare() __read_32bit_c0_register($11, 0)
789#define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
790
791#define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
792#define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
793
794#define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
795#define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
796
797#define read_c0_status() __read_32bit_c0_register($12, 0)
798#ifdef CONFIG_MIPS_MT_SMTC
799#define write_c0_status(val) \
800do { \
801 __write_32bit_c0_register($12, 0, val); \
802 __ehb(); \
803} while (0)
804#else
805/*
806 * Legacy non-SMTC code, which may be hazardous
807 * but which might not support EHB
808 */
809#define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
810#endif /* CONFIG_MIPS_MT_SMTC */
811
812#define read_c0_cause() __read_32bit_c0_register($13, 0)
813#define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
814
815#define read_c0_epc() __read_ulong_c0_register($14, 0)
816#define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
817
818#define read_c0_prid() __read_32bit_c0_register($15, 0)
819
820#define read_c0_config() __read_32bit_c0_register($16, 0)
821#define read_c0_config1() __read_32bit_c0_register($16, 1)
822#define read_c0_config2() __read_32bit_c0_register($16, 2)
823#define read_c0_config3() __read_32bit_c0_register($16, 3)
824#define read_c0_config4() __read_32bit_c0_register($16, 4)
825#define read_c0_config5() __read_32bit_c0_register($16, 5)
826#define read_c0_config6() __read_32bit_c0_register($16, 6)
827#define read_c0_config7() __read_32bit_c0_register($16, 7)
828#define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
829#define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
830#define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
831#define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
832#define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
833#define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
834#define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
835#define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
836
837/*
838 * The WatchLo register. There may be upto 8 of them.
839 */
840#define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
841#define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
842#define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
843#define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
844#define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
845#define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
846#define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
847#define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
848#define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
849#define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
850#define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
851#define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
852#define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
853#define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
854#define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
855#define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
856
857/*
858 * The WatchHi register. There may be upto 8 of them.
859 */
860#define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
861#define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
862#define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
863#define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
864#define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
865#define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
866#define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
867#define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
868
869#define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
870#define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
871#define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
872#define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
873#define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
874#define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
875#define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
876#define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
877
878#define read_c0_xcontext() __read_ulong_c0_register($20, 0)
879#define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
880
881#define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
882#define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
883
884#define read_c0_framemask() __read_32bit_c0_register($21, 0)
885#define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
886
887/* RM9000 PerfControl performance counter control register */
888#define read_c0_perfcontrol() __read_32bit_c0_register($22, 0)
889#define write_c0_perfcontrol(val) __write_32bit_c0_register($22, 0, val)
890
891#define read_c0_diag() __read_32bit_c0_register($22, 0)
892#define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
893
894#define read_c0_diag1() __read_32bit_c0_register($22, 1)
895#define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
896
897#define read_c0_diag2() __read_32bit_c0_register($22, 2)
898#define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
899
900#define read_c0_diag3() __read_32bit_c0_register($22, 3)
901#define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
902
903#define read_c0_diag4() __read_32bit_c0_register($22, 4)
904#define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
905
906#define read_c0_diag5() __read_32bit_c0_register($22, 5)
907#define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
908
909#define read_c0_debug() __read_32bit_c0_register($23, 0)
910#define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
911
912#define read_c0_depc() __read_ulong_c0_register($24, 0)
913#define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
914
915/*
916 * MIPS32 / MIPS64 performance counters
917 */
918#define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
919#define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
920#define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
921#define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
922#define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
923#define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
924#define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
925#define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
926#define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
927#define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
928#define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
929#define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
930#define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
931#define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
932#define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
933#define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
934
935/* RM9000 PerfCount performance counter register */
936#define read_c0_perfcount() __read_64bit_c0_register($25, 0)
937#define write_c0_perfcount(val) __write_64bit_c0_register($25, 0, val)
938
939#define read_c0_ecc() __read_32bit_c0_register($26, 0)
940#define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
941
942#define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
943#define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
944
945#define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
946
947#define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
948#define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
949
950#define read_c0_taglo() __read_32bit_c0_register($28, 0)
951#define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
952
953#define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
954#define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
955
956#define read_c0_taghi() __read_32bit_c0_register($29, 0)
957#define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
958
959#define read_c0_errorepc() __read_ulong_c0_register($30, 0)
960#define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
961
962/* MIPSR2 */
963#define read_c0_hwrena() __read_32bit_c0_register($7,0)
964#define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
965
966#define read_c0_intctl() __read_32bit_c0_register($12, 1)
967#define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
968
969#define read_c0_srsctl() __read_32bit_c0_register($12, 2)
970#define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
971
972#define read_c0_srsmap() __read_32bit_c0_register($12, 3)
973#define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
974
975#define read_c0_ebase() __read_32bit_c0_register($15,1)
976#define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
977
978/*
979 * Macros to access the floating point coprocessor control registers
980 */
981#define read_32bit_cp1_register(source) \
982({ int __res; \
983 __asm__ __volatile__( \
984 ".set\tpush\n\t" \
985 ".set\treorder\n\t" \
986 "cfc1\t%0,"STR(source)"\n\t" \
987 ".set\tpop" \
988 : "=r" (__res)); \
989 __res;})
990
991#define rddsp(mask) \
992({ \
993 unsigned int __res; \
994 \
995 __asm__ __volatile__( \
996 " .set push \n" \
997 " .set noat \n" \
998 " # rddsp $1, %x1 \n" \
999 " .word 0x7c000cb8 | (%x1 << 16) \n" \
1000 " move %0, $1 \n" \
1001 " .set pop \n" \
1002 : "=r" (__res) \
1003 : "i" (mask)); \
1004 __res; \
1005})
1006
1007#define wrdsp(val, mask) \
1008do { \
1009 __asm__ __volatile__( \
1010 " .set push \n" \
1011 " .set noat \n" \
1012 " move $1, %0 \n" \
1013 " # wrdsp $1, %x1 \n" \
1014 " .word 0x7c2004f8 | (%x1 << 11) \n" \
1015 " .set pop \n" \
1016 : \
1017 : "r" (val), "i" (mask)); \
1018} while (0)
1019
1020#if 0 /* Need DSP ASE capable assembler ... */
1021#define mflo0() ({ long mflo0; __asm__("mflo %0, $ac0" : "=r" (mflo0)); mflo0;})
1022#define mflo1() ({ long mflo1; __asm__("mflo %0, $ac1" : "=r" (mflo1)); mflo1;})
1023#define mflo2() ({ long mflo2; __asm__("mflo %0, $ac2" : "=r" (mflo2)); mflo2;})
1024#define mflo3() ({ long mflo3; __asm__("mflo %0, $ac3" : "=r" (mflo3)); mflo3;})
1025
1026#define mfhi0() ({ long mfhi0; __asm__("mfhi %0, $ac0" : "=r" (mfhi0)); mfhi0;})
1027#define mfhi1() ({ long mfhi1; __asm__("mfhi %0, $ac1" : "=r" (mfhi1)); mfhi1;})
1028#define mfhi2() ({ long mfhi2; __asm__("mfhi %0, $ac2" : "=r" (mfhi2)); mfhi2;})
1029#define mfhi3() ({ long mfhi3; __asm__("mfhi %0, $ac3" : "=r" (mfhi3)); mfhi3;})
1030
1031#define mtlo0(x) __asm__("mtlo %0, $ac0" ::"r" (x))
1032#define mtlo1(x) __asm__("mtlo %0, $ac1" ::"r" (x))
1033#define mtlo2(x) __asm__("mtlo %0, $ac2" ::"r" (x))
1034#define mtlo3(x) __asm__("mtlo %0, $ac3" ::"r" (x))
1035
1036#define mthi0(x) __asm__("mthi %0, $ac0" ::"r" (x))
1037#define mthi1(x) __asm__("mthi %0, $ac1" ::"r" (x))
1038#define mthi2(x) __asm__("mthi %0, $ac2" ::"r" (x))
1039#define mthi3(x) __asm__("mthi %0, $ac3" ::"r" (x))
1040
1041#else
1042
1043#define mfhi0() \
1044({ \
1045 unsigned long __treg; \
1046 \
1047 __asm__ __volatile__( \
1048 " .set push \n" \
1049 " .set noat \n" \
1050 " # mfhi %0, $ac0 \n" \
1051 " .word 0x00000810 \n" \
1052 " move %0, $1 \n" \
1053 " .set pop \n" \
1054 : "=r" (__treg)); \
1055 __treg; \
1056})
1057
1058#define mfhi1() \
1059({ \
1060 unsigned long __treg; \
1061 \
1062 __asm__ __volatile__( \
1063 " .set push \n" \
1064 " .set noat \n" \
1065 " # mfhi %0, $ac1 \n" \
1066 " .word 0x00200810 \n" \
1067 " move %0, $1 \n" \
1068 " .set pop \n" \
1069 : "=r" (__treg)); \
1070 __treg; \
1071})
1072
1073#define mfhi2() \
1074({ \
1075 unsigned long __treg; \
1076 \
1077 __asm__ __volatile__( \
1078 " .set push \n" \
1079 " .set noat \n" \
1080 " # mfhi %0, $ac2 \n" \
1081 " .word 0x00400810 \n" \
1082 " move %0, $1 \n" \
1083 " .set pop \n" \
1084 : "=r" (__treg)); \
1085 __treg; \
1086})
1087
1088#define mfhi3() \
1089({ \
1090 unsigned long __treg; \
1091 \
1092 __asm__ __volatile__( \
1093 " .set push \n" \
1094 " .set noat \n" \
1095 " # mfhi %0, $ac3 \n" \
1096 " .word 0x00600810 \n" \
1097 " move %0, $1 \n" \
1098 " .set pop \n" \
1099 : "=r" (__treg)); \
1100 __treg; \
1101})
1102
1103#define mflo0() \
1104({ \
1105 unsigned long __treg; \
1106 \
1107 __asm__ __volatile__( \
1108 " .set push \n" \
1109 " .set noat \n" \
1110 " # mflo %0, $ac0 \n" \
1111 " .word 0x00000812 \n" \
1112 " move %0, $1 \n" \
1113 " .set pop \n" \
1114 : "=r" (__treg)); \
1115 __treg; \
1116})
1117
1118#define mflo1() \
1119({ \
1120 unsigned long __treg; \
1121 \
1122 __asm__ __volatile__( \
1123 " .set push \n" \
1124 " .set noat \n" \
1125 " # mflo %0, $ac1 \n" \
1126 " .word 0x00200812 \n" \
1127 " move %0, $1 \n" \
1128 " .set pop \n" \
1129 : "=r" (__treg)); \
1130 __treg; \
1131})
1132
1133#define mflo2() \
1134({ \
1135 unsigned long __treg; \
1136 \
1137 __asm__ __volatile__( \
1138 " .set push \n" \
1139 " .set noat \n" \
1140 " # mflo %0, $ac2 \n" \
1141 " .word 0x00400812 \n" \
1142 " move %0, $1 \n" \
1143 " .set pop \n" \
1144 : "=r" (__treg)); \
1145 __treg; \
1146})
1147
1148#define mflo3() \
1149({ \
1150 unsigned long __treg; \
1151 \
1152 __asm__ __volatile__( \
1153 " .set push \n" \
1154 " .set noat \n" \
1155 " # mflo %0, $ac3 \n" \
1156 " .word 0x00600812 \n" \
1157 " move %0, $1 \n" \
1158 " .set pop \n" \
1159 : "=r" (__treg)); \
1160 __treg; \
1161})
1162
1163#define mthi0(x) \
1164do { \
1165 __asm__ __volatile__( \
1166 " .set push \n" \
1167 " .set noat \n" \
1168 " move $1, %0 \n" \
1169 " # mthi $1, $ac0 \n" \
1170 " .word 0x00200011 \n" \
1171 " .set pop \n" \
1172 : \
1173 : "r" (x)); \
1174} while (0)
1175
1176#define mthi1(x) \
1177do { \
1178 __asm__ __volatile__( \
1179 " .set push \n" \
1180 " .set noat \n" \
1181 " move $1, %0 \n" \
1182 " # mthi $1, $ac1 \n" \
1183 " .word 0x00200811 \n" \
1184 " .set pop \n" \
1185 : \
1186 : "r" (x)); \
1187} while (0)
1188
1189#define mthi2(x) \
1190do { \
1191 __asm__ __volatile__( \
1192 " .set push \n" \
1193 " .set noat \n" \
1194 " move $1, %0 \n" \
1195 " # mthi $1, $ac2 \n" \
1196 " .word 0x00201011 \n" \
1197 " .set pop \n" \
1198 : \
1199 : "r" (x)); \
1200} while (0)
1201
1202#define mthi3(x) \
1203do { \
1204 __asm__ __volatile__( \
1205 " .set push \n" \
1206 " .set noat \n" \
1207 " move $1, %0 \n" \
1208 " # mthi $1, $ac3 \n" \
1209 " .word 0x00201811 \n" \
1210 " .set pop \n" \
1211 : \
1212 : "r" (x)); \
1213} while (0)
1214
1215#define mtlo0(x) \
1216do { \
1217 __asm__ __volatile__( \
1218 " .set push \n" \
1219 " .set noat \n" \
1220 " move $1, %0 \n" \
1221 " # mtlo $1, $ac0 \n" \
1222 " .word 0x00200013 \n" \
1223 " .set pop \n" \
1224 : \
1225 : "r" (x)); \
1226} while (0)
1227
1228#define mtlo1(x) \
1229do { \
1230 __asm__ __volatile__( \
1231 " .set push \n" \
1232 " .set noat \n" \
1233 " move $1, %0 \n" \
1234 " # mtlo $1, $ac1 \n" \
1235 " .word 0x00200813 \n" \
1236 " .set pop \n" \
1237 : \
1238 : "r" (x)); \
1239} while (0)
1240
1241#define mtlo2(x) \
1242do { \
1243 __asm__ __volatile__( \
1244 " .set push \n" \
1245 " .set noat \n" \
1246 " move $1, %0 \n" \
1247 " # mtlo $1, $ac2 \n" \
1248 " .word 0x00201013 \n" \
1249 " .set pop \n" \
1250 : \
1251 : "r" (x)); \
1252} while (0)
1253
1254#define mtlo3(x) \
1255do { \
1256 __asm__ __volatile__( \
1257 " .set push \n" \
1258 " .set noat \n" \
1259 " move $1, %0 \n" \
1260 " # mtlo $1, $ac3 \n" \
1261 " .word 0x00201813 \n" \
1262 " .set pop \n" \
1263 : \
1264 : "r" (x)); \
1265} while (0)
1266
1267#endif
1268
1269/*
1270 * TLB operations.
1271 *
1272 * It is responsibility of the caller to take care of any TLB hazards.
1273 */
1274static inline void tlb_probe(void)
1275{
1276 __asm__ __volatile__(
1277 ".set noreorder\n\t"
1278 "tlbp\n\t"
1279 ".set reorder");
1280}
1281
1282static inline void tlb_read(void)
1283{
1284 __asm__ __volatile__(
1285 ".set noreorder\n\t"
1286 "tlbr\n\t"
1287 ".set reorder");
1288}
1289
1290static inline void tlb_write_indexed(void)
1291{
1292 __asm__ __volatile__(
1293 ".set noreorder\n\t"
1294 "tlbwi\n\t"
1295 ".set reorder");
1296}
1297
1298static inline void tlb_write_random(void)
1299{
1300 __asm__ __volatile__(
1301 ".set noreorder\n\t"
1302 "tlbwr\n\t"
1303 ".set reorder");
1304}
1305
1306/*
1307 * Manipulate bits in a c0 register.
1308 */
1309#ifndef CONFIG_MIPS_MT_SMTC
1310/*
1311 * SMTC Linux requires shutting-down microthread scheduling
1312 * during CP0 register read-modify-write sequences.
1313 */
1314#define __BUILD_SET_C0(name) \
1315static inline unsigned int \
1316set_c0_##name(unsigned int set) \
1317{ \
1318 unsigned int res; \
1319 \
1320 res = read_c0_##name(); \
1321 res |= set; \
1322 write_c0_##name(res); \
1323 \
1324 return res; \
1325} \
1326 \
1327static inline unsigned int \
1328clear_c0_##name(unsigned int clear) \
1329{ \
1330 unsigned int res; \
1331 \
1332 res = read_c0_##name(); \
1333 res &= ~clear; \
1334 write_c0_##name(res); \
1335 \
1336 return res; \
1337} \
1338 \
1339static inline unsigned int \
1340change_c0_##name(unsigned int change, unsigned int new) \
1341{ \
1342 unsigned int res; \
1343 \
1344 res = read_c0_##name(); \
1345 res &= ~change; \
1346 res |= (new & change); \
1347 write_c0_##name(res); \
1348 \
1349 return res; \
1350}
1351
1352#else /* SMTC versions that manage MT scheduling */
1353
1354#include <linux/irqflags.h>
1355
1356/*
1357 * This is a duplicate of dmt() in mipsmtregs.h to avoid problems with
1358 * header file recursion.
1359 */
1360static inline unsigned int __dmt(void)
1361{
1362 int res;
1363
1364 __asm__ __volatile__(
1365 " .set push \n"
1366 " .set mips32r2 \n"
1367 " .set noat \n"
1368 " .word 0x41610BC1 # dmt $1 \n"
1369 " ehb \n"
1370 " move %0, $1 \n"
1371 " .set pop \n"
1372 : "=r" (res));
1373
1374 instruction_hazard();
1375
1376 return res;
1377}
1378
1379#define __VPECONTROL_TE_SHIFT 15
1380#define __VPECONTROL_TE (1UL << __VPECONTROL_TE_SHIFT)
1381
1382#define __EMT_ENABLE __VPECONTROL_TE
1383
1384static inline void __emt(unsigned int previous)
1385{
1386 if ((previous & __EMT_ENABLE))
1387 __asm__ __volatile__(
1388 " .set mips32r2 \n"
1389 " .word 0x41600be1 # emt \n"
1390 " ehb \n"
1391 " .set mips0 \n");
1392}
1393
1394static inline void __ehb(void)
1395{
1396 __asm__ __volatile__(
1397 " .set mips32r2 \n"
1398 " ehb \n" " .set mips0 \n");
1399}
1400
1401/*
1402 * Note that local_irq_save/restore affect TC-specific IXMT state,
1403 * not Status.IE as in non-SMTC kernel.
1404 */
1405
1406#define __BUILD_SET_C0(name) \
1407static inline unsigned int \
1408set_c0_##name(unsigned int set) \
1409{ \
1410 unsigned int res; \
1411 unsigned int omt; \
1412 unsigned int flags; \
1413 \
1414 local_irq_save(flags); \
1415 omt = __dmt(); \
1416 res = read_c0_##name(); \
1417 res |= set; \
1418 write_c0_##name(res); \
1419 __emt(omt); \
1420 local_irq_restore(flags); \
1421 \
1422 return res; \
1423} \
1424 \
1425static inline unsigned int \
1426clear_c0_##name(unsigned int clear) \
1427{ \
1428 unsigned int res; \
1429 unsigned int omt; \
1430 unsigned int flags; \
1431 \
1432 local_irq_save(flags); \
1433 omt = __dmt(); \
1434 res = read_c0_##name(); \
1435 res &= ~clear; \
1436 write_c0_##name(res); \
1437 __emt(omt); \
1438 local_irq_restore(flags); \
1439 \
1440 return res; \
1441} \
1442 \
1443static inline unsigned int \
1444change_c0_##name(unsigned int change, unsigned int new) \
1445{ \
1446 unsigned int res; \
1447 unsigned int omt; \
1448 unsigned int flags; \
1449 \
1450 local_irq_save(flags); \
1451 \
1452 omt = __dmt(); \
1453 res = read_c0_##name(); \
1454 res &= ~change; \
1455 res |= (new & change); \
1456 write_c0_##name(res); \
1457 __emt(omt); \
1458 local_irq_restore(flags); \
1459 \
1460 return res; \
1461}
1462#endif
1463
1464__BUILD_SET_C0(status)
1465__BUILD_SET_C0(cause)
1466__BUILD_SET_C0(config)
1467__BUILD_SET_C0(intcontrol)
1468__BUILD_SET_C0(intctl)
1469__BUILD_SET_C0(srsmap)
1470
1471#endif /* !__ASSEMBLY__ */
1472
1473#endif /* _ASM_MIPSREGS_H */