use linkme::distributed_slice as def_trap_handler;
use memory_addr::VirtAddr;
use page_table_entry::MappingFlags;
#[cfg(feature = "uspace")]
use crate::arch::TrapFrame;
pub use linkme::distributed_slice as register_trap_handler;
#[def_trap_handler]
pub static IRQ: [fn(usize) -> bool];
#[def_trap_handler]
pub static PAGE_FAULT: [fn(VirtAddr, MappingFlags, bool) -> bool];
#[cfg(feature = "uspace")]
#[def_trap_handler]
pub static SYSCALL: [fn(&TrapFrame, usize) -> isize];
#[allow(unused_macros)]
macro_rules! handle_trap {
($trap:ident, $($args:tt)*) => {{
let mut iter = $crate::trap::$trap.iter();
if let Some(func) = iter.next() {
if iter.next().is_some() {
warn!("Multiple handlers for trap {} are not currently supported", stringify!($trap));
}
func($($args)*)
} else {
warn!("No registered handler for trap {}", stringify!($trap));
false
}
}}
}
#[cfg(feature = "uspace")]
pub(crate) fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize {
SYSCALL[0](tf, syscall_num)
}