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