diff options
| author | taitep <taitep@taitep.se> | 2025-10-04 14:07:42 +0200 |
|---|---|---|
| committer | taitep <taitep@taitep.se> | 2025-10-04 14:07:42 +0200 |
| commit | 52952840aa57512f3bbf06ea0054b5b742aabf20 (patch) | |
| tree | a064ac32313abbf79480d482e6ac67d6b87fea66 /src/core.rs | |
| parent | bb0007707c7f67f368eb1e0c644d33f986be113f (diff) | |
I guess its a working execution loop?
Diffstat (limited to 'src/core.rs')
| -rw-r--r-- | src/core.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/core.rs b/src/core.rs index fdaeafb..5a0cbe5 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,5 +1,7 @@ use crate::{ consts::{Addr, RegId, RegValue}, + decode::Instruction, + instructions::find_runner, mem::MemConfig, }; @@ -27,6 +29,46 @@ impl Core { } } + pub fn run(&mut self) { + loop { + let page = (self.pc / 4096) as usize; + let offset = (self.pc / 4) as u16; + if !self.pc.is_multiple_of(4) { + //replace eprint with logging, replace break with exception + eprintln!("PC not aligned"); + break; + } + + let instr = match self.mem.read_word(page, offset) { + Ok(i) => i, + Err(_) => { + eprintln!("Memory access fault while fetching instruction"); + break; + } + }; + + let instr = Instruction(instr); + + let runner = find_runner(instr); + + if let Some(runner) = runner { + let res = runner(self, instr); + + match res { + InstructionResult::Normal => {} + InstructionResult::Exception(_e) => { + eprintln!("Exception from instruction"); + break; + } + InstructionResult::Pause => { + eprintln!("Instruction asked for pause"); + break; + } + } + } + } + } + pub fn reset(&mut self, pc: Addr) { self.pc = pc; } |
