Make winkd somewhat portable.
[reactos.git] / reactos / ntoskrnl / kd64 / kddata.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/kddata.c
5 * PURPOSE: Contains all global variables and settings for KD64
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 VOID NTAPI RtlpBreakWithStatusInstruction(VOID);
16
17 /* GLOBALS *******************************************************************/
18
19 //
20 // Debugger State
21 //
22 KD_CONTEXT KdpContext;
23 BOOLEAN KdpPortLocked;
24 KSPIN_LOCK KdpDebuggerLock;
25 BOOLEAN KdpControlCPressed;
26
27 //
28 // Debug Trap Handlers
29 //
30 PKDEBUG_ROUTINE KiDebugRoutine = KdpStub;
31 PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
32
33 //
34 // Debugger Configuration Settings
35 //
36 BOOLEAN KdBreakAfterSymbolLoad;
37 BOOLEAN KdPitchDebugger;
38 BOOLEAN _KdDebuggerNotPresent;
39 BOOLEAN _KdDebuggerEnabled;
40 BOOLEAN KdAutoEnableOnEvent;
41 BOOLEAN KdPreviouslyEnabled;
42 BOOLEAN KdpDebuggerStructuresInitialized;
43 BOOLEAN KdEnteredDebugger;
44 ULONG KdDisableCount;
45 LARGE_INTEGER KdPerformanceCounterRate;
46
47 //
48 // Breakpoint Data
49 //
50 BREAKPOINT_ENTRY KdpBreakpointTable[20];
51 ULONG KdpBreakpointInstruction = 0xCC;
52 BOOLEAN KdpOweBreakpoint;
53 BOOLEAN BreakpointsSuspended;
54 ULONG KdpNumInternalBreakpoints;
55
56 ULONG KdpCurrentSymbolStart, KdpCurrentSymbolEnd;
57
58 //
59 // Tracepoint Data
60 //
61 ULONG TraceDataBuffer[40];
62 ULONG TraceDataBufferPosition = 1;
63
64 //
65 // Time Slip Support
66 //
67 KDPC KdpTimeSlipDpc;
68 KTIMER KdpTimeSlipTimer;
69 WORK_QUEUE_ITEM KdpTimeSlipWorkItem;
70 LONG KdpTimeSlipPending = 1;
71 PKEVENT KdpTimeSlipEvent;
72 KSPIN_LOCK KdpTimeSlipEventLock;
73 LARGE_INTEGER KdTimerStop, KdTimerStart, KdTimerDifference;
74
75 //
76 // Buffers
77 //
78 CHAR KdpMessageBuffer[4096];
79 CHAR KdpPathBuffer[4096];
80
81 //
82 // KdPrint Buffers
83 //
84 CHAR KdPrintDefaultCircularBuffer[0x8000];
85 PCHAR KdPrintWritePointer = KdPrintDefaultCircularBuffer;
86 ULONG KdPrintRolloverCount;
87 PCHAR KdPrintCircularBuffer = KdPrintDefaultCircularBuffer;
88 ULONG KdPrintBufferSize = sizeof(KdPrintDefaultCircularBuffer);
89 ULONG KdPrintBufferChanges = 0;
90
91 //
92 // Debug Filter Masks
93 //
94 ULONG Kd_WIN2000_Mask = 1;
95 ULONG Kd_SYSTEM_Mask;
96 ULONG Kd_SMSS_Mask;
97 ULONG Kd_SETUP_Mask;
98 ULONG Kd_NTFS_Mask;
99 ULONG Kd_FSTUB_Mask;
100 ULONG Kd_CRASHDUMP_Mask;
101 ULONG Kd_CDAUDIO_Mask;
102 ULONG Kd_CDROM_Mask;
103 ULONG Kd_CLASSPNP_Mask;
104 ULONG Kd_DISK_Mask;
105 ULONG Kd_REDBOOK_Mask;
106 ULONG Kd_STORPROP_Mask;
107 ULONG Kd_SCSIPORT_Mask;
108 ULONG Kd_SCSIMINIPORT_Mask;
109 ULONG Kd_CONFIG_Mask;
110 ULONG Kd_I8042PRT_Mask;
111 ULONG Kd_SERMOUSE_Mask;
112 ULONG Kd_LSERMOUS_Mask;
113 ULONG Kd_KBDHID_Mask;
114 ULONG Kd_MOUHID_Mask;
115 ULONG Kd_KBDCLASS_Mask;
116 ULONG Kd_MOUCLASS_Mask;
117 ULONG Kd_TWOTRACK_Mask;
118 ULONG Kd_WMILIB_Mask;
119 ULONG Kd_ACPI_Mask;
120 ULONG Kd_AMLI_Mask;
121 ULONG Kd_HALIA64_Mask;
122 ULONG Kd_VIDEO_Mask;
123 ULONG Kd_SVCHOST_Mask;
124 ULONG Kd_VIDEOPRT_Mask;
125 ULONG Kd_TCPIP_Mask;
126 ULONG Kd_DMSYNTH_Mask;
127 ULONG Kd_NTOSPNP_Mask;
128 ULONG Kd_FASTFAT_Mask;
129 ULONG Kd_SAMSS_Mask;
130 ULONG Kd_PNPMGR_Mask;
131 ULONG Kd_NETAPI_Mask;
132 ULONG Kd_SCSERVER_Mask;
133 ULONG Kd_SCCLIENT_Mask;
134 ULONG Kd_SERIAL_Mask;
135 ULONG Kd_SERENUM_Mask;
136 ULONG Kd_UHCD_Mask;
137 ULONG Kd_RPCPROXY_Mask;
138 ULONG Kd_AUTOCHK_Mask;
139 ULONG Kd_DCOMSS_Mask;
140 ULONG Kd_UNIMODEM_Mask;
141 ULONG Kd_SIS_Mask;
142 ULONG Kd_FLTMGR_Mask;
143 ULONG Kd_WMICORE_Mask;
144 ULONG Kd_BURNENG_Mask;
145 ULONG Kd_IMAPI_Mask;
146 ULONG Kd_SXS_Mask;
147 ULONG Kd_FUSION_Mask;
148 ULONG Kd_IDLETASK_Mask;
149 ULONG Kd_SOFTPCI_Mask;
150 ULONG Kd_TAPE_Mask;
151 ULONG Kd_MCHGR_Mask;
152 ULONG Kd_IDEP_Mask;
153 ULONG Kd_PCIIDE_Mask;
154 ULONG Kd_FLOPPY_Mask;
155 ULONG Kd_FDC_Mask;
156 ULONG Kd_TERMSRV_Mask;
157 ULONG Kd_W32TIME_Mask;
158 ULONG Kd_PREFETCHER_Mask;
159 ULONG Kd_RSFILTER_Mask;
160 ULONG Kd_FCPORT_Mask;
161 ULONG Kd_PCI_Mask;
162 ULONG Kd_DMIO_Mask;
163 ULONG Kd_DMCONFIG_Mask;
164 ULONG Kd_DMADMIN_Mask;
165 ULONG Kd_WSOCKTRANSPORT_Mask;
166 ULONG Kd_VSS_Mask;
167 ULONG Kd_PNPMEM_Mask;
168 ULONG Kd_PROCESSOR_Mask;
169 ULONG Kd_DMSERVER_Mask;
170 ULONG Kd_SR_Mask;
171 ULONG Kd_INFINIBAND_Mask;
172 ULONG Kd_IHVDRIVER_Mask;
173 ULONG Kd_IHVVIDEO_Mask;
174 ULONG Kd_IHVAUDIO_Mask;
175 ULONG Kd_IHVNETWORK_Mask;
176 ULONG Kd_IHVSTREAMING_Mask;
177 ULONG Kd_IHVBUS_Mask;
178 ULONG Kd_HPS_Mask;
179 ULONG Kd_RTLTHREADPOOL_Mask;
180 ULONG Kd_LDR_Mask;
181 ULONG Kd_TCPIP6_Mask;
182 ULONG Kd_ISAPNP_Mask;
183 ULONG Kd_SHPC_Mask;
184 ULONG Kd_STORPORT_Mask;
185 ULONG Kd_STORMINIPORT_Mask;
186 ULONG Kd_PRINTSPOOLER_Mask;
187 ULONG Kd_VSSDYNDISK_Mask;
188 ULONG Kd_VERIFIER_Mask;
189 ULONG Kd_VDS_Mask;
190 ULONG Kd_VDSBAS_Mask;
191 ULONG Kd_VDSDYNDR_Mask;
192 ULONG Kd_VDSUTIL_Mask;
193 ULONG Kd_DFRGIFC_Mask;
194 ULONG Kd_DEFAULT_Mask;
195 ULONG Kd_MM_Mask;
196 ULONG Kd_DFSC_Mask;
197 ULONG Kd_WOW64_Mask;
198 ULONG Kd_ENDOFTABLE_Mask;
199
200 //
201 // Debug Filter Component Table
202 //
203 PULONG KdComponentTable[104] =
204 {
205 &Kd_SYSTEM_Mask,
206 &Kd_SMSS_Mask,
207 &Kd_SETUP_Mask,
208 &Kd_NTFS_Mask,
209 &Kd_FSTUB_Mask,
210 &Kd_CRASHDUMP_Mask,
211 &Kd_CDAUDIO_Mask,
212 &Kd_CDROM_Mask,
213 &Kd_CLASSPNP_Mask,
214 &Kd_DISK_Mask,
215 &Kd_REDBOOK_Mask,
216 &Kd_STORPROP_Mask,
217 &Kd_SCSIPORT_Mask,
218 &Kd_SCSIMINIPORT_Mask,
219 &Kd_CONFIG_Mask,
220 &Kd_I8042PRT_Mask,
221 &Kd_SERMOUSE_Mask,
222 &Kd_LSERMOUS_Mask,
223 &Kd_KBDHID_Mask,
224 &Kd_MOUHID_Mask,
225 &Kd_KBDCLASS_Mask,
226 &Kd_MOUCLASS_Mask,
227 &Kd_TWOTRACK_Mask,
228 &Kd_WMILIB_Mask,
229 &Kd_ACPI_Mask,
230 &Kd_AMLI_Mask,
231 &Kd_HALIA64_Mask,
232 &Kd_VIDEO_Mask,
233 &Kd_SVCHOST_Mask,
234 &Kd_VIDEOPRT_Mask,
235 &Kd_TCPIP_Mask,
236 &Kd_DMSYNTH_Mask,
237 &Kd_NTOSPNP_Mask,
238 &Kd_FASTFAT_Mask,
239 &Kd_SAMSS_Mask,
240 &Kd_PNPMGR_Mask,
241 &Kd_NETAPI_Mask,
242 &Kd_SCSERVER_Mask,
243 &Kd_SCCLIENT_Mask,
244 &Kd_SERIAL_Mask,
245 &Kd_SERENUM_Mask,
246 &Kd_UHCD_Mask,
247 &Kd_RPCPROXY_Mask,
248 &Kd_AUTOCHK_Mask,
249 &Kd_DCOMSS_Mask,
250 &Kd_UNIMODEM_Mask,
251 &Kd_SIS_Mask,
252 &Kd_FLTMGR_Mask,
253 &Kd_WMICORE_Mask,
254 &Kd_BURNENG_Mask,
255 &Kd_IMAPI_Mask,
256 &Kd_SXS_Mask,
257 &Kd_FUSION_Mask,
258 &Kd_IDLETASK_Mask,
259 &Kd_SOFTPCI_Mask,
260 &Kd_TAPE_Mask,
261 &Kd_MCHGR_Mask,
262 &Kd_IDEP_Mask,
263 &Kd_PCIIDE_Mask,
264 &Kd_FLOPPY_Mask,
265 &Kd_FDC_Mask,
266 &Kd_TERMSRV_Mask,
267 &Kd_W32TIME_Mask,
268 &Kd_PREFETCHER_Mask,
269 &Kd_RSFILTER_Mask,
270 &Kd_FCPORT_Mask,
271 &Kd_PCI_Mask,
272 &Kd_DMIO_Mask,
273 &Kd_DMCONFIG_Mask,
274 &Kd_DMADMIN_Mask,
275 &Kd_WSOCKTRANSPORT_Mask,
276 &Kd_VSS_Mask,
277 &Kd_PNPMEM_Mask,
278 &Kd_PROCESSOR_Mask,
279 &Kd_DMSERVER_Mask,
280 &Kd_SR_Mask,
281 &Kd_INFINIBAND_Mask,
282 &Kd_IHVDRIVER_Mask,
283 &Kd_IHVVIDEO_Mask,
284 &Kd_IHVAUDIO_Mask,
285 &Kd_IHVNETWORK_Mask,
286 &Kd_IHVSTREAMING_Mask,
287 &Kd_IHVBUS_Mask,
288 &Kd_HPS_Mask,
289 &Kd_RTLTHREADPOOL_Mask,
290 &Kd_LDR_Mask,
291 &Kd_TCPIP6_Mask,
292 &Kd_ISAPNP_Mask,
293 &Kd_SHPC_Mask,
294 &Kd_STORPORT_Mask,
295 &Kd_STORMINIPORT_Mask,
296 &Kd_PRINTSPOOLER_Mask,
297 &Kd_VSSDYNDISK_Mask,
298 &Kd_VERIFIER_Mask,
299 &Kd_VDS_Mask,
300 &Kd_VDSBAS_Mask,
301 &Kd_VDSDYNDR_Mask,
302 &Kd_VDSUTIL_Mask,
303 &Kd_DFRGIFC_Mask,
304 &Kd_DEFAULT_Mask,
305 &Kd_MM_Mask,
306 &Kd_DFSC_Mask,
307 &Kd_WOW64_Mask,
308 &Kd_ENDOFTABLE_Mask,
309 };
310
311 ULONG KdComponentTableSize = sizeof(KdComponentTable);
312
313 //
314 // Debugger Data
315 //
316 LIST_ENTRY KdpDebuggerDataListHead;
317 KSPIN_LOCK KdpDataSpinLock;
318
319 //
320 // Debugger Version and Data Block
321 //
322 DBGKD_GET_VERSION64 KdVersionBlock =
323 {
324 0,
325 0,
326 DBGKD_64BIT_PROTOCOL_VERSION2,
327 KD_SECONDARY_VERSION_DEFAULT,
328 DBGKD_VERS_FLAG_DATA,
329 #if defined(_M_IX86)
330 IMAGE_FILE_MACHINE_I386,
331 #elif defined (_M_AMD64)
332 IMAGE_FILE_MACHINE_AMD64,
333 #elif defined(_M_PPC)
334 IMAGE_FILE_MACHINE_POWERPC,
335 #elif defined(_M_MIPS)
336 IMAGE_FILE_MACHINE_R4000,
337 #else
338 #error Unknown platform
339 #endif
340 PACKET_TYPE_MAX,
341 0,
342 0,
343 DBGKD_SIMULATION_NONE,
344 {0},
345 0,
346 0,
347 0
348 };
349 KDDEBUGGER_DATA64 KdDebuggerDataBlock =
350 {
351 {{0}},
352 0,
353 {(ULONG_PTR)RtlpBreakWithStatusInstruction},
354 0,
355 FIELD_OFFSET(KTHREAD, CallbackStack),
356 CBSTACK_CALLBACK_STACK,
357 #if defined(_M_X86)
358 CBSTACK_EBP,
359 #elif defined (_M_AMD64)
360 CBSTACK_RBP,
361 #else
362 #error Invalid architecture
363 #endif
364 0,
365 {(ULONG_PTR)KiCallUserMode},
366 {0},
367 {(ULONG_PTR)&PsLoadedModuleList},
368 {(ULONG_PTR)&PsActiveProcessHead},
369 {(ULONG_PTR)&PspCidTable},
370 {(ULONG_PTR)&ExpSystemResourcesList},
371 {0}, // ExpPagedPoolDescriptor
372 {0}, // ExpNumberOfPagedPools
373 {(ULONG_PTR)&KeTimeIncrement},
374 {(ULONG_PTR)&KeBugcheckCallbackListHead},
375 {(ULONG_PTR)KiBugCheckData},
376 {(ULONG_PTR)&IopErrorLogListHead},
377 {(ULONG_PTR)&ObpRootDirectoryObject},
378 {(ULONG_PTR)&ObpTypeObjectType},
379 {0}, // MmSystemCacheStart
380 {0}, // MmSystemCacheEnd
381 {0}, // MmSystemCacheWs
382 {0}, // MmPfnDatabase
383 {0}, // MmSystemPtesStart
384 {0}, // MmSystemPtesEnd
385 {0}, // MmSubsectionBase
386 {0}, // MmNumberOfPagingFiles
387 {0}, // MmLowestPhysicalPage
388 {0}, // MmHighestPhysicalPage
389 {0}, // MmNumberOfPhysicalPages
390 {0}, // MmMaximumNonPagedPoolInBytes
391 {0}, // MmNonPagedSystemStart
392 {0}, // MmNonPagedPoolStart
393 {0}, // MmNonPagedPoolEnd
394 {0}, // MmPagedPoolStart
395 {0}, // MmPagedPoolEnd
396 {0}, // MmPagedPoolInfo
397 PAGE_SIZE,
398 {0}, // MmSizeOfPagedPoolInBytes
399 {0}, // MmTotalCommitLimit
400 {0}, // MmTotalCommittedPages
401 {0}, // MmSharedCommit
402 {0}, // MmDriverCommit
403 {0}, // MmProcessCommit
404 {0}, // MmPagedPoolCommit
405 {0},
406 {0}, // MmZeroedPageListHead
407 {0}, // MmFreePageListHead
408 {0}, // MmStandbyPageListHead
409 {0}, // MmModifiedPageListHead
410 {0}, // MmModifiedNoWritePageListHead
411 {0}, // MmAvailablePages
412 {0}, // MmResidentAvailablePages
413 {0}, // PoolTrackTable
414 {0}, // NonPagedPoolDescriptor
415 {(ULONG_PTR)&MmHighestUserAddress},
416 {(ULONG_PTR)&MmSystemRangeStart},
417 {(ULONG_PTR)&MmUserProbeAddress},
418 {(ULONG_PTR)KdPrintDefaultCircularBuffer},
419 {(ULONG_PTR)(KdPrintDefaultCircularBuffer + 1)},
420 {(ULONG_PTR)&KdPrintWritePointer},
421 {(ULONG_PTR)&KdPrintRolloverCount},
422 {0}, // MmLoadedUserImageList
423 {(ULONG_PTR)&NtBuildLab},
424 {0},
425 {(ULONG_PTR)KiProcessorBlock},
426 {0}, // MmUnloadedDrivers
427 {0}, // MmLastUnloadedDrivers
428 {0}, // MmTriageActionTaken
429 {0}, // MmSpecialPoolTag
430 {0}, // KernelVerifier
431 {0}, // MmVerifierData
432 {0}, // MmAllocatedNonPagedPool
433 {0}, // MmPeakCommitment
434 {0}, // MmtotalCommitLimitMaximum
435 {(ULONG_PTR)&CmNtCSDVersion},
436 {0}, // MmPhysicalMemoryBlock
437 {0}, // MmSessionBase
438 {0}, // MmSessionSize
439 {0},
440 {0},
441 FIELD_OFFSET(KTHREAD, NextProcessor),
442 FIELD_OFFSET(KTHREAD, Teb),
443 FIELD_OFFSET(KTHREAD, KernelStack),
444 FIELD_OFFSET(KTHREAD, InitialStack),
445 FIELD_OFFSET(KTHREAD, ApcState.Process),
446 FIELD_OFFSET(KTHREAD, State),
447 0,
448 0,
449 sizeof(EPROCESS),
450 FIELD_OFFSET(EPROCESS, Peb),
451 FIELD_OFFSET(EPROCESS, InheritedFromUniqueProcessId),
452 FIELD_OFFSET(EPROCESS, Pcb.DirectoryTableBase),
453 sizeof(KPRCB),
454 FIELD_OFFSET(KPRCB, DpcRoutineActive),
455 FIELD_OFFSET(KPRCB, CurrentThread),
456 FIELD_OFFSET(KPRCB, MHz),
457 FIELD_OFFSET(KPRCB, CpuType),
458 FIELD_OFFSET(KPRCB, VendorString),
459 FIELD_OFFSET(KPRCB, ProcessorState.ContextFrame),
460 FIELD_OFFSET(KPRCB, Number),
461 sizeof(ETHREAD),
462 {(ULONG_PTR)KdPrintDefaultCircularBuffer},
463 {(ULONG_PTR)&KdPrintBufferSize},
464 {(ULONG_PTR)&KeLoaderBlock},
465 sizeof(KIPCR) + sizeof(KPRCB),
466 FIELD_OFFSET(KIPCR, Self),
467 #if defined(_M_X86)
468 FIELD_OFFSET(KPCR, Prcb),
469 #elif defined(_M_AMD64)
470 FIELD_OFFSET(KPCR, CurrentPrcb),
471 #else
472 #error Invalid architecture
473 #endif
474 #if defined(_M_X86)
475 FIELD_OFFSET(KIPCR, PrcbData),
476 #elif defined(_M_AMD64)
477 FIELD_OFFSET(KIPCR, Prcb),
478 #else
479 #error Invalid architecture
480 #endif
481 0,
482 0,
483 0,
484 0,
485 0,
486 #if defined(_M_X86)
487 FIELD_OFFSET(KIPCR, PrcbData) +
488 FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),
489 KGDT_R0_CODE,
490 KGDT_R0_DATA,
491 KGDT_R0_PCR,
492 KGDT_R3_CODE,
493 KGDT_R3_DATA,
494 KGDT_R3_TEB,
495 KGDT_LDT,
496 KGDT_TSS,
497 #elif defined(_M_AMD64)
498 FIELD_OFFSET(KIPCR, Prcb) +
499 FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),
500 KGDT_64_R0_CODE,
501 KGDT_64_DATA,
502 KGDT_64_DATA,
503 KGDT_64_R3_CODE,
504 KGDT_64_DATA,
505 KGDT_64_DATA,
506 0,
507 KGDT_TSS,
508 #else
509 #error Invalid architecture
510 #endif
511 0,
512 0,
513 {0}, // IopNumTriagDumpDataBlocks
514 {0}, // IopTriageDumpDataBlocks
515 };