From c920f71c45cb9d910e47b2fae2e30e480d394046 Mon Sep 17 00:00:00 2001 From: Samy Solhi Date: Wed, 9 Nov 2022 16:08:51 +0100 Subject: [PATCH 1/3] tests lui and ld --- src/print.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/print.rs b/src/print.rs index 2435951..6aaa052 100644 --- a/src/print.rs +++ b/src/print.rs @@ -184,7 +184,7 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64 } }, RISCV_LUI => { - format!("lui x{}, {:X}", ins.rd.to_string(), ins.imm31_12) + format!("lui x{}, 0x{:X}", ins.rd.to_string(), ins.imm31_12) }, RISCV_AUIPC => { format!("auipc x{}, {:X}", ins.rd.to_string(), ins.imm31_12) @@ -285,4 +285,30 @@ mod test { assert_eq!("addi x28, x17, 0", print::print(addi, 0)); } + #[test] + fn test_lui() { + let lui = decode::decode(0b01110001000011111000_11100_0110111); + assert_eq!("lui x28, 0x710F8000", print::print(lui, 0)); + } + + #[test] + fn test_ld() { + // imm rs1 f3 rd opcode + let lb = decode::decode(0b010111110000_10001_000_11100_0000011); + let lh = decode::decode(0b010111110000_10001_001_11100_0000011); + let lw = decode::decode(0b010111110000_10001_010_11100_0000011); + let lbu = decode::decode(0b010111110000_10001_100_11100_0000011); + let lhu = decode::decode(0b010111110000_10001_101_11100_0000011); + let ld = decode::decode(0b010111110000_10001_011_11100_0000011); + let lwu = decode::decode(0b010111110000_10001_110_11100_0000011); + // TODO: imm négatif produit une erreur + assert_eq!("lb x28, 1520(x17)", print::print(lb, 0)); + assert_eq!("lh x28, 1520(x17)", print::print(lh, 0)); + assert_eq!("lw x28, 1520(x17)", print::print(lw, 0)); + assert_eq!("lbu x28, 1520(x17)", print::print(lbu, 0)); + assert_eq!("lhu x28, 1520(x17)", print::print(lhu, 0)); + assert_eq!("ld x28, 1520(x17)", print::print(ld, 0)); + assert_eq!("lwu x28, 1520(x17)", print::print(lwu, 0)); + } + } \ No newline at end of file From 4e44c5a9ecb5826b0d0db13e0ec3664a37fcb876 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 9 Nov 2022 16:38:50 +0100 Subject: [PATCH 2/3] Add test for opi, fix func3 sltiu --- src/print.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/print.rs b/src/print.rs index 2435951..89165cb 100644 --- a/src/print.rs +++ b/src/print.rs @@ -131,7 +131,7 @@ const RISCV_FP_FMVW: u8 = 0x78; const names_op: [&str; 8] = ["add", "sll", "slt", "sltu", "xor", "sr", "or", "and"]; -const names_opi: [&str; 8] = ["addi", "slli", "slti", "cmpltuii", "xori", "slri", "ori", "andi"]; +const names_opi: [&str; 8] = ["addi", "slli", "slti", "sltiu", "xori", "slri", "ori", "andi"]; const names_mul: [&str; 8] = ["mpylo", "mpyhi", "mpyhi", "mpyhi", "divhi", "divhi", "divlo", "divlo"]; const names_br: [&str; 8] = ["beq", "bne", "", "", "blt", "bge", "bltu", "bgeu"]; const names_st: [&str; 4] = ["sb", "sh", "sw", "sd"]; @@ -261,6 +261,7 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64 #[cfg(test)] mod test { + use crate::{print, decode}; #[test] @@ -282,7 +283,17 @@ mod test { #[test] fn test_opi() { let addi = decode::decode(0b0000000000_10001_000_11100_0010011); + let slli = decode::decode(0b0000000000_10001_001_11100_0010011); + let slti = decode::decode(0b0000000000_10001_010_11100_0010011); + let sltiu = decode::decode(0b0000000000_10001_011_11100_0010011); + let xori = decode::decode(0b_0000000000010001_100_11100_0010011); + let ori = decode::decode(0b00000000000_10001_110_11100_0010011); assert_eq!("addi x28, x17, 0", print::print(addi, 0)); + assert_eq!("slli x28, x17, 0", print::print(slli, 0)); + assert_eq!("slti x28, x17, 0", print::print(slti, 0)); + assert_eq!("sltiu x28, x17, 0", print::print(sltiu, 0)); + assert_eq!("xori x28, x17, 0", print::print(xori, 0)); + assert_eq!("ori x28, x17, 0", print::print(ori, 0)); } } \ No newline at end of file From 2a708ce335bd2f2c77e6a8b34216f3c1858ab3d3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 9 Nov 2022 16:45:00 +0100 Subject: [PATCH 3/3] Fix machine.rs --- src/machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine.rs b/src/machine.rs index 5845ae3..1ac9c62 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -22,6 +22,6 @@ impl Machine { #[cfg(test)] mod test { - use crate::{_init_machine}; + use super::Machine; }