2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/i386/kdsup.c
5 * PURPOSE: KD support routines for x86
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Stefan Ginsberg (stefan.ginsberg@reactos.org)
10 /* INCLUDES *****************************************************************/
16 /* FUNCTIONS *****************************************************************/
20 KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version
)
22 /* Copy the version block */
23 RtlCopyMemory(Version
, &KdVersionBlock
, sizeof(DBGKD_GET_VERSION64
));
28 KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State
,
34 /* Check for success */
35 if (NT_SUCCESS(State
->u
.Continue2
.ContinueStatus
))
37 /* Check if we're tracing */
38 if (State
->u
.Continue2
.ControlSet
.TraceFlag
)
41 Context
->EFlags
|= EFLAGS_TF
;
46 Context
->EFlags
&= ~EFLAGS_TF
;
49 /* Loop all processors */
50 for (i
= 0; i
< KeNumberProcessors
; i
++)
52 /* Get the PRCB and update DR7 and DR6 */
53 Prcb
= KiProcessorBlock
[i
];
54 Prcb
->ProcessorState
.SpecialRegisters
.KernelDr7
=
55 State
->u
.Continue2
.ControlSet
.Dr7
;
56 Prcb
->ProcessorState
.SpecialRegisters
.KernelDr6
= 0;
59 /* Check if we have new symbol information */
60 if (State
->u
.Continue2
.ControlSet
.CurrentSymbolStart
!= 1)
63 KdpCurrentSymbolStart
=
64 State
->u
.Continue2
.ControlSet
.CurrentSymbolStart
;
65 KdpCurrentSymbolEnd
= State
->u
.Continue2
.ControlSet
.CurrentSymbolEnd
;
72 KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange
,
75 PKPRCB Prcb
= KeGetCurrentPrcb();
77 /* Copy i386 specific debug registers */
78 WaitStateChange
->ControlReport
.Dr6
= Prcb
->ProcessorState
.SpecialRegisters
.
80 WaitStateChange
->ControlReport
.Dr7
= Prcb
->ProcessorState
.SpecialRegisters
.
83 /* Copy i386 specific segments */
84 WaitStateChange
->ControlReport
.SegCs
= (USHORT
)Context
->SegCs
;
85 WaitStateChange
->ControlReport
.SegDs
= (USHORT
)Context
->SegDs
;
86 WaitStateChange
->ControlReport
.SegEs
= (USHORT
)Context
->SegEs
;
87 WaitStateChange
->ControlReport
.SegFs
= (USHORT
)Context
->SegFs
;
90 WaitStateChange
->ControlReport
.EFlags
= Context
->EFlags
;
92 /* Set Report Flags */
93 WaitStateChange
->ControlReport
.ReportFlags
= REPORT_INCLUDES_SEGS
;
94 if (WaitStateChange
->ControlReport
.SegCs
== KGDT_R0_CODE
)
96 WaitStateChange
->ControlReport
.ReportFlags
|= REPORT_STANDARD_CS
;
102 KdpSysReadMsr(IN ULONG Msr
,
103 OUT PLARGE_INTEGER MsrValue
)
105 /* Wrap this in SEH in case the MSR doesn't exist */
108 /* Read from the MSR */
109 MsrValue
->QuadPart
= RDMSR(Msr
);
111 //_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
114 //_SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
119 return STATUS_SUCCESS
;
124 KdpSysWriteMsr(IN ULONG Msr
,
125 IN PLARGE_INTEGER MsrValue
)
127 /* Wrap this in SEH in case the MSR doesn't exist */
130 /* Write to the MSR */
131 WRMSR(Msr
, MsrValue
->QuadPart
);
133 //_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
136 //_SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
141 return STATUS_SUCCESS
;
146 KdpSysReadBusData(IN ULONG BusDataType
,
152 OUT PULONG ActualLength
)
154 /* Just forward to HAL */
155 *ActualLength
= HalGetBusDataByOffset(BusDataType
,
163 return (*ActualLength
!= 0) ? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
;
168 KdpSysWriteBusData(IN ULONG BusDataType
,
174 OUT PULONG ActualLength
)
176 /* Just forward to HAL */
177 *ActualLength
= HalSetBusDataByOffset(BusDataType
,
185 return (*ActualLength
!= 0) ? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
;
190 KdpSysReadControlSpace(IN ULONG Processor
,
191 IN ULONG64 BaseAddress
,
194 OUT PULONG ActualLength
)
199 /* Make sure that this is a valid request */
200 if ((BaseAddress
< sizeof(KPROCESSOR_STATE
)) &&
201 (Processor
< KeNumberProcessors
))
203 /* Get the actual length */
204 RealLength
= sizeof(KPROCESSOR_STATE
) - (ULONG_PTR
)BaseAddress
;
205 if (RealLength
< Length
) Length
= RealLength
;
207 /* Set the proper address */
208 ControlStart
= (PVOID
)((ULONG_PTR
)BaseAddress
+
209 (ULONG_PTR
)&KiProcessorBlock
[Processor
]->
212 /* Copy the memory */
213 RtlCopyMemory(Buffer
, ControlStart
, Length
);
216 *ActualLength
= Length
;
217 return STATUS_SUCCESS
;
221 /* Invalid request */
223 return STATUS_UNSUCCESSFUL
;
229 KdpSysWriteControlSpace(IN ULONG Processor
,
230 IN ULONG64 BaseAddress
,
233 OUT PULONG ActualLength
)
237 /* Make sure that this is a valid request */
238 if (((BaseAddress
+ Length
) <= sizeof(KPROCESSOR_STATE
)) &&
239 (Processor
< KeNumberProcessors
))
241 /* Set the proper address */
242 ControlStart
= (PVOID
)((ULONG_PTR
)BaseAddress
+
243 (ULONG_PTR
)&KiProcessorBlock
[Processor
]->
246 /* Copy the memory */
247 RtlCopyMemory(ControlStart
, Buffer
, Length
);
250 *ActualLength
= Length
;
251 return STATUS_SUCCESS
;
255 /* Invalid request */
257 return STATUS_UNSUCCESSFUL
;
263 KdpSysReadIoSpace(IN ULONG InterfaceType
,
265 IN ULONG AddressSpace
,
266 IN ULONG64 IoAddress
,
269 OUT PULONG ActualDataSize
)
273 /* Verify parameters */
274 if ((InterfaceType
!= Isa
) ||
278 /* Fail, we don't support this */
280 return STATUS_UNSUCCESSFUL
;
290 READ_PORT_UCHAR((PUCHAR
)(ULONG_PTR
)IoAddress
);
291 *ActualDataSize
= sizeof(UCHAR
);
292 Status
= STATUS_SUCCESS
;
297 /* Make sure the address is aligned */
298 if ((IoAddress
& (sizeof(USHORT
) - 1)) != 0)
300 /* It isn't, bail out */
302 Status
= STATUS_DATATYPE_MISALIGNMENT
;
307 *(PUSHORT
)DataValue
=
308 READ_PORT_USHORT((PUSHORT
)(ULONG_PTR
)IoAddress
);
309 *ActualDataSize
= sizeof(USHORT
);
310 Status
= STATUS_SUCCESS
;
315 /* Make sure the address is aligned */
316 if ((IoAddress
& (sizeof(ULONG
) - 1)) != 0)
318 /* It isn't, bail out */
320 Status
= STATUS_DATATYPE_MISALIGNMENT
;
326 READ_PORT_ULONG((PULONG
)(ULONG_PTR
)IoAddress
);
327 *ActualDataSize
= sizeof(ULONG
);
328 Status
= STATUS_SUCCESS
;
333 /* Invalid size, fail */
335 Status
= STATUS_INVALID_PARAMETER
;
344 KdpSysWriteIoSpace(IN ULONG InterfaceType
,
346 IN ULONG AddressSpace
,
347 IN ULONG64 IoAddress
,
350 OUT PULONG ActualDataSize
)
354 /* Verify parameters */
355 if ((InterfaceType
!= Isa
) ||
359 /* Fail, we don't support this */
361 return STATUS_UNSUCCESSFUL
;
370 WRITE_PORT_UCHAR((PUCHAR
)(ULONG_PTR
)IoAddress
,
372 *ActualDataSize
= sizeof(UCHAR
);
373 Status
= STATUS_SUCCESS
;
378 /* Make sure the address is aligned */
379 if ((IoAddress
& (sizeof(USHORT
) - 1)) != 0)
381 /* It isn't, bail out */
383 Status
= STATUS_DATATYPE_MISALIGNMENT
;
388 WRITE_PORT_USHORT((PUSHORT
)(ULONG_PTR
)IoAddress
,
389 *(PUSHORT
)DataValue
);
390 *ActualDataSize
= sizeof(USHORT
);
391 Status
= STATUS_SUCCESS
;
396 /* Make sure the address is aligned */
397 if ((IoAddress
& (sizeof(ULONG
) - 1)) != 0)
399 /* It isn't, bail out */
401 Status
= STATUS_DATATYPE_MISALIGNMENT
;
406 WRITE_PORT_ULONG((PULONG
)(ULONG_PTR
)IoAddress
,
408 *ActualDataSize
= sizeof(ULONG
);
409 Status
= STATUS_SUCCESS
;
414 /* Invalid size, fail */
416 Status
= STATUS_INVALID_PARAMETER
;
425 KdpSysCheckLowMemory(IN ULONG Flags
)
427 /* Stubbed as we don't support PAE */
428 return STATUS_UNSUCCESSFUL
;