blob: b976f6ee0c6b8073b16f8f158ff55f8c14bbcd20 [file] [log] [blame]
Ben Murdochc7cc0282012-03-05 14:35:55 +00001// Copyright 2012 the V8 project authors. All rights reserved.
Andrei Popescu31002712010-02-23 13:46:05 +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_MIPS_MACRO_ASSEMBLER_MIPS_H_
29#define V8_MIPS_MACRO_ASSEMBLER_MIPS_H_
30
31#include "assembler.h"
32#include "mips/assembler-mips.h"
Ben Murdoch257744e2011-11-30 15:57:28 +000033#include "v8globals.h"
Andrei Popescu31002712010-02-23 13:46:05 +000034
35namespace v8 {
36namespace internal {
37
38// Forward declaration.
39class JumpTarget;
40
Steve Block44f0eee2011-05-26 01:26:41 +010041// Reserved Register Usage Summary.
42//
43// Registers t8, t9, and at are reserved for use by the MacroAssembler.
44//
45// The programmer should know that the MacroAssembler may clobber these three,
46// but won't touch other registers except in special cases.
47//
48// Per the MIPS ABI, register t9 must be used for indirect function call
49// via 'jalr t9' or 'jr t9' instructions. This is relied upon by gcc when
50// trying to update gp register for position-independent-code. Whenever
51// MIPS generated code calls C code, it must be via t9 register.
Andrei Popescu31002712010-02-23 13:46:05 +000052
Ben Murdoch592a9fc2012-03-05 11:04:45 +000053
Steve Block44f0eee2011-05-26 01:26:41 +010054// Flags used for the AllocateInNewSpace functions.
55enum AllocationFlags {
56 // No special flags.
57 NO_ALLOCATION_FLAGS = 0,
58 // Return the pointer to the allocated already tagged as a heap object.
59 TAG_OBJECT = 1 << 0,
60 // The content of the result register already contains the allocation top in
61 // new space.
62 RESULT_CONTAINS_TOP = 1 << 1,
63 // Specify that the requested size of the space to allocate is specified in
64 // words instead of bytes.
65 SIZE_IN_WORDS = 1 << 2
66};
67
68// Flags used for the ObjectToDoubleFPURegister function.
69enum ObjectToDoubleFlags {
70 // No special flags.
71 NO_OBJECT_TO_DOUBLE_FLAGS = 0,
72 // Object is known to be a non smi.
73 OBJECT_NOT_SMI = 1 << 0,
74 // Don't load NaNs or infinities, branch to the non number case instead.
75 AVOID_NANS_AND_INFINITIES = 1 << 1
76};
77
78// Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls.
79enum BranchDelaySlot {
80 USE_DELAY_SLOT,
81 PROTECT
82};
83
Ben Murdoch592a9fc2012-03-05 11:04:45 +000084
85enum RememberedSetAction { EMIT_REMEMBERED_SET, OMIT_REMEMBERED_SET };
86enum SmiCheck { INLINE_SMI_CHECK, OMIT_SMI_CHECK };
87enum RAStatus { kRAHasNotBeenSaved, kRAHasBeenSaved };
88
89bool AreAliased(Register r1, Register r2, Register r3, Register r4);
90
91
92// -----------------------------------------------------------------------------
93// Static helper functions.
94
95inline MemOperand ContextOperand(Register context, int index) {
96 return MemOperand(context, Context::SlotOffset(index));
97}
98
99
100inline MemOperand GlobalObjectOperand() {
101 return ContextOperand(cp, Context::GLOBAL_INDEX);
102}
103
104
105// Generate a MemOperand for loading a field from an object.
106inline MemOperand FieldMemOperand(Register object, int offset) {
107 return MemOperand(object, offset - kHeapObjectTag);
108}
109
110
111// Generate a MemOperand for storing arguments 5..N on the stack
112// when calling CallCFunction().
113inline MemOperand CFunctionArgumentOperand(int index) {
114 ASSERT(index > kCArgSlotCount);
115 // Argument 5 takes the slot just past the four Arg-slots.
116 int offset = (index - 5) * kPointerSize + kCArgsSlotsSize;
117 return MemOperand(sp, offset);
118}
119
120
Andrei Popescu31002712010-02-23 13:46:05 +0000121// MacroAssembler implements a collection of frequently used macros.
122class MacroAssembler: public Assembler {
123 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000124 // The isolate parameter can be NULL if the macro assembler should
125 // not use isolate-dependent functionality. In this case, it's the
126 // responsibility of the caller to never invoke such function on the
127 // macro assembler.
128 MacroAssembler(Isolate* isolate, void* buffer, int size);
Andrei Popescu31002712010-02-23 13:46:05 +0000129
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000130 // Arguments macros.
Steve Block44f0eee2011-05-26 01:26:41 +0100131#define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2
132#define COND_ARGS cond, r1, r2
133
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000134 // Cases when relocation is not needed.
Steve Block44f0eee2011-05-26 01:26:41 +0100135#define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \
136 void Name(target_type target, BranchDelaySlot bd = PROTECT); \
137 inline void Name(BranchDelaySlot bd, target_type target) { \
138 Name(target, bd); \
139 } \
140 void Name(target_type target, \
141 COND_TYPED_ARGS, \
142 BranchDelaySlot bd = PROTECT); \
143 inline void Name(BranchDelaySlot bd, \
144 target_type target, \
145 COND_TYPED_ARGS) { \
146 Name(target, COND_ARGS, bd); \
147 }
148
Steve Block44f0eee2011-05-26 01:26:41 +0100149#define DECLARE_BRANCH_PROTOTYPES(Name) \
150 DECLARE_NORELOC_PROTOTYPE(Name, Label*) \
151 DECLARE_NORELOC_PROTOTYPE(Name, int16_t)
152
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000153 DECLARE_BRANCH_PROTOTYPES(Branch)
154 DECLARE_BRANCH_PROTOTYPES(BranchAndLink)
Steve Block44f0eee2011-05-26 01:26:41 +0100155
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000156#undef DECLARE_BRANCH_PROTOTYPES
Steve Block44f0eee2011-05-26 01:26:41 +0100157#undef COND_TYPED_ARGS
158#undef COND_ARGS
Andrei Popescu31002712010-02-23 13:46:05 +0000159
Ben Murdoch257744e2011-11-30 15:57:28 +0000160
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000161 // Jump, Call, and Ret pseudo instructions implementing inter-working.
162#define COND_ARGS Condition cond = al, Register rs = zero_reg, \
163 const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT
164
165 void Jump(Register target, COND_ARGS);
166 void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS);
167 void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS);
168 void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000169 static int CallSize(Register target, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000170 void Call(Register target, COND_ARGS);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000171 static int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000172 void Call(Address target, RelocInfo::Mode rmode, COND_ARGS);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000173 static int CallSize(Handle<Code> code,
174 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
175 unsigned ast_id = kNoASTId,
176 COND_ARGS);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000177 void Call(Handle<Code> code,
178 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
179 unsigned ast_id = kNoASTId,
180 COND_ARGS);
181 void Ret(COND_ARGS);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000182 inline void Ret(BranchDelaySlot bd, Condition cond = al,
183 Register rs = zero_reg, const Operand& rt = Operand(zero_reg)) {
184 Ret(cond, rs, rt, bd);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000185 }
186
187#undef COND_ARGS
Ben Murdoch257744e2011-11-30 15:57:28 +0000188
Andrei Popescu31002712010-02-23 13:46:05 +0000189 // Emit code to discard a non-negative number of pointer-sized elements
190 // from the stack, clobbering only the sp register.
Steve Block44f0eee2011-05-26 01:26:41 +0100191 void Drop(int count,
192 Condition cond = cc_always,
193 Register reg = no_reg,
194 const Operand& op = Operand(no_reg));
195
196 void DropAndRet(int drop = 0,
197 Condition cond = cc_always,
198 Register reg = no_reg,
199 const Operand& op = Operand(no_reg));
200
201 // Swap two registers. If the scratch register is omitted then a slightly
202 // less efficient form using xor instead of mov is emitted.
203 void Swap(Register reg1, Register reg2, Register scratch = no_reg);
Andrei Popescu31002712010-02-23 13:46:05 +0000204
205 void Call(Label* target);
Steve Block44f0eee2011-05-26 01:26:41 +0100206
Ben Murdoch257744e2011-11-30 15:57:28 +0000207 inline void Move(Register dst, Register src) {
208 if (!dst.is(src)) {
209 mov(dst, src);
210 }
211 }
212
213 inline void Move(FPURegister dst, FPURegister src) {
214 if (!dst.is(src)) {
215 mov_d(dst, src);
216 }
217 }
218
219 inline void Move(Register dst_low, Register dst_high, FPURegister src) {
220 mfc1(dst_low, src);
221 mfc1(dst_high, FPURegister::from_code(src.code() + 1));
222 }
223
224 inline void Move(FPURegister dst, Register src_low, Register src_high) {
225 mtc1(src_low, dst);
226 mtc1(src_high, FPURegister::from_code(dst.code() + 1));
227 }
Andrei Popescu31002712010-02-23 13:46:05 +0000228
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000229 void Move(FPURegister dst, double imm);
230
Andrei Popescu31002712010-02-23 13:46:05 +0000231 // Jump unconditionally to given label.
232 // We NEED a nop in the branch delay slot, as it used by v8, for example in
233 // CodeGenerator::ProcessDeferred().
Steve Block6ded16b2010-05-10 14:33:55 +0100234 // Currently the branch delay slot is filled by the MacroAssembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000235 // Use rather b(Label) for code generation.
236 void jmp(Label* L) {
Steve Block44f0eee2011-05-26 01:26:41 +0100237 Branch(L);
Andrei Popescu31002712010-02-23 13:46:05 +0000238 }
239
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000240
Andrei Popescu31002712010-02-23 13:46:05 +0000241 // Load an object from the root table.
242 void LoadRoot(Register destination,
243 Heap::RootListIndex index);
244 void LoadRoot(Register destination,
245 Heap::RootListIndex index,
246 Condition cond, Register src1, const Operand& src2);
247
Steve Block44f0eee2011-05-26 01:26:41 +0100248 // Store an object to the root table.
249 void StoreRoot(Register source,
250 Heap::RootListIndex index);
251 void StoreRoot(Register source,
252 Heap::RootListIndex index,
253 Condition cond, Register src1, const Operand& src2);
254
Ben Murdochc7cc0282012-03-05 14:35:55 +0000255 void LoadHeapObject(Register dst, Handle<HeapObject> object);
256
257 void LoadObject(Register result, Handle<Object> object) {
258 if (object->IsHeapObject()) {
259 LoadHeapObject(result, Handle<HeapObject>::cast(object));
260 } else {
261 li(result, object);
262 }
263 }
Steve Block44f0eee2011-05-26 01:26:41 +0100264
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000265 // ---------------------------------------------------------------------------
266 // GC Support
267
268 void IncrementalMarkingRecordWriteHelper(Register object,
269 Register value,
270 Register address);
271
272 enum RememberedSetFinalAction {
273 kReturnAtEnd,
274 kFallThroughAtEnd
275 };
Steve Block44f0eee2011-05-26 01:26:41 +0100276
277
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000278 // Record in the remembered set the fact that we have a pointer to new space
279 // at the address pointed to by the addr register. Only works if addr is not
280 // in new space.
281 void RememberedSetHelper(Register object, // Used for debug code.
282 Register addr,
283 Register scratch,
284 SaveFPRegsMode save_fp,
285 RememberedSetFinalAction and_then);
Steve Block44f0eee2011-05-26 01:26:41 +0100286
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000287 void CheckPageFlag(Register object,
288 Register scratch,
289 int mask,
290 Condition cc,
291 Label* condition_met);
292
293 // Check if object is in new space. Jumps if the object is not in new space.
294 // The register scratch can be object itself, but it will be clobbered.
295 void JumpIfNotInNewSpace(Register object,
296 Register scratch,
297 Label* branch) {
298 InNewSpace(object, scratch, ne, branch);
299 }
300
301 // Check if object is in new space. Jumps if the object is in new space.
302 // The register scratch can be object itself, but scratch will be clobbered.
303 void JumpIfInNewSpace(Register object,
304 Register scratch,
305 Label* branch) {
306 InNewSpace(object, scratch, eq, branch);
307 }
308
309 // Check if an object has a given incremental marking color.
310 void HasColor(Register object,
311 Register scratch0,
312 Register scratch1,
313 Label* has_color,
314 int first_bit,
315 int second_bit);
316
317 void JumpIfBlack(Register object,
Steve Block44f0eee2011-05-26 01:26:41 +0100318 Register scratch0,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000319 Register scratch1,
320 Label* on_black);
Steve Block44f0eee2011-05-26 01:26:41 +0100321
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000322 // Checks the color of an object. If the object is already grey or black
323 // then we just fall through, since it is already live. If it is white and
324 // we can determine that it doesn't need to be scanned, then we just mark it
325 // black and fall through. For the rest we jump to the label so the
326 // incremental marker can fix its assumptions.
327 void EnsureNotWhite(Register object,
328 Register scratch1,
329 Register scratch2,
330 Register scratch3,
331 Label* object_is_white_and_not_data);
332
Ben Murdochc7cc0282012-03-05 14:35:55 +0000333 // Detects conservatively whether an object is data-only, i.e. it does need to
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000334 // be scanned by the garbage collector.
335 void JumpIfDataObject(Register value,
336 Register scratch,
337 Label* not_data_object);
338
339 // Notify the garbage collector that we wrote a pointer into an object.
340 // |object| is the object being stored into, |value| is the object being
341 // stored. value and scratch registers are clobbered by the operation.
342 // The offset is the offset from the start of the object, not the offset from
343 // the tagged HeapObject pointer. For use with FieldOperand(reg, off).
344 void RecordWriteField(
345 Register object,
346 int offset,
347 Register value,
348 Register scratch,
349 RAStatus ra_status,
350 SaveFPRegsMode save_fp,
351 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
352 SmiCheck smi_check = INLINE_SMI_CHECK);
353
354 // As above, but the offset has the tag presubtracted. For use with
355 // MemOperand(reg, off).
356 inline void RecordWriteContextSlot(
357 Register context,
358 int offset,
359 Register value,
360 Register scratch,
361 RAStatus ra_status,
362 SaveFPRegsMode save_fp,
363 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
364 SmiCheck smi_check = INLINE_SMI_CHECK) {
365 RecordWriteField(context,
366 offset + kHeapObjectTag,
367 value,
368 scratch,
369 ra_status,
370 save_fp,
371 remembered_set_action,
372 smi_check);
373 }
374
375 // For a given |object| notify the garbage collector that the slot |address|
376 // has been written. |value| is the object being stored. The value and
377 // address registers are clobbered by the operation.
378 void RecordWrite(
379 Register object,
380 Register address,
381 Register value,
382 RAStatus ra_status,
383 SaveFPRegsMode save_fp,
384 RememberedSetAction remembered_set_action = EMIT_REMEMBERED_SET,
385 SmiCheck smi_check = INLINE_SMI_CHECK);
Steve Block44f0eee2011-05-26 01:26:41 +0100386
387
388 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000389 // Inline caching support.
Steve Block44f0eee2011-05-26 01:26:41 +0100390
391 // Generate code for checking access rights - used for security checks
392 // on access to global objects across environments. The holder register
393 // is left untouched, whereas both scratch registers are clobbered.
394 void CheckAccessGlobalProxy(Register holder_reg,
395 Register scratch,
396 Label* miss);
397
Ben Murdochc7cc0282012-03-05 14:35:55 +0000398 void GetNumberHash(Register reg0, Register scratch);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000399
400 void LoadFromNumberDictionary(Label* miss,
401 Register elements,
402 Register key,
403 Register result,
404 Register reg0,
405 Register reg1,
406 Register reg2);
407
408
Steve Block44f0eee2011-05-26 01:26:41 +0100409 inline void MarkCode(NopMarkerTypes type) {
410 nop(type);
Steve Block6ded16b2010-05-10 14:33:55 +0100411 }
412
Steve Block44f0eee2011-05-26 01:26:41 +0100413 // Check if the given instruction is a 'type' marker.
Ben Murdochc7cc0282012-03-05 14:35:55 +0000414 // i.e. check if it is a sll zero_reg, zero_reg, <type> (referenced as
Steve Block44f0eee2011-05-26 01:26:41 +0100415 // nop(type)). These instructions are generated to mark special location in
416 // the code, like some special IC code.
417 static inline bool IsMarkedCode(Instr instr, int type) {
418 ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER));
419 return IsNop(instr, type);
420 }
Andrei Popescu31002712010-02-23 13:46:05 +0000421
422
Steve Block44f0eee2011-05-26 01:26:41 +0100423 static inline int GetCodeMarker(Instr instr) {
424 uint32_t opcode = ((instr & kOpcodeMask));
425 uint32_t rt = ((instr & kRtFieldMask) >> kRtShift);
426 uint32_t rs = ((instr & kRsFieldMask) >> kRsShift);
427 uint32_t sa = ((instr & kSaFieldMask) >> kSaShift);
428
429 // Return <n> if we have a sll zero_reg, zero_reg, n
430 // else return -1.
431 bool sllzz = (opcode == SLL &&
432 rt == static_cast<uint32_t>(ToNumber(zero_reg)) &&
433 rs == static_cast<uint32_t>(ToNumber(zero_reg)));
434 int type =
435 (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1;
436 ASSERT((type == -1) ||
437 ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)));
438 return type;
439 }
440
441
442
443 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000444 // Allocation support.
Steve Block44f0eee2011-05-26 01:26:41 +0100445
446 // Allocate an object in new space. The object_size is specified
447 // either in bytes or in words if the allocation flag SIZE_IN_WORDS
448 // is passed. If the new space is exhausted control continues at the
449 // gc_required label. The allocated object is returned in result. If
450 // the flag tag_allocated_object is true the result is tagged as as
451 // a heap object. All registers are clobbered also when control
452 // continues at the gc_required label.
453 void AllocateInNewSpace(int object_size,
454 Register result,
455 Register scratch1,
456 Register scratch2,
457 Label* gc_required,
458 AllocationFlags flags);
459 void AllocateInNewSpace(Register object_size,
460 Register result,
461 Register scratch1,
462 Register scratch2,
463 Label* gc_required,
464 AllocationFlags flags);
465
466 // Undo allocation in new space. The object passed and objects allocated after
467 // it will no longer be allocated. The caller must make sure that no pointers
468 // are left to the object(s) no longer allocated as they would be invalid when
469 // allocation is undone.
470 void UndoAllocationInNewSpace(Register object, Register scratch);
471
472
473 void AllocateTwoByteString(Register result,
474 Register length,
475 Register scratch1,
476 Register scratch2,
477 Register scratch3,
478 Label* gc_required);
479 void AllocateAsciiString(Register result,
480 Register length,
481 Register scratch1,
482 Register scratch2,
483 Register scratch3,
484 Label* gc_required);
485 void AllocateTwoByteConsString(Register result,
486 Register length,
487 Register scratch1,
488 Register scratch2,
489 Label* gc_required);
490 void AllocateAsciiConsString(Register result,
491 Register length,
492 Register scratch1,
493 Register scratch2,
494 Label* gc_required);
Ben Murdoch589d6972011-11-30 16:04:58 +0000495 void AllocateTwoByteSlicedString(Register result,
496 Register length,
497 Register scratch1,
498 Register scratch2,
499 Label* gc_required);
500 void AllocateAsciiSlicedString(Register result,
501 Register length,
502 Register scratch1,
503 Register scratch2,
504 Label* gc_required);
Steve Block44f0eee2011-05-26 01:26:41 +0100505
506 // Allocates a heap number or jumps to the gc_required label if the young
507 // space is full and a scavenge is needed. All registers are clobbered also
508 // when control continues at the gc_required label.
509 void AllocateHeapNumber(Register result,
510 Register scratch1,
511 Register scratch2,
512 Register heap_number_map,
513 Label* gc_required);
514 void AllocateHeapNumberWithValue(Register result,
515 FPURegister value,
516 Register scratch1,
517 Register scratch2,
518 Label* gc_required);
519
Andrei Popescu31002712010-02-23 13:46:05 +0000520 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000521 // Instruction macros.
Andrei Popescu31002712010-02-23 13:46:05 +0000522
Steve Block44f0eee2011-05-26 01:26:41 +0100523#define DEFINE_INSTRUCTION(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000524 void instr(Register rd, Register rs, const Operand& rt); \
525 void instr(Register rd, Register rs, Register rt) { \
526 instr(rd, rs, Operand(rt)); \
527 } \
528 void instr(Register rs, Register rt, int32_t j) { \
529 instr(rs, rt, Operand(j)); \
530 }
531
Steve Block44f0eee2011-05-26 01:26:41 +0100532#define DEFINE_INSTRUCTION2(instr) \
Andrei Popescu31002712010-02-23 13:46:05 +0000533 void instr(Register rs, const Operand& rt); \
534 void instr(Register rs, Register rt) { \
535 instr(rs, Operand(rt)); \
536 } \
537 void instr(Register rs, int32_t j) { \
538 instr(rs, Operand(j)); \
539 }
540
Andrei Popescu31002712010-02-23 13:46:05 +0000541 DEFINE_INSTRUCTION(Addu);
Steve Block44f0eee2011-05-26 01:26:41 +0100542 DEFINE_INSTRUCTION(Subu);
Andrei Popescu31002712010-02-23 13:46:05 +0000543 DEFINE_INSTRUCTION(Mul);
544 DEFINE_INSTRUCTION2(Mult);
545 DEFINE_INSTRUCTION2(Multu);
546 DEFINE_INSTRUCTION2(Div);
547 DEFINE_INSTRUCTION2(Divu);
548
549 DEFINE_INSTRUCTION(And);
550 DEFINE_INSTRUCTION(Or);
551 DEFINE_INSTRUCTION(Xor);
552 DEFINE_INSTRUCTION(Nor);
Ben Murdoch257744e2011-11-30 15:57:28 +0000553 DEFINE_INSTRUCTION2(Neg);
Andrei Popescu31002712010-02-23 13:46:05 +0000554
555 DEFINE_INSTRUCTION(Slt);
556 DEFINE_INSTRUCTION(Sltu);
557
Steve Block44f0eee2011-05-26 01:26:41 +0100558 // MIPS32 R2 instruction macro.
559 DEFINE_INSTRUCTION(Ror);
560
Andrei Popescu31002712010-02-23 13:46:05 +0000561#undef DEFINE_INSTRUCTION
562#undef DEFINE_INSTRUCTION2
563
564
Ben Murdoch257744e2011-11-30 15:57:28 +0000565 // ---------------------------------------------------------------------------
566 // Pseudo-instructions.
Andrei Popescu31002712010-02-23 13:46:05 +0000567
568 void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); }
Andrei Popescu31002712010-02-23 13:46:05 +0000569
Ben Murdoch257744e2011-11-30 15:57:28 +0000570 // Load int32 in the rd register.
Andrei Popescu31002712010-02-23 13:46:05 +0000571 void li(Register rd, Operand j, bool gen2instr = false);
572 inline void li(Register rd, int32_t j, bool gen2instr = false) {
573 li(rd, Operand(j), gen2instr);
574 }
Steve Block44f0eee2011-05-26 01:26:41 +0100575 inline void li(Register dst, Handle<Object> value, bool gen2instr = false) {
576 li(dst, Operand(value), gen2instr);
577 }
Andrei Popescu31002712010-02-23 13:46:05 +0000578
Andrei Popescu31002712010-02-23 13:46:05 +0000579 // Push multiple registers on the stack.
Steve Block6ded16b2010-05-10 14:33:55 +0100580 // Registers are saved in numerical order, with higher numbered registers
Ben Murdoch257744e2011-11-30 15:57:28 +0000581 // saved in higher memory addresses.
Andrei Popescu31002712010-02-23 13:46:05 +0000582 void MultiPush(RegList regs);
583 void MultiPushReversed(RegList regs);
Steve Block44f0eee2011-05-26 01:26:41 +0100584
Ben Murdoch589d6972011-11-30 16:04:58 +0000585 void MultiPushFPU(RegList regs);
586 void MultiPushReversedFPU(RegList regs);
587
Ben Murdoch257744e2011-11-30 15:57:28 +0000588 // Lower case push() for compatibility with arch-independent code.
589 void push(Register src) {
Andrei Popescu31002712010-02-23 13:46:05 +0000590 Addu(sp, sp, Operand(-kPointerSize));
591 sw(src, MemOperand(sp, 0));
592 }
Steve Block44f0eee2011-05-26 01:26:41 +0100593
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000594 // Push a handle.
595 void Push(Handle<Object> handle);
596
Ben Murdoch257744e2011-11-30 15:57:28 +0000597 // Push two registers. Pushes leftmost register first (to highest address).
598 void Push(Register src1, Register src2) {
Steve Block44f0eee2011-05-26 01:26:41 +0100599 Subu(sp, sp, Operand(2 * kPointerSize));
600 sw(src1, MemOperand(sp, 1 * kPointerSize));
601 sw(src2, MemOperand(sp, 0 * kPointerSize));
602 }
603
Ben Murdoch257744e2011-11-30 15:57:28 +0000604 // Push three registers. Pushes leftmost register first (to highest address).
605 void Push(Register src1, Register src2, Register src3) {
606 Subu(sp, sp, Operand(3 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100607 sw(src1, MemOperand(sp, 2 * kPointerSize));
608 sw(src2, MemOperand(sp, 1 * kPointerSize));
609 sw(src3, MemOperand(sp, 0 * kPointerSize));
610 }
611
Ben Murdoch257744e2011-11-30 15:57:28 +0000612 // Push four registers. Pushes leftmost register first (to highest address).
613 void Push(Register src1, Register src2, Register src3, Register src4) {
614 Subu(sp, sp, Operand(4 * kPointerSize));
Steve Block44f0eee2011-05-26 01:26:41 +0100615 sw(src1, MemOperand(sp, 3 * kPointerSize));
616 sw(src2, MemOperand(sp, 2 * kPointerSize));
617 sw(src3, MemOperand(sp, 1 * kPointerSize));
618 sw(src4, MemOperand(sp, 0 * kPointerSize));
619 }
620
Andrei Popescu31002712010-02-23 13:46:05 +0000621 void Push(Register src, Condition cond, Register tst1, Register tst2) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000622 // Since we don't have conditional execution we use a Branch.
Steve Block44f0eee2011-05-26 01:26:41 +0100623 Branch(3, cond, tst1, Operand(tst2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000624 Subu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000625 sw(src, MemOperand(sp, 0));
626 }
627
628 // Pops multiple values from the stack and load them in the
629 // registers specified in regs. Pop order is the opposite as in MultiPush.
630 void MultiPop(RegList regs);
631 void MultiPopReversed(RegList regs);
Ben Murdoch257744e2011-11-30 15:57:28 +0000632
Ben Murdoch589d6972011-11-30 16:04:58 +0000633 void MultiPopFPU(RegList regs);
634 void MultiPopReversedFPU(RegList regs);
635
Ben Murdoch257744e2011-11-30 15:57:28 +0000636 // Lower case pop() for compatibility with arch-independent code.
637 void pop(Register dst) {
Andrei Popescu31002712010-02-23 13:46:05 +0000638 lw(dst, MemOperand(sp, 0));
639 Addu(sp, sp, Operand(kPointerSize));
640 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000641
642 // Pop two registers. Pops rightmost register first (from lower address).
643 void Pop(Register src1, Register src2) {
644 ASSERT(!src1.is(src2));
645 lw(src2, MemOperand(sp, 0 * kPointerSize));
646 lw(src1, MemOperand(sp, 1 * kPointerSize));
647 Addu(sp, sp, 2 * kPointerSize);
648 }
649
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000650 // Pop three registers. Pops rightmost register first (from lower address).
651 void Pop(Register src1, Register src2, Register src3) {
652 lw(src3, MemOperand(sp, 0 * kPointerSize));
653 lw(src2, MemOperand(sp, 1 * kPointerSize));
654 lw(src1, MemOperand(sp, 2 * kPointerSize));
655 Addu(sp, sp, 3 * kPointerSize);
656 }
657
Steve Block44f0eee2011-05-26 01:26:41 +0100658 void Pop(uint32_t count = 1) {
659 Addu(sp, sp, Operand(count * kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +0000660 }
661
Steve Block44f0eee2011-05-26 01:26:41 +0100662 // Push and pop the registers that can hold pointers, as defined by the
663 // RegList constant kSafepointSavedRegisters.
Ben Murdoch257744e2011-11-30 15:57:28 +0000664 void PushSafepointRegisters();
665 void PopSafepointRegisters();
666 void PushSafepointRegistersAndDoubles();
667 void PopSafepointRegistersAndDoubles();
668 // Store value in register src in the safepoint stack slot for
669 // register dst.
670 void StoreToSafepointRegisterSlot(Register src, Register dst);
671 void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst);
672 // Load the value of the src register from its safepoint stack slot
673 // into register dst.
674 void LoadFromSafepointRegisterSlot(Register dst, Register src);
Steve Block44f0eee2011-05-26 01:26:41 +0100675
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000676 // Flush the I-cache from asm code. You should use CPU::FlushICache from C.
677 // Does not handle errors.
678 void FlushICache(Register address, unsigned instructions);
679
Steve Block44f0eee2011-05-26 01:26:41 +0100680 // MIPS32 R2 instruction macro.
681 void Ins(Register rt, Register rs, uint16_t pos, uint16_t size);
682 void Ext(Register rt, Register rs, uint16_t pos, uint16_t size);
683
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000684 // ---------------------------------------------------------------------------
685 // FPU macros. These do not handle special cases like NaN or +- inf.
686
Steve Block44f0eee2011-05-26 01:26:41 +0100687 // Convert unsigned word to double.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000688 void Cvt_d_uw(FPURegister fd, FPURegister fs, FPURegister scratch);
689 void Cvt_d_uw(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100690
691 // Convert double to unsigned word.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000692 void Trunc_uw_d(FPURegister fd, FPURegister fs, FPURegister scratch);
693 void Trunc_uw_d(FPURegister fd, Register rs, FPURegister scratch);
Steve Block44f0eee2011-05-26 01:26:41 +0100694
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000695 // Wrapper function for the different cmp/branch types.
696 void BranchF(Label* target,
697 Label* nan,
698 Condition cc,
699 FPURegister cmp1,
700 FPURegister cmp2,
701 BranchDelaySlot bd = PROTECT);
702
703 // Alternate (inline) version for better readability with USE_DELAY_SLOT.
704 inline void BranchF(BranchDelaySlot bd,
705 Label* target,
706 Label* nan,
707 Condition cc,
708 FPURegister cmp1,
709 FPURegister cmp2) {
710 BranchF(target, nan, cc, cmp1, cmp2, bd);
711 };
712
Steve Block44f0eee2011-05-26 01:26:41 +0100713 // Convert the HeapNumber pointed to by source to a 32bits signed integer
714 // dest. If the HeapNumber does not fit into a 32bits signed integer branch
715 // to not_int32 label. If FPU is available double_scratch is used but not
716 // scratch2.
717 void ConvertToInt32(Register source,
718 Register dest,
719 Register scratch,
720 Register scratch2,
721 FPURegister double_scratch,
722 Label *not_int32);
723
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000724 // Truncates a double using a specific rounding mode.
725 // The except_flag will contain any exceptions caused by the instruction.
726 // If check_inexact is kDontCheckForInexactConversion, then the inexacat
727 // exception is masked.
728 void EmitFPUTruncate(FPURoundingMode rounding_mode,
729 FPURegister result,
730 DoubleRegister double_input,
731 Register scratch1,
732 Register except_flag,
733 CheckForInexactConversion check_inexact
734 = kDontCheckForInexactConversion);
735
Ben Murdoch257744e2011-11-30 15:57:28 +0000736 // Helper for EmitECMATruncate.
737 // This will truncate a floating-point value outside of the singed 32bit
738 // integer range to a 32bit signed integer.
739 // Expects the double value loaded in input_high and input_low.
740 // Exits with the answer in 'result'.
741 // Note that this code does not work for values in the 32bit range!
742 void EmitOutOfInt32RangeTruncate(Register result,
743 Register input_high,
744 Register input_low,
745 Register scratch);
746
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000747 // Performs a truncating conversion of a floating point number as used by
748 // the JS bitwise operations. See ECMA-262 9.5: ToInt32.
749 // Exits with 'result' holding the answer and all other registers clobbered.
750 void EmitECMATruncate(Register result,
751 FPURegister double_input,
752 FPURegister single_scratch,
753 Register scratch,
754 Register scratch2,
755 Register scratch3);
756
Steve Block44f0eee2011-05-26 01:26:41 +0100757 // Enter exit frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000758 // argc - argument count to be dropped by LeaveExitFrame.
759 // save_doubles - saves FPU registers on stack, currently disabled.
760 // stack_space - extra stack space.
761 void EnterExitFrame(bool save_doubles,
762 int stack_space = 0);
Steve Block6ded16b2010-05-10 14:33:55 +0100763
Ben Murdoch257744e2011-11-30 15:57:28 +0000764 // Leave the current exit frame.
765 void LeaveExitFrame(bool save_doubles, Register arg_count);
Steve Block6ded16b2010-05-10 14:33:55 +0100766
Steve Block44f0eee2011-05-26 01:26:41 +0100767 // Get the actual activation frame alignment for target environment.
768 static int ActivationFrameAlignment();
Steve Block6ded16b2010-05-10 14:33:55 +0100769
Ben Murdoch257744e2011-11-30 15:57:28 +0000770 // Make sure the stack is aligned. Only emits code in debug mode.
771 void AssertStackIsAligned();
772
Steve Block44f0eee2011-05-26 01:26:41 +0100773 void LoadContext(Register dst, int context_chain_length);
Steve Block6ded16b2010-05-10 14:33:55 +0100774
Steve Block44f0eee2011-05-26 01:26:41 +0100775 void LoadGlobalFunction(int index, Register function);
776
777 // Load the initial map from the global function. The registers
778 // function and map can be the same, function is then overwritten.
779 void LoadGlobalFunctionInitialMap(Register function,
780 Register map,
781 Register scratch);
782
Ben Murdochc7cc0282012-03-05 14:35:55 +0000783 void InitializeRootRegister() {
784 ExternalReference roots_array_start =
785 ExternalReference::roots_array_start(isolate());
786 li(kRootRegister, Operand(roots_array_start));
787 }
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000788
Steve Block44f0eee2011-05-26 01:26:41 +0100789 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000790 // JavaScript invokes.
791
Ben Murdochc7cc0282012-03-05 14:35:55 +0000792 // Set up call kind marking in t1. The method takes t1 as an
Ben Murdoch257744e2011-11-30 15:57:28 +0000793 // explicit first parameter to make the code more readable at the
794 // call sites.
795 void SetCallKind(Register dst, CallKind kind);
Steve Block6ded16b2010-05-10 14:33:55 +0100796
797 // Invoke the JavaScript function code by either calling or jumping.
798 void InvokeCode(Register code,
799 const ParameterCount& expected,
800 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +0100801 InvokeFlag flag,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000802 const CallWrapper& call_wrapper,
803 CallKind call_kind);
Steve Block6ded16b2010-05-10 14:33:55 +0100804
805 void InvokeCode(Handle<Code> code,
806 const ParameterCount& expected,
807 const ParameterCount& actual,
808 RelocInfo::Mode rmode,
Ben Murdoch257744e2011-11-30 15:57:28 +0000809 InvokeFlag flag,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000810 CallKind call_kind);
Steve Block6ded16b2010-05-10 14:33:55 +0100811
812 // Invoke the JavaScript function in the given register. Changes the
813 // current context to the context in the function before invoking.
814 void InvokeFunction(Register function,
815 const ParameterCount& actual,
Steve Block44f0eee2011-05-26 01:26:41 +0100816 InvokeFlag flag,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000817 const CallWrapper& call_wrapper,
818 CallKind call_kind);
Steve Block44f0eee2011-05-26 01:26:41 +0100819
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000820 void InvokeFunction(Handle<JSFunction> function,
Steve Block44f0eee2011-05-26 01:26:41 +0100821 const ParameterCount& actual,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000822 InvokeFlag flag,
Ben Murdochc7cc0282012-03-05 14:35:55 +0000823 const CallWrapper& call_wrapper,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000824 CallKind call_kind);
Steve Block6ded16b2010-05-10 14:33:55 +0100825
826
Steve Block44f0eee2011-05-26 01:26:41 +0100827 void IsObjectJSObjectType(Register heap_object,
828 Register map,
829 Register scratch,
830 Label* fail);
831
832 void IsInstanceJSObjectType(Register map,
833 Register scratch,
834 Label* fail);
835
836 void IsObjectJSStringType(Register object,
837 Register scratch,
838 Label* fail);
839
Steve Block6ded16b2010-05-10 14:33:55 +0100840#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100841 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000842 // Debugger Support.
Steve Block6ded16b2010-05-10 14:33:55 +0100843
Steve Block6ded16b2010-05-10 14:33:55 +0100844 void DebugBreak();
845#endif
846
847
Steve Block44f0eee2011-05-26 01:26:41 +0100848 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000849 // Exception handling.
Andrei Popescu31002712010-02-23 13:46:05 +0000850
851 // Push a new try handler and link into try handler chain.
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000852 void PushTryHandler(CodeLocation try_location,
853 HandlerType type,
854 int handler_index);
Andrei Popescu31002712010-02-23 13:46:05 +0000855
856 // Unlink the stack handler on top of the stack from the try handler chain.
857 // Must preserve the result register.
858 void PopTryHandler();
859
Ben Murdoch257744e2011-11-30 15:57:28 +0000860 // Passes thrown value (in v0) to the handler of top of the try handler chain.
861 void Throw(Register value);
862
863 // Propagates an uncatchable exception to the top of the current JS stack's
864 // handler chain.
865 void ThrowUncatchable(UncatchableExceptionType type, Register value);
866
Steve Block44f0eee2011-05-26 01:26:41 +0100867 // Copies a fixed number of fields of heap objects from src to dst.
868 void CopyFields(Register dst, Register src, RegList temps, int field_count);
Andrei Popescu31002712010-02-23 13:46:05 +0000869
Ben Murdoch257744e2011-11-30 15:57:28 +0000870 // Copies a number of bytes from src to dst. All registers are clobbered. On
871 // exit src and dst will point to the place just after where the last byte was
872 // read or written and length will be zero.
873 void CopyBytes(Register src,
874 Register dst,
875 Register length,
876 Register scratch);
877
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000878 // Initialize fields with filler values. Fields starting at |start_offset|
879 // not including end_offset are overwritten with the value in |filler|. At
880 // the end the loop, |start_offset| takes the value of |end_offset|.
881 void InitializeFieldsWithFiller(Register start_offset,
882 Register end_offset,
883 Register filler);
884
Steve Block44f0eee2011-05-26 01:26:41 +0100885 // -------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000886 // Support functions.
887
Steve Block44f0eee2011-05-26 01:26:41 +0100888 // Try to get function prototype of a function and puts the value in
889 // the result register. Checks that the function really is a
890 // function and jumps to the miss label if the fast checks fail. The
891 // function register will be untouched; the other registers may be
892 // clobbered.
893 void TryGetFunctionPrototype(Register function,
894 Register result,
895 Register scratch,
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000896 Label* miss,
897 bool miss_on_bound_function = false);
Steve Block44f0eee2011-05-26 01:26:41 +0100898
Steve Block6ded16b2010-05-10 14:33:55 +0100899 void GetObjectType(Register function,
900 Register map,
901 Register type_reg);
902
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000903 // Check if a map for a JSObject indicates that the object has fast elements.
904 // Jump to the specified label if it does not.
905 void CheckFastElements(Register map,
906 Register scratch,
907 Label* fail);
908
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000909 // Check if a map for a JSObject indicates that the object can have both smi
910 // and HeapObject elements. Jump to the specified label if it does not.
911 void CheckFastObjectElements(Register map,
912 Register scratch,
913 Label* fail);
914
915 // Check if a map for a JSObject indicates that the object has fast smi only
916 // elements. Jump to the specified label if it does not.
917 void CheckFastSmiOnlyElements(Register map,
918 Register scratch,
919 Label* fail);
920
921 // Check to see if maybe_number can be stored as a double in
922 // FastDoubleElements. If it can, store it at the index specified by key in
923 // the FastDoubleElements array elements, otherwise jump to fail.
924 void StoreNumberToDoubleElements(Register value_reg,
925 Register key_reg,
926 Register receiver_reg,
927 Register elements_reg,
928 Register scratch1,
929 Register scratch2,
930 Register scratch3,
931 Register scratch4,
932 Label* fail);
933
Ben Murdochc7cc0282012-03-05 14:35:55 +0000934 // Compare an object's map with the specified map and its transitioned
935 // elements maps if mode is ALLOW_ELEMENT_TRANSITION_MAPS. Jumps to
936 // "branch_to" if the result of the comparison is "cond". If multiple map
937 // compares are required, the compare sequences branches to early_success.
938 void CompareMapAndBranch(Register obj,
939 Register scratch,
940 Handle<Map> map,
941 Label* early_success,
942 Condition cond,
943 Label* branch_to,
944 CompareMapMode mode = REQUIRE_EXACT_MAP);
945
946 // Check if the map of an object is equal to a specified map and branch to
947 // label if not. Skip the smi check if not required (object is known to be a
948 // heap object). If mode is ALLOW_ELEMENT_TRANSITION_MAPS, then also match
949 // against maps that are ElementsKind transition maps of the specificed map.
Steve Block44f0eee2011-05-26 01:26:41 +0100950 void CheckMap(Register obj,
951 Register scratch,
952 Handle<Map> map,
953 Label* fail,
Ben Murdochc7cc0282012-03-05 14:35:55 +0000954 SmiCheckType smi_check_type,
955 CompareMapMode mode = REQUIRE_EXACT_MAP);
956
Andrei Popescu31002712010-02-23 13:46:05 +0000957
Steve Block44f0eee2011-05-26 01:26:41 +0100958 void CheckMap(Register obj,
959 Register scratch,
960 Heap::RootListIndex index,
961 Label* fail,
Ben Murdoch257744e2011-11-30 15:57:28 +0000962 SmiCheckType smi_check_type);
963
964 // Check if the map of an object is equal to a specified map and branch to a
965 // specified target if equal. Skip the smi check if not required (object is
966 // known to be a heap object)
967 void DispatchMap(Register obj,
968 Register scratch,
969 Handle<Map> map,
970 Handle<Code> success,
971 SmiCheckType smi_check_type);
Steve Block6ded16b2010-05-10 14:33:55 +0100972
973 // Generates code for reporting that an illegal operation has
974 // occurred.
975 void IllegalOperation(int num_arguments);
976
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000977
978 // Load and check the instance type of an object for being a string.
979 // Loads the type into the second argument register.
980 // Returns a condition that will be enabled if the object was a string.
981 Condition IsObjectStringType(Register obj,
982 Register type,
983 Register result) {
984 lw(type, FieldMemOperand(obj, HeapObject::kMapOffset));
985 lbu(type, FieldMemOperand(type, Map::kInstanceTypeOffset));
986 And(type, type, Operand(kIsNotStringMask));
987 ASSERT_EQ(0, kStringTag);
988 return eq;
989 }
990
991
Steve Block44f0eee2011-05-26 01:26:41 +0100992 // Picks out an array index from the hash field.
993 // Register use:
994 // hash - holds the index's hash. Clobbered.
995 // index - holds the overwritten index on exit.
996 void IndexFromHash(Register hash, Register index);
Andrei Popescu31002712010-02-23 13:46:05 +0000997
Ben Murdoch257744e2011-11-30 15:57:28 +0000998 // Get the number of least significant bits from a register.
999 void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits);
1000 void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits);
1001
Steve Block44f0eee2011-05-26 01:26:41 +01001002 // Load the value of a number object into a FPU double register. If the
1003 // object is not a number a jump to the label not_number is performed
1004 // and the FPU double register is unchanged.
1005 void ObjectToDoubleFPURegister(
1006 Register object,
1007 FPURegister value,
1008 Register scratch1,
1009 Register scratch2,
1010 Register heap_number_map,
1011 Label* not_number,
1012 ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS);
1013
1014 // Load the value of a smi object into a FPU double register. The register
1015 // scratch1 can be the same register as smi in which case smi will hold the
1016 // untagged value afterwards.
1017 void SmiToDoubleFPURegister(Register smi,
1018 FPURegister value,
1019 Register scratch1);
1020
1021 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001022 // Overflow handling functions.
1023 // Usage: first call the appropriate arithmetic function, then call one of the
1024 // jump functions with the overflow_dst register as the second parameter.
1025
1026 void AdduAndCheckForOverflow(Register dst,
1027 Register left,
1028 Register right,
1029 Register overflow_dst,
1030 Register scratch = at);
1031
1032 void SubuAndCheckForOverflow(Register dst,
1033 Register left,
1034 Register right,
1035 Register overflow_dst,
1036 Register scratch = at);
1037
1038 void BranchOnOverflow(Label* label,
1039 Register overflow_check,
1040 BranchDelaySlot bd = PROTECT) {
1041 Branch(label, lt, overflow_check, Operand(zero_reg), bd);
1042 }
1043
1044 void BranchOnNoOverflow(Label* label,
1045 Register overflow_check,
1046 BranchDelaySlot bd = PROTECT) {
1047 Branch(label, ge, overflow_check, Operand(zero_reg), bd);
1048 }
1049
1050 void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1051 Ret(lt, overflow_check, Operand(zero_reg), bd);
1052 }
1053
1054 void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) {
1055 Ret(ge, overflow_check, Operand(zero_reg), bd);
1056 }
1057
1058 // -------------------------------------------------------------------------
1059 // Runtime calls.
Andrei Popescu31002712010-02-23 13:46:05 +00001060
1061 // Call a code stub.
1062 void CallStub(CodeStub* stub, Condition cond = cc_always,
1063 Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg));
Steve Block44f0eee2011-05-26 01:26:41 +01001064
1065 // Tail call a code stub (jump).
1066 void TailCallStub(CodeStub* stub);
1067
Andrei Popescu31002712010-02-23 13:46:05 +00001068 void CallJSExitStub(CodeStub* stub);
1069
Andrei Popescu31002712010-02-23 13:46:05 +00001070 // Call a runtime routine.
Steve Block44f0eee2011-05-26 01:26:41 +01001071 void CallRuntime(const Runtime::Function* f, int num_arguments);
1072 void CallRuntimeSaveDoubles(Runtime::FunctionId id);
Andrei Popescu31002712010-02-23 13:46:05 +00001073
1074 // Convenience function: Same as above, but takes the fid instead.
1075 void CallRuntime(Runtime::FunctionId fid, int num_arguments);
1076
Steve Block44f0eee2011-05-26 01:26:41 +01001077 // Convenience function: call an external reference.
1078 void CallExternalReference(const ExternalReference& ext,
1079 int num_arguments);
1080
Andrei Popescu31002712010-02-23 13:46:05 +00001081 // Tail call of a runtime routine (jump).
Steve Block6ded16b2010-05-10 14:33:55 +01001082 // Like JumpToExternalReference, but also takes care of passing the number
Andrei Popescu31002712010-02-23 13:46:05 +00001083 // of parameters.
Steve Block6ded16b2010-05-10 14:33:55 +01001084 void TailCallExternalReference(const ExternalReference& ext,
1085 int num_arguments,
1086 int result_size);
1087
1088 // Convenience function: tail call a runtime routine (jump).
1089 void TailCallRuntime(Runtime::FunctionId fid,
Andrei Popescu31002712010-02-23 13:46:05 +00001090 int num_arguments,
1091 int result_size);
1092
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001093 int CalculateStackPassedWords(int num_reg_arguments,
1094 int num_double_arguments);
1095
Steve Block44f0eee2011-05-26 01:26:41 +01001096 // Before calling a C-function from generated code, align arguments on stack
1097 // and add space for the four mips argument slots.
1098 // After aligning the frame, non-register arguments must be stored on the
1099 // stack, after the argument-slots using helper: CFunctionArgumentOperand().
1100 // The argument count assumes all arguments are word sized.
1101 // Some compilers/platforms require the stack to be aligned when calling
1102 // C++ code.
1103 // Needs a scratch register to do some arithmetic. This register will be
1104 // trashed.
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001105 void PrepareCallCFunction(int num_reg_arguments,
1106 int num_double_registers,
1107 Register scratch);
1108 void PrepareCallCFunction(int num_reg_arguments,
1109 Register scratch);
Steve Block44f0eee2011-05-26 01:26:41 +01001110
1111 // Arguments 1-4 are placed in registers a0 thru a3 respectively.
1112 // Arguments 5..n are stored to stack using following:
1113 // sw(t0, CFunctionArgumentOperand(5));
1114
1115 // Calls a C function and cleans up the space for arguments allocated
1116 // by PrepareCallCFunction. The called function is not allowed to trigger a
1117 // garbage collection, since that might move the code and invalidate the
1118 // return address (unless this is somehow accounted for by the called
1119 // function).
1120 void CallCFunction(ExternalReference function, int num_arguments);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001121 void CallCFunction(Register function, int num_arguments);
1122 void CallCFunction(ExternalReference function,
1123 int num_reg_arguments,
1124 int num_double_arguments);
1125 void CallCFunction(Register function,
1126 int num_reg_arguments,
1127 int num_double_arguments);
Ben Murdoch257744e2011-11-30 15:57:28 +00001128 void GetCFunctionDoubleResult(const DoubleRegister dst);
1129
1130 // There are two ways of passing double arguments on MIPS, depending on
1131 // whether soft or hard floating point ABI is used. These functions
1132 // abstract parameter passing for the three different ways we call
1133 // C functions from generated code.
1134 void SetCallCDoubleArguments(DoubleRegister dreg);
1135 void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2);
1136 void SetCallCDoubleArguments(DoubleRegister dreg, Register reg);
1137
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001138 // Calls an API function. Allocates HandleScope, extracts returned value
1139 // from handle and propagates exceptions. Restores context. stack_space
Ben Murdochc7cc0282012-03-05 14:35:55 +00001140 // - space to be unwound on exit (includes the call JS arguments space and
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001141 // the additional space allocated for the fast call).
1142 void CallApiFunctionAndReturn(ExternalReference function, int stack_space);
Steve Block44f0eee2011-05-26 01:26:41 +01001143
Andrei Popescu31002712010-02-23 13:46:05 +00001144 // Jump to the builtin routine.
Steve Block6ded16b2010-05-10 14:33:55 +01001145 void JumpToExternalReference(const ExternalReference& builtin);
Andrei Popescu31002712010-02-23 13:46:05 +00001146
1147 // Invoke specified builtin JavaScript function. Adds an entry to
1148 // the unresolved list if the name does not resolve.
Steve Block44f0eee2011-05-26 01:26:41 +01001149 void InvokeBuiltin(Builtins::JavaScript id,
Ben Murdoch257744e2011-11-30 15:57:28 +00001150 InvokeFlag flag,
1151 const CallWrapper& call_wrapper = NullCallWrapper());
Andrei Popescu31002712010-02-23 13:46:05 +00001152
1153 // Store the code object for the given builtin in the target register and
Steve Block44f0eee2011-05-26 01:26:41 +01001154 // setup the function in a1.
Andrei Popescu31002712010-02-23 13:46:05 +00001155 void GetBuiltinEntry(Register target, Builtins::JavaScript id);
1156
Steve Block44f0eee2011-05-26 01:26:41 +01001157 // Store the function for the given builtin in the target register.
1158 void GetBuiltinFunction(Register target, Builtins::JavaScript id);
1159
Andrei Popescu31002712010-02-23 13:46:05 +00001160 struct Unresolved {
1161 int pc;
Ben Murdoch257744e2011-11-30 15:57:28 +00001162 uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders.
Andrei Popescu31002712010-02-23 13:46:05 +00001163 const char* name;
1164 };
Andrei Popescu31002712010-02-23 13:46:05 +00001165
Ben Murdoch257744e2011-11-30 15:57:28 +00001166 Handle<Object> CodeObject() {
1167 ASSERT(!code_object_.is_null());
1168 return code_object_;
1169 }
Andrei Popescu31002712010-02-23 13:46:05 +00001170
Steve Block44f0eee2011-05-26 01:26:41 +01001171 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001172 // StatsCounter support.
Andrei Popescu31002712010-02-23 13:46:05 +00001173
1174 void SetCounter(StatsCounter* counter, int value,
1175 Register scratch1, Register scratch2);
1176 void IncrementCounter(StatsCounter* counter, int value,
1177 Register scratch1, Register scratch2);
1178 void DecrementCounter(StatsCounter* counter, int value,
1179 Register scratch1, Register scratch2);
1180
1181
Steve Block44f0eee2011-05-26 01:26:41 +01001182 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001183 // Debugging.
Andrei Popescu31002712010-02-23 13:46:05 +00001184
1185 // Calls Abort(msg) if the condition cc is not satisfied.
1186 // Use --debug_code to enable.
1187 void Assert(Condition cc, const char* msg, Register rs, Operand rt);
Steve Block44f0eee2011-05-26 01:26:41 +01001188 void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index);
1189 void AssertFastElements(Register elements);
Andrei Popescu31002712010-02-23 13:46:05 +00001190
1191 // Like Assert(), but always enabled.
1192 void Check(Condition cc, const char* msg, Register rs, Operand rt);
1193
1194 // Print a message to stdout and abort execution.
1195 void Abort(const char* msg);
1196
1197 // Verify restrictions about code generated in stubs.
1198 void set_generating_stub(bool value) { generating_stub_ = value; }
1199 bool generating_stub() { return generating_stub_; }
1200 void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; }
1201 bool allow_stub_calls() { return allow_stub_calls_; }
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001202 void set_has_frame(bool value) { has_frame_ = value; }
1203 bool has_frame() { return has_frame_; }
1204 inline bool AllowThisStubCall(CodeStub* stub);
Andrei Popescu31002712010-02-23 13:46:05 +00001205
Steve Block44f0eee2011-05-26 01:26:41 +01001206 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001207 // Number utilities.
Steve Block6ded16b2010-05-10 14:33:55 +01001208
Steve Block44f0eee2011-05-26 01:26:41 +01001209 // Check whether the value of reg is a power of two and not zero. If not
1210 // control continues at the label not_power_of_two. If reg is a power of two
1211 // the register scratch contains the value of (reg - 1) when control falls
1212 // through.
1213 void JumpIfNotPowerOfTwoOrZero(Register reg,
1214 Register scratch,
1215 Label* not_power_of_two_or_zero);
1216
1217 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001218 // Smi utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001219
1220 // Try to convert int32 to smi. If the value is to large, preserve
1221 // the original value and jump to not_a_smi. Destroys scratch and
1222 // sets flags.
1223 // This is only used by crankshaft atm so it is unimplemented on MIPS.
1224 void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) {
1225 UNIMPLEMENTED_MIPS();
1226 }
1227
1228 void SmiTag(Register reg) {
1229 Addu(reg, reg, reg);
1230 }
1231
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001232 // Test for overflow < 0: use BranchOnOverflow() or BranchOnNoOverflow().
1233 void SmiTagCheckOverflow(Register reg, Register overflow) {
1234 mov(overflow, reg); // Save original value.
1235 addu(reg, reg, reg);
1236 xor_(overflow, overflow, reg); // Overflow if (value ^ 2 * value) < 0.
1237 }
1238
Steve Block44f0eee2011-05-26 01:26:41 +01001239 void SmiTag(Register dst, Register src) {
1240 Addu(dst, src, src);
1241 }
1242
1243 void SmiUntag(Register reg) {
1244 sra(reg, reg, kSmiTagSize);
1245 }
1246
1247 void SmiUntag(Register dst, Register src) {
1248 sra(dst, src, kSmiTagSize);
1249 }
1250
1251 // Jump the register contains a smi.
1252 inline void JumpIfSmi(Register value, Label* smi_label,
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001253 Register scratch = at,
1254 BranchDelaySlot bd = PROTECT) {
Steve Block44f0eee2011-05-26 01:26:41 +01001255 ASSERT_EQ(0, kSmiTag);
1256 andi(scratch, value, kSmiTagMask);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001257 Branch(bd, smi_label, eq, scratch, Operand(zero_reg));
Steve Block44f0eee2011-05-26 01:26:41 +01001258 }
1259
1260 // Jump if the register contains a non-smi.
1261 inline void JumpIfNotSmi(Register value, Label* not_smi_label,
1262 Register scratch = at) {
1263 ASSERT_EQ(0, kSmiTag);
1264 andi(scratch, value, kSmiTagMask);
1265 Branch(not_smi_label, ne, scratch, Operand(zero_reg));
1266 }
1267
1268 // Jump if either of the registers contain a non-smi.
1269 void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi);
1270 // Jump if either of the registers contain a smi.
1271 void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi);
1272
1273 // Abort execution if argument is a smi. Used in debug code.
1274 void AbortIfSmi(Register object);
1275 void AbortIfNotSmi(Register object);
1276
Ben Murdoch257744e2011-11-30 15:57:28 +00001277 // Abort execution if argument is a string. Used in debug code.
1278 void AbortIfNotString(Register object);
1279
Steve Block44f0eee2011-05-26 01:26:41 +01001280 // Abort execution if argument is not the root value with the given index.
1281 void AbortIfNotRootValue(Register src,
1282 Heap::RootListIndex root_value_index,
1283 const char* message);
1284
1285 // ---------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001286 // HeapNumber utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001287
1288 void JumpIfNotHeapNumber(Register object,
1289 Register heap_number_map,
1290 Register scratch,
1291 Label* on_not_heap_number);
1292
1293 // -------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001294 // String utilities.
Steve Block44f0eee2011-05-26 01:26:41 +01001295
1296 // Checks if both instance types are sequential ASCII strings and jumps to
1297 // label if either is not.
1298 void JumpIfBothInstanceTypesAreNotSequentialAscii(
1299 Register first_object_instance_type,
1300 Register second_object_instance_type,
1301 Register scratch1,
1302 Register scratch2,
1303 Label* failure);
1304
1305 // Check if instance type is sequential ASCII string and jump to label if
1306 // it is not.
1307 void JumpIfInstanceTypeIsNotSequentialAscii(Register type,
1308 Register scratch,
1309 Label* failure);
1310
1311 // Test that both first and second are sequential ASCII strings.
1312 // Assume that they are non-smis.
1313 void JumpIfNonSmisNotBothSequentialAsciiStrings(Register first,
1314 Register second,
1315 Register scratch1,
1316 Register scratch2,
1317 Label* failure);
1318
1319 // Test that both first and second are sequential ASCII strings.
1320 // Check that they are non-smis.
1321 void JumpIfNotBothSequentialAsciiStrings(Register first,
1322 Register second,
1323 Register scratch1,
1324 Register scratch2,
1325 Label* failure);
1326
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001327 void ClampUint8(Register output_reg, Register input_reg);
1328
1329 void ClampDoubleToUint8(Register result_reg,
1330 DoubleRegister input_reg,
1331 DoubleRegister temp_double_reg);
1332
1333
Ben Murdoch257744e2011-11-30 15:57:28 +00001334 void LoadInstanceDescriptors(Register map, Register descriptors);
1335
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001336
1337 // Activation support.
1338 void EnterFrame(StackFrame::Type type);
1339 void LeaveFrame(StackFrame::Type type);
1340
1341 // Patch the relocated value (lui/ori pair).
1342 void PatchRelocatedValue(Register li_location,
1343 Register scratch,
1344 Register new_value);
1345 // Get the relocatad value (loaded data) from the lui/ori pair.
1346 void GetRelocatedValue(Register li_location,
1347 Register value,
1348 Register scratch);
1349
Steve Block44f0eee2011-05-26 01:26:41 +01001350 private:
1351 void CallCFunctionHelper(Register function,
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001352 int num_reg_arguments,
1353 int num_double_arguments);
Steve Block44f0eee2011-05-26 01:26:41 +01001354
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001355 void BranchShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1356 void BranchShort(int16_t offset, Condition cond, Register rs,
1357 const Operand& rt,
1358 BranchDelaySlot bdslot = PROTECT);
1359 void BranchShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1360 void BranchShort(Label* L, Condition cond, Register rs,
1361 const Operand& rt,
1362 BranchDelaySlot bdslot = PROTECT);
1363 void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT);
1364 void BranchAndLinkShort(int16_t offset, Condition cond, Register rs,
1365 const Operand& rt,
1366 BranchDelaySlot bdslot = PROTECT);
1367 void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT);
1368 void BranchAndLinkShort(Label* L, Condition cond, Register rs,
1369 const Operand& rt,
1370 BranchDelaySlot bdslot = PROTECT);
1371 void J(Label* L, BranchDelaySlot bdslot);
1372 void Jr(Label* L, BranchDelaySlot bdslot);
1373 void Jalr(Label* L, BranchDelaySlot bdslot);
Steve Block6ded16b2010-05-10 14:33:55 +01001374
1375 // Helper functions for generating invokes.
1376 void InvokePrologue(const ParameterCount& expected,
1377 const ParameterCount& actual,
1378 Handle<Code> code_constant,
1379 Register code_reg,
1380 Label* done,
Ben Murdochc7cc0282012-03-05 14:35:55 +00001381 bool* definitely_mismatches,
Steve Block44f0eee2011-05-26 01:26:41 +01001382 InvokeFlag flag,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001383 const CallWrapper& call_wrapper,
1384 CallKind call_kind);
Steve Block6ded16b2010-05-10 14:33:55 +01001385
1386 // Get the code for the given builtin. Returns if able to resolve
1387 // the function in the 'resolved' flag.
1388 Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved);
1389
Steve Block44f0eee2011-05-26 01:26:41 +01001390 void InitializeNewString(Register string,
1391 Register length,
1392 Heap::RootListIndex map_index,
1393 Register scratch1,
1394 Register scratch2);
1395
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001396 // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
1397 void InNewSpace(Register object,
1398 Register scratch,
1399 Condition cond, // eq for new space, ne otherwise.
1400 Label* branch);
1401
1402 // Helper for finding the mark bits for an address. Afterwards, the
1403 // bitmap register points at the word with the mark bits and the mask
1404 // the position of the first bit. Leaves addr_reg unchanged.
1405 inline void GetMarkBits(Register addr_reg,
1406 Register bitmap_reg,
1407 Register mask_reg);
1408
1409 // Helper for throwing exceptions. Compute a handler address and jump to
1410 // it. See the implementation for register usage.
1411 void JumpToHandlerEntry();
1412
Ben Murdoch257744e2011-11-30 15:57:28 +00001413 // Compute memory operands for safepoint stack slots.
1414 static int SafepointRegisterStackIndex(int reg_code);
1415 MemOperand SafepointRegisterSlot(Register reg);
1416 MemOperand SafepointRegistersAndDoublesSlot(Register reg);
Steve Block44f0eee2011-05-26 01:26:41 +01001417
1418 bool generating_stub_;
1419 bool allow_stub_calls_;
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001420 bool has_frame_;
Steve Block44f0eee2011-05-26 01:26:41 +01001421 // This handle will be patched with the code object on installation.
1422 Handle<Object> code_object_;
Ben Murdoch257744e2011-11-30 15:57:28 +00001423
1424 // Needs access to SafepointRegisterStackIndex for optimized frame
1425 // traversal.
1426 friend class OptimizedFrame;
Steve Block44f0eee2011-05-26 01:26:41 +01001427};
1428
1429
Steve Block44f0eee2011-05-26 01:26:41 +01001430// The code patcher is used to patch (typically) small parts of code e.g. for
1431// debugging and other types of instrumentation. When using the code patcher
1432// the exact number of bytes specified must be emitted. It is not legal to emit
1433// relocation information. If any of these constraints are violated it causes
1434// an assertion to fail.
1435class CodePatcher {
1436 public:
1437 CodePatcher(byte* address, int instructions);
1438 virtual ~CodePatcher();
1439
1440 // Macro assembler to emit code.
1441 MacroAssembler* masm() { return &masm_; }
1442
1443 // Emit an instruction directly.
Ben Murdoch257744e2011-11-30 15:57:28 +00001444 void Emit(Instr instr);
Steve Block44f0eee2011-05-26 01:26:41 +01001445
1446 // Emit an address directly.
1447 void Emit(Address addr);
1448
Ben Murdoch257744e2011-11-30 15:57:28 +00001449 // Change the condition part of an instruction leaving the rest of the current
1450 // instruction unchanged.
1451 void ChangeBranchCondition(Condition cond);
1452
Steve Block44f0eee2011-05-26 01:26:41 +01001453 private:
1454 byte* address_; // The address of the code being patched.
1455 int instructions_; // Number of instructions of the expected patch size.
1456 int size_; // Number of bytes of the expected patch size.
1457 MacroAssembler masm_; // Macro assembler used to generate the code.
1458};
Andrei Popescu31002712010-02-23 13:46:05 +00001459
1460
Andrei Popescu31002712010-02-23 13:46:05 +00001461
1462#ifdef GENERATED_CODE_COVERAGE
1463#define CODE_COVERAGE_STRINGIFY(x) #x
1464#define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x)
1465#define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__)
1466#define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm->
1467#else
1468#define ACCESS_MASM(masm) masm->
1469#endif
1470
1471} } // namespace v8::internal
1472
1473#endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_