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