[HAL]: Add Phase 0 HAL Heap Allocation/Mapping/Unmapping APIs, remove current broken...
[reactos.git] / reactos / 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 VOID
32 NTAPI
33 HalpFlushTLB(VOID)
34 {
35 ULONG Flags, Cr4;
36 INT CpuInfo[4];
37 ULONG_PTR PageDirectory;
38
39 //
40 // Disable interrupts
41 //
42 Flags = __readeflags();
43 _disable();
44
45 //
46 // Get page table directory base
47 //
48 PageDirectory = __readcr3();
49
50 //
51 // Check for CPUID support
52 //
53 if (KeGetCurrentPrcb()->CpuID)
54 {
55 //
56 // Check for global bit in CPU features
57 //
58 __cpuid(CpuInfo, 1);
59 if (CpuInfo[3] & 0x2000)
60 {
61 //
62 // Get current CR4 value
63 //
64 Cr4 = __readcr4();
65
66 //
67 // Disable global bit
68 //
69 __writecr4(Cr4 & ~CR4_PGE);
70
71 //
72 // Flush TLB and re-enable global bit
73 //
74 __writecr3(PageDirectory);
75 __writecr4(Cr4);
76
77 //
78 // Restore interrupts
79 //
80 __writeeflags(Flags);
81 return;
82 }
83 }
84
85 //
86 // Legacy: just flush TLB
87 //
88 __writecr3(PageDirectory);
89 __writeeflags(Flags);
90 }
91
92 /* FUNCTIONS *****************************************************************/
93
94 /*
95 * @implemented
96 */
97 VOID
98 NTAPI
99 HalHandleNMI(IN PVOID NmiInfo)
100 {
101 #ifndef _MINIHAL_
102 SYSTEM_CONTROL_PORT_B_REGISTER SystemControl;
103
104 //
105 // Don't recurse
106 //
107 if (HalpNMIInProgress++) while (TRUE);
108
109 //
110 // Read the system control register B
111 //
112 SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
113
114 //
115 // Switch to boot vieo
116 //
117 if (InbvIsBootDriverInstalled())
118 {
119 //
120 // Acquire ownership
121 //
122 InbvAcquireDisplayOwnership();
123 InbvResetDisplay();
124
125 //
126 // Fill the screen
127 //
128 InbvSolidColorFill(0, 0, 639, 479, 1);
129 InbvSetScrollRegion(0, 0, 639, 479);
130
131 //
132 // Enable text
133 //
134 InbvSetTextColor(15);
135 InbvInstallDisplayStringFilter(NULL);
136 InbvEnableDisplayString(TRUE);
137 }
138
139 //
140 // Display NMI failure string
141 //
142 InbvDisplayString("\n*** Hardware Malfunction\n\n");
143 InbvDisplayString("Call your hardware vendor for support\n\n");
144
145 //
146 // Check for parity error
147 //
148 if (SystemControl.ParityCheck)
149 {
150 //
151 // Display message
152 //
153 InbvDisplayString("NMI: Parity Check / Memory Parity Error\n");
154 }
155
156 //
157 // Check for I/O failure
158 //
159 if (SystemControl.ChannelCheck)
160 {
161 //
162 // Display message
163 //
164 InbvDisplayString("NMI: Channel Check / IOCHK\n");
165 }
166
167 //
168 // Check for EISA systems
169 //
170 if (HalpBusType == MACHINE_TYPE_EISA)
171 {
172 //
173 // FIXME: Not supported
174 //
175 UNIMPLEMENTED;
176 }
177
178 //
179 // Halt the system
180 //
181 InbvDisplayString("\n*** The system has halted ***\n");
182 #endif
183
184 //
185 // Enter the debugger if possible
186 //
187 //if (!(KdDebuggerNotPresent) && (KdDebuggerEnabled)) KeEnterKernelDebugger();
188
189 //
190 // Freeze the system
191 //
192 while (TRUE);
193 }
194
195 /*
196 * @implemented
197 */
198 UCHAR
199 FASTCALL
200 HalSystemVectorDispatchEntry(IN ULONG Vector,
201 OUT PKINTERRUPT_ROUTINE **FlatDispatch,
202 OUT PKINTERRUPT_ROUTINE *NoConnection)
203 {
204 //
205 // Not implemented on x86
206 //
207 return 0;
208 }
209
210 /*
211 * @implemented
212 */
213 VOID
214 NTAPI
215 KeFlushWriteBuffer(VOID)
216 {
217 //
218 // Not implemented on x86
219 //
220 return;
221 }
222
223 #ifdef _M_IX86
224 /* x86 fastcall wrappers */
225
226 #undef KeRaiseIrql
227 /*
228 * @implemented
229 */
230 VOID
231 NTAPI
232 KeRaiseIrql(KIRQL NewIrql,
233 PKIRQL OldIrql)
234 {
235 /* Call the fastcall function */
236 *OldIrql = KfRaiseIrql(NewIrql);
237 }
238
239 #undef KeLowerIrql
240 /*
241 * @implemented
242 */
243 VOID
244 NTAPI
245 KeLowerIrql(KIRQL NewIrql)
246 {
247 /* Call the fastcall function */
248 KfLowerIrql(NewIrql);
249 }
250
251 #undef KeAcquireSpinLock
252 /*
253 * @implemented
254 */
255 VOID
256 NTAPI
257 KeAcquireSpinLock(PKSPIN_LOCK SpinLock,
258 PKIRQL OldIrql)
259 {
260 /* Call the fastcall function */
261 *OldIrql = KfAcquireSpinLock(SpinLock);
262 }
263
264 #undef KeReleaseSpinLock
265 /*
266 * @implemented
267 */
268 VOID
269 NTAPI
270 KeReleaseSpinLock(PKSPIN_LOCK SpinLock,
271 KIRQL NewIrql)
272 {
273 /* Call the fastcall function */
274 KfReleaseSpinLock(SpinLock, NewIrql);
275 }
276
277 #endif
278