From 52268298a8280655f85f737a55bceff365e2e71b Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 27 Jan 2018 22:44:17 +0000 Subject: [PATCH] a64_emit_x64: Perform RSB predictions --- src/backend_x64/a64_emit_x64.cpp | 19 +++++++++++++++++-- .../translate/impl/exception_generating.cpp | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/backend_x64/a64_emit_x64.cpp b/src/backend_x64/a64_emit_x64.cpp index 98c25cb8..6e0d4df8 100644 --- a/src/backend_x64/a64_emit_x64.cpp +++ b/src/backend_x64/a64_emit_x64.cpp @@ -488,8 +488,23 @@ void A64EmitX64::EmitTerminalImpl(IR::Term::LinkBlockFast terminal, IR::Location } } -void A64EmitX64::EmitTerminalImpl(IR::Term::PopRSBHint, IR::LocationDescriptor initial_location) { - EmitTerminalImpl(IR::Term::ReturnToDispatch{}, initial_location); +void A64EmitX64::EmitTerminalImpl(IR::Term::PopRSBHint, IR::LocationDescriptor) { + // This calculation has to match up with A64::LocationDescriptor::UniqueHash + // TODO: Optimization is available here based on known state of FPSCR_mode and CPSR_et. + code->mov(rcx, qword[r15 + offsetof(A64JitState, pc)]); + code->mov(ebx, dword[r15 + offsetof(A64JitState, fpcr)]); + code->and_(ebx, A64::LocationDescriptor::FPCR_MASK); + code->shl(ebx, 37); + code->or_(rbx, rcx); + + code->mov(eax, dword[r15 + offsetof(A64JitState, rsb_ptr)]); + code->sub(eax, 1); + code->and_(eax, u32(A64JitState::RSBPtrMask)); + code->mov(dword[r15 + offsetof(A64JitState, rsb_ptr)], eax); + code->cmp(rbx, qword[r15 + offsetof(A64JitState, rsb_location_descriptors) + rax * sizeof(u64)]); + code->jne(code->GetReturnFromRunCodeAddress()); + code->mov(rax, qword[r15 + offsetof(A64JitState, rsb_codeptrs) + rax * sizeof(u64)]); + code->jmp(rax); } void A64EmitX64::EmitTerminalImpl(IR::Term::If terminal, IR::LocationDescriptor initial_location) { diff --git a/src/frontend/A64/translate/impl/exception_generating.cpp b/src/frontend/A64/translate/impl/exception_generating.cpp index 3b6ccf9a..a00fc0cb 100644 --- a/src/frontend/A64/translate/impl/exception_generating.cpp +++ b/src/frontend/A64/translate/impl/exception_generating.cpp @@ -9,7 +9,7 @@ namespace Dynarmic::A64 { bool TranslatorVisitor::SVC(Imm<16> imm16) { - // ir.PushRSB(ir.current_location.AdvancePC(4)); // TODO + ir.PushRSB(ir.current_location.AdvancePC(4)); ir.SetPC(ir.Imm64(ir.current_location.PC() + 4)); ir.CallSupervisor(imm16.ZeroExtend()); ir.SetTerm(IR::Term::CheckHalt{IR::Term::PopRSBHint{}});