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_TARGET=${ARCH}-unknown-yggdrasil
USER_CARGO_OPTS="--target=${USER_TARGET}" USER_CARGO_OPTS="--target=${USER_TARGET}"
if [ "${PROFILE}" = "release" ]; then
USER_CARGO_OPTS="${USER_CARGO_OPTS} --release"
fi
pstatus() { pstatus() {
echo -e "[BUILD] \033[32;1m$@\033[0m" echo -e "[BUILD] \033[32;1m$@\033[0m"
} }

View File

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