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