blob: 2b81c086787f34941694864ccb5b6f1ce003cefb [file] [log] [blame]
Ben Murdochb0fe1622011-05-05 13:52:32 +01001// Copyright 2010 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"
32
33namespace v8 {
34namespace internal {
35
Ben Murdochb8e0da22011-05-16 14:20:40 +010036// Forward declaration.
Steve Block44f0eee2011-05-26 01:26:41 +010037class CallWrapper;
Ben Murdochb8e0da22011-05-16 14:20:40 +010038
Andrei Popescu31002712010-02-23 13:46:05 +000039// ----------------------------------------------------------------------------
40// Static helper functions
41
42// Generate a MemOperand for loading a field from an object.
43static inline MemOperand FieldMemOperand(Register object, int offset) {
44 return MemOperand(object, offset - kHeapObjectTag);
45}
46
Steve Blocka7e24c12009-10-30 11:49:00 +000047
Steve Block1e0659c2011-05-24 12:43:12 +010048static inline Operand SmiUntagOperand(Register object) {
49 return Operand(object, ASR, kSmiTagSize);
50}
51
52
53
Steve Blocka7e24c12009-10-30 11:49:00 +000054// Give alias names to registers
55const Register cp = { 8 }; // JavaScript context pointer
Andrei Popescu31002712010-02-23 13:46:05 +000056const Register roots = { 10 }; // Roots array pointer.
Steve Blocka7e24c12009-10-30 11:49:00 +000057
58enum InvokeJSFlags {
59 CALL_JS,
60 JUMP_JS
61};
62
63
Kristian Monsen25f61362010-05-21 11:50:48 +010064// Flags used for the AllocateInNewSpace functions.
65enum AllocationFlags {
66 // No special flags.
67 NO_ALLOCATION_FLAGS = 0,
68 // Return the pointer to the allocated already tagged as a heap object.
69 TAG_OBJECT = 1 << 0,
70 // The content of the result register already contains the allocation top in
71 // new space.
72 RESULT_CONTAINS_TOP = 1 << 1,
73 // Specify that the requested size of the space to allocate is specified in
74 // words instead of bytes.
75 SIZE_IN_WORDS = 1 << 2
76};
77
78
Steve Block8defd9f2010-07-08 12:39:36 +010079// Flags used for the ObjectToDoubleVFPRegister function.
80enum ObjectToDoubleFlags {
81 // No special flags.
82 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
83 // Object is known to be a non smi.
84 OBJECT_NOT_SMI = 1 << 0,
85 // Don't load NaNs or infinities, branch to the non number case instead.
86 AVOID_NANS_AND_INFINITIES = 1 << 1
87};
88
89
Steve Blocka7e24c12009-10-30 11:49:00 +000090// MacroAssembler implements a collection of frequently used macros.
91class MacroAssembler: public Assembler {
92 public:
93 MacroAssembler(void* buffer, int size);
94
Andrei Popescu31002712010-02-23 13:46:05 +000095 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +000096 void Jump(Register target, Condition cond = al);
97 void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = al);
98 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
Steve Block44f0eee2011-05-26 01:26:41 +010099 int CallSize(Register target, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000100 void Call(Register target, Condition cond = al);
Steve Block44f0eee2011-05-26 01:26:41 +0100101 int CallSize(byte* target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000102 void Call(byte* target, RelocInfo::Mode rmode, Condition cond = al);
Steve Block44f0eee2011-05-26 01:26:41 +0100103 int CallSize(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000104 void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
105 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +0000106
107 // Emit code to discard a non-negative number of pointer-sized elements
108 // from the stack, clobbering only the sp register.
109 void Drop(int count, Condition cond = al);
110
Ben Murdochb0fe1622011-05-05 13:52:32 +0100111 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100112
113 // Swap two registers. If the scratch register is omitted then a slightly
114 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100115 void Swap(Register reg1,
116 Register reg2,
117 Register scratch = no_reg,
118 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100119
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100120
121 void And(Register dst, Register src1, const Operand& src2,
122 Condition cond = al);
123 void Ubfx(Register dst, Register src, int lsb, int width,
124 Condition cond = al);
125 void Sbfx(Register dst, Register src, int lsb, int width,
126 Condition cond = al);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100127 // The scratch register is not used for ARMv7.
128 // scratch can be the same register as src (in which case it is trashed), but
129 // not the same as dst.
130 void Bfi(Register dst,
131 Register src,
132 Register scratch,
133 int lsb,
134 int width,
135 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100136 void Bfc(Register dst, int lsb, int width, Condition cond = al);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100137 void Usat(Register dst, int satpos, const Operand& src,
138 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100139
Leon Clarkee46be812010-01-19 14:06:41 +0000140 void Call(Label* target);
141 void Move(Register dst, Handle<Object> value);
Steve Block6ded16b2010-05-10 14:33:55 +0100142 // May do nothing if the registers are identical.
143 void Move(Register dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000144 // Jumps to the label at the index given by the Smi in "index".
145 void SmiJumpTable(Register index, Vector<Label*> targets);
146 // Load an object from the root table.
147 void LoadRoot(Register destination,
148 Heap::RootListIndex index,
149 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100150 // Store an object to the root table.
151 void StoreRoot(Register source,
152 Heap::RootListIndex index,
153 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000154
Steve Block6ded16b2010-05-10 14:33:55 +0100155
156 // Check if object is in new space.
157 // scratch can be object itself, but it will be clobbered.
158 void InNewSpace(Register object,
159 Register scratch,
Steve Block1e0659c2011-05-24 12:43:12 +0100160 Condition cond, // eq for new space, ne otherwise
Steve Block6ded16b2010-05-10 14:33:55 +0100161 Label* branch);
162
163
Steve Block8defd9f2010-07-08 12:39:36 +0100164 // For the page containing |object| mark the region covering [address]
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100165 // dirty. The object address must be in the first 8K of an allocated page.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100166 void RecordWriteHelper(Register object,
Steve Block8defd9f2010-07-08 12:39:36 +0100167 Register address,
168 Register scratch);
Steve Block6ded16b2010-05-10 14:33:55 +0100169
Steve Block8defd9f2010-07-08 12:39:36 +0100170 // For the page containing |object| mark the region covering
171 // [object+offset] dirty. The object address must be in the first 8K
172 // of an allocated page. The 'scratch' registers are used in the
173 // implementation and all 3 registers are clobbered by the
174 // operation, as well as the ip register. RecordWrite updates the
175 // write barrier even when storing smis.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100176 void RecordWrite(Register object,
177 Operand offset,
178 Register scratch0,
179 Register scratch1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000180
Steve Block8defd9f2010-07-08 12:39:36 +0100181 // For the page containing |object| mark the region covering
182 // [address] dirty. The object address must be in the first 8K of an
183 // allocated page. All 3 registers are clobbered by the operation,
184 // as well as the ip register. RecordWrite updates the write barrier
185 // even when storing smis.
186 void RecordWrite(Register object,
187 Register address,
188 Register scratch);
189
Steve Block6ded16b2010-05-10 14:33:55 +0100190 // Push two registers. Pushes leftmost register first (to highest address).
191 void Push(Register src1, Register src2, Condition cond = al) {
192 ASSERT(!src1.is(src2));
193 if (src1.code() > src2.code()) {
194 stm(db_w, sp, src1.bit() | src2.bit(), cond);
195 } else {
196 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
197 str(src2, MemOperand(sp, 4, NegPreIndex), cond);
198 }
199 }
200
201 // Push three registers. Pushes leftmost register first (to highest address).
202 void Push(Register src1, Register src2, Register src3, Condition cond = al) {
203 ASSERT(!src1.is(src2));
204 ASSERT(!src2.is(src3));
205 ASSERT(!src1.is(src3));
206 if (src1.code() > src2.code()) {
207 if (src2.code() > src3.code()) {
208 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
209 } else {
210 stm(db_w, sp, src1.bit() | src2.bit(), cond);
211 str(src3, MemOperand(sp, 4, NegPreIndex), cond);
212 }
213 } else {
214 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
215 Push(src2, src3, cond);
216 }
217 }
218
219 // Push four registers. Pushes leftmost register first (to highest address).
220 void Push(Register src1, Register src2,
221 Register src3, Register src4, Condition cond = al) {
222 ASSERT(!src1.is(src2));
223 ASSERT(!src2.is(src3));
224 ASSERT(!src1.is(src3));
225 ASSERT(!src1.is(src4));
226 ASSERT(!src2.is(src4));
227 ASSERT(!src3.is(src4));
228 if (src1.code() > src2.code()) {
229 if (src2.code() > src3.code()) {
230 if (src3.code() > src4.code()) {
231 stm(db_w,
232 sp,
233 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
234 cond);
235 } else {
236 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
237 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
238 }
239 } else {
240 stm(db_w, sp, src1.bit() | src2.bit(), cond);
241 Push(src3, src4, cond);
242 }
243 } else {
244 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
245 Push(src2, src3, src4, cond);
246 }
247 }
248
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100249 // Pop two registers. Pops rightmost register first (from lower address).
250 void Pop(Register src1, Register src2, Condition cond = al) {
251 ASSERT(!src1.is(src2));
252 if (src1.code() > src2.code()) {
253 ldm(ia_w, sp, src1.bit() | src2.bit(), cond);
254 } else {
255 ldr(src2, MemOperand(sp, 4, PostIndex), cond);
256 ldr(src1, MemOperand(sp, 4, PostIndex), cond);
257 }
258 }
259
Ben Murdochb0fe1622011-05-05 13:52:32 +0100260 // Push and pop the registers that can hold pointers, as defined by the
261 // RegList constant kSafepointSavedRegisters.
262 void PushSafepointRegisters();
263 void PopSafepointRegisters();
Ben Murdochb8e0da22011-05-16 14:20:40 +0100264 void PushSafepointRegistersAndDoubles();
265 void PopSafepointRegistersAndDoubles();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100266 // Store value in register src in the safepoint stack slot for
267 // register dst.
268 void StoreToSafepointRegisterSlot(Register src, Register dst);
269 void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
270 // Load the value of the src register from its safepoint stack slot
271 // into register dst.
272 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100273
Leon Clarkef7060e22010-06-03 12:02:55 +0100274 // Load two consecutive registers with two consecutive memory locations.
275 void Ldrd(Register dst1,
276 Register dst2,
277 const MemOperand& src,
278 Condition cond = al);
279
280 // Store two consecutive registers to two consecutive memory locations.
281 void Strd(Register src1,
282 Register src2,
283 const MemOperand& dst,
284 Condition cond = al);
285
Ben Murdochb8e0da22011-05-16 14:20:40 +0100286 // Clear specified FPSCR bits.
287 void ClearFPSCRBits(const uint32_t bits_to_clear,
288 const Register scratch,
289 const Condition cond = al);
290
291 // Compare double values and move the result to the normal condition flags.
292 void VFPCompareAndSetFlags(const DwVfpRegister src1,
293 const DwVfpRegister src2,
294 const Condition cond = al);
295 void VFPCompareAndSetFlags(const DwVfpRegister src1,
296 const double src2,
297 const Condition cond = al);
298
299 // Compare double values and then load the fpscr flags to a register.
300 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
301 const DwVfpRegister src2,
302 const Register fpscr_flags,
303 const Condition cond = al);
304 void VFPCompareAndLoadFlags(const DwVfpRegister src1,
305 const double src2,
306 const Register fpscr_flags,
307 const Condition cond = al);
308
Ben Murdoch086aeea2011-05-13 15:57:08 +0100309
Steve Blocka7e24c12009-10-30 11:49:00 +0000310 // ---------------------------------------------------------------------------
311 // Activation frames
312
313 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
314 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
315
316 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
317 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
318
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100319 // Enter exit frame.
Steve Block1e0659c2011-05-24 12:43:12 +0100320 // stack_space - extra stack space, used for alignment before call to C.
321 void EnterExitFrame(bool save_doubles, int stack_space = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
323 // Leave the current exit frame. Expects the return value in r0.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100324 // Expect the number of values, pushed prior to the exit frame, to
325 // remove in a register (or no_reg, if there is nothing to remove).
326 void LeaveExitFrame(bool save_doubles, Register argument_count);
Steve Blocka7e24c12009-10-30 11:49:00 +0000327
Steve Block6ded16b2010-05-10 14:33:55 +0100328 // Get the actual activation frame alignment for target environment.
329 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000330
Steve Blockd0582a62009-12-15 09:54:21 +0000331 void LoadContext(Register dst, int context_chain_length);
332
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800333 void LoadGlobalFunction(int index, Register function);
334
335 // Load the initial map from the global function. The registers
336 // function and map can be the same, function is then overwritten.
337 void LoadGlobalFunctionInitialMap(Register function,
338 Register map,
339 Register scratch);
340
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 // ---------------------------------------------------------------------------
342 // JavaScript invokes
343
344 // Invoke the JavaScript function code by either calling or jumping.
345 void InvokeCode(Register code,
346 const ParameterCount& expected,
347 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100348 InvokeFlag flag,
Steve Block44f0eee2011-05-26 01:26:41 +0100349 CallWrapper* call_wrapper = NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000350
351 void InvokeCode(Handle<Code> code,
352 const ParameterCount& expected,
353 const ParameterCount& actual,
354 RelocInfo::Mode rmode,
355 InvokeFlag flag);
356
357 // Invoke the JavaScript function in the given register. Changes the
358 // current context to the context in the function before invoking.
359 void InvokeFunction(Register function,
360 const ParameterCount& actual,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100361 InvokeFlag flag,
Steve Block44f0eee2011-05-26 01:26:41 +0100362 CallWrapper* call_wrapper = NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000363
Andrei Popescu402d9372010-02-26 13:31:12 +0000364 void InvokeFunction(JSFunction* function,
365 const ParameterCount& actual,
366 InvokeFlag flag);
367
Ben Murdochb0fe1622011-05-05 13:52:32 +0100368 void IsObjectJSObjectType(Register heap_object,
369 Register map,
370 Register scratch,
371 Label* fail);
372
373 void IsInstanceJSObjectType(Register map,
374 Register scratch,
375 Label* fail);
376
377 void IsObjectJSStringType(Register object,
378 Register scratch,
379 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000380
381#ifdef ENABLE_DEBUGGER_SUPPORT
382 // ---------------------------------------------------------------------------
383 // Debugger Support
384
Andrei Popescu402d9372010-02-26 13:31:12 +0000385 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000386#endif
387
388 // ---------------------------------------------------------------------------
389 // Exception handling
390
391 // Push a new try handler and link into try handler chain.
392 // The return address must be passed in register lr.
393 // On exit, r0 contains TOS (code slot).
394 void PushTryHandler(CodeLocation try_location, HandlerType type);
395
Leon Clarkee46be812010-01-19 14:06:41 +0000396 // Unlink the stack handler on top of the stack from the try handler chain.
397 // Must preserve the result register.
398 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000399
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100400 // Passes thrown value (in r0) to the handler of top of the try handler chain.
401 void Throw(Register value);
402
403 // Propagates an uncatchable exception to the top of the current JS stack's
404 // handler chain.
405 void ThrowUncatchable(UncatchableExceptionType type, Register value);
406
Steve Blocka7e24c12009-10-30 11:49:00 +0000407 // ---------------------------------------------------------------------------
408 // Inline caching support
409
Steve Blocka7e24c12009-10-30 11:49:00 +0000410 // Generate code for checking access rights - used for security checks
411 // on access to global objects across environments. The holder register
412 // is left untouched, whereas both scratch registers are clobbered.
413 void CheckAccessGlobalProxy(Register holder_reg,
414 Register scratch,
415 Label* miss);
416
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800417 inline void MarkCode(NopMarkerTypes type) {
418 nop(type);
419 }
420
421 // Check if the given instruction is a 'type' marker.
422 // ie. check if is is a mov r<type>, r<type> (referenced as nop(type))
423 // These instructions are generated to mark special location in the code,
424 // like some special IC code.
425 static inline bool IsMarkedCode(Instr instr, int type) {
426 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
427 return IsNop(instr, type);
428 }
429
430
431 static inline int GetCodeMarker(Instr instr) {
432 int dst_reg_offset = 12;
433 int dst_mask = 0xf << dst_reg_offset;
434 int src_mask = 0xf;
435 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
436 int src_reg = instr & src_mask;
437 uint32_t non_register_mask = ~(dst_mask | src_mask);
438 uint32_t mov_mask = al | 13 << 21;
439
440 // Return <n> if we have a mov rn rn, else return -1.
441 int type = ((instr & non_register_mask) == mov_mask) &&
442 (dst_reg == src_reg) &&
443 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
444 ? src_reg
445 : -1;
446 ASSERT((type == -1) ||
447 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
448 return type;
449 }
450
Steve Blocka7e24c12009-10-30 11:49:00 +0000451
452 // ---------------------------------------------------------------------------
453 // Allocation support
454
Ben Murdoch086aeea2011-05-13 15:57:08 +0100455 // Allocate an object in new space. The object_size is specified
456 // either in bytes or in words if the allocation flag SIZE_IN_WORDS
457 // is passed. If the new space is exhausted control continues at the
458 // gc_required label. The allocated object is returned in result. If
459 // the flag tag_allocated_object is true the result is tagged as as
460 // a heap object. All registers are clobbered also when control
461 // continues at the gc_required label.
Steve Blocka7e24c12009-10-30 11:49:00 +0000462 void AllocateInNewSpace(int object_size,
463 Register result,
464 Register scratch1,
465 Register scratch2,
466 Label* gc_required,
467 AllocationFlags flags);
468 void AllocateInNewSpace(Register object_size,
469 Register result,
470 Register scratch1,
471 Register scratch2,
472 Label* gc_required,
473 AllocationFlags flags);
474
475 // Undo allocation in new space. The object passed and objects allocated after
476 // it will no longer be allocated. The caller must make sure that no pointers
477 // are left to the object(s) no longer allocated as they would be invalid when
478 // allocation is undone.
479 void UndoAllocationInNewSpace(Register object, Register scratch);
480
Andrei Popescu31002712010-02-23 13:46:05 +0000481
482 void AllocateTwoByteString(Register result,
483 Register length,
484 Register scratch1,
485 Register scratch2,
486 Register scratch3,
487 Label* gc_required);
488 void AllocateAsciiString(Register result,
489 Register length,
490 Register scratch1,
491 Register scratch2,
492 Register scratch3,
493 Label* gc_required);
494 void AllocateTwoByteConsString(Register result,
495 Register length,
496 Register scratch1,
497 Register scratch2,
498 Label* gc_required);
499 void AllocateAsciiConsString(Register result,
500 Register length,
501 Register scratch1,
502 Register scratch2,
503 Label* gc_required);
504
Kristian Monsen25f61362010-05-21 11:50:48 +0100505 // Allocates a heap number or jumps to the gc_required label if the young
506 // space is full and a scavenge is needed. All registers are clobbered also
507 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100508 void AllocateHeapNumber(Register result,
509 Register scratch1,
510 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100511 Register heap_number_map,
Steve Block6ded16b2010-05-10 14:33:55 +0100512 Label* gc_required);
Steve Block8defd9f2010-07-08 12:39:36 +0100513 void AllocateHeapNumberWithValue(Register result,
514 DwVfpRegister value,
515 Register scratch1,
516 Register scratch2,
517 Register heap_number_map,
518 Label* gc_required);
519
Ben Murdochbb769b22010-08-11 14:56:33 +0100520 // Copies a fixed number of fields of heap objects from src to dst.
521 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000522
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100523 // Copies a number of bytes from src to dst. All registers are clobbered. On
524 // exit src and dst will point to the place just after where the last byte was
525 // read or written and length will be zero.
526 void CopyBytes(Register src,
527 Register dst,
528 Register length,
529 Register scratch);
530
Steve Blocka7e24c12009-10-30 11:49:00 +0000531 // ---------------------------------------------------------------------------
532 // Support functions.
533
534 // Try to get function prototype of a function and puts the value in
535 // the result register. Checks that the function really is a
536 // function and jumps to the miss label if the fast checks fail. The
537 // function register will be untouched; the other registers may be
538 // clobbered.
539 void TryGetFunctionPrototype(Register function,
540 Register result,
541 Register scratch,
542 Label* miss);
543
544 // Compare object type for heap object. heap_object contains a non-Smi
545 // whose object type should be compared with the given type. This both
546 // sets the flags and leaves the object type in the type_reg register.
547 // It leaves the map in the map register (unless the type_reg and map register
548 // are the same register). It leaves the heap object in the heap_object
549 // register unless the heap_object register is the same register as one of the
550 // other registers.
551 void CompareObjectType(Register heap_object,
552 Register map,
553 Register type_reg,
554 InstanceType type);
555
556 // Compare instance type in a map. map contains a valid map object whose
557 // object type should be compared with the given type. This both
558 // sets the flags and leaves the object type in the type_reg register. It
559 // leaves the heap object in the heap_object register unless the heap_object
560 // register is the same register as type_reg.
561 void CompareInstanceType(Register map,
562 Register type_reg,
563 InstanceType type);
564
Andrei Popescu31002712010-02-23 13:46:05 +0000565
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100566 // Check if the map of an object is equal to a specified map (either
567 // given directly or as an index into the root list) and branch to
568 // label if not. Skip the smi check if not required (object is known
569 // to be a heap object)
Andrei Popescu31002712010-02-23 13:46:05 +0000570 void CheckMap(Register obj,
571 Register scratch,
572 Handle<Map> map,
573 Label* fail,
574 bool is_heap_object);
575
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100576 void CheckMap(Register obj,
577 Register scratch,
578 Heap::RootListIndex index,
579 Label* fail,
580 bool is_heap_object);
581
582
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100583 // Compare the object in a register to a value from the root list.
584 // Uses the ip register as scratch.
585 void CompareRoot(Register obj, Heap::RootListIndex index);
586
587
Andrei Popescu31002712010-02-23 13:46:05 +0000588 // Load and check the instance type of an object for being a string.
589 // Loads the type into the second argument register.
590 // Returns a condition that will be enabled if the object was a string.
591 Condition IsObjectStringType(Register obj,
592 Register type) {
593 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset));
594 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
595 tst(type, Operand(kIsNotStringMask));
596 ASSERT_EQ(0, kStringTag);
597 return eq;
598 }
599
600
Steve Blocka7e24c12009-10-30 11:49:00 +0000601 // Generates code for reporting that an illegal operation has
602 // occurred.
603 void IllegalOperation(int num_arguments);
604
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100605 // Picks out an array index from the hash field.
606 // Register use:
607 // hash - holds the index's hash. Clobbered.
608 // index - holds the overwritten index on exit.
609 void IndexFromHash(Register hash, Register index);
610
Andrei Popescu31002712010-02-23 13:46:05 +0000611 // Get the number of least significant bits from a register
612 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
Steve Block1e0659c2011-05-24 12:43:12 +0100613 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
Andrei Popescu31002712010-02-23 13:46:05 +0000614
Steve Blockd0582a62009-12-15 09:54:21 +0000615 // Uses VFP instructions to Convert a Smi to a double.
616 void IntegerToDoubleConversionWithVFP3(Register inReg,
617 Register outHighReg,
618 Register outLowReg);
619
Steve Block8defd9f2010-07-08 12:39:36 +0100620 // Load the value of a number object into a VFP double register. If the object
621 // is not a number a jump to the label not_number is performed and the VFP
622 // double register is unchanged.
623 void ObjectToDoubleVFPRegister(
624 Register object,
625 DwVfpRegister value,
626 Register scratch1,
627 Register scratch2,
628 Register heap_number_map,
629 SwVfpRegister scratch3,
630 Label* not_number,
631 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
632
633 // Load the value of a smi object into a VFP double register. The register
634 // scratch1 can be the same register as smi in which case smi will hold the
635 // untagged value afterwards.
636 void SmiToDoubleVFPRegister(Register smi,
637 DwVfpRegister value,
638 Register scratch1,
639 SwVfpRegister scratch2);
640
Iain Merrick9ac36c92010-09-13 15:29:50 +0100641 // Convert the HeapNumber pointed to by source to a 32bits signed integer
642 // dest. If the HeapNumber does not fit into a 32bits signed integer branch
Steve Block1e0659c2011-05-24 12:43:12 +0100643 // to not_int32 label. If VFP3 is available double_scratch is used but not
644 // scratch2.
Iain Merrick9ac36c92010-09-13 15:29:50 +0100645 void ConvertToInt32(Register source,
646 Register dest,
647 Register scratch,
648 Register scratch2,
Steve Block1e0659c2011-05-24 12:43:12 +0100649 DwVfpRegister double_scratch,
Iain Merrick9ac36c92010-09-13 15:29:50 +0100650 Label *not_int32);
651
Steve Block44f0eee2011-05-26 01:26:41 +0100652 // Truncates a double using a specific rounding mode.
653 // Clears the z flag (ne condition) if an overflow occurs.
654 // If exact_conversion is true, the z flag is also cleared if the conversion
655 // was inexact, ie. if the double value could not be converted exactly
656 // to a 32bit integer.
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100657 void EmitVFPTruncate(VFPRoundingMode rounding_mode,
658 SwVfpRegister result,
659 DwVfpRegister double_input,
660 Register scratch1,
661 Register scratch2,
662 CheckForInexactConversion check
663 = kDontCheckForInexactConversion);
664
Steve Block44f0eee2011-05-26 01:26:41 +0100665 // Helper for EmitECMATruncate.
666 // This will truncate a floating-point value outside of the singed 32bit
667 // integer range to a 32bit signed integer.
668 // Expects the double value loaded in input_high and input_low.
669 // Exits with the answer in 'result'.
670 // Note that this code does not work for values in the 32bit range!
671 void EmitOutOfInt32RangeTruncate(Register result,
672 Register input_high,
673 Register input_low,
674 Register scratch);
675
676 // Performs a truncating conversion of a floating point number as used by
677 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
678 // Exits with 'result' holding the answer and all other registers clobbered.
679 void EmitECMATruncate(Register result,
680 DwVfpRegister double_input,
681 SwVfpRegister single_scratch,
682 Register scratch,
683 Register scratch2,
684 Register scratch3);
685
Steve Block6ded16b2010-05-10 14:33:55 +0100686 // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz
687 // instruction. On pre-ARM5 hardware this routine gives the wrong answer
Steve Block8defd9f2010-07-08 12:39:36 +0100688 // for 0 (31 instead of 32). Source and scratch can be the same in which case
689 // the source is clobbered. Source and zeros can also be the same in which
690 // case scratch should be a different register.
691 void CountLeadingZeros(Register zeros,
692 Register source,
693 Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000694
695 // ---------------------------------------------------------------------------
696 // Runtime calls
697
698 // Call a code stub.
699 void CallStub(CodeStub* stub, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000700
Andrei Popescu31002712010-02-23 13:46:05 +0000701 // Call a code stub.
702 void TailCallStub(CodeStub* stub, Condition cond = al);
703
Steve Block1e0659c2011-05-24 12:43:12 +0100704 // Tail call a code stub (jump) and return the code object called. Try to
705 // generate the code if necessary. Do not perform a GC but instead return
706 // a retry after GC failure.
707 MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub,
708 Condition cond = al);
709
Steve Blocka7e24c12009-10-30 11:49:00 +0000710 // Call a runtime routine.
Steve Block44f0eee2011-05-26 01:26:41 +0100711 void CallRuntime(const Runtime::Function* f, int num_arguments);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100712 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000713
714 // Convenience function: Same as above, but takes the fid instead.
715 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
716
Andrei Popescu402d9372010-02-26 13:31:12 +0000717 // Convenience function: call an external reference.
718 void CallExternalReference(const ExternalReference& ext,
719 int num_arguments);
720
Steve Blocka7e24c12009-10-30 11:49:00 +0000721 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100722 // Like JumpToExternalReference, but also takes care of passing the number
Steve Blocka7e24c12009-10-30 11:49:00 +0000723 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +0100724 void TailCallExternalReference(const ExternalReference& ext,
725 int num_arguments,
726 int result_size);
727
Steve Block1e0659c2011-05-24 12:43:12 +0100728 // Tail call of a runtime routine (jump). Try to generate the code if
729 // necessary. Do not perform a GC but instead return a retry after GC
730 // failure.
731 MUST_USE_RESULT MaybeObject* TryTailCallExternalReference(
732 const ExternalReference& ext, int num_arguments, int result_size);
733
Steve Block6ded16b2010-05-10 14:33:55 +0100734 // Convenience function: tail call a runtime routine (jump).
735 void TailCallRuntime(Runtime::FunctionId fid,
Steve Blocka7e24c12009-10-30 11:49:00 +0000736 int num_arguments,
737 int result_size);
738
Steve Block6ded16b2010-05-10 14:33:55 +0100739 // Before calling a C-function from generated code, align arguments on stack.
740 // After aligning the frame, non-register arguments must be stored in
741 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
742 // are word sized.
743 // Some compilers/platforms require the stack to be aligned when calling
744 // C++ code.
745 // Needs a scratch register to do some arithmetic. This register will be
746 // trashed.
747 void PrepareCallCFunction(int num_arguments, Register scratch);
748
749 // Calls a C function and cleans up the space for arguments allocated
750 // by PrepareCallCFunction. The called function is not allowed to trigger a
751 // garbage collection, since that might move the code and invalidate the
752 // return address (unless this is somehow accounted for by the called
753 // function).
754 void CallCFunction(ExternalReference function, int num_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +0100755 void CallCFunction(Register function, Register scratch, int num_arguments);
Steve Block6ded16b2010-05-10 14:33:55 +0100756
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100757 void GetCFunctionDoubleResult(const DoubleRegister dst);
758
Steve Block1e0659c2011-05-24 12:43:12 +0100759 // Calls an API function. Allocates HandleScope, extracts returned value
760 // from handle and propagates exceptions. Restores context.
761 // stack_space - space to be unwound on exit (includes the call js
762 // arguments space and the additional space allocated for the fast call).
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100763 MaybeObject* TryCallApiFunctionAndReturn(ExternalReference function,
Steve Block1e0659c2011-05-24 12:43:12 +0100764 int stack_space);
765
Steve Blocka7e24c12009-10-30 11:49:00 +0000766 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100767 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +0000768
Steve Block1e0659c2011-05-24 12:43:12 +0100769 MaybeObject* TryJumpToExternalReference(const ExternalReference& ext);
770
Steve Blocka7e24c12009-10-30 11:49:00 +0000771 // Invoke specified builtin JavaScript function. Adds an entry to
772 // the unresolved list if the name does not resolve.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100773 void InvokeBuiltin(Builtins::JavaScript id,
774 InvokeJSFlags flags,
Steve Block44f0eee2011-05-26 01:26:41 +0100775 CallWrapper* call_wrapper = NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000776
777 // Store the code object for the given builtin in the target register and
778 // setup the function in r1.
779 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
780
Steve Block791712a2010-08-27 10:21:07 +0100781 // Store the function for the given builtin in the target register.
782 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
783
Steve Blocka7e24c12009-10-30 11:49:00 +0000784 Handle<Object> CodeObject() { return code_object_; }
785
786
787 // ---------------------------------------------------------------------------
788 // StatsCounter support
789
790 void SetCounter(StatsCounter* counter, int value,
791 Register scratch1, Register scratch2);
792 void IncrementCounter(StatsCounter* counter, int value,
793 Register scratch1, Register scratch2);
794 void DecrementCounter(StatsCounter* counter, int value,
795 Register scratch1, Register scratch2);
796
797
798 // ---------------------------------------------------------------------------
799 // Debugging
800
Steve Block1e0659c2011-05-24 12:43:12 +0100801 // Calls Abort(msg) if the condition cond is not satisfied.
Steve Blocka7e24c12009-10-30 11:49:00 +0000802 // Use --debug_code to enable.
Steve Block1e0659c2011-05-24 12:43:12 +0100803 void Assert(Condition cond, const char* msg);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100804 void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
Iain Merrick75681382010-08-19 15:07:18 +0100805 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +0000806
807 // Like Assert(), but always enabled.
Steve Block1e0659c2011-05-24 12:43:12 +0100808 void Check(Condition cond, const char* msg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000809
810 // Print a message to stdout and abort execution.
811 void Abort(const char* msg);
812
813 // Verify restrictions about code generated in stubs.
814 void set_generating_stub(bool value) { generating_stub_ = value; }
815 bool generating_stub() { return generating_stub_; }
816 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
817 bool allow_stub_calls() { return allow_stub_calls_; }
818
Leon Clarked91b9f72010-01-27 17:25:45 +0000819 // ---------------------------------------------------------------------------
Steve Block1e0659c2011-05-24 12:43:12 +0100820 // Number utilities
821
822 // Check whether the value of reg is a power of two and not zero. If not
823 // control continues at the label not_power_of_two. If reg is a power of two
824 // the register scratch contains the value of (reg - 1) when control falls
825 // through.
826 void JumpIfNotPowerOfTwoOrZero(Register reg,
827 Register scratch,
828 Label* not_power_of_two_or_zero);
Steve Block44f0eee2011-05-26 01:26:41 +0100829 // Check whether the value of reg is a power of two and not zero.
830 // Control falls through if it is, with scratch containing the mask
831 // value (reg - 1).
832 // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is
833 // zero or negative, or jumps to the 'not_power_of_two' label if the value is
834 // strictly positive but not a power of two.
835 void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg,
836 Register scratch,
837 Label* zero_and_neg,
838 Label* not_power_of_two);
Steve Block1e0659c2011-05-24 12:43:12 +0100839
840 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000841 // Smi utilities
842
Ben Murdochb0fe1622011-05-05 13:52:32 +0100843 void SmiTag(Register reg, SBit s = LeaveCC) {
844 add(reg, reg, Operand(reg), s);
845 }
Steve Block1e0659c2011-05-24 12:43:12 +0100846 void SmiTag(Register dst, Register src, SBit s = LeaveCC) {
847 add(dst, src, Operand(src), s);
848 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100849
Ben Murdochb8e0da22011-05-16 14:20:40 +0100850 // Try to convert int32 to smi. If the value is to large, preserve
851 // the original value and jump to not_a_smi. Destroys scratch and
852 // sets flags.
853 void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) {
854 mov(scratch, reg);
855 SmiTag(scratch, SetCC);
856 b(vs, not_a_smi);
857 mov(reg, scratch);
858 }
859
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100860 void SmiUntag(Register reg, SBit s = LeaveCC) {
861 mov(reg, Operand(reg, ASR, kSmiTagSize), s);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100862 }
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100863 void SmiUntag(Register dst, Register src, SBit s = LeaveCC) {
864 mov(dst, Operand(src, ASR, kSmiTagSize), s);
Steve Block1e0659c2011-05-24 12:43:12 +0100865 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100866
Steve Block1e0659c2011-05-24 12:43:12 +0100867 // Jump the register contains a smi.
868 inline void JumpIfSmi(Register value, Label* smi_label) {
869 tst(value, Operand(kSmiTagMask));
870 b(eq, smi_label);
871 }
872 // Jump if either of the registers contain a non-smi.
873 inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
874 tst(value, Operand(kSmiTagMask));
875 b(ne, not_smi_label);
876 }
Andrei Popescu31002712010-02-23 13:46:05 +0000877 // Jump if either of the registers contain a non-smi.
878 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
879 // Jump if either of the registers contain a smi.
880 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
881
Iain Merrick75681382010-08-19 15:07:18 +0100882 // Abort execution if argument is a smi. Used in debug code.
883 void AbortIfSmi(Register object);
Steve Block1e0659c2011-05-24 12:43:12 +0100884 void AbortIfNotSmi(Register object);
885
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100886 // Abort execution if argument is a string. Used in debug code.
887 void AbortIfNotString(Register object);
888
Steve Block1e0659c2011-05-24 12:43:12 +0100889 // Abort execution if argument is not the root value with the given index.
890 void AbortIfNotRootValue(Register src,
891 Heap::RootListIndex root_value_index,
892 const char* message);
893
894 // ---------------------------------------------------------------------------
895 // HeapNumber utilities
896
897 void JumpIfNotHeapNumber(Register object,
898 Register heap_number_map,
899 Register scratch,
900 Label* on_not_heap_number);
Iain Merrick75681382010-08-19 15:07:18 +0100901
Andrei Popescu31002712010-02-23 13:46:05 +0000902 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +0000903 // String utilities
904
905 // Checks if both objects are sequential ASCII strings and jumps to label
906 // if either is not. Assumes that neither object is a smi.
907 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1,
908 Register object2,
909 Register scratch1,
910 Register scratch2,
Steve Block6ded16b2010-05-10 14:33:55 +0100911 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +0000912
913 // Checks if both objects are sequential ASCII strings and jumps to label
914 // if either is not.
915 void JumpIfNotBothSequentialAsciiStrings(Register first,
916 Register second,
917 Register scratch1,
918 Register scratch2,
919 Label* not_flat_ascii_strings);
920
Steve Block6ded16b2010-05-10 14:33:55 +0100921 // Checks if both instance types are sequential ASCII strings and jumps to
922 // label if either is not.
923 void JumpIfBothInstanceTypesAreNotSequentialAscii(
924 Register first_object_instance_type,
925 Register second_object_instance_type,
926 Register scratch1,
927 Register scratch2,
928 Label* failure);
929
930 // Check if instance type is sequential ASCII string and jump to label if
931 // it is not.
932 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
933 Register scratch,
934 Label* failure);
935
936
Steve Block1e0659c2011-05-24 12:43:12 +0100937 // ---------------------------------------------------------------------------
938 // Patching helpers.
939
940 // Get the location of a relocated constant (its address in the constant pool)
941 // from its load site.
942 void GetRelocatedValueLocation(Register ldr_location,
943 Register result);
944
945
Steve Blocka7e24c12009-10-30 11:49:00 +0000946 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100947 void CallCFunctionHelper(Register function,
948 ExternalReference function_reference,
949 Register scratch,
950 int num_arguments);
951
Andrei Popescu31002712010-02-23 13:46:05 +0000952 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Block44f0eee2011-05-26 01:26:41 +0100953 int CallSize(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Andrei Popescu31002712010-02-23 13:46:05 +0000954 void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000955
956 // Helper functions for generating invokes.
957 void InvokePrologue(const ParameterCount& expected,
958 const ParameterCount& actual,
959 Handle<Code> code_constant,
960 Register code_reg,
961 Label* done,
Ben Murdochb8e0da22011-05-16 14:20:40 +0100962 InvokeFlag flag,
Steve Block44f0eee2011-05-26 01:26:41 +0100963 CallWrapper* call_wrapper = NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000964
Steve Blocka7e24c12009-10-30 11:49:00 +0000965 // Activation support.
966 void EnterFrame(StackFrame::Type type);
967 void LeaveFrame(StackFrame::Type type);
Andrei Popescu31002712010-02-23 13:46:05 +0000968
Steve Block6ded16b2010-05-10 14:33:55 +0100969 void InitializeNewString(Register string,
970 Register length,
971 Heap::RootListIndex map_index,
972 Register scratch1,
973 Register scratch2);
974
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100975 // Compute memory operands for safepoint stack slots.
976 static int SafepointRegisterStackIndex(int reg_code);
977 MemOperand SafepointRegisterSlot(Register reg);
978 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
979
Andrei Popescu31002712010-02-23 13:46:05 +0000980 bool generating_stub_;
981 bool allow_stub_calls_;
982 // This handle will be patched with the code object on installation.
983 Handle<Object> code_object_;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100984
985 // Needs access to SafepointRegisterStackIndex for optimized frame
986 // traversal.
987 friend class OptimizedFrame;
Steve Blocka7e24c12009-10-30 11:49:00 +0000988};
989
990
991#ifdef ENABLE_DEBUGGER_SUPPORT
992// The code patcher is used to patch (typically) small parts of code e.g. for
993// debugging and other types of instrumentation. When using the code patcher
994// the exact number of bytes specified must be emitted. It is not legal to emit
995// relocation information. If any of these constraints are violated it causes
996// an assertion to fail.
997class CodePatcher {
998 public:
999 CodePatcher(byte* address, int instructions);
1000 virtual ~CodePatcher();
1001
1002 // Macro assembler to emit code.
1003 MacroAssembler* masm() { return &masm_; }
1004
1005 // Emit an instruction directly.
Steve Block1e0659c2011-05-24 12:43:12 +01001006 void Emit(Instr instr);
Steve Blocka7e24c12009-10-30 11:49:00 +00001007
1008 // Emit an address directly.
1009 void Emit(Address addr);
1010
Steve Block1e0659c2011-05-24 12:43:12 +01001011 // Emit the condition part of an instruction leaving the rest of the current
1012 // instruction unchanged.
1013 void EmitCondition(Condition cond);
1014
Steve Blocka7e24c12009-10-30 11:49:00 +00001015 private:
1016 byte* address_; // The address of the code being patched.
1017 int instructions_; // Number of instructions of the expected patch size.
1018 int size_; // Number of bytes of the expected patch size.
1019 MacroAssembler masm_; // Macro assembler used to generate the code.
1020};
1021#endif // ENABLE_DEBUGGER_SUPPORT
1022
1023
Ben Murdochb0fe1622011-05-05 13:52:32 +01001024// Helper class for generating code or data associated with the code
1025// right after a call instruction. As an example this can be used to
1026// generate safepoint data after calls for crankshaft.
Steve Block44f0eee2011-05-26 01:26:41 +01001027class CallWrapper {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001028 public:
Steve Block44f0eee2011-05-26 01:26:41 +01001029 CallWrapper() { }
1030 virtual ~CallWrapper() { }
1031 // Called just before emitting a call. Argument is the size of the generated
1032 // call code.
1033 virtual void BeforeCall(int call_size) = 0;
1034 // Called just after emitting a call, i.e., at the return site for the call.
1035 virtual void AfterCall() = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001036};
1037
1038
Steve Blocka7e24c12009-10-30 11:49:00 +00001039// -----------------------------------------------------------------------------
1040// Static helper functions.
1041
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08001042static MemOperand ContextOperand(Register context, int index) {
1043 return MemOperand(context, Context::SlotOffset(index));
1044}
1045
1046
1047static inline MemOperand GlobalObjectOperand() {
1048 return ContextOperand(cp, Context::GLOBAL_INDEX);
1049}
1050
1051
Steve Blocka7e24c12009-10-30 11:49:00 +00001052#ifdef GENERATED_CODE_COVERAGE
1053#define CODE_COVERAGE_STRINGIFY(x) #x
1054#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1055#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1056#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1057#else
1058#define ACCESS_MASM(masm) masm->
1059#endif
1060
1061
1062} } // namespace v8::internal
1063
1064#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_