diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index 9e83ffe8..d919006f 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -4,7 +4,7 @@ use crate::task::{ run_next_task }; -pub fn sys_exit(xstate: i32) -> ! { +pub fn sys_exit(exit_code: i32) -> ! { println!("[kernel] Application exited with code {}", xstate); mark_current_exited(); run_next_task(); diff --git a/user/src/bin/00write_a.rs b/user/src/bin/00write_a.rs index f7ada612..979ec0bc 100644 --- a/user/src/bin/00write_a.rs +++ b/user/src/bin/00write_a.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -use user_lib::sys_yield; +use user_lib::yield_; const WIDTH: usize = 10; const HEIGHT: usize = 5; @@ -14,7 +14,7 @@ fn main() -> i32 { for i in 0..HEIGHT { for _ in 0..WIDTH { print!("A"); } println!(" [{}/{}]", i + 1, HEIGHT); - sys_yield(); + yield_(); } println!("Test write_a OK!"); 0 diff --git a/user/src/bin/01write_b.rs b/user/src/bin/01write_b.rs index e16b79da..7691b315 100644 --- a/user/src/bin/01write_b.rs +++ b/user/src/bin/01write_b.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -use user_lib::sys_yield; +use user_lib::yield_; const WIDTH: usize = 10; const HEIGHT: usize = 2; @@ -14,7 +14,7 @@ fn main() -> i32 { for i in 0..HEIGHT { for _ in 0..WIDTH { print!("B"); } println!(" [{}/{}]", i + 1, HEIGHT); - sys_yield(); + yield_(); } println!("Test write_b OK!"); 0 diff --git a/user/src/bin/02write_c.rs b/user/src/bin/02write_c.rs index 771f6447..6f342d12 100644 --- a/user/src/bin/02write_c.rs +++ b/user/src/bin/02write_c.rs @@ -4,7 +4,7 @@ #[macro_use] extern crate user_lib; -use user_lib::sys_yield; +use user_lib::yield_; const WIDTH: usize = 10; const HEIGHT: usize = 3; @@ -14,7 +14,7 @@ fn main() -> i32 { for i in 0..HEIGHT { for _ in 0..WIDTH { print!("C"); } println!(" [{}/{}]", i + 1, HEIGHT); - sys_yield(); + yield_(); } println!("Test write_c OK!"); 0 diff --git a/user/src/console.rs b/user/src/console.rs index a826b8fe..ac801174 100644 --- a/user/src/console.rs +++ b/user/src/console.rs @@ -1,11 +1,13 @@ use core::fmt::{self, Write}; -use crate::syscall::{STDOUT, sys_write}; +use super::write; struct Stdout; +const STDOUT: usize = 1; + impl Write for Stdout { fn write_str(&mut self, s: &str) -> fmt::Result { - sys_write(STDOUT, s.as_bytes()); + write(STDOUT, s.as_bytes()); Ok(()) } } diff --git a/user/src/lib.rs b/user/src/lib.rs index fdcb6d56..d14e3d89 100644 --- a/user/src/lib.rs +++ b/user/src/lib.rs @@ -12,7 +12,7 @@ mod lang_items; #[link_section = ".text.entry"] pub extern "C" fn _start() -> ! { clear_bss(); - syscall::sys_exit(main()); + exit(main()); panic!("unreachable after sys_exit!"); } @@ -32,4 +32,8 @@ fn clear_bss() { }); } -pub use syscall::*; \ No newline at end of file +use syscall::*; + +pub fn write(fd: usize, buf: &[u8]) -> isize { sys_write(fd, buf) } +pub fn exit(exit_code: i32) -> isize { sys_exit(exit_code) } +pub fn yield_() -> isize { sys_yield() } \ No newline at end of file diff --git a/user/src/syscall.rs b/user/src/syscall.rs index 8e4ff50b..1b23a48a 100644 --- a/user/src/syscall.rs +++ b/user/src/syscall.rs @@ -1,5 +1,3 @@ -pub const STDOUT: usize = 1; - const SYSCALL_WRITE: usize = 64; const SYSCALL_EXIT: usize = 93; const SYSCALL_YIELD: usize = 124; @@ -22,8 +20,8 @@ pub fn sys_write(fd: usize, buffer: &[u8]) -> isize { syscall(SYSCALL_WRITE, [fd, buffer.as_ptr() as usize, buffer.len()]) } -pub fn sys_exit(xstate: i32) -> isize { - syscall(SYSCALL_EXIT, [xstate as usize, 0, 0]) +pub fn sys_exit(exit_code: i32) -> isize { + syscall(SYSCALL_EXIT, [exit_code as usize, 0, 0]) } pub fn sys_yield() -> isize {