all repos — mgba @ e5379c99e015d33243a02da824f9b156264335ba

mGBA Game Boy Advance Emulator

Add ability to run code indefinitely (or at least until we crash)
Jeffrey Pfau jeffrey@endrift.com
Sat, 13 Apr 2013 13:50:41 -0700
commit

e5379c99e015d33243a02da824f9b156264335ba

parent

dbe9796b34d8bec97b7df5c488edd4b0bdafe1aa

5 files changed, 48 insertions(+), 8 deletions(-)

jump to
M src/debugger.csrc/debugger.c

@@ -28,6 +28,7 @@

typedef void (DebuggerComamnd)(struct ARMDebugger*, struct DebugVector*); static void _breakInto(struct ARMDebugger*, struct DebugVector*); +static void _continue(struct ARMDebugger*, struct DebugVector*); static void _print(struct ARMDebugger*, struct DebugVector*); static void _printHex(struct ARMDebugger*, struct DebugVector*); static void _printStatus(struct ARMDebugger*, struct DebugVector*);

@@ -40,6 +41,8 @@ struct {

const char* name; DebuggerComamnd* command; } debuggerCommands[] = { + { "c", _continue }, + { "continue", _continue }, { "i", _printStatus }, { "info", _printStatus }, { "p", _print },

@@ -78,6 +81,11 @@ (void)(dv);

sig_t oldSignal = signal(SIGTRAP, _handleDeath); kill(getpid(), SIGTRAP); signal(SIGTRAP, oldSignal); +} + +static void _continue(struct ARMDebugger* debugger, struct DebugVector* dv) { + (void)(dv); + debugger->state = DEBUGGER_RUNNING; } static void _print(struct ARMDebugger* debugger, struct DebugVector* dv) {

@@ -441,19 +449,37 @@ }

void ARMDebuggerInit(struct ARMDebugger* debugger, struct ARMCore* cpu) { debugger->cpu = cpu; + debugger->state = DEBUGGER_PAUSED; } -void ARMDebuggerEnter(struct ARMDebugger* debugger) { - char* line; - _printStatus(debugger, 0); - while ((line = linenoise("> "))) { - _parse(debugger, line); - free(line); +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) { + char* line; + _printStatus(debugger, 0); + while (debugger->state == DEBUGGER_PAUSED) { + line = linenoise("> "); + if (!line) { + debugger->state = DEBUGGER_EXITING; + return; + } + _parse(debugger, line); + free(line); + } +}
M src/debugger.hsrc/debugger.h

@@ -13,6 +13,7 @@ struct ARMCore* cpu;

}; void ARMDebuggerInit(struct ARMDebugger*, struct ARMCore*); +void ARMDebuggerRun(struct ARMDebugger*); void ARMDebuggerEnter(struct ARMDebugger*); #endif
M src/gba.csrc/gba.c

@@ -1,7 +1,10 @@

#include "gba.h" +#include "debugger.h" + #include <stdarg.h> #include <stdio.h> +#include <stdlib.h> #include <sys/mman.h> #include <unistd.h>

@@ -74,6 +77,11 @@ ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR);

cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR; ARMSetPrivilegeMode(cpu, MODE_SYSTEM); cpu->gprs[ARM_SP] = SP_BASE_SYSTEM; +} + +void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) { + ARMDebuggerInit(debugger, &gba->cpu); + gba->debugger = debugger; } void GBALoadROM(struct GBA* gba, int fd) {

@@ -382,4 +390,5 @@ }

void GBAHitStub(struct ARMBoard* board, uint32_t opcode) { GBALog(GBA_LOG_STUB, "Stub opcode: %08x", opcode); + abort(); }
M src/gba.hsrc/gba.h

@@ -92,6 +92,8 @@ struct ARMCore cpu;

struct GBABoard board; struct GBAMemory memory; + struct ARMDebugger* debugger; + enum GBAError errno; const char* errstr; };

@@ -104,6 +106,8 @@ void GBAMemoryDeinit(struct GBAMemory* memory);

void GBABoardInit(struct GBABoard* board); void GBABoardReset(struct ARMBoard* board); + +void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger); void GBALoadROM(struct GBA* gba, int fd);
M src/main.csrc/main.c

@@ -14,8 +14,8 @@ int fd = open("test.rom", O_RDONLY);

GBALoadROM(&gba, fd); gba.cpu.gprs[ARM_PC] = 0x08000004; gba.memory.d.setActiveRegion(&gba.memory.d, gba.cpu.gprs[ARM_PC]); - ARMDebuggerInit(&debugger, &gba.cpu); - ARMDebuggerEnter(&debugger); + GBAAttachDebugger(&gba, &debugger); + ARMDebuggerRun(&debugger); GBADeinit(&gba); close(fd);