From 0d707512791c1b44bec78775d40b7642c4180977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Wed, 12 Apr 2023 13:50:54 +0200 Subject: [PATCH] Moved sc_sem_create to own function --- src/kernel/exception.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index de86c49..8d13d23 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -205,18 +205,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 => { - 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); - - if initial_count <0{ - - } - Ok(MachineOk::Ok) - - }, + SC_SEM_CREATE => sc_sem_create(machine), SC_SEM_DESTROY => todo!(), SC_LOCK_CREATE => todo!(), SC_LOCK_DESTROY => todo!(), @@ -256,6 +245,17 @@ fn sc_v(machine: &mut Machine, system: &mut System) -> Result<(), Error> { } } +fn sc_sem_create(machine: &mut Machine) -> Result<(), Error> { + 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); + match initial_count < 0 { + true => Err(format!("Initial_count < 0")), + false => Ok(()) + } +} + fn get_length_param(addr: usize, machine: & Machine) -> usize{ let mut i = 0; let mut c = 1;