Add sys_yield tests and compile them to different location.
This commit is contained in:
parent
1414d05325
commit
4e8059e222
12 changed files with 99 additions and 57 deletions
|
@ -1,11 +0,0 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("Hello, world!");
|
||||
0
|
||||
}
|
18
user/src/bin/00write_a.rs
Normal file
18
user/src/bin/00write_a.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::sys_yield;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
for _ in 0..3 {
|
||||
for _ in 0..10 { print!("A"); }
|
||||
println!("");
|
||||
sys_yield();
|
||||
}
|
||||
println!("Test write_a OK!");
|
||||
0
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(llvm_asm)]
|
||||
|
||||
#[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 { (0x0 as *mut u8).write_volatile(0); }
|
||||
0
|
||||
}
|
18
user/src/bin/01write_b.rs
Normal file
18
user/src/bin/01write_b.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::sys_yield;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
for _ in 0..3 {
|
||||
for _ in 0..10 { print!("B"); }
|
||||
println!("");
|
||||
sys_yield();
|
||||
}
|
||||
println!("Test write_b OK!");
|
||||
0
|
||||
}
|
|
@ -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!("{}^{}={}", P, i, pow[index]);
|
||||
}
|
||||
}
|
||||
println!("Test power OK!");
|
||||
0
|
||||
}
|
18
user/src/bin/02write_c.rs
Normal file
18
user/src/bin/02write_c.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::sys_yield;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
for _ in 0..3 {
|
||||
for _ in 0..10 { print!("C"); }
|
||||
println!("");
|
||||
sys_yield();
|
||||
}
|
||||
println!("Test write_c OK!");
|
||||
0
|
||||
}
|
|
@ -30,4 +30,6 @@ fn clear_bss() {
|
|||
(start_bss as usize..end_bss as usize).for_each(|addr| {
|
||||
unsafe { (addr as *mut u8).write_volatile(0); }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub use syscall::*;
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
OUTPUT_ARCH(riscv)
|
||||
ENTRY(_start)
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ pub const STDOUT: usize = 1;
|
|||
|
||||
const SYSCALL_WRITE: usize = 64;
|
||||
const SYSCALL_EXIT: usize = 93;
|
||||
const SYSCALL_YIELD: usize = 124;
|
||||
const SYSCALL_GET_TIME: usize = 169;
|
||||
|
||||
fn syscall(id: usize, args: [usize; 3]) -> isize {
|
||||
let mut ret: isize;
|
||||
|
@ -23,3 +25,11 @@ pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
|
|||
pub fn sys_exit(xstate: i32) -> isize {
|
||||
syscall(SYSCALL_EXIT, [xstate as usize, 0, 0])
|
||||
}
|
||||
|
||||
pub fn sys_yield() -> isize {
|
||||
syscall(SYSCALL_YIELD, [0, 0, 0])
|
||||
}
|
||||
|
||||
pub fn sys_get_time() -> isize {
|
||||
syscall(SYSCALL_GET_TIME, [0, 0, 0])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue