Sync up ArmPkg with patch from mailing list. Changed name of BdsLib.h to BdsUnixLib...
[mirror_edk2.git] / ArmPkg / Include / AsmMacroIoLib.h
CommitLineData
2ef2b01e
A
1/** @file\r
2 Macros to work around lack of Apple support for LDR register, =expr\r
3\r
d6ebcab7 4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
2ef2b01e 5\r
d6ebcab7 6 This program and the accompanying materials\r
2ef2b01e
A
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\r
17#ifndef __MACRO_IO_LIB_H__\r
18#define __MACRO_IO_LIB_H__\r
19\r
20#if defined(__APPLE__)\r
21\r
22//\r
23// ldr reg, =expr does not work with current Apple tool chain. So do the work our selves\r
24//\r
25\r
26// returns _Data in R0 and _Address in R1\r
27#define MmioWrite32(_Address, _Data) \\r
28 ldr r1, [pc, #8] ; \\r
29 ldr r0, [pc, #8] ; \\r
30 str r0, [r1] ; \\r
31 b 1f ; \\r
32 .long (_Address) ; \\r
33 .long (_Data) ; \\r
341:\r
35\r
36// returns _Data in R0 and _Address in R1, and _OrData in r2\r
37#define MmioOr32(_Address, _OrData) \\r
38 ldr r1, [pc, #16] ; \\r
39 ldr r2, [pc, #16] ; \\r
40 ldr r0, [r1] ; \\r
41 orr r0, r0, r2 ; \\r
42 str r0, [r1] ; \\r
43 b 1f ; \\r
44 .long (_Address) ; \\r
45 .long (_OrData) ; \\r
461:\r
47\r
48// returns _Data in R0 and _Address in R1, and _OrData in r2\r
49#define MmioAnd32(_Address, _AndData) \\r
50 ldr r1, [pc, #16] ; \\r
51 ldr r2, [pc, #16] ; \\r
52 ldr r0, [r1] ; \\r
53 and r0, r0, r2 ; \\r
54 str r0, [r1] ; \\r
55 b 1f ; \\r
56 .long (_Address) ; \\r
57 .long (_AndData) ; \\r
581:\r
59\r
60// returns result in R0, _Address in R1, and _OrData in r2\r
61#define MmioAndThenOr32(_Address, _AndData, _OrData) \\r
62 ldr r1, [pc, #24] ; \\r
63 ldr r0, [r1] ; \\r
64 ldr r2, [pc, #20] ; \\r
65 and r0, r0, r2 ; \\r
66 ldr r2, [pc, #16] ; \\r
67 orr r0, r0, r2 ; \\r
68 str r0, [r1] ; \\r
69 b 1f ; \\r
70 .long (_Address) ; \\r
71 .long (_AndData) ; \\r
72 .long (_OrData) ; \\r
731:\r
74\r
75// returns _Data in _Reg and _Address in R1\r
76#define MmioWriteFromReg32(_Address, _Reg) \\r
77 ldr r1, [pc, #4] ; \\r
78 str _Reg, [r1] ; \\r
79 b 1f ; \\r
80 .long (_Address) ; \\r
811:\r
82\r
83\r
84// returns _Data in R0 and _Address in R1\r
85#define MmioRead32(_Address) \\r
86 ldr r1, [pc, #4] ; \\r
87 ldr r0, [r1] ; \\r
88 b 1f ; \\r
89 .long (_Address) ; \\r
901:\r
91\r
92// returns _Data in Reg and _Address in R1\r
93#define MmioReadToReg32(_Address, _Reg) \\r
94 ldr r1, [pc, #4] ; \\r
95 ldr _Reg, [r1] ; \\r
96 b 1f ; \\r
97 .long (_Address) ; \\r
981:\r
99\r
100\r
101// load R0 with _Data\r
102#define LoadConstant(_Data) \\r
103 ldr r0, [pc, #0] ; \\r
104 b 1f ; \\r
105 .long (_Data) ; \\r
1061:\r
107\r
108// load _Reg with _Data\r
109#define LoadConstantToReg(_Data, _Reg) \\r
110 ldr _Reg, [pc, #0] ; \\r
111 b 1f ; \\r
112 .long (_Data) ; \\r
1131:\r
114\r
115// load _Reg with _Data if eq\r
116#define LoadConstantToRegIfEq(_Data, _Reg) \\r
117 ldreq _Reg, [pc, #0] ; \\r
118 b 1f ; \\r
119 .long (_Data) ; \\r
1201:\r
121\r
122\r
123#elif defined (__GNUC__)\r
124\r
125#define MmioWrite32(Address, Data) \\r
126 ldr r1, =Address ; \\r
127 ldr r0, =Data ; \\r
128 str r0, [r1]\r
129 \r
130#define MmioOr32(Address, OrData) \\r
131 ldr r1, =Address ; \\r
132 ldr r2, =OrData ; \\r
133 ldr r0, [r1] ; \\r
134 orr r0, r0, r2 ; \\r
135 str r0, [r1]\r
136\r
137#define MmioAnd32(Address, AndData) \\r
138 ldr r1, =Address ; \\r
139 ldr r2, =AndData ; \\r
140 ldr r0, [r1] ; \\r
141 and r0, r0, r2 ; \\r
142 str r0, [r1]\r
143\r
144#define MmioAndThenOr32(Address, AndData, OrData) \\r
145 ldr r1, =Address ; \\r
146 ldr r0, [r1] ; \\r
147 ldr r2, =AndData ; \\r
148 and r0, r0, r2 ; \\r
149 ldr r2, =OrData ; \\r
150 orr r0, r0, r2 ; \\r
151 str r0, [r1] \r
152\r
153#define MmioWriteFromReg32(Address, Reg) \\r
154 ldr r1, =Address ; \\r
155 str Reg, [r1]\r
156\r
157#define MmioRead32(Address) \\r
158 ldr r1, =Address ; \\r
159 ldr r0, [r1]\r
160\r
161#define MmioReadToReg32(Address, Reg) \\r
162 ldr r1, =Address ; \\r
163 ldr Reg, [r1]\r
164\r
165#define LoadConstant(Data) \\r
166 ldr r0, =Data\r
167\r
168#define LoadConstantToReg(Data, Reg) \\r
169 ldr Reg, =Data\r
170 \r
171#else\r
172\r
173//\r
174// Use ARM assembly macros, form armasam \r
175//\r
176// Less magic in the macros if ldr reg, =expr works\r
177//\r
178\r
179// returns _Data in R0 and _Address in R1\r
180\r
181\r
182\r
183#define MmioWrite32(Address, Data) MmioWrite32Macro Address, Data\r
184\r
185\r
186\r
187\r
188// returns Data in R0 and Address in R1, and OrData in r2\r
189#define MmioOr32(Address, OrData) MmioOr32Macro Address, OrData\r
190 \r
191\r
192// returns _Data in R0 and _Address in R1, and _OrData in r2\r
193\r
194\r
195#define MmioAnd32(Address, AndData) MmioAnd32Macro Address, AndData\r
196\r
197// returns result in R0, _Address in R1, and _OrData in r2\r
198\r
199\r
200#define MmioAndThenOr32(Address, AndData, OrData) MmioAndThenOr32Macro Address, AndData, OrData\r
201\r
202\r
203// returns _Data in _Reg and _Address in R1\r
204\r
205\r
206#define MmioWriteFromReg32(Address, Reg) MmioWriteFromReg32Macro Address, Reg\r
207\r
208// returns _Data in R0 and _Address in R1\r
209\r
210\r
211#define MmioRead32(Address) MmioRead32Macro Address\r
212\r
213// returns _Data in Reg and _Address in R1\r
214\r
215\r
216#define MmioReadToReg32(Address, Reg) MmioReadToReg32Macro Address, Reg\r
217\r
218\r
219// load R0 with _Data\r
220\r
221\r
222#define LoadConstant(Data) LoadConstantMacro Data\r
223\r
224// load _Reg with _Data\r
225\r
226\r
227#define LoadConstantToReg(Data, Reg) LoadConstantToRegMacro Data, Reg\r
228\r
229// conditional load testing eq flag\r
230#define LoadConstantToRegIfEq(Data, Reg) LoadConstantToRegIfEqMacro Data, Reg\r
231\r
232\r
233#endif\r
234\r
235\r
236#endif\r