Author: hbelusca
Date: Thu May  9 13:12:58 2013
New Revision: 58974

URL: http://svn.reactos.org/svn/reactos?rev=58974&view=rev
Log:
Merge my current work done on the kd++ branch:
- FreeLdr is able now to load personalized Kernel Debugger Transport DLLs by 
reading at the kernel command line and interpreting the /DEBUGPORT=xxx entry 
(--> loads KDxxx.DLL dll in \SystemRoot\System32\).
  Therefore we can not only load the "default" kdcom.dll, but also 3rd-party 
ones such as kdbazis.dll from VirtualKD (from revision 58902).
- The GCC-compiled-only version of kdcom, containing legacy COM code, was 
removed and put directly along KDBG. It remains only a stub / template for 
future kdcom-like dlls. The MSVC-version remains untouched.
- Make those functions ^ use directly the CPORTLIB library.

Added:
    trunk/reactos/drivers/base/kdcom/   (props changed)
      - copied from r58973, branches/kd++/drivers/base/kdcom/
    trunk/reactos/drivers/base/kdrosdbg/   (props changed)
      - copied from r58973, branches/kd++/drivers/base/kdrosdbg/
    trunk/reactos/ntoskrnl/kd/arm/
      - copied from r58973, branches/kd++/ntoskrnl/kd/arm/
    trunk/reactos/ntoskrnl/kd/i386/kdbg.c
      - copied unchanged from r58973, branches/kd++/ntoskrnl/kd/i386/kdbg.c
Removed:
    trunk/reactos/drivers/base/kddll/
Modified:
    trunk/reactos/   (props changed)
    trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c
    trunk/reactos/boot/freeldr/freeldr/windows/peloader.c
    trunk/reactos/boot/freeldr/freeldr/windows/winldr.c
    trunk/reactos/drivers/base/CMakeLists.txt
    trunk/reactos/include/reactos/windbgkd.h
    trunk/reactos/ntoskrnl/CMakeLists.txt
    trunk/reactos/ntoskrnl/include/internal/kd.h
    trunk/reactos/ntoskrnl/include/internal/tag.h
    trunk/reactos/ntoskrnl/kd/kdinit.c
    trunk/reactos/ntoskrnl/kd/kdio.c
    trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
    trunk/reactos/ntoskrnl/kd/wrappers/gdbstub_powerpc.c
    trunk/reactos/ntoskrnl/kdbg/kdb.h

Propchange: trunk/reactos/
------------------------------------------------------------------------------
--- svn:mergeinfo       (original)
+++ svn:mergeinfo       Thu May  9 13:12:58 2013
@@ -4,6 +4,7 @@
 /branches/GSoC_Network:51545-51546
 /branches/cmake-bringup:50484,50693,50719,51544-52564
 /branches/header-work:45691-47721
+/branches/kd++:58883-58973
 /branches/reactos-yarotows:45219-46371,46373-48025,48027-49273
 /branches/reactx/reactos:49994-49995
 /branches/ros-amd64-bringup:36852

Modified: trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/disk/scsiport.c  [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -1568,7 +1568,7 @@
     ULONG ImportTableSize;
     PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
     CHAR NtBootDdPath[MAX_PATH];
-    PVOID ImageBase;
+    PVOID ImageBase = NULL;
     ULONG (NTAPI *EntryPoint)(IN PVOID DriverObject, IN PVOID RegistryPath);
     BOOLEAN Status;
 

Modified: trunk/reactos/boot/freeldr/freeldr/windows/peloader.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/peloader.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/peloader.c       [iso-8859-1] 
(original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/peloader.c       [iso-8859-1] 
Thu May  9 13:12:58 2013
@@ -255,11 +255,12 @@
        return TRUE;
 }
 
-/* WinLdrLoadImage loads the specified image from the file (it doesn't
-   perform any additional operations on the filename, just directly
-   calls the file I/O routines), and relocates it so that it's ready
-   to be used when paging is enabled.
-   Addressing mode: physical
+/*
+ * WinLdrLoadImage loads the specified image from the file (it doesn't
+ * perform any additional operations on the filename, just directly
+ * calls the file I/O routines), and relocates it so that it's ready
+ * to be used when paging is enabled.
+ * Addressing mode: physical
  */
 BOOLEAN
 WinLdrLoadImage(IN PCHAR FileName,
@@ -429,7 +430,6 @@
        /* If loading failed - return right now */
        if (Status != ESUCCESS)
                return FALSE;
-
 
        /* Relocate the image, if it needs it */
        if (NtHeaders->OptionalHeader.ImageBase != (ULONG_PTR)VirtualBase)
@@ -756,7 +756,7 @@
 {
        CHAR FullDllName[256];
        BOOLEAN Status;
-       PVOID BasePA;
+       PVOID BasePA = NULL;
 
        /* Prepare the full path to the file to be loaded */
        strcpy(FullDllName, DirectoryPath);
@@ -781,7 +781,7 @@
                DataTableEntry);
        if (!Status)
        {
-               ERR("WinLdrAllocateDataTableEntry() failed with Status=0x%X\n", 
Status);
+               ERR("WinLdrAllocateDataTableEntry() failed\n");
                return Status;
        }
 
@@ -791,7 +791,7 @@
        Status = WinLdrScanImportDescriptorTable(ModuleListHead, DirectoryPath, 
*DataTableEntry);
        if (!Status)
        {
-               ERR("WinLdrScanImportDescriptorTable() failed with 
Status=0x%X\n", Status);
+               ERR("WinLdrScanImportDescriptorTable() failed\n");
                return Status;
        }
 

Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/winldr.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -227,7 +227,7 @@
 
 static BOOLEAN
 WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
-                       LPSTR BootPath,
+                       LPCSTR BootPath,
                        PUNICODE_STRING FilePath,
                        ULONG Flags,
                        PLDR_DATA_TABLE_ENTRY *DriverDTE)
@@ -237,7 +237,7 @@
        CHAR DllName[1024];
        PCHAR DriverNamePos;
        BOOLEAN Status;
-       PVOID DriverBase;
+       PVOID DriverBase = NULL;
 
        // Separate the path to file name and directory path
        _snprintf(DriverPath, sizeof(DriverPath), "%wZ", FilePath);
@@ -258,7 +258,6 @@
        }
 
        TRACE("DriverPath: %s, DllName: %s, LPB\n", DriverPath, DllName);
-
 
        // Check if driver is already loaded
        Status = WinLdrCheckForLoadedDll(LoadOrderListHead, DllName, DriverDTE);
@@ -299,7 +298,7 @@
 
 BOOLEAN
 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
-                      LPSTR BootPath)
+                      LPCSTR BootPath)
 {
        PLIST_ENTRY NextBd;
        PBOOT_DRIVER_LIST_ENTRY BootDriver;
@@ -318,8 +317,11 @@
                // Paths are relative (FIXME: Are they always relative?)
 
                // Load it
-               Status = 
WinLdrLoadDeviceDriver(&LoaderBlock->LoadOrderListHead, BootPath, 
&BootDriver->FilePath,
-                       0, &BootDriver->LdrEntry);
+               Status = WinLdrLoadDeviceDriver(&LoaderBlock->LoadOrderListHead,
+                                               BootPath,
+                                               &BootDriver->FilePath,
+                                               0,
+                                               &BootDriver->LdrEntry);
 
                // If loading failed - cry loudly
                //FIXME: Maybe remove it from the list and try to continue?
@@ -340,8 +342,10 @@
        return TRUE;
 }
 
-PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size,
-                                          TYPE_OF_MEMORY MemoryType)
+PVOID
+WinLdrLoadModule(PCSTR ModuleName,
+                 ULONG *Size,
+                 TYPE_OF_MEMORY MemoryType)
 {
        ULONG FileId;
        PVOID PhysicalBase;
@@ -398,7 +402,6 @@
        return PhysicalBase;
 }
 
-
 USHORT
 WinLdrDetectVersion()
 {
@@ -420,19 +423,20 @@
 }
 
 static
-PVOID
+BOOLEAN
 LoadModule(
     PLOADER_PARAMETER_BLOCK LoaderBlock,
     PCCH Path,
     PCCH File,
     TYPE_OF_MEMORY MemoryType,
     PLDR_DATA_TABLE_ENTRY *Dte,
+    BOOLEAN IsKdTransportDll,
     ULONG Percentage)
 {
+       BOOLEAN Status;
        CHAR FullFileName[MAX_PATH];
        CHAR ProgressString[256];
-       NTSTATUS Status;
-       PVOID BaseAdress;
+       PVOID BaseAdress = NULL;
 
        UiDrawBackdrop();
        sprintf(ProgressString, "Loading %s...", File);
@@ -443,15 +447,146 @@
        strcat(FullFileName, File);
 
        Status = WinLdrLoadImage(FullFileName, MemoryType, &BaseAdress);
-       TRACE("%s loaded with status %d at %p\n",
-               File, Status, BaseAdress);
+       if (!Status)
+       {
+               TRACE("Loading %s failed\n", File);
+               return FALSE;
+       }
+       TRACE("%s loaded successfully at %p\n", File, BaseAdress);
 
        strcpy(FullFileName, "WINDOWS\\SYSTEM32\\");
        strcat(FullFileName, File);
-       WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, File,
-               FullFileName, BaseAdress, Dte);
-
-       return BaseAdress;
+       /*
+        * Cheat about the base DLL name if we are loading
+        * the Kernel Debugger Transport DLL, to make the
+        * PE loader happy.
+        */
+       Status = WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead,
+                                             (IsKdTransportDll ? "KDCOM.DLL" : 
File),
+                                             FullFileName,
+                                             BaseAdress,
+                                             Dte);
+
+       return Status;
+}
+
+static
+BOOLEAN
+LoadWindowsCore(IN USHORT OperatingSystemVersion,
+                IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
+                IN LPCSTR BootOptions,
+                IN LPCSTR BootPath,
+                IN OUT PLDR_DATA_TABLE_ENTRY* KernelDTE)
+{
+       BOOLEAN Status;
+       CHAR DirPath[MAX_PATH];
+       CHAR KdTransportDllName[MAX_PATH];
+       PLDR_DATA_TABLE_ENTRY HalDTE, KdComDTE = NULL;
+
+       if (!KernelDTE) return FALSE;
+
+       /* Load the Kernel */
+       LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", LoaderSystemCode, 
KernelDTE, FALSE, 30);
+
+       /* Load the HAL */
+       LoadModule(LoaderBlock, BootPath, "HAL.DLL", LoaderHalCode, &HalDTE, 
FALSE, 45);
+
+       /* Load the Kernel Debugger Transport DLL */
+       if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
+       {
+               /*
+                * According to http://www.nynaeve.net/?p=173 :
+                * "[...] Another enhancement that could be done Microsoft-side 
would be
+                * a better interface for replacing KD transport modules. Right 
now, due
+                * to the fact that ntoskrnl is static linked to KDCOM.DLL, the 
OS loader
+                * has a hardcoded hack that interprets the KD type in the OS 
loader options,
+                * loads one of the (hardcoded filenames) "kdcom.dll", 
"kd1394.dll", or
+                * "kdusb2.dll" modules, and inserts them into the loaded 
module list under
+                * the name "kdcom.dll". [...]"
+                */
+
+               /*
+                * This loop replaces a dumb call to strstr(..., "DEBUGPORT=").
+                * Indeed I want it to be case-insensitive to allow "debugport="
+                * or "DeBuGpOrT=" or... , and I don't want it to match 
malformed
+                * command-line options, such as:
+                *
+                * "...foo DEBUGPORT=xxx bar..."
+                * "...foo/DEBUGPORT=xxx bar..."
+                * "...foo/DEBUGPORT=bar..."
+                *
+                * i.e. the "DEBUGPORT=" switch must start with a slash and be 
separated
+                * from the rest by whitespace, unless it begins the 
command-line, e.g.:
+                *
+                * "/DEBUGPORT=COM1 foo...bar..."
+                * "...foo /DEBUGPORT=USB bar..."
+                * or:
+                * "...foo /DEBUGPORT= bar..."
+                * (in that case, we default the port to COM).
+                */
+               while (BootOptions)
+               {
+                       /* Skip possible initial whitespace */
+                       BootOptions += strspn(BootOptions, " \t");
+
+                       /* Check whether a new commutator starts and it is the 
DEBUGPORT one */
+                       if (*BootOptions != '/' || _strnicmp(++BootOptions, 
"DEBUGPORT=", 10) != 0)
+                       {
+                               /* Search for another whitespace */
+                               BootOptions = strpbrk(BootOptions, " \t");
+                               continue;
+                       }
+                       else
+                       {
+                               /* We found the DEBUGPORT commutator. Move to 
the port name. */
+                               BootOptions += 10;
+                               break;
+                       }
+               }
+
+               if (BootOptions)
+               {
+                       /*
+                        * We have found the DEBUGPORT commutator. Parse the 
port name.
+                        * Format: /DEBUGPORT=COM1 or 
/DEBUGPORT=FILE:\Device\HarddiskX\PartitionY\debug.log or /DEBUGPORT=FOO
+                        * If we only have /DEBUGPORT= (i.e. without any port 
name), defaults it to "COM".
+                        */
+                       strcpy(KdTransportDllName, "KD");
+                       if (_strnicmp(BootOptions, "COM", 3) == 0 && '0' <= 
BootOptions[3] && BootOptions[3] <= '9')
+                       {
+                               strncat(KdTransportDllName, BootOptions, 3);
+                       }
+                       else
+                       {
+                               size_t i = strcspn(BootOptions, " \t:"); /* 
Skip valid separators: whitespace or colon */
+                               if (i == 0)
+                                       strcat(KdTransportDllName, "COM");
+                               else
+                                       strncat(KdTransportDllName, 
BootOptions, i);
+                       }
+                       strcat(KdTransportDllName, ".DLL");
+                       _strupr(KdTransportDllName);
+
+                       /*
+                        * Load the transport DLL. Specify it to LoadModule so 
that it can
+                        * change the base DLL name of the loaded transport DLL 
to the default
+                        * "KDCOM.DLL" name, to make the PE loader happy.
+                        */
+                       LoadModule(LoaderBlock, BootPath, KdTransportDllName, 
LoaderSystemCode, &KdComDTE, TRUE, 60);
+               }
+       }
+
+       /* Load all referenced DLLs for Kernel, HAL and Kernel Debugger 
Transport DLL */
+       strcpy(DirPath, BootPath);
+       strcat(DirPath, "system32\\");
+       Status  = 
WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, 
*KernelDTE);
+       Status &= 
WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, 
HalDTE);
+       if (KdComDTE)
+       {
+               Status &= 
WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, DirPath, 
KdComDTE);
+       }
+
+       return Status;
 }
 
 VOID
