GDBStub: Avoid ppcState global.

This commit is contained in:
Admiral H. Curtiss 2023-01-10 19:20:15 +01:00
parent dd9907ed93
commit be2d394b8c
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
1 changed files with 123 additions and 104 deletions

View File

@ -397,6 +397,9 @@ static u64 re64hex(u8* p)
static void ReadRegister() static void ReadRegister()
{ {
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
static u8 reply[64]; static u8 reply[64];
u32 id; u32 id;
@ -410,161 +413,161 @@ static void ReadRegister()
if (id < 32) if (id < 32)
{ {
wbe32hex(reply, PowerPC::ppcState.gpr[id]); wbe32hex(reply, ppc_state.gpr[id]);
} }
else if (id >= 32 && id < 64) else if (id >= 32 && id < 64)
{ {
wbe64hex(reply, PowerPC::ppcState.ps[id - 32].PS0AsU64()); wbe64hex(reply, ppc_state.ps[id - 32].PS0AsU64());
} }
else if (id >= 71 && id < 87) else if (id >= 71 && id < 87)
{ {
wbe32hex(reply, PowerPC::ppcState.sr[id - 71]); wbe32hex(reply, ppc_state.sr[id - 71]);
} }
else if (id >= 88 && id < 104) else if (id >= 88 && id < 104)
{ {
wbe32hex(reply, PowerPC::ppcState.spr[SPR_IBAT0U + id - 88]); wbe32hex(reply, ppc_state.spr[SPR_IBAT0U + id - 88]);
} }
else else
{ {
switch (id) switch (id)
{ {
case 64: case 64:
wbe32hex(reply, PowerPC::ppcState.pc); wbe32hex(reply, ppc_state.pc);
break; break;
case 65: case 65:
wbe32hex(reply, PowerPC::ppcState.msr.Hex); wbe32hex(reply, ppc_state.msr.Hex);
break; break;
case 66: case 66:
wbe32hex(reply, PowerPC::ppcState.cr.Get()); wbe32hex(reply, ppc_state.cr.Get());
break; break;
case 67: case 67:
wbe32hex(reply, LR(PowerPC::ppcState)); wbe32hex(reply, LR(ppc_state));
break; break;
case 68: case 68:
wbe32hex(reply, CTR(PowerPC::ppcState)); wbe32hex(reply, CTR(ppc_state));
break; break;
case 69: case 69:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_XER]); wbe32hex(reply, ppc_state.spr[SPR_XER]);
break; break;
case 70: case 70:
wbe32hex(reply, PowerPC::ppcState.fpscr.Hex); wbe32hex(reply, ppc_state.fpscr.Hex);
break; break;
case 87: case 87:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_PVR]); wbe32hex(reply, ppc_state.spr[SPR_PVR]);
break; break;
case 104: case 104:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SDR]); wbe32hex(reply, ppc_state.spr[SPR_SDR]);
break; break;
case 105: case 105:
wbe64hex(reply, PowerPC::ppcState.spr[SPR_ASR]); wbe64hex(reply, ppc_state.spr[SPR_ASR]);
break; break;
case 106: case 106:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_DAR]); wbe32hex(reply, ppc_state.spr[SPR_DAR]);
break; break;
case 107: case 107:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_DSISR]); wbe32hex(reply, ppc_state.spr[SPR_DSISR]);
break; break;
case 108: case 108:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SPRG0]); wbe32hex(reply, ppc_state.spr[SPR_SPRG0]);
break; break;
case 109: case 109:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SPRG1]); wbe32hex(reply, ppc_state.spr[SPR_SPRG1]);
break; break;
case 110: case 110:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SPRG2]); wbe32hex(reply, ppc_state.spr[SPR_SPRG2]);
break; break;
case 111: case 111:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SPRG3]); wbe32hex(reply, ppc_state.spr[SPR_SPRG3]);
break; break;
case 112: case 112:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SRR0]); wbe32hex(reply, ppc_state.spr[SPR_SRR0]);
break; break;
case 113: case 113:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SRR1]); wbe32hex(reply, ppc_state.spr[SPR_SRR1]);
break; break;
case 114: case 114:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_TL]); wbe32hex(reply, ppc_state.spr[SPR_TL]);
break; break;
case 115: case 115:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_TU]); wbe32hex(reply, ppc_state.spr[SPR_TU]);
break; break;
case 116: case 116:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_DEC]); wbe32hex(reply, ppc_state.spr[SPR_DEC]);
break; break;
case 117: case 117:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_DABR]); wbe32hex(reply, ppc_state.spr[SPR_DABR]);
break; break;
case 118: case 118:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_EAR]); wbe32hex(reply, ppc_state.spr[SPR_EAR]);
break; break;
case 119: case 119:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_HID0]); wbe32hex(reply, ppc_state.spr[SPR_HID0]);
break; break;
case 120: case 120:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_HID1]); wbe32hex(reply, ppc_state.spr[SPR_HID1]);
break; break;
case 121: case 121:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_IABR]); wbe32hex(reply, ppc_state.spr[SPR_IABR]);
break; break;
case 122: case 122:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_DABR]); wbe32hex(reply, ppc_state.spr[SPR_DABR]);
break; break;
case 124: case 124:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_UMMCR0]); wbe32hex(reply, ppc_state.spr[SPR_UMMCR0]);
break; break;
case 125: case 125:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_UPMC1]); wbe32hex(reply, ppc_state.spr[SPR_UPMC1]);
break; break;
case 126: case 126:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_UPMC2]); wbe32hex(reply, ppc_state.spr[SPR_UPMC2]);
break; break;
case 127: case 127:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_USIA]); wbe32hex(reply, ppc_state.spr[SPR_USIA]);
break; break;
case 128: case 128:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_UMMCR1]); wbe32hex(reply, ppc_state.spr[SPR_UMMCR1]);
break; break;
case 129: case 129:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_UPMC3]); wbe32hex(reply, ppc_state.spr[SPR_UPMC3]);
break; break;
case 130: case 130:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_UPMC4]); wbe32hex(reply, ppc_state.spr[SPR_UPMC4]);
break; break;
case 131: case 131:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_MMCR0]); wbe32hex(reply, ppc_state.spr[SPR_MMCR0]);
break; break;
case 132: case 132:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_PMC1]); wbe32hex(reply, ppc_state.spr[SPR_PMC1]);
break; break;
case 133: case 133:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_PMC2]); wbe32hex(reply, ppc_state.spr[SPR_PMC2]);
break; break;
case 134: case 134:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_SIA]); wbe32hex(reply, ppc_state.spr[SPR_SIA]);
break; break;
case 135: case 135:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_MMCR1]); wbe32hex(reply, ppc_state.spr[SPR_MMCR1]);
break; break;
case 136: case 136:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_PMC3]); wbe32hex(reply, ppc_state.spr[SPR_PMC3]);
break; break;
case 137: case 137:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_PMC4]); wbe32hex(reply, ppc_state.spr[SPR_PMC4]);
break; break;
case 138: case 138:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_L2CR]); wbe32hex(reply, ppc_state.spr[SPR_L2CR]);
break; break;
case 139: case 139:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_ICTC]); wbe32hex(reply, ppc_state.spr[SPR_ICTC]);
break; break;
case 140: case 140:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_THRM1]); wbe32hex(reply, ppc_state.spr[SPR_THRM1]);
break; break;
case 141: case 141:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_THRM2]); wbe32hex(reply, ppc_state.spr[SPR_THRM2]);
break; break;
case 142: case 142:
wbe32hex(reply, PowerPC::ppcState.spr[SPR_THRM3]); wbe32hex(reply, ppc_state.spr[SPR_THRM3]);
break; break;
default: default:
return SendReply("E01"); return SendReply("E01");
@ -577,6 +580,9 @@ static void ReadRegister()
static void ReadRegisters() static void ReadRegisters()
{ {
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
static u8 bfr[GDB_BFR_MAX - 4]; static u8 bfr[GDB_BFR_MAX - 4];
u8* bufptr = bfr; u8* bufptr = bfr;
u32 i; u32 i;
@ -585,7 +591,7 @@ static void ReadRegisters()
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
wbe32hex(bufptr + i * 8, PowerPC::ppcState.gpr[i]); wbe32hex(bufptr + i * 8, ppc_state.gpr[i]);
} }
bufptr += 32 * 8; bufptr += 32 * 8;
@ -594,12 +600,15 @@ static void ReadRegisters()
static void WriteRegisters() static void WriteRegisters()
{ {
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
u32 i; u32 i;
u8* bufptr = s_cmd_bfr; u8* bufptr = s_cmd_bfr;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
PowerPC::ppcState.gpr[i] = re32hex(bufptr + i * 8); ppc_state.gpr[i] = re32hex(bufptr + i * 8);
} }
bufptr += 32 * 8; bufptr += 32 * 8;
@ -608,6 +617,9 @@ static void WriteRegisters()
static void WriteRegister() static void WriteRegister()
{ {
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
u32 id; u32 id;
u8* bufptr = s_cmd_bfr + 3; u8* bufptr = s_cmd_bfr + 3;
@ -622,161 +634,161 @@ static void WriteRegister()
if (id < 32) if (id < 32)
{ {
PowerPC::ppcState.gpr[id] = re32hex(bufptr); ppc_state.gpr[id] = re32hex(bufptr);
} }
else if (id >= 32 && id < 64) else if (id >= 32 && id < 64)
{ {
PowerPC::ppcState.ps[id - 32].SetPS0(re64hex(bufptr)); ppc_state.ps[id - 32].SetPS0(re64hex(bufptr));
} }
else if (id >= 71 && id < 87) else if (id >= 71 && id < 87)
{ {
PowerPC::ppcState.sr[id - 71] = re32hex(bufptr); ppc_state.sr[id - 71] = re32hex(bufptr);
} }
else if (id >= 88 && id < 104) else if (id >= 88 && id < 104)
{ {
PowerPC::ppcState.spr[SPR_IBAT0U + id - 88] = re32hex(bufptr); ppc_state.spr[SPR_IBAT0U + id - 88] = re32hex(bufptr);
} }
else else
{ {
switch (id) switch (id)
{ {
case 64: case 64:
PowerPC::ppcState.pc = re32hex(bufptr); ppc_state.pc = re32hex(bufptr);
break; break;
case 65: case 65:
PowerPC::ppcState.msr.Hex = re32hex(bufptr); ppc_state.msr.Hex = re32hex(bufptr);
break; break;
case 66: case 66:
PowerPC::ppcState.cr.Set(re32hex(bufptr)); ppc_state.cr.Set(re32hex(bufptr));
break; break;
case 67: case 67:
LR(PowerPC::ppcState) = re32hex(bufptr); LR(ppc_state) = re32hex(bufptr);
break; break;
case 68: case 68:
CTR(PowerPC::ppcState) = re32hex(bufptr); CTR(ppc_state) = re32hex(bufptr);
break; break;
case 69: case 69:
PowerPC::ppcState.spr[SPR_XER] = re32hex(bufptr); ppc_state.spr[SPR_XER] = re32hex(bufptr);
break; break;
case 70: case 70:
PowerPC::ppcState.fpscr.Hex = re32hex(bufptr); ppc_state.fpscr.Hex = re32hex(bufptr);
break; break;
case 87: case 87:
PowerPC::ppcState.spr[SPR_PVR] = re32hex(bufptr); ppc_state.spr[SPR_PVR] = re32hex(bufptr);
break; break;
case 104: case 104:
PowerPC::ppcState.spr[SPR_SDR] = re32hex(bufptr); ppc_state.spr[SPR_SDR] = re32hex(bufptr);
break; break;
case 105: case 105:
PowerPC::ppcState.spr[SPR_ASR] = re64hex(bufptr); ppc_state.spr[SPR_ASR] = re64hex(bufptr);
break; break;
case 106: case 106:
PowerPC::ppcState.spr[SPR_DAR] = re32hex(bufptr); ppc_state.spr[SPR_DAR] = re32hex(bufptr);
break; break;
case 107: case 107:
PowerPC::ppcState.spr[SPR_DSISR] = re32hex(bufptr); ppc_state.spr[SPR_DSISR] = re32hex(bufptr);
break; break;
case 108: case 108:
PowerPC::ppcState.spr[SPR_SPRG0] = re32hex(bufptr); ppc_state.spr[SPR_SPRG0] = re32hex(bufptr);
break; break;
case 109: case 109:
PowerPC::ppcState.spr[SPR_SPRG1] = re32hex(bufptr); ppc_state.spr[SPR_SPRG1] = re32hex(bufptr);
break; break;
case 110: case 110:
PowerPC::ppcState.spr[SPR_SPRG2] = re32hex(bufptr); ppc_state.spr[SPR_SPRG2] = re32hex(bufptr);
break; break;
case 111: case 111:
PowerPC::ppcState.spr[SPR_SPRG3] = re32hex(bufptr); ppc_state.spr[SPR_SPRG3] = re32hex(bufptr);
break; break;
case 112: case 112:
PowerPC::ppcState.spr[SPR_SRR0] = re32hex(bufptr); ppc_state.spr[SPR_SRR0] = re32hex(bufptr);
break; break;
case 113: case 113:
PowerPC::ppcState.spr[SPR_SRR1] = re32hex(bufptr); ppc_state.spr[SPR_SRR1] = re32hex(bufptr);
break; break;
case 114: case 114:
PowerPC::ppcState.spr[SPR_TL] = re32hex(bufptr); ppc_state.spr[SPR_TL] = re32hex(bufptr);
break; break;
case 115: case 115:
PowerPC::ppcState.spr[SPR_TU] = re32hex(bufptr); ppc_state.spr[SPR_TU] = re32hex(bufptr);
break; break;
case 116: case 116:
PowerPC::ppcState.spr[SPR_DEC] = re32hex(bufptr); ppc_state.spr[SPR_DEC] = re32hex(bufptr);
break; break;
case 117: case 117:
PowerPC::ppcState.spr[SPR_DABR] = re32hex(bufptr); ppc_state.spr[SPR_DABR] = re32hex(bufptr);
break; break;
case 118: case 118:
PowerPC::ppcState.spr[SPR_EAR] = re32hex(bufptr); ppc_state.spr[SPR_EAR] = re32hex(bufptr);
break; break;
case 119: case 119:
PowerPC::ppcState.spr[SPR_HID0] = re32hex(bufptr); ppc_state.spr[SPR_HID0] = re32hex(bufptr);
break; break;
case 120: case 120:
PowerPC::ppcState.spr[SPR_HID1] = re32hex(bufptr); ppc_state.spr[SPR_HID1] = re32hex(bufptr);
break; break;
case 121: case 121:
PowerPC::ppcState.spr[SPR_IABR] = re32hex(bufptr); ppc_state.spr[SPR_IABR] = re32hex(bufptr);
break; break;
case 122: case 122:
PowerPC::ppcState.spr[SPR_DABR] = re32hex(bufptr); ppc_state.spr[SPR_DABR] = re32hex(bufptr);
break; break;
case 124: case 124:
PowerPC::ppcState.spr[SPR_UMMCR0] = re32hex(bufptr); ppc_state.spr[SPR_UMMCR0] = re32hex(bufptr);
break; break;
case 125: case 125:
PowerPC::ppcState.spr[SPR_UPMC1] = re32hex(bufptr); ppc_state.spr[SPR_UPMC1] = re32hex(bufptr);
break; break;
case 126: case 126:
PowerPC::ppcState.spr[SPR_UPMC2] = re32hex(bufptr); ppc_state.spr[SPR_UPMC2] = re32hex(bufptr);
break; break;
case 127: case 127:
PowerPC::ppcState.spr[SPR_USIA] = re32hex(bufptr); ppc_state.spr[SPR_USIA] = re32hex(bufptr);
break; break;
case 128: case 128:
PowerPC::ppcState.spr[SPR_UMMCR1] = re32hex(bufptr); ppc_state.spr[SPR_UMMCR1] = re32hex(bufptr);
break; break;
case 129: case 129:
PowerPC::ppcState.spr[SPR_UPMC3] = re32hex(bufptr); ppc_state.spr[SPR_UPMC3] = re32hex(bufptr);
break; break;
case 130: case 130:
PowerPC::ppcState.spr[SPR_UPMC4] = re32hex(bufptr); ppc_state.spr[SPR_UPMC4] = re32hex(bufptr);
break; break;
case 131: case 131:
PowerPC::ppcState.spr[SPR_MMCR0] = re32hex(bufptr); ppc_state.spr[SPR_MMCR0] = re32hex(bufptr);
break; break;
case 132: case 132:
PowerPC::ppcState.spr[SPR_PMC1] = re32hex(bufptr); ppc_state.spr[SPR_PMC1] = re32hex(bufptr);
break; break;
case 133: case 133:
PowerPC::ppcState.spr[SPR_PMC2] = re32hex(bufptr); ppc_state.spr[SPR_PMC2] = re32hex(bufptr);
break; break;
case 134: case 134:
PowerPC::ppcState.spr[SPR_SIA] = re32hex(bufptr); ppc_state.spr[SPR_SIA] = re32hex(bufptr);
break; break;
case 135: case 135:
PowerPC::ppcState.spr[SPR_MMCR1] = re32hex(bufptr); ppc_state.spr[SPR_MMCR1] = re32hex(bufptr);
break; break;
case 136: case 136:
PowerPC::ppcState.spr[SPR_PMC3] = re32hex(bufptr); ppc_state.spr[SPR_PMC3] = re32hex(bufptr);
break; break;
case 137: case 137:
PowerPC::ppcState.spr[SPR_PMC4] = re32hex(bufptr); ppc_state.spr[SPR_PMC4] = re32hex(bufptr);
break; break;
case 138: case 138:
PowerPC::ppcState.spr[SPR_L2CR] = re32hex(bufptr); ppc_state.spr[SPR_L2CR] = re32hex(bufptr);
break; break;
case 139: case 139:
PowerPC::ppcState.spr[SPR_ICTC] = re32hex(bufptr); ppc_state.spr[SPR_ICTC] = re32hex(bufptr);
break; break;
case 140: case 140:
PowerPC::ppcState.spr[SPR_THRM1] = re32hex(bufptr); ppc_state.spr[SPR_THRM1] = re32hex(bufptr);
break; break;
case 141: case 141:
PowerPC::ppcState.spr[SPR_THRM2] = re32hex(bufptr); ppc_state.spr[SPR_THRM2] = re32hex(bufptr);
break; break;
case 142: case 142:
PowerPC::ppcState.spr[SPR_THRM3] = re32hex(bufptr); ppc_state.spr[SPR_THRM3] = re32hex(bufptr);
break; break;
default: default:
return SendReply("E01"); return SendReply("E01");
@ -981,10 +993,14 @@ void ProcessCommands(bool loop_until_continue)
ReadMemory(); ReadMemory();
break; break;
case 'M': case 'M':
{
WriteMemory(); WriteMemory();
PowerPC::ppcState.iCache.Reset(); auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
ppc_state.iCache.Reset();
Host_UpdateDisasmDialog(); Host_UpdateDisasmDialog();
break; break;
}
case 's': case 's':
Step(); Step();
return; return;
@ -1121,9 +1137,12 @@ bool JustConnected()
void SendSignal(Signal signal) void SendSignal(Signal signal)
{ {
auto& system = Core::System::GetInstance();
auto& ppc_state = system.GetPPCState();
char bfr[128] = {}; char bfr[128] = {};
fmt::format_to(bfr, "T{:02x}{:02x}:{:08x};{:02x}:{:08x};", static_cast<u8>(signal), 64, fmt::format_to(bfr, "T{:02x}{:02x}:{:08x};{:02x}:{:08x};", static_cast<u8>(signal), 64,
PowerPC::ppcState.pc, 1, PowerPC::ppcState.gpr[1]); ppc_state.pc, 1, ppc_state.gpr[1]);
SendReply(bfr); SendReply(bfr);
} }
} // namespace GDBStub } // namespace GDBStub