ReactOS  0.4.14-dev-98-gb0d4763
gdb_receive.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: GPL, see COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/base/kddll/gdb_receive.c
5  * PURPOSE: Base functions for the kernel debugger.
6  */
7 
8 #include "kdgdb.h"
9 
10 /* GLOBALS ********************************************************************/
11 CHAR gdb_input[0x1000];
12 
13 /* GLOBAL FUNCTIONS ***********************************************************/
14 char
15 hex_value(char ch)
16 {
17  if ((ch >= '0') && (ch <= '9'))
18  return (ch - '0');
19 
20  if ((ch >= 'a') && (ch <= 'f'))
21  return (ch - 'a' + 10);
22 
23  if ((ch >= 'A') && (ch <= 'F'))
24  return (ch - 'A' + 10);
25 
26  return -1;
27 }
28 
30 NTAPI
32 {
33  UCHAR* ByteBuffer = (UCHAR*)gdb_input;
34  UCHAR Byte;
36  CHAR CheckSum = 0, ReceivedCheckSum;
37 
38  do
39  {
41  if (Status != KdPacketReceived)
42  return Status;
43  if (Byte == 0x03)
44  {
45  KDDBGPRINT("BREAK!");
46  KdContext->KdpControlCPending = TRUE;
47  return KdPacketNeedsResend;
48  }
49  } while (Byte != '$');
50 
51  while (TRUE)
52  {
53  /* Try to get a byte from the port */
55  if (Status != KdPacketReceived)
56  return Status;
57 
58  if (Byte == '#')
59  {
60  *ByteBuffer = '\0';
61  break;
62  }
63  CheckSum += (CHAR)Byte;
64 
65  /* See if we should escape */
66  if (Byte == 0x7d)
67  {
69  if (Status != KdPacketReceived)
70  return Status;
71  CheckSum += (CHAR)Byte;
72  Byte ^= 0x20;
73  }
74  *ByteBuffer++ = Byte;
75  }
76 
77  /* Get Check sum (two bytes) */
79  if (Status != KdPacketReceived)
80  goto end;
81  ReceivedCheckSum = hex_value(Byte) << 4;
82 
84  if (Status != KdPacketReceived)
85  goto end;
86  ReceivedCheckSum += hex_value(Byte);
87 
88 end:
89  if (ReceivedCheckSum != CheckSum)
90  {
91  /* Do not acknowledge to GDB */
92  KDDBGPRINT("Check sums don't match!");
93  KdpSendByte('-');
94  return KdPacketNeedsResend;
95  }
96 
97  /* Acknowledge */
98  KdpSendByte('+');
99 
100  return KdPacketReceived;
101 }
#define KdPacketReceived
Definition: kddll.h:5
#define TRUE
Definition: types.h:120
#define KDDBGPRINT(...)
Definition: kddll.h:19
unsigned char Byte
Definition: zconf.h:391
char CHAR
Definition: xmlstorage.h:175
KDP_STATUS NTAPI KdpReceiveByte(OUT PUCHAR OutByte)
Definition: kdcom.c:310
GLuint GLuint end
Definition: gl.h:1545
#define KdPacketNeedsResend
Definition: kddll.h:7
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
char hex_value(char ch)
Definition: gdb_receive.c:15
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext)
Definition: gdb_receive.c:31
UCHAR CheckSum(LPSTR p, ULONG Len)
Definition: serial.c:197
#define _Inout_
Definition: no_sal2.h:244
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
ULONG KDSTATUS
Definition: kddll.h:4
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
#define CHAR(Char)