Interrupts aren't working anymore

This commit is contained in:
2026-03-15 10:48:41 +01:00
parent de6ef959ce
commit b1aac20b57
17 changed files with 455 additions and 89 deletions

View File

@@ -1,29 +1,35 @@
use core::cell::RefCell;
use core::cell::{LazyCell, RefCell};
use alloc::{boxed::Box, rc::Rc};
use io::{IoBase, Read, Seek, Write};
use crate::{
data_structures::circular_buffer::CircularBuffer,
virtual_console::VirtualConsole,
virtual_fs::{VirtualFileSystem, VirtualNode},
};
#[derive(Debug)]
pub const TTY_BUFFER_SIZE: usize = 4096; // 4Ko
pub static mut TTY0: LazyCell<Tty> = LazyCell::new(Tty::new);
#[derive(Debug, Clone)]
pub struct Tty {
pub buffer: Rc<RefCell<CircularBuffer<u8, TTY_BUFFER_SIZE>>>,
console: Rc<RefCell<VirtualConsole>>,
}
impl Tty {
pub fn new() -> Self {
Self {
buffer: RefCell::new(CircularBuffer::new()).into(),
console: RefCell::new(VirtualConsole::new()).into(),
}
}
}
#[derive(Debug)]
struct TtyNode {
console: Rc<RefCell<VirtualConsole>>,
struct TtyNode<'a> {
tty: &'a Tty,
}
impl VirtualFileSystem for Tty {
@@ -34,32 +40,36 @@ impl VirtualFileSystem for Tty {
if !path.is_empty() {
Err(())
} else {
Ok(Box::new(TtyNode {
console: self.console.clone(),
}))
Ok(Box::new(TtyNode { tty: self }))
}
}
}
impl IoBase for TtyNode {
impl IoBase for TtyNode<'_> {
type Error = ();
}
impl Read for TtyNode {
fn read(&mut self, _buf: &mut [u8]) -> Result<usize, Self::Error> {
unimplemented!()
impl Read for TtyNode<'_> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
let mut buffer = self.tty.buffer.borrow_mut();
let max_len = buffer.len();
(0..buf.len().min(max_len)).for_each(|i| {
buf[i] = buffer.pop().unwrap();
});
Ok(buf.len().min(max_len))
}
}
impl Seek for TtyNode {
impl Seek for TtyNode<'_> {
fn seek(&mut self, _pos: io::SeekFrom) -> Result<u64, Self::Error> {
unimplemented!()
}
}
impl Write for TtyNode {
impl Write for TtyNode<'_> {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.console
self.tty
.console
.borrow_mut()
.write_str(str::from_utf8(buf).unwrap());
Ok(buf.len())
@@ -70,4 +80,4 @@ impl Write for TtyNode {
}
}
impl VirtualNode for TtyNode {}
impl VirtualNode for TtyNode<'_> {}