Expand description
§Serial Logging Library for x86_64 Kernels
This crate provides robust serial port logging for kernel and bootloader environments, with a focus on QEMU usage. It offers macros and functions for formatted and raw serial output, as well as a minimal kprint! macro for early boot or no_std contexts where dependencies are limited.
§QEMU Serial Logging
QEMU can redirect the guest’s serial port (COM1, 0x3F8) to the host’s standard output or a file. This allows you to see kernel logs by running QEMU with -serial stdio or -serial file:output.log. All output sent to the serial port will appear in your terminal or the specified file, making debugging much easier, especially before graphics or higher-level logging is available.
§When to Use serial_log!/serial_print! vs kprint!
- Use
serial_log!,serial_print!, and related macros for most kernel logging. These use a full-featured serial driver (with buffering, formatting, and thread safety) and are suitable once the kernel is initialized. - Use
kprint!for minimal, dependency-free output in very early boot stages, or in environments where only core formatting is available.kprint!writes directly to the serial port using inline assembly, bypassing all higher-level abstractions.
§Features
- Thread-safe, formatted serial output via
serial_print!,serial_log!, etc. - Log level macros for info, warning, and error messages.
- Hexadecimal logging support.
- Minimal
kprint!macro for direct serial output. - Enable/disable logging at runtime.
§Example (QEMU):
qemu-system-x86_64 -serial stdio -kernel path/to/kernelIn your kernel code:
use polished_serial_logging::{serial_println, serial_log};
serial_println!("Hello, QEMU serial!");
serial_log!("[INFO] ", "Boot complete");Re-exports§
pub use crate::kprint::DebugSerial;
Modules§
Macros§
- error
- Logs an error-level message to the serial port with formatting support.
- kprint
- Minimal serial debug output for kernel/boot environments.
- serial_
log - Logs a message to the serial port with a given log level prefix.
- serial_
log_ hex - Logs a hexadecimal value to the serial port with a given log level prefix.
- serial_
print - Prints to the host through the serial interface (COM1, 0x3F8).
- serial_
println - Prints to the host through the serial interface, appending a newline.
Structs§
Functions§
- disable_
serial_ logging - Disables serial logging output.
- enable_
serial_ logging - Enables serial logging output.
- error
- Logs an error-level message to the serial port.
- info
- Logs an info-level message to the serial port.
- info_
hex - Logs an info-level hexadecimal value to the serial port.
- is_
serial_ logging_ enabled - Returns whether serial logging is currently enabled.
- serial_
write_ byte - Writes a single byte to the serial port (COM1, 0x3F8).
- serial_
write_ hex - Writes a hexadecimal representation of a
u64value to the serial port. - serial_
write_ str - Writes a string to the serial port, byte by byte.
- warn
- Logs a warning-level message to the serial port.