Move most of the arch debug::Writer impls into a common location
This commit is contained in:
@@ -1,50 +1,21 @@
|
||||
use core::fmt;
|
||||
use spin::MutexGuard;
|
||||
|
||||
use crate::{
|
||||
device::serial::COM1,
|
||||
devices::{
|
||||
graphical_debug::{DebugDisplay, DEBUG_DISPLAY},
|
||||
serial::SerialKind,
|
||||
},
|
||||
log::{Log, LOG},
|
||||
};
|
||||
use crate::{device::serial::COM1, devices::serial::SerialKind};
|
||||
|
||||
pub struct Writer<'a> {
|
||||
log: MutexGuard<'a, Option<Log>>,
|
||||
display: MutexGuard<'a, Option<DebugDisplay>>,
|
||||
serial: MutexGuard<'a, Option<SerialKind>>,
|
||||
}
|
||||
|
||||
impl<'a> Writer<'a> {
|
||||
pub fn new() -> Writer<'a> {
|
||||
Writer {
|
||||
log: LOG.lock(),
|
||||
display: DEBUG_DISPLAY.lock(),
|
||||
serial: COM1.lock(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8], preserve: bool) {
|
||||
if preserve {
|
||||
if let Some(ref mut log) = *self.log {
|
||||
log.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref mut display) = *self.display {
|
||||
let _ = display.write(buf);
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8]) {
|
||||
if let Some(ref mut serial) = *self.serial {
|
||||
serial.write(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Write for Writer<'a> {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
self.write(s.as_bytes(), true);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,21 @@
|
||||
use core::fmt;
|
||||
use spin::MutexGuard;
|
||||
|
||||
use crate::{
|
||||
device::serial::COM1,
|
||||
devices::{
|
||||
graphical_debug::{DebugDisplay, DEBUG_DISPLAY},
|
||||
serial::SerialKind,
|
||||
},
|
||||
log::{Log, LOG},
|
||||
};
|
||||
use crate::{device::serial::COM1, devices::serial::SerialKind};
|
||||
|
||||
pub struct Writer<'a> {
|
||||
log: MutexGuard<'a, Option<Log>>,
|
||||
serial: MutexGuard<'a, Option<SerialKind>>,
|
||||
display: MutexGuard<'a, Option<DebugDisplay>>,
|
||||
}
|
||||
|
||||
impl<'a> Writer<'a> {
|
||||
pub fn new() -> Writer<'a> {
|
||||
Writer {
|
||||
log: LOG.lock(),
|
||||
display: DEBUG_DISPLAY.lock(),
|
||||
serial: COM1.lock(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8], preserve: bool) {
|
||||
if preserve {
|
||||
if let Some(ref mut log) = *self.log {
|
||||
log.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref mut display) = *self.display {
|
||||
let _ = display.write(buf);
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8]) {
|
||||
if let Some(ref mut serial) = *self.serial {
|
||||
serial.write(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Write for Writer<'a> {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
self.write(s.as_bytes(), true);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use core::fmt;
|
||||
#[cfg(feature = "qemu_debug")]
|
||||
use spin::Mutex;
|
||||
use spin::MutexGuard;
|
||||
@@ -10,10 +9,6 @@ use crate::devices::uart_16550::SerialPort;
|
||||
use crate::syscall::io::Mmio;
|
||||
#[cfg(feature = "qemu_debug")]
|
||||
use crate::syscall::io::Pio;
|
||||
use crate::{
|
||||
devices::graphical_debug::{DebugDisplay, DEBUG_DISPLAY},
|
||||
log::{Log, LOG},
|
||||
};
|
||||
#[cfg(feature = "qemu_debug")]
|
||||
use syscall::io::Io;
|
||||
|
||||
@@ -27,8 +22,6 @@ use super::device::system76_ec::{System76Ec, SYSTEM76_EC};
|
||||
pub static QEMU: Mutex<Pio<u8>> = Mutex::new(Pio::<u8>::new(0x402));
|
||||
|
||||
pub struct Writer<'a> {
|
||||
log: MutexGuard<'a, Option<Log>>,
|
||||
display: MutexGuard<'a, Option<DebugDisplay>>,
|
||||
#[cfg(feature = "lpss_debug")]
|
||||
lpss: MutexGuard<'a, Option<SerialKind>>,
|
||||
#[cfg(feature = "qemu_debug")]
|
||||
@@ -41,8 +34,6 @@ pub struct Writer<'a> {
|
||||
impl<'a> Writer<'a> {
|
||||
pub fn new() -> Writer<'a> {
|
||||
Writer {
|
||||
log: LOG.lock(),
|
||||
display: DEBUG_DISPLAY.lock(),
|
||||
#[cfg(feature = "lpss_debug")]
|
||||
lpss: LPSS.lock(),
|
||||
#[cfg(feature = "qemu_debug")]
|
||||
@@ -53,17 +44,7 @@ impl<'a> Writer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8], preserve: bool) {
|
||||
if preserve {
|
||||
if let Some(ref mut log) = *self.log {
|
||||
log.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref mut display) = *self.display {
|
||||
display.write(buf);
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8]) {
|
||||
#[cfg(feature = "lpss_debug")]
|
||||
{
|
||||
if let Some(ref mut lpss) = *self.lpss {
|
||||
@@ -90,10 +71,3 @@ impl<'a> Writer<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Write for Writer<'a> {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
self.write(s.as_bytes(), true);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+41
-1
@@ -1,5 +1,8 @@
|
||||
use alloc::collections::VecDeque;
|
||||
use spin::{Mutex, Once};
|
||||
use core::fmt;
|
||||
use spin::{Mutex, MutexGuard, Once};
|
||||
|
||||
use crate::devices::graphical_debug::{DebugDisplay, DEBUG_DISPLAY};
|
||||
|
||||
pub static LOG: Mutex<Option<Log>> = Mutex::new(None);
|
||||
|
||||
@@ -66,3 +69,40 @@ pub fn init_logger(log_func: fn(&log::Record)) {
|
||||
}
|
||||
|
||||
static LOGGER: Once<RedoxLogger> = Once::new();
|
||||
|
||||
pub struct Writer<'a> {
|
||||
log: MutexGuard<'a, Option<Log>>,
|
||||
display: MutexGuard<'a, Option<DebugDisplay>>,
|
||||
arch: crate::arch::debug::Writer<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Writer<'a> {
|
||||
pub fn new() -> Writer<'a> {
|
||||
Writer {
|
||||
log: LOG.lock(),
|
||||
display: DEBUG_DISPLAY.lock(),
|
||||
arch: crate::arch::debug::Writer::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: &[u8], preserve: bool) {
|
||||
if preserve {
|
||||
if let Some(ref mut log) = *self.log {
|
||||
log.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(display) = &mut *self.display {
|
||||
display.write(buf);
|
||||
}
|
||||
|
||||
self.arch.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Write for Writer<'a> {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
self.write(s.as_bytes(), true);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => ({
|
||||
use core::fmt::Write;
|
||||
let _ = write!($crate::arch::debug::Writer::new(), $($arg)*);
|
||||
let _ = write!($crate::log::Writer::new(), $($arg)*);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ macro_rules! print {
|
||||
macro_rules! println {
|
||||
($($arg:tt)*) => ({
|
||||
use core::fmt::Write;
|
||||
let _ = writeln!($crate::arch::debug::Writer::new(), $($arg)*);
|
||||
let _ = writeln!($crate::log::Writer::new(), $($arg)*);
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,9 +2,9 @@ use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use spin::RwLock;
|
||||
|
||||
use crate::{
|
||||
arch::debug::Writer,
|
||||
devices::graphical_debug,
|
||||
event,
|
||||
log::Writer,
|
||||
scheme::*,
|
||||
sync::WaitQueue,
|
||||
syscall::{
|
||||
|
||||
Reference in New Issue
Block a user