ARM: Add serial console logging

This commit is contained in:
microtau 2023-07-20 09:21:00 +00:00
parent ea49841de2
commit 7865bca782
3 changed files with 30 additions and 7 deletions

View file

@ -0,0 +1,23 @@
use {core::fmt::Write, spin::Mutex};
const SERIAL_CONSOLE: Mutex<SerialConsole> = 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)
}

View file

@ -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!()
}

View file

@ -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)
})
}