forked from koniifer/ableos
Arm now logs to the framebuffer
This commit is contained in:
parent
e7bbb9a375
commit
9105469c3b
|
@ -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 {
|
||||
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(())
|
||||
}
|
||||
|
|
|
@ -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<SerialPort> = Mutex::new(unsafe { SerialPort::new(0x3F8) });
|
||||
static TERMINAL_LOGGER: Lazy<Mutex<TermLogger>> = 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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
// 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> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue