KD System Rewrite:

    - Totally dynamic based on the principle of Native Providers built-in the Kernel (like Screen, 
      FileLog and Serial) and a pluggable Wrapper which is optionally compiled (Bochs, GDB)
    - Nothing changed in KDBG, except for that its settings (KDSERIAL/KDNOECHO) are now stored in
      KdbDebugState instead.
    - Wrappers are currently built uncondtionally. With rbuild, I'll make them easily removable.
    - Debug Log code simplified greatly, sped up and now supports printing even the first boot messages,
      which wasn't supported before.
    - Removed most of KDBG compile-time settings, ones which are needed are in include/dbg as macros now.
    - Left in some kdbg init code and break code, but it could be made to be used as a 'wrapper' for those
      functions. I will do it later.
    - Made a hack for KdpEnterDebuggerException..it seems to be called differently and at different times
      for GDB vs KDBG and I couldn't unite them.
    - KdpServiceDispatcher now does both the documented and ros-internal debug functions and will eventually
      be called through INT2D from keyboard.sys instead of as an API.

All in all, this patch makes KD  separated from KDBG and creates a pluggable architecture for creating future wrappers that don't require changing tons of code in the future. It improves the debug
log by printing even the earliest debug messages to it and it removes many of the manual ifdef(KDBG) but making them automatic though a single macro file. It makes extra debugging functionality optional and it
allows removal of a private API from our exports.
Modified: trunk/reactos/drivers/input/keyboard/keyboard.c
Modified: trunk/reactos/include/ddk/kefuncs.h
Modified: trunk/reactos/ntoskrnl/Makefile
Modified: trunk/reactos/ntoskrnl/ex/init.c
Modified: trunk/reactos/ntoskrnl/include/internal/dbg.h
Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
Modified: trunk/reactos/ntoskrnl/include/internal/kdb.h
Added: trunk/reactos/ntoskrnl/include/internal/kdbochs.h
Added: trunk/reactos/ntoskrnl/include/internal/kdgdb.h
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
Modified: trunk/reactos/ntoskrnl/include/internal/module.h
Modified: trunk/reactos/ntoskrnl/include/ntoskrnl.h
Modified: trunk/reactos/ntoskrnl/io/iomgr.c
Modified: trunk/reactos/ntoskrnl/io/pnpreport.c
Deleted: trunk/reactos/ntoskrnl/kd/dlog.c
Deleted: trunk/reactos/ntoskrnl/kd/gdbstub.c
Deleted: trunk/reactos/ntoskrnl/kd/kdebug.c
Added: trunk/reactos/ntoskrnl/kd/kdinit.c
Added: trunk/reactos/ntoskrnl/kd/kdio.c
Added: trunk/reactos/ntoskrnl/kd/kdmain.c
Modified: trunk/reactos/ntoskrnl/kd/service.c
Added: trunk/reactos/ntoskrnl/kd/wrappers/
Added: trunk/reactos/ntoskrnl/kd/wrappers/bochs.c
Added: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
Modified: trunk/reactos/ntoskrnl/kdbg/kdb.c
Modified: trunk/reactos/ntoskrnl/kdbg/kdb_cli.c
Modified: trunk/reactos/ntoskrnl/kdbg/kdb_serial.c
Modified: trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c
Modified: trunk/reactos/ntoskrnl/ke/bug.c
Modified: trunk/reactos/ntoskrnl/ke/catch.c
Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c
Modified: trunk/reactos/ntoskrnl/ke/i386/irq.c
Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
Modified: trunk/reactos/ntoskrnl/ldr/loader.c
Modified: trunk/reactos/ntoskrnl/mm/RPoolMgr.h
Modified: trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/ntoskrnl.def

Modified: trunk/reactos/drivers/input/keyboard/keyboard.c
--- trunk/reactos/drivers/input/keyboard/keyboard.c	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/drivers/input/keyboard/keyboard.c	2005-04-25 14:44:48 UTC (rev 14799)
@@ -114,7 +114,7 @@
 };
 
 VOID STDCALL
-KdSystemDebugControl(ULONG Code);
+KdpServiceDispatcher(ULONG Code, PVOID Context1, PVOID Context2);
 
 static LONG DoSystemDebug = -1;
 static BOOLEAN InSysRq = FALSE;
@@ -421,7 +421,7 @@
    Debug = InterlockedExchange(&DoSystemDebug, -1);
    if (Debug != -1)
      {
-       KdSystemDebugControl(Debug);
+       KdpServiceDispatcher(TAG('R', 'o', 's', ' '), (PVOID)Debug, NULL);
      }
 }
 
@@ -447,7 +447,7 @@
          }
        else
          {
-           KdSystemDebugControl(DoSystemDebug);
+           KdpServiceDispatcher(TAG('R', 'o', 's', ' '), (PVOID)DoSystemDebug, NULL);
            DoSystemDebug = -1;
          }
        return;

Modified: trunk/reactos/include/ddk/kefuncs.h
--- trunk/reactos/include/ddk/kefuncs.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/include/ddk/kefuncs.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -22,6 +22,10 @@
 
 VOID STDCALL KeAttachProcess(struct _KPROCESS *Process);
 
