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 KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State
,
26 /* Check for success */
27 if (NT_SUCCESS(State
->u
.Continue2
.ContinueStatus
))
29 /* Check if we're tracing */
30 if (State
->u
.Continue2
.ControlSet
.TraceFlag
)
33 Context
->EFlags
|= EFLAGS_TF
;
38 Context
->EFlags
&= ~EFLAGS_TF
;
41 /* Loop all processors */
42 for (i
= 0; i
< KeNumberProcessors
; i
++)
44 /* Get the PRCB and update DR7 and DR6 */
45 Prcb
= KiProcessorBlock
[i
];
46 Prcb
->ProcessorState
.SpecialRegisters
.KernelDr7
=
47 State
->u
.Continue2
.ControlSet
.Dr7
;
48 Prcb
->ProcessorState
.SpecialRegisters
.KernelDr6
= 0;
51 /* Check if we have new symbol information */
52 if (State
->u
.Continue2
.ControlSet
.CurrentSymbolStart
!= 1)
55 KdpCurrentSymbolStart
=
56 State
->u
.Continue2
.ControlSet
.CurrentSymbolStart
;
57 KdpCurrentSymbolEnd
= State
->u
.Continue2
.ControlSet
.CurrentSymbolEnd
;
64 KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange
,
67 PKPRCB Prcb
= KeGetCurrentPrcb();
69 /* Copy i386 specific debug registers */
70 WaitStateChange
->ControlReport
.Dr6
= Prcb
->ProcessorState
.SpecialRegisters
.
72 WaitStateChange
->ControlReport
.Dr7
= Prcb
->ProcessorState
.SpecialRegisters
.
75 /* Copy i386 specific segments */
76 WaitStateChange
->ControlReport
.SegCs
= (USHORT
)Context
->SegCs
;
77 WaitStateChange
->ControlReport
.SegDs
= (USHORT
)Context
->SegDs
;
78 WaitStateChange
->ControlReport
.SegEs
= (USHORT
)Context
->SegEs
;
79 WaitStateChange
->ControlReport
.SegFs
= (USHORT
)Context
->SegFs
;
82 WaitStateChange
->ControlReport
.EFlags
= Context
->EFlags
;
84 /* Set Report Flags */
85 WaitStateChange
->ControlReport
.ReportFlags
= REPORT_INCLUDES_SEGS
;
86 if (WaitStateChange
->ControlReport
.SegCs
== KGDT_R0_CODE
)
88 WaitStateChange
->ControlReport
.ReportFlags
|= REPORT_STANDARD_CS
;
94 KdpSysReadMsr(IN ULONG Msr
,
95 OUT PLARGE_INTEGER MsrValue
)
97 /* Wrap this in SEH in case the MSR doesn't exist */
100 /* Read from the MSR */
101 MsrValue
->QuadPart
= RDMSR(Msr
);
103 //_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
106 //_SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
111 return STATUS_SUCCESS
;
116 KdpSysWriteMsr(IN ULONG Msr
,
117 IN PLARGE_INTEGER MsrValue
)
119 /* Wrap this in SEH in case the MSR doesn't exist */
122 /* Write to the MSR */
123 WRMSR(Msr
, MsrValue
->QuadPart
);
125 //_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
128 //_SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
133 return STATUS_SUCCESS
;
138 KdpSysReadBusData(IN ULONG BusDataType
,
144 OUT PULONG ActualLength
)
146 /* Just forward to HAL */
147 *ActualLength
= HalGetBusDataByOffset(BusDataType
,
155 return *ActualLength
!= 0 ? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
;
160 KdpSysWriteBusData(IN ULONG BusDataType
,
166 OUT PULONG ActualLength
)
168 /* Just forward to HAL */
169 *ActualLength
= HalSetBusDataByOffset(BusDataType
,
177 return *ActualLength
!= 0 ? STATUS_SUCCESS
: STATUS_UNSUCCESSFUL
;
182 KdpSysReadControlSpace(IN ULONG Processor
,
183 IN ULONG64 BaseAddress
,
186 OUT PULONG ActualLength
)
191 /* Make sure that this is a valid request */
192 if ((BaseAddress
< sizeof(KPROCESSOR_STATE
)) &&
193 (Processor
< KeNumberProcessors
))
195 /* Get the actual length */
196 RealLength
= sizeof(KPROCESSOR_STATE
) - (ULONG_PTR
)BaseAddress
;
197 if (RealLength
< Length
) Length
= RealLength
;
199 /* Set the proper address */
200 ControlStart
= (PVOID
)((ULONG_PTR
)BaseAddress
+
201 (ULONG_PTR
)&KiProcessorBlock
[Processor
]->
204 /* Read the control state safely */
205 return KdpCopyMemoryChunks((ULONG_PTR
)Buffer
,
209 MMDBG_COPY_UNSAFE
| MMDBG_COPY_WRITE
,
214 /* Invalid request */
216 return STATUS_UNSUCCESSFUL
;
222 KdpSysWriteControlSpace(IN ULONG Processor
,
223 IN ULONG64 BaseAddress
,
226 OUT PULONG ActualLength
)
230 /* Make sure that this is a valid request */
231 if (((BaseAddress
+ Length
) <= sizeof(KPROCESSOR_STATE
)) &&
232 (Processor
< KeNumberProcessors
))
234 /* Set the proper address */
235 ControlStart
= (PVOID
)((ULONG_PTR
)BaseAddress
+
236 (ULONG_PTR
)&KiProcessorBlock
[Processor
]->
239 /* Write the control state safely */
240 return KdpCopyMemoryChunks((ULONG_PTR
)Buffer
,
249 /* Invalid request */
251 return STATUS_UNSUCCESSFUL
;
257 KdpSysReadIoSpace(IN ULONG InterfaceType
,
259 IN ULONG AddressSpace
,
260 IN ULONG64 IoAddress
,
263 OUT PULONG ActualDataSize
)
267 /* Verify parameters */
268 if ((InterfaceType
!= Isa
) ||
272 /* Fail, we don't support this */
274 return STATUS_UNSUCCESSFUL
;
284 READ_PORT_UCHAR((PUCHAR
)(ULONG_PTR
)IoAddress
);
285 *ActualDataSize
= sizeof(UCHAR
);
286 Status
= STATUS_SUCCESS
;
291 /* Make sure the address is aligned */
292 if ((IoAddress
& (sizeof(USHORT
) - 1)) != 0)
294 /* It isn't, bail out */
296 Status
= STATUS_DATATYPE_MISALIGNMENT
;
301 *(PUSHORT
)DataValue
=
302 READ_PORT_USHORT((PUSHORT
)(ULONG_PTR
)IoAddress
);
303 *ActualDataSize
= sizeof(USHORT
);
304 Status
= STATUS_SUCCESS
;
309 /* Make sure the address is aligned */
310 if ((IoAddress
& (sizeof(ULONG
) - 1)) != 0)
312 /* It isn't, bail out */
314 Status
= STATUS_DATATYPE_MISALIGNMENT
;
320 READ_PORT_ULONG((PULONG
)(ULONG_PTR
)IoAddress
);
321 *ActualDataSize
= sizeof(ULONG
);
322 Status
= STATUS_SUCCESS
;
327 /* Invalid size, fail */
329 Status
= STATUS_INVALID_PARAMETER
;
338 KdpSysWriteIoSpace(IN ULONG InterfaceType
,
340 IN ULONG AddressSpace
,
341 IN ULONG64 IoAddress
,
344 OUT PULONG ActualDataSize
)
348 /* Verify parameters */
349 if ((InterfaceType
!= Isa
) ||
353 /* Fail, we don't support this */
355 return STATUS_UNSUCCESSFUL
;
364 WRITE_PORT_UCHAR((PUCHAR
)(ULONG_PTR
)IoAddress
,
366 *ActualDataSize
= sizeof(UCHAR
);
367 Status
= STATUS_SUCCESS
;
372 /* Make sure the address is aligned */
373 if ((IoAddress
& (sizeof(USHORT
) - 1)) != 0)
375 /* It isn't, bail out */
377 Status
= STATUS_DATATYPE_MISALIGNMENT
;
382 WRITE_PORT_USHORT((PUSHORT
)(ULONG_PTR
)IoAddress
,
383 *(PUSHORT
)DataValue
);
384 *ActualDataSize
= sizeof(USHORT
);
385 Status
= STATUS_SUCCESS
;
390 /* Make sure the address is aligned */
391 if ((IoAddress
& (sizeof(ULONG
) - 1)) != 0)
393 /* It isn't, bail out */
395 Status
= STATUS_DATATYPE_MISALIGNMENT
;
400 WRITE_PORT_ULONG((PULONG
)(ULONG_PTR
)IoAddress
,
402 *ActualDataSize
= sizeof(ULONG
);
403 Status
= STATUS_SUCCESS
;
408 /* Invalid size, fail */
410 Status
= STATUS_INVALID_PARAMETER
;
419 KdpSysCheckLowMemory(IN ULONG Flags
)
421 /* Stubbed as we don't support PAE */
422 return STATUS_UNSUCCESSFUL
;