Chapter3: power2/3/5 & sleep test worked on k210/qemu based on timer.

This commit is contained in:
Yifan Wu 2020-11-29 10:31:15 +08:00
parent adbe671fe1
commit 1cef77eac7
17 changed files with 183 additions and 82 deletions

View file

@ -7,10 +7,18 @@ use riscv::register::{
self,
Trap,
Exception,
Interrupt,
},
stval,
sstatus,
sie,
};
use crate::syscall::syscall;
use crate::task::{
exit_current_and_run_next,
suspend_current_and_run_next,
};
use crate::timer::set_next_trigger;
global_asm!(include_str!("trap.S"));
@ -21,6 +29,14 @@ pub fn init() {
}
}
pub fn enable_interrupt() {
unsafe { sstatus::set_sie(); }
}
pub fn enable_timer_interrupt() {
unsafe { sie::set_stimer(); }
}
#[no_mangle]
pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
let scause = scause::read();
@ -33,13 +49,15 @@ pub fn trap_handler(cx: &mut TrapContext) -> &mut TrapContext {
Trap::Exception(Exception::StoreFault) |
Trap::Exception(Exception::StorePageFault) => {
println!("[kernel] PageFault in application, bad addr = {:#x}, bad instruction = {:#x}, core dumped.", stval, cx.sepc);
panic!("[kernel] Cannot continue!");
//run_next_app();
exit_current_and_run_next();
}
Trap::Exception(Exception::IllegalInstruction) => {
println!("[kernel] IllegalInstruction in application, core dumped.");
panic!("[kernel] Cannot continue!");
//run_next_app();
exit_current_and_run_next();
}
Trap::Interrupt(Interrupt::SupervisorTimer) => {
set_next_trigger();
suspend_current_and_run_next();
}
_ => {
panic!("Unsupported trap {:?}, stval = {:#x}!", scause.cause(), stval);