Implement KdpSysGetVersion, KdpGetStateChange, KdpSetContextState, KdpSysReadMsr...
[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 Version->MajorVersion = 0;
25 Version->MinorVersion = 0;
26 Version->ProtocolVersion = DBGKD_64BIT_PROTOCOL_VERSION2;
27 Version->KdSecondaryVersion = KD_SECONDARY_VERSION_AMD64_CONTEXT;
28 Version->Flags = DBGKD_VERS_FLAG_PTR64 | DBGKD_VERS_FLAG_DATA;
29 Version->MachineType = IMAGE_FILE_MACHINE_AMD64;
30 Version->MaxPacketType = PACKET_TYPE_MAX;
31 Version->MaxStateChange = 0;
32 Version->MaxManipulate = 0;
33 Version->Simulation = DBGKD_SIMULATION_NONE;
34 Version->Unused[0] = 0;
35 Version->KernBase = 0xfffff80000800000ULL;
36 Version->PsLoadedModuleList = (ULONG_PTR)&KeLoaderBlock->LoadOrderListHead;
37 Version->DebuggerDataList = 0;
38 }
39
40 VOID
41 NTAPI
42 KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
43 IN PCONTEXT Context)
44 {
45 PKPRCB Prcb;
46 ULONG i;
47
48 /* Check for success */
49 if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
50 {
51 /* Check if we're tracing */
52 if (State->u.Continue2.ControlSet.TraceFlag)
53 {
54 /* Enable TF */
55 Context->EFlags |= EFLAGS_TF;
56 }
57 else
58 {
59 /* Remove it */
60 Context->EFlags &= ~EFLAGS_TF;
61 }
62
63 /* Loop all processors */
64 for (i = 0; i < KeNumberProcessors; i++)
65 {
66 /* Get the PRCB and update DR7 and DR6 */
67 Prcb = KiProcessorBlock[i];
68 Prcb->ProcessorState.SpecialRegisters.KernelDr7 =
69 State->u.Continue2.ControlSet.Dr7;
70 Prcb->ProcessorState.SpecialRegisters.KernelDr6 = 0;
71 }
72
73 /* Check if we have new symbol information */
74 if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
75 {
76 /* Update it */
77 KdpCurrentSymbolStart =
78 State->u.Continue2.ControlSet.CurrentSymbolStart;
79 KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
80 }
81 }
82 }
83
84 VOID
85 NTAPI
86 KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
87 IN PCONTEXT Context)
88 {
89 PKPRCB Prcb = KeGetCurrentPrcb();
90
91 /* Copy i386 specific debug registers */
92 WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
93 KernelDr6;
94 WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
95 KernelDr7;
96
97 /* Copy i386 specific segments */
98 WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;
99 WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;
100 WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;
101 WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;
102
103 /* Copy EFlags */
104 WaitStateChange->ControlReport.EFlags = Context->EFlags;
105
106 /* Set Report Flags */
107 WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
108 if (WaitStateChange->ControlReport.SegCs == KGDT_64_R0_CODE)
109 {
110 WaitStateChange->ControlReport.ReportFlags = REPORT_STANDARD_CS;
111 }
112 }
113
114 NTSTATUS
115 NTAPI
116 KdpSysReadMsr(IN ULONG Msr,
117 OUT PLARGE_INTEGER MsrValue)
118 {
119 MsrValue->QuadPart = __readmsr(Msr);
120 return STATUS_SUCCESS;
121 }
122
123 NTSTATUS
124 NTAPI
125 KdpSysWriteMsr(IN ULONG Msr,
126 IN PLARGE_INTEGER MsrValue)
127 {
128 __writemsr(Msr, MsrValue->QuadPart);
129 return STATUS_SUCCESS;
130 }
131
132 NTSTATUS
133 NTAPI
134 KdpSysReadBusData(IN ULONG BusDataType,
135 IN ULONG BusNumber,
136 IN ULONG SlotNumber,
137 IN PVOID Buffer,
138 IN ULONG Offset,
139 IN ULONG Length,
140 OUT PULONG ActualLength)
141 {
142 UNIMPLEMENTED;
143 while (TRUE);
144 return STATUS_UNSUCCESSFUL;
145 }
146
147 NTSTATUS
148 NTAPI
149 KdpSysWriteBusData(IN ULONG BusDataType,
150 IN ULONG BusNumber,
151 IN ULONG SlotNumber,
152 IN PVOID Buffer,
153 IN ULONG Offset,
154 IN ULONG Length,
155 OUT PULONG ActualLength)
156 {
157 UNIMPLEMENTED;
158 while (TRUE);
159 return STATUS_UNSUCCESSFUL;
160 }
161
162 NTSTATUS
163 NTAPI
164 KdpSysReadControlSpace(IN ULONG Processor,
165 IN ULONG64 BaseAddress,
166 IN PVOID Buffer,
167 IN ULONG Length,
168 OUT PULONG ActualLength)
169 {
170 PVOID ControlStart;
171 ULONG RealLength;
172
173 if ((ULONG)BaseAddress <= 2)
174 {
175 PKPRCB Prcb = KiProcessorBlock[Processor];
176 PKIPCR Pcr = CONTAINING_RECORD(Prcb, KIPCR, Prcb);
177
178 switch ((ULONG_PTR)BaseAddress)
179 {
180 case 0:
181 /* Copy a pointer to the Pcr */
182 ControlStart = &Pcr;
183 RealLength = sizeof(PVOID);
184 break;
185
186 case 1:
187 /* Copy a pointer to the Prcb */
188 ControlStart = &Prcb;
189 RealLength = sizeof(PVOID);
190 break;
191
192 case 2:
193 /* Copy SpecialRegisters */
194 ControlStart = &Prcb->ProcessorState.SpecialRegisters;
195 RealLength = sizeof(KSPECIAL_REGISTERS);
196 break;
197
198 default:
199 RealLength = 0;
200 ControlStart = NULL;
201 ASSERT(FALSE);
202 }
203
204 if (RealLength < Length) Length = RealLength;
205
206 /* Copy the memory */
207 RtlCopyMemory(Buffer, ControlStart, Length);
208 *ActualLength = Length;
209
210 /* Finish up */
211 return STATUS_SUCCESS;
212 }
213 else
214 {
215 /* Invalid request */
216 *ActualLength = 0;
217 return STATUS_UNSUCCESSFUL;
218 }
219 }
220
221 NTSTATUS
222 NTAPI
223 KdpSysWriteControlSpace(IN ULONG Processor,
224 IN ULONG64 BaseAddress,
225 IN PVOID Buffer,
226 IN ULONG Length,
227 OUT PULONG ActualLength)
228 {
229 UNIMPLEMENTED;
230 while (TRUE);
231 return STATUS_UNSUCCESSFUL;
232 }
233
234 NTSTATUS
235 NTAPI
236 KdpSysReadIoSpace(IN ULONG InterfaceType,
237 IN ULONG BusNumber,
238 IN ULONG AddressSpace,
239 IN ULONG64 IoAddress,
240 IN PULONG DataValue,
241 IN ULONG DataSize,
242 OUT PULONG ActualDataSize)
243 {
244 UNIMPLEMENTED;
245 while (TRUE);
246 return STATUS_UNSUCCESSFUL;
247 }
248
249 NTSTATUS
250 NTAPI
251 KdpSysWriteIoSpace(IN ULONG InterfaceType,
252 IN ULONG BusNumber,
253 IN ULONG AddressSpace,
254 IN ULONG64 IoAddress,
255 IN PULONG DataValue,
256 IN ULONG DataSize,
257 OUT PULONG ActualDataSize)
258 {
259 UNIMPLEMENTED;
260 while (TRUE);
261 return STATUS_UNSUCCESSFUL;
262 }
263
264 NTSTATUS
265 NTAPI
266 KdpSysCheckLowMemory(IN ULONG Flags)
267 {
268 UNIMPLEMENTED;
269 while (TRUE);
270 return STATUS_UNSUCCESSFUL;
271 }