hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/boot/timer.zig
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-25 18:08:17 +0200
committerhachem <im@hachem.wtf>2026-09-25 18:08:17 +0200
commitfd3f51eecaecc12806a573c38263df1de43ee8c2 (patch)
tree4bd43519ce87af6b791c7f86d8a273829a56786d /boot/timer.zig
parent6593ddc56fc96df0a566cc3b1a3e9396e4f3b2c6 (diff)
feat: pit timer
Diffstat (limited to 'boot/timer.zig')
-rw-r--r--boot/timer.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/boot/timer.zig b/boot/timer.zig
new file mode 100644
index 0000000..4569d6a
--- /dev/null
+++ b/boot/timer.zig
@@ -0,0 +1,17 @@
+// PIT channel 0 tick counter
+// configuring the PIT itself (outb to 0x43/0x40) is done in revo (kernel
+// `pit_init`), since it's just port writes the VM can drive
+
+var ticks: u64 = 0;
+
+// called from the IRQ0 handler
+pub fn onIrq() void {
+ const t: *volatile u64 = &ticks;
+ t.* +%= 1;
+}
+
+// called from the event loop
+pub fn now() u64 {
+ const t: *volatile u64 = &ticks;
+ return t.*;
+}