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