2022-04-30 16:04:58 +08:00
|
|
|
//! SBI console driver, for text output
|
2020-11-12 17:13:57 +08:00
|
|
|
use crate::sbi::console_putchar;
|
2022-01-21 14:56:19 -08:00
|
|
|
use core::fmt::{self, Write};
|
2020-11-12 17:13:57 +08:00
|
|
|
|
|
|
|
struct Stdout;
|
|
|
|
|
|
|
|
impl Write for Stdout {
|
|
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
|
|
for c in s.chars() {
|
|
|
|
console_putchar(c as usize);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print(args: fmt::Arguments) {
|
|
|
|
Stdout.write_fmt(args).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-04-30 16:04:58 +08:00
|
|
|
/// print string macro
|
2020-11-12 17:13:57 +08:00
|
|
|
macro_rules! print {
|
|
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
|
|
$crate::console::print(format_args!($fmt $(, $($arg)+)?));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
2022-04-30 16:04:58 +08:00
|
|
|
/// println string macro
|
2020-11-12 17:13:57 +08:00
|
|
|
macro_rules! println {
|
|
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
|
|
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
|
|
|
|
}
|
|
|
|
}
|