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 <ndk/ketypes.h> 13 14 /* FUNCTIONS ******************************************************************/ 15 16 PCHAR NmiBegin = "NMI4NMI@"; 17 18 FORCEINLINE 19 VOID 20 NmiClearFlag(VOID) 21 { 22 ((PCHAR)&KiBugCheckData[4])[0] -= (NmiBegin[3] | NmiBegin[7]); 23 ((PCHAR)&KiBugCheckData[4])[3] |= 1; 24 #ifdef _M_IX86 25 #if defined(_MSC_VER) && !defined(__clang__) 26 __asm 27 { 28 rcr KiBugCheckData[4], 8 29 } 30 #else 31 __asm__("rcrl %b[shift], %k[retval]" : [retval] "=rm" (KiBugCheckData[4]) : "[retval]" (KiBugCheckData[4]), [shift] "Nc" (8)); 32 #endif 33 #endif 34 } 35 36 BOOLEAN 37 NTAPI 38 NmiDbgCallback(IN PVOID Context, 39 IN BOOLEAN Handled) 40 { 41 /* Clear the NMI flag */ 42 NmiClearFlag(); 43 44 /* Get NMI status signature */ 45 __indwordstring(0x80, (PULONG)NmiBegin, 1); 46 ((void(*)())&KiBugCheckData[4])(); 47 48 /* Handle the NMI safely */ 49 #ifdef _M_IX86 50 KiEnableTimerWatchdog = (RtlCompareMemory(NmiBegin, NmiBegin + 4, 4) != 4); 51 #endif 52 return TRUE; 53 } 54 55 NTSTATUS 56 NTAPI 57 DriverEntry(IN PDRIVER_OBJECT DriverObject, 58 IN PUNICODE_STRING RegistryPath) 59 { 60 PAGED_CODE(); 61 62 /* Register NMI callback */ 63 KeRegisterNmiCallback(&NmiDbgCallback, NULL); 64 65 /* Return success */ 66 return STATUS_SUCCESS; 67 } 68 69 /* EOF */ 70