Sync with trunk (48237)
[reactos.git] / ntoskrnl / kd64 / kddata.c
index 746fe98..895753a 100644 (file)
-/*\r
- * PROJECT:         ReactOS Kernel\r
- * LICENSE:         GPL - See COPYING in the top level directory\r
- * FILE:            ntoskrnl/kd64/kddata.c\r
- * PURPOSE:         Contains all global variables and settings for KD64\r
- * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)\r
- */\r
-\r
-/* INCLUDES ******************************************************************/\r
-\r
-#include <ntoskrnl.h>\r
-#define NDEBUG\r
-#include <debug.h>\r
-\r
-VOID NTAPI RtlpBreakWithStatusInstruction(VOID);\r
-\r
-/* GLOBALS *******************************************************************/\r
-\r
-//\r
-// Debugger State\r
-//\r
-KD_CONTEXT KdpContext;\r
-BOOLEAN KdpPortLocked;\r
-KSPIN_LOCK KdpDebuggerLock;\r
-BOOLEAN KdpControlCPressed;\r
-\r
-//\r
-// Debug Trap Handlers\r
-//\r
-PKDEBUG_ROUTINE KiDebugRoutine = KdpStub;\r
-PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;\r
-\r
-//\r
-// Debugger Configuration Settings\r
-//\r
-BOOLEAN KdBreakAfterSymbolLoad;\r
-BOOLEAN KdPitchDebugger;\r
-BOOLEAN _KdDebuggerNotPresent;\r
-BOOLEAN _KdDebuggerEnabled;\r
-BOOLEAN KdAutoEnableOnEvent;\r
-BOOLEAN KdPreviouslyEnabled;\r
-BOOLEAN KdpDebuggerStructuresInitialized;\r
-BOOLEAN KdEnteredDebugger;\r
-ULONG KdDisableCount;\r
-LARGE_INTEGER KdPerformanceCounterRate;\r
-\r
-//\r
-// Breakpoint Data\r
-//\r
-BREAKPOINT_ENTRY KdpBreakpointTable[20];\r
-ULONG KdpBreakpointInstruction = 0xCC;\r
-BOOLEAN KdpOweBreakpoint;\r
-BOOLEAN BreakpointsSuspended;\r
-ULONG KdpNumInternalBreakpoints;\r
-\r
-ULONG KdpCurrentSymbolStart, KdpCurrentSymbolEnd;\r
-\r
-//\r
-// Tracepoint Data\r
-//\r
-ULONG TraceDataBuffer[40];\r
-ULONG TraceDataBufferPosition = 1;\r
-\r
-//\r
-// Time Slip Support\r
-//\r
-KDPC KdpTimeSlipDpc;\r
-KTIMER KdpTimeSlipTimer;\r
-WORK_QUEUE_ITEM KdpTimeSlipWorkItem;\r
-LONG KdpTimeSlipPending = 1;\r
-PKEVENT KdpTimeSlipEvent;\r
-KSPIN_LOCK KdpTimeSlipEventLock;\r
-LARGE_INTEGER KdTimerStop, KdTimerStart, KdTimerDifference;\r
-\r
-//\r
-// Buffers\r
-//\r
-CHAR KdpMessageBuffer[4096];\r
-CHAR KdpPathBuffer[4096];\r
-\r
-//\r
-// KdPrint Buffers\r
-//\r
-CHAR KdPrintDefaultCircularBuffer[0x8000];\r
-PCHAR KdPrintWritePointer = KdPrintDefaultCircularBuffer;\r
-ULONG KdPrintRolloverCount;\r
-PCHAR KdPrintCircularBuffer = KdPrintDefaultCircularBuffer;\r
-ULONG KdPrintBufferSize = sizeof(KdPrintDefaultCircularBuffer);\r
-ULONG KdPrintBufferChanges = 0;\r
-\r
-//\r
-// Debug Filter Masks\r
-//\r
-ULONG Kd_WIN2000_Mask = 1;\r
-ULONG Kd_SYSTEM_Mask;\r
-ULONG Kd_SMSS_Mask;\r
-ULONG Kd_SETUP_Mask;\r
-ULONG Kd_NTFS_Mask;\r
-ULONG Kd_FSTUB_Mask;\r
-ULONG Kd_CRASHDUMP_Mask;\r
-ULONG Kd_CDAUDIO_Mask;\r
-ULONG Kd_CDROM_Mask;\r
-ULONG Kd_CLASSPNP_Mask;\r
-ULONG Kd_DISK_Mask;\r
-ULONG Kd_REDBOOK_Mask;\r
-ULONG Kd_STORPROP_Mask;\r
-ULONG Kd_SCSIPORT_Mask;\r
-ULONG Kd_SCSIMINIPORT_Mask;\r
-ULONG Kd_CONFIG_Mask;\r
-ULONG Kd_I8042PRT_Mask;\r
-ULONG Kd_SERMOUSE_Mask;\r
-ULONG Kd_LSERMOUS_Mask;\r
-ULONG Kd_KBDHID_Mask;\r
-ULONG Kd_MOUHID_Mask;\r
-ULONG Kd_KBDCLASS_Mask;\r
-ULONG Kd_MOUCLASS_Mask;\r
-ULONG Kd_TWOTRACK_Mask;\r
-ULONG Kd_WMILIB_Mask;\r
-ULONG Kd_ACPI_Mask;\r
-ULONG Kd_AMLI_Mask;\r
-ULONG Kd_HALIA64_Mask;\r
-ULONG Kd_VIDEO_Mask;\r
-ULONG Kd_SVCHOST_Mask;\r
-ULONG Kd_VIDEOPRT_Mask;\r
-ULONG Kd_TCPIP_Mask;\r
-ULONG Kd_DMSYNTH_Mask;\r
-ULONG Kd_NTOSPNP_Mask;\r
-ULONG Kd_FASTFAT_Mask;\r
-ULONG Kd_SAMSS_Mask;\r
-ULONG Kd_PNPMGR_Mask;\r
-ULONG Kd_NETAPI_Mask;\r
-ULONG Kd_SCSERVER_Mask;\r
-ULONG Kd_SCCLIENT_Mask;\r
-ULONG Kd_SERIAL_Mask;\r
-ULONG Kd_SERENUM_Mask;\r
-ULONG Kd_UHCD_Mask;\r
-ULONG Kd_RPCPROXY_Mask;\r
-ULONG Kd_AUTOCHK_Mask;\r
-ULONG Kd_DCOMSS_Mask;\r
-ULONG Kd_UNIMODEM_Mask;\r
-ULONG Kd_SIS_Mask;\r
-ULONG Kd_FLTMGR_Mask;\r
-ULONG Kd_WMICORE_Mask;\r
-ULONG Kd_BURNENG_Mask;\r
-ULONG Kd_IMAPI_Mask;\r
-ULONG Kd_SXS_Mask;\r
-ULONG Kd_FUSION_Mask;\r
-ULONG Kd_IDLETASK_Mask;\r
-ULONG Kd_SOFTPCI_Mask;\r
-ULONG Kd_TAPE_Mask;\r
-ULONG Kd_MCHGR_Mask;\r
-ULONG Kd_IDEP_Mask;\r
-ULONG Kd_PCIIDE_Mask;\r
-ULONG Kd_FLOPPY_Mask;\r
-ULONG Kd_FDC_Mask;\r
-ULONG Kd_TERMSRV_Mask;\r
-ULONG Kd_W32TIME_Mask;\r
-ULONG Kd_PREFETCHER_Mask;\r
-ULONG Kd_RSFILTER_Mask;\r
-ULONG Kd_FCPORT_Mask;\r
-ULONG Kd_PCI_Mask;\r
-ULONG Kd_DMIO_Mask;\r
-ULONG Kd_DMCONFIG_Mask;\r
-ULONG Kd_DMADMIN_Mask;\r
-ULONG Kd_WSOCKTRANSPORT_Mask;\r
-ULONG Kd_VSS_Mask;\r
-ULONG Kd_PNPMEM_Mask;\r
-ULONG Kd_PROCESSOR_Mask;\r
-ULONG Kd_DMSERVER_Mask;\r
-ULONG Kd_SR_Mask;\r
-ULONG Kd_INFINIBAND_Mask;\r
-ULONG Kd_IHVDRIVER_Mask;\r
-ULONG Kd_IHVVIDEO_Mask;\r
-ULONG Kd_IHVAUDIO_Mask;\r
-ULONG Kd_IHVNETWORK_Mask;\r
-ULONG Kd_IHVSTREAMING_Mask;\r
-ULONG Kd_IHVBUS_Mask;\r
-ULONG Kd_HPS_Mask;\r
-ULONG Kd_RTLTHREADPOOL_Mask;\r
-ULONG Kd_LDR_Mask;\r
-ULONG Kd_TCPIP6_Mask;\r
-ULONG Kd_ISAPNP_Mask;\r
-ULONG Kd_SHPC_Mask;\r
-ULONG Kd_STORPORT_Mask;\r
-ULONG Kd_STORMINIPORT_Mask;\r
-ULONG Kd_PRINTSPOOLER_Mask;\r
-ULONG Kd_VSSDYNDISK_Mask;\r
-ULONG Kd_VERIFIER_Mask;\r
-ULONG Kd_VDS_Mask;\r
-ULONG Kd_VDSBAS_Mask;\r
-ULONG Kd_VDSDYNDR_Mask;\r
-ULONG Kd_VDSUTIL_Mask;\r
-ULONG Kd_DFRGIFC_Mask;\r
-ULONG Kd_DEFAULT_Mask;\r
-ULONG Kd_MM_Mask;\r
-ULONG Kd_DFSC_Mask;\r
-ULONG Kd_WOW64_Mask;\r
-ULONG Kd_ENDOFTABLE_Mask;\r
-\r
-//\r
-// Debug Filter Component Table\r
-//\r
-PULONG KdComponentTable[104] =\r
-{\r
-    &Kd_SYSTEM_Mask,\r
-    &Kd_SMSS_Mask,\r
-    &Kd_SETUP_Mask,\r
-    &Kd_NTFS_Mask,\r
-    &Kd_FSTUB_Mask,\r
-    &Kd_CRASHDUMP_Mask,\r
-    &Kd_CDAUDIO_Mask,\r
-    &Kd_CDROM_Mask,\r
-    &Kd_CLASSPNP_Mask,\r
-    &Kd_DISK_Mask,\r
-    &Kd_REDBOOK_Mask,\r
-    &Kd_STORPROP_Mask,\r
-    &Kd_SCSIPORT_Mask,\r
-    &Kd_SCSIMINIPORT_Mask,\r
-    &Kd_CONFIG_Mask,\r
-    &Kd_I8042PRT_Mask,\r
-    &Kd_SERMOUSE_Mask,\r
-    &Kd_LSERMOUS_Mask,\r
-    &Kd_KBDHID_Mask,\r
-    &Kd_MOUHID_Mask,\r
-    &Kd_KBDCLASS_Mask,\r
-    &Kd_MOUCLASS_Mask,\r
-    &Kd_TWOTRACK_Mask,\r
-    &Kd_WMILIB_Mask,\r
-    &Kd_ACPI_Mask,\r
-    &Kd_AMLI_Mask,\r
-    &Kd_HALIA64_Mask,\r
-    &Kd_VIDEO_Mask,\r
-    &Kd_SVCHOST_Mask,\r
-    &Kd_VIDEOPRT_Mask,\r
-    &Kd_TCPIP_Mask,\r
-    &Kd_DMSYNTH_Mask,\r
-    &Kd_NTOSPNP_Mask,\r
-    &Kd_FASTFAT_Mask,\r
-    &Kd_SAMSS_Mask,\r
-    &Kd_PNPMGR_Mask,\r
-    &Kd_NETAPI_Mask,\r
-    &Kd_SCSERVER_Mask,\r
-    &Kd_SCCLIENT_Mask,\r
-    &Kd_SERIAL_Mask,\r
-    &Kd_SERENUM_Mask,\r
-    &Kd_UHCD_Mask,\r
-    &Kd_RPCPROXY_Mask,\r
-    &Kd_AUTOCHK_Mask,\r
-    &Kd_DCOMSS_Mask,\r
-    &Kd_UNIMODEM_Mask,\r
-    &Kd_SIS_Mask,\r
-    &Kd_FLTMGR_Mask,\r
-    &Kd_WMICORE_Mask,\r
-    &Kd_BURNENG_Mask,\r
-    &Kd_IMAPI_Mask,\r
-    &Kd_SXS_Mask,\r
-    &Kd_FUSION_Mask,\r
-    &Kd_IDLETASK_Mask,\r
-    &Kd_SOFTPCI_Mask,\r
-    &Kd_TAPE_Mask,\r
-    &Kd_MCHGR_Mask,\r
-    &Kd_IDEP_Mask,\r
-    &Kd_PCIIDE_Mask,\r
-    &Kd_FLOPPY_Mask,\r
-    &Kd_FDC_Mask,\r
-    &Kd_TERMSRV_Mask,\r
-    &Kd_W32TIME_Mask,\r
-    &Kd_PREFETCHER_Mask,\r
-    &Kd_RSFILTER_Mask,\r
-    &Kd_FCPORT_Mask,\r
-    &Kd_PCI_Mask,\r
-    &Kd_DMIO_Mask,\r
-    &Kd_DMCONFIG_Mask,\r
-    &Kd_DMADMIN_Mask,\r
-    &Kd_WSOCKTRANSPORT_Mask,\r
-    &Kd_VSS_Mask,\r
-    &Kd_PNPMEM_Mask,\r
-    &Kd_PROCESSOR_Mask,\r
-    &Kd_DMSERVER_Mask,\r
-    &Kd_SR_Mask,\r
-    &Kd_INFINIBAND_Mask,\r
-    &Kd_IHVDRIVER_Mask,\r
-    &Kd_IHVVIDEO_Mask,\r
-    &Kd_IHVAUDIO_Mask,\r
-    &Kd_IHVNETWORK_Mask,\r
-    &Kd_IHVSTREAMING_Mask,\r
-    &Kd_IHVBUS_Mask,\r
-    &Kd_HPS_Mask,\r
-    &Kd_RTLTHREADPOOL_Mask,\r
-    &Kd_LDR_Mask,\r
-    &Kd_TCPIP6_Mask,\r
-    &Kd_ISAPNP_Mask,\r
-    &Kd_SHPC_Mask,\r
-    &Kd_STORPORT_Mask,\r
-    &Kd_STORMINIPORT_Mask,\r
-    &Kd_PRINTSPOOLER_Mask,\r
-    &Kd_VSSDYNDISK_Mask,\r
-    &Kd_VERIFIER_Mask,\r
-    &Kd_VDS_Mask,\r
-    &Kd_VDSBAS_Mask,\r
-    &Kd_VDSDYNDR_Mask,\r
-    &Kd_VDSUTIL_Mask,\r
-    &Kd_DFRGIFC_Mask,\r
-    &Kd_DEFAULT_Mask,\r
-    &Kd_MM_Mask,\r
-    &Kd_DFSC_Mask,\r
-    &Kd_WOW64_Mask,\r
-    &Kd_ENDOFTABLE_Mask,\r
-};\r
-\r
-ULONG KdComponentTableSize = sizeof(KdComponentTable);\r
-\r
-//\r
-// Debugger Data\r
-//\r
-LIST_ENTRY KdpDebuggerDataListHead;\r
-KSPIN_LOCK KdpDataSpinLock;\r
-\r
-//\r
-// Debugger Version and Data Block\r
-//\r
-DBGKD_GET_VERSION64 KdVersionBlock =\r
-{\r
-    0,\r
-    0,\r
-    DBGKD_64BIT_PROTOCOL_VERSION2,\r
-    KD_SECONDARY_VERSION_DEFAULT,\r
-    DBGKD_VERS_FLAG_DATA,\r
-#if defined(_M_IX86)\r
-    IMAGE_FILE_MACHINE_I386,\r
-#elif defined(_M_PPC)\r
-    IMAGE_FILE_MACHINE_POWERPC,\r
-#elif defined(_M_MIPS)\r
-    IMAGE_FILE_MACHINE_R4000,\r
-#else\r
-#error Unknown platform\r
-#endif\r
-    PACKET_TYPE_MAX,\r
-    0,\r
-    0,\r
-    DBGKD_SIMULATION_NONE,\r
-    {0},\r
-    0,\r
-    0,\r
-    0\r
-};\r
-KDDEBUGGER_DATA64 KdDebuggerDataBlock =\r
-{\r
-    {{0}},\r
-    0,\r
-    {PtrToUlong(RtlpBreakWithStatusInstruction)},\r
-    0,\r
-    FIELD_OFFSET(KTHREAD, CallbackStack),\r
-    CBSTACK_CALLBACK_STACK,\r
-    CBSTACK_EBP,\r
-    0,\r
-    {PtrToUlong(KiCallUserMode)},\r
-    {0},\r
-    {PtrToUlong(&PsLoadedModuleList)},\r
-    {PtrToUlong(&PsActiveProcessHead)},\r
-    {PtrToUlong(&PspCidTable)},\r
-    {PtrToUlong(&ExpSystemResourcesList)},\r
-    {0},                                                        // ExpPagedPoolDescriptor\r
-    {0},                                                        // ExpNumberOfPagedPools\r
-    {PtrToUlong(&KeTimeIncrement)},\r
-    {PtrToUlong(&KeBugcheckCallbackListHead)},\r
-    {PtrToUlong(KiBugCheckData)},\r
-    {PtrToUlong(&IopErrorLogListHead)},\r
-    {PtrToUlong(&ObpRootDirectoryObject)},\r
-    {PtrToUlong(&ObpTypeObjectType)},\r
-    {0},                                                        // MmSystemCacheStart\r
-    {0},                                                        // MmSystemCacheEnd\r
-    {0},                                                        // MmSystemCacheWs\r
-    {0},                                                        // MmPfnDatabase\r
-    {0},                                                        // MmSystemPtesStart\r
-    {0},                                                        // MmSystemPtesEnd\r
-    {0},                                                        // MmSubsectionBase\r
-    {0},                                                        // MmNumberOfPagingFiles\r
-    {0},                                                        // MmLowestPhysicalPage\r
-    {0},                                                        // MmHighestPhysicalPage\r
-    {0},                                                        // MmNumberOfPhysicalPages\r
-    {0},                                                        // MmMaximumNonPagedPoolInBytes\r
-    {0},                                                        // MmNonPagedSystemStart\r
-    {0},                                                        // MmNonPagedPoolStart\r
-    {0},                                                        // MmNonPagedPoolEnd\r
-    {0},                                                        // MmPagedPoolStart\r
-    {0},                                                        // MmPagedPoolEnd\r
-    {0},                                                        // MmPagedPoolInfo\r
-    PAGE_SIZE,\r
-    {0},                                                        // MmSizeOfPagedPoolInBytes\r
-    {0},                                                        // MmTotalCommitLimit\r
-    {0},                                                        // MmTotalCommittedPages\r
-    {0},                                                        // MmSharedCommit\r
-    {0},                                                        // MmDriverCommit\r
-    {0},                                                        // MmProcessCommit\r
-    {0},                                                        // MmPagedPoolCommit\r
-    {0},\r
-    {0},                                                        // MmZeroedPageListHead\r
-    {0},                                                        // MmFreePageListHead\r
-    {0},                                                        // MmStandbyPageListHead\r
-    {0},                                                        // MmModifiedPageListHead\r
-    {0},                                                        // MmModifiedNoWritePageListHead\r
-    {0},                                                        // MmAvailablePages\r
-    {0},                                                        // MmResidentAvailablePages\r
-    {0},                                                        // PoolTrackTable\r
-    {0},                                                        // NonPagedPoolDescriptor\r
-    {PtrToUlong(&MmHighestUserAddress)},\r
-    {PtrToUlong(&MmSystemRangeStart)},\r
-    {PtrToUlong(&MmUserProbeAddress)},\r
-    {PtrToUlong(KdPrintDefaultCircularBuffer)},\r
-    {PtrToUlong(KdPrintDefaultCircularBuffer + 1)},\r
-    {PtrToUlong(&KdPrintWritePointer)},\r
-    {PtrToUlong(&KdPrintRolloverCount)},\r
-    {0},                                                        // MmLoadedUserImageList\r
-    {PtrToUlong(&NtBuildLab)},\r
-    {0},\r
-    {PtrToUlong(KiProcessorBlock)},\r
-    {0},                                                        // MmUnloadedDrivers\r
-    {0},                                                        // MmLastUnloadedDrivers\r
-    {0},                                                        // MmTriageActionTaken\r
-    {0},                                                        // MmSpecialPoolTag\r
-    {0},                                                        // KernelVerifier\r
-    {0},                                                        // MmVerifierData\r
-    {0},                                                        // MmAllocatedNonPagedPool\r
-    {0},                                                        // MmPeakCommitment\r
-    {0},                                                        // MmtotalCommitLimitMaximum\r
-    {PtrToUlong(&CmNtCSDVersion)},\r
-    {0},                                                        // MmPhysicalMemoryBlock\r
-    {0},                                                        // MmSessionBase\r
-    {0},                                                        // MmSessionSize\r
-    {0},\r
-    {0},\r
-    FIELD_OFFSET(KTHREAD, NextProcessor),\r
-    FIELD_OFFSET(KTHREAD, Teb),\r
-    FIELD_OFFSET(KTHREAD, KernelStack),\r
-    FIELD_OFFSET(KTHREAD, InitialStack),\r
-    FIELD_OFFSET(KTHREAD, ApcState.Process),\r
-    FIELD_OFFSET(KTHREAD, State),\r
-    0,\r
-    0,\r
-    sizeof(EPROCESS),\r
-    FIELD_OFFSET(EPROCESS, Peb),\r
-    FIELD_OFFSET(EPROCESS, InheritedFromUniqueProcessId),\r
-    FIELD_OFFSET(EPROCESS, Pcb.DirectoryTableBase),\r
-    sizeof(KPRCB),\r
-    FIELD_OFFSET(KPRCB, DpcRoutineActive),\r
-    FIELD_OFFSET(KPRCB, CurrentThread),\r
-    FIELD_OFFSET(KPRCB, MHz),\r
-    FIELD_OFFSET(KPRCB, CpuType),\r
-    FIELD_OFFSET(KPRCB, VendorString),\r
-    FIELD_OFFSET(KPRCB, ProcessorState.ContextFrame),\r
-    FIELD_OFFSET(KPRCB, Number),\r
-    sizeof(ETHREAD),\r
-    {PtrToUlong(KdPrintDefaultCircularBuffer)},\r
-    {PtrToUlong(&KdPrintBufferSize)},\r
-    {PtrToUlong(&KeLoaderBlock)},\r
-    sizeof(KIPCR) + sizeof(KPRCB),\r
-    FIELD_OFFSET(KIPCR, Self),\r
-    FIELD_OFFSET(KPCR, Prcb),\r
-    FIELD_OFFSET(KIPCR, PrcbData),\r
-    0,\r
-    0,\r
-    0,\r
-    0,\r
-    0,\r
-    FIELD_OFFSET(KIPCR, PrcbData) +\r
-    FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),\r
-    KGDT_R0_CODE,\r
-    KGDT_R0_DATA,\r
-    KGDT_R0_PCR,\r
-    KGDT_R3_CODE,\r
-    KGDT_R3_DATA,\r
-    KGDT_R3_TEB,\r
-    KGDT_LDT,\r
-    KGDT_TSS,\r
-    0,\r
-    0,\r
-    {0},                                                        // IopNumTriagDumpDataBlocks\r
-    {0},                                                        // IopTriageDumpDataBlocks\r
-};\r
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            ntoskrnl/kd64/kddata.c
+ * PURPOSE:         Contains all global variables and settings for KD64
+ * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
+ */
+
+/* INCLUDES ******************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+#include "../mm/ARM3/miarm.h"
+
+VOID NTAPI RtlpBreakWithStatusInstruction(VOID);
+
+//
+// Apply the KIPCR WDK workaround for x86 and AMD64
+//
+#if defined(_X86_) || defined(_AMD64_)
+#define KPCR KIPCR
+#endif
+
+#if defined(_X86_)
+
+#define KPCR_SELF_PCR_OFFSET           FIELD_OFFSET(KPCR, Self)
+#define KPCR_CURRENT_PRCB_OFFSET       FIELD_OFFSET(KPCR, Prcb)
+#define KPCR_CONTAINED_PRCB_OFFSET     FIELD_OFFSET(KPCR, PrcbData)
+#define KPCR_INITIAL_STACK_OFFSET      0
+#define KPCR_STACK_LIMIT_OFFSET        0
+#define KPRCB_PCR_PAGE_OFFSET          0
+#define CBSTACK_FRAME_POINTER          Ebp
+
+#elif defined(_AMD64_)
+
+#define KPCR_SELF_PCR_OFFSET           FIELD_OFFSET(KPCR, Self)
+#define KPCR_CURRENT_PRCB_OFFSET       FIELD_OFFSET(KPCR, CurrentPrcb)
+#define KPCR_CONTAINED_PRCB_OFFSET     FIELD_OFFSET(KPCR, Prcb)
+#define KPCR_INITIAL_STACK_OFFSET      0
+#define KPCR_STACK_LIMIT_OFFSET        0
+#define KPRCB_PCR_PAGE_OFFSET          0
+#define CBSTACK_FRAME_POINTER          Rbp
+
+#elif defined(_ARM_)
+
+#define KPCR_SELF_PCR_OFFSET           0
+#define KPCR_CURRENT_PRCB_OFFSET       FIELD_OFFSET(KPCR, Prcb)
+#define KPCR_CONTAINED_PRCB_OFFSET     0
+#define KPCR_INITIAL_STACK_OFFSET      FIELD_OFFSET(KPCR, InitialStack)
+#define KPCR_STACK_LIMIT_OFFSET        FIELD_OFFSET(KPCR, StackLimit)
+#define KPRCB_PCR_PAGE_OFFSET          FIELD_OFFSET(KPRCB, PcrPage)
+#define CBSTACK_FRAME_POINTER          DummyFramePointer
+
+#else
+#error Unsupported Architecture
+#endif
+
+/* GLOBALS *******************************************************************/
+
+//
+// Debugger State
+//
+KD_CONTEXT KdpContext;
+BOOLEAN KdpPortLocked;
+KSPIN_LOCK KdpDebuggerLock;
+BOOLEAN KdpControlCPressed;
+BOOLEAN KdpContextSent;
+
+//
+// Debug Trap Handlers
+//
+PKDEBUG_ROUTINE KiDebugRoutine = KdpStub;
+PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
+
+//
+// Debugger Configuration Settings
+//
+BOOLEAN KdBreakAfterSymbolLoad;
+BOOLEAN KdPitchDebugger;
+BOOLEAN _KdDebuggerNotPresent;
+BOOLEAN _KdDebuggerEnabled;
+BOOLEAN KdAutoEnableOnEvent;
+BOOLEAN KdBlockEnable;
+BOOLEAN KdIgnoreUmExceptions;
+BOOLEAN KdPreviouslyEnabled;
+BOOLEAN KdpDebuggerStructuresInitialized;
+BOOLEAN KdEnteredDebugger;
+ULONG KdDisableCount;
+LARGE_INTEGER KdPerformanceCounterRate;
+
+//
+// Breakpoint Data
+//
+BREAKPOINT_ENTRY KdpBreakpointTable[KD_BREAKPOINT_MAX];
+KD_BREAKPOINT_TYPE KdpBreakpointInstruction = KD_BREAKPOINT_VALUE;
+BOOLEAN KdpOweBreakpoint;
+BOOLEAN BreakpointsSuspended;
+ULONG KdpNumInternalBreakpoints;
+
+//
+// Symbol Data
+//
+ULONG KdpCurrentSymbolStart, KdpCurrentSymbolEnd;
+
+//
+// Tracepoint Data
+//
+ULONG TraceDataBuffer[40];
+ULONG TraceDataBufferPosition = 1;
+
+//
+// Time Slip Support
+//
+KDPC KdpTimeSlipDpc;
+KTIMER KdpTimeSlipTimer;
+WORK_QUEUE_ITEM KdpTimeSlipWorkItem;
+LONG KdpTimeSlipPending = 1;
+PKEVENT KdpTimeSlipEvent;
+KSPIN_LOCK KdpTimeSlipEventLock;
+LARGE_INTEGER KdTimerStop, KdTimerStart, KdTimerDifference;
+
+//
+// Buffers
+//
+CHAR KdpMessageBuffer[0x1000];
+CHAR KdpPathBuffer[0x1000];
+
+//
+// KdPrint Buffers
+//
+CHAR KdPrintDefaultCircularBuffer[KD_DEFAULT_LOG_BUFFER_SIZE];
+PCHAR KdPrintWritePointer = KdPrintDefaultCircularBuffer;
+ULONG KdPrintRolloverCount;
+PCHAR KdPrintCircularBuffer = KdPrintDefaultCircularBuffer;
+ULONG KdPrintBufferSize = sizeof(KdPrintDefaultCircularBuffer);
+ULONG KdPrintBufferChanges = 0;
+
+//
+// Debug Filter Masks
+//
+ULONG Kd_WIN2000_Mask = 1;
+ULONG Kd_SYSTEM_Mask;
+ULONG Kd_SMSS_Mask;
+ULONG Kd_SETUP_Mask;
+ULONG Kd_NTFS_Mask;
+ULONG Kd_FSTUB_Mask;
+ULONG Kd_CRASHDUMP_Mask;
+ULONG Kd_CDAUDIO_Mask;
+ULONG Kd_CDROM_Mask;
+ULONG Kd_CLASSPNP_Mask;
+ULONG Kd_DISK_Mask;
+ULONG Kd_REDBOOK_Mask;
+ULONG Kd_STORPROP_Mask;
+ULONG Kd_SCSIPORT_Mask;
+ULONG Kd_SCSIMINIPORT_Mask;
+ULONG Kd_CONFIG_Mask;
+ULONG Kd_I8042PRT_Mask;
+ULONG Kd_SERMOUSE_Mask;
+ULONG Kd_LSERMOUS_Mask;
+ULONG Kd_KBDHID_Mask;
+ULONG Kd_MOUHID_Mask;
+ULONG Kd_KBDCLASS_Mask;
+ULONG Kd_MOUCLASS_Mask;
+ULONG Kd_TWOTRACK_Mask;
+ULONG Kd_WMILIB_Mask;
+ULONG Kd_ACPI_Mask;
+ULONG Kd_AMLI_Mask;
+ULONG Kd_HALIA64_Mask;
+ULONG Kd_VIDEO_Mask;
+ULONG Kd_SVCHOST_Mask;
+ULONG Kd_VIDEOPRT_Mask;
+ULONG Kd_TCPIP_Mask;
+ULONG Kd_DMSYNTH_Mask;
+ULONG Kd_NTOSPNP_Mask;
+ULONG Kd_FASTFAT_Mask;
+ULONG Kd_SAMSS_Mask;
+ULONG Kd_PNPMGR_Mask;
+ULONG Kd_NETAPI_Mask;
+ULONG Kd_SCSERVER_Mask;
+ULONG Kd_SCCLIENT_Mask;
+ULONG Kd_SERIAL_Mask;
+ULONG Kd_SERENUM_Mask;
+ULONG Kd_UHCD_Mask;
+ULONG Kd_RPCPROXY_Mask;
+ULONG Kd_AUTOCHK_Mask;
+ULONG Kd_DCOMSS_Mask;
+ULONG Kd_UNIMODEM_Mask;
+ULONG Kd_SIS_Mask;
+ULONG Kd_FLTMGR_Mask;
+ULONG Kd_WMICORE_Mask;
+ULONG Kd_BURNENG_Mask;
+ULONG Kd_IMAPI_Mask;
+ULONG Kd_SXS_Mask;
+ULONG Kd_FUSION_Mask;
+ULONG Kd_IDLETASK_Mask;
+ULONG Kd_SOFTPCI_Mask;
+ULONG Kd_TAPE_Mask;
+ULONG Kd_MCHGR_Mask;
+ULONG Kd_IDEP_Mask;
+ULONG Kd_PCIIDE_Mask;
+ULONG Kd_FLOPPY_Mask;
+ULONG Kd_FDC_Mask;
+ULONG Kd_TERMSRV_Mask;
+ULONG Kd_W32TIME_Mask;
+ULONG Kd_PREFETCHER_Mask;
+ULONG Kd_RSFILTER_Mask;
+ULONG Kd_FCPORT_Mask;
+ULONG Kd_PCI_Mask;
+ULONG Kd_DMIO_Mask;
+ULONG Kd_DMCONFIG_Mask;
+ULONG Kd_DMADMIN_Mask;
+ULONG Kd_WSOCKTRANSPORT_Mask;
+ULONG Kd_VSS_Mask;
+ULONG Kd_PNPMEM_Mask;
+ULONG Kd_PROCESSOR_Mask;
+ULONG Kd_DMSERVER_Mask;
+ULONG Kd_SR_Mask;
+ULONG Kd_INFINIBAND_Mask;
+ULONG Kd_IHVDRIVER_Mask;
+ULONG Kd_IHVVIDEO_Mask;
+ULONG Kd_IHVAUDIO_Mask;
+ULONG Kd_IHVNETWORK_Mask;
+ULONG Kd_IHVSTREAMING_Mask;
+ULONG Kd_IHVBUS_Mask;
+ULONG Kd_HPS_Mask;
+ULONG Kd_RTLTHREADPOOL_Mask;
+ULONG Kd_LDR_Mask;
+ULONG Kd_TCPIP6_Mask;
+ULONG Kd_ISAPNP_Mask;
+ULONG Kd_SHPC_Mask;
+ULONG Kd_STORPORT_Mask;
+ULONG Kd_STORMINIPORT_Mask;
+ULONG Kd_PRINTSPOOLER_Mask;
+ULONG Kd_VSSDYNDISK_Mask;
+ULONG Kd_VERIFIER_Mask;
+ULONG Kd_VDS_Mask;
+ULONG Kd_VDSBAS_Mask;
+ULONG Kd_VDSDYNDR_Mask;
+ULONG Kd_VDSUTIL_Mask;
+ULONG Kd_DFRGIFC_Mask;
+ULONG Kd_DEFAULT_Mask;
+ULONG Kd_MM_Mask;
+ULONG Kd_DFSC_Mask;
+ULONG Kd_WOW64_Mask;
+ULONG Kd_ENDOFTABLE_Mask;
+
+//
+// Debug Filter Component Table
+//
+PULONG KdComponentTable[104] =
+{
+    &Kd_SYSTEM_Mask,
+    &Kd_SMSS_Mask,
+    &Kd_SETUP_Mask,
+    &Kd_NTFS_Mask,
+    &Kd_FSTUB_Mask,
+    &Kd_CRASHDUMP_Mask,
+    &Kd_CDAUDIO_Mask,
+    &Kd_CDROM_Mask,
+    &Kd_CLASSPNP_Mask,
+    &Kd_DISK_Mask,
+    &Kd_REDBOOK_Mask,
+    &Kd_STORPROP_Mask,
+    &Kd_SCSIPORT_Mask,
+    &Kd_SCSIMINIPORT_Mask,
+    &Kd_CONFIG_Mask,
+    &Kd_I8042PRT_Mask,
+    &Kd_SERMOUSE_Mask,
+    &Kd_LSERMOUS_Mask,
+    &Kd_KBDHID_Mask,
+    &Kd_MOUHID_Mask,
+    &Kd_KBDCLASS_Mask,
+    &Kd_MOUCLASS_Mask,
+    &Kd_TWOTRACK_Mask,
+    &Kd_WMILIB_Mask,
+    &Kd_ACPI_Mask,
+    &Kd_AMLI_Mask,
+    &Kd_HALIA64_Mask,
+    &Kd_VIDEO_Mask,
+    &Kd_SVCHOST_Mask,
+    &Kd_VIDEOPRT_Mask,
+    &Kd_TCPIP_Mask,
+    &Kd_DMSYNTH_Mask,
+    &Kd_NTOSPNP_Mask,
+    &Kd_FASTFAT_Mask,
+    &Kd_SAMSS_Mask,
+    &Kd_PNPMGR_Mask,
+    &Kd_NETAPI_Mask,
+    &Kd_SCSERVER_Mask,
+    &Kd_SCCLIENT_Mask,
+    &Kd_SERIAL_Mask,
+    &Kd_SERENUM_Mask,
+    &Kd_UHCD_Mask,
+    &Kd_RPCPROXY_Mask,
+    &Kd_AUTOCHK_Mask,
+    &Kd_DCOMSS_Mask,
+    &Kd_UNIMODEM_Mask,
+    &Kd_SIS_Mask,
+    &Kd_FLTMGR_Mask,
+    &Kd_WMICORE_Mask,
+    &Kd_BURNENG_Mask,
+    &Kd_IMAPI_Mask,
+    &Kd_SXS_Mask,
+    &Kd_FUSION_Mask,
+    &Kd_IDLETASK_Mask,
+    &Kd_SOFTPCI_Mask,
+    &Kd_TAPE_Mask,
+    &Kd_MCHGR_Mask,
+    &Kd_IDEP_Mask,
+    &Kd_PCIIDE_Mask,
+    &Kd_FLOPPY_Mask,
+    &Kd_FDC_Mask,
+    &Kd_TERMSRV_Mask,
+    &Kd_W32TIME_Mask,
+    &Kd_PREFETCHER_Mask,
+    &Kd_RSFILTER_Mask,
+    &Kd_FCPORT_Mask,
+    &Kd_PCI_Mask,
+    &Kd_DMIO_Mask,
+    &Kd_DMCONFIG_Mask,
+    &Kd_DMADMIN_Mask,
+    &Kd_WSOCKTRANSPORT_Mask,
+    &Kd_VSS_Mask,
+    &Kd_PNPMEM_Mask,
+    &Kd_PROCESSOR_Mask,
+    &Kd_DMSERVER_Mask,
+    &Kd_SR_Mask,
+    &Kd_INFINIBAND_Mask,
+    &Kd_IHVDRIVER_Mask,
+    &Kd_IHVVIDEO_Mask,
+    &Kd_IHVAUDIO_Mask,
+    &Kd_IHVNETWORK_Mask,
+    &Kd_IHVSTREAMING_Mask,
+    &Kd_IHVBUS_Mask,
+    &Kd_HPS_Mask,
+    &Kd_RTLTHREADPOOL_Mask,
+    &Kd_LDR_Mask,
+    &Kd_TCPIP6_Mask,
+    &Kd_ISAPNP_Mask,
+    &Kd_SHPC_Mask,
+    &Kd_STORPORT_Mask,
+    &Kd_STORMINIPORT_Mask,
+    &Kd_PRINTSPOOLER_Mask,
+    &Kd_VSSDYNDISK_Mask,
+    &Kd_VERIFIER_Mask,
+    &Kd_VDS_Mask,
+    &Kd_VDSBAS_Mask,
+    &Kd_VDSDYNDR_Mask,
+    &Kd_VDSUTIL_Mask,
+    &Kd_DFRGIFC_Mask,
+    &Kd_DEFAULT_Mask,
+    &Kd_MM_Mask,
+    &Kd_DFSC_Mask,
+    &Kd_WOW64_Mask,
+    &Kd_ENDOFTABLE_Mask,
+};
+
+ULONG KdComponentTableSize = sizeof(KdComponentTable);
+
+//
+// Debugger Data
+//
+LIST_ENTRY KdpDebuggerDataListHead;
+KSPIN_LOCK KdpDataSpinLock;
+
+//
+// Debugger Version and Data Block
+//
+DBGKD_GET_VERSION64 KdVersionBlock =
+{
+    0,
+    0,
+    DBGKD_64BIT_PROTOCOL_VERSION2,
+    CURRENT_KD_SECONDARY_VERSION,
+#if defined(_WIN64)
+    DBGKD_VERS_FLAG_DATA | DBGKD_VERS_FLAG_PTR64,
+#else
+    DBGKD_VERS_FLAG_DATA,
+#endif
+    IMAGE_FILE_MACHINE_ARCHITECTURE,
+    PACKET_TYPE_MAX,
+    0,
+    0,
+    DBGKD_SIMULATION_NONE,
+    {0},
+    0,
+    0,
+    0
+};
+KDDEBUGGER_DATA64 KdDebuggerDataBlock =
+{
+    {{0}},
+    0,
+    {(ULONG_PTR)RtlpBreakWithStatusInstruction},
+    0,
+    FIELD_OFFSET(KTHREAD, CallbackStack),
+    FIELD_OFFSET(KCALLOUT_FRAME, CallbackStack),
+    FIELD_OFFSET(KCALLOUT_FRAME, CBSTACK_FRAME_POINTER),
+    FALSE,
+    {(ULONG_PTR)KiCallUserMode},
+    0,
+    {(ULONG_PTR)&PsLoadedModuleList},
+    {(ULONG_PTR)&PsActiveProcessHead},
+    {(ULONG_PTR)&PspCidTable},
+    {(ULONG_PTR)&ExpSystemResourcesList},
+    {(ULONG_PTR)ExpPagedPoolDescriptor},
+    {(ULONG_PTR)&ExpNumberOfPagedPools},
+    {(ULONG_PTR)&KeTimeIncrement},
+    {(ULONG_PTR)&KeBugcheckCallbackListHead},
+    {(ULONG_PTR)KiBugCheckData},
+    {(ULONG_PTR)&IopErrorLogListHead},
+    {(ULONG_PTR)&ObpRootDirectoryObject},
+    {(ULONG_PTR)&ObpTypeObjectType},
+    {(ULONG_PTR)&MmSystemCacheStart},
+    {(ULONG_PTR)&MmSystemCacheEnd},
+    {(ULONG_PTR)&MmSystemCacheWs},
+    {(ULONG_PTR)&MmPfnDatabase},
+    {(ULONG_PTR)MmSystemPtesStart},
+    {(ULONG_PTR)MmSystemPtesEnd},
+    {(ULONG_PTR)&MmSubsectionBase},
+    {(ULONG_PTR)&MmNumberOfPagingFiles},
+    {(ULONG_PTR)&MmLowestPhysicalPage},
+    {(ULONG_PTR)&MmHighestPhysicalPage},
+    {(ULONG_PTR)&MmNumberOfPhysicalPages},
+    {(ULONG_PTR)&MmMaximumNonPagedPoolInBytes},
+    {(ULONG_PTR)&MmNonPagedSystemStart},
+    {(ULONG_PTR)&MmNonPagedPoolStart},
+    {(ULONG_PTR)&MmNonPagedPoolEnd},
+    {(ULONG_PTR)&MmPagedPoolStart},
+    {(ULONG_PTR)&MmPagedPoolEnd},
+    {(ULONG_PTR)&MmPagedPoolInfo},
+    PAGE_SIZE,
+    {(ULONG_PTR)&MmSizeOfPagedPoolInBytes},
+    {(ULONG_PTR)&MmTotalCommitLimit},
+    {(ULONG_PTR)&MmTotalCommittedPages},
+    {(ULONG_PTR)&MmSharedCommit},
+    {(ULONG_PTR)&MmDriverCommit},
+    {(ULONG_PTR)&MmProcessCommit},
+    {(ULONG_PTR)&MmPagedPoolCommit},
+    {0},
+    {(ULONG_PTR)&MmZeroedPageListHead},
+    {(ULONG_PTR)&MmFreePageListHead},
+    {(ULONG_PTR)&MmStandbyPageListHead},
+    {(ULONG_PTR)&MmModifiedPageListHead},
+    {(ULONG_PTR)&MmModifiedNoWritePageListHead},
+    {(ULONG_PTR)&MmAvailablePages},
+    {(ULONG_PTR)&MmResidentAvailablePages},
+    {(ULONG_PTR)&PoolTrackTable},
+    {(ULONG_PTR)&NonPagedPoolDescriptor},
+    {(ULONG_PTR)&MmHighestUserAddress},
+    {(ULONG_PTR)&MmSystemRangeStart},
+    {(ULONG_PTR)&MmUserProbeAddress},
+    {(ULONG_PTR)KdPrintDefaultCircularBuffer},
+    {(ULONG_PTR)KdPrintDefaultCircularBuffer + 1},
+    {(ULONG_PTR)&KdPrintWritePointer},
+    {(ULONG_PTR)&KdPrintRolloverCount},
+    {(ULONG_PTR)&MmLoadedUserImageList},
+    {(ULONG_PTR)&NtBuildLab},
+    {0},
+    {(ULONG_PTR)KiProcessorBlock},
+    {(ULONG_PTR)&MmUnloadedDrivers},
+    {(ULONG_PTR)&MmLastUnloadedDrivers},
+    {(ULONG_PTR)&MmTriageActionTaken},
+    {(ULONG_PTR)&MmSpecialPoolTag},
+    {(ULONG_PTR)&KernelVerifier},
+    {(ULONG_PTR)&MmVerifierData},
+    {(ULONG_PTR)&MmAllocatedNonPagedPool},
+    {(ULONG_PTR)&MmPeakCommitment},
+    {(ULONG_PTR)&MmtotalCommitLimitMaximum},
+    {(ULONG_PTR)&CmNtCSDVersion},
+    {(ULONG_PTR)&MmPhysicalMemoryBlock},
+    {(ULONG_PTR)&MmSessionBase},
+    {(ULONG_PTR)&MmSessionSize},
+    {0},
+    {0},
+    FIELD_OFFSET(KTHREAD, NextProcessor),
+    FIELD_OFFSET(KTHREAD, Teb),
+    FIELD_OFFSET(KTHREAD, KernelStack),
+    FIELD_OFFSET(KTHREAD, InitialStack),
+    FIELD_OFFSET(KTHREAD, ApcState.Process),
+    FIELD_OFFSET(KTHREAD, State),
+    0,
+    0,
+    sizeof(EPROCESS),
+    FIELD_OFFSET(EPROCESS, Peb),
+    FIELD_OFFSET(EPROCESS, InheritedFromUniqueProcessId),
+    FIELD_OFFSET(EPROCESS, Pcb.DirectoryTableBase),
+    sizeof(KPRCB),
+    FIELD_OFFSET(KPRCB, DpcRoutineActive),
+    FIELD_OFFSET(KPRCB, CurrentThread),
+    FIELD_OFFSET(KPRCB, MHz),
+    FIELD_OFFSET(KPRCB, CpuType),
+    FIELD_OFFSET(KPRCB, VendorString),
+    FIELD_OFFSET(KPRCB, ProcessorState.ContextFrame),
+    FIELD_OFFSET(KPRCB, Number),
+    sizeof(ETHREAD),
+    {(ULONG_PTR)KdPrintDefaultCircularBuffer},
+    {(ULONG_PTR)&KdPrintBufferSize},
+    {(ULONG_PTR)&KeLoaderBlock},
+    sizeof(KPCR),
+    KPCR_SELF_PCR_OFFSET,
+    KPCR_CURRENT_PRCB_OFFSET,
+    KPCR_CONTAINED_PRCB_OFFSET,
+    0,
+    0,
+    KPCR_INITIAL_STACK_OFFSET,
+    KPCR_STACK_LIMIT_OFFSET,
+    KPRCB_PCR_PAGE_OFFSET,
+    FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),
+#if defined(_X86_)
+    //
+    // x86 GDT/LDT/TSS constants
+    //
+    KGDT_R0_CODE,
+    KGDT_R0_DATA,
+    KGDT_R0_PCR,
+    KGDT_R3_CODE,
+    KGDT_R3_DATA,
+    KGDT_R3_TEB,
+    KGDT_LDT,
+    KGDT_TSS,
+    0,
+    0,
+#elif defined(_AMD64_)
+    //
+    // AMD64 GDT/LDT/TSS constants
+    //
+    KGDT64_R0_CODE,
+    KGDT64_R3_DATA,
+    KGDT64_R3_DATA,
+    KGDT64_R3_CODE,
+    KGDT64_R3_DATA,
+    KGDT64_R3_DATA,
+    0,
+    KGDT64_SYS_TSS,
+    0,
+    0,
+#else
+    //
+    // No GDT/LDT/TSS on other architectures
+    //
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+#endif
+    {(ULONG_PTR)&IopNumTriageDumpDataBlocks},
+    {(ULONG_PTR)IopTriageDumpDataBlocks},
+};