diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 79d920a1d1..ce63b2e3c4 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -16,6 +16,7 @@ #endif #include "Common/CommonTypes.h" +#include "Common/EnumUtils.h" #include "Common/GekkoDisassembler.h" #include "Common/IOFile.h" #include "Common/Logging/Log.h" @@ -1035,6 +1036,30 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) } else { + auto& cpu = m_system.GetCPU(); + auto& power_pc = m_system.GetPowerPC(); + if (m_enable_debugging && power_pc.GetBreakPoints().IsAddressBreakPoint(op.address) && + !cpu.IsStepping()) + { + gpr.Flush(); + fpr.Flush(); + + MOV(32, PPCSTATE(pc), Imm32(op.address)); + ABI_PushRegistersAndAdjustStack({}, 0); + ABI_CallFunctionP(PowerPC::CheckBreakPointsFromJIT, &power_pc); + ABI_PopRegistersAndAdjustStack({}, 0); + MOV(64, R(RSCRATCH), ImmPtr(cpu.GetStatePtr())); + CMP(32, MatR(RSCRATCH), Imm32(Common::ToUnderlying(CPU::State::Running))); + FixupBranch noBreakpoint = J_CC(CC_E); + + Cleanup(); + MOV(32, PPCSTATE(npc), Imm32(op.address)); + SUB(32, PPCSTATE(downcount), Imm32(js.downcountAmount)); + JMP(asm_routines.dispatcher_exit, Jump::Near); + + SetJumpTarget(noBreakpoint); + } + if ((opinfo->flags & FL_USE_FPU) && !js.firstFPInstructionFound) { // This instruction uses FPU - needs to add FP exception bailout @@ -1061,30 +1086,6 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) js.firstFPInstructionFound = true; } - auto& cpu = m_system.GetCPU(); - auto& power_pc = m_system.GetPowerPC(); - if (m_enable_debugging && power_pc.GetBreakPoints().IsAddressBreakPoint(op.address) && - !cpu.IsStepping()) - { - gpr.Flush(); - fpr.Flush(); - - MOV(32, PPCSTATE(pc), Imm32(op.address)); - ABI_PushRegistersAndAdjustStack({}, 0); - ABI_CallFunctionP(PowerPC::CheckBreakPointsFromJIT, &power_pc); - ABI_PopRegistersAndAdjustStack({}, 0); - MOV(64, R(RSCRATCH), ImmPtr(cpu.GetStatePtr())); - TEST(32, MatR(RSCRATCH), Imm32(0xFFFFFFFF)); - FixupBranch noBreakpoint = J_CC(CC_Z); - - Cleanup(); - MOV(32, PPCSTATE(npc), Imm32(op.address)); - SUB(32, PPCSTATE(downcount), Imm32(js.downcountAmount)); - JMP(asm_routines.dispatcher_exit, Jump::Near); - - SetJumpTarget(noBreakpoint); - } - if (bJITRegisterCacheOff) { gpr.Flush(); diff --git a/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp b/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp index 7b0e3e8242..e5afb50e07 100644 --- a/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp +++ b/Source/Core/Core/PowerPC/Jit64/JitAsm.cpp @@ -6,6 +6,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/EnumUtils.h" #include "Common/JitRegister.h" #include "Common/x64ABI.h" #include "Common/x64Emitter.h" @@ -105,8 +106,8 @@ void Jit64AsmRoutineManager::Generate() if (enable_debugging) { MOV(64, R(RSCRATCH), ImmPtr(system.GetCPU().GetStatePtr())); - TEST(32, MatR(RSCRATCH), Imm32(0xFFFFFFFF)); - dbg_exit = J_CC(CC_NZ, Jump::Near); + CMP(32, MatR(RSCRATCH), Imm32(Common::ToUnderlying(CPU::State::Running))); + dbg_exit = J_CC(CC_NE, Jump::Near); } SetJumpTarget(skipToRealDispatch); @@ -236,8 +237,8 @@ void Jit64AsmRoutineManager::Generate() // Check the state pointer to see if we are exiting // Gets checked on at the end of every slice MOV(64, R(RSCRATCH), ImmPtr(system.GetCPU().GetStatePtr())); - TEST(32, MatR(RSCRATCH), Imm32(0xFFFFFFFF)); - J_CC(CC_Z, outerLoop); + CMP(32, MatR(RSCRATCH), Imm32(Common::ToUnderlying(CPU::State::Running))); + J_CC(CC_E, outerLoop); // Landing pad for drec space dispatcher_exit = GetCodePtr(); diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index cf30f546c7..6db978402f 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -8,6 +8,7 @@ #include "Common/Arm64Emitter.h" #include "Common/CommonTypes.h" +#include "Common/EnumUtils.h" #include "Common/Logging/Log.h" #include "Common/MathUtil.h" #include "Common/MsgHandler.h" @@ -1239,6 +1240,37 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) } else { + if (m_enable_debugging && !cpu.IsStepping() && + m_system.GetPowerPC().GetBreakPoints().IsAddressBreakPoint(op.address)) + { + FlushCarry(); + gpr.Flush(FlushMode::All, ARM64Reg::INVALID_REG); + fpr.Flush(FlushMode::All, ARM64Reg::INVALID_REG); + + static_assert(PPCSTATE_OFF(pc) <= 252); + static_assert(PPCSTATE_OFF(pc) + 4 == PPCSTATE_OFF(npc)); + + MOVI2R(DISPATCHER_PC, op.address); + STP(IndexType::Signed, DISPATCHER_PC, DISPATCHER_PC, PPC_REG, PPCSTATE_OFF(pc)); + ABI_CallFunction(&PowerPC::CheckBreakPointsFromJIT, &m_system.GetPowerPC()); + + LDR(IndexType::Unsigned, ARM64Reg::W0, ARM64Reg::X0, + MOVPage2R(ARM64Reg::X0, cpu.GetStatePtr())); + static_assert(Common::ToUnderlying(CPU::State::Running) == 0); + FixupBranch no_breakpoint = CBZ(ARM64Reg::W0); + + Cleanup(); + if (IsProfilingEnabled()) + { + ABI_CallFunction(&JitBlock::ProfileData::EndProfiling, b->profile_data.get(), + js.downcountAmount); + } + DoDownCount(); + B(dispatcher_exit); + + SetJumpTarget(no_breakpoint); + } + if ((opinfo->flags & FL_USE_FPU) && !js.firstFPInstructionFound) { // This instruction uses FPU - needs to add FP exception bailout @@ -1268,36 +1300,6 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) js.firstFPInstructionFound = true; } - if (m_enable_debugging && !cpu.IsStepping() && - m_system.GetPowerPC().GetBreakPoints().IsAddressBreakPoint(op.address)) - { - FlushCarry(); - gpr.Flush(FlushMode::All, ARM64Reg::INVALID_REG); - fpr.Flush(FlushMode::All, ARM64Reg::INVALID_REG); - - static_assert(PPCSTATE_OFF(pc) <= 252); - static_assert(PPCSTATE_OFF(pc) + 4 == PPCSTATE_OFF(npc)); - - MOVI2R(DISPATCHER_PC, op.address); - STP(IndexType::Signed, DISPATCHER_PC, DISPATCHER_PC, PPC_REG, PPCSTATE_OFF(pc)); - ABI_CallFunction(&PowerPC::CheckBreakPointsFromJIT, &m_system.GetPowerPC()); - - LDR(IndexType::Unsigned, ARM64Reg::W0, ARM64Reg::X0, - MOVPage2R(ARM64Reg::X0, cpu.GetStatePtr())); - FixupBranch no_breakpoint = CBZ(ARM64Reg::W0); - - Cleanup(); - if (IsProfilingEnabled()) - { - ABI_CallFunction(&JitBlock::ProfileData::EndProfiling, b->profile_data.get(), - js.downcountAmount); - } - DoDownCount(); - B(dispatcher_exit); - - SetJumpTarget(no_breakpoint); - } - if (bJITRegisterCacheOff) { FlushCarry(); diff --git a/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp b/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp index 250107a7af..56c26739a3 100644 --- a/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp @@ -9,6 +9,7 @@ #include "Common/Arm64Emitter.h" #include "Common/CommonTypes.h" #include "Common/Config/Config.h" +#include "Common/EnumUtils.h" #include "Common/FloatUtils.h" #include "Common/JitRegister.h" #include "Common/MathUtil.h" @@ -88,6 +89,7 @@ void JitArm64::GenerateAsm() { LDR(IndexType::Unsigned, ARM64Reg::W8, ARM64Reg::X8, MOVPage2R(ARM64Reg::X8, cpu.GetStatePtr())); + static_assert(Common::ToUnderlying(CPU::State::Running) == 0); debug_exit = CBNZ(ARM64Reg::W8); } @@ -195,6 +197,7 @@ void JitArm64::GenerateAsm() // Check the state pointer to see if we are exiting // Gets checked on at the end of every slice LDR(IndexType::Unsigned, ARM64Reg::W8, ARM64Reg::X8, MOVPage2R(ARM64Reg::X8, cpu.GetStatePtr())); + static_assert(Common::ToUnderlying(CPU::State::Running) == 0); FixupBranch exit = CBNZ(ARM64Reg::W8); SetJumpTarget(to_start_of_timing_slice);