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)
13 /******************************************************************************
15 * \brief Sends a buffer of data to the serial KD port.
16 * \param Buffer Pointer to the data.
17 * \param Size Size of data in bytes.
26 for (i
= 0; i
< Size
; i
++)
28 KdpSendByte(((PUCHAR
)Buffer
)[i
]);
32 /******************************************************************************
33 * \name KdpReceiveBuffer
34 * \brief Recieves data from the KD port and fills a buffer.
35 * \param Buffer Pointer to a buffer that receives the data.
36 * \param Size Size of data to receive in bytes.
37 * \return KDP_PACKET_RECEIVED if successful.
38 * KDP_PACKET_TIMEOUT if the receice timed out.
47 PUCHAR ByteBuffer
= Buffer
;
50 for (i
= 0; i
< Size
; i
++)
52 /* Try to get a byte from the port */
53 Status
= KdpReceiveByte(&ByteBuffer
[i
]);
55 if (Status
!= KDP_PACKET_RECEIVED
)
61 return KDP_PACKET_RECEIVED
;
65 /******************************************************************************
66 * \name KdpReceivePacketLeader
67 * \brief Recieves a packet leadr from the KD port.
68 * \param PacketLeader Pointer to an ULONG that receives the packet leader.
69 * \return KDP_PACKET_RECEIVED if successful.
70 * KDP_PACKET_TIMEOUT if the receive timed out.
71 * KDP_PACKET_RESEND if a breakin byte was detected.
75 KdpReceivePacketLeader(
76 OUT PULONG PacketLeader
)
78 UCHAR Index
= 0, Byte
, Buffer
[4];
81 /* Set first character to 0 */
86 /* Receive a single byte */
87 KdStatus
= KdpReceiveByte(&Byte
);
89 /* Check for timeout */
90 if (KdStatus
== KDP_PACKET_TIMEOUT
)
92 /* Check if we already got a breakin byte */
93 if (Buffer
[0] == BREAKIN_PACKET_BYTE
)
95 return KDP_PACKET_RESEND
;
99 return KDP_PACKET_TIMEOUT
;
102 /* Check if we received a byte */
103 if (KdStatus
== KDP_PACKET_RECEIVED
)
105 /* Check if this is a valid packet leader byte */
106 if (Byte
== PACKET_LEADER_BYTE
||
107 Byte
== CONTROL_PACKET_LEADER_BYTE
)
109 /* Check if we match the first byte */
110 if (Byte
!= Buffer
[0])
112 /* No, this is the new byte 0! */
116 /* Store the byte in the buffer */
117 Buffer
[Index
] = Byte
;
119 /* Continue with next byte */
124 /* Check for breakin byte */
125 if (Byte
== BREAKIN_PACKET_BYTE
)
127 KDDBGPRINT("BREAKIN_PACKET_BYTE\n");
140 /* Enable the debugger */
141 KdDebuggerNotPresent
= FALSE
;
142 SharedUserData
->KdDebuggerEnabled
|= 0x00000002;
144 /* Return the received packet leader */
145 *PacketLeader
= *(PULONG
)Buffer
;
147 return KDP_PACKET_RECEIVED
;