添加sys yield 系统调用

ch3
zhangxinyu 2 years ago
parent aedba5ac5b
commit 90cfed42ea

@ -1,5 +1,6 @@
const SYSCALL_WRITE: usize = 64; const SYSCALL_WRITE: usize = 64;
const SYSCALL_EXIT: usize = 93; const SYSCALL_EXIT: usize = 93;
const SYSCALL_YIELD: usize = 124;
mod fs; mod fs;
mod process; mod process;
@ -12,6 +13,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
match syscall_id { match syscall_id {
SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]), SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]),
SYSCALL_EXIT => sys_exit(args[0] as i32), SYSCALL_EXIT => sys_exit(args[0] as i32),
SYSCALL_YIELD => sys_yield(),
_ => panic!("Unsupported syscall_id: {}", syscall_id), _ => panic!("Unsupported syscall_id: {}", syscall_id),
} }
} }

@ -1,7 +1,7 @@
//! App management syscalls //! App management syscalls
// use crate::batch::run_next_app; // use crate::batch::run_next_app;
use crate::println; 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) -> ! { pub fn sys_exit(exit_code: i32) -> ! {
@ -9,3 +9,8 @@ pub fn sys_exit(exit_code: i32) -> ! {
exit_current_and_run_next(); exit_current_and_run_next();
panic!("Unreachable in sys_exit!"); panic!("Unreachable in sys_exit!");
} }
pub fn sys_yield() -> isize {
suspend_current_and_run_next();
0
}

@ -13,7 +13,7 @@ fn main() -> i32 {
print!("A"); print!("A");
} }
println!(" [{}/{}]", i + 1, HEIGHT); println!(" [{}/{}]", i + 1, HEIGHT);
// sys_yield(); sys_yield();
} }
println!("Test write_a OK!"); println!("Test write_a OK!");
0 0

@ -13,7 +13,7 @@ fn main() -> i32 {
print!("B"); print!("B");
} }
println!(" [{}/{}]", i + 1, HEIGHT); println!(" [{}/{}]", i + 1, HEIGHT);
// sys_yield(); sys_yield();
} }
println!("Test write_b OK!"); println!("Test write_b OK!");
0 0

@ -13,7 +13,7 @@ fn main() -> i32 {
print!("C"); print!("C");
} }
println!(" [{}/{}]", i + 1, HEIGHT); println!(" [{}/{}]", i + 1, HEIGHT);
// sys_yield(); sys_yield();
} }
println!("Test write_c OK!"); println!("Test write_c OK!");
0 0

Loading…
Cancel
Save