From 1e2e537ec99bc0d8babb3e7720598b990a260ae2 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Tue, 7 Mar 2023 17:32:59 +0100 Subject: [PATCH] compare mem_checker and machine --- src/main.rs | 2 +- src/simulator/machine.rs | 17 +++++++++++------ src/simulator/mem_cmp.rs | 13 +++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2acab96..97c0ec1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,5 +10,5 @@ fn main() { mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m); //mem_cmp::Mem_Checker::print_Mem_Checker(&checker); //Machine::print_memory(&mut m, 0x400000, 0x405000); - Machine::run(m); + //Machine::run(m); } diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 2baf432..47ee672 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -177,9 +177,7 @@ impl Machine { /// - **machine** which contains a table of instructions pub fn run(machine : Machine){ let mut m = machine; - for i in 0..MEM_SIZE{ - Machine::one_instruction(&mut m); - } + while Machine::one_instruction(&mut m) == 0 {} } /// execute the current instruction @@ -187,7 +185,7 @@ impl Machine { /// ### Parameters /// /// - **machine** which contains a table of instructions and a pc to the actual instruction - pub fn one_instruction(machine :&mut Machine) { + pub fn one_instruction(machine :&mut Machine) -> i32 { let unsigned_reg1 : u64; let unsigned_reg2 : u64; @@ -210,10 +208,11 @@ impl Machine { } let val = u32::from_be_bytes(val) as u64; + let inst : Instruction = decode(val); Self::print_machine_status(machine); println!("executing instruction : {:016x} at pc {:x}", val, machine.pc); println!("{}", print::print(decode(val), machine.pc as i32)); - let inst : Instruction = decode(val); + match inst.opcode { @@ -626,10 +625,16 @@ impl Machine { } } } + RISCV_SYSTEM => { + // temporary return value to stop the loop of run + // before we can use system call + return 1; + } _ => { panic!("{:x} opcode non géré pc : {:x}", inst.opcode, machine.pc)}, } - machine.pc += 4; // Possible bug avec jump + machine.pc += 4; + return 0; } diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index 316df70..e1cb7e4 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -194,6 +194,19 @@ impl Mem_Checker{ } + pub fn compare_machine_memory(m_c: &Mem_Checker, machine: &Machine) -> bool { + + for section in m_c.sections.iter() { + for i in 0..section.len { + if machine.main_memory[section.addr + i] != section.content[i] { + return false; + } + } + } + + return true; + } + }