diff --git a/ch3/os/src/syscall/mod.rs b/ch3/os/src/syscall/mod.rs index 0f9f63c..4b907ee 100644 --- a/ch3/os/src/syscall/mod.rs +++ b/ch3/os/src/syscall/mod.rs @@ -1,5 +1,6 @@ const SYSCALL_WRITE: usize = 64; const SYSCALL_EXIT: usize = 93; +const SYSCALL_YIELD: usize = 124; mod fs; mod process; @@ -12,6 +13,7 @@ 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), + SYSCALL_YIELD => sys_yield(), _ => panic!("Unsupported syscall_id: {}", syscall_id), } } \ No newline at end of file diff --git a/ch3/os/src/syscall/process.rs b/ch3/os/src/syscall/process.rs index 331d9b5..03fef54 100644 --- a/ch3/os/src/syscall/process.rs +++ b/ch3/os/src/syscall/process.rs @@ -1,7 +1,7 @@ //! App management syscalls // use crate::batch::run_next_app; use crate::println; -use crate::task::exit_current_and_run_next; +use crate::task::{exit_current_and_run_next, suspend_current_and_run_next}; /// 任务退出, 并立即切换任务 pub fn sys_exit(exit_code: i32) -> ! { @@ -9,3 +9,8 @@ pub fn sys_exit(exit_code: i32) -> ! { exit_current_and_run_next(); panic!("Unreachable in sys_exit!"); } + +pub fn sys_yield() -> isize { + suspend_current_and_run_next(); + 0 +} \ No newline at end of file diff --git a/ch3/user/src/bin/00write_a.rs b/ch3/user/src/bin/00write_a.rs index 67088ed..3303899 100644 --- a/ch3/user/src/bin/00write_a.rs +++ b/ch3/user/src/bin/00write_a.rs @@ -13,7 +13,7 @@ fn main() -> i32 { print!("A"); } println!(" [{}/{}]", i + 1, HEIGHT); - // sys_yield(); + sys_yield(); } println!("Test write_a OK!"); 0 diff --git a/ch3/user/src/bin/01write_b.rs b/ch3/user/src/bin/01write_b.rs index 1ae798f..64bd665 100644 --- a/ch3/user/src/bin/01write_b.rs +++ b/ch3/user/src/bin/01write_b.rs @@ -13,7 +13,7 @@ fn main() -> i32 { print!("B"); } println!(" [{}/{}]", i + 1, HEIGHT); - // sys_yield(); + sys_yield(); } println!("Test write_b OK!"); 0 diff --git a/ch3/user/src/bin/02write_c.rs b/ch3/user/src/bin/02write_c.rs index f9c8f71..25464bf 100644 --- a/ch3/user/src/bin/02write_c.rs +++ b/ch3/user/src/bin/02write_c.rs @@ -13,7 +13,7 @@ fn main() -> i32 { print!("C"); } println!(" [{}/{}]", i + 1, HEIGHT); - // sys_yield(); + sys_yield(); } println!("Test write_c OK!"); 0