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