summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-12-06 13:51:04 -0800
committeriximeow <me@iximeow.net>2020-12-06 13:51:54 -0800
commit6df899af30920a3a9bd94670d0021ca089a64698 (patch)
tree107ac9d675c8d1768ecb662a1ef66978bc6b0747
parent47a1d9d6fd48229961edf76b789328dc99a19c6c (diff)
correctly decode I25-form immediates
extension bits are base 16, not base 10 thank you @ravenslofty for finding and reporting!
-rw-r--r--src/lib.rs4
-rw-r--r--tests/test.rs9
2 files changed, 11 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ea850aa..c2a8960 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2669,8 +2669,8 @@ fn read_i_operands(encoding: OperandEncodingI, word: &BitSlice<Lsb0, u8>) -> (Op
let r1 = word[6..13].load::<u8>();
let x6 = word[27..33].load::<u8>();
let src = match x6 {
- 30 => Operand::IP,
- 33 => Operand::PR,
+ 0x30 => Operand::IP,
+ 0x33 => Operand::PR,
_ => {
// TODO: what does a bad I25 x6 get you? nop?
Operand::None
diff --git a/tests/test.rs b/tests/test.rs
index 114d81d..01df3fb 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -39,6 +39,15 @@ fn test_invalid_instruction() {
assert_eq!(format!("{}", inst), expected);
}
#[test]
+fn test_ad_hoc() {
+ let decoder = InstDecoder::default();
+
+ let expected = "[MII] nop.m 0x0; mov r2=ip;; addl r2=0x40,r2;;";
+ let data = [0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x00, 0x60, 0x00, 0x40, 0x00, 0x14, 0x00, 0x90];
+ let inst = decoder.decode(data[..].iter().cloned()).unwrap();
+ assert_eq!(format!("{}", inst), expected);
+}
+#[test]
fn test_shr_shl_dep_ext() {
// encoding of immediates for dep/ext and their pseudo-ops (shl/shr) is weird.
// `pos` is recorded as `63 - the_actual_value`? `len` is encoded as the actual length minus