summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2025-10-03 13:28:02 +0200
committertaitep <taitep@taitep.se>2025-10-03 13:28:02 +0200
commitbb0007707c7f67f368eb1e0c644d33f986be113f (patch)
treee2c5a65ee67e6d44cca704883f35a3a281ad4a05
parent4632fe29ceec9aaacdaa8bb7ff1f1a4091c52622 (diff)
Swap out execution status for instructions returning an InstructionResult
-rw-r--r--src/core.rs28
-rw-r--r--src/instructions.rs8
2 files changed, 13 insertions, 23 deletions
diff --git a/src/core.rs b/src/core.rs
index 48668b5..fdaeafb 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -3,18 +3,19 @@ use crate::{
mem::MemConfig,
};
-#[derive(PartialEq, Debug, Clone, Copy)]
-pub enum ExecutionStatus {
- Running,
- Paused,
- Halted,
+// placeholder - change when exception system is in place
+pub(crate) type Exception = ();
+
+pub(crate) enum InstructionResult {
+ Normal,
+ Exception(Exception),
+ Pause,
}
pub struct Core {
x_regs: [RegValue; 32],
pc: Addr,
mem: MemConfig,
- exec_status: ExecutionStatus,
}
impl Core {
@@ -23,26 +24,11 @@ impl Core {
x_regs: [0; 32],
pc: 0,
mem,
- exec_status: ExecutionStatus::Halted,
}
}
pub fn reset(&mut self, pc: Addr) {
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 {
diff --git a/src/instructions.rs b/src/instructions.rs
index 9f3a544..e16894e 100644
--- a/src/instructions.rs
+++ b/src/instructions.rs
@@ -6,9 +6,13 @@ static INSTRUCTIONS: Lazy<[Option<OpcodeHandler>; 32]> = Lazy::new(|| {
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)]
struct InstructionHandler {