blob: bc607a63a603d72bb7edefa8caef3f88ab1d4ae7 [file] [log] [blame]
//! Anything in Matcha that needs to poke hardware registers directly will
//! go in this crate.
#![no_std]
#![feature(asm)]
pub mod debug_uart;
pub mod mailbox;
pub mod plic;
pub mod plic_constants;
// Software interrupt enable bits in MIE
pub const USIE_BIT: u32 = 1 << 0;
pub const SSIE_BIT: u32 = 1 << 1;
pub const MSIE_BIT: u32 = 1 << 3;
// External interrupt enable bits in MIE
pub const UEIE_BIT: u32 = 1 << 8;
pub const SEIE_BIT: u32 = 1 << 9;
pub const MEIE_BIT: u32 = 1 << 11;
// Global interrupt enable bits in MSTATUS
pub const UIE_BIT: u32 = 0b00000001;
pub const SIE_BIT: u32 = 0b00000010;
pub const MIE_BIT: u32 = 0b00001000;
pub unsafe fn set_mtvec(v: u32) {
asm!("csrw mtvec, {}", in(reg) v);
}
pub unsafe fn set_mstatus_bits(mask: u32) {
asm!("csrrs zero, mstatus, {}", in(reg) mask);
}
pub unsafe fn clear_mstatus_bits(mask: u32) {
asm!("csrrc zero, mstatus, {}", in(reg) mask);
}
pub unsafe fn set_mie_bits(mask: u32) {
asm!("csrrs zero, mie, {}", in(reg) mask);
}
pub unsafe fn clear_mie_bits(mask: u32) {
asm!("csrrc zero, mie, {}", in(reg) mask);
}