添加系统调用分发以及功能
parent
771e7b12ff
commit
00e64296a8
@ -0,0 +1,20 @@
|
||||
//! File and filesystem-related syscalls
|
||||
|
||||
use crate::print;
|
||||
|
||||
const FD_STDOUT: usize = 1;
|
||||
|
||||
/// write buf of length `len` to a file with `fd`
|
||||
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {
|
||||
match fd {
|
||||
FD_STDOUT => {
|
||||
let slice = unsafe { core::slice::from_raw_parts(buf, len) };
|
||||
let str = core::str::from_utf8(slice).unwrap();
|
||||
print!("{}", str);
|
||||
len as isize
|
||||
}
|
||||
_ => {
|
||||
panic!("Unsupported fd in sys_write!");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
const SYSCALL_WRITE: usize = 64;
|
||||
const SYSCALL_EXIT: usize = 93;
|
||||
|
||||
mod fs;
|
||||
mod process;
|
||||
|
||||
use fs::*;
|
||||
use process::*;
|
||||
|
||||
/// 根据syscall_id 进行分发
|
||||
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]),
|
||||
SYSCALL_EXIT => sys_exit(args[0] as i32),
|
||||
_ => panic!("Unsupported syscall_id: {}", syscall_id),
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
//! App management syscalls
|
||||
use crate::batch::run_next_app;
|
||||
use crate::println;
|
||||
|
||||
/// 任务退出, 并立即切换任务
|
||||
pub fn sys_exit(exit_code: i32) -> ! {
|
||||
println!("[kernel] Application exited with code {}", exit_code);
|
||||
run_next_app()
|
||||
}
|
Loading…
Reference in New Issue