Add user program initproc/user_shell, allow user programs allocate data on heap.

This commit is contained in:
Yifan Wu 2020-12-09 09:56:06 +08:00
parent eddbc8954c
commit 81bef97f09
7 changed files with 170 additions and 15 deletions

View file

@ -1,11 +1,15 @@
use core::fmt::{self, Write};
use crate::syscall::{STDOUT, sys_write};
const STDIN: usize = 0;
const STDOUT: usize = 1;
use super::{read, write};
struct Stdout;
impl Write for Stdout {
fn write_str(&mut self, s: &str) -> fmt::Result {
sys_write(STDOUT, s.as_bytes());
write(STDOUT, s.as_bytes());
Ok(())
}
}
@ -26,4 +30,10 @@ macro_rules! println {
($fmt: literal $(, $($arg: tt)+)?) => {
$crate::console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
}
}
}
pub fn getchar() -> u8 {
let mut c = [0u8; 1];
read(STDIN, &mut c);
c[0]
}