64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
// Copyright (c) 2025 taitep
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
//
|
|
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
|
|
// See LICENSE file in the project root for full license text.
|
|
|
|
use int_enum::IntEnum;
|
|
|
|
#[repr(u8)]
|
|
#[allow(dead_code)]
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, IntEnum)]
|
|
pub enum ExceptionType {
|
|
InstructionAddressMisaligned = 0,
|
|
InstructionAccessFault = 1,
|
|
IllegalInstruction = 2,
|
|
Breakpoint = 3,
|
|
LoadAddressMisaligned = 4,
|
|
LoadAccessFault = 5,
|
|
StoreAmoAddressMisaligned = 6,
|
|
StoreAmoAccessFault = 7,
|
|
EnvironmentCallFromUMode = 8,
|
|
EnvironmentCallFromSMode = 9,
|
|
EnvironmentCallFromMMode = 11,
|
|
InstructionPageFault = 12,
|
|
LoadPageFault = 13,
|
|
StoreAmoPageFault = 15,
|
|
DoubleTrap = 16,
|
|
SoftwareCheck = 18,
|
|
HardwareError = 19,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
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,
|
|
}
|
|
}
|
|
}
|