From 90cfed42eade27f5e7b3242a1d5a404362e554ff Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Wed, 24 May 2023 15:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0sys=20yield=20=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch3/os/src/syscall/mod.rs | 2 ++ ch3/os/src/syscall/process.rs | 7 ++++++- ch3/user/src/bin/00write_a.rs | 2 +- ch3/user/src/bin/01write_b.rs | 2 +- ch3/user/src/bin/02write_c.rs | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) 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