From 7e5de27f43a680da74c4efc3b108e9cf3c4b2652 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 10 Apr 2013 23:34:50 -0700 Subject: [PATCH] Add ability to run Thumb code --- src/arm.c | 7 +++++++ src/arm.h | 2 ++ src/isa-thumb.c | 9 +++++++++ src/main.c | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/arm.c b/src/arm.c index 2caf04cdb..f840dc7fb 100644 --- a/src/arm.c +++ b/src/arm.c @@ -106,3 +106,10 @@ void ARMReset(struct ARMCore* cpu) { cpu->board->reset(cpu->board); } +void ARMRun(struct ARMCore* cpu) { + if (cpu->executionMode) { + ThumbStep(cpu); + } else { + ARMStep(cpu); + } +} diff --git a/src/arm.h b/src/arm.h index 6b9b5e25a..fa0046f8e 100644 --- a/src/arm.h +++ b/src/arm.h @@ -116,4 +116,6 @@ void ARMAssociateBoard(struct ARMCore* cpu, struct ARMBoard* board); void ARMReset(struct ARMCore* cpu); void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode); +void ARMRun(struct ARMCore* cpu); + #endif diff --git a/src/isa-thumb.c b/src/isa-thumb.c index 70611e465..c9c7b5bb7 100644 --- a/src/isa-thumb.c +++ b/src/isa-thumb.c @@ -4,6 +4,15 @@ static const ThumbInstruction _thumbTable[0x400]; +void ThumbStep(struct ARMCore* cpu) { + uint32_t address = cpu->gprs[ARM_PC]; + cpu->gprs[ARM_PC] = address + WORD_SIZE_THUMB; + address -= WORD_SIZE_THUMB; + uint16_t opcode = ((uint16_t*) cpu->memory->activeRegion)[(address & cpu->memory->activeMask) >> 1]; + ThumbInstruction instruction = _thumbTable[opcode >> 6]; + instruction(cpu, opcode); +} + // Instruction definitions // Beware pre-processor insanity diff --git a/src/main.c b/src/main.c index dc5445e2d..c2ed2d217 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ int main(int argc, char** argv) { gba.memory.d.setActiveRegion(&gba.memory.d, gba.cpu.gprs[ARM_PC]); int i; for (i = 0; i < 1024 * 1024 * 16; ++i) { - ARMStep(&gba.cpu); + ARMRun(&gba.cpu); } GBADeinit(&gba); close(fd);