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