]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/ArmV7/ArmV7Support.S
ArmPkg/ArmHvcLib: switch to ASM_FUNC() asm macro
[mirror_edk2.git] / ArmPkg / Library / ArmLib / ArmV7 / ArmV7Support.S
CommitLineData
3402aac7 1#------------------------------------------------------------------------------\r
bd6b9799 2#\r
3# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
9401d6f4 4# Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
bd6b9799 5#\r
6# This program and the accompanying materials\r
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14#------------------------------------------------------------------------------\r
15\r
16.text\r
17.align 2\r
18\r
19GCC_ASM_EXPORT (ArmInvalidateInstructionCache)\r
20GCC_ASM_EXPORT (ArmInvalidateDataCacheEntryByMVA)\r
cf580da1 21GCC_ASM_EXPORT (ArmInvalidateInstructionCacheEntryToPoUByMVA)\r
bd6b9799 22GCC_ASM_EXPORT (ArmCleanDataCacheEntryByMVA)\r
b7de7e3c 23GCC_ASM_EXPORT (ArmCleanDataCacheEntryToPoUByMVA)\r
bd6b9799 24GCC_ASM_EXPORT (ArmCleanInvalidateDataCacheEntryByMVA)\r
25GCC_ASM_EXPORT (ArmInvalidateDataCacheEntryBySetWay)\r
26GCC_ASM_EXPORT (ArmCleanDataCacheEntryBySetWay)\r
27GCC_ASM_EXPORT (ArmCleanInvalidateDataCacheEntryBySetWay)\r
bd6b9799 28GCC_ASM_EXPORT (ArmEnableMmu)\r
29GCC_ASM_EXPORT (ArmDisableMmu)\r
30GCC_ASM_EXPORT (ArmDisableCachesAndMmu)\r
31GCC_ASM_EXPORT (ArmMmuEnabled)\r
32GCC_ASM_EXPORT (ArmEnableDataCache)\r
33GCC_ASM_EXPORT (ArmDisableDataCache)\r
34GCC_ASM_EXPORT (ArmEnableInstructionCache)\r
35GCC_ASM_EXPORT (ArmDisableInstructionCache)\r
36GCC_ASM_EXPORT (ArmEnableSWPInstruction)\r
37GCC_ASM_EXPORT (ArmEnableBranchPrediction)\r
38GCC_ASM_EXPORT (ArmDisableBranchPrediction)\r
39GCC_ASM_EXPORT (ArmSetLowVectors)\r
40GCC_ASM_EXPORT (ArmSetHighVectors)\r
41GCC_ASM_EXPORT (ArmV7AllDataCachesOperation)\r
42GCC_ASM_EXPORT (ArmDataMemoryBarrier)\r
cf93a378 43GCC_ASM_EXPORT (ArmDataSynchronizationBarrier)\r
bd6b9799 44GCC_ASM_EXPORT (ArmInstructionSynchronizationBarrier)\r
836c3500 45GCC_ASM_EXPORT (ArmReadVBar)\r
bd6b9799 46GCC_ASM_EXPORT (ArmWriteVBar)\r
47GCC_ASM_EXPORT (ArmEnableVFP)\r
48GCC_ASM_EXPORT (ArmCallWFI)\r
49GCC_ASM_EXPORT (ArmReadCbar)\r
bd6b9799 50GCC_ASM_EXPORT (ArmReadMpidr)\r
51GCC_ASM_EXPORT (ArmReadTpidrurw)\r
52GCC_ASM_EXPORT (ArmWriteTpidrurw)\r
53GCC_ASM_EXPORT (ArmIsArchTimerImplemented)\r
54GCC_ASM_EXPORT (ArmReadIdPfr1)\r
55\r
56.set DC_ON, (0x1<<2)\r
57.set IC_ON, (0x1<<12)\r
58.set CTRL_M_BIT, (1 << 0)\r
59.set CTRL_C_BIT, (1 << 2)\r
60.set CTRL_B_BIT, (1 << 7)\r
61.set CTRL_I_BIT, (1 << 12)\r
62\r
63\r
64ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
3402aac7 65 mcr p15, 0, r0, c7, c6, 1 @invalidate single data cache line\r
bd6b9799 66 bx lr\r
67\r
68ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
3402aac7 69 mcr p15, 0, r0, c7, c10, 1 @clean single data cache line\r
bd6b9799 70 bx lr\r
71\r
72\r
b7de7e3c
EC
73ASM_PFX(ArmCleanDataCacheEntryToPoUByMVA):\r
74 mcr p15, 0, r0, c7, c11, 1 @clean single data cache line to PoU\r
75 bx lr\r
76\r
cf580da1
AB
77ASM_PFX(ArmInvalidateInstructionCacheEntryToPoUByMVA):\r
78 mcr p15, 0, r0, c7, c5, 1 @Invalidate single instruction cache line to PoU\r
79 mcr p15, 0, r0, c7, c5, 7 @Invalidate branch predictor\r
80 bx lr\r
b7de7e3c 81\r
bd6b9799 82ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
83 mcr p15, 0, r0, c7, c14, 1 @clean and invalidate single data cache line\r
bd6b9799 84 bx lr\r
85\r
86\r
87ASM_PFX(ArmInvalidateDataCacheEntryBySetWay):\r
3402aac7 88 mcr p15, 0, r0, c7, c6, 2 @ Invalidate this line\r
bd6b9799 89 bx lr\r
90\r
91\r
92ASM_PFX(ArmCleanInvalidateDataCacheEntryBySetWay):\r
3402aac7 93 mcr p15, 0, r0, c7, c14, 2 @ Clean and Invalidate this line\r
bd6b9799 94 bx lr\r
95\r
96\r
97ASM_PFX(ArmCleanDataCacheEntryBySetWay):\r
3402aac7 98 mcr p15, 0, r0, c7, c10, 2 @ Clean this line\r
bd6b9799 99 bx lr\r
100\r
101ASM_PFX(ArmInvalidateInstructionCache):\r
102 mcr p15,0,R0,c7,c5,0 @Invalidate entire instruction cache\r
103 dsb\r
104 isb\r
105 bx LR\r
106\r
107ASM_PFX(ArmEnableMmu):\r
108 mrc p15,0,R0,c1,c0,0\r
109 orr R0,R0,#1\r
110 mcr p15,0,R0,c1,c0,0\r
111 dsb\r
112 isb\r
113 bx LR\r
114\r
115\r
116ASM_PFX(ArmDisableMmu):\r
117 mrc p15,0,R0,c1,c0,0\r
118 bic R0,R0,#1\r
119 mcr p15,0,R0,c1,c0,0 @Disable MMU\r
120\r
121 mcr p15,0,R0,c8,c7,0 @Invalidate TLB\r
122 mcr p15,0,R0,c7,c5,6 @Invalidate Branch predictor array\r
123 dsb\r
124 isb\r
125 bx LR\r
126\r
127ASM_PFX(ArmDisableCachesAndMmu):\r
128 mrc p15, 0, r0, c1, c0, 0 @ Get control register\r
129 bic r0, r0, #CTRL_M_BIT @ Disable MMU\r
130 bic r0, r0, #CTRL_C_BIT @ Disable D Cache\r
131 bic r0, r0, #CTRL_I_BIT @ Disable I Cache\r
132 mcr p15, 0, r0, c1, c0, 0 @ Write control register\r
133 dsb\r
134 isb\r
135 bx LR\r
136\r
137ASM_PFX(ArmMmuEnabled):\r
138 mrc p15,0,R0,c1,c0,0\r
139 and R0,R0,#1\r
3402aac7 140 bx LR\r
bd6b9799 141\r
142ASM_PFX(ArmEnableDataCache):\r
143 ldr R1,=DC_ON\r
144 mrc p15,0,R0,c1,c0,0 @Read control register configuration data\r
145 orr R0,R0,R1 @Set C bit\r
146 mcr p15,0,r0,c1,c0,0 @Write control register configuration data\r
147 dsb\r
148 isb\r
149 bx LR\r
3402aac7 150\r
bd6b9799 151ASM_PFX(ArmDisableDataCache):\r
152 ldr R1,=DC_ON\r
153 mrc p15,0,R0,c1,c0,0 @Read control register configuration data\r
154 bic R0,R0,R1 @Clear C bit\r
155 mcr p15,0,r0,c1,c0,0 @Write control register configuration data\r
156 dsb\r
157 isb\r
158 bx LR\r
159\r
160ASM_PFX(ArmEnableInstructionCache):\r
161 ldr R1,=IC_ON\r
162 mrc p15,0,R0,c1,c0,0 @Read control register configuration data\r
163 orr R0,R0,R1 @Set I bit\r
164 mcr p15,0,r0,c1,c0,0 @Write control register configuration data\r
165 dsb\r
166 isb\r
167 bx LR\r
3402aac7 168\r
bd6b9799 169ASM_PFX(ArmDisableInstructionCache):\r
170 ldr R1,=IC_ON\r
171 mrc p15,0,R0,c1,c0,0 @Read control register configuration data\r
172 bic R0,R0,R1 @Clear I bit.\r
173 mcr p15,0,r0,c1,c0,0 @Write control register configuration data\r
174 dsb\r
175 isb\r
176 bx LR\r
177\r
178ASM_PFX(ArmEnableSWPInstruction):\r
179 mrc p15, 0, r0, c1, c0, 0\r
180 orr r0, r0, #0x00000400\r
181 mcr p15, 0, r0, c1, c0, 0\r
182 isb\r
183 bx LR\r
184\r
185ASM_PFX(ArmEnableBranchPrediction):\r
186 mrc p15, 0, r0, c1, c0, 0\r
187 orr r0, r0, #0x00000800\r
188 mcr p15, 0, r0, c1, c0, 0\r
189 dsb\r
190 isb\r
191 bx LR\r
192\r
193ASM_PFX(ArmDisableBranchPrediction):\r
194 mrc p15, 0, r0, c1, c0, 0\r
195 bic r0, r0, #0x00000800\r
196 mcr p15, 0, r0, c1, c0, 0\r
197 dsb\r
198 isb\r
199 bx LR\r
200\r
201ASM_PFX(ArmSetLowVectors):\r
202 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)\r
203 bic r0, r0, #0x00002000 @ clear V bit\r
204 mcr p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)\r
205 isb\r
206 bx LR\r
207\r
208ASM_PFX(ArmSetHighVectors):\r
209 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)\r
c6ba1c12 210 orr r0, r0, #0x00002000 @ Set V bit\r
bd6b9799 211 mcr p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)\r
212 isb\r
213 bx LR\r
214\r
215ASM_PFX(ArmV7AllDataCachesOperation):\r
216 stmfd SP!,{r4-r12, LR}\r
217 mov R1, R0 @ Save Function call in R1\r
218 mrc p15, 1, R6, c0, c0, 1 @ Read CLIDR\r
219 ands R3, R6, #0x7000000 @ Mask out all but Level of Coherency (LoC)\r
220 mov R3, R3, LSR #23 @ Cache level value (naturally aligned)\r
221 beq L_Finished\r
222 mov R10, #0\r
223\r
3402aac7 224Loop1:\r
bd6b9799 225 add R2, R10, R10, LSR #1 @ Work out 3xcachelevel\r
226 mov R12, R6, LSR R2 @ bottom 3 bits are the Cache type for this level\r
227 and R12, R12, #7 @ get those 3 bits alone\r
228 cmp R12, #2\r
229 blt L_Skip @ no cache or only instruction cache at this level\r
230 mcr p15, 2, R10, c0, c0, 0 @ write the Cache Size selection register (CSSELR) // OR in 1 for Instruction\r
3402aac7 231 isb @ isb to sync the change to the CacheSizeID reg\r
bd6b9799 232 mrc p15, 1, R12, c0, c0, 0 @ reads current Cache Size ID register (CCSIDR)\r
233 and R2, R12, #0x7 @ extract the line length field\r
234 add R2, R2, #4 @ add 4 for the line length offset (log2 16 bytes)\r
235@ ldr R4, =0x3FF\r
236 mov R4, #0x400\r
237 sub R4, R4, #1\r
238 ands R4, R4, R12, LSR #3 @ R4 is the max number on the way size (right aligned)\r
239 clz R5, R4 @ R5 is the bit position of the way size increment\r
240@ ldr R7, =0x00007FFF\r
241 mov R7, #0x00008000\r
242 sub R7, R7, #1\r
243 ands R7, R7, R12, LSR #13 @ R7 is the max number of the index size (right aligned)\r
244\r
3402aac7 245Loop2:\r
bd6b9799 246 mov R9, R4 @ R9 working copy of the max way size (right aligned)\r
247\r
3402aac7 248Loop3:\r
bd6b9799 249 orr R0, R10, R9, LSL R5 @ factor in the way number and cache number into R11\r
250 orr R0, R0, R7, LSL R2 @ factor in the index number\r
251\r
252 blx R1\r
253\r
254 subs R9, R9, #1 @ decrement the way number\r
255 bge Loop3\r
256 subs R7, R7, #1 @ decrement the index\r
257 bge Loop2\r
3402aac7 258L_Skip:\r
bd6b9799 259 add R10, R10, #2 @ increment the cache number\r
260 cmp R3, R10\r
261 bgt Loop1\r
3402aac7 262\r
bd6b9799 263L_Finished:\r
264 dsb\r
265 ldmfd SP!, {r4-r12, lr}\r
266 bx LR\r
267\r
268ASM_PFX(ArmDataMemoryBarrier):\r
269 dmb\r
270 bx LR\r
3402aac7 271\r
cf93a378 272ASM_PFX(ArmDataSynchronizationBarrier):\r
bd6b9799 273 dsb\r
274 bx LR\r
3402aac7 275\r
bd6b9799 276ASM_PFX(ArmInstructionSynchronizationBarrier):\r
277 isb\r
278 bx LR\r
279\r
836c3500 280ASM_PFX(ArmReadVBar):\r
281 # Set the Address of the Vector Table in the VBAR register\r
282 mrc p15, 0, r0, c12, c0, 0\r
283 bx lr\r
284\r
bd6b9799 285ASM_PFX(ArmWriteVBar):\r
286 # Set the Address of the Vector Table in the VBAR register\r
3402aac7 287 mcr p15, 0, r0, c12, c0, 0\r
bd6b9799 288 # Ensure the SCTLR.V bit is clear\r
289 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)\r
290 bic r0, r0, #0x00002000 @ clear V bit\r
291 mcr p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)\r
292 isb\r
293 bx lr\r
294\r
295ASM_PFX(ArmEnableVFP):\r
296 # Read CPACR (Coprocessor Access Control Register)\r
297 mrc p15, 0, r0, c1, c0, 2\r
298 # Enable VPF access (Full Access to CP10, CP11) (V* instructions)\r
299 orr r0, r0, #0x00f00000\r
300 # Write back CPACR (Coprocessor Access Control Register)\r
301 mcr p15, 0, r0, c1, c0, 2\r
18029bb9 302 isb\r
bd6b9799 303 # Set EN bit in FPEXC. The Advanced SIMD and VFP extensions are enabled and operate normally.\r
304 mov r0, #0x40000000\r
6d2449c1 305#ifndef __clang__\r
bd6b9799 306 mcr p10,#0x7,r0,c8,c0,#0\r
6d2449c1
AB
307#else\r
308 vmsr fpexc, r0\r
309#endif\r
bd6b9799 310 bx lr\r
311\r
312ASM_PFX(ArmCallWFI):\r
313 wfi\r
314 bx lr\r
315\r
316#Note: Return 0 in Uniprocessor implementation\r
317ASM_PFX(ArmReadCbar):\r
318 mrc p15, 4, r0, c15, c0, 0 @ Read Configuration Base Address Register\r
319 bx lr\r
320\r
bd6b9799 321ASM_PFX(ArmReadMpidr):\r
322 mrc p15, 0, r0, c0, c0, 5 @ read MPIDR\r
323 bx lr\r
3402aac7 324\r
bd6b9799 325ASM_PFX(ArmReadTpidrurw):\r
326 mrc p15, 0, r0, c13, c0, 2 @ read TPIDRURW\r
327 bx lr\r
328\r
329ASM_PFX(ArmWriteTpidrurw):\r
330 mcr p15, 0, r0, c13, c0, 2 @ write TPIDRURW\r
331 bx lr\r
332\r
333ASM_PFX(ArmIsArchTimerImplemented):\r
334 mrc p15, 0, r0, c0, c1, 1 @ Read ID_PFR1\r
335 and r0, r0, #0x000F0000\r
336 bx lr\r
337\r
338ASM_PFX(ArmReadIdPfr1):\r
339 mrc p15, 0, r0, c0, c1, 1 @ Read ID_PFR1 Register\r
340 bx lr\r
341\r
342ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r