ReactOS 0.4.16-dev-1025-gd3456f5
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 _In_ ULONG Msr,
98 _Out_ PULONGLONG MsrValue)
99{
100 /* Use SEH to protect from invalid MSRs */
102 {
103 *MsrValue = __readmsr(Msr);
104 }
106 {
108 }
109 _SEH2_END;
110
111 return STATUS_SUCCESS;
112}
113
115NTAPI
117 _In_ ULONG Msr,
118 _In_ PULONGLONG MsrValue)
119{
120 /* Use SEH to protect from invalid MSRs */
122 {
123 __writemsr(Msr, *MsrValue);
124 }
126 {
128 }
129 _SEH2_END;
130
131 return STATUS_SUCCESS;
132}
133
135NTAPI
137 _In_ BUS_DATA_TYPE BusDataType,
143 _Out_ PULONG ActualLength)
144{
146 return STATUS_UNSUCCESSFUL;
147}
148
150NTAPI
152 _In_ BUS_DATA_TYPE BusDataType,
158 _Out_ PULONG ActualLength)
159{
161 return STATUS_UNSUCCESSFUL;
162}
163
165NTAPI
171 _Out_ PULONG ActualLength)
172{
173 PVOID ControlStart;
175 PKIPCR Pcr = CONTAINING_RECORD(Prcb, KIPCR, Prcb);
176
177 switch (BaseAddress)
178 {
180 /* Copy a pointer to the Pcr */
181 ControlStart = &Pcr;
182 *ActualLength = sizeof(PVOID);
183 break;
184
186 /* Copy a pointer to the Prcb */
187 ControlStart = &Prcb;
188 *ActualLength = sizeof(PVOID);
189 break;
190
192 /* Copy SpecialRegisters */
193 ControlStart = &Prcb->ProcessorState.SpecialRegisters;
194 *ActualLength = sizeof(KSPECIAL_REGISTERS);
195 break;
196
198 /* Copy a pointer to the current Thread */
199 ControlStart = &Prcb->CurrentThread;
200 *ActualLength = sizeof(PVOID);
201 break;
202
203 default:
204 *ActualLength = 0;
205 ASSERT(FALSE);
206 return STATUS_UNSUCCESSFUL;
207 }
208
209 /* Copy the memory */
210 RtlCopyMemory(Buffer, ControlStart, min(Length, *ActualLength));
211
212 /* Finish up */
213 return STATUS_SUCCESS;
214}
215
217NTAPI
223 _Out_ PULONG ActualLength)
224{
225 PVOID ControlStart;
227
228 switch (BaseAddress)
229 {
231 /* Copy SpecialRegisters */
232 ControlStart = &Prcb->ProcessorState.SpecialRegisters;
233 *ActualLength = sizeof(KSPECIAL_REGISTERS);
234 break;
235
236 default:
237 *ActualLength = 0;
238 ASSERT(FALSE);
239 return STATUS_UNSUCCESSFUL;
240 }
241
242 /* Copy the memory */
243 RtlCopyMemory(ControlStart, Buffer, min(Length, *ActualLength));
244
245 return STATUS_SUCCESS;
246}
247
249NTAPI
254 _In_ ULONG64 IoAddress,
257 _Out_ PULONG ActualDataSize)
258{
259 /* Verify parameters */
260 if (InterfaceType != Isa || BusNumber != 0 || AddressSpace != 1)
261 {
262 /* No data was read */
263 *ActualDataSize = 0;
265 }
266
267 /* Check for correct alignment */
268 if ((IoAddress & (DataSize - 1)))
269 {
270 /* Invalid alignment */
271 *ActualDataSize = 0;
273 }
274
275 switch (DataSize)
276 {
277 case sizeof(UCHAR):
278 /* Read one UCHAR */
279 *(PUCHAR)DataValue = READ_PORT_UCHAR((PUCHAR)IoAddress);
280 break;
281
282 case sizeof(USHORT):
283 /* Read one USHORT */
284 *(PUSHORT)DataValue = READ_PORT_USHORT((PUSHORT)IoAddress);
285 break;
286
287 case sizeof(ULONG):
288 /* Read one ULONG */
289 *(PULONG)DataValue = READ_PORT_ULONG((PULONG)IoAddress);
290 break;
291
292 default:
293 /* Invalid data size */
294 *ActualDataSize = 0;
296 }
297
298 /* Return the size of the data */
299 *ActualDataSize = DataSize;
300
301 /* Success! */
302 return STATUS_SUCCESS;
303}
304
306NTAPI
311 _In_ ULONG64 IoAddress,
314 _Out_ PULONG ActualDataSize)
315{
316 /* Verify parameters */
317 if (InterfaceType != Isa || BusNumber != 0 || AddressSpace != 1)
318 {
319 /* No data was written */
320 *ActualDataSize = 0;
322 }
323
324 /* Check for correct alignment */
325 if ((IoAddress & (DataSize - 1)))
326 {
327 /* Invalid alignment */
328 *ActualDataSize = 0;
330 }
331
332 switch (DataSize)
333 {
334 case sizeof(UCHAR):
335 /* Write one UCHAR */
336 WRITE_PORT_UCHAR((PUCHAR)IoAddress, *(PUCHAR)DataValue);
337 break;
338
339 case sizeof(USHORT):
340 /* Write one USHORT */
341 WRITE_PORT_USHORT((PUSHORT)IoAddress, *(PUSHORT)DataValue);
342 break;
343
344 case sizeof(ULONG):
345 /* Write one ULONG */
346 WRITE_PORT_ULONG((PULONG)IoAddress, *(PULONG)DataValue);
347 break;
348
349 default:
350 /* Invalid data size */
351 *ActualDataSize = 0;
353 }
354
355 /* Return the size of the data */
356 *ActualDataSize = DataSize;
357
358 /* Success! */
359 return STATUS_SUCCESS;
360}
361
363NTAPI
365{
367 return STATUS_UNSUCCESSFUL;
368}
369
371NTAPI
373{
374 ULONG i;
375
376 /* Loop every processor */
377 for (i = 0; i < KeNumberProcessors; i++)
378 {
380
381 /* If any processor breakpoints are active,
382 * we can't allow running without a debugger */
383 if (ProcessorState->SpecialRegisters.KernelDr7 & 0xFF)
385 }
386
387 /* No processor breakpoints, allow disabling the debugger */
388 return STATUS_SUCCESS;
389}
390
391/* 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:33
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
enum _INTERFACE_TYPE INTERFACE_TYPE
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
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:559
ULONG_PTR KdpCurrentSymbolStart
Definition: kddata.c:104
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: kdx64.c:151
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:364
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: kdx64.c:307
NTSTATUS NTAPI KdpSysWriteMsr(_In_ ULONG Msr, _In_ PULONGLONG MsrValue)
Definition: kdx64.c:116
NTSTATUS NTAPI KdpSysReadMsr(_In_ ULONG Msr, _Out_ PULONGLONG MsrValue)
Definition: kdx64.c:96
NTSTATUS NTAPI KdpSysReadControlSpace(_In_ ULONG Processor, _In_ ULONG64 BaseAddress, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_ PULONG ActualLength)
Definition: kdx64.c:166
VOID NTAPI KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdx64.c:22
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: kdx64.c:136
#define UNIMPLEMENTED
Definition: kdx64.c:16
NTSTATUS NTAPI KdpSysWriteControlSpace(_In_ ULONG Processor, _In_ ULONG64 BaseAddress, _In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_ PULONG ActualLength)
Definition: kdx64.c:218
NTSTATUS NTAPI KdpAllowDisable(VOID)
Definition: kdx64.c:372
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: kdx64.c:250
#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:122
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1182
struct _KSPECIAL_REGISTERS KSPECIAL_REGISTERS
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define _In_reads_bytes_(s)
Definition: no_sal2.h:170
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _Out_writes_bytes_(s)
Definition: no_sal2.h:178
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:391
_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:31
CCHAR KeNumberProcessors
Definition: processor.c:19
#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:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:184
enum _BUS_DATA_TYPE BUS_DATA_TYPE
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _KTHREAD * CurrentThread
Definition: ketypes.h:659
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:672
KSPECIAL_REGISTERS SpecialRegisters
Definition: ketypes.h:624
ULONG64 KernelDr7
Definition: ketypes.h:599
ULONG64 KernelDr6
Definition: ketypes.h:598
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 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