14fda81ceSLoGin /// 系统调用号 24fda81ceSLoGin pub mod nr; 391e9d4abSLoGin use system_error::SystemError; 491e9d4abSLoGin 5*23ef2b33SLoGin use crate::{exception::InterruptArch, process::ProcessManager, syscall::Syscall}; 64fda81ceSLoGin 74fda81ceSLoGin use super::{interrupt::TrapFrame, CurrentIrqArch}; 84fda81ceSLoGin 94fda81ceSLoGin /// 系统调用初始化 104fda81ceSLoGin pub fn arch_syscall_init() -> Result<(), SystemError> { 1140169973SLoGin return Ok(()); 124fda81ceSLoGin } 134fda81ceSLoGin 14*23ef2b33SLoGin macro_rules! syscall_return { 15*23ef2b33SLoGin ($val:expr, $regs:expr, $show:expr) => {{ 16*23ef2b33SLoGin let ret = $val; 17*23ef2b33SLoGin $regs.a0 = ret; 18*23ef2b33SLoGin 19*23ef2b33SLoGin if $show { 20*23ef2b33SLoGin let pid = ProcessManager::current_pcb().pid(); 21*23ef2b33SLoGin crate::kdebug!("syscall return:pid={:?},ret= {:?}\n", pid, ret as isize); 22*23ef2b33SLoGin } 23*23ef2b33SLoGin 24*23ef2b33SLoGin unsafe { 25*23ef2b33SLoGin CurrentIrqArch::interrupt_disable(); 26*23ef2b33SLoGin } 27*23ef2b33SLoGin return; 28*23ef2b33SLoGin }}; 29*23ef2b33SLoGin } 30*23ef2b33SLoGin 31*23ef2b33SLoGin pub(super) fn syscall_handler(syscall_num: usize, frame: &mut TrapFrame) -> () { 324fda81ceSLoGin unsafe { 334fda81ceSLoGin CurrentIrqArch::interrupt_enable(); 344fda81ceSLoGin } 35*23ef2b33SLoGin 36*23ef2b33SLoGin let args = [frame.a0, frame.a1, frame.a2, frame.a3, frame.a4, frame.a5]; 37*23ef2b33SLoGin syscall_return!( 38*23ef2b33SLoGin Syscall::handle(syscall_num, &args, frame).unwrap_or_else(|e| e.to_posix_errno() as usize), 39*23ef2b33SLoGin frame, 40*23ef2b33SLoGin false 41*23ef2b33SLoGin ); 424fda81ceSLoGin } 43