From ee8f0b1945431ef1cf87730165bb9de620eeb268 Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Tue, 23 May 2023 10:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A03=E4=B8=AA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch3-coop/user/src/bin/00hello_world.rs | 10 ---------- ch3-coop/user/src/bin/00write_a.rs | 23 ++++++++++++++++++++++ ch3-coop/user/src/bin/01store_fault.rs | 15 -------------- ch3-coop/user/src/bin/01write_b.rs | 23 ++++++++++++++++++++++ ch3-coop/user/src/bin/02power.rs | 27 -------------------------- ch3-coop/user/src/bin/02write_c.rs | 23 ++++++++++++++++++++++ ch3-coop/user/src/bin/03priv_inst.rs | 17 ---------------- ch3-coop/user/src/bin/04priv_csr.rs | 17 ---------------- 8 files changed, 69 insertions(+), 86 deletions(-) delete mode 100644 ch3-coop/user/src/bin/00hello_world.rs create mode 100644 ch3-coop/user/src/bin/00write_a.rs delete mode 100644 ch3-coop/user/src/bin/01store_fault.rs create mode 100644 ch3-coop/user/src/bin/01write_b.rs delete mode 100644 ch3-coop/user/src/bin/02power.rs create mode 100644 ch3-coop/user/src/bin/02write_c.rs delete mode 100644 ch3-coop/user/src/bin/03priv_inst.rs delete mode 100644 ch3-coop/user/src/bin/04priv_csr.rs diff --git a/ch3-coop/user/src/bin/00hello_world.rs b/ch3-coop/user/src/bin/00hello_world.rs deleted file mode 100644 index e1391d7..0000000 --- a/ch3-coop/user/src/bin/00hello_world.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![no_std] -#![no_main] - -use user_lib::*; - -#[no_mangle] -fn main() -> i32 { - println!("hello 1"); - 0 -} \ No newline at end of file diff --git a/ch3-coop/user/src/bin/00write_a.rs b/ch3-coop/user/src/bin/00write_a.rs new file mode 100644 index 0000000..8bebc9d --- /dev/null +++ b/ch3-coop/user/src/bin/00write_a.rs @@ -0,0 +1,23 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +use user_lib::yield_; + +const WIDTH: usize = 10; +const HEIGHT: usize = 5; + +#[no_mangle] +fn main() -> i32 { + for i in 0..HEIGHT { + for _ in 0..WIDTH { + print!("A"); + } + println!(" [{}/{}]", i + 1, HEIGHT); + yield_(); + } + println!("Test write_a OK!"); + 0 +} diff --git a/ch3-coop/user/src/bin/01store_fault.rs b/ch3-coop/user/src/bin/01store_fault.rs deleted file mode 100644 index f8023eb..0000000 --- a/ch3-coop/user/src/bin/01store_fault.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![no_std] -#![no_main] - -#[macro_use] -extern crate user_lib; - -#[no_mangle] -fn main() -> i32 { - println!("Into Test store_fault, we will insert an invalid store operation..."); - println!("Kernel should kill this application!"); - unsafe { - core::ptr::null_mut::().write_volatile(0); - } - 0 -} diff --git a/ch3-coop/user/src/bin/01write_b.rs b/ch3-coop/user/src/bin/01write_b.rs new file mode 100644 index 0000000..652d5dd --- /dev/null +++ b/ch3-coop/user/src/bin/01write_b.rs @@ -0,0 +1,23 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +use user_lib::yield_; + +const WIDTH: usize = 10; +const HEIGHT: usize = 2; + +#[no_mangle] +fn main() -> i32 { + for i in 0..HEIGHT { + for _ in 0..WIDTH { + print!("B"); + } + println!(" [{}/{}]", i + 1, HEIGHT); + yield_(); + } + println!("Test write_b OK!"); + 0 +} diff --git a/ch3-coop/user/src/bin/02power.rs b/ch3-coop/user/src/bin/02power.rs deleted file mode 100644 index f628f34..0000000 --- a/ch3-coop/user/src/bin/02power.rs +++ /dev/null @@ -1,27 +0,0 @@ -#![no_std] -#![no_main] - -#[macro_use] -extern crate user_lib; - -const SIZE: usize = 10; -const P: u32 = 3; -const STEP: usize = 100000; -const MOD: u32 = 10007; - -#[no_mangle] -fn main() -> i32 { - let mut pow = [0u32; SIZE]; - let mut index: usize = 0; - pow[index] = 1; - for i in 1..=STEP { - let last = pow[index]; - index = (index + 1) % SIZE; - pow[index] = last * P % MOD; - if i % 10000 == 0 { - println!("{}^{}={}(MOD {})", P, i, pow[index], MOD); - } - } - println!("Test power OK!"); - 0 -} diff --git a/ch3-coop/user/src/bin/02write_c.rs b/ch3-coop/user/src/bin/02write_c.rs new file mode 100644 index 0000000..9bed4da --- /dev/null +++ b/ch3-coop/user/src/bin/02write_c.rs @@ -0,0 +1,23 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +use user_lib::yield_; + +const WIDTH: usize = 10; +const HEIGHT: usize = 3; + +#[no_mangle] +fn main() -> i32 { + for i in 0..HEIGHT { + for _ in 0..WIDTH { + print!("C"); + } + println!(" [{}/{}]", i + 1, HEIGHT); + yield_(); + } + println!("Test write_c OK!"); + 0 +} diff --git a/ch3-coop/user/src/bin/03priv_inst.rs b/ch3-coop/user/src/bin/03priv_inst.rs deleted file mode 100644 index 04dac37..0000000 --- a/ch3-coop/user/src/bin/03priv_inst.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_std] -#![no_main] - -#[macro_use] -extern crate user_lib; - -use core::arch::asm; - -#[no_mangle] -fn main() -> i32 { - println!("Try to execute privileged instruction in U Mode"); - println!("Kernel should kill this application!"); - unsafe { - asm!("sret"); - } - 0 -} diff --git a/ch3-coop/user/src/bin/04priv_csr.rs b/ch3-coop/user/src/bin/04priv_csr.rs deleted file mode 100644 index fbd678f..0000000 --- a/ch3-coop/user/src/bin/04priv_csr.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_std] -#![no_main] - -#[macro_use] -extern crate user_lib; - -use riscv::register::sstatus::{self, SPP}; - -#[no_mangle] -fn main() -> i32 { - println!("Try to access privileged CSR in U Mode"); - println!("Kernel should kill this application!"); - unsafe { - sstatus::set_spp(SPP::User); - } - 0 -}