From c13ca271d8824305b6242a7e5458e54656cedafd Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 10 Jan 2023 01:19:56 +0100 Subject: [PATCH] PowerPC: Parametrize CTR macro. --- Source/Core/Core/PowerPC/GDBStub.cpp | 4 ++-- .../Core/PowerPC/Interpreter/Interpreter_Branch.cpp | 10 +++++----- Source/Core/Core/PowerPC/PowerPC.h | 2 +- Source/Core/DolphinQt/Debugger/CodeWidget.cpp | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/PowerPC/GDBStub.cpp b/Source/Core/Core/PowerPC/GDBStub.cpp index d47df62adc..b50fae172b 100644 --- a/Source/Core/Core/PowerPC/GDBStub.cpp +++ b/Source/Core/Core/PowerPC/GDBStub.cpp @@ -441,7 +441,7 @@ static void ReadRegister() wbe32hex(reply, LR(PowerPC::ppcState)); break; case 68: - wbe32hex(reply, CTR); + wbe32hex(reply, CTR(PowerPC::ppcState)); break; case 69: wbe32hex(reply, PowerPC::ppcState.spr[SPR_XER]); @@ -653,7 +653,7 @@ static void WriteRegister() LR(PowerPC::ppcState) = re32hex(bufptr); break; case 68: - CTR = re32hex(bufptr); + CTR(PowerPC::ppcState) = re32hex(bufptr); break; case 69: PowerPC::ppcState.spr[SPR_XER] = re32hex(bufptr); diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp index 53be542109..89a819b34c 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp @@ -29,12 +29,12 @@ void Interpreter::bx(UGeckoInstruction inst) void Interpreter::bcx(UGeckoInstruction inst) { if ((inst.BO & BO_DONT_DECREMENT_FLAG) == 0) - CTR--; + CTR(PowerPC::ppcState)--; const bool true_false = ((inst.BO >> 3) & 1) != 0; const bool only_counter_check = ((inst.BO >> 4) & 1) != 0; const bool only_condition_check = ((inst.BO >> 2) & 1) != 0; - const u32 ctr_check = ((CTR != 0) ^ (inst.BO >> 1)) & 1; + const u32 ctr_check = ((CTR(PowerPC::ppcState) != 0) ^ (inst.BO >> 1)) & 1; const bool counter = only_condition_check || ctr_check != 0; const bool condition = only_counter_check || (PowerPC::ppcState.cr.GetBit(inst.BI) == u32(true_false)); @@ -65,7 +65,7 @@ void Interpreter::bcctrx(UGeckoInstruction inst) if (condition != 0) { - PowerPC::ppcState.npc = CTR & (~3); + PowerPC::ppcState.npc = CTR(PowerPC::ppcState) & (~3); if (inst.LK_3) LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4; } @@ -76,9 +76,9 @@ void Interpreter::bcctrx(UGeckoInstruction inst) void Interpreter::bclrx(UGeckoInstruction inst) { if ((inst.BO_2 & BO_DONT_DECREMENT_FLAG) == 0) - CTR--; + CTR(PowerPC::ppcState)--; - const u32 counter = ((inst.BO_2 >> 2) | ((CTR != 0) ^ (inst.BO_2 >> 1))) & 1; + const u32 counter = ((inst.BO_2 >> 2) | ((CTR(PowerPC::ppcState) != 0) ^ (inst.BO_2 >> 1))) & 1; const u32 condition = ((inst.BO_2 >> 4) | (PowerPC::ppcState.cr.GetBit(inst.BI_2) == ((inst.BO_2 >> 3) & 1))) & 1; diff --git a/Source/Core/Core/PowerPC/PowerPC.h b/Source/Core/Core/PowerPC/PowerPC.h index 36518b5e27..e6dc31b965 100644 --- a/Source/Core/Core/PowerPC/PowerPC.h +++ b/Source/Core/Core/PowerPC/PowerPC.h @@ -247,7 +247,7 @@ void UpdatePerformanceMonitor(u32 cycles, u32 num_load_stores, u32 num_fp_inst); #define THRM3(ppc_state) ((UReg_THRM3&)(ppc_state).spr[SPR_THRM3]) #define LR(ppc_state) (ppc_state).spr[SPR_LR] -#define CTR PowerPC::ppcState.spr[SPR_CTR] +#define CTR(ppc_state) (ppc_state).spr[SPR_CTR] #define rDEC PowerPC::ppcState.spr[SPR_DEC] #define SRR0 PowerPC::ppcState.spr[SPR_SRR0] #define SRR1 PowerPC::ppcState.spr[SPR_SRR1] diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp index 64465dda00..b7bdba7786 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp @@ -471,7 +471,8 @@ static bool WillInstructionReturn(UGeckoInstruction inst) // Is a rfi instruction if (inst.hex == 0x4C000064u) return true; - bool counter = (inst.BO_2 >> 2 & 1) != 0 || (CTR != 0) != ((inst.BO_2 >> 1 & 1) != 0); + bool counter = + (inst.BO_2 >> 2 & 1) != 0 || (CTR(PowerPC::ppcState) != 0) != ((inst.BO_2 >> 1 & 1) != 0); bool condition = inst.BO_2 >> 4 != 0 || PowerPC::ppcState.cr.GetBit(inst.BI_2) == (inst.BO_2 >> 3 & 1); bool isBclr = inst.OPCD_7 == 0b010011 && (inst.hex >> 1 & 0b10000) != 0;