diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index 6494863349..5ab5b58e42 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -133,7 +133,7 @@ void JitArm64::HLEFunction(UGeckoInstruction inst) ARM64Reg WA = gpr.GetReg(); LDR(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(npc)); - WriteExitDestInR(WA); + WriteExit(WA); } void JitArm64::DoNothing(UGeckoInstruction inst) @@ -206,61 +206,7 @@ void JitArm64::WriteExit(u32 destination) b->linkData.push_back(linkData); } -void JitArm64::WriteExceptionExit(ARM64Reg dest) -{ - Cleanup(); - DoDownCount(); - - ARM64Reg WA = gpr.GetReg(); - LDR(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(Exceptions)); - STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(pc)); - FixupBranch no_exceptions = CBZ(WA); - gpr.Unlock(WA); - - STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(npc)); - MOVI2R(EncodeRegTo64(dest), (u64)&PowerPC::CheckExceptions); - BLR(EncodeRegTo64(dest)); - LDR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(npc)); - STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(pc)); - - SetJumpTarget(no_exceptions); - - if (Profiler::g_ProfileBlocks) - EndTimeProfile(js.curBlock); - - MOVI2R(EncodeRegTo64(dest), (u64)asm_routines.dispatcher); - BR(EncodeRegTo64(dest)); - - gpr.Unlock(dest); -} - -void JitArm64::WriteExternalExceptionExit(ARM64Reg dest) -{ - Cleanup(); - DoDownCount(); - - ARM64Reg WA = gpr.GetReg(); - LDR(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(Exceptions)); - STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(pc)); - FixupBranch no_exceptions = CBZ(WA); - gpr.Unlock(WA); - - STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(npc)); - MOVI2R(EncodeRegTo64(dest), (u64)&PowerPC::CheckExternalExceptions); - BLR(EncodeRegTo64(dest)); - LDR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(npc)); - STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(pc)); - SetJumpTarget(no_exceptions); - - if (Profiler::g_ProfileBlocks) - EndTimeProfile(js.curBlock); - - MOVI2R(EncodeRegTo64(dest), (u64)asm_routines.dispatcher); - BR(EncodeRegTo64(dest)); - gpr.Unlock(dest); -} - -void JitArm64::WriteExitDestInR(ARM64Reg Reg) +void JitArm64::WriteExit(ARM64Reg Reg) { STR(INDEX_UNSIGNED, Reg, X29, PPCSTATE_OFF(pc)); Cleanup(); @@ -274,6 +220,37 @@ void JitArm64::WriteExitDestInR(ARM64Reg Reg) gpr.Unlock(Reg); } +void JitArm64::WriteExceptionExit(ARM64Reg dest, bool only_external) +{ + Cleanup(); + DoDownCount(); + + ARM64Reg WA = gpr.GetReg(); + LDR(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(Exceptions)); + STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(pc)); + FixupBranch no_exceptions = CBZ(WA); + gpr.Unlock(WA); + + STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(npc)); + if (only_external) + MOVI2R(EncodeRegTo64(dest), (u64)&PowerPC::CheckExternalExceptions); + else + MOVI2R(EncodeRegTo64(dest), (u64)&PowerPC::CheckExceptions); + BLR(EncodeRegTo64(dest)); + LDR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(npc)); + STR(INDEX_UNSIGNED, dest, X29, PPCSTATE_OFF(pc)); + + SetJumpTarget(no_exceptions); + + if (Profiler::g_ProfileBlocks) + EndTimeProfile(js.curBlock); + + MOVI2R(EncodeRegTo64(dest), (u64)asm_routines.dispatcher); + BR(EncodeRegTo64(dest)); + + gpr.Unlock(dest); +} + void JitArm64::DumpCode(const u8* start, const u8* end) { std::string output = ""; @@ -517,7 +494,7 @@ const u8* JitArm64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitB gpr.Flush(FLUSH_MAINTAIN_STATE); fpr.Flush(FLUSH_MAINTAIN_STATE); MOVI2R(W30, ops[i].address); - WriteExternalExceptionExit(W30); + WriteExceptionExit(W30, true); SwitchToNearCode(); SetJumpTarget(exit); gpr.Unlock(W30); @@ -549,7 +526,7 @@ const u8* JitArm64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer *code_buf, JitB gpr.Flush(FLUSH_MAINTAIN_STATE); fpr.Flush(FLUSH_MAINTAIN_STATE); MOVI2R(WA, ops[i].address); - WriteExternalExceptionExit(WA); + WriteExceptionExit(WA, true); SwitchToNearCode(); SetJumpTarget(NoExtException); SetJumpTarget(exit); diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.h b/Source/Core/Core/PowerPC/JitArm64/Jit.h index e37589bf00..24c59949e3 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.h +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.h @@ -237,9 +237,8 @@ private: // Exits void WriteExit(u32 destination); - void WriteExceptionExit(Arm64Gen::ARM64Reg dest); - void WriteExternalExceptionExit(ARM64Reg dest); - void WriteExitDestInR(Arm64Gen::ARM64Reg dest); + void WriteExit(Arm64Gen::ARM64Reg dest); + void WriteExceptionExit(Arm64Gen::ARM64Reg dest, bool only_external = false); FixupBranch JumpIfCRFieldBit(int field, int bit, bool jump_if_set); diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Branch.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Branch.cpp index 66519bc3c6..dde534bd22 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_Branch.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_Branch.cpp @@ -213,7 +213,7 @@ void JitArm64::bcctrx(UGeckoInstruction inst) LDR(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(spr[SPR_CTR])); AND(WA, WA, 30, 29); // Wipe the bottom 2 bits. - WriteExitDestInR(WA); + WriteExit(WA); } void JitArm64::bclrx(UGeckoInstruction inst) @@ -261,7 +261,7 @@ void JitArm64::bclrx(UGeckoInstruction inst) gpr.Flush(FlushMode::FLUSH_MAINTAIN_STATE); fpr.Flush(FlushMode::FLUSH_MAINTAIN_STATE); - WriteExitDestInR(WA); + WriteExit(WA); SwitchToNearCode();