1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! The `lang_items` module contains Rust lang items.
//! Rust lang items are functionalities that isn't hard-coded into the language,
//! but is implemented in libraries, with a special marker to tell the compiler it exists.
//! Since the kernel doesn't depend on the `std` crate, it has to implement some
//! lang items, such as the `panic_handler`.

use core::panic::PanicInfo;

use log::error;

use crate::sbi;

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    if let Some(location) = info.location() {
        error!(
            "panic at {}:{}: {}",
            location.file(),
            location.line(),
            info.message().unwrap()
        );
    } else {
        error!("panic: {}", info.message().unwrap());
    }
    sbi::shutdown();
}