ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

kdinit.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Kernel
00004  * FILE:            ntoskrnl/kd/kdinit.c
00005  * PURPOSE:         Kernel Debugger Initializtion
00006  *
00007  * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
00008  */
00009 
00010 #include <ntoskrnl.h>
00011 #define NDEBUG
00012 #include <debug.h>
00013 
00014 /* Make bochs debug output in the very early boot phase available */
00015 //#define AUTO_ENABLE_BOCHS
00016 
00017 /* VARIABLES ***************************************************************/
00018 
00019 KD_PORT_INFORMATION PortInfo = {DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_BAUD_RATE, 0};
00020 ULONG KdpPortIrq;
00021 #ifdef AUTO_ENABLE_BOCHS
00022 KDP_DEBUG_MODE KdpDebugMode = {{{.Bochs=TRUE}}};
00023 #else
00024 KDP_DEBUG_MODE KdpDebugMode;
00025 #endif
00026 PKDP_INIT_ROUTINE WrapperInitRoutine;
00027 KD_DISPATCH_TABLE WrapperTable;
00028 BOOLEAN KdpEarlyBreak = FALSE;
00029 LIST_ENTRY KdProviders = {&KdProviders, &KdProviders};
00030 KD_DISPATCH_TABLE DispatchTable[KdMax];
00031 
00032 PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit,
00033                                          KdpSerialInit,
00034                                          KdpInitDebugLog,
00035                                          KdpBochsInit,
00036                                          KdpKdbgInit};
00037 
00038 extern ANSI_STRING KdpLogFileName;
00039 
00040 /* PRIVATE FUNCTIONS *********************************************************/
00041 
00042 PCHAR
00043 NTAPI
00044 INIT_FUNCTION
00045 KdpGetDebugMode(PCHAR Currentp2)
00046 {
00047     PCHAR p1, p2 = Currentp2;
00048     ULONG Value;
00049 
00050     /* Check for Screen Debugging */
00051     if (!_strnicmp(p2, "SCREEN", 6))
00052     {
00053         /* Enable It */
00054         p2 += 6;
00055         KdpDebugMode.Screen = TRUE;
00056     }
00057     /* Check for Serial Debugging */
00058     else if (!_strnicmp(p2, "COM", 3))
00059     {
00060         /* Gheck for a valid Serial Port */
00061         p2 += 3;
00062         if (*p2 != ':')
00063         {
00064             Value = (ULONG)atol(p2);
00065             if (Value > 0 && Value < 5)
00066             {
00067                 /* Valid port found, enable Serial Debugging */
00068                 KdpDebugMode.Serial = TRUE;
00069 
00070                 /* Set the port to use */
00071                 SerialPortInfo.ComPort = Value;
00072                 KdpPort = Value;
00073             }
00074         }
00075         else
00076         {
00077             Value = strtoul(p2 + 1, NULL, 0);
00078             if (Value)
00079             {
00080                 KdpDebugMode.Serial = TRUE;
00081                 SerialPortInfo.BaseAddress = Value;
00082                 SerialPortInfo.ComPort = 0;
00083                 KdpPort = 0;
00084             }
00085         }
00086     }
00087 
00088     /* Check for Debug Log Debugging */
00089     else if (!_strnicmp(p2, "FILE", 4))
00090     {
00091         /* Enable It */
00092         p2 += 4;
00093         KdpDebugMode.File = TRUE;
00094         if (*p2 == ':')
00095         {
00096             p2++;
00097             p1 = p2;
00098             while (*p2 != '\0' && *p2 != ' ') p2++;
00099             KdpLogFileName.MaximumLength = KdpLogFileName.Length = p2 - p1;
00100             KdpLogFileName.Buffer = p1;
00101         }
00102     }
00103 
00104     /* Check for BOCHS Debugging */
00105     else if (!_strnicmp(p2, "BOCHS", 5))
00106     {
00107         /* Enable It */
00108         p2 += 5;
00109         KdpDebugMode.Bochs = TRUE;
00110     }
00111 
00112     /* Check for GDB Debugging */
00113     else if (!_strnicmp(p2, "GDB", 3))
00114     {
00115         /* Enable it */
00116         p2 += 3;
00117         KdpDebugMode.Gdb = TRUE;
00118 
00119         /* Enable Debugging */
00120         KdDebuggerEnabled = TRUE;
00121         KdDebuggerNotPresent = FALSE;
00122         WrapperInitRoutine = KdpGdbStubInit;
00123     }
00124 
00125     /* Check for PICE Debugging */
00126     else if (!_strnicmp(p2, "PICE", 4))
00127     {
00128         /* Enable it */
00129         p2 += 4;
00130         KdpDebugMode.Pice = TRUE;
00131 
00132         /* Enable Debugging */
00133         KdDebuggerEnabled = TRUE;
00134         KdDebuggerNotPresent = FALSE;
00135     }
00136 
00137     return p2;
00138 }
00139 
00140 VOID
00141 NTAPI
00142 INIT_FUNCTION
00143 KdpCallInitRoutine(ULONG BootPhase)
00144 {
00145     PLIST_ENTRY CurrentEntry;
00146     PKD_DISPATCH_TABLE CurrentTable;
00147 
00148     /* Call the registered handlers */
00149     CurrentEntry = KdProviders.Flink;
00150     while (CurrentEntry != &KdProviders)
00151     {
00152         /* Get the current table */
00153         CurrentTable = CONTAINING_RECORD(CurrentEntry,
00154                                          KD_DISPATCH_TABLE,
00155                                          KdProvidersList);
00156 
00157         /* Call it */
00158         CurrentTable->KdpInitRoutine(CurrentTable, BootPhase);
00159 
00160         /* Next Table */
00161         CurrentEntry = CurrentEntry->Flink;
00162     }
00163 
00164     /* Call the Wrapper Init Routine */
00165     if (WrapperInitRoutine)
00166         WrapperTable.KdpInitRoutine(&WrapperTable, BootPhase);
00167 }
00168 
00169 BOOLEAN
00170 NTAPI
00171 KdInitSystem(ULONG BootPhase,
00172              PLOADER_PARAMETER_BLOCK LoaderBlock)
00173 {
00174     ULONG Value;
00175     ULONG i;
00176     PCHAR CommandLine, Port, BaudRate, Irq;
00177 
00178     /* Set Default Port Options */
00179     if (BootPhase == 0)
00180     {
00181         /* Get the Command Line */
00182         CommandLine = LoaderBlock->LoadOptions;
00183 
00184         /* Upcase it */
00185         _strupr(CommandLine);
00186 
00187         /* XXX Check for settings that we support */
00188         if (strstr(CommandLine, "BREAK")) KdpEarlyBreak = TRUE;
00189         if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE;
00190         else if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE;
00191         else if (strstr(CommandLine, "DEBUG"))
00192         {
00193             /* Enable the kernel debugger */
00194             KdDebuggerEnabled = TRUE;
00195             KdDebuggerNotPresent = FALSE;
00196 #ifdef KDBG
00197             /* Get the KDBG Settings */
00198             KdbpGetCommandLineSettings(LoaderBlock->LoadOptions);
00199 #endif
00200         }
00201 
00202         /* Get the port and baud rate */
00203         Port = strstr(CommandLine, "DEBUGPORT");
00204         BaudRate = strstr(CommandLine, "BAUDRATE");
00205         Irq = strstr(CommandLine, "IRQ");
00206 
00207         /* Check if we got the /DEBUGPORT parameter(s) */
00208         while (Port)
00209         {
00210             /* Move past the actual string, to reach the port*/
00211             Port += sizeof("DEBUGPORT") - 1;
00212 
00213             /* Now get past any spaces and skip the equal sign */
00214             while (*Port == ' ') Port++;
00215             Port++;
00216 
00217             /* Get the debug mode and wrapper */
00218             Port = KdpGetDebugMode(Port);
00219             Port = strstr(Port, "DEBUGPORT");
00220         }
00221 
00222         /* Use serial port then */
00223         if (KdDebuggerEnabled && KdpDebugMode.Value == 0)
00224             KdpDebugMode.Serial = TRUE;
00225 
00226         /* Check if we got a baud rate */
00227         if (BaudRate)
00228         {
00229             /* Move past the actual string, to reach the rate */
00230             BaudRate += sizeof("BAUDRATE") - 1;
00231 
00232             /* Now get past any spaces */
00233             while (*BaudRate == ' ') BaudRate++;
00234 
00235             /* And make sure we have a rate */
00236             if (*BaudRate)
00237             {
00238                 /* Read and set it */
00239                 Value = atol(BaudRate + 1);
00240                 if (Value) PortInfo.BaudRate = SerialPortInfo.BaudRate = Value;
00241             }
00242         }
00243 
00244         /* Check Serial Port Settings [IRQ] */
00245         if (Irq)
00246         {
00247             /* Move past the actual string, to reach the rate */
00248             Irq += sizeof("IRQ") - 1;
00249 
00250             /* Now get past any spaces */
00251             while (*Irq == ' ') Irq++;
00252 
00253             /* And make sure we have an IRQ */
00254             if (*Irq)
00255             {
00256                 /* Read and set it */
00257                 Value = atol(Irq + 1);
00258                 if (Value) KdpPortIrq = Value;
00259             }
00260         }
00261 
00262         /* Call Providers at Phase 0 */
00263         for (i = 0; i < KdMax; i++)
00264         {
00265             InitRoutines[i](&DispatchTable[i], 0);
00266         }
00267 
00268         /* Call Wrapper at Phase 0 */
00269         if (WrapperInitRoutine) WrapperInitRoutine(&WrapperTable, 0);
00270         return TRUE;
00271     }
00272     else /* BootPhase > 0 */
00273     {
00274 #ifdef _M_IX86
00275         KdpEnableSafeMem();
00276 #endif
00277     }
00278 
00279     /* Call the Initialization Routines of the Registered Providers */
00280     KdpCallInitRoutine(BootPhase);
00281 
00282     /* Return success */
00283     return TRUE;
00284 }
00285 
00286 /* EOF */

Generated on Sun May 27 2012 04:37:19 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.