https://git.reactos.org/?p=reactos.git;a=commitdiff;h=aa3ef4c6326abba7d2617…
commit aa3ef4c6326abba7d261798c42918d88d3a1eedb
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Fri Jul 16 11:45:39 2021 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Mon Jul 19 23:05:03 2021 +0200
[HAL/APIC] Fix clock initialization
Previously we enabled the timer interrupt, before the kernel was notified of our time
increment, so when a clock interrupt happened, it would increment the tick count, but add
0 to the system time, resulting in an invalid state, in which timers would be inserted
into the wrong timer table slot. Fixes CORE-16253
---
hal/halx86/apic/apic.c | 4 ++--
hal/halx86/apic/rtctimer.c | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/hal/halx86/apic/apic.c b/hal/halx86/apic/apic.c
index 9f204bded55..69f1841642c 100644
--- a/hal/halx86/apic/apic.c
+++ b/hal/halx86/apic/apic.c
@@ -463,12 +463,12 @@ ApicInitializeIOApic(VOID)
HalpVectorToIndex[Vector] = APIC_FREE_VECTOR;
}
- /* Enable the timer interrupt */
+ /* Enable the timer interrupt (but keep it masked) */
ReDirReg.Vector = APIC_CLOCK_VECTOR;
ReDirReg.DeliveryMode = APIC_MT_Fixed;
ReDirReg.DestinationMode = APIC_DM_Physical;
ReDirReg.TriggerMode = APIC_TGM_Edge;
- ReDirReg.Mask = 0;
+ ReDirReg.Mask = 1;
ReDirReg.Destination = ApicRead(APIC_ID);
ApicWriteIORedirectionEntry(APIC_CLOCK_INDEX, ReDirReg);
}
diff --git a/hal/halx86/apic/rtctimer.c b/hal/halx86/apic/rtctimer.c
index f4761c5d31f..4c0b27dbc06 100644
--- a/hal/halx86/apic/rtctimer.c
+++ b/hal/halx86/apic/rtctimer.c
@@ -122,6 +122,8 @@ HalpInitializeClock(VOID)
KeSetTimeIncrement(RtcClockRateToIncrement(RtcMaximumClockRate),
RtcClockRateToIncrement(RtcMinimumClockRate));
+ /* Enable the timer interrupt */
+ HalEnableSystemInterrupt(APIC_CLOCK_VECTOR, CLOCK_LEVEL, Latched);
DPRINT1("Clock initialized\n");
}