- Finish the work around for the Pentium cmpxchg8b lock errata: We detected the errat...
[reactos.git] / reactos / hal / halx86 / generic / reboot.c
index bac0b41..fe822ac 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
+#define GetPteAddress(x) (PHARDWARE_PTE)(((((ULONG_PTR)(x)) >> 12) << 2) + 0xC0000000)
+
 /* PRIVATE FUNCTIONS *********************************************************/
 
-static VOID
+VOID
 NTAPI
 HalpWriteResetCommand(VOID)
 {
@@ -23,22 +25,32 @@ HalpWriteResetCommand(VOID)
     WRITE_PORT_UCHAR((PUCHAR)0x64, 0xFE);
 };
 
-static VOID
+VOID
 NTAPI
 HalpReboot(VOID)
 {
     UCHAR Data;
-    PVOID HalpZeroPageMapping;
-    PHYSICAL_ADDRESS Null = {{0}};
+    PVOID ZeroPageMapping;
+    PHARDWARE_PTE Pte;
 
-    /* Enable warm reboot */
-    HalpZeroPageMapping = MmMapIoSpace(Null, PAGE_SIZE, MmNonCached);
-    ((PUSHORT)HalpZeroPageMapping)[0x239] = 0x1234;
+    /* Get a PTE in the HAL reserved region */
+    ZeroPageMapping = (PVOID)(0xFFC00000 + PAGE_SIZE);
+    Pte = GetPteAddress(ZeroPageMapping);
 
-    /* FIXME: Lock CMOS Access */
+    /* Make it valid and map it to the first physical page */
+    Pte->Valid = 1;
+    Pte->Write = 1;
+    Pte->Owner = 1;
+    Pte->PageFrameNumber = 0;
 
-    /* Disable interrupts */
-    _disable();
+    /* Flush the TLB by resetting CR3 */
+    __writecr3(__readcr3());
+
+    /* Enable warm reboot */
+    ((PUSHORT)ZeroPageMapping)[0x239] = 0x1234;
+
+    /* Lock CMOS Access (and disable interrupts) */
+    HalpAcquireSystemHardwareSpinLock();
 
     /* Setup control register B */
     WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0B);
@@ -67,7 +79,7 @@ HalpReboot(VOID)
     HalpWriteResetCommand();
 
     /* Halt the CPU */
-    Ke386HaltProcessor();
+    __halt();
 }
 
 /* PUBLIC FUNCTIONS **********************************************************/
@@ -79,13 +91,16 @@ VOID
 NTAPI
 HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
 {
-    /* Check the kind of action this is */
+    /* Check what kind of action this is */
     switch (Action)
     {
         /* All recognized actions */
         case HalHaltRoutine:
         case HalRebootRoutine:
 
+            /* Acquire the display */
+            InbvAcquireDisplayOwnership();
+
             /* Call the internal reboot function */
             HalpReboot();