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