Try batch but kernel panicked.

This commit is contained in:
Yifan Wu 2020-11-19 18:01:16 +08:00
parent 220397e5a5
commit bae5383602
11 changed files with 385 additions and 17 deletions

38
os/src/trap/mod.rs Normal file
View file

@ -0,0 +1,38 @@
mod context;
use riscv::register::{
mtvec::TrapMode,
stvec,
scause::{
self,
Trap,
Exception,
},
stval,
};
global_asm!(include_str!("trap.S"));
pub fn init() {
extern "C" { fn __alltraps(); }
unsafe {
stvec::write(__alltraps as usize, TrapMode::Direct);
}
}
#[no_mangle]
pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
let scause = scause::read();
let stval = stval::read();
match scause.cause() {
Trap::Exception(Exception::UserEnvCall) => {
panic!("Triggered UserEnvCall!");
}
_ => {
panic!("Unsupported trap!");
}
}
cx
}
pub use context::TrapContext;