PowerPC: Parametrize LR macro.

This commit is contained in:
Admiral H. Curtiss 2023-01-10 01:15:18 +01:00
parent 0f301829d2
commit 0a343007cb
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
13 changed files with 37 additions and 32 deletions

View File

@ -58,7 +58,7 @@ void PresetTimeBaseTicks()
void CBoot::RunFunction(u32 address) void CBoot::RunFunction(u32 address)
{ {
PowerPC::ppcState.pc = address; PowerPC::ppcState.pc = address;
LR = 0x00; LR(PowerPC::ppcState) = 0x00;
while (PowerPC::ppcState.pc != 0x00) while (PowerPC::ppcState.pc != 0x00)
PowerPC::SingleStep(); PowerPC::SingleStep();

View File

@ -71,7 +71,7 @@ bool GetCallstack(std::vector<CallstackEntry>& output)
if (!Core::IsRunning() || !PowerPC::HostIsRAMAddress(PowerPC::ppcState.gpr[1])) if (!Core::IsRunning() || !PowerPC::HostIsRAMAddress(PowerPC::ppcState.gpr[1]))
return false; return false;
if (LR == 0) if (LR(PowerPC::ppcState) == 0)
{ {
CallstackEntry entry; CallstackEntry entry;
entry.Name = "(error: LR=0)"; entry.Name = "(error: LR=0)";
@ -81,8 +81,10 @@ bool GetCallstack(std::vector<CallstackEntry>& output)
} }
CallstackEntry entry; CallstackEntry entry;
entry.Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR), LR - 4); entry.Name =
entry.vAddress = LR - 4; 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); output.push_back(entry);
WalkTheStack([&entry, &output](u32 func_addr) { 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]); 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"); 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) { WalkTheStack([type, level](u32 func_addr) {

View File

@ -270,7 +270,7 @@ void RunCodeHandler()
// SP + 4 is reserved for the codehandler to save LR to the stack. // 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(SFP, SP + 8); // Real stack frame
PowerPC::HostWrite_U32(PowerPC::ppcState.pc, SP + 12); 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); PowerPC::HostWrite_U32(PowerPC::ppcState.cr.Get(), SP + 20);
// Registers FPR0->13 are volatile // Registers FPR0->13 are volatile
for (int i = 0; i < 14; ++i) for (int i = 0; i < 14; ++i)
@ -282,7 +282,7 @@ void RunCodeHandler()
"GeckoCodes: Initiating phantom branch-and-link. " "GeckoCodes: Initiating phantom branch-and-link. "
"PC = {:#010x}, SP = {:#010x}, SFP = {:#010x}", "PC = {:#010x}, SP = {:#010x}, SFP = {:#010x}",
PowerPC::ppcState.pc, SP, SFP); PowerPC::ppcState.pc, SP, SFP);
LR = HLE_TRAMPOLINE_ADDRESS; LR(PowerPC::ppcState) = HLE_TRAMPOLINE_ADDRESS;
PowerPC::ppcState.pc = PowerPC::ppcState.npc = ENTRY_POINT; PowerPC::ppcState.pc = PowerPC::ppcState.npc = ENTRY_POINT;
} }

View File

