blob: 02bc3846004c77f8be44a650da654647893e04c1 [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
Andrei Popescu31002712010-02-23 13:46:05 +000036// ----------------------------------------------------------------------------
37// Static helper functions
38
39// Generate a MemOperand for loading a field from an object.
40static inline MemOperand FieldMemOperand(Register object, int offset) {
41 return MemOperand(object, offset - kHeapObjectTag);
42}
43
Steve Blocka7e24c12009-10-30 11:49:00 +000044
45// Give alias names to registers
46const Register cp = { 8 }; // JavaScript context pointer
Andrei Popescu31002712010-02-23 13:46:05 +000047const Register roots = { 10 }; // Roots array pointer.
Steve Blocka7e24c12009-10-30 11:49:00 +000048
49enum InvokeJSFlags {
50 CALL_JS,
51 JUMP_JS
52};
53
54
Kristian Monsen25f61362010-05-21 11:50:48 +010055// Flags used for the AllocateInNewSpace functions.
56enum AllocationFlags {
57 // No special flags.
58 NO_ALLOCATION_FLAGS = 0,
59 // Return the pointer to the allocated already tagged as a heap object.
60 TAG_OBJECT = 1 << 0,
61 // The content of the result register already contains the allocation top in
62 // new space.
63 RESULT_CONTAINS_TOP = 1 << 1,
64 // Specify that the requested size of the space to allocate is specified in
65 // words instead of bytes.
66 SIZE_IN_WORDS = 1 << 2
67};
68
69
Steve Block8defd9f2010-07-08 12:39:36 +010070// Flags used for the ObjectToDoubleVFPRegister function.
71enum ObjectToDoubleFlags {
72 // No special flags.
73 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
74 // Object is known to be a non smi.
75 OBJECT_NOT_SMI = 1 << 0,
76 // Don't load NaNs or infinities, branch to the non number case instead.
77 AVOID_NANS_AND_INFINITIES = 1 << 1
78};
79
80
Steve Blocka7e24c12009-10-30 11:49:00 +000081// MacroAssembler implements a collection of frequently used macros.
82class MacroAssembler: public Assembler {
83 public:
84 MacroAssembler(void* buffer, int size);
85
Andrei Popescu31002712010-02-23 13:46:05 +000086 // Jump, Call, and Ret pseudo instructions implementing inter-working.
Steve Blocka7e24c12009-10-30 11:49:00 +000087 void Jump(Register target, Condition cond = al);
88 void Jump(byte* target, RelocInfo::Mode rmode, Condition cond = al);
89 void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
90 void Call(Register target, Condition cond = al);
91 void Call(byte* target, RelocInfo::Mode rmode, Condition cond = al);
92 void Call(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al);
93 void Ret(Condition cond = al);
Leon Clarkee46be812010-01-19 14:06:41 +000094
95 // Emit code to discard a non-negative number of pointer-sized elements
96 // from the stack, clobbering only the sp register.
97 void Drop(int count, Condition cond = al);
98
Ben Murdochb0fe1622011-05-05 13:52:32 +010099 void Ret(int drop, Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100100
101 // Swap two registers. If the scratch register is omitted then a slightly
102 // less efficient form using xor instead of mov is emitted.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100103 void Swap(Register reg1,
104 Register reg2,
105 Register scratch = no_reg,
106 Condition cond = al);
Steve Block6ded16b2010-05-10 14:33:55 +0100107
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100108
109 void And(Register dst, Register src1, const Operand& src2,
110 Condition cond = al);
111 void Ubfx(Register dst, Register src, int lsb, int width,
112 Condition cond = al);
113 void Sbfx(Register dst, Register src, int lsb, int width,
114 Condition cond = al);
115 void Bfc(Register dst, int lsb, int width, Condition cond = al);
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100116 void Usat(Register dst, int satpos, const Operand& src,
117 Condition cond = al);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100118
Leon Clarkee46be812010-01-19 14:06:41 +0000119 void Call(Label* target);
120 void Move(Register dst, Handle<Object> value);
Steve Block6ded16b2010-05-10 14:33:55 +0100121 // May do nothing if the registers are identical.
122 void Move(Register dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000123 // Jumps to the label at the index given by the Smi in "index".
124 void SmiJumpTable(Register index, Vector<Label*> targets);
125 // Load an object from the root table.
126 void LoadRoot(Register destination,
127 Heap::RootListIndex index,
128 Condition cond = al);
Kristian Monsen25f61362010-05-21 11:50:48 +0100129 // Store an object to the root table.
130 void StoreRoot(Register source,
131 Heap::RootListIndex index,
132 Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000133
Steve Block6ded16b2010-05-10 14:33:55 +0100134
135 // Check if object is in new space.
136 // scratch can be object itself, but it will be clobbered.
137 void InNewSpace(Register object,
138 Register scratch,
139 Condition cc, // eq for new space, ne otherwise
140 Label* branch);
141
142
Steve Block8defd9f2010-07-08 12:39:36 +0100143 // For the page containing |object| mark the region covering [address]
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100144 // dirty. The object address must be in the first 8K of an allocated page.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100145 void RecordWriteHelper(Register object,
Steve Block8defd9f2010-07-08 12:39:36 +0100146 Register address,
147 Register scratch);
Steve Block6ded16b2010-05-10 14:33:55 +0100148
Steve Block8defd9f2010-07-08 12:39:36 +0100149 // For the page containing |object| mark the region covering
150 // [object+offset] dirty. The object address must be in the first 8K
151 // of an allocated page. The 'scratch' registers are used in the
152 // implementation and all 3 registers are clobbered by the
153 // operation, as well as the ip register. RecordWrite updates the
154 // write barrier even when storing smis.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100155 void RecordWrite(Register object,
156 Operand offset,
157 Register scratch0,
158 Register scratch1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000159
Steve Block8defd9f2010-07-08 12:39:36 +0100160 // For the page containing |object| mark the region covering
161 // [address] dirty. The object address must be in the first 8K of an
162 // allocated page. All 3 registers are clobbered by the operation,
163 // as well as the ip register. RecordWrite updates the write barrier
164 // even when storing smis.
165 void RecordWrite(Register object,
166 Register address,
167 Register scratch);
168
Steve Block6ded16b2010-05-10 14:33:55 +0100169 // Push two registers. Pushes leftmost register first (to highest address).
170 void Push(Register src1, Register src2, Condition cond = al) {
171 ASSERT(!src1.is(src2));
172 if (src1.code() > src2.code()) {
173 stm(db_w, sp, src1.bit() | src2.bit(), cond);
174 } else {
175 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
176 str(src2, MemOperand(sp, 4, NegPreIndex), cond);
177 }
178 }
179
180 // Push three registers. Pushes leftmost register first (to highest address).
181 void Push(Register src1, Register src2, Register src3, Condition cond = al) {
182 ASSERT(!src1.is(src2));
183 ASSERT(!src2.is(src3));
184 ASSERT(!src1.is(src3));
185 if (src1.code() > src2.code()) {
186 if (src2.code() > src3.code()) {
187 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
188 } else {
189 stm(db_w, sp, src1.bit() | src2.bit(), cond);
190 str(src3, MemOperand(sp, 4, NegPreIndex), cond);
191 }
192 } else {
193 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
194 Push(src2, src3, cond);
195 }
196 }
197
198 // Push four registers. Pushes leftmost register first (to highest address).
199 void Push(Register src1, Register src2,
200 Register src3, Register src4, Condition cond = al) {
201 ASSERT(!src1.is(src2));
202 ASSERT(!src2.is(src3));
203 ASSERT(!src1.is(src3));
204 ASSERT(!src1.is(src4));
205 ASSERT(!src2.is(src4));
206 ASSERT(!src3.is(src4));
207 if (src1.code() > src2.code()) {
208 if (src2.code() > src3.code()) {
209 if (src3.code() > src4.code()) {
210 stm(db_w,
211 sp,
212 src1.bit() | src2.bit() | src3.bit() | src4.bit(),
213 cond);
214 } else {
215 stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond);
216 str(src4, MemOperand(sp, 4, NegPreIndex), cond);
217 }
218 } else {
219 stm(db_w, sp, src1.bit() | src2.bit(), cond);
220 Push(src3, src4, cond);
221 }
222 } else {
223 str(src1, MemOperand(sp, 4, NegPreIndex), cond);
224 Push(src2, src3, src4, cond);
225 }
226 }
227
Ben Murdochb0fe1622011-05-05 13:52:32 +0100228 // Push and pop the registers that can hold pointers, as defined by the
229 // RegList constant kSafepointSavedRegisters.
230 void PushSafepointRegisters();
231 void PopSafepointRegisters();
232 static int SafepointRegisterStackIndex(int reg_code);
233
Leon Clarkef7060e22010-06-03 12:02:55 +0100234 // Load two consecutive registers with two consecutive memory locations.
235 void Ldrd(Register dst1,
236 Register dst2,
237 const MemOperand& src,
238 Condition cond = al);
239
240 // Store two consecutive registers to two consecutive memory locations.
241 void Strd(Register src1,
242 Register src2,
243 const MemOperand& dst,
244 Condition cond = al);
245
Ben Murdoch086aeea2011-05-13 15:57:08 +0100246 // Clear FPSCR bits.
247 void ClearFPSCRBits(uint32_t bits_to_clear, Register scratch);
248
Steve Blocka7e24c12009-10-30 11:49:00 +0000249 // ---------------------------------------------------------------------------
250 // Activation frames
251
252 void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); }
253 void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); }
254
255 void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); }
256 void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); }
257
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100258 // Enter exit frame.
Steve Blockd0582a62009-12-15 09:54:21 +0000259 // Expects the number of arguments in register r0 and
Steve Blocka7e24c12009-10-30 11:49:00 +0000260 // the builtin function to call in register r1. Exits with argc in
261 // r4, argv in r6, and and the builtin function to call in r5.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100262 void EnterExitFrame(bool save_doubles);
Steve Blocka7e24c12009-10-30 11:49:00 +0000263
264 // Leave the current exit frame. Expects the return value in r0.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100265 void LeaveExitFrame(bool save_doubles);
Steve Blocka7e24c12009-10-30 11:49:00 +0000266
Steve Block6ded16b2010-05-10 14:33:55 +0100267 // Get the actual activation frame alignment for target environment.
268 static int ActivationFrameAlignment();
Steve Blocka7e24c12009-10-30 11:49:00 +0000269
Steve Blockd0582a62009-12-15 09:54:21 +0000270 void LoadContext(Register dst, int context_chain_length);
271
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800272 void LoadGlobalFunction(int index, Register function);
273
274 // Load the initial map from the global function. The registers
275 // function and map can be the same, function is then overwritten.
276 void LoadGlobalFunctionInitialMap(Register function,
277 Register map,
278 Register scratch);
279
Steve Blocka7e24c12009-10-30 11:49:00 +0000280 // ---------------------------------------------------------------------------
281 // JavaScript invokes
282
283 // Invoke the JavaScript function code by either calling or jumping.
284 void InvokeCode(Register code,
285 const ParameterCount& expected,
286 const ParameterCount& actual,
287 InvokeFlag flag);
288
289 void InvokeCode(Handle<Code> code,
290 const ParameterCount& expected,
291 const ParameterCount& actual,
292 RelocInfo::Mode rmode,
293 InvokeFlag flag);
294
295 // Invoke the JavaScript function in the given register. Changes the
296 // current context to the context in the function before invoking.
297 void InvokeFunction(Register function,
298 const ParameterCount& actual,
299 InvokeFlag flag);
300
Andrei Popescu402d9372010-02-26 13:31:12 +0000301 void InvokeFunction(JSFunction* function,
302 const ParameterCount& actual,
303 InvokeFlag flag);
304
Ben Murdochb0fe1622011-05-05 13:52:32 +0100305 void IsObjectJSObjectType(Register heap_object,
306 Register map,
307 Register scratch,
308 Label* fail);
309
310 void IsInstanceJSObjectType(Register map,
311 Register scratch,
312 Label* fail);
313
314 void IsObjectJSStringType(Register object,
315 Register scratch,
316 Label* fail);
Steve Blocka7e24c12009-10-30 11:49:00 +0000317
318#ifdef ENABLE_DEBUGGER_SUPPORT
319 // ---------------------------------------------------------------------------
320 // Debugger Support
321
Andrei Popescu402d9372010-02-26 13:31:12 +0000322 void DebugBreak();
Steve Blocka7e24c12009-10-30 11:49:00 +0000323#endif
324
325 // ---------------------------------------------------------------------------
326 // Exception handling
327
328 // Push a new try handler and link into try handler chain.
329 // The return address must be passed in register lr.
330 // On exit, r0 contains TOS (code slot).
331 void PushTryHandler(CodeLocation try_location, HandlerType type);
332
Leon Clarkee46be812010-01-19 14:06:41 +0000333 // Unlink the stack handler on top of the stack from the try handler chain.
334 // Must preserve the result register.
335 void PopTryHandler();
Steve Blocka7e24c12009-10-30 11:49:00 +0000336
337 // ---------------------------------------------------------------------------
338 // Inline caching support
339
Steve Blocka7e24c12009-10-30 11:49:00 +0000340 // Generate code for checking access rights - used for security checks
341 // on access to global objects across environments. The holder register
342 // is left untouched, whereas both scratch registers are clobbered.
343 void CheckAccessGlobalProxy(Register holder_reg,
344 Register scratch,
345 Label* miss);
346
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800347 inline void MarkCode(NopMarkerTypes type) {
348 nop(type);
349 }
350
351 // Check if the given instruction is a 'type' marker.
352 // ie. check if is is a mov r<type>, r<type> (referenced as nop(type))
353 // These instructions are generated to mark special location in the code,
354 // like some special IC code.
355 static inline bool IsMarkedCode(Instr instr, int type) {
356 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
357 return IsNop(instr, type);
358 }
359
360
361 static inline int GetCodeMarker(Instr instr) {
362 int dst_reg_offset = 12;
363 int dst_mask = 0xf << dst_reg_offset;
364 int src_mask = 0xf;
365 int dst_reg = (instr & dst_mask) >> dst_reg_offset;
366 int src_reg = instr & src_mask;
367 uint32_t non_register_mask = ~(dst_mask | src_mask);
368 uint32_t mov_mask = al | 13 << 21;
369
370 // Return <n> if we have a mov rn rn, else return -1.
371 int type = ((instr & non_register_mask) == mov_mask) &&
372 (dst_reg == src_reg) &&
373 (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER)
374 ? src_reg
375 : -1;
376 ASSERT((type == -1) ||
377 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
378 return type;
379 }
380
Steve Blocka7e24c12009-10-30 11:49:00 +0000381
382 // ---------------------------------------------------------------------------
383 // Allocation support
384
Ben Murdoch086aeea2011-05-13 15:57:08 +0100385 // Allocate an object in new space. The object_size is specified
386 // either in bytes or in words if the allocation flag SIZE_IN_WORDS
387 // is passed. If the new space is exhausted control continues at the
388 // gc_required label. The allocated object is returned in result. If
389 // the flag tag_allocated_object is true the result is tagged as as
390 // a heap object. All registers are clobbered also when control
391 // continues at the gc_required label.
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 void AllocateInNewSpace(int object_size,
393 Register result,
394 Register scratch1,
395 Register scratch2,
396 Label* gc_required,
397 AllocationFlags flags);
398 void AllocateInNewSpace(Register object_size,
399 Register result,
400 Register scratch1,
401 Register scratch2,
402 Label* gc_required,
403 AllocationFlags flags);
404
405 // Undo allocation in new space. The object passed and objects allocated after
406 // it will no longer be allocated. The caller must make sure that no pointers
407 // are left to the object(s) no longer allocated as they would be invalid when
408 // allocation is undone.
409 void UndoAllocationInNewSpace(Register object, Register scratch);
410
Andrei Popescu31002712010-02-23 13:46:05 +0000411
412 void AllocateTwoByteString(Register result,
413 Register length,
414 Register scratch1,
415 Register scratch2,
416 Register scratch3,
417 Label* gc_required);
418 void AllocateAsciiString(Register result,
419 Register length,
420 Register scratch1,
421 Register scratch2,
422 Register scratch3,
423 Label* gc_required);
424 void AllocateTwoByteConsString(Register result,
425 Register length,
426 Register scratch1,
427 Register scratch2,
428 Label* gc_required);
429 void AllocateAsciiConsString(Register result,
430 Register length,
431 Register scratch1,
432 Register scratch2,
433 Label* gc_required);
434
Kristian Monsen25f61362010-05-21 11:50:48 +0100435 // Allocates a heap number or jumps to the gc_required label if the young
436 // space is full and a scavenge is needed. All registers are clobbered also
437 // when control continues at the gc_required label.
Steve Block6ded16b2010-05-10 14:33:55 +0100438 void AllocateHeapNumber(Register result,
439 Register scratch1,
440 Register scratch2,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100441 Register heap_number_map,
Steve Block6ded16b2010-05-10 14:33:55 +0100442 Label* gc_required);
Steve Block8defd9f2010-07-08 12:39:36 +0100443 void AllocateHeapNumberWithValue(Register result,
444 DwVfpRegister value,
445 Register scratch1,
446 Register scratch2,
447 Register heap_number_map,
448 Label* gc_required);
449
Ben Murdochbb769b22010-08-11 14:56:33 +0100450 // Copies a fixed number of fields of heap objects from src to dst.
451 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000452
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 // ---------------------------------------------------------------------------
454 // Support functions.
455
456 // Try to get function prototype of a function and puts the value in
457 // the result register. Checks that the function really is a
458 // function and jumps to the miss label if the fast checks fail. The
459 // function register will be untouched; the other registers may be
460 // clobbered.
461 void TryGetFunctionPrototype(Register function,
462 Register result,
463 Register scratch,
464 Label* miss);
465
466 // Compare object type for heap object. heap_object contains a non-Smi
467 // whose object type should be compared with the given type. This both
468 // sets the flags and leaves the object type in the type_reg register.
469 // It leaves the map in the map register (unless the type_reg and map register
470 // are the same register). It leaves the heap object in the heap_object
471 // register unless the heap_object register is the same register as one of the
472 // other registers.
473 void CompareObjectType(Register heap_object,
474 Register map,
475 Register type_reg,
476 InstanceType type);
477
478 // Compare instance type in a map. map contains a valid map object whose
479 // object type should be compared with the given type. This both
480 // sets the flags and leaves the object type in the type_reg register. It
481 // leaves the heap object in the heap_object register unless the heap_object
482 // register is the same register as type_reg.
483 void CompareInstanceType(Register map,
484 Register type_reg,
485 InstanceType type);
486
Andrei Popescu31002712010-02-23 13:46:05 +0000487
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100488 // Check if the map of an object is equal to a specified map (either
489 // given directly or as an index into the root list) and branch to
490 // label if not. Skip the smi check if not required (object is known
491 // to be a heap object)
Andrei Popescu31002712010-02-23 13:46:05 +0000492 void CheckMap(Register obj,
493 Register scratch,
494 Handle<Map> map,
495 Label* fail,
496 bool is_heap_object);
497
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100498 void CheckMap(Register obj,
499 Register scratch,
500 Heap::RootListIndex index,
501 Label* fail,
502 bool is_heap_object);
503
504
Andrei Popescu31002712010-02-23 13:46:05 +0000505 // Load and check the instance type of an object for being a string.
506 // Loads the type into the second argument register.
507 // Returns a condition that will be enabled if the object was a string.
508 Condition IsObjectStringType(Register obj,
509 Register type) {
510 ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset));
511 ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
512 tst(type, Operand(kIsNotStringMask));
513 ASSERT_EQ(0, kStringTag);
514 return eq;
515 }
516
517
Steve Blocka7e24c12009-10-30 11:49:00 +0000518 inline void BranchOnSmi(Register value, Label* smi_label) {
519 tst(value, Operand(kSmiTagMask));
520 b(eq, smi_label);
521 }
522
523 inline void BranchOnNotSmi(Register value, Label* not_smi_label) {
524 tst(value, Operand(kSmiTagMask));
525 b(ne, not_smi_label);
526 }
527
528 // Generates code for reporting that an illegal operation has
529 // occurred.
530 void IllegalOperation(int num_arguments);
531
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100532 // Picks out an array index from the hash field.
533 // Register use:
534 // hash - holds the index's hash. Clobbered.
535 // index - holds the overwritten index on exit.
536 void IndexFromHash(Register hash, Register index);
537
Andrei Popescu31002712010-02-23 13:46:05 +0000538 // Get the number of least significant bits from a register
539 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
540
Steve Blockd0582a62009-12-15 09:54:21 +0000541 // Uses VFP instructions to Convert a Smi to a double.
542 void IntegerToDoubleConversionWithVFP3(Register inReg,
543 Register outHighReg,
544 Register outLowReg);
545
Steve Block8defd9f2010-07-08 12:39:36 +0100546 // Load the value of a number object into a VFP double register. If the object
547 // is not a number a jump to the label not_number is performed and the VFP
548 // double register is unchanged.
549 void ObjectToDoubleVFPRegister(
550 Register object,
551 DwVfpRegister value,
552 Register scratch1,
553 Register scratch2,
554 Register heap_number_map,
555 SwVfpRegister scratch3,
556 Label* not_number,
557 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
558
559 // Load the value of a smi object into a VFP double register. The register
560 // scratch1 can be the same register as smi in which case smi will hold the
561 // untagged value afterwards.
562 void SmiToDoubleVFPRegister(Register smi,
563 DwVfpRegister value,
564 Register scratch1,
565 SwVfpRegister scratch2);
566
Iain Merrick9ac36c92010-09-13 15:29:50 +0100567 // Convert the HeapNumber pointed to by source to a 32bits signed integer
568 // dest. If the HeapNumber does not fit into a 32bits signed integer branch
569 // to not_int32 label.
570 void ConvertToInt32(Register source,
571 Register dest,
572 Register scratch,
573 Register scratch2,
574 Label *not_int32);
575
Steve Block6ded16b2010-05-10 14:33:55 +0100576 // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz
577 // instruction. On pre-ARM5 hardware this routine gives the wrong answer
Steve Block8defd9f2010-07-08 12:39:36 +0100578 // for 0 (31 instead of 32). Source and scratch can be the same in which case
579 // the source is clobbered. Source and zeros can also be the same in which
580 // case scratch should be a different register.
581 void CountLeadingZeros(Register zeros,
582 Register source,
583 Register scratch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000584
585 // ---------------------------------------------------------------------------
586 // Runtime calls
587
588 // Call a code stub.
589 void CallStub(CodeStub* stub, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000590
Andrei Popescu31002712010-02-23 13:46:05 +0000591 // Call a code stub.
592 void TailCallStub(CodeStub* stub, Condition cond = al);
593
Steve Blocka7e24c12009-10-30 11:49:00 +0000594 // Call a runtime routine.
Steve Blocka7e24c12009-10-30 11:49:00 +0000595 void CallRuntime(Runtime::Function* f, int num_arguments);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100596 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000597
598 // Convenience function: Same as above, but takes the fid instead.
599 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
600
Andrei Popescu402d9372010-02-26 13:31:12 +0000601 // Convenience function: call an external reference.
602 void CallExternalReference(const ExternalReference& ext,
603 int num_arguments);
604
Steve Blocka7e24c12009-10-30 11:49:00 +0000605 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +0100606 // Like JumpToExternalReference, but also takes care of passing the number
Steve Blocka7e24c12009-10-30 11:49:00 +0000607 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +0100608 void TailCallExternalReference(const ExternalReference& ext,
609 int num_arguments,
610 int result_size);
611
612 // Convenience function: tail call a runtime routine (jump).
613 void TailCallRuntime(Runtime::FunctionId fid,
Steve Blocka7e24c12009-10-30 11:49:00 +0000614 int num_arguments,
615 int result_size);
616
Steve Block6ded16b2010-05-10 14:33:55 +0100617 // Before calling a C-function from generated code, align arguments on stack.
618 // After aligning the frame, non-register arguments must be stored in
619 // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments
620 // are word sized.
621 // Some compilers/platforms require the stack to be aligned when calling
622 // C++ code.
623 // Needs a scratch register to do some arithmetic. This register will be
624 // trashed.
625 void PrepareCallCFunction(int num_arguments, Register scratch);
626
627 // Calls a C function and cleans up the space for arguments allocated
628 // by PrepareCallCFunction. The called function is not allowed to trigger a
629 // garbage collection, since that might move the code and invalidate the
630 // return address (unless this is somehow accounted for by the called
631 // function).
632 void CallCFunction(ExternalReference function, int num_arguments);
633 void CallCFunction(Register function, int num_arguments);
634
Steve Blocka7e24c12009-10-30 11:49:00 +0000635 // Jump to a runtime routine.
Steve Block6ded16b2010-05-10 14:33:55 +0100636 void JumpToExternalReference(const ExternalReference& builtin);
Steve Blocka7e24c12009-10-30 11:49:00 +0000637
638 // Invoke specified builtin JavaScript function. Adds an entry to
639 // the unresolved list if the name does not resolve.
640 void InvokeBuiltin(Builtins::JavaScript id, InvokeJSFlags flags);
641
642 // Store the code object for the given builtin in the target register and
643 // setup the function in r1.
644 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
645
Steve Block791712a2010-08-27 10:21:07 +0100646 // Store the function for the given builtin in the target register.
647 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
648
Steve Blocka7e24c12009-10-30 11:49:00 +0000649 Handle<Object> CodeObject() { return code_object_; }
650
651
652 // ---------------------------------------------------------------------------
653 // StatsCounter support
654
655 void SetCounter(StatsCounter* counter, int value,
656 Register scratch1, Register scratch2);
657 void IncrementCounter(StatsCounter* counter, int value,
658 Register scratch1, Register scratch2);
659 void DecrementCounter(StatsCounter* counter, int value,
660 Register scratch1, Register scratch2);
661
662
663 // ---------------------------------------------------------------------------
664 // Debugging
665
666 // Calls Abort(msg) if the condition cc is not satisfied.
667 // Use --debug_code to enable.
668 void Assert(Condition cc, const char* msg);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100669 void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
Iain Merrick75681382010-08-19 15:07:18 +0100670 void AssertFastElements(Register elements);
Steve Blocka7e24c12009-10-30 11:49:00 +0000671
672 // Like Assert(), but always enabled.
673 void Check(Condition cc, const char* msg);
674
675 // Print a message to stdout and abort execution.
676 void Abort(const char* msg);
677
678 // Verify restrictions about code generated in stubs.
679 void set_generating_stub(bool value) { generating_stub_ = value; }
680 bool generating_stub() { return generating_stub_; }
681 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
682 bool allow_stub_calls() { return allow_stub_calls_; }
683
Leon Clarked91b9f72010-01-27 17:25:45 +0000684 // ---------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000685 // Smi utilities
686
Ben Murdochb0fe1622011-05-05 13:52:32 +0100687 void SmiTag(Register reg, SBit s = LeaveCC) {
688 add(reg, reg, Operand(reg), s);
689 }
690
691 void SmiUntag(Register reg) {
692 mov(reg, Operand(reg, ASR, kSmiTagSize));
693 }
694
Andrei Popescu31002712010-02-23 13:46:05 +0000695 // Jump if either of the registers contain a non-smi.
696 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
697 // Jump if either of the registers contain a smi.
698 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
699
Iain Merrick75681382010-08-19 15:07:18 +0100700 // Abort execution if argument is a smi. Used in debug code.
701 void AbortIfSmi(Register object);
702
Andrei Popescu31002712010-02-23 13:46:05 +0000703 // ---------------------------------------------------------------------------
Leon Clarked91b9f72010-01-27 17:25:45 +0000704 // String utilities
705
706 // Checks if both objects are sequential ASCII strings and jumps to label
707 // if either is not. Assumes that neither object is a smi.
708 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1,
709 Register object2,
710 Register scratch1,
711 Register scratch2,
Steve Block6ded16b2010-05-10 14:33:55 +0100712 Label* failure);
Leon Clarked91b9f72010-01-27 17:25:45 +0000713
714 // Checks if both objects are sequential ASCII strings and jumps to label
715 // if either is not.
716 void JumpIfNotBothSequentialAsciiStrings(Register first,
717 Register second,
718 Register scratch1,
719 Register scratch2,
720 Label* not_flat_ascii_strings);
721
Steve Block6ded16b2010-05-10 14:33:55 +0100722 // Checks if both instance types are sequential ASCII strings and jumps to
723 // label if either is not.
724 void JumpIfBothInstanceTypesAreNotSequentialAscii(
725 Register first_object_instance_type,
726 Register second_object_instance_type,
727 Register scratch1,
728 Register scratch2,
729 Label* failure);
730
731 // Check if instance type is sequential ASCII string and jump to label if
732 // it is not.
733 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
734 Register scratch,
735 Label* failure);
736
737
Steve Blocka7e24c12009-10-30 11:49:00 +0000738 private:
Andrei Popescu31002712010-02-23 13:46:05 +0000739 void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
740 void Call(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
Steve Blocka7e24c12009-10-30 11:49:00 +0000741
742 // Helper functions for generating invokes.
743 void InvokePrologue(const ParameterCount& expected,
744 const ParameterCount& actual,
745 Handle<Code> code_constant,
746 Register code_reg,
747 Label* done,
748 InvokeFlag flag);
749
Steve Blocka7e24c12009-10-30 11:49:00 +0000750 // Activation support.
751 void EnterFrame(StackFrame::Type type);
752 void LeaveFrame(StackFrame::Type type);
Andrei Popescu31002712010-02-23 13:46:05 +0000753
Steve Block6ded16b2010-05-10 14:33:55 +0100754 void InitializeNewString(Register string,
755 Register length,
756 Heap::RootListIndex map_index,
757 Register scratch1,
758 Register scratch2);
759
Andrei Popescu31002712010-02-23 13:46:05 +0000760 bool generating_stub_;
761 bool allow_stub_calls_;
762 // This handle will be patched with the code object on installation.
763 Handle<Object> code_object_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000764};
765
766
767#ifdef ENABLE_DEBUGGER_SUPPORT
768// The code patcher is used to patch (typically) small parts of code e.g. for
769// debugging and other types of instrumentation. When using the code patcher
770// the exact number of bytes specified must be emitted. It is not legal to emit
771// relocation information. If any of these constraints are violated it causes
772// an assertion to fail.
773class CodePatcher {
774 public:
775 CodePatcher(byte* address, int instructions);
776 virtual ~CodePatcher();
777
778 // Macro assembler to emit code.
779 MacroAssembler* masm() { return &masm_; }
780
781 // Emit an instruction directly.
782 void Emit(Instr x);
783
784 // Emit an address directly.
785 void Emit(Address addr);
786
787 private:
788 byte* address_; // The address of the code being patched.
789 int instructions_; // Number of instructions of the expected patch size.
790 int size_; // Number of bytes of the expected patch size.
791 MacroAssembler masm_; // Macro assembler used to generate the code.
792};
793#endif // ENABLE_DEBUGGER_SUPPORT
794
795
Ben Murdochb0fe1622011-05-05 13:52:32 +0100796// Helper class for generating code or data associated with the code
797// right after a call instruction. As an example this can be used to
798// generate safepoint data after calls for crankshaft.
799class PostCallGenerator {
800 public:
801 PostCallGenerator() { }
802 virtual ~PostCallGenerator() { }
803 virtual void Generate() = 0;
804};
805
806
Steve Blocka7e24c12009-10-30 11:49:00 +0000807// -----------------------------------------------------------------------------
808// Static helper functions.
809
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800810static MemOperand ContextOperand(Register context, int index) {
811 return MemOperand(context, Context::SlotOffset(index));
812}
813
814
815static inline MemOperand GlobalObjectOperand() {
816 return ContextOperand(cp, Context::GLOBAL_INDEX);
817}
818
819
Steve Blocka7e24c12009-10-30 11:49:00 +0000820#ifdef GENERATED_CODE_COVERAGE
821#define CODE_COVERAGE_STRINGIFY(x) #x
822#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
823#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
824#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
825#else
826#define ACCESS_MASM(masm) masm->
827#endif
828
829
830} } // namespace v8::internal
831
832#endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_