2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/kd/kdinit.c
5 * PURPOSE: Kernel Debugger Initializtion
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
14 #if defined (ALLOC_PRAGMA)
15 #pragma alloc_text(INIT, KdInitSystem)
19 /* Make bochs debug output in the very early boot phase available */
20 //#define AUTO_ENABLE_BOCHS
22 /* VARIABLES ***************************************************************/
24 KD_PORT_INFORMATION PortInfo
= {DEFAULT_DEBUG_PORT
, DEFAULT_DEBUG_BAUD_RATE
, 0};
26 #ifdef AUTO_ENABLE_BOCHS
27 KDP_DEBUG_MODE KdpDebugMode
= {{{.Bochs
=TRUE
}}};
29 KDP_DEBUG_MODE KdpDebugMode
;
31 PKDP_INIT_ROUTINE WrapperInitRoutine
;
32 KD_DISPATCH_TABLE WrapperTable
;
33 BOOLEAN KdpEarlyBreak
= FALSE
;
34 LIST_ENTRY KdProviders
= {&KdProviders
, &KdProviders
};
35 KD_DISPATCH_TABLE DispatchTable
[KdMax
];
37 PKDP_INIT_ROUTINE InitRoutines
[KdMax
] = {KdpScreenInit
,
43 /* PRIVATE FUNCTIONS *********************************************************/
48 KdpGetDebugMode(PCHAR Currentp2
)
53 /* Check for Screen Debugging */
54 if (!_strnicmp(p2
, "SCREEN", 6))
58 KdpDebugMode
.Screen
= TRUE
;
60 /* Check for Serial Debugging */
61 else if (!_strnicmp(p2
, "COM", 3))
63 /* Gheck for a valid Serial Port */
65 Value
= (ULONG
)atol(p2
);
66 if (Value
> 0 && Value
< 5)
68 /* Valid port found, enable Serial Debugging */
69 KdpDebugMode
.Serial
= TRUE
;
71 /* Set the port to use */
72 SerialPortInfo
.ComPort
= Value
;
76 /* Check for Debug Log Debugging */
77 else if (!_strnicmp(p2
, "FILE", 4))
81 KdpDebugMode
.File
= TRUE
;
84 /* Check for BOCHS Debugging */
85 else if (!_strnicmp(p2
, "BOCHS", 5))
89 KdpDebugMode
.Bochs
= TRUE
;
92 /* Check for GDB Debugging */
93 else if (!_strnicmp(p2
, "GDB", 3))
97 KdpDebugMode
.Gdb
= TRUE
;
99 /* Enable Debugging */
100 KdDebuggerEnabled
= TRUE
;
101 KdDebuggerNotPresent
= FALSE
;
102 WrapperInitRoutine
= KdpGdbStubInit
;
105 /* Check for PICE Debugging */
106 else if (!_strnicmp(p2
, "PICE", 4))
110 KdpDebugMode
.Pice
= TRUE
;
112 /* Enable Debugging */
113 KdDebuggerEnabled
= TRUE
;
114 KdDebuggerNotPresent
= FALSE
;
123 KdpCallInitRoutine(ULONG BootPhase
)
125 PLIST_ENTRY CurrentEntry
;
126 PKD_DISPATCH_TABLE CurrentTable
;
128 /* Call the registered handlers */
129 CurrentEntry
= KdProviders
.Flink
;
130 while (CurrentEntry
!= &KdProviders
)
132 /* Get the current table */
133 CurrentTable
= CONTAINING_RECORD(CurrentEntry
,
138 CurrentTable
->KdpInitRoutine(CurrentTable
, BootPhase
);
141 CurrentEntry
= CurrentEntry
->Flink
;
144 /* Call the Wrapper Init Routine */
145 if (WrapperInitRoutine
)
146 WrapperTable
.KdpInitRoutine(&WrapperTable
, BootPhase
);
152 KdInitSystem(ULONG BootPhase
,
153 PLOADER_PARAMETER_BLOCK LoaderBlock
)
157 PCHAR CommandLine
, Port
, BaudRate
, Irq
;
159 /* Set Default Port Options */
162 /* Get the Command Line */
163 CommandLine
= LoaderBlock
->LoadOptions
;
166 _strupr(CommandLine
);
168 /* XXX Check for settings that we support */
169 if (strstr(CommandLine
, "BREAK")) KdpEarlyBreak
= TRUE
;
170 if (strstr(CommandLine
, "NODEBUG")) KdDebuggerEnabled
= FALSE
;
171 else if (strstr(CommandLine
, "CRASHDEBUG")) KdDebuggerEnabled
= FALSE
;
172 else if (strstr(CommandLine
, "DEBUG"))
174 /* Enable on the serial port */
175 KdDebuggerEnabled
= TRUE
;
176 KdDebuggerNotPresent
= FALSE
;
177 KdpDebugMode
.Serial
= TRUE
;
180 /* Get the KDBG Settings */
181 KdbpGetCommandLineSettings(LoaderBlock
->LoadOptions
);
185 /* Get the port and baud rate */
186 Port
= strstr(CommandLine
, "DEBUGPORT");
187 BaudRate
= strstr(CommandLine
, "BAUDRATE");
188 Irq
= strstr(CommandLine
, "IRQ");
190 /* Check if we got the /DEBUGPORT parameter(s) */
193 /* Move past the actual string, to reach the port*/
194 Port
+= sizeof("DEBUGPORT") - 1;
196 /* Now get past any spaces and skip the equal sign */
197 while (*Port
== ' ') Port
++;
200 /* Get the debug mode and wrapper */
201 Port
= KdpGetDebugMode(Port
);
202 Port
= strstr(Port
, "DEBUGPORT");
205 /* Check if we got a baud rate */
208 /* Move past the actual string, to reach the rate */
209 BaudRate
+= sizeof("BAUDRATE") - 1;
211 /* Now get past any spaces */
212 while (*BaudRate
== ' ') BaudRate
++;
214 /* And make sure we have a rate */
217 /* Read and set it */
218 Value
= atol(BaudRate
+ 1);
219 if (Value
) PortInfo
.BaudRate
= SerialPortInfo
.BaudRate
= Value
;
223 /* Check Serial Port Settings [IRQ] */
226 /* Move past the actual string, to reach the rate */
227 Irq
+= sizeof("IRQ") - 1;
229 /* Now get past any spaces */
230 while (*Irq
== ' ') Irq
++;
232 /* And make sure we have an IRQ */
235 /* Read and set it */
236 Value
= atol(Irq
+ 1);
237 if (Value
) KdpPortIrq
= Value
;
241 /* Call Providers at Phase 0 */
242 for (i
= 0; i
< KdMax
; i
++)
244 InitRoutines
[i
](&DispatchTable
[i
], 0);
247 /* Call Wrapper at Phase 0 */
248 if (WrapperInitRoutine
) WrapperInitRoutine(&WrapperTable
, 0);
251 else /* BootPhase > 0 */
258 /* Call the Initialization Routines of the Registered Providers */
259 KdpCallInitRoutine(BootPhase
);