1use crate::hal::{self, Machinelike};
2use core::fmt::{self, Write};
3
4pub struct Printer;
5
6impl Write for Printer {
7 fn write_str(&mut self, s: &str) -> fmt::Result {
8 hal::Machine::print(s).map_err(|_| fmt::Error)?;
9 Ok(())
10 }
11}
12
13pub fn print(args: fmt::Arguments) {
14 use core::fmt::Write;
15 let mut printer = Printer;
16 printer.write_fmt(args).unwrap();
17}
18
19#[macro_export]
20macro_rules! kprint {
21 ($($arg:tt)*) => {{
22 use $crate::time;
23 use $crate::print::print;
24 let (secs, frac) = time::to_secs(time::mono_now(), time::mono_freq() as u32, 6);
26 print(format_args!("[{}.{:06}] ", secs, frac));
27 print(format_args!($($arg)*));
28 }};
29}
30
31#[macro_export]
32macro_rules! kprintln {
33 ($($arg:tt)*) => {{
34 use $crate::time;
35 use $crate::print::print;
36 let (secs, frac) = time::to_secs(time::mono_now(), time::mono_freq() as u32, 6);
38 print(format_args!("[{}.{:06}] ", secs, frac));
39 print(format_args!($($arg)*));
40 print(format_args!("\n"));
41 }};
42}
43
44#[macro_export]
45macro_rules! kprint_cont {
46 ($($arg:tt)*) => {{
47 use $crate::print::print;
48 print(format_args!($($arg)*));
49 }};
50}
51
52pub fn print_header() {
53 kprint!("****************************************************************\n");
54 kprint!(" ___ _ _ ____ _____ ___ ____ \n");
55 kprint!(" / _ \\ ___(_)_ __(_)___ | _ \\_ _/ _ \\/ ___| \n");
56 kprint!("| | | / __| | '__| / __| | |_) || || | | \\___ \\ \n");
57 kprint!("| |_| \\__ \\ | | | \\__ \\ | _ < | || |_| |___) | \n");
58 kprint!(" \\___/|___/_|_| |_|___/ |_| \\_\\|_| \\___/|____/ \n");
59 kprint!("\n");
60 kprint!("****************************************************************\n");
61 kprint!("\n");
62}