[HALXBOX] Fix clock drift (#2889)
authorDmitry Borisov <di.sean@protonmail.com>
Tue, 2 Jun 2020 23:14:16 +0000 (05:14 +0600)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 23:14:16 +0000 (02:14 +0300)
Add a new rollover table for Original Xbox (base frequency is 1.125000 MHz).
This fixes potential time issues in kernel and drivers.

CORE-16216

hal/halx86/generic/clock.c [new file with mode: 0644]
hal/halx86/generic/timer.c
hal/halx86/include/halp.h
hal/halx86/minihal/CMakeLists.txt
hal/halx86/pic.cmake
hal/halx86/xbox.cmake
hal/halx86/xbox/clock.c [new file with mode: 0644]

diff --git a/hal/halx86/generic/clock.c b/hal/halx86/generic/clock.c
new file mode 100644 (file)
index 0000000..e7b970a
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * PROJECT:         ReactOS Hardware Abstraction Layer
+ * LICENSE:         GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:         PIT rollover table
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
+ *                  Timo Kreuzer (timo.kreuzer@reactos.org)
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <hal.h>
+
+/* GLOBALS *******************************************************************/
+
+HALP_ROLLOVER HalpRolloverTable[15] =
+{
+    {1197, 10032}, /* 1 ms */
+    {2394, 20064},
+    {3591, 30096},
+    {4767, 39952},
+    {5964, 49984},
+    {7161, 60016},
+    {8358, 70048},
+    {9555, 80080},
+    {10731, 89936},
+    {11949, 100144},
+    {13125, 110000},
+    {14322, 120032},
+    {15519, 130064},
+    {16695, 139920},
+    {17892, 149952} /* 15 ms */
+};
index 35606b9..c9fe80c 100644 (file)
@@ -10,6 +10,7 @@
 /* INCLUDES ******************************************************************/
 
 #include <hal.h>
+
 #define NDEBUG
 #include <debug.h>
 
@@ -21,6 +22,8 @@
 
 #define PIT_LATCH  0x00
 
+extern HALP_ROLLOVER HalpRolloverTable[15];
+
 LARGE_INTEGER HalpLastPerfCounter;
 LARGE_INTEGER HalpPerfCounter;
 ULONG HalpPerfCounterCutoff;
@@ -30,29 +33,6 @@ ULONG HalpCurrentRollOver;
 ULONG HalpNextMSRate = 14;
 ULONG HalpLargestClockMS = 15;
 
-static struct _HALP_ROLLOVER
-{
-    ULONG RollOver;
-    ULONG Increment;
-} HalpRolloverTable[15] =
-{
-    {1197, 10032},
-    {2394, 20064},
-    {3591, 30096},
-    {4767, 39952},
-    {5964, 49984},
-    {7161, 60016},
-    {8358, 70048},
-    {9555, 80080},
-    {10731, 89936},
-    {11949, 100144},
-    {13125, 110000},
-    {14322, 120032},
-    {15519, 130064},
-    {16695, 139920},
-    {17892, 149952}
-};
-
 /* PRIVATE FUNCTIONS *********************************************************/
 
 FORCEINLINE
@@ -88,7 +68,7 @@ HalpSetTimerRollOver(USHORT RollOver)
     TimerControl.BcdMode = FALSE;
 
     /*
-     * Program the PIT to generate a normal rate wave (Mode 3) on channel 0.
+     * Program the PIT to generate a normal rate wave (Mode 2) on channel 0.
      * Channel 0 is used for the IRQ0 clock interval timer, and channel
      * 1 is used for DRAM refresh.
      *
index 52b275e..cb6f6e5 100644 (file)
@@ -223,6 +223,12 @@ INIT_FUNCTION VOID NTAPI HalpInitializeClock(VOID);
 VOID __cdecl HalpClockInterrupt(VOID);
 VOID __cdecl HalpProfileInterrupt(VOID);
 
+typedef struct _HALP_ROLLOVER
+{
+    ULONG RollOver;
+    ULONG Increment;
+} HALP_ROLLOVER, *PHALP_ROLLOVER;
+
 VOID
 NTAPI
 HalpCalibrateStallExecution(VOID);
index eb80a8e..84bdf8f 100644 (file)
@@ -9,6 +9,7 @@ list(APPEND MINI_HAL_SOURCE
     ../legacy/bussupp.c
     ../generic/beep.c
     ../generic/bios.c
+    ../generic/clock.c
     ../generic/cmos.c
     ../generic/dma.c
     ../generic/display.c
index 30737d2..40312d2 100644 (file)
@@ -5,6 +5,7 @@ list(APPEND HAL_PIC_ASM_SOURCE
     up/pic.S)
 
 list(APPEND HAL_PIC_SOURCE
+    generic/clock.c
     generic/profil.c
     generic/timer.c
     up/halinit_up.c
index 4d16aaa..98f1d1d 100644 (file)
@@ -31,6 +31,7 @@ list(APPEND HAL_XBOX_SOURCE
     legacy/halpcat.c
     generic/profil.c
     generic/timer.c
+    xbox/clock.c
     xbox/part_xbox.c
     xbox/halinit_xbox.c
     xbox/reboot.c
diff --git a/hal/halx86/xbox/clock.c b/hal/halx86/xbox/clock.c
new file mode 100644 (file)
index 0000000..f8ebb97
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * PROJECT:     Xbox HAL
+ * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE:     PIT rollover table
+ * COPYRIGHT:   Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <hal.h>
+
+/* GLOBALS *******************************************************************/
+
+HALP_ROLLOVER HalpRolloverTable[15] =
+{
+    {1125, 10000}, /* 1 ms */
+    {2250, 20000},
+    {3375, 30000},
+    {4500, 40000},
+    {5625, 50000},
+    {6750, 60000},
+    {7875, 70000},
+    {9000, 80000},
+    {10125, 90000},
+    {11250, 100000},
+    {12375, 110000},
+    {13500, 120000},
+    {14625, 130000},
+    {15750, 140000},
+    {16875, 150000} /* 15 ms */
+};