+BOOLEAN
+STDCALL
+KeIsAttachedProcess(VOID);
+
 VOID FASTCALL KiAcquireSpinLock(PKSPIN_LOCK SpinLock);
 
 VOID FASTCALL KiReleaseSpinLock(PKSPIN_LOCK SpinLock);
@@ -379,9 +383,6 @@
 ULONG STDCALL
 KeRosGetStackFrames ( PULONG Frames, ULONG FrameCount );
 
-BOOLEAN STDCALL
-KeRosPrintAddress(PVOID address);
-
 NTSTATUS STDCALL
 KeSetAffinityThread(PKTHREAD	Thread,
 		    KAFFINITY	Affinity);

Modified: trunk/reactos/ntoskrnl/Makefile
--- trunk/reactos/ntoskrnl/Makefile	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/Makefile	2005-04-25 14:44:48 UTC (rev 14799)
@@ -329,11 +329,13 @@
 
 # Kernel Debugger Support (Kd)
 OBJECTS_KD = \
-	kd/dlog.o \
-	kd/gdbstub.o \
-	kd/kdebug.o \
-	kd/service.o
-	
+	kd/kdinit.o \
+	kd/kdmain.o \
+	kd/kdio.o \
+	kd/service.o \
+	kd/wrappers/gdbstub.o \
+	kd/wrappers/bochs.o
+
 # User-Mode Debugging (Dbgk)
 OBJECTS_DBGK = \
 	dbgk/dbgkutil.o \

Modified: trunk/reactos/ntoskrnl/ex/init.c
--- trunk/reactos/ntoskrnl/ex/init.c	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/ex/init.c	2005-04-25 14:44:48 UTC (rev 14799)
@@ -11,7 +11,6 @@
 
 #include <ntoskrnl.h>
 #include <ntos/bootvid.h>
-#include <internal/kdb.h>
 #define NDEBUG
 #include <internal/debug.h>
 
@@ -416,8 +415,8 @@
     /* Parse the Loaded Modules (by FreeLoader) and cache the ones we'll need */
     ParseAndCacheLoadedModules(&SetupBoot);
     
