os/
console.rs

1//! SBI console driver, for text output
2use crate::sbi::console_putchar;
3use core::fmt::{self, Write};
4
5struct Stdout;
6
7impl Write for Stdout {
8    fn write_str(&mut self, s: &str) -> fmt::Result {
9        for c in s.chars() {
10            console_putchar(c as usize);
11        }
12        Ok(())
13    }
14}
15
16pub fn print(args: fmt::Arguments) {
17    Stdout.write_fmt(args).unwrap();
18}
19
20#[macro_export]
21/// print string macro
22macro_rules! print {
23    ($fmt: literal $(, $($arg: tt)+)?) => {
24        $crate::console::print(format_args!($fmt $(, $($arg)+)?));
25    }
26}
27
28#[macro_export]
29/// println string macro
30macro_rules! println {
31    ($fmt: literal $(, $($arg: tt)+)?) => {
32        $crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
33    }
34}