From 297a4d1d0a04ed14b684ca004b2f6705e543016d Mon Sep 17 00:00:00 2001 From: Moysan Gabriel Date: Wed, 8 Feb 2023 15:50:14 +0100 Subject: [PATCH] memory context load --- src/simulator/mem_cmp.rs | 81 ++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index 9f2e160..27b3795 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -1,6 +1,7 @@ use std::fs; use std::io; use std::io::BufRead; +use crate::Machine; const MEM_SIZE : usize = 4096; @@ -156,35 +157,43 @@ impl Mem_Checker{ } - fn Mem_Checker_check(m_c: &Mem_Checker, memory: [u8 ; MEM_SIZE]){ - /* - * Check pc, sp - */ + fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){ + + machine.sp = m_c.sp; + machine.pc = m_c.pc as u64; - /* - * Check sections - */ - - for(i, s) in m_c.sections.iter().enumerate() { - let addr = s.addr; - let len = s.len; - let segment = &s.content; - - /* - regarder dans mem[addr] - a cette adresse verifier len octets - */ - - for j in 0..(len-1){ - if segment[j] != memory[addr + j] { - println!("missmatch"); - } + for section in m_c.sections.iter() { + + for (i,b) in section.content.iter().enumerate() { + machine.main_memory[section.addr + i] = *b; } + } + } - } + + /* + * FOR DEBUG + */ + fn compare_print_m_c_machine(m_c: &Mem_Checker, machine: &mut Machine){ + + Mem_Checker::print_Mem_Checker(m_c); + + for section in m_c.sections.iter() { + + print!("\n\n"); + + println!("Content addr : {}", section.addr); + println!("Content len (number of bytes) : {}", section.len); + + for i in 0..section.len { + println!("mem[{}] = {}", section.addr + i, machine.main_memory[section.addr + i]); + } + } } + + } @@ -261,7 +270,31 @@ mod tests { use super::*; #[test] - fn test_create_Mem_Chercker(){ + fn test_fill_memory(){ + let path = "osef".to_string(); + let m_c = Mem_Checker::from(&path); + let mut machine = Machine::_init_machine(); + + Mem_Checker::fill_memory_from_Mem_Checker(&m_c, &mut machine); + + print!("\n Comparing memory from loaded context\n\n"); + + Mem_Checker::compare_print_m_c_machine(&m_c, &mut machine); + + } + + + #[test] + fn test_enum_start_at_zero(){ + let v = vec![1,2,3]; + + for (i,val) in v.iter().enumerate() { + println!("i = {} :: v[i] = {}", i, val); + } + } + + #[test] + fn test_create_Mem_Checker(){ let path: String = "osef".to_string(); let m_c = Mem_Checker::from(&path); Mem_Checker::print_Mem_Checker(&m_c);