-    /* Initialize the kernel debugger */
-    KdInitSystem (1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
+    /* Initialize the kernel debugger parameters */
+    KdInitSystem(0, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
     
     /* Initialize the Dispatcher, Clock and Bug Check Mechanisms. */
     KeInit2();
@@ -489,8 +488,8 @@
     /* initialize callbacks */
     ExpInitializeCallbacks();
     
-    /* Initialize the GDB Stub and break */
-    KdInit1();
+    /* Call KD Providers at Phase 1 */
+    KdInitSystem(1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
   
     /* Initialize I/O Objects, Filesystems, Error Logging and Shutdown */
     IoInit();
@@ -506,9 +505,6 @@
   
     /* Initialize Cache Views */
     CcInit();
-  
-    /* Hook System Interrupt for the Debugger */
-    KdInit2();
     
     /* Initialize File Locking */
     FsRtlpInitFileLockingImplementation();
@@ -537,8 +533,8 @@
             (KeLoaderBlock.MemHigher + 1088)/ 1024);
     HalDisplayString(str);
 
-    /* Print which Debugger is being used */
-    KdInit3();
+    /* Call KD Providers at Phase 2 */
+    KdInitSystem(2, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
 
     /* Import and create NLS Data and Sections */
     RtlpInitNls();
@@ -549,10 +545,8 @@
     /* Initialize the time zone information from the registry */
     ExpInitTimeZoneInfo();
    
-  /* Enter the kernel debugger before starting up the boot drivers */
-#ifdef KDBG
+   /* Enter the kernel debugger before starting up the boot drivers */
     KdbEnter();
-#endif /* KDBG */
 
     /* Setup Drivers and Root Device Node */
     IoInit2(BootLog);

Modified: trunk/reactos/ntoskrnl/include/internal/dbg.h
--- trunk/reactos/ntoskrnl/include/internal/dbg.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/dbg.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -6,9 +6,35 @@
 
 #define KdPrintEx(_x_) DbgPrintEx _x_
 
-NTSTATUS STDCALL 
-LpcSendDebugMessagePort(PEPORT Port,
-			PLPC_DBG_MESSAGE Message,
-			PLPC_DBG_MESSAGE Reply);
+#if defined(KDBG) || defined(DBG)
+# define KDB_LOADUSERMODULE_HOOK(LDRMOD)	KdbSymLoadUserModuleSymbols(LDRMOD)
+# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE)	KdbSymLoadDriverSymbols(FILENAME, MODULE)
+# define KDB_UNLOADDRIVER_HOOK(MODULE)		KdbSymUnloadDriverSymbols(MODULE)
+# define KDB_LOADERINIT_HOOK(NTOS, HAL)		KdbSymInit(NTOS, HAL)
+# define KDB_SYMBOLFILE_HOOK(FILENAME)		KdbSymProcessBootSymbols(FILENAME)
+# define KDB_DELETEPROCESS_HOOK(PROCESS)	KdbDeleteProcessHook(PROCESS)
+#else
+# define KDB_LOADUSERMODULE_HOOK(LDRMOD)	do { } while (0)
+# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE)	do { } while (0)
+# define KDB_UNLOADDRIVER_HOOK(MODULE)		do { } while (0)
+# define KDB_LOADERINIT_HOOK(NTOS, HAL)		do { } while (0)
+# define KDB_SYMBOLFILE_HOOK(FILENAME)		do { } while (0)
+# define KDB_CREATE_THREAD_HOOK(CONTEXT)	do { } while (0)
+# define KDB_DELETEPROCESS_HOOK(PROCESS)	do { } while (0)
+#endif
 
+#ifdef KDBG
+# define KeRosPrintAddress(ADDRESS)         KdbSymPrintAddress(ADDRESS)
+# define KdbInit()                          KdbpCliInit()
+# define KdbModuleLoaded(FILENAME)          KdbpCliModuleLoaded(FILENAME)
+//# define KdbBreak()                         KdbBreak()
+#else
+# define KeRosPrintAddress(ADDRESS)         KiRosPrintAddress(ADDRESS)
+# define KdbEnterDebuggerException(ER, PM, C, TF, F)  kdHandleException
+# define KdbInit()                          do { } while (0)
+# define KdbEnter()                         do { } while (0)
+# define KdbModuleLoaded(X)                 do { } while (0)
+//# define KdbBreak()                         do { } while (0)
+#endif
+
 #endif /* __INCLUDE_INTERNAL_DBG_H */

Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
--- trunk/reactos/ntoskrnl/include/internal/kd.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/kd.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -10,160 +10,169 @@
 #include <internal/ldr.h>
 #include <ntdll/ldr.h>
 
-#define KD_DEBUG_DISABLED	0x00
-#define KD_DEBUG_GDB		0x01
-#define KD_DEBUG_PICE		0x02
-#define KD_DEBUG_SCREEN		0x04
-#define KD_DEBUG_SERIAL		0x08
-#define KD_DEBUG_BOCHS		0x10
-#define KD_DEBUG_FILELOG	0x20
-#define KD_DEBUG_MDA            0x40
-#define KD_DEBUG_KDB            0x80
-#define KD_DEBUG_KDSERIAL       0x100
-#define KD_DEBUG_KDNOECHO       0x200
+struct _KD_DISPATCH_TABLE;
 
-extern ULONG KdDebugState;
+#ifdef GDB
+#include "kdgdb.h"
+#endif
+#ifdef BOCHS
+#include "kdbochs.h"
+#endif
 
-KD_PORT_INFORMATION GdbPortInfo;
-KD_PORT_INFORMATION LogPortInfo;
+/* KD ROUTINES ***************************************************************/
 
 typedef enum _KD_CONTINUE_TYPE
 {
-  kdContinue = 0,
-  kdDoNotHandleException,
-  kdHandleException
+    kdContinue = 0,
+    kdDoNotHandleException,
+    kdHandleException
 } KD_CONTINUE_TYPE;
 
+typedef
 VOID
-KbdDisableMouse();
+STDCALL
+(*PKDP_INIT_ROUTINE)(struct _KD_DISPATCH_TABLE *DispatchTable,
+                     ULONG BootPhase);
 
+typedef
 VOID
-KbdEnableMouse();
-
-ULONG
-KdpPrintString (PANSI_STRING String);
-
-VOID
-DebugLogWrite(PCH String);
-VOID
-DebugLogInit(VOID);
-VOID
-DebugLogInit2(VOID);
-
-VOID
 STDCALL
-KdDisableDebugger(
-    VOID
-    );
+(*PKDP_PRINT_ROUTINE)(PCH String);
 
+typedef
 VOID
 STDCALL
-KdEnableDebugger(
-    VOID
-    );
+(*PKDP_PROMPT_ROUTINE)(PCH String);
 
-NTSTATUS
+typedef
+KD_CONTINUE_TYPE
 STDCALL
-KdPowerTransition(
-	ULONG PowerState
-	);
+(*PKDP_EXCEPTION_ROUTINE)(PEXCEPTION_RECORD ExceptionRecord,
+                          PCONTEXT Context,
+                          PKTRAP_FRAME TrapFrame);
 
-BOOLEAN
-STDCALL
-KeIsAttachedProcess(
-	VOID
-	);
+/* INIT ROUTINES *************************************************************/
 
 VOID
-KdInit1(VOID);
-
+STDCALL
+KdpScreenInit(struct _KD_DISPATCH_TABLE *DispatchTable,
+              ULONG BootPhase);
+              
 VOID
-KdInit2(VOID);
-
+STDCALL
+KdpSerialInit(struct _KD_DISPATCH_TABLE *DispatchTable,
+              ULONG BootPhase);
+              
 VOID
-KdInit3(VOID);
+STDCALL
+KdpInitDebugLog(struct _KD_DISPATCH_TABLE *DispatchTable,
+                ULONG BootPhase);
+                
+/* KD ROUTINES ***************************************************************/
 
-VOID
-KdPutChar(UCHAR Value);
-
-UCHAR
-KdGetChar(VOID);
-
-VOID
-KdGdbStubInit(ULONG Phase);
-
-VOID
-KdGdbDebugPrint (LPSTR Message);
-
-VOID
-KdDebugPrint (LPSTR Message);
-
 KD_CONTINUE_TYPE
-KdEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
-			 PCONTEXT Context,
-			 PKTRAP_FRAME TrapFrame);
-VOID KdInitializeMda(VOID);
-VOID KdPrintMda(PCH pch);
+STDCALL
+KdpEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
+                          KPROCESSOR_MODE PreviousMode,
+                          PCONTEXT Context,
+                          PKTRAP_FRAME TrapFrame,
+                          BOOLEAN FirstChance,
+                          BOOLEAN Gdb);
+                          
+ULONG
+STDCALL
+KdpPrintString(PANSI_STRING String);
 
-#if !defined(KDBG) && !defined(DBG)
-# define KDB_LOADUSERMODULE_HOOK(LDRMOD)	do { } while (0)
-# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE)	do { } while (0)
-# define KDB_UNLOADDRIVER_HOOK(MODULE)		do { } while (0)
-# define KDB_LOADERINIT_HOOK(NTOS, HAL)		do { } while (0)
-# define KDB_SYMBOLFILE_HOOK(FILENAME)		do { } while (0)
-# define KDB_CREATE_THREAD_HOOK(CONTEXT)	do { } while (0)
-#else
-# define KDB_LOADUSERMODULE_HOOK(LDRMOD)	KdbSymLoadUserModuleSymbols(LDRMOD)
-# define KDB_LOADDRIVER_HOOK(FILENAME, MODULE)	KdbSymLoadDriverSymbols(FILENAME, MODULE)
-# define KDB_UNLOADDRIVER_HOOK(MODULE)		KdbSymUnloadDriverSymbols(MODULE)
-# define KDB_LOADERINIT_HOOK(NTOS, HAL)		KdbSymInit(NTOS, HAL)
-# define KDB_SYMBOLFILE_HOOK(FILENAME)		KdbSymProcessBootSymbols(FILENAME)
-/*#define KDB_CREATE_THREAD_HOOK(CONTEXT) \
-        KdbCreateThreadHook(CONTEXT)
-*/
+BOOLEAN
+STDCALL
+KdpDetectConflicts(PCM_RESOURCE_LIST DriverList);
+              
+/* KD GLOBALS  ***************************************************************/
 
-VOID
-KdbSymLoadUserModuleSymbols(IN PLDR_MODULE LdrModule);
+/* serial debug connection */
+#define DEFAULT_DEBUG_PORT      2 /* COM2 */
+#define DEFAULT_DEBUG_COM1_IRQ  4 /* COM1 IRQ */
+#define DEFAULT_DEBUG_COM2_IRQ  3 /* COM2 IRQ */
+#define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */
 
-VOID
-KdbSymFreeProcessSymbols(IN PEPROCESS Process);
+/* KD Native Modes */
+#define KdScreen 0
+#define KdSerial 1
+#define KdFile 2
+#define KdMax 3
 
-VOID
-KdbSymLoadDriverSymbols(IN PUNICODE_STRING Filename,
-                        IN PMODULE_OBJECT Module);
+/* KD Private Debug Modes */
+typedef struct _KDP_DEBUG_MODE
+{
+    union {
+        struct {
+            /* Native Modes */
+            UCHAR Screen :1;
+            UCHAR Serial :1;
+            UCHAR File   :1;
+    
+            /* Currently Supported Wrappers */
+            UCHAR Pice   :1;
+            UCHAR Gdb    :1;
+            UCHAR Bochs  :1;
+        };
+        
+        /* Generic Value */
+        ULONG Value;
+    };
+} KDP_DEBUG_MODE;
 
-VOID
-KdbSymUnloadDriverSymbols(IN PMODULE_OBJECT ModuleObject);
+/* KD Internal Debug Services */
+typedef enum _KDP_DEBUG_SERVICE
+{
+    DumpNonPagedPool = 0,
+    ManualBugCheck,
+    DumpNonPagedPoolStats,
+    DumpNewNonPagedPool,
+    DumpNewNonPagedPoolStats,
+    DumpAllThreads,
+    DumpUserThreads,
+    KdSpare1,
+    KdSpare2,
+    KdSpare3,
+    EnterDebugger
+} KDP_DEBUG_SERVICE;
 
-VOID
-KdbSymProcessBootSymbols(IN PCHAR FileName);
+/* Dispatch Table for Wrapper Functions */
+typedef struct _KD_DISPATCH_TABLE
+{
+    LIST_ENTRY KdProvidersList;
+    PKDP_INIT_ROUTINE KdpInitRoutine;
+    PKDP_PRINT_ROUTINE KdpPrintRoutine;
+    PKDP_PROMPT_ROUTINE KdpPromptRoutine;  
+    PKDP_EXCEPTION_ROUTINE KdpExceptionRoutine;
+} KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE;
 
-VOID
-KdbSymInit(IN PMODULE_TEXT_SECTION NtoskrnlTextSection,
-           IN PMODULE_TEXT_SECTION LdrHalTextSection);
+/* The current Debugging Mode */
+extern KDP_DEBUG_MODE KdpDebugMode;
 
+/* The current Port IRQ */
+extern ULONG KdpPortIrq;
 
-BOOLEAN 
-KdbSymPrintAddress(IN PVOID Address);
+/* The current Port */
+extern ULONG KdpPort;
 
-KD_CONTINUE_TYPE
-KdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
-			  KPROCESSOR_MODE PreviousMode,
-                          PCONTEXT Context,
-                          PKTRAP_FRAME TrapFrame,
-			  BOOLEAN FirstChance);
+/* Port Information for the Serial Native Mode */
+extern KD_PORT_INFORMATION SerialPortInfo;
 
