From 56c8f65bc2a2707109bc220a083c45be1a9de45c Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 28 Feb 2016 23:27:22 +0100 Subject: [PATCH] JitArm64: Precheck for exceptions before calling PowerPC::CheckExceptions. --- Source/Core/Core/PowerPC/JitArm64/Jit.cpp | 52 +++++++++++++------- Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp | 3 ++ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index cb06916f42..07821bd0bf 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -207,48 +207,61 @@ void JitArm64::WriteExit(u32 destination) } 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)); - gpr.Unlock(dest); - Cleanup(); - DoDownCount(); - - if (Profiler::g_ProfileBlocks) - EndTimeProfile(js.curBlock); - - MOVI2R(EncodeRegTo64(dest), (u64)&PowerPC::CheckExceptions); - BLR(EncodeRegTo64(dest)); + 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)); - gpr.Unlock(dest); - Cleanup(); - DoDownCount(); - - if (Profiler::g_ProfileBlocks) - EndTimeProfile(js.curBlock); - - MOVI2R(EncodeRegTo64(dest), (u64)&PowerPC::CheckExternalExceptions); - BLR(EncodeRegTo64(dest)); + 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) { STR(INDEX_UNSIGNED, Reg, X29, PPCSTATE_OFF(pc)); - gpr.Unlock(Reg); Cleanup(); DoDownCount(); @@ -257,6 +270,7 @@ void JitArm64::WriteExitDestInR(ARM64Reg Reg) MOVI2R(EncodeRegTo64(Reg), (u64)asm_routines.dispatcher); BR(EncodeRegTo64(Reg)); + gpr.Unlock(Reg); } void JitArm64::DumpCode(const u8* start, const u8* end) diff --git a/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp b/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp index 73f2862f6d..fd99cae155 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp @@ -71,12 +71,15 @@ void JitArm64AsmRoutineManager::Generate() BLR(X30); // Does exception checking + LDR(INDEX_UNSIGNED, W0, X29, PPCSTATE_OFF(Exceptions)); + FixupBranch no_exceptions = CBZ(W0); LDR(INDEX_UNSIGNED, W0, X29, PPCSTATE_OFF(pc)); STR(INDEX_UNSIGNED, W0, X29, PPCSTATE_OFF(npc)); MOVI2R(X30, (u64)&PowerPC::CheckExceptions); BLR(X30); LDR(INDEX_UNSIGNED, W0, X29, PPCSTATE_OFF(npc)); STR(INDEX_UNSIGNED, W0, X29, PPCSTATE_OFF(pc)); + SetJumpTarget(no_exceptions); // Check the state pointer to see if we are exiting // Gets checked on every exception check