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