From 2aa250a68ab8fa35584d3ccb2d3fb2ccf367ef12 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Thu, 7 Dec 2023 09:32:58 -0800 Subject: [PATCH] Interpreter: Install BranchWatch --- .../Interpreter/Interpreter_Branch.cpp | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp index 8b5bac0509..1d57d971b4 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp @@ -7,6 +7,7 @@ #include "Common/CommonTypes.h" #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/Debugger/BranchWatch.h" #include "Core/HLE/HLE.h" #include "Core/PowerPC/Interpreter/ExceptionUtils.h" #include "Core/PowerPC/PowerPC.h" @@ -19,12 +20,13 @@ void Interpreter::bx(Interpreter& interpreter, UGeckoInstruction inst) if (inst.LK) LR(ppc_state) = ppc_state.pc + 4; - const auto address = u32(SignExt26(inst.LI << 2)); + u32 destination_addr = u32(SignExt26(inst.LI << 2)); + if (!inst.AA) + destination_addr += ppc_state.pc; + ppc_state.npc = destination_addr; - if (inst.AA) - ppc_state.npc = address; - else - ppc_state.npc = ppc_state.pc + address; + if (auto& branch_watch = interpreter.m_branch_watch; branch_watch.GetRecordingActive()) + branch_watch.HitTrue(ppc_state.pc, destination_addr, inst, ppc_state.msr.IR); interpreter.m_end_block = true; } @@ -33,6 +35,7 @@ void Interpreter::bx(Interpreter& interpreter, UGeckoInstruction inst) void Interpreter::bcx(Interpreter& interpreter, UGeckoInstruction inst) { auto& ppc_state = interpreter.m_ppc_state; + auto& branch_watch = interpreter.m_branch_watch; if ((inst.BO & BO_DONT_DECREMENT_FLAG) == 0) CTR(ppc_state)--; @@ -49,12 +52,17 @@ void Interpreter::bcx(Interpreter& interpreter, UGeckoInstruction inst) if (inst.LK) LR(ppc_state) = ppc_state.pc + 4; - const auto address = u32(SignExt16(s16(inst.BD << 2))); + u32 destination_addr = u32(SignExt16(s16(inst.BD << 2))); + if (!inst.AA) + destination_addr += ppc_state.pc; + ppc_state.npc = destination_addr; - if (inst.AA) - ppc_state.npc = address; - else - ppc_state.npc = ppc_state.pc + address; + if (branch_watch.GetRecordingActive()) + branch_watch.HitTrue(ppc_state.pc, destination_addr, inst, ppc_state.msr.IR); + } + else if (branch_watch.GetRecordingActive()) + { + branch_watch.HitFalse(ppc_state.pc, ppc_state.pc + 4, inst, ppc_state.msr.IR); } interpreter.m_end_block = true; @@ -63,6 +71,7 @@ void Interpreter::bcx(Interpreter& interpreter, UGeckoInstruction inst) void Interpreter::bcctrx(Interpreter& interpreter, UGeckoInstruction inst) { auto& ppc_state = interpreter.m_ppc_state; + auto& branch_watch = interpreter.m_branch_watch; DEBUG_ASSERT_MSG(POWERPC, (inst.BO_2 & BO_DONT_DECREMENT_FLAG) != 0, "bcctrx with decrement and test CTR option is invalid!"); @@ -72,9 +81,17 @@ void Interpreter::bcctrx(Interpreter& interpreter, UGeckoInstruction inst) if (condition != 0) { - ppc_state.npc = CTR(ppc_state) & (~3); + const u32 destination_addr = CTR(ppc_state) & (~3); + ppc_state.npc = destination_addr; if (inst.LK_3) LR(ppc_state) = ppc_state.pc + 4; + + if (branch_watch.GetRecordingActive()) + branch_watch.HitTrue(ppc_state.pc, destination_addr, inst, ppc_state.msr.IR); + } + else if (branch_watch.GetRecordingActive()) + { + branch_watch.HitFalse(ppc_state.pc, ppc_state.pc + 4, inst, ppc_state.msr.IR); } interpreter.m_end_block = true; @@ -83,6 +100,7 @@ void Interpreter::bcctrx(Interpreter& interpreter, UGeckoInstruction inst) void Interpreter::bclrx(Interpreter& interpreter, UGeckoInstruction inst) { auto& ppc_state = interpreter.m_ppc_state; + auto& branch_watch = interpreter.m_branch_watch; if ((inst.BO_2 & BO_DONT_DECREMENT_FLAG) == 0) CTR(ppc_state)--; @@ -93,9 +111,17 @@ void Interpreter::bclrx(Interpreter& interpreter, UGeckoInstruction inst) if ((counter & condition) != 0) { - ppc_state.npc = LR(ppc_state) & (~3); + const u32 destination_addr = LR(ppc_state) & (~3); + ppc_state.npc = destination_addr; if (inst.LK_3) LR(ppc_state) = ppc_state.pc + 4; + + if (branch_watch.GetRecordingActive()) + branch_watch.HitTrue(ppc_state.pc, destination_addr, inst, ppc_state.msr.IR); + } + else if (branch_watch.GetRecordingActive()) + { + branch_watch.HitFalse(ppc_state.pc, ppc_state.pc + 4, inst, ppc_state.msr.IR); } interpreter.m_end_block = true;