diff options
author | iximeow <me@iximeow.net> | 2021-07-06 16:42:24 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2021-07-06 16:43:02 -0700 |
commit | 61513023aff4d3312287bb0fb55ea931997dfddb (patch) | |
tree | 51c07a11570d5012f68929e9c44a7fc2df97b15e /src/armv7/thumb.rs | |
parent | c75153a5efffcd2ac5f37864182e5108ea5f70ce (diff) |
update yaxpeax_arch and bump version to 0.1.00.1.0
Diffstat (limited to 'src/armv7/thumb.rs')
-rw-r--r-- | src/armv7/thumb.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/armv7/thumb.rs b/src/armv7/thumb.rs index 3c480af..8017f01 100644 --- a/src/armv7/thumb.rs +++ b/src/armv7/thumb.rs @@ -1,9 +1,12 @@ // use yaxpeax_arch::{Arch, AddressDiff, Decoder, LengthedInstruction}; +use yaxpeax_arch::Arch; +use armv7::ARMv7; use armv7::ConditionCode; use armv7::DecodeError; use armv7::CReg; use armv7::Reg; +use armv7::Reader; use armv7::RegShift; use armv7::Operand; use armv7::Opcode; @@ -97,20 +100,20 @@ fn DecodeImmShift(reg: u8, ty: u8, imm5: u8) -> RegShift { } #[allow(non_snake_case)] -pub fn decode_into<T: IntoIterator<Item=u8>>(decoder: &InstDecoder, inst: &mut Instruction, bytes: T) -> Result<(), DecodeError> { +pub fn decode_into<T: Reader<<ARMv7 as Arch>::Address, <ARMv7 as Arch>::Word>>(decoder: &InstDecoder, inst: &mut Instruction, words: &mut T) -> Result<(), <ARMv7 as Arch>::DecodeError> { // these are cleared in `armv7::InstDecoder::decode_into`. // they must be reset when switching out of thumb decoding or decoding a new thumb instruction, // which that `decode_into` is the entrypoint for in all cases. // inst.set_w(false); // inst.set_wide(false); inst.set_thumb(true); - let mut iter = bytes.into_iter(); - let instr: u16 = - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) ) | - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) << 8 ); + let mut word_bytes = [0u8; 2]; + words.next_n(&mut word_bytes)?; + let word = u16::from_le_bytes(word_bytes); + let instr = word; let mut instr2 = bitarr![Lsb0, u16; 0u16; 16]; - instr2[0..16].store(instr); + instr2[0..16].store(word); let opword = instr2[11..].load::<u16>(); @@ -122,9 +125,9 @@ pub fn decode_into<T: IntoIterator<Item=u8>>(decoder: &InstDecoder, inst: &mut I // 32b instruction - `A6-228, 32-bit Thumb instruction encoding` // opword low bits 01, 10, and 11 correspond to `op1` in table `A6-9` - let lower: u16 = - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) ) | - ((iter.next().ok_or(DecodeError::ExhaustedInput)? as u16) << 8 ); + let mut word_bytes = [0u8; 2]; + words.next_n(&mut word_bytes)?; + let lower = u16::from_le_bytes(word_bytes); let mut lower2 = bitarr![Lsb0, u16; 0u16; 16]; lower2[0..16].store(lower); |