Add exception values (what will go in mtval/stval)
This commit is contained in:
30
src/core.rs
30
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user