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)
12 #include <internal/debug.h>
14 /* Make bochs debug output in the very early boot phase available */
15 //#define AUTO_ENABLE_BOCHS
17 /* VARIABLES ***************************************************************/
19 KD_PORT_INFORMATION PortInfo
= {DEFAULT_DEBUG_PORT
, DEFAULT_DEBUG_BAUD_RATE
, 0};
21 #ifdef AUTO_ENABLE_BOCHS
22 KDP_DEBUG_MODE KdpDebugMode
= {{{.Bochs
=TRUE
}}};;
23 PKDP_INIT_ROUTINE WrapperInitRoutine
= KdpBochsInit
;
24 KD_DISPATCH_TABLE WrapperTable
= {.KdpInitRoutine
= KdpBochsInit
, .KdpPrintRoutine
= KdpBochsDebugPrint
};
26 KDP_DEBUG_MODE KdpDebugMode
;
27 PKDP_INIT_ROUTINE WrapperInitRoutine
;
28 KD_DISPATCH_TABLE WrapperTable
;
30 BOOLEAN KdpEarlyBreak
= FALSE
;
31 LIST_ENTRY KdProviders
= {&KdProviders
, &KdProviders
};
32 KD_DISPATCH_TABLE DispatchTable
[KdMax
];
34 PKDP_INIT_ROUTINE InitRoutines
[KdMax
] = {KdpScreenInit
,
38 /* PRIVATE FUNCTIONS *********************************************************/
42 KdpGetWrapperDebugMode(PCHAR Currentp2
,
43 PLOADER_PARAMETER_BLOCK LoaderBlock
)
47 /* Check for BOCHS Debugging */
48 if (!_strnicmp(p2
, "BOCHS", 5))
52 KdpDebugMode
.Bochs
= TRUE
;
53 WrapperInitRoutine
= KdpBochsInit
;
56 /* Check for GDB Debugging */
57 if (!_strnicmp(p2
, "GDB", 3))
61 KdpDebugMode
.Gdb
= TRUE
;
63 /* Enable Debugging */
64 KdDebuggerEnabled
= TRUE
;
65 WrapperInitRoutine
= KdpGdbStubInit
;
68 /* Check for PICE Debugging */
69 else if (!_strnicmp(p2
, "PICE", 4))
73 KdpDebugMode
.Pice
= TRUE
;
75 /* Enable Debugging */
76 KdDebuggerEnabled
= TRUE
;
80 /* Get the KDBG Settings and enable it */
81 KdDebuggerEnabled
= TRUE
;
82 KdpDebugMode
.Gdb
= TRUE
;
83 KdbpGetCommandLineSettings((PCHAR
)LoaderBlock
->CommandLine
);
90 KdpGetDebugMode(PCHAR Currentp2
)
95 /* Check for Screen Debugging */
96 if (!_strnicmp(p2
, "SCREEN", 6))
100 KdpDebugMode
.Screen
= TRUE
;
102 /* Check for Serial Debugging */
103 else if (!_strnicmp(p2
, "COM", 3))
105 /* Gheck for a valid Serial Port */
107 Value
= (ULONG
)atol(p2
);
108 if (Value
> 0 && Value
< 5)
110 /* Valid port found, enable Serial Debugging */
111 KdpDebugMode
.Serial
= TRUE
;
113 /* Set the port to use */
114 SerialPortInfo
.ComPort
= Value
;
118 /* Check for Debug Log Debugging */
119 else if (!_strnicmp(p2
, "FILE", 4))
123 KdpDebugMode
.File
= TRUE
;
131 KdpCallInitRoutine(ULONG BootPhase
)
133 PLIST_ENTRY CurrentEntry
;
134 PKD_DISPATCH_TABLE CurrentTable
;
136 /* Call the registered handlers */
137 CurrentEntry
= KdProviders
.Flink
;
138 while (CurrentEntry
!= &KdProviders
)
140 /* Get the current table */
141 CurrentTable
= CONTAINING_RECORD(CurrentEntry
,
146 CurrentTable
->KdpInitRoutine(CurrentTable
, BootPhase
);
149 CurrentEntry
= CurrentEntry
->Flink
;
152 /* Call the Wrapper Init Routine */
153 if (WrapperInitRoutine
)
154 WrapperTable
.KdpInitRoutine(&WrapperTable
, BootPhase
);
159 KdInitSystem(ULONG BootPhase
,
160 PLOADER_PARAMETER_BLOCK LoaderBlock
)
166 /* Set Default Port Options */
170 /* Parse the Command Line */
171 p1
= (PCHAR
)LoaderBlock
->CommandLine
;
172 while (p1
&& (p2
= strchr(p1
, '/')))
174 /* Move past the slash */
177 /* Identify the Debug Type being Used */
178 if (!_strnicmp(p2
, "DEBUGPORT=", 10))
181 p2
= KdpGetDebugMode(p2
);
182 p2
= KdpGetWrapperDebugMode(p2
, LoaderBlock
);
184 /* Check for early breakpoint */
185 else if (!_strnicmp(p2
, "BREAK", 5))
188 KdpEarlyBreak
= TRUE
;
190 /* Check for Kernel Debugging Enable */
191 else if (!_strnicmp(p2
, "DEBUG", 5))
193 /* Enable it on the Serial Port */
195 KdDebuggerEnabled
= TRUE
;
196 KdpDebugMode
.Serial
= TRUE
;
198 /* Check for Kernel Debugging Bypass */
199 else if (!_strnicmp(p2
, "NODEBUG", 7))
201 /* Disable Debugging */
203 KdDebuggerEnabled
= FALSE
;
205 /* Check for Kernel Debugging Bypass unless STOP Error */
206 else if (!_strnicmp(p2
, "CRASHDEBUG", 10))
208 /* Disable Debugging */
210 KdDebuggerEnabled
= FALSE
;
212 /* Check Serial Port Settings [Baud Rate] */
213 else if (!_strnicmp(p2
, "BAUDRATE=", 9))
215 /* Get the Baud Rate */
217 Value
= (ULONG
)atol(p2
);
219 /* Check if it's valid and Set it */
220 if (0 < Value
) PortInfo
.BaudRate
= SerialPortInfo
.BaudRate
= Value
;
222 /* Check Serial Port Settings [IRQ] */
223 else if (!_strnicmp(p2
, "IRQ=", 4))
227 Value
= (ULONG
)atol(p2
);
229 /* Check if it's valid and set it */
230 if (0 < Value
) KdpPortIrq
= Value
;
237 /* Call Providers at Phase 0 */
238 for (i
= 0; i
< KdMax
; i
++)
240 InitRoutines
[i
](&DispatchTable
[i
], 0);
243 /* Call Wrapper at Phase 0 */
244 if (WrapperInitRoutine
) WrapperInitRoutine(&WrapperTable
, 0);
249 /* Call the Initialization Routines of the Registered Providers */
250 KdpCallInitRoutine(BootPhase
);