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 *********************************************************/
47 KdpGetDebugMode(PCHAR Currentp2
)
52 /* Check for Screen Debugging */
53 if (!_strnicmp(p2
, "SCREEN", 6))
57 KdpDebugMode
.Screen
= TRUE
;
59 /* Check for Serial Debugging */
60 else if (!_strnicmp(p2
, "COM", 3))
62 /* Gheck for a valid Serial Port */
64 Value
= (ULONG
)atol(p2
);
65 if (Value
> 0 && Value
< 5)
67 /* Valid port found, enable Serial Debugging */
68 KdpDebugMode
.Serial
= TRUE
;
70 /* Set the port to use */
71 SerialPortInfo
.ComPort
= Value
;
75 /* Check for Debug Log Debugging */
76 else if (!_strnicmp(p2
, "FILE", 4))
80 KdpDebugMode
.File
= TRUE
;
83 /* Check for BOCHS Debugging */
84 else if (!_strnicmp(p2
, "BOCHS", 5))
88 KdpDebugMode
.Bochs
= TRUE
;
91 /* Check for GDB Debugging */
92 else if (!_strnicmp(p2
, "GDB", 3))
96 KdpDebugMode
.Gdb
= TRUE
;
98 /* Enable Debugging */
99 KdDebuggerEnabled
= TRUE
;
100 KdDebuggerNotPresent
= FALSE
;
101 WrapperInitRoutine
= KdpGdbStubInit
;
104 /* Check for PICE Debugging */
105 else if (!_strnicmp(p2
, "PICE", 4))
109 KdpDebugMode
.Pice
= TRUE
;
111 /* Enable Debugging */
112 KdDebuggerEnabled
= TRUE
;
113 KdDebuggerNotPresent
= FALSE
;
121 KdpCallInitRoutine(ULONG BootPhase
)
123 PLIST_ENTRY CurrentEntry
;
124 PKD_DISPATCH_TABLE CurrentTable
;
126 /* Call the registered handlers */
127 CurrentEntry
= KdProviders
.Flink
;
128 while (CurrentEntry
!= &KdProviders
)
130 /* Get the current table */
131 CurrentTable
= CONTAINING_RECORD(CurrentEntry
,
136 CurrentTable
->KdpInitRoutine(CurrentTable
, BootPhase
);
139 CurrentEntry
= CurrentEntry
->Flink
;
142 /* Call the Wrapper Init Routine */
143 if (WrapperInitRoutine
)
144 WrapperTable
.KdpInitRoutine(&WrapperTable
, BootPhase
);
150 KdInitSystem(ULONG BootPhase
,
151 PLOADER_PARAMETER_BLOCK LoaderBlock
)
155 PCHAR CommandLine
, Port
, BaudRate
, Irq
;
157 /* Set Default Port Options */
160 /* Get the Command Line */
161 CommandLine
= LoaderBlock
->LoadOptions
;
164 _strupr(CommandLine
);
166 /* XXX Check for settings that we support */
167 if (strstr(CommandLine
, "BREAK")) KdpEarlyBreak
= TRUE
;
168 if (strstr(CommandLine
, "NODEBUG")) KdDebuggerEnabled
= FALSE
;
169 if (strstr(CommandLine
, "CRASHDEBUG")) KdDebuggerEnabled
= FALSE
;
170 if (strstr(CommandLine
, "DEBUG"))
172 /* Enable on the serial port */
173 KdDebuggerEnabled
= TRUE
;
174 KdpDebugMode
.Serial
= TRUE
;
178 /* Get the KDBG Settings and enable it */
179 KdDebuggerEnabled
= TRUE
;
180 KdDebuggerNotPresent
= FALSE
;
181 KdbpGetCommandLineSettings(LoaderBlock
->LoadOptions
);
184 /* Get the port and baud rate */
185 Port
= strstr(CommandLine
, "DEBUGPORT");
186 BaudRate
= strstr(CommandLine
, "BAUDRATE");
187 Irq
= strstr(CommandLine
, "IRQ");
189 /* Check if we got the /DEBUGPORT parameter(s) */
192 /* Move past the actual string, to reach the port*/
193 Port
+= sizeof("DEBUGPORT") - 1;
195 /* Now get past any spaces and skip the equal sign */
196 while (*Port
== ' ') Port
++;
199 /* Get the debug mode and wrapper */
200 Port
= KdpGetDebugMode(Port
);
201 Port
= strstr(Port
, "DEBUGPORT");
204 /* Check if we got a baud rate */
207 /* Move past the actual string, to reach the rate */
208 BaudRate
+= sizeof("BAUDRATE") - 1;
210 /* Now get past any spaces */
211 while (*BaudRate
== ' ') BaudRate
++;
213 /* And make sure we have a rate */
216 /* Read and set it */
217 Value
= atol(BaudRate
+ 1);
218 if (Value
) PortInfo
.BaudRate
= SerialPortInfo
.BaudRate
= Value
;
222 /* Check Serial Port Settings [IRQ] */
225 /* Move past the actual string, to reach the rate */
226 Irq
+= sizeof("IRQ") - 1;
228 /* Now get past any spaces */
229 while (*Irq
== ' ') Irq
++;
231 /* And make sure we have an IRQ */
234 /* Read and set it */
235 Value
= atol(Irq
+ 1);
236 if (Value
) KdpPortIrq
= Value
;
240 /* Call Providers at Phase 0 */
241 for (i
= 0; i
< KdMax
; i
++)
243 InitRoutines
[i
](&DispatchTable
[i
], 0);
246 /* Call Wrapper at Phase 0 */
247 if (WrapperInitRoutine
) WrapperInitRoutine(&WrapperTable
, 0);
250 else /* BootPhase > 0 */
257 /* Call the Initialization Routines of the Registered Providers */
258 KdpCallInitRoutine(BootPhase
);