diff --git a/uefi/src/helpers/println.rs b/uefi/src/helpers/println.rs index 2a30eb1d5..2b9903e92 100644 --- a/uefi/src/helpers/println.rs +++ b/uefi/src/helpers/println.rs @@ -4,14 +4,25 @@ use core::fmt::Write; /// INTERNAL API! Helper for print macros. #[doc(hidden)] pub fn _print(args: core::fmt::Arguments) { - system_table_boot() - .expect("boot services are not active") - .stdout() - .write_fmt(args) - .expect("Failed to write to stdout"); + if let Some(mut bs) = system_table_boot() { + bs.stdout() + .write_fmt(args) + .expect("Failed to write to stdout"); + } else { + // Ease debugging: Depending on logger, this might write to serial or + // debugcon. + log::debug!("You are using `print!` after the boot services have been exited."); + } } -/// Prints to the standard output. +/// Prints to the standard output of the UEFI boot service console. +/// +/// # Usage +/// Use this similar to `print!` from the Rust standard library, but only +/// as long as boot services have not been exited. +/// +/// You should never use this macro in a custom Logger ([`log::Log`] impl) to +/// prevent a circular runtime dependency. /// /// # Panics /// Will panic if `SYSTEM_TABLE` is `None` (Before [`uefi::helpers::init()`] and @@ -28,7 +39,15 @@ macro_rules! print { ($($arg:tt)*) => ($crate::helpers::_print(core::format_args!($($arg)*))); } -/// Prints to the standard output, with a newline. +/// Prints to the standard output of the UEFI boot service console, but with a +/// newline. +/// +/// # Usage +/// Use this similar to `println!` from the Rust standard library, but only +/// as long as boot services have not been exited. +/// +/// You should never use this macro in a custom Logger ([`log::Log`] impl) to +/// prevent a circular runtime dependency. /// /// # Panics /// Will panic if `SYSTEM_TABLE` is `None` (Before [`uefi::helpers::init()`] and