summaryrefslogtreecommitdiff
path: root/src/core.rs
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2025-12-27 21:33:39 +0100
committertaitep <taitep@taitep.se>2025-12-27 21:33:39 +0100
commit5c008bfc0446e4631dbab64be61159af04f78dd1 (patch)
tree852f7ee883f675b4c67cf424b8f7d17357e7742d /src/core.rs
parentb5d36b7969f2759147d58a80e0e5b62c215d2998 (diff)
Add exception values (what will go in mtval/stval)
Diffstat (limited to 'src/core.rs')
-rw-r--r--src/core.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/core.rs b/src/core.rs
index 8d51947..eb0549f 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -10,7 +10,7 @@ use crate::{
consts::{Addr, RegId, RegValue},
core::commands::CoreCmd,
decode::Instruction,
- exceptions::ExceptionType,
+ exceptions::{Exception, ExceptionType, MemoryException},
gdb::{self, DebugCommand, DebugStream, StopReason},
instructions::find_and_exec,
mem::MemConfig,
@@ -86,7 +86,8 @@ impl Core {
} => {
let data = (0..len)
.map(|offset| self.mem.read_byte(addr + offset))
- .collect();
+ .collect::<Result<_, MemoryException>>()
+ .map_err(Into::into);
responder.send(data)?;
}
@@ -101,7 +102,7 @@ impl Core {
Ok(_) => gdb::StopReason::Step,
Err(e) => {
self.throw_exception(e);
- gdb::StopReason::Exception(e)
+ gdb::StopReason::Exception(e.into())
}
})?;
}
@@ -132,14 +133,17 @@ impl Core {
if let Err(e) = self.step() {
self.throw_exception(e);
- return StopReason::Exception(e);
+ return StopReason::Exception(e.into());
}
}
}
- pub(crate) fn step(&mut self) -> Result<(), ExceptionType> {
+ pub(crate) fn step(&mut self) -> Result<(), Exception> {
if !self.pc.is_multiple_of(4) {
- self.throw_exception(ExceptionType::InstructionAddressMisaligned);
+ self.throw_exception(Exception {
+ type_: ExceptionType::InstructionAddressMisaligned,
+ value: self.pc,
+ });
}
let instr = match self.mem.read_word(self.pc) {
@@ -149,13 +153,13 @@ impl Core {
}
};
- if instr == 0 {
- return Err(ExceptionType::IllegalInstruction);
- }
-
if instr & 3 != 3 {
// Compressed instruction - (currently) unsupported
- return Err(ExceptionType::IllegalInstruction);
+ // Could also be zero instruction, that also matches this
+ return Err(Exception {
+ type_: ExceptionType::IllegalInstruction,
+ value: instr as u64,
+ });
}
let instr = Instruction(instr);
@@ -168,8 +172,8 @@ impl Core {
Ok(())
}
- fn throw_exception(&mut self, exception_type: ExceptionType) {
- eprintln!("Exception: {exception_type:?}");
+ fn throw_exception(&mut self, exception: Exception) {
+ eprintln!("Exception: {exception:?}");
dbg!(self.pc, self.x_regs);
}