ch1: Print and shutdown based on sbi
This commit is contained in:
parent
43fd85405b
commit
3681c27870
6 changed files with 94 additions and 3 deletions
29
src/console.rs
Normal file
29
src/console.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use core::fmt::{self, Write};
|
||||
use crate::sbi;
|
||||
|
||||
struct Stdout;
|
||||
|
||||
impl Write for Stdout {
|
||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
sbi::console_write(s.as_bytes());
|
||||
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)+)?));
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue