65 lines
2.2 KiB
Rust
65 lines
2.2 KiB
Rust
use core::fmt::Write;
|
|
|
|
use spin::Mutex;
|
|
use uart_16550::SerialPort;
|
|
|
|
|
|
|
|
const COM_PORTS: [u16; 8] = [0x3F8, 0x2F8, 0x3E8, 0x2E8, 0x5F8, 0x4F8, 0x5E8, 0x4E8];
|
|
|
|
|
|
fn init_com_port(port_no: u16) -> Mutex<SerialPort> {
|
|
let mut p = unsafe {SerialPort::new(port_no)};
|
|
p.init();
|
|
Mutex::new(p)
|
|
}
|
|
|
|
lazy_static::lazy_static!(
|
|
pub static ref COM0: Mutex<SerialPort> = init_com_port(COM_PORTS[0]);
|
|
pub static ref COM1: Mutex<SerialPort> = init_com_port(COM_PORTS[1]);
|
|
pub static ref COM2: Mutex<SerialPort> = init_com_port(COM_PORTS[2]);
|
|
);
|
|
|
|
pub fn write_com(cp: &'static Mutex<SerialPort>, args: core::fmt::Arguments) {
|
|
use x86_64::instructions::interrupts::without_interrupts;
|
|
without_interrupts(|| {
|
|
cp.lock().write_fmt(args).unwrap();
|
|
})
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
#[allow(dead_code)]
|
|
pub mod ANSI_COLORS {
|
|
pub const RESET: &str = "\x1b[0m";
|
|
pub const BOLD: &str = "\x1b[1m";
|
|
pub const ITALIC: &str = "\x1b[3m";
|
|
pub const UNDERLINE: &str = "\x1b[4m";
|
|
pub const BLINK: &str = "\x1b[5m";
|
|
pub const BLINK2: &str = "\x1b[6m";
|
|
pub const SELECTED: &str = "\x1b[7m";
|
|
pub const BLACK: &str = "\x1b[30m";
|
|
pub const RED: &str = "\x1b[31m";
|
|
pub const GREEN: &str = "\x1b[32m";
|
|
pub const YELLOW: &str = "\x1b[33m";
|
|
pub const BLUE: &str = "\x1b[34m";
|
|
pub const MAGENTA: &str = "\x1b[35m";
|
|
pub const BEIGE: &str = "\x1b[36m";
|
|
pub const WHITE: &str = "\x1b[37m";
|
|
pub const BLACKBG: &str = "\x1b[40m";
|
|
pub const REDBG: &str = "\x1b[41m";
|
|
pub const GREENBG: &str = "\x1b[42m";
|
|
pub const YELLOWBG: &str = "\x1b[43m";
|
|
pub const BLUEBG: &str = "\x1b[44m";
|
|
pub const MAGENTABG: &str = "\x1b[45m";
|
|
pub const BEIGEBG: &str = "\x1b[46m";
|
|
pub const WHITEBG: &str = "\x1b[47m";
|
|
pub const GREY: &str = "\x1b[90m";
|
|
pub const RED2: &str = "\x1b[91m";
|
|
pub const GREEN2: &str = "\x1b[92m";
|
|
pub const YELLOW2: &str = "\x1b[93m";
|
|
pub const BLUE2: &str = "\x1b[94m";
|
|
pub const MAGENTA2: &str = "\x1b[95m";
|
|
pub const BEIGE2: &str = "\x1b[96m";
|
|
pub const WHITE2: &str = "\x1b[97m";
|
|
}
|