2 * COPYRIGHT: GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/base/kddll/kdserial.c
5 * PURPOSE: Serial communication functions for the kernel debugger.
6 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@ewactos.org)
14 /* FUNCTIONS ******************************************************************/
16 /******************************************************************************
18 * \brief Sends a buffer of data to the serial KD port.
19 * \param Buffer Pointer to the data.
20 * \param Size Size of data in bytes.
28 PUCHAR ByteBuffer
= Buffer
;
32 KdpSendByte(*ByteBuffer
++);
36 /******************************************************************************
37 * \name KdpReceiveBuffer
38 * \brief Receives data from the KD port and fills a buffer.
39 * \param Buffer Pointer to a buffer that receives the data.
40 * \param Size Size of data to receive in bytes.
41 * \return KDP_PACKET_RECEIVED if successful.
42 * KDP_PACKET_TIMEOUT if the receice timed out.
50 PUCHAR ByteBuffer
= Buffer
;
56 /* Try to get a byte from the port */
57 Status
= KdpReceiveByte(&Byte
);
58 if (Status
!= KDP_PACKET_RECEIVED
)
64 return KDP_PACKET_RECEIVED
;
68 /******************************************************************************
69 * \name KdpReceivePacketLeader
70 * \brief Receives a packet leadr from the KD port.
71 * \param PacketLeader Pointer to an ULONG that receives the packet leader.
72 * \return KDP_PACKET_RECEIVED if successful.
73 * KDP_PACKET_TIMEOUT if the receive timed out.
74 * KDP_PACKET_RESEND if a breakin byte was detected.
78 KdpReceivePacketLeader(
79 OUT PULONG PacketLeader
)
81 UCHAR Index
= 0, Byte
, Buffer
[4];
84 /* Set first character to 0 */
89 /* Receive a single byte */
90 KdStatus
= KdpReceiveByte(&Byte
);
92 /* Check for timeout */
93 if (KdStatus
== KDP_PACKET_TIMEOUT
)
95 /* Check if we already got a breakin byte */
96 if (Buffer
[0] == BREAKIN_PACKET_BYTE
)
98 return KDP_PACKET_RESEND
;
102 return KDP_PACKET_TIMEOUT
;
105 /* Check if we received a byte */
106 if (KdStatus
== KDP_PACKET_RECEIVED
)
108 /* Check if this is a valid packet leader byte */
109 if (Byte
== PACKET_LEADER_BYTE
||
110 Byte
== CONTROL_PACKET_LEADER_BYTE
)
112 /* Check if we match the first byte */
113 if (Byte
!= Buffer
[0])
115 /* No, this is the new byte 0! */
119 /* Store the byte in the buffer */
120 Buffer
[Index
] = Byte
;
122 /* Continue with next byte */
127 /* Check for breakin byte */
128 if (Byte
== BREAKIN_PACKET_BYTE
)
130 KDDBGPRINT("BREAKIN_PACKET_BYTE\n");
143 /* Enable the debugger */
144 KdDebuggerNotPresent
= FALSE
;
145 SharedUserData
->KdDebuggerEnabled
|= 0x00000002;
147 /* Return the received packet leader */
148 *PacketLeader
= *(PULONG
)Buffer
;
150 return KDP_PACKET_RECEIVED
;