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