Merge my current work done on the kd++ branch:
[reactos.git] / reactos / ntoskrnl / kd / kdinit.c
index 5fcc0ee..7a455a8 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
-#if defined (ALLOC_PRAGMA)
-#pragma alloc_text(INIT, KdInitSystem)
-#endif
-
-
 /* Make bochs debug output in the very early boot phase available */
 //#define AUTO_ENABLE_BOCHS
 
 /* 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}}};
@@ -40,13 +36,16 @@ PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit,
                                          KdpBochsInit,
                                          KdpKdbgInit};
 
+extern ANSI_STRING KdpLogFileName;
+
 /* PRIVATE FUNCTIONS *********************************************************/
 
 PCHAR
 NTAPI
+INIT_FUNCTION
 KdpGetDebugMode(PCHAR Currentp2)
 {
-    PCHAR p2 = Currentp2;
+    PCHAR p1, p2 = Currentp2;
     ULONG Value;
 
     /* Check for Screen Debugging */
@@ -61,23 +60,46 @@ KdpGetDebugMode(PCHAR Currentp2)
     {
         /* Gheck for a valid Serial Port */
         p2 += 3;
-        Value = (ULONG)atol(p2);
-        if (Value > 0 && Value < 5)
+        if (*p2 != ':')
         {
-            /* Valid port found, enable Serial Debugging */
-            KdpDebugMode.Serial = TRUE;
+            Value = (ULONG)atol(p2);
+            if (Value > 0 && Value < 5)
+            {
+                /* Valid port found, enable Serial Debugging */
+                KdpDebugMode.Serial = TRUE;
 
-            /* Set the port to use */
-            SerialPortInfo.ComPort = Value;
-            KdpPort = Value;
+                /* Set the port to use */
+                SerialPortNumber = Value;
+                KdpPort = Value;
+            }
+        }
+        else
+        {
+            Value = strtoul(p2 + 1, NULL, 0);
+            if (Value)
+            {
+                KdpDebugMode.Serial = TRUE;
+                SerialPortInfo.Address = UlongToPtr(Value);
+                SerialPortNumber = 0;
+                KdpPort = 0;
+            }
         }
     }
+
     /* Check for Debug Log Debugging */
     else if (!_strnicmp(p2, "FILE", 4))
     {
         /* Enable It */
         p2 += 4;
         KdpDebugMode.File = TRUE;
+        if (*p2 == ':')
+        {
+            p2++;
+            p1 = p2;
+            while (*p2 != '\0' && *p2 != ' ') p2++;
+            KdpLogFileName.MaximumLength = KdpLogFileName.Length = p2 - p1;
+            KdpLogFileName.Buffer = p1;
+        }
     }
 
     /* Check for BOCHS Debugging */
@@ -118,6 +140,7 @@ KdpGetDebugMode(PCHAR Currentp2)
 
 VOID
 NTAPI
+INIT_FUNCTION
 KdpCallInitRoutine(ULONG BootPhase)
 {
     PLIST_ENTRY CurrentEntry;
@@ -145,7 +168,6 @@ KdpCallInitRoutine(ULONG BootPhase)
 }
 
 BOOLEAN
-INIT_FUNCTION
 NTAPI
 KdInitSystem(ULONG BootPhase,
              PLOADER_PARAMETER_BLOCK LoaderBlock)
@@ -169,11 +191,9 @@ KdInitSystem(ULONG BootPhase,
         else if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE;
         else if (strstr(CommandLine, "DEBUG"))
         {
-            /* Enable on the serial port */
+            /* Enable the kernel debugger */
             KdDebuggerEnabled = TRUE;
             KdDebuggerNotPresent = FALSE;
-            KdpDebugMode.Serial = TRUE;
-
 #ifdef KDBG
             /* Get the KDBG Settings */
             KdbpGetCommandLineSettings(LoaderBlock->LoadOptions);
@@ -200,6 +220,10 @@ KdInitSystem(ULONG BootPhase,
             Port = strstr(Port, "DEBUGPORT");
         }
 
+        /* Use serial port then */
+        if (KdDebuggerEnabled && KdpDebugMode.Value == 0)
+            KdpDebugMode.Serial = TRUE;
+
         /* Check if we got a baud rate */
         if (BaudRate)
         {