[KDCOM]
[reactos.git] / reactos / drivers / base / kdcom / i386 / kdbg.c
index f81bcc6..45a736d 100644 (file)
@@ -5,28 +5,29 @@
  * PURPOSE:         Serial i/o functions for the kernel debugger.
  * PROGRAMMER:      Alex Ionescu
  *                  HervĂ© Poussineau
- *                  Timo Kreuzer
  */
 
 /* INCLUDES *****************************************************************/
 
 #define NOEXTAPI
-#include <ntddk.h>
-#define NDEBUG
+#include <ntifs.h>
 #include <halfuncs.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <debug.h>
 #include "arc/arc.h"
 #include "windbgkd.h"
 #include <kddll.h>
 #include <ioaccess.h> /* port intrinsics */
+#include <cportlib/cportlib.h>
+
+#define NDEBUG
+#include <debug.h>
+
 
 typedef struct _KD_PORT_INFORMATION
 {
     ULONG ComPort;
     ULONG BaudRate;
-    ULONG_PTR BaseAddress;
+    ULONG BaseAddress;
 } KD_PORT_INFORMATION, *PKD_PORT_INFORMATION;
 
 BOOLEAN
@@ -54,24 +55,16 @@ KdPortPutByteEx(
     IN PKD_PORT_INFORMATION PortInformation,
     IN UCHAR ByteToSend);
 
-/* serial debug connection */
-#define DEFAULT_DEBUG_PORT      2 /* COM2 */
-#define DEFAULT_DEBUG_COM1_IRQ  4 /* COM1 IRQ */
-#define DEFAULT_DEBUG_COM2_IRQ  3 /* COM2 IRQ */
-#define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */
-
 #define DEFAULT_BAUD_RATE    19200
 
-#ifdef _M_IX86
-const ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
+#if defined(_M_IX86) || defined(_M_AMD64)
+const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
 #elif defined(_M_PPC)
-const ULONG BaseArray[2] = {0, 0x800003f8};
+const ULONG BaseArray[] = {0, 0x800003F8};
 #elif defined(_M_MIPS)
-const ULONG BaseArray[3] = {0, 0x80006000, 0x80007000};
+const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
 #elif defined(_M_ARM)
-const ULONG BaseArray[2] = {0, 0xF1012000};
-#elif defined(_M_AMD64)
-const ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
+const ULONG BaseArray[] = {0, 0xF1012000};
 #else
 #error Unknown architecture
 #endif
@@ -124,8 +117,6 @@ const ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
 
 /* GLOBAL VARIABLES *********************************************************/
 
-ULONG CurrentPacketId = INITIAL_PACKET_ID;
-
 /* STATIC VARIABLES *********************************************************/
 
 static KD_PORT_INFORMATION DefaultPort = { 0, 0, 0 };
@@ -133,85 +124,9 @@ static KD_PORT_INFORMATION DefaultPort = { 0, 0, 0 };
 /* The com port must only be initialized once! */
 static BOOLEAN PortInitialized = FALSE;
 
