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 #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
,
42 /* PRIVATE FUNCTIONS *********************************************************/
46 KdpGetWrapperDebugMode(PCHAR Currentp2
,
47 PROS_LOADER_PARAMETER_BLOCK LoaderBlock
)
51 /* Check for GDB Debugging */
52 if (!_strnicmp(p2
, "GDB", 3))
56 KdpDebugMode
.Gdb
= TRUE
;
58 /* Enable Debugging */
59 KdDebuggerEnabled
= TRUE
;
60 WrapperInitRoutine
= KdpGdbStubInit
;
63 /* Check for PICE Debugging */
64 else if (!_strnicmp(p2
, "PICE", 4))
68 KdpDebugMode
.Pice
= TRUE
;
70 /* Enable Debugging */
71 KdDebuggerEnabled
= TRUE
;
75 /* Get the KDBG Settings and enable it */
76 KdDebuggerEnabled
= TRUE
;
77 KdpDebugMode
.Gdb
= TRUE
;
78 KdbpGetCommandLineSettings((PCHAR
)LoaderBlock
->CommandLine
);
85 KdpGetDebugMode(PCHAR Currentp2
)
90 /* Check for Screen Debugging */
91 if (!_strnicmp(p2
, "SCREEN", 6))
95 KdpDebugMode
.Screen
= TRUE
;
97 /* Check for Serial Debugging */
98 else if (!_strnicmp(p2
, "COM", 3))
100 /* Gheck for a valid Serial Port */
102 Value
= (ULONG
)atol(p2
);
103 if (Value
> 0 && Value
< 5)
105 /* Valid port found, enable Serial Debugging */
106 KdpDebugMode
.Serial
= TRUE
;
108 /* Set the port to use */
109 SerialPortInfo
.ComPort
= Value
;
113 /* Check for Debug Log Debugging */
114 else if (!_strnicmp(p2
, "FILE", 4))
118 KdpDebugMode
.File
= TRUE
;
121 /* Check for BOCHS Debugging */
122 else if (!_strnicmp(p2
, "BOCHS", 5))
126 KdpDebugMode
.Bochs
= TRUE
;
134 KdpCallInitRoutine(ULONG BootPhase
)
136 PLIST_ENTRY CurrentEntry
;
137 PKD_DISPATCH_TABLE CurrentTable
;
139 /* Call the registered handlers */
140 CurrentEntry
= KdProviders
.Flink
;
141 while (CurrentEntry
!= &KdProviders
)
143 /* Get the current table */
144 CurrentTable
= CONTAINING_RECORD(CurrentEntry
,
149 CurrentTable
->KdpInitRoutine(CurrentTable
, BootPhase
);
152 CurrentEntry
= CurrentEntry
->Flink
;
155 /* Call the Wrapper Init Routine */
156 if (WrapperInitRoutine
)
157 WrapperTable
.KdpInitRoutine(&WrapperTable
, BootPhase
);
162 KdInitSystem(ULONG BootPhase
,
163 PROS_LOADER_PARAMETER_BLOCK LoaderBlock
)
169 /* Set Default Port Options */
173 /* Parse the Command Line */
174 p1
= (PCHAR
)LoaderBlock
->CommandLine
;
175 while (p1
&& (p2
= strchr(p1
, '/')))
177 /* Move past the slash */
180 /* Identify the Debug Type being Used */
181 if (!_strnicmp(p2
, "DEBUGPORT=", 10))
184 p2
= KdpGetDebugMode(p2
);
185 p2
= KdpGetWrapperDebugMode(p2
, LoaderBlock
);
187 /* Check for early breakpoint */
188 else if (!_strnicmp(p2
, "BREAK", 5))
191 KdpEarlyBreak
= TRUE
;
193 /* Check for Kernel Debugging Enable */
194 else if (!_strnicmp(p2
, "DEBUG", 5))
196 /* Enable it on the Serial Port */
198 KdDebuggerEnabled
= TRUE
;
199 KdpDebugMode
.Serial
= TRUE
;
201 /* Check for Kernel Debugging Bypass */
202 else if (!_strnicmp(p2
, "NODEBUG", 7))
204 /* Disable Debugging */
206 KdDebuggerEnabled
= FALSE
;
208 /* Check for Kernel Debugging Bypass unless STOP Error */
209 else if (!_strnicmp(p2
, "CRASHDEBUG", 10))
211 /* Disable Debugging */
213 KdDebuggerEnabled
= FALSE
;
215 /* Check Serial Port Settings [Baud Rate] */
216 else if (!_strnicmp(p2
, "BAUDRATE=", 9))
218 /* Get the Baud Rate */
220 Value
= (ULONG
)atol(p2
);
222 /* Check if it's valid and Set it */
223 if (0 < Value
) PortInfo
.BaudRate
= SerialPortInfo
.BaudRate
= Value
;
225 /* Check Serial Port Settings [IRQ] */
226 else if (!_strnicmp(p2
, "IRQ=", 4))
230 Value
= (ULONG
)atol(p2
);
232 /* Check if it's valid and set it */
233 if (0 < 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);
252 /* Call the Initialization Routines of the Registered Providers */
253 KdpCallInitRoutine(BootPhase
);