KD64 Compatibility Bringup:
authorStefan Ginsberg <stefanginsberg@gmail.com>
Sat, 10 Oct 2009 19:27:54 +0000 (19:27 +0000)
committerStefan Ginsberg <stefanginsberg@gmail.com>
Sat, 10 Oct 2009 19:27:54 +0000 (19:27 +0000)
- Add some missing control set structures to windbgkd.h from Singularity and fix some x86 assumptions.
- Use CopyExceptionRecord instead of ExceptionRecord32To64 as we can just copy directly on 64-bit.
- Add KeGetTrapFrameInterruptState macro to retrieve the interrupt state (ON/OFF) from a trap frame.
- Use macros for retrieving certain parameters from CONTEXT in KdpTrap instead of hardcoding x86.
- Add kdsup.c for x86/AMD64/ARM and move certain architecture dependent routines in here.
- Stub out MSR, Bus and I/O Space read/write support and use KdpSys* for Control Space as it is architecture dependent. Also stub out low memory check (for x86 PAE).
- Fix assumptions in the break point code that a breakpoint is 1 byte long (it is 4 byte on ARM, for example). Define the type required to contain a breakpoint per architecture and use KD_BREAKPOINT_SIZE when copying.
- KD supports 32 breakpoints, not 20.
- Be portable when initializing members of the KD version and debugger data block.
- Pointers in the debugger data block should not be sign extended as done in the version block -- fix KdInitSystem and KdUpdateDataBlock that did this.
- Fix some comments that were x86 specific and use more generic terms instead.
- Fix a cast in KeBugCheckWithTf.

svn path=/trunk/; revision=43365

16 files changed:
reactos/include/ndk/asm.h
reactos/include/reactos/windbgkd.h
reactos/ntoskrnl/include/internal/arm/ke.h
reactos/ntoskrnl/include/internal/i386/ke.h
reactos/ntoskrnl/include/internal/kd64.h
reactos/ntoskrnl/include/internal/powerpc/ke.h
reactos/ntoskrnl/kd64/amd64/kdsup.c [new file with mode: 0644]
reactos/ntoskrnl/kd64/arm/kdsup.c [new file with mode: 0644]
reactos/ntoskrnl/kd64/i386/kdsup.c [new file with mode: 0644]
reactos/ntoskrnl/kd64/kdapi.c
reactos/ntoskrnl/kd64/kdbreak.c
reactos/ntoskrnl/kd64/kddata.c
reactos/ntoskrnl/kd64/kdinit.c
reactos/ntoskrnl/kd64/kdtrap.c
reactos/ntoskrnl/ke/bug.c
reactos/ntoskrnl/ntoskrnl-generic.rbuild

index 6068080..27bbc2e 100644 (file)
@@ -521,6 +521,7 @@ Author:
 #define CBSTACK_EBP                             0x18
 #define CBSTACK_RESULT                          0x20
 #define CBSTACK_RESULT_LENGTH                   0x24
+#define CBSTACK_FRAME_POINTER                   CBSTACK_EBP
 
 //
 // NTSTATUS, Bugcheck Codes and Debug Codes
index 9ee0dd5..bc88bf5 100644 (file)
 // Control Report Flags
 //
 #define REPORT_INCLUDES_SEGS                0x0001
-#define REPORT_INCLUDES_CS                  0x0002
+#define REPORT_STANDARD_CS                  0x0002
 
 //
 // Protocol Versions
@@ -227,6 +227,11 @@ typedef struct _X86_DBGKD_CONTROL_SET
     ULONG CurrentSymbolEnd;
 } X86_DBGKD_CONTROL_SET, *PX86_DBGKD_CONTROL_SET;
 
+typedef struct _ALPHA_DBGKD_CONTROL_SET
+{
+    ULONG __padding;
+} ALPHA_DBGKD_CONTROL_SET, *PALPHA_DBGKD_CONTROL_SET;
+
 typedef struct _IA64_DBGKD_CONTROL_SET
 {
     ULONG Continue;
@@ -254,14 +259,23 @@ typedef struct _DBGKD_ANY_CONTROL_SET
     union
     {
         X86_DBGKD_CONTROL_SET X86ControlSet;
+        ALPHA_DBGKD_CONTROL_SET AlphaControlSet;
         IA64_DBGKD_CONTROL_SET IA64ControlSet;
         AMD64_DBGKD_CONTROL_SET Amd64ControlSet;
-        ARM_DBGKD_CONTROL_SET ArmControlSet;
+        ARM_DBGKD_CONTROL_SET ARMControlSet;
     };
 } DBGKD_ANY_CONTROL_SET, *PDBGKD_ANY_CONTROL_SET;
 #include <poppack.h>
 
+#if defined(_M_IX86)
 typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
+#elif defined(_M_AMD64)
+typedef AMD64_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
+#elif defined(_M_ARM)
+typedef ARM_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
+#else
+#error Unsupported Architecture
+#endif
 
 //
 // DBGKM Structure for Exceptions
@@ -321,7 +335,12 @@ typedef struct _AMD64_DBGKD_CONTROL_REPORT
     USHORT SegFs;
 } AMD64_DBGKD_CONTROL_REPORT, *PAMD64_DBGKD_CONTROL_REPORT;
 
-typedef X86_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT;
+typedef struct _ARM_DBGKD_CONTROL_REPORT
+{
+    ULONG Cpsr;
+    ULONG InstructionCount;
+    UCHAR InstructionStream[DBGKD_MAXSTREAM];
+} ARM_DBGKD_CONTROL_REPORT, *PARM_DBGKD_CONTROL_REPORT;
 
 typedef struct _DBGKD_ANY_CONTROL_REPORT
 {
@@ -331,9 +350,20 @@ typedef struct _DBGKD_ANY_CONTROL_REPORT
         ALPHA_DBGKD_CONTROL_REPORT AlphaControlReport;
         IA64_DBGKD_CONTROL_REPORT IA64ControlReport;
         AMD64_DBGKD_CONTROL_REPORT Amd64ControlReport;
+        ARM_DBGKD_CONTROL_REPORT ARMControlReport;
     };
 } DBGKD_ANY_CONTROL_REPORT, *PDBGKD_ANY_CONTROL_REPORT;
 
+#if defined(_M_IX86)
+typedef X86_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+#elif defined(_M_AMD64)
+typedef AMD64_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+#elif defined(_M_ARM)
+typedef ARM_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
+#else
+#error Unsupported Architecture
+#endif
+
 //
 // DBGKD Structure for Debug I/O Type Print String
 //
@@ -834,6 +864,13 @@ typedef struct _DBGKD_TRACE_IO
    } u;
 } DBGKD_TRACE_IO, *PDBGKD_TRACE_IO;
 
+#if defined(_M_AMD64)
+
+#define CopyExceptionRecord(Ex64From, Ex64To) \
+        RtlCopyMemory(Ex64To, Ex64From, sizeof(EXCEPTION_RECORD64))
+
+#else
+
 FORCEINLINE
 VOID
 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
@@ -853,4 +890,9 @@ ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
     }
 }
 
+#define CopyExceptionRecord(Ex32From, Ex64To) \
+        ExceptionRecord32To64((PEXCEPTION_RECORD32)Ex32From, Ex64To)
+
+#endif
+
 #endif
index 2cbf5e8..0ccc195 100644 (file)
@@ -12,7 +12,9 @@
 //
 // BKPT is 4 bytes long
 //
-#define KD_BREAKPOINT_SIZE 4
+#define KD_BREAKPOINT_TYPE        ULONG
+#define KD_BREAKPOINT_SIZE        sizeof(ULONG)
+//#define KD_BREAKPOINT_VALUE
 
 //
 // Macros for getting and setting special purpose registers in portable code
 #define KeSetContextReturnRegister(Context, ReturnValue) \
     ((Context)->R0 = (ReturnValue))
 
+//
+// Returns the Interrupt State from a Trap Frame.
+// ON = TRUE, OFF = FALSE
+//
+//#define KeGetTrapFrameInterruptState(TrapFrame) \
+
 VOID
 KiPassiveRelease(
     VOID
index 75283b3..4c997d0 100644 (file)
@@ -13,7 +13,9 @@ extern ULONG Ke386CacheAlignment;
 //
 // INT3 is 1 byte long
 //
-#define KD_BREAKPOINT_SIZE 1
+#define KD_BREAKPOINT_TYPE        UCHAR
+#define KD_BREAKPOINT_SIZE        sizeof(UCHAR)
+#define KD_BREAKPOINT_VALUE       0xCC
 
 //
 // Macros for getting and setting special purpose registers in portable code
@@ -33,6 +35,13 @@ extern ULONG Ke386CacheAlignment;
 #define KeSetContextReturnRegister(Context, ReturnValue) \
     ((Context)->Eax = (ReturnValue))
 
+//
+// Returns the Interrupt State from a Trap Frame.
+// ON = TRUE, OFF = FALSE
+//
+#define KeGetTrapFrameInterruptState(TrapFrame) \
+        BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
+
 VOID
 FASTCALL
 Ki386InitializeTss(
index 73dff9b..9296587 100644 (file)
@@ -6,6 +6,11 @@
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)\r
  */\r
 \r
+//\r
+// Maximum supported number of breakpoints\r
+//\r
+#define KD_BREAKPOINT_MAX                               32\r
+\r
 //\r
 // Breakpoint Status Flags\r
 //\r
@@ -25,7 +30,7 @@ typedef struct _BREAKPOINT_ENTRY
     ULONG Flags;\r
     PKPROCESS Process;\r
     PVOID Address;\r
-    UCHAR Content;\r
+    KD_BREAKPOINT_TYPE Content;\r
 } BREAKPOINT_ENTRY, *PBREAKPOINT_ENTRY;\r
 \r
 //\r
