facf0c92e0
Red Bear OS is a full fork. All sources must be available from git clone with zero network access. Removed gitignore rules that excluded fetched source trees under recipes/*/source/, local/recipes/kde/*/source/, local/recipes/qt/*/source/, and vendor source trees. Build artifacts (target/, build/, source.tar, *.o, *.so) remain excluded. 127291 files added — kernel, relibc, base, bootloader, pkgar, all KDE/Qt frameworks, mesa, wayland, DRM drivers, and every other recipe source.
74 lines
1.6 KiB
Rust
74 lines
1.6 KiB
Rust
use alloc::collections::VecDeque;
|
|
use core::fmt;
|
|
use spin::{Mutex, MutexGuard};
|
|
|
|
use crate::devices::graphical_debug::{DebugDisplay, DEBUG_DISPLAY};
|
|
|
|
pub static LOG: Mutex<Option<Log>> = Mutex::new(None);
|
|
|
|
pub fn init() {
|
|
*LOG.lock() = Some(Log::new(1024 * 1024));
|
|
}
|
|
|
|
pub struct Log {
|
|
data: VecDeque<u8>,
|
|
size: usize,
|
|
}
|
|
|
|
impl Log {
|
|
pub fn new(size: usize) -> Log {
|
|
Log {
|
|
data: VecDeque::with_capacity(size),
|
|
size,
|
|
}
|
|
}
|
|
|
|
pub fn read(&self) -> (&[u8], &[u8]) {
|
|
self.data.as_slices()
|
|
}
|
|
|
|
pub fn write(&mut self, buf: &[u8]) {
|
|
for &b in buf {
|
|
while self.data.len() + 1 >= self.size {
|
|
self.data.pop_front();
|
|
}
|
|
self.data.push_back(b);
|
|
}
|
|
}
|
|
}
|
|
|
|
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 && 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 fmt::Write for Writer<'_> {
|
|
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
|
self.write(s.as_bytes(), true);
|
|
Ok(())
|
|
}
|
|
}
|