From 0a343007cb7f7b7a2003ad525c98bf6ce22d7142 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 10 Jan 2023 01:15:18 +0100 Subject: [PATCH] PowerPC: Parametrize LR macro. --- Source/Core/Core/Boot/Boot_BS2Emu.cpp | 2 +- Source/Core/Core/Debugger/Debugger_SymbolMap.cpp | 16 ++++++++++------ Source/Core/Core/GeckoCode.cpp | 4 ++-- Source/Core/Core/HLE/HLE_Misc.cpp | 4 ++-- Source/Core/Core/HLE/HLE_OS.cpp | 14 +++++++------- Source/Core/Core/HW/Memmap.cpp | 2 +- Source/Core/Core/PowerPC/GDBStub.cpp | 4 ++-- .../Core/PowerPC/Interpreter/Interpreter.cpp | 4 ++-- .../PowerPC/Interpreter/Interpreter_Branch.cpp | 10 +++++----- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 3 ++- Source/Core/Core/PowerPC/PowerPC.cpp | 2 +- Source/Core/Core/PowerPC/PowerPC.h | 2 +- Source/Core/VideoCommon/CommandProcessor.cpp | 2 +- 13 files changed, 37 insertions(+), 32 deletions(-) diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 02e02176a9..e8c0aa0b58 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -58,7 +58,7 @@ void PresetTimeBaseTicks() void CBoot::RunFunction(u32 address) { PowerPC::ppcState.pc = address; - LR = 0x00; + LR(PowerPC::ppcState) = 0x00; while (PowerPC::ppcState.pc != 0x00) PowerPC::SingleStep(); diff --git a/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp b/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp index 2283d368fd..87ba8f44df 100644 --- a/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp +++ b/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp @@ -71,7 +71,7 @@ bool GetCallstack(std::vector& output) if (!Core::IsRunning() || !PowerPC::HostIsRAMAddress(PowerPC::ppcState.gpr[1])) return false; - if (LR == 0) + if (LR(PowerPC::ppcState) == 0) { CallstackEntry entry; entry.Name = "(error: LR=0)"; @@ -81,8 +81,10 @@ bool GetCallstack(std::vector& output) } CallstackEntry entry; - entry.Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR), LR - 4); - entry.vAddress = LR - 4; + entry.Name = + fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR(PowerPC::ppcState)), + LR(PowerPC::ppcState) - 4); + entry.vAddress = LR(PowerPC::ppcState) - 4; output.push_back(entry); WalkTheStack([&entry, &output](u32 func_addr) { @@ -101,14 +103,16 @@ void PrintCallstack(Common::Log::LogType type, Common::Log::LogLevel level) { GENERIC_LOG_FMT(type, level, "== STACK TRACE - SP = {:08x} ==", PowerPC::ppcState.gpr[1]); - if (LR == 0) + if (LR(PowerPC::ppcState) == 0) { GENERIC_LOG_FMT(type, level, " LR = 0 - this is bad"); } - if (g_symbolDB.GetDescription(PowerPC::ppcState.pc) != g_symbolDB.GetDescription(LR)) + if (g_symbolDB.GetDescription(PowerPC::ppcState.pc) != + g_symbolDB.GetDescription(LR(PowerPC::ppcState))) { - GENERIC_LOG_FMT(type, level, " * {} [ LR = {:08x} ]", g_symbolDB.GetDescription(LR), LR); + GENERIC_LOG_FMT(type, level, " * {} [ LR = {:08x} ]", + g_symbolDB.GetDescription(LR(PowerPC::ppcState)), LR(PowerPC::ppcState)); } WalkTheStack([type, level](u32 func_addr) { diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index 7bcc1d6f27..dda7e1d345 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -270,7 +270,7 @@ void RunCodeHandler() // SP + 4 is reserved for the codehandler to save LR to the stack. PowerPC::HostWrite_U32(SFP, SP + 8); // Real stack frame PowerPC::HostWrite_U32(PowerPC::ppcState.pc, SP + 12); - PowerPC::HostWrite_U32(LR, SP + 16); + PowerPC::HostWrite_U32(LR(PowerPC::ppcState), SP + 16); PowerPC::HostWrite_U32(PowerPC::ppcState.cr.Get(), SP + 20); // Registers FPR0->13 are volatile for (int i = 0; i < 14; ++i) @@ -282,7 +282,7 @@ void RunCodeHandler() "GeckoCodes: Initiating phantom branch-and-link. " "PC = {:#010x}, SP = {:#010x}, SFP = {:#010x}", PowerPC::ppcState.pc, SP, SFP); - LR = HLE_TRAMPOLINE_ADDRESS; + LR(PowerPC::ppcState) = HLE_TRAMPOLINE_ADDRESS; PowerPC::ppcState.pc = PowerPC::ppcState.npc = ENTRY_POINT; } diff --git a/Source/Core/Core/HLE/HLE_Misc.cpp b/Source/Core/Core/HLE/HLE_Misc.cpp index 0b9c1783c4..48bd384b82 100644 --- a/Source/Core/Core/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/HLE/HLE_Misc.cpp @@ -17,7 +17,7 @@ namespace HLE_Misc // According to the PPC ABI, the return value is always in r3. void UnimplementedFunction() { - PowerPC::ppcState.npc = LR; + PowerPC::ppcState.npc = LR(PowerPC::ppcState); } void HBReload() @@ -59,7 +59,7 @@ void GeckoReturnTrampoline() u32 SP = PowerPC::ppcState.gpr[1]; PowerPC::ppcState.gpr[1] = PowerPC::HostRead_U32(SP + 8); PowerPC::ppcState.npc = PowerPC::HostRead_U32(SP + 12); - LR = PowerPC::HostRead_U32(SP + 16); + LR(PowerPC::ppcState) = PowerPC::HostRead_U32(SP + 16); PowerPC::ppcState.cr.Set(PowerPC::HostRead_U32(SP + 20)); for (int i = 0; i < 14; ++i) { diff --git a/Source/Core/Core/HLE/HLE_OS.cpp b/Source/Core/Core/HLE/HLE_OS.cpp index cb5a4947d5..8f98677e81 100644 --- a/Source/Core/Core/HLE/HLE_OS.cpp +++ b/Source/Core/Core/HLE/HLE_OS.cpp @@ -37,10 +37,10 @@ void HLE_OSPanic() StringPopBackIf(&msg, '\n'); PanicAlertFmt("OSPanic: {}: {}", error, msg); - ERROR_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| OSPanic: {}: {}", LR, PowerPC::ppcState.pc, error, - msg); + ERROR_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| OSPanic: {}: {}", LR(PowerPC::ppcState), + PowerPC::ppcState.pc, error, msg); - PowerPC::ppcState.npc = LR; + PowerPC::ppcState.npc = LR(PowerPC::ppcState); } // Generalized function for printing formatted string. @@ -80,7 +80,7 @@ void HLE_GeneralDebugPrint(ParameterType parameter_type) StringPopBackIf(&report_message, '\n'); - NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR, PowerPC::ppcState.pc, + NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR(PowerPC::ppcState), PowerPC::ppcState.pc, SHIFTJISToUTF8(report_message)); } @@ -117,7 +117,7 @@ void HLE_write_console() StringPopBackIf(&report_message, '\n'); - NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR, PowerPC::ppcState.pc, + NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR(PowerPC::ppcState), PowerPC::ppcState.pc, SHIFTJISToUTF8(report_message)); } @@ -129,7 +129,7 @@ void HLE_LogDPrint(ParameterType parameter_type) std::string report_message = GetStringVA(4, parameter_type); StringPopBackIf(&report_message, '\n'); - NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR, PowerPC::ppcState.pc, + NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR(PowerPC::ppcState), PowerPC::ppcState.pc, SHIFTJISToUTF8(report_message)); } @@ -169,7 +169,7 @@ void HLE_LogFPrint(ParameterType parameter_type) std::string report_message = GetStringVA(4, parameter_type); StringPopBackIf(&report_message, '\n'); - NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR, PowerPC::ppcState.pc, + NOTICE_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| {}", LR(PowerPC::ppcState), PowerPC::ppcState.pc, SHIFTJISToUTF8(report_message)); } diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index 4e458df0d2..e0350712e6 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -483,7 +483,7 @@ u8* MemoryManager::GetPointer(u32 address) const } PanicAlertFmt("Unknown Pointer {:#010x} PC {:#010x} LR {:#010x}", address, PowerPC::ppcState.pc, - LR); + LR(PowerPC::ppcState)); return nullptr; } diff --git a/Source/Core/Core/PowerPC/GDBStub.cpp b/Source/Core/Core/PowerPC/GDBStub.cpp index 6f3588a141..d47df62adc 100644 --- a/Source/Core/Core/PowerPC/GDBStub.cpp +++ b/Source/Core/Core/PowerPC/GDBStub.cpp @@ -438,7 +438,7 @@ static void ReadRegister() wbe32hex(reply, PowerPC::ppcState.cr.Get()); break; case 67: - wbe32hex(reply, LR); + wbe32hex(reply, LR(PowerPC::ppcState)); break; case 68: wbe32hex(reply, CTR); @@ -650,7 +650,7 @@ static void WriteRegister() PowerPC::ppcState.cr.Set(re32hex(bufptr)); break; case 67: - LR = re32hex(bufptr); + LR(PowerPC::ppcState) = re32hex(bufptr); break; case 68: CTR = re32hex(bufptr); diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index 70f46894ff..b13c858858 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -346,7 +346,7 @@ void Interpreter::unknown_instruction(UGeckoInstruction inst) NOTICE_LOG_FMT( POWERPC, "\nIntCPU: Unknown instruction {:08x} at PC = {:08x} last_PC = {:08x} LR = {:08x}\n", - inst.hex, PowerPC::ppcState.pc, last_pc, LR); + inst.hex, PowerPC::ppcState.pc, last_pc, LR(PowerPC::ppcState)); for (int i = 0; i < 32; i += 4) { NOTICE_LOG_FMT(POWERPC, "r{}: {:#010x} r{}: {:#010x} r{}: {:#010x} r{}: {:#010x}", i, @@ -355,7 +355,7 @@ void Interpreter::unknown_instruction(UGeckoInstruction inst) } ASSERT_MSG(POWERPC, 0, "\nIntCPU: Unknown instruction {:08x} at PC = {:08x} last_PC = {:08x} LR = {:08x}\n", - inst.hex, PowerPC::ppcState.pc, last_pc, LR); + inst.hex, PowerPC::ppcState.pc, last_pc, LR(PowerPC::ppcState)); if (Core::System::GetInstance().IsPauseOnPanicMode()) CPU::Break(); } diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp index c6a9155735..53be542109 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_Branch.cpp @@ -13,7 +13,7 @@ void Interpreter::bx(UGeckoInstruction inst) { if (inst.LK) - LR = PowerPC::ppcState.pc + 4; + LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4; const auto address = u32(SignExt26(inst.LI << 2)); @@ -42,7 +42,7 @@ void Interpreter::bcx(UGeckoInstruction inst) if (counter && condition) { if (inst.LK) - LR = PowerPC::ppcState.pc + 4; + LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4; const auto address = u32(SignExt16(s16(inst.BD << 2))); @@ -67,7 +67,7 @@ void Interpreter::bcctrx(UGeckoInstruction inst) { PowerPC::ppcState.npc = CTR & (~3); if (inst.LK_3) - LR = PowerPC::ppcState.pc + 4; + LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4; } m_end_block = true; @@ -84,9 +84,9 @@ void Interpreter::bclrx(UGeckoInstruction inst) if ((counter & condition) != 0) { - PowerPC::ppcState.npc = LR & (~3); + PowerPC::ppcState.npc = LR(PowerPC::ppcState) & (~3); if (inst.LK_3) - LR = PowerPC::ppcState.pc + 4; + LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4; } m_end_block = true; diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 7747f426c3..2a2d62b6b5 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -512,7 +512,8 @@ static void ImHere() if ((been_here.find(PowerPC::ppcState.pc)->second) & 1023) return; } - INFO_LOG_FMT(DYNA_REC, "I'm here - PC = {:08x} , LR = {:08x}", PowerPC::ppcState.pc, LR); + INFO_LOG_FMT(DYNA_REC, "I'm here - PC = {:08x} , LR = {:08x}", PowerPC::ppcState.pc, + LR(PowerPC::ppcState)); been_here[PowerPC::ppcState.pc] = 1; } diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index c430d03881..a9e1b2bc89 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -646,7 +646,7 @@ void CheckBreakPoints() PowerPC::ppcState.gpr[3], PowerPC::ppcState.gpr[4], PowerPC::ppcState.gpr[5], PowerPC::ppcState.gpr[6], PowerPC::ppcState.gpr[7], PowerPC::ppcState.gpr[8], PowerPC::ppcState.gpr[9], PowerPC::ppcState.gpr[10], PowerPC::ppcState.gpr[11], - PowerPC::ppcState.gpr[12], LR); + PowerPC::ppcState.gpr[12], LR(PowerPC::ppcState)); } if (PowerPC::breakpoints.IsTempBreakPoint(PowerPC::ppcState.pc)) PowerPC::breakpoints.Remove(PowerPC::ppcState.pc); diff --git a/Source/Core/Core/PowerPC/PowerPC.h b/Source/Core/Core/PowerPC/PowerPC.h index 9c1d5cba94..36518b5e27 100644 --- a/Source/Core/Core/PowerPC/PowerPC.h +++ b/Source/Core/Core/PowerPC/PowerPC.h @@ -246,7 +246,7 @@ void UpdatePerformanceMonitor(u32 cycles, u32 num_load_stores, u32 num_fp_inst); #define THRM2(ppc_state) ((UReg_THRM12&)(ppc_state).spr[SPR_THRM2]) #define THRM3(ppc_state) ((UReg_THRM3&)(ppc_state).spr[SPR_THRM3]) -#define LR PowerPC::ppcState.spr[SPR_LR] +#define LR(ppc_state) (ppc_state).spr[SPR_LR] #define CTR PowerPC::ppcState.spr[SPR_CTR] #define rDEC PowerPC::ppcState.spr[SPR_DEC] #define SRR0 PowerPC::ppcState.spr[SPR_SRR0] diff --git a/Source/Core/VideoCommon/CommandProcessor.cpp b/Source/Core/VideoCommon/CommandProcessor.cpp index 2e329ba285..7baeb5c020 100644 --- a/Source/Core/VideoCommon/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/CommandProcessor.cpp @@ -685,7 +685,7 @@ void CommandProcessorManager::HandleUnknownOpcode(u8 cmd_byte, const u8* buffer, fifo.bFF_GPLinkEnable.load(std::memory_order_relaxed) ? "true" : "false", fifo.bFF_HiWatermarkInt.load(std::memory_order_relaxed) ? "true" : "false", fifo.bFF_LoWatermarkInt.load(std::memory_order_relaxed) ? "true" : "false", - PowerPC::ppcState.pc, LR); + PowerPC::ppcState.pc, LR(PowerPC::ppcState)); if (!m_is_fifo_error_seen && !suppress_panic_alert) {