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 /* VARIABLES ***************************************************************/
16 KD_PORT_INFORMATION PortInfo
= {DEFAULT_DEBUG_PORT
, DEFAULT_DEBUG_BAUD_RATE
, 0};
18 KDP_DEBUG_MODE KdpDebugMode
;
19 LIST_ENTRY KdProviders
;
20 PKDP_INIT_ROUTINE WrapperInitRoutine
;
21 KD_DISPATCH_TABLE DispatchTable
[KdMax
];
22 KD_DISPATCH_TABLE WrapperTable
;
24 PKDP_INIT_ROUTINE InitRoutines
[KdMax
] = {KdpScreenInit
,
28 /* PRIVATE FUNCTIONS *********************************************************/
32 KdpGetWrapperDebugMode(PCHAR Currentp2
,
33 PLOADER_PARAMETER_BLOCK LoaderBlock
)
38 /* Check for BOCHS Debugging */
39 if (!_strnicmp(p2
, "BOCHS", 5))
43 KdpDebugMode
.Bochs
= TRUE
;
44 WrapperInitRoutine
= KdpBochsInit
;
47 /* Check for GDB Debugging */
48 if (!_strnicmp(p2
, "GDB", 3))
52 KdpDebugMode
.Gdb
= TRUE
;
54 /* Enable Debugging */
55 KdDebuggerEnabled
= TRUE
;
56 WrapperInitRoutine
= KdpGdbStubInit
;
59 /* Check for PICE Debugging */
60 else if (!_strnicmp(p2
, "PICE", 4))
64 KdpDebugMode
.Pice
= TRUE
;
66 /* Enable Debugging */
67 KdDebuggerEnabled
= TRUE
;
72 /* Get the KDBG Settings and enable it */
73 KdDebuggerEnabled
= TRUE
;
74 KdpDebugMode
.Gdb
= TRUE
;
75 KdbpGetCommandLineSettings((PCHAR
)LoaderBlock
->CommandLine
);
82 KdpGetDebugMode(PCHAR Currentp2
)
87 /* Check for Screen Debugging */
88 if (!_strnicmp(p2
, "SCREEN", 6))
92 KdpDebugMode
.Screen
= TRUE
;
94 /* Check for Serial Debugging */
95 else if (!_strnicmp(p2
, "COM", 3))
97 /* Gheck for a valid Serial Port */
99 Value
= (ULONG
)atol(p2
);
100 if (Value
> 0 && Value
< 5)
102 /* Valid port found, enable Serial Debugging */
103 KdpDebugMode
.Serial
= TRUE
;
105 /* Set the port to use */
106 SerialPortInfo
.ComPort
= Value
;
110 /* Check for Debug Log Debugging */
111 else if (!_strnicmp(p2
, "FILE", 4))
115 KdpDebugMode
.File
= TRUE
;
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
);
151 KdInitSystem(ULONG BootPhase
,
152 PLOADER_PARAMETER_BLOCK LoaderBlock
)
158 /* Set Default Port Options */
161 /* Initialize the Provider List */
162 InitializeListHead(&KdProviders
);
164 /* Parse the Command Line */
165 p1
= (PCHAR
)LoaderBlock
->CommandLine
;
166 while (p1
&& (p2
= strchr(p1
, '/')))
168 /* Move past the slash */
171 /* Identify the Debug Type being Used */
172 if (!_strnicmp(p2
, "DEBUGPORT=", 10))
175 p2
= KdpGetDebugMode(p2
);
176 p2
= KdpGetWrapperDebugMode(p2
, LoaderBlock
);
178 /* Check for Kernel Debugging Enable */
179 else if (!_strnicmp(p2
, "DEBUG", 5))
181 /* Enable it on the Serial Port */
183 KdDebuggerEnabled
= TRUE
;
184 KdpDebugMode
.Serial
= TRUE
;
186 /* Check for Kernel Debugging Bypass */
187 else if (!_strnicmp(p2
, "NODEBUG", 7))
189 /* Disable Debugging */
191 KdDebuggerEnabled
= FALSE
;
193 /* Check for Kernel Debugging Bypass unless STOP Error */
194 else if (!_strnicmp(p2
, "CRASHDEBUG", 10))
196 /* Disable Debugging */
198 KdDebuggerEnabled
= FALSE
;
200 /* Check Serial Port Settings [Baud Rate] */
201 else if (!_strnicmp(p2
, "BAUDRATE=", 9))
203 /* Get the Baud Rate */
205 Value
= (ULONG
)atol(p2
);
207 /* Check if it's valid and Set it */
208 if (0 < Value
) PortInfo
.BaudRate
= SerialPortInfo
.BaudRate
= Value
;
210 /* Check Serial Port Settings [IRQ] */
211 else if (!_strnicmp(p2
, "IRQ=", 4))
215 Value
= (ULONG
)atol(p2
);
217 /* Check if it's valid and set it */
218 if (0 < Value
) KdpPortIrq
= Value
;
225 /* Call Providers at Phase 0 */
226 for (i
= 0; i
< KdMax
; i
++)
228 InitRoutines
[i
](&DispatchTable
[i
], 0);
231 /* Call Wrapper at Phase 0 */
232 if (WrapperInitRoutine
) WrapperInitRoutine(&WrapperTable
, 0);
237 /* Call the Initialization Routines of the Registered Providers */
238 KdpCallInitRoutine(BootPhase
);