-ULONG KdpPort;
-ULONG KdpPortIrq;
-
-// HACK!!!
-typedef ULONG (*DBGRNT)(const char *Format, ...);
-DBGRNT FrLdrDbgPrint = 0;
-
-/* STATIC FUNCTIONS *********************************************************/
-
-static BOOLEAN
-KdpDoesComPortExist(
-    IN ULONG_PTR BaseAddress)
-{
-    BOOLEAN found;
-    UCHAR mcr;
-    UCHAR msr;
-
-    found = FALSE;
-
-    /* save Modem Control Register (MCR) */
-    mcr = READ_PORT_UCHAR(SER_MCR(BaseAddress));
-
-    /* enable loop mode (set Bit 4 of the MCR) */
-    WRITE_PORT_UCHAR(SER_MCR(BaseAddress), SR_MCR_LOOP);
-
-    /* clear all modem output bits */
-    WRITE_PORT_UCHAR(SER_MCR(BaseAddress), SR_MCR_LOOP);
-
-    /* read the Modem Status Register */
-    msr = READ_PORT_UCHAR(SER_MSR(BaseAddress));
-
-    /*
-     * the upper nibble of the MSR (modem output bits) must be
-     * equal to the lower nibble of the MCR (modem input bits)
-     */
-    if ((msr & 0xF0) == 0x00)
-    {
-        /* set all modem output bits */
-        WRITE_PORT_UCHAR(SER_MCR(BaseAddress), SR_MCR_DTR | SR_MCR_RTS | SR_MCR_OUT1 | SR_MCR_OUT2 | SR_MCR_LOOP);
-
-        /* read the Modem Status Register */
-        msr = READ_PORT_UCHAR(SER_MSR(BaseAddress));
-
-        /*
-         * the upper nibble of the MSR (modem output bits) must be
-         * equal to the lower nibble of the MCR (modem input bits)
-         */
-        if ((msr & 0xF0) == 0xF0)
-        {
-            /*
-             * setup a resonable state for the port:
-             * enable fifo and clear recieve/transmit buffers
-             */
-            WRITE_PORT_UCHAR(SER_FCR(BaseAddress),
-                            (SR_FCR_ENABLE_FIFO | SR_FCR_CLEAR_RCVR | SR_FCR_CLEAR_XMIT));
-            WRITE_PORT_UCHAR(SER_FCR(BaseAddress), 0);
-            READ_PORT_UCHAR(SER_RBR(BaseAddress));
-            WRITE_PORT_UCHAR(SER_IER(BaseAddress), 0);
-            found = TRUE;
-        }
-    }
-
-    /* restore MCR */
-    WRITE_PORT_UCHAR(SER_MCR(BaseAddress), mcr);
-
-    return found;
-}
-
 
 /* FUNCTIONS ****************************************************************/
 
-NTSTATUS
-DriverEntry(
-    IN PDRIVER_OBJECT  DriverObject,
-    IN PUNICODE_STRING  RegistryPath)
-{
-    return STATUS_SUCCESS;
-}
-
 /* HAL.KdPortInitialize */
 BOOLEAN
 NTAPI
