diff --git a/src/arm/isa-inlines.h b/src/arm/isa-inlines.h index cfdd73410..f9a8daf9d 100644 --- a/src/arm/isa-inlines.h +++ b/src/arm/isa-inlines.h @@ -91,4 +91,15 @@ static inline void _ARMReadCPSR(struct ARMCore* cpu) { cpu->irqh.readCPSR(cpu); } +static inline uint32_t _ARMPCAddress(struct ARMCore* cpu) { + int instructionLength; + enum ExecutionMode mode = cpu->cpsr.t; + if (mode == MODE_ARM) { + instructionLength = WORD_SIZE_ARM; + } else { + instructionLength = WORD_SIZE_THUMB; + } + return cpu->gprs[ARM_PC] - instructionLength * 2; +} + #endif diff --git a/src/gba/gba.c b/src/gba/gba.c index 86201dbe4..92d438735 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -628,7 +628,7 @@ void GBAHitStub(struct ARMCore* cpu, uint32_t opcode) { if (gba->debugger) { level = GBA_LOG_STUB; struct DebuggerEntryInfo info = { - .address = cpu->gprs[ARM_PC], + .address = _ARMPCAddress(cpu), .opcode = opcode }; ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info); @@ -641,7 +641,7 @@ void GBAIllegal(struct ARMCore* cpu, uint32_t opcode) { GBALog(gba, GBA_LOG_WARN, "Illegal opcode: %08x", opcode); if (gba->debugger) { struct DebuggerEntryInfo info = { - .address = cpu->gprs[ARM_PC], + .address = _ARMPCAddress(cpu), .opcode = opcode }; ARMDebuggerEnter(gba->debugger, DEBUGGER_ENTER_ILLEGAL_OP, &info);