[Kd64] Copy KdVersionBlock like for x86, fix Value of ReportFlags member in KdpSetCon...
[reactos.git] / reactos / ntoskrnl / kd64 / amd64 / kdsup.c
1 /*
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)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 #undef UNIMPLEMENTED
16 #define UNIMPLEMENTED KdpDprintf("%s is unimplemented\n", __FUNCTION__)
17
18 /* FUNCTIONS *****************************************************************/
19
20 VOID
21 NTAPI
22 KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
23 {
24 /* Copy the version block */
25 RtlCopyMemory(Version, &KdVersionBlock, sizeof(DBGKD_GET_VERSION64));
26 }
27
28 VOID
29 NTAPI
30 KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
31 IN PCONTEXT Context)
32 {
33 PKPRCB Prcb;
34 ULONG i;
35
36 /* Check for success */
37 if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
38 {
39 /* Check if we're tracing */
40 if (State->u.Continue2.ControlSet.TraceFlag)
41 {
42 /* Enable TF */
43 Context->EFlags |= EFLAGS_TF;
44 }
45 else
46 {
47 /* Remove it */
48 Context->EFlags &= ~EFLAGS_TF;
49 }
50
51 /* Loop all processors */
52 for (i = 0; i < KeNumberProcessors; i++)
53 {
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;
59 }
60
61 /* Check if we have new symbol information */
62 if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
63 {
64 /* Update it */
65 KdpCurrentSymbolStart =
66 State->u.Continue2.ControlSet.CurrentSymbolStart;
67 KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
68 }
69 }
70 }
71
72 VOID
73 NTAPI
74 KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
75 IN PCONTEXT Context)
76 {
77 PKPRCB Prcb = KeGetCurrentPrcb();
78
79 /* Copy i386 specific debug registers */
80 WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
81 KernelDr6;
82 WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
83 KernelDr7;
84
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;
90
91 /* Copy EFlags */
92 WaitStateChange->ControlReport.EFlags = Context->EFlags;
93
94 /* Set Report Flags */
95 WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
96 if (WaitStateChange->ControlReport.SegCs == KGDT_64_R0_CODE)
97 {
98 WaitStateChange->ControlReport.ReportFlags |= REPORT_STANDARD_CS;
99 }
100 }
101
102 NTSTATUS
103 NTAPI
104 KdpSysReadMsr(IN ULONG Msr,
105 OUT PLARGE_INTEGER MsrValue)
106 {
107 MsrValue->QuadPart = __readmsr(Msr);
108 return STATUS_SUCCESS;
109 }
110
111 NTSTATUS
112 NTAPI
113 KdpSysWriteMsr(IN ULONG Msr,
114 IN PLARGE_INTEGER MsrValue)
115 {
116 __writemsr(Msr, MsrValue->QuadPart);
117 return STATUS_SUCCESS;
118 }
119
120 NTSTATUS
121 NTAPI
122 KdpSysReadBusData(IN ULONG BusDataType,
123 IN ULONG BusNumber,
124 IN ULONG SlotNumber,
125 IN PVOID Buffer,
126 IN ULONG Offset,
127 IN ULONG Length,
128 OUT PULONG ActualLength)
129 {
130 UNIMPLEMENTED;
131 while (TRUE);
132 return STATUS_UNSUCCESSFUL;
133 }
134
135 NTSTATUS
136 NTAPI
137 KdpSysWriteBusData(IN ULONG BusDataType,
138 IN ULONG BusNumber,
139 IN ULONG SlotNumber,
140 IN PVOID Buffer,
141 IN ULONG Offset,
142 IN ULONG Length,
143 OUT PULONG ActualLength)
144 {
145 UNIMPLEMENTED;
146 while (TRUE);
147 return STATUS_UNSUCCESSFUL;
148 }
149
150 NTSTATUS
151 NTAPI
152 KdpSysReadControlSpace(IN ULONG Processor,
153 IN ULONG64 BaseAddress,
154 IN PVOID Buffer,
155 IN ULONG Length,
156 OUT PULONG ActualLength)
157 {
158 PVOID ControlStart;
159 ULONG RealLength;
160
161 if ((ULONG)BaseAddress <= 2)
162 {
163 PKPRCB Prcb = KiProcessorBlock[Processor];
164 PKIPCR Pcr = CONTAINING_RECORD(Prcb, KIPCR, Prcb);
165
166 switch ((ULONG_PTR)BaseAddress)
167 {
168 case 0:
169 /* Copy a pointer to the Pcr */
170 ControlStart = &Pcr;
171 RealLength = sizeof(PVOID);
172 break;
173
174 case 1:
175 /* Copy a pointer to the Prcb */
176 ControlStart = &Prcb;
177 RealLength = sizeof(PVOID);
178 break;
179
180 case 2:
181 /* Copy SpecialRegisters */
182 ControlStart = &Prcb->ProcessorState.SpecialRegisters;
183 RealLength = sizeof(KSPECIAL_REGISTERS);
184 break;
185
186 default:
187 RealLength = 0;
188 ControlStart = NULL;
189 ASSERT(FALSE);
190 }
191
192 if (RealLength < Length) Length = RealLength;
193
194 /* Copy the memory */
195 RtlCopyMemory(Buffer, ControlStart, Length);
196 *ActualLength = Length;
197
198 /* Finish up */
199 return STATUS_SUCCESS;
200 }
201 else
202 {
203 /* Invalid request */
204 *ActualLength = 0;
205 return STATUS_UNSUCCESSFUL;
206 }
207 }
208
209 NTSTATUS
210 NTAPI
211 KdpSysWriteControlSpace(IN ULONG Processor,
212 IN ULONG64 BaseAddress,
213 IN PVOID Buffer,
214 IN ULONG Length,
215 OUT PULONG ActualLength)
216 {
217 UNIMPLEMENTED;
218 while (TRUE);
219 return STATUS_UNSUCCESSFUL;
220 }
221
222 NTSTATUS
223 NTAPI
224 KdpSysReadIoSpace(IN ULONG InterfaceType,
225 IN ULONG BusNumber,
226 IN ULONG AddressSpace,
227 IN ULONG64 IoAddress,
228 IN PULONG DataValue,
229 IN ULONG DataSize,
230 OUT PULONG ActualDataSize)
231 {
232 UNIMPLEMENTED;
233 while (TRUE);
234 return STATUS_UNSUCCESSFUL;
235 }
236
237 NTSTATUS
238 NTAPI
239 KdpSysWriteIoSpace(IN ULONG InterfaceType,
240 IN ULONG BusNumber,
241 IN ULONG AddressSpace,
242 IN ULONG64 IoAddress,
243 IN PULONG DataValue,
244 IN ULONG DataSize,
245 OUT PULONG ActualDataSize)
246 {
247 UNIMPLEMENTED;
248 while (TRUE);
249 return STATUS_UNSUCCESSFUL;
250 }
251
252 NTSTATUS
253 NTAPI
254 KdpSysCheckLowMemory(IN ULONG Flags)
255 {
256 UNIMPLEMENTED;
257 while (TRUE);
258 return STATUS_UNSUCCESSFUL;
259 }