From 976579b62bbf774248c06e40483199f9cc620586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 12 Dec 2024 12:18:05 +0100 Subject: [PATCH] refactor(console): extract `Console::read` --- src/arch/aarch64/kernel/serial.rs | 5 ----- src/arch/x86_64/kernel/serial.rs | 7 ------- src/console.rs | 8 ++++++++ src/shell.rs | 3 +-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/arch/aarch64/kernel/serial.rs b/src/arch/aarch64/kernel/serial.rs index b061573564..15577c22d3 100644 --- a/src/arch/aarch64/kernel/serial.rs +++ b/src/arch/aarch64/kernel/serial.rs @@ -34,11 +34,6 @@ impl SerialPort { } } - #[allow(dead_code)] - pub fn read(&mut self) -> Option { - None - } - pub fn init(&self, _baudrate: u32) { // We don't do anything here (yet). } diff --git a/src/arch/x86_64/kernel/serial.rs b/src/arch/x86_64/kernel/serial.rs index 5db44653ca..3e02a1c8eb 100644 --- a/src/arch/x86_64/kernel/serial.rs +++ b/src/arch/x86_64/kernel/serial.rs @@ -52,18 +52,11 @@ impl SerialPort { } } - #[allow(dead_code)] #[cfg(feature = "shell")] pub fn read(&mut self) -> Option { self.buffer.pop_front() } - #[allow(dead_code)] - #[cfg(not(feature = "shell"))] - pub fn read(&mut self) -> Option { - None - } - pub fn send(&mut self, buf: &[u8]) { match &mut self.inner { SerialInner::Uhyve(s) => { diff --git a/src/console.rs b/src/console.rs index f2ab905105..b4b44d4d18 100644 --- a/src/console.rs +++ b/src/console.rs @@ -10,6 +10,14 @@ impl Console { pub fn write(&mut self, buf: &[u8]) { arch::output_message_buf(buf); } + + #[cfg(feature = "shell")] + pub fn read(&mut self) -> Option { + crate::arch::kernel::COM1 + .lock() + .as_mut() + .map(|s| s.read())? + } } /// A collection of methods that are required to format diff --git a/src/shell.rs b/src/shell.rs index 4aa7d7b7aa..f9771ec625 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -1,10 +1,9 @@ use simple_shell::*; -use crate::arch::kernel::COM1; use crate::interrupts::print_statistics; fn read() -> Option { - COM1.lock().as_mut().map(|s| s.read())? + crate::console::CONSOLE.lock().read() } pub(crate) fn init() {