diff --git a/theseus/src/lib.rs b/theseus/src/lib.rs index 3c74574..4f91dd2 100644 --- a/theseus/src/lib.rs +++ b/theseus/src/lib.rs @@ -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 {} } diff --git a/theseus/src/uart.rs b/theseus/src/uart.rs index 3477dca..1957f08 100644 --- a/theseus/src/uart.rs +++ b/theseus/src/uart.rs @@ -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.