diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 2c7f0d3..1c2e1d5 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -172,7 +172,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!(), @@ -196,6 +202,35 @@ 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 +} + +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}; @@ -241,7 +276,7 @@ mod test { machine.write_memory(4, 4, 0b000000000000_00000_000_10001_0010011); // r17 <- SC_SHUTDOWN machine.write_memory(4, 8, 0b000000000000_00000_000_00000_1110011); // ecall - + let mut system = System::default(); machine.run(&mut system); }