diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp index f104e223..a0abae1e 100644 --- a/src/backend_x64/emit_x64.cpp +++ b/src/backend_x64/emit_x64.cpp @@ -702,11 +702,11 @@ void EmitX64::EmitTerminalInterpret(IR::Term::Interpret terminal, Arm::LocationD code->MOV(32, MJitStateReg(Arm::Reg::PC), R(ABI_PARAM1)); code->MOV(64, R(RSP), MDisp(R15, offsetof(JitState, save_host_RSP))); code->ABI_CallFunction(reinterpret_cast(cb.InterpreterFallback)); - code->JMP(routines->RunCodeReturnAddress(), true); // TODO: Check cycles + routines->GenReturnFromRunCode(code); // TODO: Check cycles } void EmitX64::EmitTerminalReturnToDispatch(IR::Term::ReturnToDispatch, Arm::LocationDescriptor initial_location) { - code->JMP(routines->RunCodeReturnAddress(), true); + routines->GenReturnFromRunCode(code); } void EmitX64::EmitTerminalLinkBlock(IR::Term::LinkBlock terminal, Arm::LocationDescriptor initial_location) { @@ -714,7 +714,7 @@ void EmitX64::EmitTerminalLinkBlock(IR::Term::LinkBlock terminal, Arm::LocationD ASSERT_MSG(terminal.next.EFlag == initial_location.EFlag, "Unimplemented"); code->MOV(32, MJitStateReg(Arm::Reg::PC), Imm32(terminal.next.arm_pc)); - code->JMP(routines->RunCodeReturnAddress(), true); // TODO: Check cycles, Properly do a link + routines->GenReturnFromRunCode(code); // TODO: Check cycles, Properly do a link } void EmitX64::EmitTerminalLinkBlockFast(IR::Term::LinkBlockFast terminal, Arm::LocationDescriptor initial_location) { diff --git a/src/backend_x64/routines.cpp b/src/backend_x64/routines.cpp index 55c82b63..e570c24c 100644 --- a/src/backend_x64/routines.cpp +++ b/src/backend_x64/routines.cpp @@ -19,7 +19,6 @@ Routines::Routines() { AllocCodeSpace(1024); GenRunCode(); - GenReturnFromRunCode(); } size_t Routines::RunCode(JitState* jit_state, CodePtr basic_block, size_t cycles_to_run) const { @@ -30,10 +29,6 @@ size_t Routines::RunCode(JitState* jit_state, CodePtr basic_block, size_t cycles return cycles_to_run - jit_state->cycles_remaining; // Return number of cycles actually run. } -CodePtr Routines::RunCodeReturnAddress() const { - return return_from_run_code; -} - void Routines::GenRunCode() { run_code = reinterpret_cast(const_cast(this->GetCodePtr())); @@ -49,12 +44,10 @@ void Routines::GenRunCode() { JMPptr(R(ABI_PARAM2)); } -void Routines::GenReturnFromRunCode() { - return_from_run_code = this->GetCodePtr(); - - MOV(64, R(RSP), MDisp(R15, offsetof(JitState, save_host_RSP))); - ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); - RET(); +void Routines::GenReturnFromRunCode(XEmitter* code) const { + code->MOV(64, R(RSP), MDisp(R15, offsetof(JitState, save_host_RSP))); + code->ABI_PopRegistersAndAdjustStack(ABI_ALL_CALLEE_SAVED, 8); + code->RET(); } } // namespace BackendX64 diff --git a/src/backend_x64/routines.h b/src/backend_x64/routines.h index 0acb59eb..bd113dad 100644 --- a/src/backend_x64/routines.h +++ b/src/backend_x64/routines.h @@ -18,15 +18,12 @@ public: Routines(); size_t RunCode(JitState* jit_state, CodePtr basic_block, size_t cycles_to_run) const; - CodePtr RunCodeReturnAddress() const; + void GenReturnFromRunCode(Gen::XEmitter* code) const; private: using RunCodeFuncType = void(*)(JitState*, CodePtr); RunCodeFuncType run_code; void GenRunCode(); - - CodePtr return_from_run_code; - void GenReturnFromRunCode(); }; } // namespace BackendX64