Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2 | // 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 Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 33 | #include "v8globals.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | // Forward declaration. |
| 39 | class JumpTarget; |
| 40 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 41 | // 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 Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 52 | |
| 53 | // Registers aliases |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 54 | // cp is assumed to be a callee saved register. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 55 | const Register roots = s6; // Roots array pointer. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 56 | const Register cp = s7; // JavaScript context pointer. |
| 57 | const Register fp = s8_fp; // Alias for fp. |
| 58 | // Registers used for condition evaluation. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 59 | const Register condReg1 = s4; |
| 60 | const Register condReg2 = s5; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 61 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 62 | |
| 63 | // Flags used for the AllocateInNewSpace functions. |
| 64 | enum AllocationFlags { |
| 65 | // No special flags. |
| 66 | NO_ALLOCATION_FLAGS = 0, |
| 67 | // Return the pointer to the allocated already tagged as a heap object. |
| 68 | TAG_OBJECT = 1 << 0, |
| 69 | // The content of the result register already contains the allocation top in |
| 70 | // new space. |
| 71 | RESULT_CONTAINS_TOP = 1 << 1, |
| 72 | // Specify that the requested size of the space to allocate is specified in |
| 73 | // words instead of bytes. |
| 74 | SIZE_IN_WORDS = 1 << 2 |
| 75 | }; |
| 76 | |
| 77 | // Flags used for the ObjectToDoubleFPURegister function. |
| 78 | enum ObjectToDoubleFlags { |
| 79 | // No special flags. |
| 80 | NO_OBJECT_TO_DOUBLE_FLAGS = 0, |
| 81 | // Object is known to be a non smi. |
| 82 | OBJECT_NOT_SMI = 1 << 0, |
| 83 | // Don't load NaNs or infinities, branch to the non number case instead. |
| 84 | AVOID_NANS_AND_INFINITIES = 1 << 1 |
| 85 | }; |
| 86 | |
| 87 | // Allow programmer to use Branch Delay Slot of Branches, Jumps, Calls. |
| 88 | enum BranchDelaySlot { |
| 89 | USE_DELAY_SLOT, |
| 90 | PROTECT |
| 91 | }; |
| 92 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 93 | // MacroAssembler implements a collection of frequently used macros. |
| 94 | class MacroAssembler: public Assembler { |
| 95 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 96 | // The isolate parameter can be NULL if the macro assembler should |
| 97 | // not use isolate-dependent functionality. In this case, it's the |
| 98 | // responsibility of the caller to never invoke such function on the |
| 99 | // macro assembler. |
| 100 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 101 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 102 | // Arguments macros. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 103 | #define COND_TYPED_ARGS Condition cond, Register r1, const Operand& r2 |
| 104 | #define COND_ARGS cond, r1, r2 |
| 105 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 106 | // Cases when relocation is not needed. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 107 | #define DECLARE_NORELOC_PROTOTYPE(Name, target_type) \ |
| 108 | void Name(target_type target, BranchDelaySlot bd = PROTECT); \ |
| 109 | inline void Name(BranchDelaySlot bd, target_type target) { \ |
| 110 | Name(target, bd); \ |
| 111 | } \ |
| 112 | void Name(target_type target, \ |
| 113 | COND_TYPED_ARGS, \ |
| 114 | BranchDelaySlot bd = PROTECT); \ |
| 115 | inline void Name(BranchDelaySlot bd, \ |
| 116 | target_type target, \ |
| 117 | COND_TYPED_ARGS) { \ |
| 118 | Name(target, COND_ARGS, bd); \ |
| 119 | } |
| 120 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 121 | #define DECLARE_BRANCH_PROTOTYPES(Name) \ |
| 122 | DECLARE_NORELOC_PROTOTYPE(Name, Label*) \ |
| 123 | DECLARE_NORELOC_PROTOTYPE(Name, int16_t) |
| 124 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 125 | DECLARE_BRANCH_PROTOTYPES(Branch) |
| 126 | DECLARE_BRANCH_PROTOTYPES(BranchAndLink) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 127 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 128 | #undef DECLARE_BRANCH_PROTOTYPES |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 129 | #undef COND_TYPED_ARGS |
| 130 | #undef COND_ARGS |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 131 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 132 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 133 | // Jump, Call, and Ret pseudo instructions implementing inter-working. |
| 134 | #define COND_ARGS Condition cond = al, Register rs = zero_reg, \ |
| 135 | const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT |
| 136 | |
| 137 | void Jump(Register target, COND_ARGS); |
| 138 | void Jump(intptr_t target, RelocInfo::Mode rmode, COND_ARGS); |
| 139 | void Jump(Address target, RelocInfo::Mode rmode, COND_ARGS); |
| 140 | void Jump(Handle<Code> code, RelocInfo::Mode rmode, COND_ARGS); |
| 141 | int CallSize(Register target, COND_ARGS); |
| 142 | void Call(Register target, COND_ARGS); |
| 143 | int CallSize(Address target, RelocInfo::Mode rmode, COND_ARGS); |
| 144 | void Call(Address target, RelocInfo::Mode rmode, COND_ARGS); |
| 145 | int CallSize(Handle<Code> code, |
| 146 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 147 | unsigned ast_id = kNoASTId, |
| 148 | COND_ARGS); |
| 149 | void Call(Handle<Code> code, |
| 150 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 151 | unsigned ast_id = kNoASTId, |
| 152 | COND_ARGS); |
| 153 | void Ret(COND_ARGS); |
| 154 | inline void Ret(BranchDelaySlot bd) { |
| 155 | Ret(al, zero_reg, Operand(zero_reg), bd); |
| 156 | } |
| 157 | |
| 158 | #undef COND_ARGS |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 159 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 160 | // Emit code to discard a non-negative number of pointer-sized elements |
| 161 | // from the stack, clobbering only the sp register. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 162 | void Drop(int count, |
| 163 | Condition cond = cc_always, |
| 164 | Register reg = no_reg, |
| 165 | const Operand& op = Operand(no_reg)); |
| 166 | |
| 167 | void DropAndRet(int drop = 0, |
| 168 | Condition cond = cc_always, |
| 169 | Register reg = no_reg, |
| 170 | const Operand& op = Operand(no_reg)); |
| 171 | |
| 172 | // Swap two registers. If the scratch register is omitted then a slightly |
| 173 | // less efficient form using xor instead of mov is emitted. |
| 174 | void Swap(Register reg1, Register reg2, Register scratch = no_reg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 175 | |
| 176 | void Call(Label* target); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 177 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 178 | inline void Move(Register dst, Register src) { |
| 179 | if (!dst.is(src)) { |
| 180 | mov(dst, src); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | inline void Move(FPURegister dst, FPURegister src) { |
| 185 | if (!dst.is(src)) { |
| 186 | mov_d(dst, src); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | inline void Move(Register dst_low, Register dst_high, FPURegister src) { |
| 191 | mfc1(dst_low, src); |
| 192 | mfc1(dst_high, FPURegister::from_code(src.code() + 1)); |
| 193 | } |
| 194 | |
| 195 | inline void Move(FPURegister dst, Register src_low, Register src_high) { |
| 196 | mtc1(src_low, dst); |
| 197 | mtc1(src_high, FPURegister::from_code(dst.code() + 1)); |
| 198 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 199 | |
| 200 | // Jump unconditionally to given label. |
| 201 | // We NEED a nop in the branch delay slot, as it used by v8, for example in |
| 202 | // CodeGenerator::ProcessDeferred(). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 203 | // Currently the branch delay slot is filled by the MacroAssembler. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 204 | // Use rather b(Label) for code generation. |
| 205 | void jmp(Label* L) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 206 | Branch(L); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // Load an object from the root table. |
| 210 | void LoadRoot(Register destination, |
| 211 | Heap::RootListIndex index); |
| 212 | void LoadRoot(Register destination, |
| 213 | Heap::RootListIndex index, |
| 214 | Condition cond, Register src1, const Operand& src2); |
| 215 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 216 | // Store an object to the root table. |
| 217 | void StoreRoot(Register source, |
| 218 | Heap::RootListIndex index); |
| 219 | void StoreRoot(Register source, |
| 220 | Heap::RootListIndex index, |
| 221 | Condition cond, Register src1, const Operand& src2); |
| 222 | |
| 223 | |
| 224 | // Check if object is in new space. |
| 225 | // scratch can be object itself, but it will be clobbered. |
| 226 | void InNewSpace(Register object, |
| 227 | Register scratch, |
| 228 | Condition cc, // eq for new space, ne otherwise. |
| 229 | Label* branch); |
| 230 | |
| 231 | |
| 232 | // For the page containing |object| mark the region covering [address] |
| 233 | // dirty. The object address must be in the first 8K of an allocated page. |
| 234 | void RecordWriteHelper(Register object, |
| 235 | Register address, |
| 236 | Register scratch); |
| 237 | |
| 238 | // For the page containing |object| mark the region covering |
| 239 | // [object+offset] dirty. The object address must be in the first 8K |
| 240 | // of an allocated page. The 'scratch' registers are used in the |
| 241 | // implementation and all 3 registers are clobbered by the |
| 242 | // operation, as well as the 'at' register. RecordWrite updates the |
| 243 | // write barrier even when storing smis. |
| 244 | void RecordWrite(Register object, |
| 245 | Operand offset, |
| 246 | Register scratch0, |
| 247 | Register scratch1); |
| 248 | |
| 249 | // For the page containing |object| mark the region covering |
| 250 | // [address] dirty. The object address must be in the first 8K of an |
| 251 | // allocated page. All 3 registers are clobbered by the operation, |
| 252 | // as well as the ip register. RecordWrite updates the write barrier |
| 253 | // even when storing smis. |
| 254 | void RecordWrite(Register object, |
| 255 | Register address, |
| 256 | Register scratch); |
| 257 | |
| 258 | |
| 259 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 260 | // Inline caching support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 261 | |
| 262 | // Generate code for checking access rights - used for security checks |
| 263 | // on access to global objects across environments. The holder register |
| 264 | // is left untouched, whereas both scratch registers are clobbered. |
| 265 | void CheckAccessGlobalProxy(Register holder_reg, |
| 266 | Register scratch, |
| 267 | Label* miss); |
| 268 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 269 | |
| 270 | void LoadFromNumberDictionary(Label* miss, |
| 271 | Register elements, |
| 272 | Register key, |
| 273 | Register result, |
| 274 | Register reg0, |
| 275 | Register reg1, |
| 276 | Register reg2); |
| 277 | |
| 278 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 279 | inline void MarkCode(NopMarkerTypes type) { |
| 280 | nop(type); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 283 | // Check if the given instruction is a 'type' marker. |
| 284 | // ie. check if it is a sll zero_reg, zero_reg, <type> (referenced as |
| 285 | // nop(type)). These instructions are generated to mark special location in |
| 286 | // the code, like some special IC code. |
| 287 | static inline bool IsMarkedCode(Instr instr, int type) { |
| 288 | ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)); |
| 289 | return IsNop(instr, type); |
| 290 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 291 | |
| 292 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 293 | static inline int GetCodeMarker(Instr instr) { |
| 294 | uint32_t opcode = ((instr & kOpcodeMask)); |
| 295 | uint32_t rt = ((instr & kRtFieldMask) >> kRtShift); |
| 296 | uint32_t rs = ((instr & kRsFieldMask) >> kRsShift); |
| 297 | uint32_t sa = ((instr & kSaFieldMask) >> kSaShift); |
| 298 | |
| 299 | // Return <n> if we have a sll zero_reg, zero_reg, n |
| 300 | // else return -1. |
| 301 | bool sllzz = (opcode == SLL && |
| 302 | rt == static_cast<uint32_t>(ToNumber(zero_reg)) && |
| 303 | rs == static_cast<uint32_t>(ToNumber(zero_reg))); |
| 304 | int type = |
| 305 | (sllzz && FIRST_IC_MARKER <= sa && sa < LAST_CODE_MARKER) ? sa : -1; |
| 306 | ASSERT((type == -1) || |
| 307 | ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER))); |
| 308 | return type; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | |
| 313 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 314 | // Allocation support. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 315 | |
| 316 | // Allocate an object in new space. The object_size is specified |
| 317 | // either in bytes or in words if the allocation flag SIZE_IN_WORDS |
| 318 | // is passed. If the new space is exhausted control continues at the |
| 319 | // gc_required label. The allocated object is returned in result. If |
| 320 | // the flag tag_allocated_object is true the result is tagged as as |
| 321 | // a heap object. All registers are clobbered also when control |
| 322 | // continues at the gc_required label. |
| 323 | void AllocateInNewSpace(int object_size, |
| 324 | Register result, |
| 325 | Register scratch1, |
| 326 | Register scratch2, |
| 327 | Label* gc_required, |
| 328 | AllocationFlags flags); |
| 329 | void AllocateInNewSpace(Register object_size, |
| 330 | Register result, |
| 331 | Register scratch1, |
| 332 | Register scratch2, |
| 333 | Label* gc_required, |
| 334 | AllocationFlags flags); |
| 335 | |
| 336 | // Undo allocation in new space. The object passed and objects allocated after |
| 337 | // it will no longer be allocated. The caller must make sure that no pointers |
| 338 | // are left to the object(s) no longer allocated as they would be invalid when |
| 339 | // allocation is undone. |
| 340 | void UndoAllocationInNewSpace(Register object, Register scratch); |
| 341 | |
| 342 | |
| 343 | void AllocateTwoByteString(Register result, |
| 344 | Register length, |
| 345 | Register scratch1, |
| 346 | Register scratch2, |
| 347 | Register scratch3, |
| 348 | Label* gc_required); |
| 349 | void AllocateAsciiString(Register result, |
| 350 | Register length, |
| 351 | Register scratch1, |
| 352 | Register scratch2, |
| 353 | Register scratch3, |
| 354 | Label* gc_required); |
| 355 | void AllocateTwoByteConsString(Register result, |
| 356 | Register length, |
| 357 | Register scratch1, |
| 358 | Register scratch2, |
| 359 | Label* gc_required); |
| 360 | void AllocateAsciiConsString(Register result, |
| 361 | Register length, |
| 362 | Register scratch1, |
| 363 | Register scratch2, |
| 364 | Label* gc_required); |
| 365 | |
| 366 | // Allocates a heap number or jumps to the gc_required label if the young |
| 367 | // space is full and a scavenge is needed. All registers are clobbered also |
| 368 | // when control continues at the gc_required label. |
| 369 | void AllocateHeapNumber(Register result, |
| 370 | Register scratch1, |
| 371 | Register scratch2, |
| 372 | Register heap_number_map, |
| 373 | Label* gc_required); |
| 374 | void AllocateHeapNumberWithValue(Register result, |
| 375 | FPURegister value, |
| 376 | Register scratch1, |
| 377 | Register scratch2, |
| 378 | Label* gc_required); |
| 379 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 380 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 381 | // Instruction macros. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 382 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 383 | #define DEFINE_INSTRUCTION(instr) \ |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 384 | void instr(Register rd, Register rs, const Operand& rt); \ |
| 385 | void instr(Register rd, Register rs, Register rt) { \ |
| 386 | instr(rd, rs, Operand(rt)); \ |
| 387 | } \ |
| 388 | void instr(Register rs, Register rt, int32_t j) { \ |
| 389 | instr(rs, rt, Operand(j)); \ |
| 390 | } |
| 391 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 392 | #define DEFINE_INSTRUCTION2(instr) \ |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 393 | void instr(Register rs, const Operand& rt); \ |
| 394 | void instr(Register rs, Register rt) { \ |
| 395 | instr(rs, Operand(rt)); \ |
| 396 | } \ |
| 397 | void instr(Register rs, int32_t j) { \ |
| 398 | instr(rs, Operand(j)); \ |
| 399 | } |
| 400 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 401 | DEFINE_INSTRUCTION(Addu); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 402 | DEFINE_INSTRUCTION(Subu); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 403 | DEFINE_INSTRUCTION(Mul); |
| 404 | DEFINE_INSTRUCTION2(Mult); |
| 405 | DEFINE_INSTRUCTION2(Multu); |
| 406 | DEFINE_INSTRUCTION2(Div); |
| 407 | DEFINE_INSTRUCTION2(Divu); |
| 408 | |
| 409 | DEFINE_INSTRUCTION(And); |
| 410 | DEFINE_INSTRUCTION(Or); |
| 411 | DEFINE_INSTRUCTION(Xor); |
| 412 | DEFINE_INSTRUCTION(Nor); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 413 | DEFINE_INSTRUCTION2(Neg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 414 | |
| 415 | DEFINE_INSTRUCTION(Slt); |
| 416 | DEFINE_INSTRUCTION(Sltu); |
| 417 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 418 | // MIPS32 R2 instruction macro. |
| 419 | DEFINE_INSTRUCTION(Ror); |
| 420 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 421 | #undef DEFINE_INSTRUCTION |
| 422 | #undef DEFINE_INSTRUCTION2 |
| 423 | |
| 424 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 425 | // --------------------------------------------------------------------------- |
| 426 | // Pseudo-instructions. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 427 | |
| 428 | void mov(Register rd, Register rt) { or_(rd, rt, zero_reg); } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 429 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 430 | // Load int32 in the rd register. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 431 | void li(Register rd, Operand j, bool gen2instr = false); |
| 432 | inline void li(Register rd, int32_t j, bool gen2instr = false) { |
| 433 | li(rd, Operand(j), gen2instr); |
| 434 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 435 | inline void li(Register dst, Handle<Object> value, bool gen2instr = false) { |
| 436 | li(dst, Operand(value), gen2instr); |
| 437 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 438 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 439 | // Push multiple registers on the stack. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 440 | // Registers are saved in numerical order, with higher numbered registers |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 441 | // saved in higher memory addresses. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 442 | void MultiPush(RegList regs); |
| 443 | void MultiPushReversed(RegList regs); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 444 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 445 | // Lower case push() for compatibility with arch-independent code. |
| 446 | void push(Register src) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 447 | Addu(sp, sp, Operand(-kPointerSize)); |
| 448 | sw(src, MemOperand(sp, 0)); |
| 449 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 450 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 451 | // Push a handle. |
| 452 | void Push(Handle<Object> handle); |
| 453 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 454 | // Push two registers. Pushes leftmost register first (to highest address). |
| 455 | void Push(Register src1, Register src2) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 456 | Subu(sp, sp, Operand(2 * kPointerSize)); |
| 457 | sw(src1, MemOperand(sp, 1 * kPointerSize)); |
| 458 | sw(src2, MemOperand(sp, 0 * kPointerSize)); |
| 459 | } |
| 460 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 461 | // Push three registers. Pushes leftmost register first (to highest address). |
| 462 | void Push(Register src1, Register src2, Register src3) { |
| 463 | Subu(sp, sp, Operand(3 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 464 | sw(src1, MemOperand(sp, 2 * kPointerSize)); |
| 465 | sw(src2, MemOperand(sp, 1 * kPointerSize)); |
| 466 | sw(src3, MemOperand(sp, 0 * kPointerSize)); |
| 467 | } |
| 468 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 469 | // Push four registers. Pushes leftmost register first (to highest address). |
| 470 | void Push(Register src1, Register src2, Register src3, Register src4) { |
| 471 | Subu(sp, sp, Operand(4 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 472 | sw(src1, MemOperand(sp, 3 * kPointerSize)); |
| 473 | sw(src2, MemOperand(sp, 2 * kPointerSize)); |
| 474 | sw(src3, MemOperand(sp, 1 * kPointerSize)); |
| 475 | sw(src4, MemOperand(sp, 0 * kPointerSize)); |
| 476 | } |
| 477 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 478 | void Push(Register src, Condition cond, Register tst1, Register tst2) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 479 | // Since we don't have conditional execution we use a Branch. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 480 | Branch(3, cond, tst1, Operand(tst2)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 481 | Subu(sp, sp, Operand(kPointerSize)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 482 | sw(src, MemOperand(sp, 0)); |
| 483 | } |
| 484 | |
| 485 | // Pops multiple values from the stack and load them in the |
| 486 | // registers specified in regs. Pop order is the opposite as in MultiPush. |
| 487 | void MultiPop(RegList regs); |
| 488 | void MultiPopReversed(RegList regs); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 489 | |
| 490 | // Lower case pop() for compatibility with arch-independent code. |
| 491 | void pop(Register dst) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 492 | lw(dst, MemOperand(sp, 0)); |
| 493 | Addu(sp, sp, Operand(kPointerSize)); |
| 494 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 495 | |
| 496 | // Pop two registers. Pops rightmost register first (from lower address). |
| 497 | void Pop(Register src1, Register src2) { |
| 498 | ASSERT(!src1.is(src2)); |
| 499 | lw(src2, MemOperand(sp, 0 * kPointerSize)); |
| 500 | lw(src1, MemOperand(sp, 1 * kPointerSize)); |
| 501 | Addu(sp, sp, 2 * kPointerSize); |
| 502 | } |
| 503 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 504 | void Pop(uint32_t count = 1) { |
| 505 | Addu(sp, sp, Operand(count * kPointerSize)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 508 | // Push and pop the registers that can hold pointers, as defined by the |
| 509 | // RegList constant kSafepointSavedRegisters. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 510 | void PushSafepointRegisters(); |
| 511 | void PopSafepointRegisters(); |
| 512 | void PushSafepointRegistersAndDoubles(); |
| 513 | void PopSafepointRegistersAndDoubles(); |
| 514 | // Store value in register src in the safepoint stack slot for |
| 515 | // register dst. |
| 516 | void StoreToSafepointRegisterSlot(Register src, Register dst); |
| 517 | void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst); |
| 518 | // Load the value of the src register from its safepoint stack slot |
| 519 | // into register dst. |
| 520 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 521 | |
| 522 | // MIPS32 R2 instruction macro. |
| 523 | void Ins(Register rt, Register rs, uint16_t pos, uint16_t size); |
| 524 | void Ext(Register rt, Register rs, uint16_t pos, uint16_t size); |
| 525 | |
| 526 | // Convert unsigned word to double. |
| 527 | void Cvt_d_uw(FPURegister fd, FPURegister fs); |
| 528 | void Cvt_d_uw(FPURegister fd, Register rs); |
| 529 | |
| 530 | // Convert double to unsigned word. |
| 531 | void Trunc_uw_d(FPURegister fd, FPURegister fs); |
| 532 | void Trunc_uw_d(FPURegister fd, Register rs); |
| 533 | |
| 534 | // Convert the HeapNumber pointed to by source to a 32bits signed integer |
| 535 | // dest. If the HeapNumber does not fit into a 32bits signed integer branch |
| 536 | // to not_int32 label. If FPU is available double_scratch is used but not |
| 537 | // scratch2. |
| 538 | void ConvertToInt32(Register source, |
| 539 | Register dest, |
| 540 | Register scratch, |
| 541 | Register scratch2, |
| 542 | FPURegister double_scratch, |
| 543 | Label *not_int32); |
| 544 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 545 | // Helper for EmitECMATruncate. |
| 546 | // This will truncate a floating-point value outside of the singed 32bit |
| 547 | // integer range to a 32bit signed integer. |
| 548 | // Expects the double value loaded in input_high and input_low. |
| 549 | // Exits with the answer in 'result'. |
| 550 | // Note that this code does not work for values in the 32bit range! |
| 551 | void EmitOutOfInt32RangeTruncate(Register result, |
| 552 | Register input_high, |
| 553 | Register input_low, |
| 554 | Register scratch); |
| 555 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 556 | // Performs a truncating conversion of a floating point number as used by |
| 557 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. |
| 558 | // Exits with 'result' holding the answer and all other registers clobbered. |
| 559 | void EmitECMATruncate(Register result, |
| 560 | FPURegister double_input, |
| 561 | FPURegister single_scratch, |
| 562 | Register scratch, |
| 563 | Register scratch2, |
| 564 | Register scratch3); |
| 565 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 566 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 567 | // Activation frames. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 568 | |
| 569 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 570 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 571 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 572 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 573 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 574 | |
| 575 | // Enter exit frame. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 576 | // argc - argument count to be dropped by LeaveExitFrame. |
| 577 | // save_doubles - saves FPU registers on stack, currently disabled. |
| 578 | // stack_space - extra stack space. |
| 579 | void EnterExitFrame(bool save_doubles, |
| 580 | int stack_space = 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 581 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 582 | // Leave the current exit frame. |
| 583 | void LeaveExitFrame(bool save_doubles, Register arg_count); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 584 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 585 | // Get the actual activation frame alignment for target environment. |
| 586 | static int ActivationFrameAlignment(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 587 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 588 | // Make sure the stack is aligned. Only emits code in debug mode. |
| 589 | void AssertStackIsAligned(); |
| 590 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 591 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 592 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 593 | void LoadGlobalFunction(int index, Register function); |
| 594 | |
| 595 | // Load the initial map from the global function. The registers |
| 596 | // function and map can be the same, function is then overwritten. |
| 597 | void LoadGlobalFunctionInitialMap(Register function, |
| 598 | Register map, |
| 599 | Register scratch); |
| 600 | |
| 601 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 602 | // JavaScript invokes. |
| 603 | |
| 604 | // Setup call kind marking in t1. The method takes t1 as an |
| 605 | // explicit first parameter to make the code more readable at the |
| 606 | // call sites. |
| 607 | void SetCallKind(Register dst, CallKind kind); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 608 | |
| 609 | // Invoke the JavaScript function code by either calling or jumping. |
| 610 | void InvokeCode(Register code, |
| 611 | const ParameterCount& expected, |
| 612 | const ParameterCount& actual, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 613 | InvokeFlag flag, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 614 | const CallWrapper& call_wrapper, |
| 615 | CallKind call_kind); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 616 | |
| 617 | void InvokeCode(Handle<Code> code, |
| 618 | const ParameterCount& expected, |
| 619 | const ParameterCount& actual, |
| 620 | RelocInfo::Mode rmode, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 621 | InvokeFlag flag, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 622 | CallKind call_kind); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 623 | |
| 624 | // Invoke the JavaScript function in the given register. Changes the |
| 625 | // current context to the context in the function before invoking. |
| 626 | void InvokeFunction(Register function, |
| 627 | const ParameterCount& actual, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 628 | InvokeFlag flag, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 629 | const CallWrapper& call_wrapper, |
| 630 | CallKind call_kind); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 631 | |
| 632 | void InvokeFunction(JSFunction* function, |
| 633 | const ParameterCount& actual, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 634 | InvokeFlag flag, |
| 635 | CallKind call_kind); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 636 | |
| 637 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 638 | void IsObjectJSObjectType(Register heap_object, |
| 639 | Register map, |
| 640 | Register scratch, |
| 641 | Label* fail); |
| 642 | |
| 643 | void IsInstanceJSObjectType(Register map, |
| 644 | Register scratch, |
| 645 | Label* fail); |
| 646 | |
| 647 | void IsObjectJSStringType(Register object, |
| 648 | Register scratch, |
| 649 | Label* fail); |
| 650 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 651 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 652 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 653 | // Debugger Support. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 654 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 655 | void DebugBreak(); |
| 656 | #endif |
| 657 | |
| 658 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 659 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 660 | // Exception handling. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 661 | |
| 662 | // Push a new try handler and link into try handler chain. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 663 | // The return address must be passed in register ra. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 664 | // Clobber t0, t1, t2. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 665 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 666 | |
| 667 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 668 | // Must preserve the result register. |
| 669 | void PopTryHandler(); |
| 670 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 671 | // Passes thrown value (in v0) to the handler of top of the try handler chain. |
| 672 | void Throw(Register value); |
| 673 | |
| 674 | // Propagates an uncatchable exception to the top of the current JS stack's |
| 675 | // handler chain. |
| 676 | void ThrowUncatchable(UncatchableExceptionType type, Register value); |
| 677 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 678 | // Copies a fixed number of fields of heap objects from src to dst. |
| 679 | void CopyFields(Register dst, Register src, RegList temps, int field_count); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 680 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 681 | // Copies a number of bytes from src to dst. All registers are clobbered. On |
| 682 | // exit src and dst will point to the place just after where the last byte was |
| 683 | // read or written and length will be zero. |
| 684 | void CopyBytes(Register src, |
| 685 | Register dst, |
| 686 | Register length, |
| 687 | Register scratch); |
| 688 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 689 | // ------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 690 | // Support functions. |
| 691 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 692 | // Try to get function prototype of a function and puts the value in |
| 693 | // the result register. Checks that the function really is a |
| 694 | // function and jumps to the miss label if the fast checks fail. The |
| 695 | // function register will be untouched; the other registers may be |
| 696 | // clobbered. |
| 697 | void TryGetFunctionPrototype(Register function, |
| 698 | Register result, |
| 699 | Register scratch, |
| 700 | Label* miss); |
| 701 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 702 | void GetObjectType(Register function, |
| 703 | Register map, |
| 704 | Register type_reg); |
| 705 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 706 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 707 | // Jump to the specified label if it does not. |
| 708 | void CheckFastElements(Register map, |
| 709 | Register scratch, |
| 710 | Label* fail); |
| 711 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 712 | // Check if the map of an object is equal to a specified map (either |
| 713 | // given directly or as an index into the root list) and branch to |
| 714 | // label if not. Skip the smi check if not required (object is known |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 715 | // to be a heap object). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 716 | void CheckMap(Register obj, |
| 717 | Register scratch, |
| 718 | Handle<Map> map, |
| 719 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 720 | SmiCheckType smi_check_type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 721 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 722 | void CheckMap(Register obj, |
| 723 | Register scratch, |
| 724 | Heap::RootListIndex index, |
| 725 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 726 | SmiCheckType smi_check_type); |
| 727 | |
| 728 | // Check if the map of an object is equal to a specified map and branch to a |
| 729 | // specified target if equal. Skip the smi check if not required (object is |
| 730 | // known to be a heap object) |
| 731 | void DispatchMap(Register obj, |
| 732 | Register scratch, |
| 733 | Handle<Map> map, |
| 734 | Handle<Code> success, |
| 735 | SmiCheckType smi_check_type); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 736 | |
| 737 | // Generates code for reporting that an illegal operation has |
| 738 | // occurred. |
| 739 | void IllegalOperation(int num_arguments); |
| 740 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 741 | // Picks out an array index from the hash field. |
| 742 | // Register use: |
| 743 | // hash - holds the index's hash. Clobbered. |
| 744 | // index - holds the overwritten index on exit. |
| 745 | void IndexFromHash(Register hash, Register index); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 746 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 747 | // Get the number of least significant bits from a register. |
| 748 | void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits); |
| 749 | void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits); |
| 750 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 751 | // Load the value of a number object into a FPU double register. If the |
| 752 | // object is not a number a jump to the label not_number is performed |
| 753 | // and the FPU double register is unchanged. |
| 754 | void ObjectToDoubleFPURegister( |
| 755 | Register object, |
| 756 | FPURegister value, |
| 757 | Register scratch1, |
| 758 | Register scratch2, |
| 759 | Register heap_number_map, |
| 760 | Label* not_number, |
| 761 | ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS); |
| 762 | |
| 763 | // Load the value of a smi object into a FPU double register. The register |
| 764 | // scratch1 can be the same register as smi in which case smi will hold the |
| 765 | // untagged value afterwards. |
| 766 | void SmiToDoubleFPURegister(Register smi, |
| 767 | FPURegister value, |
| 768 | Register scratch1); |
| 769 | |
| 770 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 771 | // Overflow handling functions. |
| 772 | // Usage: first call the appropriate arithmetic function, then call one of the |
| 773 | // jump functions with the overflow_dst register as the second parameter. |
| 774 | |
| 775 | void AdduAndCheckForOverflow(Register dst, |
| 776 | Register left, |
| 777 | Register right, |
| 778 | Register overflow_dst, |
| 779 | Register scratch = at); |
| 780 | |
| 781 | void SubuAndCheckForOverflow(Register dst, |
| 782 | Register left, |
| 783 | Register right, |
| 784 | Register overflow_dst, |
| 785 | Register scratch = at); |
| 786 | |
| 787 | void BranchOnOverflow(Label* label, |
| 788 | Register overflow_check, |
| 789 | BranchDelaySlot bd = PROTECT) { |
| 790 | Branch(label, lt, overflow_check, Operand(zero_reg), bd); |
| 791 | } |
| 792 | |
| 793 | void BranchOnNoOverflow(Label* label, |
| 794 | Register overflow_check, |
| 795 | BranchDelaySlot bd = PROTECT) { |
| 796 | Branch(label, ge, overflow_check, Operand(zero_reg), bd); |
| 797 | } |
| 798 | |
| 799 | void RetOnOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) { |
| 800 | Ret(lt, overflow_check, Operand(zero_reg), bd); |
| 801 | } |
| 802 | |
| 803 | void RetOnNoOverflow(Register overflow_check, BranchDelaySlot bd = PROTECT) { |
| 804 | Ret(ge, overflow_check, Operand(zero_reg), bd); |
| 805 | } |
| 806 | |
| 807 | // ------------------------------------------------------------------------- |
| 808 | // Runtime calls. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 809 | |
| 810 | // Call a code stub. |
| 811 | void CallStub(CodeStub* stub, Condition cond = cc_always, |
| 812 | Register r1 = zero_reg, const Operand& r2 = Operand(zero_reg)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 813 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 814 | // Call a code stub and return the code object called. Try to generate |
| 815 | // the code if necessary. Do not perform a GC but instead return a retry |
| 816 | // after GC failure. |
| 817 | MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub, |
| 818 | Condition cond = cc_always, |
| 819 | Register r1 = zero_reg, |
| 820 | const Operand& r2 = |
| 821 | Operand(zero_reg)); |
| 822 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 823 | // Tail call a code stub (jump). |
| 824 | void TailCallStub(CodeStub* stub); |
| 825 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 826 | // Tail call a code stub (jump) and return the code object called. Try to |
| 827 | // generate the code if necessary. Do not perform a GC but instead return |
| 828 | // a retry after GC failure. |
| 829 | MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub, |
| 830 | Condition cond = cc_always, |
| 831 | Register r1 = zero_reg, |
| 832 | const Operand& r2 = |
| 833 | Operand(zero_reg)); |
| 834 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 835 | void CallJSExitStub(CodeStub* stub); |
| 836 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 837 | // Call a runtime routine. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 838 | void CallRuntime(const Runtime::Function* f, int num_arguments); |
| 839 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 840 | |
| 841 | // Convenience function: Same as above, but takes the fid instead. |
| 842 | void CallRuntime(Runtime::FunctionId fid, int num_arguments); |
| 843 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 844 | // Convenience function: call an external reference. |
| 845 | void CallExternalReference(const ExternalReference& ext, |
| 846 | int num_arguments); |
| 847 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 848 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 849 | // Like JumpToExternalReference, but also takes care of passing the number |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 850 | // of parameters. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 851 | void TailCallExternalReference(const ExternalReference& ext, |
| 852 | int num_arguments, |
| 853 | int result_size); |
| 854 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 855 | // Tail call of a runtime routine (jump). Try to generate the code if |
| 856 | // necessary. Do not perform a GC but instead return a retry after GC |
| 857 | // failure. |
| 858 | MUST_USE_RESULT MaybeObject* TryTailCallExternalReference( |
| 859 | const ExternalReference& ext, int num_arguments, int result_size); |
| 860 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 861 | // Convenience function: tail call a runtime routine (jump). |
| 862 | void TailCallRuntime(Runtime::FunctionId fid, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 863 | int num_arguments, |
| 864 | int result_size); |
| 865 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 866 | // Before calling a C-function from generated code, align arguments on stack |
| 867 | // and add space for the four mips argument slots. |
| 868 | // After aligning the frame, non-register arguments must be stored on the |
| 869 | // stack, after the argument-slots using helper: CFunctionArgumentOperand(). |
| 870 | // The argument count assumes all arguments are word sized. |
| 871 | // Some compilers/platforms require the stack to be aligned when calling |
| 872 | // C++ code. |
| 873 | // Needs a scratch register to do some arithmetic. This register will be |
| 874 | // trashed. |
| 875 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 876 | |
| 877 | // Arguments 1-4 are placed in registers a0 thru a3 respectively. |
| 878 | // Arguments 5..n are stored to stack using following: |
| 879 | // sw(t0, CFunctionArgumentOperand(5)); |
| 880 | |
| 881 | // Calls a C function and cleans up the space for arguments allocated |
| 882 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 883 | // garbage collection, since that might move the code and invalidate the |
| 884 | // return address (unless this is somehow accounted for by the called |
| 885 | // function). |
| 886 | void CallCFunction(ExternalReference function, int num_arguments); |
| 887 | void CallCFunction(Register function, Register scratch, int num_arguments); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 888 | void GetCFunctionDoubleResult(const DoubleRegister dst); |
| 889 | |
| 890 | // There are two ways of passing double arguments on MIPS, depending on |
| 891 | // whether soft or hard floating point ABI is used. These functions |
| 892 | // abstract parameter passing for the three different ways we call |
| 893 | // C functions from generated code. |
| 894 | void SetCallCDoubleArguments(DoubleRegister dreg); |
| 895 | void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2); |
| 896 | void SetCallCDoubleArguments(DoubleRegister dreg, Register reg); |
| 897 | |
| 898 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 899 | // from handle and propagates exceptions. Restores context. |
| 900 | MaybeObject* TryCallApiFunctionAndReturn(ExternalReference function, |
| 901 | int stack_space); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 902 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 903 | // Jump to the builtin routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 904 | void JumpToExternalReference(const ExternalReference& builtin); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 905 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 906 | MaybeObject* TryJumpToExternalReference(const ExternalReference& ext); |
| 907 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 908 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 909 | // the unresolved list if the name does not resolve. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 910 | void InvokeBuiltin(Builtins::JavaScript id, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 911 | InvokeFlag flag, |
| 912 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 913 | |
| 914 | // Store the code object for the given builtin in the target register and |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 915 | // setup the function in a1. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 916 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 917 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 918 | // Store the function for the given builtin in the target register. |
| 919 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 920 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 921 | struct Unresolved { |
| 922 | int pc; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 923 | uint32_t flags; // See Bootstrapper::FixupFlags decoders/encoders. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 924 | const char* name; |
| 925 | }; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 926 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 927 | Handle<Object> CodeObject() { |
| 928 | ASSERT(!code_object_.is_null()); |
| 929 | return code_object_; |
| 930 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 931 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 932 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 933 | // StatsCounter support. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 934 | |
| 935 | void SetCounter(StatsCounter* counter, int value, |
| 936 | Register scratch1, Register scratch2); |
| 937 | void IncrementCounter(StatsCounter* counter, int value, |
| 938 | Register scratch1, Register scratch2); |
| 939 | void DecrementCounter(StatsCounter* counter, int value, |
| 940 | Register scratch1, Register scratch2); |
| 941 | |
| 942 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 943 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 944 | // Debugging. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 945 | |
| 946 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 947 | // Use --debug_code to enable. |
| 948 | void Assert(Condition cc, const char* msg, Register rs, Operand rt); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 949 | void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index); |
| 950 | void AssertFastElements(Register elements); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 951 | |
| 952 | // Like Assert(), but always enabled. |
| 953 | void Check(Condition cc, const char* msg, Register rs, Operand rt); |
| 954 | |
| 955 | // Print a message to stdout and abort execution. |
| 956 | void Abort(const char* msg); |
| 957 | |
| 958 | // Verify restrictions about code generated in stubs. |
| 959 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 960 | bool generating_stub() { return generating_stub_; } |
| 961 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 962 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 963 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 964 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 965 | // Number utilities. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 966 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 967 | // Check whether the value of reg is a power of two and not zero. If not |
| 968 | // control continues at the label not_power_of_two. If reg is a power of two |
| 969 | // the register scratch contains the value of (reg - 1) when control falls |
| 970 | // through. |
| 971 | void JumpIfNotPowerOfTwoOrZero(Register reg, |
| 972 | Register scratch, |
| 973 | Label* not_power_of_two_or_zero); |
| 974 | |
| 975 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 976 | // Smi utilities. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 977 | |
| 978 | // Try to convert int32 to smi. If the value is to large, preserve |
| 979 | // the original value and jump to not_a_smi. Destroys scratch and |
| 980 | // sets flags. |
| 981 | // This is only used by crankshaft atm so it is unimplemented on MIPS. |
| 982 | void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) { |
| 983 | UNIMPLEMENTED_MIPS(); |
| 984 | } |
| 985 | |
| 986 | void SmiTag(Register reg) { |
| 987 | Addu(reg, reg, reg); |
| 988 | } |
| 989 | |
| 990 | void SmiTag(Register dst, Register src) { |
| 991 | Addu(dst, src, src); |
| 992 | } |
| 993 | |
| 994 | void SmiUntag(Register reg) { |
| 995 | sra(reg, reg, kSmiTagSize); |
| 996 | } |
| 997 | |
| 998 | void SmiUntag(Register dst, Register src) { |
| 999 | sra(dst, src, kSmiTagSize); |
| 1000 | } |
| 1001 | |
| 1002 | // Jump the register contains a smi. |
| 1003 | inline void JumpIfSmi(Register value, Label* smi_label, |
| 1004 | Register scratch = at) { |
| 1005 | ASSERT_EQ(0, kSmiTag); |
| 1006 | andi(scratch, value, kSmiTagMask); |
| 1007 | Branch(smi_label, eq, scratch, Operand(zero_reg)); |
| 1008 | } |
| 1009 | |
| 1010 | // Jump if the register contains a non-smi. |
| 1011 | inline void JumpIfNotSmi(Register value, Label* not_smi_label, |
| 1012 | Register scratch = at) { |
| 1013 | ASSERT_EQ(0, kSmiTag); |
| 1014 | andi(scratch, value, kSmiTagMask); |
| 1015 | Branch(not_smi_label, ne, scratch, Operand(zero_reg)); |
| 1016 | } |
| 1017 | |
| 1018 | // Jump if either of the registers contain a non-smi. |
| 1019 | void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi); |
| 1020 | // Jump if either of the registers contain a smi. |
| 1021 | void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi); |
| 1022 | |
| 1023 | // Abort execution if argument is a smi. Used in debug code. |
| 1024 | void AbortIfSmi(Register object); |
| 1025 | void AbortIfNotSmi(Register object); |
| 1026 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1027 | // Abort execution if argument is a string. Used in debug code. |
| 1028 | void AbortIfNotString(Register object); |
| 1029 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1030 | // Abort execution if argument is not the root value with the given index. |
| 1031 | void AbortIfNotRootValue(Register src, |
| 1032 | Heap::RootListIndex root_value_index, |
| 1033 | const char* message); |
| 1034 | |
| 1035 | // --------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1036 | // HeapNumber utilities. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1037 | |
| 1038 | void JumpIfNotHeapNumber(Register object, |
| 1039 | Register heap_number_map, |
| 1040 | Register scratch, |
| 1041 | Label* on_not_heap_number); |
| 1042 | |
| 1043 | // ------------------------------------------------------------------------- |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1044 | // String utilities. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1045 | |
| 1046 | // Checks if both instance types are sequential ASCII strings and jumps to |
| 1047 | // label if either is not. |
| 1048 | void JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 1049 | Register first_object_instance_type, |
| 1050 | Register second_object_instance_type, |
| 1051 | Register scratch1, |
| 1052 | Register scratch2, |
| 1053 | Label* failure); |
| 1054 | |
| 1055 | // Check if instance type is sequential ASCII string and jump to label if |
| 1056 | // it is not. |
| 1057 | void JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 1058 | Register scratch, |
| 1059 | Label* failure); |
| 1060 | |
| 1061 | // Test that both first and second are sequential ASCII strings. |
| 1062 | // Assume that they are non-smis. |
| 1063 | void JumpIfNonSmisNotBothSequentialAsciiStrings(Register first, |
| 1064 | Register second, |
| 1065 | Register scratch1, |
| 1066 | Register scratch2, |
| 1067 | Label* failure); |
| 1068 | |
| 1069 | // Test that both first and second are sequential ASCII strings. |
| 1070 | // Check that they are non-smis. |
| 1071 | void JumpIfNotBothSequentialAsciiStrings(Register first, |
| 1072 | Register second, |
| 1073 | Register scratch1, |
| 1074 | Register scratch2, |
| 1075 | Label* failure); |
| 1076 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1077 | void LoadInstanceDescriptors(Register map, Register descriptors); |
| 1078 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1079 | private: |
| 1080 | void CallCFunctionHelper(Register function, |
| 1081 | ExternalReference function_reference, |
| 1082 | Register scratch, |
| 1083 | int num_arguments); |
| 1084 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1085 | void BranchShort(int16_t offset, BranchDelaySlot bdslot = PROTECT); |
| 1086 | void BranchShort(int16_t offset, Condition cond, Register rs, |
| 1087 | const Operand& rt, |
| 1088 | BranchDelaySlot bdslot = PROTECT); |
| 1089 | void BranchShort(Label* L, BranchDelaySlot bdslot = PROTECT); |
| 1090 | void BranchShort(Label* L, Condition cond, Register rs, |
| 1091 | const Operand& rt, |
| 1092 | BranchDelaySlot bdslot = PROTECT); |
| 1093 | void BranchAndLinkShort(int16_t offset, BranchDelaySlot bdslot = PROTECT); |
| 1094 | void BranchAndLinkShort(int16_t offset, Condition cond, Register rs, |
| 1095 | const Operand& rt, |
| 1096 | BranchDelaySlot bdslot = PROTECT); |
| 1097 | void BranchAndLinkShort(Label* L, BranchDelaySlot bdslot = PROTECT); |
| 1098 | void BranchAndLinkShort(Label* L, Condition cond, Register rs, |
| 1099 | const Operand& rt, |
| 1100 | BranchDelaySlot bdslot = PROTECT); |
| 1101 | void J(Label* L, BranchDelaySlot bdslot); |
| 1102 | void Jr(Label* L, BranchDelaySlot bdslot); |
| 1103 | void Jalr(Label* L, BranchDelaySlot bdslot); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1104 | |
| 1105 | // Helper functions for generating invokes. |
| 1106 | void InvokePrologue(const ParameterCount& expected, |
| 1107 | const ParameterCount& actual, |
| 1108 | Handle<Code> code_constant, |
| 1109 | Register code_reg, |
| 1110 | Label* done, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1111 | InvokeFlag flag, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1112 | const CallWrapper& call_wrapper, |
| 1113 | CallKind call_kind); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1114 | |
| 1115 | // Get the code for the given builtin. Returns if able to resolve |
| 1116 | // the function in the 'resolved' flag. |
| 1117 | Handle<Code> ResolveBuiltin(Builtins::JavaScript id, bool* resolved); |
| 1118 | |
| 1119 | // Activation support. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1120 | void EnterFrame(StackFrame::Type type); |
| 1121 | void LeaveFrame(StackFrame::Type type); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1122 | |
| 1123 | void InitializeNewString(Register string, |
| 1124 | Register length, |
| 1125 | Heap::RootListIndex map_index, |
| 1126 | Register scratch1, |
| 1127 | Register scratch2); |
| 1128 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1129 | // Compute memory operands for safepoint stack slots. |
| 1130 | static int SafepointRegisterStackIndex(int reg_code); |
| 1131 | MemOperand SafepointRegisterSlot(Register reg); |
| 1132 | MemOperand SafepointRegistersAndDoublesSlot(Register reg); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1133 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1134 | bool UseAbsoluteCodePointers(); |
| 1135 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1136 | bool generating_stub_; |
| 1137 | bool allow_stub_calls_; |
| 1138 | // This handle will be patched with the code object on installation. |
| 1139 | Handle<Object> code_object_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1140 | |
| 1141 | // Needs access to SafepointRegisterStackIndex for optimized frame |
| 1142 | // traversal. |
| 1143 | friend class OptimizedFrame; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1144 | }; |
| 1145 | |
| 1146 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1147 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1148 | // debugging and other types of instrumentation. When using the code patcher |
| 1149 | // the exact number of bytes specified must be emitted. It is not legal to emit |
| 1150 | // relocation information. If any of these constraints are violated it causes |
| 1151 | // an assertion to fail. |
| 1152 | class CodePatcher { |
| 1153 | public: |
| 1154 | CodePatcher(byte* address, int instructions); |
| 1155 | virtual ~CodePatcher(); |
| 1156 | |
| 1157 | // Macro assembler to emit code. |
| 1158 | MacroAssembler* masm() { return &masm_; } |
| 1159 | |
| 1160 | // Emit an instruction directly. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1161 | void Emit(Instr instr); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1162 | |
| 1163 | // Emit an address directly. |
| 1164 | void Emit(Address addr); |
| 1165 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1166 | // Change the condition part of an instruction leaving the rest of the current |
| 1167 | // instruction unchanged. |
| 1168 | void ChangeBranchCondition(Condition cond); |
| 1169 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1170 | private: |
| 1171 | byte* address_; // The address of the code being patched. |
| 1172 | int instructions_; // Number of instructions of the expected patch size. |
| 1173 | int size_; // Number of bytes of the expected patch size. |
| 1174 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 1175 | }; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1176 | |
| 1177 | |
| 1178 | // ----------------------------------------------------------------------------- |
| 1179 | // Static helper functions. |
| 1180 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1181 | static MemOperand ContextOperand(Register context, int index) { |
| 1182 | return MemOperand(context, Context::SlotOffset(index)); |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | static inline MemOperand GlobalObjectOperand() { |
| 1187 | return ContextOperand(cp, Context::GLOBAL_INDEX); |
| 1188 | } |
| 1189 | |
| 1190 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1191 | // Generate a MemOperand for loading a field from an object. |
| 1192 | static inline MemOperand FieldMemOperand(Register object, int offset) { |
| 1193 | return MemOperand(object, offset - kHeapObjectTag); |
| 1194 | } |
| 1195 | |
| 1196 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1197 | // Generate a MemOperand for storing arguments 5..N on the stack |
| 1198 | // when calling CallCFunction(). |
| 1199 | static inline MemOperand CFunctionArgumentOperand(int index) { |
| 1200 | ASSERT(index > StandardFrameConstants::kCArgSlotCount); |
| 1201 | // Argument 5 takes the slot just past the four Arg-slots. |
| 1202 | int offset = |
| 1203 | (index - 5) * kPointerSize + StandardFrameConstants::kCArgsSlotsSize; |
| 1204 | return MemOperand(sp, offset); |
| 1205 | } |
| 1206 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1207 | |
| 1208 | #ifdef GENERATED_CODE_COVERAGE |
| 1209 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1210 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1211 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1212 | #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> |
| 1213 | #else |
| 1214 | #define ACCESS_MASM(masm) masm-> |
| 1215 | #endif |
| 1216 | |
| 1217 | } } // namespace v8::internal |
| 1218 | |
| 1219 | #endif // V8_MIPS_MACRO_ASSEMBLER_MIPS_H_ |