@@ -262,6 +267,139 @@ KdpAddBreakpoint(
     IN PVOID Address\r
 );\r
 \r
+//\r
+// Architecture dependent support routines\r
+//\r
+\r
+//\r
+// Version\r
+//\r
+VOID\r
+NTAPI\r
+KdpSysGetVersion(\r
+    IN PDBGKD_GET_VERSION64 Version\r
+);\r
+\r
+//\r
+// Context\r
+//\r
+VOID\r
+NTAPI\r
+KdpGetStateChange(\r
+    IN PDBGKD_MANIPULATE_STATE64 State,\r
+    IN PCONTEXT Context\r
+);\r
+\r
+VOID\r
+NTAPI\r
+KdpSetContextState(\r
+    IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,\r
+    IN PCONTEXT Context\r
+);\r
+\r
+//\r
+// MSR\r
+//\r
+NTSTATUS\r
+NTAPI\r
+KdpSysReadMsr(\r
+    IN ULONG Msr,\r
+    OUT PLARGE_INTEGER MsrValue\r
+);\r
+\r
+NTSTATUS\r
+NTAPI\r
+KdpSysWriteMsr(\r
+    IN ULONG Msr,\r
+    IN PLARGE_INTEGER MsrValue\r
+);\r
+\r
+//\r
+// Bus\r
+//\r
+NTSTATUS\r
+NTAPI\r
+KdpSysReadBusData(\r
+    IN ULONG BusDataType,\r
+    IN ULONG BusNumber,\r
+    IN ULONG SlotNumber,\r
+    IN PVOID Buffer,\r
+    IN ULONG Offset,\r
+    IN ULONG Length,\r
+    OUT PULONG ActualLength\r
+);\r
+\r
+NTSTATUS\r
+NTAPI\r
+KdpSysWriteBusData(\r
+    IN ULONG BusDataType,\r
+    IN ULONG BusNumber,\r
+    IN ULONG SlotNumber,\r
+    IN PVOID Buffer,\r
+    IN ULONG Offset,\r
+    IN ULONG Length,\r
+    OUT PULONG ActualLength\r
+);\r
+\r
+//\r
+// Control Space\r
+//\r
+NTSTATUS\r
+NTAPI\r
+KdpSysReadControlSpace(\r
+    IN ULONG Processor,\r
+    IN ULONG64 BaseAddress,\r
+    IN PVOID Buffer,\r
+    IN ULONG Length,\r
+    OUT PULONG ActualLength\r
+);\r
+\r
+NTSTATUS\r
+NTAPI\r
+KdpSysWriteControlSpace(\r
+    IN ULONG Processor,\r
+    IN ULONG64 BaseAddress,\r
+    IN PVOID Buffer,\r
+    IN ULONG Length,\r
+    OUT PULONG ActualLength\r
+);\r
+\r
+//\r
+// I/O Space\r
+//\r
+NTSTATUS\r
+NTAPI\r
+KdpSysReadIoSpace(\r
+    IN ULONG InterfaceType,\r
+    IN ULONG BusNumber,\r
+    IN ULONG AddressSpace,\r
+    IN ULONG64 IoAddress,\r
+    IN PULONG DataValue,\r
+    IN ULONG DataSize,\r
+    OUT PULONG ActualDataSize\r
+);\r
+\r
+NTSTATUS\r
+NTAPI\r
+KdpSysWriteIoSpace(\r
+    IN ULONG InterfaceType,\r
+    IN ULONG BusNumber,\r
+    IN ULONG AddressSpace,\r
+    IN ULONG64 IoAddress,\r
+    IN PULONG DataValue,\r
+    IN ULONG DataSize,\r
+    OUT PULONG ActualDataSize\r
+);\r
+\r
+//\r
+// Low Memory\r
+//\r
+NTSTATUS\r
+NTAPI\r
+KdpSysCheckLowMemory(\r
+    IN ULONG Flags\r
+);\r
+\r
 //\r
 // Internal routine for sending strings directly to the debugger\r
 //\r
@@ -307,8 +445,8 @@ extern ULONG KdComponentTableSize;
 extern ULONG Kd_WIN2000_Mask;\r
 extern PULONG KdComponentTable[104];\r
 extern CHAR KdpMessageBuffer[4096], KdpPathBuffer[4096];\r
-extern BREAKPOINT_ENTRY KdpBreakpointTable[20];\r
-extern ULONG KdpBreakpointInstruction;\r
+extern BREAKPOINT_ENTRY KdpBreakpointTable[KD_BREAKPOINT_MAX];\r
+extern KD_BREAKPOINT_TYPE KdpBreakpointInstruction;\r
 extern BOOLEAN KdpOweBreakpoint;\r
 extern BOOLEAN BreakpointsSuspended;\r
 extern ULONG KdpNumInternalBreakpoints;\r
index 4c87473..1947bca 100644 (file)
@@ -37,6 +37,10 @@ extern ULONG KePPCCacheAlignment;
 
 #define IMAGE_FILE_MACHINE_ARCHITECTURE IMAGE_FILE_MACHINE_POWERPC
 
+//#define KD_BREAKPOINT_TYPE
+//#define KD_BREAKPOINT_SIZE
+//#define KD_BREAKPOINT_VALUE
+
 //
 // Macros for getting and setting special purpose registers in portable code
 //
@@ -55,6 +59,12 @@ extern ULONG KePPCCacheAlignment;
 #define KeSetContextReturnRegister(Context, ReturnValue) \
     ((Context)->Gpr3 = (ReturnValue))
 
+//
+// Returns the Interrupt State from a Trap Frame.
+// ON = TRUE, OFF = FALSE
+//
+//#define KeGetTrapFrameInterruptState(TrapFrame) \
+
 #define KePPCRdmsr(msr,val1,val2) __asm__ __volatile__("mfmsr 3")
 
 #define KePPCWrmsr(msr,val1,val2) __asm__ __volatile__("mtmsr 3")
