From 5a78e122c616326301881f5feb4f687b8ef3f28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E5=87=AF=E5=A4=AB?= Date: Mon, 14 Mar 2022 16:37:10 +0800 Subject: [PATCH] Update docs --- os/src/sbi.rs | 3 +++ os/src/syscall/mod.rs | 1 + os/src/syscall/process.rs | 1 + os/src/trap/mod.rs | 6 ++++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/os/src/sbi.rs b/os/src/sbi.rs index 90ba2c2a..f66d9751 100644 --- a/os/src/sbi.rs +++ b/os/src/sbi.rs @@ -27,14 +27,17 @@ fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize { ret } +/// use sbi call to putchar in console (qemu uart handler) pub fn console_putchar(c: usize) { sbi_call(SBI_CONSOLE_PUTCHAR, c, 0, 0); } +/// use sbi call to getchar from console (qemu uart handler) pub fn console_getchar() -> usize { sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0) } +/// use sbi call to shutdown the kernel pub fn shutdown() -> ! { sbi_call(SBI_SHUTDOWN, 0, 0, 0); panic!("It should shutdown!"); diff --git a/os/src/syscall/mod.rs b/os/src/syscall/mod.rs index 430af564..5b409e98 100644 --- a/os/src/syscall/mod.rs +++ b/os/src/syscall/mod.rs @@ -7,6 +7,7 @@ mod process; use fs::*; use process::*; +/// handle syscall exception with `syscall_id` and other arguments pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize { match syscall_id { SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]), diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index 8f4170d1..79a2522c 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -1,5 +1,6 @@ use crate::batch::run_next_app; +/// task exits and submit an exit code pub fn sys_exit(exit_code: i32) -> ! { println!("[kernel] Application exited with code {}", exit_code); run_next_app() diff --git a/os/src/trap/mod.rs b/os/src/trap/mod.rs index 0210809e..b6fdabab 100644 --- a/os/src/trap/mod.rs +++ b/os/src/trap/mod.rs @@ -11,6 +11,7 @@ use riscv::register::{ global_asm!(include_str!("trap.S")); +/// initialize CSR `stvec` as the entry of `__alltraps` pub fn init() { extern "C" { fn __alltraps(); @@ -21,9 +22,10 @@ pub fn init() { } #[no_mangle] +/// handle an interrupt, exception, or system call from user space pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext { - let scause = scause::read(); - let stval = stval::read(); + let scause = scause::read(); // get trap cause + let stval = stval::read(); // get extra value match scause.cause() { Trap::Exception(Exception::UserEnvCall) => { cx.sepc += 4;