xref: /reactos/hal/halx86/generic/reboot.c (revision cc439606)
1 /*
2  * PROJECT:         ReactOS HAL
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            hal/halx86/generic/reboot.c
5  * PURPOSE:         Reboot functions
6  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
7  *                  Eric Kohl
8  */
9 
10 /* INCLUDES ******************************************************************/
11 
12 #include <hal.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* PRIVATE FUNCTIONS *********************************************************/
17 
18 VOID
19 NTAPI
20 HalpWriteResetCommand(VOID)
21 {
22     /* Generate RESET signal via keyboard controller */
23     WRITE_PORT_UCHAR((PUCHAR)0x64, 0xFE);
24 };
25 
26 VOID
27 NTAPI
28 HalpReboot(VOID)
29 {
30     PHYSICAL_ADDRESS PhysicalAddress;
31     UCHAR Data;
32     PVOID ZeroPageMapping;
33 
34     /* Map the first physical page */
35     PhysicalAddress.QuadPart = 0;
36     ZeroPageMapping = HalpMapPhysicalMemory64(PhysicalAddress, 1);
37 
38     /* Enable warm reboot */
39     ((PUSHORT)ZeroPageMapping)[0x239] = 0x1234;
40 
41     /* Lock CMOS Access (and disable interrupts) */
42     HalpAcquireCmosSpinLock();
43 
44     /* Setup control register B */
45     WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0B);
46     KeStallExecutionProcessor(1);
47 
48     /* Read periodic register and clear the interrupt enable */
49     Data = READ_PORT_UCHAR((PUCHAR)0x71);
50     WRITE_PORT_UCHAR((PUCHAR)0x71, Data & ~0x40);
51     KeStallExecutionProcessor(1);
52 
53     /* Setup control register A */
54     WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0A);
55     KeStallExecutionProcessor(1);
56 
57     /* Read divider rate and reset it */
58     Data = READ_PORT_UCHAR((PUCHAR)0x71);
59     WRITE_PORT_UCHAR((PUCHAR)0x71, (Data & ~0x9) | 0x06);
60     KeStallExecutionProcessor(1);
61 
62     /* Reset neutral CMOS address */
63     WRITE_PORT_UCHAR((PUCHAR)0x70, 0x15);
64     KeStallExecutionProcessor(1);
65 
66     /* Flush write buffers and send the reset command */
67     KeFlushWriteBuffer();
68     HalpWriteResetCommand();
69 
70     /* Halt the CPU */
71     __halt();
72 }
73 
74 /* PUBLIC FUNCTIONS **********************************************************/
75 
76 /*
77  * @implemented
78  */
79 VOID
80 NTAPI
81 HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
82 {
83     /* Check what kind of action this is */
84     switch (Action)
85     {
86         /* All recognized actions */
87         case HalHaltRoutine:
88         case HalRebootRoutine:
89 
90 #ifndef _MINIHAL_
91             /* Acquire the display */
92             InbvAcquireDisplayOwnership();
93 #endif
94 
95             /* Call the internal reboot function */
96             HalpReboot();
97 
98         /* Anything else */
99         default:
100 
101             /* Print message and break */
102             DbgPrint("HalReturnToFirmware called!\n");
103             DbgBreakPoint();
104     }
105 }
106 
107 /* EOF */
108