2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/amd64/kdsup.c
5 * PURPOSE: KD support routines for AMD64
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
9 /* INCLUDES *****************************************************************/
16 #define UNIMPLEMENTED KdpDprintf("%s is unimplemented\n", __FUNCTION__)
18 /* FUNCTIONS *****************************************************************/
22 KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version
)
24 /* Copy the version block */
25 RtlCopyMemory(Version
, &KdVersionBlock
, sizeof(DBGKD_GET_VERSION64
));
30 KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State
,
36 /* Check for success */
37 if (NT_SUCCESS(State
->u
.Continue2
.ContinueStatus
))
39 /* Check if we're tracing */
40 if (State
->u
.Continue2
.ControlSet
.TraceFlag
)
43 Context
->EFlags
|= EFLAGS_TF
;
48 Context
->EFlags
&= ~EFLAGS_TF
;
51 /* Loop all processors */
52 for (i
= 0; i
< KeNumberProcessors
; i
++)
54 /* Get the PRCB and update DR7 and DR6 */
55 Prcb
= KiProcessorBlock
[i
];
56 Prcb
->ProcessorState
.SpecialRegisters
.KernelDr7
=
57 State
->u
.Continue2
.ControlSet
.Dr7
;
58 Prcb
->ProcessorState
.SpecialRegisters
.KernelDr6
= 0;
61 /* Check if we have new symbol information */
62 if (State
->u
.Continue2
.ControlSet
.CurrentSymbolStart
!= 1)
65 KdpCurrentSymbolStart
=
66 State
->u
.Continue2
.ControlSet
.CurrentSymbolStart
;
67 KdpCurrentSymbolEnd
= State
->u
.Continue2
.ControlSet
.CurrentSymbolEnd
;
74 KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange
,
77 PKPRCB Prcb
= KeGetCurrentPrcb();
79 /* Copy i386 specific debug registers */
80 WaitStateChange
->ControlReport
.Dr6
= Prcb
->ProcessorState
.SpecialRegisters
.
82 WaitStateChange
->ControlReport
.Dr7
= Prcb
->ProcessorState
.SpecialRegisters
.
85 /* Copy i386 specific segments */
86 WaitStateChange
->ControlReport
.SegCs
= (USHORT
)Context
->SegCs
;
87 WaitStateChange
->ControlReport
.SegDs
= (USHORT
)Context
->SegDs
;
88 WaitStateChange
->ControlReport
.SegEs
= (USHORT
)Context
->SegEs
;
89 WaitStateChange
->ControlReport
.SegFs
= (USHORT
)Context
->SegFs
;
92 WaitStateChange
->ControlReport
.EFlags
= Context
->EFlags
;
94 /* Set Report Flags */
95 WaitStateChange
->ControlReport
.ReportFlags
= REPORT_INCLUDES_SEGS
;
96 if (WaitStateChange
->ControlReport
.SegCs
== KGDT_64_R0_CODE
)
98 WaitStateChange
->ControlReport
.ReportFlags
|= REPORT_STANDARD_CS
;
104 KdpSysReadMsr(IN ULONG Msr
,
105 OUT PLARGE_INTEGER MsrValue
)
107 /* Use SEH to protect from invalid MSRs */
110 MsrValue
->QuadPart
= __readmsr(Msr
);
112 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
114 _SEH2_YIELD(return STATUS_NO_SUCH_DEVICE
);
118 return STATUS_SUCCESS
;
123 KdpSysWriteMsr(IN ULONG Msr
,
124 IN PLARGE_INTEGER MsrValue
)
126 /* Use SEH to protect from invalid MSRs */
129 __writemsr(Msr
, MsrValue
->QuadPart
);
131 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
133 _SEH2_YIELD(return STATUS_NO_SUCH_DEVICE
);
137 return STATUS_SUCCESS
;
142 KdpSysReadBusData(IN ULONG BusDataType
,
148 OUT PULONG ActualLength
)
152 return STATUS_UNSUCCESSFUL
;
157 KdpSysWriteBusData(IN ULONG BusDataType
,
163 OUT PULONG ActualLength
)
167 return STATUS_UNSUCCESSFUL
;
172 KdpSysReadControlSpace(IN ULONG Processor
,
173 IN ULONG64 BaseAddress
,
176 OUT PULONG ActualLength
)
181 if ((ULONG
)BaseAddress
<= 2)
183 PKPRCB Prcb
= KiProcessorBlock
[Processor
];
184 PKIPCR Pcr
= CONTAINING_RECORD(Prcb
, KIPCR
, Prcb
);
186 switch ((ULONG_PTR
)BaseAddress
)
188 case AMD64_DEBUG_CONTROL_SPACE_KPCR
:
189 /* Copy a pointer to the Pcr */
191 RealLength
= sizeof(PVOID
);
194 case AMD64_DEBUG_CONTROL_SPACE_KPRCB
:
195 /* Copy a pointer to the Prcb */
196 ControlStart
= &Prcb
;
197 RealLength
= sizeof(PVOID
);
200 case AMD64_DEBUG_CONTROL_SPACE_KSPECIAL
:
201 /* Copy SpecialRegisters */
202 ControlStart
= &Prcb
->ProcessorState
.SpecialRegisters
;
203 RealLength
= sizeof(KSPECIAL_REGISTERS
);
206 case AMD64_DEBUG_CONTROL_SPACE_KTHREAD
:
207 /* Copy a pointer to the current Thread */
208 ControlStart
= &Prcb
->CurrentThread
;
209 RealLength
= sizeof(PVOID
);
216 return STATUS_UNSUCCESSFUL
;
219 if (RealLength
< Length
) Length
= RealLength
;
221 /* Copy the memory */
222 RtlCopyMemory(Buffer
, ControlStart
, Length
);
223 *ActualLength
= Length
;
226 return STATUS_SUCCESS
;
230 /* Invalid request */
232 return STATUS_UNSUCCESSFUL
;
238 KdpSysWriteControlSpace(IN ULONG Processor
,
239 IN ULONG64 BaseAddress
,
242 OUT PULONG ActualLength
)
246 return STATUS_UNSUCCESSFUL
;
251 KdpSysReadIoSpace(IN ULONG InterfaceType
,
253 IN ULONG AddressSpace
,
254 IN ULONG64 IoAddress
,
257 OUT PULONG ActualDataSize
)
259 /* Verify parameters */
260 if (InterfaceType
!= Isa
|| BusNumber
!= 0 || AddressSpace
!= 1)
262 /* No data was read */
264 return STATUS_INVALID_PARAMETER
;
267 /* Check for correct alignment */
268 if ((IoAddress
& (DataSize
- 1)))
270 /* Invalid alignment */
272 return STATUS_DATATYPE_MISALIGNMENT
;
279 *(PUCHAR
)DataValue
= READ_PORT_UCHAR((PUCHAR
)IoAddress
);
283 /* Read one USHORT */
284 *(PUSHORT
)DataValue
= READ_PORT_USHORT((PUSHORT
)IoAddress
);
289 *(PULONG
)DataValue
= READ_PORT_ULONG((PULONG
)IoAddress
);
293 /* Invalid data size */
295 return STATUS_INVALID_PARAMETER
;
298 /* Return the size of the data */
299 *ActualDataSize
= DataSize
;
302 return STATUS_SUCCESS
;
308 KdpSysWriteIoSpace(IN ULONG InterfaceType
,
310 IN ULONG AddressSpace
,
311 IN ULONG64 IoAddress
,
314 OUT PULONG ActualDataSize
)
316 /* Verify parameters */
317 if (InterfaceType
!= Isa
|| BusNumber
!= 0 || AddressSpace
!= 1)
319 /* No data was written */
321 return STATUS_INVALID_PARAMETER
;
324 /* Check for correct alignment */
325 if ((IoAddress
& (DataSize
- 1)))
327 /* Invalid alignment */
329 return STATUS_DATATYPE_MISALIGNMENT
;
335 /* Write one UCHAR */
336 WRITE_PORT_UCHAR((PUCHAR
)IoAddress
, *(PUCHAR
)DataValue
);
340 /* Write one USHORT */
341 WRITE_PORT_USHORT((PUSHORT
)IoAddress
, *(PUSHORT
)DataValue
);
345 /* Write one ULONG */
346 WRITE_PORT_ULONG((PULONG
)IoAddress
, *(PULONG
)DataValue
);
350 /* Invalid data size */
352 return STATUS_INVALID_PARAMETER
;
355 /* Return the size of the data */
356 *ActualDataSize
= DataSize
;
359 return STATUS_SUCCESS
;
364 KdpSysCheckLowMemory(IN ULONG Flags
)
368 return STATUS_UNSUCCESSFUL
;