1*c2c66affSColin Finck #pragma once
2*c2c66affSColin Finck 
3*c2c66affSColin Finck FORCEINLINE
4*c2c66affSColin Finck VOID
KeArmHaltProcessor(VOID)5*c2c66affSColin Finck KeArmHaltProcessor(VOID)
6*c2c66affSColin Finck {
7*c2c66affSColin Finck     //
8*c2c66affSColin Finck     // Enter Wait-For-Interrupt Mode
9*c2c66affSColin Finck     //
10*c2c66affSColin Finck #ifdef _MSC_VER
11*c2c66affSColin Finck #else
12*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c7, c0, 4" : : "r"(0) : "cc");
13*c2c66affSColin Finck #endif
14*c2c66affSColin Finck }
15*c2c66affSColin Finck 
16*c2c66affSColin Finck FORCEINLINE
17*c2c66affSColin Finck ARM_CONTROL_REGISTER
KeArmControlRegisterGet(VOID)18*c2c66affSColin Finck KeArmControlRegisterGet(VOID)
19*c2c66affSColin Finck {
20*c2c66affSColin Finck     ARM_CONTROL_REGISTER Value;
21*c2c66affSColin Finck #ifdef _MSC_VER
22*c2c66affSColin Finck     Value.AsUlong = 0;
23*c2c66affSColin Finck #else
24*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c1, c0, 0" : "=r"(Value.AsUlong) : : "cc");
25*c2c66affSColin Finck #endif
26*c2c66affSColin Finck     return Value;
27*c2c66affSColin Finck }
28*c2c66affSColin Finck 
29*c2c66affSColin Finck FORCEINLINE
30*c2c66affSColin Finck ARM_ID_CODE_REGISTER
KeArmIdCodeRegisterGet(VOID)31*c2c66affSColin Finck KeArmIdCodeRegisterGet(VOID)
32*c2c66affSColin Finck {
33*c2c66affSColin Finck     ARM_ID_CODE_REGISTER Value;
34*c2c66affSColin Finck #ifdef _MSC_VER
35*c2c66affSColin Finck     Value.AsUlong = 0;
36*c2c66affSColin Finck #else
37*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c0, c0, 0" : "=r"(Value.AsUlong) : : "cc");
38*c2c66affSColin Finck #endif
39*c2c66affSColin Finck     return Value;
40*c2c66affSColin Finck }
41*c2c66affSColin Finck 
42*c2c66affSColin Finck FORCEINLINE
43*c2c66affSColin Finck ULONG
KeArmFaultStatusRegisterGet(VOID)44*c2c66affSColin Finck KeArmFaultStatusRegisterGet(VOID)
45*c2c66affSColin Finck {
46*c2c66affSColin Finck     ULONG Value;
47*c2c66affSColin Finck #ifdef _MSC_VER
48*c2c66affSColin Finck     Value = 0;
49*c2c66affSColin Finck #else
50*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c5, c0, 0" : "=r"(Value) : : "cc");
51*c2c66affSColin Finck #endif
52*c2c66affSColin Finck     return Value;
53*c2c66affSColin Finck }
54*c2c66affSColin Finck 
55*c2c66affSColin Finck FORCEINLINE
56*c2c66affSColin Finck ULONG
KeArmInstructionFaultStatusRegisterGet(VOID)57*c2c66affSColin Finck KeArmInstructionFaultStatusRegisterGet(VOID)
58*c2c66affSColin Finck {
59*c2c66affSColin Finck     ULONG Value;
60*c2c66affSColin Finck #ifdef _MSC_VER
61*c2c66affSColin Finck     Value = 0;
62*c2c66affSColin Finck #else
63*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c5, c0, 1" : "=r"(Value) : : "cc");
64*c2c66affSColin Finck #endif
65*c2c66affSColin Finck     return Value;
66*c2c66affSColin Finck }
67*c2c66affSColin Finck 
68*c2c66affSColin Finck FORCEINLINE
69*c2c66affSColin Finck ULONG
KeArmFaultAddressRegisterGet(VOID)70*c2c66affSColin Finck KeArmFaultAddressRegisterGet(VOID)
71*c2c66affSColin Finck {
72*c2c66affSColin Finck     ULONG Value;
73*c2c66affSColin Finck #ifdef _MSC_VER
74*c2c66affSColin Finck     Value = 0;
75*c2c66affSColin Finck #else
76*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c6, c0, 0" : "=r"(Value) : : "cc");
77*c2c66affSColin Finck #endif
78*c2c66affSColin Finck     return Value;
79*c2c66affSColin Finck }
80*c2c66affSColin Finck 
81*c2c66affSColin Finck FORCEINLINE
82*c2c66affSColin Finck ARM_LOCKDOWN_REGISTER
KeArmLockdownRegisterGet(VOID)83*c2c66affSColin Finck KeArmLockdownRegisterGet(VOID)
84*c2c66affSColin Finck {
85*c2c66affSColin Finck     ARM_LOCKDOWN_REGISTER Value;
86*c2c66affSColin Finck #ifdef _MSC_VER
87*c2c66affSColin Finck     Value.AsUlong = 0;
88*c2c66affSColin Finck #else
89*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c10, c0, 0" : "=r"(Value.AsUlong) : : "cc");
90*c2c66affSColin Finck #endif
91*c2c66affSColin Finck     return Value;
92*c2c66affSColin Finck }
93*c2c66affSColin Finck 
94*c2c66affSColin Finck FORCEINLINE
95*c2c66affSColin Finck ARM_TTB_REGISTER
KeArmTranslationTableRegisterGet(VOID)96*c2c66affSColin Finck KeArmTranslationTableRegisterGet(VOID)
97*c2c66affSColin Finck {
98*c2c66affSColin Finck     ARM_TTB_REGISTER Value;
99*c2c66affSColin Finck #ifdef _MSC_VER
100*c2c66affSColin Finck     Value.AsUlong = 0;
101*c2c66affSColin Finck #else
102*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c2, c0, 0" : "=r"(Value.AsUlong) : : "cc");
103*c2c66affSColin Finck #endif
104*c2c66affSColin Finck     return Value;
105*c2c66affSColin Finck }
106*c2c66affSColin Finck 
107*c2c66affSColin Finck FORCEINLINE
108*c2c66affSColin Finck ARM_CACHE_REGISTER
KeArmCacheRegisterGet(VOID)109*c2c66affSColin Finck KeArmCacheRegisterGet(VOID)
110*c2c66affSColin Finck {
111*c2c66affSColin Finck     ARM_CACHE_REGISTER Value;
112*c2c66affSColin Finck #ifdef _MSC_VER
113*c2c66affSColin Finck     Value.AsUlong = 0;
114*c2c66affSColin Finck #else
115*c2c66affSColin Finck     __asm__ __volatile__ ("mrc p15, 0, %0, c0, c0, 1" : "=r"(Value.AsUlong) : : "cc");
116*c2c66affSColin Finck #endif
117*c2c66affSColin Finck     return Value;
118*c2c66affSColin Finck }
119*c2c66affSColin Finck 
120*c2c66affSColin Finck FORCEINLINE
121*c2c66affSColin Finck ARM_STATUS_REGISTER
KeArmStatusRegisterGet(VOID)122*c2c66affSColin Finck KeArmStatusRegisterGet(VOID)
123*c2c66affSColin Finck {
124*c2c66affSColin Finck     ARM_STATUS_REGISTER Value;
125*c2c66affSColin Finck #ifdef _MSC_VER
126*c2c66affSColin Finck     Value.AsUlong = _ReadStatusReg(0);
127*c2c66affSColin Finck #else
128*c2c66affSColin Finck     __asm__ __volatile__ ("mrs %0, cpsr" : "=r"(Value.AsUlong) : : "cc");
129*c2c66affSColin Finck #endif
130*c2c66affSColin Finck     return Value;
131*c2c66affSColin Finck }
132*c2c66affSColin Finck 
133*c2c66affSColin Finck FORCEINLINE
134*c2c66affSColin Finck VOID
KeArmControlRegisterSet(IN ARM_CONTROL_REGISTER ControlRegister)135*c2c66affSColin Finck KeArmControlRegisterSet(IN ARM_CONTROL_REGISTER ControlRegister)
136*c2c66affSColin Finck {
137*c2c66affSColin Finck #ifdef _MSC_VER
138*c2c66affSColin Finck #else
139*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r"(ControlRegister.AsUlong) : "cc");
140*c2c66affSColin Finck #endif
141*c2c66affSColin Finck }
142*c2c66affSColin Finck 
143*c2c66affSColin Finck FORCEINLINE
144*c2c66affSColin Finck VOID
KeArmTranslationTableRegisterSet(IN ARM_TTB_REGISTER Ttb)145*c2c66affSColin Finck KeArmTranslationTableRegisterSet(IN ARM_TTB_REGISTER Ttb)
146*c2c66affSColin Finck {
147*c2c66affSColin Finck #ifdef _MSC_VER
148*c2c66affSColin Finck #else
149*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c2, c0, 0" : : "r"(Ttb.AsUlong) : "cc");
150*c2c66affSColin Finck #endif
151*c2c66affSColin Finck }
152*c2c66affSColin Finck 
153*c2c66affSColin Finck FORCEINLINE
154*c2c66affSColin Finck VOID
KeArmDomainRegisterSet(IN ARM_DOMAIN_REGISTER DomainRegister)155*c2c66affSColin Finck KeArmDomainRegisterSet(IN ARM_DOMAIN_REGISTER DomainRegister)
156*c2c66affSColin Finck {
157*c2c66affSColin Finck #ifdef _MSC_VER
158*c2c66affSColin Finck #else
159*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c3, c0, 0" : : "r"(DomainRegister.AsUlong) : "cc");
160*c2c66affSColin Finck #endif
161*c2c66affSColin Finck }
162*c2c66affSColin Finck 
163*c2c66affSColin Finck FORCEINLINE
164*c2c66affSColin Finck VOID
KeArmLockdownRegisterSet(IN ARM_LOCKDOWN_REGISTER LockdownRegister)165*c2c66affSColin Finck KeArmLockdownRegisterSet(IN ARM_LOCKDOWN_REGISTER LockdownRegister)
166*c2c66affSColin Finck {
167*c2c66affSColin Finck #ifdef _MSC_VER
168*c2c66affSColin Finck #else
169*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c10, c0, 0" : : "r"(LockdownRegister.AsUlong) : "cc");
170*c2c66affSColin Finck #endif
171*c2c66affSColin Finck }
172*c2c66affSColin Finck 
173*c2c66affSColin Finck FORCEINLINE
174*c2c66affSColin Finck VOID
KeArmFlushTlb(VOID)175*c2c66affSColin Finck KeArmFlushTlb(VOID)
176*c2c66affSColin Finck {
177*c2c66affSColin Finck #ifdef _MSC_VER
178*c2c66affSColin Finck #else
179*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c8, c7, 0" : : "r"(0) : "cc");
180*c2c66affSColin Finck #endif
181*c2c66affSColin Finck }
182*c2c66affSColin Finck 
183*c2c66affSColin Finck FORCEINLINE
184*c2c66affSColin Finck VOID
KeArmInvalidateTlbEntry(IN PVOID Address)185*c2c66affSColin Finck KeArmInvalidateTlbEntry(IN PVOID Address)
186*c2c66affSColin Finck {
187*c2c66affSColin Finck #ifdef _MSC_VER
188*c2c66affSColin Finck #else
189*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c8, c7, 1" : : "r"(Address) : "cc");
190*c2c66affSColin Finck #endif
191*c2c66affSColin Finck }
192*c2c66affSColin Finck 
193*c2c66affSColin Finck FORCEINLINE
194*c2c66affSColin Finck VOID
KeArmInvalidateAllCaches(VOID)195*c2c66affSColin Finck KeArmInvalidateAllCaches(VOID)
196*c2c66affSColin Finck {
197*c2c66affSColin Finck #ifdef _MSC_VER
198*c2c66affSColin Finck #else
199*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c7, c7, 0" : : "r"(0) : "cc");
200*c2c66affSColin Finck #endif
201*c2c66affSColin Finck }
202*c2c66affSColin Finck 
203*c2c66affSColin Finck FORCEINLINE
204*c2c66affSColin Finck VOID
KeArmFlushIcache(VOID)205*c2c66affSColin Finck KeArmFlushIcache(VOID)
206*c2c66affSColin Finck {
207*c2c66affSColin Finck #ifdef _MSC_VER
208*c2c66affSColin Finck #else
209*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c7, c5, 0" : : "r"(0) : "cc");
210*c2c66affSColin Finck #endif
211*c2c66affSColin Finck }
212*c2c66affSColin Finck 
213*c2c66affSColin Finck FORCEINLINE
214*c2c66affSColin Finck VOID
KeArmWaitForInterrupt(VOID)215*c2c66affSColin Finck KeArmWaitForInterrupt(VOID)
216*c2c66affSColin Finck {
217*c2c66affSColin Finck #ifdef _MSC_VER
218*c2c66affSColin Finck #else
219*c2c66affSColin Finck     __asm__ __volatile__ ("mcr p15, 0, %0, c7, c0, 4" : : "r"(0) : "cc");
220*c2c66affSColin Finck #endif
221*c2c66affSColin Finck }
222