Log on tty (serial and vga)

This commit is contained in:
2026-03-22 16:00:41 +01:00
parent 15ecefb5fb
commit f966a1239e
9 changed files with 129 additions and 96 deletions

View File

@@ -1,4 +1,7 @@
use core::cell::{LazyCell, RefCell};
use core::{
cell::{LazyCell, RefCell},
sync::atomic::AtomicBool,
};
use alloc::{boxed::Box, rc::Rc};
use io::{IoBase, Read, Seek, Write};
@@ -10,7 +13,12 @@ use crate::{
};
pub const TTY_BUFFER_SIZE: usize = 4096; // 4Ko
pub static mut TTY0: LazyCell<Tty> = LazyCell::new(Tty::new);
pub static mut TTY0: LazyCell<Tty> = LazyCell::new(|| {
let tty = Tty::new();
TTY_INITIALIZED.store(true, core::sync::atomic::Ordering::Relaxed);
tty
});
pub static TTY_INITIALIZED: AtomicBool = AtomicBool::new(false);
#[derive(Debug, Clone)]
pub struct Tty {
@@ -25,10 +33,13 @@ impl Tty {
console: RefCell::new(VirtualConsole::new()).into(),
}
}
pub fn new_node(&'_ self) -> TtyNode<'_> {
TtyNode { tty: self }
}
}
#[derive(Debug)]
struct TtyNode<'a> {
pub struct TtyNode<'a> {
tty: &'a Tty,
}
@@ -40,7 +51,7 @@ impl VirtualFileSystem for Tty {
if !path.is_empty() {
Err(())
} else {
Ok(Box::new(TtyNode { tty: self }))
Ok(Box::new(self.new_node()))
}
}
}
@@ -68,10 +79,12 @@ impl Seek for TtyNode<'_> {
impl Write for TtyNode<'_> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.tty
.console
.borrow_mut()
.write_str(str::from_utf8(buf).unwrap());
critical_section::with(|_| {
self.tty
.console
.borrow_mut()
.write_str(str::from_utf8(buf).unwrap());
});
Ok(buf.len())
}