Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 28 | #include <limits.h> // For LONG_MIN, LONG_MAX. |
| 29 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 30 | #include "v8.h" |
| 31 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 32 | #if defined(V8_TARGET_ARCH_ARM) |
| 33 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | #include "bootstrapper.h" |
| 35 | #include "codegen-inl.h" |
| 36 | #include "debug.h" |
| 37 | #include "runtime.h" |
| 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
| 42 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 43 | : Assembler(buffer, size), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 44 | generating_stub_(false), |
| 45 | allow_stub_calls_(true), |
| 46 | code_object_(Heap::undefined_value()) { |
| 47 | } |
| 48 | |
| 49 | |
| 50 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 51 | // thumb, so we require inter-working support |
| 52 | #if defined(__thumb__) && !defined(USE_THUMB_INTERWORK) |
| 53 | #error "flag -mthumb-interwork missing" |
| 54 | #endif |
| 55 | |
| 56 | |
| 57 | // We do not support thumb inter-working with an arm architecture not supporting |
| 58 | // the blx instruction (below v5t). If you know what CPU you are compiling for |
| 59 | // you can use -march=armv7 or similar. |
| 60 | #if defined(USE_THUMB_INTERWORK) && !defined(CAN_USE_THUMB_INSTRUCTIONS) |
| 61 | # error "For thumb inter-working we require an architecture which supports blx" |
| 62 | #endif |
| 63 | |
| 64 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 65 | // Using bx does not yield better code, so use it only when required |
| 66 | #if defined(USE_THUMB_INTERWORK) |
| 67 | #define USE_BX 1 |
| 68 | #endif |
| 69 | |
| 70 | |
| 71 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 72 | #if USE_BX |
| 73 | bx(target, cond); |
| 74 | #else |
| 75 | mov(pc, Operand(target), LeaveCC, cond); |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 81 | Condition cond) { |
| 82 | #if USE_BX |
| 83 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 84 | bx(ip, cond); |
| 85 | #else |
| 86 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 87 | #endif |
| 88 | } |
| 89 | |
| 90 | |
| 91 | void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, |
| 92 | Condition cond) { |
| 93 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 94 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 99 | Condition cond) { |
| 100 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 101 | // 'code' is always generated ARM code, never THUMB code |
| 102 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void MacroAssembler::Call(Register target, Condition cond) { |
| 107 | #if USE_BLX |
| 108 | blx(target, cond); |
| 109 | #else |
| 110 | // set lr for return at current pc + 8 |
| 111 | mov(lr, Operand(pc), LeaveCC, cond); |
| 112 | mov(pc, Operand(target), LeaveCC, cond); |
| 113 | #endif |
| 114 | } |
| 115 | |
| 116 | |
| 117 | void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode, |
| 118 | Condition cond) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 119 | #if USE_BLX |
| 120 | // On ARMv5 and after the recommended call sequence is: |
| 121 | // ldr ip, [pc, #...] |
| 122 | // blx ip |
| 123 | |
| 124 | // The two instructions (ldr and blx) could be separated by a constant |
| 125 | // pool and the code would still work. The issue comes from the |
| 126 | // patching code which expect the ldr to be just above the blx. |
| 127 | { BlockConstPoolScope block_const_pool(this); |
| 128 | // Statement positions are expected to be recorded when the target |
| 129 | // address is loaded. The mov method will automatically record |
| 130 | // positions when pc is the target, since this is not the case here |
| 131 | // we have to do it explicitly. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 132 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 133 | |
| 134 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 135 | blx(ip, cond); |
| 136 | } |
| 137 | |
| 138 | ASSERT(kCallTargetAddressOffset == 2 * kInstrSize); |
| 139 | #else |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 140 | // Set lr for return at current pc + 8. |
| 141 | mov(lr, Operand(pc), LeaveCC, cond); |
| 142 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 143 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 144 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | ASSERT(kCallTargetAddressOffset == kInstrSize); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 146 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
| 150 | void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode, |
| 151 | Condition cond) { |
| 152 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 153 | Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, |
| 158 | Condition cond) { |
| 159 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 160 | // 'code' is always generated ARM code, never THUMB code |
| 161 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | void MacroAssembler::Ret(Condition cond) { |
| 166 | #if USE_BX |
| 167 | bx(lr, cond); |
| 168 | #else |
| 169 | mov(pc, Operand(lr), LeaveCC, cond); |
| 170 | #endif |
| 171 | } |
| 172 | |
| 173 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 174 | void MacroAssembler::Drop(int count, Condition cond) { |
| 175 | if (count > 0) { |
| 176 | add(sp, sp, Operand(count * kPointerSize), LeaveCC, cond); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 181 | void MacroAssembler::Ret(int drop, Condition cond) { |
| 182 | Drop(drop, cond); |
| 183 | Ret(cond); |
| 184 | } |
| 185 | |
| 186 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 187 | void MacroAssembler::Swap(Register reg1, |
| 188 | Register reg2, |
| 189 | Register scratch, |
| 190 | Condition cond) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 191 | if (scratch.is(no_reg)) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 192 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
| 193 | eor(reg2, reg2, Operand(reg1), LeaveCC, cond); |
| 194 | eor(reg1, reg1, Operand(reg2), LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 195 | } else { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 196 | mov(scratch, reg1, LeaveCC, cond); |
| 197 | mov(reg1, reg2, LeaveCC, cond); |
| 198 | mov(reg2, scratch, LeaveCC, cond); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
| 202 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 203 | void MacroAssembler::Call(Label* target) { |
| 204 | bl(target); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | void MacroAssembler::Move(Register dst, Handle<Object> value) { |
| 209 | mov(dst, Operand(value)); |
| 210 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 211 | |
| 212 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 213 | void MacroAssembler::Move(Register dst, Register src) { |
| 214 | if (!dst.is(src)) { |
| 215 | mov(dst, src); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 220 | void MacroAssembler::And(Register dst, Register src1, const Operand& src2, |
| 221 | Condition cond) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 222 | if (!src2.is_reg() && |
| 223 | !src2.must_use_constant_pool() && |
| 224 | src2.immediate() == 0) { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 225 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, cond); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 226 | |
| 227 | } else if (!src2.is_single_instruction() && |
| 228 | !src2.must_use_constant_pool() && |
| 229 | CpuFeatures::IsSupported(ARMv7) && |
| 230 | IsPowerOf2(src2.immediate() + 1)) { |
| 231 | ubfx(dst, src1, 0, WhichPowerOf2(src2.immediate() + 1), cond); |
| 232 | |
| 233 | } else { |
| 234 | and_(dst, src1, src2, LeaveCC, cond); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 235 | } |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
| 239 | void MacroAssembler::Ubfx(Register dst, Register src1, int lsb, int width, |
| 240 | Condition cond) { |
| 241 | ASSERT(lsb < 32); |
| 242 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 243 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 244 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 245 | if (lsb != 0) { |
| 246 | mov(dst, Operand(dst, LSR, lsb), LeaveCC, cond); |
| 247 | } |
| 248 | } else { |
| 249 | ubfx(dst, src1, lsb, width, cond); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void MacroAssembler::Sbfx(Register dst, Register src1, int lsb, int width, |
| 255 | Condition cond) { |
| 256 | ASSERT(lsb < 32); |
| 257 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 258 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 259 | and_(dst, src1, Operand(mask), LeaveCC, cond); |
| 260 | int shift_up = 32 - lsb - width; |
| 261 | int shift_down = lsb + shift_up; |
| 262 | if (shift_up != 0) { |
| 263 | mov(dst, Operand(dst, LSL, shift_up), LeaveCC, cond); |
| 264 | } |
| 265 | if (shift_down != 0) { |
| 266 | mov(dst, Operand(dst, ASR, shift_down), LeaveCC, cond); |
| 267 | } |
| 268 | } else { |
| 269 | sbfx(dst, src1, lsb, width, cond); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | |
| 274 | void MacroAssembler::Bfc(Register dst, int lsb, int width, Condition cond) { |
| 275 | ASSERT(lsb < 32); |
| 276 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 277 | int mask = (1 << (width + lsb)) - 1 - ((1 << lsb) - 1); |
| 278 | bic(dst, dst, Operand(mask)); |
| 279 | } else { |
| 280 | bfc(dst, lsb, width, cond); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 285 | void MacroAssembler::Usat(Register dst, int satpos, const Operand& src, |
| 286 | Condition cond) { |
| 287 | if (!CpuFeatures::IsSupported(ARMv7)) { |
| 288 | ASSERT(!dst.is(pc) && !src.rm().is(pc)); |
| 289 | ASSERT((satpos >= 0) && (satpos <= 31)); |
| 290 | |
| 291 | // These asserts are required to ensure compatibility with the ARMv7 |
| 292 | // implementation. |
| 293 | ASSERT((src.shift_op() == ASR) || (src.shift_op() == LSL)); |
| 294 | ASSERT(src.rs().is(no_reg)); |
| 295 | |
| 296 | Label done; |
| 297 | int satval = (1 << satpos) - 1; |
| 298 | |
| 299 | if (cond != al) { |
| 300 | b(NegateCondition(cond), &done); // Skip saturate if !condition. |
| 301 | } |
| 302 | if (!(src.is_reg() && dst.is(src.rm()))) { |
| 303 | mov(dst, src); |
| 304 | } |
| 305 | tst(dst, Operand(~satval)); |
| 306 | b(eq, &done); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 307 | mov(dst, Operand(0, RelocInfo::NONE), LeaveCC, mi); // 0 if negative. |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 308 | mov(dst, Operand(satval), LeaveCC, pl); // satval if positive. |
| 309 | bind(&done); |
| 310 | } else { |
| 311 | usat(dst, satpos, src, cond); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) { |
| 317 | // Empty the const pool. |
| 318 | CheckConstPool(true, true); |
| 319 | add(pc, pc, Operand(index, |
| 320 | LSL, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 321 | Instruction::kInstrSizeLog2 - kSmiTagSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 322 | BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * kInstrSize); |
| 323 | nop(); // Jump table alignment. |
| 324 | for (int i = 0; i < targets.length(); i++) { |
| 325 | b(targets[i]); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
| 330 | void MacroAssembler::LoadRoot(Register destination, |
| 331 | Heap::RootListIndex index, |
| 332 | Condition cond) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 333 | ldr(destination, MemOperand(roots, index << kPointerSizeLog2), cond); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 337 | void MacroAssembler::StoreRoot(Register source, |
| 338 | Heap::RootListIndex index, |
| 339 | Condition cond) { |
| 340 | str(source, MemOperand(roots, index << kPointerSizeLog2), cond); |
| 341 | } |
| 342 | |
| 343 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 344 | void MacroAssembler::RecordWriteHelper(Register object, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 345 | Register address, |
| 346 | Register scratch) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 347 | if (FLAG_debug_code) { |
| 348 | // Check that the object is not in new space. |
| 349 | Label not_in_new_space; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 350 | InNewSpace(object, scratch, ne, ¬_in_new_space); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 351 | Abort("new-space object passed to RecordWriteHelper"); |
| 352 | bind(¬_in_new_space); |
| 353 | } |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 354 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 355 | // Calculate page address. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 356 | Bfc(object, 0, kPageSizeBits); |
| 357 | |
| 358 | // Calculate region number. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 359 | Ubfx(address, address, Page::kRegionSizeLog2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 360 | kPageSizeBits - Page::kRegionSizeLog2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 361 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 362 | // Mark region dirty. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 363 | ldr(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | mov(ip, Operand(1)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 365 | orr(scratch, scratch, Operand(ip, LSL, address)); |
| 366 | str(scratch, MemOperand(object, Page::kDirtyFlagOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | |
| 370 | void MacroAssembler::InNewSpace(Register object, |
| 371 | Register scratch, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 372 | Condition cond, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 373 | Label* branch) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 374 | ASSERT(cond == eq || cond == ne); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 375 | and_(scratch, object, Operand(ExternalReference::new_space_mask())); |
| 376 | cmp(scratch, Operand(ExternalReference::new_space_start())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 377 | b(cond, branch); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | |
| 381 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 382 | // register 'object' contains a heap object pointer. The heap object |
| 383 | // tag is shifted away. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 384 | void MacroAssembler::RecordWrite(Register object, |
| 385 | Operand offset, |
| 386 | Register scratch0, |
| 387 | Register scratch1) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 388 | // The compiled code assumes that record write doesn't change the |
| 389 | // context register, so we check that none of the clobbered |
| 390 | // registers are cp. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 391 | ASSERT(!object.is(cp) && !scratch0.is(cp) && !scratch1.is(cp)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 392 | |
| 393 | Label done; |
| 394 | |
| 395 | // First, test that the object is not in the new space. We cannot set |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 396 | // region marks for new space pages. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 397 | InNewSpace(object, scratch0, eq, &done); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 398 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 399 | // Add offset into the object. |
| 400 | add(scratch0, object, offset); |
| 401 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 402 | // Record the actual write. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 403 | RecordWriteHelper(object, scratch0, scratch1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 404 | |
| 405 | bind(&done); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 406 | |
| 407 | // Clobber all input registers when running with the debug-code flag |
| 408 | // turned on to provoke errors. |
| 409 | if (FLAG_debug_code) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 410 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 411 | mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 412 | mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 413 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 417 | // Will clobber 4 registers: object, address, scratch, ip. The |
| 418 | // register 'object' contains a heap object pointer. The heap object |
| 419 | // tag is shifted away. |
| 420 | void MacroAssembler::RecordWrite(Register object, |
| 421 | Register address, |
| 422 | Register scratch) { |
| 423 | // The compiled code assumes that record write doesn't change the |
| 424 | // context register, so we check that none of the clobbered |
| 425 | // registers are cp. |
| 426 | ASSERT(!object.is(cp) && !address.is(cp) && !scratch.is(cp)); |
| 427 | |
| 428 | Label done; |
| 429 | |
| 430 | // First, test that the object is not in the new space. We cannot set |
| 431 | // region marks for new space pages. |
| 432 | InNewSpace(object, scratch, eq, &done); |
| 433 | |
| 434 | // Record the actual write. |
| 435 | RecordWriteHelper(object, address, scratch); |
| 436 | |
| 437 | bind(&done); |
| 438 | |
| 439 | // Clobber all input registers when running with the debug-code flag |
| 440 | // turned on to provoke errors. |
| 441 | if (FLAG_debug_code) { |
| 442 | mov(object, Operand(BitCast<int32_t>(kZapValue))); |
| 443 | mov(address, Operand(BitCast<int32_t>(kZapValue))); |
| 444 | mov(scratch, Operand(BitCast<int32_t>(kZapValue))); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 449 | // Push and pop all registers that can hold pointers. |
| 450 | void MacroAssembler::PushSafepointRegisters() { |
| 451 | // Safepoints expect a block of contiguous register values starting with r0: |
| 452 | ASSERT(((1 << kNumSafepointSavedRegisters) - 1) == kSafepointSavedRegisters); |
| 453 | // Safepoints expect a block of kNumSafepointRegisters values on the |
| 454 | // stack, so adjust the stack for unsaved registers. |
| 455 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 456 | ASSERT(num_unsaved >= 0); |
| 457 | sub(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 458 | stm(db_w, sp, kSafepointSavedRegisters); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | void MacroAssembler::PopSafepointRegisters() { |
| 463 | const int num_unsaved = kNumSafepointRegisters - kNumSafepointSavedRegisters; |
| 464 | ldm(ia_w, sp, kSafepointSavedRegisters); |
| 465 | add(sp, sp, Operand(num_unsaved * kPointerSize)); |
| 466 | } |
| 467 | |
| 468 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 469 | void MacroAssembler::PushSafepointRegistersAndDoubles() { |
| 470 | PushSafepointRegisters(); |
| 471 | sub(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 472 | kDoubleSize)); |
| 473 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 474 | vstr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | |
| 479 | void MacroAssembler::PopSafepointRegistersAndDoubles() { |
| 480 | for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; i++) { |
| 481 | vldr(DwVfpRegister::FromAllocationIndex(i), sp, i * kDoubleSize); |
| 482 | } |
| 483 | add(sp, sp, Operand(DwVfpRegister::kNumAllocatableRegisters * |
| 484 | kDoubleSize)); |
| 485 | PopSafepointRegisters(); |
| 486 | } |
| 487 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 488 | void MacroAssembler::StoreToSafepointRegistersAndDoublesSlot(Register reg) { |
| 489 | str(reg, SafepointRegistersAndDoublesSlot(reg)); |
| 490 | } |
| 491 | |
| 492 | |
| 493 | void MacroAssembler::StoreToSafepointRegisterSlot(Register reg) { |
| 494 | str(reg, SafepointRegisterSlot(reg)); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | void MacroAssembler::LoadFromSafepointRegisterSlot(Register reg) { |
| 499 | ldr(reg, SafepointRegisterSlot(reg)); |
| 500 | } |
| 501 | |
| 502 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 503 | int MacroAssembler::SafepointRegisterStackIndex(int reg_code) { |
| 504 | // The registers are pushed starting with the highest encoding, |
| 505 | // which means that lowest encodings are closest to the stack pointer. |
| 506 | ASSERT(reg_code >= 0 && reg_code < kNumSafepointRegisters); |
| 507 | return reg_code; |
| 508 | } |
| 509 | |
| 510 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 511 | MemOperand MacroAssembler::SafepointRegisterSlot(Register reg) { |
| 512 | return MemOperand(sp, SafepointRegisterStackIndex(reg.code()) * kPointerSize); |
| 513 | } |
| 514 | |
| 515 | |
| 516 | MemOperand MacroAssembler::SafepointRegistersAndDoublesSlot(Register reg) { |
| 517 | // General purpose registers are pushed last on the stack. |
| 518 | int doubles_size = DwVfpRegister::kNumAllocatableRegisters * kDoubleSize; |
| 519 | int register_offset = SafepointRegisterStackIndex(reg.code()) * kPointerSize; |
| 520 | return MemOperand(sp, doubles_size + register_offset); |
| 521 | } |
| 522 | |
| 523 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 524 | void MacroAssembler::Ldrd(Register dst1, Register dst2, |
| 525 | const MemOperand& src, Condition cond) { |
| 526 | ASSERT(src.rm().is(no_reg)); |
| 527 | ASSERT(!dst1.is(lr)); // r14. |
| 528 | ASSERT_EQ(0, dst1.code() % 2); |
| 529 | ASSERT_EQ(dst1.code() + 1, dst2.code()); |
| 530 | |
| 531 | // Generate two ldr instructions if ldrd is not available. |
| 532 | if (CpuFeatures::IsSupported(ARMv7)) { |
| 533 | CpuFeatures::Scope scope(ARMv7); |
| 534 | ldrd(dst1, dst2, src, cond); |
| 535 | } else { |
| 536 | MemOperand src2(src); |
| 537 | src2.set_offset(src2.offset() + 4); |
| 538 | if (dst1.is(src.rn())) { |
| 539 | ldr(dst2, src2, cond); |
| 540 | ldr(dst1, src, cond); |
| 541 | } else { |
| 542 | ldr(dst1, src, cond); |
| 543 | ldr(dst2, src2, cond); |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | |
| 549 | void MacroAssembler::Strd(Register src1, Register src2, |
| 550 | const MemOperand& dst, Condition cond) { |
| 551 | ASSERT(dst.rm().is(no_reg)); |
| 552 | ASSERT(!src1.is(lr)); // r14. |
| 553 | ASSERT_EQ(0, src1.code() % 2); |
| 554 | ASSERT_EQ(src1.code() + 1, src2.code()); |
| 555 | |
| 556 | // Generate two str instructions if strd is not available. |
| 557 | if (CpuFeatures::IsSupported(ARMv7)) { |
| 558 | CpuFeatures::Scope scope(ARMv7); |
| 559 | strd(src1, src2, dst, cond); |
| 560 | } else { |
| 561 | MemOperand dst2(dst); |
| 562 | dst2.set_offset(dst2.offset() + 4); |
| 563 | str(src1, dst, cond); |
| 564 | str(src2, dst2, cond); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 569 | void MacroAssembler::ClearFPSCRBits(const uint32_t bits_to_clear, |
| 570 | const Register scratch, |
| 571 | const Condition cond) { |
| 572 | vmrs(scratch, cond); |
| 573 | bic(scratch, scratch, Operand(bits_to_clear), LeaveCC, cond); |
| 574 | vmsr(scratch, cond); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 579 | const DwVfpRegister src2, |
| 580 | const Condition cond) { |
| 581 | // Compare and move FPSCR flags to the normal condition flags. |
| 582 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 583 | } |
| 584 | |
| 585 | void MacroAssembler::VFPCompareAndSetFlags(const DwVfpRegister src1, |
| 586 | const double src2, |
| 587 | const Condition cond) { |
| 588 | // Compare and move FPSCR flags to the normal condition flags. |
| 589 | VFPCompareAndLoadFlags(src1, src2, pc, cond); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 594 | const DwVfpRegister src2, |
| 595 | const Register fpscr_flags, |
| 596 | const Condition cond) { |
| 597 | // Compare and load FPSCR. |
| 598 | vcmp(src1, src2, cond); |
| 599 | vmrs(fpscr_flags, cond); |
| 600 | } |
| 601 | |
| 602 | void MacroAssembler::VFPCompareAndLoadFlags(const DwVfpRegister src1, |
| 603 | const double src2, |
| 604 | const Register fpscr_flags, |
| 605 | const Condition cond) { |
| 606 | // Compare and load FPSCR. |
| 607 | vcmp(src1, src2, cond); |
| 608 | vmrs(fpscr_flags, cond); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 612 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
| 613 | // r0-r3: preserved |
| 614 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 615 | mov(ip, Operand(Smi::FromInt(type))); |
| 616 | push(ip); |
| 617 | mov(ip, Operand(CodeObject())); |
| 618 | push(ip); |
| 619 | add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP. |
| 620 | } |
| 621 | |
| 622 | |
| 623 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
| 624 | // r0: preserved |
| 625 | // r1: preserved |
| 626 | // r2: preserved |
| 627 | |
| 628 | // Drop the execution stack down to the frame pointer and restore |
| 629 | // the caller frame pointer and return address. |
| 630 | mov(sp, fp); |
| 631 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 632 | } |
| 633 | |
| 634 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 635 | void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
| 636 | // Setup the frame structure on the stack. |
| 637 | ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
| 638 | ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
| 639 | ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
| 640 | Push(lr, fp); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 641 | mov(fp, Operand(sp)); // Setup new frame pointer. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 642 | // Reserve room for saved entry sp and code object. |
| 643 | sub(sp, sp, Operand(2 * kPointerSize)); |
| 644 | if (FLAG_debug_code) { |
| 645 | mov(ip, Operand(0)); |
| 646 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
| 647 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 648 | mov(ip, Operand(CodeObject())); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 649 | str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 650 | |
| 651 | // Save the frame pointer and the context in top. |
| 652 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 653 | str(fp, MemOperand(ip)); |
| 654 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 655 | str(cp, MemOperand(ip)); |
| 656 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 657 | // Optionally save all double registers. |
| 658 | if (save_doubles) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 659 | sub(sp, sp, Operand(DwVfpRegister::kNumRegisters * kDoubleSize)); |
| 660 | const int offset = -2 * kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 661 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 662 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 663 | vstr(reg, fp, offset - ((i + 1) * kDoubleSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 664 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 665 | // Note that d0 will be accessible at |
| 666 | // fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize, |
| 667 | // since the sp slot and code slot were pushed after the fp. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 668 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 669 | |
| 670 | // Reserve place for the return address and stack space and align the frame |
| 671 | // preparing for calling the runtime function. |
| 672 | const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 673 | sub(sp, sp, Operand((stack_space + 1) * kPointerSize)); |
| 674 | if (frame_alignment > 0) { |
| 675 | ASSERT(IsPowerOf2(frame_alignment)); |
| 676 | and_(sp, sp, Operand(-frame_alignment)); |
| 677 | } |
| 678 | |
| 679 | // Set the exit frame sp value to point just before the return address |
| 680 | // location. |
| 681 | add(ip, sp, Operand(kPointerSize)); |
| 682 | str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 686 | void MacroAssembler::InitializeNewString(Register string, |
| 687 | Register length, |
| 688 | Heap::RootListIndex map_index, |
| 689 | Register scratch1, |
| 690 | Register scratch2) { |
| 691 | mov(scratch1, Operand(length, LSL, kSmiTagSize)); |
| 692 | LoadRoot(scratch2, map_index); |
| 693 | str(scratch1, FieldMemOperand(string, String::kLengthOffset)); |
| 694 | mov(scratch1, Operand(String::kEmptyHashField)); |
| 695 | str(scratch2, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 696 | str(scratch1, FieldMemOperand(string, String::kHashFieldOffset)); |
| 697 | } |
| 698 | |
| 699 | |
| 700 | int MacroAssembler::ActivationFrameAlignment() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 701 | #if defined(V8_HOST_ARCH_ARM) |
| 702 | // Running on the real platform. Use the alignment as mandated by the local |
| 703 | // environment. |
| 704 | // Note: This will break if we ever start generating snapshots on one ARM |
| 705 | // platform for another ARM platform with a different alignment. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 706 | return OS::ActivationFrameAlignment(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 707 | #else // defined(V8_HOST_ARCH_ARM) |
| 708 | // If we are using the simulator then we should always align to the expected |
| 709 | // alignment. As the simulator is used to generate snapshots we do not know |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 710 | // if the target platform will need alignment, so this is controlled from a |
| 711 | // flag. |
| 712 | return FLAG_sim_stack_alignment; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | #endif // defined(V8_HOST_ARCH_ARM) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 717 | void MacroAssembler::LeaveExitFrame(bool save_doubles) { |
| 718 | // Optionally restore all double registers. |
| 719 | if (save_doubles) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 720 | for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
| 721 | DwVfpRegister reg = DwVfpRegister::from_code(i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 722 | const int offset = -2 * kPointerSize; |
| 723 | vldr(reg, fp, offset - ((i + 1) * kDoubleSize)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 727 | // Clear top frame. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 728 | mov(r3, Operand(0, RelocInfo::NONE)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 729 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 730 | str(r3, MemOperand(ip)); |
| 731 | |
| 732 | // Restore current context from top and clear it in debug mode. |
| 733 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 734 | ldr(cp, MemOperand(ip)); |
| 735 | #ifdef DEBUG |
| 736 | str(r3, MemOperand(ip)); |
| 737 | #endif |
| 738 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 739 | // Tear down the exit frame, pop the arguments, and return. Callee-saved |
| 740 | // register r4 still holds argc. |
| 741 | mov(sp, Operand(fp)); |
| 742 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 743 | add(sp, sp, Operand(r4, LSL, kPointerSizeLog2)); |
| 744 | mov(pc, lr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | |
| 748 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 749 | const ParameterCount& actual, |
| 750 | Handle<Code> code_constant, |
| 751 | Register code_reg, |
| 752 | Label* done, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 753 | InvokeFlag flag, |
| 754 | PostCallGenerator* post_call_generator) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 755 | bool definitely_matches = false; |
| 756 | Label regular_invoke; |
| 757 | |
| 758 | // Check whether the expected and actual arguments count match. If not, |
| 759 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 760 | // r0: actual arguments count |
| 761 | // r1: function (passed through to callee) |
| 762 | // r2: expected arguments count |
| 763 | // r3: callee code entry |
| 764 | |
| 765 | // The code below is made a lot easier because the calling code already sets |
| 766 | // up actual and expected registers according to the contract if values are |
| 767 | // passed in registers. |
| 768 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 769 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 770 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 771 | |
| 772 | if (expected.is_immediate()) { |
| 773 | ASSERT(actual.is_immediate()); |
| 774 | if (expected.immediate() == actual.immediate()) { |
| 775 | definitely_matches = true; |
| 776 | } else { |
| 777 | mov(r0, Operand(actual.immediate())); |
| 778 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 779 | if (expected.immediate() == sentinel) { |
| 780 | // Don't worry about adapting arguments for builtins that |
| 781 | // don't want that done. Skip adaption code by making it look |
| 782 | // like we have a match between expected and actual number of |
| 783 | // arguments. |
| 784 | definitely_matches = true; |
| 785 | } else { |
| 786 | mov(r2, Operand(expected.immediate())); |
| 787 | } |
| 788 | } |
| 789 | } else { |
| 790 | if (actual.is_immediate()) { |
| 791 | cmp(expected.reg(), Operand(actual.immediate())); |
| 792 | b(eq, ®ular_invoke); |
| 793 | mov(r0, Operand(actual.immediate())); |
| 794 | } else { |
| 795 | cmp(expected.reg(), Operand(actual.reg())); |
| 796 | b(eq, ®ular_invoke); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | if (!definitely_matches) { |
| 801 | if (!code_constant.is_null()) { |
| 802 | mov(r3, Operand(code_constant)); |
| 803 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 804 | } |
| 805 | |
| 806 | Handle<Code> adaptor = |
| 807 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 808 | if (flag == CALL_FUNCTION) { |
| 809 | Call(adaptor, RelocInfo::CODE_TARGET); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 810 | if (post_call_generator != NULL) post_call_generator->Generate(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 811 | b(done); |
| 812 | } else { |
| 813 | Jump(adaptor, RelocInfo::CODE_TARGET); |
| 814 | } |
| 815 | bind(®ular_invoke); |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | |
| 820 | void MacroAssembler::InvokeCode(Register code, |
| 821 | const ParameterCount& expected, |
| 822 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 823 | InvokeFlag flag, |
| 824 | PostCallGenerator* post_call_generator) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 825 | Label done; |
| 826 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 827 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag, |
| 828 | post_call_generator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | if (flag == CALL_FUNCTION) { |
| 830 | Call(code); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 831 | if (post_call_generator != NULL) post_call_generator->Generate(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 832 | } else { |
| 833 | ASSERT(flag == JUMP_FUNCTION); |
| 834 | Jump(code); |
| 835 | } |
| 836 | |
| 837 | // Continue here if InvokePrologue does handle the invocation due to |
| 838 | // mismatched parameter counts. |
| 839 | bind(&done); |
| 840 | } |
| 841 | |
| 842 | |
| 843 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 844 | const ParameterCount& expected, |
| 845 | const ParameterCount& actual, |
| 846 | RelocInfo::Mode rmode, |
| 847 | InvokeFlag flag) { |
| 848 | Label done; |
| 849 | |
| 850 | InvokePrologue(expected, actual, code, no_reg, &done, flag); |
| 851 | if (flag == CALL_FUNCTION) { |
| 852 | Call(code, rmode); |
| 853 | } else { |
| 854 | Jump(code, rmode); |
| 855 | } |
| 856 | |
| 857 | // Continue here if InvokePrologue does handle the invocation due to |
| 858 | // mismatched parameter counts. |
| 859 | bind(&done); |
| 860 | } |
| 861 | |
| 862 | |
| 863 | void MacroAssembler::InvokeFunction(Register fun, |
| 864 | const ParameterCount& actual, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 865 | InvokeFlag flag, |
| 866 | PostCallGenerator* post_call_generator) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 867 | // Contract with called JS functions requires that function is passed in r1. |
| 868 | ASSERT(fun.is(r1)); |
| 869 | |
| 870 | Register expected_reg = r2; |
| 871 | Register code_reg = r3; |
| 872 | |
| 873 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 874 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 875 | ldr(expected_reg, |
| 876 | FieldMemOperand(code_reg, |
| 877 | SharedFunctionInfo::kFormalParameterCountOffset)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 878 | mov(expected_reg, Operand(expected_reg, ASR, kSmiTagSize)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 879 | ldr(code_reg, |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 880 | FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 881 | |
| 882 | ParameterCount expected(expected_reg); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 883 | InvokeCode(code_reg, expected, actual, flag, post_call_generator); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 887 | void MacroAssembler::InvokeFunction(JSFunction* function, |
| 888 | const ParameterCount& actual, |
| 889 | InvokeFlag flag) { |
| 890 | ASSERT(function->is_compiled()); |
| 891 | |
| 892 | // Get the function and setup the context. |
| 893 | mov(r1, Operand(Handle<JSFunction>(function))); |
| 894 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 895 | |
| 896 | // Invoke the cached code. |
| 897 | Handle<Code> code(function->code()); |
| 898 | ParameterCount expected(function->shared()->formal_parameter_count()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 899 | if (V8::UseCrankshaft()) { |
| 900 | // TODO(kasperl): For now, we always call indirectly through the |
| 901 | // code field in the function to allow recompilation to take effect |
| 902 | // without changing any of the call sites. |
| 903 | ldr(r3, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
| 904 | InvokeCode(r3, expected, actual, flag); |
| 905 | } else { |
| 906 | InvokeCode(code, expected, actual, RelocInfo::CODE_TARGET, flag); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | |
| 911 | void MacroAssembler::IsObjectJSObjectType(Register heap_object, |
| 912 | Register map, |
| 913 | Register scratch, |
| 914 | Label* fail) { |
| 915 | ldr(map, FieldMemOperand(heap_object, HeapObject::kMapOffset)); |
| 916 | IsInstanceJSObjectType(map, scratch, fail); |
| 917 | } |
| 918 | |
| 919 | |
| 920 | void MacroAssembler::IsInstanceJSObjectType(Register map, |
| 921 | Register scratch, |
| 922 | Label* fail) { |
| 923 | ldrb(scratch, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 924 | cmp(scratch, Operand(FIRST_JS_OBJECT_TYPE)); |
| 925 | b(lt, fail); |
| 926 | cmp(scratch, Operand(LAST_JS_OBJECT_TYPE)); |
| 927 | b(gt, fail); |
| 928 | } |
| 929 | |
| 930 | |
| 931 | void MacroAssembler::IsObjectJSStringType(Register object, |
| 932 | Register scratch, |
| 933 | Label* fail) { |
| 934 | ASSERT(kNotStringTag != 0); |
| 935 | |
| 936 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 937 | ldrb(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 938 | tst(scratch, Operand(kIsNotStringMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 939 | b(ne, fail); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 942 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 943 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 944 | void MacroAssembler::DebugBreak() { |
| 945 | ASSERT(allow_stub_calls()); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 946 | mov(r0, Operand(0, RelocInfo::NONE)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 947 | mov(r1, Operand(ExternalReference(Runtime::kDebugBreak))); |
| 948 | CEntryStub ces(1); |
| 949 | Call(ces.GetCode(), RelocInfo::DEBUG_BREAK); |
| 950 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 951 | #endif |
| 952 | |
| 953 | |
| 954 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 955 | HandlerType type) { |
| 956 | // Adjust this code if not the case. |
| 957 | ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize); |
| 958 | // The pc (return address) is passed in register lr. |
| 959 | if (try_location == IN_JAVASCRIPT) { |
| 960 | if (type == TRY_CATCH_HANDLER) { |
| 961 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 962 | } else { |
| 963 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 964 | } |
| 965 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 966 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 967 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 968 | stm(db_w, sp, r3.bit() | fp.bit() | lr.bit()); |
| 969 | // Save the current handler as the next handler. |
| 970 | mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 971 | ldr(r1, MemOperand(r3)); |
| 972 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 973 | push(r1); |
| 974 | // Link this handler as the new current one. |
| 975 | str(sp, MemOperand(r3)); |
| 976 | } else { |
| 977 | // Must preserve r0-r4, r5-r7 are available. |
| 978 | ASSERT(try_location == IN_JS_ENTRY); |
| 979 | // The frame pointer does not point to a JS frame so we save NULL |
| 980 | // for fp. We expect the code throwing an exception to check fp |
| 981 | // before dereferencing it to restore the context. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 982 | mov(ip, Operand(0, RelocInfo::NONE)); // To save a NULL frame pointer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 983 | mov(r6, Operand(StackHandler::ENTRY)); |
| 984 | ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize |
| 985 | && StackHandlerConstants::kFPOffset == 2 * kPointerSize |
| 986 | && StackHandlerConstants::kPCOffset == 3 * kPointerSize); |
| 987 | stm(db_w, sp, r6.bit() | ip.bit() | lr.bit()); |
| 988 | // Save the current handler as the next handler. |
| 989 | mov(r7, Operand(ExternalReference(Top::k_handler_address))); |
| 990 | ldr(r6, MemOperand(r7)); |
| 991 | ASSERT(StackHandlerConstants::kNextOffset == 0); |
| 992 | push(r6); |
| 993 | // Link this handler as the new current one. |
| 994 | str(sp, MemOperand(r7)); |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 999 | void MacroAssembler::PopTryHandler() { |
| 1000 | ASSERT_EQ(0, StackHandlerConstants::kNextOffset); |
| 1001 | pop(r1); |
| 1002 | mov(ip, Operand(ExternalReference(Top::k_handler_address))); |
| 1003 | add(sp, sp, Operand(StackHandlerConstants::kSize - kPointerSize)); |
| 1004 | str(r1, MemOperand(ip)); |
| 1005 | } |
| 1006 | |
| 1007 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1008 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 1009 | Register scratch, |
| 1010 | Label* miss) { |
| 1011 | Label same_contexts; |
| 1012 | |
| 1013 | ASSERT(!holder_reg.is(scratch)); |
| 1014 | ASSERT(!holder_reg.is(ip)); |
| 1015 | ASSERT(!scratch.is(ip)); |
| 1016 | |
| 1017 | // Load current lexical context from the stack frame. |
| 1018 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 1019 | // In debug mode, make sure the lexical context is set. |
| 1020 | #ifdef DEBUG |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1021 | cmp(scratch, Operand(0, RelocInfo::NONE)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1022 | Check(ne, "we should not have an empty lexical context"); |
| 1023 | #endif |
| 1024 | |
| 1025 | // Load the global context of the current context. |
| 1026 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 1027 | ldr(scratch, FieldMemOperand(scratch, offset)); |
| 1028 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 1029 | |
| 1030 | // Check the context is a global context. |
| 1031 | if (FLAG_debug_code) { |
| 1032 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1033 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1034 | // that ip is clobbered as part of cmp with an object Operand. |
| 1035 | push(holder_reg); // Temporarily save holder on the stack. |
| 1036 | // Read the first word and compare to the global_context_map. |
| 1037 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 1038 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1039 | cmp(holder_reg, ip); |
| 1040 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1041 | pop(holder_reg); // Restore holder. |
| 1042 | } |
| 1043 | |
| 1044 | // Check if both contexts are the same. |
| 1045 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1046 | cmp(scratch, Operand(ip)); |
| 1047 | b(eq, &same_contexts); |
| 1048 | |
| 1049 | // Check the context is a global context. |
| 1050 | if (FLAG_debug_code) { |
| 1051 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 1052 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 1053 | // that ip is clobbered as part of cmp with an object Operand. |
| 1054 | push(holder_reg); // Temporarily save holder on the stack. |
| 1055 | mov(holder_reg, ip); // Move ip to its holding place. |
| 1056 | LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1057 | cmp(holder_reg, ip); |
| 1058 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 1059 | |
| 1060 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
| 1061 | LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1062 | cmp(holder_reg, ip); |
| 1063 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 1064 | // Restore ip is not needed. ip is reloaded below. |
| 1065 | pop(holder_reg); // Restore holder. |
| 1066 | // Restore ip to holder's context. |
| 1067 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 1068 | } |
| 1069 | |
| 1070 | // Check that the security token in the calling global object is |
| 1071 | // compatible with the security token in the receiving global |
| 1072 | // object. |
| 1073 | int token_offset = Context::kHeaderSize + |
| 1074 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 1075 | |
| 1076 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 1077 | ldr(ip, FieldMemOperand(ip, token_offset)); |
| 1078 | cmp(scratch, Operand(ip)); |
| 1079 | b(ne, miss); |
| 1080 | |
| 1081 | bind(&same_contexts); |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | void MacroAssembler::AllocateInNewSpace(int object_size, |
| 1086 | Register result, |
| 1087 | Register scratch1, |
| 1088 | Register scratch2, |
| 1089 | Label* gc_required, |
| 1090 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1091 | if (!FLAG_inline_new) { |
| 1092 | if (FLAG_debug_code) { |
| 1093 | // Trash the registers to simulate an allocation failure. |
| 1094 | mov(result, Operand(0x7091)); |
| 1095 | mov(scratch1, Operand(0x7191)); |
| 1096 | mov(scratch2, Operand(0x7291)); |
| 1097 | } |
| 1098 | jmp(gc_required); |
| 1099 | return; |
| 1100 | } |
| 1101 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1102 | ASSERT(!result.is(scratch1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1103 | ASSERT(!result.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1104 | ASSERT(!scratch1.is(scratch2)); |
| 1105 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1106 | // Make object size into bytes. |
| 1107 | if ((flags & SIZE_IN_WORDS) != 0) { |
| 1108 | object_size *= kPointerSize; |
| 1109 | } |
| 1110 | ASSERT_EQ(0, object_size & kObjectAlignmentMask); |
| 1111 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1112 | // Check relative positions of allocation top and limit addresses. |
| 1113 | // The values must be adjacent in memory to allow the use of LDM. |
| 1114 | // Also, assert that the registers are numbered such that the values |
| 1115 | // are loaded in the correct order. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1116 | ExternalReference new_space_allocation_top = |
| 1117 | ExternalReference::new_space_allocation_top_address(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1118 | ExternalReference new_space_allocation_limit = |
| 1119 | ExternalReference::new_space_allocation_limit_address(); |
| 1120 | intptr_t top = |
| 1121 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1122 | intptr_t limit = |
| 1123 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1124 | ASSERT((limit - top) == kPointerSize); |
| 1125 | ASSERT(result.code() < ip.code()); |
| 1126 | |
| 1127 | // Set up allocation top address and object size registers. |
| 1128 | Register topaddr = scratch1; |
| 1129 | Register obj_size_reg = scratch2; |
| 1130 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1131 | mov(obj_size_reg, Operand(object_size)); |
| 1132 | |
| 1133 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1134 | // does not need ip for implicit literal generation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1135 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1136 | // Load allocation top into result and allocation limit into ip. |
| 1137 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1138 | } else { |
| 1139 | if (FLAG_debug_code) { |
| 1140 | // Assert that result actually contains top on entry. ip is used |
| 1141 | // immediately below so this use of ip does not cause difference with |
| 1142 | // respect to register content between debug and release mode. |
| 1143 | ldr(ip, MemOperand(topaddr)); |
| 1144 | cmp(result, ip); |
| 1145 | Check(eq, "Unexpected allocation top"); |
| 1146 | } |
| 1147 | // Load allocation limit into ip. Result already contains allocation top. |
| 1148 | ldr(ip, MemOperand(topaddr, limit - top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | // Calculate new top and bail out if new space is exhausted. Use result |
| 1152 | // to calculate the new top. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1153 | add(scratch2, result, Operand(obj_size_reg), SetCC); |
| 1154 | b(cs, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1155 | cmp(scratch2, Operand(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1156 | b(hi, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1157 | str(scratch2, MemOperand(topaddr)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1158 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1159 | // Tag object if requested. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1160 | if ((flags & TAG_OBJECT) != 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1161 | add(result, result, Operand(kHeapObjectTag)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | |
| 1166 | void MacroAssembler::AllocateInNewSpace(Register object_size, |
| 1167 | Register result, |
| 1168 | Register scratch1, |
| 1169 | Register scratch2, |
| 1170 | Label* gc_required, |
| 1171 | AllocationFlags flags) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1172 | if (!FLAG_inline_new) { |
| 1173 | if (FLAG_debug_code) { |
| 1174 | // Trash the registers to simulate an allocation failure. |
| 1175 | mov(result, Operand(0x7091)); |
| 1176 | mov(scratch1, Operand(0x7191)); |
| 1177 | mov(scratch2, Operand(0x7291)); |
| 1178 | } |
| 1179 | jmp(gc_required); |
| 1180 | return; |
| 1181 | } |
| 1182 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1183 | // Assert that the register arguments are different and that none of |
| 1184 | // them are ip. ip is used explicitly in the code generated below. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1185 | ASSERT(!result.is(scratch1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1186 | ASSERT(!result.is(scratch2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1187 | ASSERT(!scratch1.is(scratch2)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1188 | ASSERT(!result.is(ip)); |
| 1189 | ASSERT(!scratch1.is(ip)); |
| 1190 | ASSERT(!scratch2.is(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1191 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1192 | // Check relative positions of allocation top and limit addresses. |
| 1193 | // The values must be adjacent in memory to allow the use of LDM. |
| 1194 | // Also, assert that the registers are numbered such that the values |
| 1195 | // are loaded in the correct order. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1196 | ExternalReference new_space_allocation_top = |
| 1197 | ExternalReference::new_space_allocation_top_address(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1198 | ExternalReference new_space_allocation_limit = |
| 1199 | ExternalReference::new_space_allocation_limit_address(); |
| 1200 | intptr_t top = |
| 1201 | reinterpret_cast<intptr_t>(new_space_allocation_top.address()); |
| 1202 | intptr_t limit = |
| 1203 | reinterpret_cast<intptr_t>(new_space_allocation_limit.address()); |
| 1204 | ASSERT((limit - top) == kPointerSize); |
| 1205 | ASSERT(result.code() < ip.code()); |
| 1206 | |
| 1207 | // Set up allocation top address. |
| 1208 | Register topaddr = scratch1; |
| 1209 | mov(topaddr, Operand(new_space_allocation_top)); |
| 1210 | |
| 1211 | // This code stores a temporary value in ip. This is OK, as the code below |
| 1212 | // does not need ip for implicit literal generation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1213 | if ((flags & RESULT_CONTAINS_TOP) == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1214 | // Load allocation top into result and allocation limit into ip. |
| 1215 | ldm(ia, topaddr, result.bit() | ip.bit()); |
| 1216 | } else { |
| 1217 | if (FLAG_debug_code) { |
| 1218 | // Assert that result actually contains top on entry. ip is used |
| 1219 | // immediately below so this use of ip does not cause difference with |
| 1220 | // respect to register content between debug and release mode. |
| 1221 | ldr(ip, MemOperand(topaddr)); |
| 1222 | cmp(result, ip); |
| 1223 | Check(eq, "Unexpected allocation top"); |
| 1224 | } |
| 1225 | // Load allocation limit into ip. Result already contains allocation top. |
| 1226 | ldr(ip, MemOperand(topaddr, limit - top)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | // Calculate new top and bail out if new space is exhausted. Use result |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1230 | // to calculate the new top. Object size may be in words so a shift is |
| 1231 | // required to get the number of bytes. |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1232 | if ((flags & SIZE_IN_WORDS) != 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1233 | add(scratch2, result, Operand(object_size, LSL, kPointerSizeLog2), SetCC); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1234 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1235 | add(scratch2, result, Operand(object_size), SetCC); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1236 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1237 | b(cs, gc_required); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1238 | cmp(scratch2, Operand(ip)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1239 | b(hi, gc_required); |
| 1240 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1241 | // Update allocation top. result temporarily holds the new top. |
| 1242 | if (FLAG_debug_code) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1243 | tst(scratch2, Operand(kObjectAlignmentMask)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1244 | Check(eq, "Unaligned allocation in new space"); |
| 1245 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1246 | str(scratch2, MemOperand(topaddr)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1247 | |
| 1248 | // Tag object if requested. |
| 1249 | if ((flags & TAG_OBJECT) != 0) { |
| 1250 | add(result, result, Operand(kHeapObjectTag)); |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | void MacroAssembler::UndoAllocationInNewSpace(Register object, |
| 1256 | Register scratch) { |
| 1257 | ExternalReference new_space_allocation_top = |
| 1258 | ExternalReference::new_space_allocation_top_address(); |
| 1259 | |
| 1260 | // Make sure the object has no tag before resetting top. |
| 1261 | and_(object, object, Operand(~kHeapObjectTagMask)); |
| 1262 | #ifdef DEBUG |
| 1263 | // Check that the object un-allocated is below the current top. |
| 1264 | mov(scratch, Operand(new_space_allocation_top)); |
| 1265 | ldr(scratch, MemOperand(scratch)); |
| 1266 | cmp(object, scratch); |
| 1267 | Check(lt, "Undo allocation of non allocated memory"); |
| 1268 | #endif |
| 1269 | // Write the address of the object to un-allocate as the current top. |
| 1270 | mov(scratch, Operand(new_space_allocation_top)); |
| 1271 | str(object, MemOperand(scratch)); |
| 1272 | } |
| 1273 | |
| 1274 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1275 | void MacroAssembler::AllocateTwoByteString(Register result, |
| 1276 | Register length, |
| 1277 | Register scratch1, |
| 1278 | Register scratch2, |
| 1279 | Register scratch3, |
| 1280 | Label* gc_required) { |
| 1281 | // Calculate the number of bytes needed for the characters in the string while |
| 1282 | // observing object alignment. |
| 1283 | ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1284 | mov(scratch1, Operand(length, LSL, 1)); // Length in bytes, not chars. |
| 1285 | add(scratch1, scratch1, |
| 1286 | Operand(kObjectAlignmentMask + SeqTwoByteString::kHeaderSize)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1287 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1288 | |
| 1289 | // Allocate two-byte string in new space. |
| 1290 | AllocateInNewSpace(scratch1, |
| 1291 | result, |
| 1292 | scratch2, |
| 1293 | scratch3, |
| 1294 | gc_required, |
| 1295 | TAG_OBJECT); |
| 1296 | |
| 1297 | // Set the map, length and hash field. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1298 | InitializeNewString(result, |
| 1299 | length, |
| 1300 | Heap::kStringMapRootIndex, |
| 1301 | scratch1, |
| 1302 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | void MacroAssembler::AllocateAsciiString(Register result, |
| 1307 | Register length, |
| 1308 | Register scratch1, |
| 1309 | Register scratch2, |
| 1310 | Register scratch3, |
| 1311 | Label* gc_required) { |
| 1312 | // Calculate the number of bytes needed for the characters in the string while |
| 1313 | // observing object alignment. |
| 1314 | ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 1315 | ASSERT(kCharSize == 1); |
| 1316 | add(scratch1, length, |
| 1317 | Operand(kObjectAlignmentMask + SeqAsciiString::kHeaderSize)); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1318 | and_(scratch1, scratch1, Operand(~kObjectAlignmentMask)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1319 | |
| 1320 | // Allocate ASCII string in new space. |
| 1321 | AllocateInNewSpace(scratch1, |
| 1322 | result, |
| 1323 | scratch2, |
| 1324 | scratch3, |
| 1325 | gc_required, |
| 1326 | TAG_OBJECT); |
| 1327 | |
| 1328 | // Set the map, length and hash field. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1329 | InitializeNewString(result, |
| 1330 | length, |
| 1331 | Heap::kAsciiStringMapRootIndex, |
| 1332 | scratch1, |
| 1333 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | |
| 1337 | void MacroAssembler::AllocateTwoByteConsString(Register result, |
| 1338 | Register length, |
| 1339 | Register scratch1, |
| 1340 | Register scratch2, |
| 1341 | Label* gc_required) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1342 | AllocateInNewSpace(ConsString::kSize, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1343 | result, |
| 1344 | scratch1, |
| 1345 | scratch2, |
| 1346 | gc_required, |
| 1347 | TAG_OBJECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1348 | |
| 1349 | InitializeNewString(result, |
| 1350 | length, |
| 1351 | Heap::kConsStringMapRootIndex, |
| 1352 | scratch1, |
| 1353 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | void MacroAssembler::AllocateAsciiConsString(Register result, |
| 1358 | Register length, |
| 1359 | Register scratch1, |
| 1360 | Register scratch2, |
| 1361 | Label* gc_required) { |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 1362 | AllocateInNewSpace(ConsString::kSize, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1363 | result, |
| 1364 | scratch1, |
| 1365 | scratch2, |
| 1366 | gc_required, |
| 1367 | TAG_OBJECT); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1368 | |
| 1369 | InitializeNewString(result, |
| 1370 | length, |
| 1371 | Heap::kConsAsciiStringMapRootIndex, |
| 1372 | scratch1, |
| 1373 | scratch2); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1377 | void MacroAssembler::CompareObjectType(Register object, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1378 | Register map, |
| 1379 | Register type_reg, |
| 1380 | InstanceType type) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1381 | ldr(map, FieldMemOperand(object, HeapObject::kMapOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1382 | CompareInstanceType(map, type_reg, type); |
| 1383 | } |
| 1384 | |
| 1385 | |
| 1386 | void MacroAssembler::CompareInstanceType(Register map, |
| 1387 | Register type_reg, |
| 1388 | InstanceType type) { |
| 1389 | ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 1390 | cmp(type_reg, Operand(type)); |
| 1391 | } |
| 1392 | |
| 1393 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1394 | void MacroAssembler::CheckMap(Register obj, |
| 1395 | Register scratch, |
| 1396 | Handle<Map> map, |
| 1397 | Label* fail, |
| 1398 | bool is_heap_object) { |
| 1399 | if (!is_heap_object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1400 | JumpIfSmi(obj, fail); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1401 | } |
| 1402 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1403 | mov(ip, Operand(map)); |
| 1404 | cmp(scratch, ip); |
| 1405 | b(ne, fail); |
| 1406 | } |
| 1407 | |
| 1408 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1409 | void MacroAssembler::CheckMap(Register obj, |
| 1410 | Register scratch, |
| 1411 | Heap::RootListIndex index, |
| 1412 | Label* fail, |
| 1413 | bool is_heap_object) { |
| 1414 | if (!is_heap_object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1415 | JumpIfSmi(obj, fail); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1416 | } |
| 1417 | ldr(scratch, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 1418 | LoadRoot(ip, index); |
| 1419 | cmp(scratch, ip); |
| 1420 | b(ne, fail); |
| 1421 | } |
| 1422 | |
| 1423 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1424 | void MacroAssembler::TryGetFunctionPrototype(Register function, |
| 1425 | Register result, |
| 1426 | Register scratch, |
| 1427 | Label* miss) { |
| 1428 | // Check that the receiver isn't a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1429 | JumpIfSmi(function, miss); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1430 | |
| 1431 | // Check that the function really is a function. Load map into result reg. |
| 1432 | CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE); |
| 1433 | b(ne, miss); |
| 1434 | |
| 1435 | // Make sure that the function has an instance prototype. |
| 1436 | Label non_instance; |
| 1437 | ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset)); |
| 1438 | tst(scratch, Operand(1 << Map::kHasNonInstancePrototype)); |
| 1439 | b(ne, &non_instance); |
| 1440 | |
| 1441 | // Get the prototype or initial map from the function. |
| 1442 | ldr(result, |
| 1443 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 1444 | |
| 1445 | // If the prototype or initial map is the hole, don't return it and |
| 1446 | // simply miss the cache instead. This will allow us to allocate a |
| 1447 | // prototype object on-demand in the runtime system. |
| 1448 | LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1449 | cmp(result, ip); |
| 1450 | b(eq, miss); |
| 1451 | |
| 1452 | // If the function does not have an initial map, we're done. |
| 1453 | Label done; |
| 1454 | CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 1455 | b(ne, &done); |
| 1456 | |
| 1457 | // Get the prototype from the initial map. |
| 1458 | ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 1459 | jmp(&done); |
| 1460 | |
| 1461 | // Non-instance prototype: Fetch prototype from constructor field |
| 1462 | // in initial map. |
| 1463 | bind(&non_instance); |
| 1464 | ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
| 1465 | |
| 1466 | // All done. |
| 1467 | bind(&done); |
| 1468 | } |
| 1469 | |
| 1470 | |
| 1471 | void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1472 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1473 | Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1474 | } |
| 1475 | |
| 1476 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1477 | void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1478 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1479 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1480 | } |
| 1481 | |
| 1482 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1483 | MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { |
| 1484 | ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1485 | Object* result; |
| 1486 | { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1487 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1488 | } |
| 1489 | Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1490 | return result; |
| 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 1495 | return ref0.address() - ref1.address(); |
| 1496 | } |
| 1497 | |
| 1498 | |
| 1499 | MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
| 1500 | ApiFunction* function, int stack_space) { |
| 1501 | ExternalReference next_address = |
| 1502 | ExternalReference::handle_scope_next_address(); |
| 1503 | const int kNextOffset = 0; |
| 1504 | const int kLimitOffset = AddressOffset( |
| 1505 | ExternalReference::handle_scope_limit_address(), |
| 1506 | next_address); |
| 1507 | const int kLevelOffset = AddressOffset( |
| 1508 | ExternalReference::handle_scope_level_address(), |
| 1509 | next_address); |
| 1510 | |
| 1511 | // Allocate HandleScope in callee-save registers. |
| 1512 | mov(r7, Operand(next_address)); |
| 1513 | ldr(r4, MemOperand(r7, kNextOffset)); |
| 1514 | ldr(r5, MemOperand(r7, kLimitOffset)); |
| 1515 | ldr(r6, MemOperand(r7, kLevelOffset)); |
| 1516 | add(r6, r6, Operand(1)); |
| 1517 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1518 | |
| 1519 | // Native call returns to the DirectCEntry stub which redirects to the |
| 1520 | // return address pushed on stack (could have moved after GC). |
| 1521 | // DirectCEntry stub itself is generated early and never moves. |
| 1522 | DirectCEntryStub stub; |
| 1523 | stub.GenerateCall(this, function); |
| 1524 | |
| 1525 | Label promote_scheduled_exception; |
| 1526 | Label delete_allocated_handles; |
| 1527 | Label leave_exit_frame; |
| 1528 | |
| 1529 | // If result is non-zero, dereference to get the result value |
| 1530 | // otherwise set it to undefined. |
| 1531 | cmp(r0, Operand(0)); |
| 1532 | LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1533 | ldr(r0, MemOperand(r0), ne); |
| 1534 | |
| 1535 | // No more valid handles (the result handle was the last one). Restore |
| 1536 | // previous handle scope. |
| 1537 | str(r4, MemOperand(r7, kNextOffset)); |
| 1538 | if (FLAG_debug_code) { |
| 1539 | ldr(r1, MemOperand(r7, kLevelOffset)); |
| 1540 | cmp(r1, r6); |
| 1541 | Check(eq, "Unexpected level after return from api call"); |
| 1542 | } |
| 1543 | sub(r6, r6, Operand(1)); |
| 1544 | str(r6, MemOperand(r7, kLevelOffset)); |
| 1545 | ldr(ip, MemOperand(r7, kLimitOffset)); |
| 1546 | cmp(r5, ip); |
| 1547 | b(ne, &delete_allocated_handles); |
| 1548 | |
| 1549 | // Check if the function scheduled an exception. |
| 1550 | bind(&leave_exit_frame); |
| 1551 | LoadRoot(r4, Heap::kTheHoleValueRootIndex); |
| 1552 | mov(ip, Operand(ExternalReference::scheduled_exception_address())); |
| 1553 | ldr(r5, MemOperand(ip)); |
| 1554 | cmp(r4, r5); |
| 1555 | b(ne, &promote_scheduled_exception); |
| 1556 | |
| 1557 | // LeaveExitFrame expects unwind space to be in r4. |
| 1558 | mov(r4, Operand(stack_space)); |
| 1559 | LeaveExitFrame(false); |
| 1560 | |
| 1561 | bind(&promote_scheduled_exception); |
| 1562 | MaybeObject* result = TryTailCallExternalReference( |
| 1563 | ExternalReference(Runtime::kPromoteScheduledException), 0, 1); |
| 1564 | if (result->IsFailure()) { |
| 1565 | return result; |
| 1566 | } |
| 1567 | |
| 1568 | // HandleScope limit has changed. Delete allocated extensions. |
| 1569 | bind(&delete_allocated_handles); |
| 1570 | str(r5, MemOperand(r7, kLimitOffset)); |
| 1571 | mov(r4, r0); |
| 1572 | PrepareCallCFunction(0, r5); |
| 1573 | CallCFunction(ExternalReference::delete_handle_scope_extensions(), 0); |
| 1574 | mov(r0, r4); |
| 1575 | jmp(&leave_exit_frame); |
| 1576 | |
| 1577 | return result; |
| 1578 | } |
| 1579 | |
| 1580 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1581 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1582 | if (num_arguments > 0) { |
| 1583 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1584 | } |
| 1585 | LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 1586 | } |
| 1587 | |
| 1588 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1589 | void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1590 | // If the hash field contains an array index pick it out. The assert checks |
| 1591 | // that the constants for the maximum number of digits for an array index |
| 1592 | // cached in the hash field and the number of bits reserved for it does not |
| 1593 | // conflict. |
| 1594 | ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
| 1595 | (1 << String::kArrayIndexValueBits)); |
| 1596 | // We want the smi-tagged index in key. kArrayIndexValueMask has zeros in |
| 1597 | // the low kHashShift bits. |
| 1598 | STATIC_ASSERT(kSmiTag == 0); |
| 1599 | Ubfx(hash, hash, String::kHashShift, String::kArrayIndexValueBits); |
| 1600 | mov(index, Operand(hash, LSL, kSmiTagSize)); |
| 1601 | } |
| 1602 | |
| 1603 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1604 | void MacroAssembler::IntegerToDoubleConversionWithVFP3(Register inReg, |
| 1605 | Register outHighReg, |
| 1606 | Register outLowReg) { |
| 1607 | // ARMv7 VFP3 instructions to implement integer to double conversion. |
| 1608 | mov(r7, Operand(inReg, ASR, kSmiTagSize)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1609 | vmov(s15, r7); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1610 | vcvt_f64_s32(d7, s15); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1611 | vmov(outLowReg, outHighReg, d7); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1615 | void MacroAssembler::ObjectToDoubleVFPRegister(Register object, |
| 1616 | DwVfpRegister result, |
| 1617 | Register scratch1, |
| 1618 | Register scratch2, |
| 1619 | Register heap_number_map, |
| 1620 | SwVfpRegister scratch3, |
| 1621 | Label* not_number, |
| 1622 | ObjectToDoubleFlags flags) { |
| 1623 | Label done; |
| 1624 | if ((flags & OBJECT_NOT_SMI) == 0) { |
| 1625 | Label not_smi; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1626 | JumpIfNotSmi(object, ¬_smi); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1627 | // Remove smi tag and convert to double. |
| 1628 | mov(scratch1, Operand(object, ASR, kSmiTagSize)); |
| 1629 | vmov(scratch3, scratch1); |
| 1630 | vcvt_f64_s32(result, scratch3); |
| 1631 | b(&done); |
| 1632 | bind(¬_smi); |
| 1633 | } |
| 1634 | // Check for heap number and load double value from it. |
| 1635 | ldr(scratch1, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 1636 | sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1637 | cmp(scratch1, heap_number_map); |
| 1638 | b(ne, not_number); |
| 1639 | if ((flags & AVOID_NANS_AND_INFINITIES) != 0) { |
| 1640 | // If exponent is all ones the number is either a NaN or +/-Infinity. |
| 1641 | ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 1642 | Sbfx(scratch1, |
| 1643 | scratch1, |
| 1644 | HeapNumber::kExponentShift, |
| 1645 | HeapNumber::kExponentBits); |
| 1646 | // All-one value sign extend to -1. |
| 1647 | cmp(scratch1, Operand(-1)); |
| 1648 | b(eq, not_number); |
| 1649 | } |
| 1650 | vldr(result, scratch2, HeapNumber::kValueOffset); |
| 1651 | bind(&done); |
| 1652 | } |
| 1653 | |
| 1654 | |
| 1655 | void MacroAssembler::SmiToDoubleVFPRegister(Register smi, |
| 1656 | DwVfpRegister value, |
| 1657 | Register scratch1, |
| 1658 | SwVfpRegister scratch2) { |
| 1659 | mov(scratch1, Operand(smi, ASR, kSmiTagSize)); |
| 1660 | vmov(scratch2, scratch1); |
| 1661 | vcvt_f64_s32(value, scratch2); |
| 1662 | } |
| 1663 | |
| 1664 | |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1665 | // Tries to get a signed int32 out of a double precision floating point heap |
| 1666 | // number. Rounds towards 0. Branch to 'not_int32' if the double is out of the |
| 1667 | // 32bits signed integer range. |
| 1668 | void MacroAssembler::ConvertToInt32(Register source, |
| 1669 | Register dest, |
| 1670 | Register scratch, |
| 1671 | Register scratch2, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1672 | DwVfpRegister double_scratch, |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1673 | Label *not_int32) { |
| 1674 | if (CpuFeatures::IsSupported(VFP3)) { |
| 1675 | CpuFeatures::Scope scope(VFP3); |
| 1676 | sub(scratch, source, Operand(kHeapObjectTag)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1677 | vldr(double_scratch, scratch, HeapNumber::kValueOffset); |
| 1678 | vcvt_s32_f64(double_scratch.low(), double_scratch); |
| 1679 | vmov(dest, double_scratch.low()); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1680 | // Signed vcvt instruction will saturate to the minimum (0x80000000) or |
| 1681 | // maximun (0x7fffffff) signed 32bits integer when the double is out of |
| 1682 | // range. When substracting one, the minimum signed integer becomes the |
| 1683 | // maximun signed integer. |
| 1684 | sub(scratch, dest, Operand(1)); |
| 1685 | cmp(scratch, Operand(LONG_MAX - 1)); |
| 1686 | // If equal then dest was LONG_MAX, if greater dest was LONG_MIN. |
| 1687 | b(ge, not_int32); |
| 1688 | } else { |
| 1689 | // This code is faster for doubles that are in the ranges -0x7fffffff to |
| 1690 | // -0x40000000 or 0x40000000 to 0x7fffffff. This corresponds almost to |
| 1691 | // the range of signed int32 values that are not Smis. Jumps to the label |
| 1692 | // 'not_int32' if the double isn't in the range -0x80000000.0 to |
| 1693 | // 0x80000000.0 (excluding the endpoints). |
| 1694 | Label right_exponent, done; |
| 1695 | // Get exponent word. |
| 1696 | ldr(scratch, FieldMemOperand(source, HeapNumber::kExponentOffset)); |
| 1697 | // Get exponent alone in scratch2. |
| 1698 | Ubfx(scratch2, |
| 1699 | scratch, |
| 1700 | HeapNumber::kExponentShift, |
| 1701 | HeapNumber::kExponentBits); |
| 1702 | // Load dest with zero. We use this either for the final shift or |
| 1703 | // for the answer. |
| 1704 | mov(dest, Operand(0, RelocInfo::NONE)); |
| 1705 | // Check whether the exponent matches a 32 bit signed int that is not a Smi. |
| 1706 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). This is |
| 1707 | // the exponent that we are fastest at and also the highest exponent we can |
| 1708 | // handle here. |
| 1709 | const uint32_t non_smi_exponent = HeapNumber::kExponentBias + 30; |
| 1710 | // The non_smi_exponent, 0x41d, is too big for ARM's immediate field so we |
| 1711 | // split it up to avoid a constant pool entry. You can't do that in general |
| 1712 | // for cmp because of the overflow flag, but we know the exponent is in the |
| 1713 | // range 0-2047 so there is no overflow. |
| 1714 | int fudge_factor = 0x400; |
| 1715 | sub(scratch2, scratch2, Operand(fudge_factor)); |
| 1716 | cmp(scratch2, Operand(non_smi_exponent - fudge_factor)); |
| 1717 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 1718 | // logic. |
| 1719 | b(eq, &right_exponent); |
| 1720 | // If the exponent is higher than that then go to slow case. This catches |
| 1721 | // numbers that don't fit in a signed int32, infinities and NaNs. |
| 1722 | b(gt, not_int32); |
| 1723 | |
| 1724 | // We know the exponent is smaller than 30 (biased). If it is less than |
| 1725 | // 0 (biased) then the number is smaller in magnitude than 1.0 * 2^0, ie |
| 1726 | // it rounds to zero. |
| 1727 | const uint32_t zero_exponent = HeapNumber::kExponentBias + 0; |
| 1728 | sub(scratch2, scratch2, Operand(zero_exponent - fudge_factor), SetCC); |
| 1729 | // Dest already has a Smi zero. |
| 1730 | b(lt, &done); |
| 1731 | |
| 1732 | // We have an exponent between 0 and 30 in scratch2. Subtract from 30 to |
| 1733 | // get how much to shift down. |
| 1734 | rsb(dest, scratch2, Operand(30)); |
| 1735 | |
| 1736 | bind(&right_exponent); |
| 1737 | // Get the top bits of the mantissa. |
| 1738 | and_(scratch2, scratch, Operand(HeapNumber::kMantissaMask)); |
| 1739 | // Put back the implicit 1. |
| 1740 | orr(scratch2, scratch2, Operand(1 << HeapNumber::kExponentShift)); |
| 1741 | // Shift up the mantissa bits to take up the space the exponent used to |
| 1742 | // take. We just orred in the implicit bit so that took care of one and |
| 1743 | // we want to leave the sign bit 0 so we subtract 2 bits from the shift |
| 1744 | // distance. |
| 1745 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 1746 | mov(scratch2, Operand(scratch2, LSL, shift_distance)); |
| 1747 | // Put sign in zero flag. |
| 1748 | tst(scratch, Operand(HeapNumber::kSignMask)); |
| 1749 | // Get the second half of the double. For some exponents we don't |
| 1750 | // actually need this because the bits get shifted out again, but |
| 1751 | // it's probably slower to test than just to do it. |
| 1752 | ldr(scratch, FieldMemOperand(source, HeapNumber::kMantissaOffset)); |
| 1753 | // Shift down 22 bits to get the last 10 bits. |
| 1754 | orr(scratch, scratch2, Operand(scratch, LSR, 32 - shift_distance)); |
| 1755 | // Move down according to the exponent. |
| 1756 | mov(dest, Operand(scratch, LSR, dest)); |
| 1757 | // Fix sign if sign bit was set. |
| 1758 | rsb(dest, dest, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
| 1759 | bind(&done); |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1764 | void MacroAssembler::GetLeastBitsFromSmi(Register dst, |
| 1765 | Register src, |
| 1766 | int num_least_bits) { |
| 1767 | if (CpuFeatures::IsSupported(ARMv7)) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1768 | ubfx(dst, src, kSmiTagSize, num_least_bits); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1769 | } else { |
| 1770 | mov(dst, Operand(src, ASR, kSmiTagSize)); |
| 1771 | and_(dst, dst, Operand((1 << num_least_bits) - 1)); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1776 | void MacroAssembler::GetLeastBitsFromInt32(Register dst, |
| 1777 | Register src, |
| 1778 | int num_least_bits) { |
| 1779 | and_(dst, src, Operand((1 << num_least_bits) - 1)); |
| 1780 | } |
| 1781 | |
| 1782 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1783 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
| 1784 | // All parameters are on the stack. r0 has the return value after call. |
| 1785 | |
| 1786 | // If the expected number of arguments of the runtime function is |
| 1787 | // constant, we check that the actual number of arguments match the |
| 1788 | // expectation. |
| 1789 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 1790 | IllegalOperation(num_arguments); |
| 1791 | return; |
| 1792 | } |
| 1793 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1794 | // TODO(1236192): Most runtime routines don't need the number of |
| 1795 | // arguments passed in because it is constant. At some point we |
| 1796 | // should remove this need and make the runtime routine entry code |
| 1797 | // smarter. |
| 1798 | mov(r0, Operand(num_arguments)); |
| 1799 | mov(r1, Operand(ExternalReference(f))); |
| 1800 | CEntryStub stub(1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1801 | CallStub(&stub); |
| 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 1806 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 1807 | } |
| 1808 | |
| 1809 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1810 | void MacroAssembler::CallRuntimeSaveDoubles(Runtime::FunctionId id) { |
| 1811 | Runtime::Function* function = Runtime::FunctionForId(id); |
| 1812 | mov(r0, Operand(function->nargs)); |
| 1813 | mov(r1, Operand(ExternalReference(function))); |
| 1814 | CEntryStub stub(1); |
| 1815 | stub.SaveDoubles(); |
| 1816 | CallStub(&stub); |
| 1817 | } |
| 1818 | |
| 1819 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1820 | void MacroAssembler::CallExternalReference(const ExternalReference& ext, |
| 1821 | int num_arguments) { |
| 1822 | mov(r0, Operand(num_arguments)); |
| 1823 | mov(r1, Operand(ext)); |
| 1824 | |
| 1825 | CEntryStub stub(1); |
| 1826 | CallStub(&stub); |
| 1827 | } |
| 1828 | |
| 1829 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1830 | void MacroAssembler::TailCallExternalReference(const ExternalReference& ext, |
| 1831 | int num_arguments, |
| 1832 | int result_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1833 | // TODO(1236192): Most runtime routines don't need the number of |
| 1834 | // arguments passed in because it is constant. At some point we |
| 1835 | // should remove this need and make the runtime routine entry code |
| 1836 | // smarter. |
| 1837 | mov(r0, Operand(num_arguments)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1838 | JumpToExternalReference(ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1842 | MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 1843 | const ExternalReference& ext, int num_arguments, int result_size) { |
| 1844 | // TODO(1236192): Most runtime routines don't need the number of |
| 1845 | // arguments passed in because it is constant. At some point we |
| 1846 | // should remove this need and make the runtime routine entry code |
| 1847 | // smarter. |
| 1848 | mov(r0, Operand(num_arguments)); |
| 1849 | return TryJumpToExternalReference(ext); |
| 1850 | } |
| 1851 | |
| 1852 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1853 | void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1854 | int num_arguments, |
| 1855 | int result_size) { |
| 1856 | TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1861 | #if defined(__thumb__) |
| 1862 | // Thumb mode builtin. |
| 1863 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1864 | #endif |
| 1865 | mov(r1, Operand(builtin)); |
| 1866 | CEntryStub stub(1); |
| 1867 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 1868 | } |
| 1869 | |
| 1870 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1871 | MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 1872 | const ExternalReference& builtin) { |
| 1873 | #if defined(__thumb__) |
| 1874 | // Thumb mode builtin. |
| 1875 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1876 | #endif |
| 1877 | mov(r1, Operand(builtin)); |
| 1878 | CEntryStub stub(1); |
| 1879 | return TryTailCallStub(&stub); |
| 1880 | } |
| 1881 | |
| 1882 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1883 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1884 | InvokeJSFlags flags, |
| 1885 | PostCallGenerator* post_call_generator) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1886 | GetBuiltinEntry(r2, id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1887 | if (flags == CALL_JS) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1888 | Call(r2); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1889 | if (post_call_generator != NULL) post_call_generator->Generate(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1890 | } else { |
| 1891 | ASSERT(flags == JUMP_JS); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1892 | Jump(r2); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 1897 | void MacroAssembler::GetBuiltinFunction(Register target, |
| 1898 | Builtins::JavaScript id) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1899 | // Load the builtins object into target register. |
| 1900 | ldr(target, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 1901 | ldr(target, FieldMemOperand(target, GlobalObject::kBuiltinsOffset)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1902 | // Load the JavaScript builtin function from the builtins object. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1903 | ldr(target, FieldMemOperand(target, |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 1904 | JSBuiltinsObject::OffsetOfFunctionWithId(id))); |
| 1905 | } |
| 1906 | |
| 1907 | |
| 1908 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 1909 | ASSERT(!target.is(r1)); |
| 1910 | GetBuiltinFunction(r1, id); |
| 1911 | // Load the code entry point from the builtins object. |
| 1912 | ldr(target, FieldMemOperand(r1, JSFunction::kCodeEntryOffset)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | |
| 1916 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 1917 | Register scratch1, Register scratch2) { |
| 1918 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1919 | mov(scratch1, Operand(value)); |
| 1920 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1921 | str(scratch1, MemOperand(scratch2)); |
| 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | |
| 1926 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 1927 | Register scratch1, Register scratch2) { |
| 1928 | ASSERT(value > 0); |
| 1929 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1930 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1931 | ldr(scratch1, MemOperand(scratch2)); |
| 1932 | add(scratch1, scratch1, Operand(value)); |
| 1933 | str(scratch1, MemOperand(scratch2)); |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | |
| 1938 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 1939 | Register scratch1, Register scratch2) { |
| 1940 | ASSERT(value > 0); |
| 1941 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 1942 | mov(scratch2, Operand(ExternalReference(counter))); |
| 1943 | ldr(scratch1, MemOperand(scratch2)); |
| 1944 | sub(scratch1, scratch1, Operand(value)); |
| 1945 | str(scratch1, MemOperand(scratch2)); |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1950 | void MacroAssembler::Assert(Condition cond, const char* msg) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1951 | if (FLAG_debug_code) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1952 | Check(cond, msg); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1956 | void MacroAssembler::AssertRegisterIsRoot(Register reg, |
| 1957 | Heap::RootListIndex index) { |
| 1958 | if (FLAG_debug_code) { |
| 1959 | LoadRoot(ip, index); |
| 1960 | cmp(reg, ip); |
| 1961 | Check(eq, "Register did not match expected root"); |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1966 | void MacroAssembler::AssertFastElements(Register elements) { |
| 1967 | if (FLAG_debug_code) { |
| 1968 | ASSERT(!elements.is(ip)); |
| 1969 | Label ok; |
| 1970 | push(elements); |
| 1971 | ldr(elements, FieldMemOperand(elements, HeapObject::kMapOffset)); |
| 1972 | LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 1973 | cmp(elements, ip); |
| 1974 | b(eq, &ok); |
| 1975 | LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 1976 | cmp(elements, ip); |
| 1977 | b(eq, &ok); |
| 1978 | Abort("JSObject with fast elements map has slow elements"); |
| 1979 | bind(&ok); |
| 1980 | pop(elements); |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1985 | void MacroAssembler::Check(Condition cond, const char* msg) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1986 | Label L; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1987 | b(cond, &L); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1988 | Abort(msg); |
| 1989 | // will not return here |
| 1990 | bind(&L); |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | void MacroAssembler::Abort(const char* msg) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1995 | Label abort_start; |
| 1996 | bind(&abort_start); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1997 | // We want to pass the msg string like a smi to avoid GC |
| 1998 | // problems, however msg is not guaranteed to be aligned |
| 1999 | // properly. Instead, we pass an aligned pointer that is |
| 2000 | // a proper v8 smi, but also pass the alignment difference |
| 2001 | // from the real pointer as a smi. |
| 2002 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 2003 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 2004 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 2005 | #ifdef DEBUG |
| 2006 | if (msg != NULL) { |
| 2007 | RecordComment("Abort message: "); |
| 2008 | RecordComment(msg); |
| 2009 | } |
| 2010 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2011 | // Disable stub call restrictions to always allow calls to abort. |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 2012 | AllowStubCallsScope allow_scope(this, true); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2013 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2014 | mov(r0, Operand(p0)); |
| 2015 | push(r0); |
| 2016 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
| 2017 | push(r0); |
| 2018 | CallRuntime(Runtime::kAbort, 2); |
| 2019 | // will not return here |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2020 | if (is_const_pool_blocked()) { |
| 2021 | // If the calling code cares about the exact number of |
| 2022 | // instructions generated, we insert padding here to keep the size |
| 2023 | // of the Abort macro constant. |
| 2024 | static const int kExpectedAbortInstructions = 10; |
| 2025 | int abort_instructions = InstructionsGeneratedSince(&abort_start); |
| 2026 | ASSERT(abort_instructions <= kExpectedAbortInstructions); |
| 2027 | while (abort_instructions++ < kExpectedAbortInstructions) { |
| 2028 | nop(); |
| 2029 | } |
| 2030 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2034 | void MacroAssembler::LoadContext(Register dst, int context_chain_length) { |
| 2035 | if (context_chain_length > 0) { |
| 2036 | // Move up the chain of contexts to the context containing the slot. |
| 2037 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2038 | // Load the function context (which is the incoming, outer context). |
| 2039 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 2040 | for (int i = 1; i < context_chain_length; i++) { |
| 2041 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX))); |
| 2042 | ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset)); |
| 2043 | } |
| 2044 | // The context may be an intermediate context, not a function context. |
| 2045 | ldr(dst, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2046 | } else { // Slot is in the current function context. |
| 2047 | // The context may be an intermediate context, not a function context. |
| 2048 | ldr(dst, MemOperand(cp, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2053 | void MacroAssembler::LoadGlobalFunction(int index, Register function) { |
| 2054 | // Load the global or builtins object from the current context. |
| 2055 | ldr(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 2056 | // Load the global context from the global or builtins object. |
| 2057 | ldr(function, FieldMemOperand(function, |
| 2058 | GlobalObject::kGlobalContextOffset)); |
| 2059 | // Load the function from the global context. |
| 2060 | ldr(function, MemOperand(function, Context::SlotOffset(index))); |
| 2061 | } |
| 2062 | |
| 2063 | |
| 2064 | void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, |
| 2065 | Register map, |
| 2066 | Register scratch) { |
| 2067 | // Load the initial map. The global functions all have initial maps. |
| 2068 | ldr(map, FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2069 | if (FLAG_debug_code) { |
| 2070 | Label ok, fail; |
| 2071 | CheckMap(map, scratch, Heap::kMetaMapRootIndex, &fail, false); |
| 2072 | b(&ok); |
| 2073 | bind(&fail); |
| 2074 | Abort("Global functions must have initial map"); |
| 2075 | bind(&ok); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2080 | void MacroAssembler::JumpIfNotPowerOfTwoOrZero( |
| 2081 | Register reg, |
| 2082 | Register scratch, |
| 2083 | Label* not_power_of_two_or_zero) { |
| 2084 | sub(scratch, reg, Operand(1), SetCC); |
| 2085 | b(mi, not_power_of_two_or_zero); |
| 2086 | tst(scratch, reg); |
| 2087 | b(ne, not_power_of_two_or_zero); |
| 2088 | } |
| 2089 | |
| 2090 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2091 | void MacroAssembler::JumpIfNotBothSmi(Register reg1, |
| 2092 | Register reg2, |
| 2093 | Label* on_not_both_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2094 | STATIC_ASSERT(kSmiTag == 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2095 | tst(reg1, Operand(kSmiTagMask)); |
| 2096 | tst(reg2, Operand(kSmiTagMask), eq); |
| 2097 | b(ne, on_not_both_smi); |
| 2098 | } |
| 2099 | |
| 2100 | |
| 2101 | void MacroAssembler::JumpIfEitherSmi(Register reg1, |
| 2102 | Register reg2, |
| 2103 | Label* on_either_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2104 | STATIC_ASSERT(kSmiTag == 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2105 | tst(reg1, Operand(kSmiTagMask)); |
| 2106 | tst(reg2, Operand(kSmiTagMask), ne); |
| 2107 | b(eq, on_either_smi); |
| 2108 | } |
| 2109 | |
| 2110 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2111 | void MacroAssembler::AbortIfSmi(Register object) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2112 | STATIC_ASSERT(kSmiTag == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2113 | tst(object, Operand(kSmiTagMask)); |
| 2114 | Assert(ne, "Operand is a smi"); |
| 2115 | } |
| 2116 | |
| 2117 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2118 | void MacroAssembler::AbortIfNotSmi(Register object) { |
| 2119 | STATIC_ASSERT(kSmiTag == 0); |
| 2120 | tst(object, Operand(kSmiTagMask)); |
| 2121 | Assert(eq, "Operand is not smi"); |
| 2122 | } |
| 2123 | |
| 2124 | |
| 2125 | void MacroAssembler::AbortIfNotRootValue(Register src, |
| 2126 | Heap::RootListIndex root_value_index, |
| 2127 | const char* message) { |
| 2128 | ASSERT(!src.is(ip)); |
| 2129 | LoadRoot(ip, root_value_index); |
| 2130 | cmp(src, ip); |
| 2131 | Assert(eq, message); |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | void MacroAssembler::JumpIfNotHeapNumber(Register object, |
| 2136 | Register heap_number_map, |
| 2137 | Register scratch, |
| 2138 | Label* on_not_heap_number) { |
| 2139 | ldr(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2140 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2141 | cmp(scratch, heap_number_map); |
| 2142 | b(ne, on_not_heap_number); |
| 2143 | } |
| 2144 | |
| 2145 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2146 | void MacroAssembler::JumpIfNonSmisNotBothSequentialAsciiStrings( |
| 2147 | Register first, |
| 2148 | Register second, |
| 2149 | Register scratch1, |
| 2150 | Register scratch2, |
| 2151 | Label* failure) { |
| 2152 | // Test that both first and second are sequential ASCII strings. |
| 2153 | // Assume that they are non-smis. |
| 2154 | ldr(scratch1, FieldMemOperand(first, HeapObject::kMapOffset)); |
| 2155 | ldr(scratch2, FieldMemOperand(second, HeapObject::kMapOffset)); |
| 2156 | ldrb(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset)); |
| 2157 | ldrb(scratch2, FieldMemOperand(scratch2, Map::kInstanceTypeOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2158 | |
| 2159 | JumpIfBothInstanceTypesAreNotSequentialAscii(scratch1, |
| 2160 | scratch2, |
| 2161 | scratch1, |
| 2162 | scratch2, |
| 2163 | failure); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first, |
| 2167 | Register second, |
| 2168 | Register scratch1, |
| 2169 | Register scratch2, |
| 2170 | Label* failure) { |
| 2171 | // Check that neither is a smi. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2172 | STATIC_ASSERT(kSmiTag == 0); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2173 | and_(scratch1, first, Operand(second)); |
| 2174 | tst(scratch1, Operand(kSmiTagMask)); |
| 2175 | b(eq, failure); |
| 2176 | JumpIfNonSmisNotBothSequentialAsciiStrings(first, |
| 2177 | second, |
| 2178 | scratch1, |
| 2179 | scratch2, |
| 2180 | failure); |
| 2181 | } |
| 2182 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2183 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2184 | // Allocates a heap number or jumps to the need_gc label if the young space |
| 2185 | // is full and a scavenge is needed. |
| 2186 | void MacroAssembler::AllocateHeapNumber(Register result, |
| 2187 | Register scratch1, |
| 2188 | Register scratch2, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2189 | Register heap_number_map, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2190 | Label* gc_required) { |
| 2191 | // Allocate an object in the heap for the heap number and tag it as a heap |
| 2192 | // object. |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2193 | AllocateInNewSpace(HeapNumber::kSize, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2194 | result, |
| 2195 | scratch1, |
| 2196 | scratch2, |
| 2197 | gc_required, |
| 2198 | TAG_OBJECT); |
| 2199 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2200 | // Store heap number map in the allocated object. |
| 2201 | AssertRegisterIsRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2202 | str(heap_number_map, FieldMemOperand(result, HeapObject::kMapOffset)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2206 | void MacroAssembler::AllocateHeapNumberWithValue(Register result, |
| 2207 | DwVfpRegister value, |
| 2208 | Register scratch1, |
| 2209 | Register scratch2, |
| 2210 | Register heap_number_map, |
| 2211 | Label* gc_required) { |
| 2212 | AllocateHeapNumber(result, scratch1, scratch2, heap_number_map, gc_required); |
| 2213 | sub(scratch1, result, Operand(kHeapObjectTag)); |
| 2214 | vstr(value, scratch1, HeapNumber::kValueOffset); |
| 2215 | } |
| 2216 | |
| 2217 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2218 | // Copies a fixed number of fields of heap objects from src to dst. |
| 2219 | void MacroAssembler::CopyFields(Register dst, |
| 2220 | Register src, |
| 2221 | RegList temps, |
| 2222 | int field_count) { |
| 2223 | // At least one bit set in the first 15 registers. |
| 2224 | ASSERT((temps & ((1 << 15) - 1)) != 0); |
| 2225 | ASSERT((temps & dst.bit()) == 0); |
| 2226 | ASSERT((temps & src.bit()) == 0); |
| 2227 | // Primitive implementation using only one temporary register. |
| 2228 | |
| 2229 | Register tmp = no_reg; |
| 2230 | // Find a temp register in temps list. |
| 2231 | for (int i = 0; i < 15; i++) { |
| 2232 | if ((temps & (1 << i)) != 0) { |
| 2233 | tmp.set_code(i); |
| 2234 | break; |
| 2235 | } |
| 2236 | } |
| 2237 | ASSERT(!tmp.is(no_reg)); |
| 2238 | |
| 2239 | for (int i = 0; i < field_count; i++) { |
| 2240 | ldr(tmp, FieldMemOperand(src, i * kPointerSize)); |
| 2241 | str(tmp, FieldMemOperand(dst, i * kPointerSize)); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2246 | void MacroAssembler::CountLeadingZeros(Register zeros, // Answer. |
| 2247 | Register source, // Input. |
| 2248 | Register scratch) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2249 | ASSERT(!zeros.is(source) || !source.is(scratch)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2250 | ASSERT(!zeros.is(scratch)); |
| 2251 | ASSERT(!scratch.is(ip)); |
| 2252 | ASSERT(!source.is(ip)); |
| 2253 | ASSERT(!zeros.is(ip)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2254 | #ifdef CAN_USE_ARMV5_INSTRUCTIONS |
| 2255 | clz(zeros, source); // This instruction is only supported after ARM5. |
| 2256 | #else |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 2257 | mov(zeros, Operand(0, RelocInfo::NONE)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2258 | Move(scratch, source); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2259 | // Top 16. |
| 2260 | tst(scratch, Operand(0xffff0000)); |
| 2261 | add(zeros, zeros, Operand(16), LeaveCC, eq); |
| 2262 | mov(scratch, Operand(scratch, LSL, 16), LeaveCC, eq); |
| 2263 | // Top 8. |
| 2264 | tst(scratch, Operand(0xff000000)); |
| 2265 | add(zeros, zeros, Operand(8), LeaveCC, eq); |
| 2266 | mov(scratch, Operand(scratch, LSL, 8), LeaveCC, eq); |
| 2267 | // Top 4. |
| 2268 | tst(scratch, Operand(0xf0000000)); |
| 2269 | add(zeros, zeros, Operand(4), LeaveCC, eq); |
| 2270 | mov(scratch, Operand(scratch, LSL, 4), LeaveCC, eq); |
| 2271 | // Top 2. |
| 2272 | tst(scratch, Operand(0xc0000000)); |
| 2273 | add(zeros, zeros, Operand(2), LeaveCC, eq); |
| 2274 | mov(scratch, Operand(scratch, LSL, 2), LeaveCC, eq); |
| 2275 | // Top bit. |
| 2276 | tst(scratch, Operand(0x80000000u)); |
| 2277 | add(zeros, zeros, Operand(1), LeaveCC, eq); |
| 2278 | #endif |
| 2279 | } |
| 2280 | |
| 2281 | |
| 2282 | void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 2283 | Register first, |
| 2284 | Register second, |
| 2285 | Register scratch1, |
| 2286 | Register scratch2, |
| 2287 | Label* failure) { |
| 2288 | int kFlatAsciiStringMask = |
| 2289 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2290 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2291 | and_(scratch1, first, Operand(kFlatAsciiStringMask)); |
| 2292 | and_(scratch2, second, Operand(kFlatAsciiStringMask)); |
| 2293 | cmp(scratch1, Operand(kFlatAsciiStringTag)); |
| 2294 | // Ignore second test if first test failed. |
| 2295 | cmp(scratch2, Operand(kFlatAsciiStringTag), eq); |
| 2296 | b(ne, failure); |
| 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii(Register type, |
| 2301 | Register scratch, |
| 2302 | Label* failure) { |
| 2303 | int kFlatAsciiStringMask = |
| 2304 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask; |
| 2305 | int kFlatAsciiStringTag = ASCII_STRING_TYPE; |
| 2306 | and_(scratch, type, Operand(kFlatAsciiStringMask)); |
| 2307 | cmp(scratch, Operand(kFlatAsciiStringTag)); |
| 2308 | b(ne, failure); |
| 2309 | } |
| 2310 | |
| 2311 | |
| 2312 | void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) { |
| 2313 | int frame_alignment = ActivationFrameAlignment(); |
| 2314 | // Up to four simple arguments are passed in registers r0..r3. |
| 2315 | int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4; |
| 2316 | if (frame_alignment > kPointerSize) { |
| 2317 | // Make stack end at alignment and make room for num_arguments - 4 words |
| 2318 | // and the original value of sp. |
| 2319 | mov(scratch, sp); |
| 2320 | sub(sp, sp, Operand((stack_passed_arguments + 1) * kPointerSize)); |
| 2321 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2322 | and_(sp, sp, Operand(-frame_alignment)); |
| 2323 | str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 2324 | } else { |
| 2325 | sub(sp, sp, Operand(stack_passed_arguments * kPointerSize)); |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | |
| 2330 | void MacroAssembler::CallCFunction(ExternalReference function, |
| 2331 | int num_arguments) { |
| 2332 | mov(ip, Operand(function)); |
| 2333 | CallCFunction(ip, num_arguments); |
| 2334 | } |
| 2335 | |
| 2336 | |
| 2337 | void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
| 2338 | // Make sure that the stack is aligned before calling a C function unless |
| 2339 | // running in the simulator. The simulator has its own alignment check which |
| 2340 | // provides more information. |
| 2341 | #if defined(V8_HOST_ARCH_ARM) |
| 2342 | if (FLAG_debug_code) { |
| 2343 | int frame_alignment = OS::ActivationFrameAlignment(); |
| 2344 | int frame_alignment_mask = frame_alignment - 1; |
| 2345 | if (frame_alignment > kPointerSize) { |
| 2346 | ASSERT(IsPowerOf2(frame_alignment)); |
| 2347 | Label alignment_as_expected; |
| 2348 | tst(sp, Operand(frame_alignment_mask)); |
| 2349 | b(eq, &alignment_as_expected); |
| 2350 | // Don't use Check here, as it will call Runtime_Abort possibly |
| 2351 | // re-entering here. |
| 2352 | stop("Unexpected alignment"); |
| 2353 | bind(&alignment_as_expected); |
| 2354 | } |
| 2355 | } |
| 2356 | #endif |
| 2357 | |
| 2358 | // Just call directly. The function called cannot cause a GC, or |
| 2359 | // allow preemption, so the return address in the link register |
| 2360 | // stays correct. |
| 2361 | Call(function); |
| 2362 | int stack_passed_arguments = (num_arguments <= 4) ? 0 : num_arguments - 4; |
| 2363 | if (OS::ActivationFrameAlignment() > kPointerSize) { |
| 2364 | ldr(sp, MemOperand(sp, stack_passed_arguments * kPointerSize)); |
| 2365 | } else { |
| 2366 | add(sp, sp, Operand(stack_passed_arguments * sizeof(kPointerSize))); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2371 | void MacroAssembler::GetRelocatedValueLocation(Register ldr_location, |
| 2372 | Register result) { |
| 2373 | const uint32_t kLdrOffsetMask = (1 << 12) - 1; |
| 2374 | const int32_t kPCRegOffset = 2 * kPointerSize; |
| 2375 | ldr(result, MemOperand(ldr_location)); |
| 2376 | if (FLAG_debug_code) { |
| 2377 | // Check that the instruction is a ldr reg, [pc + offset] . |
| 2378 | and_(result, result, Operand(kLdrPCPattern)); |
| 2379 | cmp(result, Operand(kLdrPCPattern)); |
| 2380 | Check(eq, "The instruction to patch should be a load from pc."); |
| 2381 | // Result was clobbered. Restore it. |
| 2382 | ldr(result, MemOperand(ldr_location)); |
| 2383 | } |
| 2384 | // Get the address of the constant. |
| 2385 | and_(result, result, Operand(kLdrOffsetMask)); |
| 2386 | add(result, ldr_location, Operand(result)); |
| 2387 | add(result, result, Operand(kPCRegOffset)); |
| 2388 | } |
| 2389 | |
| 2390 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2391 | CodePatcher::CodePatcher(byte* address, int instructions) |
| 2392 | : address_(address), |
| 2393 | instructions_(instructions), |
| 2394 | size_(instructions * Assembler::kInstrSize), |
| 2395 | masm_(address, size_ + Assembler::kGap) { |
| 2396 | // Create a new macro assembler pointing to the address of the code to patch. |
| 2397 | // The size is adjusted with kGap on order for the assembler to generate size |
| 2398 | // bytes of instructions without failing with buffer size constraints. |
| 2399 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2400 | } |
| 2401 | |
| 2402 | |
| 2403 | CodePatcher::~CodePatcher() { |
| 2404 | // Indicate that code has changed. |
| 2405 | CPU::FlushICache(address_, size_); |
| 2406 | |
| 2407 | // Check that the code was patched as expected. |
| 2408 | ASSERT(masm_.pc_ == address_ + size_); |
| 2409 | ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2410 | } |
| 2411 | |
| 2412 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2413 | void CodePatcher::Emit(Instr instr) { |
| 2414 | masm()->emit(instr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | |
| 2418 | void CodePatcher::Emit(Address addr) { |
| 2419 | masm()->emit(reinterpret_cast<Instr>(addr)); |
| 2420 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 2421 | |
| 2422 | |
| 2423 | void CodePatcher::EmitCondition(Condition cond) { |
| 2424 | Instr instr = Assembler::instr_at(masm_.pc_); |
| 2425 | instr = (instr & ~kCondMask) | cond; |
| 2426 | masm_.emit(instr); |
| 2427 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2428 | |
| 2429 | |
| 2430 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2431 | |
| 2432 | #endif // V8_TARGET_ARCH_ARM |