Add ability to print current instruction

This commit is contained in:
Jeffrey Pfau 2013-04-13 00:22:27 -07:00
parent 67750e351b
commit 10884de57a
1 changed files with 19 additions and 0 deletions

View File

@ -52,6 +52,17 @@ static void _breakInto(struct ARMDebugger* debugger) {
signal(SIGTRAP, oldSignal);
}
static inline void _printLine(struct ARMDebugger* debugger, uint32_t address, enum ExecutionMode mode) {
// TODO: write a disassembler
if (mode == MODE_ARM) {
uint32_t instruction = debugger->cpu->memory->load32(debugger->cpu->memory, address);
printf("%08X\n", instruction);
} else {
uint16_t instruction = debugger->cpu->memory->loadU16(debugger->cpu->memory, address);
printf("%04X\n", instruction);
}
}
static void _printStatus(struct ARMDebugger* debugger) {
int r;
for (r = 0; r < 4; ++r) {
@ -62,6 +73,14 @@ static void _printStatus(struct ARMDebugger* debugger) {
debugger->cpu->gprs[(r << 2) + 3]);
}
_printPSR(debugger->cpu->cpsr);
int instructionLength;
enum ExecutionMode mode = debugger->cpu->cpsr.t;
if (mode == MODE_ARM) {
instructionLength = WORD_SIZE_ARM;
} else {
instructionLength = WORD_SIZE_THUMB;
}
_printLine(debugger, debugger->cpu->gprs[ARM_PC] - instructionLength, mode);
}
static void _quit(struct ARMDebugger* debugger) {