forked from M-Labs/artiq
runtime: impl riscv exception handling
This commit is contained in:
parent
252594a606
commit
ecedec577c
|
@ -257,29 +257,67 @@ pub extern fn main() -> i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) {
|
#[repr(C)]
|
||||||
let vect = irq::Exception::try_from(vect).expect("unknown exception");
|
pub struct TrapFrame {
|
||||||
match vect {
|
pub ra: usize,
|
||||||
irq::Exception::Interrupt =>
|
pub t0: usize,
|
||||||
panic!("spurious irq {}", irq::pending_mask().trailing_zeros()),
|
pub t1: usize,
|
||||||
_ => {
|
pub t2: usize,
|
||||||
fn hexdump(addr: u32) {
|
pub t3: usize,
|
||||||
let addr = (addr - addr % 4) as *const u32;
|
pub t4: usize,
|
||||||
let mut ptr = addr;
|
pub t5: usize,
|
||||||
println!("@ {:08p}", ptr);
|
pub t6: usize,
|
||||||
for _ in 0..4 {
|
pub a0: usize,
|
||||||
print!("+{:04x}: ", ptr as usize - addr as usize);
|
pub a1: usize,
|
||||||
print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
pub a2: usize,
|
||||||
print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
pub a3: usize,
|
||||||
print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
pub a4: usize,
|
||||||
print!("{:08x}\n", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
pub a5: usize,
|
||||||
}
|
pub a6: usize,
|
||||||
}
|
pub a7: usize,
|
||||||
|
}
|
||||||
|
|
||||||
hexdump(pc);
|
#[no_mangle]
|
||||||
hexdump(ea);
|
pub extern fn exception(regs: *const TrapFrame) {
|
||||||
panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea)
|
unsafe {
|
||||||
|
let pc = mepc::read();
|
||||||
|
let cause = mcause::read().cause();
|
||||||
|
match cause {
|
||||||
|
mcause::Trap::Interrupt(source) => {
|
||||||
|
info!("Called interrupt with {:?}", source);
|
||||||
|
// while irq::pending_mask() != 0 {
|
||||||
|
// match () {
|
||||||
|
// #[cfg(has_timer1)]
|
||||||
|
// () if irq::is_pending(csr::TIMER1_INTERRUPT) =>
|
||||||
|
// profiler::sample(pc as usize),
|
||||||
|
// _ => {
|
||||||
|
// panic!("spurious irq {}", irq::pending_mask().trailing_zeros())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
panic!("Interrupt not present");
|
||||||
|
},
|
||||||
|
mcause::Trap::Exception(e) => {
|
||||||
|
println!("Stack pointer: {:p}", regs);
|
||||||
|
println!("Trap frame: {:x?}", unsafe { *regs });
|
||||||
|
|
||||||
|
fn hexdump(addr: u32) {
|
||||||
|
let addr = (addr - addr % 4) as *const u32;
|
||||||
|
let mut ptr = addr;
|
||||||
|
println!("@ {:08p}", ptr);
|
||||||
|
for _ in 0..4 {
|
||||||
|
print!("+{:04x}: ", ptr as usize - addr as usize);
|
||||||
|
print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
||||||
|
print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
||||||
|
print!("{:08x} ", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
||||||
|
print!("{:08x}\n", unsafe { *ptr }); ptr = ptr.wrapping_offset(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hexdump(u32::try_from(pc).unwrap());
|
||||||
|
panic!("exception {:?} at PC 0x{:x}", e, u32::try_from(pc).unwrap())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue