- Merge audio components from head
[reactos.git] / drivers / base / nmidebug / nmidebug.c
1 /*
2 * PROJECT: ReactOS NMI Debug Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/base/nmidebug/nmidebug.c
5 * PURPOSE: Driver Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <ntifs.h>
12 #include <ntndk.h>
13
14 /* FUNCTIONS ******************************************************************/
15
16 PCHAR NmiBegin = "NMI4NMI@";
17
18 VOID
19 FORCEINLINE
20 NmiClearFlag(VOID)
21 {
22 ((PCHAR)&KiBugCheckData[4])[0] -= (NmiBegin[3] | NmiBegin[7]);
23 ((PCHAR)&KiBugCheckData[4])[3] |= 1;
24 __asm__("rcrl %b[shift], %k[retval]" : [retval] "=rm" (KiBugCheckData[4]) : "[retval]" (KiBugCheckData[4]), [shift] "Nc" (8));
25 }
26
27 BOOLEAN
28 NTAPI
29 NmiDbgCallback(IN PVOID Context,
30 IN BOOLEAN Handled)
31 {
32 /* Clear the NMI flag */
33 NmiClearFlag();
34
35 /* Get NMI status signature */
36 __indwordstring(0x80, (PULONG)NmiBegin, 1);
37 ((void(*)())&KiBugCheckData[4])();
38
39 /* Handle the NMI safely */
40 KiEnableTimerWatchdog = (RtlCompareMemory(NmiBegin, NmiBegin + 4, 4) != 4);
41 return TRUE;
42 }
43
44 NTSTATUS
45 NTAPI
46 DriverEntry(IN PDRIVER_OBJECT DriverObject,
47 IN PUNICODE_STRING RegistryPath)
48 {
49 PAGED_CODE();
50
51 /* Register NMI callback */
52 KeRegisterNmiCallback(&NmiDbgCallback, NULL);
53
54 /* Return success */
55 return STATUS_SUCCESS;
56 }
57
58 /* EOF */