Added sc_v call

This commit is contained in:
François Autin
2023-04-12 13:25:33 +02:00
parent afce2c66c9
commit 729eba656c
2 changed files with 45 additions and 21 deletions

View File

@ -1,8 +1,10 @@
use std::{cell::RefCell, rc::Rc};
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}};
use super::{system::System, thread::Thread};
use super::{system::System, thread::Thread, synch::Semaphore};
type Error = String;
/// The halt system call. Stops Burritos.
pub const SC_SHUTDOWN: u8 = 0;
@ -202,7 +204,7 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
SC_YIELD => todo!(),
SC_PERROR => todo!(),
SC_P => todo!(),
SC_V => todo!(),
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);
@ -238,6 +240,14 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
}
}
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(()) },
None => Err(format!("Couldn't find semaphore {}", id_sema))
}
}
fn get_length_param(addr: usize, machine: & Machine) -> usize{
let mut i = 0;
let mut c = 1;