From 786c9eabcb485f69a27f25c751af3635233bc9b6 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 10 Sep 2025 18:40:30 +0200 Subject: [PATCH] Share print! and println! between architectures --- src/arch/aarch64/mod.rs | 3 --- src/arch/riscv64/macros.rs | 16 ---------------- src/arch/riscv64/mod.rs | 3 --- src/arch/x86/macros.rs | 17 ----------------- src/arch/x86_64/macros.rs | 17 ----------------- src/{arch/aarch64 => }/macros.rs | 0 src/main.rs | 3 +++ 7 files changed, 3 insertions(+), 56 deletions(-) delete mode 100644 src/arch/riscv64/macros.rs rename src/{arch/aarch64 => }/macros.rs (100%) diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs index eb10d09ab2..94ab7981c9 100644 --- a/src/arch/aarch64/mod.rs +++ b/src/arch/aarch64/mod.rs @@ -1,6 +1,3 @@ -#[macro_use] -pub mod macros; - /// Constants like memory locations pub mod consts; diff --git a/src/arch/riscv64/macros.rs b/src/arch/riscv64/macros.rs deleted file mode 100644 index a9c83081f0..0000000000 --- a/src/arch/riscv64/macros.rs +++ /dev/null @@ -1,16 +0,0 @@ -/// Print to console -#[macro_export] -macro_rules! print { - ($($arg:tt)*) => ({ - use core::fmt::Write; - let _ = write!($crate::arch::debug::Writer::new(), $($arg)*); - }); -} - -/// Print with new line to console -#[macro_export] -macro_rules! println { - () => (print!("\n")); - ($fmt:expr_2021) => (print!(concat!($fmt, "\n"))); - ($fmt:expr_2021, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); -} diff --git a/src/arch/riscv64/mod.rs b/src/arch/riscv64/mod.rs index 3ad2bcb2ce..bf1f2ef527 100644 --- a/src/arch/riscv64/mod.rs +++ b/src/arch/riscv64/mod.rs @@ -1,6 +1,3 @@ -#[macro_use] -pub mod macros; - pub mod consts; pub mod debug; pub mod device; diff --git a/src/arch/x86/macros.rs b/src/arch/x86/macros.rs index ef4d8bd22f..25b5e3bbec 100644 --- a/src/arch/x86/macros.rs +++ b/src/arch/x86/macros.rs @@ -1,20 +1,3 @@ -/// Print to console -#[macro_export] -macro_rules! print { - ($($arg:tt)*) => ({ - use core::fmt::Write; - let _ = write!($crate::arch::debug::Writer::new(), $($arg)*); - }); -} - -/// Print with new line to console -#[macro_export] -macro_rules! println { - () => (print!("\n")); - ($fmt:expr_2021) => (print!(concat!($fmt, "\n"))); - ($fmt:expr_2021, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); -} - #[macro_export] macro_rules! irqs( ( [ $( ($idt:expr_2021, $number:literal, $name:ident) ,)* ], $submac:ident ) => { diff --git a/src/arch/x86_64/macros.rs b/src/arch/x86_64/macros.rs index efdfa22295..8d7e7b2e08 100644 --- a/src/arch/x86_64/macros.rs +++ b/src/arch/x86_64/macros.rs @@ -1,20 +1,3 @@ -/// Print to console -#[macro_export] -macro_rules! print { - ($($arg:tt)*) => ({ - use core::fmt::Write; - let _ = write!($crate::arch::debug::Writer::new(), $($arg)*); - }); -} - -/// Print with new line to console -#[macro_export] -macro_rules! println { - () => (print!("\n")); - ($fmt:expr_2021) => (print!(concat!($fmt, "\n"))); - ($fmt:expr_2021, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); -} - macro_rules! expand_bool( ($value:expr_2021) => { concat!($value) diff --git a/src/arch/aarch64/macros.rs b/src/macros.rs similarity index 100% rename from src/arch/aarch64/macros.rs rename to src/macros.rs diff --git a/src/main.rs b/src/main.rs index 316b0e918d..9eb8cc8a56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,9 @@ use crate::consts::*; /// Shared data structures mod common; +#[macro_use] +mod macros; + /// Architecture-dependent stuff #[macro_use] #[allow(dead_code)] // TODO