Merge branch 'decode_print' of https://gitlab.istic.univ-rennes1.fr/simpleos/burritos into decode_print

This commit is contained in:
Quentin Legot 2022-11-09 16:39:10 +01:00
commit 31faa6501e
3 changed files with 55 additions and 1 deletions

27
src/machine.rs Normal file
View File

@ -0,0 +1,27 @@
use crate::decode::*;
pub struct Machine {
pub _pc : u32,
pub _int_reg : [u32 ; 32],
pub _instructions : [u32 ; 100]
}
impl Machine {
fn _init_machine() -> Machine {
Machine {
_pc : 0,
_instructions : [0 ; 100],
_int_reg : [0 ; 32]
}
}
}
#[cfg(test)]
mod test {
use crate::{_init_machine};
}

View File

@ -1,5 +1,6 @@
mod decode;
mod print;
mod machine;
fn main() {
let instr = decode::decode(98);

View File

@ -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)
@ -296,4 +296,30 @@ mod test {
assert_eq!("ori x28, x17, 0", print::print(ori, 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));
}
}