[KD64]
[reactos.git] / reactos / ntoskrnl / kd64 / amd64 / kdsup.c
index ba07617..2f293d7 100644 (file)
 
 VOID
 NTAPI
-KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
-                  IN PCONTEXT Context)
+KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    /* Copy the version block */
+    RtlCopyMemory(Version, &KdVersionBlock, sizeof(DBGKD_GET_VERSION64));
 }
 
 VOID
 NTAPI
-KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
-                   IN PCONTEXT Context)
+KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
+                  IN PCONTEXT Context)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    PKPRCB Prcb;
+    ULONG i;
+
+    /* Check for success */
+    if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
+    {
+        /* Check if we're tracing */
+        if (State->u.Continue2.ControlSet.TraceFlag)
+        {
+            /* Enable TF */
+            Context->EFlags |= EFLAGS_TF;
+        }
+        else
+        {
+            /* Remove it */
+            Context->EFlags &= ~EFLAGS_TF;
+        }
+
+        /* Loop all processors */
+        for (i = 0; i < KeNumberProcessors; i++)
+        {
+            /* Get the PRCB and update DR7 and DR6 */
+            Prcb = KiProcessorBlock[i];
+            Prcb->ProcessorState.SpecialRegisters.KernelDr7 =
+                State->u.Continue2.ControlSet.Dr7;
+            Prcb->ProcessorState.SpecialRegisters.KernelDr6 = 0;
+        }
+
+        /* Check if we have new symbol information */
+        if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
+        {
+            /* Update it */
+            KdpCurrentSymbolStart =
+                State->u.Continue2.ControlSet.CurrentSymbolStart;
+            KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
+        }
+    }
 }
 
 VOID
 NTAPI
-KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
+KdpSetContextState(IN PDBGKD_WAIT_STATE_CHANGE64 WaitStateChange,
+                   IN PCONTEXT Context)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    PKPRCB Prcb = KeGetCurrentPrcb();
+
+    /* Copy i386 specific debug registers */
+    WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
+                                         KernelDr6;
+    WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
+                                         KernelDr7;
+
+    /* Copy i386 specific segments */
+    WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;
+    WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;
+    WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;
+    WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;
+
+    /* Copy EFlags */
+    WaitStateChange->ControlReport.EFlags = Context->EFlags;
+
+    /* Set Report Flags */
+    WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
+    if (WaitStateChange->ControlReport.SegCs == KGDT_64_R0_CODE)
+    {
+        WaitStateChange->ControlReport.ReportFlags |= REPORT_STANDARD_CS;
+    }
 }
 
 NTSTATUS
@@ -48,9 +104,18 @@ NTAPI
 KdpSysReadMsr(IN ULONG Msr,
               OUT PLARGE_INTEGER MsrValue)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
-    return STATUS_UNSUCCESSFUL;
+    /* Use SEH to protect from invalid MSRs */
+    _SEH2_TRY
+    {
+        MsrValue->QuadPart = __readmsr(Msr);
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        _SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
+    }
+    _SEH2_END
+
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS
@@ -58,9 +123,18 @@ NTAPI
 KdpSysWriteMsr(IN ULONG Msr,
                IN PLARGE_INTEGER MsrValue)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
-    return STATUS_UNSUCCESSFUL;
+    /* Use SEH to protect from invalid MSRs */
+    _SEH2_TRY
+    {
+        __writemsr(Msr, MsrValue->QuadPart);
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        _SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
+    }
+    _SEH2_END
+
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS
@@ -101,9 +175,62 @@ KdpSysReadControlSpace(IN ULONG Processor,
                        IN ULONG Length,
                        OUT PULONG ActualLength)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
