From 365c2c1ce38a34efddea4b444f4eab3c7fed7677 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Thu, 2 May 2024 13:21:13 +0300 Subject: [PATCH] [HAL:APIC] Fix HalSetTimeIncrement Fix calculation of clock rate. Previously it would go above the maximum, causing issues with KeUpdateSystemTime. --- hal/halx86/apic/rtctimer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hal/halx86/apic/rtctimer.c b/hal/halx86/apic/rtctimer.c index 30058baebdd..5bdf6bf93c9 100644 --- a/hal/halx86/apic/rtctimer.c +++ b/hal/halx86/apic/rtctimer.c @@ -31,7 +31,7 @@ static BOOLEAN HalpSetClockRate; static UCHAR HalpNextClockRate; /*! - \brief Converts the CMOS RTC rate into the time increment in 100ns intervals. + \brief Converts the CMOS RTC rate into the time increment in 0.1ns intervals. Rate Frequency Interval (ms) Precise increment (0.1ns) ------------------------------------------------------ @@ -222,14 +222,15 @@ NTAPI HalSetTimeIncrement(IN ULONG Increment) { UCHAR Rate; - ULONG CurrentIncrement; + ULONG NextIncrement; /* Lookup largest value below given Increment */ - for (Rate = RtcMinimumClockRate; Rate <= RtcMaximumClockRate; Rate++) + for (Rate = RtcMinimumClockRate; Rate < RtcMaximumClockRate; Rate++) { /* Check if this is the largest rate possible */ - CurrentIncrement = RtcClockRateToPreciseIncrement(Rate + 1) / 1000; - if (Increment > CurrentIncrement) break; + NextIncrement = RtcClockRateToPreciseIncrement(Rate + 1) / 1000; + if (NextIncrement > Increment) + break; } /* Set the rate and tell HAL we want to change it */