ReactOS  0.4.15-dev-980-ge160524
kdinit.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdinit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

INIT_FUNCTION PCHAR NTAPI KdpGetDebugMode (PCHAR Currentp2)
 
INIT_FUNCTION VOID NTAPI KdpCallInitRoutine (ULONG BootPhase)
 
BOOLEAN NTAPI KdInitSystem (ULONG BootPhase, PLOADER_PARAMETER_BLOCK LoaderBlock)
 

Variables

ULONG PortNumber = DEFAULT_DEBUG_PORT
 
CPPORT PortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0}
 
ULONG KdpPortIrq
 
KDP_DEBUG_MODE KdpDebugMode
 
PKDP_INIT_ROUTINE WrapperInitRoutine
 
KD_DISPATCH_TABLE WrapperTable
 
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}
 
KD_DISPATCH_TABLE DispatchTable [KdMax]
 
PKDP_INIT_ROUTINE InitRoutines [KdMax]
 
ANSI_STRING KdpLogFileName
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file kdinit.c.

Function Documentation

◆ KdInitSystem()

BOOLEAN NTAPI KdInitSystem ( ULONG  BootPhase,
PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 169 of file kdinit.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
CPPORT Port[4]
Definition: headless.c:34
INIT_FUNCTION PCHAR NTAPI KdpGetDebugMode(PCHAR Currentp2)
Definition: kdinit.c:45
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
#define TRUE
Definition: types.h:120
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
CPPORT PortInfo
Definition: kdinit.c:20
IN UCHAR Value
Definition: halp.h:394
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
#define FALSE
Definition: types.h:117
KD_DISPATCH_TABLE DispatchTable[KdMax]
Definition: kdinit.c:30
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:48
VOID NTAPI KdbpGetCommandLineSettings(PCHAR p1)
Definition: kdb.c:1696
PKDP_INIT_ROUTINE InitRoutines[KdMax]
Definition: kdinit.c:32
INIT_FUNCTION VOID NTAPI KdpCallInitRoutine(ULONG BootPhase)
Definition: kdinit.c:141
ULONG KdpPortIrq
Definition: kdinit.c:21
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define SharedUserData
PKDP_INIT_ROUTINE WrapperInitRoutine
Definition: kdinit.c:27
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
ULONG BaudRate
Definition: cportlib.h:30
CPPORT SerialPortInfo
Definition: kdio.c:32
KD_DISPATCH_TABLE WrapperTable
Definition: kdinit.c:28
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN KdDebuggerNotPresent
Definition: kdmain.c:50

Referenced by IoInitSystem(), KeEnterKernelDebugger(), KiInitializeSystem(), KiSystemStartup(), KiSystemStartupReal(), and Phase1InitializationDiscard().

◆ KdpCallInitRoutine()

INIT_FUNCTION VOID NTAPI KdpCallInitRoutine ( ULONG  BootPhase)

Definition at line 141 of file kdinit.c.

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 }
LIST_ENTRY KdProviders
Definition: kdinit.c:29
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: typedefs.h:119
PKDP_INIT_ROUTINE WrapperInitRoutine
Definition: kdinit.c:27
KD_DISPATCH_TABLE WrapperTable
Definition: kdinit.c:28

Referenced by KdInitSystem().

◆ KdpGetDebugMode()

INIT_FUNCTION PCHAR NTAPI KdpGetDebugMode ( PCHAR  Currentp2)

Definition at line 45 of file kdinit.c.

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 }
signed char * PCHAR
Definition: retypes.h:7
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
#define TRUE
Definition: types.h:120
VOID NTAPI KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable, ULONG BootPhase)
Definition: kd.c:19
ANSI_STRING KdpLogFileName
Definition: kdio.c:28
IN UCHAR Value
Definition: halp.h:394
#define FALSE
Definition: types.h:117
ULONG KdpPort
Definition: kdio.c:35
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:48
#define UlongToPtr(u)
Definition: config.h:106
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define SharedUserData
PUCHAR Address
Definition: cportlib.h:29
PKDP_INIT_ROUTINE WrapperInitRoutine
Definition: kdinit.c:27
CPPORT SerialPortInfo
Definition: kdio.c:32
ULONG SerialPortNumber
Definition: kdio.c:31
unsigned int ULONG
Definition: retypes.h:1
BOOLEAN KdDebuggerNotPresent
Definition: kdmain.c:50

Referenced by KdInitSystem().

Variable Documentation

◆ DispatchTable

KD_DISPATCH_TABLE DispatchTable[KdMax]

Definition at line 30 of file kdinit.c.

Referenced by KdInitSystem().

◆ InitRoutines

PKDP_INIT_ROUTINE InitRoutines[KdMax]
Initial value:
VOID NTAPI KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdbg.c:21
VOID NTAPI KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:374
VOID NTAPI KdpBochsInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: bochs.c:39
VOID NTAPI KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:545
VOID NTAPI KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:248

Definition at line 32 of file kdinit.c.

Referenced by KdInitSystem().

◆ KdpDebugMode

◆ KdpLogFileName

ANSI_STRING KdpLogFileName

Definition at line 28 of file kdio.c.

Referenced by KdpDebugLogInit(), and KdpGetDebugMode().

◆ KdpPortIrq

ULONG KdpPortIrq

Definition at line 21 of file kdinit.c.

Referenced by KdInitSystem().

◆ KdProviders

LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}

◆ PortInfo

CPPORT PortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0}

Definition at line 20 of file kdinit.c.

Referenced by AcpiHwValidateIoRequest(), and KdInitSystem().

◆ PortNumber

ULONG PortNumber = DEFAULT_DEBUG_PORT

Definition at line 19 of file kdinit.c.

◆ WrapperInitRoutine

PKDP_INIT_ROUTINE WrapperInitRoutine

◆ WrapperTable

KD_DISPATCH_TABLE WrapperTable