]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Include/AsmMacroIoLib.h
2 Macros to work around lack of Apple support for LDR register, =expr
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #ifndef __MACRO_IO_LIB_H__
19 #define __MACRO_IO_LIB_H__
21 #if defined(__APPLE__)
24 // ldr reg, =expr does not work with current Apple tool chain. So do the work our selves
27 // returns _Data in R0 and _Address in R1
28 #define MmioWrite32(_Address, _Data) \
37 // returns _Data in R0 and _Address in R1, and _OrData in r2
38 #define MmioOr32(_Address, _OrData) \
49 // returns _Data in R0 and _Address in R1, and _OrData in r2
50 #define MmioAnd32(_Address, _AndData) \
61 // returns result in R0, _Address in R1, and _OrData in r2
62 #define MmioAndThenOr32(_Address, _AndData, _OrData) \
76 // returns _Data in _Reg and _Address in R1
77 #define MmioWriteFromReg32(_Address, _Reg) \
85 // returns _Data in R0 and _Address in R1
86 #define MmioRead32(_Address) \
93 // returns _Data in Reg and _Address in R1
94 #define MmioReadToReg32(_Address, _Reg) \
102 // load R0 with _Data
103 #define LoadConstant(_Data) \
109 // load _Reg with _Data
110 #define LoadConstantToReg(_Data, _Reg) \
111 ldr _Reg, [pc, #0] ; \
116 // load _Reg with _Data if eq
117 #define LoadConstantToRegIfEq(_Data, _Reg) \
118 ldreq _Reg, [pc, #0] ; \
123 // Convert the (ClusterId,CoreId) into a Core Position
124 // We assume there are 4 cores per cluster
125 // Note: 0xFFFF is the magic value for ARM_CORE_MASK | ARM_CLUSTER_MASK
126 #define GetCorePositionFromMpId(Pos, MpId, Tmp) \
129 lsr Pos, MpId, #6 ; \
130 and Tmp, MpId, #3 ; \
133 // Reserve a region at the top of the Primary Core stack
134 // for Global variables for the XIP phase
135 #define SetPrimaryStack(StackTop, GlobalSize, Tmp) \
136 and Tmp, GlobalSize, #7 ; \
137 rsbne Tmp, Tmp, #8 ; \
138 add GlobalSize, GlobalSize, Tmp ; \
139 sub sp, StackTop, GlobalSize ; \
142 mov GlobalSize, #0x0 ; \
143 _SetPrimaryStackInitGlobals: ; \
144 cmp Tmp, StackTop ; \
145 beq _SetPrimaryStackEnd ; \
146 str GlobalSize, [Tmp], #4 ; \
147 b _SetPrimaryStackInitGlobals ; \
150 // Initialize the Global Variable with '0'
151 #define InitializePrimaryStack(GlobalSize, Tmp1) \
152 and Tmp1, GlobalSize, #7 ; \
153 rsbne Tmp1, Tmp1, #8 ; \
154 add GlobalSize, GlobalSize, Tmp1 ; \
157 sub sp, GlobalSize ; \
158 mov GlobalSize, #0x0 ; \
159 _InitializePrimaryStackLoop: ; \
161 bls _InitializePrimaryStackEnd ; \
162 str GlobalSize, [Tmp1], #-4 ; \
163 b _InitializePrimaryStackLoop ; \
164 _InitializePrimaryStackEnd:
166 #elif defined (__GNUC__)
168 #define MmioWrite32(Address, Data) \
173 #define MmioOr32(Address, OrData) \
180 #define MmioAnd32(Address, AndData) \
187 #define MmioAndThenOr32(Address, AndData, OrData) \
196 #define MmioWriteFromReg32(Address, Reg) \
200 #define MmioRead32(Address) \
204 #define MmioReadToReg32(Address, Reg) \
208 #define LoadConstant(Data) \
211 #define LoadConstantToReg(Data, Reg) \
214 // Convert the (ClusterId,CoreId) into a Core Position
215 // We assume there are 4 cores per cluster
216 // Note: 0xFFFF is the magic value for ARM_CORE_MASK | ARM_CLUSTER_MASK
217 #define GetCorePositionFromMpId(Pos, MpId, Tmp) \
220 lsr Pos, MpId, #6 ; \
221 and Tmp, MpId, #3 ; \
224 #define SetPrimaryStack(StackTop, GlobalSize, Tmp) \
225 and Tmp, GlobalSize, #7 ; \
226 rsbne Tmp, Tmp, #8 ; \
227 add GlobalSize, GlobalSize, Tmp ; \
228 sub sp, StackTop, GlobalSize ; \
231 mov GlobalSize, #0x0 ; \
232 _SetPrimaryStackInitGlobals: ; \
233 cmp Tmp, StackTop ; \
234 beq _SetPrimaryStackEnd ; \
235 str GlobalSize, [Tmp], #4 ; \
236 b _SetPrimaryStackInitGlobals ; \
239 // Initialize the Global Variable with '0'
240 #define InitializePrimaryStack(GlobalSize, Tmp1) \
241 and Tmp1, GlobalSize, #7 ; \
242 rsbne Tmp1, Tmp1, #8 ; \
243 add GlobalSize, GlobalSize, Tmp1 ; \
246 sub sp, GlobalSize ; \
247 mov GlobalSize, #0x0 ; \
248 _InitializePrimaryStackLoop: ; \
250 bls _InitializePrimaryStackEnd ; \
251 str GlobalSize, [Tmp1], #-4 ; \
252 b _InitializePrimaryStackLoop ; \
253 _InitializePrimaryStackEnd:
258 // Use ARM assembly macros, form armasam
260 // Less magic in the macros if ldr reg, =expr works
263 // returns _Data in R0 and _Address in R1
267 #define MmioWrite32(Address, Data) MmioWrite32Macro Address, Data
272 // returns Data in R0 and Address in R1, and OrData in r2
273 #define MmioOr32(Address, OrData) MmioOr32Macro Address, OrData
276 // returns _Data in R0 and _Address in R1, and _OrData in r2
279 #define MmioAnd32(Address, AndData) MmioAnd32Macro Address, AndData
281 // returns result in R0, _Address in R1, and _OrData in r2
284 #define MmioAndThenOr32(Address, AndData, OrData) MmioAndThenOr32Macro Address, AndData, OrData
287 // returns _Data in _Reg and _Address in R1
290 #define MmioWriteFromReg32(Address, Reg) MmioWriteFromReg32Macro Address, Reg
292 // returns _Data in R0 and _Address in R1
295 #define MmioRead32(Address) MmioRead32Macro Address
297 // returns _Data in Reg and _Address in R1
300 #define MmioReadToReg32(Address, Reg) MmioReadToReg32Macro Address, Reg
303 // load R0 with _Data
306 #define LoadConstant(Data) LoadConstantMacro Data
308 // load _Reg with _Data
311 #define LoadConstantToReg(Data, Reg) LoadConstantToRegMacro Data, Reg
313 // conditional load testing eq flag
314 #define LoadConstantToRegIfEq(Data, Reg) LoadConstantToRegIfEqMacro Data, Reg
316 #define GetCorePositionFromMpId(Pos, MpId, Tmp) GetCorePositionFromMpId Pos, MpId, Tmp
318 #define SetPrimaryStack(StackTop,GlobalSize,Tmp) SetPrimaryStack StackTop, GlobalSize, Tmp
320 // Initialize the Global Variable with '0'
321 #define InitializePrimaryStack(GlobalSize, Tmp1) InitializePrimaryStack GlobalSize, Tmp1