-#endif /* KDBG || DBG */
+/* Init Functions for Native Providers */
+extern PKDP_INIT_ROUTINE InitRoutines[KdMax];
 
-#if !defined(KDBG)
-# define KDB_DELETEPROCESS_HOOK(PROCESS)	do { } while (0)
-#else
-# define KDB_DELETEPROCESS_HOOK(PROCESS)	KdbDeleteProcessHook(PROCESS)
-VOID
-KdbDeleteProcessHook(IN PEPROCESS Process);
-#endif /* KDBG */
+/* Wrapper Init Function */
+extern PKDP_INIT_ROUTINE WrapperInitRoutine;
+                                                        
+/* Dispatch Tables for Native Providers */
+extern KD_DISPATCH_TABLE DispatchTable[KdMax];
 
-VOID
-DebugLogDumpMessages(VOID);
+/* Dispatch Table for the Wrapper */
+extern KD_DISPATCH_TABLE WrapperTable;
+                                     
+/* The KD Native Provider List */
+extern LIST_ENTRY KdProviders;
 
 #endif /* __INCLUDE_INTERNAL_KERNEL_DEBUGGER_H */

Modified: trunk/reactos/ntoskrnl/include/internal/kdb.h
--- trunk/reactos/ntoskrnl/include/internal/kdb.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/kdb.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -16,7 +16,6 @@
 # define RTL_NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
 #endif
 
