Delegate rust panics to c

feat/start
hheik 2024-05-02 14:57:37 +03:00
parent 1cdd849d49
commit d57cdc9d6c
2 changed files with 15 additions and 3 deletions

View File

@ -6,8 +6,19 @@ pub mod riscv;
pub mod spinlock;
pub mod uart;
extern "C" {
// printf.c
fn panic(s: *const u8);
}
/// '!RUST PANIC!\0'
static PANIC_MSG: [u8; 13] = [33, 82, 85, 83, 84, 32, 80, 65, 78, 73, 67, 33, 0];
#[panic_handler]
#[no_mangle]
fn panic(_info: &core::panic::PanicInfo) -> ! {
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
unsafe {
panic(core::ptr::addr_of!(PANIC_MSG[0]));
}
loop {}
}

View File

@ -15,6 +15,9 @@ extern "C" {
// proc.c
fn sleep(chan: *const u64, spinlock: *mut SpinLock);
fn wakeup(chan: *const u64);
//printf.c
static mut panicked: bool;
}
// the UART control registers are memory-mapped
@ -69,8 +72,6 @@ static mut uart_tx_buf: [u8; UART_TX_BUF_SIZE] = [0; UART_TX_BUF_SIZE];
static mut uart_tx_w: u64 = 0; // write next to uart_tx_buf[uart_tx_w % UART_TX_BUF_SIZE]
static mut uart_tx_r: u64 = 0; // read next from uart_tx_buf[uart_tx_r % UART_TX_BUF_SIZE]
static mut panicked: bool = false;
#[no_mangle]
pub extern "C" fn uartinit() {
// disable interrupts.