ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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 | |
| 35 | namespace v8 { namespace internal { |
| 36 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | // Give alias names to registers |
| 38 | Register cp = { 8 }; // JavaScript context pointer |
| 39 | Register pp = { 10 }; // parameter pointer |
| 40 | |
| 41 | |
| 42 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 43 | : Assembler(buffer, size), |
| 44 | unresolved_(0), |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 45 | generating_stub_(false), |
| 46 | allow_stub_calls_(true) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | |
| 50 | // We always generate arm code, never thumb code, even if V8 is compiled to |
| 51 | // thumb, so we require inter-working support |
| 52 | #if defined(__thumb__) && !defined(__THUMB_INTERWORK__) |
| 53 | #error "flag -mthumb-interwork missing" |
| 54 | #endif |
| 55 | |
| 56 | |
| 57 | // We do not support thumb inter-working with an arm architecture not supporting |
| 58 | // the blx instruction (below v5t) |
| 59 | #if defined(__THUMB_INTERWORK__) |
| 60 | #if !defined(__ARM_ARCH_5T__) && !defined(__ARM_ARCH_5TE__) |
| 61 | // add tests for other versions above v5t as required |
| 62 | #error "for thumb inter-working we require architecture v5t or above" |
| 63 | #endif |
| 64 | #endif |
| 65 | |
| 66 | |
| 67 | // Using blx may yield better code, so use it when required or when available |
| 68 | #if defined(__THUMB_INTERWORK__) || defined(__ARM_ARCH_5__) |
| 69 | #define USE_BLX 1 |
| 70 | #endif |
| 71 | |
| 72 | // Using bx does not yield better code, so use it only when required |
| 73 | #if defined(__THUMB_INTERWORK__) |
| 74 | #define USE_BX 1 |
| 75 | #endif |
| 76 | |
| 77 | |
| 78 | void MacroAssembler::Jump(Register target, Condition cond) { |
| 79 | #if USE_BX |
| 80 | bx(target, cond); |
| 81 | #else |
| 82 | mov(pc, Operand(target), LeaveCC, cond); |
| 83 | #endif |
| 84 | } |
| 85 | |
| 86 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 87 | void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode, |
| 88 | Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | #if USE_BX |
| 90 | mov(ip, Operand(target, rmode), LeaveCC, cond); |
| 91 | bx(ip, cond); |
| 92 | #else |
| 93 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 98 | void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode, |
| 99 | Condition cond) { |
| 100 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | Jump(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 102 | } |
| 103 | |
| 104 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 105 | void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode, |
| 106 | Condition cond) { |
| 107 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | // 'code' is always generated ARM code, never THUMB code |
| 109 | Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | void MacroAssembler::Call(Register target, Condition cond) { |
| 114 | #if USE_BLX |
| 115 | blx(target, cond); |
| 116 | #else |
| 117 | // set lr for return at current pc + 8 |
| 118 | mov(lr, Operand(pc), LeaveCC, cond); |
| 119 | mov(pc, Operand(target), LeaveCC, cond); |
| 120 | #endif |
| 121 | } |
| 122 | |
| 123 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 124 | void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode, |
| 125 | Condition cond) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | #if !defined(__arm__) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 127 | if (rmode == RelocInfo::RUNTIME_ENTRY) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | mov(r2, Operand(target, rmode), LeaveCC, cond); |
| 129 | // Set lr for return at current pc + 8. |
| 130 | mov(lr, Operand(pc), LeaveCC, cond); |
| 131 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 132 | // Notify the simulator of the transition to C code. |
| 133 | swi(assembler::arm::call_rt_r2); |
| 134 | } else { |
| 135 | // set lr for return at current pc + 8 |
| 136 | mov(lr, Operand(pc), LeaveCC, cond); |
| 137 | // emit a ldr<cond> pc, [pc + offset of target in constant pool] |
| 138 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 139 | } |
| 140 | #else |
| 141 | // Set lr for return at current pc + 8. |
| 142 | mov(lr, Operand(pc), LeaveCC, cond); |
| 143 | // Emit a ldr<cond> pc, [pc + offset of target in constant pool]. |
| 144 | mov(pc, Operand(target, rmode), LeaveCC, cond); |
| 145 | #endif // !defined(__arm__) |
| 146 | // If USE_BLX is defined, we could emit a 'mov ip, target', followed by a |
| 147 | // 'blx ip'; however, the code would not be shorter than the above sequence |
| 148 | // and the target address of the call would be referenced by the first |
| 149 | // instruction rather than the second one, which would make it harder to patch |
| 150 | // (two instructions before the return address, instead of one). |
| 151 | ASSERT(kTargetAddrToReturnAddrDist == sizeof(Instr)); |
| 152 | } |
| 153 | |
| 154 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 155 | void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode, |
| 156 | Condition cond) { |
| 157 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 158 | Call(reinterpret_cast<intptr_t>(target), rmode, cond); |
| 159 | } |
| 160 | |
| 161 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 162 | void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode, |
| 163 | Condition cond) { |
| 164 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 165 | // 'code' is always generated ARM code, never THUMB code |
| 166 | Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | void MacroAssembler::Ret() { |
| 171 | #if USE_BX |
| 172 | bx(lr); |
| 173 | #else |
| 174 | mov(pc, Operand(lr)); |
| 175 | #endif |
| 176 | } |
| 177 | |
| 178 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 179 | // Will clobber 4 registers: object, offset, scratch, ip. The |
| 180 | // register 'object' contains a heap object pointer. The heap object |
| 181 | // tag is shifted away. |
| 182 | void MacroAssembler::RecordWrite(Register object, Register offset, |
| 183 | Register scratch) { |
| 184 | // This is how much we shift the remembered set bit offset to get the |
| 185 | // offset of the word in the remembered set. We divide by kBitsPerInt (32, |
| 186 | // shift right 5) and then multiply by kIntSize (4, shift left 2). |
| 187 | const int kRSetWordShift = 3; |
| 188 | |
| 189 | Label fast, done; |
| 190 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 191 | // First, test that the object is not in the new space. We cannot set |
| 192 | // remembered set bits in the new space. |
| 193 | // object: heap object pointer (with tag) |
| 194 | // offset: offset to store location from the object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 195 | and_(scratch, object, Operand(Heap::NewSpaceMask())); |
| 196 | cmp(scratch, Operand(ExternalReference::new_space_start())); |
| 197 | b(eq, &done); |
| 198 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | // Compute the bit offset in the remembered set. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 200 | // object: heap object pointer (with tag) |
| 201 | // offset: offset to store location from the object |
| 202 | mov(ip, Operand(Page::kPageAlignmentMask)); // load mask only once |
| 203 | and_(scratch, object, Operand(ip)); // offset into page of the object |
| 204 | add(offset, scratch, Operand(offset)); // add offset into the object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 205 | mov(offset, Operand(offset, LSR, kObjectAlignmentBits)); |
| 206 | |
| 207 | // Compute the page address from the heap object pointer. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 208 | // object: heap object pointer (with tag) |
| 209 | // offset: bit offset of store position in the remembered set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | bic(object, object, Operand(ip)); |
| 211 | |
| 212 | // If the bit offset lies beyond the normal remembered set range, it is in |
| 213 | // the extra remembered set area of a large object. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 214 | // object: page start |
| 215 | // offset: bit offset of store position in the remembered set |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 216 | cmp(offset, Operand(Page::kPageSize / kPointerSize)); |
| 217 | b(lt, &fast); |
| 218 | |
| 219 | // Adjust the bit offset to be relative to the start of the extra |
| 220 | // remembered set and the start address to be the address of the extra |
| 221 | // remembered set. |
| 222 | sub(offset, offset, Operand(Page::kPageSize / kPointerSize)); |
| 223 | // Load the array length into 'scratch' and multiply by four to get the |
| 224 | // size in bytes of the elements. |
| 225 | ldr(scratch, MemOperand(object, Page::kObjectStartOffset |
| 226 | + FixedArray::kLengthOffset)); |
| 227 | mov(scratch, Operand(scratch, LSL, kObjectAlignmentBits)); |
| 228 | // Add the page header (including remembered set), array header, and array |
| 229 | // body size to the page address. |
| 230 | add(object, object, Operand(Page::kObjectStartOffset |
| 231 | + Array::kHeaderSize)); |
| 232 | add(object, object, Operand(scratch)); |
| 233 | |
| 234 | bind(&fast); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | // Get address of the rset word. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 236 | // object: start of the remembered set (page start for the fast case) |
| 237 | // offset: bit offset of store position in the remembered set |
| 238 | bic(scratch, offset, Operand(kBitsPerInt - 1)); // clear the bit offset |
| 239 | add(object, object, Operand(scratch, LSR, kRSetWordShift)); |
| 240 | // Get bit offset in the rset word. |
| 241 | // object: address of remembered set word |
| 242 | // offset: bit offset of store position |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 243 | and_(offset, offset, Operand(kBitsPerInt - 1)); |
| 244 | |
| 245 | ldr(scratch, MemOperand(object)); |
| 246 | mov(ip, Operand(1)); |
| 247 | orr(scratch, scratch, Operand(ip, LSL, offset)); |
| 248 | str(scratch, MemOperand(object)); |
| 249 | |
| 250 | bind(&done); |
| 251 | } |
| 252 | |
| 253 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 254 | void MacroAssembler::EnterFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 255 | // r0-r3: preserved |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 256 | stm(db_w, sp, cp.bit() | fp.bit() | lr.bit()); |
| 257 | mov(ip, Operand(Smi::FromInt(type))); |
| 258 | push(ip); |
| 259 | mov(ip, Operand(0)); |
| 260 | push(ip); // Push an empty code cache slot. |
| 261 | 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] | 262 | } |
| 263 | |
| 264 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 265 | void MacroAssembler::LeaveFrame(StackFrame::Type type) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 266 | // r0: preserved |
| 267 | // r1: preserved |
| 268 | // r2: preserved |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 269 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 270 | // Drop the execution stack down to the frame pointer and restore |
| 271 | // the caller frame pointer and return address. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 272 | mov(sp, fp); |
| 273 | ldm(ia_w, sp, fp.bit() | lr.bit()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 277 | void MacroAssembler::EnterExitFrame(StackFrame::Type type) { |
| 278 | ASSERT(type == StackFrame::EXIT || type == StackFrame::EXIT_DEBUG); |
| 279 | // Compute parameter pointer before making changes and save it as ip |
| 280 | // register so that it is restored as sp register on exit, thereby |
| 281 | // popping the args. |
| 282 | |
| 283 | // ip = sp + kPointerSize * #args; |
| 284 | add(ip, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 285 | |
| 286 | // Push in reverse order: caller_fp, sp_on_exit, and caller_pc. |
| 287 | stm(db_w, sp, fp.bit() | ip.bit() | lr.bit()); |
| 288 | mov(fp, Operand(sp)); // setup new frame pointer |
| 289 | |
| 290 | // Push debug marker. |
| 291 | mov(ip, Operand(type == StackFrame::EXIT_DEBUG ? 1 : 0)); |
| 292 | push(ip); |
| 293 | |
| 294 | // Save the frame pointer and the context in top. |
| 295 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 296 | str(fp, MemOperand(ip)); |
| 297 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 298 | str(cp, MemOperand(ip)); |
| 299 | |
| 300 | // Setup argc and the builtin function in callee-saved registers. |
| 301 | mov(r4, Operand(r0)); |
| 302 | mov(r5, Operand(r1)); |
| 303 | |
| 304 | // Compute the argv pointer and keep it in a callee-saved register. |
| 305 | add(r6, fp, Operand(r4, LSL, kPointerSizeLog2)); |
| 306 | add(r6, r6, Operand(ExitFrameConstants::kPPDisplacement - kPointerSize)); |
| 307 | |
| 308 | // Save the state of all registers to the stack from the memory |
| 309 | // location. This is needed to allow nested break points. |
| 310 | if (type == StackFrame::EXIT_DEBUG) { |
| 311 | // Use sp as base to push. |
| 312 | CopyRegistersFromMemoryToStack(sp, kJSCallerSaved); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | void MacroAssembler::LeaveExitFrame(StackFrame::Type type) { |
| 318 | // Restore the memory copy of the registers by digging them out from |
| 319 | // the stack. This is needed to allow nested break points. |
| 320 | if (type == StackFrame::EXIT_DEBUG) { |
| 321 | // This code intentionally clobbers r2 and r3. |
| 322 | const int kCallerSavedSize = kNumJSCallerSaved * kPointerSize; |
| 323 | const int kOffset = ExitFrameConstants::kDebugMarkOffset - kCallerSavedSize; |
| 324 | add(r3, fp, Operand(kOffset)); |
| 325 | CopyRegistersFromStackToMemory(r3, r2, kJSCallerSaved); |
| 326 | } |
| 327 | |
| 328 | // Clear top frame. |
| 329 | mov(r3, Operand(0)); |
| 330 | mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 331 | str(r3, MemOperand(ip)); |
| 332 | |
| 333 | // Restore current context from top and clear it in debug mode. |
| 334 | mov(ip, Operand(ExternalReference(Top::k_context_address))); |
| 335 | ldr(cp, MemOperand(ip)); |
| 336 | if (kDebug) { |
| 337 | str(r3, MemOperand(ip)); |
| 338 | } |
| 339 | |
| 340 | // Pop the arguments, restore registers, and return. |
| 341 | mov(sp, Operand(fp)); // respect ABI stack constraint |
| 342 | ldm(ia, sp, fp.bit() | sp.bit() | pc.bit()); |
| 343 | } |
| 344 | |
| 345 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 346 | void MacroAssembler::InvokePrologue(const ParameterCount& expected, |
| 347 | const ParameterCount& actual, |
| 348 | Handle<Code> code_constant, |
| 349 | Register code_reg, |
| 350 | Label* done, |
| 351 | InvokeFlag flag) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 352 | bool definitely_matches = false; |
| 353 | Label regular_invoke; |
| 354 | |
| 355 | // Check whether the expected and actual arguments count match. If not, |
| 356 | // setup registers according to contract with ArgumentsAdaptorTrampoline: |
| 357 | // r0: actual arguments count |
| 358 | // r1: function (passed through to callee) |
| 359 | // r2: expected arguments count |
| 360 | // r3: callee code entry |
| 361 | |
| 362 | // The code below is made a lot easier because the calling code already sets |
| 363 | // up actual and expected registers according to the contract if values are |
| 364 | // passed in registers. |
| 365 | ASSERT(actual.is_immediate() || actual.reg().is(r0)); |
| 366 | ASSERT(expected.is_immediate() || expected.reg().is(r2)); |
| 367 | ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3)); |
| 368 | |
| 369 | if (expected.is_immediate()) { |
| 370 | ASSERT(actual.is_immediate()); |
| 371 | if (expected.immediate() == actual.immediate()) { |
| 372 | definitely_matches = true; |
| 373 | } else { |
| 374 | mov(r0, Operand(actual.immediate())); |
| 375 | const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 376 | if (expected.immediate() == sentinel) { |
| 377 | // Don't worry about adapting arguments for builtins that |
| 378 | // don't want that done. Skip adaption code by making it look |
| 379 | // like we have a match between expected and actual number of |
| 380 | // arguments. |
| 381 | definitely_matches = true; |
| 382 | } else { |
| 383 | mov(r2, Operand(expected.immediate())); |
| 384 | } |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 385 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 386 | } else { |
| 387 | if (actual.is_immediate()) { |
| 388 | cmp(expected.reg(), Operand(actual.immediate())); |
| 389 | b(eq, ®ular_invoke); |
| 390 | mov(r0, Operand(actual.immediate())); |
| 391 | } else { |
| 392 | cmp(expected.reg(), Operand(actual.reg())); |
| 393 | b(eq, ®ular_invoke); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | if (!definitely_matches) { |
| 398 | if (!code_constant.is_null()) { |
| 399 | mov(r3, Operand(code_constant)); |
| 400 | add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 401 | } |
| 402 | |
| 403 | Handle<Code> adaptor = |
| 404 | Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)); |
| 405 | if (flag == CALL_FUNCTION) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 406 | Call(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 407 | b(done); |
| 408 | } else { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 409 | Jump(adaptor, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 410 | } |
| 411 | bind(®ular_invoke); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
| 415 | |
| 416 | void MacroAssembler::InvokeCode(Register code, |
| 417 | const ParameterCount& expected, |
| 418 | const ParameterCount& actual, |
| 419 | InvokeFlag flag) { |
| 420 | Label done; |
| 421 | |
| 422 | InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag); |
| 423 | if (flag == CALL_FUNCTION) { |
| 424 | Call(code); |
| 425 | } else { |
| 426 | ASSERT(flag == JUMP_FUNCTION); |
| 427 | Jump(code); |
| 428 | } |
| 429 | |
| 430 | // Continue here if InvokePrologue does handle the invocation due to |
| 431 | // mismatched parameter counts. |
| 432 | bind(&done); |
| 433 | } |
| 434 | |
| 435 | |
| 436 | void MacroAssembler::InvokeCode(Handle<Code> code, |
| 437 | const ParameterCount& expected, |
| 438 | const ParameterCount& actual, |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 439 | RelocInfo::Mode rmode, |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 440 | InvokeFlag flag) { |
| 441 | Label done; |
| 442 | |
| 443 | InvokePrologue(expected, actual, code, no_reg, &done, flag); |
| 444 | if (flag == CALL_FUNCTION) { |
| 445 | Call(code, rmode); |
| 446 | } else { |
| 447 | Jump(code, rmode); |
| 448 | } |
| 449 | |
| 450 | // Continue here if InvokePrologue does handle the invocation due to |
| 451 | // mismatched parameter counts. |
| 452 | bind(&done); |
| 453 | } |
| 454 | |
| 455 | |
| 456 | void MacroAssembler::InvokeFunction(Register fun, |
| 457 | const ParameterCount& actual, |
| 458 | InvokeFlag flag) { |
| 459 | // Contract with called JS functions requires that function is passed in r1. |
| 460 | ASSERT(fun.is(r1)); |
| 461 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 462 | Register expected_reg = r2; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 463 | Register code_reg = r3; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 464 | |
| 465 | ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); |
| 466 | ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset)); |
| 467 | ldr(expected_reg, |
| 468 | FieldMemOperand(code_reg, |
| 469 | SharedFunctionInfo::kFormalParameterCountOffset)); |
| 470 | ldr(code_reg, |
| 471 | MemOperand(code_reg, SharedFunctionInfo::kCodeOffset - kHeapObjectTag)); |
| 472 | add(code_reg, code_reg, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 473 | |
| 474 | ParameterCount expected(expected_reg); |
| 475 | InvokeCode(code_reg, expected, actual, flag); |
| 476 | } |
| 477 | |
| 478 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | void MacroAssembler::SaveRegistersToMemory(RegList regs) { |
| 480 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 481 | // Copy the content of registers to memory location. |
| 482 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 483 | int r = JSCallerSavedCode(i); |
| 484 | if ((regs & (1 << r)) != 0) { |
| 485 | Register reg = { r }; |
| 486 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 487 | str(reg, MemOperand(ip)); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | |
| 493 | void MacroAssembler::RestoreRegistersFromMemory(RegList regs) { |
| 494 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 495 | // Copy the content of memory location to registers. |
| 496 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 497 | int r = JSCallerSavedCode(i); |
| 498 | if ((regs & (1 << r)) != 0) { |
| 499 | Register reg = { r }; |
| 500 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 501 | ldr(reg, MemOperand(ip)); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | |
| 507 | void MacroAssembler::CopyRegistersFromMemoryToStack(Register base, |
| 508 | RegList regs) { |
| 509 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 510 | // Copy the content of the memory location to the stack and adjust base. |
| 511 | for (int i = kNumJSCallerSaved; --i >= 0;) { |
| 512 | int r = JSCallerSavedCode(i); |
| 513 | if ((regs & (1 << r)) != 0) { |
| 514 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 515 | ldr(ip, MemOperand(ip)); |
| 516 | str(ip, MemOperand(base, 4, NegPreIndex)); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | |
| 522 | void MacroAssembler::CopyRegistersFromStackToMemory(Register base, |
| 523 | Register scratch, |
| 524 | RegList regs) { |
| 525 | ASSERT((regs & ~kJSCallerSaved) == 0); |
| 526 | // Copy the content of the stack to the memory location and adjust base. |
| 527 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 528 | int r = JSCallerSavedCode(i); |
| 529 | if ((regs & (1 << r)) != 0) { |
| 530 | mov(ip, Operand(ExternalReference(Debug_Address::Register(i)))); |
| 531 | ldr(scratch, MemOperand(base, 4, PostIndex)); |
| 532 | str(scratch, MemOperand(ip)); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 539 | HandlerType type) { |
| 540 | ASSERT(StackHandlerConstants::kSize == 6 * kPointerSize); // adjust this code |
| 541 | // The pc (return address) is passed in register lr. |
| 542 | if (try_location == IN_JAVASCRIPT) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 543 | stm(db_w, sp, pp.bit() | fp.bit() | lr.bit()); |
| 544 | if (type == TRY_CATCH_HANDLER) { |
| 545 | mov(r3, Operand(StackHandler::TRY_CATCH)); |
| 546 | } else { |
| 547 | mov(r3, Operand(StackHandler::TRY_FINALLY)); |
| 548 | } |
| 549 | push(r3); // state |
| 550 | mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 551 | ldr(r1, MemOperand(r3)); |
| 552 | push(r1); // next sp |
| 553 | str(sp, MemOperand(r3)); // chain handler |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 554 | mov(r0, Operand(Smi::FromInt(StackHandler::kCodeNotPresent))); // new TOS |
| 555 | push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 556 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 557 | // Must preserve r0-r4, r5-r7 are available. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 558 | ASSERT(try_location == IN_JS_ENTRY); |
| 559 | // The parameter pointer is meaningless here and fp does not point to a JS |
| 560 | // frame. So we save NULL for both pp and fp. We expect the code throwing an |
| 561 | // exception to check fp before dereferencing it to restore the context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | mov(pp, Operand(0)); // set pp to NULL |
| 563 | mov(ip, Operand(0)); // to save a NULL fp |
| 564 | stm(db_w, sp, pp.bit() | ip.bit() | lr.bit()); |
| 565 | mov(r6, Operand(StackHandler::ENTRY)); |
| 566 | push(r6); // state |
| 567 | mov(r7, Operand(ExternalReference(Top::k_handler_address))); |
| 568 | ldr(r6, MemOperand(r7)); |
| 569 | push(r6); // next sp |
| 570 | str(sp, MemOperand(r7)); // chain handler |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 571 | mov(r5, Operand(Smi::FromInt(StackHandler::kCodeNotPresent))); // new TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 572 | push(r5); // flush TOS |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | |
| 577 | Register MacroAssembler::CheckMaps(JSObject* object, Register object_reg, |
| 578 | JSObject* holder, Register holder_reg, |
| 579 | Register scratch, |
| 580 | Label* miss) { |
| 581 | // Make sure there's no overlap between scratch and the other |
| 582 | // registers. |
| 583 | ASSERT(!scratch.is(object_reg) && !scratch.is(holder_reg)); |
| 584 | |
| 585 | // Keep track of the current object in register reg. |
| 586 | Register reg = object_reg; |
| 587 | int depth = 1; |
| 588 | |
| 589 | // Check the maps in the prototype chain. |
| 590 | // Traverse the prototype chain from the object and do map checks. |
| 591 | while (object != holder) { |
| 592 | depth++; |
| 593 | |
| 594 | // Only global objects and objects that do not require access |
| 595 | // checks are allowed in stubs. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 596 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 597 | |
| 598 | // Get the map of the current object. |
| 599 | ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 600 | cmp(scratch, Operand(Handle<Map>(object->map()))); |
| 601 | |
| 602 | // Branch on the result of the map check. |
| 603 | b(ne, miss); |
| 604 | |
| 605 | // Check access rights to the global object. This has to happen |
| 606 | // after the map check so that we know that the object is |
| 607 | // actually a global object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 608 | if (object->IsJSGlobalProxy()) { |
| 609 | CheckAccessGlobalProxy(reg, scratch, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 610 | // Restore scratch register to be the map of the object. In the |
| 611 | // new space case below, we load the prototype from the map in |
| 612 | // the scratch register. |
| 613 | ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 614 | } |
| 615 | |
| 616 | reg = holder_reg; // from now the object is in holder_reg |
| 617 | JSObject* prototype = JSObject::cast(object->GetPrototype()); |
| 618 | if (Heap::InNewSpace(prototype)) { |
| 619 | // The prototype is in new space; we cannot store a reference |
| 620 | // to it in the code. Load it from the map. |
| 621 | ldr(reg, FieldMemOperand(scratch, Map::kPrototypeOffset)); |
| 622 | } else { |
| 623 | // The prototype is in old space; load it directly. |
| 624 | mov(reg, Operand(Handle<JSObject>(prototype))); |
| 625 | } |
| 626 | |
| 627 | // Go to the next object in the prototype chain. |
| 628 | object = prototype; |
| 629 | } |
| 630 | |
| 631 | // Check the holder map. |
| 632 | ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 633 | cmp(scratch, Operand(Handle<Map>(object->map()))); |
| 634 | b(ne, miss); |
| 635 | |
| 636 | // Log the check depth. |
| 637 | LOG(IntEvent("check-maps-depth", depth)); |
| 638 | |
| 639 | // Perform security check for access to the global object and return |
| 640 | // the holder register. |
| 641 | ASSERT(object == holder); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 642 | ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded()); |
| 643 | if (object->IsJSGlobalProxy()) { |
| 644 | CheckAccessGlobalProxy(reg, scratch, miss); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 645 | } |
| 646 | return reg; |
| 647 | } |
| 648 | |
| 649 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 650 | void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg, |
| 651 | Register scratch, |
| 652 | Label* miss) { |
| 653 | Label same_contexts; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 654 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 655 | ASSERT(!holder_reg.is(scratch)); |
| 656 | ASSERT(!holder_reg.is(ip)); |
| 657 | ASSERT(!scratch.is(ip)); |
| 658 | |
| 659 | // Load current lexical context from the stack frame. |
| 660 | ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 661 | // In debug mode, make sure the lexical context is set. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 662 | if (kDebug) { |
| 663 | cmp(scratch, Operand(0)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 664 | Check(ne, "we should not have an empty lexical context"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | } |
| 666 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 667 | // Load the global context of the current context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 668 | int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 669 | ldr(scratch, FieldMemOperand(scratch, offset)); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 670 | ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); |
| 671 | |
| 672 | // Check the context is a global context. |
| 673 | if (FLAG_debug_code) { |
| 674 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 675 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 676 | // that ip is clobbered as part of cmp with an object Operand. |
| 677 | push(holder_reg); // Temporarily save holder on the stack. |
| 678 | // Read the first word and compare to the global_context_map. |
| 679 | ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 680 | cmp(holder_reg, Operand(Factory::global_context_map())); |
| 681 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 682 | pop(holder_reg); // Restore holder. |
| 683 | } |
| 684 | |
| 685 | // Check if both contexts are the same. |
| 686 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 687 | cmp(scratch, Operand(ip)); |
| 688 | b(eq, &same_contexts); |
| 689 | |
| 690 | // Check the context is a global context. |
| 691 | if (FLAG_debug_code) { |
| 692 | // TODO(119): avoid push(holder_reg)/pop(holder_reg) |
| 693 | // Cannot use ip as a temporary in this verification code. Due to the fact |
| 694 | // that ip is clobbered as part of cmp with an object Operand. |
| 695 | push(holder_reg); // Temporarily save holder on the stack. |
| 696 | mov(holder_reg, ip); // Move ip to its holding place. |
| 697 | cmp(holder_reg, Operand(Factory::null_value())); |
| 698 | Check(ne, "JSGlobalProxy::context() should not be null."); |
| 699 | |
| 700 | ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset)); |
| 701 | cmp(holder_reg, Operand(Factory::global_context_map())); |
| 702 | Check(eq, "JSGlobalObject::global_context should be a global context."); |
| 703 | // Restore ip is not needed. ip is reloaded below. |
| 704 | pop(holder_reg); // Restore holder. |
| 705 | // Restore ip to holder's context. |
| 706 | ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset)); |
| 707 | } |
| 708 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 709 | // Check that the security token in the calling global object is |
| 710 | // compatible with the security token in the receiving global |
| 711 | // object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 712 | int token_offset = Context::kHeaderSize + |
| 713 | Context::SECURITY_TOKEN_INDEX * kPointerSize; |
| 714 | |
| 715 | ldr(scratch, FieldMemOperand(scratch, token_offset)); |
| 716 | ldr(ip, FieldMemOperand(ip, token_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 717 | cmp(scratch, Operand(ip)); |
| 718 | b(ne, miss); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 719 | |
| 720 | bind(&same_contexts); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | |
| 724 | void MacroAssembler::CallStub(CodeStub* stub) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 725 | ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 726 | Call(stub->GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | void MacroAssembler::StubReturn(int argc) { |
| 731 | ASSERT(argc >= 1 && generating_stub()); |
| 732 | if (argc > 1) |
| 733 | add(sp, sp, Operand((argc - 1) * kPointerSize)); |
| 734 | Ret(); |
| 735 | } |
| 736 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 737 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 738 | void MacroAssembler::IllegalOperation(int num_arguments) { |
| 739 | if (num_arguments > 0) { |
| 740 | add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 741 | } |
| 742 | mov(r0, Operand(Factory::undefined_value())); |
| 743 | } |
| 744 | |
| 745 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 746 | void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 747 | // 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] | 748 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 749 | // If the expected number of arguments of the runtime function is |
| 750 | // constant, we check that the actual number of arguments match the |
| 751 | // expectation. |
| 752 | if (f->nargs >= 0 && f->nargs != num_arguments) { |
| 753 | IllegalOperation(num_arguments); |
| 754 | return; |
| 755 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 756 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 757 | Runtime::FunctionId function_id = |
| 758 | static_cast<Runtime::FunctionId>(f->stub_id); |
| 759 | RuntimeStub stub(function_id, num_arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 760 | CallStub(&stub); |
| 761 | } |
| 762 | |
| 763 | |
| 764 | void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) { |
| 765 | CallRuntime(Runtime::FunctionForId(fid), num_arguments); |
| 766 | } |
| 767 | |
| 768 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 769 | void MacroAssembler::TailCallRuntime(const ExternalReference& ext, |
| 770 | int num_arguments) { |
| 771 | // TODO(1236192): Most runtime routines don't need the number of |
| 772 | // arguments passed in because it is constant. At some point we |
| 773 | // should remove this need and make the runtime routine entry code |
| 774 | // smarter. |
| 775 | mov(r0, Operand(num_arguments)); |
| 776 | JumpToBuiltin(ext); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | |
| 780 | void MacroAssembler::JumpToBuiltin(const ExternalReference& builtin) { |
| 781 | #if defined(__thumb__) |
| 782 | // Thumb mode builtin. |
| 783 | ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 784 | #endif |
| 785 | mov(r1, Operand(builtin)); |
| 786 | CEntryStub stub; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 787 | Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 791 | Handle<Code> MacroAssembler::ResolveBuiltin(Builtins::JavaScript id, |
| 792 | bool* resolved) { |
| 793 | // Contract with compiled functions is that the function is passed in r1. |
| 794 | int builtins_offset = |
| 795 | JSBuiltinsObject::kJSBuiltinsOffset + (id * kPointerSize); |
| 796 | ldr(r1, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 797 | ldr(r1, FieldMemOperand(r1, GlobalObject::kBuiltinsOffset)); |
| 798 | ldr(r1, FieldMemOperand(r1, builtins_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 799 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 800 | return Builtins::GetCode(id, resolved); |
| 801 | } |
| 802 | |
| 803 | |
| 804 | void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 805 | InvokeJSFlags flags) { |
| 806 | bool resolved; |
| 807 | Handle<Code> code = ResolveBuiltin(id, &resolved); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | |
| 809 | if (flags == CALL_JS) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 810 | Call(code, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 811 | } else { |
| 812 | ASSERT(flags == JUMP_JS); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 813 | Jump(code, RelocInfo::CODE_TARGET); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 814 | } |
| 815 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 816 | if (!resolved) { |
| 817 | const char* name = Builtins::GetName(id); |
| 818 | int argc = Builtins::GetArgumentsCount(id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 819 | uint32_t flags = |
| 820 | Bootstrapper::FixupFlagsArgumentsCount::encode(argc) | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 821 | Bootstrapper::FixupFlagsIsPCRelative::encode(true) | |
| 822 | Bootstrapper::FixupFlagsUseCodeObject::encode(false); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 823 | Unresolved entry = { pc_offset() - sizeof(Instr), flags, name }; |
| 824 | unresolved_.Add(entry); |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | |
| 829 | void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) { |
| 830 | bool resolved; |
| 831 | Handle<Code> code = ResolveBuiltin(id, &resolved); |
| 832 | |
| 833 | mov(target, Operand(code)); |
| 834 | if (!resolved) { |
| 835 | const char* name = Builtins::GetName(id); |
| 836 | int argc = Builtins::GetArgumentsCount(id); |
| 837 | uint32_t flags = |
| 838 | Bootstrapper::FixupFlagsArgumentsCount::encode(argc) | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 839 | Bootstrapper::FixupFlagsIsPCRelative::encode(true) | |
| 840 | Bootstrapper::FixupFlagsUseCodeObject::encode(true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 841 | Unresolved entry = { pc_offset() - sizeof(Instr), flags, name }; |
| 842 | unresolved_.Add(entry); |
| 843 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 844 | |
| 845 | add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame^] | 849 | void MacroAssembler::SetCounter(StatsCounter* counter, int value, |
| 850 | Register scratch1, Register scratch2) { |
| 851 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 852 | mov(scratch1, Operand(value)); |
| 853 | mov(scratch2, Operand(ExternalReference(counter))); |
| 854 | str(scratch1, MemOperand(scratch2)); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | |
| 859 | void MacroAssembler::IncrementCounter(StatsCounter* counter, int value, |
| 860 | Register scratch1, Register scratch2) { |
| 861 | ASSERT(value > 0); |
| 862 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 863 | mov(scratch2, Operand(ExternalReference(counter))); |
| 864 | ldr(scratch1, MemOperand(scratch2)); |
| 865 | add(scratch1, scratch1, Operand(value)); |
| 866 | str(scratch1, MemOperand(scratch2)); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | |
| 871 | void MacroAssembler::DecrementCounter(StatsCounter* counter, int value, |
| 872 | Register scratch1, Register scratch2) { |
| 873 | ASSERT(value > 0); |
| 874 | if (FLAG_native_code_counters && counter->Enabled()) { |
| 875 | mov(scratch2, Operand(ExternalReference(counter))); |
| 876 | ldr(scratch1, MemOperand(scratch2)); |
| 877 | sub(scratch1, scratch1, Operand(value)); |
| 878 | str(scratch1, MemOperand(scratch2)); |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 883 | void MacroAssembler::Assert(Condition cc, const char* msg) { |
| 884 | if (FLAG_debug_code) |
| 885 | Check(cc, msg); |
| 886 | } |
| 887 | |
| 888 | |
| 889 | void MacroAssembler::Check(Condition cc, const char* msg) { |
| 890 | Label L; |
| 891 | b(cc, &L); |
| 892 | Abort(msg); |
| 893 | // will not return here |
| 894 | bind(&L); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | void MacroAssembler::Abort(const char* msg) { |
| 899 | // We want to pass the msg string like a smi to avoid GC |
| 900 | // problems, however msg is not guaranteed to be aligned |
| 901 | // properly. Instead, we pass an aligned pointer that is |
| 902 | // a proper v8 smi, but also pass the aligment difference |
| 903 | // from the real pointer as a smi. |
| 904 | intptr_t p1 = reinterpret_cast<intptr_t>(msg); |
| 905 | intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag; |
| 906 | ASSERT(reinterpret_cast<Object*>(p0)->IsSmi()); |
| 907 | #ifdef DEBUG |
| 908 | if (msg != NULL) { |
| 909 | RecordComment("Abort message: "); |
| 910 | RecordComment(msg); |
| 911 | } |
| 912 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | mov(r0, Operand(p0)); |
| 914 | push(r0); |
| 915 | mov(r0, Operand(Smi::FromInt(p1 - p0))); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 916 | push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 917 | CallRuntime(Runtime::kAbort, 2); |
| 918 | // will not return here |
| 919 | } |
| 920 | |
| 921 | } } // namespace v8::internal |