-
 /* TYPES *********************************************************************/
 
 /* from kdb.c */
@@ -75,6 +74,11 @@
    KdbEnterFromUmode
 } KDB_ENTER_CONDITION;
 
+typedef enum _KDB_OUTPUT_SETTINGS
+{
+   KD_DEBUG_KDSERIAL,
+   KD_DEBUG_KDNOECHO
+} KDB_OUTPUT_SETTINGS;
 
 /* from kdb_symbols.c */
 typedef struct _KDB_MODULE_INFO
@@ -176,7 +180,41 @@
                             OUT PULONG LineNumber  OPTIONAL,
                             OUT PCH FileName  OPTIONAL,
                             OUT PCH FunctionName  OPTIONAL);
+                            
+VOID
+KdbSymLoadUserModuleSymbols(IN PLDR_MODULE LdrModule);
 
+VOID
+KdbSymFreeProcessSymbols(IN PEPROCESS Process);
+
+VOID
+KdbSymLoadDriverSymbols(IN PUNICODE_STRING Filename,
+                        IN PMODULE_OBJECT Module);
+
+VOID
+KdbSymUnloadDriverSymbols(IN PMODULE_OBJECT ModuleObject);
+
+VOID
+KdbSymProcessBootSymbols(IN PCHAR FileName);
+
+VOID
+KdbSymInit(IN PMODULE_TEXT_SECTION NtoskrnlTextSection,
+           IN PMODULE_TEXT_SECTION LdrHalTextSection);
+
+
+BOOLEAN 
+KdbSymPrintAddress(IN PVOID Address);
+
+KD_CONTINUE_TYPE
+KdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
+                           KPROCESSOR_MODE PreviousMode,
+                           PCONTEXT Context,
+                           PKTRAP_FRAME TrapFrame,
+                           BOOLEAN FirstChance);
+
+VOID
+KdbDeleteProcessHook(IN PEPROCESS Process);
+
 /* from kdb.c */
 
 extern PEPROCESS KdbCurrentProcess;
@@ -185,14 +223,8 @@
 extern ULONG KdbNumSingleSteps;
 extern BOOLEAN KdbSingleStepOver;
 extern PKDB_KTRAP_FRAME KdbCurrentTrapFrame;
+extern ULONG KdbDebugState;
 
-VOID
-KdbInit();
-
-VOID
-KdbModuleLoaded(
-   IN PUNICODE_STRING Name);
-
 LONG
 KdbpGetNextBreakPointNr(
    IN ULONG Start  OPTIONAL);
@@ -255,6 +287,10 @@
 KdbpAttachToProcess(
    PVOID ProcessId);
 
+VOID
+STDCALL
+KdbpGetCommandLineSettings(PCHAR p1);
+
 /* other functions */
 
 #define KdbpSafeReadMemory(dst, src, size)   MmSafeCopyFromUser(dst, src, size)
