From 7865bca782738407b981878a294128139035a1c5 Mon Sep 17 00:00:00 2001 From: microtau Date: Thu, 20 Jul 2023 09:21:00 +0000 Subject: [PATCH] ARM: Add serial console logging --- kernel/src/arch/aarch64/logging.rs | 23 +++++++++++++++++++++++ kernel/src/arch/aarch64/mod.rs | 10 ++++++---- kernel/src/arch/x86_64/logging.rs | 4 +--- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 kernel/src/arch/aarch64/logging.rs diff --git a/kernel/src/arch/aarch64/logging.rs b/kernel/src/arch/aarch64/logging.rs new file mode 100644 index 0000000..e52ecf7 --- /dev/null +++ b/kernel/src/arch/aarch64/logging.rs @@ -0,0 +1,23 @@ +use {core::fmt::Write, spin::Mutex}; + +const SERIAL_CONSOLE: Mutex = Mutex::new(SerialConsole { + uart: 0x09000000 as *mut u8, +}); + +struct SerialConsole { + uart: *mut u8, +} + +impl core::fmt::Write for SerialConsole { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + for c in s.chars() { + unsafe { *self.uart = c as u8 } + } + + Ok(()) + } +} + +pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { + SERIAL_CONSOLE.lock().write_fmt(args) +} diff --git a/kernel/src/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs index ca0d88c..9bc405d 100644 --- a/kernel/src/arch/aarch64/mod.rs +++ b/kernel/src/arch/aarch64/mod.rs @@ -1,9 +1,15 @@ use {core::arch::asm, limine::FramebufferRequest}; +pub mod logging; +pub use logging::log; + pub const PAGE_SIZE: usize = 4096; #[no_mangle] unsafe extern "C" fn _kernel_start() -> ! { + crate::logger::init().expect("failed to set logger"); + log::info!("Initialising AKern {}", crate::VERSION); + static FB_REQ: FramebufferRequest = FramebufferRequest::new(0); let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0]; @@ -26,7 +32,3 @@ pub fn spin_loop() -> ! { pub fn hardware_random_u64() -> u64 { 0 } - -pub fn log(_args: core::fmt::Arguments<'_>) -> core::fmt::Result { - panic!() -} diff --git a/kernel/src/arch/x86_64/logging.rs b/kernel/src/arch/x86_64/logging.rs index ad32eb0..ec1e012 100644 --- a/kernel/src/arch/x86_64/logging.rs +++ b/kernel/src/arch/x86_64/logging.rs @@ -19,9 +19,7 @@ pub fn init() { pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { x86_64::instructions::interrupts::without_interrupts(|| { // TERMINAL_LOGGER.lock().write_fmt(args)?; - let mut sc = SERIAL_CONSOLE.lock(); - sc.write_fmt(args)?; - Ok(()) + SERIAL_CONSOLE.lock().write_fmt(args) }) }