massive feat: added a GDB stub for debugging

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-06-16 07:45:54 +05:30
parent c22333812e
commit a7d919eea0
15 changed files with 708 additions and 34 deletions

View File

@@ -31,7 +31,6 @@ class Bus {
uint32_t read_word(uint32_t, bool = true);
void write_word(uint32_t, uint32_t, bool = true);
// not sure what else to do?
inline void internal_cycle() { cycles++; }

View File

@@ -4,11 +4,19 @@
#include "bus.hh"
#include "cpu/psr.hh"
#include "thumb/instruction.hh"
#include <cstdint>
#include <memory>
#include <cstdint>
#ifdef GDB_DEBUG
#include <unordered_set>
#endif
namespace matar {
#ifdef GDB_DEBUG
class GdbRsp;
#endif
class Cpu {
public:
Cpu(std::shared_ptr<Bus>) noexcept;
@@ -16,24 +24,12 @@ class Cpu {
void step();
void chg_mode(const Mode to);
bool is_flushed = false;
inline void flush_pipeline() {
is_flushed = true;
if (cpsr.state() == State::Arm) {
opcodes[0] = bus->read_word(pc, false);
advance_pc_arm();
opcodes[1] = bus->read_word(pc);
advance_pc_arm();
} else {
opcodes[0] = bus->read_halfword(pc, false);
advance_pc_thumb();
opcodes[1] = bus->read_halfword(pc);
advance_pc_thumb();
}
sequential = true;
};
inline bool is_halted() { return halted; }
inline void resume() { halted = false; }
private:
bool halted = false;
friend void arm::Instruction::exec(Cpu& cpu);
friend void thumb::Instruction::exec(Cpu& cpu);
@@ -93,5 +89,26 @@ class Cpu {
inline void advance_pc_arm() { pc += arm::INSTRUCTION_SIZE; };
inline void advance_pc_thumb() { pc += thumb::INSTRUCTION_SIZE; }
bool is_flushed = false;
inline void flush_pipeline() {
if (cpsr.state() == State::Arm) {
opcodes[0] = bus->read_word(pc, false);
advance_pc_arm();
opcodes[1] = bus->read_word(pc);
advance_pc_arm();
} else {
opcodes[0] = bus->read_halfword(pc, false);
advance_pc_thumb();
opcodes[1] = bus->read_halfword(pc);
advance_pc_thumb();
}
sequential = true;
};
#ifdef GDB_DEBUG
friend class GdbRsp;
std::unordered_set<uint32_t> breakpoints = {};
#endif
};
}