1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::arch::riscv_sbi::console_putchar;
use core::fmt::{self, Write};

struct Stdout;

impl Write for Stdout {
    /// In order to 
    /// See <https://github.com/rcore-os/rCore-Tutorial-Book-v3/issues/100#issuecomment-1127614678>
    fn write_str(&mut self, s: &str) -> fmt::Result {
        for b in s.bytes() {
            console_putchar(b as usize);
        }
        Ok(())
    }
}
pub fn printk(args: fmt::Arguments) {
    Stdout.write_fmt(args).unwrap();
}

//#[macro_export]
macro_rules! print {
    ($fmt: literal $(, $($arg: tt)+)?) => {
        $crate::os::printk::printk(format_args!($fmt $(, $($arg)+)?));
    }
}

//#[macro_export]
macro_rules! println {
    ($fmt: literal $(, $($arg: tt)+)?) => {
        $crate::os::printk::printk(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
    }
}

// #[macro_export]
#[cfg(debug_assertions)]
macro_rules! debug_print {
    ($fmt: literal $(, $($arg: tt)+)?) => {
        $crate::os::printk::print!("[D]");
        $crate::os::printk::print!($fmt $(, $($arg)+)?);
    }
}

// #[macro_export]
#[cfg(debug_assertions)]
macro_rules! debug_println {
    ($fmt: literal $(, $($arg: tt)+)?) => {
        $crate::os::printk::print!("[D]");
        $crate::os::printk::println!($fmt $(, $($arg)+)?);
    }
}

#[doc(inline)]
pub(crate) use {
    print,
    println,
    debug_print,
    debug_println,
};