Author: tkreuzer Date: Wed Oct 28 00:38:56 2009 New Revision: 43801
URL: http://svn.reactos.org/svn/reactos?rev=43801&view=rev Log: Sync kdcom from amd64 branch
Modified: trunk/reactos/drivers/base/kddll/kdcom.c trunk/reactos/drivers/base/kddll/kddll.c trunk/reactos/drivers/base/kddll/kddll.rbuild trunk/reactos/drivers/base/kddll/kdserial.c
Modified: trunk/reactos/drivers/base/kddll/kdcom.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kdcom.c?... ============================================================================== --- trunk/reactos/drivers/base/kddll/kdcom.c [iso-8859-1] (original) +++ trunk/reactos/drivers/base/kddll/kdcom.c [iso-8859-1] Wed Oct 28 00:38:56 2009 @@ -216,6 +216,11 @@ /* Wait for the port to be ready */ while ((READ_PORT_UCHAR(ComPortBase + COM_LSR) & LSR_TBE) == 0);
+ /* This is needed due to subtle timing issues */ + READ_PORT_UCHAR(ComPortBase + COM_MSR); + while ((READ_PORT_UCHAR(ComPortBase + COM_LSR) & LSR_TBE) == 0); + READ_PORT_UCHAR(ComPortBase + COM_MSR); + /* Send the byte */ WRITE_PORT_UCHAR(ComPortBase + COM_DAT, Byte); } @@ -224,6 +229,8 @@ NTAPI KdpPollByte(OUT PBYTE OutByte) { + READ_PORT_UCHAR(ComPortBase + COM_MSR); // Timing + /* Check if data is available */ if ((READ_PORT_UCHAR(ComPortBase + COM_LSR) & LSR_DR)) {
Modified: trunk/reactos/drivers/base/kddll/kddll.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kddll.c?... ============================================================================== --- trunk/reactos/drivers/base/kddll/kddll.c [iso-8859-1] (original) +++ trunk/reactos/drivers/base/kddll/kddll.c [iso-8859-1] Wed Oct 28 00:38:56 2009 @@ -13,6 +13,7 @@
PFNDBGPRNT KdpDbgPrint = NULL; ULONG CurrentPacketId = INITIAL_PACKET_ID | SYNC_PACKET_ID; +ULONG RemotePacketId = 0;
/* PRIVATE FUNCTIONS **********************************************************/ @@ -148,24 +149,31 @@ KdStatus = KdpReceiveBuffer(&Packet.PacketType, sizeof(USHORT)); if (KdStatus != KDP_PACKET_RECEIVED) { - /* Didn't receive a PacketType or PacketType is bad. Start over. */ - continue; + /* Didn't receive a PacketType. */ + return KdStatus; + } + + /* Check if we got a resend packet */ + if (Packet.PacketLeader == CONTROL_PACKET_LEADER && + Packet.PacketType == PACKET_TYPE_KD_RESEND) + { + return KDP_PACKET_RESEND; }
/* Step 3 - Read ByteCount */ KdStatus = KdpReceiveBuffer(&Packet.ByteCount, sizeof(USHORT)); - if (KdStatus != KDP_PACKET_RECEIVED || Packet.ByteCount > PACKET_MAX_SIZE) - { - /* Didn't receive ByteCount or it's too big. Start over. */ - continue; + if (KdStatus != KDP_PACKET_RECEIVED) + { + /* Didn't receive ByteCount. */ + return KdStatus; }
/* Step 4 - Read PacketId */ KdStatus = KdpReceiveBuffer(&Packet.PacketId, sizeof(ULONG)); if (KdStatus != KDP_PACKET_RECEIVED) { - /* Didn't receive PacketId. Start over. */ - continue; + /* Didn't receive PacketId. */ + return KdStatus; }
/* @@ -180,8 +188,8 @@ KdStatus = KdpReceiveBuffer(&Packet.Checksum, sizeof(ULONG)); if (KdStatus != KDP_PACKET_RECEIVED) { - /* Didn't receive Checksum. Start over. */ - continue; + /* Didn't receive Checksum. */ + return KdStatus; }
/* Step 6 - Handle control packets */ @@ -205,6 +213,7 @@ KDDBGPRINT("KdReceivePacket - got a reset packet\n"); KdpSendControlPacket(PACKET_TYPE_KD_RESET, 0); CurrentPacketId = INITIAL_PACKET_ID; + RemotePacketId = INITIAL_PACKET_ID; /* Fall through */
case PACKET_TYPE_KD_RESEND: @@ -227,43 +236,18 @@ return KDP_PACKET_RECEIVED; }
- /* Did we get the right packet type? */ - if (PacketType != Packet.PacketType) - { - /* We received something different, start over */ - KDDBGPRINT("KdReceivePacket - wrong PacketType\n"); - KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0); - 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: - KDDBGPRINT("KdReceivePacket - unknown PacketType\n"); - return KDP_PACKET_RESEND; - } - - //KDDBGPRINT("KdReceivePacket - got normal PacketType\n"); - - /* Packet smaller than expected? */ - if (MessageHeader->Length > Packet.ByteCount) + MessageHeader->Length = MessageHeader->MaximumLength; + + /* Packet smaller than expected or too big? */ + if (Packet.ByteCount < MessageHeader->Length || + Packet.ByteCount > PACKET_MAX_SIZE) { KDDBGPRINT("KdReceivePacket - too few data (%d) for type %d\n", Packet.ByteCount, MessageHeader->Length); MessageHeader->Length = Packet.ByteCount; + KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0); + continue; }
//KDDBGPRINT("KdReceivePacket - got normal PacketType, Buffer = %p\n", MessageHeader->Buffer); @@ -316,6 +300,15 @@ } }
+ /* We must receive a PACKET_TRAILING_BYTE now */ + KdStatus = KdpReceiveBuffer(&Byte, sizeof(UCHAR)); + if (KdStatus != KDP_PACKET_RECEIVED || Byte != PACKET_TRAILING_BYTE) + { + KDDBGPRINT("KdReceivePacket - wrong trailing byte (0x%x), status 0x%x\n", Byte, KdStatus); + KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0); + continue; + } + /* Compare checksum */ if (Packet.Checksum != Checksum) { @@ -325,21 +318,27 @@ continue; }
- /* We must receive a PACKET_TRAILING_BYTE now */ - KdStatus = KdpReceiveBuffer(&Byte, sizeof(UCHAR)); - if (KdStatus != KDP_PACKET_RECEIVED || Byte != PACKET_TRAILING_BYTE) - { - KDDBGPRINT("KdReceivePacket - wrong trailing byte (0x%x), status 0x%x\n", Byte, KdStatus); - KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0); - continue; - } - /* Acknowledge the received packet */ KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE, Packet.PacketId);
- //KDDBGPRINT("KdReceivePacket - all ok\n"); - - return KDP_PACKET_RECEIVED; + /* Check if the received PacketId is ok */ + if (Packet.PacketId != RemotePacketId) + { + /* Continue with next packet */ + continue; + } + + /* Did we get the right packet type? */ + if (PacketType == Packet.PacketType) + { + /* Yes, return success */ + //KDDBGPRINT("KdReceivePacket - all ok\n"); + RemotePacketId ^= 1; + return KDP_PACKET_RECEIVED; + } + + /* We received something different, ignore it. */ + KDDBGPRINT("KdReceivePacket - wrong PacketType\n"); }
return KDP_PACKET_RECEIVED; @@ -352,10 +351,11 @@ IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, - IN OUT PKD_CONTEXT Context) + IN OUT PKD_CONTEXT KdContext) { KD_PACKET Packet; KDP_STATUS KdStatus; + ULONG Retries;
/* Initialize a KD_PACKET */ Packet.PacketLeader = PACKET_LEADER; @@ -372,7 +372,9 @@ MessageData->Length); }
- for (;;) + Retries = KdContext->KdpDefaultRetries; + + do { /* Set the packet id */ Packet.PacketId = CurrentPacketId; @@ -394,10 +396,10 @@
/* Wait for acknowledge */ KdStatus = KdReceivePacket(PACKET_TYPE_KD_ACKNOWLEDGE, - NULL, - NULL, - 0, - NULL); + NULL, + NULL, + 0, + KdContext);
/* Did we succeed? */ if (KdStatus == KDP_PACKET_RECEIVED) @@ -413,9 +415,14 @@ return; }
+ if (KdStatus == KDP_PACKET_TIMEOUT) + { + Retries--; + } + /* Packet timed out, send it again */ + KDDBGPRINT("KdSendPacket got KdStatus 0x%x\n", KdStatus); } - - return; -} - + while (Retries > 0); +} +
Modified: trunk/reactos/drivers/base/kddll/kddll.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kddll.rb... ============================================================================== --- trunk/reactos/drivers/base/kddll/kddll.rbuild [iso-8859-1] (original) +++ trunk/reactos/drivers/base/kddll/kddll.rbuild [iso-8859-1] Wed Oct 28 00:38:56 2009 @@ -10,6 +10,7 @@
<module name="kdserial" type="staticlibrary"> <include base="kdserial">.</include> + <library>ntoskrnl</library> <file>kdserial.c</file> </module>
Modified: trunk/reactos/drivers/base/kddll/kdserial.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kdserial... ============================================================================== --- trunk/reactos/drivers/base/kddll/kdserial.c [iso-8859-1] (original) +++ trunk/reactos/drivers/base/kddll/kdserial.c [iso-8859-1] Wed Oct 28 00:38:56 2009 @@ -124,7 +124,7 @@ /* Check for breakin byte */ if (Byte == BREAKIN_PACKET_BYTE) { - KdpDbgPrint("BREAKIN_PACKET_BYTE\n"); + KDDBGPRINT("BREAKIN_PACKET_BYTE\n"); Index = 0; Buffer[0] = Byte; continue; @@ -138,7 +138,7 @@ while (Index < 4);
/* Enable the debugger */ -// KdDebuggerNotPresent = FALSE; + KdDebuggerNotPresent = FALSE; SharedUserData->KdDebuggerEnabled |= 0x00000002;
/* Return the received packet leader */