diff --git a/reactos/ntoskrnl/kd64/amd64/kdsup.c b/reactos/ntoskrnl/kd64/amd64/kdsup.c
new file mode 100644 (file)
index 0000000..ba07617
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            ntoskrnl/kd64/amd64/kdsup.c
+ * PURPOSE:         KD support routines for AMD64
+ * PROGRAMMERS:     Timo Kreuzer (timo.kreuzer@reactos.org)
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#undef UNIMPLEMENTED
+#define UNIMPLEMENTED KdpDprintf("%s is unimplemented\n", __FUNCTION__)
+
+/* FUNCTIONS *****************************************************************/
+
+VOID
+NTAPI
+KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
+                  IN PCONTEXT Context)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+}
+
+VOID
+NTAPI
+KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+                   IN PCONTEXT Context)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+}
+
+VOID
+NTAPI
+KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadMsr(IN ULONG Msr,
+              OUT PLARGE_INTEGER MsrValue)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteMsr(IN ULONG Msr,
+               IN PLARGE_INTEGER MsrValue)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadBusData(IN ULONG BusDataType,
+                  IN ULONG BusNumber,
+                  IN ULONG SlotNumber,
+                  IN PVOID Buffer,
+                  IN ULONG Offset,
+                  IN ULONG Length,
+                  OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteBusData(IN ULONG BusDataType,
+                   IN ULONG BusNumber,
+                   IN ULONG SlotNumber,
+                   IN PVOID Buffer,
+                   IN ULONG Offset,
+                   IN ULONG Length,
+                   OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadControlSpace(IN ULONG Processor,
+                       IN ULONG64 BaseAddress,
+                       IN PVOID Buffer,
+                       IN ULONG Length,
+                       OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteControlSpace(IN ULONG Processor,
+                        IN ULONG64 BaseAddress,
+                        IN PVOID Buffer,
+                        IN ULONG Length,
+                        OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadIoSpace(IN ULONG InterfaceType,
+                  IN ULONG BusNumber,
+                  IN ULONG AddressSpace,
+                  IN ULONG64 IoAddress,
+                  IN PULONG DataValue,
+                  IN ULONG DataSize,
+                  OUT PULONG ActualDataSize)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteIoSpace(IN ULONG InterfaceType,
+                   IN ULONG BusNumber,
+                   IN ULONG AddressSpace,
+                   IN ULONG64 IoAddress,
+                   IN PULONG DataValue,
+                   IN ULONG DataSize,
+                   OUT PULONG ActualDataSize)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysCheckLowMemory(IN ULONG Flags)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
diff --git a/reactos/ntoskrnl/kd64/arm/kdsup.c b/reactos/ntoskrnl/kd64/arm/kdsup.c
new file mode 100644 (file)
index 0000000..44857e6
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         BSD - See COPYING.ARM in the top level directory
+ * FILE:            ntoskrnl/kd64/arm/kdsup.c
+ * PURPOSE:         KD support routines for ARM
+ * PROGRAMMERS:     ReactOS Portable Systems Group
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#undef UNIMPLEMENTED
+#define UNIMPLEMENTED KdpDprintf("%s is unimplemented\n", __FUNCTION__)
+
+/* FUNCTIONS *****************************************************************/
+
+VOID
+NTAPI
+KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
+                  IN PCONTEXT Context)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+}
+
+VOID
+NTAPI
+KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+                   IN PCONTEXT Context)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+}
+
+VOID
+NTAPI
+KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadMsr(IN ULONG Msr,
+              OUT PLARGE_INTEGER MsrValue)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteMsr(IN ULONG Msr,
+               IN PLARGE_INTEGER MsrValue)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadBusData(IN ULONG BusDataType,
+                  IN ULONG BusNumber,
+                  IN ULONG SlotNumber,
+                  IN PVOID Buffer,
+                  IN ULONG Offset,
+                  IN ULONG Length,
+                  OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteBusData(IN ULONG BusDataType,
+                   IN ULONG BusNumber,
+                   IN ULONG SlotNumber,
+                   IN PVOID Buffer,
+                   IN ULONG Offset,
+                   IN ULONG Length,
+                   OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadControlSpace(IN ULONG Processor,
+                       IN ULONG64 BaseAddress,
+                       IN PVOID Buffer,
+                       IN ULONG Length,
+                       OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteControlSpace(IN ULONG Processor,
+                        IN ULONG64 BaseAddress,
+                        IN PVOID Buffer,
+                        IN ULONG Length,
+                        OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadIoSpace(IN ULONG InterfaceType,
+                  IN ULONG BusNumber,
+                  IN ULONG AddressSpace,
+                  IN ULONG64 IoAddress,
+                  IN PULONG DataValue,
+                  IN ULONG DataSize,
+                  OUT PULONG ActualDataSize)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteIoSpace(IN ULONG InterfaceType,
+                   IN ULONG BusNumber,
+                   IN ULONG AddressSpace,
+                   IN ULONG64 IoAddress,
+                   IN PULONG DataValue,
+                   IN ULONG DataSize,
+                   OUT PULONG ActualDataSize)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysCheckLowMemory(IN ULONG Flags)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
diff --git a/reactos/ntoskrnl/kd64/i386/kdsup.c b/reactos/ntoskrnl/kd64/i386/kdsup.c
new file mode 100644 (file)
index 0000000..69d1f34
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * FILE:            ntoskrnl/kd64/i386/kdsup.c
+ * PURPOSE:         KD support routines for x86
+ * PROGRAMMERS:     Stefan Ginsberg (stefan.ginsberg@reactos.org)
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#undef UNIMPLEMENTED
+#define UNIMPLEMENTED KdpDprintf("%s is unimplemented\n", __FUNCTION__)
+
+/* FUNCTIONS *****************************************************************/
+
+VOID
+NTAPI
+KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
+{
+    /* Copy the version block */
+    RtlCopyMemory(Version, &KdVersionBlock, sizeof(DBGKD_GET_VERSION64));
+}
+
+VOID
+NTAPI
+KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
+                  IN PCONTEXT Context)
+{
+    PKPRCB Prcb;
+    ULONG i;
+
+    /* Check for success */
+    if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
+    {
+        /* Check if we're tracing */
+        if (State->u.Continue2.ControlSet.TraceFlag)
+        {
+            /* Enable TF */
+            Context->EFlags |= EFLAGS_TF;
+        }
+        else
+        {
+            /* Remove it */
+            Context->EFlags &= ~EFLAGS_TF;
+        }
+
+        /* Loop all processors */
+        for (i = 0; i < KeNumberProcessors; i++)
+        {
+            /* Get the PRCB and update DR7 and DR6 */
+            Prcb = KiProcessorBlock[i];
+            Prcb->ProcessorState.SpecialRegisters.KernelDr7 =
+                State->u.Continue2.ControlSet.Dr7;
+            Prcb->ProcessorState.SpecialRegisters.KernelDr6 = 0;
+        }
+
+        /* Check if we have new symbol information */
+        if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
+        {
+            /* Update it */
+            KdpCurrentSymbolStart =
+                State->u.Continue2.ControlSet.CurrentSymbolStart;
+            KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
+        }
+    }
+}
+
+VOID
+NTAPI
+KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+                   IN PCONTEXT Context)
+{
+    PKPRCB Prcb = KeGetCurrentPrcb();
+
+    /* Copy i386 specific debug registers */
+    WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
+                                         KernelDr6;
+    WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
+                                         KernelDr7;
+
+    /* Copy i386 specific segments */
+    WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;
+    WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;
+    WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;
+    WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;
+
+    /* Copy EFlags */
+    WaitStateChange->ControlReport.EFlags = Context->EFlags;
+
+    /* Set Report Flags */
+    WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
+    if (WaitStateChange->ControlReport.SegCs == KGDT_R0_CODE)
+    {
+        WaitStateChange->ControlReport.ReportFlags = REPORT_STANDARD_CS;
+    }
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadMsr(IN ULONG Msr,
+              OUT PLARGE_INTEGER MsrValue)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteMsr(IN ULONG Msr,
+               IN PLARGE_INTEGER MsrValue)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadBusData(IN ULONG BusDataType,
+                  IN ULONG BusNumber,
+                  IN ULONG SlotNumber,
+                  IN PVOID Buffer,
+                  IN ULONG Offset,
+                  IN ULONG Length,
+                  OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteBusData(IN ULONG BusDataType,
+                   IN ULONG BusNumber,
+                   IN ULONG SlotNumber,
+                   IN PVOID Buffer,
+                   IN ULONG Offset,
+                   IN ULONG Length,
+                   OUT PULONG ActualLength)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadControlSpace(IN ULONG Processor,
+                       IN ULONG64 BaseAddress,
+                       IN PVOID Buffer,
+                       IN ULONG Length,
+                       OUT PULONG ActualLength)
+{
+    PVOID ControlStart;
+    ULONG RealLength;
+
+    /* Make sure that this is a valid request */
+    if (((ULONG)BaseAddress < sizeof(KPROCESSOR_STATE)) &&
+        (Processor < KeNumberProcessors))
+    {
+        /* Get the actual length */
+        RealLength = sizeof(KPROCESSOR_STATE) - (ULONG_PTR)BaseAddress;
+        if (RealLength < Length) Length = RealLength;
+
+        /* Set the proper address */
+        ControlStart = (PVOID)((ULONG_PTR)BaseAddress +
+                               (ULONG_PTR)&KiProcessorBlock[Processor]->
+                                           ProcessorState);
+
+        /* Copy the memory */
+        RtlCopyMemory(Buffer, ControlStart, Length);
+
+        /* Finish up */
+        *ActualLength = Length;
+        return STATUS_SUCCESS;
+    }
+    else
+    {
+        /* Invalid request */
+        *ActualLength = 0;
+        return STATUS_UNSUCCESSFUL;
+    }
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteControlSpace(IN ULONG Processor,
+                        IN ULONG64 BaseAddress,
+                        IN PVOID Buffer,
+                        IN ULONG Length,
+                        OUT PULONG ActualLength)
+{
+    PVOID ControlStart;
+
+    /* Make sure that this is a valid request */
+    if ((((ULONG)BaseAddress + Length) <= sizeof(KPROCESSOR_STATE)) &&
+        (Processor < KeNumberProcessors))
+    {
+        /* Set the proper address */
+        ControlStart = (PVOID)((ULONG_PTR)BaseAddress +
+                               (ULONG_PTR)&KiProcessorBlock[Processor]->
+                                           ProcessorState);
+
+        /* Copy the memory */
+        RtlCopyMemory(ControlStart, Buffer, Length);
+
+        /* Finish up */
+        *ActualLength = Length;
+        return STATUS_SUCCESS;
+    }
+    else
+    {
+        /* Invalid request */
+        *ActualLength = 0;
+        return STATUS_UNSUCCESSFUL;
+    }
+}
+
+NTSTATUS
+NTAPI
+KdpSysReadIoSpace(IN ULONG InterfaceType,
+                  IN ULONG BusNumber,
+                  IN ULONG AddressSpace,
+                  IN ULONG64 IoAddress,
+                  IN PULONG DataValue,
+                  IN ULONG DataSize,
+                  OUT PULONG ActualDataSize)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysWriteIoSpace(IN ULONG InterfaceType,
+                   IN ULONG BusNumber,
+                   IN ULONG AddressSpace,
+                   IN ULONG64 IoAddress,
+                   IN PULONG DataValue,
+                   IN ULONG DataSize,
+                   OUT PULONG ActualDataSize)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
+
+NTSTATUS
+NTAPI
+KdpSysCheckLowMemory(IN ULONG Flags)
+{
+    UNIMPLEMENTED;
+    while (TRUE);
+    return STATUS_UNSUCCESSFUL;
+}
index 1a55204..4948175 100644 (file)
@@ -27,7 +27,7 @@ KdpQueryMemory(IN PDBGKD_MANIPULATE_STATE64 State,
     if (Memory->AddressSpace == DBGKD_QUERY_MEMORY_VIRTUAL)\r
     {\r
         /* Check if this is process memory */\r
-        if ((PVOID)(LONG_PTR)Memory->Address < MmHighestUserAddress)\r
+        if ((PVOID)(ULONG_PTR)Memory->Address < MmHighestUserAddress)\r
         {\r
             /* It is */\r
             Memory->AddressSpace = DBGKD_QUERY_MEMORY_PROCESS;\r
@@ -80,7 +80,7 @@ KdpWriteBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State,
 \r
     /* Create the breakpoint */\r
     Breakpoint->BreakPointHandle =\r
-        KdpAddBreakpoint((PVOID)(LONG_PTR)Breakpoint->BreakPointAddress);\r
+        KdpAddBreakpoint((PVOID)(ULONG_PTR)Breakpoint->BreakPointAddress);\r
     if (!Breakpoint->BreakPointHandle)\r
     {\r
         /* We failed */\r
@@ -114,50 +114,6 @@ DumpTraceData(IN PSTRING TraceData)
     TraceDataBufferPosition = 1;\r
 }\r
 \r
-VOID\r
-NTAPI\r
-KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,\r
-                  IN PCONTEXT Context)\r
-{\r
-    PKPRCB Prcb;\r
-    ULONG i;\r
-\r
-    /* Check for success */\r
-    if (NT_SUCCESS(State->u.Continue2.ContinueStatus))\r
-    {\r
-        /* Check if we're tracing */\r
-        if (State->u.Continue2.ControlSet.TraceFlag)\r
-        {\r
-            /* Enable TF */\r
-            Context->EFlags |= EFLAGS_TF;\r
-        }\r
-        else\r
-        {\r
-            /* Remove it */\r
-            Context->EFlags &= ~EFLAGS_TF;\r
-        }\r
-\r
-        /* Loop all processors */\r
-        for (i = 0; i < KeNumberProcessors; i++)\r
-        {\r
-            /* Get the PRCB and update DR7 and DR6 */\r
-            Prcb = KiProcessorBlock[i];\r
-            Prcb->ProcessorState.SpecialRegisters.KernelDr7 =\r
-                State->u.Continue2.ControlSet.Dr7;\r
-            Prcb->ProcessorState.SpecialRegisters.KernelDr6 = 0;\r
-        }\r
-\r
-        /* Check if we have new symbol information */\r
-        if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)\r
-        {\r
-            /* Update it */\r
-            KdpCurrentSymbolStart =\r
-                State->u.Continue2.ControlSet.CurrentSymbolStart;\r
-            KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;\r
-        }\r
-    }\r
-}\r
-\r
 VOID\r
 NTAPI\r
 KdpSetCommonState(IN ULONG NewState,\r
@@ -188,7 +144,7 @@ KdpSetCommonState(IN ULONG NewState,
 \r
     /* Clear all the breakpoints in this region */\r
     HadBreakpoints =\r
-        KdpDeleteBreakpointRange((PVOID)(LONG_PTR)WaitStateChange->ProgramCounter,\r
+        KdpDeleteBreakpointRange((PVOID)(ULONG_PTR)WaitStateChange->ProgramCounter,\r
                                  (PVOID)((ULONG_PTR)WaitStateChange->ProgramCounter +\r
                                          WaitStateChange->ControlReport.InstructionCount - 1));\r
     if (HadBreakpoints)\r
@@ -200,44 +156,6 @@ KdpSetCommonState(IN ULONG NewState,
     }\r
 }\r
 \r
-VOID\r
-NTAPI\r
-KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,\r
-                   IN PCONTEXT Context)\r
-{\r
-    PKPRCB Prcb = KeGetCurrentPrcb();\r
-\r
-    /* Copy i386 specific debug registers */\r
-    WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.\r
-                                         KernelDr6;\r
-    WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.\r
-                                         KernelDr7;\r
-\r
-    /* Copy i386 specific segments */\r
-    WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;\r
-    WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;\r
-    WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;\r
-    WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;\r
-\r
-    /* Copy EFlags */\r
-    WaitStateChange->ControlReport.EFlags = Context->EFlags;\r
-\r
-    /* Set Report Flags */\r
-    WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;\r
-    if (WaitStateChange->ControlReport.SegCs == KGDT_R0_CODE)\r
-    {\r
-        WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_CS;\r
-    }\r
-}\r
-\r
-VOID\r
-NTAPI\r
-KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)\r
-{\r
-    /* Copy the version block */\r
-    RtlCopyMemory(Version, &KdVersionBlock, sizeof(DBGKD_GET_VERSION64));\r
-}\r
-\r
 VOID\r
 NTAPI\r
 KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)\r
@@ -324,8 +242,7 @@ KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
 {\r
     PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;\r
     STRING Header;\r
-    ULONG Length, RealLength;\r
-    PVOID ControlStart;\r
+    ULONG Length;\r
 \r
     /* Setup the header */\r
     Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
@@ -340,35 +257,15 @@ KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
         Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);\r
     }\r
 \r
-    /* Make sure that this is a valid request */\r
-    if (((ULONG)ReadMemory->TargetBaseAddress < sizeof(KPROCESSOR_STATE)) &&\r
-        (State->Processor < KeNumberProcessors))\r
-    {\r
-        /* Get the actual length */\r
-        RealLength = sizeof(KPROCESSOR_STATE) -\r
-                     (ULONG_PTR)ReadMemory->TargetBaseAddress;\r
-        if (RealLength < Length) Length = RealLength;\r
-\r
-        /* Set the proper address */\r
-        ControlStart = (PVOID)((ULONG_PTR)ReadMemory->TargetBaseAddress +\r
-                               (ULONG_PTR)&KiProcessorBlock[State->Processor]->\r
-                                           ProcessorState);\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysReadControlSpace(State->Processor,\r
+                                                 ReadMemory->TargetBaseAddress,\r
+                                                 Data->Buffer,\r
+                                                 Length,\r
+                                                 &Length);\r
 \r
-        /* Copy the memory */\r
-        RtlCopyMemory(Data->Buffer, ControlStart, Length);\r
-        Data->Length = Length;\r
-\r
-        /* Finish up */\r
-        State->ReturnStatus = STATUS_SUCCESS;\r
-        ReadMemory->ActualBytesRead = Data->Length;\r
-    }\r
-    else\r
-    {\r
-        /* Invalid request */\r
-        Data->Length = 0;\r
-        State->ReturnStatus = STATUS_UNSUCCESSFUL;\r
-        ReadMemory->ActualBytesRead = 0;\r
-    }\r
+    /* Return the actual length read */\r
+    Data->Length = ReadMemory->ActualBytesRead = Length;\r
 \r
     /* Send the reply */\r
     KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
@@ -386,38 +283,20 @@ KdpWriteControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
     PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;\r
     STRING Header;\r
     ULONG Length;\r
-    PVOID ControlStart;\r
 \r
     /* Setup the header */\r
     Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
     Header.Buffer = (PCHAR)State;\r
 \r
-    /* Make sure that this is a valid request */\r
-    Length = WriteMemory->TransferCount;\r
-    if ((((ULONG)WriteMemory->TargetBaseAddress + Length) <=\r
-          sizeof(KPROCESSOR_STATE)) &&\r
-        (State->Processor < KeNumberProcessors))\r
-    {\r
-        /* Set the proper address */\r
-        ControlStart = (PVOID)((ULONG_PTR)WriteMemory->TargetBaseAddress +\r
-                               (ULONG_PTR)&KiProcessorBlock[State->Processor]->\r
-                                           ProcessorState);\r
-\r
-        /* Copy the memory */\r
-        RtlCopyMemory(ControlStart, Data->Buffer, Data->Length);\r
-        Length = Data->Length;\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysWriteControlSpace(State->Processor,\r
+                                                  WriteMemory->TargetBaseAddress,\r
+                                                  Data->Buffer,\r
+                                                  Data->Length,\r
+                                                  &Length);\r
 \r
-        /* Finish up */\r
-        State->ReturnStatus = STATUS_SUCCESS;\r
-        WriteMemory->ActualBytesWritten = Length;\r
-    }\r
-    else\r
-    {\r
-        /* Invalid request */\r
-        Data->Length = 0;\r
-        State->ReturnStatus = STATUS_UNSUCCESSFUL;\r
-        WriteMemory->ActualBytesWritten = 0;\r
-    }\r
+    /* Return the length written */\r
+    WriteMemory->ActualBytesWritten = Length;\r
 \r
     /* Send the reply */\r
     KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
@@ -568,6 +447,293 @@ KdpCauseBugCheck(IN PDBGKD_MANIPULATE_STATE64 State)
     KeBugCheck(MANUALLY_INITIATED_CRASH);\r
 }\r
 \r
+VOID\r
+NTAPI\r
+KdpReadMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State,\r
+                               IN PSTRING Data,\r
+                               IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_READ_WRITE_MSR ReadMsr = &State->u.ReadWriteMsr;\r
+    LARGE_INTEGER MsrValue;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysReadMsr(ReadMsr->Msr,\r
+                                        &MsrValue);\r
+\r
+    /* Return the data */\r
+    ReadMsr->DataValueLow = MsrValue.LowPart;\r
+    ReadMsr->DataValueHigh = MsrValue.HighPart;\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpWriteMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State,\r
+                                IN PSTRING Data,\r
+                                IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_READ_WRITE_MSR WriteMsr = &State->u.ReadWriteMsr;\r
+    LARGE_INTEGER MsrValue;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /* Call the internal routine */\r
+    MsrValue.LowPart = WriteMsr->DataValueLow;\r
+    MsrValue.HighPart = WriteMsr->DataValueHigh;\r
+    State->ReturnStatus = KdpSysWriteMsr(WriteMsr->Msr,\r
+                                         &MsrValue);\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpGetBusData(IN PDBGKD_MANIPULATE_STATE64 State,\r
+              IN PSTRING Data,\r
+              IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_GET_SET_BUS_DATA GetBusData = &State->u.GetSetBusData;\r
+    ULONG Length;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /* Check the length requested */\r
+    Length = GetBusData->Length;\r
+    if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))\r
+    {\r
+        /* Use maximum allowed */\r
+        Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);\r
+    }\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysReadBusData(GetBusData->BusDataType,\r
+                                            GetBusData->BusNumber,\r
+                                            GetBusData->SlotNumber,\r
+                                            Data->Buffer,\r
+                                            GetBusData->Offset,\r
+                                            Length,\r
+                                            &Length);\r
+\r
+    /* Return the actual length read */\r
+    Data->Length = GetBusData->Length = Length;\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 Data,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpSetBusData(IN PDBGKD_MANIPULATE_STATE64 State,\r
+              IN PSTRING Data,\r
+              IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_GET_SET_BUS_DATA SetBusData = &State->u.GetSetBusData;\r
+    ULONG Length;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysWriteBusData(SetBusData->BusDataType,\r
+                                             SetBusData->BusNumber,\r
+                                             SetBusData->SlotNumber,\r
+                                             Data->Buffer,\r
+                                             SetBusData->Offset,\r
+                                             SetBusData->Length,\r
+                                             &Length);\r
+\r
+    /* Return the actual length written */\r
+    SetBusData->Length = Length;\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 Data,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpReadIoSpace(IN PDBGKD_MANIPULATE_STATE64 State,\r
+               IN PSTRING Data,\r
+               IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_READ_WRITE_IO64 ReadIo = &State->u.ReadWriteIo;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /*\r
+     * Clear the value so 1 or 2 byte reads\r
+     * don't leave the higher bits unmodified \r
+     */\r
+    ReadIo->DataValue = 0;\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysReadIoSpace(Isa,\r
+                                            0,\r
+                                            1,\r
+                                            ReadIo->IoAddress,\r
+                                            &ReadIo->DataValue,\r
+                                            ReadIo->DataSize,\r
+                                            &ReadIo->DataSize);\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpWriteIoSpace(IN PDBGKD_MANIPULATE_STATE64 State,\r
+                IN PSTRING Data,\r
+                IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_READ_WRITE_IO64 WriteIo = &State->u.ReadWriteIo;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysWriteIoSpace(Isa,\r
+                                             0,\r
+                                             1,\r
+                                             WriteIo->IoAddress,\r
+                                             &WriteIo->DataValue,\r
+                                             WriteIo->DataSize,\r
+                                             &WriteIo->DataSize);\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpReadIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State,\r
+                       IN PSTRING Data,\r
+                       IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_READ_WRITE_IO_EXTENDED64 ReadIoExtended = &State->u.\r
+                                                      ReadWriteIoExtended;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /*\r
+     * Clear the value so 1 or 2 byte reads\r
+     * don't leave the higher bits unmodified \r
+     */\r
+    ReadIoExtended->DataValue = 0;\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysReadIoSpace(ReadIoExtended->InterfaceType,\r
+                                            ReadIoExtended->BusNumber,\r
+                                            ReadIoExtended->AddressSpace,\r
+                                            ReadIoExtended->IoAddress,\r
+                                            &ReadIoExtended->DataValue,\r
+                                            ReadIoExtended->DataSize,\r
+                                            &ReadIoExtended->DataSize);\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpWriteIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State,\r
+                        IN PSTRING Data,\r
+                        IN PCONTEXT Context)\r
+{\r
+    STRING Header;\r
+    PDBGKD_READ_WRITE_IO_EXTENDED64 WriteIoExtended = &State->u.\r
+                                                       ReadWriteIoExtended;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+    ASSERT(Data->Length == 0);\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysReadIoSpace(WriteIoExtended->InterfaceType,\r
+                                            WriteIoExtended->BusNumber,\r
+                                            WriteIoExtended->AddressSpace,\r
+                                            WriteIoExtended->IoAddress,\r
+                                            &WriteIoExtended->DataValue,\r
+                                            WriteIoExtended->DataSize,\r
+                                            &WriteIoExtended->DataSize);\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
+VOID\r
+NTAPI\r
+KdpCheckLowMemory(IN PDBGKD_MANIPULATE_STATE64 State)\r
+{\r
+    STRING Header;\r
+\r
+    /* Setup the header */\r
+    Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);\r
+    Header.Buffer = (PCHAR)State;\r
+\r
+    /* Call the internal routine */\r
+    State->ReturnStatus = KdpSysCheckLowMemory(0x4);\r
+\r
+    /* Send the reply */\r
+    KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,\r
+                 &Header,\r
+                 NULL,\r
+                 &KdpContext);\r
+}\r
+\r
 KCONTINUE_STATUS\r
 NTAPI\r
 KdpSendWaitContinue(IN ULONG PacketType,\r
@@ -670,16 +836,14 @@ SendPacket:
 \r
             case DbgKdReadIoSpaceApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdReadIoSpaceApi called\n");\r
-                while (TRUE);\r
+                /* Read I/O Space */\r
+                KdpReadIoSpace(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdWriteIoSpaceApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdWriteIoSpaceApi called\n");\r
-                while (TRUE);\r
+                /* Write I/O Space */\r
+                KdpWriteIoSpace(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdRebootApi:\r
@@ -757,16 +921,14 @@ SendPacket:
 \r
             case DbgKdReadIoSpaceExtendedApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdReadIoSpaceExtendedApi called\n");\r
-                while (TRUE);\r
+                /* Read I/O Space */\r
+                KdpReadIoSpaceExtended(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdWriteIoSpaceExtendedApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdWriteIoSpaceExtendedApi called\n");\r
-                while (TRUE);\r
+                /* Write I/O Space */\r
+                KdpWriteIoSpaceExtended(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdGetVersionApi:\r
@@ -811,16 +973,14 @@ SendPacket:
 \r
             case DbgKdReadMachineSpecificRegister:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdReadMachineSpecificRegister called\n");\r
-                while (TRUE);\r
+                /* Read from the specified MSR */\r
+                KdpReadMachineSpecificRegister(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdWriteMachineSpecificRegister:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdWriteMachineSpecificRegister called\n");\r
-                while (TRUE);\r
+                /* Write to the specified MSR */\r
+                KdpWriteMachineSpecificRegister(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case OldVlm1:\r
@@ -846,23 +1006,20 @@ SendPacket:
 \r
             case DbgKdGetBusDataApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdGetBusDataApi called\n");\r
-                while (TRUE);\r
+                /* Read from the bus */\r
+                KdpGetBusData(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdSetBusDataApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdSetBusDataApi called\n");\r
-                while (TRUE);\r
+                /* Write to the bus */\r
+                KdpSetBusData(&ManipulateState, &Data, Context);\r
                 break;\r
 \r
             case DbgKdCheckLowMemoryApi:\r
 \r
-                /* FIXME: TODO */\r
-                KdpDprintf("DbgKdCheckLowMemoryApi called\n");\r
-                while (TRUE);\r
+                /* Check for memory corruption in the lower 4 GB */\r
+                KdpCheckLowMemory(&ManipulateState);\r
                 break;\r
 \r
             case DbgKdClearAllInternalBreakpointsApi:\r
@@ -936,7 +1093,7 @@ KdpReportLoadSymbolsStateChange(IN PSTRING PathName,
 \r
         /* Fill out load data */\r
         WaitStateChange.u.LoadSymbols.UnloadSymbols = Unload;\r
-        WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONGLONG)(LONG_PTR)SymbolInfo->BaseOfDll;\r
+        WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONG64)(LONG_PTR)SymbolInfo->BaseOfDll;\r
         WaitStateChange.u.LoadSymbols.ProcessId = SymbolInfo->ProcessId;\r
         WaitStateChange.u.LoadSymbols.CheckSum = SymbolInfo->CheckSum;\r
         WaitStateChange.u.LoadSymbols.SizeOfImage = SymbolInfo->SizeOfImage;\r
@@ -981,7 +1138,7 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
 {\r
     STRING Header, Data;\r
     DBGKD_WAIT_STATE_CHANGE64 WaitStateChange;\r
-    BOOLEAN Status;\r
+    KCONTINUE_STATUS Status;\r
 \r
     /* Start report loop */\r
     do\r
@@ -989,9 +1146,9 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
         /* Build the architecture common parts of the message */\r
         KdpSetCommonState(DbgKdExceptionStateChange, Context, &WaitStateChange);\r
 \r
-        /* Convert the exception record to 64-bits and set First Chance flag */\r
-        ExceptionRecord32To64((PEXCEPTION_RECORD32)ExceptionRecord,\r
-                              &WaitStateChange.u.Exception.ExceptionRecord);\r
+        /* Copy the Exception Record and set First Chance flag */\r
+        CopyExceptionRecord(ExceptionRecord,\r
+                            &WaitStateChange.u.Exception.ExceptionRecord);\r
         WaitStateChange.u.Exception.FirstChance = !SecondChanceException;\r
 \r
         /* Now finish creating the structure */\r
@@ -1091,7 +1248,7 @@ KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame)
     LARGE_INTEGER Null = {{0}};\r
 \r
     /* Check if interrupts were disabled */\r
-    if (!(TrapFrame->EFlags & EFLAGS_INTERRUPT_MASK))\r
+    if (!KeGetTrapFrameInterruptState(TrapFrame))\r
     {\r
         /* Nothing to return */\r
         return Null;\r
@@ -1191,9 +1348,14 @@ KdExitDebugger(IN BOOLEAN Entered)
 \r
 NTSTATUS\r
 NTAPI\r
-KdEnableDebuggerWithLock(BOOLEAN NeedLock)\r
+KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)\r
 {\r
-    KIRQL OldIrql = PASSIVE_LEVEL;\r
+    KIRQL OldIrql;\r
+\r
+#if defined(__GNUC__)\r
+    /* Make gcc happy */\r
+    OldIrql = PASSIVE_LEVEL;\r
+#endif\r
 \r
     /* Check if we need to acquire the lock */\r
     if (NeedLock)\r
index 31c8b68..5b02884 100644 (file)
@@ -18,11 +18,11 @@ ULONG
 NTAPI\r
 KdpAddBreakpoint(IN PVOID Address)\r
 {\r
-    UCHAR Content;\r
+    KD_BREAKPOINT_TYPE Content;\r
     ULONG i;\r
 \r
     /* Loop current breakpoints */\r
-    for (i = 0; i < 20; i++)\r
+    for (i = 0; i < KD_BREAKPOINT_MAX; i++)\r
     {\r
         /* Check if the breakpoint is valid */\r
         if ((KdpBreakpointTable[i].Flags & KdpBreakpointActive) &&\r
@@ -44,21 +44,21 @@ KdpAddBreakpoint(IN PVOID Address)
     }\r
 \r
     /* Find a free entry */\r
-    for (i = 0; i < 20; i++) if (!(KdpBreakpointTable[i].Flags)) break;\r
+    for (i = 0; i < KD_BREAKPOINT_MAX; i++) if (!(KdpBreakpointTable[i].Flags)) break;\r
 \r
     /* Fail if no free entry was found */\r
-    if (i == 20) return 0;\r
+    if (i == KD_BREAKPOINT_MAX) return 0;\r
 \r
     /* Save the old instruction */\r
-    RtlCopyMemory(&Content, Address, sizeof(UCHAR));\r
+    RtlCopyMemory(&Content, Address, KD_BREAKPOINT_SIZE);\r
 \r
     /* Write the entry */\r
     KdpBreakpointTable[i].Address = Address;\r
     KdpBreakpointTable[i].Content = Content;\r
     KdpBreakpointTable[i].Flags = KdpBreakpointActive;\r
 \r
-    /* Write the INT3 and return the handle */\r
-    RtlCopyMemory(Address, &KdpBreakpointInstruction, sizeof(UCHAR));\r
+    /* Write the breakpoint and return the handle */\r
+    RtlCopyMemory(Address, &KdpBreakpointInstruction, KD_BREAKPOINT_SIZE);\r
     return i + 1;\r
 }\r
 \r
@@ -74,7 +74,7 @@ KdpLowWriteContent(IN ULONG BpIndex)
         return TRUE;\r
     }\r
 \r
-    /* Is the original instruction an INT3 anyway? */\r
+    /* Is the original instruction a breakpoint anyway? */\r
     if (KdpBreakpointTable[BpIndex].Content == KdpBreakpointInstruction)\r
     {\r
         /* Then leave it that way... */\r
@@ -84,7 +84,7 @@ KdpLowWriteContent(IN ULONG BpIndex)
     /* We have an active breakpoint with an instruction to bring back. Do it. */\r
     RtlCopyMemory(KdpBreakpointTable[BpIndex].Address,\r
                   &KdpBreakpointTable[BpIndex].Content,\r
-                  sizeof(UCHAR));\r
+                  KD_BREAKPOINT_SIZE);\r
 \r
     /* Everything went fine, return */\r
     return TRUE;\r
@@ -102,7 +102,7 @@ KdpLowRestoreBreakpoint(IN ULONG BpIndex)
         return TRUE;\r
     }\r
 \r
-    /* Are we merely writing an INT3 on top of another INT3? */\r
+    /* Are we merely writing a breakpoint on top of another breakpoint? */\r
     if (KdpBreakpointTable[BpIndex].Content == KdpBreakpointInstruction)\r
     {\r
         /* Nothing to do then... */\r
@@ -112,7 +112,7 @@ KdpLowRestoreBreakpoint(IN ULONG BpIndex)
     /* Ok, we actually have to overwrite the instruction now */\r
     RtlCopyMemory(KdpBreakpointTable[BpIndex].Address,\r
                   &KdpBreakpointInstruction,\r
-                  sizeof(UCHAR));\r
+                  KD_BREAKPOINT_SIZE);\r
 \r
     /* Clear any possible previous pending flag and return success */\r
     KdpBreakpointTable[BpIndex].Flags &= ~KdpBreakpointPending;\r
@@ -126,7 +126,7 @@ KdpDeleteBreakpoint(IN ULONG BpEntry)
     ULONG BpIndex = BpEntry - 1;\r
 \r
     /* Check for invalid breakpoint entry */\r
-    if (!(BpEntry) || (BpEntry > 20)) return FALSE;\r
+    if (!(BpEntry) || (BpEntry > KD_BREAKPOINT_MAX)) return FALSE;\r
 \r
     /* If the specified breakpoint table entry is not valid, then return FALSE. */\r
     if (!KdpBreakpointTable[BpIndex].Flags) return FALSE;\r
@@ -157,7 +157,7 @@ KdpDeleteBreakpointRange(IN PVOID Base,
     BOOLEAN Return = FALSE;\r
 \r
     /* Loop the breakpoint table */\r
-    for (BpIndex = 0; BpIndex < 20; BpIndex++)\r
+    for (BpIndex = 0; BpIndex < KD_BREAKPOINT_MAX; BpIndex++)\r
     {\r
         /* Make sure that the breakpoint is active and matches the range. */\r
         if ((KdpBreakpointTable[BpIndex].Flags & KdpBreakpointActive) &&\r
@@ -183,7 +183,7 @@ KdpRestoreAllBreakpoints(VOID)
     BreakpointsSuspended = FALSE;\r
 \r
     /* Loop the breakpoints */\r
-    for (BpIndex = 0; BpIndex < 20; BpIndex++ )\r
+    for (BpIndex = 0; BpIndex < KD_BREAKPOINT_MAX; BpIndex++ )\r
     {\r
         /* Check if they are valid, suspended breakpoints */\r
         if ((KdpBreakpointTable[BpIndex].Flags & KdpBreakpointActive) &&\r
index ba06152..294c479 100644 (file)
 \r
 VOID NTAPI RtlpBreakWithStatusInstruction(VOID);\r
 \r
+//\r
+// Apply the KIPCR WDK workaround for x86 and AMD64\r
+//\r
+#if defined(_M_IX86) || defined(_M_AMD64)\r
+#define KPCR KIPCR\r
+#endif\r
+\r
+#if defined(_M_IX86)\r
+\r
+#define KPCR_SELF_OFFSET               FIELD_OFFSET(KPCR, Self)\r
+#define KPCR_CURRENT_PRCB_OFFSET       FIELD_OFFSET(KPCR, Prcb)\r
+#define KPCR_CONTAINED_PRCB_OFFSET     FIELD_OFFSET(KPCR, PrcbData)\r
+\r
+#elif defined(_M_AMD64)\r
+\r
+#define KPCR_SELF_OFFSET               FIELD_OFFSET(KPCR, Self)\r
+#define KPCR_CURRENT_PRCB_OFFSET       FIELD_OFFSET(KPCR, CurrentPrcb)\r
+#define KPCR_CONTAINED_PRCB_OFFSET     FIELD_OFFSET(KPCR, Prcb)\r
+\r
+#elif defined(_M_ARM)\r
+\r
+//#define KPCR_SELF_OFFSET\r
+#define KPCR_CURRENT_PRCB_OFFSET       FIELD_OFFSET(KPCR, Prcb)\r
+//#define KPCR_CONTAINED_PRCB_OFFSET\r
+\r
+#else\r
+#error Unsupported Architecture\r
+#endif\r
+\r
 /* GLOBALS *******************************************************************/\r
 \r
 //\r
@@ -48,12 +77,8 @@ LARGE_INTEGER KdPerformanceCounterRate;
 //\r
 // Breakpoint Data\r
 //\r
-BREAKPOINT_ENTRY KdpBreakpointTable[20];\r
-#if defined(_M_IX86) || defined(_M_AMD64)\r
-ULONG KdpBreakpointInstruction = 0xCC; // INT3\r
-#else\r
-#error Define the breakpoint instruction for this architecture\r
-#endif\r
+BREAKPOINT_ENTRY KdpBreakpointTable[KD_BREAKPOINT_MAX];\r
+KD_BREAKPOINT_TYPE KdpBreakpointInstruction = KD_BREAKPOINT_VALUE;\r
 BOOLEAN KdpOweBreakpoint;\r
 BOOLEAN BreakpointsSuspended;\r
 ULONG KdpNumInternalBreakpoints;\r
@@ -329,8 +354,12 @@ DBGKD_GET_VERSION64 KdVersionBlock =
     0,\r
     0,\r
     DBGKD_64BIT_PROTOCOL_VERSION2,\r
-    KD_SECONDARY_VERSION_DEFAULT,\r
+    CURRENT_KD_SECONDARY_VERSION,\r
+#if defined(_M_AMD64)\r
+    DBGKD_VERS_FLAG_DATA | DBGKD_VERS_FLAG_PTR64,\r
+#else\r
     DBGKD_VERS_FLAG_DATA,\r
+#endif\r
     IMAGE_FILE_MACHINE_ARCHITECTURE,\r
     PACKET_TYPE_MAX,\r
     0,\r
@@ -345,46 +374,46 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
 {\r
     {{0}},\r
     0,\r
-    {PtrToUlong(RtlpBreakWithStatusInstruction)},\r
+    {(ULONG_PTR)RtlpBreakWithStatusInstruction},\r
     0,\r
     FIELD_OFFSET(KTHREAD, CallbackStack),\r
     CBSTACK_CALLBACK_STACK,\r
-    CBSTACK_EBP,\r
+    CBSTACK_FRAME_POINTER,\r
     FALSE,\r
-    {PtrToUlong(KiCallUserMode)},\r
+    {(ULONG_PTR)KiCallUserMode},\r
     0,\r
-    {PtrToUlong(&PsLoadedModuleList)},\r
-    {PtrToUlong(&PsActiveProcessHead)},\r
-    {PtrToUlong(&PspCidTable)},\r
-    {PtrToUlong(&ExpSystemResourcesList)},\r
+    {(ULONG_PTR)&PsLoadedModuleList},\r
+    {(ULONG_PTR)&PsActiveProcessHead},\r
+    {(ULONG_PTR)&PspCidTable},\r
+    {(ULONG_PTR)&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
+    {(ULONG_PTR)&KeTimeIncrement},\r
+    {(ULONG_PTR)&KeBugcheckCallbackListHead},\r
+    {(ULONG_PTR)KiBugCheckData},\r
+    {(ULONG_PTR)&IopErrorLogListHead},\r
+    {(ULONG_PTR)&ObpRootDirectoryObject},\r
+    {(ULONG_PTR)&ObpTypeObjectType},\r
     {0},                                                        // MmSystemCacheStart\r
     {0},                                                        // MmSystemCacheEnd\r
     {0},                                                        // MmSystemCacheWs\r
-    {PtrToUlong(&MmPfnDatabase)},\r
-    {PtrToUlong(MmSystemPtesStart)},\r
-    {PtrToUlong(MmSystemPtesEnd)},\r
+    {(ULONG_PTR)&MmPfnDatabase},\r
+    {(ULONG_PTR)MmSystemPtesStart},\r
+    {(ULONG_PTR)MmSystemPtesEnd},\r
     {0},                                                        // MmSubsectionBase\r
     {0},                                                        // MmNumberOfPagingFiles\r
-    {PtrToUlong(&MmLowestPhysicalPage)},\r
-    {PtrToUlong(&MmHighestPhysicalPage)},\r
-    {PtrToUlong(&MmNumberOfPhysicalPages)},\r
-    {PtrToUlong(&MmMaximumNonPagedPoolInBytes)},\r
-    {PtrToUlong(&MmNonPagedSystemStart)},\r
-    {PtrToUlong(&MmNonPagedPoolStart)},\r
-    {PtrToUlong(&MmNonPagedPoolEnd)},\r
-    {PtrToUlong(&MmPagedPoolStart)},\r
-    {PtrToUlong(&MmPagedPoolEnd)},\r
-    {PtrToUlong(&MmPagedPoolInfo)},\r
+    {(ULONG_PTR)&MmLowestPhysicalPage},\r
+    {(ULONG_PTR)&MmHighestPhysicalPage},\r
+    {(ULONG_PTR)&MmNumberOfPhysicalPages},\r
+    {(ULONG_PTR)&MmMaximumNonPagedPoolInBytes},\r
+    {(ULONG_PTR)&MmNonPagedSystemStart},\r
+    {(ULONG_PTR)&MmNonPagedPoolStart},\r
+    {(ULONG_PTR)&MmNonPagedPoolEnd},\r
+    {(ULONG_PTR)&MmPagedPoolStart},\r
+    {(ULONG_PTR)&MmPagedPoolEnd},\r
+    {(ULONG_PTR)&MmPagedPoolInfo},\r
     PAGE_SIZE,\r
-    {PtrToUlong(&MmSizeOfPagedPoolInBytes)},\r
+    {(ULONG_PTR)&MmSizeOfPagedPoolInBytes},\r
     {0},                                                        // MmTotalCommitLimit\r
     {0},                                                        // MmTotalCommittedPages\r
     {0},                                                        // MmSharedCommit\r
@@ -400,18 +429,18 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
     {0},                                                        // MmAvailablePages\r
     {0},                                                        // MmResidentAvailablePages\r
     {0},                                                        // PoolTrackTable\r
-    {PtrToUlong(&NonPagedPoolDescriptor)},\r
-    {PtrToUlong(&MmHighestUserAddress)},\r
-    {PtrToUlong(&MmSystemRangeStart)},\r
-    {PtrToUlong(&MmUserProbeAddress)},\r
-    {PtrToUlong(KdPrintDefaultCircularBuffer)},\r
-    {PtrToUlong(KdPrintDefaultCircularBuffer + 1)},\r
-    {PtrToUlong(&KdPrintWritePointer)},\r
-    {PtrToUlong(&KdPrintRolloverCount)},\r
+    {(ULONG_PTR)&NonPagedPoolDescriptor},\r
+    {(ULONG_PTR)&MmHighestUserAddress},\r
+    {(ULONG_PTR)&MmSystemRangeStart},\r
+    {(ULONG_PTR)&MmUserProbeAddress},\r
+    {(ULONG_PTR)KdPrintDefaultCircularBuffer},\r
+    {(ULONG_PTR)KdPrintDefaultCircularBuffer + 1},\r
+    {(ULONG_PTR)&KdPrintWritePointer},\r
+    {(ULONG_PTR)&KdPrintRolloverCount},\r
     {0},                                                        // MmLoadedUserImageList\r
-    {PtrToUlong(&NtBuildLab)},\r
+    {(ULONG_PTR)&NtBuildLab},\r
     {0},\r
-    {PtrToUlong(KiProcessorBlock)},\r
+    {(ULONG_PTR)KiProcessorBlock},\r
     {0},                                                        // MmUnloadedDrivers\r
     {0},                                                        // MmLastUnloadedDrivers\r
     {0},                                                        // MmTriageActionTaken\r
@@ -421,10 +450,10 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
     {0},                                                        // MmAllocatedNonPagedPool\r
     {0},                                                        // MmPeakCommitment\r
     {0},                                                        // MmtotalCommitLimitMaximum\r
-    {PtrToUlong(&CmNtCSDVersion)},\r
-    {PtrToUlong(&MmPhysicalMemoryBlock)},\r
-    {PtrToUlong(&MmSessionBase)},\r
-    {PtrToUlong(&MmSessionSize)},\r
+    {(ULONG_PTR)&CmNtCSDVersion},\r
+    {(ULONG_PTR)&MmPhysicalMemoryBlock},\r
+    {(ULONG_PTR)&MmSessionBase},\r
+    {(ULONG_PTR)&MmSessionSize},\r
     {0},\r
     {0},\r
     FIELD_OFFSET(KTHREAD, NextProcessor),\r
@@ -448,20 +477,24 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
     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
+    {(ULONG_PTR)KdPrintDefaultCircularBuffer},\r
+    {(ULONG_PTR)&KdPrintBufferSize},\r
+    {(ULONG_PTR)&KeLoaderBlock},\r
+    sizeof(KPCR) + sizeof(KPRCB),\r
+    KPCR_SELF_OFFSET,\r
+    KPCR_CURRENT_PRCB_OFFSET,\r
+    KPCR_CONTAINED_PRCB_OFFSET,\r
     0,\r
     0,\r
     0,\r
     0,\r
     0,\r
-    FIELD_OFFSET(KIPCR, PrcbData) +\r
+    KPCR_CONTAINED_PRCB_OFFSET +\r
     FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),\r
+#if defined(_M_IX86)\r
+    //\r
+    // x86 GDT/LDT/TSS constants\r
+    //\r
     KGDT_R0_CODE,\r
     KGDT_R0_DATA,\r
     KGDT_R0_PCR,\r
@@ -472,6 +505,35 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
     KGDT_TSS,\r
     0,\r
     0,\r
+#elif defined(_M_AMD64)\r
+    //\r
+    // AMD64 GDT/LDT/TSS constants\r
+    //\r
+    KGDT_64_R0_CODE,\r
+    KGDT_64_DATA,\r
+    KGDT_64_DATA,\r
+    KGDT_64_R3_CODE,\r
+    KGDT_64_DATA,\r
+    KGDT_64_DATA,\r
+    0,\r
+    KGDT_TSS,\r
+    0,\r
+    0,\r
+#else\r
+    //\r
+    // No GDT/LDT/TSS on other architectures\r
+    //\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+    0,\r
+#endif\r
     {0},                                                        // IopNumTriageDumpDataBlocks\r
     {0},                                                        // IopTriageDumpDataBlocks\r
 };\r
index efd8e29..feee0d9 100644 (file)
@@ -20,7 +20,7 @@ KdUpdateDataBlock(VOID)
 {\r
     /* Update the KeUserCallbackDispatcher pointer */\r
     KdDebuggerDataBlock.KeUserCallbackDispatcher =\r
-        (ULONG64)(LONG_PTR)KeUserCallbackDispatcher;\r
+        (ULONG_PTR)KeUserCallbackDispatcher;\r
 }\r
 \r
 BOOLEAN\r
@@ -119,8 +119,8 @@ KdInitSystem(IN ULONG BootPhase,
 #endif\r
 \r
         /* Save Pointers to Loaded Module List and Debugger Data */\r
-        KdVersionBlock.PsLoadedModuleList = (ULONGLONG)(LONG_PTR)&PsLoadedModuleList;\r
-        KdVersionBlock.DebuggerDataList = (ULONGLONG)(LONG_PTR)&KdpDebuggerDataListHead;\r
+        KdVersionBlock.PsLoadedModuleList = (ULONG64)(LONG_PTR)&PsLoadedModuleList;\r
+        KdVersionBlock.DebuggerDataList = (ULONG64)(LONG_PTR)&KdpDebuggerDataListHead;\r
 \r
         /* Set protocol limits */\r
         KdVersionBlock.MaxStateChange = DbgKdMaximumStateChange -\r
@@ -143,7 +143,7 @@ KdInitSystem(IN ULONG BootPhase,
 \r
         /* Save the Kernel Base */\r
         PsNtosImageBase = (ULONG_PTR)LdrEntry->DllBase;\r
-        KdVersionBlock.KernBase = (ULONGLONG)(LONG_PTR)LdrEntry->DllBase;\r
+        KdVersionBlock.KernBase = (ULONG64)(LONG_PTR)LdrEntry->DllBase;\r
 \r
         /* Check if we have a command line */\r
         CommandLine = LoaderBlock->LoadOptions;\r
@@ -183,14 +183,14 @@ KdInitSystem(IN ULONG BootPhase,
     else\r
     {\r
         /* Called from a bugcheck...Save the Kernel Base */\r
-        KdVersionBlock.KernBase = (ULONGLONG)(LONG_PTR)PsNtosImageBase;\r
+        KdVersionBlock.KernBase = (ULONG64)(LONG_PTR)PsNtosImageBase;\r
 \r
         /* Unconditionally enable KD */\r
         EnableKd = TRUE;\r
     }\r
 \r
     /* Set the Kernel Base in the Data Block */\r
-    KdDebuggerDataBlock.KernBase = (ULONGLONG)(LONG_PTR)KdVersionBlock.KernBase;\r
+    KdDebuggerDataBlock.KernBase = (ULONG_PTR)KdVersionBlock.KernBase;\r
 \r
     /* Initialize the debugger if requested */\r
     if ((EnableKd) && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))\r
index 154043f..604cea3 100644 (file)
 #define NDEBUG\r
 #include <debug.h>\r
 \r
+//\r
+// Retrieves the ComponentId and Level for BREAKPOINT_PRINT\r
+// and OutputString and OutputStringLength for BREAKPOINT_PROMPT.\r
+//\r
+#if defined(_M_IX86)\r
+\r
+//\r
+// EBX/EDI on x86\r
+//\r
+#define KdpGetFirstParameter(Context)  ((Context)->Ebx)\r
+#define KdpGetSecondParameter(Context) ((Context)->Edi)\r
+\r
+#elif defined(_M_AMD64)\r
+\r
+//\r
+// R8/R9 on AMD64\r
+//\r
+#define KdpGetFirstParameter(Context)  ((Context)->R8)\r
+#define KdpGetSecondParameter(Context) ((Context)->R9)\r
+\r
+#elif defined(_M_ARM)\r
+\r
+#error Yo Ninjas!\r
+\r
+#else\r
+#error Unsupported Architecture\r
+#endif\r
+\r
 /* FUNCTIONS *****************************************************************/\r
 \r
 BOOLEAN\r
@@ -27,7 +55,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
     PKPRCB Prcb;\r
     NTSTATUS ExceptionCode = ExceptionRecord->ExceptionCode;\r
 \r
-    /* Check if this is INT1 or 3, or if we're forced to handle it */\r
+    /* Check if this is single step or a breakpoint, or if we're forced to handle it */\r
     if ((ExceptionCode == STATUS_BREAKPOINT) ||\r
         (ExceptionCode == STATUS_SINGLE_STEP) ||\r
         (ExceptionCode == STATUS_ASSERTION_FAILURE) ||\r
@@ -109,8 +137,8 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
             case BREAKPOINT_PRINT:\r
 \r
                 /* Call the worker routine */\r
-                ReturnValue = KdpPrint((ULONG)ContextRecord->Ebx,\r
-                                       (ULONG)ContextRecord->Edi,\r
+                ReturnValue = KdpPrint((ULONG)KdpGetFirstParameter(ContextRecord),\r
+                                       (ULONG)KdpGetSecondParameter(ContextRecord),\r
                                        (LPSTR)ExceptionRecord->\r
                                        ExceptionInformation[1],\r
                                        (USHORT)ExceptionRecord->\r
@@ -132,8 +160,8 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
                                         ExceptionInformation[1],\r
                                         (USHORT)ExceptionRecord->\r
                                         ExceptionInformation[2],\r
-                                        (LPSTR)ContextRecord->Ebx,\r
-                                        (USHORT)ContextRecord->Edi,\r
+                                        (LPSTR)KdpGetFirstParameter(ContextRecord),\r
+                                        (USHORT)KdpGetSecondParameter(ContextRecord),\r
                                         PreviousMode,\r
                                         TrapFrame,\r
                                         ExceptionFrame);\r
@@ -143,7 +171,7 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
                 KeSetContextReturnRegister(ContextRecord, ReturnValue);\r
                 break;\r
 \r
-            /* DbgUnloadImageSymbols */\r
+            /* DbgUnLoadImageSymbols */\r
             case BREAKPOINT_UNLOAD_SYMBOLS:\r
 \r
                 /* Drop into the load case below, with the unload parameter */\r
index 1d50391..1df8556 100644 (file)
@@ -1063,7 +1063,7 @@ KeBugCheckWithTf(IN ULONG BugCheckCode,
 
     /* Check if we need to save the context for KD */
 #ifdef _WINKD_
-    if (!KdPitchDebugger) KdDebuggerDataBlock.SavedContext = (ULONG)&Context;
+    if (!KdPitchDebugger) KdDebuggerDataBlock.SavedContext = (ULONG_PTR)&Context;
 #endif
 
     /* Check if a debugger is connected */
index 0f30116..10c672c 100644 (file)
        </if>
        <if property="_WINKD_" value ="1">
                <directory name="kd64">
+                       <if property="ARCH" value="i386">
+                               <directory name="i386">
+                                       <file>kdsup.c</file>
+                               </directory>
+                       </if>
+                       <if property="ARCH" value="amd64">
+                               <directory name="amd64">
+                                       <file>kdsup.c</file>
+                               </directory>
+                       </if>
+                       <if property="ARCH" value="arm">
+                               <directory name="arm">
+                                       <file>kdsup.c</file>
+                               </directory>
+                       </if>
                        <file>kdapi.c</file>
                        <file>kdbreak.c</file>
                        <file>kddata.c</file>