Fix wrong calculation of conditional branch offset in Thumb mode

Former-commit-id: 4cc28b13b19b2bf45e2b0e34d9a9dc0f83f82b01
This commit is contained in:
Michel Heily 2019-07-05 16:01:16 +03:00
parent 37117257a6
commit 0c50209735
2 changed files with 4 additions and 4 deletions

View file

@ -164,8 +164,8 @@ impl ThumbInstruction {
"b{cond}\t{addr:#x}", "b{cond}\t{addr:#x}",
cond = self.cond(), cond = self.cond(),
addr = { addr = {
let offset = self.offset8() as i8 as i32; let offset = ((self.offset8() as i8) << 1) as i32;
(self.pc as i32).wrapping_add(offset) as Addr (self.pc as i32 + 4).wrapping_add(offset) as Addr
} }
) )
} }

View file

@ -247,8 +247,8 @@ impl Core {
if !self.check_arm_cond(insn.cond()) { if !self.check_arm_cond(insn.cond()) {
Ok(CpuPipelineAction::IncPC) Ok(CpuPipelineAction::IncPC)
} else { } else {
let offset = insn.offset8() as i8 as i32; let offset = ((insn.offset8() as i8) << 1) as i32;
self.pc = (insn.pc as i32).wrapping_add(offset) as u32; self.pc = (self.pc as i32).wrapping_add(offset) as u32;
Ok(CpuPipelineAction::Flush) Ok(CpuPipelineAction::Flush)
} }
} }