From 73c49414ff120b549005d607fa444268d483728b Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 1 Mar 2023 15:11:35 +0100 Subject: [PATCH] print_memory dans Machine --- src/main.rs | 8 +++----- src/simulator/loader.rs | 2 +- src/simulator/machine.rs | 11 +++++++++++ src/simulator/mem_cmp.rs | 6 +++--- src/simulator/print.rs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 41ec194..b245e37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,11 @@ mod simulator; use simulator::machine::Machine; -use simulator::mem_cmp; +use simulator::{mem_cmp, loader}; fn main() { - let mut m = Machine::_init_machine(); let path = "test_file_section.txt".to_string(); - let checker = mem_cmp::Mem_Checker::from(&path); - mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m); + let mut m = loader::load(&path, 4); + Machine::print_memory(&mut m); Machine::run(m); - mem_cmp::Mem_Checker::print_Mem_Checker(&checker); } diff --git a/src/simulator/loader.rs b/src/simulator/loader.rs index 5659003..7d31d18 100644 --- a/src/simulator/loader.rs +++ b/src/simulator/loader.rs @@ -24,7 +24,7 @@ pub fn load(path : &str, instruction_size: i32) -> Machine { let res = u64::from_str_radix(&line.unwrap(), 16); match res { Ok(value) => { - Machine::write_memory(&mut machine, instruction_size, i, value); + Machine::write_memory(&mut machine, instruction_size, i*instruction_size as usize, value); }, _ => panic!() } diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 662ae2d..e7af292 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -609,6 +609,17 @@ impl Machine { machine.pc += 4; // Possible bug avec jump } + + pub fn print_memory(machine : &mut Machine) { + for i in 0..MEM_SIZE { + if i%16 == 0 { + print!("\n@{:04x} ", i); + } + print!("{:02x}", machine.main_memory[i]); + } + println!(); + } + } #[cfg(test)] diff --git a/src/simulator/mem_cmp.rs b/src/simulator/mem_cmp.rs index 8b3bed4..5c81029 100644 --- a/src/simulator/mem_cmp.rs +++ b/src/simulator/mem_cmp.rs @@ -232,11 +232,11 @@ fn one_hex_to_dec(c: char) -> u8 { 'E' | 'e' => 14, 'F' | 'f' => 15, _ => { - let ret : u8 = c.to_digit(10).unwrap() as u8; + let ret : u8 = c.to_digit(10).unwrap() as u8; return ret; - }, - } + }, } +} diff --git a/src/simulator/print.rs b/src/simulator/print.rs index 4cf103b..0539a43 100644 --- a/src/simulator/print.rs +++ b/src/simulator/print.rs @@ -217,7 +217,7 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64 RISCV_SYSTEM => { "ecall".to_string() }, - _ => todo!("Unknown or currently unsupported opcode") // Change todo! to panic! in the future, I put todo! because there's a lot of opcode currently not implemented + _ => todo!("{:x} opcode non géré pc : {:x}, value : {:x}", ins.opcode, pc, ins.value) // Change todo! to panic! in the future, I put todo! because there's a lot of opcode currently not implemented } }