diff --git a/tests/chapter1/hello_world.rs b/tests/chapter1/hello_world.rs new file mode 100644 index 00000000..bf369df4 --- /dev/null +++ b/tests/chapter1/hello_world.rs @@ -0,0 +1,5 @@ +/// Run this as a application on RV64 bare-metal. + +fn main() { + println!("Hello, world!"); +} diff --git a/tests/chapter2/power.rs b/tests/chapter2/power.rs new file mode 100644 index 00000000..8826a900 --- /dev/null +++ b/tests/chapter2/power.rs @@ -0,0 +1,23 @@ +/// rCore application without user_lib. +/// Load it manually to 0x80040000. +/// It should OK. + +const SIZE: usize = 10; +const P: u32 = 3; +const STEP: usize = 10000000; +const MOD: u32 = 10007; +fn main() -> ! { + 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!("{}^{}={}", P, i, pow[index]); + } + } + println!("Test power OK!"); + loop {} +} \ No newline at end of file diff --git a/tests/chapter2/power_bad.rs b/tests/chapter2/power_bad.rs new file mode 100644 index 00000000..11226f33 --- /dev/null +++ b/tests/chapter2/power_bad.rs @@ -0,0 +1,26 @@ +/// rCore application without user_lib. +/// Load it manually to 0x80040000. +/// It should not OK. Kernel should catch the page fault. + +const SIZE: usize = 10; +const P: u32 = 3; +const STEP: usize = 10000000; +const MOD: u32 = 10007; +fn main() -> ! { + 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!("{}^{}={}", P, i, pow[index]); + } + if i == STEP / 2 { + // TODO: Modify satp to a malicious value in order to destroy memory access mechanism. + } + } + println!("Test power_bad OK!"); + loop {} +} \ No newline at end of file diff --git a/tests/chapter3/write_a.rs b/tests/chapter3/write_a.rs new file mode 100644 index 00000000..a1a5f69b --- /dev/null +++ b/tests/chapter3/write_a.rs @@ -0,0 +1,15 @@ +/// rCore application without user_lib. +/// Load it manually to 0x80040000. + +use user_lib::{sys_yield}; + +fn main() -> ! { + for _ in 0..10 { + for _ in 0..10 { + print!("A"); + } + println!(); + sys_yield(); + } + loop {} +} \ No newline at end of file diff --git a/tests/chapter3/write_b.rs b/tests/chapter3/write_b.rs new file mode 100644 index 00000000..e2a2b12a --- /dev/null +++ b/tests/chapter3/write_b.rs @@ -0,0 +1,15 @@ +/// rCore application without user_lib. +/// Load it manually to 0x80050000. + +use user_lib::{sys_yield}; + +fn main() -> ! { + for _ in 0..10 { + for _ in 0..10 { + print!("B"); + } + println!(); + sys_yield(); + } + loop {} +} \ No newline at end of file