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_ANY_WAIT_STATE_CHANGE 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
)
179 PKPRCB Prcb
= KiProcessorBlock
[Processor
];
180 PKIPCR Pcr
= CONTAINING_RECORD(Prcb
, KIPCR
, Prcb
);
184 case AMD64_DEBUG_CONTROL_SPACE_KPCR
:
185 /* Copy a pointer to the Pcr */
187 *ActualLength
= sizeof(PVOID
);
190 case AMD64_DEBUG_CONTROL_SPACE_KPRCB
:
191 /* Copy a pointer to the Prcb */
192 ControlStart
= &Prcb
;
193 *ActualLength
= sizeof(PVOID
);
196 case AMD64_DEBUG_CONTROL_SPACE_KSPECIAL
:
197 /* Copy SpecialRegisters */
198 ControlStart
= &Prcb
->ProcessorState
.SpecialRegisters
;
199 *ActualLength
= sizeof(KSPECIAL_REGISTERS
);
202 case AMD64_DEBUG_CONTROL_SPACE_KTHREAD
:
203 /* Copy a pointer to the current Thread */
204 ControlStart
= &Prcb
->CurrentThread
;
205 *ActualLength
= sizeof(PVOID
);
211 return STATUS_UNSUCCESSFUL
;
214 /* Copy the memory */
215 RtlCopyMemory(Buffer
, ControlStart
, min(Length
, *ActualLength
));
218 return STATUS_SUCCESS
;
223 KdpSysWriteControlSpace(IN ULONG Processor
,
224 IN ULONG64 BaseAddress
,
227 OUT PULONG ActualLength
)
231 return STATUS_UNSUCCESSFUL
;
236 KdpSysReadIoSpace(IN ULONG InterfaceType
,
238 IN ULONG AddressSpace
,
239 IN ULONG64 IoAddress
,
242 OUT PULONG ActualDataSize
)
244 /* Verify parameters */
245 if (InterfaceType
!= Isa
|| BusNumber
!= 0 || AddressSpace
!= 1)
247 /* No data was read */
249 return STATUS_INVALID_PARAMETER
;
252 /* Check for correct alignment */
253 if ((IoAddress
& (DataSize
- 1)))
255 /* Invalid alignment */
257 return STATUS_DATATYPE_MISALIGNMENT
;
264 *(PUCHAR
)DataValue
= READ_PORT_UCHAR((PUCHAR
)IoAddress
);
268 /* Read one USHORT */
269 *(PUSHORT
)DataValue
= READ_PORT_USHORT((PUSHORT
)IoAddress
);
274 *(PULONG
)DataValue
= READ_PORT_ULONG((PULONG
)IoAddress
);
278 /* Invalid data size */
280 return STATUS_INVALID_PARAMETER
;
283 /* Return the size of the data */
284 *ActualDataSize
= DataSize
;
287 return STATUS_SUCCESS
;
293 KdpSysWriteIoSpace(IN ULONG InterfaceType
,
295 IN ULONG AddressSpace
,
296 IN ULONG64 IoAddress
,
299 OUT PULONG ActualDataSize
)
301 /* Verify parameters */
302 if (InterfaceType
!= Isa
|| BusNumber
!= 0 || AddressSpace
!= 1)
304 /* No data was written */
306 return STATUS_INVALID_PARAMETER
;
309 /* Check for correct alignment */
310 if ((IoAddress
& (DataSize
- 1)))
312 /* Invalid alignment */
314 return STATUS_DATATYPE_MISALIGNMENT
;
320 /* Write one UCHAR */
321 WRITE_PORT_UCHAR((PUCHAR
)IoAddress
, *(PUCHAR
)DataValue
);
325 /* Write one USHORT */
326 WRITE_PORT_USHORT((PUSHORT
)IoAddress
, *(PUSHORT
)DataValue
);
330 /* Write one ULONG */
331 WRITE_PORT_ULONG((PULONG
)IoAddress
, *(PULONG
)DataValue
);
335 /* Invalid data size */
337 return STATUS_INVALID_PARAMETER
;
340 /* Return the size of the data */
341 *ActualDataSize
= DataSize
;
344 return STATUS_SUCCESS
;
349 KdpSysCheckLowMemory(IN ULONG Flags
)
353 return STATUS_UNSUCCESSFUL
;