KD64 Compatibility Bringup:

- 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
This commit is contained in:
Stefan Ginsberg 2009-10-10 19:27:54 +00:00
parent 3f7bed2eae
commit ca6fbc0be9
16 changed files with 1322 additions and 267 deletions

View 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

View file

@ -142,7 +142,7 @@
// 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

View 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
@ -32,6 +34,12 @@
#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

View 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(

View file

@ -6,6 +6,11 @@
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
*/
//
// Maximum supported number of breakpoints
//
#define KD_BREAKPOINT_MAX 32
//
// Breakpoint Status Flags
//
@ -25,7 +30,7 @@ typedef struct _BREAKPOINT_ENTRY
ULONG Flags;
PKPROCESS Process;
PVOID Address;
UCHAR Content;
KD_BREAKPOINT_TYPE Content;
} BREAKPOINT_ENTRY, *PBREAKPOINT_ENTRY;
//
@ -262,6 +267,139 @@ KdpAddBreakpoint(
IN PVOID Address
);
//
// Architecture dependent support routines
//
//
// Version
//
VOID
NTAPI
KdpSysGetVersion(
IN PDBGKD_GET_VERSION64 Version
);
//
// Context
//
VOID
NTAPI
KdpGetStateChange(
IN PDBGKD_MANIPULATE_STATE64 State,
IN PCONTEXT Context
);
VOID
NTAPI
KdpSetContextState(
IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
IN PCONTEXT Context
);
//
// MSR
//
NTSTATUS
NTAPI
KdpSysReadMsr(
IN ULONG Msr,
OUT PLARGE_INTEGER MsrValue
);
NTSTATUS
NTAPI
KdpSysWriteMsr(
IN ULONG Msr,
IN PLARGE_INTEGER MsrValue
);
//
// Bus
//
NTSTATUS
NTAPI
KdpSysReadBusData(
IN ULONG BusDataType,
IN ULONG BusNumber,
IN ULONG SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length,
OUT PULONG ActualLength
);
NTSTATUS
NTAPI
KdpSysWriteBusData(
IN ULONG BusDataType,
IN ULONG BusNumber,
IN ULONG SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length,
OUT PULONG ActualLength
);
//
// Control Space
//
NTSTATUS
NTAPI
KdpSysReadControlSpace(
IN ULONG Processor,
IN ULONG64 BaseAddress,
IN PVOID Buffer,
IN ULONG Length,
OUT PULONG ActualLength
);
NTSTATUS
NTAPI
KdpSysWriteControlSpace(
IN ULONG Processor,
IN ULONG64 BaseAddress,
IN PVOID Buffer,
IN ULONG Length,
OUT PULONG ActualLength
);
//
// I/O Space
//
NTSTATUS
NTAPI
KdpSysReadIoSpace(
IN ULONG InterfaceType,
IN ULONG BusNumber,
IN ULONG AddressSpace,
IN ULONG64 IoAddress,
IN PULONG DataValue,
IN ULONG DataSize,
OUT PULONG ActualDataSize
);
NTSTATUS
NTAPI
KdpSysWriteIoSpace(
IN ULONG InterfaceType,
IN ULONG BusNumber,
IN ULONG AddressSpace,
IN ULONG64 IoAddress,
IN PULONG DataValue,
IN ULONG DataSize,
OUT PULONG ActualDataSize
);
//
// Low Memory
//
NTSTATUS
NTAPI
KdpSysCheckLowMemory(
IN ULONG Flags
);
//
// Internal routine for sending strings directly to the debugger
//
@ -307,8 +445,8 @@ extern ULONG KdComponentTableSize;
extern ULONG Kd_WIN2000_Mask;
extern PULONG KdComponentTable[104];
extern CHAR KdpMessageBuffer[4096], KdpPathBuffer[4096];
extern BREAKPOINT_ENTRY KdpBreakpointTable[20];
extern ULONG KdpBreakpointInstruction;
extern BREAKPOINT_ENTRY KdpBreakpointTable[KD_BREAKPOINT_MAX];
extern KD_BREAKPOINT_TYPE KdpBreakpointInstruction;
extern BOOLEAN KdpOweBreakpoint;
extern BOOLEAN BreakpointsSuspended;
extern ULONG KdpNumInternalBreakpoints;

