1
0
Fork 0
forked from AbleOS/ableos

Arm now logs to the framebuffer

This commit is contained in:
able 2023-09-17 17:13:23 -05:00
parent e7bbb9a375
commit 9105469c3b
4 changed files with 41 additions and 33 deletions

View file

@ -1,5 +1,4 @@
use {core::fmt::Write, spin::Mutex}; use {crate::logger::TERMINAL_LOGGER, core::fmt::Write, spin::Mutex};
const SERIAL_CONSOLE: Mutex<SerialConsole> = Mutex::new(SerialConsole { const SERIAL_CONSOLE: Mutex<SerialConsole> = Mutex::new(SerialConsole {
uart: 0x09000000 as *mut u8, 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 { 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(())
} }

View file

@ -1,6 +1,5 @@
//! Logging (as in terms of console / serial output) //! Logging (as in terms of console / serial output)
#![allow(deprecated)] #![allow(deprecated)]
use { use {
core::fmt::Write, core::fmt::Write,
limine::{TerminalRequest, TerminalResponse}, limine::{TerminalRequest, TerminalResponse},
@ -9,11 +8,10 @@ use {
}; };
pub static SERIAL_CONSOLE: Mutex<SerialPort> = Mutex::new(unsafe { SerialPort::new(0x3F8) }); pub static SERIAL_CONSOLE: Mutex<SerialPort> = Mutex::new(unsafe { SerialPort::new(0x3F8) });
static TERMINAL_LOGGER: Lazy<Mutex<TermLogger>> = Lazy::new(|| Mutex::new(TermLogger::new()));
pub fn init() { pub fn init() {
SERIAL_CONSOLE.lock().init(); SERIAL_CONSOLE.lock().init();
Lazy::force(&TERMINAL_LOGGER); // Lazy::force(&TERMINAL_LOGGER);
} }
pub fn log(args: core::fmt::Arguments<'_>) -> core::fmt::Result { 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) 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(())
}
}

View file

@ -34,7 +34,7 @@ pub fn kmain(cmdline: &str, boot_modules: BootModules) -> ! {
let dt = DEVICE_TREE.lock(); let dt = DEVICE_TREE.lock();
// TODO(Able): This line causes a deadlock // TODO(Able): This line causes a deadlock
// info!("Device Tree: {}", dt); info!("Device Tree: {}", dt);
info!("Boot complete. Moving to init_system"); info!("Boot complete. Moving to init_system");

View file

@ -1,10 +1,18 @@
// TODO: Add a logger api with logger levels and various outputs // TODO: Add a logger api with logger levels and various outputs
pub static TERMINAL_LOGGER: Lazy<Mutex<TermLogger>> = 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> { pub fn init() -> Result<(), SetLoggerError> {
log::set_logger(&crate::logger::Logger)?; log::set_logger(&crate::logger::Logger)?;
log::set_max_level(log::LevelFilter::Debug); log::set_max_level(log::LevelFilter::Debug);
Lazy::force(&TERMINAL_LOGGER);
Ok(()) Ok(())
} }
@ -34,3 +42,28 @@ impl log::Log for Logger {
fn flush(&self) {} 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(())
}
}