feat(userspace): programs in /bin w/o .elf; bin manifests (needs = display) so shell runs snake; Ctrl+C kills foreground via terminal interrupt notification; ctrl keys; sleep

This commit is contained in:
2026-10-27 21:16:00 +01:00
parent 1fc5a54f06
commit 83809bbe94
33 changed files with 608 additions and 121 deletions

View File

@@ -0,0 +1,14 @@
[package]
name = "sleep"
version = "0.1.0"
edition = "2024"
[[bin]]
name = "sleep"
test = false
bench = false
[dependencies]
types = { workspace = true }
libkos = { workspace = true }

View File

@@ -0,0 +1,28 @@
//! Waits: `sleep <seconds>`. Mostly something to stop with Ctrl+C.
#![no_std]
#![no_main]
extern crate libkos;
use libkos::{println, syscall};
use types::time::Ticks;
/// QEMU virt's timebase.
const TICKS_PER_SECOND: u64 = 10_000_000;
#[unsafe(no_mangle)]
extern "C" fn main() {
let Some(seconds) = libkos::start::args().nth(1).and_then(|s| s.parse::<u64>().ok()) else {
println!("usage: sleep <seconds>");
return;
};
let Ok(alarm) = syscall::create_notification() else {
println!("sleep: no notification");
return;
};
let at = syscall::get_time().raw().saturating_add(seconds.saturating_mul(TICKS_PER_SECOND));
if syscall::set_timer(alarm, Ticks::from_raw(at)).is_ok() {
let _ = syscall::wait(alarm);
}
}