@ -17,7 +17,7 @@ namespace HLE_Misc
// According to the PPC ABI, the return value is always in r3. // According to the PPC ABI, the return value is always in r3.
void UnimplementedFunction() void UnimplementedFunction()
{ {
PowerPC::ppcState.npc = LR; PowerPC::ppcState.npc = LR(PowerPC::ppcState);
} }
void HBReload() void HBReload()
@ -59,7 +59,7 @@ void GeckoReturnTrampoline()
u32 SP = PowerPC::ppcState.gpr[1]; u32 SP = PowerPC::ppcState.gpr[1];
PowerPC::ppcState.gpr[1] = PowerPC::HostRead_U32(SP + 8); PowerPC::ppcState.gpr[1] = PowerPC::HostRead_U32(SP + 8);
PowerPC::ppcState.npc = PowerPC::HostRead_U32(SP + 12); 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)); PowerPC::ppcState.cr.Set(PowerPC::HostRead_U32(SP + 20));
for (int i = 0; i < 14; ++i) for (int i = 0; i < 14; ++i)
{ {

View File

@ -37,10 +37,10 @@ void HLE_OSPanic()
StringPopBackIf(&msg, '\n'); StringPopBackIf(&msg, '\n');
PanicAlertFmt("OSPanic: {}: {}", error, msg); PanicAlertFmt("OSPanic: {}: {}", error, msg);
ERROR_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| OSPanic: {}: {}", LR, PowerPC::ppcState.pc, error, ERROR_LOG_FMT(OSREPORT_HLE, "{:08x}->{:08x}| OSPanic: {}: {}", LR(PowerPC::ppcState),
msg); PowerPC::ppcState.pc, error, msg);
PowerPC::ppcState.npc = LR; PowerPC::ppcState.npc = LR(PowerPC::ppcState);
} }
// Generalized function for printing formatted string. // Generalized function for printing formatted string.
@ -80,7 +80,7 @@ void HLE_GeneralDebugPrint(ParameterType parameter_type)
StringPopBackIf(&report_message, '\n'); 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)); SHIFTJISToUTF8(report_message));
} }
@ -117,7 +117,7 @@ void HLE_write_console()
StringPopBackIf(&report_message, '\n'); 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)); SHIFTJISToUTF8(report_message));
} }
@ -129,7 +129,7 @@ void HLE_LogDPrint(ParameterType parameter_type)
std::string report_message = GetStringVA(4, parameter_type); std::string report_message = GetStringVA(4, parameter_type);
StringPopBackIf(&report_message, '\n'); 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)); SHIFTJISToUTF8(report_message));
} }
@ -169,7 +169,7 @@ void HLE_LogFPrint(ParameterType parameter_type)
std::string report_message = GetStringVA(4, parameter_type); std::string report_message = GetStringVA(4, parameter_type);
StringPopBackIf(&report_message, '\n'); 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)); SHIFTJISToUTF8(report_message));
} }

View File

@ -483,7 +483,7 @@ u8* MemoryManager::GetPointer(u32 address) const
} }
PanicAlertFmt("Unknown Pointer {:#010x} PC {:#010x} LR {:#010x}", address, PowerPC::ppcState.pc, PanicAlertFmt("Unknown Pointer {:#010x} PC {:#010x} LR {:#010x}", address, PowerPC::ppcState.pc,
LR); LR(PowerPC::ppcState));
return nullptr; return nullptr;
} }

View File

@ -438,7 +438,7 @@ static void ReadRegister()
wbe32hex(reply, PowerPC::ppcState.cr.Get()); wbe32hex(reply, PowerPC::ppcState.cr.Get());
break; break;
case 67: case 67:
wbe32hex(reply, LR); wbe32hex(reply, LR(PowerPC::ppcState));
break; break;
case 68: case 68:
wbe32hex(reply, CTR); wbe32hex(reply, CTR);
@ -650,7 +650,7 @@ static void WriteRegister()
PowerPC::ppcState.cr.Set(re32hex(bufptr)); PowerPC::ppcState.cr.Set(re32hex(bufptr));
break; break;
case 67: case 67:
LR = re32hex(bufptr); LR(PowerPC::ppcState) = re32hex(bufptr);
break; break;
case 68: case 68:
CTR = re32hex(bufptr); CTR = re32hex(bufptr);

View File

