| // 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" |
| |
| #include "src/mips/code-stubs-mips.h" // Cannot be the first include. |
| |
| namespace v8 { |
| namespace internal { |
| |
| #define __ ACCESS_MASM(masm) |
| |
| void JSEntryStub::Generate(MacroAssembler* masm) { |
| Label invoke, handler_entry, exit; |
| Isolate* isolate = masm->isolate(); |
| |
| { |
| NoRootArrayScope no_root_array(masm); |
| |
| // Registers: |
| // a0: entry address |
| // a1: function |
| // a2: receiver |
| // a3: argc |
| // |
| // Stack: |
| // 4 args slots |
| // args |
| |
| // 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); |
| |
| __ InitializeRootRegister(); |
| } |
| |
| // Load argv in s0 register. |
| int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
| offset_to_argv += kNumCalleeSavedFPU * kDoubleSize; |
| |
| __ lw(s0, MemOperand(sp, offset_to_argv + kCArgsSlotsSize)); |
| |
| // 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); |
| } |
| |
| void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| // Make place for arguments to fit C calling convention. Most of the callers |
| // of DirectCEntryStub::GenerateCall are using EnterExitFrame/LeaveExitFrame |
| // so they handle stack restoring and we don't have to do that here. |
| // Any caller of DirectCEntryStub::GenerateCall must take care of dropping |
| // kCArgsSlotsSize stack space after the call. |
| __ Subu(sp, sp, Operand(kCArgsSlotsSize)); |
| // Place the return address on the stack, making the call |
| // GC safe. The RegExp backend also relies on this. |
| __ sw(ra, MemOperand(sp, kCArgsSlotsSize)); |
| __ Call(t9); // Call the C++ function. |
| __ lw(t9, MemOperand(sp, kCArgsSlotsSize)); |
| |
| if (FLAG_debug_code && FLAG_enable_slow_asserts) { |
| // In case of an error the return address may point to a memory area |
| // filled with kZapValue by the GC. |
| // Dereference the address and check for this. |
| __ lw(t0, MemOperand(t9)); |
| __ Assert(ne, AbortReason::kReceivedInvalidReturnAddress, t0, |
| Operand(reinterpret_cast<uint32_t>(kZapValue))); |
| } |
| __ Jump(t9); |
| } |
| |
| |
| void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| Register target) { |
| if (FLAG_embedded_builtins) { |
| if (masm->root_array_available() && |
| isolate()->ShouldLoadConstantsFromRootList()) { |
| // This is basically an inlined version of Call(Handle<Code>) that loads |
| // the code object into kScratchReg instead of t9. |
| __ Move(t9, target); |
| __ IndirectLoadConstant(kScratchReg, GetCode()); |
| __ Call(kScratchReg, Code::kHeaderSize - kHeapObjectTag); |
| return; |
| } |
| } |
| intptr_t loc = |
| reinterpret_cast<intptr_t>(GetCode().location()); |
| __ Move(t9, target); |
| __ li(kScratchReg, Operand(loc, RelocInfo::CODE_TARGET), CONSTANT_SIZE); |
| __ Call(kScratchReg); |
| } |
| |
| #undef __ |
| |
| } // namespace internal |
| } // namespace v8 |
| |
| #endif // V8_TARGET_ARCH_MIPS |