diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 67a2026..4009d8a 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -1,6 +1,7 @@ use std::{cell::RefCell, rc::Rc}; use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}}; +use crate::kernel::synch::Semaphore; use super::{system::System, thread::Thread}; @@ -172,7 +173,7 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result todo!(), SC_P => sc_p(machine, system), SC_V => sc_v(machine, system), - SC_SEM_CREATE => sc_sem_create(machine), + SC_SEM_CREATE => sc_sem_create(machine, system), SC_SEM_DESTROY => todo!(), SC_LOCK_CREATE => todo!(), SC_LOCK_DESTROY => todo!(), @@ -206,14 +207,17 @@ fn sc_v(machine: &mut Machine, system: &mut System) -> Result Result { +fn sc_sem_create(machine: &mut Machine, system: &mut System) -> Result { let addr_name = machine.read_int_register(10) as usize; - let initial_count = machine.read_int_register(11); + let initial_count = machine.read_int_register(11) as i32; let size = get_length_param(addr_name as usize, machine); let _name = get_string_param(addr_name, size, machine); match initial_count < 0 { true => Err(format!("Initial_count < 0"))?, - false => Ok(MachineOk::Ok) + false => { + system.get_thread_manager().get_obj_addrs().add_semaphore(Semaphore::new(initial_count)); + Ok(MachineOk::Ok) + } } }