From bee5b4b1cfce1b372abbd930bca48d90a7abf619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 9 Apr 2024 11:47:18 +0200 Subject: [PATCH] fix(uefi): enable console struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/console.rs | 3 +++ src/macros.rs | 26 ++++++-------------------- src/main.rs | 2 -- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/console.rs b/src/console.rs index a1f0fd8f..1ac2edb3 100644 --- a/src/console.rs +++ b/src/console.rs @@ -6,7 +6,10 @@ pub struct Console(()); impl fmt::Write for Console { fn write_str(&mut self, s: &str) -> fmt::Result { + #[cfg(target_os = "none")] crate::arch::write_to_console(s.as_bytes()); + #[cfg(target_os = "uefi")] + uefi_services::system_table().stdout().write_str(s)?; Ok(()) } } diff --git a/src/macros.rs b/src/macros.rs index 7ee46533..4b123083 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -5,16 +5,9 @@ /// [`std::print`]: https://doc.rust-lang.org/stable/std/macro.print.html #[macro_export] macro_rules! print { - ($($arg:tt)*) => { - #[cfg(target_os = "none")] - { - $crate::_print(::core::format_args!($($arg)*)); - } - #[cfg(target_os = "uefi")] - { - ::uefi_services::print!($($arg)*); - } - }; + ($($arg:tt)*) => {{ + $crate::_print(::core::format_args!($($arg)*)); + }}; } /// Prints to the standard output, with a newline. @@ -27,16 +20,9 @@ macro_rules! println { () => { $crate::print!("\n") }; - ($($arg:tt)*) => { - #[cfg(target_os = "none")] - { - $crate::_print(::core::format_args!("{}\n", format_args!($($arg)*))); - } - #[cfg(target_os = "uefi")] - { - ::uefi_services::println!($($arg)*); - } - }; + ($($arg:tt)*) => {{ + $crate::_print(::core::format_args!("{}\n", format_args!($($arg)*))); + }}; } /// Prints and returns the value of a given expression for quick and dirty diff --git a/src/main.rs b/src/main.rs index e464b188..0ab6cc66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,6 @@ mod macros; #[cfg(target_os = "none")] mod allocator; mod arch; -#[cfg(target_os = "none")] mod console; #[cfg(target_os = "none")] mod log; @@ -26,7 +25,6 @@ mod uefi; ))] extern crate alloc; -#[cfg(target_os = "none")] #[doc(hidden)] fn _print(args: core::fmt::Arguments<'_>) { use core::fmt::Write;