From 703c8e5448a92333b18b875178847259e3a17612 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 28 Mar 2023 21:26:58 +0200 Subject: [PATCH] Loader seem to work, be seem we have a problem with jalr --- src/kernel/thread_manager.rs | 9 +++++++-- src/simulator/loader.rs | 4 ++-- src/simulator/machine.rs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index 07390a6..e88cf59 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -207,20 +207,25 @@ mod test { fn test_thread_context() { let mut machine = Machine::init_machine(); loader::load("./test/riscv_instructions/simple_arithmetics/unsigned_addition", &mut machine, 0).expect("IO Error"); - let start_pc = 0x4000; + let start_pc = 0x1000; let system = &mut System::default(); + let thread1 = Thread::new("th1"); let thread1 = Rc::new(RefCell::new(thread1)); system.get_thread_manager().get_g_alive().push(Rc::clone(&thread1)); + let owner = Process { num_thread: 0 }; - system.get_thread_manager().start_thread(Rc::clone(&thread1), owner, start_pc, 0); + system.get_thread_manager().start_thread(Rc::clone(&thread1), owner, start_pc, -1); debug_assert_eq!(thread1.borrow_mut().thread_context.pc, start_pc); + let to_run = system.get_thread_manager().find_next_to_run().unwrap(); debug_assert_eq!(to_run, Rc::clone(&thread1)); debug_assert!(system.get_thread_manager().get_g_alive().contains(&Rc::clone(&thread1))); + system.get_thread_manager().switch_to(&mut machine, Rc::clone(&to_run)); debug_assert_eq!(system.get_thread_manager().g_current_thread, Option::Some(Rc::clone(&thread1))); debug_assert_eq!(machine.pc, start_pc); + machine.run(); } diff --git a/src/simulator/loader.rs b/src/simulator/loader.rs index 3404128..4ed2b64 100644 --- a/src/simulator/loader.rs +++ b/src/simulator/loader.rs @@ -59,7 +59,7 @@ pub fn load(path: &str, machine: &mut Machine, start_index: usize) -> Result<(), for i in 0..instructions.len() { machine.write_memory(4, 4 * i + start_index, instructions[i] as u64); } - #[cfg(debug_assertions)] - println!("{:04x?}", instructions); // only print loaded program in debug build + // #[cfg(debug_assertions)] + // println!("{:04x?}", instructions); // only print loaded program in debug build Ok(()) } \ No newline at end of file diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 0d9619b..1a8775a 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -240,7 +240,7 @@ impl Machine { let val = u32::from_be_bytes(val) as u64; let inst : Instruction = decode(val); self.print_status(); - println!("executing instruction : {:016x} at pc {:x}", val, self.pc); + println!("executing instruction : {:016x} at pc 0x{:x}", val, self.pc); println!("{}", print::print(decode(val), self.pc as i32)); let trace = Self::string_registers(self); self.registers_trace.push_str(format!("{}\n", trace).as_str());