Initialize sp value for each threads (temporary workaround)
This commit is contained in:
parent
8239079130
commit
8c844c3e5c
@ -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]) {
|
||||
|
@ -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();
|
||||
|
@ -308,16 +308,18 @@ pub enum LoaderError {
|
||||
|
||||
impl Loader {
|
||||
|
||||
pub fn new(path: &str, machine: &mut Machine, start_index: usize) -> Result<Self, LoaderError> {
|
||||
pub fn new(path: &str, machine: &mut Machine, start_index: usize) -> Result<(Self, u64), LoaderError> {
|
||||
let loader = Self::load_and_parse(path)?;
|
||||
loader.load_into_machine(machine, start_index)?;
|
||||
Ok(loader)
|
||||
let end_alloc = loader.load_into_machine(machine, start_index)?;
|
||||
Ok((loader, end_alloc))
|
||||
}
|
||||
|
||||
fn load_into_machine(&self, machine: &mut Machine, start_index: usize) -> Result<u64, LoaderError>{
|
||||
fn load_into_machine(&self, machine: &mut Machine, start_index: usize) -> Result<u64, LoaderError> {
|
||||
let mut end_index = 0;
|
||||
for i in 0..self.sections.len() {
|
||||
let section = &self.sections[i];
|
||||
if section.does_flag_contains_key(FlagValue::ShfAlloc) {
|
||||
end_index = section.virt_addr + section.section_size;
|
||||
// Can allocate to machine memory
|
||||
for j in (0..section.section_size as usize).step_by(4) {
|
||||
let mut buf: [u8; 4] = [0; 4];
|
||||
@ -328,8 +330,7 @@ impl Loader {
|
||||
}
|
||||
}
|
||||
}
|
||||
let last = self.sections.last().ok_or(LoaderError::ParsingError)?;
|
||||
Ok(start_index as u64 + last.virt_addr + last.section_size)
|
||||
Ok(start_index as u64 + end_index)
|
||||
}
|
||||
|
||||
fn load_and_parse(path: &str) -> Result<Self, LoaderError> {
|
||||
|
Loading…
Reference in New Issue
Block a user