Add first user program hello_world.rs

This commit is contained in:
Yifan Wu 2020-11-18 14:48:13 +08:00
parent c701cd00ce
commit db0c174f52
79 changed files with 343 additions and 0 deletions

29
user/src/console.rs Normal file
View file

@ -0,0 +1,29 @@
use core::fmt::{self, Write};
use crate::syscall::{STDOUT, sys_write};
struct Stdout;
impl Write for Stdout {
fn write_str(&mut self, s: &str) -> fmt::Result {
sys_write(STDOUT, 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)+)?));
}
}