ReactOS  0.4.15-dev-509-g96a357b
kdserial.c File Reference
#include "kddll.h"
Include dependency graph for kdserial.c:

Go to the source code of this file.

Functions

VOID NTAPI KdpSendBuffer (IN PVOID Buffer, IN ULONG Size)
 
KDP_STATUS NTAPI KdpReceiveBuffer (OUT PVOID Buffer, IN ULONG Size)
 
KDP_STATUS NTAPI KdpReceivePacketLeader (OUT PULONG PacketLeader)
 

Function Documentation

◆ KdpReceiveBuffer()

KDP_STATUS NTAPI KdpReceiveBuffer ( OUT PVOID  Buffer,
IN ULONG  Size 
)

Definition at line 43 of file kdserial.c.

46 {
47  PUCHAR ByteBuffer = Buffer;
48  UCHAR Byte;
50 
51  while (Size-- > 0)
52  {
53  /* Try to get a byte from the port */
56  return Status;
57 
58  *ByteBuffer++ = Byte;
59  }
60 
61  return KDP_PACKET_RECEIVED;
62 }
unsigned char Byte
Definition: zconf.h:391
KDP_STATUS
Definition: kddll.h:25
unsigned char * PUCHAR
Definition: retypes.h:3
KDP_STATUS NTAPI KdpReceiveByte(OUT PUCHAR OutByte)
Definition: kdcom.c:321
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Status
Definition: gdiplustypes.h:24
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by KdReceivePacket().

◆ KdpReceivePacketLeader()

KDP_STATUS NTAPI KdpReceivePacketLeader ( OUT PULONG  PacketLeader)

Definition at line 75 of file kdserial.c.

77 {
78  UCHAR Index = 0, Byte, Buffer[4];
79  KDP_STATUS KdStatus;
80 
81  /* Set first character to 0 */
82  Buffer[0] = 0;
83 
84  do
85  {
86  /* Receive a single byte */
87  KdStatus = KdpReceiveByte(&Byte);
88 
89  /* Check for timeout */
90  if (KdStatus == KDP_PACKET_TIMEOUT)
91  {
92  /* Check if we already got a breakin byte */
93  if (Buffer[0] == BREAKIN_PACKET_BYTE)
94  {
95  return KDP_PACKET_RESEND;
96  }
97 
98  /* Report timeout */
99  return KDP_PACKET_TIMEOUT;
100  }
101 
102  /* Check if we received a byte */
103  if (KdStatus == KDP_PACKET_RECEIVED)
104  {
105  /* Check if this is a valid packet leader byte */
106  if (Byte == PACKET_LEADER_BYTE ||
108  {
109  /* Check if we match the first byte */
110  if (Byte != Buffer[0])
111  {
112  /* No, this is the new byte 0! */
113  Index = 0;
114  }
115 
116  /* Store the byte in the buffer */
117  Buffer[Index] = Byte;
118 
119  /* Continue with next byte */
120  Index++;
121  continue;
122  }
123 
124  /* Check for breakin byte */
125  if (Byte == BREAKIN_PACKET_BYTE)
126  {
127  KDDBGPRINT("BREAKIN_PACKET_BYTE\n");
128  Index = 0;
129  Buffer[0] = Byte;
130  continue;
131  }
132  }
133 
134  /* Restart */
135  Index = 0;
136  Buffer[0] = 0;
137  }
138  while (Index < 4);
139 
140  /* Enable the debugger */
142  SharedUserData->KdDebuggerEnabled |= 0x00000002;
143 
144  /* Return the received packet leader */
145  *PacketLeader = *(PULONG)Buffer;
146 
147  return KDP_PACKET_RECEIVED;
148 }
#define KDDBGPRINT(...)
Definition: kddll.h:19
unsigned char Byte
Definition: zconf.h:391
KDP_STATUS
Definition: kddll.h:25
KDP_STATUS NTAPI KdpReceiveByte(OUT PUCHAR OutByte)
Definition: kdcom.c:321
#define KD_DEBUGGER_NOT_PRESENT
Definition: kdfuncs.h:133
#define CONTROL_PACKET_LEADER_BYTE
Definition: windbgkd.h:35
Definition: bufpool.h:45
static const UCHAR Index[8]
Definition: usbohci.c:18
#define BREAKIN_PACKET_BYTE
Definition: windbgkd.h:31
#define SharedUserData
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned int * PULONG
Definition: retypes.h:1
#define PACKET_LEADER_BYTE
Definition: windbgkd.h:33

Referenced by KdReceivePacket().

◆ KdpSendBuffer()

VOID NTAPI KdpSendBuffer ( IN PVOID  Buffer,
IN ULONG  Size 
)

Definition at line 21 of file kdserial.c.

24 {
25  PUCHAR ByteBuffer = Buffer;
26 
27  while (Size-- > 0)
28  {
29  KdpSendByte(*ByteBuffer++);
30  }
31 }
unsigned char * PUCHAR
Definition: retypes.h:3
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:291
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by KdpSendControlPacket(), and KdSendPacket().