You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
4 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
|
//
|
||
4 years ago
|
// Copyright (c) 2018-2021 Andre Richter <andre.o.richter@gmail.com>
|
||
4 years ago
|
|
||
|
//! A panic handler that infinitely waits.
|
||
|
|
||
4 years ago
|
use crate::{bsp, cpu, exception};
|
||
4 years ago
|
use core::{fmt, panic::PanicInfo};
|
||
|
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Private Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
|
fn _panic_print(args: fmt::Arguments) {
|
||
|
use fmt::Write;
|
||
|
|
||
|
unsafe { bsp::console::panic_console_out().write_fmt(args).unwrap() };
|
||
|
}
|
||
|
|
||
3 years ago
|
/// The point of exit for `libkernel`.
|
||
4 years ago
|
///
|
||
3 years ago
|
/// It is linked weakly, so that the integration tests can overload its standard behavior.
|
||
4 years ago
|
#[linkage = "weak"]
|
||
|
#[no_mangle]
|
||
|
fn _panic_exit() -> ! {
|
||
3 years ago
|
#[cfg(not(test_build))]
|
||
|
{
|
||
|
cpu::wait_forever()
|
||
|
}
|
||
|
|
||
|
#[cfg(test_build)]
|
||
|
{
|
||
|
cpu::qemu_exit_failure()
|
||
|
}
|
||
4 years ago
|
}
|
||
|
|
||
|
/// Prints with a newline - only use from the panic handler.
|
||
|
///
|
||
3 years ago
|
/// Carbon copy from <https://doc.rust-lang.org/src/std/macros.rs.html>
|
||
4 years ago
|
#[macro_export]
|
||
|
macro_rules! panic_println {
|
||
|
($($arg:tt)*) => ({
|
||
|
_panic_print(format_args_nl!($($arg)*));
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[panic_handler]
|
||
|
fn panic(info: &PanicInfo) -> ! {
|
||
4 years ago
|
unsafe { exception::asynchronous::local_irq_mask() };
|
||
|
|
||
4 years ago
|
if let Some(args) = info.message() {
|
||
|
panic_println!("\nKernel panic: {}", args);
|
||
|
} else {
|
||
|
panic_println!("\nKernel panic!");
|
||
|
}
|
||
|
|
||
|
_panic_exit()
|
||
|
}
|