-    return STATUS_UNSUCCESSFUL;
+    PVOID ControlStart;
+    ULONG RealLength;
+
+    if ((ULONG)BaseAddress <= 2)
+    {
+        PKPRCB Prcb = KiProcessorBlock[Processor];
+        PKIPCR Pcr = CONTAINING_RECORD(Prcb, KIPCR, Prcb);
+
+        switch ((ULONG_PTR)BaseAddress)
+        {
+            case DEBUG_CONTROL_SPACE_KPCR:
+                /* Copy a pointer to the Pcr */
+                ControlStart = &Pcr;
+                RealLength = sizeof(PVOID);
+                break;
+
+            case DEBUG_CONTROL_SPACE_KPRCB:
+                /* Copy a pointer to the Prcb */
+                ControlStart = &Prcb;
+                RealLength = sizeof(PVOID);
+                break;
+
+            case DEBUG_CONTROL_SPACE_KSPECIAL:
+                /* Copy SpecialRegisters */
+                ControlStart = &Prcb->ProcessorState.SpecialRegisters;
+                RealLength = sizeof(KSPECIAL_REGISTERS);
+                break;
+
+            case DEBUG_CONTROL_SPACE_KTHREAD:
+                /* Copy a pointer to the current Thread */
+                ControlStart = &Prcb->CurrentThread;
+                RealLength = sizeof(PVOID);
+                break;
+
+            default:
+                RealLength = 0;
+                ControlStart = NULL;
+                ASSERT(FALSE);
+                return STATUS_UNSUCCESSFUL;
+        }
+
+        if (RealLength < Length) Length = RealLength;
+
+        /* Copy the memory */
+        RtlCopyMemory(Buffer, ControlStart, Length);
+        *ActualLength = Length;
+
+        /* Finish up */
+        return STATUS_SUCCESS;
+    }
+    else
+    {
+        /* Invalid request */
+        *ActualLength = 0;
+        return STATUS_UNSUCCESSFUL;
+    }
 }
 
 NTSTATUS
@@ -125,28 +252,95 @@ KdpSysReadIoSpace(IN ULONG InterfaceType,
                   IN ULONG BusNumber,
                   IN ULONG AddressSpace,
                   IN ULONG64 IoAddress,
-                  IN PULONG DataValue,
+                  OUT PVOID DataValue,
                   IN ULONG DataSize,
                   OUT PULONG ActualDataSize)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
-    return STATUS_UNSUCCESSFUL;
+    /* Verify parameters */
+    if (InterfaceType != Isa || BusNumber != 0 || AddressSpace != 1)
+    {
+        /* No data was read */
+        *ActualDataSize = 0;
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    switch (DataSize)
+    {
+        case sizeof(UCHAR):
+            /* read one UCHAR */
+            *(PUCHAR)DataValue = READ_PORT_UCHAR((PUCHAR)IoAddress);
+            break;
+
+        case sizeof(USHORT):
+            /* Read one USHORT */
+            *(PUSHORT)DataValue = READ_PORT_USHORT((PUSHORT)IoAddress);
+            break;
+
+        case sizeof(ULONG):
+            /* Read one ULONG */
+            *(PULONG)DataValue = READ_PORT_ULONG((PULONG)IoAddress);
+            break;
+
+        default:
+            /* Invalid data size */
+             *ActualDataSize = 0;
+            return STATUS_UNSUCCESSFUL;
+    }
+
+    /* Return the size of the data */
+    *ActualDataSize = DataSize;
+
+    /* Success! */
+    return STATUS_SUCCESS;
 }
 
+
 NTSTATUS
 NTAPI
 KdpSysWriteIoSpace(IN ULONG InterfaceType,
                    IN ULONG BusNumber,
                    IN ULONG AddressSpace,
                    IN ULONG64 IoAddress,
-                   IN PULONG DataValue,
+                   IN PVOID DataValue,
                    IN ULONG DataSize,
                    OUT PULONG ActualDataSize)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
-    return STATUS_UNSUCCESSFUL;
+    /* Verify parameters */
+    if (InterfaceType != Isa || BusNumber != 0 || AddressSpace != 1)
+    {
+        /* No data was written */
+        *ActualDataSize = 0;
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    switch (DataSize)
+    {
+        case sizeof(UCHAR):
+            /* read one UCHAR */
+            WRITE_PORT_UCHAR((PUCHAR)IoAddress, *(PUCHAR)DataValue);
+            break;
+
+        case sizeof(USHORT):
+            /* Read one USHORT */
+            WRITE_PORT_USHORT((PUSHORT)IoAddress, *(PUSHORT)DataValue);
+            break;
+
+        case sizeof(ULONG):
+            /* Read one ULONG */
+            WRITE_PORT_ULONG((PULONG)IoAddress, *(PULONG)DataValue);
+            break;
+
+        default:
+            /* Invalid data size */
+             *ActualDataSize = 0;
+            return STATUS_UNSUCCESSFUL;
+    }
+
+    /* Return the size of the data */
+    *ActualDataSize = DataSize;
+
+    /* Success! */
+    return STATUS_SUCCESS;
 }
 
 NTSTATUS