1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef jit_arm64_SharedICHelpers_arm64_h
8 #define jit_arm64_SharedICHelpers_arm64_h
9
10 #include "jit/BaselineFrame.h"
11 #include "jit/BaselineIC.h"
12 #include "jit/MacroAssembler.h"
13 #include "jit/SharedICRegisters.h"
14
15 namespace js {
16 namespace jit {
17
18 // Distance from sp to the top Value inside an IC stub (no return address on the
19 // stack on ARM).
20 static const size_t ICStackValueOffset = 0;
21
EmitRestoreTailCallReg(MacroAssembler & masm)22 inline void EmitRestoreTailCallReg(MacroAssembler& masm) {
23 // No-op on ARM because link register is always holding the return address.
24 }
25
EmitRepushTailCallReg(MacroAssembler & masm)26 inline void EmitRepushTailCallReg(MacroAssembler& masm) {
27 // No-op on ARM because link register is always holding the return address.
28 }
29
EmitCallIC(MacroAssembler & masm,const ICEntry * entry,CodeOffset * callOffset)30 inline void EmitCallIC(MacroAssembler& masm, const ICEntry* entry,
31 CodeOffset* callOffset) {
32 // Load stub pointer into ICStubReg.
33 masm.loadPtr(AbsoluteAddress(entry).offset(ICEntry::offsetOfFirstStub()),
34 ICStubReg);
35
36 // Load stubcode pointer from the ICStub.
37 // R2 won't be active when we call ICs, so we can use r0.
38 static_assert(R2 == ValueOperand(r0));
39 masm.loadPtr(Address(ICStubReg, ICStub::offsetOfStubCode()), r0);
40
41 // Call the stubcode via a direct branch-and-link.
42 masm.Blr(x0);
43 *callOffset = CodeOffset(masm.currentOffset());
44 }
45
46 inline void EmitEnterTypeMonitorIC(
47 MacroAssembler& masm,
48 size_t monitorStubOffset = ICMonitoredStub::offsetOfFirstMonitorStub()) {
49 // This is expected to be called from within an IC, when ICStubReg is
50 // properly initialized to point to the stub.
51 masm.loadPtr(Address(ICStubReg, (uint32_t)monitorStubOffset), ICStubReg);
52
53 // Load stubcode pointer from BaselineStubEntry.
54 // R2 won't be active when we call ICs, so we can use r0.
55 static_assert(R2 == ValueOperand(r0));
56 masm.loadPtr(Address(ICStubReg, ICStub::offsetOfStubCode()), r0);
57
58 // Jump to the stubcode.
59 masm.Br(x0);
60 }
61
EmitReturnFromIC(MacroAssembler & masm)62 inline void EmitReturnFromIC(MacroAssembler& masm) {
63 masm.abiret(); // Defaults to lr.
64 }
65
66 inline void EmitBaselineLeaveStubFrame(MacroAssembler& masm,
67 bool calledIntoIon = false) {
68 vixl::UseScratchRegisterScope temps(&masm.asVIXL());
69 const ARMRegister scratch64 = temps.AcquireX();
70
71 // Ion frames do not save and restore the frame pointer. If we called
72 // into Ion, we have to restore the stack pointer from the frame descriptor.
73 // If we performed a VM call, the descriptor has been popped already so
74 // in that case we use the frame pointer.
75 if (calledIntoIon) {
76 masm.pop(scratch64.asUnsized());
77 masm.Lsr(scratch64, scratch64, FRAMESIZE_SHIFT);
78 masm.Add(masm.GetStackPointer64(), masm.GetStackPointer64(), scratch64);
79 } else {
80 masm.Mov(masm.GetStackPointer64(), BaselineFrameReg64);
81 }
82
83 // Pop values, discarding the frame descriptor.
84 masm.pop(BaselineFrameReg, ICStubReg, ICTailCallReg, scratch64.asUnsized());
85
86 // Stack should remain 16-byte aligned.
87 masm.checkStackAlignment();
88 }
89
90 template <typename AddrType>
EmitPreBarrier(MacroAssembler & masm,const AddrType & addr,MIRType type)91 inline void EmitPreBarrier(MacroAssembler& masm, const AddrType& addr,
92 MIRType type) {
93 // On AArch64, lr is clobbered by guardedCallPreBarrier. Save it first.
94 masm.push(lr);
95 masm.guardedCallPreBarrier(addr, type);
96 masm.pop(lr);
97 }
98
EmitStubGuardFailure(MacroAssembler & masm)99 inline void EmitStubGuardFailure(MacroAssembler& masm) {
100 // Load next stub into ICStubReg.
101 masm.loadPtr(Address(ICStubReg, ICStub::offsetOfNext()), ICStubReg);
102
103 // Return address is already loaded, just jump to the next stubcode.
104 masm.jump(Address(ICStubReg, ICStub::offsetOfStubCode()));
105 }
106
107 } // namespace jit
108 } // namespace js
109
110 #endif // jit_arm64_SharedICHelpers_arm64_h
111