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:
14
crates/apps/sleep/Cargo.toml
Normal file
14
crates/apps/sleep/Cargo.toml
Normal 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 }
|
||||
28
crates/apps/sleep/src/main.rs
Normal file
28
crates/apps/sleep/src/main.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user