ReactOS  0.4.14-dev-342-gdc047f9
kdinit.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Kernel
4  * FILE: ntoskrnl/kd/kdinit.c
5  * PURPOSE: Kernel Debugger Initializtion
6  *
7  * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8  */
9 
10 #include <ntoskrnl.h>
11 #define NDEBUG
12 #include <debug.h>
13 
14 /* Make bochs debug output in the very early boot phase available */
15 //#define AUTO_ENABLE_BOCHS
16 
17 /* VARIABLES ***************************************************************/
18 
22 #ifdef AUTO_ENABLE_BOCHS
23 KDP_DEBUG_MODE KdpDebugMode = {{{.Bochs=TRUE}}};
24 #else
25 KDP_DEBUG_MODE KdpDebugMode;
26 #endif
27 PKDP_INIT_ROUTINE WrapperInitRoutine;
28 KD_DISPATCH_TABLE WrapperTable;
30 KD_DISPATCH_TABLE DispatchTable[KdMax];
31 
32 PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit,
36  KdpKdbgInit};
37 
39 
40 /* PRIVATE FUNCTIONS *********************************************************/
41 
42 PCHAR
43 NTAPI
44 INIT_FUNCTION
46 {
47  PCHAR p1, p2 = Currentp2;
48  ULONG Value;
49 
50  /* Check for Screen Debugging */
51  if (!_strnicmp(p2, "SCREEN", 6))
52  {
53  /* Enable It */
54  p2 += 6;
55  KdpDebugMode.Screen = TRUE;
56  }
57  /* Check for Serial Debugging */
58  else if (!_strnicmp(p2, "COM", 3))
59  {
60  /* Gheck for a valid Serial Port */
61  p2 += 3;
62  if (*p2 != ':')
63  {
64  Value = (ULONG)atol(p2);
65  if (Value > 0 && Value < 5)
66  {
67  /* Valid port found, enable Serial Debugging */
68  KdpDebugMode.Serial = TRUE;
69 
70  /* Set the port to use */
72  KdpPort = Value;
73  }
74  }
75  else
76  {
77  Value = strtoul(p2 + 1, NULL, 0);
78  if (Value)
79  {
80  KdpDebugMode.Serial = TRUE;
82  SerialPortNumber = 0;
83  KdpPort = 0;
84  }
85  }
86  }
87  /* Check for Debug Log Debugging */
88  else if (!_strnicmp(p2, "FILE", 4))
89  {
90  /* Enable It */
91  p2 += 4;
92  KdpDebugMode.File = TRUE;
93  if (*p2 == ':')
94  {
95  p2++;
96  p1 = p2;
97  while (*p2 != '\0' && *p2 != ' ') p2++;
100  }
101  }
102  /* Check for BOCHS Debugging */
103  else if (!_strnicmp(p2, "BOCHS", 5))
104  {
105  /* Enable It */
106  p2 += 5;
107  KdpDebugMode.Bochs = TRUE;
108  }
109  /* Check for GDB Debugging */
110  else if (!_strnicmp(p2, "GDB", 3))
111  {
112  /* Enable it */
113  p2 += 3;
114  KdpDebugMode.Gdb = TRUE;
115 
116  /* Enable Debugging */
119  SharedUserData->KdDebuggerEnabled = TRUE;
121  }
122  /* Check for PICE Debugging */
123  else if (!_strnicmp(p2, "PICE", 4))
124  {
125  /* Enable it */
126  p2 += 4;
127  KdpDebugMode.Pice = TRUE;
128 
129  /* Enable Debugging */
132  SharedUserData->KdDebuggerEnabled = TRUE;
133  }
134 
135  return p2;
136 }
137 
138 VOID
139 NTAPI
140 INIT_FUNCTION
142 {
143  PLIST_ENTRY CurrentEntry;
144  PKD_DISPATCH_TABLE CurrentTable;
145 
146  /* Call the registered handlers */
147  CurrentEntry = KdProviders.Flink;
148  while (CurrentEntry != &KdProviders)
149  {
150  /* Get the current table */
151  CurrentTable = CONTAINING_RECORD(CurrentEntry,
152  KD_DISPATCH_TABLE,
153  KdProvidersList);
154 
155  /* Call it */
156  CurrentTable->KdpInitRoutine(CurrentTable, BootPhase);
157 
158  /* Next Table */
159  CurrentEntry = CurrentEntry->Flink;
160  }
161 
162  /* Call the Wrapper Init Routine */
163  if (WrapperInitRoutine)
164  WrapperTable.KdpInitRoutine(&WrapperTable, BootPhase);
165 }
166 
167 BOOLEAN
168 NTAPI
169 KdInitSystem(ULONG BootPhase,
170  PLOADER_PARAMETER_BLOCK LoaderBlock)
171 {
172  ULONG Value;
173  ULONG i;
174  PCHAR CommandLine, Port = NULL, BaudRate = NULL, Irq = NULL;
175 
176  /* Set Default Port Options */
177  if (BootPhase == 0)
178  {
179  /* Check if we have a loader block */
180  if (LoaderBlock)
181  {
182  /* Check if we have a command line */
183  CommandLine = LoaderBlock->LoadOptions;
184  if (CommandLine)
185  {
186  /* Upcase it */
187  _strupr(CommandLine);
188 
189  /* XXX Check for settings that we support */
190  if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE;
191  else if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE;
192  else if (strstr(CommandLine, "DEBUG"))
193  {
194  /* Enable the kernel debugger */
197 #ifdef KDBG
198  /* Get the KDBG Settings */
200 #endif
201  }
202 
203  /* Get the port and baud rate */
204  Port = strstr(CommandLine, "DEBUGPORT");
205  BaudRate = strstr(CommandLine, "BAUDRATE");
206  Irq = strstr(CommandLine, "IRQ");
207  }
208  else
209  {
210  /* No command line options? Disable debugger by default */
212  }
213  }
214  else
215  {
216  /* Called from a bugcheck or a re-enable. Unconditionally enable KD */
218  }
219 
220  /* Let user-mode know our state */
221  SharedUserData->KdDebuggerEnabled = KdDebuggerEnabled;
222 
223  /* Check if we got the /DEBUGPORT parameter(s) */
224  while (Port)
225  {
226  /* Move past the actual string, to reach the port*/
227  Port += sizeof("DEBUGPORT") - 1;
228 
229  /* Now get past any spaces and skip the equal sign */
230  while (*Port == ' ') Port++;
231  Port++;
232 
233  /* Get the debug mode and wrapper */
235  Port = strstr(Port, "DEBUGPORT");
236  }
237 
238  /* Use serial port then */
239  if (KdDebuggerEnabled && KdpDebugMode.Value == 0)
240  KdpDebugMode.Serial = TRUE;
241 
242  /* Check if we got a baud rate */
243  if (BaudRate)
244  {
245  /* Move past the actual string, to reach the rate */
246  BaudRate += sizeof("BAUDRATE") - 1;
247 
248  /* Now get past any spaces */
249  while (*BaudRate == ' ') BaudRate++;
250 
251  /* And make sure we have a rate */
252  if (*BaudRate)
253  {
254  /* Read and set it */
255  Value = atol(BaudRate + 1);
257  }
258  }
259 
260  /* Check Serial Port Settings [IRQ] */
261  if (Irq)
262  {
263  /* Move past the actual string, to reach the rate */
264  Irq += sizeof("IRQ") - 1;
265 
266  /* Now get past any spaces */
267  while (*Irq == ' ') Irq++;
268 
269  /* And make sure we have an IRQ */
270  if (*Irq)
271  {
272  /* Read and set it */
273  Value = atol(Irq + 1);
274  if (Value) KdpPortIrq = Value;
275  }
276  }
277 
278  /* Call Providers at Phase 0 */
279  for (i = 0; i < KdMax; i++)
280  {
281  InitRoutines[i](&DispatchTable[i], 0);
282  }
283 
284  /* Call Wrapper at Phase 0 */
286  return TRUE;
287  }
288  else /* BootPhase > 0 */
289  {
290  }
291 
292  /* Call the Initialization Routines of the Registered Providers */
293  KdpCallInitRoutine(BootPhase);
294 
295  /* Return success */
296  return TRUE;
297 }
298 
299 /* EOF */
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
signed char * PCHAR
Definition: retypes.h:7
CPPORT Port[4]
Definition: headless.c:34
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
VOID NTAPI KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdbg.c:21
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
VOID NTAPI INIT_FUNCTION KdpCallInitRoutine(ULONG BootPhase)
Definition: kdinit.c:141
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
VOID NTAPI INIT_FUNCTION KdbpGetCommandLineSettings(PCHAR p1)
Definition: kdb.c:1704
VOID NTAPI KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable, ULONG BootPhase)
Definition: kd.c:19
VOID NTAPI KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:364
CPPORT PortInfo
Definition: kdinit.c:20
ANSI_STRING KdpLogFileName
Definition: kdio.c:27
VOID NTAPI INIT_FUNCTION KdpInitDebugLog(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:224
BOOLEAN NTAPI KdInitSystem(ULONG BootPhase, PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:169
VOID NTAPI KdpBochsInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: bochs.c:39
LIST_ENTRY KdProviders
Definition: kdinit.c:29
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VOID NTAPI KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:521
ULONG KdpPort
Definition: kdio.c:34
KD_DISPATCH_TABLE DispatchTable[KdMax]
Definition: kdinit.c:30
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
#define DEFAULT_DEBUG_PORT
Definition: kdcom.c:18
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define UlongToPtr(u)
Definition: config.h:106
PKDP_INIT_ROUTINE InitRoutines[KdMax]
Definition: kdinit.c:32
USHORT MaximumLength
Definition: env_spec_w32.h:377
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define DEFAULT_DEBUG_BAUD_RATE
Definition: kdcom.c:21
ULONG KdpPortIrq
Definition: kdinit.c:21
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define SharedUserData
Definition: typedefs.h:117
PUCHAR Address
Definition: cportlib.h:29
PKDP_INIT_ROUTINE WrapperInitRoutine
Definition: kdinit.c:27
ULONG PortNumber
Definition: kdinit.c:19
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
ULONG BaudRate
Definition: cportlib.h:30
CPPORT SerialPortInfo
Definition: kdio.c:31
ULONG SerialPortNumber
Definition: kdio.c:30
KD_DISPATCH_TABLE WrapperTable
Definition: kdinit.c:28
unsigned int ULONG
Definition: retypes.h:1
PCHAR NTAPI INIT_FUNCTION KdpGetDebugMode(PCHAR Currentp2)
Definition: kdinit.c:45
BOOLEAN KdDebuggerNotPresent
Definition: kdmain.c:18