]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmLib/Common/AArch64/ArmLibSupport.S
ArmPkg/Library: AArch64 MMU EL1 support
[mirror_edk2.git] / ArmPkg / Library / ArmLib / Common / AArch64 / ArmLibSupport.S
CommitLineData
93deac7e
HL
1#------------------------------------------------------------------------------\r
2#\r
3# Copyright (c) 2008 - 2009, 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 <AsmMacroIoLibV8.h>\r
17\r
18.text\r
19.align 3\r
20GCC_ASM_EXPORT (ArmMainIdCode)\r
21GCC_ASM_EXPORT (ArmCacheInfo)\r
22GCC_ASM_EXPORT (ArmGetInterruptState)\r
23GCC_ASM_EXPORT (ArmGetFiqState)\r
24GCC_ASM_EXPORT (ArmGetTTBR0BaseAddress)\r
25GCC_ASM_EXPORT (ArmSetTTBR0)\r
26GCC_ASM_EXPORT (ArmGetTCR)\r
27GCC_ASM_EXPORT (ArmSetTCR)\r
28GCC_ASM_EXPORT (ArmGetMAIR)\r
29GCC_ASM_EXPORT (ArmSetMAIR)\r
30GCC_ASM_EXPORT (ArmWriteCpacr)\r
31GCC_ASM_EXPORT (ArmWriteAuxCr)\r
32GCC_ASM_EXPORT (ArmReadAuxCr)\r
33GCC_ASM_EXPORT (ArmInvalidateTlb)\r
34GCC_ASM_EXPORT (ArmUpdateTranslationTableEntry)\r
35GCC_ASM_EXPORT (ArmWriteNsacr)\r
36GCC_ASM_EXPORT (ArmWriteScr)\r
37GCC_ASM_EXPORT (ArmWriteMVBar)\r
38GCC_ASM_EXPORT (ArmCallWFE)\r
39GCC_ASM_EXPORT (ArmCallSEV)\r
40\r
41#------------------------------------------------------------------------------\r
42\r
43.set DAIF_FIQ_BIT, (1 << 0)\r
44.set DAIF_IRQ_BIT, (1 << 1)\r
45\r
46ASM_PFX(ArmiMainIdCode):\r
47 mrs x0, midr_el1 // Read from Main ID Register (MIDR)\r
48 ret\r
49\r
50ASM_PFX(ArmCacheInfo):\r
51 mrs x0, ctr_el0 // Read from Cache Type Regiter (CTR)\r
52 ret\r
53\r
54ASM_PFX(ArmGetInterruptState):\r
55 mrs x0, daif\r
56 tst w0, #DAIF_IRQ_BIT // Check if IRQ is enabled. Enabled if 0.\r
57 mov w0, #0\r
58 mov w1, #1\r
59 csel w0, w1, w0, ne\r
60 ret\r
61\r
62ASM_PFX(ArmGetFiqState):\r
63 mrs x0, daif\r
64 tst w0, #DAIF_FIQ_BIT // Check if FIQ is enabled. Enabled if 0.\r
65 mov w0, #0\r
66 mov w1, #1\r
67 csel w0, w1, w0, ne\r
68 ret\r
69\r
70ASM_PFX(ArmWriteCpacr):\r
71 msr cpacr_el1, x0 // Coprocessor Access Control Reg (CPACR)\r
72 ret\r
73\r
74ASM_PFX(ArmWriteAuxCr):\r
75 EL1_OR_EL2(x1)\r
761:msr actlr_el1, x0 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
77 b 3f\r
782:msr actlr_el2, x0 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
793:ret\r
80\r
81ASM_PFX(ArmReadAuxCr):\r
82 EL1_OR_EL2(x1)\r
831:mrs x0, actlr_el1 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
84 b 3f\r
852:mrs x0, actlr_el2 // Aux Control Reg (ACTLR) at EL1. Also available in EL2 and EL3\r
863:ret\r
87\r
88ASM_PFX(ArmSetTTBR0):\r
89 EL1_OR_EL2_OR_EL3(x1)\r
901:msr ttbr0_el1, x0 // Translation Table Base Reg 0 (TTBR0)\r
91 b 4f\r
922:msr ttbr0_el2, x0 // Translation Table Base Reg 0 (TTBR0)\r
93 b 4f\r
943:msr ttbr0_el3, x0 // Translation Table Base Reg 0 (TTBR0)\r
954:isb\r
96 ret\r
97\r
98ASM_PFX(ArmGetTTBR0BaseAddress):\r
99 EL1_OR_EL2(x1)\r
1001:mrs x0, ttbr0_el1\r
101 b 3f\r
1022:mrs x0, ttbr0_el2\r
1033:LoadConstantToReg(0xFFFFFFFFFFFF, x1) /* Look at bottom 48 bits */\r
104 and x0, x0, x1\r
105 isb\r
106 ret\r
107\r
108ASM_PFX(ArmGetTCR):\r
109 EL1_OR_EL2_OR_EL3(x1)\r
1101:mrs x0, tcr_el1\r
111 b 4f\r
1122:mrs x0, tcr_el2\r
113 b 4f\r
1143:mrs x0, tcr_el3\r
1154:isb\r
116 ret\r
117\r
118ASM_PFX(ArmSetTCR):\r
119 EL1_OR_EL2_OR_EL3(x1)\r
1201:msr tcr_el1, x0\r
121 b 4f\r
1222:msr tcr_el2, x0\r
123 b 4f\r
1243:msr tcr_el3, x0\r
1254:isb\r
126 ret\r
127\r
128ASM_PFX(ArmGetMAIR):\r
129 EL1_OR_EL2_OR_EL3(x1)\r
1301:mrs x0, mair_el1\r
131 b 4f\r
1322:mrs x0, mair_el2\r
133 b 4f\r
1343:mrs x0, mair_el3\r
1354:isb\r
136 ret\r
137\r
138ASM_PFX(ArmSetMAIR):\r
139 EL1_OR_EL2_OR_EL3(x1)\r
1401:msr mair_el1, x0\r
141 b 4f\r
1422:msr mair_el2, x0\r
143 b 4f\r
1443:msr mair_el3, x0\r
1454:isb\r
146 ret\r
147\r
148\r
149//\r
150//VOID\r
151//ArmUpdateTranslationTableEntry (\r
152// IN VOID *TranslationTableEntry // X0\r
153// IN VOID *MVA // X1\r
154// );\r
155ASM_PFX(ArmUpdateTranslationTableEntry):\r
156 dc civac, x0 // Clean and invalidate data line\r
157 dsb sy\r
158 EL1_OR_EL2_OR_EL3(x0)\r
1591: tlbi vaae1, x1 // TLB Invalidate VA , EL1\r
160 b 4f\r
1612: tlbi vae2, x1 // TLB Invalidate VA , EL2\r
162 b 4f\r
1633: tlbi vae3, x1 // TLB Invalidate VA , EL3\r
1644: dsb sy\r
165 isb\r
166 ret\r
167\r
168ASM_PFX(ArmInvalidateTlb):\r
169 EL1_OR_EL2_OR_EL3(x0)\r
1701: tlbi alle1\r
171 b 4f\r
1722: tlbi alle2\r
173 b 4f\r
1743: tlbi alle3\r
1754: dsb sy\r
176 isb\r
177 ret\r
178\r
179ASM_PFX(ArmWriteNsacr):\r
180 msr cptr_el3, x0 // EL3 Coprocessor Trap Reg (CPTR)\r
181 ret // Non-Secure Access Control Reg (NSACR) in ARMv7\r
182\r
183ASM_PFX(ArmWriteScr):\r
184 msr scr_el3, x0 // Secure configuration register EL3\r
185 ret\r
186\r
187ASM_PFX(ArmWriteMVBar):\r
188 msr vbar_el3, x0 // Excpetion Vector Base address for Monitor on EL3\r
189 ret\r
190\r
191ASM_PFX(ArmCallWFE):\r
192 wfe\r
193 ret\r
194\r
195ASM_PFX(ArmCallSEV):\r
196 sev\r
197 ret\r
198\r
199dead:\r
200 b dead\r
201\r
202ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r