mirror of
https://github.com/LearningOS/rust-based-os-comp2022.git
synced 2026-07-06 04:26:07 +08:00
add os[1-8]-ref for os refereces, add guide, add README
This commit is contained in:
15
os2-ref/src/syscall/fs.rs
Normal file
15
os2-ref/src/syscall/fs.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
const FD_STDOUT: usize = 1;
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
16
os2-ref/src/syscall/mod.rs
Normal file
16
os2-ref/src/syscall/mod.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
const SYSCALL_WRITE: usize = 64;
|
||||
const SYSCALL_EXIT: usize = 93;
|
||||
|
||||
mod fs;
|
||||
mod process;
|
||||
|
||||
use fs::*;
|
||||
use process::*;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
6
os2-ref/src/syscall/process.rs
Normal file
6
os2-ref/src/syscall/process.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use crate::batch::run_next_app;
|
||||
|
||||
pub fn sys_exit(exit_code: i32) -> ! {
|
||||
info!("[kernel] Application exited with code {}", exit_code);
|
||||
run_next_app()
|
||||
}
|
||||
Reference in New Issue
Block a user