openhcl_boot/
boot_logger.rs#[cfg(target_arch = "x86_64")]
use crate::arch::tdx::TdxIoAccess;
use crate::host_params::shim_params::IsolationType;
use crate::single_threaded::SingleThreaded;
use core::cell::RefCell;
use core::fmt;
use core::fmt::Write;
#[cfg(target_arch = "x86_64")]
use minimal_rt::arch::InstrIoAccess;
use minimal_rt::arch::Serial;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LoggerType {
Serial,
}
enum Logger {
#[cfg(target_arch = "x86_64")]
Serial(Serial<InstrIoAccess>),
#[cfg(target_arch = "aarch64")]
Serial(Serial),
#[cfg(target_arch = "x86_64")]
TdxSerial(Serial<TdxIoAccess>),
None,
}
impl Logger {
fn write_str(&mut self, s: &str) -> fmt::Result {
match self {
Logger::Serial(serial) => serial.write_str(s),
#[cfg(target_arch = "x86_64")]
Logger::TdxSerial(serial) => serial.write_str(s),
Logger::None => Ok(()),
}
}
}
pub struct BootLogger {
logger: SingleThreaded<RefCell<Logger>>,
}
pub static BOOT_LOGGER: BootLogger = BootLogger {
logger: SingleThreaded(RefCell::new(Logger::None)),
};
pub fn boot_logger_init(isolation_type: IsolationType, logger_type: LoggerType) {
let mut logger = BOOT_LOGGER.logger.borrow_mut();
*logger = match (isolation_type, logger_type) {
#[cfg(target_arch = "x86_64")]
(IsolationType::None, LoggerType::Serial) => Logger::Serial(Serial::init(InstrIoAccess)),
#[cfg(target_arch = "aarch64")]
(IsolationType::None, LoggerType::Serial) => Logger::Serial(Serial::init()),
#[cfg(target_arch = "x86_64")]
(IsolationType::Tdx, LoggerType::Serial) => Logger::TdxSerial(Serial::init(TdxIoAccess)),
_ => Logger::None,
};
}
impl Write for &BootLogger {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.logger.borrow_mut().write_str(s)
}
}
macro_rules! log {
() => {};
($($arg:tt)*) => {
{
use core::fmt::Write;
let _ = writeln!(&$crate::boot_logger::BOOT_LOGGER, $($arg)*);
}
};
}
pub(crate) use log;
#[expect(unused_macros)]
macro_rules! debug_log {
($($arg:tt)*) => {
$crate::boot_logger::log!($($arg)*)
};
}
#[expect(unused_imports)]
pub(crate) use debug_log;