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(ArmInvalidateInstructionAndDataTlb)
22 GCC_ASM_EXPORT(ArmCleanInvalidateDataCache)
23 GCC_ASM_EXPORT(ArmCleanDataCache)
24 GCC_ASM_EXPORT(ArmInvalidateDataCache)
25 GCC_ASM_EXPORT(ArmInvalidateInstructionCache)
26 GCC_ASM_EXPORT(ArmInvalidateDataCacheEntryByMVA)
27 GCC_ASM_EXPORT(ArmCleanDataCacheEntryByMVA)
28 GCC_ASM_EXPORT(ArmCleanInvalidateDataCacheEntryByMVA)
29 GCC_ASM_EXPORT(ArmEnableMmu)
30 GCC_ASM_EXPORT(ArmDisableMmu)
31 GCC_ASM_EXPORT(ArmMmuEnabled)
32 GCC_ASM_EXPORT(ArmEnableDataCache)
33 GCC_ASM_EXPORT(ArmDisableDataCache)
34 GCC_ASM_EXPORT(ArmEnableInstructionCache)
35 GCC_ASM_EXPORT(ArmDisableInstructionCache)
36 GCC_ASM_EXPORT(ArmEnableBranchPrediction)
37 GCC_ASM_EXPORT(ArmDisableBranchPrediction)
38 GCC_ASM_EXPORT(ArmDataMemoryBarrier)
39 GCC_ASM_EXPORT(ArmDataSyncronizationBarrier)
40 GCC_ASM_EXPORT(ArmInstructionSynchronizationBarrier)
41 GCC_ASM_EXPORT(ArmSetLowVectors)
42 GCC_ASM_EXPORT(ArmSetHighVectors)
43 GCC_ASM_EXPORT(ArmIsMpCore)
44 GCC_ASM_EXPORT(ArmCallWFI)
45 GCC_ASM_EXPORT(ArmReadMpidr)
46 GCC_ASM_EXPORT(ArmReadMidr)
47 GCC_ASM_EXPORT(ArmUpdateTranslationTableEntry)
48 GCC_ASM_EXPORT(ArmEnableFiq)
49 GCC_ASM_EXPORT(ArmDisableFiq)
50 GCC_ASM_EXPORT(ArmEnableInterrupts)
51 GCC_ASM_EXPORT(ArmDisableInterrupts)
52 GCC_ASM_EXPORT (ArmEnableVFP)
54 Arm11PartNumberMask: .word 0xFFF0
55 Arm11PartNumber: .word 0xB020
60 .set CTRL_M_BIT, (1 << 0)
61 .set CTRL_C_BIT, (1 << 2)
62 .set CTRL_I_BIT, (1 << 12)
64 ASM_PFX(ArmDisableCachesAndMmu):
65 mrc p15, 0, r0, c1, c0, 0 @ Get control register
66 bic r0, r0, #CTRL_M_BIT @ Disable MMU
67 bic r0, r0, #CTRL_C_BIT @ Disable D Cache
68 bic r0, r0, #CTRL_I_BIT @ Disable I Cache
69 mcr p15, 0, r0, c1, c0, 0 @ Write control register
72 ASM_PFX(ArmInvalidateInstructionAndDataTlb):
73 mcr p15, 0, r0, c8, c7, 0 @ Invalidate Inst TLB and Data TLB
76 ASM_PFX(ArmInvalidateDataCacheEntryByMVA):
77 mcr p15, 0, r0, c7, c6, 1 @invalidate single data cache line
81 ASM_PFX(ArmCleanDataCacheEntryByMVA):
82 mcr p15, 0, r0, c7, c10, 1 @clean single data cache line
86 ASM_PFX(ArmCleanInvalidateDataCacheEntryByMVA):
87 mcr p15, 0, r0, c7, c14, 1 @clean and invalidate single data cache line
91 ASM_PFX(ArmCleanDataCache):
92 mcr p15, 0, r0, c7, c10, 0 @ clean entire data cache
96 ASM_PFX(ArmCleanInvalidateDataCache):
97 mcr p15, 0, r0, c7, c14, 0 @ clean and invalidate entire data cache
101 ASM_PFX(ArmInvalidateDataCache):
102 mcr p15, 0, r0, c7, c6, 0 @ invalidate entire data cache
106 ASM_PFX(ArmInvalidateInstructionCache):
107 mcr p15, 0, r0, c7, c5, 0 @invalidate entire instruction cache
109 mcr p15,0,R0,c7,c5,4 @Flush Prefetch buffer
112 ASM_PFX(ArmEnableMmu):
118 ASM_PFX(ArmMmuEnabled):
123 ASM_PFX(ArmDisableMmu):
128 mcr p15,0,R0,c7,c10,4 @Data synchronization barrier
130 mcr p15,0,R0,c7,c5,4 @Flush Prefetch buffer
133 ASM_PFX(ArmEnableDataCache):
134 LoadConstantToReg(DC_ON, R1) @ldr R1,=DC_ON
135 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
136 orr R0,R0,R1 @Set C bit
137 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
140 ASM_PFX(ArmDisableDataCache):
141 LoadConstantToReg(DC_ON, R1) @ldr R1,=DC_ON
142 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
143 bic R0,R0,R1 @Clear C bit
144 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
147 ASM_PFX(ArmEnableInstructionCache):
149 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
150 orr R0,R0,R1 @Set I bit
151 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
154 ASM_PFX(ArmDisableInstructionCache):
156 mrc p15,0,R0,c1,c0,0 @Read control register configuration data
157 bic R0,R0,R1 @Clear I bit.
158 mcr p15,0,r0,c1,c0,0 @Write control register configuration data
161 ASM_PFX(ArmEnableBranchPrediction):
162 mrc p15, 0, r0, c1, c0, 0
163 orr r0, r0, #0x00000800
164 mcr p15, 0, r0, c1, c0, 0
167 ASM_PFX(ArmDisableBranchPrediction):
168 mrc p15, 0, r0, c1, c0, 0
169 bic r0, r0, #0x00000800
170 mcr p15, 0, r0, c1, c0, 0
173 ASM_PFX(ArmDataMemoryBarrier):
175 mcr P15, #0, R0, C7, C10, #5
178 ASM_PFX(ArmDataSyncronizationBarrier):
180 mcr P15, #0, R0, C7, C10, #4
183 ASM_PFX(ArmInstructionSynchronizationBarrier):
185 mcr P15, #0, R0, C7, C5, #4
188 ASM_PFX(ArmSetLowVectors):
189 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)
190 bic 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(ArmSetHighVectors):
195 mrc p15, 0, r0, c1, c0, 0 @ Read SCTLR into R0 (Read control register configuration data)
196 orr r0, r0, #0x00002000 @ clear V bit
197 mcr p15, 0, r0, c1, c0, 0 @ Write R0 into SCTLR (Write control register configuration data)
200 ASM_PFX(ArmIsMpCore):
202 mrc p15, 0, r0, c0, c0, 0
203 # Extract Part Number to check it is an ARM11MP core (0xB02)
204 LoadConstantToReg (Arm11PartNumberMask, r1)
206 LoadConstantToReg (Arm11PartNumber, r1)
216 ASM_PFX(ArmReadMpidr):
217 mrc p15, 0, r0, c0, c0, 5 @ read MPIDR
220 ASM_PFX(ArmReadMpidr):
221 mrc p15, 0, r0, c0, c0, 0 @ Read Main ID Register
224 ASM_PFX(ArmEnableFiq):
226 bic R0,R0,#0x40 @Enable FIQ interrupts
230 ASM_PFX(ArmDisableFiq):
232 orr R1,R0,#0x40 @Disable FIQ interrupts
239 ASM_PFX(ArmEnableInterrupts):
241 bic R0,R0,#0x80 @Enable IRQ interrupts
245 ASM_PFX(ArmDisableInterrupts):
247 orr R1,R0,#0x80 @Disable IRQ interrupts
254 ASM_PFX(ArmEnableVFP):
255 # Read CPACR (Coprocessor Access Control Register)
256 mrc p15, 0, r0, c1, c0, 2
257 # Enable VPF access (Full Access to CP10, CP11) (V* instructions)
258 orr r0, r0, #0x00f00000
259 # Write back CPACR (Coprocessor Access Control Register)
260 mcr p15, 0, r0, c1, c0, 2
261 # Set EN bit in FPEXC. The Advanced SIMD and VFP extensions are enabled and operate normally.
263 #TODO: Fixme - need compilation flag
267 ASM_FUNCTION_REMOVE_IF_UNREFERENCED