2009-06-09 09:26:53 +00:00
|
|
|
// Copyright 2006-2009 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "bootstrapper.h"
|
|
|
|
#include "codegen-inl.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "runtime.h"
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
MacroAssembler::MacroAssembler(void* buffer, int size)
|
|
|
|
: Assembler(buffer, size),
|
|
|
|
unresolved_(0),
|
2008-07-30 08:49:36 +00:00
|
|
|
generating_stub_(false),
|
2009-02-25 16:52:15 +00:00
|
|
|
allow_stub_calls_(true),
|
|
|
|
code_object_(Heap::undefined_value()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We always generate arm code, never thumb code, even if V8 is compiled to
|
|
|
|
// thumb, so we require inter-working support
|
2009-06-30 13:38:40 +00:00
|
|
|
#if defined(__thumb__) && !defined(USE_THUMB_INTERWORK)
|
2008-07-03 15:10:15 +00:00
|
|
|
#error "flag -mthumb-interwork missing"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// We do not support thumb inter-working with an arm architecture not supporting
|
|
|
|
// the blx instruction (below v5t)
|
2009-06-30 13:38:40 +00:00
|
|
|
#if defined(USE_THUMB_INTERWORK)
|
2009-05-19 20:12:50 +00:00
|
|
|
#if !defined(__ARM_ARCH_5T__) && \
|
|
|
|
!defined(__ARM_ARCH_5TE__) && \
|
|
|
|
!defined(__ARM_ARCH_7A__) && \
|
|
|
|
!defined(__ARM_ARCH_7__)
|
2008-07-03 15:10:15 +00:00
|
|
|
// add tests for other versions above v5t as required
|
|
|
|
#error "for thumb inter-working we require architecture v5t or above"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Using blx may yield better code, so use it when required or when available
|
2009-06-30 13:38:40 +00:00
|
|
|
#if defined(USE_THUMB_INTERWORK) || defined(__ARM_ARCH_5__)
|
2008-07-03 15:10:15 +00:00
|
|
|
#define USE_BLX 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Using bx does not yield better code, so use it only when required
|
2009-06-30 13:38:40 +00:00
|
|
|
#if defined(USE_THUMB_INTERWORK)
|
2008-07-03 15:10:15 +00:00
|
|
|
#define USE_BX 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Jump(Register target, Condition cond) {
|
|
|
|
#if USE_BX
|
|
|
|
bx(target, cond);
|
|
|
|
#else
|
|
|
|
mov(pc, Operand(target), LeaveCC, cond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Jump(intptr_t target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
2008-07-03 15:10:15 +00:00
|
|
|
#if USE_BX
|
|
|
|
mov(ip, Operand(target, rmode), LeaveCC, cond);
|
|
|
|
bx(ip, cond);
|
|
|
|
#else
|
|
|
|
mov(pc, Operand(target, rmode), LeaveCC, cond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Jump(byte* target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(!RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
Jump(reinterpret_cast<intptr_t>(target), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
// 'code' is always generated ARM code, never THUMB code
|
|
|
|
Jump(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Call(Register target, Condition cond) {
|
|
|
|
#if USE_BLX
|
|
|
|
blx(target, cond);
|
|
|
|
#else
|
|
|
|
// set lr for return at current pc + 8
|
|
|
|
mov(lr, Operand(pc), LeaveCC, cond);
|
|
|
|
mov(pc, Operand(target), LeaveCC, cond);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Call(intptr_t target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
2008-07-03 15:10:15 +00:00
|
|
|
// Set lr for return at current pc + 8.
|
|
|
|
mov(lr, Operand(pc), LeaveCC, cond);
|
|
|
|
// Emit a ldr<cond> pc, [pc + offset of target in constant pool].
|
|
|
|
mov(pc, Operand(target, rmode), LeaveCC, cond);
|
|
|
|
// If USE_BLX is defined, we could emit a 'mov ip, target', followed by a
|
|
|
|
// 'blx ip'; however, the code would not be shorter than the above sequence
|
|
|
|
// and the target address of the call would be referenced by the first
|
|
|
|
// instruction rather than the second one, which would make it harder to patch
|
|
|
|
// (two instructions before the return address, instead of one).
|
2009-08-19 10:18:30 +00:00
|
|
|
ASSERT(kPatchReturnSequenceLength == sizeof(Instr));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Call(byte* target, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(!RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
Call(reinterpret_cast<intptr_t>(target), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
void MacroAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
|
|
|
|
Condition cond) {
|
|
|
|
ASSERT(RelocInfo::IsCodeTarget(rmode));
|
2008-07-03 15:10:15 +00:00
|
|
|
// 'code' is always generated ARM code, never THUMB code
|
|
|
|
Call(reinterpret_cast<intptr_t>(code.location()), rmode, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:30:23 +00:00
|
|
|
void MacroAssembler::Ret(Condition cond) {
|
2008-07-03 15:10:15 +00:00
|
|
|
#if USE_BX
|
2009-04-16 09:30:23 +00:00
|
|
|
bx(lr, cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
#else
|
2009-04-16 09:30:23 +00:00
|
|
|
mov(pc, Operand(lr), LeaveCC, cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 08:37:58 +00:00
|
|
|
void MacroAssembler::SmiJumpTable(Register index, Vector<Label*> targets) {
|
|
|
|
// Empty the const pool.
|
|
|
|
CheckConstPool(true, true);
|
|
|
|
add(pc, pc, Operand(index,
|
|
|
|
LSL,
|
|
|
|
assembler::arm::Instr::kInstrSizeLog2 - kSmiTagSize));
|
|
|
|
BlockConstPoolBefore(pc_offset() + (targets.length() + 1) * sizeof(Instr));
|
|
|
|
nop(); // Jump table alignment.
|
|
|
|
for (int i = 0; i < targets.length(); i++) {
|
|
|
|
b(targets[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-24 11:57:57 +00:00
|
|
|
void MacroAssembler::LoadRoot(Register destination,
|
|
|
|
Heap::RootListIndex index,
|
|
|
|
Condition cond) {
|
|
|
|
ldr(destination, MemOperand(r10, index << kPointerSizeLog2), cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Will clobber 4 registers: object, offset, scratch, ip. The
|
|
|
|
// register 'object' contains a heap object pointer. The heap object
|
|
|
|
// tag is shifted away.
|
|
|
|
void MacroAssembler::RecordWrite(Register object, Register offset,
|
|
|
|
Register scratch) {
|
|
|
|
// This is how much we shift the remembered set bit offset to get the
|
|
|
|
// offset of the word in the remembered set. We divide by kBitsPerInt (32,
|
|
|
|
// shift right 5) and then multiply by kIntSize (4, shift left 2).
|
|
|
|
const int kRSetWordShift = 3;
|
|
|
|
|
|
|
|
Label fast, done;
|
|
|
|
|
2008-07-30 08:49:36 +00:00
|
|
|
// First, test that the object is not in the new space. We cannot set
|
|
|
|
// remembered set bits in the new space.
|
|
|
|
// object: heap object pointer (with tag)
|
|
|
|
// offset: offset to store location from the object
|
2008-07-03 15:10:15 +00:00
|
|
|
and_(scratch, object, Operand(Heap::NewSpaceMask()));
|
|
|
|
cmp(scratch, Operand(ExternalReference::new_space_start()));
|
|
|
|
b(eq, &done);
|
|
|
|
|
|
|
|
// Compute the bit offset in the remembered set.
|
2008-07-30 08:49:36 +00:00
|
|
|
// object: heap object pointer (with tag)
|
|
|
|
// offset: offset to store location from the object
|
|
|
|
mov(ip, Operand(Page::kPageAlignmentMask)); // load mask only once
|
|
|
|
and_(scratch, object, Operand(ip)); // offset into page of the object
|
|
|
|
add(offset, scratch, Operand(offset)); // add offset into the object
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(offset, Operand(offset, LSR, kObjectAlignmentBits));
|
|
|
|
|
|
|
|
// Compute the page address from the heap object pointer.
|
2008-07-30 08:49:36 +00:00
|
|
|
// object: heap object pointer (with tag)
|
|
|
|
// offset: bit offset of store position in the remembered set
|
2008-07-03 15:10:15 +00:00
|
|
|
bic(object, object, Operand(ip));
|
|
|
|
|
|
|
|
// If the bit offset lies beyond the normal remembered set range, it is in
|
|
|
|
// the extra remembered set area of a large object.
|
2008-07-30 08:49:36 +00:00
|
|
|
// object: page start
|
|
|
|
// offset: bit offset of store position in the remembered set
|
2008-07-03 15:10:15 +00:00
|
|
|
cmp(offset, Operand(Page::kPageSize / kPointerSize));
|
|
|
|
b(lt, &fast);
|
|
|
|
|
|
|
|
// Adjust the bit offset to be relative to the start of the extra
|
|
|
|
// remembered set and the start address to be the address of the extra
|
|
|
|
// remembered set.
|
|
|
|
sub(offset, offset, Operand(Page::kPageSize / kPointerSize));
|
|
|
|
// Load the array length into 'scratch' and multiply by four to get the
|
|
|
|
// size in bytes of the elements.
|
|
|
|
ldr(scratch, MemOperand(object, Page::kObjectStartOffset
|
|
|
|
+ FixedArray::kLengthOffset));
|
|
|
|
mov(scratch, Operand(scratch, LSL, kObjectAlignmentBits));
|
|
|
|
// Add the page header (including remembered set), array header, and array
|
|
|
|
// body size to the page address.
|
|
|
|
add(object, object, Operand(Page::kObjectStartOffset
|
2009-07-17 12:12:24 +00:00
|
|
|
+ FixedArray::kHeaderSize));
|
2008-07-03 15:10:15 +00:00
|
|
|
add(object, object, Operand(scratch));
|
|
|
|
|
|
|
|
bind(&fast);
|
|
|
|
// Get address of the rset word.
|
2008-07-30 08:49:36 +00:00
|
|
|
// object: start of the remembered set (page start for the fast case)
|
|
|
|
// offset: bit offset of store position in the remembered set
|
|
|
|
bic(scratch, offset, Operand(kBitsPerInt - 1)); // clear the bit offset
|
|
|
|
add(object, object, Operand(scratch, LSR, kRSetWordShift));
|
|
|
|
// Get bit offset in the rset word.
|
|
|
|
// object: address of remembered set word
|
|
|
|
// offset: bit offset of store position
|
2008-07-03 15:10:15 +00:00
|
|
|
and_(offset, offset, Operand(kBitsPerInt - 1));
|
|
|
|
|
|
|
|
ldr(scratch, MemOperand(object));
|
|
|
|
mov(ip, Operand(1));
|
|
|
|
orr(scratch, scratch, Operand(ip, LSL, offset));
|
|
|
|
str(scratch, MemOperand(object));
|
|
|
|
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 09:09:38 +00:00
|
|
|
void MacroAssembler::EnterFrame(StackFrame::Type type) {
|
2008-09-12 03:29:06 +00:00
|
|
|
// r0-r3: preserved
|
|
|
|
stm(db_w, sp, cp.bit() | fp.bit() | lr.bit());
|
|
|
|
mov(ip, Operand(Smi::FromInt(type)));
|
|
|
|
push(ip);
|
2009-02-25 16:52:15 +00:00
|
|
|
mov(ip, Operand(CodeObject()));
|
|
|
|
push(ip);
|
2008-09-12 03:29:06 +00:00
|
|
|
add(fp, sp, Operand(3 * kPointerSize)); // Adjust FP to point to saved FP.
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 09:09:38 +00:00
|
|
|
void MacroAssembler::LeaveFrame(StackFrame::Type type) {
|
2008-09-12 03:29:06 +00:00
|
|
|
// r0: preserved
|
|
|
|
// r1: preserved
|
|
|
|
// r2: preserved
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-10 09:09:38 +00:00
|
|
|
// Drop the execution stack down to the frame pointer and restore
|
|
|
|
// the caller frame pointer and return address.
|
2008-09-12 03:29:06 +00:00
|
|
|
mov(sp, fp);
|
|
|
|
ldm(ia_w, sp, fp.bit() | lr.bit());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-23 08:19:26 +00:00
|
|
|
void MacroAssembler::EnterExitFrame(StackFrame::Type type) {
|
|
|
|
ASSERT(type == StackFrame::EXIT || type == StackFrame::EXIT_DEBUG);
|
2009-05-12 20:11:01 +00:00
|
|
|
|
|
|
|
// Compute the argv pointer and keep it in a callee-saved register.
|
|
|
|
// r0 is argc.
|
|
|
|
add(r6, sp, Operand(r0, LSL, kPointerSizeLog2));
|
|
|
|
sub(r6, r6, Operand(kPointerSize));
|
|
|
|
|
2009-06-10 15:08:25 +00:00
|
|
|
// Compute callee's stack pointer before making changes and save it as
|
|
|
|
// ip register so that it is restored as sp register on exit, thereby
|
2008-09-23 08:19:26 +00:00
|
|
|
// popping the args.
|
|
|
|
|
|
|
|
// ip = sp + kPointerSize * #args;
|
|
|
|
add(ip, sp, Operand(r0, LSL, kPointerSizeLog2));
|
|
|
|
|
2009-05-12 20:11:01 +00:00
|
|
|
// Align the stack at this point. After this point we have 5 pushes,
|
|
|
|
// so in fact we have to unalign here! See also the assert on the
|
|
|
|
// alignment immediately below.
|
2009-07-08 22:13:42 +00:00
|
|
|
#if defined(V8_HOST_ARCH_ARM)
|
|
|
|
// Running on the real platform. Use the alignment as mandated by the local
|
|
|
|
// environment.
|
|
|
|
// Note: This will break if we ever start generating snapshots on one ARM
|
|
|
|
// platform for another ARM platform with a different alignment.
|
|
|
|
int activation_frame_alignment = OS::ActivationFrameAlignment();
|
|
|
|
#else // defined(V8_HOST_ARCH_ARM)
|
|
|
|
// If we are using the simulator then we should always align to the expected
|
|
|
|
// alignment. As the simulator is used to generate snapshots we do not know
|
|
|
|
// if the target platform will need alignment, so we will always align at
|
|
|
|
// this point here.
|
|
|
|
int activation_frame_alignment = 2 * kPointerSize;
|
|
|
|
#endif // defined(V8_HOST_ARCH_ARM)
|
|
|
|
if (activation_frame_alignment != kPointerSize) {
|
2009-05-12 20:11:01 +00:00
|
|
|
// This code needs to be made more general if this assert doesn't hold.
|
2009-07-08 22:13:42 +00:00
|
|
|
ASSERT(activation_frame_alignment == 2 * kPointerSize);
|
2009-05-12 20:11:01 +00:00
|
|
|
mov(r7, Operand(Smi::FromInt(0)));
|
2009-07-08 22:13:42 +00:00
|
|
|
tst(sp, Operand(activation_frame_alignment - 1));
|
2009-05-12 20:11:01 +00:00
|
|
|
push(r7, eq); // Conditional push instruction.
|
|
|
|
}
|
|
|
|
|
2008-09-23 08:19:26 +00:00
|
|
|
// Push in reverse order: caller_fp, sp_on_exit, and caller_pc.
|
|
|
|
stm(db_w, sp, fp.bit() | ip.bit() | lr.bit());
|
|
|
|
mov(fp, Operand(sp)); // setup new frame pointer
|
|
|
|
|
|
|
|
// Push debug marker.
|
|
|
|
mov(ip, Operand(type == StackFrame::EXIT_DEBUG ? 1 : 0));
|
|
|
|
push(ip);
|
|
|
|
|
|
|
|
// Save the frame pointer and the context in top.
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address)));
|
|
|
|
str(fp, MemOperand(ip));
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_context_address)));
|
|
|
|
str(cp, MemOperand(ip));
|
|
|
|
|
|
|
|
// Setup argc and the builtin function in callee-saved registers.
|
|
|
|
mov(r4, Operand(r0));
|
|
|
|
mov(r5, Operand(r1));
|
|
|
|
|
2008-09-23 12:21:54 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-09-23 12:21:54 +00:00
|
|
|
// Save the state of all registers to the stack from the memory
|
|
|
|
// location. This is needed to allow nested break points.
|
|
|
|
if (type == StackFrame::EXIT_DEBUG) {
|
|
|
|
// Use sp as base to push.
|
|
|
|
CopyRegistersFromMemoryToStack(sp, kJSCallerSaved);
|
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-09-23 08:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-23 12:21:54 +00:00
|
|
|
void MacroAssembler::LeaveExitFrame(StackFrame::Type type) {
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-09-23 12:21:54 +00:00
|
|
|
// Restore the memory copy of the registers by digging them out from
|
|
|
|
// the stack. This is needed to allow nested break points.
|
|
|
|
if (type == StackFrame::EXIT_DEBUG) {
|
|
|
|
// This code intentionally clobbers r2 and r3.
|
|
|
|
const int kCallerSavedSize = kNumJSCallerSaved * kPointerSize;
|
|
|
|
const int kOffset = ExitFrameConstants::kDebugMarkOffset - kCallerSavedSize;
|
|
|
|
add(r3, fp, Operand(kOffset));
|
|
|
|
CopyRegistersFromStackToMemory(r3, r2, kJSCallerSaved);
|
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-09-23 12:21:54 +00:00
|
|
|
|
2008-09-23 08:19:26 +00:00
|
|
|
// Clear top frame.
|
|
|
|
mov(r3, Operand(0));
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address)));
|
|
|
|
str(r3, MemOperand(ip));
|
|
|
|
|
|
|
|
// Restore current context from top and clear it in debug mode.
|
|
|
|
mov(ip, Operand(ExternalReference(Top::k_context_address)));
|
|
|
|
ldr(cp, MemOperand(ip));
|
2009-04-22 09:25:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
str(r3, MemOperand(ip));
|
|
|
|
#endif
|
2008-09-23 08:19:26 +00:00
|
|
|
|
|
|
|
// Pop the arguments, restore registers, and return.
|
|
|
|
mov(sp, Operand(fp)); // respect ABI stack constraint
|
|
|
|
ldm(ia, sp, fp.bit() | sp.bit() | pc.bit());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-06 10:02:49 +00:00
|
|
|
void MacroAssembler::InvokePrologue(const ParameterCount& expected,
|
|
|
|
const ParameterCount& actual,
|
|
|
|
Handle<Code> code_constant,
|
|
|
|
Register code_reg,
|
|
|
|
Label* done,
|
|
|
|
InvokeFlag flag) {
|
2008-09-12 03:29:06 +00:00
|
|
|
bool definitely_matches = false;
|
|
|
|
Label regular_invoke;
|
|
|
|
|
|
|
|
// Check whether the expected and actual arguments count match. If not,
|
|
|
|
// setup registers according to contract with ArgumentsAdaptorTrampoline:
|
|
|
|
// r0: actual arguments count
|
|
|
|
// r1: function (passed through to callee)
|
|
|
|
// r2: expected arguments count
|
|
|
|
// r3: callee code entry
|
|
|
|
|
|
|
|
// The code below is made a lot easier because the calling code already sets
|
|
|
|
// up actual and expected registers according to the contract if values are
|
|
|
|
// passed in registers.
|
|
|
|
ASSERT(actual.is_immediate() || actual.reg().is(r0));
|
|
|
|
ASSERT(expected.is_immediate() || expected.reg().is(r2));
|
|
|
|
ASSERT((!code_constant.is_null() && code_reg.is(no_reg)) || code_reg.is(r3));
|
|
|
|
|
|
|
|
if (expected.is_immediate()) {
|
|
|
|
ASSERT(actual.is_immediate());
|
|
|
|
if (expected.immediate() == actual.immediate()) {
|
|
|
|
definitely_matches = true;
|
|
|
|
} else {
|
|
|
|
mov(r0, Operand(actual.immediate()));
|
2008-09-16 07:24:46 +00:00
|
|
|
const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel;
|
|
|
|
if (expected.immediate() == sentinel) {
|
|
|
|
// Don't worry about adapting arguments for builtins that
|
|
|
|
// don't want that done. Skip adaption code by making it look
|
|
|
|
// like we have a match between expected and actual number of
|
|
|
|
// arguments.
|
|
|
|
definitely_matches = true;
|
|
|
|
} else {
|
|
|
|
mov(r2, Operand(expected.immediate()));
|
|
|
|
}
|
2008-09-12 03:29:06 +00:00
|
|
|
}
|
2008-08-06 10:02:49 +00:00
|
|
|
} else {
|
2008-09-12 03:29:06 +00:00
|
|
|
if (actual.is_immediate()) {
|
|
|
|
cmp(expected.reg(), Operand(actual.immediate()));
|
|
|
|
b(eq, ®ular_invoke);
|
|
|
|
mov(r0, Operand(actual.immediate()));
|
|
|
|
} else {
|
|
|
|
cmp(expected.reg(), Operand(actual.reg()));
|
|
|
|
b(eq, ®ular_invoke);
|
2008-08-06 10:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 03:29:06 +00:00
|
|
|
|
|
|
|
if (!definitely_matches) {
|
|
|
|
if (!code_constant.is_null()) {
|
|
|
|
mov(r3, Operand(code_constant));
|
|
|
|
add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle<Code> adaptor =
|
|
|
|
Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline));
|
|
|
|
if (flag == CALL_FUNCTION) {
|
2008-09-22 13:57:03 +00:00
|
|
|
Call(adaptor, RelocInfo::CODE_TARGET);
|
2008-09-12 03:29:06 +00:00
|
|
|
b(done);
|
|
|
|
} else {
|
2008-09-22 13:57:03 +00:00
|
|
|
Jump(adaptor, RelocInfo::CODE_TARGET);
|
2008-09-12 03:29:06 +00:00
|
|
|
}
|
|
|
|
bind(®ular_invoke);
|
|
|
|
}
|
2008-08-06 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeCode(Register code,
|
|
|
|
const ParameterCount& expected,
|
|
|
|
const ParameterCount& actual,
|
|
|
|
InvokeFlag flag) {
|
|
|
|
Label done;
|
|
|
|
|
|
|
|
InvokePrologue(expected, actual, Handle<Code>::null(), code, &done, flag);
|
|
|
|
if (flag == CALL_FUNCTION) {
|
|
|
|
Call(code);
|
|
|
|
} else {
|
|
|
|
ASSERT(flag == JUMP_FUNCTION);
|
|
|
|
Jump(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue here if InvokePrologue does handle the invocation due to
|
|
|
|
// mismatched parameter counts.
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeCode(Handle<Code> code,
|
|
|
|
const ParameterCount& expected,
|
|
|
|
const ParameterCount& actual,
|
2008-09-22 13:57:03 +00:00
|
|
|
RelocInfo::Mode rmode,
|
2008-08-06 10:02:49 +00:00
|
|
|
InvokeFlag flag) {
|
|
|
|
Label done;
|
|
|
|
|
|
|
|
InvokePrologue(expected, actual, code, no_reg, &done, flag);
|
|
|
|
if (flag == CALL_FUNCTION) {
|
|
|
|
Call(code, rmode);
|
|
|
|
} else {
|
|
|
|
Jump(code, rmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue here if InvokePrologue does handle the invocation due to
|
|
|
|
// mismatched parameter counts.
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeFunction(Register fun,
|
|
|
|
const ParameterCount& actual,
|
|
|
|
InvokeFlag flag) {
|
|
|
|
// Contract with called JS functions requires that function is passed in r1.
|
|
|
|
ASSERT(fun.is(r1));
|
|
|
|
|
|
|
|
Register expected_reg = r2;
|
2008-09-12 03:29:06 +00:00
|
|
|
Register code_reg = r3;
|
2008-08-06 10:02:49 +00:00
|
|
|
|
|
|
|
ldr(code_reg, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
|
|
|
|
ldr(expected_reg,
|
|
|
|
FieldMemOperand(code_reg,
|
|
|
|
SharedFunctionInfo::kFormalParameterCountOffset));
|
|
|
|
ldr(code_reg,
|
|
|
|
MemOperand(code_reg, SharedFunctionInfo::kCodeOffset - kHeapObjectTag));
|
|
|
|
add(code_reg, code_reg, Operand(Code::kHeaderSize - kHeapObjectTag));
|
|
|
|
|
|
|
|
ParameterCount expected(expected_reg);
|
|
|
|
InvokeCode(code_reg, expected, actual, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::SaveRegistersToMemory(RegList regs) {
|
|
|
|
ASSERT((regs & ~kJSCallerSaved) == 0);
|
|
|
|
// Copy the content of registers to memory location.
|
|
|
|
for (int i = 0; i < kNumJSCallerSaved; i++) {
|
|
|
|
int r = JSCallerSavedCode(i);
|
|
|
|
if ((regs & (1 << r)) != 0) {
|
|
|
|
Register reg = { r };
|
|
|
|
mov(ip, Operand(ExternalReference(Debug_Address::Register(i))));
|
|
|
|
str(reg, MemOperand(ip));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::RestoreRegistersFromMemory(RegList regs) {
|
|
|
|
ASSERT((regs & ~kJSCallerSaved) == 0);
|
|
|
|
// Copy the content of memory location to registers.
|
|
|
|
for (int i = kNumJSCallerSaved; --i >= 0;) {
|
|
|
|
int r = JSCallerSavedCode(i);
|
|
|
|
if ((regs & (1 << r)) != 0) {
|
|
|
|
Register reg = { r };
|
|
|
|
mov(ip, Operand(ExternalReference(Debug_Address::Register(i))));
|
|
|
|
ldr(reg, MemOperand(ip));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CopyRegistersFromMemoryToStack(Register base,
|
|
|
|
RegList regs) {
|
|
|
|
ASSERT((regs & ~kJSCallerSaved) == 0);
|
|
|
|
// Copy the content of the memory location to the stack and adjust base.
|
|
|
|
for (int i = kNumJSCallerSaved; --i >= 0;) {
|
|
|
|
int r = JSCallerSavedCode(i);
|
|
|
|
if ((regs & (1 << r)) != 0) {
|
|
|
|
mov(ip, Operand(ExternalReference(Debug_Address::Register(i))));
|
|
|
|
ldr(ip, MemOperand(ip));
|
|
|
|
str(ip, MemOperand(base, 4, NegPreIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CopyRegistersFromStackToMemory(Register base,
|
|
|
|
Register scratch,
|
|
|
|
RegList regs) {
|
|
|
|
ASSERT((regs & ~kJSCallerSaved) == 0);
|
|
|
|
// Copy the content of the stack to the memory location and adjust base.
|
|
|
|
for (int i = 0; i < kNumJSCallerSaved; i++) {
|
|
|
|
int r = JSCallerSavedCode(i);
|
|
|
|
if ((regs & (1 << r)) != 0) {
|
|
|
|
mov(ip, Operand(ExternalReference(Debug_Address::Register(i))));
|
|
|
|
ldr(scratch, MemOperand(base, 4, PostIndex));
|
|
|
|
str(scratch, MemOperand(ip));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-06-10 09:00:07 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::PushTryHandler(CodeLocation try_location,
|
|
|
|
HandlerType type) {
|
2009-06-10 09:00:07 +00:00
|
|
|
// Adjust this code if not the case.
|
|
|
|
ASSERT(StackHandlerConstants::kSize == 4 * kPointerSize);
|
2008-07-03 15:10:15 +00:00
|
|
|
// The pc (return address) is passed in register lr.
|
|
|
|
if (try_location == IN_JAVASCRIPT) {
|
|
|
|
if (type == TRY_CATCH_HANDLER) {
|
|
|
|
mov(r3, Operand(StackHandler::TRY_CATCH));
|
|
|
|
} else {
|
|
|
|
mov(r3, Operand(StackHandler::TRY_FINALLY));
|
|
|
|
}
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kFPOffset == 2 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kPCOffset == 3 * kPointerSize);
|
|
|
|
stm(db_w, sp, r3.bit() | fp.bit() | lr.bit());
|
|
|
|
// Save the current handler as the next handler.
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r3, Operand(ExternalReference(Top::k_handler_address)));
|
|
|
|
ldr(r1, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kNextOffset == 0);
|
|
|
|
push(r1);
|
|
|
|
// Link this handler as the new current one.
|
|
|
|
str(sp, MemOperand(r3));
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2008-09-12 03:29:06 +00:00
|
|
|
// Must preserve r0-r4, r5-r7 are available.
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(try_location == IN_JS_ENTRY);
|
2009-06-10 09:00:07 +00:00
|
|
|
// The frame pointer does not point to a JS frame so we save NULL
|
|
|
|
// for fp. We expect the code throwing an exception to check fp
|
|
|
|
// before dereferencing it to restore the context.
|
|
|
|
mov(ip, Operand(0)); // To save a NULL frame pointer.
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r6, Operand(StackHandler::ENTRY));
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kStateOffset == 1 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kFPOffset == 2 * kPointerSize
|
|
|
|
&& StackHandlerConstants::kPCOffset == 3 * kPointerSize);
|
|
|
|
stm(db_w, sp, r6.bit() | ip.bit() | lr.bit());
|
|
|
|
// Save the current handler as the next handler.
|
2008-07-03 15:10:15 +00:00
|
|
|
mov(r7, Operand(ExternalReference(Top::k_handler_address)));
|
|
|
|
ldr(r6, MemOperand(r7));
|
2009-06-10 09:00:07 +00:00
|
|
|
ASSERT(StackHandlerConstants::kNextOffset == 0);
|
|
|
|
push(r6);
|
|
|
|
// Link this handler as the new current one.
|
|
|
|
str(sp, MemOperand(r7));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Register MacroAssembler::CheckMaps(JSObject* object, Register object_reg,
|
|
|
|
JSObject* holder, Register holder_reg,
|
|
|
|
Register scratch,
|
|
|
|
Label* miss) {
|
|
|
|
// Make sure there's no overlap between scratch and the other
|
|
|
|
// registers.
|
|
|
|
ASSERT(!scratch.is(object_reg) && !scratch.is(holder_reg));
|
|
|
|
|
|
|
|
// Keep track of the current object in register reg.
|
|
|
|
Register reg = object_reg;
|
|
|
|
int depth = 1;
|
|
|
|
|
|
|
|
// Check the maps in the prototype chain.
|
|
|
|
// Traverse the prototype chain from the object and do map checks.
|
|
|
|
while (object != holder) {
|
|
|
|
depth++;
|
|
|
|
|
|
|
|
// Only global objects and objects that do not require access
|
|
|
|
// checks are allowed in stubs.
|
2008-10-21 20:11:50 +00:00
|
|
|
ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Get the map of the current object.
|
|
|
|
ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset));
|
|
|
|
cmp(scratch, Operand(Handle<Map>(object->map())));
|
|
|
|
|
|
|
|
// Branch on the result of the map check.
|
|
|
|
b(ne, miss);
|
|
|
|
|
|
|
|
// Check access rights to the global object. This has to happen
|
|
|
|
// after the map check so that we know that the object is
|
|
|
|
// actually a global object.
|
2008-10-21 20:11:50 +00:00
|
|
|
if (object->IsJSGlobalProxy()) {
|
|
|
|
CheckAccessGlobalProxy(reg, scratch, miss);
|
2008-07-03 15:10:15 +00:00
|
|
|
// Restore scratch register to be the map of the object. In the
|
|
|
|
// new space case below, we load the prototype from the map in
|
|
|
|
// the scratch register.
|
|
|
|
ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
reg = holder_reg; // from now the object is in holder_reg
|
|
|
|
JSObject* prototype = JSObject::cast(object->GetPrototype());
|
|
|
|
if (Heap::InNewSpace(prototype)) {
|
|
|
|
// The prototype is in new space; we cannot store a reference
|
|
|
|
// to it in the code. Load it from the map.
|
|
|
|
ldr(reg, FieldMemOperand(scratch, Map::kPrototypeOffset));
|
|
|
|
} else {
|
|
|
|
// The prototype is in old space; load it directly.
|
|
|
|
mov(reg, Operand(Handle<JSObject>(prototype)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go to the next object in the prototype chain.
|
|
|
|
object = prototype;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the holder map.
|
|
|
|
ldr(scratch, FieldMemOperand(reg, HeapObject::kMapOffset));
|
|
|
|
cmp(scratch, Operand(Handle<Map>(object->map())));
|
|
|
|
b(ne, miss);
|
|
|
|
|
|
|
|
// Log the check depth.
|
|
|
|
LOG(IntEvent("check-maps-depth", depth));
|
|
|
|
|
|
|
|
// Perform security check for access to the global object and return
|
|
|
|
// the holder register.
|
|
|
|
ASSERT(object == holder);
|
2008-10-21 20:11:50 +00:00
|
|
|
ASSERT(object->IsJSGlobalProxy() || !object->IsAccessCheckNeeded());
|
|
|
|
if (object->IsJSGlobalProxy()) {
|
|
|
|
CheckAccessGlobalProxy(reg, scratch, miss);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-21 20:11:50 +00:00
|
|
|
void MacroAssembler::CheckAccessGlobalProxy(Register holder_reg,
|
2008-10-21 22:40:14 +00:00
|
|
|
Register scratch,
|
|
|
|
Label* miss) {
|
2008-10-21 20:11:50 +00:00
|
|
|
Label same_contexts;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ASSERT(!holder_reg.is(scratch));
|
2008-10-21 20:11:50 +00:00
|
|
|
ASSERT(!holder_reg.is(ip));
|
|
|
|
ASSERT(!scratch.is(ip));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-21 20:11:50 +00:00
|
|
|
// Load current lexical context from the stack frame.
|
|
|
|
ldr(scratch, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
|
|
|
// In debug mode, make sure the lexical context is set.
|
2009-04-22 09:25:41 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
cmp(scratch, Operand(0));
|
|
|
|
Check(ne, "we should not have an empty lexical context");
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-21 20:11:50 +00:00
|
|
|
// Load the global context of the current context.
|
2008-07-03 15:10:15 +00:00
|
|
|
int offset = Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
|
|
|
|
ldr(scratch, FieldMemOperand(scratch, offset));
|
2008-10-21 20:11:50 +00:00
|
|
|
ldr(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset));
|
|
|
|
|
|
|
|
// Check the context is a global context.
|
|
|
|
if (FLAG_debug_code) {
|
2008-10-21 22:40:14 +00:00
|
|
|
// TODO(119): avoid push(holder_reg)/pop(holder_reg)
|
|
|
|
// Cannot use ip as a temporary in this verification code. Due to the fact
|
|
|
|
// that ip is clobbered as part of cmp with an object Operand.
|
|
|
|
push(holder_reg); // Temporarily save holder on the stack.
|
2008-10-21 20:11:50 +00:00
|
|
|
// Read the first word and compare to the global_context_map.
|
2008-10-21 22:40:14 +00:00
|
|
|
ldr(holder_reg, FieldMemOperand(scratch, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kGlobalContextMapRootIndex);
|
|
|
|
cmp(holder_reg, ip);
|
2008-10-21 20:11:50 +00:00
|
|
|
Check(eq, "JSGlobalObject::global_context should be a global context.");
|
2008-10-21 22:40:14 +00:00
|
|
|
pop(holder_reg); // Restore holder.
|
2008-10-21 20:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if both contexts are the same.
|
|
|
|
ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset));
|
|
|
|
cmp(scratch, Operand(ip));
|
|
|
|
b(eq, &same_contexts);
|
|
|
|
|
|
|
|
// Check the context is a global context.
|
|
|
|
if (FLAG_debug_code) {
|
2008-10-21 22:40:14 +00:00
|
|
|
// TODO(119): avoid push(holder_reg)/pop(holder_reg)
|
|
|
|
// Cannot use ip as a temporary in this verification code. Due to the fact
|
|
|
|
// that ip is clobbered as part of cmp with an object Operand.
|
|
|
|
push(holder_reg); // Temporarily save holder on the stack.
|
|
|
|
mov(holder_reg, ip); // Move ip to its holding place.
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kNullValueRootIndex);
|
|
|
|
cmp(holder_reg, ip);
|
2008-10-21 20:11:50 +00:00
|
|
|
Check(ne, "JSGlobalProxy::context() should not be null.");
|
|
|
|
|
2008-10-21 22:40:14 +00:00
|
|
|
ldr(holder_reg, FieldMemOperand(holder_reg, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kGlobalContextMapRootIndex);
|
|
|
|
cmp(holder_reg, ip);
|
2008-10-21 20:11:50 +00:00
|
|
|
Check(eq, "JSGlobalObject::global_context should be a global context.");
|
2008-10-21 22:40:14 +00:00
|
|
|
// Restore ip is not needed. ip is reloaded below.
|
|
|
|
pop(holder_reg); // Restore holder.
|
2008-10-21 20:11:50 +00:00
|
|
|
// Restore ip to holder's context.
|
|
|
|
ldr(ip, FieldMemOperand(holder_reg, JSGlobalProxy::kContextOffset));
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Check that the security token in the calling global object is
|
|
|
|
// compatible with the security token in the receiving global
|
|
|
|
// object.
|
2008-10-21 20:11:50 +00:00
|
|
|
int token_offset = Context::kHeaderSize +
|
|
|
|
Context::SECURITY_TOKEN_INDEX * kPointerSize;
|
|
|
|
|
|
|
|
ldr(scratch, FieldMemOperand(scratch, token_offset));
|
|
|
|
ldr(ip, FieldMemOperand(ip, token_offset));
|
2008-07-03 15:10:15 +00:00
|
|
|
cmp(scratch, Operand(ip));
|
|
|
|
b(ne, miss);
|
2008-10-21 20:11:50 +00:00
|
|
|
|
|
|
|
bind(&same_contexts);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-10 11:42:13 +00:00
|
|
|
void MacroAssembler::CompareObjectType(Register function,
|
|
|
|
Register map,
|
|
|
|
Register type_reg,
|
|
|
|
InstanceType type) {
|
|
|
|
ldr(map, FieldMemOperand(function, HeapObject::kMapOffset));
|
|
|
|
ldrb(type_reg, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
|
|
|
cmp(type_reg, Operand(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::TryGetFunctionPrototype(Register function,
|
|
|
|
Register result,
|
|
|
|
Register scratch,
|
|
|
|
Label* miss) {
|
|
|
|
// Check that the receiver isn't a smi.
|
|
|
|
BranchOnSmi(function, miss);
|
|
|
|
|
|
|
|
// Check that the function really is a function. Load map into result reg.
|
|
|
|
CompareObjectType(function, result, scratch, JS_FUNCTION_TYPE);
|
|
|
|
b(ne, miss);
|
|
|
|
|
|
|
|
// Make sure that the function has an instance prototype.
|
|
|
|
Label non_instance;
|
|
|
|
ldrb(scratch, FieldMemOperand(result, Map::kBitFieldOffset));
|
|
|
|
tst(scratch, Operand(1 << Map::kHasNonInstancePrototype));
|
|
|
|
b(ne, &non_instance);
|
|
|
|
|
|
|
|
// Get the prototype or initial map from the function.
|
|
|
|
ldr(result,
|
|
|
|
FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset));
|
|
|
|
|
|
|
|
// If the prototype or initial map is the hole, don't return it and
|
|
|
|
// simply miss the cache instead. This will allow us to allocate a
|
|
|
|
// prototype object on-demand in the runtime system.
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
|
|
|
cmp(result, ip);
|
2009-06-10 11:42:13 +00:00
|
|
|
b(eq, miss);
|
|
|
|
|
|
|
|
// If the function does not have an initial map, we're done.
|
|
|
|
Label done;
|
|
|
|
CompareObjectType(result, scratch, scratch, MAP_TYPE);
|
|
|
|
b(ne, &done);
|
|
|
|
|
|
|
|
// Get the prototype from the initial map.
|
|
|
|
ldr(result, FieldMemOperand(result, Map::kPrototypeOffset));
|
|
|
|
jmp(&done);
|
|
|
|
|
|
|
|
// Non-instance prototype: Fetch prototype from constructor field
|
|
|
|
// in initial map.
|
|
|
|
bind(&non_instance);
|
|
|
|
ldr(result, FieldMemOperand(result, Map::kConstructorOffset));
|
|
|
|
|
|
|
|
// All done.
|
|
|
|
bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-26 10:27:32 +00:00
|
|
|
void MacroAssembler::CallStub(CodeStub* stub, Condition cond) {
|
2008-07-30 08:49:36 +00:00
|
|
|
ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs
|
2009-08-26 10:27:32 +00:00
|
|
|
Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::StubReturn(int argc) {
|
|
|
|
ASSERT(argc >= 1 && generating_stub());
|
|
|
|
if (argc > 1)
|
|
|
|
add(sp, sp, Operand((argc - 1) * kPointerSize));
|
|
|
|
Ret();
|
|
|
|
}
|
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2008-10-06 06:41:10 +00:00
|
|
|
void MacroAssembler::IllegalOperation(int num_arguments) {
|
|
|
|
if (num_arguments > 0) {
|
|
|
|
add(sp, sp, Operand(num_arguments * kPointerSize));
|
|
|
|
}
|
2009-08-24 11:57:57 +00:00
|
|
|
LoadRoot(r0, Heap::kUndefinedValueRootIndex);
|
2008-10-06 06:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::CallRuntime(Runtime::Function* f, int num_arguments) {
|
2008-08-13 09:32:07 +00:00
|
|
|
// All parameters are on the stack. r0 has the return value after call.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-06 06:41:10 +00:00
|
|
|
// If the expected number of arguments of the runtime function is
|
|
|
|
// constant, we check that the actual number of arguments match the
|
|
|
|
// expectation.
|
|
|
|
if (f->nargs >= 0 && f->nargs != num_arguments) {
|
|
|
|
IllegalOperation(num_arguments);
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
Runtime::FunctionId function_id =
|
|
|
|
static_cast<Runtime::FunctionId>(f->stub_id);
|
|
|
|
RuntimeStub stub(function_id, num_arguments);
|
2008-07-03 15:10:15 +00:00
|
|
|
CallStub(&stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::CallRuntime(Runtime::FunctionId fid, int num_arguments) {
|
|
|
|
CallRuntime(Runtime::FunctionForId(fid), num_arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
void MacroAssembler::TailCallRuntime(const ExternalReference& ext,
|
|
|
|
int num_arguments) {
|
|
|
|
// TODO(1236192): Most runtime routines don't need the number of
|
|
|
|
// arguments passed in because it is constant. At some point we
|
|
|
|
// should remove this need and make the runtime routine entry code
|
|
|
|
// smarter.
|
|
|
|
mov(r0, Operand(num_arguments));
|
|
|
|
JumpToBuiltin(ext);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::JumpToBuiltin(const ExternalReference& builtin) {
|
|
|
|
#if defined(__thumb__)
|
|
|
|
// Thumb mode builtin.
|
|
|
|
ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1);
|
|
|
|
#endif
|
|
|
|
mov(r1, Operand(builtin));
|
|
|
|
CEntryStub stub;
|
2008-09-22 13:57:03 +00:00
|
|
|
Jump(stub.GetCode(), RelocInfo::CODE_TARGET);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-12 03:29:06 +00:00
|
|
|
Handle<Code> MacroAssembler::ResolveBuiltin(Builtins::JavaScript id,
|
|
|
|
bool* resolved) {
|
|
|
|
// Contract with compiled functions is that the function is passed in r1.
|
|
|
|
int builtins_offset =
|
|
|
|
JSBuiltinsObject::kJSBuiltinsOffset + (id * kPointerSize);
|
|
|
|
ldr(r1, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
|
|
|
|
ldr(r1, FieldMemOperand(r1, GlobalObject::kBuiltinsOffset));
|
|
|
|
ldr(r1, FieldMemOperand(r1, builtins_offset));
|
|
|
|
|
|
|
|
return Builtins::GetCode(id, resolved);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id,
|
2008-07-03 15:10:15 +00:00
|
|
|
InvokeJSFlags flags) {
|
2008-09-12 03:29:06 +00:00
|
|
|
bool resolved;
|
|
|
|
Handle<Code> code = ResolveBuiltin(id, &resolved);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
if (flags == CALL_JS) {
|
2008-09-22 13:57:03 +00:00
|
|
|
Call(code, RelocInfo::CODE_TARGET);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(flags == JUMP_JS);
|
2008-09-22 13:57:03 +00:00
|
|
|
Jump(code, RelocInfo::CODE_TARGET);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-09-12 03:29:06 +00:00
|
|
|
if (!resolved) {
|
|
|
|
const char* name = Builtins::GetName(id);
|
|
|
|
int argc = Builtins::GetArgumentsCount(id);
|
|
|
|
uint32_t flags =
|
|
|
|
Bootstrapper::FixupFlagsArgumentsCount::encode(argc) |
|
2008-11-10 22:53:19 +00:00
|
|
|
Bootstrapper::FixupFlagsIsPCRelative::encode(true) |
|
|
|
|
Bootstrapper::FixupFlagsUseCodeObject::encode(false);
|
2008-09-12 03:29:06 +00:00
|
|
|
Unresolved entry = { pc_offset() - sizeof(Instr), flags, name };
|
|
|
|
unresolved_.Add(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::GetBuiltinEntry(Register target, Builtins::JavaScript id) {
|
|
|
|
bool resolved;
|
|
|
|
Handle<Code> code = ResolveBuiltin(id, &resolved);
|
|
|
|
|
|
|
|
mov(target, Operand(code));
|
|
|
|
if (!resolved) {
|
|
|
|
const char* name = Builtins::GetName(id);
|
|
|
|
int argc = Builtins::GetArgumentsCount(id);
|
2008-07-03 15:10:15 +00:00
|
|
|
uint32_t flags =
|
|
|
|
Bootstrapper::FixupFlagsArgumentsCount::encode(argc) |
|
2008-11-10 22:53:19 +00:00
|
|
|
Bootstrapper::FixupFlagsIsPCRelative::encode(true) |
|
|
|
|
Bootstrapper::FixupFlagsUseCodeObject::encode(true);
|
2008-07-03 15:10:15 +00:00
|
|
|
Unresolved entry = { pc_offset() - sizeof(Instr), flags, name };
|
|
|
|
unresolved_.Add(entry);
|
|
|
|
}
|
2008-11-10 22:53:19 +00:00
|
|
|
|
|
|
|
add(target, target, Operand(Code::kHeaderSize - kHeapObjectTag));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-20 16:59:00 +00:00
|
|
|
void MacroAssembler::SetCounter(StatsCounter* counter, int value,
|
|
|
|
Register scratch1, Register scratch2) {
|
|
|
|
if (FLAG_native_code_counters && counter->Enabled()) {
|
|
|
|
mov(scratch1, Operand(value));
|
|
|
|
mov(scratch2, Operand(ExternalReference(counter)));
|
|
|
|
str(scratch1, MemOperand(scratch2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::IncrementCounter(StatsCounter* counter, int value,
|
|
|
|
Register scratch1, Register scratch2) {
|
|
|
|
ASSERT(value > 0);
|
|
|
|
if (FLAG_native_code_counters && counter->Enabled()) {
|
|
|
|
mov(scratch2, Operand(ExternalReference(counter)));
|
|
|
|
ldr(scratch1, MemOperand(scratch2));
|
|
|
|
add(scratch1, scratch1, Operand(value));
|
|
|
|
str(scratch1, MemOperand(scratch2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::DecrementCounter(StatsCounter* counter, int value,
|
|
|
|
Register scratch1, Register scratch2) {
|
|
|
|
ASSERT(value > 0);
|
|
|
|
if (FLAG_native_code_counters && counter->Enabled()) {
|
|
|
|
mov(scratch2, Operand(ExternalReference(counter)));
|
|
|
|
ldr(scratch1, MemOperand(scratch2));
|
|
|
|
sub(scratch1, scratch1, Operand(value));
|
|
|
|
str(scratch1, MemOperand(scratch2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void MacroAssembler::Assert(Condition cc, const char* msg) {
|
|
|
|
if (FLAG_debug_code)
|
|
|
|
Check(cc, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Check(Condition cc, const char* msg) {
|
|
|
|
Label L;
|
|
|
|
b(cc, &L);
|
|
|
|
Abort(msg);
|
|
|
|
// will not return here
|
|
|
|
bind(&L);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MacroAssembler::Abort(const char* msg) {
|
|
|
|
// We want to pass the msg string like a smi to avoid GC
|
|
|
|
// problems, however msg is not guaranteed to be aligned
|
|
|
|
// properly. Instead, we pass an aligned pointer that is
|
2009-01-15 19:08:34 +00:00
|
|
|
// a proper v8 smi, but also pass the alignment difference
|
2008-07-03 15:10:15 +00:00
|
|
|
// from the real pointer as a smi.
|
|
|
|
intptr_t p1 = reinterpret_cast<intptr_t>(msg);
|
|
|
|
intptr_t p0 = (p1 & ~kSmiTagMask) + kSmiTag;
|
|
|
|
ASSERT(reinterpret_cast<Object*>(p0)->IsSmi());
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (msg != NULL) {
|
|
|
|
RecordComment("Abort message: ");
|
|
|
|
RecordComment(msg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mov(r0, Operand(p0));
|
|
|
|
push(r0);
|
|
|
|
mov(r0, Operand(Smi::FromInt(p1 - p0)));
|
2008-08-13 09:32:07 +00:00
|
|
|
push(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
CallRuntime(Runtime::kAbort, 2);
|
|
|
|
// will not return here
|
|
|
|
}
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|