xref: /DragonOS/kernel/src/arch/riscv64/syscall/mod.rs (revision fae6e9ade46a52976ad5d099643d51cc20876448)
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             log::debug!("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     // debug!("syscall_handler: syscall_num: {}", syscall_num);
33     unsafe {
34         CurrentIrqArch::interrupt_enable();
35     }
36 
37     let args = [frame.a0, frame.a1, frame.a2, frame.a3, frame.a4, frame.a5];
38     syscall_return!(
39         Syscall::handle(syscall_num, &args, frame).unwrap_or_else(|e| e.to_posix_errno() as usize),
40         frame,
41         false
42     );
43 }
44