Skip to content

Commit 241b2b8

Browse files
authored
fix minor thumb blx immediate bugs (#2450)
1 parent 220b238 commit 241b2b8

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/ARMInterpreter_Branch.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,22 @@ void T_BL_LONG_2(ARM* cpu)
106106
{
107107
s32 offset = (cpu->CurInstr & 0x7FF) << 1;
108108
u32 pc = cpu->R[14] + offset;
109-
cpu->R[14] = (cpu->R[15] - 2) | 1;
110109

111-
if ((cpu->Num==1) || (cpu->CurInstr & (1<<12)))
110+
if ((cpu->Num==1) || (cpu->CurInstr & (1<<12))) // BL
111+
{
112112
pc |= 1;
113+
}
114+
else // BLX
115+
{
116+
if (cpu->CurInstr & 1) // lsb of immediate is set, implying halfword offset; this raises undefined.
117+
return T_UNK(cpu);
113118

119+
// instruction always switches to arm mode
120+
// interworking bit should be cleared.
121+
pc &= ~1;
122+
}
123+
124+
cpu->R[14] = (cpu->R[15] - 2) | 1;
114125
cpu->JumpTo(pc);
115126
}
116127

0 commit comments

Comments
 (0)