ReactOS  0.4.14-dev-323-g6fe6a88
kdx64.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/kd64/amd64/kdx64.c
5  * PURPOSE: KD support routines for AMD64
6  * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 #undef UNIMPLEMENTED
16 #define UNIMPLEMENTED KdpDprintf("%s is unimplemented\n", __FUNCTION__)
17 
18 /* FUNCTIONS *****************************************************************/
19 
20 VOID
21 NTAPI
24 {
25  PKPRCB Prcb;
26  ULONG i;
27 
28  /* Check for success */
29  if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
30  {
31  /* Check if we're tracing */
32  if (State->u.Continue2.ControlSet.TraceFlag)
33  {
34  /* Enable TF */
35  Context->EFlags |= EFLAGS_TF;
36  }
37  else
38  {
39  /* Remove it */
40  Context->EFlags &= ~EFLAGS_TF;
41  }
42 
43  /* Loop all processors */
44  for (i = 0; i < KeNumberProcessors; i++)
45  {
46  /* Get the PRCB and update DR7 and DR6 */
47  Prcb = KiProcessorBlock[i];
49  State->u.Continue2.ControlSet.Dr7;
51  }
52 
53  /* Check if we have new symbol information */
54  if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
55  {
56  /* Update it */
58  State->u.Continue2.ControlSet.CurrentSymbolStart;
59  KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
60  }
61  }
62 }
63 
64 VOID
65 NTAPI
68 {
69  PKPRCB Prcb = KeGetCurrentPrcb();
70 
71  /* Copy i386 specific debug registers */
72  WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
73  KernelDr6;
74  WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
75  KernelDr7;
76 
77  /* Copy i386 specific segments */
78  WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;
79  WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;
80  WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;
81  WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;
82 
83  /* Copy EFlags */
84  WaitStateChange->ControlReport.EFlags = Context->EFlags;
85 
86  /* Set Report Flags */
87  WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
88  if (WaitStateChange->ControlReport.SegCs == KGDT64_R0_CODE)
89  {
90  WaitStateChange->ControlReport.ReportFlags |= REPORT_STANDARD_CS;
91  }
92 }
93 
95 NTAPI
97  OUT PLARGE_INTEGER MsrValue)
98 {
99  /* Use SEH to protect from invalid MSRs */
100  _SEH2_TRY
101  {
102  MsrValue->QuadPart = __readmsr(Msr);
103  }
105  {
107  }
108  _SEH2_END;
109 
110  return STATUS_SUCCESS;
111 }
112 
113 NTSTATUS
114 NTAPI
116  IN PLARGE_INTEGER MsrValue)
117 {
118  /* Use SEH to protect from invalid MSRs */
119  _SEH2_TRY
120  {
121  __writemsr(Msr, MsrValue->QuadPart);
122  }
124  {
126  }
127  _SEH2_END;
128 
129  return STATUS_SUCCESS;
130 }
131 
132 NTSTATUS
133 NTAPI
137  IN ULONG Offset,
138  IN PVOID Buffer,
139  IN ULONG Length,
140  OUT PULONG ActualLength)
141 {
143  return STATUS_UNSUCCESSFUL;
144 }
145 
146 NTSTATUS
147 NTAPI
151  IN ULONG Offset,
152  IN PVOID Buffer,
153  IN ULONG Length,
154  OUT PULONG ActualLength)
155 {
157  return STATUS_UNSUCCESSFUL;
158 }
159 
160 NTSTATUS
161 NTAPI
164  IN PVOID Buffer,
165  IN ULONG Length,
166  OUT PULONG ActualLength)
167 {
168  PVOID ControlStart;
170  PKIPCR Pcr = CONTAINING_RECORD(Prcb, KIPCR, Prcb);
171 
172  switch (BaseAddress)
173  {
175  /* Copy a pointer to the Pcr */
176  ControlStart = &Pcr;
177  *ActualLength = sizeof(PVOID);
178  break;
179 
181  /* Copy a pointer to the Prcb */
182  ControlStart = &Prcb;
183  *ActualLength = sizeof(PVOID);
184  break;
185 
187  /* Copy SpecialRegisters */
188  ControlStart = &Prcb->ProcessorState.SpecialRegisters;
189  *ActualLength = sizeof(KSPECIAL_REGISTERS);
190  break;
191 
193  /* Copy a pointer to the current Thread */
194  ControlStart = &Prcb->CurrentThread;
195  *ActualLength = sizeof(PVOID);
196  break;
197 
198  default:
199  *ActualLength = 0;
200  ASSERT(FALSE);
201  return STATUS_UNSUCCESSFUL;
202  }
203 
204  /* Copy the memory */
205  RtlCopyMemory(Buffer, ControlStart, min(Length, *ActualLength));
206 
207  /* Finish up */
208  return STATUS_SUCCESS;
209 }
210 
211 NTSTATUS
212 NTAPI
215  IN PVOID Buffer,
216  IN ULONG Length,
217  OUT PULONG ActualLength)
218 {
219  PVOID ControlStart;
221 
222  switch (BaseAddress)
223  {
225  /* Copy SpecialRegisters */
226  ControlStart = &Prcb->ProcessorState.SpecialRegisters;
227  *ActualLength = sizeof(KSPECIAL_REGISTERS);
228  break;
229 
230  default:
231  *ActualLength = 0;
232  ASSERT(FALSE);
233  return STATUS_UNSUCCESSFUL;
234  }
235 
236  /* Copy the memory */
237  RtlCopyMemory(ControlStart, Buffer, min(Length, *ActualLength));
238 
239  return STATUS_SUCCESS;
240 }
241 
242 NTSTATUS
243 NTAPI
244 KdpSysReadIoSpace(IN ULONG InterfaceType,
247  IN ULONG64 IoAddress,
248  OUT PVOID DataValue,
249  IN ULONG DataSize,
250  OUT PULONG ActualDataSize)
251 {
252  /* Verify parameters */
253  if (InterfaceType != Isa || BusNumber != 0 || AddressSpace != 1)
254  {
255  /* No data was read */
256  *ActualDataSize = 0;
258  }
259 
260  /* Check for correct alignment */
261  if ((IoAddress & (DataSize - 1)))
262  {
263  /* Invalid alignment */
264  *ActualDataSize = 0;
266  }
267 
268  switch (DataSize)
269  {
270  case sizeof(UCHAR):
271  /* Read one UCHAR */
272  *(PUCHAR)DataValue = READ_PORT_UCHAR((PUCHAR)IoAddress);
273  break;
274 
275  case sizeof(USHORT):
276  /* Read one USHORT */
277  *(PUSHORT)DataValue = READ_PORT_USHORT((PUSHORT)IoAddress);
278  break;
279 
280  case sizeof(ULONG):
281  /* Read one ULONG */
282  *(PULONG)DataValue = READ_PORT_ULONG((PULONG)IoAddress);
283  break;
284 
285  default:
286  /* Invalid data size */
287  *ActualDataSize = 0;
289  }
290 
291  /* Return the size of the data */
292  *ActualDataSize = DataSize;
293 
294  /* Success! */
295  return STATUS_SUCCESS;
296 }
297 
298 NTSTATUS
299 NTAPI
303  IN ULONG64 IoAddress,
304  IN PVOID DataValue,
305  IN ULONG DataSize,
306  OUT PULONG ActualDataSize)
307 {
308  /* Verify parameters */
309  if (InterfaceType != Isa || BusNumber != 0 || AddressSpace != 1)
310  {
311  /* No data was written */
312  *ActualDataSize = 0;
314  }
315 
316  /* Check for correct alignment */
317  if ((IoAddress & (DataSize - 1)))
318  {
319  /* Invalid alignment */
320  *ActualDataSize = 0;
322  }
323 
324  switch (DataSize)
325  {
326  case sizeof(UCHAR):
327  /* Write one UCHAR */
328  WRITE_PORT_UCHAR((PUCHAR)IoAddress, *(PUCHAR)DataValue);
329  break;
330 
331  case sizeof(USHORT):
332  /* Write one USHORT */
333  WRITE_PORT_USHORT((PUSHORT)IoAddress, *(PUSHORT)DataValue);
334  break;
335 
336  case sizeof(ULONG):
337  /* Write one ULONG */
338  WRITE_PORT_ULONG((PULONG)IoAddress, *(PULONG)DataValue);
339  break;
340 
341  default:
342  /* Invalid data size */
343  *ActualDataSize = 0;
345  }
346 
347  /* Return the size of the data */
348  *ActualDataSize = DataSize;
349 
350  /* Success! */
351  return STATUS_SUCCESS;
352 }
353 
354 NTSTATUS
355 NTAPI
357 {
359  return STATUS_UNSUCCESSFUL;
360 }
361 
362 NTSTATUS
363 NTAPI
365 {
367  return STATUS_ACCESS_DENIED;
368 }
369 
370 /* EOF */
#define IN
Definition: typedefs.h:38
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define AMD64_DEBUG_CONTROL_SPACE_KPCR
Definition: windbgkd.h:203
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
NTSTATUS NTAPI KdpAllowDisable(VOID)
Definition: kdx64.c:364
NTSTATUS NTAPI KdpSysReadBusData(IN ULONG BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:134
ULONG64 KernelDr7
Definition: ketypes.h:505
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
unsigned char * PUCHAR
Definition: retypes.h:3
NTSTATUS NTAPI KdpSysReadMsr(IN ULONG Msr, OUT PLARGE_INTEGER MsrValue)
Definition: kdx64.c:96
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
LONG NTSTATUS
Definition: precomp.h:26
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
NTSTATUS NTAPI KdpSysReadIoSpace(IN ULONG InterfaceType, IN ULONG BusNumber, IN ULONG AddressSpace, IN ULONG64 IoAddress, OUT PVOID DataValue, IN ULONG DataSize, OUT PULONG ActualDataSize)
Definition: kdx64.c:244
NTSTATUS NTAPI KdpSysCheckLowMemory(IN ULONG Flags)
Definition: kdx64.c:356
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
_In_ UCHAR Processor
Definition: kefuncs.h:695
KSPECIAL_REGISTERS SpecialRegisters
Definition: ketypes.h:530
#define REPORT_STANDARD_CS
Definition: windbgkd.h:148
NTSTATUS NTAPI KdpSysReadControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:162
_SEH2_TRY
Definition: create.c:4250
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
#define AMD64_DEBUG_CONTROL_SPACE_KTHREAD
Definition: windbgkd.h:206
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID NTAPI KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
Definition: kdx64.c:66
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
struct _KTHREAD * CurrentThread
Definition: ketypes.h:566
ULONG_PTR KdpCurrentSymbolEnd
Definition: kddata.c:105
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI KdpSysWriteControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:213
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define KGDT64_R0_CODE
Definition: ketypes.h:72
NTSTATUS NTAPI KdpSysWriteMsr(IN ULONG Msr, IN PLARGE_INTEGER MsrValue)
Definition: kdx64.c:115
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:579
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
unsigned __int64 ULONG64
Definition: imports.h:198
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG_PTR KdpCurrentSymbolStart
Definition: kddata.c:105
#define REPORT_INCLUDES_SEGS
Definition: windbgkd.h:147
#define EFLAGS_TF
Definition: ketypes.h:125
struct _KSPECIAL_REGISTERS KSPECIAL_REGISTERS
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
_SEH2_END
Definition: create.c:4424
NTSTATUS NTAPI KdpSysWriteBusData(IN ULONG BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:148
unsigned short USHORT
Definition: pedump.c:61
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
NTSTATUS NTAPI KdpSysWriteIoSpace(IN ULONG InterfaceType, IN ULONG BusNumber, IN ULONG AddressSpace, IN ULONG64 IoAddress, IN PVOID DataValue, IN ULONG DataSize, OUT PULONG ActualDataSize)
Definition: kdx64.c:300
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
#define AMD64_DEBUG_CONTROL_SPACE_KSPECIAL
Definition: windbgkd.h:205
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define OUT
Definition: typedefs.h:39
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171
unsigned int ULONG
Definition: retypes.h:1
ULONG64 KernelDr6
Definition: ketypes.h:504
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63
VOID NTAPI KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdx64.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
unsigned short * PUSHORT
Definition: retypes.h:2
#define AMD64_DEBUG_CONTROL_SPACE_KPRCB
Definition: windbgkd.h:204