twizzler_abi/
klog.rs

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
//! Utilities that enable formatted printing for early runtime init.

use core::fmt;

use crate::syscall::{sys_kernel_console_write, KernelConsoleWriteFlags};

#[repr(C)]
struct KernelLogger;

impl fmt::Write for KernelLogger {
    fn write_str(&mut self, s: &str) -> fmt::Result {
        sys_kernel_console_write(s.as_bytes(), KernelConsoleWriteFlags::empty());
        Ok(())
    }
}

#[doc(hidden)]
pub fn _print_normal(args: core::fmt::Arguments) {
    use fmt::Write;
    let _ = KernelLogger.write_fmt(args);
}

#[macro_export]
macro_rules! klog_print {
    ($($arg:tt)*) => {
        $crate::klog::_print_normal(format_args!($($arg)*))
    };
}

#[macro_export]
macro_rules! klog_println {
    () => {
        $crate::klog_print!("\n")
    };
    ($fmt:expr) => {
        $crate::klog_print!(concat!($fmt, "\n"))
    };
    ($fmt:expr, $($arg:tt)*) => {
        $crate::klog_print!(concat!($fmt, "\n"), $($arg)*)
    };
}