Initialize sp value for each threads (temporary workaround)

This commit is contained in:
Quentin Legot
2023-04-02 19:55:06 +02:00
parent 8239079130
commit 8c844c3e5c
3 changed files with 13 additions and 12 deletions

View File

@ -47,10 +47,10 @@ impl Thread {
}
}
pub fn init_thread_context(&mut self, initial_pc_reg: u64, initial_sp: i64, arg: i64) {
pub fn init_thread_context(&mut self, initial_pc_reg: u64, initial_sp: u64, arg: i64) {
self.thread_context.pc = initial_pc_reg;
self.thread_context.int_registers[10] = arg;
self.thread_context.int_registers[STACK_REG] = initial_sp;
self.thread_context.int_registers[STACK_REG] = initial_sp as i64;
}
pub fn init_simulator_context(&self, base_stack_addr: [i8; SIMULATORSTACKSIZE]) {

View File

@ -86,11 +86,11 @@ impl ThreadManager {
}
/// Start a thread, attaching it to a process
pub fn start_thread(&mut self, thread: Rc<RefCell<Thread>>, owner: Process, func_pc: u64, argument: i64) {
pub fn start_thread(&mut self, thread: Rc<RefCell<Thread>>, owner: Process, func_pc: u64, sp_loc: u64, argument: i64) {
let mut thread_m = thread.borrow_mut();
assert_eq!(thread_m.process, Option::None);
thread_m.process = Option::Some(owner);
let ptr = 0; // todo addrspace
let ptr = sp_loc; // todo addrspace
thread_m.init_thread_context(func_pc, ptr, argument);
let base_stack_addr: [i8; SIMULATORSTACKSIZE] = [0; SIMULATORSTACKSIZE]; // todo AllocBoundedArray
thread_m.init_simulator_context(base_stack_addr);
@ -206,7 +206,7 @@ mod test {
#[ignore = "Pas encore terminé, contient des bugs"]
fn test_thread_context() {
let mut machine = Machine::init_machine();
let loader = loader::Loader::new("./test/riscv_instructions/simple_arithmetics/unsigned_addition", &mut machine, 0).expect("IO Error");
let (loader, ptr) = loader::Loader::new("./test/riscv_instructions/simple_arithmetics/unsigned_addition", &mut machine, 0).expect("IO Error");
let start_pc = loader.elf_header.entrypoint;
let system = &mut System::default();
@ -215,7 +215,7 @@ mod test {
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, -1);
system.get_thread_manager().start_thread(Rc::clone(&thread1), owner, start_pc, ptr, -1);
debug_assert_eq!(thread1.borrow_mut().thread_context.pc, start_pc);
let to_run = system.get_thread_manager().find_next_to_run().unwrap();