Files
RedBear-OS/rtcd/src/main.rs
T
4lDO2 af1dd1e78e Add a userspace RTC driver for x86 PCs.
The reason behind this is that an RTC driver should ideally consult ACPI
tables before assuming any I/O ports exist, which userspace can do much
better.
2025-03-30 16:37:04 +02:00

27 lines
978 B
Rust

use anyhow::{Context, Result};
// TODO: Do not use target architecture to distinguish these.
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86;
/// The rtc driver runs only once, being perhaps the first of all processes that init starts (since
/// early logging benefits from knowing the time, even though this can be adjusted later once the
/// time is known). The sole job of `rtcd` is to read from the hardware real-time clock, and then
/// write the offset to the kernel.
fn main() -> Result<()> {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
common::acquire_port_io_rights().context("failed to set iopl")?;
let time_s = self::x86::get_time();
let time_ns = u128::from(time_s) * 1_000_000_000;
std::fs::write("/scheme/sys/update_time_offset", &time_ns.to_ne_bytes())
.context("failed to write to time offset")?;
}
// TODO: aarch64 is currently handled in the kernel
Ok(())
}