ReactOS 0.4.16-dev-752-g47bae01
kdx86.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdx86.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KdpGetStateChange (IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
 
VOID NTAPI KdpSetContextState (IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
 
NTSTATUS NTAPI KdpSysReadMsr (_In_ ULONG Msr, _Out_ PULONGLONG MsrValue)
 
NTSTATUS NTAPI KdpSysWriteMsr (_In_ ULONG Msr, _In_ PULONGLONG MsrValue)
 
NTSTATUS NTAPI KdpSysReadBusData (_In_ BUS_DATA_TYPE BusDataType, _In_ ULONG BusNumber, _In_ ULONG SlotNumber, _In_ ULONG Offset, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_ PULONG ActualLength)
 
NTSTATUS NTAPI KdpSysWriteBusData (_In_ BUS_DATA_TYPE BusDataType, _In_ ULONG BusNumber, _In_ ULONG SlotNumber, _In_ ULONG Offset, _In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_ PULONG ActualLength)
 
NTSTATUS NTAPI KdpSysReadControlSpace (_In_ ULONG Processor, _In_ ULONG64 BaseAddress, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_ PULONG ActualLength)
 
NTSTATUS NTAPI KdpSysWriteControlSpace (_In_ ULONG Processor, _In_ ULONG64 BaseAddress, _In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_ PULONG ActualLength)
 
NTSTATUS NTAPI KdpSysReadIoSpace (_In_ INTERFACE_TYPE InterfaceType, _In_ ULONG BusNumber, _In_ ULONG AddressSpace, _In_ ULONG64 IoAddress, _Out_writes_bytes_(DataSize) PVOID DataValue, _In_ ULONG DataSize, _Out_ PULONG ActualDataSize)
 
NTSTATUS NTAPI KdpSysWriteIoSpace (_In_ INTERFACE_TYPE InterfaceType, _In_ ULONG BusNumber, _In_ ULONG AddressSpace, _In_ ULONG64 IoAddress, _In_reads_bytes_(DataSize) PVOID DataValue, _In_ ULONG DataSize, _Out_ PULONG ActualDataSize)
 
NTSTATUS NTAPI KdpSysCheckLowMemory (IN ULONG Flags)
 
NTSTATUS NTAPI KdpAllowDisable (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file kdx86.c.

Function Documentation

◆ KdpAllowDisable()

NTSTATUS NTAPI KdpAllowDisable ( VOID  )

Definition at line 429 of file kdx86.c.

430{
431 ULONG i;
432
433 /* Loop every processor */
434 for (i = 0; i < KeNumberProcessors; i++)
435 {
437
438 /* If any processor breakpoints are active,
439 * we can't allow running without a debugger */
440 if (ProcessorState->SpecialRegisters.KernelDr7 & 0xFF)
442 }
443
444 /* No processor breakpoints, allow disabling the debugger */
445 return STATUS_SUCCESS;
446}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:31
CCHAR KeNumberProcessors
Definition: processor.c:16
#define STATUS_SUCCESS
Definition: shellext.h:65
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:672
KSPECIAL_REGISTERS SpecialRegisters
Definition: ketypes.h:624
ULONG64 KernelDr7
Definition: ketypes.h:599
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145

Referenced by KdDisableDebuggerWithLock().

◆ KdpGetStateChange()

VOID NTAPI KdpGetStateChange ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PCONTEXT  Context 
)

Definition at line 20 of file kdx86.c.

22{
23 PKPRCB Prcb;
24 ULONG i;
25
26 /* Check for success */
27 if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
28 {
29 /* Check if we're tracing */
30 if (State->u.Continue2.ControlSet.TraceFlag)
31 {
32 /* Enable TF */
33 Context->EFlags |= EFLAGS_TF;
34 }
35 else
36 {
37 /* Remove it */
38 Context->EFlags &= ~EFLAGS_TF;
39 }
40
41 /* Loop all processors */
42 for (i = 0; i < KeNumberProcessors; i++)
43 {
44 /* Get the PRCB and update DR7 and DR6 */
45 Prcb = KiProcessorBlock[i];
47 State->u.Continue2.ControlSet.Dr7;
49 }
50
51 /* Check if we have new symbol information */
52 if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
53 {
54 /* Update it */
56 State->u.Continue2.ControlSet.CurrentSymbolStart;
57 KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
58 }
59 }
60}
#define EFLAGS_TF
Definition: SystemCall.c:10
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
ULONG_PTR KdpCurrentSymbolEnd
Definition: kd64.h:559
ULONG_PTR KdpCurrentSymbolStart
Definition: kddata.c:104
ULONG64 KernelDr6
Definition: ketypes.h:598

Referenced by KdpSendWaitContinue().

◆ KdpSetContextState()

VOID NTAPI KdpSetContextState ( IN PDBGKD_ANY_WAIT_STATE_CHANGE  WaitStateChange,
IN PCONTEXT  Context 
)

Definition at line 64 of file kdx86.c.

66{
67 PKPRCB Prcb = KeGetCurrentPrcb();
68
69 /* Copy i386 specific debug registers */
70 WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
71 KernelDr6;
72 WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
73 KernelDr7;
74
75 /* Copy i386 specific segments */
76 WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;
77 WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;
78 WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;
79 WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;
80
81 /* Copy EFlags */
82 WaitStateChange->ControlReport.EFlags = Context->EFlags;
83
84 /* Set Report Flags */
85 WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
86 if (WaitStateChange->ControlReport.SegCs == KGDT_R0_CODE)
87 {
88 WaitStateChange->ControlReport.ReportFlags |= REPORT_STANDARD_CS;
89 }
90}
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1182
#define KGDT_R0_CODE
Definition: ketypes.h:123
unsigned short USHORT
Definition: pedump.c:61
#define REPORT_INCLUDES_SEGS
Definition: windbgkd.h:147
#define REPORT_STANDARD_CS
Definition: windbgkd.h:148

Referenced by KdpReportCommandStringStateChange(), KdpReportExceptionStateChange(), and KdpReportLoadSymbolsStateChange().

◆ KdpSysCheckLowMemory()

NTSTATUS NTAPI KdpSysCheckLowMemory ( IN ULONG  Flags)

Definition at line 421 of file kdx86.c.

422{
423 /* Stubbed as we don't support PAE */
424 return STATUS_UNSUCCESSFUL;
425}
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by KdpCheckLowMemory(), and KdSystemDebugControl().

◆ KdpSysReadBusData()

NTSTATUS NTAPI KdpSysReadBusData ( _In_ BUS_DATA_TYPE  BusDataType,
_In_ ULONG  BusNumber,
_In_ ULONG  SlotNumber,
_In_ ULONG  Offset,
_Out_writes_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length,
_Out_ PULONG  ActualLength 
)

Definition at line 134 of file kdx86.c.

142{
143 /* Just forward to HAL */
144 *ActualLength = HalGetBusDataByOffset(BusDataType,
145 BusNumber,
147 Buffer,
148 Offset,
149 Length);
150
151 /* Return status */
152 return (*ActualLength != 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
153}
Definition: bufpool.h:45
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160

Referenced by KdpGetBusData(), and KdSystemDebugControl().

◆ KdpSysReadControlSpace()

NTSTATUS NTAPI KdpSysReadControlSpace ( _In_ ULONG  Processor,
_In_ ULONG64  BaseAddress,
_Out_writes_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length,
_Out_ PULONG  ActualLength 
)

Definition at line 180 of file kdx86.c.

186{
187 PVOID ControlStart;
188 ULONG RealLength;
189
190 /* Make sure that this is a valid request */
191 if ((BaseAddress < sizeof(KPROCESSOR_STATE)) &&
193 {
194 /* Get the actual length */
195 RealLength = sizeof(KPROCESSOR_STATE) - (ULONG_PTR)BaseAddress;
196 if (RealLength < Length) Length = RealLength;
197
198 /* Set the proper address */
199 ControlStart = (PVOID)((ULONG_PTR)BaseAddress +
201 ProcessorState);
202
203 /* Read the control state safely */
205 ControlStart,
206 Length,
207 0,
209 ActualLength);
210 }
211 else
212 {
213 /* Invalid request */
214 *ActualLength = 0;
215 return STATUS_UNSUCCESSFUL;
216 }
217}
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI KdpCopyMemoryChunks(_In_ ULONG64 Address, _In_ PVOID Buffer, _In_ ULONG TotalSize, _In_ ULONG ChunkSize, _In_ ULONG Flags, _Out_opt_ PULONG ActualSize)
Definition: kdapi.c:55
struct _KPROCESSOR_STATE KPROCESSOR_STATE
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77
#define MMDBG_COPY_WRITE
Definition: mm.h:75
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ UCHAR Processor
Definition: kefuncs.h:670

Referenced by KdpReadControlSpace(), and KdSystemDebugControl().

◆ KdpSysReadIoSpace()

NTSTATUS NTAPI KdpSysReadIoSpace ( _In_ INTERFACE_TYPE  InterfaceType,
_In_ ULONG  BusNumber,
_In_ ULONG  AddressSpace,
_In_ ULONG64  IoAddress,
_Out_writes_bytes_(DataSize) PVOID  DataValue,
_In_ ULONG  DataSize,
_Out_ PULONG  ActualDataSize 
)

Definition at line 257 of file kdx86.c.

265{
267
268 /* Verify parameters */
269 if ((InterfaceType != Isa) || (BusNumber != 0) || (AddressSpace != 1))
270 {
271 /* Fail, we don't support this */
272 *ActualDataSize = 0;
273 return STATUS_UNSUCCESSFUL;
274 }
275
276 /* Check the size */
277 switch (DataSize)
278 {
279 case sizeof(UCHAR):
280 {
281 /* Read 1 byte */
282 *(PUCHAR)DataValue =
283 READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)IoAddress);
284 *ActualDataSize = sizeof(UCHAR);
286 break;
287 }
288
289 case sizeof(USHORT):
290 {
291 /* Make sure the address is aligned */
292 if ((IoAddress & (sizeof(USHORT) - 1)) != 0)
293 {
294 /* It isn't, bail out */
295 *ActualDataSize = 0;
297 break;
298 }
299
300 /* Read 2 bytes */
301 *(PUSHORT)DataValue =
303 *ActualDataSize = sizeof(USHORT);
305 break;
306 }
307
308 case sizeof(ULONG):
309 {
310 /* Make sure the address is aligned */
311 if ((IoAddress & (sizeof(ULONG) - 1)) != 0)
312 {
313 /* It isn't, bail out */
314 *ActualDataSize = 0;
316 break;
317 }
318
319 /* Read 4 bytes */
320 *(PULONG)DataValue =
321 READ_PORT_ULONG((PULONG)(ULONG_PTR)IoAddress);
322 *ActualDataSize = sizeof(ULONG);
324 break;
325 }
326
327 default:
328 /* Invalid size, fail */
329 *ActualDataSize = 0;
331 }
332
333 /* Return status */
334 return Status;
335}
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:25
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63
@ Isa
Definition: hwresource.cpp:138
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
uint32_t * PULONG
Definition: typedefs.h:59
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by KdpReadIoSpace(), KdpReadIoSpaceExtended(), and KdSystemDebugControl().

◆ KdpSysReadMsr()

NTSTATUS NTAPI KdpSysReadMsr ( _In_ ULONG  Msr,
_Out_ PULONGLONG  MsrValue 
)

Definition at line 94 of file kdx86.c.

97{
98 /* Use SEH to protect from invalid MSRs */
100 {
101 *MsrValue = __readmsr(Msr);
102 }
104 {
106 }
107 _SEH2_END;
108
109 return STATUS_SUCCESS;
110}
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_END
Definition: pseh2_64.h:155
#define _SEH2_TRY
Definition: pseh2_64.h:55
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by KdpReadMachineSpecificRegister(), and KdSystemDebugControl().

◆ KdpSysWriteBusData()

NTSTATUS NTAPI KdpSysWriteBusData ( _In_ BUS_DATA_TYPE  BusDataType,
_In_ ULONG  BusNumber,
_In_ ULONG  SlotNumber,
_In_ ULONG  Offset,
_In_reads_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length,
_Out_ PULONG  ActualLength 
)

Definition at line 157 of file kdx86.c.

165{
166 /* Just forward to HAL */
167 *ActualLength = HalSetBusDataByOffset(BusDataType,
168 BusNumber,
170 Buffer,
171 Offset,
172 Length);
173
174 /* Return status */
175 return (*ActualLength != 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
176}
ULONG NTAPI HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:123

Referenced by KdpSetBusData(), and KdSystemDebugControl().

◆ KdpSysWriteControlSpace()

NTSTATUS NTAPI KdpSysWriteControlSpace ( _In_ ULONG  Processor,
_In_ ULONG64  BaseAddress,
_In_reads_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length,
_Out_ PULONG  ActualLength 
)

Definition at line 221 of file kdx86.c.

227{
228 PVOID ControlStart;
229
230 /* Make sure that this is a valid request */
231 if (((BaseAddress + Length) <= sizeof(KPROCESSOR_STATE)) &&
233 {
234 /* Set the proper address */
235 ControlStart = (PVOID)((ULONG_PTR)BaseAddress +
237 ProcessorState);
238
239 /* Write the control state safely */
241 ControlStart,
242 Length,
243 0,
245 ActualLength);
246 }
247 else
248 {
249 /* Invalid request */
250 *ActualLength = 0;
251 return STATUS_UNSUCCESSFUL;
252 }
253}

Referenced by KdpWriteControlSpace(), and KdSystemDebugControl().

◆ KdpSysWriteIoSpace()

NTSTATUS NTAPI KdpSysWriteIoSpace ( _In_ INTERFACE_TYPE  InterfaceType,
_In_ ULONG  BusNumber,
_In_ ULONG  AddressSpace,
_In_ ULONG64  IoAddress,
_In_reads_bytes_(DataSize) PVOID  DataValue,
_In_ ULONG  DataSize,
_Out_ PULONG  ActualDataSize 
)

Definition at line 339 of file kdx86.c.

347{
349
350 /* Verify parameters */
351 if ((InterfaceType != Isa) || (BusNumber != 0) || (AddressSpace != 1))
352 {
353 /* Fail, we don't support this */
354 *ActualDataSize = 0;
355 return STATUS_UNSUCCESSFUL;
356 }
357
358 /* Check the size */
359 switch (DataSize)
360 {
361 case sizeof(UCHAR):
362 {
363 /* Write 1 byte */
365 *(PUCHAR)DataValue);
366 *ActualDataSize = sizeof(UCHAR);
368 break;
369 }
370
371 case sizeof(USHORT):
372 {
373 /* Make sure the address is aligned */
374 if ((IoAddress & (sizeof(USHORT) - 1)) != 0)
375 {
376 /* It isn't, bail out */
377 *ActualDataSize = 0;
379 break;
380 }
381
382 /* Write 2 bytes */
384 *(PUSHORT)DataValue);
385 *ActualDataSize = sizeof(USHORT);
387 break;
388 }
389
390 case sizeof(ULONG):
391 {
392 /* Make sure the address is aligned */
393 if ((IoAddress & (sizeof(ULONG) - 1)) != 0)
394 {
395 /* It isn't, bail out */
396 *ActualDataSize = 0;
398 break;
399 }
400
401 /* Write 4 bytes */
403 *(PULONG)DataValue);
404 *ActualDataSize = sizeof(ULONG);
406 break;
407 }
408
409 default:
410 /* Invalid size, fail */
411 *ActualDataSize = 0;
413 }
414
415 /* Return status */
416 return Status;
417}
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21

Referenced by KdpWriteIoSpace(), KdpWriteIoSpaceExtended(), and KdSystemDebugControl().

◆ KdpSysWriteMsr()

NTSTATUS NTAPI KdpSysWriteMsr ( _In_ ULONG  Msr,
_In_ PULONGLONG  MsrValue 
)

Definition at line 114 of file kdx86.c.

117{
118 /* Use SEH to protect from invalid MSRs */
120 {
121 __writemsr(Msr, *MsrValue);
122 }
124 {
126 }
127 _SEH2_END;
128
129 return STATUS_SUCCESS;
130}
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748

Referenced by KdpWriteMachineSpecificRegister(), and KdSystemDebugControl().