Added shutdown system call
This commit is contained in:
parent
e117ec2132
commit
2981925401
@ -1,7 +1,7 @@
|
||||
use crate::simulator::machine::{ExceptionType, Machine};
|
||||
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
|
||||
|
||||
|
||||
pub const SC_HALT: u8 = 0;
|
||||
pub const SC_SHUTDOWN: u8 = 0;
|
||||
pub const SC_EXIT: u8 = 1;
|
||||
pub const SC_EXEC: u8 = 2;
|
||||
pub const SC_JOIN: u8 = 3;
|
||||
@ -17,28 +17,28 @@ pub const SC_PERROR: u8 = 12;
|
||||
pub const SC_P: u8 = 13;
|
||||
pub const SC_V: u8 = 14;
|
||||
pub const SC_SEM_CREATE: u8 = 15 ;
|
||||
pub const SC_SEM_DESTROY: u8 = 16;
|
||||
pub const SC_LOCK_CREATE: u8 = 17 ;
|
||||
pub const SC_LOCK_DESTROY: u8 = 18 ;
|
||||
pub const SC_LOCK_ACQUIRE: u8 = 19 ;
|
||||
pub const SC_LOCK_RELEASE: u8 = 20 ;
|
||||
pub const SC_COND_CREATE: u8 = 21 ;
|
||||
pub const SC_COND_DESTROY: u8 = 22 ;
|
||||
pub const SC_COND_WAIT: u8 = 23 ;
|
||||
pub const SC_COND_SIGNAL: u8 = 24;
|
||||
pub const SC_SEM_DESTROY: u8 = 16;
|
||||
pub const SC_LOCK_CREATE: u8 = 17 ;
|
||||
pub const SC_LOCK_DESTROY: u8 = 18 ;
|
||||
pub const SC_LOCK_ACQUIRE: u8 = 19 ;
|
||||
pub const SC_LOCK_RELEASE: u8 = 20 ;
|
||||
pub const SC_COND_CREATE: u8 = 21 ;
|
||||
pub const SC_COND_DESTROY: u8 = 22 ;
|
||||
pub const SC_COND_WAIT: u8 = 23 ;
|
||||
pub const SC_COND_SIGNAL: u8 = 24;
|
||||
pub const SC_COND_BROADCAST: u8 = 25;
|
||||
pub const SC_TTY_SEND: u8 = 26;
|
||||
pub const SC_TTY_RECEIVE: u8 = 27;
|
||||
pub const SC_MKDIR: u8 = 28;
|
||||
pub const SC_RMDIR: u8 = 29;
|
||||
pub const SC_REMOVE: u8 = 30;
|
||||
pub const SC_FSLIST: u8 = 31;
|
||||
pub const SC_SYS_TIME: u8 = 32 ;
|
||||
pub const SC_MMAP: u8 = 33;
|
||||
pub const SC_DEBUG: u8 = 34;
|
||||
pub const SC_TTY_SEND: u8 = 26;
|
||||
pub const SC_TTY_RECEIVE: u8 = 27;
|
||||
pub const SC_MKDIR: u8 = 28;
|
||||
pub const SC_RMDIR: u8 = 29;
|
||||
pub const SC_REMOVE: u8 = 30;
|
||||
pub const SC_FSLIST: u8 = 31;
|
||||
pub const SC_SYS_TIME: u8 = 32 ;
|
||||
pub const SC_MMAP: u8 = 33;
|
||||
pub const SC_DEBUG: u8 = 34;
|
||||
|
||||
|
||||
pub fn call(exception: ExceptionType, machine: &Machine) {
|
||||
pub fn call(exception: ExceptionType, machine: &Machine) -> Result<MachineOk, MachineError> {
|
||||
|
||||
match exception {
|
||||
ExceptionType::NoException => todo!(),
|
||||
@ -53,8 +53,45 @@ pub fn call(exception: ExceptionType, machine: &Machine) {
|
||||
}
|
||||
}
|
||||
|
||||
fn syscall(machine: &Machine) {
|
||||
let call_type = machine.read_int_register(17);
|
||||
fn syscall(machine: &Machine) -> Result<MachineOk, MachineError> {
|
||||
let call_type = machine.read_int_register(17) as u8;
|
||||
|
||||
todo!()
|
||||
match call_type {
|
||||
SC_SHUTDOWN => Ok(MachineOk::Shutdown),
|
||||
SC_EXIT => todo!(),
|
||||
SC_EXEC => todo!(),
|
||||
SC_JOIN => todo!(),
|
||||
SC_CREATE => todo!(),
|
||||
SC_OPEN => todo!(),
|
||||
SC_READ => todo!(),
|
||||
SC_WRITE => todo!(),
|
||||
SC_SEEK => todo!(),
|
||||
SC_CLOSE => todo!(),
|
||||
SC_NEW_THREAD => todo!(),
|
||||
SC_YIELD => todo!(),
|
||||
SC_PERROR => todo!(),
|
||||
SC_P => todo!(),
|
||||
SC_V => todo!(),
|
||||
SC_SEM_CREATE => todo!(),
|
||||
SC_SEM_DESTROY => todo!(),
|
||||
SC_LOCK_CREATE => todo!(),
|
||||
SC_LOCK_DESTROY => todo!(),
|
||||
SC_LOCK_ACQUIRE => todo!(),
|
||||
SC_LOCK_RELEASE => todo!(),
|
||||
SC_COND_CREATE => todo!(),
|
||||
SC_COND_DESTROY => todo!(),
|
||||
SC_COND_WAIT => todo!(),
|
||||
SC_COND_SIGNAL => todo!(),
|
||||
SC_COND_BROADCAST => todo!(),
|
||||
SC_TTY_SEND => todo!(),
|
||||
SC_TTY_RECEIVE => todo!(),
|
||||
SC_MKDIR => todo!(),
|
||||
SC_RMDIR => todo!(),
|
||||
SC_REMOVE => todo!(),
|
||||
SC_FSLIST => todo!(),
|
||||
SC_SYS_TIME => todo!(),
|
||||
SC_MMAP => todo!(),
|
||||
SC_DEBUG => todo!(),
|
||||
_ => todo!()
|
||||
}
|
||||
}
|
@ -230,7 +230,13 @@ impl Machine {
|
||||
|
||||
self.set_status(MachineStatus::SystemMode);
|
||||
// Handle the interruption
|
||||
exception::call(exception, self); // todo: return error if the syscall code is invalid
|
||||
match exception::call(exception, self) {
|
||||
Ok(MachineOk::Shutdown) => {
|
||||
self.set_status(MachineStatus::UserMode);
|
||||
return Ok(MachineOk::Shutdown);
|
||||
}
|
||||
_ => ()
|
||||
} // todo: return error if the syscall code is invalid
|
||||
self.set_status(MachineStatus::UserMode);
|
||||
Ok(MachineOk::Ok)
|
||||
}
|
||||
@ -243,7 +249,8 @@ impl Machine {
|
||||
pub fn run(&mut self) {
|
||||
loop {
|
||||
match self.one_instruction() {
|
||||
Ok(_) => println!("hello"),
|
||||
Ok(MachineOk::Ok) => println!("hello"),
|
||||
Ok(MachineOk::Shutdown) => break,
|
||||
Err(e) => { if e.to_string().contains("System") { break; } panic!("FATAL at pc {} -> {}", self.pc, e) }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user