mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 10:56:25 +04:00
Add sys_yield tests and compile them to different location.
This commit is contained in:
parent
f53f5e4b98
commit
e552f3cfca
@ -1,5 +1,7 @@
|
||||
const SYSCALL_WRITE: usize = 64;
|
||||
const SYSCALL_EXIT: usize = 93;
|
||||
const SYSCALL_YIELD: usize = 124;
|
||||
const SYSCALL_GET_TIME: usize = 169;
|
||||
|
||||
mod fs;
|
||||
mod process;
|
||||
|
@ -10,12 +10,12 @@ OBJDUMP := rust-objdump --arch-name=riscv64
|
||||
OBJCOPY := rust-objcopy --binary-architecture=riscv64
|
||||
|
||||
elf:
|
||||
@cargo build --release
|
||||
@echo $(APPS)
|
||||
@echo $(ELFS)
|
||||
@echo $(BINS)
|
||||
@python3 build.py
|
||||
|
||||
binary: elf
|
||||
$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));)
|
||||
|
||||
build: binary
|
||||
|
||||
clean:
|
||||
@cargo clean
|
25
user/build.py
Normal file
25
user/build.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
base_address = 0x80040000
|
||||
step = 0x20000
|
||||
linker = 'src/linker.ld'
|
||||
|
||||
app_id = 0
|
||||
apps = os.listdir('src/bin')
|
||||
apps.sort()
|
||||
for app in apps:
|
||||
app = app[:app.find('.')]
|
||||
lines = []
|
||||
lines_before = []
|
||||
with open(linker, 'r') as f:
|
||||
for line in f.readlines():
|
||||
lines_before.append(line)
|
||||
line = line.replace(hex(base_address), hex(base_address+step*app_id))
|
||||
lines.append(line)
|
||||
with open(linker, 'w+') as f:
|
||||
f.writelines(lines)
|
||||
os.system('cargo build --bin %s --release' % app)
|
||||
print('[build.py] application %s start with address %s' %(app, hex(base_address+step*app_id)))
|
||||
with open(linker, 'w+') as f:
|
||||
f.writelines(lines_before)
|
||||
app_id = app_id + 1
|
@ -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
|
||||
}
|
@ -31,3 +31,5 @@ fn clear_bss() {
|
||||
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…
Reference in New Issue
Block a user