- Move NCI generated files to arch-specific directories
[reactos.git] / reactos / hal / halx86 / generic / reboot.c
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 (ekohl@abo.rhein-zeitung.de)
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <hal.h>
13 #define NDEBUG
14 #include <debug.h>
15
16 /* PRIVATE FUNCTIONS *********************************************************/
17
18 static VOID
19 NTAPI
20 HalpWriteResetCommand(VOID)
21 {
22 /* Generate RESET signal via keyboard controller */
23 WRITE_PORT_UCHAR((PUCHAR)0x64, 0xFE);
24 };
25
26 static VOID
27 NTAPI
28 HalpReboot(VOID)
29 {
30 UCHAR Data;
31 PVOID HalpZeroPageMapping;
32 PHYSICAL_ADDRESS Null = {{0}};
33
34 /* Enable warm reboot */
35 HalpZeroPageMapping = MmMapIoSpace(Null, PAGE_SIZE, MmNonCached);
36 ((PUSHORT)HalpZeroPageMapping)[0x239] = 0x1234;
37
38 /* FIXME: Lock CMOS Access */
39
40 /* Disable interrupts */
41 _disable();
42
43 /* Setup control register B */
44 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0B);
45 KeStallExecutionProcessor(1);
46
47 /* Read periodic register and clear the interrupt enable */
48 Data = READ_PORT_UCHAR((PUCHAR)0x71);
49 WRITE_PORT_UCHAR((PUCHAR)0x71, Data & ~0x40);
50 KeStallExecutionProcessor(1);
51
52 /* Setup control register A */
53 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0A);
54 KeStallExecutionProcessor(1);
55
56 /* Read divider rate and reset it */
57 Data = READ_PORT_UCHAR((PUCHAR)0x71);
58 WRITE_PORT_UCHAR((PUCHAR)0x71, (Data & ~0x9) | 0x06);
59 KeStallExecutionProcessor(1);
60
61 /* Reset neutral CMOS address */
62 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x15);
63 KeStallExecutionProcessor(1);
64
65 /* Flush write buffers and send the reset command */
66 KeFlushWriteBuffer();
67 HalpWriteResetCommand();
68
69 /* Halt the CPU */
70 Ke386HaltProcessor();
71 }
72
73 /* PUBLIC FUNCTIONS **********************************************************/
74
75 /*
76 * @implemented
77 */
78 VOID
79 NTAPI
80 HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
81 {
82 /* Check the kind of action this is */
83 switch (Action)
84 {
85 /* All recognized actions */
86 case HalHaltRoutine:
87 case HalRebootRoutine:
88
89 /* Call the internal reboot function */
90 HalpReboot();
91
92 /* Anything else */
93 default:
94
95 /* Print message and break */
96 DbgPrint("HalReturnToFirmware called!\n");
97 DbgBreakPoint();
98 }
99 }
100
101 /* EOF */