From a10305e786f88ea0adf8258035d6373c4f76ac43 Mon Sep 17 00:00:00 2001 From: luigi__ Date: Sun, 2 Aug 2009 11:21:50 +0000 Subject: [PATCH] CPU (THUMB): fix for opcode 'BX PC' which does switch to ARM state. This fix allows the BIOS to boot a bit further (still doesn't boot). --- desmume/src/thumb_instructions.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/desmume/src/thumb_instructions.cpp b/desmume/src/thumb_instructions.cpp index cb761bc5f..4ae2c8888 100644 --- a/desmume/src/thumb_instructions.cpp +++ b/desmume/src/thumb_instructions.cpp @@ -540,11 +540,22 @@ TEMPLATE static u32 FASTCALL OP_MOV_SPE() TEMPLATE static u32 FASTCALL OP_BX_THUMB() { - u32 Rm = cpu->R[REG_POS(cpu->instruction, 3)]; - - cpu->CPSR.bits.T = BIT0(Rm); - cpu->R[15] = (Rm & 0xFFFFFFFE); - cpu->next_instruction = cpu->R[15]; + // When using PC as operand with BX opcode, switch to ARM state and jump to (instruct_adr+4) + // Reference: http://nocash.emubase.de/gbatek.htm#thumb5hiregisteroperationsbranchexchange + if (REG_POS(cpu->instruction, 3) == 15) + { + cpu->CPSR.bits.T = 0; + cpu->R[15] &= 0xFFFFFFFC; + cpu->next_instruction = cpu->R[15]; + } + else + { + u32 Rm = cpu->R[REG_POS(cpu->instruction, 3)]; + + cpu->CPSR.bits.T = BIT0(Rm); + cpu->R[15] = (Rm & 0xFFFFFFFE); + cpu->next_instruction = cpu->R[15]; + } return 3; }