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