]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
ArmPkg/BdsLib: Increase fallback tftp buffer size
[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
9401d6f4 4# Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
25402f5d
HL
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
f0247796 48GCC_ASM_EXPORT (ArmReadVBar)\r
25402f5d
HL
49GCC_ASM_EXPORT (ArmEnableVFP)\r
50GCC_ASM_EXPORT (ArmCallWFI)\r
25402f5d
HL
51GCC_ASM_EXPORT (ArmReadMpidr)\r
52GCC_ASM_EXPORT (ArmReadTpidrurw)\r
53GCC_ASM_EXPORT (ArmWriteTpidrurw)\r
54GCC_ASM_EXPORT (ArmIsArchTimerImplemented)\r
55GCC_ASM_EXPORT (ArmReadIdPfr0)\r
56GCC_ASM_EXPORT (ArmReadIdPfr1)\r
57GCC_ASM_EXPORT (ArmWriteHcr)\r
58GCC_ASM_EXPORT (ArmReadCurrentEL)\r
59\r
60.set CTRL_M_BIT, (1 << 0)\r
61.set CTRL_A_BIT, (1 << 1)\r
62.set CTRL_C_BIT, (1 << 2)\r
63.set CTRL_I_BIT, (1 << 12)\r
64.set CTRL_V_BIT, (1 << 12)\r
65.set CPACR_VFP_BITS, (3 << 20)\r
66\r
67ASM_PFX(ArmInvalidateDataCacheEntryByMVA):\r
68 dc ivac, x0 // Invalidate single data cache line\r
69 dsb sy\r
70 isb\r
71 ret\r
72\r
73\r
74ASM_PFX(ArmCleanDataCacheEntryByMVA):\r
75 dc cvac, x0 // Clean single data cache line\r
76 dsb sy\r
77 isb\r
78 ret\r
79\r
80\r
81ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):\r
82 dc civac, x0 // Clean and invalidate single data cache line\r
83 dsb sy\r
84 isb\r
85 ret\r
86\r
87\r
88ASM_PFX(ArmInvalidateDataCacheEntryBySetWay):\r
89 dc isw, x0 // Invalidate this line\r
90 dsb sy\r
91 isb\r
92 ret\r
93\r
94\r
95ASM_PFX(ArmCleanInvalidateDataCacheEntryBySetWay):\r
96 dc cisw, x0 // Clean and Invalidate this line\r
97 dsb sy\r
98 isb\r
99 ret\r
100\r
101\r
102ASM_PFX(ArmCleanDataCacheEntryBySetWay):\r
103 dc csw, x0 // Clean this line\r
104 dsb sy\r
105 isb\r
106 ret\r
107\r
108\r
109ASM_PFX(ArmInvalidateInstructionCache):\r
110 ic iallu // Invalidate entire instruction cache\r
111 dsb sy\r
112 isb\r
113 ret\r
114\r
115\r
116ASM_PFX(ArmEnableMmu):\r
117 EL1_OR_EL2_OR_EL3(x1)\r
1181: mrs x0, sctlr_el1 // Read System control register EL1\r
119 b 4f\r
1202: mrs x0, sctlr_el2 // Read System control register EL2\r
121 b 4f\r
1223: mrs x0, sctlr_el3 // Read System control register EL3\r
1234: orr x0, x0, #CTRL_M_BIT // Set MMU enable bit\r
124 EL1_OR_EL2_OR_EL3(x1)\r
70f89c0b 1251: tlbi vmalle1\r
25402f5d
HL
126 isb\r
127 msr sctlr_el1, x0 // Write back\r
128 b 4f\r
1292: tlbi alle2\r
130 isb\r
131 msr sctlr_el2, x0 // Write back\r
132 b 4f\r
1333: tlbi alle3\r
134 isb\r
135 msr sctlr_el3, x0 // Write back\r
1364: dsb sy\r
137 isb\r
138 ret\r
139\r
140\r
141ASM_PFX(ArmDisableMmu):\r
142 EL1_OR_EL2_OR_EL3(x1)\r
1431: mrs x0, sctlr_el1 // Read System Control Register EL1\r
144 b 4f\r
1452: mrs x0, sctlr_el2 // Read System Control Register EL2\r
146 b 4f\r
1473: mrs x0, sctlr_el3 // Read System Control Register EL3\r
73ca5009 1484: and x0, x0, #~CTRL_M_BIT // Clear MMU enable bit\r
25402f5d
HL
149 EL1_OR_EL2_OR_EL3(x1)\r
1501: msr sctlr_el1, x0 // Write back\r
70f89c0b 151 tlbi vmalle1\r
25402f5d
HL
152 b 4f\r
1532: msr sctlr_el2, x0 // Write back\r
154 tlbi alle2\r
155 b 4f\r
1563: msr sctlr_el3, x0 // Write back\r
157 tlbi alle3\r
1584: dsb sy\r
159 isb\r
160 ret\r
161\r
162\r
163ASM_PFX(ArmDisableCachesAndMmu):\r
164 EL1_OR_EL2_OR_EL3(x1)\r
1651: mrs x0, sctlr_el1 // Get control register EL1\r
166 b 4f\r
1672: mrs x0, sctlr_el2 // Get control register EL2\r
168 b 4f\r
1693: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009
BJ
1704: mov x1, #~(CTRL_M_BIT | CTRL_C_BIT | CTRL_I_BIT) // Disable MMU, D & I caches\r
171 and x0, x0, x1\r
25402f5d
HL
172 EL1_OR_EL2_OR_EL3(x1)\r
1731: msr sctlr_el1, x0 // Write back control register\r
174 b 4f\r
1752: msr sctlr_el2, x0 // Write back control register\r
176 b 4f\r
1773: msr sctlr_el3, x0 // Write back control register\r
1784: dsb sy\r
179 isb\r
180 ret\r
181\r
182\r
183ASM_PFX(ArmMmuEnabled):\r
184 EL1_OR_EL2_OR_EL3(x1)\r
1851: mrs x0, sctlr_el1 // Get control register EL1\r
186 b 4f\r
1872: mrs x0, sctlr_el2 // Get control register EL2\r
188 b 4f\r
1893: mrs x0, sctlr_el3 // Get control register EL3\r
1904: and x0, x0, #CTRL_M_BIT\r
191 ret\r
192\r
193\r
194ASM_PFX(ArmEnableDataCache):\r
195 EL1_OR_EL2_OR_EL3(x1)\r
1961: mrs x0, sctlr_el1 // Get control register EL1\r
197 b 4f\r
1982: mrs x0, sctlr_el2 // Get control register EL2\r
199 b 4f\r
2003: mrs x0, sctlr_el3 // Get control register EL3\r
2014: orr x0, x0, #CTRL_C_BIT // Set C bit\r
202 EL1_OR_EL2_OR_EL3(x1)\r
2031: msr sctlr_el1, x0 // Write back control register\r
204 b 4f\r
2052: msr sctlr_el2, x0 // Write back control register\r
206 b 4f\r
2073: msr sctlr_el3, x0 // Write back control register\r
2084: dsb sy\r
209 isb\r
210 ret\r
211\r
212\r
213ASM_PFX(ArmDisableDataCache):\r
214 EL1_OR_EL2_OR_EL3(x1)\r
2151: mrs x0, sctlr_el1 // Get control register EL1\r
216 b 4f\r
2172: mrs x0, sctlr_el2 // Get control register EL2\r
218 b 4f\r
2193: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2204: and x0, x0, #~CTRL_C_BIT // Clear C bit\r
25402f5d
HL
221 EL1_OR_EL2_OR_EL3(x1)\r
2221: msr sctlr_el1, x0 // Write back control register\r
223 b 4f\r
2242: msr sctlr_el2, x0 // Write back control register\r
225 b 4f\r
2263: msr sctlr_el3, x0 // Write back control register\r
2274: dsb sy\r
228 isb\r
229 ret\r
230\r
231\r
232ASM_PFX(ArmEnableInstructionCache):\r
233 EL1_OR_EL2_OR_EL3(x1)\r
2341: mrs x0, sctlr_el1 // Get control register EL1\r
235 b 4f\r
2362: mrs x0, sctlr_el2 // Get control register EL2\r
237 b 4f\r
2383: mrs x0, sctlr_el3 // Get control register EL3\r
2394: orr x0, x0, #CTRL_I_BIT // Set I bit\r
240 EL1_OR_EL2_OR_EL3(x1)\r
2411: msr sctlr_el1, x0 // Write back control register\r
242 b 4f\r
2432: msr sctlr_el2, x0 // Write back control register\r
244 b 4f\r
2453: msr sctlr_el3, x0 // Write back control register\r
2464: dsb sy\r
247 isb\r
248 ret\r
249\r
250\r
251ASM_PFX(ArmDisableInstructionCache):\r
252 EL1_OR_EL2_OR_EL3(x1)\r
2531: mrs x0, sctlr_el1 // Get control register EL1\r
254 b 4f\r
2552: mrs x0, sctlr_el2 // Get control register EL2\r
256 b 4f\r
2573: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2584: and x0, x0, #~CTRL_I_BIT // Clear I bit\r
25402f5d
HL
259 EL1_OR_EL2_OR_EL3(x1)\r
2601: msr sctlr_el1, x0 // Write back control register\r
261 b 4f\r
2622: msr sctlr_el2, x0 // Write back control register\r
263 b 4f\r
2643: msr sctlr_el3, x0 // Write back control register\r
2654: dsb sy\r
266 isb\r
267 ret\r
268\r
269\r
270ASM_PFX(ArmEnableAlignmentCheck):\r
271 EL1_OR_EL2(x1)\r
2721: mrs x0, sctlr_el1 // Get control register EL1\r
273 b 3f\r
2742: mrs x0, sctlr_el2 // Get control register EL2\r
2753: orr x0, x0, #CTRL_A_BIT // Set A (alignment check) bit\r
276 EL1_OR_EL2(x1)\r
2771: msr sctlr_el1, x0 // Write back control register\r
278 b 3f\r
2792: msr sctlr_el2, x0 // Write back control register\r
2803: dsb sy\r
281 isb\r
282 ret\r
283\r
284\r
285ASM_PFX(ArmDisableAlignmentCheck):\r
286 EL1_OR_EL2_OR_EL3(x1)\r
2871: mrs x0, sctlr_el1 // Get control register EL1\r
288 b 4f\r
2892: mrs x0, sctlr_el2 // Get control register EL2\r
290 b 4f\r
2913: mrs x0, sctlr_el3 // Get control register EL3\r
73ca5009 2924: and x0, x0, #~CTRL_A_BIT // Clear A (alignment check) bit\r
25402f5d
HL
293 EL1_OR_EL2_OR_EL3(x1)\r
2941: msr sctlr_el1, x0 // Write back control register\r
295 b 4f\r
2962: msr sctlr_el2, x0 // Write back control register\r
297 b 4f\r
2983: msr sctlr_el3, x0 // Write back control register\r
2994: dsb sy\r
300 isb\r
301 ret\r
302\r
303\r
304// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now\r
305ASM_PFX(ArmEnableBranchPrediction):\r
306 ret\r
307\r
308\r
309// Always turned on in AArch64. Else implementation specific. Leave in for C compatibility for now.\r
310ASM_PFX(ArmDisableBranchPrediction):\r
311 ret\r
312\r
313\r
314ASM_PFX(AArch64AllDataCachesOperation):\r
315// We can use regs 0-7 and 9-15 without having to save/restore.\r
fb7ea611
OM
316// Save our link register on the stack. - The stack must always be quad-word aligned\r
317 str x30, [sp, #-16]!\r
25402f5d
HL
318 mov x1, x0 // Save Function call in x1\r
319 mrs x6, clidr_el1 // Read EL1 CLIDR\r
320 and x3, x6, #0x7000000 // Mask out all but Level of Coherency (LoC)\r
433a49a0
OM
321 lsr x3, x3, #23 // Left align cache level value - the level is shifted by 1 to the\r
322 // right to ease the access to CSSELR and the Set/Way operation.\r
25402f5d
HL
323 cbz x3, L_Finished // No need to clean if LoC is 0\r
324 mov x10, #0 // Start clean at cache level 0\r
325 b Loop1\r
326\r
327ASM_PFX(AArch64PerformPoUDataCacheOperation):\r
328// We can use regs 0-7 and 9-15 without having to save/restore.\r
fb7ea611
OM
329// Save our link register on the stack. - The stack must always be quad-word aligned\r
330 str x30, [sp, #-16]!\r
25402f5d
HL
331 mov x1, x0 // Save Function call in x1\r
332 mrs x6, clidr_el1 // Read EL1 CLIDR\r
333 and x3, x6, #0x38000000 // Mask out all but Point of Unification (PoU)\r
433a49a0
OM
334 lsr x3, x3, #26 // Left align cache level value - the level is shifted by 1 to the\r
335 // right to ease the access to CSSELR and the Set/Way operation.\r
25402f5d
HL
336 cbz x3, L_Finished // No need to clean if LoC is 0\r
337 mov x10, #0 // Start clean at cache level 0\r
338\r
339Loop1:\r
340 add x2, x10, x10, lsr #1 // Work out 3x cachelevel for cache info\r
341 lsr x12, x6, x2 // bottom 3 bits are the Cache type for this level\r
342 and x12, x12, #7 // get those 3 bits alone\r
343 cmp x12, #2 // what cache at this level?\r
344 b.lt L_Skip // no cache or only instruction cache at this level\r
345 msr csselr_el1, x10 // write the Cache Size selection register with current level (CSSELR)\r
346 isb // isb to sync the change to the CacheSizeID reg\r
347 mrs x12, ccsidr_el1 // reads current Cache Size ID register (CCSIDR)\r
348 and x2, x12, #0x7 // extract the line length field\r
349 add x2, x2, #4 // add 4 for the line length offset (log2 16 bytes)\r
350 mov x4, #0x400\r
351 sub x4, x4, #1\r
352 and x4, x4, x12, lsr #3 // x4 is the max number on the way size (right aligned)\r
353 clz w5, w4 // w5 is the bit position of the way size increment\r
354 mov x7, #0x00008000\r
355 sub x7, x7, #1\r
356 and x7, x7, x12, lsr #13 // x7 is the max number of the index size (right aligned)\r
357\r
358Loop2:\r
359 mov x9, x4 // x9 working copy of the max way size (right aligned)\r
360\r
361Loop3:\r
362 lsl x11, x9, x5\r
363 orr x0, x10, x11 // factor in the way number and cache number\r
364 lsl x11, x7, x2\r
365 orr x0, x0, x11 // factor in the index number\r
366\r
367 blr x1 // Goto requested cache operation\r
368\r
369 subs x9, x9, #1 // decrement the way number\r
370 b.ge Loop3\r
371 subs x7, x7, #1 // decrement the index\r
372 b.ge Loop2\r
373L_Skip:\r
374 add x10, x10, #2 // increment the cache number\r
375 cmp x3, x10\r
376 b.gt Loop1\r
377\r
378L_Finished:\r
379 dsb sy\r
380 isb\r
381 ldr x30, [sp], #0x10\r
382 ret\r
383\r
384\r
385ASM_PFX(ArmDataMemoryBarrier):\r
386 dmb sy\r
387 ret\r
388\r
389\r
390ASM_PFX(ArmDataSyncronizationBarrier):\r
391ASM_PFX(ArmDrainWriteBuffer):\r
392 dsb sy\r
393 ret\r
394\r
395\r
396ASM_PFX(ArmInstructionSynchronizationBarrier):\r
397 isb\r
398 ret\r
399\r
400\r
401ASM_PFX(ArmWriteVBar):\r
402 EL1_OR_EL2_OR_EL3(x1)\r
4031: msr vbar_el1, x0 // Set the Address of the EL1 Vector Table in the VBAR register\r
404 b 4f\r
4052: msr vbar_el2, x0 // Set the Address of the EL2 Vector Table in the VBAR register\r
406 b 4f\r
4073: msr vbar_el3, x0 // Set the Address of the EL3 Vector Table in the VBAR register\r
4084: isb\r
409 ret\r
410\r
f0247796
OM
411ASM_PFX(ArmReadVBar):\r
412 EL1_OR_EL2_OR_EL3(x1)\r
4131: mrs x0, vbar_el1 // Set the Address of the EL1 Vector Table in the VBAR register\r
414 ret\r
4152: mrs x0, vbar_el2 // Set the Address of the EL2 Vector Table in the VBAR register\r
416 ret\r
4173: mrs x0, vbar_el3 // Set the Address of the EL3 Vector Table in the VBAR register\r
418 ret\r
419\r
420\r
25402f5d
HL
421ASM_PFX(ArmEnableVFP):\r
422 // Check whether floating-point is implemented in the processor.\r
423 mov x1, x30 // Save LR\r
424 bl ArmReadIdPfr0 // Read EL1 Processor Feature Register (PFR0)\r
425 mov x30, x1 // Restore LR\r
426 ands x0, x0, #AARCH64_PFR0_FP// Extract bits indicating VFP implementation\r
427 cmp x0, #0 // VFP is implemented if '0'.\r
428 b.ne 4f // Exit if VFP not implemented.\r
429 // FVP is implemented.\r
430 // Make sure VFP exceptions are not trapped (to any exception level).\r
431 mrs x0, cpacr_el1 // Read EL1 Coprocessor Access Control Register (CPACR)\r
432 orr x0, x0, #CPACR_VFP_BITS // Disable FVP traps to EL1\r
433 msr cpacr_el1, x0 // Write back EL1 Coprocessor Access Control Register (CPACR)\r
434 mov x1, #AARCH64_CPTR_TFP // TFP Bit for trapping VFP Exceptions\r
435 EL1_OR_EL2_OR_EL3(x2)\r
4361:ret // Not configurable in EL1\r
4372:mrs x0, cptr_el2 // Disable VFP traps to EL2\r
438 bic x0, x0, x1\r
439 msr cptr_el2, x0\r
440 ret\r
4413:mrs x0, cptr_el3 // Disable VFP traps to EL3\r
442 bic x0, x0, x1\r
443 msr cptr_el3, x0\r
4444:ret\r
445\r
446\r
447ASM_PFX(ArmCallWFI):\r
448 wfi\r
449 ret\r
450\r
451\r
25402f5d
HL
452ASM_PFX(ArmReadMpidr):\r
453 mrs x0, mpidr_el1 // read EL1 MPIDR\r
454 ret\r
455\r
456\r
457// Keep old function names for C compatibilty for now. Change later?\r
458ASM_PFX(ArmReadTpidrurw):\r
459 mrs x0, tpidr_el0 // read tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
460 ret\r
461\r
462\r
463// Keep old function names for C compatibilty for now. Change later?\r
464ASM_PFX(ArmWriteTpidrurw):\r
465 msr tpidr_el0, x0 // write tpidr_el0 (v7 TPIDRURW) -> (v8 TPIDR_EL0)\r
466 ret\r
467\r
468\r
469// Arch timers are mandatory on AArch64\r
470ASM_PFX(ArmIsArchTimerImplemented):\r
471 mov x0, #1\r
472 ret\r
473\r
474\r
475ASM_PFX(ArmReadIdPfr0):\r
476 mrs x0, id_aa64pfr0_el1 // Read ID_AA64PFR0 Register\r
477 ret\r
478\r
479\r
480// Q: id_aa64pfr1_el1 not defined yet. What does this funtion want to access?\r
481// A: used to setup arch timer. Check if we have security extensions, permissions to set stuff.\r
482// See: ArmPkg/Library/ArmArchTimerLib/AArch64/ArmArchTimerLib.c\r
483// Not defined yet, but stick in here for now, should read all zeros.\r
484ASM_PFX(ArmReadIdPfr1):\r
485 mrs x0, id_aa64pfr1_el1 // Read ID_PFR1 Register\r
486 ret\r
487\r
488// VOID ArmWriteHcr(UINTN Hcr)\r
489ASM_PFX(ArmWriteHcr):\r
490 msr hcr_el2, x0 // Write the passed HCR value\r
491 ret\r
492\r
493// UINTN ArmReadCurrentEL(VOID)\r
494ASM_PFX(ArmReadCurrentEL):\r
495 mrs x0, CurrentEL\r
496 ret\r
497\r
25402f5d 498ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r