@@ -229,14 +144,18 @@ KdPortInitialize(
 
         if (PortInformation->ComPort == 0)
         {
+            /*
+             * Start enumerating COM ports from the last one to the first one,
+             * and break when we find a valid port.
+             * If we reach the first element of the list, the invalid COM port,
+             * then it means that no valid port was found.
+             */
             for (i = sizeof(BaseArray) / sizeof(BaseArray[0]) - 1; i > 0; i--)
             {
-                if (KdpDoesComPortExist(BaseArray[i]))
+                if (CpDoesPortExist(UlongToPtr(BaseArray[i])))
                 {
-                    DefaultPort.BaseAddress = BaseArray[i];
-                    DefaultPort.ComPort = i;
-                    PortInformation->BaseAddress = DefaultPort.BaseAddress;
-                    PortInformation->ComPort = DefaultPort.ComPort;
+                    PortInformation->BaseAddress = DefaultPort.BaseAddress = BaseArray[i];
+                    PortInformation->ComPort     = DefaultPort.ComPort     = i;
                     break;
                 }
             }
@@ -263,7 +182,7 @@ KdPortInitialize(
 }
 
 
-/* HAL.KdPortInitializeEx */
+/* HAL.KdPortInitializeEx ; ReactOS-specific */
 BOOLEAN
 NTAPI
 KdPortInitializeEx(
@@ -271,7 +190,7 @@ KdPortInitializeEx(
     IN ULONG Unknown1,
     IN ULONG Unknown2)
 {
-    ULONG_PTR ComPortBase;
+    ULONG ComPortBase;
     CHAR buffer[80];
     ULONG divisor;
     UCHAR lcr;
@@ -284,19 +203,27 @@ KdPortInitializeEx(
     if (PortInformation->BaudRate == 0)
         PortInformation->BaudRate = DEFAULT_BAUD_RATE;
 
-    if (PortInformation->ComPort == 0)
-        return FALSE;
+    if (PortInformation->ComPort != 0)
+    {
+        if (!CpDoesPortExist(UlongToPtr(BaseArray[PortInformation->ComPort])))
+        {
+            sprintf(buffer,
+                    "\nKernel Debugger: Serial port not found!\n\n");
+            HalDisplayString(buffer);
+            return FALSE;
+        }
 
-    if (!KdpDoesComPortExist(BaseArray[PortInformation->ComPort]))
+        ComPortBase = BaseArray[PortInformation->ComPort];
+        PortInformation->BaseAddress = ComPortBase;
+    }
+    else
     {
-        sprintf(buffer,
-                "\nKernel Debugger: Serial port not found!\n\n");
-        HalDisplayString(buffer);
-        return FALSE;
+        ComPortBase = PortInformation->BaseAddress;
     }
 
-    ComPortBase = BaseArray[PortInformation->ComPort];
-    PortInformation->BaseAddress = ComPortBase;
+    if (ComPortBase == 0)
+        return FALSE;
+
 #ifndef NDEBUG
     sprintf(buffer,
             "\nSerial port COM%ld found at 0x%lx\n",
@@ -353,7 +280,7 @@ KdPortGetByte(
 }
 
 
-/* HAL.KdPortGetByteEx */
+/* HAL.KdPortGetByteEx ; ReactOS-specific */
 BOOLEAN
 NTAPI
 KdPortGetByteEx(
@@ -384,7 +311,7 @@ KdPortPollByte(
 }
 
 
-/* HAL.KdPortPollByteEx */
+/* HAL.KdPortPollByteEx ; ReactOS-specific */
 BOOLEAN
 NTAPI
 KdPortPollByteEx(
@@ -413,7 +340,7 @@ KdPortPutByte(
     KdPortPutByteEx(&DefaultPort, ByteToSend);
 }
 
-/* HAL.KdPortPutByteEx */
+/* HAL.KdPortPutByteEx ; ReactOS-specific */
 VOID
 NTAPI
 KdPortPutByteEx(
@@ -492,270 +419,25 @@ KdPortEnableInterrupts(VOID)
     return TRUE;
 }
 
-/* NEW INTERNAL FUNCTIONS ****************************************************/
-
-/******************************************************************************
- * \name KdpCalculateChecksum
- * \brief Calculates the checksum for the packet data.
- * \param Buffer Pointer to the packet data.
- * \param Length Length of data in bytes.
- * \return The calculated checksum.
- * \sa http://www.vista-xp.co.uk/forums/technical-reference-library/2540-basics-debugging.html
- */
-ULONG
-NTAPI
-KdpCalculateChecksum(
-    IN PVOID Buffer,
-    IN ULONG Length)
-{
-    ULONG i, Checksum = 0;
-
-    for (i = 0; i < Length; i++)
-    {
-        Checksum += ((PUCHAR)Buffer)[i];
-    }
-    return Checksum;
-}
-
-/******************************************************************************
- * \name KdpSendBuffer
- * \brief Sends a buffer of data to the KD port.
- * \param Buffer Pointer to the data.
- * \param Size Size of data in bytes.
- */
-VOID
-NTAPI
-KdpSendBuffer(
-    IN PVOID Buffer,
-    IN ULONG Size)
-{
-    INT i;
-    for (i = 0; i < Size; i++)
-    {
-        KdPortPutByteEx(&DefaultPort, ((PUCHAR)Buffer)[i]);
-    }
-}
-
-
-/******************************************************************************
- * \name KdpReceiveBuffer
- * \brief Recieves data from the KD port and fills a buffer.
- * \param Buffer Pointer to a buffer that receives the data.
- * \param Size Size of data to receive in bytes.
- * \return KdPacketReceived if successful. 
- *         KdPacketTimedOut if the receice timed out (10 seconds).
- * \todo Handle timeout.
- */
-KDSTATUS
-NTAPI
-KdpReceiveBuffer(
-    OUT PVOID Buffer,
-    IN  ULONG Size)
-{
-    ULONG i;
-    PUCHAR ByteBuffer = Buffer;
-    BOOLEAN Ret, TimeOut;
-
-    for (i = 0; i < Size; i++)
-    {
-        do
-        {
-            Ret = KdPortGetByteEx(&DefaultPort, &ByteBuffer[i]);
-            TimeOut = FALSE; // FIXME timeout after 10 Sec
-        }
-        while (!Ret || TimeOut);
-
-        if (TimeOut)
-        {
-            return KdPacketTimedOut;
-        }
-//        FrLdrDbgPrint("Received byte: %x\n", ByteBuffer[i]);
-    }
-
-    return KdPacketReceived;
-}
-
-KDSTATUS
-NTAPI
-KdpReceivePacketLeader(
-    OUT PULONG PacketLeader)
-{
-    UCHAR Byte, PrevByte;
-    ULONG i, Temp;
-    KDSTATUS RcvCode;
-
-    Temp = 0;
-    PrevByte = 0;
-    for (i = 0; i < 4; i++)
-    {
-        RcvCode = KdpReceiveBuffer(&Byte, sizeof(UCHAR));
-        Temp = (Temp << 8) | Byte;
-        if ( (RcvCode != KdPacketReceived) ||
-             ((Byte != PACKET_LEADER_BYTE) &&
-              (Byte != CONTROL_PACKET_LEADER_BYTE)) ||
-             (PrevByte != 0 && Byte != PrevByte) )
-        {
-            return KdPacketNeedsResend;
-        }
-        PrevByte = Byte;
-    }
-    
-    *PacketLeader = Temp;
-
-    return KdPacketReceived;
-}
-
-
-VOID
-NTAPI
-KdpSendControlPacket(
-    IN USHORT PacketType,
-    IN ULONG PacketId OPTIONAL)
-{
-    KD_PACKET Packet;
-
-    Packet.PacketLeader = CONTROL_PACKET_LEADER;
-    Packet.PacketId = PacketId;
-    Packet.ByteCount = 0;
-    Packet.Checksum = 0;
-    Packet.PacketType = PacketType;
-
-    KdpSendBuffer(&Packet, sizeof(KD_PACKET));
-}
-
-
-/* NEW PUBLIC FUNCTIONS ******************************************************/
-
-/******************************************************************************
- * \name KdDebuggerInitialize0
- * \brief Phase 0 initialization.
- * \param [opt] LoaderBlock Pointer to the Loader parameter block. Can be NULL.
- * \return Status
+/*
+ * @unimplemented
  */
 NTSTATUS
 NTAPI
 KdDebuggerInitialize0(
     IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
 {
-    ULONG Value;
-    PCHAR CommandLine, Port, BaudRate, Irq;
-
-    /* Apply default values */
-    KdpPortIrq = 0;
-    DefaultPort.ComPort = DEFAULT_DEBUG_PORT;
-    DefaultPort.BaudRate = DEFAULT_DEBUG_BAUD_RATE;
-
-    /* Check if e have a LoaderBlock */
-    if (LoaderBlock)
-    {
-        /* Get the Command Line */
-        CommandLine = LoaderBlock->LoadOptions;
-
-        /* Upcase it */
-        _strupr(CommandLine);
-
-        /* Get the port and baud rate */
-        Port = strstr(CommandLine, "DEBUGPORT");
-        BaudRate = strstr(CommandLine, "BAUDRATE");
-        Irq = strstr(CommandLine, "IRQ");
-
-        /* Check if we got the /DEBUGPORT parameter */
-        if (Port)
-        {
-            /* Move past the actual string, to reach the port*/
-            Port += strlen("DEBUGPORT");
-
-            /* Now get past any spaces and skip the equal sign */
-            while (*Port == ' ') Port++;
-            Port++;
-
-            /* Do we have a serial port? */
-            if (strncmp(Port, "COM", 3) != 0)
-            {
-                return STATUS_INVALID_PARAMETER;
-            }
-
-            /* Gheck for a valid Serial Port */
-            Port += 3;
-            Value = atol(Port);
-            if (Value > 4)
-            {
-                return STATUS_INVALID_PARAMETER;
-            }
-
-            /* Set the port to use */
-            DefaultPort.ComPort = Value;
-       }
-
-        /* Check if we got a baud rate */
-        if (BaudRate)
-        {
-            /* Move past the actual string, to reach the rate */
-            BaudRate += strlen("BAUDRATE");
-
-            /* Now get past any spaces */
-            while (*BaudRate == ' ') BaudRate++;
-
-            /* And make sure we have a rate */
-            if (*BaudRate)
-            {
-                /* Read and set it */
-                Value = atol(BaudRate + 1);
-                if (Value) DefaultPort.BaudRate = Value;
-            }
-        }
-
-        /* Check Serial Port Settings [IRQ] */
-        if (Irq)
-        {
-            /* Move past the actual string, to reach the rate */
-            Irq += strlen("IRQ");
-
-            /* Now get past any spaces */
-            while (*Irq == ' ') Irq++;
-
-            /* And make sure we have an IRQ */
-            if (*Irq)
-            {
-                /* Read and set it */
-                Value = atol(Irq + 1);
-                if (Value) KdpPortIrq = Value;
-            }
-        }
-    }
-
-    // HACK use com1 for FrLdrDbg, com2 for WinDbg
-    DefaultPort.ComPort = 2;
-
-    /* Get base address */
-    DefaultPort.BaseAddress = BaseArray[DefaultPort.ComPort];
-
-    /* Check if the COM port does exist */
-    if (!KdpDoesComPortExist(DefaultPort.BaseAddress))
-    {
-        return STATUS_INVALID_PARAMETER;
-    }
-
-    /* Initialize the port */
-    KdPortInitializeEx(&DefaultPort, 0, 0);
-    PortInitialized = TRUE;
-
-    return STATUS_SUCCESS;
+    return STATUS_NOT_IMPLEMENTED;
 }
 
-/******************************************************************************
- * \name KdDebuggerInitialize1
- * \brief Phase 1 initialization.
- * \param [opt] LoaderBlock Pointer to the Loader parameter block. Can be NULL.
- * \return Status
+/*
+ * @unimplemented
  */
 NTSTATUS
 NTAPI
 KdDebuggerInitialize1(
     IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
 {
-    // HACK: misuse this function to get a pointer to FrLdrDbgPrint
-    FrLdrDbgPrint = (PVOID)LoaderBlock;
     return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -794,86 +476,12 @@ KdSendPacket(
     IN PSTRING MessageData,
     IN OUT PKD_CONTEXT Context)
 {
-    KD_PACKET Packet;
-    KDSTATUS RcvCode;
-
-    for (;;)
-    {
-        /* Initialize a KD_PACKET */
-        Packet.PacketLeader = PACKET_LEADER;
-        Packet.PacketType = PacketType;
-        Packet.ByteCount = MessageHeader->Length;
-        Packet.Checksum = KdpCalculateChecksum(MessageHeader->Buffer,
-                                               MessageHeader->Length);
-
-        /* If we have message data, add it to the packet */
-        if (MessageData)
-        {
-            Packet.ByteCount += MessageData->Length;
-            Packet.Checksum += KdpCalculateChecksum(MessageData->Buffer,
-                                                    MessageData->Length);
-        }
-
-        /* Set the packet id */
-        Packet.PacketId = CurrentPacketId;
-
-        /* Send the packet header to the KD port */
-        KdpSendBuffer(&Packet, sizeof(KD_PACKET));
-
-        /* Send the message header */
-        KdpSendBuffer(MessageHeader->Buffer, MessageHeader->Length);
-
-        /* If we have meesage data, also send it */
-        if (MessageData)
-        {
-            KdpSendBuffer(MessageData->Buffer, MessageData->Length);
-        }
-
-        /* Finalize with a trailing byte */
-        KdPortPutByte(PACKET_TRAILING_BYTE);
-
-        /* Wait for acknowledge */
-        RcvCode = KdReceivePacket(PACKET_TYPE_KD_ACKNOWLEDGE,
-                                  NULL,
-                                  NULL,
-                                  0,
-                                  NULL);
-
-        /* Did we succeed? */
-        if (RcvCode == KdPacketReceived)
-        {
-            CurrentPacketId &= ~SYNC_PACKET_ID;
-            break;
-        }
-
-        /* PACKET_TYPE_KD_DEBUG_IO is allowed to instantly timeout */
-        if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
-        {
-            /* No response, silently fail. */
-//            return;
-        }
-
-        /* Packet timed out, send it again */
-    }
-
+    UNIMPLEMENTED;
     return;
 }
 
-
-/******************************************************************************
- * \name KdReceivePacket
- * \brief Receive a packet from the KD port.
- * \param [in] PacketType Describes the type of the packet to receive.
- *        This can be one of the PACKET_TYPE_ constants.
- * \param [out] MessageHeader Pointer to a STRING structure for the header.
- * \param [out] MessageData Pointer to a STRING structure for the data.
- * \return KdPacketReceived if successful, KdPacketTimedOut if the receive
- *         timed out, KdPacketNeedsResend to signal that the last packet needs
- *         to be sent again.
- * \note If PacketType is PACKET_TYPE_KD_POLL_BREAKIN, the function doesn't
- *       wait for any data, but returns KdPacketTimedOut instantly if no breakin
- *       packet byte is received.
- * \sa http://www.nynaeve.net/?p=169
+/*
+ * @unimplemented
  */
 KDSTATUS
 NTAPI
@@ -884,215 +492,8 @@ KdReceivePacket(
     OUT PULONG DataLength,
     IN OUT PKD_CONTEXT Context)
 {
-    UCHAR Byte = 0;
-    KDSTATUS RcvCode;
-    KD_PACKET Packet;
-    ULONG Checksum;
-
-    /* Special handling for breakin packet */
-    if(PacketType == PACKET_TYPE_KD_POLL_BREAKIN)
-    {
-        if (KdPortGetByteEx(&DefaultPort, &Byte))
-        {
-            if (Byte == BREAKIN_PACKET_BYTE)
-            {
-                return KdPacketReceived;
-            }
-        }
-        return KdPacketTimedOut;
-    }
-
-    for (;;)
-    {
-        /* Step 1 - Read PacketLeader */
-        RcvCode = KdpReceivePacketLeader(&Packet.PacketLeader);
-        if (RcvCode != KdPacketReceived)
-        {
-            /* Couldn't read a correct packet leader. Start over. */
-            continue;
-        }
-
-        /* Step 2 - Read PacketType */
-        RcvCode = KdpReceiveBuffer(&Packet.PacketType, sizeof(USHORT));
-        if (RcvCode != KdPacketReceived)
-        {
-            /* Didn't receive a PacketType or PacketType is bad. Start over. */
-            continue;
-        }
-
-        /* Step 3 - Read ByteCount */
-        RcvCode = KdpReceiveBuffer(&Packet.ByteCount, sizeof(USHORT));
-        if (RcvCode != KdPacketReceived || Packet.ByteCount > PACKET_MAX_SIZE)
-        {
-            /* Didn't receive ByteCount or it's too big. Start over. */
-            continue;
-        }
-
-        /* Step 4 - Read PacketId */
-        RcvCode = KdpReceiveBuffer(&Packet.PacketId, sizeof(ULONG));
-        if (RcvCode != KdPacketReceived)
-        {
-            /* Didn't receive PacketId. Start over. */
-            continue;
-        }
-
-/*
-        if (Packet.PacketId != ExpectedPacketId)
-        {
-            // Ask for a resend!
-            continue;
-        }
-*/
-
-        /* Step 5 - Read Checksum */
-        RcvCode = KdpReceiveBuffer(&Packet.Checksum, sizeof(ULONG));
-        if (RcvCode != KdPacketReceived)
-        {
-            /* Didn't receive Checksum. Start over. */
-            continue;
-        }
-
-        /* Step 6 - Handle control packets */
-        if (Packet.PacketLeader == CONTROL_PACKET_LEADER)
-        {
-            switch (Packet.PacketType)
-            {
-                case PACKET_TYPE_KD_ACKNOWLEDGE:
-                    if (PacketType == PACKET_TYPE_KD_ACKNOWLEDGE)
-                    {
-                        /* Remote acknowledges the last packet */
-                        CurrentPacketId ^= 1;
-                        return KdPacketReceived;
-                    }
-                    /* That's not what we were waiting for, start over. */
-                    continue;
-
-                case PACKET_TYPE_KD_RESET:
-                    FrLdrDbgPrint("KdReceivePacket - got a reset packet\n");
-                    KdpSendControlPacket(PACKET_TYPE_KD_RESET, 0);
-                    CurrentPacketId = INITIAL_PACKET_ID;
-                    /* Fall through */
-
-                case PACKET_TYPE_KD_RESEND:
-                    /* Remote wants us to resend the last packet */
-                    return KdPacketNeedsResend;
-
-                default:
-                    FrLdrDbgPrint("KdReceivePacket - got unknown control packet\n");
-                    return KdPacketNeedsResend;
-            }
-        }
-
-        /* Did we wait for an ack packet? */
-        if (PacketType == PACKET_TYPE_KD_ACKNOWLEDGE)
-        {
-            /* We received something different, start over */
-            continue;
-        }
-
-        /* Did we get the right packet type? */
-        if (PacketType != Packet.PacketType)
-        {
-            /* We received something different, start over */
-            continue;
-        }
-
-        /* Get size of the message header */
-        switch (Packet.PacketType)
-        {
-            case PACKET_TYPE_KD_STATE_CHANGE64:
-                MessageHeader->Length = sizeof(DBGKD_WAIT_STATE_CHANGE64);
-                break;
-
-            case PACKET_TYPE_KD_STATE_MANIPULATE:
-                MessageHeader->Length = sizeof(DBGKD_MANIPULATE_STATE64);
-                break;
-
-            case PACKET_TYPE_KD_DEBUG_IO:
-                MessageHeader->Length = sizeof(DBGKD_DEBUG_IO);
-                break;
-
-            default:
-                FrLdrDbgPrint("KdReceivePacket - unknown PacketType\n");
-                return KdPacketNeedsResend;
-        }
-
-//FrLdrDbgPrint("KdReceivePacket - got normal PacketType\n");
-
-        /* Packet smaller than expected? */
-        if (MessageHeader->Length > Packet.ByteCount)
-        {
-            FrLdrDbgPrint("KdReceivePacket - too few data (%d) for type %d\n",
-                          Packet.ByteCount, MessageHeader->Length);
-            MessageHeader->Length = Packet.ByteCount;
-        }
-
-//FrLdrDbgPrint("KdReceivePacket - got normal PacketType, Buffer = %p\n", MessageHeader->Buffer);
-
-        /* Receive the message header data */
-        RcvCode = KdpReceiveBuffer(MessageHeader->Buffer,
-                                   MessageHeader->Length);
-        if (RcvCode != KdPacketReceived)
-        {
-            /* Didn't receive data. Start over. */
-            FrLdrDbgPrint("KdReceivePacket - Didn't receive message header data. Start over\n");
-            continue;
-        }
-
-//FrLdrDbgPrint("KdReceivePacket - got normal PacketType 3\n");
-
-        /* Calculate checksum for the header data */
-        Checksum = KdpCalculateChecksum(MessageHeader->Buffer,
-                                        MessageHeader->Length);
-
-        /* Shall we receive messsage data? */
-        if (MessageData)
-        {
-            /* Calculate the length of the message data */
-            MessageData->Length = Packet.ByteCount - MessageHeader->Length;
-
-            /* Do we have data? */
-            if (MessageData->Length)
-            {
-                FrLdrDbgPrint("KdReceivePacket - got data\n");
-
-                /* Receive the message data */
-                RcvCode = KdpReceiveBuffer(MessageData->Buffer,
-                                           MessageData->Length);
-                if (RcvCode != KdPacketReceived)
-                {
-                    /* Didn't receive data. Start over. */
-                    FrLdrDbgPrint("KdReceivePacket - Didn't receive message data. Start over\n");
-                    continue;
-                }
-
-                /* Add cheksum for message data */
-                Checksum += KdpCalculateChecksum(MessageData->Buffer,
-                                                 MessageData->Length);
-            }
-        }
-
-        /* Compare checksum */
-        if (Packet.Checksum != Checksum)
-        {
-            KdpSendControlPacket(PACKET_TYPE_KD_RESEND, CurrentPacketId);
-            FrLdrDbgPrint("KdReceivePacket - wrong cheksum, got %x, calculated %x\n",
-                          Packet.Checksum, Checksum);
-            continue;
-        }
-
-        /* We must receive a PACKET_TRAILING_BYTE now */
-        RcvCode = KdpReceiveBuffer(&Byte, sizeof(UCHAR));
-
-        /* Acknowledge the received packet */
-        KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE, Packet.PacketId);
-
-//FrLdrDbgPrint("KdReceivePacket - all ok\n");
-
-        return KdPacketReceived;
-    }
-
-    return KdPacketReceived;
+    UNIMPLEMENTED;
+    return 0;
 }
 
 /* EOF */