riscii

An emulator for the RISC II
Log | Files | Refs | LICENSE

commit 36179599c65b09c5b75075614773c1dc6d1a82cf
parent 0c561dfa0990290dd0fd286d1bca610083f27888
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Thu,  6 Oct 2022 10:11:57 -0700

Fix imm19 for test

Diffstat:
Msrc/decode.rs | 12+++++++++---
Msrc/decode_test.rs | 69+++++++++++++++++++++++++++++++++------------------------------------
2 files changed, 42 insertions(+), 39 deletions(-)

diff --git a/src/decode.rs b/src/decode.rs @@ -49,7 +49,7 @@ macro_rules! bdece { // Struct declarations. /// Opcode errors. -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(PartialEq, Eq, Clone)] pub enum DecodeError { /// Indicates an invalid instruction. The first u32 indicates which bits are invalid, /// the final u32 is the whole opcode. @@ -69,6 +69,12 @@ pub enum DecodeError { // Public function declarations. +impl fmt::Debug for DecodeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self) + } +} + pub fn decode(opcode: u32) -> Result<Instruction> { type I = Instruction; // SCC flag (<24>). @@ -84,8 +90,8 @@ pub fn decode(opcode: u32) -> Result<Instruction> { ShortSource::Imm13(opcode & 0x1fff) } else { ShortSource::Reg((opcode & 0x1f) as u8) - }; // TODO fix ambiguous sign problem. - // The opcode itself. + }; + // The opcode itself. let op = (opcode & 0xFE000000) >> 25; let cond = get_cond_from_opcode(opcode); diff --git a/src/decode_test.rs b/src/decode_test.rs @@ -32,7 +32,7 @@ mod test { fn decode_calli() -> Result<()> { assert_eq!( decode(0x0329f00f)?, - I::Calli(ShortInstruction::new(true, 5, 7, SS::UImm13(4111))) + I::Calli(ShortInstruction::new(true, 5, 7, SS::Imm13(4111))) ); Ok(()) } @@ -41,7 +41,7 @@ mod test { fn decode_getpsw() -> Result<()> { assert_eq!( decode(0x05293fff)?, - I::GetPSW(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1fff))) + I::GetPSW(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1fff))) ); Ok(()) } @@ -50,7 +50,7 @@ mod test { fn decode_getipc() -> Result<()> { assert_eq!( decode(0x07293f69)?, - I::GetLPC(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::GetLPC(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -59,7 +59,7 @@ mod test { fn decode_putpsw() -> Result<()> { assert_eq!( decode(0x09293f69)?, - I::PutPSW(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::PutPSW(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -70,7 +70,7 @@ mod test { fn decode_callx() -> Result<()> { assert_eq!( decode(0x11293f69)?, - I::Callx(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Callx(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -92,7 +92,7 @@ mod test { true, Conditional::Hi, 4, - SS::UImm13(0x1f69) + SS::Imm13(0x1f69) )) ); Ok(()) @@ -115,7 +115,7 @@ mod test { true, Conditional::Hi, 4, - SS::UImm13(0x1f69) + SS::Imm13(0x1f69) )) ); Ok(()) @@ -129,7 +129,7 @@ mod test { true, Conditional::Hi, 4, - SS::UImm13(0x1f69) + SS::Imm13(0x1f69) )) ); Ok(()) @@ -141,7 +141,7 @@ mod test { fn decode_sll() -> Result<()> { assert_eq!( decode(0x23293f69)?, - I::Sll(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Sll(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -150,7 +150,7 @@ mod test { fn decode_sra() -> Result<()> { assert_eq!( decode(0x25293f69)?, - I::Sra(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Sra(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -159,7 +159,7 @@ mod test { fn decode_srl() -> Result<()> { assert_eq!( decode(0x27293f69)?, - I::Srl(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Srl(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -177,7 +177,7 @@ mod test { fn decode_and() -> Result<()> { assert_eq!( decode(0x2b293f69)?, - I::And(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::And(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -186,7 +186,7 @@ mod test { fn decode_or() -> Result<()> { assert_eq!( decode(0x2d293f69)?, - I::Or(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Or(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -195,7 +195,7 @@ mod test { fn decode_xor() -> Result<()> { assert_eq!( decode(0x2f293f69)?, - I::Xor(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Xor(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -204,7 +204,7 @@ mod test { fn decode_add() -> Result<()> { assert_eq!( decode(0x31293f69)?, - I::Add(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Add(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -213,7 +213,7 @@ mod test { fn decode_addc() -> Result<()> { assert_eq!( decode(0x33293f69)?, - I::Addc(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Addc(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -222,7 +222,7 @@ mod test { fn decode_sub() -> Result<()> { assert_eq!( decode(0x39293f69)?, - I::Sub(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Sub(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -231,7 +231,7 @@ mod test { fn decode_subc() -> Result<()> { assert_eq!( decode(0x3b293f69)?, - I::Subc(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Subc(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -240,7 +240,7 @@ mod test { fn decode_subi() -> Result<()> { assert_eq!( decode(0x3d293f69)?, - I::Subi(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Subi(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -249,7 +249,7 @@ mod test { fn decode_subci() -> Result<()> { assert_eq!( decode(0x3f293f69)?, - I::Subci(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Subci(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -260,7 +260,7 @@ mod test { fn decode_ldxw() -> Result<()> { assert_eq!( decode(0x4d293f69)?, - I::Ldxw(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Ldxw(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -278,7 +278,7 @@ mod test { fn decode_ldxhu() -> Result<()> { assert_eq!( decode(0x51293f69)?, - I::Ldxhu(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Ldxhu(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -296,7 +296,7 @@ mod test { fn decode_ldxhs() -> Result<()> { assert_eq!( decode(0x55293f69)?, - I::Ldxhs(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Ldxhs(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -314,7 +314,7 @@ mod test { fn decode_ldxbu() -> Result<()> { assert_eq!( decode(0x59293f69)?, - I::Ldxbu(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Ldxbu(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -332,7 +332,7 @@ mod test { fn decode_ldxbs() -> Result<()> { assert_eq!( decode(0x5d293f69)?, - I::Ldxbs(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Ldxbs(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -352,7 +352,7 @@ mod test { fn decode_stxw() -> Result<()> { assert_eq!( decode(0x6d293f69)?, - I::Stxw(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Stxw(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -370,7 +370,7 @@ mod test { fn decode_stxh() -> Result<()> { assert_eq!( decode(0x75293f69)?, - I::Stxh(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Stxh(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -388,7 +388,7 @@ mod test { fn decode_stxb() -> Result<()> { assert_eq!( decode(0x7d293f69)?, - I::Stxb(ShortInstruction::new(true, 5, 4, SS::UImm13(0x1f69))) + I::Stxb(ShortInstruction::new(true, 5, 4, SS::Imm13(0x1f69))) ); Ok(()) } @@ -406,14 +406,17 @@ mod test { #[test] fn ss_uimm_to_simm1() { - assert_eq!(SS::new(0xf00f, false).uimm_to_simm(), SS::SImm13(-4111)); + assert_eq!( + SS::new(0xf00f, false).uimm_to_simm(), + SS::Imm13(-4111i32 as u32) + ); } #[test] fn ss_uimm_to_simm2() { assert_eq!( SS::new(0xf0ff, false).uimm_to_simm(), - SS::SImm13(-(0x10ff as i32)) + SS::Imm13(-0x10ffi32 as u32) ); } @@ -423,12 +426,6 @@ mod test { } } - impl fmt::Debug for DecodeError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self) - } - } - impl fmt::Debug for I { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Instruction to string conversion.