-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement serial and serial println with better qemu
- Loading branch information
1 parent
670619e
commit 0369e2b
Showing
4 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use uart_16550::SerialPort; | ||
use spin::Mutex; | ||
use lazy_static::lazy_static; | ||
|
||
lazy_static! { | ||
pub static ref SERIAL1: Mutex<SerialPort> = { | ||
let mut serial_port = unsafe { SerialPort::new(0x3F8) }; | ||
serial_port.init(); | ||
Mutex::new(serial_port) | ||
}; | ||
} | ||
|
||
#[doc(hidden)] | ||
pub fn _print(args: ::core::fmt::Arguments) { | ||
use core::fmt::Write; | ||
SERIAL1.lock().write_fmt(args).expect("Printing to serial failed"); | ||
} | ||
|
||
/// Prints to the host through the serial interface. | ||
#[macro_export] | ||
macro_rules! serial_print { | ||
($($arg:tt)*) => { | ||
$crate::serial::_print(format_args!($($arg)*)); | ||
}; | ||
} | ||
|
||
/// Prints to the host through the serial interface, appending a newline. | ||
#[macro_export] | ||
macro_rules! serial_println { | ||
() => ($crate::serial_print!("\n")); | ||
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n"))); | ||
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!( | ||
concat!($fmt, "\n"), $($arg)*)); | ||
} |