diff options
Diffstat (limited to 'src/exceptions.rs')
| -rw-r--r-- | src/exceptions.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/exceptions.rs b/src/exceptions.rs index 2929d65..7f00e5c 100644 --- a/src/exceptions.rs +++ b/src/exceptions.rs @@ -10,7 +10,7 @@ use int_enum::IntEnum; #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq, Eq, IntEnum)] pub enum ExceptionType { - InstructionAccessMisaligned = 0, + InstructionAddressMisaligned = 0, InstructionAccessFault = 1, IllegalInstruction = 2, Breakpoint = 3, @@ -28,3 +28,35 @@ pub enum ExceptionType { SoftwareCheck = 18, HardwareError = 19, } + +pub enum MemoryExceptionType { + AddressMisaligned, + AccessFault, + 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, + } + } + + 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_load(&self) -> ExceptionType { + match self { + Self::AddressMisaligned => ExceptionType::LoadAddressMisaligned, + Self::AccessFault => ExceptionType::LoadAccessFault, + Self::PageFault => ExceptionType::LoadPageFault, + } + } +} |
