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