@@ -496,7 +631,7 @@
                strcat(BootPath, FileName);
        }
 
-       /* append a backslash */
+       /* Append a backslash */
        if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\')
                strcat(BootPath, "\\");
 
@@ -547,13 +682,13 @@
        UiDrawBackdrop();
        UiDrawProgressBarCenter(15, 100, "Loading system hive...");
        Status = WinLdrInitSystemHive(LoaderBlock, BootPath);
-       TRACE("SYSTEM hive loaded with status %d\n", Status);
+       TRACE("SYSTEM hive %s\n", (Status ? "loaded" : "not loaded"));
 
        /* Load NLS data, OEM font, and prepare boot drivers list */
        Status = WinLdrScanSystemHive(LoaderBlock, BootPath);
-       TRACE("SYSTEM hive scanned with status %d\n", Status);
-
-
+       TRACE("SYSTEM hive %s\n", (Status ? "scanned" : "not scanned"));
+
+       /* Finish loading */
        LoadAndBootWindowsCommon(OperatingSystemVersion,
                                 LoaderBlock,
                                 BootOptions,
@@ -571,8 +706,7 @@
 {
        PLOADER_PARAMETER_BLOCK LoaderBlockVA;
        BOOLEAN Status;
-       CHAR FileName[MAX_PATH];
-       PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
+       PLDR_DATA_TABLE_ENTRY KernelDTE;
        KERNEL_ENTRY_POINT KiSystemStartup;
        LPCSTR SystemRoot;
        TRACE("LoadAndBootWindowsCommon()\n");
@@ -586,40 +720,30 @@
        if (OperatingSystemVersion == 0)
                OperatingSystemVersion = WinLdrDetectVersion();
 
-       /* Load kernel */
-       LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", LoaderSystemCode, 
&KernelDTE, 30);
-
-       /* Load HAL */
-       LoadModule(LoaderBlock, BootPath, "HAL.DLL", LoaderHalCode, &HalDTE, 
45);
-
-       /* Load kernel-debugger support dll */
-       if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
-       {
-               LoadModule(LoaderBlock, BootPath, "KDCOM.DLL", 
LoaderSystemCode, &KdComDTE, 60);
-       }
-
-       /* Load all referenced DLLs for kernel, HAL and kdcom.dll */
-       strcpy(FileName, BootPath);
-       strcat(FileName, "system32\\");
-       Status = 
WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, 
KernelDTE);
-       Status &= 
WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, 
HalDTE);
-       if (KdComDTE)
-               Status &= 
WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, 
KdComDTE);
-
+       /* Load the operating system core: the Kernel, the HAL and the Kernel 
Debugger Transport DLL */
+       Status = LoadWindowsCore(OperatingSystemVersion,
+                                LoaderBlock,
+                                BootOptions,
+                                BootPath,
+                                &KernelDTE);
        if (!Status)
        {
-               UiMessageBox("Error loading imported dll.");
+               UiMessageBox("Error loading NTOS core.");
                return;
        }
 
        /* Load boot drivers */
        UiDrawBackdrop();
        UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
-       Status = WinLdrLoadBootDrivers(LoaderBlock, (PCHAR)BootPath);
+       Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
        TRACE("Boot drivers loaded with status %d\n", Status);
 
        /* Initialize Phase 1 - no drivers loading anymore */
-       WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, 
OperatingSystemVersion);
+       WinLdrInitializePhase1(LoaderBlock,
+                              BootOptions,
+                              SystemRoot,
+                              BootPath,
+                              OperatingSystemVersion);
 
        /* Save entry-point pointer and Loader block VAs */
        KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
@@ -644,7 +768,7 @@
        LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
 
        TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
-               KiSystemStartup, LoaderBlockVA);
+             KiSystemStartup, LoaderBlockVA);
 
        // Zero KI_USER_SHARED_DATA page
        memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);
@@ -722,5 +846,3 @@
                NextBd = ArcDisk->ListEntry.Flink;
        }
 }
-
-

