2018-04-04 20:58:23 +04:00
|
|
|
use core::fmt;
|
2018-04-17 15:42:58 +04:00
|
|
|
use arch::driver::serial::COM1;
|
2018-04-04 20:58:23 +04:00
|
|
|
|
|
|
|
mod vga_writer;
|
|
|
|
|
2018-04-07 16:57:14 +04:00
|
|
|
macro_rules! _debug {
|
|
|
|
($($arg:tt)*) => ({
|
|
|
|
$crate::io::debug(format_args!($($arg)*));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! debug {
|
|
|
|
($fmt:expr) => (_debug!(concat!($fmt, "\n")));
|
|
|
|
($fmt:expr, $($arg:tt)*) => (_debug!(concat!($fmt, "\n"), $($arg)*));
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:58:23 +04:00
|
|
|
macro_rules! print {
|
|
|
|
($($arg:tt)*) => ({
|
|
|
|
$crate::io::print(format_args!($($arg)*));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! println {
|
|
|
|
($fmt:expr) => (print!(concat!($fmt, "\n")));
|
|
|
|
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
|
|
|
}
|
|
|
|
|
2018-04-07 16:57:14 +04:00
|
|
|
use arch::driver::vga::Color;
|
|
|
|
|
|
|
|
fn print_in_color(args: fmt::Arguments, color: Color) {
|
2018-04-04 20:58:23 +04:00
|
|
|
use core::fmt::Write;
|
2018-04-18 11:22:06 +04:00
|
|
|
use arch::driver::vga::*;
|
2018-04-25 21:00:32 +04:00
|
|
|
// {
|
|
|
|
// let mut writer = vga_writer::VGA_WRITER.lock();
|
|
|
|
// writer.set_color(color);
|
|
|
|
// writer.write_fmt(args).unwrap();
|
|
|
|
// }
|
2018-04-27 17:49:01 +04:00
|
|
|
// TODO: 解决死锁问题
|
|
|
|
// 若进程在持有锁时被中断,中断处理程序请求输出,就会死锁
|
|
|
|
unsafe{ COM1.force_unlock(); }
|
2018-04-17 15:42:58 +04:00
|
|
|
COM1.lock().write_fmt(args).unwrap();
|
2018-04-07 16:57:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print(args: fmt::Arguments) {
|
|
|
|
print_in_color(args, Color::LightGray);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn debug(args: fmt::Arguments) {
|
|
|
|
print_in_color(args, Color::LightRed);
|
2018-05-12 23:41:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write(fd: usize, base: *const u8, len: usize) {
|
|
|
|
// debug!("write: fd: {}, base: {:?}, len: {:#x}", fd, base, len);
|
|
|
|
use core::slice;
|
|
|
|
use core::str;
|
|
|
|
let slice = unsafe { slice::from_raw_parts(base, len) };
|
|
|
|
print!("{}", str::from_utf8(slice).unwrap());
|
2018-04-04 20:58:23 +04:00
|
|
|
}
|