Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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_ARM_MACRO_ASSEMBLER_ARM_H_ |
| 29 | #define V8_ARM_MACRO_ASSEMBLER_ARM_H_ |
| 30 | |
| 31 | #include "assembler.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 32 | #include "v8globals.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 37 | // ---------------------------------------------------------------------------- |
| 38 | // Static helper functions |
| 39 | |
| 40 | // Generate a MemOperand for loading a field from an object. |
| 41 | static inline MemOperand FieldMemOperand(Register object, int offset) { |
| 42 | return MemOperand(object, offset - kHeapObjectTag); |
| 43 | } |
| 44 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 45 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 46 | static inline Operand SmiUntagOperand(Register object) { |
| 47 | return Operand(object, ASR, kSmiTagSize); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | // Give alias names to registers |
| 53 | const Register cp = { 8 }; // JavaScript context pointer |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 54 | const Register kRootRegister = { 10 }; // Roots array pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 55 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 56 | // Flags used for the AllocateInNewSpace functions. |
| 57 | enum AllocationFlags { |
| 58 | // No special flags. |
| 59 | NO_ALLOCATION_FLAGS = 0, |
| 60 | // Return the pointer to the allocated already tagged as a heap object. |
| 61 | TAG_OBJECT = 1 << 0, |
| 62 | // The content of the result register already contains the allocation top in |
| 63 | // new space. |
| 64 | RESULT_CONTAINS_TOP = 1 << 1, |
| 65 | // Specify that the requested size of the space to allocate is specified in |
| 66 | // words instead of bytes. |
| 67 | SIZE_IN_WORDS = 1 << 2 |
| 68 | }; |
| 69 | |
| 70 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 71 | // Flags used for the ObjectToDoubleVFPRegister function. |
| 72 | enum ObjectToDoubleFlags { |
| 73 | // No special flags. |
| 74 | NO_OBJECT_TO_DOUBLE_FLAGS = 0, |
| 75 | // Object is known to be a non smi. |
| 76 | OBJECT_NOT_SMI = 1 << 0, |
| 77 | // Don't load NaNs or infinities, branch to the non number case instead. |
| 78 | AVOID_NANS_AND_INFINITIES = 1 << 1 |
| 79 | }; |
| 80 | |
| 81 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | // MacroAssembler implements a collection of frequently used macros. |
| 83 | class MacroAssembler: public Assembler { |
| 84 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 85 | // The isolate parameter can be NULL if the macro assembler should |
| 86 | // not use isolate-dependent functionality. In this case, it's the |
| 87 | // responsibility of the caller to never invoke such function on the |
| 88 | // macro assembler. |
| 89 | MacroAssembler(Isolate* isolate, void* buffer, int size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 90 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 91 | // Jump, Call, and Ret pseudo instructions implementing inter-working. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 92 | void Jump(Register target, Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 93 | void Jump(Address target, RelocInfo::Mode rmode, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al); |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 95 | static int CallSize(Register target, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | void Call(Register target, Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 97 | static int CallSize(Address target, |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 98 | RelocInfo::Mode rmode, |
| 99 | Condition cond = al); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 100 | void Call(Address target, RelocInfo::Mode rmode, Condition cond = al); |
| 101 | static int CallSize(Handle<Code> code, |
| 102 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 103 | unsigned ast_id = kNoASTId, |
| 104 | Condition cond = al); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 105 | void Call(Handle<Code> code, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 106 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
| 107 | unsigned ast_id = kNoASTId, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 108 | Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 109 | void Ret(Condition cond = al); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 110 | |
| 111 | // Emit code to discard a non-negative number of pointer-sized elements |
| 112 | // from the stack, clobbering only the sp register. |
| 113 | void Drop(int count, Condition cond = al); |
| 114 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 115 | void Ret(int drop, Condition cond = al); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 116 | |
| 117 | // Swap two registers. If the scratch register is omitted then a slightly |
| 118 | // less efficient form using xor instead of mov is emitted. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 119 | void Swap(Register reg1, |
| 120 | Register reg2, |
| 121 | Register scratch = no_reg, |
| 122 | Condition cond = al); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 123 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 124 | |
| 125 | void And(Register dst, Register src1, const Operand& src2, |
| 126 | Condition cond = al); |
| 127 | void Ubfx(Register dst, Register src, int lsb, int width, |
| 128 | Condition cond = al); |
| 129 | void Sbfx(Register dst, Register src, int lsb, int width, |
| 130 | Condition cond = al); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 131 | // The scratch register is not used for ARMv7. |
| 132 | // scratch can be the same register as src (in which case it is trashed), but |
| 133 | // not the same as dst. |
| 134 | void Bfi(Register dst, |
| 135 | Register src, |
| 136 | Register scratch, |
| 137 | int lsb, |
| 138 | int width, |
| 139 | Condition cond = al); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 140 | void Bfc(Register dst, int lsb, int width, Condition cond = al); |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 141 | void Usat(Register dst, int satpos, const Operand& src, |
| 142 | Condition cond = al); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 143 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 144 | void Call(Label* target); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 145 | |
| 146 | // Register move. May do nothing if the registers are identical. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 147 | void Move(Register dst, Handle<Object> value); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 148 | void Move(Register dst, Register src, Condition cond = al); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 149 | void Move(DoubleRegister dst, DoubleRegister src); |
| 150 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 151 | // Load an object from the root table. |
| 152 | void LoadRoot(Register destination, |
| 153 | Heap::RootListIndex index, |
| 154 | Condition cond = al); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 155 | // Store an object to the root table. |
| 156 | void StoreRoot(Register source, |
| 157 | Heap::RootListIndex index, |
| 158 | Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 159 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 160 | |
| 161 | // Check if object is in new space. |
| 162 | // scratch can be object itself, but it will be clobbered. |
| 163 | void InNewSpace(Register object, |
| 164 | Register scratch, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 165 | Condition cond, // eq for new space, ne otherwise |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 166 | Label* branch); |
| 167 | |
| 168 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 169 | // For the page containing |object| mark the region covering [address] |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 170 | // dirty. The object address must be in the first 8K of an allocated page. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 171 | void RecordWriteHelper(Register object, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 172 | Register address, |
| 173 | Register scratch); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 174 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 175 | // For the page containing |object| mark the region covering |
| 176 | // [object+offset] dirty. The object address must be in the first 8K |
| 177 | // of an allocated page. The 'scratch' registers are used in the |
| 178 | // implementation and all 3 registers are clobbered by the |
| 179 | // operation, as well as the ip register. RecordWrite updates the |
| 180 | // write barrier even when storing smis. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 181 | void RecordWrite(Register object, |
| 182 | Operand offset, |
| 183 | Register scratch0, |
| 184 | Register scratch1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 185 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 186 | // For the page containing |object| mark the region covering |
| 187 | // [address] dirty. The object address must be in the first 8K of an |
| 188 | // allocated page. All 3 registers are clobbered by the operation, |
| 189 | // as well as the ip register. RecordWrite updates the write barrier |
| 190 | // even when storing smis. |
| 191 | void RecordWrite(Register object, |
| 192 | Register address, |
| 193 | Register scratch); |
| 194 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 195 | // Push a handle. |
| 196 | void Push(Handle<Object> handle); |
| 197 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 198 | // Push two registers. Pushes leftmost register first (to highest address). |
| 199 | void Push(Register src1, Register src2, Condition cond = al) { |
| 200 | ASSERT(!src1.is(src2)); |
| 201 | if (src1.code() > src2.code()) { |
| 202 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 203 | } else { |
| 204 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 205 | str(src2, MemOperand(sp, 4, NegPreIndex), cond); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // Push three registers. Pushes leftmost register first (to highest address). |
| 210 | void Push(Register src1, Register src2, Register src3, Condition cond = al) { |
| 211 | ASSERT(!src1.is(src2)); |
| 212 | ASSERT(!src2.is(src3)); |
| 213 | ASSERT(!src1.is(src3)); |
| 214 | if (src1.code() > src2.code()) { |
| 215 | if (src2.code() > src3.code()) { |
| 216 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 217 | } else { |
| 218 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 219 | str(src3, MemOperand(sp, 4, NegPreIndex), cond); |
| 220 | } |
| 221 | } else { |
| 222 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 223 | Push(src2, src3, cond); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // Push four registers. Pushes leftmost register first (to highest address). |
| 228 | void Push(Register src1, Register src2, |
| 229 | Register src3, Register src4, Condition cond = al) { |
| 230 | ASSERT(!src1.is(src2)); |
| 231 | ASSERT(!src2.is(src3)); |
| 232 | ASSERT(!src1.is(src3)); |
| 233 | ASSERT(!src1.is(src4)); |
| 234 | ASSERT(!src2.is(src4)); |
| 235 | ASSERT(!src3.is(src4)); |
| 236 | if (src1.code() > src2.code()) { |
| 237 | if (src2.code() > src3.code()) { |
| 238 | if (src3.code() > src4.code()) { |
| 239 | stm(db_w, |
| 240 | sp, |
| 241 | src1.bit() | src2.bit() | src3.bit() | src4.bit(), |
| 242 | cond); |
| 243 | } else { |
| 244 | stm(db_w, sp, src1.bit() | src2.bit() | src3.bit(), cond); |
| 245 | str(src4, MemOperand(sp, 4, NegPreIndex), cond); |
| 246 | } |
| 247 | } else { |
| 248 | stm(db_w, sp, src1.bit() | src2.bit(), cond); |
| 249 | Push(src3, src4, cond); |
| 250 | } |
| 251 | } else { |
| 252 | str(src1, MemOperand(sp, 4, NegPreIndex), cond); |
| 253 | Push(src2, src3, src4, cond); |
| 254 | } |
| 255 | } |
| 256 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 257 | // Pop two registers. Pops rightmost register first (from lower address). |
| 258 | void Pop(Register src1, Register src2, Condition cond = al) { |
| 259 | ASSERT(!src1.is(src2)); |
| 260 | if (src1.code() > src2.code()) { |
| 261 | ldm(ia_w, sp, src1.bit() | src2.bit(), cond); |
| 262 | } else { |
| 263 | ldr(src2, MemOperand(sp, 4, PostIndex), cond); |
| 264 | ldr(src1, MemOperand(sp, 4, PostIndex), cond); |
| 265 | } |
| 266 | } |
| 267 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 268 | // Push and pop the registers that can hold pointers, as defined by the |
| 269 | // RegList constant kSafepointSavedRegisters. |
| 270 | void PushSafepointRegisters(); |
| 271 | void PopSafepointRegisters(); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 272 | void PushSafepointRegistersAndDoubles(); |
| 273 | void PopSafepointRegistersAndDoubles(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 274 | // Store value in register src in the safepoint stack slot for |
| 275 | // register dst. |
| 276 | void StoreToSafepointRegisterSlot(Register src, Register dst); |
| 277 | void StoreToSafepointRegistersAndDoublesSlot(Register src, Register dst); |
| 278 | // Load the value of the src register from its safepoint stack slot |
| 279 | // into register dst. |
| 280 | void LoadFromSafepointRegisterSlot(Register dst, Register src); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 281 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 282 | // Load two consecutive registers with two consecutive memory locations. |
| 283 | void Ldrd(Register dst1, |
| 284 | Register dst2, |
| 285 | const MemOperand& src, |
| 286 | Condition cond = al); |
| 287 | |
| 288 | // Store two consecutive registers to two consecutive memory locations. |
| 289 | void Strd(Register src1, |
| 290 | Register src2, |
| 291 | const MemOperand& dst, |
| 292 | Condition cond = al); |
| 293 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 294 | // Clear specified FPSCR bits. |
| 295 | void ClearFPSCRBits(const uint32_t bits_to_clear, |
| 296 | const Register scratch, |
| 297 | const Condition cond = al); |
| 298 | |
| 299 | // Compare double values and move the result to the normal condition flags. |
| 300 | void VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 301 | const DwVfpRegister src2, |
| 302 | const Condition cond = al); |
| 303 | void VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 304 | const double src2, |
| 305 | const Condition cond = al); |
| 306 | |
| 307 | // Compare double values and then load the fpscr flags to a register. |
| 308 | void VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 309 | const DwVfpRegister src2, |
| 310 | const Register fpscr_flags, |
| 311 | const Condition cond = al); |
| 312 | void VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 313 | const double src2, |
| 314 | const Register fpscr_flags, |
| 315 | const Condition cond = al); |
| 316 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 317 | void Vmov(const DwVfpRegister dst, |
| 318 | const double imm, |
| 319 | const Condition cond = al); |
| 320 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 321 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | // --------------------------------------------------------------------------- |
| 323 | // Activation frames |
| 324 | |
| 325 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 326 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 327 | |
| 328 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 329 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 330 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 331 | // Enter exit frame. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 332 | // stack_space - extra stack space, used for alignment before call to C. |
| 333 | void EnterExitFrame(bool save_doubles, int stack_space = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 334 | |
| 335 | // Leave the current exit frame. Expects the return value in r0. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 336 | // Expect the number of values, pushed prior to the exit frame, to |
| 337 | // remove in a register (or no_reg, if there is nothing to remove). |
| 338 | void LeaveExitFrame(bool save_doubles, Register argument_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 339 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 340 | // Get the actual activation frame alignment for target environment. |
| 341 | static int ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 343 | void LoadContext(Register dst, int context_chain_length); |
| 344 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 345 | void LoadGlobalFunction(int index, Register function); |
| 346 | |
| 347 | // Load the initial map from the global function. The registers |
| 348 | // function and map can be the same, function is then overwritten. |
| 349 | void LoadGlobalFunctionInitialMap(Register function, |
| 350 | Register map, |
| 351 | Register scratch); |
| 352 | |
Ben Murdoch | 692be65 | 2012-01-10 18:47:50 +0000 | [diff] [blame] | 353 | void InitializeRootRegister() { |
| 354 | ExternalReference roots_address = |
| 355 | ExternalReference::roots_address(isolate()); |
| 356 | mov(kRootRegister, Operand(roots_address)); |
| 357 | } |
| 358 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 359 | // --------------------------------------------------------------------------- |
| 360 | // JavaScript invokes |
| 361 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 362 | // Setup call kind marking in ecx. The method takes ecx as an |
| 363 | // explicit first parameter to make the code more readable at the |
| 364 | // call sites. |
| 365 | void SetCallKind(Register dst, CallKind kind); |
| 366 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | // Invoke the JavaScript function code by either calling or jumping. |
| 368 | void InvokeCode(Register code, |
| 369 | const ParameterCount& expected, |
| 370 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 371 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 372 | const CallWrapper& call_wrapper, |
| 373 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 374 | |
| 375 | void InvokeCode(Handle<Code> code, |
| 376 | const ParameterCount& expected, |
| 377 | const ParameterCount& actual, |
| 378 | RelocInfo::Mode rmode, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 379 | InvokeFlag flag, |
| 380 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 381 | |
| 382 | // Invoke the JavaScript function in the given register. Changes the |
| 383 | // current context to the context in the function before invoking. |
| 384 | void InvokeFunction(Register function, |
| 385 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 386 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 387 | const CallWrapper& call_wrapper, |
| 388 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 389 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 390 | void InvokeFunction(JSFunction* function, |
| 391 | const ParameterCount& actual, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 392 | InvokeFlag flag, |
| 393 | CallKind call_kind); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 394 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 395 | void IsObjectJSObjectType(Register heap_object, |
| 396 | Register map, |
| 397 | Register scratch, |
| 398 | Label* fail); |
| 399 | |
| 400 | void IsInstanceJSObjectType(Register map, |
| 401 | Register scratch, |
| 402 | Label* fail); |
| 403 | |
| 404 | void IsObjectJSStringType(Register object, |
| 405 | Register scratch, |
| 406 | Label* fail); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 407 | |
| 408 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 409 | // --------------------------------------------------------------------------- |
| 410 | // Debugger Support |
| 411 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 412 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 413 | #endif |
| 414 | |
| 415 | // --------------------------------------------------------------------------- |
| 416 | // Exception handling |
| 417 | |
| 418 | // Push a new try handler and link into try handler chain. |
| 419 | // The return address must be passed in register lr. |
| 420 | // On exit, r0 contains TOS (code slot). |
| 421 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 422 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 423 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 424 | // Must preserve the result register. |
| 425 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 426 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 427 | // Passes thrown value (in r0) to the handler of top of the try handler chain. |
| 428 | void Throw(Register value); |
| 429 | |
| 430 | // Propagates an uncatchable exception to the top of the current JS stack's |
| 431 | // handler chain. |
| 432 | void ThrowUncatchable(UncatchableExceptionType type, Register value); |
| 433 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 434 | // --------------------------------------------------------------------------- |
| 435 | // Inline caching support |
| 436 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | // Generate code for checking access rights - used for security checks |
| 438 | // on access to global objects across environments. The holder register |
| 439 | // is left untouched, whereas both scratch registers are clobbered. |
| 440 | void CheckAccessGlobalProxy(Register holder_reg, |
| 441 | Register scratch, |
| 442 | Label* miss); |
| 443 | |
Ben Murdoch | 2b4ba11 | 2012-01-20 14:57:15 +0000 | [diff] [blame] | 444 | void GetNumberHash(Register t0, Register scratch); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 445 | |
| 446 | void LoadFromNumberDictionary(Label* miss, |
| 447 | Register elements, |
| 448 | Register key, |
| 449 | Register result, |
| 450 | Register t0, |
| 451 | Register t1, |
| 452 | Register t2); |
| 453 | |
| 454 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 455 | inline void MarkCode(NopMarkerTypes type) { |
| 456 | nop(type); |
| 457 | } |
| 458 | |
| 459 | // Check if the given instruction is a 'type' marker. |
| 460 | // ie. check if is is a mov r<type>, r<type> (referenced as nop(type)) |
| 461 | // These instructions are generated to mark special location in the code, |
| 462 | // like some special IC code. |
| 463 | static inline bool IsMarkedCode(Instr instr, int type) { |
| 464 | ASSERT((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER)); |
| 465 | return IsNop(instr, type); |
| 466 | } |
| 467 | |
| 468 | |
| 469 | static inline int GetCodeMarker(Instr instr) { |
| 470 | int dst_reg_offset = 12; |
| 471 | int dst_mask = 0xf << dst_reg_offset; |
| 472 | int src_mask = 0xf; |
| 473 | int dst_reg = (instr & dst_mask) >> dst_reg_offset; |
| 474 | int src_reg = instr & src_mask; |
| 475 | uint32_t non_register_mask = ~(dst_mask | src_mask); |
| 476 | uint32_t mov_mask = al | 13 << 21; |
| 477 | |
| 478 | // Return <n> if we have a mov rn rn, else return -1. |
| 479 | int type = ((instr & non_register_mask) == mov_mask) && |
| 480 | (dst_reg == src_reg) && |
| 481 | (FIRST_IC_MARKER <= dst_reg) && (dst_reg < LAST_CODE_MARKER) |
| 482 | ? src_reg |
| 483 | : -1; |
| 484 | ASSERT((type == -1) || |
| 485 | ((FIRST_IC_MARKER <= type) && (type < LAST_CODE_MARKER))); |
| 486 | return type; |
| 487 | } |
| 488 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | |
| 490 | // --------------------------------------------------------------------------- |
| 491 | // Allocation support |
| 492 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 493 | // Allocate an object in new space. The object_size is specified |
| 494 | // either in bytes or in words if the allocation flag SIZE_IN_WORDS |
| 495 | // is passed. If the new space is exhausted control continues at the |
| 496 | // gc_required label. The allocated object is returned in result. If |
| 497 | // the flag tag_allocated_object is true the result is tagged as as |
| 498 | // a heap object. All registers are clobbered also when control |
| 499 | // continues at the gc_required label. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | void AllocateInNewSpace(int object_size, |
| 501 | Register result, |
| 502 | Register scratch1, |
| 503 | Register scratch2, |
| 504 | Label* gc_required, |
| 505 | AllocationFlags flags); |
| 506 | void AllocateInNewSpace(Register object_size, |
| 507 | Register result, |
| 508 | Register scratch1, |
| 509 | Register scratch2, |
| 510 | Label* gc_required, |
| 511 | AllocationFlags flags); |
| 512 | |
| 513 | // Undo allocation in new space. The object passed and objects allocated after |
| 514 | // it will no longer be allocated. The caller must make sure that no pointers |
| 515 | // are left to the object(s) no longer allocated as they would be invalid when |
| 516 | // allocation is undone. |
| 517 | void UndoAllocationInNewSpace(Register object, Register scratch); |
| 518 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 519 | |
| 520 | void AllocateTwoByteString(Register result, |
| 521 | Register length, |
| 522 | Register scratch1, |
| 523 | Register scratch2, |
| 524 | Register scratch3, |
| 525 | Label* gc_required); |
| 526 | void AllocateAsciiString(Register result, |
| 527 | Register length, |
| 528 | Register scratch1, |
| 529 | Register scratch2, |
| 530 | Register scratch3, |
| 531 | Label* gc_required); |
| 532 | void AllocateTwoByteConsString(Register result, |
| 533 | Register length, |
| 534 | Register scratch1, |
| 535 | Register scratch2, |
| 536 | Label* gc_required); |
| 537 | void AllocateAsciiConsString(Register result, |
| 538 | Register length, |
| 539 | Register scratch1, |
| 540 | Register scratch2, |
| 541 | Label* gc_required); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 542 | void AllocateTwoByteSlicedString(Register result, |
| 543 | Register length, |
| 544 | Register scratch1, |
| 545 | Register scratch2, |
| 546 | Label* gc_required); |
| 547 | void AllocateAsciiSlicedString(Register result, |
| 548 | Register length, |
| 549 | Register scratch1, |
| 550 | Register scratch2, |
| 551 | Label* gc_required); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 552 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 553 | // Allocates a heap number or jumps to the gc_required label if the young |
| 554 | // space is full and a scavenge is needed. All registers are clobbered also |
| 555 | // when control continues at the gc_required label. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 556 | void AllocateHeapNumber(Register result, |
| 557 | Register scratch1, |
| 558 | Register scratch2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 559 | Register heap_number_map, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 560 | Label* gc_required); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 561 | void AllocateHeapNumberWithValue(Register result, |
| 562 | DwVfpRegister value, |
| 563 | Register scratch1, |
| 564 | Register scratch2, |
| 565 | Register heap_number_map, |
| 566 | Label* gc_required); |
| 567 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 568 | // Copies a fixed number of fields of heap objects from src to dst. |
| 569 | void CopyFields(Register dst, Register src, RegList temps, int field_count); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 570 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 571 | // Copies a number of bytes from src to dst. All registers are clobbered. On |
| 572 | // exit src and dst will point to the place just after where the last byte was |
| 573 | // read or written and length will be zero. |
| 574 | void CopyBytes(Register src, |
| 575 | Register dst, |
| 576 | Register length, |
| 577 | Register scratch); |
| 578 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 579 | // --------------------------------------------------------------------------- |
| 580 | // Support functions. |
| 581 | |
| 582 | // Try to get function prototype of a function and puts the value in |
| 583 | // the result register. Checks that the function really is a |
| 584 | // function and jumps to the miss label if the fast checks fail. The |
| 585 | // function register will be untouched; the other registers may be |
| 586 | // clobbered. |
| 587 | void TryGetFunctionPrototype(Register function, |
| 588 | Register result, |
| 589 | Register scratch, |
| 590 | Label* miss); |
| 591 | |
| 592 | // Compare object type for heap object. heap_object contains a non-Smi |
| 593 | // whose object type should be compared with the given type. This both |
| 594 | // sets the flags and leaves the object type in the type_reg register. |
| 595 | // It leaves the map in the map register (unless the type_reg and map register |
| 596 | // are the same register). It leaves the heap object in the heap_object |
| 597 | // register unless the heap_object register is the same register as one of the |
| 598 | // other registers. |
| 599 | void CompareObjectType(Register heap_object, |
| 600 | Register map, |
| 601 | Register type_reg, |
| 602 | InstanceType type); |
| 603 | |
| 604 | // Compare instance type in a map. map contains a valid map object whose |
| 605 | // object type should be compared with the given type. This both |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 606 | // sets the flags and leaves the object type in the type_reg register. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 607 | void CompareInstanceType(Register map, |
| 608 | Register type_reg, |
| 609 | InstanceType type); |
| 610 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 611 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 612 | // Check if a map for a JSObject indicates that the object has fast elements. |
| 613 | // Jump to the specified label if it does not. |
| 614 | void CheckFastElements(Register map, |
| 615 | Register scratch, |
| 616 | Label* fail); |
| 617 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 618 | // Check if the map of an object is equal to a specified map (either |
| 619 | // given directly or as an index into the root list) and branch to |
| 620 | // label if not. Skip the smi check if not required (object is known |
| 621 | // to be a heap object) |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 622 | void CheckMap(Register obj, |
| 623 | Register scratch, |
| 624 | Handle<Map> map, |
| 625 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 626 | SmiCheckType smi_check_type); |
| 627 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 628 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 629 | void CheckMap(Register obj, |
| 630 | Register scratch, |
| 631 | Heap::RootListIndex index, |
| 632 | Label* fail, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 633 | SmiCheckType smi_check_type); |
| 634 | |
| 635 | |
| 636 | // Check if the map of an object is equal to a specified map and branch to a |
| 637 | // specified target if equal. Skip the smi check if not required (object is |
| 638 | // known to be a heap object) |
| 639 | void DispatchMap(Register obj, |
| 640 | Register scratch, |
| 641 | Handle<Map> map, |
| 642 | Handle<Code> success, |
| 643 | SmiCheckType smi_check_type); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 644 | |
| 645 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 646 | // Compare the object in a register to a value from the root list. |
| 647 | // Uses the ip register as scratch. |
| 648 | void CompareRoot(Register obj, Heap::RootListIndex index); |
| 649 | |
| 650 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 651 | // Load and check the instance type of an object for being a string. |
| 652 | // Loads the type into the second argument register. |
| 653 | // Returns a condition that will be enabled if the object was a string. |
| 654 | Condition IsObjectStringType(Register obj, |
| 655 | Register type) { |
| 656 | ldr(type, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 657 | ldrb(type, FieldMemOperand(type, Map::kInstanceTypeOffset)); |
| 658 | tst(type, Operand(kIsNotStringMask)); |
| 659 | ASSERT_EQ(0, kStringTag); |
| 660 | return eq; |
| 661 | } |
| 662 | |
| 663 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 664 | // Generates code for reporting that an illegal operation has |
| 665 | // occurred. |
| 666 | void IllegalOperation(int num_arguments); |
| 667 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 668 | // Picks out an array index from the hash field. |
| 669 | // Register use: |
| 670 | // hash - holds the index's hash. Clobbered. |
| 671 | // index - holds the overwritten index on exit. |
| 672 | void IndexFromHash(Register hash, Register index); |
| 673 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 674 | // Get the number of least significant bits from a register |
| 675 | void GetLeastBitsFromSmi(Register dst, Register src, int num_least_bits); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 676 | void GetLeastBitsFromInt32(Register dst, Register src, int mun_least_bits); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 677 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 678 | // Uses VFP instructions to Convert a Smi to a double. |
| 679 | void IntegerToDoubleConversionWithVFP3(Register inReg, |
| 680 | Register outHighReg, |
| 681 | Register outLowReg); |
| 682 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 683 | // Load the value of a number object into a VFP double register. If the object |
| 684 | // is not a number a jump to the label not_number is performed and the VFP |
| 685 | // double register is unchanged. |
| 686 | void ObjectToDoubleVFPRegister( |
| 687 | Register object, |
| 688 | DwVfpRegister value, |
| 689 | Register scratch1, |
| 690 | Register scratch2, |
| 691 | Register heap_number_map, |
| 692 | SwVfpRegister scratch3, |
| 693 | Label* not_number, |
| 694 | ObjectToDoubleFlags flags = NO_OBJECT_TO_DOUBLE_FLAGS); |
| 695 | |
| 696 | // Load the value of a smi object into a VFP double register. The register |
| 697 | // scratch1 can be the same register as smi in which case smi will hold the |
| 698 | // untagged value afterwards. |
| 699 | void SmiToDoubleVFPRegister(Register smi, |
| 700 | DwVfpRegister value, |
| 701 | Register scratch1, |
| 702 | SwVfpRegister scratch2); |
| 703 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 704 | // Convert the HeapNumber pointed to by source to a 32bits signed integer |
| 705 | // dest. If the HeapNumber does not fit into a 32bits signed integer branch |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 706 | // to not_int32 label. If VFP3 is available double_scratch is used but not |
| 707 | // scratch2. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 708 | void ConvertToInt32(Register source, |
| 709 | Register dest, |
| 710 | Register scratch, |
| 711 | Register scratch2, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 712 | DwVfpRegister double_scratch, |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 713 | Label *not_int32); |
| 714 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 715 | // Truncates a double using a specific rounding mode. |
| 716 | // Clears the z flag (ne condition) if an overflow occurs. |
| 717 | // If exact_conversion is true, the z flag is also cleared if the conversion |
| 718 | // was inexact, ie. if the double value could not be converted exactly |
| 719 | // to a 32bit integer. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 720 | void EmitVFPTruncate(VFPRoundingMode rounding_mode, |
| 721 | SwVfpRegister result, |
| 722 | DwVfpRegister double_input, |
| 723 | Register scratch1, |
| 724 | Register scratch2, |
| 725 | CheckForInexactConversion check |
| 726 | = kDontCheckForInexactConversion); |
| 727 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 728 | // Helper for EmitECMATruncate. |
| 729 | // This will truncate a floating-point value outside of the singed 32bit |
| 730 | // integer range to a 32bit signed integer. |
| 731 | // Expects the double value loaded in input_high and input_low. |
| 732 | // Exits with the answer in 'result'. |
| 733 | // Note that this code does not work for values in the 32bit range! |
| 734 | void EmitOutOfInt32RangeTruncate(Register result, |
| 735 | Register input_high, |
| 736 | Register input_low, |
| 737 | Register scratch); |
| 738 | |
| 739 | // Performs a truncating conversion of a floating point number as used by |
| 740 | // the JS bitwise operations. See ECMA-262 9.5: ToInt32. |
| 741 | // Exits with 'result' holding the answer and all other registers clobbered. |
| 742 | void EmitECMATruncate(Register result, |
| 743 | DwVfpRegister double_input, |
| 744 | SwVfpRegister single_scratch, |
| 745 | Register scratch, |
| 746 | Register scratch2, |
| 747 | Register scratch3); |
| 748 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 749 | // Count leading zeros in a 32 bit word. On ARM5 and later it uses the clz |
| 750 | // instruction. On pre-ARM5 hardware this routine gives the wrong answer |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 751 | // for 0 (31 instead of 32). Source and scratch can be the same in which case |
| 752 | // the source is clobbered. Source and zeros can also be the same in which |
| 753 | // case scratch should be a different register. |
| 754 | void CountLeadingZeros(Register zeros, |
| 755 | Register source, |
| 756 | Register scratch); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 757 | |
| 758 | // --------------------------------------------------------------------------- |
| 759 | // Runtime calls |
| 760 | |
| 761 | // Call a code stub. |
| 762 | void CallStub(CodeStub* stub, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 763 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 764 | // Call a code stub and return the code object called. Try to generate |
| 765 | // the code if necessary. Do not perform a GC but instead return a retry |
| 766 | // after GC failure. |
| 767 | MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub, Condition cond = al); |
| 768 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 769 | // Call a code stub. |
| 770 | void TailCallStub(CodeStub* stub, Condition cond = al); |
| 771 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 772 | // Tail call a code stub (jump) and return the code object called. Try to |
| 773 | // generate the code if necessary. Do not perform a GC but instead return |
| 774 | // a retry after GC failure. |
| 775 | MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub, |
| 776 | Condition cond = al); |
| 777 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 778 | // Call a runtime routine. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 779 | void CallRuntime(const Runtime::Function* f, int num_arguments); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 780 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 781 | |
| 782 | // Convenience function: Same as above, but takes the fid instead. |
| 783 | void CallRuntime(Runtime::FunctionId fid, int num_arguments); |
| 784 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 785 | // Convenience function: call an external reference. |
| 786 | void CallExternalReference(const ExternalReference& ext, |
| 787 | int num_arguments); |
| 788 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 789 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 790 | // Like JumpToExternalReference, but also takes care of passing the number |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 791 | // of parameters. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 792 | void TailCallExternalReference(const ExternalReference& ext, |
| 793 | int num_arguments, |
| 794 | int result_size); |
| 795 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 796 | // Tail call of a runtime routine (jump). Try to generate the code if |
| 797 | // necessary. Do not perform a GC but instead return a retry after GC |
| 798 | // failure. |
| 799 | MUST_USE_RESULT MaybeObject* TryTailCallExternalReference( |
| 800 | const ExternalReference& ext, int num_arguments, int result_size); |
| 801 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 802 | // Convenience function: tail call a runtime routine (jump). |
| 803 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 804 | int num_arguments, |
| 805 | int result_size); |
| 806 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 807 | int CalculateStackPassedWords(int num_reg_arguments, |
| 808 | int num_double_arguments); |
| 809 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 810 | // Before calling a C-function from generated code, align arguments on stack. |
| 811 | // After aligning the frame, non-register arguments must be stored in |
| 812 | // sp[0], sp[4], etc., not pushed. The argument count assumes all arguments |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 813 | // are word sized. If double arguments are used, this function assumes that |
| 814 | // all double arguments are stored before core registers; otherwise the |
| 815 | // correct alignment of the double values is not guaranteed. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 816 | // Some compilers/platforms require the stack to be aligned when calling |
| 817 | // C++ code. |
| 818 | // Needs a scratch register to do some arithmetic. This register will be |
| 819 | // trashed. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 820 | void PrepareCallCFunction(int num_reg_arguments, |
| 821 | int num_double_registers, |
| 822 | Register scratch); |
| 823 | void PrepareCallCFunction(int num_reg_arguments, |
| 824 | Register scratch); |
| 825 | |
| 826 | // There are two ways of passing double arguments on ARM, depending on |
| 827 | // whether soft or hard floating point ABI is used. These functions |
| 828 | // abstract parameter passing for the three different ways we call |
| 829 | // C functions from generated code. |
| 830 | void SetCallCDoubleArguments(DoubleRegister dreg); |
| 831 | void SetCallCDoubleArguments(DoubleRegister dreg1, DoubleRegister dreg2); |
| 832 | void SetCallCDoubleArguments(DoubleRegister dreg, Register reg); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 833 | |
| 834 | // Calls a C function and cleans up the space for arguments allocated |
| 835 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 836 | // garbage collection, since that might move the code and invalidate the |
| 837 | // return address (unless this is somehow accounted for by the called |
| 838 | // function). |
| 839 | void CallCFunction(ExternalReference function, int num_arguments); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 840 | void CallCFunction(Register function, Register scratch, int num_arguments); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 841 | void CallCFunction(ExternalReference function, |
| 842 | int num_reg_arguments, |
| 843 | int num_double_arguments); |
| 844 | void CallCFunction(Register function, Register scratch, |
| 845 | int num_reg_arguments, |
| 846 | int num_double_arguments); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 847 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 848 | void GetCFunctionDoubleResult(const DoubleRegister dst); |
| 849 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 850 | // Calls an API function. Allocates HandleScope, extracts returned value |
| 851 | // from handle and propagates exceptions. Restores context. |
| 852 | // stack_space - space to be unwound on exit (includes the call js |
| 853 | // arguments space and the additional space allocated for the fast call). |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 854 | MaybeObject* TryCallApiFunctionAndReturn(ExternalReference function, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 855 | int stack_space); |
| 856 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 857 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 858 | void JumpToExternalReference(const ExternalReference& builtin); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 859 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 860 | MaybeObject* TryJumpToExternalReference(const ExternalReference& ext); |
| 861 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 862 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 863 | // the unresolved list if the name does not resolve. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 864 | void InvokeBuiltin(Builtins::JavaScript id, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 865 | InvokeFlag flag, |
| 866 | const CallWrapper& call_wrapper = NullCallWrapper()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 867 | |
| 868 | // Store the code object for the given builtin in the target register and |
| 869 | // setup the function in r1. |
| 870 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 871 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 872 | // Store the function for the given builtin in the target register. |
| 873 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 874 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 875 | Handle<Object> CodeObject() { |
| 876 | ASSERT(!code_object_.is_null()); |
| 877 | return code_object_; |
| 878 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 879 | |
| 880 | |
| 881 | // --------------------------------------------------------------------------- |
| 882 | // StatsCounter support |
| 883 | |
| 884 | void SetCounter(StatsCounter* counter, int value, |
| 885 | Register scratch1, Register scratch2); |
| 886 | void IncrementCounter(StatsCounter* counter, int value, |
| 887 | Register scratch1, Register scratch2); |
| 888 | void DecrementCounter(StatsCounter* counter, int value, |
| 889 | Register scratch1, Register scratch2); |
| 890 | |
| 891 | |
| 892 | // --------------------------------------------------------------------------- |
| 893 | // Debugging |
| 894 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 895 | // Calls Abort(msg) if the condition cond is not satisfied. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 896 | // Use --debug_code to enable. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 897 | void Assert(Condition cond, const char* msg); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 898 | void AssertRegisterIsRoot(Register reg, Heap::RootListIndex index); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 899 | void AssertFastElements(Register elements); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 900 | |
| 901 | // Like Assert(), but always enabled. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 902 | void Check(Condition cond, const char* msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 903 | |
| 904 | // Print a message to stdout and abort execution. |
| 905 | void Abort(const char* msg); |
| 906 | |
| 907 | // Verify restrictions about code generated in stubs. |
| 908 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 909 | bool generating_stub() { return generating_stub_; } |
| 910 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 911 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 912 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 913 | // EABI variant for double arguments in use. |
| 914 | bool use_eabi_hardfloat() { |
| 915 | #if USE_EABI_HARDFLOAT |
| 916 | return true; |
| 917 | #else |
| 918 | return false; |
| 919 | #endif |
| 920 | } |
| 921 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 922 | // --------------------------------------------------------------------------- |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 923 | // Number utilities |
| 924 | |
| 925 | // Check whether the value of reg is a power of two and not zero. If not |
| 926 | // control continues at the label not_power_of_two. If reg is a power of two |
| 927 | // the register scratch contains the value of (reg - 1) when control falls |
| 928 | // through. |
| 929 | void JumpIfNotPowerOfTwoOrZero(Register reg, |
| 930 | Register scratch, |
| 931 | Label* not_power_of_two_or_zero); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 932 | // Check whether the value of reg is a power of two and not zero. |
| 933 | // Control falls through if it is, with scratch containing the mask |
| 934 | // value (reg - 1). |
| 935 | // Otherwise control jumps to the 'zero_and_neg' label if the value of reg is |
| 936 | // zero or negative, or jumps to the 'not_power_of_two' label if the value is |
| 937 | // strictly positive but not a power of two. |
| 938 | void JumpIfNotPowerOfTwoOrZeroAndNeg(Register reg, |
| 939 | Register scratch, |
| 940 | Label* zero_and_neg, |
| 941 | Label* not_power_of_two); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 942 | |
| 943 | // --------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 944 | // Smi utilities |
| 945 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 946 | void SmiTag(Register reg, SBit s = LeaveCC) { |
| 947 | add(reg, reg, Operand(reg), s); |
| 948 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 949 | void SmiTag(Register dst, Register src, SBit s = LeaveCC) { |
| 950 | add(dst, src, Operand(src), s); |
| 951 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 952 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 953 | // Try to convert int32 to smi. If the value is to large, preserve |
| 954 | // the original value and jump to not_a_smi. Destroys scratch and |
| 955 | // sets flags. |
| 956 | void TrySmiTag(Register reg, Label* not_a_smi, Register scratch) { |
| 957 | mov(scratch, reg); |
| 958 | SmiTag(scratch, SetCC); |
| 959 | b(vs, not_a_smi); |
| 960 | mov(reg, scratch); |
| 961 | } |
| 962 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 963 | void SmiUntag(Register reg, SBit s = LeaveCC) { |
| 964 | mov(reg, Operand(reg, ASR, kSmiTagSize), s); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 965 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 966 | void SmiUntag(Register dst, Register src, SBit s = LeaveCC) { |
| 967 | mov(dst, Operand(src, ASR, kSmiTagSize), s); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 968 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 969 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 970 | // Jump the register contains a smi. |
| 971 | inline void JumpIfSmi(Register value, Label* smi_label) { |
| 972 | tst(value, Operand(kSmiTagMask)); |
| 973 | b(eq, smi_label); |
| 974 | } |
| 975 | // Jump if either of the registers contain a non-smi. |
| 976 | inline void JumpIfNotSmi(Register value, Label* not_smi_label) { |
| 977 | tst(value, Operand(kSmiTagMask)); |
| 978 | b(ne, not_smi_label); |
| 979 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 980 | // Jump if either of the registers contain a non-smi. |
| 981 | void JumpIfNotBothSmi(Register reg1, Register reg2, Label* on_not_both_smi); |
| 982 | // Jump if either of the registers contain a smi. |
| 983 | void JumpIfEitherSmi(Register reg1, Register reg2, Label* on_either_smi); |
| 984 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 985 | // Abort execution if argument is a smi. Used in debug code. |
| 986 | void AbortIfSmi(Register object); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 987 | void AbortIfNotSmi(Register object); |
| 988 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 989 | // Abort execution if argument is a string. Used in debug code. |
| 990 | void AbortIfNotString(Register object); |
| 991 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 992 | // Abort execution if argument is not the root value with the given index. |
| 993 | void AbortIfNotRootValue(Register src, |
| 994 | Heap::RootListIndex root_value_index, |
| 995 | const char* message); |
| 996 | |
| 997 | // --------------------------------------------------------------------------- |
| 998 | // HeapNumber utilities |
| 999 | |
| 1000 | void JumpIfNotHeapNumber(Register object, |
| 1001 | Register heap_number_map, |
| 1002 | Register scratch, |
| 1003 | Label* on_not_heap_number); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1004 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1005 | // --------------------------------------------------------------------------- |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1006 | // String utilities |
| 1007 | |
| 1008 | // Checks if both objects are sequential ASCII strings and jumps to label |
| 1009 | // if either is not. Assumes that neither object is a smi. |
| 1010 | void JumpIfNonSmisNotBothSequentialAsciiStrings(Register object1, |
| 1011 | Register object2, |
| 1012 | Register scratch1, |
| 1013 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1014 | Label* failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1015 | |
| 1016 | // Checks if both objects are sequential ASCII strings and jumps to label |
| 1017 | // if either is not. |
| 1018 | void JumpIfNotBothSequentialAsciiStrings(Register first, |
| 1019 | Register second, |
| 1020 | Register scratch1, |
| 1021 | Register scratch2, |
| 1022 | Label* not_flat_ascii_strings); |
| 1023 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1024 | // Checks if both instance types are sequential ASCII strings and jumps to |
| 1025 | // label if either is not. |
| 1026 | void JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 1027 | Register first_object_instance_type, |
| 1028 | Register second_object_instance_type, |
| 1029 | Register scratch1, |
| 1030 | Register scratch2, |
| 1031 | Label* failure); |
| 1032 | |
| 1033 | // Check if instance type is sequential ASCII string and jump to label if |
| 1034 | // it is not. |
| 1035 | void JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 1036 | Register scratch, |
| 1037 | Label* failure); |
| 1038 | |
| 1039 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1040 | // --------------------------------------------------------------------------- |
| 1041 | // Patching helpers. |
| 1042 | |
| 1043 | // Get the location of a relocated constant (its address in the constant pool) |
| 1044 | // from its load site. |
| 1045 | void GetRelocatedValueLocation(Register ldr_location, |
| 1046 | Register result); |
| 1047 | |
| 1048 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1049 | void ClampUint8(Register output_reg, Register input_reg); |
| 1050 | |
| 1051 | void ClampDoubleToUint8(Register result_reg, |
| 1052 | DoubleRegister input_reg, |
| 1053 | DoubleRegister temp_double_reg); |
| 1054 | |
| 1055 | |
| 1056 | void LoadInstanceDescriptors(Register map, Register descriptors); |
| 1057 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1058 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1059 | void CallCFunctionHelper(Register function, |
| 1060 | ExternalReference function_reference, |
| 1061 | Register scratch, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1062 | int num_reg_arguments, |
| 1063 | int num_double_arguments); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1064 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1065 | void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1066 | |
| 1067 | // Helper functions for generating invokes. |
| 1068 | void InvokePrologue(const ParameterCount& expected, |
| 1069 | const ParameterCount& actual, |
| 1070 | Handle<Code> code_constant, |
| 1071 | Register code_reg, |
| 1072 | Label* done, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1073 | InvokeFlag flag, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1074 | const CallWrapper& call_wrapper, |
| 1075 | CallKind call_kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1076 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1077 | // Activation support. |
| 1078 | void EnterFrame(StackFrame::Type type); |
| 1079 | void LeaveFrame(StackFrame::Type type); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1080 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1081 | void InitializeNewString(Register string, |
| 1082 | Register length, |
| 1083 | Heap::RootListIndex map_index, |
| 1084 | Register scratch1, |
| 1085 | Register scratch2); |
| 1086 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1087 | // Compute memory operands for safepoint stack slots. |
| 1088 | static int SafepointRegisterStackIndex(int reg_code); |
| 1089 | MemOperand SafepointRegisterSlot(Register reg); |
| 1090 | MemOperand SafepointRegistersAndDoublesSlot(Register reg); |
| 1091 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1092 | bool generating_stub_; |
| 1093 | bool allow_stub_calls_; |
| 1094 | // This handle will be patched with the code object on installation. |
| 1095 | Handle<Object> code_object_; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1096 | |
| 1097 | // Needs access to SafepointRegisterStackIndex for optimized frame |
| 1098 | // traversal. |
| 1099 | friend class OptimizedFrame; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1100 | }; |
| 1101 | |
| 1102 | |
| 1103 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1104 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 1105 | // debugging and other types of instrumentation. When using the code patcher |
| 1106 | // the exact number of bytes specified must be emitted. It is not legal to emit |
| 1107 | // relocation information. If any of these constraints are violated it causes |
| 1108 | // an assertion to fail. |
| 1109 | class CodePatcher { |
| 1110 | public: |
| 1111 | CodePatcher(byte* address, int instructions); |
| 1112 | virtual ~CodePatcher(); |
| 1113 | |
| 1114 | // Macro assembler to emit code. |
| 1115 | MacroAssembler* masm() { return &masm_; } |
| 1116 | |
| 1117 | // Emit an instruction directly. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1118 | void Emit(Instr instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1119 | |
| 1120 | // Emit an address directly. |
| 1121 | void Emit(Address addr); |
| 1122 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1123 | // Emit the condition part of an instruction leaving the rest of the current |
| 1124 | // instruction unchanged. |
| 1125 | void EmitCondition(Condition cond); |
| 1126 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1127 | private: |
| 1128 | byte* address_; // The address of the code being patched. |
| 1129 | int instructions_; // Number of instructions of the expected patch size. |
| 1130 | int size_; // Number of bytes of the expected patch size. |
| 1131 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 1132 | }; |
| 1133 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1134 | |
| 1135 | |
| 1136 | // ----------------------------------------------------------------------------- |
| 1137 | // Static helper functions. |
| 1138 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1139 | static MemOperand ContextOperand(Register context, int index) { |
| 1140 | return MemOperand(context, Context::SlotOffset(index)); |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | static inline MemOperand GlobalObjectOperand() { |
| 1145 | return ContextOperand(cp, Context::GLOBAL_INDEX); |
| 1146 | } |
| 1147 | |
| 1148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1149 | #ifdef GENERATED_CODE_COVERAGE |
| 1150 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 1151 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 1152 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 1153 | #define ACCESS_MASM(masm) masm->stop(__FILE_LINE__); masm-> |
| 1154 | #else |
| 1155 | #define ACCESS_MASM(masm) masm-> |
| 1156 | #endif |
| 1157 | |
| 1158 | |
| 1159 | } } // namespace v8::internal |
| 1160 | |
| 1161 | #endif // V8_ARM_MACRO_ASSEMBLER_ARM_H_ |