init: add test std*** setup

This commit is contained in:
Mark Poliakov 2023-07-20 18:14:48 +03:00
parent 36ac85cb80
commit 4eb8faae84
2 changed files with 18 additions and 19 deletions

View File

@ -13,6 +13,10 @@ fi
USER_TARGET=${ARCH}-unknown-yggdrasil
USER_CARGO_OPTS="--target=${USER_TARGET}"
if [ "${PROFILE}" = "release" ]; then
USER_CARGO_OPTS="${USER_CARGO_OPTS} --release"
fi
pstatus() {
echo -e "[BUILD] \033[32;1m$@\033[0m"
}

View File

@ -1,12 +1,9 @@
#![feature(rustc_private)]
use std::fs::File;
use std::io::Read;
use std::os::yggdrasil::{mount, unmount, MountOptions, UnmountOptions};
use std::os::yggdrasil::{mount, open, OpenOptions, FileMode, unmount, MountOptions, UnmountOptions};
fn main() {
println!("Hello!");
unsafe {
mount(MountOptions {
source: None,
@ -14,26 +11,24 @@ fn main() {
target: "/dev",
})
.unwrap();
// Open stdin/stdout/stderr
open("/dev/ttyS0", OpenOptions::READ, FileMode::empty()).unwrap();
open("/dev/ttyS0", OpenOptions::WRITE, FileMode::empty()).unwrap();
open("/dev/ttyS0", OpenOptions::WRITE, FileMode::empty()).unwrap();
}
let mut file = File::open("/dev/ttyS0").unwrap();
let mut buf = [0; 1];
let mut stdin = std::io::stdin();
let mut buffer = String::new();
while let Ok(count) = file.read(&mut buf) {
if count != 1 {
while let Ok(len) = stdin.read_line(&mut buffer) {
if len == 0 {
println!("End of file reached");
break;
}
if buf[0] == 0x3 {
break;
println!("{:?}", buffer.trim());
buffer.clear();
}
println!("Got {:#x}", buf[0]);
}
unsafe {
unmount(UnmountOptions {
mountpoint: "/dev"
}).unwrap();
}
loop {}
}