@@ -278,7 +314,10 @@
 DbgEnableFile(PCH Filename);
 VOID
 DbgDisableFile(PCH Filename);
+VOID
+KbdDisableMouse();
+VOID
+KbdEnableMouse();
 
-
 #endif /* NTOSKRNL_KDB_H */
 

Added: trunk/reactos/ntoskrnl/include/internal/kdbochs.h
--- trunk/reactos/ntoskrnl/include/internal/kdbochs.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/kdbochs.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -0,0 +1,18 @@
+/* $Id: kd.h 13948 2005-03-12 01:11:06Z navaraf $
+ *
+ * kernel debugger prototypes
+ */
+
+#ifndef __INCLUDE_INTERNAL_KD_BOCHS_H
+#define __INCLUDE_INTERNAL_KD_BOCHS_H
+
+#include <internal/ke.h>
+#include <internal/ldr.h>
+#include <ntdll/ldr.h>
+
+VOID
+STDCALL
+KdpBochsInit(struct _KD_DISPATCH_TABLE *DispatchTable,
+             ULONG BootPhase);
+             
+#endif /* __INCLUDE_INTERNAL_KD_BOCHS_H */

Added: trunk/reactos/ntoskrnl/include/internal/kdgdb.h
--- trunk/reactos/ntoskrnl/include/internal/kdgdb.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/kdgdb.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -0,0 +1,20 @@
+/* $Id: kd.h 13948 2005-03-12 01:11:06Z navaraf $
+ *
+ * kernel debugger prototypes
+ */
+
+#ifndef __INCLUDE_INTERNAL_KD_GDB_H
+#define __INCLUDE_INTERNAL_KD_GDB_H
+
+#include <internal/ke.h>
+#include <internal/ldr.h>
+#include <ntdll/ldr.h>
+
+VOID
+STDCALL
+KdpGdbStubInit(struct _KD_DISPATCH_TABLE *DispatchTable,
+               ULONG BootPhase);
+
+extern KD_PORT_INFORMATION GdbPortInfo;
+                            
+#endif /* __INCLUDE_INTERNAL_KD_BOCHS_H */

Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
--- trunk/reactos/ntoskrnl/include/internal/ke.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/ke.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -231,6 +231,9 @@
 	IN KPROFILE_SOURCE		Source
 );
 
+BOOLEAN 
+STDCALL
+KiRosPrintAddress(PVOID Address);
 
 VOID STDCALL KeUpdateSystemTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
 VOID STDCALL KeUpdateRunTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);

Modified: trunk/reactos/ntoskrnl/include/internal/module.h
--- trunk/reactos/ntoskrnl/include/internal/module.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/internal/module.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -14,9 +14,7 @@
   LIST_ENTRY ListEntry;
   PWCH Name;
   PIMAGE_OPTIONAL_HEADER OptionalHeader;
-#if defined(DBG) || defined(KDBG)
   PROSSYM_INFO RosSymInfo;
-#endif /* KDBG */
 } MODULE_TEXT_SECTION, *PMODULE_TEXT_SECTION;
 
 typedef struct _MODULE_OBJECT

Modified: trunk/reactos/ntoskrnl/include/ntoskrnl.h
--- trunk/reactos/ntoskrnl/include/ntoskrnl.h	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/include/ntoskrnl.h	2005-04-25 14:44:48 UTC (rev 14799)
@@ -54,6 +54,9 @@
 #include <internal/port.h>
 #include <internal/nls.h>
 #include <internal/dbg.h>
+#ifdef KDBG
+#include <internal/kdb.h>
+#endif
 #include <internal/dbgk.h>
 #include <internal/trap.h>
 #include <internal/safe.h>

Modified: trunk/reactos/ntoskrnl/io/iomgr.c
--- trunk/reactos/ntoskrnl/io/iomgr.c	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/io/iomgr.c	2005-04-25 14:44:48 UTC (rev 14799)
@@ -11,7 +11,6 @@
 /* INCLUDES ****************************************************************/
 
 #include <ntoskrnl.h>
-#include <internal/kdb.h>
 #define NDEBUG
 #include <internal/debug.h>
 
@@ -645,13 +644,11 @@
         KEBUGCHECK(INACCESSIBLE_BOOT_DEVICE);
     }
 
-    /* Start Profiling on a Debug Build */
-#if defined(KDBG)
+    /* Read KDB Data */
     KdbInit();
-#endif /* KDBG */
 
