- More sharing between ntdll/ntoskrnl: shared Dbg code.
- Added NtCreateDebugObject, NtDebugContinue, NtQueryDebugFilterState, NtSetDebugFilterState, NtWaitForDebugEvent to system call list.
- Added some debug constants to headers
- Updated RtlpCheckForActiveDebugger in ntoskrnl to return whatever we're expecting as the "normal" case.
- Added RtlpSetInDbgPrint to rtl support library for special DbgPrint implementation difference in user-mode
- Removed all the deprecated debug APIs in ntdll.
- Implemented NtQueryDebugFilterState and NtSetDebugFilterState based on royce's implementation.
- Started modifications on KeDebugService, and implemented DebugService in rtl
- Implemented all the Dbg* APIs in RTL.
- Implemented DbgUiConnectToDbg, DbgUiContinue, DbgUiWaitStateChange, DbgUiRemoteBreakin, DbgUiIssueRemoteBreakin
- Changed KD Print callbacks to also receive the length of the string.

Right now, one call that should be shared still isn't (the final DebugPrint call) because calling KeDebugService from kernel-mode seems to cause a hang. Also, DebugService does not currently cause an exception like it should (instead it still calls the Kdp handler), because those changes would've made the patch even bigger and are still untested.
Deleted: trunk/reactos/lib/ntdll/dbg/debug.c
Deleted: trunk/reactos/lib/ntdll/dbg/print.c
Modified: trunk/reactos/lib/ntdll/def/ntdll.def
Modified: trunk/reactos/lib/ntdll/ntdll.xml
Modified: trunk/reactos/lib/ntdll/rtl/libsupp.c
Modified: trunk/reactos/lib/rtl/exception.c
Modified: trunk/reactos/lib/rtl/i386/debug.S
Modified: trunk/reactos/lib/rtl/rtl.xml
Modified: trunk/reactos/lib/rtl/rtlp.h
Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
Modified: trunk/reactos/ntoskrnl/kd/kdio.c
Modified: trunk/reactos/ntoskrnl/kd/kdmain.c
Modified: trunk/reactos/ntoskrnl/kd/wrappers/bochs.c
Modified: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
Modified: trunk/reactos/ntoskrnl/ntoskrnl.xml
Modified: trunk/reactos/ntoskrnl/rtl/debug.c
Modified: trunk/reactos/ntoskrnl/rtl/libsupp.c
Modified: trunk/reactos/ntoskrnl/rtl/misc.c
Modified: trunk/reactos/tools/nci/sysfuncs.lst
Modified: trunk/reactos/w32api/include/ddk/winddk.h
Modified: trunk/reactos/w32api/include/ntstatus.h

