From 905330b0f1c5ba19ca27b55be881e89067e2e57b Mon Sep 17 00:00:00 2001 From: occheung Date: Wed, 11 Aug 2021 12:20:41 +0800 Subject: [PATCH] ksupport: handle riscv exceptions --- artiq/firmware/ksupport/Cargo.toml | 2 +- artiq/firmware/ksupport/lib.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/artiq/firmware/ksupport/Cargo.toml b/artiq/firmware/ksupport/Cargo.toml index ba53a7c9a..fbedbd792 100644 --- a/artiq/firmware/ksupport/Cargo.toml +++ b/artiq/firmware/ksupport/Cargo.toml @@ -19,4 +19,4 @@ io = { path = "../libio", features = ["byteorder"] } dyld = { path = "../libdyld" } board_misoc = { path = "../libboard_misoc" } board_artiq = { path = "../libboard_artiq" } -proto_artiq = { path = "../libproto_artiq" } +riscv = { version = "0.6.0", features = ["inline-asm"] } diff --git a/artiq/firmware/ksupport/lib.rs b/artiq/firmware/ksupport/lib.rs index 5e42fd100..b4a430289 100644 --- a/artiq/firmware/ksupport/lib.rs +++ b/artiq/firmware/ksupport/lib.rs @@ -12,8 +12,9 @@ extern crate dyld; extern crate board_misoc; extern crate board_artiq; extern crate proto_artiq; +extern crate riscv; -use core::{mem, ptr, slice, str}; +use core::{mem, ptr, slice, str, convert::TryFrom}; use cslice::{CSlice, AsCSlice}; use io::Cursor; use dyld::Library; @@ -22,6 +23,7 @@ use proto_artiq::{kernel_proto, rpc_proto}; use kernel_proto::*; #[cfg(has_rtio_dma)] use board_misoc::csr; +use riscv::register::{mcause, mepc}; fn send(request: &Message) { unsafe { mailbox::send(request as *const _ as usize) } @@ -519,8 +521,10 @@ pub unsafe fn main() { #[no_mangle] #[unwind(allowed)] -pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) { - panic!("exception {:?} at PC 0x{:x}, EA 0x{:x}", vect, pc, ea) +pub extern fn exception(_regs: *const u32) { + let pc = mepc::read(); + let cause = mcause::read().cause(); + panic!("{:?} at PC {:#08x}", cause, u32::try_from(pc).unwrap()) } #[no_mangle]