@@ -39,76 +39,11 @@ extern ANSI_STRING KdpLogFileName;
39
39
40
40
/* PRIVATE FUNCTIONS *********************************************************/
41
41
42
- INIT_FUNCTION
43
- PCHAR
42
+ BOOLEAN
44
43
NTAPI
45
- KdpGetDebugMode (PCHAR Currentp2 )
46
- {
47
- PCHAR p1 , p2 = Currentp2 ;
48
- ULONG Value ;
49
-
50
- /* Check for Screen Debugging */
51
- if (!_strnicmp (p2 , "SCREEN" , 6 ))
52
- {
53
- /* Enable It */
54
- p2 += 6 ;
55
- KdpDebugMode .Screen = TRUE;
56
- }
57
- /* Check for Serial Debugging */
58
- else if (!_strnicmp (p2 , "COM" , 3 ))
59
- {
60
- /* Gheck for a valid Serial Port */
61
- p2 += 3 ;
62
- if (* p2 != ':' )
63
- {
64
- Value = (ULONG )atol (p2 );
65
- if (Value > 0 && Value < 5 )
66
- {
67
- /* Valid port found, enable Serial Debugging */
68
- KdpDebugMode .Serial = TRUE;
69
-
70
- /* Set the port to use */
71
- SerialPortNumber = Value ;
72
- KdpPort = Value ;
73
- }
74
- }
75
- else
76
- {
77
- Value = strtoul (p2 + 1 , NULL , 0 );
78
- if (Value )
79
- {
80
- KdpDebugMode .Serial = TRUE;
81
- SerialPortInfo .Address = UlongToPtr (Value );
82
- SerialPortNumber = 0 ;
83
- KdpPort = 0 ;
84
- }
85
- }
86
- }
87
- /* Check for Debug Log Debugging */
88
- else if (!_strnicmp (p2 , "FILE" , 4 ))
89
- {
90
- /* Enable It */
91
- p2 += 4 ;
92
- KdpDebugMode .File = TRUE;
93
- if (* p2 == ':' )
94
- {
95
- p2 ++ ;
96
- p1 = p2 ;
97
- while (* p2 != '\0' && * p2 != ' ' ) p2 ++ ;
98
- KdpLogFileName .MaximumLength = KdpLogFileName .Length = p2 - p1 ;
99
- KdpLogFileName .Buffer = p1 ;
100
- }
101
- }
102
- /* Check for BOCHS Debugging */
103
- else if (!_strnicmp (p2 , "BOCHS" , 5 ))
104
- {
105
- /* Enable It */
106
- p2 += 5 ;
107
- KdpDebugMode .Bochs = TRUE;
108
- }
109
-
110
- return p2 ;
111
- }
44
+ KdRegisterDebuggerDataBlock (IN ULONG Tag ,
45
+ IN PDBGKD_DEBUG_DATA_HEADER64 DataHeader ,
46
+ IN ULONG Size );
112
47
113
48
INIT_FUNCTION
114
49
VOID
@@ -141,133 +76,172 @@ KdpCallInitRoutine(ULONG BootPhase)
141
76
142
77
BOOLEAN
143
78
NTAPI
144
- KdInitSystem (ULONG BootPhase ,
145
- PLOADER_PARAMETER_BLOCK LoaderBlock )
79
+ KdInitSystem (IN ULONG BootPhase ,
80
+ IN PLOADER_PARAMETER_BLOCK LoaderBlock )
146
81
{
147
- ULONG Value ;
82
+ BOOLEAN EnableKd ;
83
+ LPSTR DebugLine ;
84
+ PLDR_DATA_TABLE_ENTRY LdrEntry ;
148
85
ULONG i ;
149
- PCHAR CommandLine , Port = NULL , BaudRate = NULL , Irq = NULL ;
86
+ PCHAR CommandLine ;
150
87
151
- /* Set Default Port Options */
152
- if (BootPhase == 0 )
88
+ /* Check if this is Phase 1 */
89
+ if (BootPhase )
153
90
{
154
- /* Check if we have a loader block */
155
- if (LoaderBlock )
156
- {
157
- /* Check if we have a command line */
158
- CommandLine = LoaderBlock -> LoadOptions ;
159
- if (CommandLine )
160
- {
161
- /* Upcase it */
162
- _strupr (CommandLine );
163
-
164
- /* XXX Check for settings that we support */
165
- if (strstr (CommandLine , "NODEBUG" )) KdDebuggerEnabled = FALSE;
166
- else if (strstr (CommandLine , "CRASHDEBUG" )) KdDebuggerEnabled = FALSE;
167
- else if (strstr (CommandLine , "DEBUG" ))
168
- {
169
- /* Enable the kernel debugger */
170
- KdDebuggerNotPresent = FALSE;
171
- KdDebuggerEnabled = TRUE;
172
- #ifdef KDBG
173
- /* Get the KDBG Settings */
174
- KdbpGetCommandLineSettings (LoaderBlock -> LoadOptions );
175
- #endif
176
- }
91
+ /* Call the Initialization Routines of the Registered Providers */
92
+ KdpCallInitRoutine (BootPhase );
93
+ return TRUE;
94
+ }
177
95
178
- /* Get the port and baud rate */
179
- Port = strstr (CommandLine , "DEBUGPORT" );
180
- BaudRate = strstr (CommandLine , "BAUDRATE" );
181
- Irq = strstr (CommandLine , "IRQ" );
182
- }
183
- else
184
- {
185
- /* No command line options? Disable debugger by default */
186
- KdDebuggerEnabled = FALSE;
187
- }
188
- }
189
- else
190
- {
191
- /* Called from a bugcheck or a re-enable. Unconditionally enable KD. */
192
- KdDebuggerEnabled = TRUE;
193
- }
96
+ /* Check if we already initialized once */
97
+ if (KdDebuggerEnabled ) return TRUE;
194
98
195
- /* Let user-mode know our state */
196
- SharedUserData -> KdDebuggerEnabled = KdDebuggerEnabled ;
99
+ /* Disable break after symbol load for now */
100
+ KdBreakAfterSymbolLoad = FALSE ;
197
101
198
- /* Check if we got the /DEBUGPORT parameter(s) */
199
- while ( Port )
200
- {
201
- /* Move past the actual string, to reach the port */
202
- Port += sizeof ( "DEBUGPORT" ) - 1 ;
102
+ /* Check if the Debugger Data Block was already initialized */
103
+ if (! KdpDebuggerDataListHead . Flink )
104
+ {
105
+ /* It wasn't...Initialize the KD Data Listhead */
106
+ InitializeListHead ( & KdpDebuggerDataListHead ) ;
203
107
204
- /* Now get past any spaces and skip the equal sign */
205
- while (* Port == ' ' ) Port ++ ;
206
- Port ++ ;
108
+ /* Register the Debugger Data Block */
109
+ KdRegisterDebuggerDataBlock (KDBG_TAG ,
110
+ & KdDebuggerDataBlock .Header ,
111
+ sizeof (KdDebuggerDataBlock ));
207
112
208
- /* Get the debug mode and wrapper */
209
- Port = KdpGetDebugMode (Port );
210
- Port = strstr (Port , "DEBUGPORT" );
211
- }
113
+ /* Fill out the KD Version Block */
114
+ KdVersionBlock .MajorVersion = (USHORT )((DBGKD_MAJOR_NT << 8 ) | (NtBuildNumber >> 28 ));
115
+ KdVersionBlock .MinorVersion = (USHORT )(NtBuildNumber & 0xFFFF );
116
+
117
+ #ifdef CONFIG_SMP
118
+ /* This is an MP Build */
119
+ KdVersionBlock .Flags |= DBGKD_VERS_FLAG_MP ;
120
+ #endif
121
+
122
+ /* Save Pointers to Loaded Module List and Debugger Data */
123
+ KdVersionBlock .PsLoadedModuleList = (ULONG64 )(LONG_PTR )& PsLoadedModuleList ;
124
+ KdVersionBlock .DebuggerDataList = (ULONG64 )(LONG_PTR )& KdpDebuggerDataListHead ;
212
125
213
- /* Use serial port then */
214
- if (KdDebuggerEnabled && KdpDebugMode .Value == 0 )
215
- KdpDebugMode .Serial = TRUE;
126
+ /* Set protocol limits */
127
+ KdVersionBlock .MaxStateChange = DbgKdMaximumStateChange -
128
+ DbgKdMinimumStateChange ;
129
+ KdVersionBlock .MaxManipulate = DbgKdMaximumManipulate -
130
+ DbgKdMinimumManipulate ;
131
+ KdVersionBlock .Unused [0 ] = 0 ;
216
132
217
- /* Check if we got a baud rate */
218
- if (BaudRate )
133
+ /* Link us in the KPCR */
134
+ KeGetPcr ()-> KdVersionBlock = & KdVersionBlock ;
135
+ }
136
+
137
+ /* Check if we have a loader block */
138
+ if (LoaderBlock )
139
+ {
140
+ /* Get the image entry */
141
+ LdrEntry = CONTAINING_RECORD (LoaderBlock -> LoadOrderListHead .Flink ,
142
+ LDR_DATA_TABLE_ENTRY ,
143
+ InLoadOrderLinks );
144
+
145
+ /* Save the Kernel Base */
146
+ PsNtosImageBase = (ULONG_PTR )LdrEntry -> DllBase ;
147
+ KdVersionBlock .KernBase = (ULONG64 )(LONG_PTR )LdrEntry -> DllBase ;
148
+
149
+ /* Check if we have a command line */
150
+ CommandLine = LoaderBlock -> LoadOptions ;
151
+ if (CommandLine )
219
152
{
220
- /* Move past the actual string, to reach the rate */
221
- BaudRate += sizeof ( "BAUDRATE" ) - 1 ;
153
+ /* Upcase it */
154
+ _strupr ( CommandLine ) ;
222
155
223
- /* Now get past any spaces */
224
- while ( * BaudRate == ' ' ) BaudRate ++ ;
156
+ /* Assume we'll disable KD */
157
+ EnableKd = FALSE ;
225
158
226
- /* And make sure we have a rate */
227
- if (* BaudRate )
159
+ /* Check for CRASHDEBUG, NODEBUG and just DEBUG */
160
+ if (strstr (CommandLine , "CRASHDEBUG" ))
161
+ {
162
+ /* Don't enable KD now, but allow it to be enabled later */
163
+ KdPitchDebugger = FALSE;
164
+ }
165
+ else if (strstr (CommandLine , "NODEBUG" ))
228
166
{
229
- /* Read and set it */
230
- Value = atol (BaudRate + 1 );
231
- if (Value ) PortInfo .BaudRate = SerialPortInfo .BaudRate = Value ;
167
+ /* Don't enable KD and don't let it be enabled later */
168
+ KdPitchDebugger = TRUE;
169
+ }
170
+ else if ((DebugLine = strstr (CommandLine , "DEBUG" )) != NULL )
171
+ {
172
+ /* Enable KD */
173
+ EnableKd = TRUE;
174
+ KdDebuggerNotPresent = FALSE;
175
+ #ifdef KDBG
176
+ /* Get the KDBG Settings */
177
+ KdbpGetCommandLineSettings (LoaderBlock -> LoadOptions );
178
+ #endif
232
179
}
233
180
}
234
-
235
- /* Check Serial Port Settings [IRQ] */
236
- if (Irq )
181
+ else
237
182
{
238
- /* Move past the actual string, to reach the rate */
239
- Irq += sizeof ("IRQ" ) - 1 ;
183
+ /* No command line options? Disable debugger by default */
184
+ KdPitchDebugger = TRUE;
185
+ EnableKd = FALSE;
186
+ }
187
+ }
188
+ else
189
+ {
190
+ /* Called from a bugcheck or a re-enable. Save the Kernel Base. */
191
+ KdVersionBlock .KernBase = (ULONG64 )(LONG_PTR )PsNtosImageBase ;
240
192
241
- /* Now get past any spaces */
242
- while (* Irq == ' ' ) Irq ++ ;
193
+ /* Unconditionally enable KD */
194
+ EnableKd = TRUE;
195
+ }
196
+
197
+ /* Set the Kernel Base in the Data Block */
198
+ KdDebuggerDataBlock .KernBase = (ULONG_PTR )KdVersionBlock .KernBase ;
243
199
244
- /* And make sure we have an IRQ */
245
- if (* Irq )
200
+ /* Initialize the debugger if requested */
201
+ if (EnableKd && (NT_SUCCESS (KdDebuggerInitialize0 (LoaderBlock ))))
202
+ {
203
+ /* Check if we've already initialized our structures */
204
+ if (!KdpDebuggerStructuresInitialized )
205
+ {
206
+ /* Set the Debug Switch Routine and Retries */
207
+ KdpContext .KdpDefaultRetries = 20 ;
208
+ KiDebugSwitchRoutine = KdpSwitchProcessor ;
209
+
210
+ /* Initialize breakpoints owed flag and table */
211
+ KdpOweBreakpoint = FALSE;
212
+ for (i = 0 ; i < KD_BREAKPOINT_MAX ; i ++ )
246
213
{
247
- /* Read and set it */
248
- Value = atol ( Irq + 1 ) ;
249
- if ( Value ) KdpPortIrq = Value ;
214
+ KdpBreakpointTable [ i ]. Flags = 0 ;
215
+ KdpBreakpointTable [ i ]. DirectoryTableBase = 0 ;
216
+ KdpBreakpointTable [ i ]. Address = NULL ;
250
217
}
251
- }
252
218
253
- /* Call Providers at Phase 0 */
254
- for (i = 0 ; i < KdMax ; i ++ )
255
- {
256
- InitRoutines [i ](& DispatchTable [i ], 0 );
219
+ /* Initialize the Time Slip DPC */
220
+ KeInitializeDpc (& KdpTimeSlipDpc , KdpTimeSlipDpcRoutine , NULL );
221
+ KeInitializeTimer (& KdpTimeSlipTimer );
222
+ ExInitializeWorkItem (& KdpTimeSlipWorkItem , KdpTimeSlipWork , NULL );
223
+
224
+ /* First-time initialization done! */
225
+ KdpDebuggerStructuresInitialized = TRUE;
257
226
}
258
227
259
- /* Call Wrapper at Phase 0 */
260
- if (WrapperInitRoutine ) WrapperInitRoutine (& WrapperTable , 0 );
261
- return TRUE;
228
+ /* Initialize the timer */
229
+ KdTimerStart .QuadPart = 0 ;
230
+
231
+ /* Officially enable KD */
232
+ KdPitchDebugger = FALSE;
233
+ KdDebuggerEnabled = TRUE;
234
+
235
+ /* Let user-mode know that it's enabled as well */
236
+ SharedUserData -> KdDebuggerEnabled = TRUE;
262
237
}
263
- else /* BootPhase > 0 */
238
+ else
264
239
{
240
+ /* Disable debugger */
241
+ KdDebuggerNotPresent = TRUE;
265
242
}
266
243
267
- /* Call the Initialization Routines of the Registered Providers */
268
- KdpCallInitRoutine (BootPhase );
269
-
270
- /* Return success */
244
+ /* Return initialized */
271
245
return TRUE;
272
246
}
273
247
0 commit comments