Cemu/src/Cafe/HW/Espresso/Interpreter/PPCInterpreterOPC.hpp
Crementif 6d75776b28
Add GDB stub for debugging (#657)
* Implement GDB stub debugger

Can be enabled by using the "--enable-gdbstub" option (and the debugger GUI, although that's untested) which'll pause any game you launch at start-up. Will start at port 1337 although it'll eventually be user-editable. The code is a bit weirdly sorted and also just needs a general cleanup, so expect that eventually too. And uses egyptian braces but formatting was easier to do at the end, so that's also something to do.

It has been tested to work with IDA Pro, Clion and the standalone interface for now, but I plan on writing some instructions in the PR to follow for people who want to use this. Memory breakpoints aren't possible yet, only execution breakpoints.

This code was aimed to be decoupled from the existing debugger to be able to be ported to the Wii U for an equal debugging experience. That's also why it uses the Cafe OS's thread sleep and resuming functions whenever possible instead of using recompiler/interpreter controls.

* Add memory writing and floating point registers support

* Reformat code a bit

* Format code to adhere to Cemu's coding style

* Rework GDB Stub settings in GUI

* Small styling fixes

* Rework execution breakpoints

Should work better in some edge cases now. But this should also allow for adding access breakpoints since it's now more separated.

* Implement access breakpoints

* Fix some issues with breakpoints

* Fix includes for Linux

* Fix unnecessary include

* Tweaks for Linux compatibility

* Use std::thread instead of std::jthread to fix MacOS support

* Enable GDB read/write breakpoints on x86 only

* Fix compilation for GCC compilers at least

The thread type varies on some platforms, so supporting this is hell... but let's get it to compile on MacOS first.

* Disable them for MacOS due to lack of ptrace

---------

Co-authored-by: Exzap <13877693+Exzap@users.noreply.github.com>
2023-02-19 15:41:49 +01:00

76 lines
1.8 KiB
C++

static void PPCInterpreter_MFSPR(PPCInterpreter_t* hCPU, uint32 opcode)
{
uint32 rD, spr1, spr2, spr;
PPC_OPC_TEMPL_XO(opcode, rD, spr1, spr2);
spr = spr1 | (spr2 << 5);
// copy SPR
hCPU->gpr[rD] = PPCSpr_get(hCPU, spr);
// next instruction
PPCInterpreter_nextInstruction(hCPU);
}
static void PPCInterpreter_MTSPR(PPCInterpreter_t* hCPU, uint32 opcode)
{
uint32 rD, spr1, spr2, spr;
PPC_OPC_TEMPL_XO(opcode, rD, spr1, spr2);
spr = spr1 | (spr2 << 5);
PPCSpr_set(hCPU, spr, hCPU->gpr[rD]);
// next instruction
PPCInterpreter_nextInstruction(hCPU);
}
static void PPCInterpreter_MFSR(PPCInterpreter_t* hCPU, uint32 opcode)
{
uint32 rD, SR, rB;
PPC_OPC_TEMPL_X(opcode, rD, SR, rB);
hCPU->gpr[rD] = getSR(hCPU, SR & 0xF);
// next instruction
PPCInterpreter_nextInstruction(hCPU);
}
static void PPCInterpreter_MTSR(PPCInterpreter_t* hCPU, uint32 opcode)
{
uint32 rS, SR, rB;
PPC_OPC_TEMPL_X(opcode, rS, SR, rB);
setSR(hCPU, SR&0xF, hCPU->gpr[rS]);
// next instruction
PPCInterpreter_nextInstruction(hCPU);
}
static void PPCInterpreter_MFTB(PPCInterpreter_t* hCPU, uint32 opcode)
{
uint32 rD, spr1, spr2, spr;
// get SPR ID
PPC_OPC_TEMPL_XO(opcode, rD, spr1, spr2);
spr = spr1 | (spr2 << 5);
// get core cycle counter
uint64 coreTime = ppcItpCtrl::getTB(hCPU);
switch (spr)
{
case 268: // TBL
hCPU->gpr[rD] = (uint32)(coreTime & 0xFFFFFFFF);
break;
case 269: // TBU
hCPU->gpr[rD] = (uint32)((coreTime >> 32) & 0xFFFFFFFF);
break;
default:
assert_dbg();
}
// next instruction
PPCInterpreter_nextInstruction(hCPU);
}
static void PPCInterpreter_TW(PPCInterpreter_t* hCPU, uint32 opcode)
{
sint32 to, rA, rB;
PPC_OPC_TEMPL_X(opcode, to, rA, rB);
cemu_assert_debug(to == 0);
if (rA == DEBUGGER_BP_T_DEBUGGER)
debugger_enterTW(hCPU);
else if (rA == DEBUGGER_BP_T_GDBSTUB)
g_gdbstub->HandleTrapInstruction(hCPU);
}