blob: 40a9beb84cde9f98a97cbb651de9051719ea0253 [file] [log] [blame]
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if V8_TARGET_ARCH_MIPS
#include "src/api-arguments-inl.h"
#include "src/base/bits.h"
#include "src/bootstrapper.h"
#include "src/code-stubs.h"
#include "src/frame-constants.h"
#include "src/frames.h"
#include "src/ic/ic.h"
#include "src/ic/stub-cache.h"
#include "src/isolate.h"
#include "src/macro-assembler.h"
#include "src/objects/api-callbacks.h"
#include "src/regexp/jsregexp.h"
#include "src/regexp/regexp-macro-assembler.h"
#include "src/runtime/runtime.h"
namespace v8 {
namespace internal {
#define __ ACCESS_MASM(masm)
// Called with the native C calling convention. The corresponding function
// signature is:
//
// using JSEntryFunction = GeneratedCode<Object*(
// Object * new_target, Object * target, Object * receiver, int argc,
// Object*** args, Address root_register_value)>;
void JSEntryStub::Generate(MacroAssembler* masm) {
Label invoke, handler_entry, exit;
Isolate* isolate = masm->isolate();
static constexpr int kPushedStackSpace =
(kNumCalleeSaved + 1) * kPointerSize + kNumCalleeSavedFPU * kDoubleSize;
{
NoRootArrayScope no_root_array(masm);
// Registers:
// a0: entry address
// a1: function
// a2: receiver
// a3: argc
//
// Stack:
// 4 arg slots
// argv
// root register value
// Save callee saved registers on the stack.
__ MultiPush(kCalleeSaved | ra.bit());
// Save callee-saved FPU registers.
__ MultiPushFPU(kCalleeSavedFPU);
// Set up the reserved register for 0.0.
__ Move(kDoubleRegZero, 0.0);
// Initialize the root register.
// C calling convention. The sixth argument is passed on the stack.
static constexpr int kOffsetToRootRegisterValue =
kPushedStackSpace + kCArgsSlotsSize +
EntryFrameConstants::kRootRegisterValueOffset;
__ lw(kRootRegister, MemOperand(sp, kOffsetToRootRegisterValue));
}
// Load argv in s0 register.
static constexpr int kOffsetToArgv =
kPushedStackSpace + kCArgsSlotsSize + EntryFrameConstants::kArgvOffset;
__ lw(s0, MemOperand(sp, kOffsetToArgv));
// We build an EntryFrame.
__ li(t3, Operand(-1)); // Push a bad frame pointer to fail if it is used.
StackFrame::Type marker = type();
__ li(t2, Operand(StackFrame::TypeToMarker(marker)));
__ li(t1, Operand(StackFrame::TypeToMarker(marker)));
__ li(t0,
ExternalReference::Create(IsolateAddressId::kCEntryFPAddress, isolate));
__ lw(t0, MemOperand(t0));
__ Push(t3, t2, t1, t0);
// Set up frame pointer for the frame to be pushed.
__ addiu(fp, sp, -EntryFrameConstants::kCallerFPOffset);
// Registers:
// a0: entry_address
// a1: function
// a2: receiver_pointer
// a3: argc
// s0: argv
//
// Stack:
// caller fp |
// function slot | entry frame
// context slot |
// bad fp (0xFF...F) |
// callee saved registers + ra
// 4 args slots
// args
// If this is the outermost JS call, set js_entry_sp value.
Label non_outermost_js;
ExternalReference js_entry_sp =
ExternalReference::Create(IsolateAddressId::kJSEntrySPAddress, isolate);
__ li(t1, js_entry_sp);
__ lw(t2, MemOperand(t1));
__ Branch(&non_outermost_js, ne, t2, Operand(zero_reg));
__ sw(fp, MemOperand(t1));
__ li(t0, Operand(StackFrame::OUTERMOST_JSENTRY_FRAME));
Label cont;
__ b(&cont);
__ nop(); // Branch delay slot nop.
__ bind(&non_outermost_js);
__ li(t0, Operand(StackFrame::INNER_JSENTRY_FRAME));
__ bind(&cont);
__ push(t0);
// Jump to a faked try block that does the invoke, with a faked catch
// block that sets the pending exception.
__ jmp(&invoke);
__ bind(&handler_entry);
handler_offset_ = handler_entry.pos();
// Caught exception: Store result (exception) in the pending exception
// field in the JSEnv and return a failure sentinel. Coming in here the
// fp will be invalid because the PushStackHandler below sets it to 0 to
// signal the existence of the JSEntry frame.
__ li(t0, ExternalReference::Create(
IsolateAddressId::kPendingExceptionAddress, isolate));
__ sw(v0, MemOperand(t0)); // We come back from 'invoke'. result is in v0.
__ LoadRoot(v0, RootIndex::kException);
__ b(&exit); // b exposes branch delay slot.
__ nop(); // Branch delay slot nop.
// Invoke: Link this frame into the handler chain.
__ bind(&invoke);
__ PushStackHandler();
// If an exception not caught by another handler occurs, this handler
// returns control to the code after the bal(&invoke) above, which
// restores all kCalleeSaved registers (including cp and fp) to their
// saved values before returning a failure to C.
// Invoke the function by calling through JS entry trampoline builtin.
// Notice that we cannot store a reference to the trampoline code directly in
// this stub, because runtime stubs are not traversed when doing GC.
// Registers:
// a0: entry_address
// a1: function
// a2: receiver_pointer
// a3: argc
// s0: argv
//
// Stack:
// handler frame
// entry frame
// callee saved registers + ra
// 4 args slots
// args
__ Call(EntryTrampoline(), RelocInfo::CODE_TARGET);
// Unlink this frame from the handler chain.
__ PopStackHandler();
__ bind(&exit); // v0 holds result
// Check if the current stack frame is marked as the outermost JS frame.
Label non_outermost_js_2;
__ pop(t1);
__ Branch(&non_outermost_js_2, ne, t1,
Operand(StackFrame::OUTERMOST_JSENTRY_FRAME));
__ li(t1, ExternalReference(js_entry_sp));
__ sw(zero_reg, MemOperand(t1));
__ bind(&non_outermost_js_2);
// Restore the top frame descriptors from the stack.
__ pop(t1);
__ li(t0,
ExternalReference::Create(IsolateAddressId::kCEntryFPAddress, isolate));
__ sw(t1, MemOperand(t0));
// Reset the stack to the callee saved registers.
__ addiu(sp, sp, -EntryFrameConstants::kCallerFPOffset);
// Restore callee-saved fpu registers.
__ MultiPopFPU(kCalleeSavedFPU);
// Restore callee saved registers from the stack.
__ MultiPop(kCalleeSaved | ra.bit());
// Return.
__ Jump(ra);
}
#undef __
} // namespace internal
} // namespace v8
#endif // V8_TARGET_ARCH_MIPS