2003-08-11 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / ntoskrnl / ke / bug.c
index 145ee64..df3bc16 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: bug.c,v 1.23 2002/05/14 21:19:18 dwelch Exp $
+/* $Id: bug.c,v 1.35 2003/08/11 18:50:12 chorns Exp $
  *
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/bug.c
 
 /* INCLUDES *****************************************************************/
 
-#include <ddk/ntddk.h>
+#include <roskrnl.h>
+#include <ntos/bootvid.h>
+#include <internal/kd.h>
 #include <internal/ke.h>
 #include <internal/ps.h>
 
 #include <internal/debug.h>
 
+#include "../../hal/halx86/include/hal.h"
+
 /* GLOBALS ******************************************************************/
 
 static LIST_ENTRY BugcheckCallbackListHead = {NULL,NULL};
@@ -52,12 +56,19 @@ KeInitializeBugCheck(VOID)
   InBugCheck = 0;
 }
 
+/*
+ * @unimplemented
+ */
 BOOLEAN STDCALL
 KeDeregisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
 {
   UNIMPLEMENTED;
+  return FALSE;
 }
 
+/*
+ * @implemented
+ */
 BOOLEAN STDCALL
 KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
                           PKBUGCHECK_CALLBACK_ROUTINE  CallbackRoutine,
@@ -81,11 +92,77 @@ KeBugCheckWithTf(ULONG BugCheckCode,
                 ULONG BugCheckParameter4,
                 PKTRAP_FRAME Tf)
 {
-  DbgPrint("Bug detected code: 0x%X\n", BugCheckCode);
+  PRTL_MESSAGE_RESOURCE_ENTRY Message;
+  NTSTATUS Status;
+
+  /*
+   * The bug check may have happened while the bootscreen image was displayed.
+   * If this happened, switch back to text mode.
+   */
+  if (InbvIsBootDriverInstalled())
+    {
+      InbvEnableBootDriver(FALSE);
+    }
+
+  /* Make sure we're switching back to the blue screen and print messages on it */
+  HalReleaseDisplayOwnership();  
+  KdDebugState |= KD_DEBUG_SCREEN;
+
+  __asm__("cli\n\t");
+  DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
+          BugCheckCode,
+          BugCheckParameter1,
+          BugCheckParameter2,
+          BugCheckParameter3,
+          BugCheckParameter4);
+
+  Status = RtlFindMessage((PVOID)KERNEL_BASE, //0xC0000000,
+                         11, //RT_MESSAGETABLE,
+                         0x09, //0x409,
+                         BugCheckCode,
+                         &Message);
+  if (NT_SUCCESS(Status))
+    {
+      if (Message->Flags == 0)
+       DbgPrint("  %s\n", Message->Text);
+      else
+       DbgPrint("  %S\n", (PWSTR)Message->Text);
+    }
+  else
+    {
+      DbgPrint("  No message text found!\n\n");
+    }
+
+  if (InBugCheck == 1)
+    {
+      DbgPrint("Recursive bug check halting now\n");
+      for (;;)
+       {
+         __asm__ ("hlt\n\t");
+       }
+    }
+  InBugCheck = 1;
   KiDumpTrapFrame(Tf, BugCheckParameter1, BugCheckParameter2);
-  for(;;);
+  MmDumpToPagingFile(BugCheckCode, BugCheckParameter1, 
+                    BugCheckParameter2, BugCheckParameter3,
+                    BugCheckParameter4, Tf);
+
+  if (KdDebuggerEnabled)
+    {
+      __asm__("sti\n\t");
+      DbgBreakPoint();
+      __asm__("cli\n\t");
+    }
+
+  for (;;)
+    {
+      __asm__("hlt\n\t");
+    }
 }
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 KeBugCheckEx(ULONG BugCheckCode,
             ULONG BugCheckParameter1,
@@ -103,8 +180,20 @@ KeBugCheckEx(ULONG BugCheckCode,
 {
   PRTL_MESSAGE_RESOURCE_ENTRY Message;
   NTSTATUS Status;
+
+  /*
+   * The bug check may have happened while the bootscreen image was displayed.
+   * If this happened, switch back to text mode.
+   */
+  if (InbvIsBootDriverInstalled())
+    {
+      InbvEnableBootDriver(FALSE);
+    }
   
-  /* PJS: disable interrupts first, then do the rest */
+  /* Make sure we're switching back to the blue screen and print messages on it */
+  HalReleaseDisplayOwnership();  
+  KdDebugState |= KD_DEBUG_SCREEN;
+
   __asm__("cli\n\t");
   DbgPrint("Bug detected (code %x param %x %x %x %x)\n",
           BugCheckCode,
@@ -150,22 +239,27 @@ KeBugCheckEx(ULONG BugCheckCode,
               PsGetCurrentThread(),
               PsGetCurrentThread()->Cid.UniqueThread);
     }
-//   PsDumpThreads();
   KeDumpStackFrames((PULONG)__builtin_frame_address(0));
-  
+  MmDumpToPagingFile(BugCheckCode, BugCheckParameter1, 
+                    BugCheckParameter2, BugCheckParameter3,
+                    BugCheckParameter4, NULL);
+
   if (KdDebuggerEnabled)
     {
       __asm__("sti\n\t");
       DbgBreakPoint();
+      __asm__("cli\n\t");
     }
 
-  for(;;)
+  for (;;)
     {
-      /* PJS: use HLT instruction, rather than busy wait */
       __asm__("hlt\n\t");
     }
 }
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 KeBugCheck(ULONG BugCheckCode)
 /*