Swap out execution status for instructions returning an InstructionResult

This commit is contained in:
2025-10-03 13:28:02 +02:00
parent 4632fe29ce
commit bb0007707c
2 changed files with 13 additions and 23 deletions

View File

@@ -3,18 +3,19 @@ use crate::{
mem::MemConfig, mem::MemConfig,
}; };
#[derive(PartialEq, Debug, Clone, Copy)] // placeholder - change when exception system is in place
pub enum ExecutionStatus { pub(crate) type Exception = ();
Running,
Paused, pub(crate) enum InstructionResult {
Halted, Normal,
Exception(Exception),
Pause,
} }
pub struct Core { pub struct Core {
x_regs: [RegValue; 32], x_regs: [RegValue; 32],
pc: Addr, pc: Addr,
mem: MemConfig, mem: MemConfig,
exec_status: ExecutionStatus,
} }
impl Core { impl Core {
@@ -23,26 +24,11 @@ impl Core {
x_regs: [0; 32], x_regs: [0; 32],
pc: 0, pc: 0,
mem, mem,
exec_status: ExecutionStatus::Halted,
} }
} }
pub fn reset(&mut self, pc: Addr) { pub fn reset(&mut self, pc: Addr) {
self.pc = pc; self.pc = pc;
self.exec_status = ExecutionStatus::Running;
}
pub fn resume(&mut self) -> ExecutionStatus {
if self.exec_status == ExecutionStatus::Halted {
ExecutionStatus::Halted
} else {
self.exec_status = ExecutionStatus::Running;
ExecutionStatus::Running
}
}
pub fn exec_status(&self) -> ExecutionStatus {
self.exec_status
} }
fn reg_read(&self, id: RegId) -> RegValue { fn reg_read(&self, id: RegId) -> RegValue {

View File

@@ -6,9 +6,13 @@ static INSTRUCTIONS: Lazy<[Option<OpcodeHandler>; 32]> = Lazy::new(|| {
instructions instructions
}); });
use crate::{consts::Word, core::Core, decode::Instruction}; use crate::{
consts::Word,
core::{Core, InstructionResult},
decode::Instruction,
};
type Runner = fn(&mut Core, Instruction) -> Result<(), ()>; type Runner = fn(&mut Core, Instruction) -> Result<(), InstructionResult>;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct InstructionHandler { struct InstructionHandler {