init: add test std*** setup
This commit is contained in:
parent
36ac85cb80
commit
4eb8faae84
4
build.sh
4
build.sh
@ -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"
|
||||
}
|
||||
|
@ -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!("Got {:#x}", buf[0]);
|
||||
println!("{:?}", buffer.trim());
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
unmount(UnmountOptions {
|
||||
mountpoint: "/dev"
|
||||
}).unwrap();
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user