use core::arch::asm;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct Stvt {
bits: usize,
}
impl Stvt {
#[inline]
pub const fn base_address(self) -> usize {
self.bits & !0b111111
}
}
#[inline]
pub unsafe fn write(addr: usize) {
assert!(
addr & 0b111111 == 0,
"CLIC vector base address must align to 64 bytes"
);
asm!("csrw 0x307, {}", in(reg) addr)
}
#[inline]
pub fn read() -> Stvt {
let bits: usize;
unsafe { asm!("csrr {}, 0x107", out(reg) bits) };
Stvt { bits }
}