#[allow(unused)]
macro_rules! debug {
($($arg:tt)*) => ({
$crate::device::Output::Debug.write(format_args!($($arg)*));
});
}
#[allow(unused)]
macro_rules! print {
($($arg:tt)*) => ({
$crate::device::Output::Print.write(format_args!($($arg)*));
});
}
#[allow(unused)]
macro_rules! println {
($($arg:tt)*) => ({
$crate::device::Output::Println.write(format_args!($($arg)*));
});
}
#[allow(unused)]
macro_rules! serial {
(force: $($arg:tt)*) => ({
$crate::device::Output::Serial {
force: true,
file: core::file!(),
line: core::line!(),
}.write(format_args!($($arg)*))
});
($($arg:tt)*) => ({
$crate::device::Output::Serial {
force: false,
file: core::file!(),
line: core::line!(),
}.write(format_args!($($arg)*));
});
}
use core::fmt::{self, Write};
mod serial;
pub use serial::Serial;
pub mod cga;
use cga::{Attribute, Color, Rect, Window};
#[cfg(feature = "graphics")]
pub mod vga;
mod keyboard;
pub use keyboard::{KeyBuffer, PS2Controller};
use crate::arch::{cpu, int};
use crate::interrupts::guard::GUARD;
use crate::util::Spin;
pub static mut KEYBOARD: PS2Controller = PS2Controller::new();
pub static KOUT: Spin<Window> = Spin::new(
Window::new(Rect::new(0, 10, 40, 15))
.with_hw_cursor()
.with_style(Attribute::with(Color::Black, Color::Brown)),
);
pub static DBG: Spin<Window> = Spin::new(
Window::new(Rect::new(40, 0, 40, 25)).with_style(Attribute::with(Color::Red, Color::Blue)),
);
pub static SERIAL: Spin<Serial> = Spin::new(Serial::new(serial::COM1));
#[allow(unused)]
pub enum Output {
Debug,
Print,
Println,
Serial {
force: bool,
file: &'static str,
line: u32,
},
}
impl Output {
pub fn write(self, args: fmt::Arguments) {
let _ = int::suppress(|| match self {
Self::Debug => writeln!(DBG.lock(), "{args}"),
Self::Print => write!(KOUT.lock(), "{args}"),
Self::Println => writeln!(KOUT.lock(), "{args}"),
Self::Serial { force, file, line } => {
let mut _lock = None; let serial = if force {
unsafe { SERIAL.raw() }
} else {
_lock = Some(SERIAL.lock());
_lock.as_mut().unwrap()
};
let c = cpu::id();
let t = unsafe { GUARD.read().scheduler.active().unwrap_or(0) };
writeln!(serial, "\x1b[0;90m[{c}:{t} {file}:{line}]\x1b[0m {args}")
}
});
}
}