ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2009 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_ARM) |
| 31 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
| 33 | #include "codegen-inl.h" |
| 34 | #include "debug.h" |
| 35 | #include "runtime.h" |
| 36 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 37 | namespace v8 { |
| 38 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 41 | : Assembler(buffer, size), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 42 | generating_stub_(false), |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 43 | allow_stub_calls_(true), |
| 44 | code_object_(Heap::undefined_value()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
| 48 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 49 | // thumb, so we require inter-working support |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 50 | #if defined(__thumb__) && !defined(USE_THUMB_INTERWORK) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | #error "flag -mthumb-interwork missing" |
| 52 | #endif |
| 53 | |
| 54 | |
| 55 | // We do not support thumb inter-working with an arm architecture not supporting |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 56 | // the blx instruction (below v5t). If you know what CPU you are compiling for |
| 57 | // you can use -march=armv7 or similar. |
| 58 | #if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS) |
| 59 | # error "For thumb inter-working we require an architecture which supports blx" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 63 | // Using bx does not yield better code, so use it only when required |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 64 | #if defined(USE_THUMB_INTERWORK) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | #define USE_BX 1 |
| 66 | #endif |
| 67 | |
| 68 | |
| 69 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 70 | #if USE_BX |
| 71 | bx(target, cond); |
| 72 | #else |
| 73 | mov(pc, Operand(target), LeaveCC, cond); |
| 74 | #endif |
| 75 | } |
| 76 | |
| 77 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 78 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 79 | Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 80 | #if USE_BX |
| 81 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 82 | bx(ip, cond); |
| 83 | #else |
| 84 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 89 | void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, |
| 90 | Condition cond) { |
| 91 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 93 | } |
| 94 | |
| 95 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 96 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 97 | Condition cond) { |
| 98 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 99 | // 'code' is always generated ARM code, never THUMB code |
| 100 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | void MacroAssembler::Call(Register target, Condition cond) { |
| 105 | #if USE_BLX |
| 106 | blx(target, cond); |
| 107 | #else |
| 108 | // set lr for return at current pc + 8 |
| 109 | mov(lr, Operand(pc), LeaveCC, cond); |
| 110 | mov(pc, Operand(target), LeaveCC, cond); |
| 111 | #endif |
| 112 | } |
| 113 | |
| 114 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 115 | void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode, |
| 116 | Condition cond) { |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 117 | #if USE_BLX |
| 118 | // On ARMv5 and after the recommended call sequence is: |
| 119 | // ldr ip, [pc, #...] |
| 120 | // blx ip |
| 121 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 122 | // The two instructions (ldr and blx) could be separated by a constant |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 123 | // pool and the code would still work. The issue comes from the |
| 124 | // patching code which expect the ldr to be just above the blx. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 125 | { BlockConstPoolScope block_const_pool(this); |
| 126 | // Statement positions are expected to be recorded when the target |
| 127 | // address is loaded. The mov method will automatically record |
| 128 | // positions when pc is the target, since this is not the case here |
| 129 | // we have to do it explicitly. |
| 130 | WriteRecordedPositions(); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 131 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 132 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 133 | blx(ip, cond); |
| 134 | } |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 135 | |
| 136 | ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 137 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | // Set lr for return at current pc + 8. |
| 139 | mov(lr, Operand(pc), LeaveCC, cond); |
| 140 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 141 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 142 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 143 | ASSERT(kCallTargetAddressOffset == kInstrSize); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 144 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 148 | void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode, |
| 149 | Condition cond) { |
| 150 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 151 | Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 152 | } |
| 153 | |
| 154 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 155 | void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, |
| 156 | Condition cond) { |
| 157 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | // 'code' is always generated ARM code, never THUMB code |
| 159 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 160 | } |
| 161 | |
| 162 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 163 | void MacroAssembler::Ret(Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 164 | #if USE_BX |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 165 | bx(lr, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 166 | #else |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 167 | mov(pc, Operand(lr), LeaveCC, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 168 | #endif |
| 169 | } |
| 170 | |
| 171 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 172 | void MacroAssembler::StackLimitCheck(Label* on_stack_overflow) { |
| 173 | LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 174 | cmp(sp, Operand(ip)); |
| 175 | b(lo, on_stack_overflow); |
| 176 | } |
| 177 | |
| 178 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 179 | void MacroAssembler::Drop(int count, Condition cond) { |
| 180 | if (count > 0) { |
| 181 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
| 185 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 186 | void MacroAssembler::Swap(Register reg1, |
| 187 | Register reg2, |
| 188 | Register scratch, |
| 189 | Condition cond) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 190 | if (scratch.is(no_reg)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 191 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 192 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 193 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 194 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 195 | mov(scratch, reg1, LeaveCC, cond); |
| 196 | mov(reg1, reg2, LeaveCC, cond); |
| 197 | mov(reg2, scratch, LeaveCC, cond); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 202 | void MacroAssembler::Call(Label* target) { |
| 203 | bl(target); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 208 | mov(dst, Operand(value)); |
| 209 | } |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 210 | |
| 211 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 212 | void MacroAssembler::Move(Register dst, Register src) { |
| 213 | if (!dst.is(src)) { |
| 214 | mov(dst, src); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 219 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 220 | Condition cond) { |
| 221 | if (!CpuFeatures::IsSupported(ARMv7) || src2.is_single_instruction()) { |
| 222 | and_(dst, src1, src2, LeaveCC, cond); |
| 223 | return; |
| 224 | } |
| 225 | int32_t immediate = src2.immediate(); |
| 226 | if (immediate == 0) { |
| 227 | mov(dst, Operand(0), LeaveCC, cond); |
| 228 | return; |
| 229 | } |
| 230 | if (IsPowerOf2(immediate + 1) && ((immediate & 1) != 0)) { |
| 231 | ubfx(dst, src1, 0, WhichPowerOf2(immediate + 1), cond); |
| 232 | return; |
| 233 | } |
| 234 | and_(dst, src1, src2, LeaveCC, cond); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 239 | Condition cond) { |
| 240 | ASSERT(lsb < 32); |
| 241 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 242 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 243 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 244 | if (lsb != 0) { |
| 245 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 246 | } |
| 247 | } else { |
| 248 | ubfx(dst, src1, lsb, width, cond); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 254 | Condition cond) { |
| 255 | ASSERT(lsb < 32); |
| 256 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 257 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 258 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 259 | int shift_up = 32 - lsb - width; |
| 260 | int shift_down = lsb + shift_up; |
| 261 | if (shift_up != 0) { |
| 262 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 263 | } |
| 264 | if (shift_down != 0) { |
| 265 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 266 | } |
| 267 | } else { |
| 268 | sbfx(dst, src1, lsb, width, cond); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 273 | void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) { |
| 274 | ASSERT(lsb < 32); |
| 275 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 276 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 277 | bic(dst, dst, Operand(mask)); |
| 278 | } else { |
| 279 | bfc(dst, lsb, width, cond); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 284 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 285 | Condition cond) { |
| 286 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 287 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 288 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 289 | |
| 290 | // These asserts are required to ensure compatibility with the ARMv7 |
| 291 | // implementation. |
| 292 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 293 | ASSERT(src.rs().is(no_reg)); |
| 294 | |
| 295 | Label done; |
| 296 | int satval = (1 << satpos) - 1; |
| 297 | |
| 298 | if (cond != al) { |
| 299 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 300 | } |
| 301 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 302 | mov(dst, src); |
| 303 | } |
| 304 | tst(dst, Operand(~satval)); |
| 305 | b(eq, &done); |
| 306 | mov(dst, Operand(0), LeaveCC, mi); // 0 if negative. |
| 307 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 308 | bind(&done); |
| 309 | } else { |
| 310 | usat(dst, satpos, src, cond); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 315 | void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) { |
| 316 | // Empty the const pool. |
| 317 | CheckConstPool(true, true); |
| 318 | add(pc, pc, Operand(index, |
| 319 | LSL, |
| 320 | assembler::arm::Instr::kInstrSizeLog2 - kSmiTagSize)); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 321 | BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * kInstrSize); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 322 | nop(); // Jump table alignment. |
| 323 | for (int i = 0; i < targets.length(); i++) { |
| 324 | b(targets[i]); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 329 | void MacroAssembler::LoadRoot(Register destination, |
| 330 | Heap::RootListIndex index, |
| 331 | Condition cond) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 332 | ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 336 | void MacroAssembler::StoreRoot(Register source, |
| 337 | Heap::RootListIndex index, |
| 338 | Condition cond) { |
| 339 | str(source, MemOperand(roots, index << kPointerSizeLog2), cond); |
| 340 | } |
| 341 | |
| 342 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 343 | void MacroAssembler::RecordWriteHelper(Register object, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 344 | Register address, |
| 345 | Register scratch) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 346 | if (FLAG_debug_code) { |
| 347 | // Check that the object is not in new space. |
| 348 | Label not_in_new_space; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 349 | InNewSpace(object, scratch, ne, ¬_in_new_space); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 350 | Abort("new-space object passed to RecordWriteHelper"); |
| 351 | bind(¬_in_new_space); |
| 352 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 353 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 354 | // Calculate page address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 355 | Bfc(object, 0, kPageSizeBits); |
| 356 | |
| 357 | // Calculate region number. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 358 | Ubfx(address, address, Page::kRegionSizeLog2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 359 | kPageSizeBits - Page::kRegionSizeLog2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 360 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 361 | // Mark region dirty. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 362 | ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 363 | mov(ip, Operand(1)); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 364 | orr(scratch, scratch, Operand(ip, LSL, address)); |
| 365 | str(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | |
| 369 | void MacroAssembler::InNewSpace(Register object, |
| 370 | Register scratch, |
| 371 | Condition cc, |
| 372 | Label* branch) { |
| 373 | ASSERT(cc == eq || cc == ne); |
| 374 | and_(scratch, object, Operand(ExternalReference::new_space_mask())); |
| 375 | cmp(scratch, Operand(ExternalReference::new_space_start())); |
| 376 | b(cc, branch); |
| 377 | } |
| 378 | |
| 379 | |
| 380 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 381 | // register 'object' contains a heap object pointer. The heap object |
| 382 | // tag is shifted away. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 383 | void MacroAssembler::RecordWrite(Register object, |
| 384 | Operand offset, |
| 385 | Register scratch0, |
| 386 | Register scratch1) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 387 | // The compiled code assumes that record write doesn't change the |
| 388 | // context register, so we check that none of the clobbered |
| 389 | // registers are cp. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 390 | ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp)); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 391 | |
| 392 | Label done; |
| 393 | |
| 394 | // First, test that the object is not in the new space. We cannot set |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 395 | // region marks for new space pages. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 396 | InNewSpace(object, scratch0, eq, &done); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 397 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 398 | // Add offset into the object. |
| 399 | add(scratch0, object, offset); |
| 400 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 401 | // Record the actual write. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 402 | RecordWriteHelper(object, scratch0, scratch1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 403 | |
| 404 | bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 405 | |
| 406 | // Clobber all input registers when running with the debug-code flag |
| 407 | // turned on to provoke errors. |
| 408 | if (FLAG_debug_code) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 409 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 410 | mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 411 | mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 412 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 416 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 417 | // register 'object' contains a heap object pointer. The heap object |
| 418 | // tag is shifted away. |
| 419 | void MacroAssembler::RecordWrite(Register object, |
| 420 | Register address, |
| 421 | Register scratch) { |
| 422 | // The compiled code assumes that record write doesn't change the |
| 423 | // context register, so we check that none of the clobbered |
| 424 | // registers are cp. |
| 425 | ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp)); |
| 426 | |
| 427 | Label done; |
| 428 | |
| 429 | // First, test that the object is not in the new space. We cannot set |
| 430 | // region marks for new space pages. |
| 431 | InNewSpace(object, scratch, eq, &done); |
| 432 | |
| 433 | // Record the actual write. |
| 434 | RecordWriteHelper(object, address, scratch); |
| 435 | |
| 436 | bind(&done); |
| 437 | |
| 438 | // Clobber all input registers when running with the debug-code flag |
| 439 | // turned on to provoke errors. |
| 440 | if (FLAG_debug_code) { |
| 441 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
| 442 | mov(address, Operand(BitCast<int32_t>(kZapValue))); |
| 443 | mov(scratch, Operand(BitCast<int32_t>(kZapValue))); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 448 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 449 | const MemOperand& src, Condition cond) { |
| 450 | ASSERT(src.rm().is(no_reg)); |
| 451 | ASSERT(!dst1.is(lr)); // r14. |
| 452 | ASSERT_EQ(0, dst1.code() % 2); |
| 453 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 454 | |
| 455 | // Generate two ldr instructions if ldrd is not available. |
| 456 | if (CpuFeatures::IsSupported(ARMv7)) { |
| 457 | CpuFeatures::Scope scope(ARMv7); |
| 458 | ldrd(dst1, dst2, src, cond); |
| 459 | } else { |
| 460 | MemOperand src2(src); |
| 461 | src2.set_offset(src2.offset() + 4); |
| 462 | if (dst1.is(src.rn())) { |
| 463 | ldr(dst2, src2, cond); |
| 464 | ldr(dst1, src, cond); |
| 465 | } else { |
| 466 | ldr(dst1, src, cond); |
| 467 | ldr(dst2, src2, cond); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | |
| 473 | void MacroAssembler::Strd(Register src1, Register src2, |
| 474 | const MemOperand& dst, Condition cond) { |
| 475 | ASSERT(dst.rm().is(no_reg)); |
| 476 | ASSERT(!src1.is(lr)); // r14. |
| 477 | ASSERT_EQ(0, src1.code() % 2); |
| 478 | ASSERT_EQ(src1.code() + 1, src2.code()); |
| 479 | |
| 480 | // Generate two str instructions if strd is not available. |
| 481 | if (CpuFeatures::IsSupported(ARMv7)) { |
| 482 | CpuFeatures::Scope scope(ARMv7); |
| 483 | strd(src1, src2, dst, cond); |
| 484 | } else { |
| 485 | MemOperand dst2(dst); |
| 486 | dst2.set_offset(dst2.offset() + 4); |
| 487 | str(src1, dst, cond); |
| 488 | str(src2, dst2, cond); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 493 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 494 | // r0-r3: preserved |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 495 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 496 | mov(ip, Operand(Smi::FromInt(type))); |
| 497 | push(ip); |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 498 | mov(ip, Operand(CodeObject())); |
| 499 | push(ip); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 500 | add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 504 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 505 | // r0: preserved |
| 506 | // r1: preserved |
| 507 | // r2: preserved |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 508 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 509 | // Drop the execution stack down to the frame pointer and restore |
| 510 | // the caller frame pointer and return address. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 511 | mov(sp, fp); |
| 512 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 516 | void MacroAssembler::EnterExitFrame(ExitFrame::Mode mode) { |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 517 | // Compute the argv pointer and keep it in a callee-saved register. |
| 518 | // r0 is argc. |
| 519 | add(r6, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 520 | sub(r6, r6, Operand(kPointerSize)); |
| 521 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 522 | // Compute callee's stack pointer before making changes and save it as |
| 523 | // ip register so that it is restored as sp register on exit, thereby |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 524 | // popping the args. |
| 525 | |
| 526 | // ip = sp + kPointerSize * #args; |
| 527 | add(ip, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 528 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 529 | // Prepare the stack to be aligned when calling into C. After this point there |
| 530 | // are 5 pushes before the call into C, so the stack needs to be aligned after |
| 531 | // 5 pushes. |
| 532 | int frame_alignment = ActivationFrameAlignment(); |
| 533 | int frame_alignment_mask = frame_alignment - 1; |
| 534 | if (frame_alignment != kPointerSize) { |
| 535 | // The following code needs to be more general if this assert does not hold. |
| 536 | ASSERT(frame_alignment == 2 * kPointerSize); |
| 537 | // With 5 pushes left the frame must be unaligned at this point. |
| 538 | mov(r7, Operand(Smi::FromInt(0))); |
| 539 | tst(sp, Operand((frame_alignment - kPointerSize) & frame_alignment_mask)); |
| 540 | push(r7, eq); // Push if aligned to make it unaligned. |
| 541 | } |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 542 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 543 | // Push in reverse order: caller_fp, sp_on_exit, and caller_pc. |
| 544 | stm(db_w, sp, fp.bit() | ip.bit() | lr.bit()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 545 | mov(fp, Operand(sp)); // Setup new frame pointer. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 546 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 547 | mov(ip, Operand(CodeObject())); |
| 548 | push(ip); // Accessed from ExitFrame::code_slot. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 549 | |
| 550 | // Save the frame pointer and the context in top. |
| 551 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 552 | str(fp, MemOperand(ip)); |
| 553 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 554 | str(cp, MemOperand(ip)); |
| 555 | |
| 556 | // Setup argc and the builtin function in callee-saved registers. |
| 557 | mov(r4, Operand(r0)); |
| 558 | mov(r5, Operand(r1)); |
| 559 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 560 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 561 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 562 | // Save the state of all registers to the stack from the memory |
| 563 | // location. This is needed to allow nested break points. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 564 | if (mode == ExitFrame::MODE_DEBUG) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 565 | // Use sp as base to push. |
| 566 | CopyRegistersFromMemoryToStack(sp, kJSCallerSaved); |
| 567 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 568 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 572 | void MacroAssembler::InitializeNewString(Register string, |
| 573 | Register length, |
| 574 | Heap::RootListIndex map_index, |
| 575 | Register scratch1, |
| 576 | Register scratch2) { |
| 577 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 578 | LoadRoot(scratch2, map_index); |
| 579 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 580 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 581 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 582 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 583 | } |
| 584 | |
| 585 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 586 | int MacroAssembler::ActivationFrameAlignment() { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 587 | #if defined(V8_HOST_ARCH_ARM) |
| 588 | // Running on the real platform. Use the alignment as mandated by the local |
| 589 | // environment. |
| 590 | // Note: This will break if we ever start generating snapshots on one ARM |
| 591 | // platform for another ARM platform with a different alignment. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 592 | return OS::ActivationFrameAlignment(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 593 | #else // defined(V8_HOST_ARCH_ARM) |
| 594 | // If we are using the simulator then we should always align to the expected |
| 595 | // alignment. As the simulator is used to generate snapshots we do not know |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 596 | // if the target platform will need alignment, so this is controlled from a |
| 597 | // flag. |
| 598 | return FLAG_sim_stack_alignment; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 599 | #endif // defined(V8_HOST_ARCH_ARM) |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 603 | void MacroAssembler::LeaveExitFrame(ExitFrame::Mode mode) { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 604 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 605 | // Restore the memory copy of the registers by digging them out from |
| 606 | // the stack. This is needed to allow nested break points. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 607 | if (mode == ExitFrame::MODE_DEBUG) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 608 | // This code intentionally clobbers r2 and r3. |
| 609 | const int kCallerSavedSize = kNumJSCallerSaved * kPointerSize; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 610 | const int kOffset = ExitFrameConstants::kCodeOffset - kCallerSavedSize; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 611 | add(r3, fp, Operand(kOffset)); |
| 612 | CopyRegistersFromStackToMemory(r3, r2, kJSCallerSaved); |
| 613 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 614 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 615 | |
| 616 | // Clear top frame. |
| 617 | mov(r3, Operand(0)); |
| 618 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 619 | str(r3, MemOperand(ip)); |
| 620 | |
| 621 | // Restore current context from top and clear it in debug mode. |
| 622 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 623 | ldr(cp, MemOperand(ip)); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 624 | #ifdef DEBUG |
| 625 | str(r3, MemOperand(ip)); |
| 626 | #endif |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 627 | |
| 628 | // Pop the arguments, restore registers, and return. |
| 629 | mov(sp, Operand(fp)); // respect ABI stack constraint |
| 630 | ldm(ia, sp, fp.bit() | sp.bit() | pc.bit()); |
| 631 | } |
| 632 | |
| 633 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 634 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 635 | const ParameterCount& actual, |
| 636 | Handle<Code> code_constant, |
| 637 | Register code_reg, |
| 638 | Label* done, |
| 639 | InvokeFlag flag) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 640 | bool definitely_matches = false; |
| 641 | Label regular_invoke; |
| 642 | |
| 643 | // Check whether the expected and actual arguments count match. If not, |
| 644 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 645 | // r0: actual arguments count |
| 646 | // r1: function (passed through to callee) |
| 647 | // r2: expected arguments count |
| 648 | // r3: callee code entry |
| 649 | |
| 650 | // The code below is made a lot easier because the calling code already sets |
| 651 | // up actual and expected registers according to the contract if values are |
| 652 | // passed in registers. |
| 653 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 654 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 655 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 656 | |
| 657 | if (expected.is_immediate()) { |
| 658 | ASSERT(actual.is_immediate()); |
| 659 | if (expected.immediate() == actual.immediate()) { |
| 660 | definitely_matches = true; |
| 661 | } else { |
| 662 | mov(r0, Operand(actual.immediate())); |
| 663 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 664 | if (expected.immediate() == sentinel) { |
| 665 | // Don't worry about adapting arguments for builtins that |
| 666 | // don't want that done. Skip adaption code by making it look |
| 667 | // like we have a match between expected and actual number of |
| 668 | // arguments. |
| 669 | definitely_matches = true; |
| 670 | } else { |
| 671 | mov(r2, Operand(expected.immediate())); |
| 672 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 673 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 674 | } else { |
| 675 | if (actual.is_immediate()) { |
| 676 | cmp(expected.reg(), Operand(actual.immediate())); |
| 677 | b(eq, ®ular_invoke); |
| 678 | mov(r0, Operand(actual.immediate())); |
| 679 | } else { |
| 680 | cmp(expected.reg(), Operand(actual.reg())); |
| 681 | b(eq, ®ular_invoke); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | if (!definitely_matches) { |
| 686 | if (!code_constant.is_null()) { |
| 687 | mov(r3, Operand(code_constant)); |
| 688 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 689 | } |
| 690 | |
| 691 | Handle<Code> adaptor = |
| 692 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 693 | if (flag == CALL_FUNCTION) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 694 | Call(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 695 | b(done); |
| 696 | } else { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 697 | Jump(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 698 | } |
| 699 | bind(®ular_invoke); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | |
| 704 | void MacroAssembler::InvokeCode(Register code, |
| 705 | const ParameterCount& expected, |
| 706 | const ParameterCount& actual, |
| 707 | InvokeFlag flag) { |
| 708 | Label done; |
| 709 | |
| 710 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag); |
| 711 | if (flag == CALL_FUNCTION) { |
| 712 | Call(code); |
| 713 | } else { |
| 714 | ASSERT(flag == JUMP_FUNCTION); |
| 715 | Jump(code); |
| 716 | } |
| 717 | |
| 718 | // Continue here if InvokePrologue does handle the invocation due to |
| 719 | // mismatched parameter counts. |
| 720 | bind(&done); |
| 721 | } |
| 722 | |
| 723 | |
| 724 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 725 | const ParameterCount& expected, |
| 726 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 727 | RelocInfo::Mode rmode, |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 728 | InvokeFlag flag) { |
| 729 | Label done; |
| 730 | |
| 731 | InvokePrologue(expected, actual, code, no_reg, &done, flag); |
| 732 | if (flag == CALL_FUNCTION) { |
| 733 | Call(code, rmode); |
| 734 | } else { |
| 735 | Jump(code, rmode); |
| 736 | } |
| 737 | |
| 738 | // Continue here if InvokePrologue does handle the invocation due to |
| 739 | // mismatched parameter counts. |
| 740 | bind(&done); |
| 741 | } |
| 742 | |
| 743 | |
| 744 | void MacroAssembler::InvokeFunction(Register fun, |
| 745 | const ParameterCount& actual, |
| 746 | InvokeFlag flag) { |
| 747 | // Contract with called JS functions requires that function is passed in r1. |
| 748 | ASSERT(fun.is(r1)); |
| 749 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 750 | Register expected_reg = r2; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 751 | Register code_reg = r3; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 752 | |
| 753 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 754 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 755 | ldr(expected_reg, |
| 756 | FieldMemOperand(code_reg, |
| 757 | SharedFunctionInfo::kFormalParameterCountOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 758 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 759 | ldr(code_reg, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame^] | 760 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 761 | |
| 762 | ParameterCount expected(expected_reg); |
| 763 | InvokeCode(code_reg, expected, actual, flag); |
| 764 | } |
| 765 | |
| 766 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 767 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 768 | const ParameterCount& actual, |
| 769 | InvokeFlag flag) { |
| 770 | ASSERT(function->is_compiled()); |
| 771 | |
| 772 | // Get the function and setup the context. |
| 773 | mov(r1, Operand(Handle<JSFunction>(function))); |
| 774 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 775 | |
| 776 | // Invoke the cached code. |
| 777 | Handle<Code> code(function->code()); |
| 778 | ParameterCount expected(function->shared()->formal_parameter_count()); |
| 779 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag); |
| 780 | } |
| 781 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 782 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 783 | void MacroAssembler::SaveRegistersToMemory(RegList regs) { |
| 784 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 785 | // Copy the content of registers to memory location. |
| 786 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 787 | int r = JSCallerSavedCode(i); |
| 788 | if ((regs & (1 << r)) != 0) { |
| 789 | Register reg = { r }; |
| 790 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 791 | str(reg, MemOperand(ip)); |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | |
| 797 | void MacroAssembler::RestoreRegistersFromMemory(RegList regs) { |
| 798 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 799 | // Copy the content of memory location to registers. |
| 800 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 801 | int r = JSCallerSavedCode(i); |
| 802 | if ((regs & (1 << r)) != 0) { |
| 803 | Register reg = { r }; |
| 804 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 805 | ldr(reg, MemOperand(ip)); |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | |
| 811 | void MacroAssembler::CopyRegistersFromMemoryToStack(Register base, |
| 812 | RegList regs) { |
| 813 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 814 | // Copy the content of the memory location to the stack and adjust base. |
| 815 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 816 | int r = JSCallerSavedCode(i); |
| 817 | if ((regs & (1 << r)) != 0) { |
| 818 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 819 | ldr(ip, MemOperand(ip)); |
| 820 | str(ip, MemOperand(base, 4, NegPreIndex)); |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | void MacroAssembler::CopyRegistersFromStackToMemory(Register base, |
| 827 | Register scratch, |
| 828 | RegList regs) { |
| 829 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 830 | // Copy the content of the stack to the memory location and adjust base. |
| 831 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 832 | int r = JSCallerSavedCode(i); |
| 833 | if ((regs & (1 << r)) != 0) { |
| 834 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 835 | ldr(scratch, MemOperand(base, 4, PostIndex)); |
| 836 | str(scratch, MemOperand(ip)); |
| 837 | } |
| 838 | } |
| 839 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 840 | |
| 841 | |
| 842 | void MacroAssembler::DebugBreak() { |
| 843 | ASSERT(allow_stub_calls()); |
| 844 | mov(r0, Operand(0)); |
| 845 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak))); |
| 846 | CEntryStub ces(1); |
| 847 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 848 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 849 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 850 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 851 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 852 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 853 | HandlerType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 854 | // Adjust this code if not the case. |
| 855 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | // The pc (return address) is passed in register lr. |
| 857 | if (try_location == IN_JAVASCRIPT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | if (type == TRY_CATCH_HANDLER) { |
| 859 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 860 | } else { |
| 861 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 862 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 863 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 864 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 865 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 866 | stm(db_w, sp, r3.bit() | fp.bit() | lr.bit()); |
| 867 | // Save the current handler as the next handler. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 868 | mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 869 | ldr(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 870 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 871 | push(r1); |
| 872 | // Link this handler as the new current one. |
| 873 | str(sp, MemOperand(r3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 875 | // Must preserve r0-r4, r5-r7 are available. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 876 | ASSERT(try_location == IN_JS_ENTRY); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 877 | // The frame pointer does not point to a JS frame so we save NULL |
| 878 | // for fp. We expect the code throwing an exception to check fp |
| 879 | // before dereferencing it to restore the context. |
| 880 | mov(ip, Operand(0)); // To save a NULL frame pointer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 881 | mov(r6, Operand(StackHandler::ENTRY)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 882 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 883 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 884 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 885 | stm(db_w, sp, r6.bit() | ip.bit() | lr.bit()); |
| 886 | // Save the current handler as the next handler. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | mov(r7, Operand(ExternalReference(Top::k_handler_address))); |
| 888 | ldr(r6, MemOperand(r7)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 889 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 890 | push(r6); |
| 891 | // Link this handler as the new current one. |
| 892 | str(sp, MemOperand(r7)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
| 896 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 897 | void MacroAssembler::PopTryHandler() { |
| 898 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 899 | pop(r1); |
| 900 | mov(ip, Operand(ExternalReference(Top::k_handler_address))); |
| 901 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 902 | str(r1, MemOperand(ip)); |
| 903 | } |
| 904 | |
| 905 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 906 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 907 | Register scratch, |
| 908 | Label* miss) { |
| 909 | Label same_contexts; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 910 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 911 | ASSERT(!holder_reg.is(scratch)); |
| 912 | ASSERT(!holder_reg.is(ip)); |
| 913 | ASSERT(!scratch.is(ip)); |
| 914 | |
| 915 | // Load current lexical context from the stack frame. |
| 916 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 917 | // In debug mode, make sure the lexical context is set. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 918 | #ifdef DEBUG |
| 919 | cmp(scratch, Operand(0)); |
| 920 | Check(ne, "we should not have an empty lexical context"); |
| 921 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 922 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 923 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 925 | ldr(scratch, FieldMemOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 926 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 927 | |
| 928 | // Check the context is a global context. |
| 929 | if (FLAG_debug_code) { |
| 930 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 931 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 932 | // that ip is clobbered as part of cmp with an object Operand. |
| 933 | push(holder_reg); // Temporarily save holder on the stack. |
| 934 | // Read the first word and compare to the global_context_map. |
| 935 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 936 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 937 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 938 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 939 | pop(holder_reg); // Restore holder. |
| 940 | } |
| 941 | |
| 942 | // Check if both contexts are the same. |
| 943 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 944 | cmp(scratch, Operand(ip)); |
| 945 | b(eq, &same_contexts); |
| 946 | |
| 947 | // Check the context is a global context. |
| 948 | if (FLAG_debug_code) { |
| 949 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 950 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 951 | // that ip is clobbered as part of cmp with an object Operand. |
| 952 | push(holder_reg); // Temporarily save holder on the stack. |
| 953 | mov(holder_reg, ip); // Move ip to its holding place. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 954 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 955 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 956 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 957 | |
| 958 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 959 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 960 | cmp(holder_reg, ip); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 961 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 962 | // Restore ip is not needed. ip is reloaded below. |
| 963 | pop(holder_reg); // Restore holder. |
| 964 | // Restore ip to holder's context. |
| 965 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 966 | } |
| 967 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 968 | // Check that the security token in the calling global object is |
| 969 | // compatible with the security token in the receiving global |
| 970 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 971 | int token_offset = Context::kHeaderSize + |
| 972 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 973 | |
| 974 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 975 | ldr(ip, FieldMemOperand(ip, token_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 976 | cmp(scratch, Operand(ip)); |
| 977 | b(ne, miss); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 978 | |
| 979 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 983 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 984 | Register result, |
| 985 | Register scratch1, |
| 986 | Register scratch2, |
| 987 | Label* gc_required, |
| 988 | AllocationFlags flags) { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 989 | ASSERT(!result.is(scratch1)); |
| 990 | ASSERT(!scratch1.is(scratch2)); |
| 991 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 992 | // Make object size into bytes. |
| 993 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 994 | object_size *= kPointerSize; |
| 995 | } |
| 996 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 997 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 998 | // Load address of new object into result and allocation top address into |
| 999 | // scratch1. |
| 1000 | ExternalReference new_space_allocation_top = |
| 1001 | ExternalReference::new_space_allocation_top_address(); |
| 1002 | mov(scratch1, Operand(new_space_allocation_top)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1003 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 1004 | ldr(result, MemOperand(scratch1)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1005 | } else if (FLAG_debug_code) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1006 | // Assert that result actually contains top on entry. scratch2 is used |
| 1007 | // immediately below so this use of scratch2 does not cause difference with |
| 1008 | // respect to register content between debug and release mode. |
| 1009 | ldr(scratch2, MemOperand(scratch1)); |
| 1010 | cmp(result, scratch2); |
| 1011 | Check(eq, "Unexpected allocation top"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1012 | } |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1013 | |
| 1014 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1015 | // to calculate the new top. |
| 1016 | ExternalReference new_space_allocation_limit = |
| 1017 | ExternalReference::new_space_allocation_limit_address(); |
| 1018 | mov(scratch2, Operand(new_space_allocation_limit)); |
| 1019 | ldr(scratch2, MemOperand(scratch2)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1020 | add(result, result, Operand(object_size)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1021 | cmp(result, Operand(scratch2)); |
| 1022 | b(hi, gc_required); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1023 | str(result, MemOperand(scratch1)); |
| 1024 | |
| 1025 | // Tag and adjust back to start of new object. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1026 | if ((flags & TAG_OBJECT) != 0) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1027 | sub(result, result, Operand(object_size - kHeapObjectTag)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1028 | } else { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1029 | sub(result, result, Operand(object_size)); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1034 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 1035 | Register result, |
| 1036 | Register scratch1, |
| 1037 | Register scratch2, |
| 1038 | Label* gc_required, |
| 1039 | AllocationFlags flags) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1040 | ASSERT(!result.is(scratch1)); |
| 1041 | ASSERT(!scratch1.is(scratch2)); |
| 1042 | |
| 1043 | // Load address of new object into result and allocation top address into |
| 1044 | // scratch1. |
| 1045 | ExternalReference new_space_allocation_top = |
| 1046 | ExternalReference::new_space_allocation_top_address(); |
| 1047 | mov(scratch1, Operand(new_space_allocation_top)); |
| 1048 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
| 1049 | ldr(result, MemOperand(scratch1)); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1050 | } else if (FLAG_debug_code) { |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1051 | // Assert that result actually contains top on entry. scratch2 is used |
| 1052 | // immediately below so this use of scratch2 does not cause difference with |
| 1053 | // respect to register content between debug and release mode. |
| 1054 | ldr(scratch2, MemOperand(scratch1)); |
| 1055 | cmp(result, scratch2); |
| 1056 | Check(eq, "Unexpected allocation top"); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1060 | // to calculate the new top. Object size is in words so a shift is required to |
| 1061 | // get the number of bytes |
| 1062 | ExternalReference new_space_allocation_limit = |
| 1063 | ExternalReference::new_space_allocation_limit_address(); |
| 1064 | mov(scratch2, Operand(new_space_allocation_limit)); |
| 1065 | ldr(scratch2, MemOperand(scratch2)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1066 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1067 | add(result, result, Operand(object_size, LSL, kPointerSizeLog2)); |
| 1068 | } else { |
| 1069 | add(result, result, Operand(object_size)); |
| 1070 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1071 | cmp(result, Operand(scratch2)); |
| 1072 | b(hi, gc_required); |
| 1073 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1074 | // Update allocation top. result temporarily holds the new top. |
| 1075 | if (FLAG_debug_code) { |
| 1076 | tst(result, Operand(kObjectAlignmentMask)); |
| 1077 | Check(eq, "Unaligned allocation in new space"); |
| 1078 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1079 | str(result, MemOperand(scratch1)); |
| 1080 | |
| 1081 | // Adjust back to start of new object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1082 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1083 | sub(result, result, Operand(object_size, LSL, kPointerSizeLog2)); |
| 1084 | } else { |
| 1085 | sub(result, result, Operand(object_size)); |
| 1086 | } |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1087 | |
| 1088 | // Tag object if requested. |
| 1089 | if ((flags & TAG_OBJECT) != 0) { |
| 1090 | add(result, result, Operand(kHeapObjectTag)); |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | |
| 1095 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1096 | Register scratch) { |
| 1097 | ExternalReference new_space_allocation_top = |
| 1098 | ExternalReference::new_space_allocation_top_address(); |
| 1099 | |
| 1100 | // Make sure the object has no tag before resetting top. |
| 1101 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1102 | #ifdef DEBUG |
| 1103 | // Check that the object un-allocated is below the current top. |
| 1104 | mov(scratch, Operand(new_space_allocation_top)); |
| 1105 | ldr(scratch, MemOperand(scratch)); |
| 1106 | cmp(object, scratch); |
| 1107 | Check(lt, "Undo allocation of non allocated memory"); |
| 1108 | #endif |
| 1109 | // Write the address of the object to un-allocate as the current top. |
| 1110 | mov(scratch, Operand(new_space_allocation_top)); |
| 1111 | str(object, MemOperand(scratch)); |
| 1112 | } |
| 1113 | |
| 1114 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1115 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1116 | Register length, |
| 1117 | Register scratch1, |
| 1118 | Register scratch2, |
| 1119 | Register scratch3, |
| 1120 | Label* gc_required) { |
| 1121 | // Calculate the number of bytes needed for the characters in the string while |
| 1122 | // observing object alignment. |
| 1123 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1124 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1125 | add(scratch1, scratch1, |
| 1126 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1127 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1128 | |
| 1129 | // Allocate two-byte string in new space. |
| 1130 | AllocateInNewSpace(scratch1, |
| 1131 | result, |
| 1132 | scratch2, |
| 1133 | scratch3, |
| 1134 | gc_required, |
| 1135 | TAG_OBJECT); |
| 1136 | |
| 1137 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1138 | InitializeNewString(result, |
| 1139 | length, |
| 1140 | Heap::kStringMapRootIndex, |
| 1141 | scratch1, |
| 1142 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1147 | Register length, |
| 1148 | Register scratch1, |
| 1149 | Register scratch2, |
| 1150 | Register scratch3, |
| 1151 | Label* gc_required) { |
| 1152 | // Calculate the number of bytes needed for the characters in the string while |
| 1153 | // observing object alignment. |
| 1154 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1155 | ASSERT(kCharSize == 1); |
| 1156 | add(scratch1, length, |
| 1157 | Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1158 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1159 | |
| 1160 | // Allocate ASCII string in new space. |
| 1161 | AllocateInNewSpace(scratch1, |
| 1162 | result, |
| 1163 | scratch2, |
| 1164 | scratch3, |
| 1165 | gc_required, |
| 1166 | TAG_OBJECT); |
| 1167 | |
| 1168 | // Set the map, length and hash field. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1169 | InitializeNewString(result, |
| 1170 | length, |
| 1171 | Heap::kAsciiStringMapRootIndex, |
| 1172 | scratch1, |
| 1173 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1178 | Register length, |
| 1179 | Register scratch1, |
| 1180 | Register scratch2, |
| 1181 | Label* gc_required) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1182 | AllocateInNewSpace(ConsString::kSize, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1183 | result, |
| 1184 | scratch1, |
| 1185 | scratch2, |
| 1186 | gc_required, |
| 1187 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1188 | |
| 1189 | InitializeNewString(result, |
| 1190 | length, |
| 1191 | Heap::kConsStringMapRootIndex, |
| 1192 | scratch1, |
| 1193 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1198 | Register length, |
| 1199 | Register scratch1, |
| 1200 | Register scratch2, |
| 1201 | Label* gc_required) { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1202 | AllocateInNewSpace(ConsString::kSize, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1203 | result, |
| 1204 | scratch1, |
| 1205 | scratch2, |
| 1206 | gc_required, |
| 1207 | TAG_OBJECT); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1208 | |
| 1209 | InitializeNewString(result, |
| 1210 | length, |
| 1211 | Heap::kConsAsciiStringMapRootIndex, |
| 1212 | scratch1, |
| 1213 | scratch2); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1217 | void MacroAssembler::CompareObjectType(Register object, |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1218 | Register map, |
| 1219 | Register type_reg, |
| 1220 | InstanceType type) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1221 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1222 | CompareInstanceType(map, type_reg, type); |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | void MacroAssembler::CompareInstanceType(Register map, |
| 1227 | Register type_reg, |
| 1228 | InstanceType type) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1229 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1230 | cmp(type_reg, Operand(type)); |
| 1231 | } |
| 1232 | |
| 1233 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1234 | void MacroAssembler::CheckMap(Register obj, |
| 1235 | Register scratch, |
| 1236 | Handle<Map> map, |
| 1237 | Label* fail, |
| 1238 | bool is_heap_object) { |
| 1239 | if (!is_heap_object) { |
| 1240 | BranchOnSmi(obj, fail); |
| 1241 | } |
| 1242 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1243 | mov(ip, Operand(map)); |
| 1244 | cmp(scratch, ip); |
| 1245 | b(ne, fail); |
| 1246 | } |
| 1247 | |
| 1248 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1249 | void MacroAssembler::CheckMap(Register obj, |
| 1250 | Register scratch, |
| 1251 | Heap::RootListIndex index, |
| 1252 | Label* fail, |
| 1253 | bool is_heap_object) { |
| 1254 | if (!is_heap_object) { |
| 1255 | BranchOnSmi(obj, fail); |
| 1256 | } |
| 1257 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1258 | LoadRoot(ip, index); |
| 1259 | cmp(scratch, ip); |
| 1260 | b(ne, fail); |
| 1261 | } |
| 1262 | |
| 1263 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1264 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1265 | Register result, |
| 1266 | Register scratch, |
| 1267 | Label* miss) { |
| 1268 | // Check that the receiver isn't a smi. |
| 1269 | BranchOnSmi(function, miss); |
| 1270 | |
| 1271 | // Check that the function really is a function. Load map into result reg. |
| 1272 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 1273 | b(ne, miss); |
| 1274 | |
| 1275 | // Make sure that the function has an instance prototype. |
| 1276 | Label non_instance; |
| 1277 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 1278 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1279 | b(ne, &non_instance); |
| 1280 | |
| 1281 | // Get the prototype or initial map from the function. |
| 1282 | ldr(result, |
| 1283 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1284 | |
| 1285 | // If the prototype or initial map is the hole, don't return it and |
| 1286 | // simply miss the cache instead. This will allow us to allocate a |
| 1287 | // prototype object on-demand in the runtime system. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1288 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1289 | cmp(result, ip); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1290 | b(eq, miss); |
| 1291 | |
| 1292 | // If the function does not have an initial map, we're done. |
| 1293 | Label done; |
| 1294 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 1295 | b(ne, &done); |
| 1296 | |
| 1297 | // Get the prototype from the initial map. |
| 1298 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 1299 | jmp(&done); |
| 1300 | |
| 1301 | // Non-instance prototype: Fetch prototype from constructor field |
| 1302 | // in initial map. |
| 1303 | bind(&non_instance); |
| 1304 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 1305 | |
| 1306 | // All done. |
| 1307 | bind(&done); |
| 1308 | } |
| 1309 | |
| 1310 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1311 | void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1312 | ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1313 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1317 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
| 1318 | ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
| 1319 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1320 | } |
| 1321 | |
| 1322 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 1323 | void MacroAssembler::StubReturn(int argc, Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1324 | ASSERT(argc >= 1 && generating_stub()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1325 | if (argc > 1) { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 1326 | add(sp, sp, Operand((argc - 1) * kPointerSize), LeaveCC, cond); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1327 | } |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 1328 | Ret(cond); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1331 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1332 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1333 | if (num_arguments > 0) { |
| 1334 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1335 | } |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1336 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1340 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 1341 | Register outHighReg, |
| 1342 | Register outLowReg) { |
| 1343 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 1344 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1345 | vmov(s15, r7); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1346 | vcvt_f64_s32(d7, s15); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1347 | vmov(outLowReg, outHighReg, d7); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1351 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 1352 | DwVfpRegister result, |
| 1353 | Register scratch1, |
| 1354 | Register scratch2, |
| 1355 | Register heap_number_map, |
| 1356 | SwVfpRegister scratch3, |
| 1357 | Label* not_number, |
| 1358 | ObjectToDoubleFlags flags) { |
| 1359 | Label done; |
| 1360 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 1361 | Label not_smi; |
| 1362 | BranchOnNotSmi(object, ¬_smi); |
| 1363 | // Remove smi tag and convert to double. |
| 1364 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 1365 | vmov(scratch3, scratch1); |
| 1366 | vcvt_f64_s32(result, scratch3); |
| 1367 | b(&done); |
| 1368 | bind(¬_smi); |
| 1369 | } |
| 1370 | // Check for heap number and load double value from it. |
| 1371 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1372 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1373 | cmp(scratch1, heap_number_map); |
| 1374 | b(ne, not_number); |
| 1375 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 1376 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 1377 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 1378 | Sbfx(scratch1, |
| 1379 | scratch1, |
| 1380 | HeapNumber::kExponentShift, |
| 1381 | HeapNumber::kExponentBits); |
| 1382 | // All-one value sign extend to -1. |
| 1383 | cmp(scratch1, Operand(-1)); |
| 1384 | b(eq, not_number); |
| 1385 | } |
| 1386 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 1387 | bind(&done); |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 1392 | DwVfpRegister value, |
| 1393 | Register scratch1, |
| 1394 | SwVfpRegister scratch2) { |
| 1395 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 1396 | vmov(scratch2, scratch1); |
| 1397 | vcvt_f64_s32(value, scratch2); |
| 1398 | } |
| 1399 | |
| 1400 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1401 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 1402 | Register src, |
| 1403 | int num_least_bits) { |
| 1404 | if (CpuFeatures::IsSupported(ARMv7)) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1405 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1406 | } else { |
| 1407 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 1408 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1413 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1414 | // All parameters are on the stack. r0 has the return value after call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1415 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1416 | // If the expected number of arguments of the runtime function is |
| 1417 | // constant, we check that the actual number of arguments match the |
| 1418 | // expectation. |
| 1419 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1420 | IllegalOperation(num_arguments); |
| 1421 | return; |
| 1422 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1423 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1424 | // TODO(1236192): Most runtime routines don't need the number of |
| 1425 | // arguments passed in because it is constant. At some point we |
| 1426 | // should remove this need and make the runtime routine entry code |
| 1427 | // smarter. |
| 1428 | mov(r0, Operand(num_arguments)); |
| 1429 | mov(r1, Operand(ExternalReference(f))); |
| 1430 | CEntryStub stub(1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1431 | CallStub(&stub); |
| 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 1436 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 1437 | } |
| 1438 | |
| 1439 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1440 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 1441 | int num_arguments) { |
| 1442 | mov(r0, Operand(num_arguments)); |
| 1443 | mov(r1, Operand(ext)); |
| 1444 | |
| 1445 | CEntryStub stub(1); |
| 1446 | CallStub(&stub); |
| 1447 | } |
| 1448 | |
| 1449 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1450 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 1451 | int num_arguments, |
| 1452 | int result_size) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1453 | // TODO(1236192): Most runtime routines don't need the number of |
| 1454 | // arguments passed in because it is constant. At some point we |
| 1455 | // should remove this need and make the runtime routine entry code |
| 1456 | // smarter. |
| 1457 | mov(r0, Operand(num_arguments)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1458 | JumpToExternalReference(ext); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1462 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1463 | int num_arguments, |
| 1464 | int result_size) { |
| 1465 | TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 1466 | } |
| 1467 | |
| 1468 | |
| 1469 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1470 | #if defined(__thumb__) |
| 1471 | // Thumb mode builtin. |
| 1472 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1473 | #endif |
| 1474 | mov(r1, Operand(builtin)); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 1475 | CEntryStub stub(1); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1476 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1480 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 1481 | InvokeJSFlags flags) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1482 | GetBuiltinEntry(r2, id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1483 | if (flags == CALL_JS) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1484 | Call(r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1485 | } else { |
| 1486 | ASSERT(flags == JUMP_JS); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1487 | Jump(r2); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame^] | 1492 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 1493 | Builtins::JavaScript id) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1494 | // Load the builtins object into target register. |
| 1495 | ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1496 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1497 | // Load the JavaScript builtin function from the builtins object. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1498 | ldr(target, FieldMemOperand(target, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame^] | 1499 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 1504 | ASSERT(!target.is(r1)); |
| 1505 | GetBuiltinFunction(r1, id); |
| 1506 | // Load the code entry point from the builtins object. |
| 1507 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1511 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 1512 | Register scratch1, Register scratch2) { |
| 1513 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1514 | mov(scratch1, Operand(value)); |
| 1515 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1516 | str(scratch1, MemOperand(scratch2)); |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | |
| 1521 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 1522 | Register scratch1, Register scratch2) { |
| 1523 | ASSERT(value > 0); |
| 1524 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1525 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1526 | ldr(scratch1, MemOperand(scratch2)); |
| 1527 | add(scratch1, scratch1, Operand(value)); |
| 1528 | str(scratch1, MemOperand(scratch2)); |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | |
| 1533 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 1534 | Register scratch1, Register scratch2) { |
| 1535 | ASSERT(value > 0); |
| 1536 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1537 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1538 | ldr(scratch1, MemOperand(scratch2)); |
| 1539 | sub(scratch1, scratch1, Operand(value)); |
| 1540 | str(scratch1, MemOperand(scratch2)); |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1545 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
| 1546 | if (FLAG_debug_code) |
| 1547 | Check(cc, msg); |
| 1548 | } |
| 1549 | |
| 1550 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1551 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 1552 | Heap::RootListIndex index) { |
| 1553 | if (FLAG_debug_code) { |
| 1554 | LoadRoot(ip, index); |
| 1555 | cmp(reg, ip); |
| 1556 | Check(eq, "Register did not match expected root"); |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1561 | void MacroAssembler::AssertFastElements(Register elements) { |
| 1562 | if (FLAG_debug_code) { |
| 1563 | ASSERT(!elements.is(ip)); |
| 1564 | Label ok; |
| 1565 | push(elements); |
| 1566 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 1567 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 1568 | cmp(elements, ip); |
| 1569 | b(eq, &ok); |
| 1570 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 1571 | cmp(elements, ip); |
| 1572 | b(eq, &ok); |
| 1573 | Abort("JSObject with fast elements map has slow elements"); |
| 1574 | bind(&ok); |
| 1575 | pop(elements); |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1580 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 1581 | Label L; |
| 1582 | b(cc, &L); |
| 1583 | Abort(msg); |
| 1584 | // will not return here |
| 1585 | bind(&L); |
| 1586 | } |
| 1587 | |
| 1588 | |
| 1589 | void MacroAssembler::Abort(const char* msg) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1590 | Label abort_start; |
| 1591 | bind(&abort_start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1592 | // We want to pass the msg string like a smi to avoid GC |
| 1593 | // problems, however msg is not guaranteed to be aligned |
| 1594 | // properly. Instead, we pass an aligned pointer that is |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1595 | // a proper v8 smi, but also pass the alignment difference |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1596 | // from the real pointer as a smi. |
| 1597 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 1598 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 1599 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 1600 | #ifdef DEBUG |
| 1601 | if (msg != NULL) { |
| 1602 | RecordComment("Abort message: "); |
| 1603 | RecordComment(msg); |
| 1604 | } |
| 1605 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1606 | // Disable stub call restrictions to always allow calls to abort. |
| 1607 | set_allow_stub_calls(true); |
| 1608 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1609 | mov(r0, Operand(p0)); |
| 1610 | push(r0); |
| 1611 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1612 | push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1613 | CallRuntime(Runtime::kAbort, 2); |
| 1614 | // will not return here |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1615 | if (is_const_pool_blocked()) { |
| 1616 | // If the calling code cares about the exact number of |
| 1617 | // instructions generated, we insert padding here to keep the size |
| 1618 | // of the Abort macro constant. |
| 1619 | static const int kExpectedAbortInstructions = 10; |
| 1620 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 1621 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 1622 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 1623 | nop(); |
| 1624 | } |
| 1625 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1628 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1629 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 1630 | if (context_chain_length > 0) { |
| 1631 | // Move up the chain of contexts to the context containing the slot. |
| 1632 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1633 | // Load the function context (which is the incoming, outer context). |
| 1634 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 1635 | for (int i = 1; i < context_chain_length; i++) { |
| 1636 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 1637 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 1638 | } |
| 1639 | // The context may be an intermediate context, not a function context. |
| 1640 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1641 | } else { // Slot is in the current function context. |
| 1642 | // The context may be an intermediate context, not a function context. |
| 1643 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1648 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 1649 | Register reg2, |
| 1650 | Label* on_not_both_smi) { |
| 1651 | ASSERT_EQ(0, kSmiTag); |
| 1652 | tst(reg1, Operand(kSmiTagMask)); |
| 1653 | tst(reg2, Operand(kSmiTagMask), eq); |
| 1654 | b(ne, on_not_both_smi); |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 1659 | Register reg2, |
| 1660 | Label* on_either_smi) { |
| 1661 | ASSERT_EQ(0, kSmiTag); |
| 1662 | tst(reg1, Operand(kSmiTagMask)); |
| 1663 | tst(reg2, Operand(kSmiTagMask), ne); |
| 1664 | b(eq, on_either_smi); |
| 1665 | } |
| 1666 | |
| 1667 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1668 | void MacroAssembler::AbortIfSmi(Register object) { |
| 1669 | ASSERT_EQ(0, kSmiTag); |
| 1670 | tst(object, Operand(kSmiTagMask)); |
| 1671 | Assert(ne, "Operand is a smi"); |
| 1672 | } |
| 1673 | |
| 1674 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1675 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 1676 | Register first, |
| 1677 | Register second, |
| 1678 | Register scratch1, |
| 1679 | Register scratch2, |
| 1680 | Label* failure) { |
| 1681 | // Test that both first and second are sequential ASCII strings. |
| 1682 | // Assume that they are non-smis. |
| 1683 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 1684 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 1685 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 1686 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1687 | |
| 1688 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 1689 | scratch2, |
| 1690 | scratch1, |
| 1691 | scratch2, |
| 1692 | failure); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 1696 | Register second, |
| 1697 | Register scratch1, |
| 1698 | Register scratch2, |
| 1699 | Label* failure) { |
| 1700 | // Check that neither is a smi. |
| 1701 | ASSERT_EQ(0, kSmiTag); |
| 1702 | and_(scratch1, first, Operand(second)); |
| 1703 | tst(scratch1, Operand(kSmiTagMask)); |
| 1704 | b(eq, failure); |
| 1705 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 1706 | second, |
| 1707 | scratch1, |
| 1708 | scratch2, |
| 1709 | failure); |
| 1710 | } |
| 1711 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 1712 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1713 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 1714 | // is full and a scavenge is needed. |
| 1715 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 1716 | Register scratch1, |
| 1717 | Register scratch2, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1718 | Register heap_number_map, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1719 | Label* gc_required) { |
| 1720 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 1721 | // object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1722 | AllocateInNewSpace(HeapNumber::kSize, |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1723 | result, |
| 1724 | scratch1, |
| 1725 | scratch2, |
| 1726 | gc_required, |
| 1727 | TAG_OBJECT); |
| 1728 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1729 | // Store heap number map in the allocated object. |
| 1730 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 1731 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1735 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 1736 | DwVfpRegister value, |
| 1737 | Register scratch1, |
| 1738 | Register scratch2, |
| 1739 | Register heap_number_map, |
| 1740 | Label* gc_required) { |
| 1741 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 1742 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 1743 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 1744 | } |
| 1745 | |
| 1746 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1747 | // Copies a fixed number of fields of heap objects from src to dst. |
| 1748 | void MacroAssembler::CopyFields(Register dst, |
| 1749 | Register src, |
| 1750 | RegList temps, |
| 1751 | int field_count) { |
| 1752 | // At least one bit set in the first 15 registers. |
| 1753 | ASSERT((temps & ((1 << 15) - 1)) != 0); |
| 1754 | ASSERT((temps & dst.bit()) == 0); |
| 1755 | ASSERT((temps & src.bit()) == 0); |
| 1756 | // Primitive implementation using only one temporary register. |
| 1757 | |
| 1758 | Register tmp = no_reg; |
| 1759 | // Find a temp register in temps list. |
| 1760 | for (int i = 0; i < 15; i++) { |
| 1761 | if ((temps & (1 << i)) != 0) { |
| 1762 | tmp.set_code(i); |
| 1763 | break; |
| 1764 | } |
| 1765 | } |
| 1766 | ASSERT(!tmp.is(no_reg)); |
| 1767 | |
| 1768 | for (int i = 0; i < field_count; i++) { |
| 1769 | ldr(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 1770 | str(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1775 | void MacroAssembler::CountLeadingZeros(Register zeros, // Answer. |
| 1776 | Register source, // Input. |
| 1777 | Register scratch) { |
| 1778 | ASSERT(!zeros.is(source) || !source.is(zeros)); |
| 1779 | ASSERT(!zeros.is(scratch)); |
| 1780 | ASSERT(!scratch.is(ip)); |
| 1781 | ASSERT(!source.is(ip)); |
| 1782 | ASSERT(!zeros.is(ip)); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1783 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
| 1784 | clz(zeros, source); // This instruction is only supported after ARM5. |
| 1785 | #else |
| 1786 | mov(zeros, Operand(0)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 1787 | Move(scratch, source); |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 1788 | // Top 16. |
| 1789 | tst(scratch, Operand(0xffff0000)); |
| 1790 | add(zeros, zeros, Operand(16), LeaveCC, eq); |
| 1791 | mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq); |
| 1792 | // Top 8. |
| 1793 | tst(scratch, Operand(0xff000000)); |
| 1794 | add(zeros, zeros, Operand(8), LeaveCC, eq); |
| 1795 | mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq); |
| 1796 | // Top 4. |
| 1797 | tst(scratch, Operand(0xf0000000)); |
| 1798 | add(zeros, zeros, Operand(4), LeaveCC, eq); |
| 1799 | mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq); |
| 1800 | // Top 2. |
| 1801 | tst(scratch, Operand(0xc0000000)); |
| 1802 | add(zeros, zeros, Operand(2), LeaveCC, eq); |
| 1803 | mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq); |
| 1804 | // Top bit. |
| 1805 | tst(scratch, Operand(0x80000000u)); |
| 1806 | add(zeros, zeros, Operand(1), LeaveCC, eq); |
| 1807 | #endif |
| 1808 | } |
| 1809 | |
| 1810 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1811 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 1812 | Register first, |
| 1813 | Register second, |
| 1814 | Register scratch1, |
| 1815 | Register scratch2, |
| 1816 | Label* failure) { |
| 1817 | int kFlatAsciiStringMask = |
| 1818 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 1819 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1820 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 1821 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 1822 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 1823 | // Ignore second test if first test failed. |
| 1824 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 1825 | b(ne, failure); |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 1830 | Register scratch, |
| 1831 | Label* failure) { |
| 1832 | int kFlatAsciiStringMask = |
| 1833 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 1834 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 1835 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 1836 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 1837 | b(ne, failure); |
| 1838 | } |
| 1839 | |
| 1840 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1841 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1842 | int frame_alignment = ActivationFrameAlignment(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1843 | // Up to four simple arguments are passed in registers r0..r3. |
| 1844 | int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1845 | if (frame_alignment > kPointerSize) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1846 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 1847 | // and the original value of sp. |
| 1848 | mov(scratch, sp); |
| 1849 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1850 | ASSERT(IsPowerOf2(frame_alignment)); |
| 1851 | and_(sp, sp, Operand(-frame_alignment)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1852 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 1853 | } else { |
| 1854 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | |
| 1859 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 1860 | int num_arguments) { |
| 1861 | mov(ip, Operand(function)); |
| 1862 | CallCFunction(ip, num_arguments); |
| 1863 | } |
| 1864 | |
| 1865 | |
| 1866 | void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 1867 | // Make sure that the stack is aligned before calling a C function unless |
| 1868 | // running in the simulator. The simulator has its own alignment check which |
| 1869 | // provides more information. |
| 1870 | #if defined(V8_HOST_ARCH_ARM) |
| 1871 | if (FLAG_debug_code) { |
| 1872 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 1873 | int frame_alignment_mask = frame_alignment - 1; |
| 1874 | if (frame_alignment > kPointerSize) { |
| 1875 | ASSERT(IsPowerOf2(frame_alignment)); |
| 1876 | Label alignment_as_expected; |
| 1877 | tst(sp, Operand(frame_alignment_mask)); |
| 1878 | b(eq, &alignment_as_expected); |
| 1879 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 1880 | // re-entering here. |
| 1881 | stop("Unexpected alignment"); |
| 1882 | bind(&alignment_as_expected); |
| 1883 | } |
| 1884 | } |
| 1885 | #endif |
| 1886 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1887 | // Just call directly. The function called cannot cause a GC, or |
| 1888 | // allow preemption, so the return address in the link register |
| 1889 | // stays correct. |
| 1890 | Call(function); |
| 1891 | int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4; |
| 1892 | if (OS::ActivationFrameAlignment() > kPointerSize) { |
| 1893 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 1894 | } else { |
| 1895 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1900 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1901 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 1902 | : address_(address), |
| 1903 | instructions_(instructions), |
| 1904 | size_(instructions * Assembler::kInstrSize), |
| 1905 | masm_(address, size_ + Assembler::kGap) { |
| 1906 | // Create a new macro assembler pointing to the address of the code to patch. |
| 1907 | // The size is adjusted with kGap on order for the assembler to generate size |
| 1908 | // bytes of instructions without failing with buffer size constraints. |
| 1909 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1910 | } |
| 1911 | |
| 1912 | |
| 1913 | CodePatcher::~CodePatcher() { |
| 1914 | // Indicate that code has changed. |
| 1915 | CPU::FlushICache(address_, size_); |
| 1916 | |
| 1917 | // Check that the code was patched as expected. |
| 1918 | ASSERT(masm_.pc_ == address_ + size_); |
| 1919 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 1920 | } |
| 1921 | |
| 1922 | |
| 1923 | void CodePatcher::Emit(Instr x) { |
| 1924 | masm()->emit(x); |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | void CodePatcher::Emit(Address addr) { |
| 1929 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 1930 | } |
| 1931 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1932 | |
| 1933 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1934 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1935 | |
| 1936 | #endif // V8_TARGET_ARCH_ARM |