Skip to content

Commit

Permalink
Messing about with mapping our local registers on to valid x86 ones. …
Browse files Browse the repository at this point in the history
…So we can use x86 clients. Just that A = eax, X = ecx, Y = edx, SP = esp, PC = eip and SR = eflags. It could just work :D
  • Loading branch information
nacnud-sco committed May 7, 2024
1 parent d0cfd96 commit 62eee19
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
52 changes: 36 additions & 16 deletions Src/BeebWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5339,16 +5339,36 @@ void BeebWin::OpenDebugWindow()

#pragma once

constexpr uint8_t REG_PC = 0;
constexpr uint8_t REG_A = 1;
constexpr uint8_t REG_X = 2;
constexpr uint8_t REG_Y = 3;
constexpr uint8_t REG_SP = 4;
constexpr uint8_t REG_SR = 5;
constexpr uint8_t REG_COUNT = 6;
enum class REG_INDEX : uint8_t {
REG_A = 0, // eax
REG_X = 1, // ecx
REG_Y = 2, // edx
// ebx
REG_SP = 4, // esp
// ebp, esi, edi
REG_PC = 8, // eip
REG_SR = 9, // eflags
};

static uint8_t localRegisters[REG_COUNT] = { REG_PC, REG_A, REG_X, REG_Y, REG_SP, REG_SR };
bool isValidRegIndex(uint8_t value) {
REG_INDEX valueToTest = static_cast<REG_INDEX>(value);
if (valueToTest == REG_INDEX::REG_A ||
valueToTest == REG_INDEX::REG_X ||
valueToTest == REG_INDEX::REG_Y ||
valueToTest == REG_INDEX::REG_SP ||
valueToTest == REG_INDEX::REG_PC ||
valueToTest == REG_INDEX::REG_SR ) {
return true;
} else {
return false;
}
}

uint8_t getIntValueFrom(REG_INDEX reg) {
return static_cast<uint8_t>(reg);
}

static uint8_t localRegisters[GdbServer::REG_ARRAY_LEN] = { 0, 1, 2, 255, 3, 255, 255, 255, 4, 5 };
static uint8_t m_localMemory[(1014 * 1024) * 20] {};

class _6502SimControl : public ISimulationControl {
Expand Down Expand Up @@ -5440,16 +5460,16 @@ void _6502SimControl::removeBreakpoint(unsigned addr) {

// Register access
uint32_t _6502SimControl::readReg(std::size_t num) {
if (num < REG_COUNT) {

if (isValidRegIndex(static_cast<uint8_t>(num))) {
return localRegisters[num];
}
else {
} else {
return 0xff;
}
}

void _6502SimControl::writeReg(std::size_t num, uint32_t value) {
if (num < REG_COUNT) {
if(isValidRegIndex(static_cast<uint8_t>(num))) {
localRegisters[num] = value & 0xff;
}
}
Expand Down Expand Up @@ -5478,19 +5498,19 @@ bool _6502SimControl::writeMem(uint8_t* src, unsigned addr, std::size_t len) {
uint32_t _6502SimControl::pcRegNum() {
// TODO: Implement pcRegNum functionality
// ...
return REG_PC; // 0 = PC
return static_cast<uint32_t>(REG_INDEX::REG_PC); // 8 = PC ( To match Intel )
}

uint32_t _6502SimControl::nRegs() {
// TODO: Implement nRegs functionality
// ...
return REG_COUNT; // PC, A, X, Y, , SR, SP
return GdbServer::REG_COUNT; // A, X, Y, SP, PC, SR
}

uint32_t _6502SimControl::wordSize() {
// TODO: Implement wordSize functionality
// ...
return 2; // Placeholder return value
return 1; // Placeholder return value
}

// Control debugger
Expand All @@ -5508,7 +5528,7 @@ bool _6502SimControl::shouldStopServer() {
bool _6502SimControl::isServerRunning() {
// TODO: Implement isServerRunning functionality
// ...
return false; // Placeholder return value
return true; // Placeholder return value
}

void _6502SimControl::setServerRunning(bool status) {
Expand Down
2 changes: 1 addition & 1 deletion Src/gdb_server/gdb_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void GdbServer::rspContinue(uint32_t addr, uint32_t except) {
//! Each byte is packed as a pair of hex digits.
//-----------------------------------------------------------------------------
void GdbServer::rspReadAllRegs() {
for (int r = 0; r < m_simCtrl->nRegs(); r++) {
for (uint8_t r = 0; r < GdbServer::REG_ARRAY_LEN; r++) {
GdbServerUtils::reg2Hex(m_simCtrl->readReg(r),
&(pkt->data[r * 8]));
}
Expand Down
2 changes: 2 additions & 0 deletions Src/gdb_server/headers/gdb_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class GdbServer {
// SystemC thread to listen for and service RSP requests
void serverThread();

static constexpr uint8_t REG_COUNT = 6;
static constexpr uint8_t REG_ARRAY_LEN = REG_COUNT + 4;

private:
//! Definition of GDB target signals.
Expand Down

0 comments on commit 62eee19

Please sign in to comment.