]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
ArmPkg/BdsLib: Removed unused MachineType argument (AArch64)
[mirror_edk2.git] / ArmPkg / Library / ArmLib / AArch64 / AArch64Support.S
CommitLineData
25402f5d
HL
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r
4# Copyright (c) 2011 - 2013, ARM Limited. All rights reserved.\r
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#include <Chipset/AArch64.h>\r
17#include <AsmMacroIoLibV8.h>\r
18\r
19.text\r
20.align 3\r
21\r
22GCC_ASM_EXPORT (ArmInvalidateInstructionCache)\r
23GCC_ASM_EXPORT (ArmInvalidateDataCacheEntryByMVA)\r
24GCC_ASM_EXPORT (ArmCleanDataCacheEntryByMVA)\r
25GCC_ASM_EXPORT (ArmCleanInvalidateDataCacheEntryByMVA)\r
26GCC_ASM_EXPORT (ArmInvalidateDataCacheEntryBySetWay)\r
27GCC_ASM_EXPORT (ArmCleanDataCacheEntryBySetWay)\r
28GCC_ASM_EXPORT (ArmCleanInvalidateDataCacheEntryBySetWay)\r
29GCC_ASM_EXPORT (ArmDrainWriteBuffer)\r
30GCC_ASM_EXPORT (ArmEnableMmu)\r
31GCC_ASM_EXPORT (ArmDisableMmu)\r
32GCC_ASM_EXPORT (ArmDisableCachesAndMmu)\r
33GCC_ASM_EXPORT (ArmMmuEnabled)\r
34GCC_ASM_EXPORT (ArmEnableDataCache)\r
35GCC_ASM_EXPORT (ArmDisableDataCache)\r
36GCC_ASM_EXPORT (ArmEnableInstructionCache)\r
37GCC_ASM_EXPORT (ArmDisableInstructionCache)\r
38GCC_ASM_EXPORT (ArmDisableAlignmentCheck)\r
39GCC_ASM_EXPORT (ArmEnableAlignmentCheck)\r
40GCC_ASM_EXPORT (ArmEnableBranchPrediction)\r
41GCC_ASM_EXPORT (ArmDisableBranchPrediction)\r
42GCC_ASM_EXPORT (AArch64AllDataCachesOperation)\r
43GCC_ASM_EXPORT (AArch64PerformPoUDataCacheOperation)\r
44GCC_ASM_EXPORT (ArmDataMemoryBarrier)\r
45GCC_ASM_EXPORT (ArmDataSyncronizationBarrier)\r
46GCC_ASM_EXPORT (ArmInstructionSynchronizationBarrier)\r
47GCC_ASM_EXPORT (ArmWriteVBar)\r
48GCC_ASM_EXPORT (ArmVFPImplemented)\r
49GCC_ASM_EXPORT (ArmEnableVFP)\r
50GCC_ASM_EXPORT (ArmCallWFI)\r
51GCC_ASM_EXPORT (ArmInvalidateInstructionAndDataTlb)\r
52GCC_ASM_EXPORT (ArmReadMpidr)\r
53GCC_ASM_EXPORT (ArmReadTpidrurw)\r
54GCC_ASM_EXPORT (ArmWriteTpidrurw)\r
55GCC_ASM_EXPORT (ArmIsArchTimerImplemented)\r
56GCC_ASM_EXPORT (ArmReadIdPfr0)\r
57GCC_ASM_EXPORT (ArmReadIdPfr1)\r
58GCC_ASM_EXPORT (ArmWriteHcr)\r
59GCC_ASM_EXPORT (ArmReadCurrentEL)\r
60\r
61.set CTRL_M_BIT, (1 << 0)\r
62.set CTRL_A_BIT, (1 << 1)\r
63.set CTRL_C_BIT, (1 << 2)\r
64.set CTRL_I_BIT, (1 << 12)\r
65.set CTRL_V_BIT, (1 << 12)\r
66.set CPACR_VFP_BITS, (3 << 20)\r
67\r
68ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
69 dc ivac, x0 // Invalidate single data cache line\r
70 dsb sy\r
71 isb\r
72 ret\r
73\r
74\r
75ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
76 dc cvac, x0 // Clean single data cache line\r
77 dsb sy\r
78 isb\r
79 ret\r
80\r
81\r
82ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
83 dc civac, x0 // Clean and invalidate single data cache line\r
84 dsb sy\r
85 isb\r
86 ret\r
87\r
88\r
89ASM_PFX(ArmInvalidateDataCacheEntryBySetWay):\r
90 dc isw, x0 // Invalidate this line\r
91 dsb sy\r
92 isb\r
93 ret\r
94\r
95\r
96ASM_PFX(ArmCleanInvalidateDataCacheEntryBySetWay):\r
97 dc cisw, x0 // Clean and Invalidate this line\r
98 dsb sy\r
99 isb\r
100 ret\r
101\r
102\r
103ASM_PFX(ArmCleanDataCacheEntryBySetWay):\r
104 dc csw, x0 // Clean this line\r
105 dsb sy\r
106 isb\r
107 ret\r
108\r
109\r
110ASM_PFX(ArmInvalidateInstructionCache):\r
111 ic iallu // Invalidate entire instruction cache\r
112 dsb sy\r
113 isb\r
114 ret\r
115\r
116\r
117ASM_PFX(ArmEnableMmu):\r
118 EL1_OR_EL2_OR_EL3(x1)\r
1191: mrs x0, sctlr_el1 // Read System control register EL1\r
120 b 4f\r
1212: mrs x0, sctlr_el2 // Read System control register EL2\r
122 b 4f\r
1233: mrs x0, sctlr_el3 // Read System control register EL3\r
1244: orr x0, x0, #CTRL_M_BIT // Set MMU enable bit\r
125 EL1_OR_EL2_OR_EL3(x1)\r
70f89c0b 1261: tlbi vmalle1\r
25402f5d
HL
127 isb\r
128 msr sctlr_el1, x0 // Write back\r
129 b 4f\r
1302: tlbi alle2\r
131 isb\r
132 msr sctlr_el2, x0 // Write back\r
133 b 4f\r
1343: tlbi alle3\r
135 isb\r
136 msr sctlr_el3, x0 // Write back\r
1374: dsb sy\r
138 isb\r
139 ret\r
140\r
141\r
142ASM_PFX(ArmDisableMmu):\r
143 EL1_OR_EL2_OR_EL3(x1)\r
1441: mrs x0, sctlr_el1 // Read System Control Register EL1\r
145 b 4f\r
1462: mrs x0, sctlr_el2 // Read System Control Register EL2\r
147 b 4f\r
1483: mrs x0, sctlr_el3 // Read System Control Register EL3\r
1494: bic x0, x0, #CTRL_M_BIT // Clear MMU enable bit\r
150 EL1_OR_EL2_OR_EL3(x1)\r
1511: msr sctlr_el1, x0 // Write back\r
70f89c0b 152 tlbi vmalle1\r
25402f5d
HL
153 b 4f\r
1542: msr sctlr_el2, x0 // Write back\r
155 tlbi alle2\r
156 b 4f\r
1573: msr sctlr_el3, x0 // Write back\r
158 tlbi alle3\r
1594: dsb sy\r
160 isb\r
161 ret\r
162\r
163\r
164ASM_PFX(ArmDisableCachesAndMmu):\r
165 EL1_OR_EL2_OR_EL3(x1)\r
1661: mrs x0, sctlr_el1 // Get control register EL1\r
167 b 4f\r
1682: mrs x0, sctlr_el2 // Get control register EL2\r
169 b 4f\r
1703: mrs x0, sctlr_el3 // Get control register EL3\r
1714: bic x0, x0, #CTRL_M_BIT // Disable MMU\r
172 bic x0, x0, #CTRL_C_BIT // Disable D Cache\r
173 bic x0, x0, #CTRL_I_BIT // Disable I Cache\r
174 EL1_OR_EL2_OR_EL3(x1)\r
1751: msr sctlr_el1, x0 // Write back control register\r
176 b 4f\r
1772: msr sctlr_el2, x0 // Write back control register\r
178 b 4f\r
1793: msr sctlr_el3, x0 // Write back control register\r
1804: dsb sy\r
181 isb\r
182 ret\r
183\r
184\r
185ASM_PFX(ArmMmuEnabled):\r
186 EL1_OR_EL2_OR_EL3(x1)\r
1871: mrs x0, sctlr_el1 // Get control register EL1\r
188 b 4f\r
1892: mrs x0, sctlr_el2 // Get control register EL2\r
190 b 4f\r
1913: mrs x0, sctlr_el3 // Get control register EL3\r
1924: and x0, x0, #CTRL_M_BIT\r
193 ret\r
194\r
195\r
196ASM_PFX(ArmEnableDataCache):\r
197 EL1_OR_EL2_OR_EL3(x1)\r
1981: mrs x0, sctlr_el1 // Get control register EL1\r
199 b 4f\r
2002: mrs x0, sctlr_el2 // Get control register EL2\r
201 b 4f\r
2023: mrs x0, sctlr_el3 // Get control register EL3\r
2034: orr x0, x0, #CTRL_C_BIT // Set C bit\r
204 EL1_OR_EL2_OR_EL3(x1)\r
2051: msr sctlr_el1, x0 // Write back control register\r
206 b 4f\r
2072: msr sctlr_el2, x0 // Write back control register\r
208 b 4f\r
2093: msr sctlr_el3, x0 // Write back control register\r
2104: dsb sy\r
211 isb\r
212 ret\r
213\r
214\r
215ASM_PFX(ArmDisableDataCache):\r
216 EL1_OR_EL2_OR_EL3(x1)\r
2171: mrs x0, sctlr_el1 // Get control register EL1\r
218 b 4f\r
2192: mrs x0, sctlr_el2 // Get control register EL2\r
220 b 4f\r
2213: mrs x0, sctlr_el3 // Get control register EL3\r
2224: bic x0, x0, #CTRL_C_BIT // Clear C bit\r
223 EL1_OR_EL2_OR_EL3(x1)\r
2241: msr sctlr_el1, x0 // Write back control register\r
225 b 4f\r
2262: msr sctlr_el2, x0 // Write back control register\r
227 b 4f\r
2283: msr sctlr_el3, x0 // Write back control register\r
2294: dsb sy\r
230 isb\r
231 ret\r
232\r
233\r
234ASM_PFX(ArmEnableInstructionCache):\r
235 EL1_OR_EL2_OR_EL3(x1)\r
2361: mrs x0, sctlr_el1 // Get control register EL1\r
237 b 4f\r
2382: mrs x0, sctlr_el2 // Get control register EL2\r
239 b 4f\r
2403: mrs x0, sctlr_el3 // Get control register EL3\r
2414: orr x0, x0, #CTRL_I_BIT // Set I bit\r
242 EL1_OR_EL2_OR_EL3(x1)\r
2431: msr sctlr_el1, x0 // Write back control register\r
244 b 4f\r
2452: msr sctlr_el2, x0 // Write back control register\r
246 b 4f\r
2473: msr sctlr_el3, x0 // Write back control register\r
2484: dsb sy\r
249 isb\r
250 ret\r
251\r
252\r
253ASM_PFX(ArmDisableInstructionCache):\r
254 EL1_OR_EL2_OR_EL3(x1)\r
2551: mrs x0, sctlr_el1 // Get control register EL1\r
256 b 4f\r
2572: mrs x0, sctlr_el2 // Get control register EL2\r
258 b 4f\r
2593: mrs x0, sctlr_el3 // Get control register EL3\r
2604: bic x0, x0, #CTRL_I_BIT // Clear I bit\r
261 EL1_OR_EL2_OR_EL3(x1)\r
2621: msr sctlr_el1, x0 // Write back control register\r
263 b 4f\r
2642: msr sctlr_el2, x0 // Write back control register\r
265 b 4f\r
2663: msr sctlr_el3, x0 // Write back control register\r
2674: dsb sy\r
268 isb\r
269 ret\r
270\r
271\r
272ASM_PFX(ArmEnableAlignmentCheck):\r
273 EL1_OR_EL2(x1)\r
2741: mrs x0, sctlr_el1 // Get control register EL1\r
275 b 3f\r
2762: mrs x0, sctlr_el2 // Get control register EL2\r
2773: orr x0, x0, #CTRL_A_BIT // Set A (alignment check) bit\r
278 EL1_OR_EL2(x1)\r
2791: msr sctlr_el1, x0 // Write back control register\r
280 b 3f\r
2812: msr sctlr_el2, x0 // Write back control register\r
2823: dsb sy\r
283 isb\r
284 ret\r
285\r
286\r
287ASM_PFX(ArmDisableAlignmentCheck):\r
288 EL1_OR_EL2_OR_EL3(x1)\r
2891: mrs x0, sctlr_el1 // Get control register EL1\r
290 b 4f\r
2912: mrs x0, sctlr_el2 // Get control register EL2\r
292 b 4f\r
2933: mrs x0, sctlr_el3 // Get control register EL3\r
2944: bic x0, x0, #CTRL_A_BIT // Clear A (alignment check) bit\r
295 EL1_OR_EL2_OR_EL3(x1)\r
2961: msr sctlr_el1, x0 // Write back control register\r
297 b 4f\r
2982: msr sctlr_el2, x0 // Write back control register\r
299 b 4f\r
3003: msr sctlr_el3, x0 // Write back control register\r
3014: dsb sy\r
302 isb\r
303 ret\r
304\r
305\r
306// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now\r
307ASM_PFX(ArmEnableBranchPrediction):\r
308 ret\r
309\r
310\r
311// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now.\r
312ASM_PFX(ArmDisableBranchPrediction):\r
313 ret\r
314\r
315\r
316ASM_PFX(AArch64AllDataCachesOperation):\r
317// We can use regs 0-7 and 9-15 without having to save/restore.\r
318// Save our link register on the stack.\r
319 str x30, [sp, #-0x10]!\r
320 mov x1, x0 // Save Function call in x1\r
321 mrs x6, clidr_el1 // Read EL1 CLIDR\r
322 and x3, x6, #0x7000000 // Mask out all but Level of Coherency (LoC)\r
433a49a0
OM
323 lsr x3, x3, #23 // Left align cache level value - the level is shifted by 1 to the\r
324 // right to ease the access to CSSELR and the Set/Way operation.\r
25402f5d
HL
325 cbz x3, L_Finished // No need to clean if LoC is 0\r
326 mov x10, #0 // Start clean at cache level 0\r
327 b Loop1\r
328\r
329ASM_PFX(AArch64PerformPoUDataCacheOperation):\r
330// We can use regs 0-7 and 9-15 without having to save/restore.\r
331// Save our link register on the stack.\r
332 str x30, [sp, #-0x10]!\r
333 mov x1, x0 // Save Function call in x1\r
334 mrs x6, clidr_el1 // Read EL1 CLIDR\r
335 and x3, x6, #0x38000000 // Mask out all but Point of Unification (PoU)\r
433a49a0
OM
336 lsr x3, x3, #26 // Left align cache level value - the level is shifted by 1 to the\r
337 // right to ease the access to CSSELR and the Set/Way operation.\r
25402f5d
HL
338 cbz x3, L_Finished // No need to clean if LoC is 0\r
339 mov x10, #0 // Start clean at cache level 0\r
340\r
341Loop1:\r
342 add x2, x10, x10, lsr #1 // Work out 3x cachelevel for cache info\r
343 lsr x12, x6, x2 // bottom 3 bits are the Cache type for this level\r
344 and x12, x12, #7 // get those 3 bits alone\r
345 cmp x12, #2 // what cache at this level?\r
346 b.lt L_Skip // no cache or only instruction cache at this level\r
347 msr csselr_el1, x10 // write the Cache Size selection register with current level (CSSELR)\r
348 isb // isb to sync the change to the CacheSizeID reg\r
349 mrs x12, ccsidr_el1 // reads current Cache Size ID register (CCSIDR)\r
350 and x2, x12, #0x7 // extract the line length field\r
351 add x2, x2, #4 // add 4 for the line length offset (log2 16 bytes)\r
352 mov x4, #0x400\r
353 sub x4, x4, #1\r
354 and x4, x4, x12, lsr #3 // x4 is the max number on the way size (right aligned)\r
355 clz w5, w4 // w5 is the bit position of the way size increment\r
356 mov x7, #0x00008000\r
357 sub x7, x7, #1\r
358 and x7, x7, x12, lsr #13 // x7 is the max number of the index size (right aligned)\r
359\r
360Loop2:\r
361 mov x9, x4 // x9 working copy of the max way size (right aligned)\r
362\r
363Loop3:\r
364 lsl x11, x9, x5\r
365 orr x0, x10, x11 // factor in the way number and cache number\r
366 lsl x11, x7, x2\r
367 orr x0, x0, x11 // factor in the index number\r
368\r
369 blr x1 // Goto requested cache operation\r
370\r
371 subs x9, x9, #1 // decrement the way number\r
372 b.ge Loop3\r
373 subs x7, x7, #1 // decrement the index\r
374 b.ge Loop2\r
375L_Skip:\r
376 add x10, x10, #2 // increment the cache number\r
377 cmp x3, x10\r
378 b.gt Loop1\r
379\r
380L_Finished:\r
381 dsb sy\r
382 isb\r
383 ldr x30, [sp], #0x10\r
384 ret\r
385\r
386\r
387ASM_PFX(ArmDataMemoryBarrier):\r
388 dmb sy\r
389 ret\r
390\r
391\r
392ASM_PFX(ArmDataSyncronizationBarrier):\r
393ASM_PFX(ArmDrainWriteBuffer):\r
394 dsb sy\r
395 ret\r
396\r
397\r
398ASM_PFX(ArmInstructionSynchronizationBarrier):\r
399 isb\r
400 ret\r
401\r
402\r
403ASM_PFX(ArmWriteVBar):\r
404 EL1_OR_EL2_OR_EL3(x1)\r
4051: msr vbar_el1, x0 // Set the Address of the EL1 Vector Table in the VBAR register\r
406 b 4f\r
4072: msr vbar_el2, x0 // Set the Address of the EL2 Vector Table in the VBAR register\r
408 b 4f\r
4093: msr vbar_el3, x0 // Set the Address of the EL3 Vector Table in the VBAR register\r
4104: isb\r
411 ret\r
412\r
413ASM_PFX(ArmEnableVFP):\r
414 // Check whether floating-point is implemented in the processor.\r
415 mov x1, x30 // Save LR\r
416 bl ArmReadIdPfr0 // Read EL1 Processor Feature Register (PFR0)\r
417 mov x30, x1 // Restore LR\r
418 ands x0, x0, #AARCH64_PFR0_FP// Extract bits indicating VFP implementation\r
419 cmp x0, #0 // VFP is implemented if '0'.\r
420 b.ne 4f // Exit if VFP not implemented.\r
421 // FVP is implemented.\r
422 // Make sure VFP exceptions are not trapped (to any exception level).\r
423 mrs x0, cpacr_el1 // Read EL1 Coprocessor Access Control Register (CPACR)\r
424 orr x0, x0, #CPACR_VFP_BITS // Disable FVP traps to EL1\r
425 msr cpacr_el1, x0 // Write back EL1 Coprocessor Access Control Register (CPACR)\r
426 mov x1, #AARCH64_CPTR_TFP // TFP Bit for trapping VFP Exceptions\r
427 EL1_OR_EL2_OR_EL3(x2)\r
4281:ret // Not configurable in EL1\r
4292:mrs x0, cptr_el2 // Disable VFP traps to EL2\r
430 bic x0, x0, x1\r
431 msr cptr_el2, x0\r
432 ret\r
4333:mrs x0, cptr_el3 // Disable VFP traps to EL3\r
434 bic x0, x0, x1\r
435 msr cptr_el3, x0\r
4364:ret\r
437\r
438\r
439ASM_PFX(ArmCallWFI):\r
440 wfi\r
441 ret\r
442\r
443\r
444ASM_PFX(ArmInvalidateInstructionAndDataTlb):\r
445 EL1_OR_EL2_OR_EL3(x0)\r
70f89c0b 4461: tlbi vmalle1\r
25402f5d
HL
447 b 4f\r
4482: tlbi alle2\r
449 b 4f\r
4503: tlbi alle3\r
4514: dsb sy\r
452 isb\r
453 ret\r
454\r
455\r
456ASM_PFX(ArmReadMpidr):\r
457 mrs x0, mpidr_el1 // read EL1 MPIDR\r
458 ret\r
459\r
460\r
461// Keep old function names for C compatibilty for now. Change later?\r
462ASM_PFX(ArmReadTpidrurw):\r
463 mrs x0, tpidr_el0 // read tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
464 ret\r
465\r
466\r
467// Keep old function names for C compatibilty for now. Change later?\r
468ASM_PFX(ArmWriteTpidrurw):\r
469 msr tpidr_el0, x0 // write tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
470 ret\r
471\r
472\r
473// Arch timers are mandatory on AArch64\r
474ASM_PFX(ArmIsArchTimerImplemented):\r
475 mov x0, #1\r
476 ret\r
477\r
478\r
479ASM_PFX(ArmReadIdPfr0):\r
480 mrs x0, id_aa64pfr0_el1 // Read ID_AA64PFR0 Register\r
481 ret\r
482\r
483\r
484// Q: id_aa64pfr1_el1 not defined yet. What does this funtion want to access?\r
485// A: used to setup arch timer. Check if we have security extensions, permissions to set stuff.\r
486// See: ArmPkg/Library/ArmArchTimerLib/AArch64/ArmArchTimerLib.c\r
487// Not defined yet, but stick in here for now, should read all zeros.\r
488ASM_PFX(ArmReadIdPfr1):\r
489 mrs x0, id_aa64pfr1_el1 // Read ID_PFR1 Register\r
490 ret\r
491\r
492// VOID ArmWriteHcr(UINTN Hcr)\r
493ASM_PFX(ArmWriteHcr):\r
494 msr hcr_el2, x0 // Write the passed HCR value\r
495 ret\r
496\r
497// UINTN ArmReadCurrentEL(VOID)\r
498ASM_PFX(ArmReadCurrentEL):\r
499 mrs x0, CurrentEL\r
500 ret\r
501\r
502dead:\r
503 b dead\r
504\r
505ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r