1 | /*
|
---|
2 | * Copyright (C) 2008 Apple Inc. All rights reserved.
|
---|
3 | *
|
---|
4 | * Redistribution and use in source and binary forms, with or without
|
---|
5 | * modification, are permitted provided that the following conditions
|
---|
6 | * are met:
|
---|
7 | * 1. Redistributions of source code must retain the above copyright
|
---|
8 | * notice, this list of conditions and the following disclaimer.
|
---|
9 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer in the
|
---|
11 | * documentation and/or other materials provided with the distribution.
|
---|
12 | *
|
---|
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
---|
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
---|
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
---|
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
---|
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef MacroAssembler_h
|
---|
27 | #define MacroAssembler_h
|
---|
28 |
|
---|
29 | #include <wtf/Platform.h>
|
---|
30 |
|
---|
31 | #if ENABLE(ASSEMBLER)
|
---|
32 |
|
---|
33 | #if PLATFORM_ARM_ARCH(7)
|
---|
34 | #include "MacroAssemblerARMv7.h"
|
---|
35 | namespace JSC { typedef MacroAssemblerARMv7 MacroAssemblerBase; };
|
---|
36 |
|
---|
37 | #elif PLATFORM(X86)
|
---|
38 | #include "MacroAssemblerX86.h"
|
---|
39 | namespace JSC { typedef MacroAssemblerX86 MacroAssemblerBase; };
|
---|
40 |
|
---|
41 | #elif PLATFORM(X86_64)
|
---|
42 | #include "MacroAssemblerX86_64.h"
|
---|
43 | namespace JSC { typedef MacroAssemblerX86_64 MacroAssemblerBase; };
|
---|
44 |
|
---|
45 | #else
|
---|
46 | #error "The MacroAssembler is not supported on this platform."
|
---|
47 | #endif
|
---|
48 |
|
---|
49 |
|
---|
50 | namespace JSC {
|
---|
51 |
|
---|
52 | class MacroAssembler : public MacroAssemblerBase {
|
---|
53 | public:
|
---|
54 |
|
---|
55 | using MacroAssemblerBase::pop;
|
---|
56 | using MacroAssemblerBase::jump;
|
---|
57 | using MacroAssemblerBase::branch32;
|
---|
58 | using MacroAssemblerBase::branch16;
|
---|
59 | #if PLATFORM(X86_64)
|
---|
60 | using MacroAssemblerBase::branchPtr;
|
---|
61 | using MacroAssemblerBase::branchTestPtr;
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 | // Platform agnostic onvenience functions,
|
---|
66 | // described in terms of other macro assembly methods.
|
---|
67 | void pop()
|
---|
68 | {
|
---|
69 | addPtr(Imm32(sizeof(void*)), stackPointerRegister);
|
---|
70 | }
|
---|
71 |
|
---|
72 | void peek(RegisterID dest, int index = 0)
|
---|
73 | {
|
---|
74 | loadPtr(Address(stackPointerRegister, (index * sizeof(void*))), dest);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void poke(RegisterID src, int index = 0)
|
---|
78 | {
|
---|
79 | storePtr(src, Address(stackPointerRegister, (index * sizeof(void*))));
|
---|
80 | }
|
---|
81 |
|
---|
82 | void poke(Imm32 value, int index = 0)
|
---|
83 | {
|
---|
84 | store32(value, Address(stackPointerRegister, (index * sizeof(void*))));
|
---|
85 | }
|
---|
86 |
|
---|
87 | void poke(ImmPtr imm, int index = 0)
|
---|
88 | {
|
---|
89 | storePtr(imm, Address(stackPointerRegister, (index * sizeof(void*))));
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | // Backwards banches, these are currently all implemented using existing forwards branch mechanisms.
|
---|
94 | void branchPtr(Condition cond, RegisterID op1, ImmPtr imm, Label target)
|
---|
95 | {
|
---|
96 | branchPtr(cond, op1, imm).linkTo(target, this);
|
---|
97 | }
|
---|
98 |
|
---|
99 | void branch32(Condition cond, RegisterID op1, RegisterID op2, Label target)
|
---|
100 | {
|
---|
101 | branch32(cond, op1, op2).linkTo(target, this);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void branch32(Condition cond, RegisterID op1, Imm32 imm, Label target)
|
---|
105 | {
|
---|
106 | branch32(cond, op1, imm).linkTo(target, this);
|
---|
107 | }
|
---|
108 |
|
---|
109 | void branch32(Condition cond, RegisterID left, Address right, Label target)
|
---|
110 | {
|
---|
111 | branch32(cond, left, right).linkTo(target, this);
|
---|
112 | }
|
---|
113 |
|
---|
114 | void branch16(Condition cond, BaseIndex left, RegisterID right, Label target)
|
---|
115 | {
|
---|
116 | branch16(cond, left, right).linkTo(target, this);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void branchTestPtr(Condition cond, RegisterID reg, Label target)
|
---|
120 | {
|
---|
121 | branchTestPtr(cond, reg).linkTo(target, this);
|
---|
122 | }
|
---|
123 |
|
---|
124 | void jump(Label target)
|
---|
125 | {
|
---|
126 | jump().linkTo(target, this);
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | // Ptr methods
|
---|
131 | // On 32-bit platforms (i.e. x86), these methods directly map onto their 32-bit equivalents.
|
---|
132 | #if !PLATFORM(X86_64)
|
---|
133 | void addPtr(RegisterID src, RegisterID dest)
|
---|
134 | {
|
---|
135 | add32(src, dest);
|
---|
136 | }
|
---|
137 |
|
---|
138 | void addPtr(Imm32 imm, RegisterID srcDest)
|
---|
139 | {
|
---|
140 | add32(imm, srcDest);
|
---|
141 | }
|
---|
142 |
|
---|
143 | void addPtr(ImmPtr imm, RegisterID dest)
|
---|
144 | {
|
---|
145 | add32(Imm32(imm), dest);
|
---|
146 | }
|
---|
147 |
|
---|
148 | void addPtr(Imm32 imm, RegisterID src, RegisterID dest)
|
---|
149 | {
|
---|
150 | add32(imm, src, dest);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void andPtr(RegisterID src, RegisterID dest)
|
---|
154 | {
|
---|
155 | and32(src, dest);
|
---|
156 | }
|
---|
157 |
|
---|
158 | void andPtr(Imm32 imm, RegisterID srcDest)
|
---|
159 | {
|
---|
160 | and32(imm, srcDest);
|
---|
161 | }
|
---|
162 |
|
---|
163 | void orPtr(RegisterID src, RegisterID dest)
|
---|
164 | {
|
---|
165 | or32(src, dest);
|
---|
166 | }
|
---|
167 |
|
---|
168 | void orPtr(ImmPtr imm, RegisterID dest)
|
---|
169 | {
|
---|
170 | or32(Imm32(imm), dest);
|
---|
171 | }
|
---|
172 |
|
---|
173 | void orPtr(Imm32 imm, RegisterID dest)
|
---|
174 | {
|
---|
175 | or32(imm, dest);
|
---|
176 | }
|
---|
177 |
|
---|
178 | void rshiftPtr(RegisterID shift_amount, RegisterID dest)
|
---|
179 | {
|
---|
180 | rshift32(shift_amount, dest);
|
---|
181 | }
|
---|
182 |
|
---|
183 | void rshiftPtr(Imm32 imm, RegisterID dest)
|
---|
184 | {
|
---|
185 | rshift32(imm, dest);
|
---|
186 | }
|
---|
187 |
|
---|
188 | void subPtr(RegisterID src, RegisterID dest)
|
---|
189 | {
|
---|
190 | sub32(src, dest);
|
---|
191 | }
|
---|
192 |
|
---|
193 | void subPtr(Imm32 imm, RegisterID dest)
|
---|
194 | {
|
---|
195 | sub32(imm, dest);
|
---|
196 | }
|
---|
197 |
|
---|
198 | void subPtr(ImmPtr imm, RegisterID dest)
|
---|
199 | {
|
---|
200 | sub32(Imm32(imm), dest);
|
---|
201 | }
|
---|
202 |
|
---|
203 | void xorPtr(RegisterID src, RegisterID dest)
|
---|
204 | {
|
---|
205 | xor32(src, dest);
|
---|
206 | }
|
---|
207 |
|
---|
208 | void xorPtr(Imm32 imm, RegisterID srcDest)
|
---|
209 | {
|
---|
210 | xor32(imm, srcDest);
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | void loadPtr(ImplicitAddress address, RegisterID dest)
|
---|
215 | {
|
---|
216 | load32(address, dest);
|
---|
217 | }
|
---|
218 |
|
---|
219 | void loadPtr(BaseIndex address, RegisterID dest)
|
---|
220 | {
|
---|
221 | load32(address, dest);
|
---|
222 | }
|
---|
223 |
|
---|
224 | void loadPtr(void* address, RegisterID dest)
|
---|
225 | {
|
---|
226 | load32(address, dest);
|
---|
227 | }
|
---|
228 |
|
---|
229 | DataLabel32 loadPtrWithAddressOffsetPatch(Address address, RegisterID dest)
|
---|
230 | {
|
---|
231 | return load32WithAddressOffsetPatch(address, dest);
|
---|
232 | }
|
---|
233 |
|
---|
234 | void setPtr(Condition cond, RegisterID left, Imm32 right, RegisterID dest)
|
---|
235 | {
|
---|
236 | set32(cond, left, right, dest);
|
---|
237 | }
|
---|
238 |
|
---|
239 | void storePtr(RegisterID src, ImplicitAddress address)
|
---|
240 | {
|
---|
241 | store32(src, address);
|
---|
242 | }
|
---|
243 |
|
---|
244 | void storePtr(RegisterID src, BaseIndex address)
|
---|
245 | {
|
---|
246 | store32(src, address);
|
---|
247 | }
|
---|
248 |
|
---|
249 | void storePtr(RegisterID src, void* address)
|
---|
250 | {
|
---|
251 | store32(src, address);
|
---|
252 | }
|
---|
253 |
|
---|
254 | void storePtr(ImmPtr imm, ImplicitAddress address)
|
---|
255 | {
|
---|
256 | store32(Imm32(imm), address);
|
---|
257 | }
|
---|
258 |
|
---|
259 | void storePtr(ImmPtr imm, void* address)
|
---|
260 | {
|
---|
261 | store32(Imm32(imm), address);
|
---|
262 | }
|
---|
263 |
|
---|
264 | DataLabel32 storePtrWithAddressOffsetPatch(RegisterID src, Address address)
|
---|
265 | {
|
---|
266 | return store32WithAddressOffsetPatch(src, address);
|
---|
267 | }
|
---|
268 |
|
---|
269 |
|
---|
270 | Jump branchPtr(Condition cond, RegisterID left, RegisterID right)
|
---|
271 | {
|
---|
272 | return branch32(cond, left, right);
|
---|
273 | }
|
---|
274 |
|
---|
275 | Jump branchPtr(Condition cond, RegisterID left, ImmPtr right)
|
---|
276 | {
|
---|
277 | return branch32(cond, left, Imm32(right));
|
---|
278 | }
|
---|
279 |
|
---|
280 | Jump branchPtr(Condition cond, RegisterID left, Address right)
|
---|
281 | {
|
---|
282 | return branch32(cond, left, right);
|
---|
283 | }
|
---|
284 |
|
---|
285 | Jump branchPtr(Condition cond, Address left, RegisterID right)
|
---|
286 | {
|
---|
287 | return branch32(cond, left, right);
|
---|
288 | }
|
---|
289 |
|
---|
290 | Jump branchPtr(Condition cond, AbsoluteAddress left, RegisterID right)
|
---|
291 | {
|
---|
292 | return branch32(cond, left, right);
|
---|
293 | }
|
---|
294 |
|
---|
295 | Jump branchPtr(Condition cond, Address left, ImmPtr right)
|
---|
296 | {
|
---|
297 | return branch32(cond, left, Imm32(right));
|
---|
298 | }
|
---|
299 |
|
---|
300 | Jump branchPtr(Condition cond, AbsoluteAddress left, ImmPtr right)
|
---|
301 | {
|
---|
302 | return branch32(cond, left, Imm32(right));
|
---|
303 | }
|
---|
304 |
|
---|
305 | Jump branchTestPtr(Condition cond, RegisterID reg, RegisterID mask)
|
---|
306 | {
|
---|
307 | return branchTest32(cond, reg, mask);
|
---|
308 | }
|
---|
309 |
|
---|
310 | Jump branchTestPtr(Condition cond, RegisterID reg, Imm32 mask = Imm32(-1))
|
---|
311 | {
|
---|
312 | return branchTest32(cond, reg, mask);
|
---|
313 | }
|
---|
314 |
|
---|
315 | Jump branchTestPtr(Condition cond, Address address, Imm32 mask = Imm32(-1))
|
---|
316 | {
|
---|
317 | return branchTest32(cond, address, mask);
|
---|
318 | }
|
---|
319 |
|
---|
320 | Jump branchTestPtr(Condition cond, BaseIndex address, Imm32 mask = Imm32(-1))
|
---|
321 | {
|
---|
322 | return branchTest32(cond, address, mask);
|
---|
323 | }
|
---|
324 |
|
---|
325 |
|
---|
326 | Jump branchAddPtr(Condition cond, RegisterID src, RegisterID dest)
|
---|
327 | {
|
---|
328 | return branchAdd32(cond, src, dest);
|
---|
329 | }
|
---|
330 |
|
---|
331 | Jump branchSubPtr(Condition cond, Imm32 imm, RegisterID dest)
|
---|
332 | {
|
---|
333 | return branchSub32(cond, imm, dest);
|
---|
334 | }
|
---|
335 | #endif
|
---|
336 |
|
---|
337 | };
|
---|
338 |
|
---|
339 | } // namespace JSC
|
---|
340 |
|
---|
341 | #endif // ENABLE(ASSEMBLER)
|
---|
342 |
|
---|
343 | #endif // MacroAssembler_h
|
---|