blob: 60c2e6f6bf605a732b1e1e5c09f8edb17efee221 [file] [log] [blame]
Ben Murdochc7cc0282012-03-05 14:35:55 +00001// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_ARM_MACRO_ASSEMBLER_ARM_H_
29#define V8_ARM_MACRO_ASSEMBLER_ARM_H_
30
31#include "assembler.h"
Ben Murdoch592a9fc2012-03-05 11:04:45 +000032#include "frames.h"
Ben Murdoch257744e2011-11-30 15:57:28 +000033#include "v8globals.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35namespace v8 {
36namespace internal {
37
Andrei Popescu31002712010-02-23 13:46:05 +000038// ----------------------------------------------------------------------------
39// Static helper functions
40
41// Generate a MemOperand for loading a field from an object.
Ben Murdoch592a9fc2012-03-05 11:04:45 +000042inline MemOperand FieldMemOperand(Register object, int offset) {
Andrei Popescu31002712010-02-23 13:46:05 +000043 return MemOperand(object, offset - kHeapObjectTag);
44}
45
Steve Blocka7e24c12009-10-30 11:49:00 +000046
Ben Murdoch592a9fc2012-03-05 11:04:45 +000047inline Operand SmiUntagOperand(Register object) {
Steve Block1e0659c2011-05-24 12:43:12 +010048 return Operand(object, ASR, kSmiTagSize);
49}
50
51
52
Steve Blocka7e24c12009-10-30 11:49:00 +000053// Give alias names to registers
54const Register cp = { 8 }; // JavaScript context pointer
Ben Murdochc7cc0282012-03-05 14:35:55 +000055const Register kRootRegister = { 10 }; // Roots array pointer.
Steve Blocka7e24c12009-10-30 11:49:00 +000056
Kristian Monsen25f61362010-05-21 11:50:48 +010057// Flags used for the AllocateInNewSpace functions.
58enum AllocationFlags {
59 // No special flags.
60 NO_ALLOCATION_FLAGS = 0,
61 // Return the pointer to the allocated already tagged as a heap object.
62 TAG_OBJECT = 1 << 0,
63 // The content of the result register already contains the allocation top in
64 // new space.
65 RESULT_CONTAINS_TOP = 1 << 1,
66 // Specify that the requested size of the space to allocate is specified in
67 // words instead of bytes.
68 SIZE_IN_WORDS = 1 << 2
69};
70
71
Steve Block8defd9f2010-07-08 12:39:36 +010072// Flags used for the ObjectToDoubleVFPRegister function.
73enum ObjectToDoubleFlags {
74 // No special flags.
75 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
76 // Object is known to be a non smi.
77 OBJECT_NOT_SMI = 1 << 0,
78 // Don't load NaNs or infinities, branch to the non number case instead.
79 AVOID_NANS_AND_INFINITIES = 1 << 1
80};
81
82
Ben Murdoch592a9fc2012-03-05 11:04:45 +000083enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
84enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
85enum LinkRegisterStatus { kLRHasNotBeenSaved, kLRHasBeenSaved };
86
87
88bool AreAliased(Register r1, Register r2, Register r3, Register r4);
89
90
Steve Blocka7e24c12009-10-30 11:49:00 +000091// MacroAssembler implements a collection of frequently used macros.
92class MacroAssembler: public Assembler {
93 public:
Ben Murdoch8b112d22011-06-08 16:22:53 +010094 // The isolate parameter can be NULL if the macro assembler should
95 // not use isolate-dependent functionality. In this case, it's the
96 // responsibility of the caller to never invoke such function on the
97 // macro assembler.
98 MacroAssembler(Isolate* isolate, void* buffer, int size);
Steve Blocka7e24c12009-10-30 11:49:00 +000099
Andrei Popescu31002712010-02-23 13:46:05 +0000100 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +0000101 void Jump(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000102 void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000103 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
Ben Murdoch42effa52011-08-19 16:40:31 +0100104 static int CallSize(Register target, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000105 void Call(Register target, Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000106 static int CallSize(Address target,
Ben Murdoch42effa52011-08-19 16:40:31 +0100107 RelocInfo::Mode rmode,
108 Condition cond = al);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000109 void Call(Address target, RelocInfo::Mode rmode, Condition cond = al);
110 static int CallSize(Handle<Code> code,
111 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
112 unsigned ast_id = kNoASTId,
113 Condition cond = al);
Ben Murdoch257744e2011-11-30 15:57:28 +0000114 void Call(Handle<Code> code,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000115 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
116 unsigned ast_id = kNoASTId,
Ben Murdoch257744e2011-11-30 15:57:28 +0000117 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000119
120 // Emit code to discard a non-negative number of pointer-sized elements
121 // from the stack, clobbering only the sp register.
122 void Drop(int count, Condition cond = al);
123
Ben Murdochb0fe1622011-05-05 13:52:32 +0100124 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100125
126 // Swap two registers. If the scratch register is omitted then a slightly
127 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100128 void Swap(Register reg1,
129 Register reg2,
130 Register scratch = no_reg,
131 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100132
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100133
134 void And(Register dst, Register src1, const Operand& src2,
135 Condition cond = al);
136 void Ubfx(Register dst, Register src, int lsb, int width,
137 Condition cond = al);
138 void Sbfx(Register dst, Register src, int lsb, int width,
139 Condition cond = al);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100140 // The scratch register is not used for ARMv7.
141 // scratch can be the same register as src (in which case it is trashed), but
142 // not the same as dst.
143 void Bfi(Register dst,
144 Register src,
145 Register scratch,
146 int lsb,
147 int width,
148 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100149 void Bfc(Register dst, int lsb, int width, Condition cond = al);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100150 void Usat(Register dst, int satpos, const Operand& src,
151 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100152
Leon Clarkee46be812010-01-19 14:06:41 +0000153 void Call(Label* target);
Ben Murdoch257744e2011-11-30 15:57:28 +0000154
155 // Register move. May do nothing if the registers are identical.
Leon Clarkee46be812010-01-19 14:06:41 +0000156 void Move(Register dst, Handle<Object> value);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000157 void Move(Register dst, Register src, Condition cond = al);
Ben Murdoch257744e2011-11-30 15:57:28 +0000158 void Move(DoubleRegister dst, DoubleRegister src);
159
Steve Blocka7e24c12009-10-30 11:49:00 +0000160 // Load an object from the root table.
161 void LoadRoot(Register destination,
162 Heap::RootListIndex index,
163 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100164 // Store an object to the root table.
165 void StoreRoot(Register source,
166 Heap::RootListIndex index,
167 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000168
Ben Murdochc7cc0282012-03-05 14:35:55 +0000169 void LoadHeapObject(Register dst, Handle<HeapObject> object);
170
171 void LoadObject(Register result, Handle<Object> object) {
172 if (object->IsHeapObject()) {
173 LoadHeapObject(result, Handle<HeapObject>::cast(object));
174 } else {
175 Move(result, object);
176 }
177 }
178
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000179 // ---------------------------------------------------------------------------
180 // GC Support
Steve Block6ded16b2010-05-10 14:33:55 +0100181
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000182 void IncrementalMarkingRecordWriteHelper(Register object,
183 Register value,
184 Register address);
Steve Block6ded16b2010-05-10 14:33:55 +0100185
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000186 enum RememberedSetFinalAction {
187 kReturnAtEnd,
188 kFallThroughAtEnd
189 };
Steve Block6ded16b2010-05-10 14:33:55 +0100190
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000191 // Record in the remembered set the fact that we have a pointer to new space
192 // at the address pointed to by the addr register. Only works if addr is not
193 // in new space.
194 void RememberedSetHelper(Register object, // Used for debug code.
195 Register addr,
196 Register scratch,
197 SaveFPRegsMode save_fp,
198 RememberedSetFinalAction and_then);
Steve Block6ded16b2010-05-10 14:33:55 +0100199
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000200 void CheckPageFlag(Register object,
201 Register scratch,
202 int mask,
203 Condition cc,
204 Label* condition_met);
205
206 // Check if object is in new space. Jumps if the object is not in new space.
207 // The register scratch can be object itself, but scratch will be clobbered.
208 void JumpIfNotInNewSpace(Register object,
209 Register scratch,
210 Label* branch) {
211 InNewSpace(object, scratch, ne, branch);
212 }
213
214 // Check if object is in new space. Jumps if the object is in new space.
215 // The register scratch can be object itself, but it will be clobbered.
216 void JumpIfInNewSpace(Register object,
217 Register scratch,
218 Label* branch) {
219 InNewSpace(object, scratch, eq, branch);
220 }
221
222 // Check if an object has a given incremental marking color.
223 void HasColor(Register object,
224 Register scratch0,
225 Register scratch1,
226 Label* has_color,
227 int first_bit,
228 int second_bit);
229
230 void JumpIfBlack(Register object,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100231 Register scratch0,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000232 Register scratch1,
233 Label* on_black);
Steve Blocka7e24c12009-10-30 11:49:00 +0000234
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000235 // Checks the color of an object. If the object is already grey or black
236 // then we just fall through, since it is already live. If it is white and
237 // we can determine that it doesn't need to be scanned, then we just mark it
238 // black and fall through. For the rest we jump to the label so the
239 // incremental marker can fix its assumptions.
240 void EnsureNotWhite(Register object,
241 Register scratch1,
242 Register scratch2,
243 Register scratch3,
244 Label* object_is_white_and_not_data);
245
Ben Murdochc7cc0282012-03-05 14:35:55 +0000246 // Detects conservatively whether an object is data-only, i.e. it does need to
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000247 // be scanned by the garbage collector.
248 void JumpIfDataObject(Register value,
249 Register scratch,
250 Label* not_data_object);
251
252 // Notify the garbage collector that we wrote a pointer into an object.
253 // |object| is the object being stored into, |value| is the object being
254 // stored. value and scratch registers are clobbered by the operation.
255 // The offset is the offset from the start of the object, not the offset from
256 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
257 void RecordWriteField(
258 Register object,
259 int offset,
260 Register value,
261 Register scratch,
262 LinkRegisterStatus lr_status,
263 SaveFPRegsMode save_fp,
264 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
265 SmiCheck smi_check = INLINE_SMI_CHECK);
266
267 // As above, but the offset has the tag presubtracted. For use with
268 // MemOperand(reg, off).
269 inline void RecordWriteContextSlot(
270 Register context,
271 int offset,
272 Register value,
273 Register scratch,
274 LinkRegisterStatus lr_status,
275 SaveFPRegsMode save_fp,
276 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
277 SmiCheck smi_check = INLINE_SMI_CHECK) {
278 RecordWriteField(context,
279 offset + kHeapObjectTag,
280 value,
281 scratch,
282 lr_status,
283 save_fp,
284 remembered_set_action,
285 smi_check);
286 }
287
288 // For a given |object| notify the garbage collector that the slot |address|
289 // has been written. |value| is the object being stored. The value and
290 // address registers are clobbered by the operation.
291 void RecordWrite(
292 Register object,
293 Register address,
294 Register value,
295 LinkRegisterStatus lr_status,
296 SaveFPRegsMode save_fp,
297 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
298 SmiCheck smi_check = INLINE_SMI_CHECK);
Steve Block8defd9f2010-07-08 12:39:36 +0100299
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000300 // Push a handle.
301 void Push(Handle<Object> handle);
302
Steve Block6ded16b2010-05-10 14:33:55 +0100303 // Push two registers. Pushes leftmost register first (to highest address).
304 void Push(Register src1, Register src2, Condition cond = al) {
305 ASSERT(!src1.is(src2));
306 if (src1.code() > src2.code()) {
307 stm(db_w, sp, src1.bit() | src2.bit(), cond);
308 } else {
309 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
310 str(src2, MemOperand(sp, 4, NegPreIndex), cond);
311 }
312 }
313
314 // Push three registers. Pushes leftmost register first (to highest address).
315 void Push(Register src1, Register src2, Register src3, Condition cond = al) {
316 ASSERT(!src1.is(src2));
317 ASSERT(!src2.is(src3));
318 ASSERT(!src1.is(src3));
319 if (src1.code() > src2.code()) {
320 if (src2.code() > src3.code()) {
321 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
322 } else {
323 stm(db_w, sp, src1.bit() | src2.bit(), cond);
324 str(src3, MemOperand(sp, 4, NegPreIndex), cond);
325 }
326 } else {
327 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
328 Push(src2, src3, cond);
329 }
330 }
331
332 // Push four registers. Pushes leftmost register first (to highest address).
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000333 void Push(Register src1,
334 Register src2,
335 Register src3,
336 Register src4,
337 Condition cond = al) {
Steve Block6ded16b2010-05-10 14:33:55 +0100338 ASSERT(!src1.is(src2));
339 ASSERT(!src2.is(src3));
340 ASSERT(!src1.is(src3));
341 ASSERT(!src1.is(src4));
342 ASSERT(!src2.is(src4));
343 ASSERT(!src3.is(src4));
344 if (src1.code() > src2.code()) {
345 if (src2.code() > src3.code()) {
346 if (src3.code() > src4.code()) {
347 stm(db_w,
348 sp,
349 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
350 cond);
351 } else {
352 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
353 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
354 }
355 } else {
356 stm(db_w, sp, src1.bit() | src2.bit(), cond);
357 Push(src3, src4, cond);
358 }
359 } else {
360 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
361 Push(src2, src3, src4, cond);
362 }
363 }
364
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100365 // Pop two registers. Pops rightmost register first (from lower address).
366 void Pop(Register src1, Register src2, Condition cond = al) {
367 ASSERT(!src1.is(src2));
368 if (src1.code() > src2.code()) {
369 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
370 } else {
371 ldr(src2, MemOperand(sp, 4, PostIndex), cond);
372 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
373 }
374 }
375
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000376 // Pop three registers. Pops rightmost register first (from lower address).
377 void Pop(Register src1, Register src2, Register src3, Condition cond = al) {
378 ASSERT(!src1.is(src2));
379 ASSERT(!src2.is(src3));
380 ASSERT(!src1.is(src3));
381 if (src1.code() > src2.code()) {
382 if (src2.code() > src3.code()) {
383 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
384 } else {
385 ldr(src3, MemOperand(sp, 4, PostIndex), cond);
386 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
387 }
388 } else {
389 Pop(src2, src3, cond);
390 str(src1, MemOperand(sp, 4, PostIndex), cond);
391 }
392 }
393
394 // Pop four registers. Pops rightmost register first (from lower address).
395 void Pop(Register src1,
396 Register src2,
397 Register src3,
398 Register src4,
399 Condition cond = al) {
400 ASSERT(!src1.is(src2));
401 ASSERT(!src2.is(src3));
402 ASSERT(!src1.is(src3));
403 ASSERT(!src1.is(src4));
404 ASSERT(!src2.is(src4));
405 ASSERT(!src3.is(src4));
406 if (src1.code() > src2.code()) {
407 if (src2.code() > src3.code()) {
408 if (src3.code() > src4.code()) {
409 ldm(ia_w,
410 sp,
411 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
412 cond);
413 } else {
414 ldr(src4, MemOperand(sp, 4, PostIndex), cond);
415 ldm(ia_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
416 }
417 } else {
418 Pop(src3, src4, cond);
419 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
420 }
421 } else {
422 Pop(src2, src3, src4, cond);
423 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
424 }
425 }
426
Ben Murdochb0fe1622011-05-05 13:52:32 +0100427 // Push and pop the registers that can hold pointers, as defined by the
428 // RegList constant kSafepointSavedRegisters.
429 void PushSafepointRegisters();
430 void PopSafepointRegisters();
Ben Murdochb8e0da22011-05-16 14:20:40 +0100431 void PushSafepointRegistersAndDoubles();
432 void PopSafepointRegistersAndDoubles();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100433 // Store value in register src in the safepoint stack slot for
434 // register dst.
435 void StoreToSafepointRegisterSlot(Register src, Register dst);
436 void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
437 // Load the value of the src register from its safepoint stack slot
438 // into register dst.
439 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100440
Leon Clarkef7060e22010-06-03 12:02:55 +0100441 // Load two consecutive registers with two consecutive memory locations.
442 void Ldrd(Register dst1,
443 Register dst2,
444 const MemOperand& src,
445 Condition cond = al);
446
447 // Store two consecutive registers to two consecutive memory locations.
448 void Strd(Register src1,
449 Register src2,
450 const MemOperand& dst,
451 Condition cond = al);
452
Ben Murdochb8e0da22011-05-16 14:20:40 +0100453 // Clear specified FPSCR bits.
454 void ClearFPSCRBits(const uint32_t bits_to_clear,
455 const Register scratch,
456 const Condition cond = al);
457
458 // Compare double values and move the result to the normal condition flags.
459 void VFPCompareAndSetFlags(const DwVfpRegister src1,
460 const DwVfpRegister src2,
461 const Condition cond = al);
462 void VFPCompareAndSetFlags(const DwVfpRegister src1,
463 const double src2,
464 const Condition cond = al);
465
466 // Compare double values and then load the fpscr flags to a register.
467 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
468 const DwVfpRegister src2,
469 const Register fpscr_flags,
470 const Condition cond = al);
471 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
472 const double src2,
473 const Register fpscr_flags,
474 const Condition cond = al);
475
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000476 void Vmov(const DwVfpRegister dst,
477 const double imm,
478 const Condition cond = al);
479
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100480 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100481 // stack_space - extra stack space, used for alignment before call to C.
482 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000483
484 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100485 // Expect the number of values, pushed prior to the exit frame, to
486 // remove in a register (or no_reg, if there is nothing to remove).
487 void LeaveExitFrame(bool save_doubles, Register argument_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000488
Steve Block6ded16b2010-05-10 14:33:55 +0100489 // Get the actual activation frame alignment for target environment.
490 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000491
Steve Blockd0582a62009-12-15 09:54:21 +0000492 void LoadContext(Register dst, int context_chain_length);
493
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800494 void LoadGlobalFunction(int index, Register function);
495
496 // Load the initial map from the global function. The registers
497 // function and map can be the same, function is then overwritten.
498 void LoadGlobalFunctionInitialMap(Register function,
499 Register map,
500 Register scratch);
501
Ben Murdochc7cc0282012-03-05 14:35:55 +0000502 void InitializeRootRegister() {
503 ExternalReference roots_array_start =
504 ExternalReference::roots_array_start(isolate());
505 mov(kRootRegister, Operand(roots_array_start));
506 }
507
Steve Blocka7e24c12009-10-30 11:49:00 +0000508 // ---------------------------------------------------------------------------
509 // JavaScript invokes
510
Ben Murdochc7cc0282012-03-05 14:35:55 +0000511 // Set up call kind marking in ecx. The method takes ecx as an
Ben Murdoch257744e2011-11-30 15:57:28 +0000512 // explicit first parameter to make the code more readable at the
513 // call sites.
514 void SetCallKind(Register dst, CallKind kind);
515
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 // Invoke the JavaScript function code by either calling or jumping.
517 void InvokeCode(Register code,
518 const ParameterCount& expected,
519 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100520 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000521 const CallWrapper& call_wrapper,
522 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000523
524 void InvokeCode(Handle<Code> code,
525 const ParameterCount& expected,
526 const ParameterCount& actual,
527 RelocInfo::Mode rmode,
Ben Murdoch257744e2011-11-30 15:57:28 +0000528 InvokeFlag flag,
529 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000530
531 // Invoke the JavaScript function in the given register. Changes the
532 // current context to the context in the function before invoking.
533 void InvokeFunction(Register function,
534 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100535 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +0000536 const CallWrapper& call_wrapper,
537 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000538
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000539 void InvokeFunction(Handle<JSFunction> function,
Andrei Popescu402d9372010-02-26 13:31:12 +0000540 const ParameterCount& actual,
Ben Murdoch257744e2011-11-30 15:57:28 +0000541 InvokeFlag flag,
Ben Murdochc7cc0282012-03-05 14:35:55 +0000542 const CallWrapper& call_wrapper,
Ben Murdoch257744e2011-11-30 15:57:28 +0000543 CallKind call_kind);
Andrei Popescu402d9372010-02-26 13:31:12 +0000544
Ben Murdochb0fe1622011-05-05 13:52:32 +0100545 void IsObjectJSObjectType(Register heap_object,
546 Register map,
547 Register scratch,
548 Label* fail);
549
550 void IsInstanceJSObjectType(Register map,
551 Register scratch,
552 Label* fail);
553
554 void IsObjectJSStringType(Register object,
555 Register scratch,
556 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000557
558#ifdef ENABLE_DEBUGGER_SUPPORT
559 // ---------------------------------------------------------------------------
560 // Debugger Support
561
Andrei Popescu402d9372010-02-26 13:31:12 +0000562 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000563#endif
564
565 // ---------------------------------------------------------------------------
566 // Exception handling
567
568 // Push a new try handler and link into try handler chain.
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000569 void PushTryHandler(CodeLocation try_location,
570 HandlerType type,
571 int handler_index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000572
Leon Clarkee46be812010-01-19 14:06:41 +0000573 // Unlink the stack handler on top of the stack from the try handler chain.
574 // Must preserve the result register.
575 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000576
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100577 // Passes thrown value (in r0) to the handler of top of the try handler chain.
578 void Throw(Register value);
579
580 // Propagates an uncatchable exception to the top of the current JS stack's
581 // handler chain.
582 void ThrowUncatchable(UncatchableExceptionType type, Register value);
583
Steve Blocka7e24c12009-10-30 11:49:00 +0000584 // ---------------------------------------------------------------------------
585 // Inline caching support
586
Steve Blocka7e24c12009-10-30 11:49:00 +0000587 // Generate code for checking access rights - used for security checks
588 // on access to global objects across environments. The holder register
589 // is left untouched, whereas both scratch registers are clobbered.
590 void CheckAccessGlobalProxy(Register holder_reg,
591 Register scratch,
592 Label* miss);
593
Ben Murdochc7cc0282012-03-05 14:35:55 +0000594 void GetNumberHash(Register t0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000595
596 void LoadFromNumberDictionary(Label* miss,
597 Register elements,
598 Register key,
599 Register result,
600 Register t0,
601 Register t1,
602 Register t2);
603
604
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800605 inline void MarkCode(NopMarkerTypes type) {
606 nop(type);
607 }
608
609 // Check if the given instruction is a 'type' marker.
Ben Murdochc7cc0282012-03-05 14:35:55 +0000610 // i.e. check if is is a mov r<type>, r<type> (referenced as nop(type))
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800611 // These instructions are generated to mark special location in the code,
612 // like some special IC code.
613 static inline bool IsMarkedCode(Instr instr, int type) {
614 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
615 return IsNop(instr, type);
616 }
617
618
619 static inline int GetCodeMarker(Instr instr) {
620 int dst_reg_offset = 12;
621 int dst_mask = 0xf << dst_reg_offset;
622 int src_mask = 0xf;
623 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
624 int src_reg = instr & src_mask;
625 uint32_t non_register_mask = ~(dst_mask | src_mask);
626 uint32_t mov_mask = al | 13 << 21;
627
628 // Return <n> if we have a mov rn rn, else return -1.
629 int type = ((instr & non_register_mask) == mov_mask) &&
630 (dst_reg == src_reg) &&
631 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
632 ? src_reg
633 : -1;
634 ASSERT((type == -1) ||
635 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
636 return type;
637 }
638
Steve Blocka7e24c12009-10-30 11:49:00 +0000639
640 // ---------------------------------------------------------------------------
641 // Allocation support
642
Ben Murdoch086aeea2011-05-13 15:57:08 +0100643 // Allocate an object in new space. The object_size is specified
644 // either in bytes or in words if the allocation flag SIZE_IN_WORDS
645 // is passed. If the new space is exhausted control continues at the
646 // gc_required label. The allocated object is returned in result. If
647 // the flag tag_allocated_object is true the result is tagged as as
648 // a heap object. All registers are clobbered also when control
649 // continues at the gc_required label.
Steve Blocka7e24c12009-10-30 11:49:00 +0000650 void AllocateInNewSpace(int object_size,
651 Register result,
652 Register scratch1,
653 Register scratch2,
654 Label* gc_required,
655 AllocationFlags flags);
656 void AllocateInNewSpace(Register object_size,
657 Register result,
658 Register scratch1,
659 Register scratch2,
660 Label* gc_required,
661 AllocationFlags flags);
662
663 // Undo allocation in new space. The object passed and objects allocated after
664 // it will no longer be allocated. The caller must make sure that no pointers
665 // are left to the object(s) no longer allocated as they would be invalid when
666 // allocation is undone.
667 void UndoAllocationInNewSpace(Register object, Register scratch);
668
Andrei Popescu31002712010-02-23 13:46:05 +0000669
670 void AllocateTwoByteString(Register result,
671 Register length,
672 Register scratch1,
673 Register scratch2,
674 Register scratch3,
675 Label* gc_required);
676 void AllocateAsciiString(Register result,
677 Register length,
678 Register scratch1,
679 Register scratch2,
680 Register scratch3,
681 Label* gc_required);
682 void AllocateTwoByteConsString(Register result,
683 Register length,
684 Register scratch1,
685 Register scratch2,
686 Label* gc_required);
687 void AllocateAsciiConsString(Register result,
688 Register length,
689 Register scratch1,
690 Register scratch2,
691 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000692 void AllocateTwoByteSlicedString(Register result,
693 Register length,
694 Register scratch1,
695 Register scratch2,
696 Label* gc_required);
697 void AllocateAsciiSlicedString(Register result,
698 Register length,
699 Register scratch1,
700 Register scratch2,
701 Label* gc_required);
Andrei Popescu31002712010-02-23 13:46:05 +0000702
Kristian Monsen25f61362010-05-21 11:50:48 +0100703 // Allocates a heap number or jumps to the gc_required label if the young
704 // space is full and a scavenge is needed. All registers are clobbered also
705 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100706 void AllocateHeapNumber(Register result,
707 Register scratch1,
708 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100709 Register heap_number_map,
Steve Block6ded16b2010-05-10 14:33:55 +0100710 Label* gc_required);
Steve Block8defd9f2010-07-08 12:39:36 +0100711 void AllocateHeapNumberWithValue(Register result,
712 DwVfpRegister value,
713 Register scratch1,
714 Register scratch2,
715 Register heap_number_map,
716 Label* gc_required);
717
Ben Murdochbb769b22010-08-11 14:56:33 +0100718 // Copies a fixed number of fields of heap objects from src to dst.
719 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000720
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100721 // Copies a number of bytes from src to dst. All registers are clobbered. On
722 // exit src and dst will point to the place just after where the last byte was
723 // read or written and length will be zero.
724 void CopyBytes(Register src,
725 Register dst,
726 Register length,
727 Register scratch);
728
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000729 // Initialize fields with filler values. Fields starting at |start_offset|
730 // not including end_offset are overwritten with the value in |filler|. At
731 // the end the loop, |start_offset| takes the value of |end_offset|.
732 void InitializeFieldsWithFiller(Register start_offset,
733 Register end_offset,
734 Register filler);
735
Steve Blocka7e24c12009-10-30 11:49:00 +0000736 // ---------------------------------------------------------------------------
737 // Support functions.
738
739 // Try to get function prototype of a function and puts the value in
740 // the result register. Checks that the function really is a
741 // function and jumps to the miss label if the fast checks fail. The
742 // function register will be untouched; the other registers may be
743 // clobbered.
744 void TryGetFunctionPrototype(Register function,
745 Register result,
746 Register scratch,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000747 Label* miss,
748 bool miss_on_bound_function = false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000749
750 // Compare object type for heap object. heap_object contains a non-Smi
751 // whose object type should be compared with the given type. This both
752 // sets the flags and leaves the object type in the type_reg register.
753 // It leaves the map in the map register (unless the type_reg and map register
754 // are the same register). It leaves the heap object in the heap_object
755 // register unless the heap_object register is the same register as one of the
756 // other registers.
757 void CompareObjectType(Register heap_object,
758 Register map,
759 Register type_reg,
760 InstanceType type);
761
762 // Compare instance type in a map. map contains a valid map object whose
763 // object type should be compared with the given type. This both
Ben Murdoch589d6972011-11-30 16:04:58 +0000764 // sets the flags and leaves the object type in the type_reg register.
Steve Blocka7e24c12009-10-30 11:49:00 +0000765 void CompareInstanceType(Register map,
766 Register type_reg,
767 InstanceType type);
768
Andrei Popescu31002712010-02-23 13:46:05 +0000769
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000770 // Check if a map for a JSObject indicates that the object has fast elements.
771 // Jump to the specified label if it does not.
772 void CheckFastElements(Register map,
773 Register scratch,
774 Label* fail);
775
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000776 // Check if a map for a JSObject indicates that the object can have both smi
777 // and HeapObject elements. Jump to the specified label if it does not.
778 void CheckFastObjectElements(Register map,
779 Register scratch,
780 Label* fail);
781
782 // Check if a map for a JSObject indicates that the object has fast smi only
783 // elements. Jump to the specified label if it does not.
784 void CheckFastSmiOnlyElements(Register map,
785 Register scratch,
786 Label* fail);
787
788 // Check to see if maybe_number can be stored as a double in
789 // FastDoubleElements. If it can, store it at the index specified by key in
790 // the FastDoubleElements array elements, otherwise jump to fail.
791 void StoreNumberToDoubleElements(Register value_reg,
792 Register key_reg,
793 Register receiver_reg,
794 Register elements_reg,
795 Register scratch1,
796 Register scratch2,
797 Register scratch3,
798 Register scratch4,
799 Label* fail);
800
Ben Murdochc7cc0282012-03-05 14:35:55 +0000801 // Compare an object's map with the specified map and its transitioned
802 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Condition flags are
803 // set with result of map compare. If multiple map compares are required, the
804 // compare sequences branches to early_success.
805 void CompareMap(Register obj,
806 Register scratch,
807 Handle<Map> map,
808 Label* early_success,
809 CompareMapMode mode = REQUIRE_EXACT_MAP);
810
811 // Check if the map of an object is equal to a specified map and branch to
812 // label if not. Skip the smi check if not required (object is known to be a
813 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
814 // against maps that are ElementsKind transition maps of the specified map.
Andrei Popescu31002712010-02-23 13:46:05 +0000815 void CheckMap(Register obj,
816 Register scratch,
817 Handle<Map> map,
818 Label* fail,
Ben Murdochc7cc0282012-03-05 14:35:55 +0000819 SmiCheckType smi_check_type,
820 CompareMapMode mode = REQUIRE_EXACT_MAP);
Ben Murdoch257744e2011-11-30 15:57:28 +0000821
Andrei Popescu31002712010-02-23 13:46:05 +0000822
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100823 void CheckMap(Register obj,
824 Register scratch,
825 Heap::RootListIndex index,
826 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000827 SmiCheckType smi_check_type);
828
829
830 // Check if the map of an object is equal to a specified map and branch to a
831 // specified target if equal. Skip the smi check if not required (object is
832 // known to be a heap object)
833 void DispatchMap(Register obj,
834 Register scratch,
835 Handle<Map> map,
836 Handle<Code> success,
837 SmiCheckType smi_check_type);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100838
839
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100840 // Compare the object in a register to a value from the root list.
841 // Uses the ip register as scratch.
842 void CompareRoot(Register obj, Heap::RootListIndex index);
843
844
Andrei Popescu31002712010-02-23 13:46:05 +0000845 // Load and check the instance type of an object for being a string.
846 // Loads the type into the second argument register.
847 // Returns a condition that will be enabled if the object was a string.
848 Condition IsObjectStringType(Register obj,
849 Register type) {
850 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset));
851 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
852 tst(type, Operand(kIsNotStringMask));
853 ASSERT_EQ(0, kStringTag);
854 return eq;
855 }
856
857
Steve Blocka7e24c12009-10-30 11:49:00 +0000858 // Generates code for reporting that an illegal operation has
859 // occurred.
860 void IllegalOperation(int num_arguments);
861
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100862 // Picks out an array index from the hash field.
863 // Register use:
864 // hash - holds the index's hash. Clobbered.
865 // index - holds the overwritten index on exit.
866 void IndexFromHash(Register hash, Register index);
867
Andrei Popescu31002712010-02-23 13:46:05 +0000868 // Get the number of least significant bits from a register
869 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +0100870 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +0000871
Steve Blockd0582a62009-12-15 09:54:21 +0000872 // Uses VFP instructions to Convert a Smi to a double.
873 void IntegerToDoubleConversionWithVFP3(Register inReg,
874 Register outHighReg,
875 Register outLowReg);
876
Steve Block8defd9f2010-07-08 12:39:36 +0100877 // Load the value of a number object into a VFP double register. If the object
878 // is not a number a jump to the label not_number is performed and the VFP
879 // double register is unchanged.
880 void ObjectToDoubleVFPRegister(
881 Register object,
882 DwVfpRegister value,
883 Register scratch1,
884 Register scratch2,
885 Register heap_number_map,
886 SwVfpRegister scratch3,
887 Label* not_number,
888 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
889
890 // Load the value of a smi object into a VFP double register. The register
891 // scratch1 can be the same register as smi in which case smi will hold the
892 // untagged value afterwards.
893 void SmiToDoubleVFPRegister(Register smi,
894 DwVfpRegister value,
895 Register scratch1,
896 SwVfpRegister scratch2);
897
Iain Merrick9ac36c92010-09-13 15:29:50 +0100898 // Convert the HeapNumber pointed to by source to a 32bits signed integer
899 // dest. If the HeapNumber does not fit into a 32bits signed integer branch
Steve Block1e0659c2011-05-24 12:43:12 +0100900 // to not_int32 label. If VFP3 is available double_scratch is used but not
901 // scratch2.
Iain Merrick9ac36c92010-09-13 15:29:50 +0100902 void ConvertToInt32(Register source,
903 Register dest,
904 Register scratch,
905 Register scratch2,
Steve Block1e0659c2011-05-24 12:43:12 +0100906 DwVfpRegister double_scratch,
Iain Merrick9ac36c92010-09-13 15:29:50 +0100907 Label *not_int32);
908
Steve Block44f0eee2011-05-26 01:26:41 +0100909 // Truncates a double using a specific rounding mode.
910 // Clears the z flag (ne condition) if an overflow occurs.
911 // If exact_conversion is true, the z flag is also cleared if the conversion
Ben Murdochc7cc0282012-03-05 14:35:55 +0000912 // was inexact, i.e. if the double value could not be converted exactly
Steve Block44f0eee2011-05-26 01:26:41 +0100913 // to a 32bit integer.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100914 void EmitVFPTruncate(VFPRoundingMode rounding_mode,
915 SwVfpRegister result,
916 DwVfpRegister double_input,
917 Register scratch1,
918 Register scratch2,
919 CheckForInexactConversion check
920 = kDontCheckForInexactConversion);
921
Steve Block44f0eee2011-05-26 01:26:41 +0100922 // Helper for EmitECMATruncate.
923 // This will truncate a floating-point value outside of the singed 32bit
924 // integer range to a 32bit signed integer.
925 // Expects the double value loaded in input_high and input_low.
926 // Exits with the answer in 'result'.
927 // Note that this code does not work for values in the 32bit range!
928 void EmitOutOfInt32RangeTruncate(Register result,
929 Register input_high,
930 Register input_low,
931 Register scratch);
932
933 // Performs a truncating conversion of a floating point number as used by
934 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
935 // Exits with 'result' holding the answer and all other registers clobbered.
936 void EmitECMATruncate(Register result,
937 DwVfpRegister double_input,
938 SwVfpRegister single_scratch,
939 Register scratch,
940 Register scratch2,
941 Register scratch3);
942
Steve Block6ded16b2010-05-10 14:33:55 +0100943 // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz
944 // instruction. On pre-ARM5 hardware this routine gives the wrong answer
Steve Block8defd9f2010-07-08 12:39:36 +0100945 // for 0 (31 instead of 32). Source and scratch can be the same in which case
946 // the source is clobbered. Source and zeros can also be the same in which
947 // case scratch should be a different register.
948 void CountLeadingZeros(Register zeros,
949 Register source,
950 Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000951
952 // ---------------------------------------------------------------------------
953 // Runtime calls
954
955 // Call a code stub.
956 void CallStub(CodeStub* stub, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000957
Andrei Popescu31002712010-02-23 13:46:05 +0000958 // Call a code stub.
959 void TailCallStub(CodeStub* stub, Condition cond = al);
960
Steve Blocka7e24c12009-10-30 11:49:00 +0000961 // Call a runtime routine.
Steve Block44f0eee2011-05-26 01:26:41 +0100962 void CallRuntime(const Runtime::Function* f, int num_arguments);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100963 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000964
965 // Convenience function: Same as above, but takes the fid instead.
966 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
967
Andrei Popescu402d9372010-02-26 13:31:12 +0000968 // Convenience function: call an external reference.
969 void CallExternalReference(const ExternalReference& ext,
970 int num_arguments);
971
Steve Blocka7e24c12009-10-30 11:49:00 +0000972 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100973 // Like JumpToExternalReference, but also takes care of passing the number
Steve Blocka7e24c12009-10-30 11:49:00 +0000974 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +0100975 void TailCallExternalReference(const ExternalReference& ext,
976 int num_arguments,
977 int result_size);
978
979 // Convenience function: tail call a runtime routine (jump).
980 void TailCallRuntime(Runtime::FunctionId fid,
Steve Blocka7e24c12009-10-30 11:49:00 +0000981 int num_arguments,
982 int result_size);
983
Ben Murdoch257744e2011-11-30 15:57:28 +0000984 int CalculateStackPassedWords(int num_reg_arguments,
985 int num_double_arguments);
986
Steve Block6ded16b2010-05-10 14:33:55 +0100987 // Before calling a C-function from generated code, align arguments on stack.
988 // After aligning the frame, non-register arguments must be stored in
989 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
Ben Murdoch257744e2011-11-30 15:57:28 +0000990 // are word sized. If double arguments are used, this function assumes that
991 // all double arguments are stored before core registers; otherwise the
992 // correct alignment of the double values is not guaranteed.
Steve Block6ded16b2010-05-10 14:33:55 +0100993 // Some compilers/platforms require the stack to be aligned when calling
994 // C++ code.
995 // Needs a scratch register to do some arithmetic. This register will be
996 // trashed.
Ben Murdoch257744e2011-11-30 15:57:28 +0000997 void PrepareCallCFunction(int num_reg_arguments,
998 int num_double_registers,
999 Register scratch);
1000 void PrepareCallCFunction(int num_reg_arguments,
1001 Register scratch);
1002
1003 // There are two ways of passing double arguments on ARM, depending on
1004 // whether soft or hard floating point ABI is used. These functions
1005 // abstract parameter passing for the three different ways we call
1006 // C functions from generated code.
1007 void SetCallCDoubleArguments(DoubleRegister dreg);
1008 void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2);
1009 void SetCallCDoubleArguments(DoubleRegister dreg, Register reg);
Steve Block6ded16b2010-05-10 14:33:55 +01001010
1011 // Calls a C function and cleans up the space for arguments allocated
1012 // by PrepareCallCFunction. The called function is not allowed to trigger a
1013 // garbage collection, since that might move the code and invalidate the
1014 // return address (unless this is somehow accounted for by the called
1015 // function).
1016 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001017 void CallCFunction(Register function, int num_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00001018 void CallCFunction(ExternalReference function,
1019 int num_reg_arguments,
1020 int num_double_arguments);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001021 void CallCFunction(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001022 int num_reg_arguments,
1023 int num_double_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +01001024
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001025 void GetCFunctionDoubleResult(const DoubleRegister dst);
1026
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001027 // Calls an API function. Allocates HandleScope, extracts returned value
1028 // from handle and propagates exceptions. Restores context. stack_space
Ben Murdochc7cc0282012-03-05 14:35:55 +00001029 // - space to be unwound on exit (includes the call JS arguments space and
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001030 // the additional space allocated for the fast call).
1031 void CallApiFunctionAndReturn(ExternalReference function, int stack_space);
Steve Block1e0659c2011-05-24 12:43:12 +01001032
Steve Blocka7e24c12009-10-30 11:49:00 +00001033 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +01001034 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +00001035
1036 // Invoke specified builtin JavaScript function. Adds an entry to
1037 // the unresolved list if the name does not resolve.
Ben Murdochb8e0da22011-05-16 14:20:40 +01001038 void InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +00001039 InvokeFlag flag,
1040 const CallWrapper& call_wrapper = NullCallWrapper());
Steve Blocka7e24c12009-10-30 11:49:00 +00001041
1042 // Store the code object for the given builtin in the target register and
1043 // setup the function in r1.
1044 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1045
Steve Block791712a2010-08-27 10:21:07 +01001046 // Store the function for the given builtin in the target register.
1047 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1048
Ben Murdoch8b112d22011-06-08 16:22:53 +01001049 Handle<Object> CodeObject() {
1050 ASSERT(!code_object_.is_null());
1051 return code_object_;
1052 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001053
1054
1055 // ---------------------------------------------------------------------------
1056 // StatsCounter support
1057
1058 void SetCounter(StatsCounter* counter, int value,
1059 Register scratch1, Register scratch2);
1060 void IncrementCounter(StatsCounter* counter, int value,
1061 Register scratch1, Register scratch2);
1062 void DecrementCounter(StatsCounter* counter, int value,
1063 Register scratch1, Register scratch2);
1064
1065
1066 // ---------------------------------------------------------------------------
1067 // Debugging
1068
Steve Block1e0659c2011-05-24 12:43:12 +01001069 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +00001070 // Use --debug_code to enable.
Steve Block1e0659c2011-05-24 12:43:12 +01001071 void Assert(Condition cond, const char* msg);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01001072 void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
Iain Merrick75681382010-08-19 15:07:18 +01001073 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +00001074
1075 // Like Assert(), but always enabled.
Steve Block1e0659c2011-05-24 12:43:12 +01001076 void Check(Condition cond, const char* msg);
Steve Blocka7e24c12009-10-30 11:49:00 +00001077
1078 // Print a message to stdout and abort execution.
1079 void Abort(const char* msg);
1080
1081 // Verify restrictions about code generated in stubs.
1082 void set_generating_stub(bool value) { generating_stub_ = value; }
1083 bool generating_stub() { return generating_stub_; }
1084 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1085 bool allow_stub_calls() { return allow_stub_calls_; }
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001086 void set_has_frame(bool value) { has_frame_ = value; }
1087 bool has_frame() { return has_frame_; }
1088 inline bool AllowThisStubCall(CodeStub* stub);
Steve Blocka7e24c12009-10-30 11:49:00 +00001089
Ben Murdoch257744e2011-11-30 15:57:28 +00001090 // EABI variant for double arguments in use.
1091 bool use_eabi_hardfloat() {
1092#if USE_EABI_HARDFLOAT
1093 return true;
1094#else
1095 return false;
1096#endif
1097 }
1098
Leon Clarked91b9f72010-01-27 17:25:45 +00001099 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +01001100 // Number utilities
1101
1102 // Check whether the value of reg is a power of two and not zero. If not
1103 // control continues at the label not_power_of_two. If reg is a power of two
1104 // the register scratch contains the value of (reg - 1) when control falls
1105 // through.
1106 void JumpIfNotPowerOfTwoOrZero(Register reg,
1107 Register scratch,
1108 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +01001109 // Check whether the value of reg is a power of two and not zero.
1110 // Control falls through if it is, with scratch containing the mask
1111 // value (reg - 1).
1112 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
1113 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
1114 // strictly positive but not a power of two.
1115 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
1116 Register scratch,
1117 Label* zero_and_neg,
1118 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +01001119
1120 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +00001121 // Smi utilities
1122
Ben Murdochb0fe1622011-05-05 13:52:32 +01001123 void SmiTag(Register reg, SBit s = LeaveCC) {
1124 add(reg, reg, Operand(reg), s);
1125 }
Steve Block1e0659c2011-05-24 12:43:12 +01001126 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
1127 add(dst, src, Operand(src), s);
1128 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001129
Ben Murdochb8e0da22011-05-16 14:20:40 +01001130 // Try to convert int32 to smi. If the value is to large, preserve
1131 // the original value and jump to not_a_smi. Destroys scratch and
1132 // sets flags.
1133 void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) {
1134 mov(scratch, reg);
1135 SmiTag(scratch, SetCC);
1136 b(vs, not_a_smi);
1137 mov(reg, scratch);
1138 }
1139
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001140 void SmiUntag(Register reg, SBit s = LeaveCC) {
1141 mov(reg, Operand(reg, ASR, kSmiTagSize), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001142 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001143 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
1144 mov(dst, Operand(src, ASR, kSmiTagSize), s);
Steve Block1e0659c2011-05-24 12:43:12 +01001145 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001146
Steve Block1e0659c2011-05-24 12:43:12 +01001147 // Jump the register contains a smi.
1148 inline void JumpIfSmi(Register value, Label* smi_label) {
1149 tst(value, Operand(kSmiTagMask));
1150 b(eq, smi_label);
1151 }
1152 // Jump if either of the registers contain a non-smi.
1153 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
1154 tst(value, Operand(kSmiTagMask));
1155 b(ne, not_smi_label);
1156 }
Andrei Popescu31002712010-02-23 13:46:05 +00001157 // Jump if either of the registers contain a non-smi.
1158 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1159 // Jump if either of the registers contain a smi.
1160 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1161
Iain Merrick75681382010-08-19 15:07:18 +01001162 // Abort execution if argument is a smi. Used in debug code.
1163 void AbortIfSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +01001164 void AbortIfNotSmi(Register object);
1165
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001166 // Abort execution if argument is a string. Used in debug code.
1167 void AbortIfNotString(Register object);
1168
Steve Block1e0659c2011-05-24 12:43:12 +01001169 // Abort execution if argument is not the root value with the given index.
1170 void AbortIfNotRootValue(Register src,
1171 Heap::RootListIndex root_value_index,
1172 const char* message);
1173
1174 // ---------------------------------------------------------------------------
1175 // HeapNumber utilities
1176
1177 void JumpIfNotHeapNumber(Register object,
1178 Register heap_number_map,
1179 Register scratch,
1180 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +01001181
Andrei Popescu31002712010-02-23 13:46:05 +00001182 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +00001183 // String utilities
1184
1185 // Checks if both objects are sequential ASCII strings and jumps to label
1186 // if either is not. Assumes that neither object is a smi.
1187 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1,
1188 Register object2,
1189 Register scratch1,
1190 Register scratch2,
Steve Block6ded16b2010-05-10 14:33:55 +01001191 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +00001192
1193 // Checks if both objects are sequential ASCII strings and jumps to label
1194 // if either is not.
1195 void JumpIfNotBothSequentialAsciiStrings(Register first,
1196 Register second,
1197 Register scratch1,
1198 Register scratch2,
1199 Label* not_flat_ascii_strings);
1200
Steve Block6ded16b2010-05-10 14:33:55 +01001201 // Checks if both instance types are sequential ASCII strings and jumps to
1202 // label if either is not.
1203 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1204 Register first_object_instance_type,
1205 Register second_object_instance_type,
1206 Register scratch1,
1207 Register scratch2,
1208 Label* failure);
1209
1210 // Check if instance type is sequential ASCII string and jump to label if
1211 // it is not.
1212 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1213 Register scratch,
1214 Label* failure);
1215
1216
Steve Block1e0659c2011-05-24 12:43:12 +01001217 // ---------------------------------------------------------------------------
1218 // Patching helpers.
1219
1220 // Get the location of a relocated constant (its address in the constant pool)
1221 // from its load site.
1222 void GetRelocatedValueLocation(Register ldr_location,
1223 Register result);
1224
1225
Ben Murdoch257744e2011-11-30 15:57:28 +00001226 void ClampUint8(Register output_reg, Register input_reg);
1227
1228 void ClampDoubleToUint8(Register result_reg,
1229 DoubleRegister input_reg,
1230 DoubleRegister temp_double_reg);
1231
1232
1233 void LoadInstanceDescriptors(Register map, Register descriptors);
1234
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001235 // Activation support.
1236 void EnterFrame(StackFrame::Type type);
1237 void LeaveFrame(StackFrame::Type type);
1238
Steve Blocka7e24c12009-10-30 11:49:00 +00001239 private:
Steve Block44f0eee2011-05-26 01:26:41 +01001240 void CallCFunctionHelper(Register function,
Ben Murdoch257744e2011-11-30 15:57:28 +00001241 int num_reg_arguments,
1242 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001243
Andrei Popescu31002712010-02-23 13:46:05 +00001244 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +00001245
1246 // Helper functions for generating invokes.
1247 void InvokePrologue(const ParameterCount& expected,
1248 const ParameterCount& actual,
1249 Handle<Code> code_constant,
1250 Register code_reg,
1251 Label* done,
Ben Murdochc7cc0282012-03-05 14:35:55 +00001252 bool* definitely_mismatches,
Ben Murdochb8e0da22011-05-16 14:20:40 +01001253 InvokeFlag flag,
Ben Murdoch257744e2011-11-30 15:57:28 +00001254 const CallWrapper& call_wrapper,
1255 CallKind call_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +00001256
Steve Block6ded16b2010-05-10 14:33:55 +01001257 void InitializeNewString(Register string,
1258 Register length,
1259 Heap::RootListIndex map_index,
1260 Register scratch1,
1261 Register scratch2);
1262
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001263 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1264 void InNewSpace(Register object,
1265 Register scratch,
1266 Condition cond, // eq for new space, ne otherwise.
1267 Label* branch);
1268
1269 // Helper for finding the mark bits for an address. Afterwards, the
1270 // bitmap register points at the word with the mark bits and the mask
1271 // the position of the first bit. Leaves addr_reg unchanged.
1272 inline void GetMarkBits(Register addr_reg,
1273 Register bitmap_reg,
1274 Register mask_reg);
1275
1276 // Helper for throwing exceptions. Compute a handler address and jump to
1277 // it. See the implementation for register usage.
1278 void JumpToHandlerEntry();
1279
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001280 // Compute memory operands for safepoint stack slots.
1281 static int SafepointRegisterStackIndex(int reg_code);
1282 MemOperand SafepointRegisterSlot(Register reg);
1283 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
1284
Andrei Popescu31002712010-02-23 13:46:05 +00001285 bool generating_stub_;
1286 bool allow_stub_calls_;
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001287 bool has_frame_;
Andrei Popescu31002712010-02-23 13:46:05 +00001288 // This handle will be patched with the code object on installation.
1289 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001290
1291 // Needs access to SafepointRegisterStackIndex for optimized frame
1292 // traversal.
1293 friend class OptimizedFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +00001294};
1295
1296
1297#ifdef ENABLE_DEBUGGER_SUPPORT
1298// The code patcher is used to patch (typically) small parts of code e.g. for
1299// debugging and other types of instrumentation. When using the code patcher
1300// the exact number of bytes specified must be emitted. It is not legal to emit
1301// relocation information. If any of these constraints are violated it causes
1302// an assertion to fail.
1303class CodePatcher {
1304 public:
1305 CodePatcher(byte* address, int instructions);
1306 virtual ~CodePatcher();
1307
1308 // Macro assembler to emit code.
1309 MacroAssembler* masm() { return &masm_; }
1310
1311 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001312 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001313
1314 // Emit an address directly.
1315 void Emit(Address addr);
1316
Steve Block1e0659c2011-05-24 12:43:12 +01001317 // Emit the condition part of an instruction leaving the rest of the current
1318 // instruction unchanged.
1319 void EmitCondition(Condition cond);
1320
Steve Blocka7e24c12009-10-30 11:49:00 +00001321 private:
1322 byte* address_; // The address of the code being patched.
1323 int instructions_; // Number of instructions of the expected patch size.
1324 int size_; // Number of bytes of the expected patch size.
1325 MacroAssembler masm_; // Macro assembler used to generate the code.
1326};
1327#endif // ENABLE_DEBUGGER_SUPPORT
1328
1329
1330// -----------------------------------------------------------------------------
1331// Static helper functions.
1332
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001333inline MemOperand ContextOperand(Register context, int index) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001334 return MemOperand(context, Context::SlotOffset(index));
1335}
1336
1337
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001338inline MemOperand GlobalObjectOperand() {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001339 return ContextOperand(cp, Context::GLOBAL_INDEX);
1340}
1341
1342
Steve Blocka7e24c12009-10-30 11:49:00 +00001343#ifdef GENERATED_CODE_COVERAGE
1344#define CODE_COVERAGE_STRINGIFY(x) #x
1345#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1346#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1347#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1348#else
1349#define ACCESS_MASM(masm) masm->
1350#endif
1351
1352
1353} } // namespace v8::internal
1354
1355#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_