aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / src / helpers / println.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | use crate::{boot, system}; |
| 4 | use core::fmt::Write; |
| 5 | |
| 6 | /// INTERNAL API! Helper for print macros. |
| 7 | #[doc(hidden)] |
| 8 | pub fn _print(args: core::fmt::Arguments) { |
| 9 | if boot::are_boot_services_active() { |
| 10 | system::with_stdout(|stdout| { |
| 11 | stdout.write_fmt(args).expect("Failed to write to stdout"); |
| 12 | }); |
| 13 | } else { |
| 14 | // Ease debugging: Depending on logger, this might write to serial or |
| 15 | // debugcon. |
| 16 | log::debug!("You are using `print!` after the boot services have been exited."); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | /// Prints to the standard output of the UEFI boot service console. |
| 21 | /// |
| 22 | /// # Usage |
| 23 | /// Use this similar to `print!` from the Rust standard library, but only |
| 24 | /// as long as boot services have not been exited. |
| 25 | /// |
| 26 | /// You should never use this macro in a custom Logger ([`log::Log`] impl) to |
| 27 | /// prevent a circular runtime dependency. |
| 28 | /// |
| 29 | /// # Panics |
| 30 | /// Will panic if the system table's `stdout` is not set, or if writing fails. |
| 31 | /// |
| 32 | /// # Examples |
| 33 | /// ``` |
| 34 | /// print!(""); |
| 35 | /// print!("Hello World\n"); |
| 36 | /// print!("Hello {}", "World"); |
| 37 | /// ``` |
| 38 | #[macro_export] |
| 39 | macro_rules! print { |
| 40 | ($($arg:tt)*) => ($crate::helpers::_print(core::format_args!($($arg)*))); |
| 41 | } |
| 42 | |
| 43 | /// Prints to the standard output of the UEFI boot service console, but with a |
| 44 | /// newline. |
| 45 | /// |
| 46 | /// # Usage |
| 47 | /// Use this similar to `println!` from the Rust standard library, but only |
| 48 | /// as long as boot services have not been exited. |
| 49 | /// |
| 50 | /// You should never use this macro in a custom Logger ([`log::Log`] impl) to |
| 51 | /// prevent a circular runtime dependency. |
| 52 | /// |
| 53 | /// # Panics |
| 54 | /// Will panic if the system table's `stdout` is not set, or if writing fails. |
| 55 | /// |
| 56 | /// # Examples |
| 57 | /// ``` |
| 58 | /// println!(); |
| 59 | /// println!("Hello World"); |
| 60 | /// println!("Hello {}", "World"); |
| 61 | /// ``` |
| 62 | #[macro_export] |
| 63 | macro_rules! println { |
| 64 | () => ($crate::print!("\n")); |
| 65 | ($($arg:tt)*) => ($crate::helpers::_print(core::format_args!("{}{}", core::format_args!($($arg)*), "\n"))); |
| 66 | } |