From 7aa8eb17788b65f07197832115affdea1dbe5860 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 17 Aug 2026 04:33:20 +0300 Subject: [PATCH] Kernel: Use 64 bit write on HPET on x86_64 --- kernel/kernel/Timer/HPET.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/kernel/kernel/Timer/HPET.cpp b/kernel/kernel/Timer/HPET.cpp index b3e67783..aebd8b36 100644 --- a/kernel/kernel/Timer/HPET.cpp +++ b/kernel/kernel/Timer/HPET.cpp @@ -240,25 +240,35 @@ namespace Kernel // set timer period to 1000 Hz const uint64_t ticks_per_ms = m_ticks_per_s / 1000; - timer0.configuration = timer0.configuration | Tn_VAL_SET_CNF; - timer0.comparator.low = ticks_per_ms; + if (timer0.configuration & Tn_SIZE_CAP) { +#if ARCH(x86_64) timer0.configuration = timer0.configuration | Tn_VAL_SET_CNF; + timer0.comparator.full = ticks_per_ms; +#else + timer0.configuration = timer0.configuration | Tn_VAL_SET_CNF; + timer0.comparator.low = ticks_per_ms; + timer0.configuration = timer0.configuration | Tn_VAL_SET_CNF; timer0.comparator.high = ticks_per_ms >> 32; +#endif } - else if (ticks_per_ms > 0xFFFFFFFF) + else if (ticks_per_ms <= 0xFFFFFFFF) + { + timer0.configuration = timer0.configuration | Tn_VAL_SET_CNF; + timer0.comparator.low = ticks_per_ms; + } + else { dprintln("HPET: cannot create 1 kHz timer"); return BAN::Error::from_errno(ENOTSUP); } - // enable main counter - regs.configuration.low = regs.configuration.low | ENABLE_CNF; - set_irq(irq); InterruptController::get().enable_irq(irq); + regs.configuration.low = regs.configuration.low | ENABLE_CNF; + return {}; }