From 77086155b5ecc5802475669efeabaa1d5ef78a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rativel?= Date: Wed, 5 Apr 2023 15:47:46 +0200 Subject: [PATCH 1/2] started to implement sc_sem_create and auxiliar function --- src/kernel/exception.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index b020f6e..bb99263 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -105,7 +105,13 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result todo!(), SC_P => todo!(), SC_V => todo!(), - SC_SEM_CREATE => todo!(), + SC_SEM_CREATE => { + let addr_name = machine.read_int_register(10); + let initial_count = machine.read_int_register((11)); + let size = get_length_param(addr_name as usize, machine); + Ok(MachineOk::Ok) + + }, SC_SEM_DESTROY => todo!(), SC_LOCK_CREATE => todo!(), SC_LOCK_DESTROY => todo!(), @@ -129,6 +135,17 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result usize{ + let mut i = 0; + let mut c = 1; + while c!= 0 { + c = machine.read_memory(1, addr + i); + i+=1; + + } + i + 1 +} + #[cfg(test)] mod test { use crate::kernel::exception::{SC_SHUTDOWN, SC_WRITE}; From a151bef7efb1d15415d04b7830ee050869699469 Mon Sep 17 00:00:00 2001 From: Samy Solhi Date: Wed, 5 Apr 2023 15:57:34 +0200 Subject: [PATCH 2/2] added fn get string param --- src/kernel/exception.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 24555fe..978cec6 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -120,6 +120,24 @@ fn syscall(machine: &Machine) -> Result { } } +fn get_string_param(addr: i64, maxlen: i64, machine: &Machine) -> Vec{ + let mut dest = Vec::with_capacity(maxlen as usize); + + let mut i = 0; + let mut c = 1; + + while c != 0 && i < maxlen { + c = machine.read_memory(1, (addr + i) as usize); + //dest.push(c as char); + dest[i] = c as char; + i += 1; + } + + dest[maxlen - 1] = '\0'; + + dest +} + #[cfg(test)] mod test { use crate::kernel::exception::{SC_SHUTDOWN, SC_WRITE};