Update rustsbi-qemu && batch worked on qemu/k210.

This commit is contained in:
Yifan Wu 2020-11-20 11:10:38 +08:00
parent 3b920ac8f5
commit 5e5ed05399
8 changed files with 33 additions and 5 deletions

Binary file not shown.

View File

@ -28,6 +28,7 @@ $(KERNEL_BIN): kernel
@$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@
kernel:
@cd ../user && make build
@cargo build --release
clean:

View File

@ -10,7 +10,7 @@ static TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/release/";
fn insert_app_data() -> Result<()> {
let mut f = File::create("src/link_app.S").unwrap();
let apps: Vec<_> = read_dir("../user/src/bin")
let mut apps: Vec<_> = read_dir("../user/src/bin")
.unwrap()
.into_iter()
.map(|dir_entry| {
@ -19,6 +19,7 @@ fn insert_app_data() -> Result<()> {
name_with_ext
})
.collect();
apps.sort();
writeln!(f, r#"
.align 4

View File

@ -50,9 +50,9 @@ unsafe impl Sync for AppManager {}
impl AppManagerInner {
pub fn print_app_info(&self) {
println!("num_app = {}", self.num_app);
println!("[kernel] num_app = {}", self.num_app);
for i in 0..self.num_app {
println!("app_{} [{:#x}, {:#x})", i, self.app_start[i], self.app_start[i + 1]);
println!("[kernel] app_{} [{:#x}, {:#x})", i, self.app_start[i], self.app_start[i + 1]);
}
}
@ -61,6 +61,8 @@ impl AppManagerInner {
panic!("All applications completed!");
}
println!("[kernel] Loading app_{}", app_id);
// clear icache
llvm_asm!("fence.i" :::: "volatile");
// clear app area
(APP_BASE_ADDRESS..APP_BASE_ADDRESS + APP_SIZE_LIMIT).for_each(|addr| {
(addr as *mut u8).write_volatile(0);

View File

@ -11,6 +11,7 @@ use riscv::register::{
stval,
};
use crate::syscall::syscall;
use crate::batch::run_next_app;
global_asm!(include_str!("trap.S"));
@ -24,14 +25,23 @@ pub fn init() {
#[no_mangle]
pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
let scause = scause::read();
let _stval = stval::read();
let stval = stval::read();
match scause.cause() {
Trap::Exception(Exception::UserEnvCall) => {
cx.sepc += 4;
cx.x[10] = syscall(cx.x[17], [cx.x[10], cx.x[11], cx.x[12]]) as usize;
}
Trap::Exception(Exception::StoreFault) |
Trap::Exception(Exception::StorePageFault) => {
println!("[kernel] PageFault in application, core dumped.");
run_next_app();
}
Trap::Exception(Exception::IllegalInstruction) => {
println!("[kernel] IllegalInstruction in application, core dumped.");
run_next_app();
}
_ => {
panic!("Unsupported trap!");
panic!("Unsupported trap {:?}, stval = {:#x}!", scause.cause(), stval);
}
}
cx

View File

@ -0,0 +1,14 @@
#![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 behavior...");
println!("Kernel should kill this application!");
unsafe { (0x0 as *mut u8).write_volatile(0); }
0
}