https://git.reactos.org/?p=reactos.git;a=commitdiff;h=17c5fb8866b012ec4011c0acbf089d041c33cda5

commit 17c5fb8866b012ec4011c0acbf089d041c33cda5
Author:     Dmitry Borisov <[email protected]>
AuthorDate: Wed Jun 3 05:14:16 2020 +0600
Commit:     GitHub <[email protected]>
CommitDate: Wed Jun 3 02:14:16 2020 +0300

    [HALXBOX] Fix clock drift (#2889)
    
    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        | 32 ++++++++++++++++++++++++++++++++
 hal/halx86/generic/timer.c        | 28 ++++------------------------
 hal/halx86/include/halp.h         |  6 ++++++
 hal/halx86/minihal/CMakeLists.txt |  1 +
 hal/halx86/pic.cmake              |  1 +
 hal/halx86/xbox.cmake             |  1 +
 hal/halx86/xbox/clock.c           | 31 +++++++++++++++++++++++++++++++
 7 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/hal/halx86/generic/clock.c b/hal/halx86/generic/clock.c
new file mode 100644
index 00000000000..e7b970a18c8
--- /dev/null
+++ b/hal/halx86/generic/clock.c
@@ -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 ([email protected])
+ *                  Timo Kreuzer ([email protected])
+ */
+
+/* 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 */
+};
diff --git a/hal/halx86/generic/timer.c b/hal/halx86/generic/timer.c
index 35606b96ece..c9fe80c16e2 100644
--- a/hal/halx86/generic/timer.c
+++ b/hal/halx86/generic/timer.c
@@ -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.
      *
diff --git a/hal/halx86/include/halp.h b/hal/halx86/include/halp.h
index 52b275e40df..cb6f6e58809 100644
--- a/hal/halx86/include/halp.h
+++ b/hal/halx86/include/halp.h
@@ -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);
diff --git a/hal/halx86/minihal/CMakeLists.txt 
b/hal/halx86/minihal/CMakeLists.txt
index eb80a8ea0a1..84bdf8fee25 100644
--- a/hal/halx86/minihal/CMakeLists.txt
+++ b/hal/halx86/minihal/CMakeLists.txt
@@ -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
diff --git a/hal/halx86/pic.cmake b/hal/halx86/pic.cmake
index 30737d20da9..40312d2273f 100644
--- a/hal/halx86/pic.cmake
+++ b/hal/halx86/pic.cmake
@@ -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
diff --git a/hal/halx86/xbox.cmake b/hal/halx86/xbox.cmake
index 4d16aaa4834..98f1d1d3d8a 100644
--- a/hal/halx86/xbox.cmake
+++ b/hal/halx86/xbox.cmake
@@ -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
index 00000000000..f8ebb97b121
--- /dev/null
+++ b/hal/halx86/xbox/clock.c
@@ -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 ([email protected])
+ */
+
+/* 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 */
+};

Reply via email to