ReactOS  r75214
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

PCHAR NTAPI INIT_FUNCTION KdpGetDebugMode (PCHAR Currentp2)
 
VOID NTAPI INIT_FUNCTION 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
 
BOOLEAN KdpEarlyBreak = FALSE
 
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}
 
KD_DISPATCH_TABLE DispatchTable [KdMax]
 
PKDP_INIT_ROUTINE InitRoutines [KdMax]
 
ANSI_STRING KdpLogFileName
 

Macro Definition Documentation

#define NDEBUG

Definition at line 11 of file kdinit.c.

Function Documentation

BOOLEAN NTAPI KdInitSystem ( ULONG  BootPhase,
PLOADER_PARAMETER_BLOCK  LoaderBlock 
)

Definition at line 174 of file kdinit.c.

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

176 {
177  ULONG Value;
178  ULONG i;
179  PCHAR CommandLine, Port, BaudRate, Irq;
180 
181  /* Set Default Port Options */
182  if (BootPhase == 0)
183  {
184  /* Get the Command Line */
185  CommandLine = LoaderBlock->LoadOptions;
186 
187  /* Upcase it */
188  _strupr(CommandLine);
189 
190  /* XXX Check for settings that we support */
191  if (strstr(CommandLine, "BREAK")) KdpEarlyBreak = TRUE;
192  if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE;
193  else if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE;
194  else if (strstr(CommandLine, "DEBUG"))
195  {
196  /* Enable the kernel debugger */
199 #ifdef KDBG
200  /* Get the KDBG Settings */
202 #endif
203  }
204 
205  /* Let user-mode know our state */
206  SharedUserData->KdDebuggerEnabled = KdDebuggerEnabled;
207 
208  /* Get the port and baud rate */
209  Port = strstr(CommandLine, "DEBUGPORT");
210  BaudRate = strstr(CommandLine, "BAUDRATE");
211  Irq = strstr(CommandLine, "IRQ");
212 
213  /* Check if we got the /DEBUGPORT parameter(s) */
214  while (Port)
215  {
216  /* Move past the actual string, to reach the port*/
217  Port += sizeof("DEBUGPORT") - 1;
218 
219  /* Now get past any spaces and skip the equal sign */
220  while (*Port == ' ') Port++;
221  Port++;
222 
223  /* Get the debug mode and wrapper */
224  Port = KdpGetDebugMode(Port);
225  Port = strstr(Port, "DEBUGPORT");
226  }
227 
228  /* Use serial port then */
229  if (KdDebuggerEnabled && KdpDebugMode.Value == 0)
230  KdpDebugMode.Serial = TRUE;
231 
232  /* Check if we got a baud rate */
233  if (BaudRate)
234  {
235  /* Move past the actual string, to reach the rate */
236  BaudRate += sizeof("BAUDRATE") - 1;
237 
238  /* Now get past any spaces */
239  while (*BaudRate == ' ') BaudRate++;
240 
241  /* And make sure we have a rate */
242  if (*BaudRate)
243  {
244  /* Read and set it */
245  Value = atol(BaudRate + 1);
247  }
248  }
249 
250  /* Check Serial Port Settings [IRQ] */
251  if (Irq)
252  {
253  /* Move past the actual string, to reach the rate */
254  Irq += sizeof("IRQ") - 1;
255 
256  /* Now get past any spaces */
257  while (*Irq == ' ') Irq++;
258 
259  /* And make sure we have an IRQ */
260  if (*Irq)
261  {
262  /* Read and set it */
263  Value = atol(Irq + 1);
264  if (Value) KdpPortIrq = Value;
265  }
266  }
267 
268  /* Call Providers at Phase 0 */
269  for (i = 0; i < KdMax; i++)
270  {
271  InitRoutines[i](&DispatchTable[i], 0);
272  }
273 
274  /* Call Wrapper at Phase 0 */
276  return TRUE;
277  }
278  else /* BootPhase > 0 */
279  {
280 #ifdef _M_IX86
282 #endif
283  }
284 
285  /* Call the Initialization Routines of the Registered Providers */
286  KdpCallInitRoutine(BootPhase);
287 
288  /* Return success */
289  return TRUE;
290 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
VOID NTAPI KdpEnableSafeMem(VOID)
Definition: kdmemsup.c:212
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
VOID NTAPI INIT_FUNCTION KdpCallInitRoutine(ULONG BootPhase)
Definition: kdinit.c:146
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
VOID NTAPI INIT_FUNCTION KdbpGetCommandLineSettings(PCHAR p1)
Definition: kdb.c:1731
BOOLEAN KdpEarlyBreak
Definition: kdinit.c:29
CPPORT PortInfo
Definition: kdinit.c:20
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
KD_DISPATCH_TABLE DispatchTable[KdMax]
Definition: kdinit.c:31
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
PKDP_INIT_ROUTINE InitRoutines[KdMax]
Definition: kdinit.c:33
ULONG KdpPortIrq
Definition: kdinit.c:21
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define SharedUserData
UINTN UINT8 Value
Definition: acefiex.h:725
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:31
signed char * PCHAR
Definition: retypes.h:7
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:46
BOOLEAN KdDebuggerNotPresent
Definition: kdmain.c:18
VOID NTAPI INIT_FUNCTION KdpCallInitRoutine ( ULONG  BootPhase)

Definition at line 146 of file kdinit.c.

Referenced by KdInitSystem().

147 {
148  PLIST_ENTRY CurrentEntry;
149  PKD_DISPATCH_TABLE CurrentTable;
150 
151  /* Call the registered handlers */
152  CurrentEntry = KdProviders.Flink;
153  while (CurrentEntry != &KdProviders)
154  {
155  /* Get the current table */
156  CurrentTable = CONTAINING_RECORD(CurrentEntry,
157  KD_DISPATCH_TABLE,
158  KdProvidersList);
159 
160  /* Call it */
161  CurrentTable->KdpInitRoutine(CurrentTable, BootPhase);
162 
163  /* Next Table */
164  CurrentEntry = CurrentEntry->Flink;
165  }
166 
167  /* Call the Wrapper Init Routine */
168  if (WrapperInitRoutine)
169  WrapperTable.KdpInitRoutine(&WrapperTable, BootPhase);
170 }
LIST_ENTRY KdProviders
Definition: kdinit.c:30
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
PKDP_INIT_ROUTINE WrapperInitRoutine
Definition: kdinit.c:27
KD_DISPATCH_TABLE WrapperTable
Definition: kdinit.c:28
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
PCHAR NTAPI INIT_FUNCTION KdpGetDebugMode ( PCHAR  Currentp2)

Definition at line 46 of file kdinit.c.

Referenced by KdInitSystem().

47 {
48  PCHAR p1, p2 = Currentp2;
49  ULONG Value;
50 
51  /* Check for Screen Debugging */
52  if (!_strnicmp(p2, "SCREEN", 6))
53  {
54  /* Enable It */
55  p2 += 6;
56  KdpDebugMode.Screen = TRUE;
57  }
58  /* Check for Serial Debugging */
59  else if (!_strnicmp(p2, "COM", 3))
60  {
61  /* Gheck for a valid Serial Port */
62  p2 += 3;
63  if (*p2 != ':')
64  {
65  Value = (ULONG)atol(p2);
66  if (Value > 0 && Value < 5)
67  {
68  /* Valid port found, enable Serial Debugging */
69  KdpDebugMode.Serial = TRUE;
70 
71  /* Set the port to use */
73  KdpPort = Value;
74  }
75  }
76  else
77  {
78  Value = strtoul(p2 + 1, NULL, 0);
79  if (Value)
80  {
81  KdpDebugMode.Serial = TRUE;
83  SerialPortNumber = 0;
84  KdpPort = 0;
85  }
86  }
87  }
88 
89  /* Check for Debug Log Debugging */
90  else if (!_strnicmp(p2, "FILE", 4))
91  {
92  /* Enable It */
93  p2 += 4;
94  KdpDebugMode.File = TRUE;
95  if (*p2 == ':')
96  {
97  p2++;
98  p1 = p2;
99  while (*p2 != '\0' && *p2 != ' ') p2++;
102  }
103  }
104 
105  /* Check for BOCHS Debugging */
106  else if (!_strnicmp(p2, "BOCHS", 5))
107  {
108  /* Enable It */
109  p2 += 5;
110  KdpDebugMode.Bochs = TRUE;
111  }
112 
113  /* Check for GDB Debugging */
114  else if (!_strnicmp(p2, "GDB", 3))
115  {
116  /* Enable it */
117  p2 += 3;
118  KdpDebugMode.Gdb = TRUE;
119 
120  /* Enable Debugging */
123  SharedUserData->KdDebuggerEnabled = TRUE;
125  }
126 
127  /* Check for PICE Debugging */
128  else if (!_strnicmp(p2, "PICE", 4))
129  {
130  /* Enable it */
131  p2 += 4;
132  KdpDebugMode.Pice = TRUE;
133 
134  /* Enable Debugging */
137  SharedUserData->KdDebuggerEnabled = TRUE;
138  }
139 
140  return p2;
141 }
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
KDP_DEBUG_MODE KdpDebugMode
Definition: kdinit.c:25
VOID NTAPI KdpGdbStubInit(PKD_DISPATCH_TABLE WrapperTable, ULONG BootPhase)
Definition: kd.c:19
ANSI_STRING KdpLogFileName
Definition: kdio.c:27
const GLfloat * p2
Definition: s_aatritemp.h:44
#define FALSE
Definition: types.h:117
ULONG KdpPort
Definition: kdio.c:34
_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)
smooth NULL
Definition: ftsmooth.c:513
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define UlongToPtr(ul)
Definition: basetsd.h:97
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define SharedUserData
UINTN UINT8 Value
Definition: acefiex.h:725
PUCHAR Address
Definition: cportlib.h:29
PKDP_INIT_ROUTINE WrapperInitRoutine
Definition: kdinit.c:27
CPPORT SerialPortInfo
Definition: kdio.c:31
ULONG SerialPortNumber
Definition: kdio.c:30
signed char * PCHAR
Definition: retypes.h:7
unsigned int ULONG
Definition: retypes.h:1
const GLfloat * p1
Definition: s_aatritemp.h:43
BOOLEAN KdDebuggerNotPresent
Definition: kdmain.c:18

Variable Documentation

KD_DISPATCH_TABLE DispatchTable[KdMax]

Definition at line 31 of file kdinit.c.

Referenced by KdInitSystem().

PKDP_INIT_ROUTINE InitRoutines[KdMax]
Initial value:
VOID NTAPI KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:357
VOID NTAPI INIT_FUNCTION KdpInitDebugLog(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdio.c:211
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:521
VOID NTAPI KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase)
Definition: kdbg.c:21

Definition at line 33 of file kdinit.c.

Referenced by KdInitSystem().

BOOLEAN KdpEarlyBreak = FALSE

Definition at line 29 of file kdinit.c.

Referenced by KdInitSystem().

ANSI_STRING KdpLogFileName

Definition at line 27 of file kdio.c.

ULONG KdpPortIrq

Definition at line 21 of file kdinit.c.

Referenced by KdInitSystem().

LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}
CPPORT PortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0}

Definition at line 20 of file kdinit.c.

Referenced by AcpiHwValidateIoRequest().

Definition at line 19 of file kdinit.c.

Referenced by USBHI_CreateUsbDevice(), and WinLdrInitializeHeadlessPort().

PKDP_INIT_ROUTINE WrapperInitRoutine
KD_DISPATCH_TABLE WrapperTable