diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 64b7e28..de86c49 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -203,7 +203,7 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result todo!(), SC_PERROR => todo!(), - SC_P => todo!(), + SC_P => sc_p(machine, system), SC_V => sc_v(machine, system), SC_SEM_CREATE => { let addr_name = machine.read_int_register(10) as usize; @@ -240,7 +240,15 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result Result<(), Error>{ +fn sc_p(machine: &mut Machine, system: &mut System) -> Result<(), Error> { + let id_sema = machine.int_reg.get_reg(10); + match system.get_obj_addrs().search_semaphore(id_sema) { + Some(sema) => { sema.p(machine, system.get_thread_manager()); Ok(()) } + None => Err(format!("Coudn't find semaphore {}", id_sema)) + } +} + +fn sc_v(machine: &mut Machine, system: &mut System) -> Result<(), Error> { let id_sema = machine.int_reg.get_reg(10); match system.get_obj_addrs().search_semaphore(id_sema) { Some(sema) => { sema.v(machine, system.get_thread_manager()); Ok(()) },