sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
mipscopaccess.h
Go to the documentation of this file.
1
6
7
#ifndef __MIPSCOPACCESS_H__
8
#define __MIPSCOPACCESS_H__
9
10
#include <
tamtypes.h
>
11
13
#define COP0_REG_Index 0
15
#define COP0_REG_Random 1
17
#define COP0_REG_EntryLo0 2
19
#define COP0_REG_EntryLo1 3
21
#define COP0_REG_Context 4
23
#define COP0_REG_PageMask 5
25
#define COP0_REG_Wired 6
27
#define COP0_REG_BadVAddr 8
29
#define COP0_REG_Count 9
31
#define COP0_REG_EntryHi 10
33
#define COP0_REG_Compare 11
35
#define COP0_REG_Status 12
37
#define COP0_REG_Cause 13
39
#define COP0_REG_EPC 14
41
#define COP0_REG_PRId 15
43
#define COP0_REG_Config 16
45
#define COP0_REG_BadPAddr 23
47
#define COP0_REG_Debug 24
49
#define COP0_REG_Perf 25
51
#define COP0_REG_TagLo 28
53
#define COP0_REG_TagHi 29
55
#define COP0_REG_ErrorPC 30
56
57
// cop/idx need to be real preprocessor tokens (not just compile-time-
58
// constant expressions) so # can stringize them directly into the
59
// mnemonic/register text - real GCC could fold get_mips_cop_reg's old
60
// "i"-constrained function-parameter version lazily, after always_inline
61
// substituted each call site's constant arguments, regardless of the
62
// caller's own -O level. Clang instead validates "i" constraints during
63
// Sema, before any constant-folding pass runs, so a caller built at -O0
64
// (e.g. sdk-core's eedebug package) hit "invalid operand for inline asm
65
// constraint 'i'" even though cop/idx are always real compile-time
66
// constants at every call site. Macros sidestep the whole question -
67
// this is why COP0_REG_* above became #defines instead of an enum, so
68
// they're valid ## arguments here.
69
// COP0_REG_* are themselves macros, so #cop/#idx need the classic
70
// two-layer stringize indirection (MIPSCOPACCESS_STR/_XSTR) - a bare
71
// "#idx" would stringize the literal argument text ("COP0_REG_PRId"),
72
// not its expansion ("15"); routing through one more macro layer forces
73
// idx to expand first.
74
#define MIPSCOPACCESS_STR(x) #x
75
#define MIPSCOPACCESS_XSTR(x) MIPSCOPACCESS_STR(x)
76
77
#define get_mips_cop_reg(cop, idx) \
78
({ \
79
u32 __val; \
80
__asm__ __volatile__("mfc" MIPSCOPACCESS_XSTR(cop) "\t%0, $" MIPSCOPACCESS_XSTR(idx) "\n" : "=r"(__val)); \
81
__val; \
82
})
83
84
#define set_mips_cop_reg(cop, idx, val) \
85
__asm__ __volatile__("mtc" MIPSCOPACCESS_XSTR(cop) "\t%0, $" MIPSCOPACCESS_XSTR(idx) "\n" :: "r"((u32)(val)))
86
87
#endif
/* __MIPSCOPACCESS_H__ */
tamtypes.h
core
common
include
mipscopaccess.h
Generated by
1.18.0