Modified: trunk/reactos/drivers/base/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/CMakeLists.txt?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/drivers/base/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/drivers/base/CMakeLists.txt   [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -3,9 +3,10 @@
 add_subdirectory(bootvid)
 
 if(_WINKD_)
-add_subdirectory(kddll)
+add_subdirectory(kdcom)
 else()
-add_subdirectory(kdcom)
+add_subdirectory(kdrosdbg)
 endif()
+
 add_subdirectory(nmidebug)
 add_subdirectory(null)

Propchange: trunk/reactos/drivers/base/kdcom/
------------------------------------------------------------------------------
--- bugtraq:logregex    (added)
+++ bugtraq:logregex    Thu May  9 13:12:58 2013
@@ -0,0 +1,2 @@
+([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))?
+(\d+)

Propchange: trunk/reactos/drivers/base/kdcom/
------------------------------------------------------------------------------
    bugtraq:message = See issue #%BUGID% for more details.

Propchange: trunk/reactos/drivers/base/kdcom/
------------------------------------------------------------------------------
    bugtraq:url = http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%

Propchange: trunk/reactos/drivers/base/kdcom/
------------------------------------------------------------------------------
    tsvn:logminsize = 10

Propchange: trunk/reactos/drivers/base/kdrosdbg/
------------------------------------------------------------------------------
--- svn:ignore  (added)
+++ svn:ignore  Thu May  9 13:12:58 2013
@@ -0,0 +1,7 @@
+GNUmakefile
+*.vcproj
+*.user
+*.cbp
+*.ncb
+*.suo
+*.sln

Modified: trunk/reactos/include/reactos/windbgkd.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/windbgkd.h?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/include/reactos/windbgkd.h    [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/windbgkd.h    [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -451,7 +451,7 @@
     ULONG Thread;
     ULONG ProgramCounter;
     union
-       {
+    {
         DBGKM_EXCEPTION32 Exception;
         DBGKD_LOAD_SYMBOLS32 LoadSymbols;
     } u;
@@ -481,13 +481,13 @@
     ULONG64 Thread;
     ULONG64 ProgramCounter;
     union
-       {
+    {
         DBGKM_EXCEPTION64 Exception;
         DBGKD_LOAD_SYMBOLS64 LoadSymbols;
         DBGKD_COMMAND_STRING CommandString;
     } u;
     union
-       {
+    {
         DBGKD_CONTROL_REPORT ControlReport;
         DBGKD_ANY_CONTROL_REPORT AnyControlReport;
     };
@@ -814,7 +814,7 @@
     ULONG ApiNumber;
     ULONG Status;
     union
-       {
+    {
         ULONG64 ReserveSpace[7];
         DBGKD_CREATE_FILE CreateFile;
         DBGKD_READ_FILE ReadFile;
@@ -843,7 +843,7 @@
 {
     ULONG ApiNumber;
     union
-       {
+    {
         DBGKD_REQUEST_BREAKPOINT RequestBreakpoint;
         DBGKD_RELEASE_BREAKPOINT ReleaseBreakpoint;
     } u;

Modified: trunk/reactos/ntoskrnl/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/CMakeLists.txt?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/CMakeLists.txt       [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/CMakeLists.txt       [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -363,6 +363,7 @@
 if(NOT _WINKD_)
     if(ARCH STREQUAL "i386")
         list(APPEND SOURCE
+            kd/i386/kdbg.c
             kd/i386/kdmemsup.c
             kd/wrappers/gdbstub.c)
         if(KDBG)
@@ -372,6 +373,7 @@
     elseif(ARCH STREQUAL "amd64")
         list(APPEND SOURCE
             kd/amd64/kd.c
+            kd/i386/kdbg.c  # Use the x86 file
             kd/amd64/kdmemsup.c)
         if(KDBG)
             list(APPEND ASM_SOURCE kdbg/amd64/kdb_help.S)
@@ -379,6 +381,8 @@
                 kdbg/amd64/i386-dis.c
                 kdbg/amd64/kdb.c)
         endif()
+    elseif(ARCH STREQUAL "arm")
+        list(APPEND SOURCE kd/arm/kdbg.c)
     elseif(ARCH STREQUAL "powerpc")
         list(APPEND SOURCE kd/wrappers/gdbstub_powerpc.c)
     endif()

Modified: trunk/reactos/ntoskrnl/include/internal/kd.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/kd.h?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/kd.h        [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/kd.h        [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -1,4 +1,6 @@
 #pragma once
+
+#include <cportlib/cportlib.h>
 
 #ifdef _M_PPC
 #define KdDebuggerEnabled _KdDebuggerEnabled
@@ -8,15 +10,8 @@
 //
 // Kernel Debugger Port Definition
 //
-typedef struct _KD_PORT_INFORMATION
-{
-    ULONG ComPort;
-    ULONG BaudRate;
-    ULONG BaseAddress;
-} KD_PORT_INFORMATION, *PKD_PORT_INFORMATION;
-
 struct _KD_DISPATCH_TABLE;
-extern KD_PORT_INFORMATION GdbPortInfo;
+extern CPPORT GdbPortInfo;
 extern BOOLEAN _KdDebuggerEnabled;
 extern BOOLEAN _KdDebuggerNotPresent;
 extern BOOLEAN KdBreakAfterSymbolLoad;
@@ -25,41 +20,21 @@
 
 BOOLEAN
 NTAPI
-KdPortInitialize(
-    PKD_PORT_INFORMATION PortInformation,
-    ULONG Unknown1,
-    ULONG Unknown2
-);
-
-BOOLEAN
-NTAPI
 KdPortInitializeEx(
-    PKD_PORT_INFORMATION PortInformation,
-    ULONG Unknown1,
-    ULONG Unknown2
-);
-
-BOOLEAN
-NTAPI
-KdPortGetByte(
+    PCPPORT PortInformation,
+    ULONG ComPortNumber
+);
+
+BOOLEAN
+NTAPI
+KdPortGetByteEx(
+    PCPPORT PortInformation,
     PUCHAR ByteReceived);
 
-BOOLEAN
-NTAPI
-KdPortGetByteEx(
-    PKD_PORT_INFORMATION PortInformation,
-    PUCHAR ByteReceived);
-
-VOID
-NTAPI
-KdPortPutByte(
-    UCHAR ByteToSend
-);
-
 VOID
 NTAPI
 KdPortPutByteEx(
-    PKD_PORT_INFORMATION PortInformation,
+    PCPPORT PortInformation,
     UCHAR ByteToSend
 );
 
@@ -359,7 +334,8 @@
 extern ULONG KdpPort;
 
 /* Port Information for the Serial Native Mode */
-extern KD_PORT_INFORMATION SerialPortInfo;
+extern ULONG  SerialPortNumber;
+extern CPPORT SerialPortInfo;
 
 /* Init Functions for Native Providers */
 extern PKDP_INIT_ROUTINE InitRoutines[KdMax];

Modified: trunk/reactos/ntoskrnl/include/internal/tag.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/tag.h?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/tag.h       [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/tag.h       [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -95,10 +95,6 @@
 #define TAG_VPB    ' BPV'
 #define TAG_SYSB   'BSYS'
 
-/* formerly located in kdbg/kdb_symbols.c */
-#define TAG_KDBS 'SBDK'
-#define TAG_KDBG 'GBDK'
-
 /* formerly located in ldr/loader.c */
 #define TAG_DRIVER_MEM  'MVRD' /* drvm */
 #define TAG_MODULE_OBJECT 'omlk' /* klmo - kernel ldr module object */

Modified: trunk/reactos/ntoskrnl/kd/kdinit.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/kdinit.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/kd/kdinit.c  [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kd/kdinit.c  [iso-8859-1] Thu May  9 13:12:58 2013
@@ -16,7 +16,8 @@
 
 /* VARIABLES ***************************************************************/
 
-KD_PORT_INFORMATION PortInfo = {DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_BAUD_RATE, 
0};
+ULONG  PortNumber = DEFAULT_DEBUG_PORT;
+CPPORT PortInfo   = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
 ULONG KdpPortIrq;
 #ifdef AUTO_ENABLE_BOCHS
 KDP_DEBUG_MODE KdpDebugMode = {{{.Bochs=TRUE}}};
@@ -68,7 +69,7 @@
                 KdpDebugMode.Serial = TRUE;
 
                 /* Set the port to use */
-                SerialPortInfo.ComPort = Value;
+                SerialPortNumber = Value;
                 KdpPort = Value;
             }
         }
@@ -78,8 +79,8 @@
             if (Value)
             {
                 KdpDebugMode.Serial = TRUE;
-                SerialPortInfo.BaseAddress = Value;
-                SerialPortInfo.ComPort = 0;
+                SerialPortInfo.Address = UlongToPtr(Value);
+                SerialPortNumber = 0;
                 KdpPort = 0;
             }
         }

Modified: trunk/reactos/ntoskrnl/kd/kdio.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/kdio.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/kd/kdio.c    [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kd/kdio.c    [iso-8859-1] Thu May  9 13:12:58 2013
@@ -26,7 +26,8 @@
 ANSI_STRING KdpLogFileName = RTL_CONSTANT_STRING("\\SystemRoot\\debug.log");
 
 KSPIN_LOCK KdpSerialSpinLock;
-KD_PORT_INFORMATION SerialPortInfo = { DEFAULT_DEBUG_PORT, 
DEFAULT_DEBUG_BAUD_RATE, 0 };
+ULONG  SerialPortNumber = DEFAULT_DEBUG_PORT;
+CPPORT SerialPortInfo   = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
 
 /* Current Port in use. FIXME: Do we support more then one? */
 ULONG KdpPort;
@@ -358,12 +359,12 @@
         DispatchTable->KdpPrintRoutine = KdpSerialDebugPrint;
 
         /* Initialize the Port */
-        if (!KdPortInitializeEx(&SerialPortInfo, 0, 0))
+        if (!KdPortInitializeEx(&SerialPortInfo, SerialPortNumber))
         {
             KdpDebugMode.Serial = FALSE;
             return;
         }
-        KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress;
+        KdComPortInUse = SerialPortInfo.Address;
 
         /* Initialize spinlock */
         KeInitializeSpinLock(&KdpSerialSpinLock);

Modified: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c        [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kd/wrappers/gdbstub.c        [iso-8859-1] Thu May  9 
13:12:58 2013
@@ -44,7 +44,8 @@
 extern LIST_ENTRY PsActiveProcessHead;
 
 /* FIXME hardcoded for COM2, 115200 baud */
-KD_PORT_INFORMATION GdbPortInfo = { 2, 115200, 0 };
+ULONG  GdbPortNumber = DEFAULT_DEBUG_PORT;
+CPPORT GdbPortInfo   = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
 
 static CHAR GspInBuffer[1000];
 static CHAR GspOutBuffer[1000];
@@ -126,9 +127,7 @@
 {
     UCHAR Value;
 
-    while (!KdPortGetByteEx(&GdbPortInfo, &Value))
-        ;
-
+    while (!KdPortGetByteEx(&GdbPortInfo, &Value)) ;
     return Value;
 }
 
@@ -145,8 +144,7 @@
     while (TRUE)
     {
         /* wait around for the start character, ignore all other characters */
-        while ((ch = GdbGetChar()) != '$')
-            ;
+        while ((ch = GdbGetChar()) != '$') ;
 
 retry:
         Checksum = 0;
@@ -784,7 +782,6 @@
     }
     else if (strncmp(Request, "Rcmd,", 5) == 0)
     {
-        ;
     }
 }
 
@@ -943,12 +940,14 @@
     ULONG Index;
 
     for (Index = 0; Index < GspSwBreakpointCount; Index++)
+    {
         if (GspSwBreakpoints[Index].Address == Address)
         {
             if (PIndex)
                 *PIndex = Index;
             return TRUE;
         }
+    }
 
     return FALSE;
 }
@@ -1569,7 +1568,7 @@
         WrapperTable->KdpExceptionRoutine = KdpGdbEnterDebuggerException;
 
         /* Initialize the Port */
-        KdPortInitializeEx(&GdbPortInfo, 0, 0);
+        KdPortInitializeEx(&GdbPortInfo, GdbPortNumber);
     }
     else if (BootPhase == 1)
     {

Modified: trunk/reactos/ntoskrnl/kd/wrappers/gdbstub_powerpc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/wrappers/gdbstub_powerpc.c?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/kd/wrappers/gdbstub_powerpc.c        [iso-8859-1] 
(original)
+++ trunk/reactos/ntoskrnl/kd/wrappers/gdbstub_powerpc.c        [iso-8859-1] 
Thu May  9 13:12:58 2013
@@ -88,44 +88,47 @@
 #include <debug.h>
 
 /************************************************************************/
+
+static BOOLEAN GspInitialized;
+static BOOLEAN GspRemoteDebug;
+
+static CONST CHAR HexChars[]="0123456789abcdef";
+
+static PETHREAD GspRunThread; /* NULL means run all threads */
+static PETHREAD GspDbgThread;
+static PETHREAD GspEnumThread;
+
+static FAST_MUTEX GspLock;
+
+extern LIST_ENTRY PsActiveProcessHead;
+
+/* FIXME hardcoded for COM2, 115200 baud */
+ULONG  GdbPortNumber = DEFAULT_DEBUG_PORT;
+CPPORT GdbPortInfo   = {0, DEFAULT_DEBUG_BAUD_RATE, 0};
+
 /* BUFMAX defines the maximum number of characters in inbound/outbound 
buffers*/
 /* at least NUMREGBYTES*2 are needed for register packets */
 #define BUFMAX 1000
-
-static BOOLEAN GspInitialized;
-
-static BOOLEAN GspRemoteDebug;
-
-static CONST CHAR HexChars[]="0123456789abcdef";
-
-static PETHREAD GspRunThread; /* NULL means run all threads */
-static PETHREAD GspDbgThread;
-static PETHREAD GspEnumThread;
-
-static FAST_MUTEX GspLock;
-
-extern LIST_ENTRY PsActiveProcessHead;
-
-/* FIXME hardcoded for COM2, 115200 baud */
-KD_PORT_INFORMATION GdbPortInfo = { 2, 115200, 0 };
+static CHAR GspInBuffer[BUFMAX];
+static CHAR GspOutBuffer[BUFMAX];
 
 /* Number of Registers.  */
 #define NUMREGS 16
 
 enum REGISTER_NAMES
 {
-  EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
-  PC /* also known as eip */,
-  PS /* also known as eflags */,
-  CS, SS, DS, ES, FS, GS
+    EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
+    PC /* also known as eip */,
+    PS /* also known as eflags */,
+    CS, SS, DS, ES, FS, GS
 };
 
 typedef struct _CPU_REGISTER
 {
-  ULONG Size;
-  ULONG OffsetInTF;
-  ULONG OffsetInContext;
-  BOOLEAN SetInContext;
+    ULONG Size;
+    ULONG OffsetInTF;
+    ULONG OffsetInContext;
+    BOOLEAN SetInContext;
 } CPU_REGISTER, *PCPU_REGISTER;
 
 static CPU_REGISTER GspRegisters[NUMREGS] =
@@ -134,54 +137,45 @@
 
 static PCHAR GspThreadStates[DeferredReady+1] =
 {
-  "Initialized",
-  "Ready",
-  "Running",
-  "Standby",
-  "Terminated",
-  "Waiting",
-  "Transition",
-  "DeferredReady"
+    "Initialized",
+    "Ready",
+    "Running",
+    "Standby",
+    "Terminated",
+    "Waiting",
+    "Transition",
+    "DeferredReady"
 };
 
 
 LONG
 HexValue(CHAR ch)
 {
-  if ((ch >= '0') && (ch <= '9'))
-    {
-      return (ch - '0');
-    }
-  if ((ch >= 'a') && (ch <= 'f'))
-    {
-      return (ch - 'a' + 10);
-    }
-  if ((ch >= 'A') && (ch <= 'F'))
-    {
-      return (ch - 'A' + 10);
-    }
-
-  return -1;
-}
-
-static CHAR GspInBuffer[BUFMAX];
-static CHAR GspOutBuffer[BUFMAX];
+    if ((ch >= '0') && (ch <= '9'))
+        return (ch - '0');
+
+    if ((ch >= 'a') && (ch <= 'f'))
+        return (ch - 'a' + 10);
+
+    if ((ch >= 'A') && (ch <= 'F'))
+        return (ch - 'A' + 10);
+
+    return -1;
+}
 
 VOID
 GdbPutChar(UCHAR Value)
 {
-  KdPortPutByteEx(&GdbPortInfo, Value);
+    KdPortPutByteEx(&GdbPortInfo, Value);
 }
 
 UCHAR
 GdbGetChar(VOID)
 {
-  UCHAR Value;
-
-  while (!KdPortGetByteEx(&GdbPortInfo, &Value))
-    ;
-
-  return Value;
+    UCHAR Value;
+
+    while (!KdPortGetByteEx(&GdbPortInfo, &Value)) ;
+    return Value;
 }
 
 /* scan for the sequence $<data>#<Checksum>     */
@@ -189,57 +183,53 @@
 PCHAR
 GspGetPacket()
 {
-  PCHAR Buffer = &GspInBuffer[0];
-  CHAR Checksum;
-  CHAR XmitChecksum;
-  ULONG Count;
-  CHAR ch;
-
-  while (TRUE)
-    {
-      /* wait around for the start character, ignore all other characters */
-      while ((ch = GdbGetChar ()) != '$')
-        ;
-
-    retry:
-      Checksum = 0;
-      XmitChecksum = -1;
-      Count = 0;
-
-      /* now, read until a # or end of Buffer is found */
-      while (Count < BUFMAX)
-        {
-          ch = GdbGetChar();
-          if (ch == '$')
-            {
-              goto retry;
-            }
-          if (ch == '#')
-            {
-              break;
-            }
-          Checksum = Checksum + ch;
-          Buffer[Count] = ch;
-          Count = Count + 1;
-        }
-      Buffer[Count] = 0;
-
-      if (ch == '#')
-        {
-          ch = GdbGetChar();
-          XmitChecksum = (CHAR)(HexValue(ch) << 4);
-          ch = GdbGetChar();
-          XmitChecksum += (CHAR)(HexValue(ch));
-
-          if (Checksum != XmitChecksum)
-            {
-              GdbPutChar('-'); /* failed checksum */
-            }
-          else
-            {
-              GdbPutChar('+'); /* successful transfer */
-
-              return &Buffer[0];
+    PCHAR Buffer = &GspInBuffer[0];
+    CHAR Checksum;
+    CHAR XmitChecksum;
+    ULONG Count;
+    CHAR ch;
+
+    while (TRUE)
+    {
+        /* wait around for the start character, ignore all other characters */
+        while ((ch = GdbGetChar ()) != '$') ;
+
+retry:
+        Checksum = 0;
+        XmitChecksum = -1;
+        Count = 0;
+
+        /* now, read until a # or end of Buffer is found */
+        while (Count < BUFMAX)
+        {
+            ch = GdbGetChar();
+            if (ch == '$')
+                goto retry;
+
+            if (ch == '#')
+                break;
+
+            Checksum = Checksum + ch;
+            Buffer[Count] = ch;
+            Count = Count + 1;
+        }
+        Buffer[Count] = 0;
+
+        if (ch == '#')
+        {
+            ch = GdbGetChar();
+            XmitChecksum = (CHAR)(HexValue(ch) << 4);
+            ch = GdbGetChar();
+            XmitChecksum += (CHAR)(HexValue(ch));
+
+            if (Checksum != XmitChecksum)
+            {
+                GdbPutChar('-'); /* failed checksum */
+            }
+            else
+            {
+                GdbPutChar('+'); /* successful transfer */
+                return &Buffer[0];
             }
         }
     }
@@ -250,54 +240,54 @@
 VOID
 GspPutPacket(PCHAR Buffer)
 {
-  CHAR Checksum;
-  LONG Count;
-  CHAR ch;
-
-  /*  $<packet info>#<Checksum>. */
-  do
-    {
-      GdbPutChar('$');
-      Checksum = 0;
-      Count = 0;
-
-      while ((ch = Buffer[Count]))
-        {
-          GdbPutChar(ch);
-          Checksum += ch;
-          Count += 1;
-        }
-
-      GdbPutChar('#');
-      GdbPutChar(HexChars[(Checksum >> 4) & 0xf]);
-      GdbPutChar(HexChars[Checksum & 0xf]);
-    }
-  while (GdbGetChar() != '+');
+    CHAR Checksum;
+    LONG Count;
+    CHAR ch;
+
+    /*  $<packet info>#<Checksum>. */
+    do
+    {
+        GdbPutChar('$');
+        Checksum = 0;
+        Count = 0;
+
+        while ((ch = Buffer[Count]))
+        {
+            GdbPutChar(ch);
+            Checksum += ch;
+            Count += 1;
+        }
+
+        GdbPutChar('#');
+        GdbPutChar(HexChars[(Checksum >> 4) & 0xf]);
+        GdbPutChar(HexChars[Checksum & 0xf]);
+    }
+    while (GdbGetChar() != '+');
 }
 
 
 VOID
 GspPutPacketNoWait(PCHAR Buffer)
 {
-  CHAR Checksum;
-  LONG Count;
-  CHAR ch;
-
-  /*  $<packet info>#<Checksum>. */
-  GdbPutChar('$');
-  Checksum = 0;
-  Count = 0;
-
-  while ((ch = Buffer[Count]))
-    {
-      GdbPutChar(ch);
-      Checksum += ch;
-      Count += 1;
-    }
-
-  GdbPutChar('#');
-  GdbPutChar(HexChars[(Checksum >> 4) & 0xf]);
-  GdbPutChar(HexChars[Checksum & 0xf]);
+    CHAR Checksum;
+    LONG Count;
+    CHAR ch;
+
+    /*  $<packet info>#<Checksum>. */
+    GdbPutChar('$');
+    Checksum = 0;
+    Count = 0;
+
+    while ((ch = Buffer[Count]))
+    {
+        GdbPutChar(ch);
+        Checksum += ch;
+        Count += 1;
+    }
+
+    GdbPutChar('#');
+    GdbPutChar(HexChars[(Checksum >> 4) & 0xf]);
+    GdbPutChar(HexChars[Checksum & 0xf]);
 }
 
 /* Indicate to caller of GspMem2Hex or GspHex2Mem that there has been an
@@ -308,19 +298,33 @@
 static CHAR
 GspReadMemSafe(PCHAR Address)
 {
-  CHAR ch;
-
-  if (NULL == Address)
-    {
-      GspMemoryError = TRUE;
-      return '\0';
-    }
-
-  GspAccessLocation = Address;
-  ch = *Address;
-  GspAccessLocation = NULL;
-
-  return ch;
+    CHAR ch;
+
+    if (NULL == Address)
+    {
+        GspMemoryError = TRUE;
+        return '\0';
+    }
+
+    GspAccessLocation = Address;
+    ch = *Address;
+    GspAccessLocation = NULL;
+
+    return ch;
+}
+
+static CHAR
+GspWriteMemSafeGetContent(PVOID Context, ULONG Offset)
+{
+    ASSERT(0 == Offset);
+    return *((PCHAR) Context);
+}
+
+static void
+GspWriteMemSafe(PCHAR Address,
+                CHAR Ch)
+{
+    GspWriteMem(Address, 1, TRUE, GspWriteMemSafeGetContent, &Ch);
 }
 
 /* Convert the memory pointed to by Address into hex, placing result in Buffer 
*/
@@ -329,131 +333,110 @@
    a fault; if FALSE treat a fault like any other fault in the stub.  */
 static PCHAR
 GspMem2Hex(PCHAR Address,
-  PCHAR Buffer,
-  LONG Count,
-  BOOLEAN MayFault)
-{
-  ULONG i;
-  CHAR ch;
-
-  for (i = 0; i < (ULONG) Count; i++)
-    {
-      if (MayFault)
-        {
-          ch = GspReadMemSafe(Address);
-          if (GspMemoryError)
-            {
-              return Buffer;
-            }
-        }
-      else
-        {
-          ch = *Address;
-        }
-      *Buffer++ = HexChars[(ch >> 4) & 0xf];
-      *Buffer++ = HexChars[ch & 0xf];
-      Address++;
-    }
-
-  *Buffer = 0;
-  return Buffer;
+           PCHAR Buffer,
+           LONG Count,
+           BOOLEAN MayFault)
+{
+    ULONG i;
+    CHAR ch;
+
+    for (i = 0; i < (ULONG) Count; i++)
+    {
+        if (MayFault)
+        {
+            ch = GspReadMemSafe(Address);
+            if (GspMemoryError)
+                return Buffer;
+        }
+        else
+        {
+            ch = *Address;
+        }
+        *Buffer++ = HexChars[(ch >> 4) & 0xf];
+        *Buffer++ = HexChars[ch & 0xf];
+        Address++;
+    }
+
+    *Buffer = 0;
+    return Buffer;
 }
 
 static ULONG
 GspWriteMem(PCHAR Address,
-  ULONG Count,
-  BOOLEAN MayFault,
-  CHAR (*GetContent)(PVOID Context, ULONG Offset),
-  PVOID Context)
-{
-  PCHAR Current;
-  PCHAR Page;
-  ULONG CountInPage;
-  ULONG i;
-  CHAR ch;
-  ULONG OldProt = 0;
-
-  Current = Address;
-  while (Current < Address + Count)
-    {
-      Page = (PCHAR)PAGE_ROUND_DOWN(Current);
-      if (Address + Count <= Page + PAGE_SIZE)
-        {
-          /* Fits in this page */
-          CountInPage = Count;
-        }
-      else
-        {
-          /* Flows into next page, handle only current page in this iteration 
*/
-          CountInPage = PAGE_SIZE - (Address - Page);
-        }
-      if (MayFault)
-        {
-          OldProt = MmGetPageProtect(NULL, Address);
-          MmSetPageProtect(NULL, Address, PAGE_EXECUTE_READWRITE);
-        }
-
-      for (i = 0; i < CountInPage && ! GspMemoryError; i++)
-        {
-          ch = (*GetContent)(Context, Current - Address);
-
-          if (MayFault)
-            {
-              GspAccessLocation = Current;
-            }
-          *Current = ch;
-          if (MayFault)
-            {
-              GspAccessLocation = NULL;
-            }
-          Current++;
-        }
-      if (MayFault)
-        {
-          MmSetPageProtect(NULL, Page, OldProt);
-          if (GspMemoryError)
-            {
-              return Current - Address;
-            }
-        }
-    }
-
-  return Current - Address;
+            ULONG Count,
+            BOOLEAN MayFault,
+            CHAR (*GetContent)(PVOID Context, ULONG Offset),
+            PVOID Context)
+{
+    PCHAR Current;
+    PCHAR Page;
+    ULONG CountInPage;
+    ULONG i;
+    CHAR ch;
+    ULONG OldProt = 0;
+
+    Current = Address;
+    while (Current < Address + Count)
+    {
+        Page = (PCHAR)PAGE_ROUND_DOWN(Current);
+        if (Address + Count <= Page + PAGE_SIZE)
+        {
+            /* Fits in this page */
+            CountInPage = Count;
+        }
+        else
+        {
+            /* Flows into next page, handle only current page in this 
iteration */
+            CountInPage = PAGE_SIZE - (Address - Page);
+        }
+        if (MayFault)
+        {
+            OldProt = MmGetPageProtect(NULL, Address);
+            MmSetPageProtect(NULL, Address, PAGE_EXECUTE_READWRITE);
+        }
+
+        for (i = 0; i < CountInPage && ! GspMemoryError; i++)
+        {
+            ch = (*GetContent)(Context, Current - Address);
+
+            if (MayFault)
+                GspAccessLocation = Current;
+
+            *Current = ch;
+
+            if (MayFault)
+                GspAccessLocation = NULL;
+
+            Current++;
+        }
+        if (MayFault)
+        {
+            MmSetPageProtect(NULL, Page, OldProt);
+            if (GspMemoryError)
+                return Current - Address;
+        }
+    }
+
+    return Current - Address;
 }
 
 static CHAR
 GspHex2MemGetContent(PVOID Context, ULONG Offset)
 {
-  return (CHAR)((HexValue(*((PCHAR) Context + 2 * Offset)) << 4) +
-                HexValue(*((PCHAR) Context + 2 * Offset + 1)));
+    return (CHAR)((HexValue(*((PCHAR) Context + 2 * Offset)) << 4) +
+                   HexValue(*((PCHAR) Context + 2 * Offset + 1)));
 }
 
 /* Convert the hex array pointed to by Buffer into binary to be placed at 
Address */
 /* Return a pointer to the character AFTER the last byte read from Buffer */
 static PCHAR
 GspHex2Mem(PCHAR Buffer,
-  PCHAR Address,
-  ULONG Count,
-  BOOLEAN MayFault)
-{
-  Count = GspWriteMem(Address, Count, MayFault, GspHex2MemGetContent, Buffer);
-
-  return Buffer + 2 * Count;
-}
-
-static CHAR
-GspWriteMemSafeGetContent(PVOID Context, ULONG Offset)
-{
-  ASSERT(0 == Offset);
-
-  return *((PCHAR) Context);
-}
-
-static void
-GspWriteMemSafe(PCHAR Address,
-  CHAR Ch)
-{
-  GspWriteMem(Address, 1, TRUE, GspWriteMemSafeGetContent, &Ch);
+           PCHAR Address,
+           ULONG Count,
+           BOOLEAN MayFault)
+{
+    Count = GspWriteMem(Address, Count, MayFault, GspHex2MemGetContent, 
Buffer);
+    return Buffer + 2 * Count;
 }
 
 
@@ -462,33 +445,38 @@
 ULONG
 GspComputeSignal(NTSTATUS ExceptionCode)
 {
-  ULONG SigVal;
-
-  switch (ExceptionCode)
-    {
-    case STATUS_INTEGER_DIVIDE_BY_ZERO:
-      SigVal = 8; /* divide by zero */
-      break;
-    case STATUS_SINGLE_STEP:
-    case STATUS_BREAKPOINT:
-      SigVal = 5; /* breakpoint */
-      break;
-    case STATUS_INTEGER_OVERFLOW:
-    case STATUS_ARRAY_BOUNDS_EXCEEDED:
-      SigVal = 16; /* bound instruction */
-      break;
-    case STATUS_ILLEGAL_INSTRUCTION:
-      SigVal = 4; /* Invalid opcode */
-      break;
-    case STATUS_STACK_OVERFLOW:
-    case STATUS_DATATYPE_MISALIGNMENT:
-    case STATUS_ACCESS_VIOLATION:
-      SigVal = 11; /* access violation */
-      break;
-    default:
-      SigVal = 7; /* "software generated" */
-    }
-  return SigVal;
+    ULONG SigVal;
+
+    switch (ExceptionCode)
+    {
+        case STATUS_INTEGER_DIVIDE_BY_ZERO:
+            SigVal = 8; /* divide by zero */
+            break;
+
+        case STATUS_SINGLE_STEP:
+        case STATUS_BREAKPOINT:
+            SigVal = 5; /* breakpoint */
+            break;
+
+        case STATUS_INTEGER_OVERFLOW:
+        case STATUS_ARRAY_BOUNDS_EXCEEDED:
+            SigVal = 16; /* bound instruction */
+            break;
+
+        case STATUS_ILLEGAL_INSTRUCTION:
+            SigVal = 4; /* Invalid opcode */
+            break;
+
+        case STATUS_STACK_OVERFLOW:
+        case STATUS_DATATYPE_MISALIGNMENT:
+        case STATUS_ACCESS_VIOLATION:
+            SigVal = 11; /* access violation */
+            break;
+
+        default:
+            SigVal = 7; /* "software generated" */
+    }
+    return SigVal;
 }
 
 
@@ -1626,43 +1614,39 @@
 BOOLEAN
 NTAPI
 GspBreakIn(PKINTERRUPT Interrupt,
-  PVOID ServiceContext)
-{
-  PKTRAP_FRAME TrapFrame;
-  BOOLEAN DoBreakIn;
-  CONTEXT Context;
-  KIRQL OldIrql;
-  UCHAR Value;
-
-  DPRINT("Break In\n");
-
-  DoBreakIn = FALSE;
-  while (KdPortGetByteEx(&GdbPortInfo, &Value))
-    {
-      if (Value == 0x03)
-        {
-          DoBreakIn = TRUE;
-        }
-    }
-
-  if (!DoBreakIn)
-    {
-      return TRUE;
-    }
-
-  KeRaiseIrql(HIGH_LEVEL, &OldIrql);
-
-  TrapFrame = PsGetCurrentThread()->Tcb.TrapFrame;
-
-  KeTrapFrameToContext(TrapFrame, NULL, &Context);
-
-  KdpGdbEnterDebuggerException(NULL, &Context, TrapFrame);
-
-  KeContextToTrapFrame(&Context, NULL, TrapFrame, Context.ContextFlags, 
KernelMode);
-
-  KeLowerIrql(OldIrql);
-
-  return TRUE;
+           PVOID ServiceContext)
+{
+    PKTRAP_FRAME TrapFrame;
+    BOOLEAN DoBreakIn;
+    CONTEXT Context;
+    KIRQL OldIrql;
+    UCHAR Value;
+
+    DPRINT("Break In\n");
+
+    DoBreakIn = FALSE;
+    while (KdPortGetByteEx(&GdbPortInfo, &Value))
+    {
+        if (Value == 0x03)
+            DoBreakIn = TRUE;
+    }
+
+    if (!DoBreakIn)
+        return TRUE;
+
+    KeRaiseIrql(HIGH_LEVEL, &OldIrql);
+
+    TrapFrame = PsGetCurrentThread()->Tcb.TrapFrame;
+
+    KeTrapFrameToContext(TrapFrame, NULL, &Context);
+
+    KdpGdbEnterDebuggerException(NULL, &Context, TrapFrame);
+
+    KeContextToTrapFrame(&Context, NULL, TrapFrame, Context.ContextFlags, 
KernelMode);
+
+    KeLowerIrql(OldIrql);
+
+    return TRUE;
 }
 
 VOID
@@ -1677,39 +1661,36 @@
 KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable,
                ULONG BootPhase)
 {
-  if (!KdDebuggerEnabled || !KdpDebugMode.Gdb)
-    {
-      return;
-    }
-
-  if (BootPhase == 0)
-    {
-      ExInitializeFastMutex(&GspLock);
-
-      /* Write out the functions that we support for now */
-      WrapperTable->KdpInitRoutine = KdpGdbStubInit;
-      WrapperTable->KdpPrintRoutine = KdpGdbDebugPrint;
-      WrapperTable->KdpExceptionRoutine = KdpGdbEnterDebuggerException;
-
-      /* Initialize the Port */
-      KdPortInitializeEx(&GdbPortInfo, 0, 0);
-
-      KdpPort = GdbPortInfo.ComPort;
-    }
-  else if (BootPhase == 1)
-    {
-      GspInitialized = TRUE;
-
-      GspRunThread = NULL;
-      GspDbgThread = NULL;
-      GspEnumThread = NULL;
-
-      HalDisplayString("Waiting for GDB to attach\n");
-      DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
-    }
-  else if (BootPhase == 2)
-    {
-      HalDisplayString("\n   GDB debugging enabled\n\n");
+    if (!KdDebuggerEnabled || !KdpDebugMode.Gdb)
+        return;
+
+    if (BootPhase == 0)
+    {
+        ExInitializeFastMutex(&GspLock);
+
+        /* Write out the functions that we support for now */
+        WrapperTable->KdpInitRoutine = KdpGdbStubInit;
+        WrapperTable->KdpPrintRoutine = KdpGdbDebugPrint;
+        WrapperTable->KdpExceptionRoutine = KdpGdbEnterDebuggerException;
+
+        /* Initialize the Port */
+        KdPortInitializeEx(&GdbPortInfo, GdbPortNumber);
+        // KdpPort = GdbPortInfo.ComPort;
+    }
+    else if (BootPhase == 1)
+    {
+        GspInitialized = TRUE;
+
+        GspRunThread = NULL;
+        GspDbgThread = NULL;
+        GspEnumThread = NULL;
+
+        HalDisplayString("Waiting for GDB to attach\n");
+        DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
+    }
+    else if (BootPhase == 2)
+    {
+        HalDisplayString("\n   GDB debugging enabled\n\n");
     }
 }
 

Modified: trunk/reactos/ntoskrnl/kdbg/kdb.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb.h?rev=58974&r1=58973&r2=58974&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/kdbg/kdb.h   [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kdbg/kdb.h   [iso-8859-1] Thu May  9 13:12:58 2013
@@ -5,6 +5,10 @@
 #ifndef RTL_NUMBER_OF
 # define RTL_NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
 #endif
+
+/* formerly located in kdbg/kdb_symbols.c */
+#define TAG_KDBS 'SBDK'
+#define TAG_KDBG 'GBDK'
 
 /* TYPES *********************************************************************/
 


Reply via email to