ReactOS 0.4.15-dev-7958-gcd0bb1a
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
20VOID
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
64VOID
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
97 OUT PLARGE_INTEGER MsrValue)
98{
99 /* Use SEH to protect from invalid MSRs */
101 {
102 MsrValue->QuadPart = __readmsr(Msr);
103 }
105 {
107 }
108 _SEH2_END;
109
110 return STATUS_SUCCESS;
111}
112
114NTAPI
116 IN PLARGE_INTEGER MsrValue)
117{
118 /* Use SEH to protect from invalid MSRs */
120 {
121 __writemsr(Msr, MsrValue->QuadPart);
122 }
124 {
126 }
127 _SEH2_END;
128
129 return STATUS_SUCCESS;
130}
131
133NTAPI
140 OUT PULONG ActualLength)
141{
143 return STATUS_UNSUCCESSFUL;
144}
145
147NTAPI
154 OUT PULONG ActualLength)
155{
157 return STATUS_UNSUCCESSFUL;
158}
159
161NTAPI
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
212NTAPI
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
243NTAPI
247 IN ULONG64 IoAddress,
248 OUT PVOID DataValue,
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
299NTAPI
303 IN ULONG64 IoAddress,
304 IN PVOID DataValue,
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
355NTAPI
357{
359 return STATUS_UNSUCCESSFUL;
360}
361
363NTAPI
365{
368}
369
370/* EOF */
#define EFLAGS_TF
Definition: SystemCall.c:10
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
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
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63
@ Isa
Definition: hwresource.cpp:138
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
PPC_QUAL void __writemsr(const unsigned long Value)
Definition: intrin_ppc.h:748
PPC_QUAL unsigned long long __readmsr()
Definition: intrin_ppc.h:741
ULONG_PTR KdpCurrentSymbolEnd
Definition: kd64.h:568
ULONG_PTR KdpCurrentSymbolStart
Definition: kddata.c:104
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
NTSTATUS NTAPI KdpSysReadControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:162
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
VOID NTAPI KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
Definition: kdx64.c:66
NTSTATUS NTAPI KdpSysCheckLowMemory(IN ULONG Flags)
Definition: kdx64.c:356
VOID NTAPI KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdx64.c:22
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
NTSTATUS NTAPI KdpSysWriteMsr(IN ULONG Msr, IN PLARGE_INTEGER MsrValue)
Definition: kdx64.c:115
NTSTATUS NTAPI KdpSysWriteControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:213
NTSTATUS NTAPI KdpSysReadMsr(IN ULONG Msr, OUT PLARGE_INTEGER MsrValue)
Definition: kdx64.c:96
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
NTSTATUS NTAPI KdpAllowDisable(VOID)
Definition: kdx64.c:364
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
#define ASSERT(a)
Definition: mode.c:44
unsigned __int64 ULONG64
Definition: imports.h:198
#define min(a, b)
Definition: monoChain.cc:55
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
#define KGDT64_R0_CODE
Definition: ketypes.h:133
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
struct _KSPECIAL_REGISTERS KSPECIAL_REGISTERS
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
unsigned short USHORT
Definition: pedump.c:61
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _KTHREAD * CurrentThread
Definition: ketypes.h:650
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:663
KSPECIAL_REGISTERS SpecialRegisters
Definition: ketypes.h:615
ULONG64 KernelDr7
Definition: ketypes.h:590
ULONG64 KernelDr6
Definition: ketypes.h:589
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68
#define AMD64_DEBUG_CONTROL_SPACE_KPRCB
Definition: windbgkd.h:204
#define AMD64_DEBUG_CONTROL_SPACE_KSPECIAL
Definition: windbgkd.h:205
#define REPORT_INCLUDES_SEGS
Definition: windbgkd.h:147
#define AMD64_DEBUG_CONTROL_SPACE_KPCR
Definition: windbgkd.h:203
#define REPORT_STANDARD_CS
Definition: windbgkd.h:148
#define AMD64_DEBUG_CONTROL_SPACE_KTHREAD
Definition: windbgkd.h:206
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
_In_ UCHAR Processor
Definition: kefuncs.h:670
unsigned char UCHAR
Definition: xmlstorage.h:181