@ -346,7 +346,7 @@ void Interpreter::unknown_instruction(UGeckoInstruction inst)
NOTICE_LOG_FMT( NOTICE_LOG_FMT(
POWERPC, POWERPC,
"\nIntCPU: Unknown instruction {:08x} at PC = {:08x} last_PC = {:08x} LR = {:08x}\n", "\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) for (int i = 0; i < 32; i += 4)
{ {
NOTICE_LOG_FMT(POWERPC, "r{}: {:#010x} r{}: {:#010x} r{}: {:#010x} r{}: {:#010x}", i, 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, ASSERT_MSG(POWERPC, 0,
"\nIntCPU: Unknown instruction {:08x} at PC = {:08x} last_PC = {:08x} LR = {:08x}\n", "\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()) if (Core::System::GetInstance().IsPauseOnPanicMode())
CPU::Break(); CPU::Break();
} }

View File

@ -13,7 +13,7 @@
void Interpreter::bx(UGeckoInstruction inst) void Interpreter::bx(UGeckoInstruction inst)
{ {
if (inst.LK) if (inst.LK)
LR = PowerPC::ppcState.pc + 4; LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4;
const auto address = u32(SignExt26(inst.LI << 2)); const auto address = u32(SignExt26(inst.LI << 2));
@ -42,7 +42,7 @@ void Interpreter::bcx(UGeckoInstruction inst)
if (counter && condition) if (counter && condition)
{ {
if (inst.LK) if (inst.LK)
LR = PowerPC::ppcState.pc + 4; LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4;
const auto address = u32(SignExt16(s16(inst.BD << 2))); const auto address = u32(SignExt16(s16(inst.BD << 2)));
@ -67,7 +67,7 @@ void Interpreter::bcctrx(UGeckoInstruction inst)
{ {
PowerPC::ppcState.npc = CTR & (~3); PowerPC::ppcState.npc = CTR & (~3);
if (inst.LK_3) if (inst.LK_3)
LR = PowerPC::ppcState.pc + 4; LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4;
} }
m_end_block = true; m_end_block = true;
@ -84,9 +84,9 @@ void Interpreter::bclrx(UGeckoInstruction inst)
if ((counter & condition) != 0) if ((counter & condition) != 0)
{ {
PowerPC::ppcState.npc = LR & (~3); PowerPC::ppcState.npc = LR(PowerPC::ppcState) & (~3);
if (inst.LK_3) if (inst.LK_3)
LR = PowerPC::ppcState.pc + 4; LR(PowerPC::ppcState) = PowerPC::ppcState.pc + 4;
} }
m_end_block = true; m_end_block = true;

View File

@ -512,7 +512,8 @@ static void ImHere()
if ((been_here.find(PowerPC::ppcState.pc)->second) & 1023) if ((been_here.find(PowerPC::ppcState.pc)->second) & 1023)
return; 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; been_here[PowerPC::ppcState.pc] = 1;
} }

View File

@ -646,7 +646,7 @@ void CheckBreakPoints()
PowerPC::ppcState.gpr[3], PowerPC::ppcState.gpr[4], PowerPC::ppcState.gpr[5], 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[6], PowerPC::ppcState.gpr[7], PowerPC::ppcState.gpr[8],
PowerPC::ppcState.gpr[9], PowerPC::ppcState.gpr[10], PowerPC::ppcState.gpr[11], 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)) if (PowerPC::breakpoints.IsTempBreakPoint(PowerPC::ppcState.pc))
PowerPC::breakpoints.Remove(PowerPC::ppcState.pc); PowerPC::breakpoints.Remove(PowerPC::ppcState.pc);

View File

@ -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 THRM2(ppc_state) ((UReg_THRM12&)(ppc_state).spr[SPR_THRM2])
#define THRM3(ppc_state) ((UReg_THRM3&)(ppc_state).spr[SPR_THRM3]) #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 CTR PowerPC::ppcState.spr[SPR_CTR]
#define rDEC PowerPC::ppcState.spr[SPR_DEC] #define rDEC PowerPC::ppcState.spr[SPR_DEC]
#define SRR0 PowerPC::ppcState.spr[SPR_SRR0] #define SRR0 PowerPC::ppcState.spr[SPR_SRR0]

View File

@ -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_GPLinkEnable.load(std::memory_order_relaxed) ? "true" : "false",
fifo.bFF_HiWatermarkInt.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", 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) if (!m_is_fifo_error_seen && !suppress_panic_alert)
{ {