Expand description
§Custom Panic Handler for Polished Kernel
This crate provides a custom panic handler for use in low-level, no_std Rust environments such as OS kernels or bootloaders.
§How Rust Uses This Panic Handler
In Rust, when a panic occurs (e.g., via panic!() or an assertion failure), the compiler looks for a function marked with the #[panic_handler] attribute. In no_std environments, you must provide your own panic handler, as the standard library’s default is unavailable. This function is called with a reference to a core::panic::PanicInfo struct, which contains information about the panic location and message.
This implementation:
- Uses serial logging (via the
serial_loggingcrate) to output panic information to a serial port, which is essential for debugging in early boot or kernel code where no display is available. - Prints the panic location (file, line, column) and message, if available.
- Halts the CPU after logging, preventing further execution.
§Usage
Link this crate in your kernel or bootloader. When a panic occurs, information will be sent over the serial port for developer diagnostics.
Functions§
- panic
- Custom panic handler for the kernel.
- print_
panic_ info_ serial - Print detailed panic information to the serial port for debugging.