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
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 MIPS Technologies, Inc. All rights reserved.
12 #ifndef _ASM_MIPSREGS_H
13 #define _ASM_MIPSREGS_H
15 #include <linux/config.h>
16 #include <linux/linkage.h>
19 * The following macros are especially useful for __asm__
26 #define STR(x) __STR(x)
30 * Coprocessor 0 register names
34 #define CP0_ENTRYLO0 $2
35 #define CP0_ENTRYLO1 $3
37 #define CP0_CONTEXT $4
38 #define CP0_PAGEMASK $5
41 #define CP0_BADVADDR $8
43 #define CP0_ENTRYHI $10
44 #define CP0_COMPARE $11
45 #define CP0_STATUS $12
49 #define CP0_CONFIG $16
50 #define CP0_LLADDR $17
51 #define CP0_WATCHLO $18
52 #define CP0_WATCHHI $19
53 #define CP0_XCONTEXT $20
54 #define CP0_FRAMEMASK $21
55 #define CP0_DIAGNOSTIC $22
58 #define CP0_PERFORMANCE $25
60 #define CP0_CACHEERR $27
63 #define CP0_ERROREPC $30
64 #define CP0_DESAVE $31
67 * R4640/R4650 cp0 register names. These registers are listed
68 * here only for completeness; without MMU these CPUs are not useable
69 * by Linux. A future ELKS port might take make Linux run on them
77 #define CP0_IWATCH $18
78 #define CP0_DWATCH $19
81 * Coprocessor 0 Set 1 register names
83 #define CP0_S1_DERRADDR0 $26
84 #define CP0_S1_DERRADDR1 $27
85 #define CP0_S1_INTCONTROL $20
90 #define CP0_TX39_CACHE $7
93 * Coprocessor 1 (FPU) register names
95 #define CP1_REVISION $0
96 #define CP1_STATUS $31
99 * FPU Status Register Values
102 * Status Register Values
105 #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
106 #define FPU_CSR_COND 0x00800000 /* $fcc0 */
107 #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
108 #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
109 #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
110 #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
111 #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
112 #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
113 #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
114 #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
117 * X the exception cause indicator
118 * E the exception enable
119 * S the sticky/flag bit
121 #define FPU_CSR_ALL_X 0x0003f000
122 #define FPU_CSR_UNI_X 0x00020000
123 #define FPU_CSR_INV_X 0x00010000
124 #define FPU_CSR_DIV_X 0x00008000
125 #define FPU_CSR_OVF_X 0x00004000
126 #define FPU_CSR_UDF_X 0x00002000
127 #define FPU_CSR_INE_X 0x00001000
129 #define FPU_CSR_ALL_E 0x00000f80
130 #define FPU_CSR_INV_E 0x00000800
131 #define FPU_CSR_DIV_E 0x00000400
132 #define FPU_CSR_OVF_E 0x00000200
133 #define FPU_CSR_UDF_E 0x00000100
134 #define FPU_CSR_INE_E 0x00000080
136 #define FPU_CSR_ALL_S 0x0000007c
137 #define FPU_CSR_INV_S 0x00000040
138 #define FPU_CSR_DIV_S 0x00000020
139 #define FPU_CSR_OVF_S 0x00000010
140 #define FPU_CSR_UDF_S 0x00000008
141 #define FPU_CSR_INE_S 0x00000004
144 #define FPU_CSR_RN 0x0 /* nearest */
145 #define FPU_CSR_RZ 0x1 /* towards zero */
146 #define FPU_CSR_RU 0x2 /* towards +Infinity */
147 #define FPU_CSR_RD 0x3 /* towards -Infinity */
151 * Values for PageMask register
153 #ifdef CONFIG_CPU_VR41XX
155 /* Why doesn't stupidity hurt ... */
157 #define PM_1K 0x00000000
158 #define PM_4K 0x00001800
159 #define PM_16K 0x00007800
160 #define PM_64K 0x0001f800
161 #define PM_256K 0x0007f800
165 #define PM_4K 0x00000000
166 #define PM_16K 0x00006000
167 #define PM_64K 0x0001e000
168 #define PM_256K 0x0007e000
169 #define PM_1M 0x001fe000
170 #define PM_4M 0x007fe000
171 #define PM_16M 0x01ffe000
172 #define PM_64M 0x07ffe000
173 #define PM_256M 0x1fffe000
178 * Values used for computation of new tlb entries
191 * R4x00 interrupt enable / cause bits
193 #define IE_SW0 (1<< 8)
194 #define IE_SW1 (1<< 9)
195 #define IE_IRQ0 (1<<10)
196 #define IE_IRQ1 (1<<11)
197 #define IE_IRQ2 (1<<12)
198 #define IE_IRQ3 (1<<13)
199 #define IE_IRQ4 (1<<14)
200 #define IE_IRQ5 (1<<15)
203 * R4x00 interrupt cause bits
205 #define C_SW0 (1<< 8)
206 #define C_SW1 (1<< 9)
207 #define C_IRQ0 (1<<10)
208 #define C_IRQ1 (1<<11)
209 #define C_IRQ2 (1<<12)
210 #define C_IRQ3 (1<<13)
211 #define C_IRQ4 (1<<14)
212 #define C_IRQ5 (1<<15)
215 * Bitfields in the R4xx0 cp0 status register
217 #define ST0_IE 0x00000001
218 #define ST0_EXL 0x00000002
219 #define ST0_ERL 0x00000004
220 #define ST0_KSU 0x00000018
221 # define KSU_USER 0x00000010
222 # define KSU_SUPERVISOR 0x00000008
223 # define KSU_KERNEL 0x00000000
224 #define ST0_UX 0x00000020
225 #define ST0_SX 0x00000040
226 #define ST0_KX 0x00000080
227 #define ST0_DE 0x00010000
228 #define ST0_CE 0x00020000
231 * Bitfields in the R[23]000 cp0 status register.
233 #define ST0_IEC 0x00000001
234 #define ST0_KUC 0x00000002
235 #define ST0_IEP 0x00000004
236 #define ST0_KUP 0x00000008
237 #define ST0_IEO 0x00000010
238 #define ST0_KUO 0x00000020
239 /* bits 6 & 7 are reserved on R[23]000 */
240 #define ST0_ISC 0x00010000
241 #define ST0_SWC 0x00020000
242 #define ST0_CM 0x00080000
245 * Bits specific to the R4640/R4650
247 #define ST0_UM (1 << 4)
248 #define ST0_IL (1 << 23)
249 #define ST0_DL (1 << 24)
252 * Bitfields in the TX39 family CP0 Configuration Register 3
254 #define TX39_CONF_ICS_SHIFT 19
255 #define TX39_CONF_ICS_MASK 0x00380000
256 #define TX39_CONF_ICS_1KB 0x00000000
257 #define TX39_CONF_ICS_2KB 0x00080000
258 #define TX39_CONF_ICS_4KB 0x00100000
259 #define TX39_CONF_ICS_8KB 0x00180000
260 #define TX39_CONF_ICS_16KB 0x00200000
262 #define TX39_CONF_DCS_SHIFT 16
263 #define TX39_CONF_DCS_MASK 0x00070000
264 #define TX39_CONF_DCS_1KB 0x00000000
265 #define TX39_CONF_DCS_2KB 0x00010000
266 #define TX39_CONF_DCS_4KB 0x00020000
267 #define TX39_CONF_DCS_8KB 0x00030000
268 #define TX39_CONF_DCS_16KB 0x00040000
270 #define TX39_CONF_CWFON 0x00004000
271 #define TX39_CONF_WBON 0x00002000
272 #define TX39_CONF_RF_SHIFT 10
273 #define TX39_CONF_RF_MASK 0x00000c00
274 #define TX39_CONF_DOZE 0x00000200
275 #define TX39_CONF_HALT 0x00000100
276 #define TX39_CONF_LOCK 0x00000080
277 #define TX39_CONF_ICE 0x00000020
278 #define TX39_CONF_DCE 0x00000010
279 #define TX39_CONF_IRSIZE_SHIFT 2
280 #define TX39_CONF_IRSIZE_MASK 0x0000000c
281 #define TX39_CONF_DRSIZE_SHIFT 0
282 #define TX39_CONF_DRSIZE_MASK 0x00000003
285 * Status register bits available in all MIPS CPUs.
287 #define ST0_IM 0x0000ff00
288 #define STATUSB_IP0 8
289 #define STATUSF_IP0 (1 << 8)
290 #define STATUSB_IP1 9
291 #define STATUSF_IP1 (1 << 9)
292 #define STATUSB_IP2 10
293 #define STATUSF_IP2 (1 << 10)
294 #define STATUSB_IP3 11
295 #define STATUSF_IP3 (1 << 11)
296 #define STATUSB_IP4 12
297 #define STATUSF_IP4 (1 << 12)
298 #define STATUSB_IP5 13
299 #define STATUSF_IP5 (1 << 13)
300 #define STATUSB_IP6 14
301 #define STATUSF_IP6 (1 << 14)
302 #define STATUSB_IP7 15
303 #define STATUSF_IP7 (1 << 15)
304 #define STATUSB_IP8 0
305 #define STATUSF_IP8 (1 << 0)
306 #define STATUSB_IP9 1
307 #define STATUSF_IP9 (1 << 1)
308 #define STATUSB_IP10 2
309 #define STATUSF_IP10 (1 << 2)
310 #define STATUSB_IP11 3
311 #define STATUSF_IP11 (1 << 3)
312 #define STATUSB_IP12 4
313 #define STATUSF_IP12 (1 << 4)
314 #define STATUSB_IP13 5
315 #define STATUSF_IP13 (1 << 5)
316 #define STATUSB_IP14 6
317 #define STATUSF_IP14 (1 << 6)
318 #define STATUSB_IP15 7
319 #define STATUSF_IP15 (1 << 7)
320 #define ST0_CH 0x00040000
321 #define ST0_SR 0x00100000
322 #define ST0_TS 0x00200000
323 #define ST0_BEV 0x00400000
324 #define ST0_RE 0x02000000
325 #define ST0_FR 0x04000000
326 #define ST0_CU 0xf0000000
327 #define ST0_CU0 0x10000000
328 #define ST0_CU1 0x20000000
329 #define ST0_CU2 0x40000000
330 #define ST0_CU3 0x80000000
331 #define ST0_XX 0x80000000 /* MIPS IV naming */
334 * Bitfields and bit numbers in the coprocessor 0 cause register.
336 * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
338 #define CAUSEB_EXCCODE 2
339 #define CAUSEF_EXCCODE (31 << 2)
341 #define CAUSEF_IP (255 << 8)
343 #define CAUSEF_IP0 (1 << 8)
345 #define CAUSEF_IP1 (1 << 9)
346 #define CAUSEB_IP2 10
347 #define CAUSEF_IP2 (1 << 10)
348 #define CAUSEB_IP3 11
349 #define CAUSEF_IP3 (1 << 11)
350 #define CAUSEB_IP4 12
351 #define CAUSEF_IP4 (1 << 12)
352 #define CAUSEB_IP5 13
353 #define CAUSEF_IP5 (1 << 13)
354 #define CAUSEB_IP6 14
355 #define CAUSEF_IP6 (1 << 14)
356 #define CAUSEB_IP7 15
357 #define CAUSEF_IP7 (1 << 15)
359 #define CAUSEF_IV (1 << 23)
361 #define CAUSEF_CE (3 << 28)
363 #define CAUSEF_BD (1 << 31)
366 * Bits in the coprozessor 0 config register.
368 #define CONF_CM_CACHABLE_NO_WA 0
369 #define CONF_CM_CACHABLE_WA 1
370 #define CONF_CM_UNCACHED 2
371 #define CONF_CM_CACHABLE_NONCOHERENT 3
372 #define CONF_CM_CACHABLE_CE 4
373 #define CONF_CM_CACHABLE_COW 5
374 #define CONF_CM_CACHABLE_CUW 6
375 #define CONF_CM_CACHABLE_ACCELERATED 7
376 #define CONF_CM_CMASK 7
377 #define CONF_CU (1 << 3)
378 #define CONF_DB (1 << 4)
379 #define CONF_IB (1 << 5)
380 #define CONF_SE (1 << 12)
381 #define CONF_SC (1 << 17)
382 #define CONF_AC (1 << 23)
383 #define CONF_HALT (1 << 25)
386 * Bits in the TX49 coprozessor 0 config register.
388 #define TX49_CONF_DC (1 << 16)
389 #define TX49_CONF_IC (1 << 17) /* conflict with CONF_SC */
390 #define TX49_CONF_HALT (1 << 18)
391 #define TX49_CONF_CWFON (1 << 27)
394 * R10000 performance counter definitions.
396 * FIXME: The R10000 performance counter opens a nice way to implement CPU
397 * time accounting with a precission of one cycle. I don't have
398 * R10000 silicon but just a manual, so ...
402 * Events counted by counter #0
405 #define CE0_INSN_ISSUED 1
406 #define CE0_LPSC_ISSUED 2
407 #define CE0_S_ISSUED 3
408 #define CE0_SC_ISSUED 4
409 #define CE0_SC_FAILED 5
410 #define CE0_BRANCH_DECODED 6
411 #define CE0_QW_WB_SECONDARY 7
412 #define CE0_CORRECTED_ECC_ERRORS 8
413 #define CE0_ICACHE_MISSES 9
414 #define CE0_SCACHE_I_MISSES 10
415 #define CE0_SCACHE_I_WAY_MISSPREDICTED 11
416 #define CE0_EXT_INTERVENTIONS_REQ 12
417 #define CE0_EXT_INVALIDATE_REQ 13
418 #define CE0_VIRTUAL_COHERENCY_COND 14
419 #define CE0_INSN_GRADUATED 15
422 * Events counted by counter #1
425 #define CE1_INSN_GRADUATED 1
426 #define CE1_LPSC_GRADUATED 2
427 #define CE1_S_GRADUATED 3
428 #define CE1_SC_GRADUATED 4
429 #define CE1_FP_INSN_GRADUATED 5
430 #define CE1_QW_WB_PRIMARY 6
431 #define CE1_TLB_REFILL 7
432 #define CE1_BRANCH_MISSPREDICTED 8
433 #define CE1_DCACHE_MISS 9
434 #define CE1_SCACHE_D_MISSES 10
435 #define CE1_SCACHE_D_WAY_MISSPREDICTED 11
436 #define CE1_EXT_INTERVENTION_HITS 12
437 #define CE1_EXT_INVALIDATE_REQ 13
438 #define CE1_SP_HINT_TO_CEXCL_SC_BLOCKS 14
439 #define CE1_SP_HINT_TO_SHARED_SC_BLOCKS 15
442 * These flags define in which priviledge mode the counters count events
444 #define CEB_USER 8 /* Count events in user mode, EXL = ERL = 0 */
445 #define CEB_SUPERVISOR 4 /* Count events in supvervisor mode EXL = ERL = 0 */
446 #define CEB_KERNEL 2 /* Count events in kernel mode EXL = ERL = 0 */
447 #define CEB_EXL 1 /* Count events with EXL = 1, ERL = 0 */
452 * Functions to access the r10k performance counter and control registers
454 #define read_r10k_perf_cntr(counter) \
455 ({ unsigned int __res; \
456 __asm__ __volatile__( \
457 "mfpc\t%0, "STR(counter) \
461 #define write_r10k_perf_cntr(counter,val) \
462 __asm__ __volatile__( \
463 "mtpc\t%0, "STR(counter) \
466 #define read_r10k_perf_cntl(counter) \
467 ({ unsigned int __res; \
468 __asm__ __volatile__( \
469 "mfps\t%0, "STR(counter) \
473 #define write_r10k_perf_cntl(counter,val) \
474 __asm__ __volatile__( \
475 "mtps\t%0, "STR(counter) \
479 * Macros to access the system control coprocessor
481 #define read_32bit_cp0_register(source) \
483 __asm__ __volatile__( \
485 ".set\treorder\n\t" \
486 "mfc0\t%0,"STR(source)"\n\t" \
491 #define read_32bit_cp0_set1_register(source) \
493 __asm__ __volatile__( \
495 ".set\treorder\n\t" \
496 "cfc0\t%0,"STR(source)"\n\t" \
502 * For now use this only with interrupts disabled!
504 #define read_64bit_cp0_register(source) \
505 ({ unsigned long __res; \
506 __asm__ __volatile__( \
508 "dmfc0\t%0,"STR(source)"\n\t" \
513 #define write_32bit_cp0_register(register,value) \
514 __asm__ __volatile__( \
515 "mtc0\t%0,"STR(register)"\n\t" \
519 #define write_32bit_cp0_set1_register(register,value) \
520 __asm__ __volatile__( \
521 "ctc0\t%0,"STR(register)"\n\t" \
525 #define write_64bit_cp0_register(register,value) \
526 __asm__ __volatile__( \
528 "dmtc0\t%0,"STR(register)"\n\t" \
533 * This should be changed when we get a compiler that support the MIPS32 ISA.
535 #define read_mips32_cp0_config1() \
537 __asm__ __volatile__( \
538 ".set\tnoreorder\n\t" \
540 "#.set\tmips64\n\t" \
541 "#mfc0\t$1, $16, 1\n\t" \
543 ".word\t0x40018001\n\t" \
551 * Macros to access the floating point coprocessor control registers
553 #define read_32bit_cp1_register(source) \
555 __asm__ __volatile__( \
557 ".set\treorder\n\t" \
558 "cfc1\t%0,"STR(source)"\n\t" \
563 /* TLB operations. */
564 static inline void tlb_probe(void)
566 __asm__ __volatile__(
573 static inline void tlb_read(void)
575 __asm__ __volatile__(
582 static inline void tlb_write_indexed(void)
584 __asm__ __volatile__(
591 static inline void tlb_write_random(void)
593 __asm__ __volatile__(
600 /* Dealing with various CP0 mmu/cache related registers. */
603 static inline unsigned long get_pagemask(void)
607 __asm__ __volatile__(
616 static inline void set_pagemask(unsigned long val)
618 __asm__ __volatile__(
626 #if defined(CONFIG_64BIT_PHYS_ADDR) && !defined(CONFIG_CPU_MIPS32)
628 #include <asm/system.h>
631 * These versions are only needed for systems with more than 38 bits of
632 * physical address space.
634 static inline void set_entrylo0(unsigned long long val)
638 __save_and_cli(flags);
639 __asm__ __volatile__(
641 "dsll\t%L0, %L0, 32\n\t"
642 "dsrl\t%L0, %L0, 32\n\t"
643 "dsll\t%M0, %M0, 32\n\t"
644 "or\t%L0, %L0, %M0\n\t"
648 __restore_flags(flags);
651 static inline void set_entrylo1(unsigned long long val)
655 __save_and_cli(flags);
656 __asm__ __volatile__(
658 "dsll\t%L0, %L0, 32\n\t"
659 "dsrl\t%L0, %L0, 32\n\t"
660 "dsll\t%M0, %M0, 32\n\t"
661 "or\t%L0, %L0, %M0\n\t"
665 __restore_flags(flags);
668 static inline unsigned long long get_entrylo0(void)
670 unsigned long flags, val;
672 __save_and_cli(flags);
673 __asm__ __volatile__(
676 "dsll\t%L0, %M0, 32\n\t"
677 "dsrl\t%M0, %M0, 32\n\t"
678 "dsrl\t%L0, %L0, 32\n\t"
681 __restore_flags(flags);
686 static inline unsigned long long get_entrylo1(void)
688 unsigned long flags, val;
690 __save_and_cli(flags);
691 __asm__ __volatile__(
694 "dsrl\t%L0, %M0, 32\n\t"
695 "dsrl\t%M0, %M0, 32\n\t"
696 "dsll\t%L0, %L0, 32\n\t"
699 __restore_flags(flags);
706 static inline void set_entrylo0(unsigned long val)
708 __asm__ __volatile__(
716 static inline void set_entrylo1(unsigned long val)
718 __asm__ __volatile__(
726 static inline unsigned long get_entrylo0(void)
730 __asm__ __volatile__(
734 ".set pop" : "=r" (val));
739 static inline unsigned long get_entrylo1(void)
743 __asm__ __volatile__(
747 ".set pop" : "=r" (val));
754 /* CP0_ENTRYHI register */
755 static inline unsigned long get_entryhi(void)
759 __asm__ __volatile__(
769 static inline void set_entryhi(unsigned long val)
771 __asm__ __volatile__(
779 /* CP0_INDEX register */
780 static inline unsigned long get_index(void)
784 __asm__ __volatile__(
793 static inline void set_index(unsigned long val)
795 __asm__ __volatile__(
803 /* CP0_WIRED register */
804 static inline unsigned long get_wired(void)
808 __asm__ __volatile__(
817 static inline void set_wired(unsigned long val)
819 __asm__ __volatile__(
827 /* CP0_STATUS register */
828 static inline unsigned int get_status(void)
832 __asm__ __volatile__(
841 static inline void set_status(unsigned long val)
843 __asm__ __volatile__(
851 static inline unsigned long get_info(void)
864 /* CP0_TAGLO and CP0_TAGHI registers */
865 static inline unsigned long get_taglo(void)
869 __asm__ __volatile__(
878 static inline void set_taglo(unsigned long val)
880 __asm__ __volatile__(
888 static inline unsigned long get_taghi(void)
892 __asm__ __volatile__(
901 static inline void set_taghi(unsigned long val)
903 __asm__ __volatile__(
911 static inline unsigned long get_context(void)
915 __asm__ __volatile__(
925 static inline void set_context(unsigned long val)
927 __asm__ __volatile__(
935 static inline unsigned long get_errorepc(void)
939 __asm__ __volatile__(
949 static inline void set_errorepc(unsigned long val)
951 __asm__ __volatile__(
960 * Manipulate the status register.
961 * Mostly used to access the interrupt bits.
963 #define __BUILD_SET_CP0(name,register) \
964 static inline unsigned int \
965 set_cp0_##name(unsigned int set) \
969 res = read_32bit_cp0_register(register); \
971 write_32bit_cp0_register(register, res); \
976 static inline unsigned int \
977 clear_cp0_##name(unsigned int clear) \
981 res = read_32bit_cp0_register(register); \
983 write_32bit_cp0_register(register, res); \
988 static inline unsigned int \
989 change_cp0_##name(unsigned int change, unsigned int new) \
993 res = read_32bit_cp0_register(register); \
995 res |= (new & change); \
996 write_32bit_cp0_register(register, res); \
1001 __BUILD_SET_CP0(status,CP0_STATUS)
1002 __BUILD_SET_CP0(cause,CP0_CAUSE)
1003 __BUILD_SET_CP0(config,CP0_CONFIG)
1005 #define __enable_fpu() \
1007 set_cp0_status(ST0_CU1); \
1008 asm("nop;nop;nop;nop"); /* max. hazard */ \
1011 #define __disable_fpu() \
1013 clear_cp0_status(ST0_CU1); \
1014 /* We don't care about the cp0 hazard here */ \
1017 #define enable_fpu() \
1019 if (mips_cpu.options & MIPS_CPU_FPU) \
1023 #define disable_fpu() \
1025 if (mips_cpu.options & MIPS_CPU_FPU) \
1029 #endif /* !__ASSEMBLY__ */
1031 #endif /* _ASM_MIPSREGS_H */