From eea26d239321d37550cc2d1181e75ca45049a48c Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Mon, 22 Jul 2019 00:25:26 +0300 Subject: [PATCH] thumb: Change ordering when decoding thumb instruction. This fixes a bug where "swi" instructions are decoded as conditional branches. The order really matters here, because Swi instructions are actually conditional branch with illegal condition code. Former-commit-id: 0024a8b53386a510dd321c157391c99a2af29223 --- src/core/arm7tdmi/thumb/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/arm7tdmi/thumb/mod.rs b/src/core/arm7tdmi/thumb/mod.rs index 87ae10f..4f09d05 100644 --- a/src/core/arm7tdmi/thumb/mod.rs +++ b/src/core/arm7tdmi/thumb/mod.rs @@ -124,10 +124,10 @@ impl InstructionDecoder for ThumbInstruction { Ok(PushPop) } else if raw & 0xf000 == 0xc000 { Ok(LdmStm) - } else if raw & 0xf000 == 0xd000 { - Ok(BranchConditional) } else if raw & 0xff00 == 0xdf00 { Ok(Swi) + } else if raw & 0xf000 == 0xd000 { + Ok(BranchConditional) } else if raw & 0xf800 == 0xe000 { Ok(Branch) } else if raw & 0xf000 == 0xf000 { @@ -323,7 +323,7 @@ impl ThumbInstruction { } pub fn cond(&self) -> ArmCond { - ArmCond::from_u8(self.raw.bit_range(8..12) as u8).unwrap() + ArmCond::from_u8(self.raw.bit_range(8..12) as u8).expect("bad condition") } pub fn flag(&self, bit: usize) -> bool {