mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 07:13:23 +00:00
Sync kdcom from amd64 branch
svn path=/trunk/; revision=43801
This commit is contained in:
parent
0cf8717f6d
commit
4869ba0006
4 changed files with 77 additions and 62 deletions
|
@ -216,6 +216,11 @@ KdpSendByte(IN BYTE Byte)
|
||||||
/* Wait for the port to be ready */
|
/* Wait for the port to be ready */
|
||||||
while ((READ_PORT_UCHAR(ComPortBase + COM_LSR) & LSR_TBE) == 0);
|
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 */
|
/* Send the byte */
|
||||||
WRITE_PORT_UCHAR(ComPortBase + COM_DAT, Byte);
|
WRITE_PORT_UCHAR(ComPortBase + COM_DAT, Byte);
|
||||||
}
|
}
|
||||||
|
@ -224,6 +229,8 @@ KDP_STATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
KdpPollByte(OUT PBYTE OutByte)
|
KdpPollByte(OUT PBYTE OutByte)
|
||||||
{
|
{
|
||||||
|
READ_PORT_UCHAR(ComPortBase + COM_MSR); // Timing
|
||||||
|
|
||||||
/* Check if data is available */
|
/* Check if data is available */
|
||||||
if ((READ_PORT_UCHAR(ComPortBase + COM_LSR) & LSR_DR))
|
if ((READ_PORT_UCHAR(ComPortBase + COM_LSR) & LSR_DR))
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
PFNDBGPRNT KdpDbgPrint = NULL;
|
PFNDBGPRNT KdpDbgPrint = NULL;
|
||||||
ULONG CurrentPacketId = INITIAL_PACKET_ID | SYNC_PACKET_ID;
|
ULONG CurrentPacketId = INITIAL_PACKET_ID | SYNC_PACKET_ID;
|
||||||
|
ULONG RemotePacketId = 0;
|
||||||
|
|
||||||
|
|
||||||
/* PRIVATE FUNCTIONS **********************************************************/
|
/* PRIVATE FUNCTIONS **********************************************************/
|
||||||
|
@ -148,24 +149,31 @@ KdReceivePacket(
|
||||||
KdStatus = KdpReceiveBuffer(&Packet.PacketType, sizeof(USHORT));
|
KdStatus = KdpReceiveBuffer(&Packet.PacketType, sizeof(USHORT));
|
||||||
if (KdStatus != KDP_PACKET_RECEIVED)
|
if (KdStatus != KDP_PACKET_RECEIVED)
|
||||||
{
|
{
|
||||||
/* Didn't receive a PacketType or PacketType is bad. Start over. */
|
/* Didn't receive a PacketType. */
|
||||||
continue;
|
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 */
|
/* Step 3 - Read ByteCount */
|
||||||
KdStatus = KdpReceiveBuffer(&Packet.ByteCount, sizeof(USHORT));
|
KdStatus = KdpReceiveBuffer(&Packet.ByteCount, sizeof(USHORT));
|
||||||
if (KdStatus != KDP_PACKET_RECEIVED || Packet.ByteCount > PACKET_MAX_SIZE)
|
if (KdStatus != KDP_PACKET_RECEIVED)
|
||||||
{
|
{
|
||||||
/* Didn't receive ByteCount or it's too big. Start over. */
|
/* Didn't receive ByteCount. */
|
||||||
continue;
|
return KdStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 4 - Read PacketId */
|
/* Step 4 - Read PacketId */
|
||||||
KdStatus = KdpReceiveBuffer(&Packet.PacketId, sizeof(ULONG));
|
KdStatus = KdpReceiveBuffer(&Packet.PacketId, sizeof(ULONG));
|
||||||
if (KdStatus != KDP_PACKET_RECEIVED)
|
if (KdStatus != KDP_PACKET_RECEIVED)
|
||||||
{
|
{
|
||||||
/* Didn't receive PacketId. Start over. */
|
/* Didn't receive PacketId. */
|
||||||
continue;
|
return KdStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -180,8 +188,8 @@ KdReceivePacket(
|
||||||
KdStatus = KdpReceiveBuffer(&Packet.Checksum, sizeof(ULONG));
|
KdStatus = KdpReceiveBuffer(&Packet.Checksum, sizeof(ULONG));
|
||||||
if (KdStatus != KDP_PACKET_RECEIVED)
|
if (KdStatus != KDP_PACKET_RECEIVED)
|
||||||
{
|
{
|
||||||
/* Didn't receive Checksum. Start over. */
|
/* Didn't receive Checksum. */
|
||||||
continue;
|
return KdStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 6 - Handle control packets */
|
/* Step 6 - Handle control packets */
|
||||||
|
@ -205,6 +213,7 @@ KdReceivePacket(
|
||||||
KDDBGPRINT("KdReceivePacket - got a reset packet\n");
|
KDDBGPRINT("KdReceivePacket - got a reset packet\n");
|
||||||
KdpSendControlPacket(PACKET_TYPE_KD_RESET, 0);
|
KdpSendControlPacket(PACKET_TYPE_KD_RESET, 0);
|
||||||
CurrentPacketId = INITIAL_PACKET_ID;
|
CurrentPacketId = INITIAL_PACKET_ID;
|
||||||
|
RemotePacketId = INITIAL_PACKET_ID;
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
|
|
||||||
case PACKET_TYPE_KD_RESEND:
|
case PACKET_TYPE_KD_RESEND:
|
||||||
|
@ -227,43 +236,18 @@ KdReceivePacket(
|
||||||
return KDP_PACKET_RECEIVED;
|
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 */
|
/* Get size of the message header */
|
||||||
switch (Packet.PacketType)
|
MessageHeader->Length = MessageHeader->MaximumLength;
|
||||||
{
|
|
||||||
case PACKET_TYPE_KD_STATE_CHANGE64:
|
|
||||||
MessageHeader->Length = sizeof(DBGKD_WAIT_STATE_CHANGE64);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PACKET_TYPE_KD_STATE_MANIPULATE:
|
/* Packet smaller than expected or too big? */
|
||||||
MessageHeader->Length = sizeof(DBGKD_MANIPULATE_STATE64);
|
if (Packet.ByteCount < MessageHeader->Length ||
|
||||||
break;
|
Packet.ByteCount > PACKET_MAX_SIZE)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
KDDBGPRINT("KdReceivePacket - too few data (%d) for type %d\n",
|
KDDBGPRINT("KdReceivePacket - too few data (%d) for type %d\n",
|
||||||
Packet.ByteCount, MessageHeader->Length);
|
Packet.ByteCount, MessageHeader->Length);
|
||||||
MessageHeader->Length = Packet.ByteCount;
|
MessageHeader->Length = Packet.ByteCount;
|
||||||
|
KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//KDDBGPRINT("KdReceivePacket - got normal PacketType, Buffer = %p\n", MessageHeader->Buffer);
|
//KDDBGPRINT("KdReceivePacket - got normal PacketType, Buffer = %p\n", MessageHeader->Buffer);
|
||||||
|
@ -316,15 +300,6 @@ KdReceivePacket(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare checksum */
|
|
||||||
if (Packet.Checksum != Checksum)
|
|
||||||
{
|
|
||||||
KDDBGPRINT("KdReceivePacket - wrong cheksum, got %x, calculated %x\n",
|
|
||||||
Packet.Checksum, Checksum);
|
|
||||||
KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We must receive a PACKET_TRAILING_BYTE now */
|
/* We must receive a PACKET_TRAILING_BYTE now */
|
||||||
KdStatus = KdpReceiveBuffer(&Byte, sizeof(UCHAR));
|
KdStatus = KdpReceiveBuffer(&Byte, sizeof(UCHAR));
|
||||||
if (KdStatus != KDP_PACKET_RECEIVED || Byte != PACKET_TRAILING_BYTE)
|
if (KdStatus != KDP_PACKET_RECEIVED || Byte != PACKET_TRAILING_BYTE)
|
||||||
|
@ -334,12 +309,36 @@ KdReceivePacket(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compare checksum */
|
||||||
|
if (Packet.Checksum != Checksum)
|
||||||
|
{
|
||||||
|
KDDBGPRINT("KdReceivePacket - wrong cheksum, got %x, calculated %x\n",
|
||||||
|
Packet.Checksum, Checksum);
|
||||||
|
KdpSendControlPacket(PACKET_TYPE_KD_RESEND, 0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* Acknowledge the received packet */
|
/* Acknowledge the received packet */
|
||||||
KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE, Packet.PacketId);
|
KdpSendControlPacket(PACKET_TYPE_KD_ACKNOWLEDGE, Packet.PacketId);
|
||||||
|
|
||||||
//KDDBGPRINT("KdReceivePacket - all ok\n");
|
/* Check if the received PacketId is ok */
|
||||||
|
if (Packet.PacketId != RemotePacketId)
|
||||||
|
{
|
||||||
|
/* Continue with next packet */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return KDP_PACKET_RECEIVED;
|
/* 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;
|
return KDP_PACKET_RECEIVED;
|
||||||
|
@ -352,10 +351,11 @@ KdSendPacket(
|
||||||
IN ULONG PacketType,
|
IN ULONG PacketType,
|
||||||
IN PSTRING MessageHeader,
|
IN PSTRING MessageHeader,
|
||||||
IN PSTRING MessageData,
|
IN PSTRING MessageData,
|
||||||
IN OUT PKD_CONTEXT Context)
|
IN OUT PKD_CONTEXT KdContext)
|
||||||
{
|
{
|
||||||
KD_PACKET Packet;
|
KD_PACKET Packet;
|
||||||
KDP_STATUS KdStatus;
|
KDP_STATUS KdStatus;
|
||||||
|
ULONG Retries;
|
||||||
|
|
||||||
/* Initialize a KD_PACKET */
|
/* Initialize a KD_PACKET */
|
||||||
Packet.PacketLeader = PACKET_LEADER;
|
Packet.PacketLeader = PACKET_LEADER;
|
||||||
|
@ -372,7 +372,9 @@ KdSendPacket(
|
||||||
MessageData->Length);
|
MessageData->Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;)
|
Retries = KdContext->KdpDefaultRetries;
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
/* Set the packet id */
|
/* Set the packet id */
|
||||||
Packet.PacketId = CurrentPacketId;
|
Packet.PacketId = CurrentPacketId;
|
||||||
|
@ -394,10 +396,10 @@ KdSendPacket(
|
||||||
|
|
||||||
/* Wait for acknowledge */
|
/* Wait for acknowledge */
|
||||||
KdStatus = KdReceivePacket(PACKET_TYPE_KD_ACKNOWLEDGE,
|
KdStatus = KdReceivePacket(PACKET_TYPE_KD_ACKNOWLEDGE,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
NULL);
|
KdContext);
|
||||||
|
|
||||||
/* Did we succeed? */
|
/* Did we succeed? */
|
||||||
if (KdStatus == KDP_PACKET_RECEIVED)
|
if (KdStatus == KDP_PACKET_RECEIVED)
|
||||||
|
@ -413,9 +415,14 @@ KdSendPacket(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Packet timed out, send it again */
|
if (KdStatus == KDP_PACKET_TIMEOUT)
|
||||||
}
|
{
|
||||||
|
Retries--;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
/* Packet timed out, send it again */
|
||||||
|
KDDBGPRINT("KdSendPacket got KdStatus 0x%x\n", KdStatus);
|
||||||
|
}
|
||||||
|
while (Retries > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
<module name="kdserial" type="staticlibrary">
|
<module name="kdserial" type="staticlibrary">
|
||||||
<include base="kdserial">.</include>
|
<include base="kdserial">.</include>
|
||||||
|
<library>ntoskrnl</library>
|
||||||
<file>kdserial.c</file>
|
<file>kdserial.c</file>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ KdpReceivePacketLeader(
|
||||||
/* Check for breakin byte */
|
/* Check for breakin byte */
|
||||||
if (Byte == BREAKIN_PACKET_BYTE)
|
if (Byte == BREAKIN_PACKET_BYTE)
|
||||||
{
|
{
|
||||||
KdpDbgPrint("BREAKIN_PACKET_BYTE\n");
|
KDDBGPRINT("BREAKIN_PACKET_BYTE\n");
|
||||||
Index = 0;
|
Index = 0;
|
||||||
Buffer[0] = Byte;
|
Buffer[0] = Byte;
|
||||||
continue;
|
continue;
|
||||||
|
@ -138,7 +138,7 @@ KdpReceivePacketLeader(
|
||||||
while (Index < 4);
|
while (Index < 4);
|
||||||
|
|
||||||
/* Enable the debugger */
|
/* Enable the debugger */
|
||||||
// KdDebuggerNotPresent = FALSE;
|
KdDebuggerNotPresent = FALSE;
|
||||||
SharedUserData->KdDebuggerEnabled |= 0x00000002;
|
SharedUserData->KdDebuggerEnabled |= 0x00000002;
|
||||||
|
|
||||||
/* Return the received packet leader */
|
/* Return the received packet leader */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue