1 #------------------------------------------------------------------------------
3 # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 # Copyright (c) 2011, ARM Limited. All rights reserved.
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #------------------------------------------------------------------------------
16 #include <AsmMacroIoLib.h>
20 GCC_ASM_EXPORT(ArmDisableCachesAndMmu)
21 GCC_ASM_EXPORT(ArmCleanInvalidateDataCache)
22 GCC_ASM_EXPORT(ArmCleanDataCache)
23 GCC_ASM_EXPORT(ArmInvalidateDataCache)
24 GCC_ASM_EXPORT(ArmInvalidateInstructionCache)
25 GCC_ASM_EXPORT(ArmInvalidateDataCacheEntryByMVA)
26 GCC_ASM_EXPORT(ArmCleanDataCacheEntryByMVA)
27 GCC_ASM_EXPORT(ArmCleanInvalidateDataCacheEntryByMVA)
28 GCC_ASM_EXPORT(ArmEnableMmu)
29 GCC_ASM_EXPORT(ArmDisableMmu)
30 GCC_ASM_EXPORT(ArmMmuEnabled)
31 GCC_ASM_EXPORT(ArmEnableDataCache)
32 GCC_ASM_EXPORT(ArmDisableDataCache)
33 GCC_ASM_EXPORT(ArmEnableInstructionCache)
34 GCC_ASM_EXPORT(ArmDisableInstructionCache)
35 GCC_ASM_EXPORT(ArmEnableBranchPrediction)
36 GCC_ASM_EXPORT(ArmDisableBranchPrediction)
37 GCC_ASM_EXPORT(ArmDataMemoryBarrier)
38 GCC_ASM_EXPORT(ArmDataSyncronizationBarrier)
39 GCC_ASM_EXPORT(ArmInstructionSynchronizationBarrier)
40 GCC_ASM_EXPORT(ArmSetLowVectors)
41 GCC_ASM_EXPORT(ArmSetHighVectors)
42 GCC_ASM_EXPORT(ArmIsMpCore)
43 GCC_ASM_EXPORT(ArmCallWFI)
44 GCC_ASM_EXPORT(ArmReadMpidr)
45 GCC_ASM_EXPORT(ArmUpdateTranslationTableEntry)
46 GCC_ASM_EXPORT(ArmEnableFiq)
47 GCC_ASM_EXPORT(ArmDisableFiq)
48 GCC_ASM_EXPORT(ArmEnableInterrupts)
49 GCC_ASM_EXPORT(ArmDisableInterrupts)
50 GCC_ASM_EXPORT (ArmEnableVFP)
52 Arm11PartNumberMask: .word 0xFFF0
53 Arm11PartNumber: .word 0xB020
58 .set CTRL_M_BIT, (1 << 0)
59 .set CTRL_C_BIT, (1 << 2)
60 .set CTRL_I_BIT, (1 << 12)
62 ASM_PFX(ArmDisableCachesAndMmu):
63 mrc p15, 0, r0, c1, c0, 0 @ Get control register
64 bic r0, r0, #CTRL_M_BIT @ Disable MMU
65 bic r0, r0, #CTRL_C_BIT @ Disable D Cache
66 bic r0, r0, #CTRL_I_BIT @ Disable I Cache
67 mcr p15, 0, r0, c1, c0, 0 @ Write control register
70 ASM_PFX(ArmInvalidateDataCacheEntryByMVA):
71 mcr p15, 0, r0, c7, c6, 1 @invalidate single data cache line
75 ASM_PFX(ArmCleanDataCacheEntryByMVA):
76 mcr p15, 0, r0, c7, c10, 1 @clean single data cache line
80 ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):
81 mcr p15, 0, r0, c7, c14, 1 @clean and invalidate single data cache line
85 ASM_PFX(ArmCleanDataCache):
86 mcr p15, 0, r0, c7, c10, 0 @ clean entire data cache
90 ASM_PFX(ArmCleanInvalidateDataCache):
91 mcr p15, 0, r0, c7, c14, 0 @ clean and invalidate entire data cache
95 ASM_PFX(ArmInvalidateDataCache):
96 mcr p15, 0, r0, c7, c6, 0 @ invalidate entire data cache
100 ASM_PFX(ArmInvalidateInstructionCache):
101 mcr p15, 0, r0, c7, c5, 0 @invalidate entire instruction cache
103 mcr p15,0,R0,c7,c5,4 @Flush Prefetch buffer
106 ASM_PFX(ArmEnableMmu):
112 ASM_PFX(ArmMmuEnabled):
117 ASM_PFX(ArmDisableMmu):
122 mcr p15,0,R0,c7,c10,4 @Data synchronization barrier
124 mcr p15,0,R0,c7,c5,4 @Flush Prefetch buffer
127 ASM_PFX(ArmEnableDataCache):
128 LoadConstantToReg(DC_ON, R1) @ldr R1,=DC_ON
129 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
130 orr R0,R0,R1 @Set C bit
131 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
134 ASM_PFX(ArmDisableDataCache):
135 LoadConstantToReg(DC_ON, R1) @ldr R1,=DC_ON
136 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
137 bic R0,R0,R1 @Clear C bit
138 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
141 ASM_PFX(ArmEnableInstructionCache):
143 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
144 orr R0,R0,R1 @Set I bit
145 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
148 ASM_PFX(ArmDisableInstructionCache):
150 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
151 bic R0,R0,R1 @Clear I bit.
152 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
155 ASM_PFX(ArmEnableBranchPrediction):
156 mrc p15, 0, r0, c1, c0, 0
157 orr r0, r0, #0x00000800
158 mcr p15, 0, r0, c1, c0, 0
161 ASM_PFX(ArmDisableBranchPrediction):
162 mrc p15, 0, r0, c1, c0, 0
163 bic r0, r0, #0x00000800
164 mcr p15, 0, r0, c1, c0, 0
167 ASM_PFX(ArmDataMemoryBarrier):
169 mcr P15, #0, R0, C7, C10, #5
172 ASM_PFX(ArmDataSyncronizationBarrier):
174 mcr P15, #0, R0, C7, C10, #4
177 ASM_PFX(ArmInstructionSynchronizationBarrier):
179 mcr P15, #0, R0, C7, C5, #4
182 ASM_PFX(ArmSetLowVectors):
183 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)
184 bic r0, r0, #0x00002000 @ clear V bit
185 mcr p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)
188 ASM_PFX(ArmSetHighVectors):
189 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)
190 orr r0, r0, #0x00002000 @ clear V bit
191 mcr p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)
194 ASM_PFX(ArmIsMpCore):
196 mrc p15, 0, r0, c0, c0, 0
197 # Extract Part Number to check it is an ARM11MP core (0xB02)
198 LoadConstantToReg (Arm11PartNumberMask, r1)
200 LoadConstantToReg (Arm11PartNumber, r1)
210 ASM_PFX(ArmReadMpidr):
211 mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
214 ASM_PFX(ArmEnableFiq):
216 bic R0,R0,#0x40 @Enable FIQ interrupts
220 ASM_PFX(ArmDisableFiq):
222 orr R1,R0,#0x40 @Disable FIQ interrupts
229 ASM_PFX(ArmEnableInterrupts):
231 bic R0,R0,#0x80 @Enable IRQ interrupts
235 ASM_PFX(ArmDisableInterrupts):
237 orr R1,R0,#0x80 @Disable IRQ interrupts
244 ASM_PFX(ArmEnableVFP):
245 # Read CPACR (Coprocessor Access Control Register)
246 mrc p15, 0, r0, c1, c0, 2
247 # Enable VPF access (Full Access to CP10, CP11) (V* instructions)
248 orr r0, r0, #0x00f00000
249 # Write back CPACR (Coprocessor Access Control Register)
250 mcr p15, 0, r0, c1, c0, 2
251 # Set EN bit in FPEXC. The Advanced SIMD and VFP extensions are enabled and operate normally.
253 #TODO: Fixme - need compilation flag
257 ASM_FUNCTION_REMOVE_IF_UNREFERENCED