feat(drivers): HPET high-res timer, LPT parallel port, CMOS NVRAM

Add three real platform device drivers (x86 hardware, ARM-stubbed):

- drivers/timer/hpet.c + include/drivers/hpet.h: High Precision Event Timer.
  Maps the HPET block at the standard 0xFED00000, reads the femtosecond period
  from the capability register, enables the main counter and exposes a
  monotonic nanosecond time source (hpet_get_ns) far finer than the 100 Hz PIT.
- drivers/char/lpt.c + include/drivers/lpt.h: IBM PC parallel port (LPT1) with
  the Centronics data/strobe handshake over ports 0x378/0x379/0x37A.
- drivers/char/nvram.c + include/drivers/nvram.h: MC146818 CMOS NVRAM read/write
  over 0x70/0x71, preserving the NMI-disable bit, with checksum and hex dump.

Wired all three into the [5/14] device-enumeration boot step and added LazyBox
applets `hpet`, `lpt`, and `nvram`.

Verified live under QEMU (screenshotted): HPET reports 100 MHz / 3 comparators /
10 ns period and its counter advances ~1.4 s of real time between two `hpet`
runs; NVRAM dumps 128 bytes with a computed checksum; LPT1 detected at 0x378.
Clean build on x86_64/aarch64/armv8i; 0 panics / 0 OOM.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fh5z6V7nGPbHvqVG5p4CXX
This commit is contained in:
subhobhai943andClaude Opus 4.8 committed 2026-08-25 21:04:03 +05:30
1 parent ea937a699c
commit 0377726615
9 files changed
+340 -1

No files matched your search

+39
View File
@@ -32,6 +32,9 @@
#include <kernel/nt/ob.h>
#include <kernel/nt/reg.h>
#include <kernel/nt/io.h>
#include <drivers/hpet.h>
#include <drivers/nvram.h>
#include <drivers/lpt.h>
#include <kernel/sub_lang.h>
#include <kernel/cpp_kernel.h>
#include <userland/snake.h>
@@ -715,6 +718,39 @@ static int applet_iodev(int argc, char** argv) {
return 0;
}
static int applet_hpet(int argc, char** argv) {
(void)argc; (void)argv;
if (!hpet_available()) {
printk("HPET: not available on this platform\n");
return 1;
}
printk(ANSI_BRIGHT_CYAN "High Precision Event Timer:\n" ANSI_RESET);
printk(" Frequency : %llu Hz\n", (unsigned long long)hpet_get_frequency_hz());
printk(" Comparators: %u\n", hpet_num_timers());
printk(" Main count : %llu\n", (unsigned long long)hpet_read_counter());
printk(" Uptime : %llu ns since HPET enable\n", (unsigned long long)hpet_get_ns());
return 0;
}
static int applet_nvram(int argc, char** argv) {
(void)argc; (void)argv;
nvram_dump();
printk(" checksum(0x0E..0x7F) = 0x%02X\n", nvram_checksum());
return 0;
}
static int applet_lpt(int argc, char** argv) {
if (!lpt_present()) {
printk("LPT: no parallel port present\n");
return 1;
}
const char* text = (argc >= 2) ? argv[1] : "SUB-OS\n";
int n = lpt_write(text, strlen(text));
printk("LPT1: status=0x%02X, wrote %d byte(s) to the parallel port\n",
lpt_status(), n);
return 0;
}
static int applet_rand(int argc, char** argv) {
int count = (argc >= 2) ? atoi(argv[1]) : 4;
printk("Random Integers: ");
@@ -2428,6 +2464,9 @@ static const lazybox_applet_t applets[] = {
{"ntobj", applet_ntobj, "ntobj", "NT Object Manager stats/demo","Kernel"},
{"reg", applet_reg, "reg query|add|set|stats", "NT configuration registry", "Kernel"},
{"iodev", applet_iodev, "iodev", "NT I/O Manager devices & IRP","Kernel"},
{"hpet", applet_hpet, "hpet", "High Precision Event Timer", "Hardware"},
{"nvram", applet_nvram, "nvram", "Dump CMOS NVRAM bytes", "Hardware"},
{"lpt", applet_lpt, "lpt [text]", "Send text to LPT1 parallel", "Hardware"},
{"rand", applet_rand, "rand [count]", "Generate random numbers", "Crypto"},
{"certcheck", applet_certcheck, "certcheck", "View X.509 kernel keyring", "Security"},
{"capsh", applet_capsh, "capsh", "View process capabilities", "Security"},