forked from Rativel/BurritOS
Add new thread exception (untested)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
|
||||
|
||||
use super::system::System;
|
||||
use super::{system::System, thread::Thread};
|
||||
|
||||
/// The halt system call. Stops Burritos.
|
||||
pub const SC_SHUTDOWN: u8 = 0;
|
||||
@@ -165,13 +167,44 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
|
||||
},
|
||||
SC_SEEK => todo!(),
|
||||
SC_CLOSE => todo!(),
|
||||
SC_NEW_THREAD => todo!(),
|
||||
SC_NEW_THREAD => {
|
||||
// Get the address of the string for the name of the thread
|
||||
let name_addr = machine.read_int_register(10) as usize;
|
||||
// Get the pointer of the function to be executed in the new thread
|
||||
let func = machine.read_int_register(11);
|
||||
// Get function parameters
|
||||
let args = machine.read_int_register(12);
|
||||
// get string name
|
||||
let name_size = get_length_param(name_addr, machine);
|
||||
let thread_name: String = get_string_param(name_addr, name_size, machine).into_iter().collect();
|
||||
|
||||
let n_thread = Thread::new(thread_name.as_str());
|
||||
let n_thread = Rc::new(RefCell::new(n_thread));
|
||||
let current_thread = match system.get_thread_manager().get_g_current_thread() {
|
||||
Some(th) => {
|
||||
Rc::clone(th)
|
||||
},
|
||||
None => {
|
||||
return Err("Current thread is none")?;
|
||||
}
|
||||
};
|
||||
let current_thread = current_thread.borrow_mut();
|
||||
if let Some(process) = current_thread.get_process_owner() {
|
||||
system.get_thread_manager().start_thread(n_thread, Rc::clone(&process), func as u64, current_thread.thread_context.int_registers[2] as u64, args);
|
||||
// TODO changé la valeur de sp quand on supportera les addresses virtuels
|
||||
// machine.write_fp_register(10, tid); // tid obtenu en faisant int32_t tid = g_object_addrs->AddObject(ptThread);
|
||||
Ok(MachineOk::Ok)
|
||||
} else {
|
||||
return Err("Process owner of current thread is none")?;
|
||||
}
|
||||
|
||||
},
|
||||
SC_YIELD => todo!(),
|
||||
SC_PERROR => todo!(),
|
||||
SC_P => todo!(),
|
||||
SC_V => todo!(),
|
||||
SC_SEM_CREATE => {
|
||||
let addr_name = machine.read_int_register(10);
|
||||
let addr_name = machine.read_int_register(10) as usize;
|
||||
let initial_count = machine.read_int_register(11);
|
||||
let size = get_length_param(addr_name as usize, machine);
|
||||
let _name = get_string_param(addr_name, size, machine);
|
||||
@@ -216,14 +249,14 @@ fn get_length_param(addr: usize, machine: & Machine) -> usize{
|
||||
i + 1
|
||||
}
|
||||
|
||||
fn get_string_param(addr: i64, maxlen: usize, machine: &Machine) -> Vec<char>{
|
||||
fn get_string_param(addr: usize, maxlen: usize, machine: &Machine) -> Vec<char>{
|
||||
let mut dest = Vec::with_capacity(maxlen);
|
||||
|
||||
let mut i: usize = 0;
|
||||
let mut c = 1;
|
||||
|
||||
while c != 0 && i < maxlen {
|
||||
c = machine.read_memory(1, addr as usize + i) as u8;
|
||||
c = machine.read_memory(1, addr + i) as u8;
|
||||
//dest.push(c as char);
|
||||
dest[i] = c as char;
|
||||
i += 1;
|
||||
|
||||
Reference in New Issue
Block a user