Added shutdown system call

This commit is contained in:
Samy Solhi
2023-03-29 17:21:34 +02:00
parent e117ec2132
commit 2981925401
2 changed files with 70 additions and 26 deletions

View File

@ -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) }
}
}