use crate::register::CpuMode;
use bit_field::BitField;
impl_define_csr!(
Prmd,
"Pre-exception Mode Information (PRMD)
When an exception is triggered,
if the exception type is not TLB refill exception and machine error exception,
the hardware will save the processor core’s `PLV`,`IE` and `WE` bits at that time,
to `PRMD` to restore the processor core to the context when the exception returns.
"
);
impl_read_csr!(0x1, Prmd);
impl Prmd {
pub fn pplv(&self) -> usize {
self.bits.get_bits(0..2)
}
pub fn pie(&self) -> bool {
self.bits.get_bit(2)
}
pub fn pwe(&self) -> bool {
self.bits.get_bit(3)
}
}
pub fn set_pplv(pplv: CpuMode) {
set_csr_loong_bits!(0x1, 0..2, pplv as usize);
}
pub fn set_pie(pie: bool) {
set_csr_loong_bit!(0x1, 2, pie);
}
pub fn set_pwe(pwe: bool) {
set_csr_loong_bit!(0x1, 3, pwe);
}