1 /// 系统调用号 2 pub mod nr; 3 use system_error::SystemError; 4 5 use crate::{exception::InterruptArch, process::ProcessManager, syscall::Syscall}; 6 7 use super::{interrupt::TrapFrame, CurrentIrqArch}; 8 9 /// 系统调用初始化 10 pub fn arch_syscall_init() -> Result<(), SystemError> { 11 return Ok(()); 12 } 13 14 macro_rules! syscall_return { 15 ($val:expr, $regs:expr, $show:expr) => {{ 16 let ret = $val; 17 $regs.a0 = ret; 18 19 if $show { 20 let pid = ProcessManager::current_pcb().pid(); 21 crate::kdebug!("syscall return:pid={:?},ret= {:?}\n", pid, ret as isize); 22 } 23 24 unsafe { 25 CurrentIrqArch::interrupt_disable(); 26 } 27 return; 28 }}; 29 } 30 31 pub(super) fn syscall_handler(syscall_num: usize, frame: &mut TrapFrame) -> () { 32 unsafe { 33 CurrentIrqArch::interrupt_enable(); 34 } 35 36 let args = [frame.a0, frame.a1, frame.a2, frame.a3, frame.a4, frame.a5]; 37 syscall_return!( 38 Syscall::handle(syscall_num, &args, frame).unwrap_or_else(|e| e.to_posix_errno() as usize), 39 frame, 40 false 41 ); 42 } 43