Improved syscall handling.

This commit is contained in:
2021-05-01 19:30:06 +01:00
parent e50d8f0ec4
commit d9be541f2e
5 changed files with 55 additions and 58 deletions

View File

@@ -207,9 +207,8 @@ impl Executable for Inst {
Inst::Mult (inst) => inst.exec(state),
Inst::Shift(inst) => inst.exec(state),
Inst::Store(inst) => inst.exec(state),
//Inst::Sys (inst) => inst.exec(state),
//Inst::Co (inst) => inst.exec(state),
_ => todo!(),
Inst::Sys (inst) => inst.exec(state),
Inst::Co (_) => todo!(),
}
}
}

View File

@@ -4,6 +4,7 @@
use super::ModifiesReg;
use crate::inst::{
basic::{Decode, TryEncode},
exec::{ExecCtx, ExecError, Executable},
parse::LineArg,
DisplayCtx, InstDisplay, InstFmtArg, Parsable, ParseCtx, ParseError, Register,
};
@@ -121,3 +122,9 @@ impl ModifiesReg for Inst {
false
}
}
impl Executable for Inst {
fn exec<Ctx: ExecCtx>(&self, state: &mut Ctx) -> Result<(), ExecError> {
state.sys(*self)
}
}

View File

@@ -7,6 +7,7 @@ pub mod error;
pub use error::ExecError;
// Imports
use super::basic;
use crate::{
inst::{basic::mult::MultReg, Register},
Pos,
@@ -40,6 +41,9 @@ pub trait ExecCtx:
/// Writes a byte
fn write_byte(&mut self, pos: Pos, value: u8) -> Result<(), ExecError>;
/// Executes a syscall
fn sys(&mut self, inst: basic::sys::Inst) -> Result<(), ExecError>;
}
/// An executable instruction

View File

@@ -33,6 +33,9 @@ pub enum ExecError {
JumpWhileJumping,
/// Unknown syscall
#[error("Unknown syscall")]
UnknownSys,
#[error("Unknown syscall {comment:#x}")]
UnknownSys {
/// Syscall comment
comment: u32,
},
}