/* ============================================================================ * Pactor64 — PIT Timer Driver (x86-64) * IRQ0 (INT 0x20), 100 Hz default, monotonic tick counter * ============================================================================ */ #include "../include/pactor64.h" /* === Tick Counters === */ static volatile uint64_t timer_ticks = 0; static volatile uint64_t timer_seconds = 0; /* Forward declaration — defined in idt.c */ extern void irq_install(int irq, void (*handler)(registers_t *regs)); /* === Timer ISR (IRQ0) === */ static void timer_isr(registers_t *regs) { (void)regs; timer_ticks++; if (timer_ticks % 100 == 0) { timer_seconds++; } } /* === Initialize PIT at given frequency === */ void timer_init(uint32_t hz) { uint32_t divisor = 1193182 / hz; /* Channel 0, lobyte/hibyte, rate generator (mode 2) */ outb(0x43, 0x34); outb(0x40, divisor & 0xFF); outb(0x40, (divisor >> 8) & 0xFF); /* Register our ISR for IRQ0 and unmask it */ irq_install(0x20, timer_isr); pic_unmask_irq(0); } uint64_t timer_get_ticks(void) { return timer_ticks; } uint64_t timer_get_seconds(void) { return timer_seconds; }