Pass the right TrapFrame to the exception handler

This commit is contained in:
bjoernQ 2022-05-04 14:08:50 +02:00 committed by Jesse Braham
parent 67f21460f8
commit 23b6e17e52

View File

@ -239,7 +239,8 @@ pub unsafe extern "C" fn start_trap_rust_hal(trap_frame: *mut TrapFrame) {
let cause = mcause::read(); let cause = mcause::read();
if cause.is_exception() { if cause.is_exception() {
handle_exception(trap_frame); let pc = riscv::register::mepc::read();
handle_exception(pc, trap_frame);
} else { } else {
let code = riscv::register::mcause::read().code(); let code = riscv::register::mcause::read().code();
match code { match code {
@ -286,7 +287,23 @@ pub unsafe extern "C" fn start_trap_rust_hal(trap_frame: *mut TrapFrame) {
/// ///
/// This function is called from an trap handler. /// This function is called from an trap handler.
#[doc(hidden)] #[doc(hidden)]
unsafe fn handle_exception(trap_frame: *mut TrapFrame) { unsafe fn handle_exception(pc: usize, trap_frame: *mut TrapFrame) {
let insn: usize = *(pc as *const _);
let needs_atomic_emulation = if (insn & 0b1111111) != 0b0101111 {
false
} else {
true
};
if !needs_atomic_emulation {
extern "C" {
fn ExceptionHandler(tf: *mut TrapFrame);
}
ExceptionHandler(trap_frame);
return;
}
extern "C" { extern "C" {
pub fn _start_trap_atomic_rust(trap_frame: *mut riscv_atomic_emulation_trap::TrapFrame); pub fn _start_trap_atomic_rust(trap_frame: *mut riscv_atomic_emulation_trap::TrapFrame);
} }