View 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")

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -27,7 +27,7 @@ KdpQueryMemory(IN PDBGKD_MANIPULATE_STATE64 State,
if (Memory->AddressSpace == DBGKD_QUERY_MEMORY_VIRTUAL)
{
/* Check if this is process memory */
if ((PVOID)(LONG_PTR)Memory->Address < MmHighestUserAddress)
if ((PVOID)(ULONG_PTR)Memory->Address < MmHighestUserAddress)
{
/* It is */
Memory->AddressSpace = DBGKD_QUERY_MEMORY_PROCESS;
@ -80,7 +80,7 @@ KdpWriteBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State,
/* Create the breakpoint */
Breakpoint->BreakPointHandle =
KdpAddBreakpoint((PVOID)(LONG_PTR)Breakpoint->BreakPointAddress);
KdpAddBreakpoint((PVOID)(ULONG_PTR)Breakpoint->BreakPointAddress);
if (!Breakpoint->BreakPointHandle)
{
/* We failed */
@ -114,50 +114,6 @@ DumpTraceData(IN PSTRING TraceData)
TraceDataBufferPosition = 1;
}
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
KdpSetCommonState(IN ULONG NewState,
@ -188,7 +144,7 @@ KdpSetCommonState(IN ULONG NewState,
/* Clear all the breakpoints in this region */
HadBreakpoints =
KdpDeleteBreakpointRange((PVOID)(LONG_PTR)WaitStateChange->ProgramCounter,
KdpDeleteBreakpointRange((PVOID)(ULONG_PTR)WaitStateChange->ProgramCounter,
(PVOID)((ULONG_PTR)WaitStateChange->ProgramCounter +
WaitStateChange->ControlReport.InstructionCount - 1));
if (HadBreakpoints)
@ -200,44 +156,6 @@ KdpSetCommonState(IN ULONG NewState,
}
}
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_INCLUDES_CS;
}
}
VOID
NTAPI
KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
{
/* Copy the version block */
RtlCopyMemory(Version, &KdVersionBlock, sizeof(DBGKD_GET_VERSION64));
}
VOID
NTAPI
KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
@ -324,8 +242,7 @@ KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
{
PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
STRING Header;
ULONG Length, RealLength;
PVOID ControlStart;
ULONG Length;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
@ -340,35 +257,15 @@ KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
}
/* Make sure that this is a valid request */
if (((ULONG)ReadMemory->TargetBaseAddress < sizeof(KPROCESSOR_STATE)) &&
(State->Processor < KeNumberProcessors))
{
/* Get the actual length */
RealLength = sizeof(KPROCESSOR_STATE) -
(ULONG_PTR)ReadMemory->TargetBaseAddress;
if (RealLength < Length) Length = RealLength;
/* Call the internal routine */
State->ReturnStatus = KdpSysReadControlSpace(State->Processor,
ReadMemory->TargetBaseAddress,
Data->Buffer,
Length,
&Length);
/* Set the proper address */
ControlStart = (PVOID)((ULONG_PTR)ReadMemory->TargetBaseAddress +
(ULONG_PTR)&KiProcessorBlock[State->Processor]->
ProcessorState);
/* Copy the memory */
RtlCopyMemory(Data->Buffer, ControlStart, Length);
Data->Length = Length;
/* Finish up */
State->ReturnStatus = STATUS_SUCCESS;
ReadMemory->ActualBytesRead = Data->Length;
}
else
{
/* Invalid request */
Data->Length = 0;
State->ReturnStatus = STATUS_UNSUCCESSFUL;
ReadMemory->ActualBytesRead = 0;
}
/* Return the actual length read */
Data->Length = ReadMemory->ActualBytesRead = Length;
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
@ -386,38 +283,20 @@ KdpWriteControlSpace(IN PDBGKD_MANIPULATE_STATE64 State,
PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
STRING Header;
ULONG Length;
PVOID ControlStart;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
/* Make sure that this is a valid request */
Length = WriteMemory->TransferCount;
if ((((ULONG)WriteMemory->TargetBaseAddress + Length) <=
sizeof(KPROCESSOR_STATE)) &&
(State->Processor < KeNumberProcessors))
{
/* Set the proper address */
ControlStart = (PVOID)((ULONG_PTR)WriteMemory->TargetBaseAddress +
(ULONG_PTR)&KiProcessorBlock[State->Processor]->
ProcessorState);
/* Call the internal routine */
State->ReturnStatus = KdpSysWriteControlSpace(State->Processor,
WriteMemory->TargetBaseAddress,
Data->Buffer,
Data->Length,
&Length);
/* Copy the memory */
RtlCopyMemory(ControlStart, Data->Buffer, Data->Length);
Length = Data->Length;
/* Finish up */
State->ReturnStatus = STATUS_SUCCESS;
WriteMemory->ActualBytesWritten = Length;
}
else
{
/* Invalid request */
Data->Length = 0;
State->ReturnStatus = STATUS_UNSUCCESSFUL;
WriteMemory->ActualBytesWritten = 0;
}
/* Return the length written */
WriteMemory->ActualBytesWritten = Length;
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
@ -568,6 +447,293 @@ KdpCauseBugCheck(IN PDBGKD_MANIPULATE_STATE64 State)
KeBugCheck(MANUALLY_INITIATED_CRASH);
}
VOID
NTAPI
KdpReadMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_READ_WRITE_MSR ReadMsr = &State->u.ReadWriteMsr;
LARGE_INTEGER MsrValue;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/* Call the internal routine */
State->ReturnStatus = KdpSysReadMsr(ReadMsr->Msr,
&MsrValue);
/* Return the data */
ReadMsr->DataValueLow = MsrValue.LowPart;
ReadMsr->DataValueHigh = MsrValue.HighPart;
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
VOID
NTAPI
KdpWriteMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_READ_WRITE_MSR WriteMsr = &State->u.ReadWriteMsr;
LARGE_INTEGER MsrValue;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/* Call the internal routine */
MsrValue.LowPart = WriteMsr->DataValueLow;
MsrValue.HighPart = WriteMsr->DataValueHigh;
State->ReturnStatus = KdpSysWriteMsr(WriteMsr->Msr,
&MsrValue);
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
VOID
NTAPI
KdpGetBusData(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_GET_SET_BUS_DATA GetBusData = &State->u.GetSetBusData;
ULONG Length;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/* Check the length requested */
Length = GetBusData->Length;
if (Length > (PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64)))
{
/* Use maximum allowed */
Length = PACKET_MAX_SIZE - sizeof(DBGKD_MANIPULATE_STATE64);
}
/* Call the internal routine */
State->ReturnStatus = KdpSysReadBusData(GetBusData->BusDataType,
GetBusData->BusNumber,
GetBusData->SlotNumber,
Data->Buffer,
GetBusData->Offset,
Length,
&Length);
/* Return the actual length read */
Data->Length = GetBusData->Length = Length;
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
Data,
&KdpContext);
}
VOID
NTAPI
KdpSetBusData(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_GET_SET_BUS_DATA SetBusData = &State->u.GetSetBusData;
ULONG Length;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
/* Call the internal routine */
State->ReturnStatus = KdpSysWriteBusData(SetBusData->BusDataType,
SetBusData->BusNumber,
SetBusData->SlotNumber,
Data->Buffer,
SetBusData->Offset,
SetBusData->Length,
&Length);
/* Return the actual length written */
SetBusData->Length = Length;
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
Data,
&KdpContext);
}
VOID
NTAPI
KdpReadIoSpace(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_READ_WRITE_IO64 ReadIo = &State->u.ReadWriteIo;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/*
* Clear the value so 1 or 2 byte reads
* don't leave the higher bits unmodified
*/
ReadIo->DataValue = 0;
/* Call the internal routine */
State->ReturnStatus = KdpSysReadIoSpace(Isa,
0,
1,
ReadIo->IoAddress,
&ReadIo->DataValue,
ReadIo->DataSize,
&ReadIo->DataSize);
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
VOID
NTAPI
KdpWriteIoSpace(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_READ_WRITE_IO64 WriteIo = &State->u.ReadWriteIo;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/* Call the internal routine */
State->ReturnStatus = KdpSysWriteIoSpace(Isa,
0,
1,
WriteIo->IoAddress,
&WriteIo->DataValue,
WriteIo->DataSize,
&WriteIo->DataSize);
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
VOID
NTAPI
KdpReadIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_READ_WRITE_IO_EXTENDED64 ReadIoExtended = &State->u.
ReadWriteIoExtended;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/*
* Clear the value so 1 or 2 byte reads
* don't leave the higher bits unmodified
*/
ReadIoExtended->DataValue = 0;
/* Call the internal routine */
State->ReturnStatus = KdpSysReadIoSpace(ReadIoExtended->InterfaceType,
ReadIoExtended->BusNumber,
ReadIoExtended->AddressSpace,
ReadIoExtended->IoAddress,
&ReadIoExtended->DataValue,
ReadIoExtended->DataSize,
&ReadIoExtended->DataSize);
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
VOID
NTAPI
KdpWriteIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State,
IN PSTRING Data,
IN PCONTEXT Context)
{
STRING Header;
PDBGKD_READ_WRITE_IO_EXTENDED64 WriteIoExtended = &State->u.
ReadWriteIoExtended;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
ASSERT(Data->Length == 0);
/* Call the internal routine */
State->ReturnStatus = KdpSysReadIoSpace(WriteIoExtended->InterfaceType,
WriteIoExtended->BusNumber,
WriteIoExtended->AddressSpace,
WriteIoExtended->IoAddress,
&WriteIoExtended->DataValue,
WriteIoExtended->DataSize,
&WriteIoExtended->DataSize);
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
VOID
NTAPI
KdpCheckLowMemory(IN PDBGKD_MANIPULATE_STATE64 State)
{
STRING Header;
/* Setup the header */
Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
Header.Buffer = (PCHAR)State;
/* Call the internal routine */
State->ReturnStatus = KdpSysCheckLowMemory(0x4);
/* Send the reply */
KdSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE,
&Header,
NULL,
&KdpContext);
}
KCONTINUE_STATUS
NTAPI
KdpSendWaitContinue(IN ULONG PacketType,
@ -670,16 +836,14 @@ SendPacket:
case DbgKdReadIoSpaceApi:
/* FIXME: TODO */
KdpDprintf("DbgKdReadIoSpaceApi called\n");
while (TRUE);
/* Read I/O Space */
KdpReadIoSpace(&ManipulateState, &Data, Context);
break;
case DbgKdWriteIoSpaceApi:
/* FIXME: TODO */
KdpDprintf("DbgKdWriteIoSpaceApi called\n");
while (TRUE);
/* Write I/O Space */
KdpWriteIoSpace(&ManipulateState, &Data, Context);
break;
case DbgKdRebootApi:
@ -757,16 +921,14 @@ SendPacket:
case DbgKdReadIoSpaceExtendedApi:
/* FIXME: TODO */
KdpDprintf("DbgKdReadIoSpaceExtendedApi called\n");
while (TRUE);
/* Read I/O Space */
KdpReadIoSpaceExtended(&ManipulateState, &Data, Context);
break;
case DbgKdWriteIoSpaceExtendedApi:
/* FIXME: TODO */
KdpDprintf("DbgKdWriteIoSpaceExtendedApi called\n");
while (TRUE);
/* Write I/O Space */
KdpWriteIoSpaceExtended(&ManipulateState, &Data, Context);
break;
case DbgKdGetVersionApi:
@ -811,16 +973,14 @@ SendPacket:
case DbgKdReadMachineSpecificRegister:
/* FIXME: TODO */
KdpDprintf("DbgKdReadMachineSpecificRegister called\n");
while (TRUE);
/* Read from the specified MSR */
KdpReadMachineSpecificRegister(&ManipulateState, &Data, Context);
break;
case DbgKdWriteMachineSpecificRegister:
/* FIXME: TODO */
KdpDprintf("DbgKdWriteMachineSpecificRegister called\n");
while (TRUE);
/* Write to the specified MSR */
KdpWriteMachineSpecificRegister(&ManipulateState, &Data, Context);
break;
case OldVlm1:
@ -846,23 +1006,20 @@ SendPacket:
case DbgKdGetBusDataApi:
/* FIXME: TODO */
KdpDprintf("DbgKdGetBusDataApi called\n");
while (TRUE);
/* Read from the bus */
KdpGetBusData(&ManipulateState, &Data, Context);
break;
case DbgKdSetBusDataApi:
/* FIXME: TODO */
KdpDprintf("DbgKdSetBusDataApi called\n");
while (TRUE);
/* Write to the bus */
KdpSetBusData(&ManipulateState, &Data, Context);
break;
case DbgKdCheckLowMemoryApi:
/* FIXME: TODO */
KdpDprintf("DbgKdCheckLowMemoryApi called\n");
while (TRUE);
/* Check for memory corruption in the lower 4 GB */
KdpCheckLowMemory(&ManipulateState);
break;
case DbgKdClearAllInternalBreakpointsApi:
@ -936,7 +1093,7 @@ KdpReportLoadSymbolsStateChange(IN PSTRING PathName,
/* Fill out load data */
WaitStateChange.u.LoadSymbols.UnloadSymbols = Unload;
WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONGLONG)(LONG_PTR)SymbolInfo->BaseOfDll;
WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONG64)(LONG_PTR)SymbolInfo->BaseOfDll;
WaitStateChange.u.LoadSymbols.ProcessId = SymbolInfo->ProcessId;
WaitStateChange.u.LoadSymbols.CheckSum = SymbolInfo->CheckSum;
WaitStateChange.u.LoadSymbols.SizeOfImage = SymbolInfo->SizeOfImage;
@ -981,7 +1138,7 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
{
STRING Header, Data;
DBGKD_WAIT_STATE_CHANGE64 WaitStateChange;
BOOLEAN Status;
KCONTINUE_STATUS Status;
/* Start report loop */
do
@ -989,9 +1146,9 @@ KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord,
/* Build the architecture common parts of the message */
KdpSetCommonState(DbgKdExceptionStateChange, Context, &WaitStateChange);
/* Convert the exception record to 64-bits and set First Chance flag */
ExceptionRecord32To64((PEXCEPTION_RECORD32)ExceptionRecord,
&WaitStateChange.u.Exception.ExceptionRecord);
/* Copy the Exception Record and set First Chance flag */
CopyExceptionRecord(ExceptionRecord,
&WaitStateChange.u.Exception.ExceptionRecord);
WaitStateChange.u.Exception.FirstChance = !SecondChanceException;
/* Now finish creating the structure */
@ -1091,7 +1248,7 @@ KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame)
LARGE_INTEGER Null = {{0}};
/* Check if interrupts were disabled */
if (!(TrapFrame->EFlags & EFLAGS_INTERRUPT_MASK))
if (!KeGetTrapFrameInterruptState(TrapFrame))
{
/* Nothing to return */
return Null;
@ -1191,9 +1348,14 @@ KdExitDebugger(IN BOOLEAN Entered)
NTSTATUS
NTAPI
KdEnableDebuggerWithLock(BOOLEAN NeedLock)
KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
{
KIRQL OldIrql = PASSIVE_LEVEL;
KIRQL OldIrql;
#if defined(__GNUC__)
/* Make gcc happy */
OldIrql = PASSIVE_LEVEL;
#endif
/* Check if we need to acquire the lock */
if (NeedLock)

View file

@ -18,11 +18,11 @@ ULONG
NTAPI
KdpAddBreakpoint(IN PVOID Address)
{
UCHAR Content;
KD_BREAKPOINT_TYPE Content;
ULONG i;
/* Loop current breakpoints */
for (i = 0; i < 20; i++)
for (i = 0; i < KD_BREAKPOINT_MAX; i++)
{
/* Check if the breakpoint is valid */
if ((KdpBreakpointTable[i].Flags & KdpBreakpointActive) &&
@ -44,21 +44,21 @@ KdpAddBreakpoint(IN PVOID Address)
}
/* Find a free entry */
for (i = 0; i < 20; i++) if (!(KdpBreakpointTable[i].Flags)) break;
for (i = 0; i < KD_BREAKPOINT_MAX; i++) if (!(KdpBreakpointTable[i].Flags)) break;
/* Fail if no free entry was found */
if (i == 20) return 0;
if (i == KD_BREAKPOINT_MAX) return 0;
/* Save the old instruction */
RtlCopyMemory(&Content, Address, sizeof(UCHAR));
RtlCopyMemory(&Content, Address, KD_BREAKPOINT_SIZE);
/* Write the entry */
KdpBreakpointTable[i].Address = Address;
KdpBreakpointTable[i].Content = Content;
KdpBreakpointTable[i].Flags = KdpBreakpointActive;
/* Write the INT3 and return the handle */
RtlCopyMemory(Address, &KdpBreakpointInstruction, sizeof(UCHAR));
/* Write the breakpoint and return the handle */
RtlCopyMemory(Address, &KdpBreakpointInstruction, KD_BREAKPOINT_SIZE);
return i + 1;
}
@ -74,7 +74,7 @@ KdpLowWriteContent(IN ULONG BpIndex)
return TRUE;
}
/* Is the original instruction an INT3 anyway? */
/* Is the original instruction a breakpoint anyway? */
if (KdpBreakpointTable[BpIndex].Content == KdpBreakpointInstruction)
{
/* Then leave it that way... */
@ -84,7 +84,7 @@ KdpLowWriteContent(IN ULONG BpIndex)
/* We have an active breakpoint with an instruction to bring back. Do it. */
RtlCopyMemory(KdpBreakpointTable[BpIndex].Address,
&KdpBreakpointTable[BpIndex].Content,
sizeof(UCHAR));
KD_BREAKPOINT_SIZE);
/* Everything went fine, return */
return TRUE;
@ -102,7 +102,7 @@ KdpLowRestoreBreakpoint(IN ULONG BpIndex)
return TRUE;
}
/* Are we merely writing an INT3 on top of another INT3? */
/* Are we merely writing a breakpoint on top of another breakpoint? */
if (KdpBreakpointTable[BpIndex].Content == KdpBreakpointInstruction)
{
/* Nothing to do then... */
@ -112,7 +112,7 @@ KdpLowRestoreBreakpoint(IN ULONG BpIndex)
/* Ok, we actually have to overwrite the instruction now */
RtlCopyMemory(KdpBreakpointTable[BpIndex].Address,
&KdpBreakpointInstruction,
sizeof(UCHAR));
KD_BREAKPOINT_SIZE);
/* Clear any possible previous pending flag and return success */
KdpBreakpointTable[BpIndex].Flags &= ~KdpBreakpointPending;
@ -126,7 +126,7 @@ KdpDeleteBreakpoint(IN ULONG BpEntry)
ULONG BpIndex = BpEntry - 1;
/* Check for invalid breakpoint entry */
if (!(BpEntry) || (BpEntry > 20)) return FALSE;
if (!(BpEntry) || (BpEntry > KD_BREAKPOINT_MAX)) return FALSE;
/* If the specified breakpoint table entry is not valid, then return FALSE. */
if (!KdpBreakpointTable[BpIndex].Flags) return FALSE;
@ -157,7 +157,7 @@ KdpDeleteBreakpointRange(IN PVOID Base,
BOOLEAN Return = FALSE;
/* Loop the breakpoint table */
for (BpIndex = 0; BpIndex < 20; BpIndex++)
for (BpIndex = 0; BpIndex < KD_BREAKPOINT_MAX; BpIndex++)
{
/* Make sure that the breakpoint is active and matches the range. */
if ((KdpBreakpointTable[BpIndex].Flags & KdpBreakpointActive) &&
@ -183,7 +183,7 @@ KdpRestoreAllBreakpoints(VOID)
BreakpointsSuspended = FALSE;
/* Loop the breakpoints */
for (BpIndex = 0; BpIndex < 20; BpIndex++ )
for (BpIndex = 0; BpIndex < KD_BREAKPOINT_MAX; BpIndex++ )
{
/* Check if they are valid, suspended breakpoints */
if ((KdpBreakpointTable[BpIndex].Flags & KdpBreakpointActive) &&

View file

@ -15,6 +15,35 @@
VOID NTAPI RtlpBreakWithStatusInstruction(VOID);
//
// Apply the KIPCR WDK workaround for x86 and AMD64
//
#if defined(_M_IX86) || defined(_M_AMD64)
#define KPCR KIPCR
#endif
#if defined(_M_IX86)
#define KPCR_SELF_OFFSET FIELD_OFFSET(KPCR, Self)
#define KPCR_CURRENT_PRCB_OFFSET FIELD_OFFSET(KPCR, Prcb)
#define KPCR_CONTAINED_PRCB_OFFSET FIELD_OFFSET(KPCR, PrcbData)
#elif defined(_M_AMD64)
#define KPCR_SELF_OFFSET FIELD_OFFSET(KPCR, Self)
#define KPCR_CURRENT_PRCB_OFFSET FIELD_OFFSET(KPCR, CurrentPrcb)
#define KPCR_CONTAINED_PRCB_OFFSET FIELD_OFFSET(KPCR, Prcb)
#elif defined(_M_ARM)
//#define KPCR_SELF_OFFSET
#define KPCR_CURRENT_PRCB_OFFSET FIELD_OFFSET(KPCR, Prcb)
//#define KPCR_CONTAINED_PRCB_OFFSET
#else
#error Unsupported Architecture
#endif
/* GLOBALS *******************************************************************/
//
@ -48,12 +77,8 @@ LARGE_INTEGER KdPerformanceCounterRate;
//
// Breakpoint Data
//
BREAKPOINT_ENTRY KdpBreakpointTable[20];
#if defined(_M_IX86) || defined(_M_AMD64)
ULONG KdpBreakpointInstruction = 0xCC; // INT3
#else
#error Define the breakpoint instruction for this architecture
#endif
BREAKPOINT_ENTRY KdpBreakpointTable[KD_BREAKPOINT_MAX];
KD_BREAKPOINT_TYPE KdpBreakpointInstruction = KD_BREAKPOINT_VALUE;
BOOLEAN KdpOweBreakpoint;
BOOLEAN BreakpointsSuspended;
ULONG KdpNumInternalBreakpoints;
@ -329,8 +354,12 @@ DBGKD_GET_VERSION64 KdVersionBlock =
0,
0,
DBGKD_64BIT_PROTOCOL_VERSION2,
KD_SECONDARY_VERSION_DEFAULT,
CURRENT_KD_SECONDARY_VERSION,
#if defined(_M_AMD64)
DBGKD_VERS_FLAG_DATA | DBGKD_VERS_FLAG_PTR64,
#else
DBGKD_VERS_FLAG_DATA,
#endif
IMAGE_FILE_MACHINE_ARCHITECTURE,
PACKET_TYPE_MAX,
0,
@ -345,46 +374,46 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
{
{{0}},
0,
{PtrToUlong(RtlpBreakWithStatusInstruction)},
{(ULONG_PTR)RtlpBreakWithStatusInstruction},
0,
FIELD_OFFSET(KTHREAD, CallbackStack),
CBSTACK_CALLBACK_STACK,
CBSTACK_EBP,
CBSTACK_FRAME_POINTER,
FALSE,
{PtrToUlong(KiCallUserMode)},
{(ULONG_PTR)KiCallUserMode},
0,
{PtrToUlong(&PsLoadedModuleList)},
{PtrToUlong(&PsActiveProcessHead)},
{PtrToUlong(&PspCidTable)},
{PtrToUlong(&ExpSystemResourcesList)},
{(ULONG_PTR)&PsLoadedModuleList},
{(ULONG_PTR)&PsActiveProcessHead},
{(ULONG_PTR)&PspCidTable},
{(ULONG_PTR)&ExpSystemResourcesList},
{0}, // ExpPagedPoolDescriptor
{0}, // ExpNumberOfPagedPools
{PtrToUlong(&KeTimeIncrement)},
{PtrToUlong(&KeBugcheckCallbackListHead)},
{PtrToUlong(KiBugCheckData)},
{PtrToUlong(&IopErrorLogListHead)},
{PtrToUlong(&ObpRootDirectoryObject)},
{PtrToUlong(&ObpTypeObjectType)},
{(ULONG_PTR)&KeTimeIncrement},
{(ULONG_PTR)&KeBugcheckCallbackListHead},
{(ULONG_PTR)KiBugCheckData},
{(ULONG_PTR)&IopErrorLogListHead},
{(ULONG_PTR)&ObpRootDirectoryObject},
{(ULONG_PTR)&ObpTypeObjectType},
{0}, // MmSystemCacheStart
{0}, // MmSystemCacheEnd
{0}, // MmSystemCacheWs
{PtrToUlong(&MmPfnDatabase)},
{PtrToUlong(MmSystemPtesStart)},
{PtrToUlong(MmSystemPtesEnd)},
{(ULONG_PTR)&MmPfnDatabase},
{(ULONG_PTR)MmSystemPtesStart},
{(ULONG_PTR)MmSystemPtesEnd},
{0}, // MmSubsectionBase
{0}, // MmNumberOfPagingFiles
{PtrToUlong(&MmLowestPhysicalPage)},
{PtrToUlong(&MmHighestPhysicalPage)},
{PtrToUlong(&MmNumberOfPhysicalPages)},
{PtrToUlong(&MmMaximumNonPagedPoolInBytes)},
{PtrToUlong(&MmNonPagedSystemStart)},
{PtrToUlong(&MmNonPagedPoolStart)},
{PtrToUlong(&MmNonPagedPoolEnd)},
{PtrToUlong(&MmPagedPoolStart)},
{PtrToUlong(&MmPagedPoolEnd)},
{PtrToUlong(&MmPagedPoolInfo)},
{(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,
{PtrToUlong(&MmSizeOfPagedPoolInBytes)},
{(ULONG_PTR)&MmSizeOfPagedPoolInBytes},
{0}, // MmTotalCommitLimit
{0}, // MmTotalCommittedPages
{0}, // MmSharedCommit
@ -400,18 +429,18 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
{0}, // MmAvailablePages
{0}, // MmResidentAvailablePages
{0}, // PoolTrackTable
{PtrToUlong(&NonPagedPoolDescriptor)},
{PtrToUlong(&MmHighestUserAddress)},
{PtrToUlong(&MmSystemRangeStart)},
{PtrToUlong(&MmUserProbeAddress)},
{PtrToUlong(KdPrintDefaultCircularBuffer)},
{PtrToUlong(KdPrintDefaultCircularBuffer + 1)},
{PtrToUlong(&KdPrintWritePointer)},
{PtrToUlong(&KdPrintRolloverCount)},
{(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},
{0}, // MmLoadedUserImageList
{PtrToUlong(&NtBuildLab)},
{(ULONG_PTR)&NtBuildLab},
{0},
{PtrToUlong(KiProcessorBlock)},
{(ULONG_PTR)KiProcessorBlock},
{0}, // MmUnloadedDrivers
{0}, // MmLastUnloadedDrivers
{0}, // MmTriageActionTaken
@ -421,10 +450,10 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
{0}, // MmAllocatedNonPagedPool
{0}, // MmPeakCommitment
{0}, // MmtotalCommitLimitMaximum
{PtrToUlong(&CmNtCSDVersion)},
{PtrToUlong(&MmPhysicalMemoryBlock)},
{PtrToUlong(&MmSessionBase)},
{PtrToUlong(&MmSessionSize)},
{(ULONG_PTR)&CmNtCSDVersion},
{(ULONG_PTR)&MmPhysicalMemoryBlock},
{(ULONG_PTR)&MmSessionBase},
{(ULONG_PTR)&MmSessionSize},
{0},
{0},
FIELD_OFFSET(KTHREAD, NextProcessor),
@ -448,20 +477,24 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
FIELD_OFFSET(KPRCB, ProcessorState.ContextFrame),
FIELD_OFFSET(KPRCB, Number),
sizeof(ETHREAD),
{PtrToUlong(KdPrintDefaultCircularBuffer)},
{PtrToUlong(&KdPrintBufferSize)},
{PtrToUlong(&KeLoaderBlock)},
sizeof(KIPCR) + sizeof(KPRCB),
FIELD_OFFSET(KIPCR, Self),
FIELD_OFFSET(KPCR, Prcb),
FIELD_OFFSET(KIPCR, PrcbData),
{(ULONG_PTR)KdPrintDefaultCircularBuffer},
{(ULONG_PTR)&KdPrintBufferSize},
{(ULONG_PTR)&KeLoaderBlock},
sizeof(KPCR) + sizeof(KPRCB),
KPCR_SELF_OFFSET,
KPCR_CURRENT_PRCB_OFFSET,
KPCR_CONTAINED_PRCB_OFFSET,
0,
0,
0,
0,
0,
FIELD_OFFSET(KIPCR, PrcbData) +
KPCR_CONTAINED_PRCB_OFFSET +
FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),
#if defined(_M_IX86)
//
// x86 GDT/LDT/TSS constants
//
KGDT_R0_CODE,
KGDT_R0_DATA,
KGDT_R0_PCR,
@ -472,6 +505,35 @@ KDDEBUGGER_DATA64 KdDebuggerDataBlock =
KGDT_TSS,
0,
0,
#elif defined(_M_AMD64)
//
// AMD64 GDT/LDT/TSS constants
//
KGDT_64_R0_CODE,
KGDT_64_DATA,
KGDT_64_DATA,
KGDT_64_R3_CODE,
KGDT_64_DATA,
KGDT_64_DATA,
0,
KGDT_TSS,
0,
0,
#else
//
// No GDT/LDT/TSS on other architectures
//
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
#endif
{0}, // IopNumTriageDumpDataBlocks
{0}, // IopTriageDumpDataBlocks
};

View file

@ -20,7 +20,7 @@ KdUpdateDataBlock(VOID)
{
/* Update the KeUserCallbackDispatcher pointer */
KdDebuggerDataBlock.KeUserCallbackDispatcher =
(ULONG64)(LONG_PTR)KeUserCallbackDispatcher;
(ULONG_PTR)KeUserCallbackDispatcher;
}
BOOLEAN
@ -119,8 +119,8 @@ KdInitSystem(IN ULONG BootPhase,
#endif
/* Save Pointers to Loaded Module List and Debugger Data */
KdVersionBlock.PsLoadedModuleList = (ULONGLONG)(LONG_PTR)&PsLoadedModuleList;
KdVersionBlock.DebuggerDataList = (ULONGLONG)(LONG_PTR)&KdpDebuggerDataListHead;
KdVersionBlock.PsLoadedModuleList = (ULONG64)(LONG_PTR)&PsLoadedModuleList;
KdVersionBlock.DebuggerDataList = (ULONG64)(LONG_PTR)&KdpDebuggerDataListHead;
/* Set protocol limits */
KdVersionBlock.MaxStateChange = DbgKdMaximumStateChange -
@ -143,7 +143,7 @@ KdInitSystem(IN ULONG BootPhase,
/* Save the Kernel Base */
PsNtosImageBase = (ULONG_PTR)LdrEntry->DllBase;
KdVersionBlock.KernBase = (ULONGLONG)(LONG_PTR)LdrEntry->DllBase;
KdVersionBlock.KernBase = (ULONG64)(LONG_PTR)LdrEntry->DllBase;
/* Check if we have a command line */
CommandLine = LoaderBlock->LoadOptions;
@ -183,14 +183,14 @@ KdInitSystem(IN ULONG BootPhase,
else
{
/* Called from a bugcheck...Save the Kernel Base */
KdVersionBlock.KernBase = (ULONGLONG)(LONG_PTR)PsNtosImageBase;
KdVersionBlock.KernBase = (ULONG64)(LONG_PTR)PsNtosImageBase;
/* Unconditionally enable KD */
EnableKd = TRUE;
}
/* Set the Kernel Base in the Data Block */
KdDebuggerDataBlock.KernBase = (ULONGLONG)(LONG_PTR)KdVersionBlock.KernBase;
KdDebuggerDataBlock.KernBase = (ULONG_PTR)KdVersionBlock.KernBase;
/* Initialize the debugger if requested */
if ((EnableKd) && (NT_SUCCESS(KdDebuggerInitialize0(LoaderBlock))))

View file

@ -12,6 +12,34 @@
#define NDEBUG
#include <debug.h>
//
// Retrieves the ComponentId and Level for BREAKPOINT_PRINT
// and OutputString and OutputStringLength for BREAKPOINT_PROMPT.
//
#if defined(_M_IX86)
//
// EBX/EDI on x86
//
#define KdpGetFirstParameter(Context) ((Context)->Ebx)
#define KdpGetSecondParameter(Context) ((Context)->Edi)
#elif defined(_M_AMD64)
//
// R8/R9 on AMD64
//
#define KdpGetFirstParameter(Context) ((Context)->R8)
#define KdpGetSecondParameter(Context) ((Context)->R9)
#elif defined(_M_ARM)
#error Yo Ninjas!
#else
#error Unsupported Architecture
#endif
/* FUNCTIONS *****************************************************************/
BOOLEAN
@ -27,7 +55,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
PKPRCB Prcb;
NTSTATUS ExceptionCode = ExceptionRecord->ExceptionCode;
/* Check if this is INT1 or 3, or if we're forced to handle it */
/* Check if this is single step or a breakpoint, or if we're forced to handle it */
if ((ExceptionCode == STATUS_BREAKPOINT) ||
(ExceptionCode == STATUS_SINGLE_STEP) ||
(ExceptionCode == STATUS_ASSERTION_FAILURE) ||
@ -109,8 +137,8 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
case BREAKPOINT_PRINT:
/* Call the worker routine */
ReturnValue = KdpPrint((ULONG)ContextRecord->Ebx,
(ULONG)ContextRecord->Edi,
ReturnValue = KdpPrint((ULONG)KdpGetFirstParameter(ContextRecord),
(ULONG)KdpGetSecondParameter(ContextRecord),
(LPSTR)ExceptionRecord->
ExceptionInformation[1],
(USHORT)ExceptionRecord->
@ -132,8 +160,8 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
ExceptionInformation[1],
(USHORT)ExceptionRecord->
ExceptionInformation[2],
(LPSTR)ContextRecord->Ebx,
(USHORT)ContextRecord->Edi,
(LPSTR)KdpGetFirstParameter(ContextRecord),
(USHORT)KdpGetSecondParameter(ContextRecord),
PreviousMode,
TrapFrame,
ExceptionFrame);
@ -143,7 +171,7 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
KeSetContextReturnRegister(ContextRecord, ReturnValue);
break;
/* DbgUnloadImageSymbols */
/* DbgUnLoadImageSymbols */
case BREAKPOINT_UNLOAD_SYMBOLS:
/* Drop into the load case below, with the unload parameter */

View 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 */

View file

@ -321,6 +321,21 @@
</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>