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 /* Read the control state safely */
213 return KdpCopyMemoryChunks((ULONG_PTR
)Buffer
,
217 MMDBG_COPY_UNSAFE
| MMDBG_COPY_WRITE
,
222 /* Invalid request */
224 return STATUS_UNSUCCESSFUL
;
230 KdpSysWriteControlSpace(IN ULONG Processor
,
231 IN ULONG64 BaseAddress
,
234 OUT PULONG ActualLength
)
238 /* Make sure that this is a valid request */
239 if (((BaseAddress
+ Length
) <= sizeof(KPROCESSOR_STATE
)) &&
240 (Processor
< KeNumberProcessors
))
242 /* Set the proper address */
243 ControlStart
= (PVOID
)((ULONG_PTR
)BaseAddress
+
244 (ULONG_PTR
)&KiProcessorBlock
[Processor
]->
247 /* Write the control state safely */
248 return KdpCopyMemoryChunks((ULONG_PTR
)Buffer
,
257 /* Invalid request */
259 return STATUS_UNSUCCESSFUL
;
265 KdpSysReadIoSpace(IN ULONG InterfaceType
,
267 IN ULONG AddressSpace
,
268 IN ULONG64 IoAddress
,
271 OUT PULONG ActualDataSize
)
275 /* Verify parameters */
276 if ((InterfaceType
!= Isa
) ||
280 /* Fail, we don't support this */
282 return STATUS_UNSUCCESSFUL
;
292 READ_PORT_UCHAR((PUCHAR
)(ULONG_PTR
)IoAddress
);
293 *ActualDataSize
= sizeof(UCHAR
);
294 Status
= STATUS_SUCCESS
;
299 /* Make sure the address is aligned */
300 if ((IoAddress
& (sizeof(USHORT
) - 1)) != 0)
302 /* It isn't, bail out */
304 Status
= STATUS_DATATYPE_MISALIGNMENT
;
309 *(PUSHORT
)DataValue
=
310 READ_PORT_USHORT((PUSHORT
)(ULONG_PTR
)IoAddress
);
311 *ActualDataSize
= sizeof(USHORT
);
312 Status
= STATUS_SUCCESS
;
317 /* Make sure the address is aligned */
318 if ((IoAddress
& (sizeof(ULONG
) - 1)) != 0)
320 /* It isn't, bail out */
322 Status
= STATUS_DATATYPE_MISALIGNMENT
;
328 READ_PORT_ULONG((PULONG
)(ULONG_PTR
)IoAddress
);
329 *ActualDataSize
= sizeof(ULONG
);
330 Status
= STATUS_SUCCESS
;
335 /* Invalid size, fail */
337 Status
= STATUS_INVALID_PARAMETER
;
346 KdpSysWriteIoSpace(IN ULONG InterfaceType
,
348 IN ULONG AddressSpace
,
349 IN ULONG64 IoAddress
,
352 OUT PULONG ActualDataSize
)
356 /* Verify parameters */
357 if ((InterfaceType
!= Isa
) ||
361 /* Fail, we don't support this */
363 return STATUS_UNSUCCESSFUL
;
372 WRITE_PORT_UCHAR((PUCHAR
)(ULONG_PTR
)IoAddress
,
374 *ActualDataSize
= sizeof(UCHAR
);
375 Status
= STATUS_SUCCESS
;
380 /* Make sure the address is aligned */
381 if ((IoAddress
& (sizeof(USHORT
) - 1)) != 0)
383 /* It isn't, bail out */
385 Status
= STATUS_DATATYPE_MISALIGNMENT
;
390 WRITE_PORT_USHORT((PUSHORT
)(ULONG_PTR
)IoAddress
,
391 *(PUSHORT
)DataValue
);
392 *ActualDataSize
= sizeof(USHORT
);
393 Status
= STATUS_SUCCESS
;
398 /* Make sure the address is aligned */
399 if ((IoAddress
& (sizeof(ULONG
) - 1)) != 0)
401 /* It isn't, bail out */
403 Status
= STATUS_DATATYPE_MISALIGNMENT
;
408 WRITE_PORT_ULONG((PULONG
)(ULONG_PTR
)IoAddress
,
410 *ActualDataSize
= sizeof(ULONG
);
411 Status
= STATUS_SUCCESS
;
416 /* Invalid size, fail */
418 Status
= STATUS_INVALID_PARAMETER
;
427 KdpSysCheckLowMemory(IN ULONG Flags
)
429 /* Stubbed as we don't support PAE */
430 return STATUS_UNSUCCESSFUL
;