-    /* I/O is now setup for disk access, so start the debugging logger thread. */
-    if (KdDebugState & KD_DEBUG_FILELOG) DebugLogInit2();
+    /* I/O is now setup for disk access, so phase 3 */
+    KdInitSystem(3, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
 
     /* Load services for devices found by PnP manager */
     IopInitializePnpServices(IopRootDeviceNode, FALSE);

Modified: trunk/reactos/ntoskrnl/io/pnpreport.c
--- trunk/reactos/ntoskrnl/io/pnpreport.c	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/io/pnpreport.c	2005-04-25 14:44:48 UTC (rev 14799)
@@ -83,70 +83,16 @@
   *ConflictDetected = FALSE;
   DPRINT1("IoReportResourceForDetection partly implemented\n");
   
-  /* HACK: check if serial debug output is enabled. If yes,
-   * prevent serial port driver to detect this serial port
-   * by indicating a conflict
-   */
-  if ((KdDebugState & KD_DEBUG_SERIAL) && DriverList != NULL)
+  /* FIXME: Manually indicate conflicts with KD Ports */
+  if (DriverList)
   {
-    ULONG ComPortBase = 0;
-    ULONG i;
-    PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
-    
-    switch (LogPortInfo.ComPort)
-    {
-      case 1: ComPortBase = 0x3f8; break;
-      case 2: ComPortBase = 0x2f8; break;
-      case 3: ComPortBase = 0x3e8; break;
-      case 4: ComPortBase = 0x2e8; break;
-    }
-    
-    /* search for this port address in DriverList */
-    for (i = 0; i < DriverList->List[0].PartialResourceList.Count; i++)
-    {
-      ResourceDescriptor = &DriverList->List[0].PartialResourceList.PartialDescriptors[i];
-      if (ResourceDescriptor->Type == CmResourceTypePort)
+      if (KdpDetectConflicts(DriverList))
       {
-        if (ResourceDescriptor->u.Port.Start.u.LowPart <= ComPortBase
-         && ResourceDescriptor->u.Port.Start.u.LowPart + ResourceDescriptor->u.Port.Length > ComPortBase)
-        {
-          *ConflictDetected = TRUE;
-          return STATUS_CONFLICTING_ADDRESSES;
-        }
+        *ConflictDetected = TRUE;
+        return STATUS_CONFLICTING_ADDRESSES; 
       }
-    }
   }
-
-  if ((KdDebugState & KD_DEBUG_GDB) && DriverList != NULL)
-  {
-    ULONG ComPortBase = 0;
-    ULONG i;
-    PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor;
     
-    switch (GdbPortInfo.ComPort)
-    {
-      case 1: ComPortBase = 0x3f8; break;
-      case 2: ComPortBase = 0x2f8; break;
-      case 3: ComPortBase = 0x3e8; break;
-      case 4: ComPortBase = 0x2e8; break;
-    }
-    
-    /* search for this port address in DriverList */
-    for (i = 0; i < DriverList->List[0].PartialResourceList.Count; i++)
-    {
-      ResourceDescriptor = &DriverList->List[0].PartialResourceList.PartialDescriptors[i];
-      if (ResourceDescriptor->Type == CmResourceTypePort)
-      {
-        if (ResourceDescriptor->u.Port.Start.u.LowPart <= ComPortBase
-         && ResourceDescriptor->u.Port.Start.u.LowPart + ResourceDescriptor->u.Port.Length > ComPortBase)
-        {
-          *ConflictDetected = TRUE;
-          return STATUS_CONFLICTING_ADDRESSES;
-        }
-      }
-    }
-  }
-    
   if (PopSystemPowerDeviceNode != NULL && DriverListSize > 0)
   {
     /* We hope legacy devices will be enumerated by ACPI */

Deleted: trunk/reactos/ntoskrnl/kd/dlog.c
--- trunk/reactos/ntoskrnl/kd/dlog.c	2005-04-25 10:58:34 UTC (rev 14798)
+++ trunk/reactos/ntoskrnl/kd/dlog.c	2005-04-25 14:44:48 UTC (rev 14799)
@@ -1,230 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            ntoskrnl/kd/kdebug.c
- * PURPOSE:         Kernel debugger
- *
- * PROGRAMMERS:     Eric Kohl (ekohl@abo.rhein-zeitung.de)
- */
-
-/* INCLUDES ******************************************************************/
-
-#include <ntoskrnl.h>
-
-/* GLOBALS *******************************************************************/
-
-#define DEBUGLOG_SIZE (32*1024)
-
-static CHAR DebugLog[DEBUGLOG_SIZE];
-static ULONG DebugLogStart;
-static ULONG DebugLogEnd;
-static ULONG DebugLogCount;
-static KSPIN_LOCK DebugLogLock;
-static ULONG DebugLogOverflow;
-static HANDLE DebugLogThreadHandle;
-static CLIENT_ID DebugLogThreadCid;
-static HANDLE DebugLogFile;
-static KEVENT DebugLogEvent;
-
-/* FUNCTIONS *****************************************************************/
-
-VOID
-DebugLogDumpMessages(VOID)
-{
-  static CHAR Buffer[256];
-  ULONG Offset;
-  ULONG Length;
-
-  if (!(KdDebugState & KD_DEBUG_FILELOG))
-    {
-      return;
-    }
-  KdDebugState &= ~KD_DEBUG_FILELOG;
- 
-  Offset = (DebugLogEnd + 1) % DEBUGLOG_SIZE;
-  do
-    {
-      if (Offset <= DebugLogEnd)
-	{
-	  Length = min(255, DebugLogEnd - Offset);
-	}
-      else
-	{
-	  Length = min(255, DEBUGLOG_SIZE - Offset);
-	}
-      memcpy(Buffer, DebugLog + Offset, Length);
-      Buffer[Length] = 0;
-      DbgPrint(Buffer);
-      Offset = (Offset + Length) % DEBUGLOG_SIZE;
-    }
-  while (Length > 0);
-}
-
-VOID INIT_FUNCTION
-DebugLogInit(VOID)
-{
-  KeInitializeSpinLock(&DebugLogLock);
-  DebugLogStart = 0;
-  DebugLogEnd = 0;
-  DebugLogOverflow = 0;
-  DebugLogCount = 0;
-  KeInitializeEvent(&DebugLogEvent, NotificationEvent, FALSE);
-}
-
-VOID STDCALL
-DebugLogThreadMain(PVOID Context)
-{
-  KIRQL oldIrql;
-  IO_STATUS_BLOCK Iosb;
-  static CHAR Buffer[256];
-  ULONG WLen;
-
-  for (;;)
-    {
-      LARGE_INTEGER TimeOut;
-      TimeOut.QuadPart = -5000000; /* Half a second. */
-      KeWaitForSingleObject(&DebugLogEvent,
-			    0,
-			    KernelMode,
-			    FALSE,
-			    &TimeOut);
-      KeAcquireSpinLock(&DebugLogLock, &oldIrql);
-      while (DebugLogCount > 0)
-	{
-	  if (DebugLogStart > DebugLogEnd)
-	    {
-	      WLen = min(256, DEBUGLOG_SIZE - DebugLogStart);
-	      memcpy(Buffer, &DebugLog[DebugLogStart], WLen);
-              Buffer[WLen + 1] = '\n';
-	      DebugLogStart = 
-		(DebugLogStart + WLen) % DEBUGLOG_SIZE;
-	      DebugLogCount = DebugLogCount - WLen;
-	      KeReleaseSpinLock(&DebugLogLock, oldIrql);
-	      NtWriteFile(DebugLogFile,
-			  NULL,
-			  NULL,
-			  NULL,
-			  &Iosb,
-			  Buffer,
-			  WLen + 1,
-			  NULL,
-			  NULL);
-	    }
-	  else
-	    {
-	      WLen = min(255, DebugLogEnd - DebugLogStart);
-	      memcpy(Buffer, &DebugLog[DebugLogStart], WLen);
-	      DebugLogStart = 
-		(DebugLogStart + WLen) % DEBUGLOG_SIZE;
-	      DebugLogCount = DebugLogCount - WLen;
-	      KeReleaseSpinLock(&DebugLogLock, oldIrql);
-	      NtWriteFile(DebugLogFile,
-			  NULL,
-			  NULL,
-			  NULL,
-			  &Iosb,
-			  Buffer,
-			  WLen,
-			  NULL,
-			  NULL);
-	    }
-	  KeAcquireSpinLock(&DebugLogLock, &oldIrql);
-	}
-      KeResetEvent(&DebugLogEvent);
-      KeReleaseSpinLock(&DebugLogLock, oldIrql);
-    }
-}
-
-VOID INIT_FUNCTION
-DebugLogInit2(VOID)
-{
-  NTSTATUS Status;
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  UNICODE_STRING FileName;
-  IO_STATUS_BLOCK Iosb;
-
-  RtlInitUnicodeString(&FileName, L"\\SystemRoot\\debug.log");
-  InitializeObjectAttributes(&ObjectAttributes,
-			     &FileName,
-			     0,
-			     NULL,
-			     NULL);
-			     
-  Status = NtCreateFile(&DebugLogFile,
-			FILE_ALL_ACCESS,
-			&ObjectAttributes,
-			&Iosb,
-			NULL,
-			FILE_ATTRIBUTE_NORMAL,
-			FILE_SHARE_READ,
-			FILE_SUPERSEDE,
-			FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT,
-			NULL,
-			0);
-  if (!NT_SUCCESS(Status))
-    {
-      DbgPrint("Failed to create debug log file\n");
-      return;
-    }
-
-  Status = PsCreateSystemThread(&DebugLogThreadHandle,
-				THREAD_ALL_ACCESS,
-				NULL,
-				NULL,
-				&DebugLogThreadCid,
-				DebugLogThreadMain,
-				NULL);
-}
-
-VOID 
-DebugLogWrite(PCH String)
-{
-  KIRQL oldIrql;
-
-   if (KeGetCurrentIrql() > DISPATCH_LEVEL)
-    {
-      DebugLogOverflow++;
-      return;
-    }
-
-   KeAcquireSpinLock(&DebugLogLock, &oldIrql);
-
-   if (DebugLogCount == DEBUGLOG_SIZE)
-    {
-      DebugLogOverflow++;
-      KeReleaseSpinLock(&DebugLogLock, oldIrql);
-      if (oldIrql < DISPATCH_LEVEL)
- 	{
-	  KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
- 	}
-      	return;
-    }
-
-   while ((*String) != 0)
-    {
-      DebugLog[DebugLogEnd] = *String;
-      String++;
-      DebugLogCount++;
[truncated at 1000 lines; 5130 more skipped]