You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.3 KiB
62 lines
1.3 KiB
use crate::drivers::chardev::{CharDevice, UART};
|
|
use core::fmt::{self, Write};
|
|
|
|
struct Stdout;
|
|
|
|
impl Write for Stdout {
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
for c in s.chars() {
|
|
UART.write(c as u8);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub fn print(args: fmt::Arguments) {
|
|
Stdout.write_fmt(args).unwrap();
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! print {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!($fmt $(, $($arg)+)?))
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! println {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?))
|
|
}
|
|
}
|
|
|
|
use crate::sbi::console_putchar;
|
|
struct Kstdout;
|
|
|
|
impl Write for Kstdout {
|
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
for c in s.chars() {
|
|
console_putchar(c as usize);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub fn kprint(args: fmt::Arguments) {
|
|
Kstdout.write_fmt(args).unwrap();
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! kprint {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::kprint(format_args!($fmt $(, $($arg)+)?));
|
|
}
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! kprintln {
|
|
($fmt: literal $(, $($arg: tt)+)?) => {
|
|
$crate::console::kprint(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
|
|
}
|
|
}
|