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.
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
5 years ago
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||
5 years ago
|
//
|
||
5 years ago
|
// Copyright (c) 2018-2020 Andre Richter <andre.o.richter@gmail.com>
|
||
5 years ago
|
|
||
|
//! A panic handler that infinitely waits.
|
||
|
|
||
4 years ago
|
use crate::{bsp, cpu};
|
||
5 years ago
|
use core::{fmt, panic::PanicInfo};
|
||
|
|
||
4 years ago
|
//--------------------------------------------------------------------------------------------------
|
||
|
// Private Code
|
||
|
//--------------------------------------------------------------------------------------------------
|
||
|
|
||
5 years ago
|
fn _panic_print(args: fmt::Arguments) {
|
||
|
use fmt::Write;
|
||
|
|
||
4 years ago
|
unsafe { bsp::console::panic_console_out().write_fmt(args).unwrap() };
|
||
5 years ago
|
}
|
||
|
|
||
|
/// Prints with a newline - only use from the panic handler.
|
||
|
///
|
||
|
/// Carbon copy from https://doc.rust-lang.org/src/std/macros.rs.html
|
||
|
#[macro_export]
|
||
|
macro_rules! panic_println {
|
||
|
($($arg:tt)*) => ({
|
||
|
_panic_print(format_args_nl!($($arg)*));
|
||
|
})
|
||
|
}
|
||
5 years ago
|
|
||
|
#[panic_handler]
|
||
|
fn panic(info: &PanicInfo) -> ! {
|
||
|
if let Some(args) = info.message() {
|
||
5 years ago
|
panic_println!("\nKernel panic: {}", args);
|
||
5 years ago
|
} else {
|
||
5 years ago
|
panic_println!("\nKernel panic!");
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
cpu::wait_forever()
|
||
5 years ago
|
}
|