ReactOS  0.4.13-dev-650-g34bf247
misc.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Hardware Abstraction Layer (HAL)
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: hal/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 #if defined(ALLOC_PRAGMA) && !defined(_MINIHAL_)
16 #pragma alloc_text(INIT, HalpMarkAcpiHal)
17 #pragma alloc_text(INIT, HalpReportSerialNumber)
18 #endif
19 
20 /* GLOBALS *******************************************************************/
21 
23 
26 
27 /* PRIVATE FUNCTIONS **********************************************************/
28 
29 #ifndef _MINIHAL_
30 INIT_FUNCTION
31 VOID
32 NTAPI
34 {
36  UNICODE_STRING KeyString;
37  HANDLE Handle;
38 
39  /* Make sure there is a serial number */
40  if (!HalpSerialLen) return;
41 
42  /* Open the system key */
43  RtlInitUnicodeString(&KeyString, L"\\Registry\\Machine\\Hardware\\Description\\System");
45  if (NT_SUCCESS(Status))
46  {
47  /* Add the serial number */
48  RtlInitUnicodeString(&KeyString, L"Serial Number");
49  ZwSetValueKey(Handle,
50  &KeyString,
51  0,
52  REG_BINARY,
55 
56  /* Close the handle */
57  ZwClose(Handle);
58  }
59 }
60 
61 INIT_FUNCTION
63 NTAPI
65 {
67  UNICODE_STRING KeyString;
69  HANDLE Handle;
71 
72  /* Open the control set key */
73  RtlInitUnicodeString(&KeyString,
74  L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
76  if (NT_SUCCESS(Status))
77  {
78  /* Open the PNP key */
79  RtlInitUnicodeString(&KeyString, L"Control\\Pnp");
81  Handle,
82  &KeyString,
84  TRUE);
85  /* Close root key */
86  ZwClose(Handle);
87 
88  /* Check if PNP BIOS key exists */
89  if (NT_SUCCESS(Status))
90  {
91  /* Set the disable value to false -- we need the mapper */
92  RtlInitUnicodeString(&KeyString, L"DisableFirmwareMapper");
93  Status = ZwSetValueKey(KeyHandle,
94  &KeyString,
95  0,
96  REG_DWORD,
97  &Value,
98  sizeof(Value));
99 
100  /* Close subkey */
102  }
103  }
104 
105  /* Return status */
106  return Status;
107 }
108 
109 NTSTATUS
110 NTAPI
112  IN HANDLE RootKey,
115  IN BOOLEAN Create)
116 {
120 
121  /* Setup the attributes we received */
123  KeyName,
125  RootKey,
126  NULL);
127 
128  /* What to do? */
129  if ( Create )
130  {
131  /* Create the key */
132  Status = ZwCreateKey(KeyHandle,
135  0,
136  NULL,
138  &Disposition);
139  }
140  else
141  {
142  /* Open the key */
144  }
145 
146  /* We're done */
147  return Status;
148 }
149 #endif
150 
151 VOID
152 NTAPI
154 {
155  //
156  // Nothing to do on non-ACPI
157  //
158  return;
159 }
160 
161 VOID
162 NTAPI
164 {
165  ULONG_PTR Flags, Cr4;
166  INT CpuInfo[4];
167  ULONG_PTR PageDirectory;
168 
169  //
170  // Disable interrupts
171  //
172  Flags = __readeflags();
173  _disable();
174 
175  //
176  // Get page table directory base
177  //
178  PageDirectory = __readcr3();
179 
180  //
181  // Check for CPUID support
182  //
183  if (KeGetCurrentPrcb()->CpuID)
184  {
185  //
186  // Check for global bit in CPU features
187  //
188  __cpuid(CpuInfo, 1);
189  if (CpuInfo[3] & 0x2000)
190  {
191  //
192  // Get current CR4 value
193  //
194  Cr4 = __readcr4();
195 
196  //
197  // Disable global bit
198  //
199  __writecr4(Cr4 & ~CR4_PGE);
200 
201  //
202  // Flush TLB and re-enable global bit
203  //
204  __writecr3(PageDirectory);
205  __writecr4(Cr4);
206 
207  //
208  // Restore interrupts
209  //
211  return;
212  }
213  }
214 
215  //
216  // Legacy: just flush TLB
217  //
218  __writecr3(PageDirectory);
220 }
221 
222 /* FUNCTIONS *****************************************************************/
223 
224 /*
225  * @implemented
226  */
227 VOID
228 NTAPI
230 {
231 #ifndef _MINIHAL_
232  SYSTEM_CONTROL_PORT_B_REGISTER SystemControl;
233 
234  //
235  // Don't recurse
236  //
238 
239  //
240  // Read the system control register B
241  //
242  SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
243 
244  //
245  // Switch to boot vieo
246  //
248  {
249  //
250  // Acquire ownership
251  //
254 
255  //
256  // Fill the screen
257  //
258  InbvSolidColorFill(0, 0, 639, 479, 1);
259  InbvSetScrollRegion(0, 0, 639, 479);
260 
261  //
262  // Enable text
263  //
264  InbvSetTextColor(15);
267  }
268 
269  //
270  // Display NMI failure string
271  //
272  InbvDisplayString("\r\n*** Hardware Malfunction\r\n\r\n");
273  InbvDisplayString("Call your hardware vendor for support\r\n\r\n");
274 
275  //
276  // Check for parity error
277  //
278  if (SystemControl.ParityCheck)
279  {
280  //
281  // Display message
282  //
283  InbvDisplayString("NMI: Parity Check / Memory Parity Error\r\n");
284  }
285 
286  //
287  // Check for I/O failure
288  //
289  if (SystemControl.ChannelCheck)
290  {
291  //
292  // Display message
293  //
294  InbvDisplayString("NMI: Channel Check / IOCHK\r\n");
295  }
296 
297  //
298  // Check for EISA systems
299  //
301  {
302  //
303  // FIXME: Not supported
304  //
306  }
307 
308  //
309  // Halt the system
310  //
311  InbvDisplayString("\r\n*** The system has halted ***\r\n");
312 
313 
314  //
315  // Enter the debugger if possible
316  //
317  KiBugCheckData[0] = (ULONG_PTR)KeServiceDescriptorTable; /* NMI Corruption? */
318  //if (!(KdDebuggerNotPresent) && (KdDebuggerEnabled)) KeEnterKernelDebugger();
319 #endif
320  //
321  // Freeze the system
322  //
323  while (TRUE);
324 }
325 
326 /*
327  * @implemented
328  */
329 UCHAR
330 FASTCALL
332  OUT PKINTERRUPT_ROUTINE **FlatDispatch,
333  OUT PKINTERRUPT_ROUTINE *NoConnection)
334 {
335  //
336  // Not implemented on x86
337  //
338  return 0;
339 }
340 
341 /*
342  * @implemented
343  */
344 VOID
345 NTAPI
347 {
348  //
349  // Not implemented on x86
350  //
351  return;
352 }
353 
354 #ifdef _M_IX86
355 /* x86 fastcall wrappers */
356 
357 #undef KeRaiseIrql
358 /*
359  * @implemented
360  */
361 VOID
362 NTAPI
364  PKIRQL OldIrql)
365 {
366  /* Call the fastcall function */
368 }
369 
370 #undef KeLowerIrql
371 /*
372  * @implemented
373  */
374 VOID
375 NTAPI
377 {
378  /* Call the fastcall function */
380 }
381 
382 #undef KeAcquireSpinLock
383 /*
384  * @implemented
385  */
386 VOID
387 NTAPI
389  PKIRQL OldIrql)
390 {
391  /* Call the fastcall function */
393 }
394 
395 #undef KeReleaseSpinLock
396 /*
397  * @implemented
398  */
399 VOID
400 NTAPI
402  KIRQL NewIrql)
403 {
404  /* Call the fastcall function */
406 }
407 
408 #endif
409 
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1680
#define IN
Definition: typedefs.h:38
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
VOID NTAPI HalpCheckPowerButton(VOID)
Definition: misc.c:20
INIT_FUNCTION NTSTATUS NTAPI HalpMarkAcpiHal(VOID)
Definition: misc.c:64
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
static PMEMKEY RootKey
Definition: registry.c:55
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define REG_BINARY
Definition: nt_native.h:1496
VOID NTAPI HalpFlushTLB(VOID)
Definition: misc.c:163
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ BOOLEAN Create
Definition: pstypes.h:511
BOOLEAN NTAPI InbvDisplayString(IN PCHAR String)
Definition: inbv.c:552
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
VOID NTAPI InbvSolidColorFill(IN ULONG Left, IN ULONG Top, IN ULONG Right, IN ULONG Bottom, IN ULONG Color)
Definition: inbv.c:699
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1706
#define FASTCALL
Definition: nt_native.h:50
int32_t INT
Definition: typedefs.h:56
VOID NTAPI HalHandleNMI(IN PVOID NmiInfo)
Definition: misc.c:53
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define CR4_PGE
Definition: ketypes.h:91
UCHAR KIRQL
Definition: env_spec_w32.h:591
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1675
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define SYSTEM_CONTROL_PORT_B
Definition: halp.h:171
NTSTATUS NTAPI HalpOpenRegistryKey(IN PHANDLE KeyHandle, IN HANDLE RootKey, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN BOOLEAN Create)
Definition: misc.c:111
#define ERROR_DBGBREAK(...)
Definition: debug.h:221
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI InbvSetTextColor(IN ULONG Color)
Definition: inbv.c:675
VOID(NTAPI * PKINTERRUPT_ROUTINE)(VOID)
Definition: ketypes.h:490
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
_In_ HANDLE Handle
Definition: extypes.h:390
ULONG HalpBusType
Definition: bus.c:17
UCHAR HalpSerialLen
Definition: misc.c:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ULONG_PTR KiBugCheckData[5]
Definition: bug.c:30
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
UCHAR FASTCALL HalSystemVectorDispatchEntry(IN ULONG Vector, OUT PKINTERRUPT_ROUTINE **FlatDispatch, OUT PKINTERRUPT_ROUTINE *NoConnection)
Definition: misc.c:24
VOID NTAPI InbvAcquireDisplayOwnership(VOID)
Definition: inbv.c:511
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1550
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
BOOLEAN HalpNMIInProgress
Definition: misc.c:22
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1713
Status
Definition: gdiplustypes.h:24
VOID NTAPI KeFlushWriteBuffer(VOID)
Definition: misc.c:39
BOOLEAN NTAPI InbvEnableDisplayString(IN BOOLEAN Enable)
Definition: inbv.c:589
CHAR HalpSerialNumber[31]
Definition: misc.c:25
BOOLEAN HalDisableFirmwareMapper
Definition: halacpi.c:43
BOOLEAN NTAPI InbvIsBootDriverInstalled(VOID)
Definition: inbv.c:613
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
BOOLEAN NTAPI InbvResetDisplay(VOID)
Definition: inbv.c:647
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
VOID NTAPI InbvInstallDisplayStringFilter(IN INBV_DISPLAY_STRING_FILTER Filter)
Definition: inbv.c:605
#define OUT
Definition: typedefs.h:39
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNIMPLEMENTED
Definition: debug.h:114
#define ULONG_PTR
Definition: config.h:101
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
VOID NTAPI InbvSetScrollRegion(IN ULONG Left, IN ULONG Top, IN ULONG Right, IN ULONG Bottom)
Definition: inbv.c:664
#define REG_DWORD
Definition: sdbapi.c:596
ULONG ACCESS_MASK
Definition: nt_native.h:40
INIT_FUNCTION VOID NTAPI HalpReportSerialNumber(VOID)
Definition: misc.c:33
#define MACHINE_TYPE_EISA
Definition: ketypes.h:53
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
PPC_QUAL unsigned char __inbyte(const unsigned long Port)
Definition: intrin_ppc.h:539