From 355071a2f1a0677c3f4424384b554e0183604c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Wed, 12 Apr 2023 13:28:55 +0200 Subject: [PATCH] Added sc_p call --- src/kernel/exception.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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(()) },