diff --git a/ch3-coop/user/src/bin/00write_a.rs b/ch3-coop/user/src/bin/00write_a.rs index 8bebc9d..3303899 100644 --- a/ch3-coop/user/src/bin/00write_a.rs +++ b/ch3-coop/user/src/bin/00write_a.rs @@ -1,10 +1,7 @@ #![no_std] #![no_main] -#[macro_use] -extern crate user_lib; - -use user_lib::yield_; +use user_lib::{syscall::*, *}; const WIDTH: usize = 10; const HEIGHT: usize = 5; @@ -16,7 +13,7 @@ fn main() -> i32 { print!("A"); } println!(" [{}/{}]", i + 1, HEIGHT); - yield_(); + sys_yield(); } println!("Test write_a OK!"); 0 diff --git a/ch3-coop/user/src/bin/01write_b.rs b/ch3-coop/user/src/bin/01write_b.rs index 652d5dd..64bd665 100644 --- a/ch3-coop/user/src/bin/01write_b.rs +++ b/ch3-coop/user/src/bin/01write_b.rs @@ -1,10 +1,7 @@ #![no_std] #![no_main] -#[macro_use] -extern crate user_lib; - -use user_lib::yield_; +use user_lib::{syscall::*, *}; const WIDTH: usize = 10; const HEIGHT: usize = 2; @@ -16,7 +13,7 @@ fn main() -> i32 { print!("B"); } println!(" [{}/{}]", i + 1, HEIGHT); - yield_(); + sys_yield(); } println!("Test write_b OK!"); 0 diff --git a/ch3-coop/user/src/bin/02write_c.rs b/ch3-coop/user/src/bin/02write_c.rs index 9bed4da..25464bf 100644 --- a/ch3-coop/user/src/bin/02write_c.rs +++ b/ch3-coop/user/src/bin/02write_c.rs @@ -1,10 +1,7 @@ #![no_std] #![no_main] -#[macro_use] -extern crate user_lib; - -use user_lib::yield_; +use user_lib::{syscall::*, *}; const WIDTH: usize = 10; const HEIGHT: usize = 3; @@ -16,7 +13,7 @@ fn main() -> i32 { print!("C"); } println!(" [{}/{}]", i + 1, HEIGHT); - yield_(); + sys_yield(); } println!("Test write_c OK!"); 0 diff --git a/ch3-coop/user/src/syscall.rs b/ch3-coop/user/src/syscall.rs index 1604d1b..0c9f3e1 100644 --- a/ch3-coop/user/src/syscall.rs +++ b/ch3-coop/user/src/syscall.rs @@ -2,6 +2,7 @@ use core::arch::asm; const SYSCALL_WRITE: usize = 64; const SYSCALL_EXIT: usize = 93; +const SYSCALL_YIELD: usize = 124; fn syscall(id: usize, args: [usize; 3]) -> isize { @@ -28,3 +29,7 @@ pub fn sys_exit(exit_code: i32) -> isize { syscall(SYSCALL_EXIT, [exit_code as usize, 0, 0]) } +pub fn sys_yield() { + syscall(SYSCALL_YIELD, [0, 0, 0]); +} +