diff --git a/bootloader/rustsbi-qemu.bin b/bootloader/rustsbi-qemu.bin index 72742c20..54329fcb 100755 Binary files a/bootloader/rustsbi-qemu.bin and b/bootloader/rustsbi-qemu.bin differ diff --git a/os/Makefile b/os/Makefile index 6f0f525c..217a0c41 100644 --- a/os/Makefile +++ b/os/Makefile @@ -28,6 +28,7 @@ $(KERNEL_BIN): kernel @$(OBJCOPY) $(KERNEL_ELF) --strip-all -O binary $@ kernel: + @cd ../user && make build @cargo build --release clean: diff --git a/os/build.rs b/os/build.rs index ba1ff3de..eb553e5b 100644 --- a/os/build.rs +++ b/os/build.rs @@ -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 diff --git a/os/src/batch.rs b/os/src/batch.rs index 9e6bc278..31903dee 100644 --- a/os/src/batch.rs +++ b/os/src/batch.rs @@ -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); diff --git a/os/src/trap/mod.rs b/os/src/trap/mod.rs index 25cd9405..e42b05fb 100644 --- a/os/src/trap/mod.rs +++ b/os/src/trap/mod.rs @@ -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 diff --git a/user/src/bin/hello_world.rs b/user/src/bin/00hello_world.rs similarity index 100% rename from user/src/bin/hello_world.rs rename to user/src/bin/00hello_world.rs diff --git a/user/src/bin/01store_fault.rs b/user/src/bin/01store_fault.rs new file mode 100644 index 00000000..7f02ae8e --- /dev/null +++ b/user/src/bin/01store_fault.rs @@ -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 +} \ No newline at end of file diff --git a/user/src/bin/power.rs b/user/src/bin/02power.rs similarity index 100% rename from user/src/bin/power.rs rename to user/src/bin/02power.rs