diff --git a/src/debugger.c b/src/debugger.c index 414117caf..a08517515 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -447,30 +447,7 @@ static void _parse(struct ARMDebugger* debugger, const char* line) { _printStatus(debugger, 0); } -void ARMDebuggerInit(struct ARMDebugger* debugger, struct ARMCore* cpu) { - debugger->cpu = cpu; - debugger->state = DEBUGGER_PAUSED; -} - -void ARMDebuggerRun(struct ARMDebugger* debugger) { - while (debugger->state != DEBUGGER_EXITING) { - while (debugger->state == DEBUGGER_RUNNING) { - ARMRun(debugger->cpu); - } - switch (debugger->state) { - case DEBUGGER_PAUSED: - ARMDebuggerEnter(debugger); - break; - case DEBUGGER_EXITING: - return; - default: - // Should never be reached - break; - } - } -} - -void ARMDebuggerEnter(struct ARMDebugger* debugger) { +static void _commandLine(struct ARMDebugger* debugger) { char* line; _printStatus(debugger, 0); while (debugger->state == DEBUGGER_PAUSED) { @@ -483,3 +460,30 @@ void ARMDebuggerEnter(struct ARMDebugger* debugger) { free(line); } } + +void ARMDebuggerInit(struct ARMDebugger* debugger, struct ARMCore* cpu) { + debugger->cpu = cpu; + debugger->state = DEBUGGER_PAUSED; +} + +void ARMDebuggerRun(struct ARMDebugger* debugger) { + while (debugger->state != DEBUGGER_EXITING) { + while (debugger->state == DEBUGGER_RUNNING) { + ARMRun(debugger->cpu); + } + switch (debugger->state) { + case DEBUGGER_PAUSED: + _commandLine(debugger); + break; + case DEBUGGER_EXITING: + return; + default: + // Should never be reached + break; + } + } +} + +void ARMDebuggerEnter(struct ARMDebugger* debugger) { + debugger->state = DEBUGGER_PAUSED; +} diff --git a/src/gba.c b/src/gba.c index 3c5a58388..22820f7f5 100644 --- a/src/gba.c +++ b/src/gba.c @@ -23,6 +23,7 @@ void GBAInit(struct GBA* gba) { GBAMemoryInit(&gba->memory); ARMAssociateMemory(&gba->cpu, &gba->memory.d); + gba->board.p = gba; GBABoardInit(&gba->board); ARMAssociateBoard(&gba->cpu, &gba->board.d); @@ -390,5 +391,10 @@ void GBALog(int level, const char* format, ...) { void GBAHitStub(struct ARMBoard* board, uint32_t opcode) { GBALog(GBA_LOG_STUB, "Stub opcode: %08x", opcode); - abort(); + struct GBABoard* gbaBoard = (struct GBABoard*) board; + if (!gbaBoard->p->debugger) { + abort(); + } else { + ARMDebuggerEnter(gbaBoard->p->debugger); + } } diff --git a/src/gba.h b/src/gba.h index 5258ae47f..df7b9c78f 100644 --- a/src/gba.h +++ b/src/gba.h @@ -85,6 +85,7 @@ struct GBAMemory { struct GBABoard { struct ARMBoard d; + struct GBA* p; }; struct GBA {