| // 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_ARM |
| |
| #include "src/api-arguments-inl.h" |
| #include "src/assembler-inl.h" |
| #include "src/base/bits.h" |
| #include "src/bootstrapper.h" |
| #include "src/code-stubs.h" |
| #include "src/counters.h" |
| #include "src/double.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/objects/regexp-match-info.h" |
| #include "src/regexp/jsregexp.h" |
| #include "src/regexp/regexp-macro-assembler.h" |
| #include "src/runtime/runtime.h" |
| |
| #include "src/arm/code-stubs-arm.h" // Cannot be the first include. |
| |
| namespace v8 { |
| namespace internal { |
| |
| #define __ ACCESS_MASM(masm) |
| |
| void JSEntryStub::Generate(MacroAssembler* masm) { |
| // r0: code entry |
| // r1: function |
| // r2: receiver |
| // r3: argc |
| // [sp+0]: argv |
| |
| Label invoke, handler_entry, exit; |
| |
| { |
| NoRootArrayScope no_root_array(masm); |
| |
| // Called from C, so do not pop argc and args on exit (preserve sp) |
| // No need to save register-passed args |
| // Save callee-saved registers (incl. cp and fp), sp, and lr |
| __ stm(db_w, sp, kCalleeSaved | lr.bit()); |
| |
| // Save callee-saved vfp registers. |
| __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
| // Set up the reserved register for 0.0. |
| __ vmov(kDoubleRegZero, Double(0.0)); |
| |
| __ InitializeRootRegister(); |
| } |
| |
| // Get address of argv, see stm above. |
| // r0: code entry |
| // r1: function |
| // r2: receiver |
| // r3: argc |
| |
| // Set up argv in r4. |
| int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
| offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize; |
| __ ldr(r4, MemOperand(sp, offset_to_argv)); |
| |
| // Push a frame with special values setup to mark it as an entry frame. |
| // r0: code entry |
| // r1: function |
| // r2: receiver |
| // r3: argc |
| // r4: argv |
| StackFrame::Type marker = type(); |
| __ mov(r7, Operand(StackFrame::TypeToMarker(marker))); |
| __ mov(r6, Operand(StackFrame::TypeToMarker(marker))); |
| __ mov(r5, Operand(ExternalReference::Create( |
| IsolateAddressId::kCEntryFPAddress, isolate()))); |
| __ ldr(r5, MemOperand(r5)); |
| { |
| UseScratchRegisterScope temps(masm); |
| Register scratch = temps.Acquire(); |
| |
| // Push a bad frame pointer to fail if it is used. |
| __ mov(scratch, Operand(-1)); |
| __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() | scratch.bit()); |
| } |
| |
| Register scratch = r6; |
| |
| // Set up frame pointer for the frame to be pushed. |
| __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| |
| // 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()); |
| __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| __ ldr(scratch, MemOperand(r5)); |
| __ cmp(scratch, Operand::Zero()); |
| __ b(ne, &non_outermost_js); |
| __ str(fp, MemOperand(r5)); |
| __ mov(scratch, Operand(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
| Label cont; |
| __ b(&cont); |
| __ bind(&non_outermost_js); |
| __ mov(scratch, Operand(StackFrame::INNER_JSENTRY_FRAME)); |
| __ bind(&cont); |
| __ push(scratch); |
| |
| // Jump to a faked try block that does the invoke, with a faked catch |
| // block that sets the pending exception. |
| __ jmp(&invoke); |
| |
| // Block literal pool emission whilst taking the position of the handler |
| // entry. This avoids making the assumption that literal pools are always |
| // emitted after an instruction is emitted, rather than before. |
| { |
| Assembler::BlockConstPoolScope block_const_pool(masm); |
| __ 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. |
| __ mov(scratch, |
| Operand(ExternalReference::Create( |
| IsolateAddressId::kPendingExceptionAddress, isolate()))); |
| } |
| __ str(r0, MemOperand(scratch)); |
| __ LoadRoot(r0, RootIndex::kException); |
| __ b(&exit); |
| |
| // Invoke: Link this frame into the handler chain. |
| __ bind(&invoke); |
| // Must preserve r0-r4, r5-r6 are available. |
| __ PushStackHandler(); |
| // If an exception not caught by another handler occurs, this handler |
| // returns control to the code after the bl(&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. |
| |
| // Expected registers by Builtins::JSEntryTrampoline |
| // r0: code entry |
| // r1: function |
| // r2: receiver |
| // r3: argc |
| // r4: argv |
| __ Call(EntryTrampoline(), RelocInfo::CODE_TARGET); |
| |
| // Unlink this frame from the handler chain. |
| __ PopStackHandler(); |
| |
| __ bind(&exit); // r0 holds result |
| // Check if the current stack frame is marked as the outermost JS frame. |
| Label non_outermost_js_2; |
| __ pop(r5); |
| __ cmp(r5, Operand(StackFrame::OUTERMOST_JSENTRY_FRAME)); |
| __ b(ne, &non_outermost_js_2); |
| __ mov(r6, Operand::Zero()); |
| __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| __ str(r6, MemOperand(r5)); |
| __ bind(&non_outermost_js_2); |
| |
| // Restore the top frame descriptors from the stack. |
| __ pop(r3); |
| __ mov(scratch, Operand(ExternalReference::Create( |
| IsolateAddressId::kCEntryFPAddress, isolate()))); |
| __ str(r3, MemOperand(scratch)); |
| |
| // Reset the stack to the callee saved registers. |
| __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| |
| // Restore callee-saved registers and return. |
| #ifdef DEBUG |
| if (FLAG_debug_code) { |
| __ mov(lr, Operand(pc)); |
| } |
| #endif |
| |
| // Restore callee-saved vfp registers. |
| __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
| |
| __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| } |
| |
| void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| // Place the return address on the stack, making the call |
| // GC safe. The RegExp backend also relies on this. |
| __ str(lr, MemOperand(sp, 0)); |
| __ blx(ip); // Call the C++ function. |
| __ ldr(pc, MemOperand(sp, 0)); |
| } |
| |
| |
| 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 lr instead of ip. |
| __ Move(ip, target); |
| __ IndirectLoadConstant(lr, GetCode()); |
| __ add(lr, lr, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| __ blx(lr); |
| return; |
| } |
| } |
| intptr_t code = |
| reinterpret_cast<intptr_t>(GetCode().location()); |
| __ Move(ip, target); |
| __ mov(lr, Operand(code, RelocInfo::CODE_TARGET)); |
| __ blx(lr); // Call the stub. |
| } |
| |
| #undef __ |
| |
| } // namespace internal |
| } // namespace v8 |
| |
| #endif // V8_TARGET_ARCH_ARM |