libdragon
Loading...
Searching...
No Matches
cop0.h
Go to the documentation of this file.
1
12#ifndef __LIBDRAGON_COP0_H
13#define __LIBDRAGON_COP0_H
14
15#include <stdint.h>
16
18#define C0_COUNT() ({ \
19 uint32_t x; \
20 asm volatile("mfc0 %0,$9":"=r"(x)); \
21 x; \
22})
23
25#define C0_WRITE_COUNT(x) ({ \
26 asm volatile("mtc0 %0,$9"::"r"(x)); \
27})
28
29
31#define C0_COMPARE() ({ \
32 uint32_t x; \
33 asm volatile("mfc0 %0,$11":"=r"(x)); \
34 x; \
35})
36
38#define C0_WRITE_COMPARE(x) ({ \
39 asm volatile("mtc0 %0,$11"::"r"(x)); \
40})
41
42
44#define C0_STATUS() ({ \
45 uint32_t x; \
46 asm volatile("mfc0 %0,$12":"=r"(x)); \
47 x; \
48})
49
51#define C0_WRITE_STATUS(x) ({ \
52 asm volatile("mtc0 %0,$12"::"r"(x)); \
53})
54
64#define C0_CAUSE() ({ \
65 uint32_t x; \
66 asm volatile("mfc0 %0,$13" : "=r" (x) : ); \
67 x; \
68})
69
75#define C0_WRITE_CAUSE(x) ({ \
76 asm volatile("mtc0 %0,$13"::"r"(x)); \
77})
78
80/* Alternative version with different naming */
81#define C0_CR() C0_CAUSE()
82#define C0_WRITE_CR(x) C0_WRITE_CAUSE(x)
92#define C0_BADVADDR() ({ \
93 uint64_t x; \
94 asm volatile("dmfc0 %0,$8" : "=r" (x) : ); \
95 x; \
96})
97
108#define C0_EPC() ({ \
109 uint32_t x; \
110 asm volatile("mfc0 %0,$14" : "=r" (x) : ); \
111 x; \
112})
113
120#define C0_INDEX() ({ \
121 uint32_t x; \
122 asm volatile("mfc0 %0,$0":"=r"(x)); \
123 x; \
124})
125
132#define C0_WRITE_INDEX(x) asm volatile("mtc0 %0,$0; nop; nop"::"r"(x))
133
134
141#define C0_ENTRYHI() ({ \
142 uint32_t x; \
143 asm volatile("mfc0 %0,$10":"=r"(x)); \
144 x; \
145})
146
152#define C0_WRITE_ENTRYHI(x) asm volatile("mtc0 %0,$10; nop; nop"::"r"(x))
153
160#define C0_ENTRYLO0() ({ \
161 uint32_t x; \
162 asm volatile("mfc0 %0,$2":"=r"(x)); \
163 x; \
164})
165
172#define C0_WRITE_ENTRYLO0(x) asm volatile("mtc0 %0,$2; nop; nop"::"r"(x))
173
180#define C0_ENTRYLO1() ({ \
181 uint32_t x; \
182 asm volatile("mfc0 %0,$3":"=r"(x)); \
183 x; \
184})
185
192#define C0_WRITE_ENTRYLO1(x) asm volatile("mtc0 %0,$3; nop; nop"::"r"(x))
193
194
201#define C0_PAGEMASK() ({ \
202 uint32_t x; \
203 asm volatile("mfc0 %0,$5":"=r"(x)); \
204 x; \
205})
206
213#define C0_WRITE_PAGEMASK(x) asm volatile("mtc0 %0,$5; nop; nop"::"r"(x))
214
215
223#define C0_WIRED() ({ \
224 uint32_t x; \
225 asm volatile("mfc0 %0,$6":"=r"(x)); \
226 x; \
227})
228
235#define C0_WATCHLO() ({ \
236 uint32_t x; \
237 asm volatile("mfc0 %0,$18":"=r"(x)); \
238 x; \
239})
240
247#define C0_WRITE_WATCHLO(x) asm volatile("mtc0 %0,$18"::"r"(x))
248
256#define C0_WRITE_WIRED(x) asm volatile("mtc0 %0,$6; nop; nop"::"r"(x))
257
259/* Deprecated version of macros with wrong naming that include "READ" */
260#define C0_READ_CR() C0_CAUSE()
261#define C0_READ_EPC() C0_EPC()
262#define C0_READ_BADVADDR() C0_BADVADDR()
265/* COP0 Status bits definition. Please refer to MIPS R4300 manual. */
266#define C0_STATUS_IE 0x00000001
267#define C0_STATUS_EXL 0x00000002
268#define C0_STATUS_ERL 0x00000004
269
270/* COP0 Cause bits definition. Please refer to MIPS R4300 manual. */
271#define C0_CAUSE_BD 0x80000000
272#define C0_CAUSE_CE 0x30000000
273#define C0_CAUSE_EXC_CODE 0x0000007C
274
275/* COP0 interrupt bits definition. These are compatible bothwith mask and pending bits. */
276#define C0_INTERRUPT_0 0x00000100
277#define C0_INTERRUPT_1 0x00000200
278#define C0_INTERRUPT_2 0x00000400
279#define C0_INTERRUPT_3 0x00000800
280#define C0_INTERRUPT_4 0x00001000
281#define C0_INTERRUPT_5 0x00002000
282#define C0_INTERRUPT_6 0x00004000
283#define C0_INTERRUPT_7 0x00008000
284
285#define C0_INTERRUPT_RCP C0_INTERRUPT_2
286#define C0_INTERRUPT_CART C0_INTERRUPT_3
287#define C0_INTERRUPT_PRENMI C0_INTERRUPT_4
288#define C0_INTERRUPT_TIMER C0_INTERRUPT_7
289
296#define C0_GET_CAUSE_CE(cr) (((cr) & C0_CAUSE_CE) >> 28)
297
301#define C0_GET_CAUSE_EXC_CODE(sr) (((sr) & C0_CAUSE_EXC_CODE) >> 2)
302
303/* Flag bits valid for COP0 ENTRYLO0/ENTRYLO1 registers */
304#define C0_ENTRYLO_GLOBAL (1<<0)
305#define C0_ENTRYLO_VALID (1<<1)
306#define C0_ENTRYLO_DIRTY (1<<2)
307
308/* Flag bits valid for COP0 INDEX register */
309#define C0_INDEX_PROBE_FAILED (1<<31)
310
311
318#define C0_TLBWI() asm volatile("tlbwi; nop; nop; nop; nop")
319
327#define C0_TLBWR() asm volatile("tlbwr; nop; nop; nop; nop")
328
336#define C0_TLBR() asm volatile("tlbr; nop; nop; nop; nop")
337
346#define C0_TLBP() asm volatile("tlbp; nop; nop; nop; nop")
347
350#endif