- Merge from trunk up to r45543
[reactos.git] / hal / halx86 / generic / misc.c
1 /*
2 * PROJECT: ReactOS Hardware Abstraction Layer (HAL)
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: halx86/generic/misc.c
5 * PURPOSE: NMI, I/O Mapping and x86 Subs
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <hal.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS *******************************************************************/
16
17 BOOLEAN HalpNMIInProgress;
18
19 /* PRIVATE FUNCTIONS **********************************************************/
20
21 VOID
22 NTAPI
23 HalpCheckPowerButton(VOID)
24 {
25 //
26 // Nothing to do on non-ACPI
27 //
28 return;
29 }
30
31 PVOID
32 NTAPI
33 HalpMapPhysicalMemory64(IN PHYSICAL_ADDRESS PhysicalAddress,
34 IN ULONG NumberPage)
35 {
36 //
37 // Use kernel memory manager I/O map facilities
38 //
39 return MmMapIoSpace(PhysicalAddress,
40 NumberPage << PAGE_SHIFT,
41 MmNonCached);
42 }
43
44 VOID
45 NTAPI
46 HalpUnmapVirtualAddress(IN PVOID VirtualAddress,
47 IN ULONG NumberPages)
48 {
49 //
50 // Use kernel memory manager I/O map facilities
51 //
52 MmUnmapIoSpace(VirtualAddress, NumberPages << PAGE_SHIFT);
53 }
54
55 VOID
56 NTAPI
57 HalpFlushTLB(VOID)
58 {
59 ULONG Flags, Cr4;
60 INT CpuInfo[4];
61 ULONG_PTR PageDirectory;
62
63 //
64 // Disable interrupts
65 //
66 Flags = __readeflags();
67 _disable();
68
69 //
70 // Get page table directory base
71 //
72 PageDirectory = __readcr3();
73
74 //
75 // Check for CPUID support
76 //
77 if (KeGetCurrentPrcb()->CpuID)
78 {
79 //
80 // Check for global bit in CPU features
81 //
82 __cpuid(CpuInfo, 1);
83 if (CpuInfo[3] & 0x2000)
84 {
85 //
86 // Get current CR4 value
87 //
88 Cr4 = __readcr4();
89
90 //
91 // Disable global bit
92 //
93 __writecr4(Cr4 & ~CR4_PGE);
94
95 //
96 // Flush TLB and re-enable global bit
97 //
98 __writecr3(PageDirectory);
99 __writecr4(Cr4);
100
101 //
102 // Restore interrupts
103 //
104 __writeeflags(Flags);
105 return;
106 }
107 }
108
109 //
110 // Legacy: just flush TLB
111 //
112 __writecr3(PageDirectory);
113 __writeeflags(Flags);
114 }
115
116 /* FUNCTIONS *****************************************************************/
117
118 /*
119 * @implemented
120 */
121 VOID
122 NTAPI
123 HalHandleNMI(IN PVOID NmiInfo)
124 {
125 SYSTEM_CONTROL_PORT_B_REGISTER SystemControl;
126
127 //
128 // Don't recurse
129 //
130 if (HalpNMIInProgress++) while (TRUE);
131
132 //
133 // Read the system control register B
134 //
135 SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
136
137 //
138 // Switch to boot vieo
139 //
140 if (InbvIsBootDriverInstalled())
141 {
142 //
143 // Acquire ownership
144 //
145 InbvAcquireDisplayOwnership();
146 InbvResetDisplay();
147
148 //
149 // Fill the screen
150 //
151 InbvSolidColorFill(0, 0, 639, 479, 1);
152 InbvSetScrollRegion(0, 0, 639, 479);
153
154 //
155 // Enable text
156 //
157 InbvSetTextColor(15);
158 InbvInstallDisplayStringFilter(NULL);
159 InbvEnableDisplayString(TRUE);
160 }
161
162 //
163 // Display NMI failure string
164 //
165 InbvDisplayString("\n*** Hardware Malfunction\n\n");
166 InbvDisplayString("Call your hardware vendor for support\n\n");
167
168 //
169 // Check for parity error
170 //
171 if (SystemControl.ParityCheck)
172 {
173 //
174 // Display message
175 //
176 InbvDisplayString("NMI: Parity Check / Memory Parity Error\n");
177 }
178
179 //
180 // Check for I/O failure
181 //
182 if (SystemControl.ChannelCheck)
183 {
184 //
185 // Display message
186 //
187 InbvDisplayString("NMI: Channel Check / IOCHK\n");
188 }
189
190 //
191 // Check for EISA systems
192 //
193 if (HalpBusType == MACHINE_TYPE_EISA)
194 {
195 //
196 // FIXME: Not supported
197 //
198 UNIMPLEMENTED;
199 }
200
201 //
202 // Halt the system
203 //
204 InbvDisplayString("\n*** The system has halted ***\n");
205
206 //
207 // Enter the debugger if possible
208 //
209 //if (!(KdDebuggerNotPresent) && (KdDebuggerEnabled)) KeEnterKernelDebugger();
210
211 //
212 // Freeze the system
213 //
214 while (TRUE);
215 }
216
217 /*
218 * @implemented
219 */
220 UCHAR
221 FASTCALL
222 HalSystemVectorDispatchEntry(IN ULONG Vector,
223 OUT PKINTERRUPT_ROUTINE **FlatDispatch,
224 OUT PKINTERRUPT_ROUTINE *NoConnection)
225 {
226 //
227 // Not implemented on x86
228 //
229 return 0;
230 }
231
232 /*
233 * @implemented
234 */
235 VOID
236 NTAPI
237 KeFlushWriteBuffer(VOID)
238 {
239 //
240 // Not implemented on x86
241 //
242 return;
243 }