summaryrefslogtreecommitdiff
path: root/src/core.rs
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2025-09-27 21:43:10 +0200
committertaitep <taitep@taitep.se>2025-09-27 21:43:10 +0200
commit3163b43fa48f7db6f45075f5f24ff130d33b22b2 (patch)
treeba79feb7760d1e483f3dade6d1de33ede49e3d10 /src/core.rs
parent5919041f07c1e49b53833a38002f22d8712230de (diff)
base core state & instruction decoder
Diffstat (limited to 'src/core.rs')
-rw-r--r--src/core.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/core.rs b/src/core.rs
new file mode 100644
index 0000000..48668b5
--- /dev/null
+++ b/src/core.rs
@@ -0,0 +1,58 @@
+use crate::{
+ consts::{Addr, RegId, RegValue},
+ mem::MemConfig,
+};
+
+#[derive(PartialEq, Debug, Clone, Copy)]
+pub enum ExecutionStatus {
+ Running,
+ Paused,
+ Halted,
+}
+
+pub struct Core {
+ x_regs: [RegValue; 32],
+ pc: Addr,
+ mem: MemConfig,
+ exec_status: ExecutionStatus,
+}
+
+impl Core {
+ pub fn new(mem: MemConfig) -> Self {
+ Self {
+ 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 {
+ self.x_regs[id as usize]
+ }
+
+ fn reg_write(&mut self, id: RegId, value: RegValue) {
+ if id == 0 {
+ return;
+ }
+ self.x_regs[id as usize] = value;
+ }
+}