From 9105469c3b8ca63af7c0268e26d4e355e97ee0e0 Mon Sep 17 00:00:00 2001 From: able Date: Sun, 17 Sep 2023 17:13:23 -0500 Subject: [PATCH] Arm now logs to the framebuffer --- kernel/src/arch/aarch64/logging.rs | 8 ++++--- kernel/src/arch/x86_64/logging.rs | 29 +------------------------ kernel/src/kmain.rs | 2 +- kernel/src/logger.rs | 35 +++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/kernel/src/arch/aarch64/logging.rs b/kernel/src/arch/aarch64/logging.rs index e52ecf7f0..5db9bc050 100644 --- a/kernel/src/arch/aarch64/logging.rs +++ b/kernel/src/arch/aarch64/logging.rs @@ -1,5 +1,4 @@ -use {core::fmt::Write, spin::Mutex}; - +use {crate::logger::TERMINAL_LOGGER, core::fmt::Write, spin::Mutex}; const SERIAL_CONSOLE: Mutex = Mutex::new(SerialConsole { uart: 0x09000000 as *mut u8, }); @@ -19,5 +18,8 @@ impl core::fmt::Write for SerialConsole { } pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { - SERIAL_CONSOLE.lock().write_fmt(args) + SERIAL_CONSOLE.lock().write_fmt(args)?; + TERMINAL_LOGGER.lock().write_fmt(args)?; + + Ok(()) } diff --git a/kernel/src/arch/x86_64/logging.rs b/kernel/src/arch/x86_64/logging.rs index ec1e01269..5652b255f 100644 --- a/kernel/src/arch/x86_64/logging.rs +++ b/kernel/src/arch/x86_64/logging.rs @@ -1,6 +1,5 @@ //! Logging (as in terms of console / serial output) #![allow(deprecated)] - use { core::fmt::Write, limine::{TerminalRequest, TerminalResponse}, @@ -9,11 +8,10 @@ use { }; pub static SERIAL_CONSOLE: Mutex = Mutex::new(unsafe { SerialPort::new(0x3F8) }); -static TERMINAL_LOGGER: Lazy> = Lazy::new(|| Mutex::new(TermLogger::new())); pub fn init() { SERIAL_CONSOLE.lock().init(); - Lazy::force(&TERMINAL_LOGGER); + // Lazy::force(&TERMINAL_LOGGER); } pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { @@ -22,28 +20,3 @@ pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { SERIAL_CONSOLE.lock().write_fmt(args) }) } - -struct TermLogger(&'static TerminalResponse); -unsafe impl Send for TermLogger {} -impl TermLogger { - pub fn new() -> Self { - static TERM_REQ: TerminalRequest = TerminalRequest::new(0); - Self( - TERM_REQ - .get_response() - .get() - .expect("failed to get terminal response"), - ) - } -} - -impl Write for TermLogger { - fn write_str(&mut self, s: &str) -> core::fmt::Result { - if let (Some(w), ts) = (self.0.write(), self.0.terminals()) { - for term in ts { - w(term, s); - } - } - Ok(()) - } -} diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index a2e81093e..53e278686 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -34,7 +34,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! { let dt = DEVICE_TREE.lock(); // TODO(Able): This line causes a deadlock - // info!("Device Tree: {}", dt); + info!("Device Tree: {}", dt); info!("Boot complete. Moving to init_system"); diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs index 486a3688b..3431775fe 100644 --- a/kernel/src/logger.rs +++ b/kernel/src/logger.rs @@ -1,10 +1,18 @@ // TODO: Add a logger api with logger levels and various outputs +pub static TERMINAL_LOGGER: Lazy> = Lazy::new(|| Mutex::new(TermLogger::new())); -use log::{Level, SetLoggerError}; +use { + limine::{TerminalRequest, TerminalResponse}, + log::{Level, SetLoggerError}, + spin::{lazy::Lazy, mutex::Mutex}, +}; pub fn init() -> Result<(), SetLoggerError> { log::set_logger(&crate::logger::Logger)?; log::set_max_level(log::LevelFilter::Debug); + + Lazy::force(&TERMINAL_LOGGER); + Ok(()) } @@ -34,3 +42,28 @@ impl log::Log for Logger { fn flush(&self) {} } + +pub struct TermLogger(&'static TerminalResponse); +unsafe impl Send for TermLogger {} +impl TermLogger { + pub fn new() -> Self { + static TERM_REQ: TerminalRequest = TerminalRequest::new(0); + Self( + TERM_REQ + .get_response() + .get() + .expect("failed to get terminal response"), + ) + } +} + +impl core::fmt::Write for TermLogger { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + if let (Some(w), ts) = (self.0.write(), self.0.terminals()) { + for term in ts { + w(term, s); + } + } + Ok(()) + } +}