all repos — mgba @ 7e5de27f43a680da74c4efc3b108e9cf3c4b2652

mGBA Game Boy Advance Emulator

Add ability to run Thumb code
Jeffrey Pfau jeffrey@endrift.com
Wed, 10 Apr 2013 23:34:50 -0700
commit

7e5de27f43a680da74c4efc3b108e9cf3c4b2652

parent

9a0d14645b1acd3dd67453ccecfc8b074e794518

4 files changed, 19 insertions(+), 1 deletions(-)

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

@@ -106,3 +106,10 @@

cpu->board->reset(cpu->board); } +void ARMRun(struct ARMCore* cpu) { + if (cpu->executionMode) { + ThumbStep(cpu); + } else { + ARMStep(cpu); + } +}
M src/arm.hsrc/arm.h

@@ -116,4 +116,6 @@

void ARMReset(struct ARMCore* cpu); void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode); +void ARMRun(struct ARMCore* cpu); + #endif
M src/isa-thumb.csrc/isa-thumb.c

@@ -4,6 +4,15 @@ #include "isa-inlines.h"

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
M src/main.csrc/main.c

@@ -15,7 +15,7 @@ gba.cpu.gprs[ARM_PC] = 0x08000004;

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);