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