Add ability to run Thumb code

This commit is contained in:
Jeffrey Pfau 2013-04-10 23:34:50 -07:00
parent 9a0d14645b
commit 7e5de27f43
4 changed files with 19 additions and 1 deletions

View File

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

View File

@ -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

View File

@ -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

View File

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