- Stub out DbgKdWriteVirtualMemoryApi, DbgKdReadPhysicalMemoryApi, DbgKdWritePhysical...
[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 #define GetPteAddress(x) (PHARDWARE_PTE)(((((ULONG_PTR)(x)) >> 12) << 2) + 0xC0000000)
17
18 /* PRIVATE FUNCTIONS *********************************************************/
19
20 VOID
21 NTAPI
22 HalpWriteResetCommand(VOID)
23 {
24 /* Generate RESET signal via keyboard controller */
25 WRITE_PORT_UCHAR((PUCHAR)0x64, 0xFE);
26 };
27
28 VOID
29 NTAPI
30 HalpReboot(VOID)
31 {
32 UCHAR Data;
33 PVOID ZeroPageMapping;
34 PHARDWARE_PTE Pte;
35
36 /* Get a PTE in the HAL reserved region */
37 ZeroPageMapping = (PVOID)(0xFFC00000 + PAGE_SIZE);
38 Pte = GetPteAddress(ZeroPageMapping);
39
40 /* Make it valid and map it to the first physical page */
41 Pte->Valid = 1;
42 Pte->Write = 1;
43 Pte->Owner = 1;
44 Pte->PageFrameNumber = 0;
45
46 /* Flush the TLB by resetting CR3 */
47 __writecr3(__readcr3());
48
49 /* Enable warm reboot */
50 ((PUSHORT)ZeroPageMapping)[0x239] = 0x1234;
51
52 /* FIXME: Lock CMOS Access */
53
54 /* Disable interrupts */
55 _disable();
56
57 /* Setup control register B */
58 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0B);
59 KeStallExecutionProcessor(1);
60
61 /* Read periodic register and clear the interrupt enable */
62 Data = READ_PORT_UCHAR((PUCHAR)0x71);
63 WRITE_PORT_UCHAR((PUCHAR)0x71, Data & ~0x40);
64 KeStallExecutionProcessor(1);
65
66 /* Setup control register A */
67 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x0A);
68 KeStallExecutionProcessor(1);
69
70 /* Read divider rate and reset it */
71 Data = READ_PORT_UCHAR((PUCHAR)0x71);
72 WRITE_PORT_UCHAR((PUCHAR)0x71, (Data & ~0x9) | 0x06);
73 KeStallExecutionProcessor(1);
74
75 /* Reset neutral CMOS address */
76 WRITE_PORT_UCHAR((PUCHAR)0x70, 0x15);
77 KeStallExecutionProcessor(1);
78
79 /* Flush write buffers and send the reset command */
80 KeFlushWriteBuffer();
81 HalpWriteResetCommand();
82
83 /* Halt the CPU */
84 __halt();
85 }
86
87 /* PUBLIC FUNCTIONS **********************************************************/
88
89 /*
90 * @implemented
91 */
92 VOID
93 NTAPI
94 HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
95 {
96 /* Check what kind of action this is */
97 switch (Action)
98 {
99 /* All recognized actions */
100 case HalHaltRoutine:
101 case HalRebootRoutine:
102
103 /* Acquire the display */
104 InbvAcquireDisplayOwnership();
105
106 /* Call the internal reboot function */
107 HalpReboot();
108
109 /* Anything else */
110 default:
111
112 /* Print message and break */
113 DbgPrint("HalReturnToFirmware called!\n");
114 DbgBreakPoint();
115 }
116 }
117
118 /* EOF */