diff options
Diffstat (limited to 'src/exceptions.rs')
| -rw-r--r-- | src/exceptions.rs | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/src/exceptions.rs b/src/exceptions.rs index 9a84edc..5e3f02f 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -6,6 +6,8 @@ use int_enum::IntEnum; +use crate::consts::{Addr, DWord}; + #[repr(u8)] #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq, IntEnum)] @@ -29,6 +31,12 @@ pub enum ExceptionType { HardwareError = 19, } +#[derive(Debug, Clone, Copy)] +pub struct Exception { + pub type_: ExceptionType, + pub value: DWord, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MemoryExceptionType { AddressMisaligned, @@ -36,28 +44,55 @@ pub enum MemoryExceptionType { PageFault, } -impl MemoryExceptionType { - pub(crate) fn to_exception_store(&self) -> ExceptionType { - match self { - Self::AddressMisaligned => ExceptionType::StoreAmoAddressMisaligned, - Self::AccessFault => ExceptionType::StoreAmoAccessFault, - Self::PageFault => ExceptionType::StoreAmoPageFault, +#[derive(Debug, Clone, Copy)] +pub struct MemoryException { + pub type_: MemoryExceptionType, + pub addr: Addr, +} + +impl MemoryException { + pub(crate) fn to_exception_store(&self) -> Exception { + Exception { + type_: match self.type_ { + MemoryExceptionType::AddressMisaligned => ExceptionType::StoreAmoAddressMisaligned, + MemoryExceptionType::AccessFault => ExceptionType::StoreAmoAccessFault, + MemoryExceptionType::PageFault => ExceptionType::StoreAmoPageFault, + }, + value: self.addr, } } - pub(crate) fn to_exception_instr(&self) -> ExceptionType { - match self { - Self::AddressMisaligned => ExceptionType::InstructionAddressMisaligned, - Self::AccessFault => ExceptionType::InstructionAccessFault, - Self::PageFault => ExceptionType::InstructionPageFault, + pub(crate) fn to_exception_instr(&self) -> Exception { + Exception { + type_: match self.type_ { + MemoryExceptionType::AddressMisaligned => ExceptionType::InstructionAccessFault, + MemoryExceptionType::AccessFault => ExceptionType::InstructionAccessFault, + MemoryExceptionType::PageFault => ExceptionType::InstructionPageFault, + }, + value: self.addr, } } - pub(crate) fn to_exception_load(&self) -> ExceptionType { - match self { - Self::AddressMisaligned => ExceptionType::LoadAddressMisaligned, - Self::AccessFault => ExceptionType::LoadAccessFault, - Self::PageFault => ExceptionType::LoadPageFault, + pub(crate) fn to_exception_load(&self) -> Exception { + Exception { + type_: match self.type_ { + MemoryExceptionType::AddressMisaligned => ExceptionType::LoadAddressMisaligned, + MemoryExceptionType::AccessFault => ExceptionType::LoadAccessFault, + MemoryExceptionType::PageFault => ExceptionType::LoadPageFault, + }, + value: self.addr, } } } + +impl Into<MemoryExceptionType> for MemoryException { + fn into(self) -> MemoryExceptionType { + self.type_ + } +} + +impl Into<ExceptionType> for Exception { + fn into(self) -> ExceptionType { + self.type_ + } +} |