Deleted: trunk/reactos/lib/ntdll/dbg/debug.c
--- trunk/reactos/lib/ntdll/dbg/debug.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/ntdll/dbg/debug.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -1,222 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            lib/ntdll/dbg/debug.c
- * PURPOSE:         User mode debugger support functions
- * PROGRAMMER:      Eric Kohl
- * UPDATE HISTORY:
- *                  14/04/2000 Created
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <ntdll.h>
-#define NDEBUG
-#include <debug.h>
-
-/* FUNCTIONS *****************************************************************/
-
-static HANDLE DbgSsApiPort = NULL;
-static HANDLE DbgSsReplyPort = NULL;
-static NTSTATUS (STDCALL * DbgSsCallback)(PVOID,PVOID) = NULL;
-
-
-typedef struct _LPC_DBGSS_MESSAGE
-{
-	PORT_MESSAGE Header;
-	ULONG Unknown1;
-	ULONG Unknown2;
-	ULONG Unknown3;
-	ULONG Unknown4;
-} LPC_DBGSS_MESSAGE, *PLPC_DBGSS_MESSAGE;
-
-
-/* FUNCTIONS *****************************************************************/
-
-VOID STDCALL
-DbgSsServerThread(PVOID Unused)
-{
-	LPC_DBGSS_MESSAGE Message;
-	NTSTATUS Status;
-
-	for (;;)
-	{
-		Status = NtReplyWaitReceivePort (DbgSsApiPort,
-		                                 NULL,
-		                                 NULL,
-		                                 (PPORT_MESSAGE)&Message);
-		if (!NT_SUCCESS(Status))
-		{
-			DbgPrint ("DbgSs: NtReplyWaitReceivePort failed - Status == %lx\n",
-			          Status);
-
-			DbgBreakPoint ();
-		}
-		else
-		{
-			/* FIXME: missing code!! */
-
-		}
-	}
-}
-
-
-/*
- * @unimplemented
- */
-NTSTATUS STDCALL
-DbgSsHandleKmApiMsg(ULONG Unknown1,
-		    HANDLE EventHandle)
-{
-  return STATUS_NOT_IMPLEMENTED;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-DbgSsInitialize(HANDLE ReplyPort,
-		PVOID Callback,
-		ULONG Unknown2,
-		ULONG Unknown3)
-{
-	SECURITY_QUALITY_OF_SERVICE Qos;
-	UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\DbgSsApiPort");
-	NTSTATUS Status;
-
-	Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
-	Qos.ImpersonationLevel = SecurityIdentification;
-	Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
-	Qos.EffectiveOnly = TRUE;
-
-	Status = NtConnectPort (&DbgSsApiPort,
-	                        &PortName,
-	                        &Qos,
-	                        NULL,
-	                        NULL,
-	                        NULL,
-	                        NULL,
-	                        NULL);
-	if (!NT_SUCCESS(Status))
-		return Status;
-
-	DbgSsReplyPort = ReplyPort;
-	DbgSsCallback = Callback;
-//	UnknownData2 = Unknown2;
-//	UnknownData3 = Unknown3;
-
-	Status = RtlCreateUserThread (NtCurrentProcess (),
-	                              NULL,
-	                              FALSE,
-	                              0,
-	                              0,
-	                              0,
-	                              (PTHREAD_START_ROUTINE)DbgSsServerThread,
-	                              NULL,
-	                              NULL,
-	                              NULL);
-
-	return Status;
-}
-
-
-/*
- * @implemented
- */
-NTSTATUS STDCALL
-DbgUiConnectToDbg(VOID)
-{
-	SECURITY_QUALITY_OF_SERVICE Qos;
-	UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\DbgUiApiPort");
-	NTSTATUS Status;
-	PTEB Teb;
-	ULONG InfoSize;
-
-	Teb = NtCurrentTeb ();
-
-	Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
-	Qos.ImpersonationLevel = SecurityIdentification;
-	Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
-	Qos.EffectiveOnly = TRUE;
-
-	InfoSize = sizeof(ULONG);
-
-	Status = NtConnectPort (&Teb->DbgSsReserved[1],
-	                        &PortName,
-	                        &Qos,
-	                        NULL,
-	                        NULL,
-	                        NULL,
-	                        &Teb->DbgSsReserved[0],
-	                        &InfoSize);
-	if (!NT_SUCCESS(Status))
-	{
-		Teb->DbgSsReserved[1] = NULL;
-		return Status;
-	}
-
-	NtRegisterThreadTerminatePort(Teb->DbgSsReserved[1]);
-
-	return Status;
-}
-
-
-/*
- * @unimplemented
- */
-NTSTATUS STDCALL
-DbgUiContinue(PCLIENT_ID ClientId,
-	      ULONG ContinueStatus)
-{
-  return STATUS_NOT_IMPLEMENTED;
-}
-
-
-/*
- * @unimplemented
- */
-NTSTATUS STDCALL
-DbgUiWaitStateChange(PDBGUI_WAIT_STATE_CHANGE DbgUiWaitStateCange,
-                     PLARGE_INTEGER TimeOut)
-{
-  return STATUS_NOT_IMPLEMENTED;
-}
-
-VOID STDCALL DbgUiRemoteBreakin(VOID)
-{
- DbgBreakPoint();
-
- RtlExitUserThread(STATUS_SUCCESS);
-}
-
-NTSTATUS STDCALL DbgUiIssueRemoteBreakin(HANDLE Process)
-{
- HANDLE hThread;
- CLIENT_ID cidClientId;
- NTSTATUS nErrCode;
- ULONG nStackSize = PAGE_SIZE;
-
- nErrCode = RtlCreateUserThread
- (
-  Process,
-  NULL,
-  FALSE,
-  0,
-  nStackSize,
-  nStackSize,
-  (PTHREAD_START_ROUTINE)DbgUiRemoteBreakin,
-  NULL,
-  &hThread,
-  &cidClientId
- );
-
- if(!NT_SUCCESS(nErrCode)) return nErrCode;
-
- NtClose(hThread);
-
- return STATUS_SUCCESS;
-}
-
-/* EOF */

Deleted: trunk/reactos/lib/ntdll/dbg/print.c
--- trunk/reactos/lib/ntdll/dbg/print.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/ntdll/dbg/print.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -1,106 +0,0 @@
-/* $Id$
- *
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            lib/ntdll/dbg/print.c
- * PURPOSE:         Debug output
- * PROGRAMMER:      Eric Kohl
- * UPDATE HISTORY:
- *                  Created 28/12/1999
- */
-
-#include <ntdll.h>
-#define NDEBUG
-#include <debug.h>
-
-/* FUNCTIONS ***************************************************************/
-
-ULONG DbgService (ULONG Service, PVOID Context1, PVOID Context2);
-__asm__ ("\n\t.global _DbgService\n\t"
-         "_DbgService:\n\t"
-         "mov 4(%esp), %eax\n\t"
-         "mov 8(%esp), %ecx\n\t"
-         "mov 12(%esp), %edx\n\t"
-         "int $0x2D\n\t"
-         "ret\n\t");
-
-/*
- * @unimplemented
- */
-ULONG
-DbgPrintEx(
-    IN ULONG ComponentId,
-    IN ULONG Level,
-    IN PCH Format,
-    ...
-    )
-{
-   ANSI_STRING DebugString;
-   CHAR Buffer[4096];
-   va_list ap;
-
-   /* init ansi string */
-   DebugString.Buffer = Buffer;
-   DebugString.MaximumLength = sizeof(Buffer);
-
-   va_start (ap, Format);
-   DebugString.Length = _vsnprintf (Buffer, sizeof(Buffer), Format, ap);
-   va_end (ap);
-
-   DbgService (1, &DebugString, NULL);
-
-   return (ULONG)DebugString.Length;
-}
-
-
-/*
- * @implemented
- */
-ULONG
-DbgPrint(PCH Format, ...)
-{
-   ANSI_STRING DebugString;
-   CHAR Buffer[4096];
-   va_list ap;
-
-   /* init ansi string */
-   DebugString.Buffer = Buffer;
-   DebugString.MaximumLength = sizeof(Buffer);
-
-   va_start (ap, Format);
-   DebugString.Length = _vsnprintf (Buffer, sizeof(Buffer), Format, ap);
-   va_end (ap);
-
-
-   return DbgPrintEx (0, 0, DebugString.Buffer);
-}
-
-
-/*
- * @implemented
- */
-VOID
-STDCALL
-DbgPrompt (
-	PCH OutputString,
-	PCH InputString,
-	USHORT InputSize
-	)
-{
-	ANSI_STRING Output;
-	ANSI_STRING Input;
-
-	Input.Length = 0;
-	Input.MaximumLength = InputSize;
-	Input.Buffer = InputString;
-
-	Output.Length = strlen (OutputString);
-	Output.MaximumLength = Output.Length + 1;
-	Output.Buffer = OutputString;
-
-	DbgService (2,
-	            &Output,
-	            &Input);
-}
-
-/* EOF */

Modified: trunk/reactos/lib/ntdll/def/ntdll.def
--- trunk/reactos/lib/ntdll/def/ntdll.def	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/ntdll/def/ntdll.def	2005-09-26 04:59:48 UTC (rev 18078)
@@ -24,8 +24,6 @@
 DbgPrint
 DbgPrintEx
 DbgPrompt@12
-DbgSsHandleKmApiMsg@8
-DbgSsInitialize@16
 DbgUiConnectToDbg@0
 DbgUiContinue@8
 DbgUiIssueRemoteBreakin@4
@@ -161,6 +159,7 @@
 NtProtectVirtualMemory@20
 NtPulseEvent@8
 NtQueryAttributesFile@8
+NtQueryDebugFilterState@8
 NtQueryDefaultLocale@8
 NtQueryDefaultUILanguage@4
 NtQueryDirectoryFile@44
@@ -218,6 +217,7 @@
 NtResumeThread@8
 NtSaveKey@8
 NtSecureConnectPort@36
+NtSetDebugFilterState@12
 NtSetContextThread@8
 NtSetDefaultHardErrorPort@4
 NtSetDefaultLocale@8
@@ -265,6 +265,7 @@
 NtUnlockVirtualMemory@16
 NtUnmapViewOfSection@8
 NtVdmControl@8
+NtWaitForDebugEvent@16
 NtWaitForMultipleObjects@20
 NtWaitForSingleObject@12
 NtWaitHighEventPair@4
@@ -716,6 +717,7 @@
 ZwCompleteConnectPort@4
 ZwConnectPort@32
 ZwContinue@8
+ZwCreateDebugObject@16
 ZwCreateDirectoryObject@12
 ZwCreateEvent@20
 ZwCreateEventPair@12
@@ -735,6 +737,7 @@
 ZwCreateThread@32
 ZwCreateTimer@16
 ZwCreateToken@52
+ZwDebugContinue@12
 ZwDelayExecution@8
 ZwDeleteAtom@4
 ZwDeleteFile@4

Modified: trunk/reactos/lib/ntdll/ntdll.xml
--- trunk/reactos/lib/ntdll/ntdll.xml	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/ntdll/ntdll.xml	2005-09-26 04:59:48 UTC (rev 18078)
@@ -20,8 +20,7 @@
 		<file>connect.c</file>
 	</directory>
 	<directory name="dbg">
-		<file>debug.c</file>
-		<file>print.c</file>
+		<file>dbgui.c</file>
 	</directory>
 	<directory name="ldr">
 		<file>res.c</file>

Modified: trunk/reactos/lib/ntdll/rtl/libsupp.c
--- trunk/reactos/lib/ntdll/rtl/libsupp.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/ntdll/rtl/libsupp.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -17,11 +17,30 @@
 
 BOOLEAN
 NTAPI
-RtlpCheckForActiveDebugger(VOID)
+RtlpCheckForActiveDebugger(BOOLEAN Type)
 {
     return (NtCurrentPeb()->BeingDebugged);
 }
 
+BOOLEAN
+NTAPI
+RtlpSetInDbgPrint(IN BOOLEAN NewValue)
+{
+    /* If we're setting it to false, do it and return */
+    if (NewValue == FALSE)
+    {
+        NtCurrentTeb()->InDbgPrint = FALSE;
+        return FALSE;
+    }
+
+    /* Setting to true; check if it's not already */
+    if (NtCurrentTeb()->InDbgPrint) return TRUE;
+
+    /* Set it and return */
+    NtCurrentTeb()->InDbgPrint = TRUE;
+    return FALSE;
+}
+
 KPROCESSOR_MODE
 STDCALL
 RtlpGetMode()

Modified: trunk/reactos/lib/rtl/exception.c
--- trunk/reactos/lib/rtl/exception.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/rtl/exception.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -39,7 +39,7 @@
     Context.ContextFlags = CONTEXT_FULL;
 
     /* Check if we're being debugged (user-mode only) */
-    if (!RtlpCheckForActiveDebugger())
+    if (!RtlpCheckForActiveDebugger(TRUE))
     {
         /* Raise an exception immediately */
         Status = ZwRaiseException(ExceptionRecord, &Context, TRUE);
@@ -91,7 +91,7 @@
     Context.ContextFlags = CONTEXT_FULL;
 
     /* Check if we're being debugged (user-mode only) */
-    if (!RtlpCheckForActiveDebugger())
+    if (!RtlpCheckForActiveDebugger(TRUE))
     {
         /* Raise an exception immediately */
         ZwRaiseException(&ExceptionRecord, &Context, TRUE);

Modified: trunk/reactos/lib/rtl/i386/debug.S
--- trunk/reactos/lib/rtl/i386/debug.S	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/rtl/i386/debug.S	2005-09-26 04:59:48 UTC (rev 18078)
@@ -1,10 +1,9 @@
 /*
  * COPYRIGHT:         See COPYING in the top level directory
- * PROJECT:           ReactOS kernel
- * PURPOSE:           Run-Time Library
+ * PROJECT:           ReactOS Run-Time Library
+ * PURPOSE:           Debug Routines
  * FILE:              lib/rtl/i386/debug.S
  * PROGRAMER:         Alex Ionescu (alex@relsoft.net)
- * REVISION HISTORY:  27/07/2005 Created
  */
 
 .intel_syntax noprefix
@@ -14,6 +13,7 @@
 .globl  _DbgBreakPoint@0
 .globl  _DbgBreakPointWithStatus@4
 .globl  _DbgUserBreakPoint@0
+.globl  _DebugService@20
 
 /* FUNCTIONS ***************************************************************/
 
@@ -26,3 +26,36 @@
     mov eax, [esp+4]
     int 3
     ret 4
+
+_DebugService@20:
+
+    /* Setup the stack */
+    push ebp
+    mov ebp, esp
+
+    /* Save the registers */
+    push ecx
+    push ebx
+    push edi
+    push edi
+    push ebx
+
+    /* Call the Interrupt */
+    mov eax, [ebp+8]
+    mov ecx, [ebp+12]
+    mov edx, [ebp+16]
+    mov ebx, [ebp+20]
+    mov edi, [ebp+24]
+    int 0x2D
+    //int 3
+
+    /* Restore registers */
+    pop ebx
+    pop edi
+    pop edi
+    pop ebx
+
+    /* Return */
+    leave
+    ret 20
+

Modified: trunk/reactos/lib/rtl/rtl.xml
--- trunk/reactos/lib/rtl/rtl.xml	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/rtl/rtl.xml	2005-09-26 04:59:48 UTC (rev 18078)
@@ -24,6 +24,7 @@
 	<file>crc32.c</file>
 	<file>critical.c</file>
 	<file>dbgbuffer.c</file>
+	<file>debug.c</file>
 	<file>dos8dot3.c</file>
 	<file>encode.c</file>
 	<file>env.c</file>

Modified: trunk/reactos/lib/rtl/rtlp.h
--- trunk/reactos/lib/rtl/rtlp.h	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/lib/rtl/rtlp.h	2005-09-26 04:59:48 UTC (rev 18078)
@@ -51,7 +51,7 @@
 
 BOOLEAN
 NTAPI
-RtlpCheckForActiveDebugger(VOID);
+RtlpCheckForActiveDebugger(BOOLEAN Type);
 
 BOOLEAN
 NTAPI

Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
--- trunk/reactos/ntoskrnl/include/internal/kd.h	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/include/internal/kd.h	2005-09-26 04:59:48 UTC (rev 18078)
@@ -107,7 +107,10 @@
 
 typedef
 VOID
-(STDCALL*PKDP_PRINT_ROUTINE)(PCH String);
+(STDCALL*PKDP_PRINT_ROUTINE)(
+    LPSTR String,
+    ULONG Length
+);
 
 typedef
 VOID
@@ -172,7 +175,9 @@
 
 ULONG
 STDCALL
-KdpPrintString(PANSI_STRING String);
+KdpPrintString(
+    LPSTR String,
+    ULONG Length);
 
 BOOLEAN
 STDCALL
@@ -180,7 +185,10 @@
 
 VOID
 STDCALL
-KdpBochsDebugPrint(IN PCH Message);
+KdpBochsDebugPrint(
+    IN PCH Message,
+    IN ULONG Length
+);
 
 /* KD GLOBALS  ***************************************************************/
 

Modified: trunk/reactos/ntoskrnl/kd/kdio.c
--- trunk/reactos/ntoskrnl/kd/kdio.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/kd/kdio.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -55,10 +55,9 @@
 
 VOID
 STDCALL
-KdpPrintToLog(PCH String)
+KdpPrintToLog(PCH String,
+              ULONG StringLength)
 {
-    ULONG StringLength = strlen(String);
-
     /* Don't overflow */
     if ((CurrentPosition + StringLength) > BufferSize) return;
 
@@ -142,7 +141,8 @@
 
 VOID
 STDCALL
-KdpSerialDebugPrint(LPSTR Message)
+KdpSerialDebugPrint(LPSTR Message,
+                    ULONG Length)
 {
     PCHAR pch = (PCHAR) Message;
 
@@ -186,6 +186,15 @@
 
 VOID
 STDCALL
+KdpScreenPrint(LPSTR Message,
+               ULONG Length)
+{
+    /* Call HAL */
+    HalDisplayString(Message);
+}
+
+VOID
+STDCALL
 KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
               ULONG BootPhase)
 {
@@ -195,7 +204,7 @@
     {
         /* Write out the functions that we support for now */
         DispatchTable->KdpInitRoutine = KdpScreenInit;
-        DispatchTable->KdpPrintRoutine = HalDisplayString;
+        DispatchTable->KdpPrintRoutine = KdpScreenPrint;
 
         /* Register as a Provider */
         InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
@@ -247,10 +256,10 @@
 
 ULONG
 STDCALL
-KdpPrintString(PANSI_STRING String)
+KdpPrintString(LPSTR String,
+               ULONG Length)
 {
     if (!KdpDebugMode.Value) return 0;
-    PCH pch = String->Buffer;
     PLIST_ENTRY CurrentEntry;
     PKD_DISPATCH_TABLE CurrentTable;
 
@@ -264,17 +273,17 @@
                                          KdProvidersList);
 
         /* Call it */
-        CurrentTable->KdpPrintRoutine(pch);
+        CurrentTable->KdpPrintRoutine(String, Length);
 
         /* Next Table */
         CurrentEntry = CurrentEntry->Flink;
     }
 
     /* Call the Wrapper Routine */
-    if (WrapperInitRoutine) WrapperTable.KdpPrintRoutine(pch);
+    if (WrapperInitRoutine) WrapperTable.KdpPrintRoutine(String, Length);
 
     /* Return the Length */
-    return((ULONG)String->Length);
+    return Length;
 }
 
 /* EOF */

Modified: trunk/reactos/ntoskrnl/kd/kdmain.c
--- trunk/reactos/ntoskrnl/kd/kdmain.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/kd/kdmain.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -21,26 +21,35 @@
 BOOLEAN KdpBreakPending;
 VOID STDCALL PspDumpThreads(BOOLEAN SystemThreads);
 
+typedef struct
+{
+	ULONG ComponentId;
+	ULONG Level;
+} KD_COMPONENT_DATA;
+#define MAX_KD_COMPONENT_TABLE_ENTRIES 128
+KD_COMPONENT_DATA KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES];
+ULONG KdComponentTableEntries = 0;
+
 /* PRIVATE FUNCTIONS *********************************************************/
 
 ULONG
 STDCALL
 KdpServiceDispatcher(ULONG Service,
-                     PVOID Context1,
-                     PVOID Context2)
+                     PVOID Buffer1,
+                     ULONG Buffer1Length)
 {
     ULONG Result = 0;
 
     switch (Service)
     {
-        case 1: /* DbgPrint */
-            Result = KdpPrintString ((PANSI_STRING)Context1);
+        case BREAKPOINT_PRINT: /* DbgPrint */
+            Result = KdpPrintString(Buffer1, Buffer1Length);
             break;
 
 #ifdef DBG
         case TAG('R', 'o', 's', ' '): /* ROS-INTERNAL */
         {
-            switch ((ULONG)Context1)
+            switch ((ULONG)Buffer1)
             {
                 case DumpNonPagedPool:
                     MiDebugDumpNonPagedPool(FALSE);
@@ -203,4 +212,54 @@
     return STATUS_NOT_IMPLEMENTED;
 }
 
+NTSTATUS
+STDCALL
+NtQueryDebugFilterState(IN ULONG ComponentId,
+                        IN ULONG Level)
+{
+	int i;
+
+	/* convert Level to mask if it isn't already one */
+	if ( Level < 32 )
+		Level = 1 << Level;
+
+	for ( i = 0; i < KdComponentTableEntries; i++ )
+	{
+		if ( ComponentId == KdComponentTable[i].ComponentId )
+		{
+			if ( Level & KdComponentTable[i].Level )
+				return TRUE;
+			break;
+		}
+	}
+	return FALSE;
+}
+
+NTSTATUS
+STDCALL
+NtSetDebugFilterState(IN ULONG ComponentId,
+                      IN ULONG Level,
+                      IN BOOLEAN State)
+{
+	int i;
+	for ( i = 0; i < KdComponentTableEntries; i++ )
+	{
+		if ( ComponentId == KdComponentTable[i].ComponentId )
+			break;
+	}
+	if ( i == KdComponentTableEntries )
+	{
+		if ( i == MAX_KD_COMPONENT_TABLE_ENTRIES )
+			return STATUS_INVALID_PARAMETER_1;
+		++KdComponentTableEntries;
+		KdComponentTable[i].ComponentId = ComponentId;
+		KdComponentTable[i].Level = 0;
+	}
+	if ( State )
+		KdComponentTable[i].Level |= Level;
+	else
+		KdComponentTable[i].Level &= ~Level;
+	return STATUS_SUCCESS;
+}
+
  /* EOF */

Modified: trunk/reactos/ntoskrnl/kd/wrappers/bochs.c
--- trunk/reactos/ntoskrnl/kd/wrappers/bochs.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/kd/wrappers/bochs.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -18,7 +18,8 @@
 
 VOID
 STDCALL
-KdpBochsDebugPrint(IN PCH Message)
+KdpBochsDebugPrint(IN PCH Message,
+                   IN ULONG Length)
 {
     while (*Message != 0)
     {
@@ -41,8 +42,6 @@
     }
 }
 
-
-
 VOID
 STDCALL
 KdpBochsInit(PKD_DISPATCH_TABLE WrapperTable,

Modified: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
--- trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -1446,7 +1446,7 @@
 
 VOID
 STDCALL
-KdpGdbDebugPrint(PCH Message)
+KdpGdbDebugPrint(PCH Message, ULONG Length)
 {
 #if 0
   /* This can be quite annoying! */

Modified: trunk/reactos/ntoskrnl/ke/i386/syscall.S
--- trunk/reactos/ntoskrnl/ke/i386/syscall.S	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/ke/i386/syscall.S	2005-09-26 04:59:48 UTC (rev 18078)
@@ -839,12 +839,49 @@
     mov [ebp+KTRAP_FRAME_DEBUGEBP], ebx
     mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
 
+    /* Increase EIP so we skip the INT3 */
+    //inc dword ptr [ebp+KTRAP_FRAME_EIP]
+
     /* Call debug service dispatcher */
-    push [ebp+KTRAP_FRAME_EDX]
-    push [ebp+KTRAP_FRAME_ECX]
-    push [ebp+KTRAP_FRAME_EAX]
+    mov eax, [ebp+KTRAP_FRAME_EAX]
+    mov ecx, [ebp+KTRAP_FRAME_ECX]
+    mov edx, [ebp+KTRAP_FRAME_EAX]
+
+    /* Check for V86 mode */
+    test dword ptr [ebp+KTRAP_FRAME_EFLAGS], X86_EFLAGS_VM
+    jnz NotUserMode
+
+    /* Check if this is kernel or user-mode */
+    test byte ptr [ebp+KTRAP_FRAME_CS], 1
+    jz CallDispatch
+    cmp word ptr [ebp+KTRAP_FRAME_CS], USER_CS
+    jnz NotUserMode
+
+    /* Re-enable interrupts */
+VdmProc:
+    sti
+
+    /* Call the debug routine */
+CallDispatch:
+    mov esi, ecx
+    mov edi, edx
+    mov edx, eax
+    mov ecx, 3
+    push edi
+    push esi
+    push edx
     call _KdpServiceDispatcher@12
 
+NotUserMode:
+
+    /* Get the current process */
+    mov ebx, [fs:KPCR_CURRENT_THREAD]
+    mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS]
+
+    /* Check if this is a VDM Process */
+    //cmp dword ptr [ebx+KPROCESS_VDM_OBJECTS], 0
+    //jz VdmProc
+
     /* Exit through common routine */
     jmp Kei386EoiHelper@0
 

Modified: trunk/reactos/ntoskrnl/ntoskrnl.xml
--- trunk/reactos/ntoskrnl/ntoskrnl.xml	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/ntoskrnl.xml	2005-09-26 04:59:48 UTC (rev 18078)
@@ -306,7 +306,6 @@
 			</directory>
 		</if>
 		<file>atom.c</file>
-		<file>debug.c</file>
 		<file>libsupp.c</file>
 		<file>misc.c</file>
 		<file>nls.c</file>

Modified: trunk/reactos/ntoskrnl/rtl/debug.c
--- trunk/reactos/ntoskrnl/rtl/debug.c	2005-09-26 03:18:53 UTC (rev 18077)
+++ trunk/reactos/ntoskrnl/rtl/debug.c	2005-09-26 04:59:48 UTC (rev 18078)
@@ -1,299 +0,0 @@
-/*
- * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS kernel
- * FILE:            ntoskrnl/rtl/dbgprint.c
- * PURPOSE:         Debug output
- *
- * PROGRAMMERS:     Eric Kohl (ekohl@abo.rhein-zeitung.de)
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <ntoskrnl.h>
-#include <internal/debug.h>
-
-/* DATA *********************************************************************/
-
-typedef struct
-{
-	ULONG ComponentId;
-	ULONG Level;
-} KD_COMPONENT_DATA;
-#define MAX_KD_COMPONENT_TABLE_ENTRIES 128
-KD_COMPONENT_DATA KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES];
-ULONG KdComponentTableEntries = 0;
-
-/* FUNCTIONS ****************************************************************/
-
-/*
- * Note: DON'T CHANGE THIS FUNCTION!!!
- *       DON'T CALL HalDisplayString OR SOMETING ELSE!!!
- *       You'll only break the serial/bochs debugging feature!!!
- */
-
-/*
- * @implemented
- */
-ULONG STDCALL
-vDbgPrintExWithPrefix(IN LPCSTR Prefix,
-                      IN ULONG ComponentId,
-                      IN ULONG Level,
-                      IN LPCSTR Format,
-                      IN va_list ap)
-{
-   ANSI_STRING DebugString;
-   CHAR Buffer[513];
-   PCHAR pBuffer;
-   ULONG pBufferSize;
-#ifdef SERIALIZE_DBGPRINT
-#  define MESSAGETABLE_SIZE  16
-   LONG MyTableIndex;
-   static LONG Lock = 0;
-   static LONG TableWriteIndex = 0, TableReadIndex = 0;
-   static CHAR MessageTable[MESSAGETABLE_SIZE][sizeof(Buffer)] = { { '\0' } };
-#endif /* SERIALIZE_DBGPRINT */
-
-   /* TODO FIXME - call NtQueryDebugFilterState() instead per Alex */
-   if ( !DbgQueryDebugFilterState ( ComponentId, Level ) )
-      return 0;
-
-   /* init ansi string */
-   DebugString.Buffer = Buffer;
-   DebugString.MaximumLength = sizeof(Buffer);
-
-   pBuffer = Buffer;
-   pBufferSize = sizeof(Buffer);
-   DebugString.Length = 0;
-   if ( Prefix && *Prefix )
-   {
-      DebugString.Length = strlen(Prefix);
-      if ( DebugString.Length >= sizeof(Buffer) )
-         DebugString.Length = sizeof(Buffer) - 1;
-      memmove ( Buffer, Prefix, DebugString.Length );
-      Buffer[DebugString.Length] = '\0';
-      pBuffer = &Buffer[DebugString.Length];
-      pBufferSize -= DebugString.Length;
-   }
-
-   DebugString.Length += _vsnprintf ( pBuffer, pBufferSize, Format, ap );
-   Buffer[sizeof(Buffer)-1] = '\0';
-
-#ifdef SERIALIZE_DBGPRINT
-   /* check if we are already running */
-   if (InterlockedCompareExchange(&Lock, 1, 0) == 1)
-     {
-        MyTableIndex = InterlockedIncrement(&TableWriteIndex) - 1;
-        InterlockedCompareExchange(&TableWriteIndex, 0, MESSAGETABLE_SIZE);
-        MyTableIndex %= MESSAGETABLE_SIZE;
-
-        if (MessageTable[MyTableIndex][0] != '\0') /* table is full */
-          {
-             DebugString.Buffer = "CRITICAL ERROR: DbgPrint Table is FULL!";
-             DebugString.Length = 39;
-             KdpPrintString(&DebugString);
-             for (;;);
-          }
-        else
-          {
-             memcpy(MessageTable[MyTableIndex], DebugString.Buffer, DebugString.Length);
-             MessageTable[MyTableIndex][DebugString.Length] = '\0';
-          }
-     }
-   else
-     {
-#endif /* SERIALIZE_DBGPRINT */
-        KdpPrintString (&DebugString);
-#ifdef SERIALIZE_DBGPRINT
-        MyTableIndex = TableReadIndex;
-        while (MessageTable[MyTableIndex][0] != '\0')
-          {
-             /*DebugString.Buffer = "$$$";
-             DebugString.Length = 3;
-             KdpPrintString(&DebugString);*/
-
-             DebugString.Buffer = MessageTable[MyTableIndex];
-             DebugString.Length = strlen(DebugString.Buffer);
[truncated at 1000 lines; 306 more skipped]