| // 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_MIPS64 |
| |
| #include "src/api-arguments.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(); |
| |
| { |
| NoRootArrayScope no_root_array(masm); |
| |
| // TODO(plind): unify the ABI description here. |
| // Registers: |
| // a0: entry address |
| // a1: function |
| // a2: receiver |
| // a3: argc |
| // a4: argv |
| // a5: root register value |
| // |
| // Stack: |
| // 0 arg slots on mips64 (4 args slots on mips) |
| |
| // 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 in a5. |
| __ mov(kRootRegister, a5); |
| } |
| |
| // Load argv in s0. |
| __ mov(s0, a4); // The 5th argument is passed in a4. |
| |
| // We build an EntryFrame. |
| __ li(a7, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| StackFrame::Type marker = type(); |
| __ li(a6, Operand(StackFrame::TypeToMarker(marker))); |
| __ li(a5, Operand(StackFrame::TypeToMarker(marker))); |
| ExternalReference c_entry_fp = |
| ExternalReference::Create(IsolateAddressId::kCEntryFPAddress, isolate); |
| __ li(a4, Operand(c_entry_fp)); |
| __ Ld(a4, MemOperand(a4)); |
| __ Push(a7, a6, a5, a4); |
| // Set up frame pointer for the frame to be pushed. |
| __ daddiu(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 |
| // [ O32: 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(a5, js_entry_sp); |
| __ Ld(a6, MemOperand(a5)); |
| __ Branch(&non_outermost_js, ne, a6, Operand(zero_reg)); |
| __ Sd(fp, MemOperand(a5)); |
| __ li(a4, Operand(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
| Label cont; |
| __ b(&cont); |
| __ nop(); // Branch delay slot nop. |
| __ bind(&non_outermost_js); |
| __ li(a4, Operand(StackFrame::INNER_JSENTRY_FRAME)); |
| __ bind(&cont); |
| __ push(a4); |
| |
| // 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(a4, ExternalReference::Create( |
| IsolateAddressId::kPendingExceptionAddress, isolate)); |
| __ Sd(v0, MemOperand(a4)); // 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 |
| // [ O32: 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(a5); |
| __ Branch(&non_outermost_js_2, ne, a5, |
| Operand(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
| __ li(a5, ExternalReference(js_entry_sp)); |
| __ Sd(zero_reg, MemOperand(a5)); |
| __ bind(&non_outermost_js_2); |
| |
| // Restore the top frame descriptors from the stack. |
| __ pop(a5); |
| __ li(a4, |
| ExternalReference::Create(IsolateAddressId::kCEntryFPAddress, isolate)); |
| __ Sd(a5, MemOperand(a4)); |
| |
| // Reset the stack to the callee saved registers. |
| __ daddiu(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_MIPS64 |