Skip to content
Prev Previous commit
Next Next commit
32X GDB stub commit
  • Loading branch information
Genos3 committed May 14, 2025
commit 1369a3887bc863a96a73d9cb2cf0bd155a1c7646
11 changes: 4 additions & 7 deletions ares/component/processor/sh2/exceptions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <nall/gdb/server.hpp>

auto SH2::exceptionHandler() -> void {
if(!exceptions) return;
if(inDelaySlot()) { cyclesUntilRecompilerExit = 0; return; }
Expand Down Expand Up @@ -35,15 +33,14 @@ auto SH2::push(u32 data) -> void {
}

auto SH2::interrupt(u8 level, u8 vector) -> void {
nall::GDB::server.reportSignal(nall::GDB::Signal::TRAP, PC - 4);
push(SR);
push(PC - 4);
jump(readLong(VBR + vector * 4) + 4);
SR.I = level;
}

auto SH2::addressErrorCPU() -> void {
nall::GDB::server.reportSignal(nall::GDB::Signal::BUS, PC - 4);
GDB::server.reportSignal(GDB::Signal::BUS, PC - 4);
static constexpr u8 vector = 0x09;
SP &= ~3; //not accurate; but prevents infinite recursion
push(SR);
Expand All @@ -52,7 +49,7 @@ auto SH2::addressErrorCPU() -> void {
}

auto SH2::addressErrorDMA() -> void {
nall::GDB::server.reportSignal(nall::GDB::Signal::BUS, PC - 4);
GDB::server.reportSignal(GDB::Signal::BUS, PC - 4);
static constexpr u8 vector = 0x0a;
SP &= ~3; //not accurate; but prevents infinite recursion
push(SR);
Expand All @@ -62,7 +59,7 @@ auto SH2::addressErrorDMA() -> void {

auto SH2::illegalInstruction() -> void {
if(inDelaySlot()) return illegalSlotInstruction();
nall::GDB::server.reportSignal(nall::GDB::Signal::ILL, PC - 4);
GDB::server.reportSignal(GDB::Signal::ILL, PC - 4);
debug(unusual, "[SH2] illegal instruction: 0x", hex(busReadWord(PC - 4), 4L), " @ 0x", hex(PC - 4));
static constexpr u8 vector = 0x04;
push(SR);
Expand All @@ -71,7 +68,7 @@ auto SH2::illegalInstruction() -> void {
}

auto SH2::illegalSlotInstruction() -> void {
nall::GDB::server.reportSignal(nall::GDB::Signal::ILL, PC - 4);
GDB::server.reportSignal(GDB::Signal::ILL, PC - 4);
debug(unusual, "[SH2] illegal slot instruction: 0x", hex(busReadWord(PC - 4), 4L));
static constexpr u8 vector = 0x06;
push(SR);
Expand Down
1 change: 1 addition & 0 deletions ares/component/processor/sh2/sh2.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <nall/recompiler/generic/generic.hpp>
#include <nall/gdb/server.hpp>

//Hitachi SH-2

Expand Down
30 changes: 14 additions & 16 deletions ares/md/m32x/sh7604.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <nall/gdb/server.hpp>

auto M32X::SH7604::load(Node::Object parent, string name, string bootFile) -> void {
node = parent->append<Node::Object>(name);
if(auto fp = system.pak->read(bootFile)) {
Expand Down Expand Up @@ -46,10 +44,10 @@ auto M32X::SH7604::main() -> void {

if (m32x.shm.active()) {
if (m32x.vdp.vblank) {
nall::GDB::server.updateLoop();
GDB::server.updateLoop();
}

nall::GDB::server.reportPC(regs.PC);
GDB::server.reportPC(regs.PC);
}

SH2::instruction();
Expand Down Expand Up @@ -149,7 +147,7 @@ auto M32X::SH7604::syncM68k(bool force) -> void {

auto M32X::SH7604::busReadByte(u32 address) -> u32 {
if (m32x.shm.active()) {
nall::GDB::server.reportMemRead(address, 1);
GDB::server.reportMemRead(address, 1);
}
if(address & 1) {
return m32x.readInternal(0, 1, address & ~1).byte(0);
Expand All @@ -160,22 +158,22 @@ auto M32X::SH7604::busReadByte(u32 address) -> u32 {

auto M32X::SH7604::busReadWord(u32 address) -> u32 {
if (m32x.shm.active()) {
nall::GDB::server.reportMemRead(address, 2);
GDB::server.reportMemRead(address, 2);
}
return m32x.readInternal(1, 1, address & ~1);
}

auto M32X::SH7604::busReadLong(u32 address) -> u32 {
if (m32x.shm.active()) {
nall::GDB::server.reportMemRead(address, 4);
GDB::server.reportMemRead(address, 4);
}
u32 data = m32x.readInternal(1, 1, address & ~3 | 0) << 16;
return data | m32x.readInternal(1, 1, address & ~3 | 2) << 0;
}

auto M32X::SH7604::busWriteByte(u32 address, u32 data) -> void {
if (m32x.shm.active()) {
nall::GDB::server.reportMemWrite(address, 1);
GDB::server.reportMemWrite(address, 1);
}
debugger.tracer.instruction->invalidate(address & ~1);
if(address & 1) {
Expand All @@ -187,15 +185,15 @@ auto M32X::SH7604::busWriteByte(u32 address, u32 data) -> void {

auto M32X::SH7604::busWriteWord(u32 address, u32 data) -> void {
if (m32x.shm.active()) {
nall::GDB::server.reportMemWrite(address, 2);
GDB::server.reportMemWrite(address, 2);
}
debugger.tracer.instruction->invalidate(address & ~1);
m32x.writeInternal(1, 1, address & ~1, data);
}

auto M32X::SH7604::busWriteLong(u32 address, u32 data) -> void {
if (m32x.shm.active()) {
nall::GDB::server.reportMemWrite(address, 4);
GDB::server.reportMemWrite(address, 4);
}
debugger.tracer.instruction->invalidate(address & ~3 | 0);
debugger.tracer.instruction->invalidate(address & ~3 | 2);
Expand All @@ -206,13 +204,13 @@ auto M32X::SH7604::busWriteLong(u32 address, u32 data) -> void {
auto M32X::SH7604::initDebugHooks() -> void {

// See: https://sourceware.org/gdb/onlinedocs/gdb/Target-Description-Format.html#Target-Description-Format
nall::GDB::server.hooks.targetXML = []() -> string {
GDB::server.hooks.targetXML = []() -> string {
return "<target version=\"1.0\">"
"<architecture>sheb</architecture>"
"</target>";
};

nall::GDB::server.hooks.read = [](u64 address, u32 byteCount) -> string {
GDB::server.hooks.read = [](u64 address, u32 byteCount) -> string {
address = (s32)address;

string res{};
Expand All @@ -228,15 +226,15 @@ auto M32X::SH7604::initDebugHooks() -> void {
return res;
};

nall::GDB::server.hooks.regRead = [this](u32 regIdx) {
GDB::server.hooks.regRead = [this](u32 regIdx) {
if(regIdx < 16) {
return hex(regs.R[regIdx], 16, '0');
}

switch (regIdx)
{
case 16: { // PC
auto pcOverride = nall::GDB::server.getPcOverride();
auto pcOverride = GDB::server.getPcOverride();
return hex(pcOverride ? pcOverride.get() : regs.PC, 16, '0');
}
case 17: return hex(regs.PR, 16, '0');
Expand All @@ -255,10 +253,10 @@ auto M32X::SH7604::initDebugHooks() -> void {
return string{"0000000000000000"};
};

nall::GDB::server.hooks.regReadGeneral = []() {
GDB::server.hooks.regReadGeneral = []() {
string res{};
for(auto i : range(28)) {
res.append(nall::GDB::server.hooks.regRead(i));
res.append(GDB::server.hooks.regRead(i));
}
return res;
};
Expand Down
1 change: 1 addition & 0 deletions ares/md/md.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <component/audio/sn76489/sn76489.hpp>
#include <component/audio/ym2612/ym2612.hpp>
#include <component/eeprom/m24c/m24c.hpp>
#include <nall/gdb/server.hpp>

namespace ares::MegaDrive {
#include <ares/inline.hpp>
Expand Down