/****************************************************************************** * \name KdpSendBuffer * \brief Sends a buffer of data to the serial 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++) { KdpSendByte(((PUCHAR)Buffer)[i]); } }
/****************************************************************************** * \name KdpSendBuffer * \brief Sends a buffer of data to the serial KD port. * \param Buffer Pointer to the data. * \param Size Size of data in bytes. */ VOID NTAPI KdpSendBuffer( IN PVOID Buffer, IN ULONG Size) { PUCHAR ByteBuffer = Buffer; while (Size-- > 0) { KdpSendByte(*ByteBuffer++); } }
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext) { char* ByteBuffer = gdb_input; UCHAR Byte; KDSTATUS Status; CHAR CheckSum = 0, ReceivedCheckSum; do { Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) return Status; if (Byte == 0x03) { KdContext->KdpControlCPending = TRUE; return KdPacketNeedsResend; } } while (Byte != '$'); while (TRUE) { /* Try to get a byte from the port */ Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) return Status; if (Byte == '#') { *ByteBuffer = '\0'; break; } *ByteBuffer++ = Byte; CheckSum += (CHAR)Byte; } /* Get Check sum (two bytes) */ Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) goto end; ReceivedCheckSum = hex_value(Byte) << 4; Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) goto end; ReceivedCheckSum += hex_value(Byte); end: if (ReceivedCheckSum != CheckSum) { /* Do not acknowledge to GDB */ KdpSendByte('-'); return KdPacketNeedsResend; } /* Acknowledge */ KdpSendByte('+'); return KdPacketReceived; }
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext) { UCHAR* ByteBuffer = (UCHAR*)gdb_input; UCHAR Byte; KDSTATUS Status; CHAR CheckSum = 0, ReceivedCheckSum; do { Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) return Status; if (Byte == 0x03) { KDDBGPRINT("BREAK!"); KdContext->KdpControlCPending = TRUE; return KdPacketNeedsResend; } } while (Byte != '$'); while (TRUE) { /* Try to get a byte from the port */ Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) return Status; if (Byte == '#') { *ByteBuffer = '\0'; break; } CheckSum += (CHAR)Byte; /* See if we should escape */ if (Byte == 0x7d) { Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) return Status; CheckSum += (CHAR)Byte; Byte ^= 0x20; } *ByteBuffer++ = Byte; } /* Get Check sum (two bytes) */ Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) goto end; ReceivedCheckSum = hex_value(Byte) << 4; Status = KdpReceiveByte(&Byte); if (Status != KdPacketReceived) goto end; ReceivedCheckSum += hex_value(Byte); end: if (ReceivedCheckSum != CheckSum) { /* Do not acknowledge to GDB */ KDDBGPRINT("Check sums don't match!"); KdpSendByte('-'); return KdPacketNeedsResend; } /* Acknowledge */ KdpSendByte('+'); return KdPacketReceived; }