use crate::isa::csr::{SATP_MODE_BARE, SATP_MODE_SV39, SATP_MODE_SV48, SATP_MODE_SV57};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PagingMode {
Bare,
Sv39,
Sv48,
Sv57,
}
impl PagingMode {
pub const fn from_satp_mode(mode: u64) -> Option<Self> {
match mode {
SATP_MODE_BARE => Some(Self::Bare),
SATP_MODE_SV39 => Some(Self::Sv39),
SATP_MODE_SV48 => Some(Self::Sv48),
SATP_MODE_SV57 => Some(Self::Sv57),
_ => None,
}
}
pub const fn levels(self) -> usize {
match self {
Self::Bare => 0,
Self::Sv39 => 3,
Self::Sv48 => 4,
Self::Sv57 => 5,
}
}
pub const fn va_top_bit(self) -> u32 {
match self {
Self::Bare => 63,
Self::Sv39 => 38,
Self::Sv48 => 47,
Self::Sv57 => 56,
}
}
pub const fn is_at_most(self, cap: Self) -> bool {
self.levels() <= cap.levels()
}
}