ReactOS 0.4.16-dev-2491-g3dc6630
kdcom.c File Reference
#include "kddll.h"
#include <arc/arc.h>
#include <stdlib.h>
#include <ndk/halfuncs.h>
#include <cportlib/cportlib.h>
#include <cportlib/uartinfo.h>
Include dependency graph for kdcom.c:

Go to the source code of this file.

Macros

#define CONST_STR_LEN(x)   (sizeof(x)/sizeof(x[0]) - 1)
 

Functions

NTSTATUS NTAPI KdD0Transition (VOID)
 
NTSTATUS NTAPI KdD3Transition (VOID)
 
NTSTATUS NTAPI KdSave (IN BOOLEAN SleepTransition)
 
NTSTATUS NTAPI KdRestore (IN BOOLEAN SleepTransition)
 
NTSTATUS NTAPI KdpPortInitialize (_In_ PUCHAR PortAddress, _In_ ULONG BaudRate)
 
NTSTATUS NTAPI KdDebuggerInitialize0 (IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
 
NTSTATUS NTAPI KdDebuggerInitialize1 (IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
 
VOID NTAPI KdpSendByte (IN UCHAR Byte)
 
KDP_STATUS NTAPI KdpPollByte (OUT PUCHAR OutByte)
 
KDP_STATUS NTAPI KdpReceiveByte (OUT PUCHAR OutByte)
 
KDP_STATUS NTAPI KdpPollBreakIn (VOID)
 

Variables

CPPORT KdComPort
 

Macro Definition Documentation

◆ CONST_STR_LEN

#define CONST_STR_LEN (   x)    (sizeof(x)/sizeof(x[0]) - 1)

Function Documentation

◆ KdD0Transition()

NTSTATUS NTAPI KdD0Transition ( VOID  )

Definition at line 67 of file kdcom.c.

68{
69 return STATUS_SUCCESS;
70}
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by KdPowerTransition().

◆ KdD3Transition()

NTSTATUS NTAPI KdD3Transition ( VOID  )

Definition at line 74 of file kdcom.c.

75{
76 return STATUS_SUCCESS;
77}

Referenced by KdPowerTransition().

◆ KdDebuggerInitialize0()

NTSTATUS NTAPI KdDebuggerInitialize0 ( IN PLOADER_PARAMETER_BLOCK LoaderBlock  OPTIONAL)

Definition at line 119 of file kdcom.c.

120{
121#define CONST_STR_LEN(x) (sizeof(x)/sizeof(x[0]) - 1)
122
123 ULONG ComPortNumber = DEFAULT_DEBUG_PORT;
124 ULONG ComPortBaudRate = DEFAULT_DEBUG_BAUD_RATE;
125 PUCHAR ComPortAddress = NULL;
126
127 PSTR CommandLine, PortString, BaudString;
128 ULONG Value;
129
130 /* Check if we have a LoaderBlock */
131 if (LoaderBlock)
132 {
133 /* Get the Command Line */
134 CommandLine = LoaderBlock->LoadOptions;
135
136 /* Upcase it */
137 _strupr(CommandLine);
138
139 /* Get the port and baud rate */
140 PortString = strstr(CommandLine, "DEBUGPORT");
141 BaudString = strstr(CommandLine, "BAUDRATE");
142
143 /* Check if we got the DEBUGPORT parameter */
144 if (PortString)
145 {
146 /* Move past the actual string and any spaces */
147 PortString += CONST_STR_LEN("DEBUGPORT");
148 while (*PortString == ' ') ++PortString;
149 /* Skip the equals sign */
150 if (*PortString) ++PortString;
151
152 /* Do we have a serial port? */
153 if (_strnicmp(PortString, "COM", CONST_STR_LEN("COM")) != 0)
155
156 /* Check for a valid serial port */
157 PortString += CONST_STR_LEN("COM");
158 if (*PortString != ':')
159 {
160 Value = (ULONG)atol(PortString);
161 if (Value > MAX_COM_PORTS)
163 // if (Value > 0 && Value <= MAX_COM_PORTS)
164 /* Set the port to use */
165 ComPortNumber = Value;
166 }
167 else
168 {
169 /* Retrieve and set its address */
170 Value = strtoul(PortString + 1, NULL, 0);
171 if (Value)
172 {
173 ComPortNumber = 0;
174 ComPortAddress = UlongToPtr(Value);
175 }
176 }
177 }
178
179 /* Check if we got a baud rate */
180 if (BaudString)
181 {
182 /* Move past the actual string and any spaces */
183 BaudString += CONST_STR_LEN("BAUDRATE");
184 while (*BaudString == ' ') ++BaudString;
185
186 /* Make sure we have a rate */
187 if (*BaudString)
188 {
189 /* Read and set it */
190 Value = (ULONG)atol(BaudString + 1);
191 if (Value) ComPortBaudRate = Value;
192 }
193 }
194 }
195
196 if (!ComPortAddress)
197 ComPortAddress = UlongToPtr(BaseArray[ComPortNumber]);
198
199#ifdef KDDEBUG
200 /*
201 * Try to find a free COM port and use it as the KD debugging port.
202 * NOTE: Inspired by freeldr/comm/rs232.c, Rs232PortInitialize(...)
203 */
204 {
205 /*
206 * Enumerate COM ports from the last to the first one, and stop
207 * when we find a valid port. If we reach the first list element
208 * (the undefined COM port), no valid port was found.
209 */
211 ULONG ComPort;
212 for (ComPort = MAX_COM_PORTS; ComPort > 0; ComPort--)
213 {
214 /* Check if the port exist; skip the KD port */
215 Address = UlongToPtr(BaseArray[ComPort]);
216 if ((Address != ComPortAddress) && CpDoesPortExist(Address))
217 break;
218 }
219 if (ComPort != 0 && Address != NULL)
220 CpInitialize(&KdDebugComPort, Address, DEFAULT_BAUD_RATE);
221 }
222#endif
223
224 /* Initialize the port */
225 return KdpPortInitialize(ComPortAddress, ComPortBaudRate);
226}
NTSTATUS NTAPI CpInitialize(_Inout_ PCPPORT Port, _In_ PUCHAR Address, _In_ ULONG BaudRate)
Definition: cport.c:59
BOOLEAN NTAPI CpDoesPortExist(_In_ PUCHAR Address)
Definition: cport.c:33
#define NULL
Definition: types.h:112
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
_ACRTIMP __msvcrt_long __cdecl atol(const char *)
Definition: string.c:1782
_ACRTIMP __msvcrt_ulong __cdecl strtoul(const char *, char **, int)
Definition: string.c:1859
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3415
#define UlongToPtr(u)
Definition: config.h:106
#define CONST_STR_LEN(x)
NTSTATUS NTAPI KdpPortInitialize(_In_ PUCHAR PortAddress, _In_ ULONG BaudRate)
Definition: kdcom.c:97
#define MAX_COM_PORTS
Definition: machpc.c:29
static WCHAR Address[46]
Definition: ping.c:68
_strupr
Definition: string.h:453
char * PSTR
Definition: typedefs.h:51
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define DEFAULT_DEBUG_PORT
Definition: uartinfo.h:16
#define DEFAULT_DEBUG_BAUD_RATE
Definition: uartinfo.h:17
#define DEFAULT_BAUD_RATE
Definition: uartinfo.h:24
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by KdInitSystem().

◆ KdDebuggerInitialize1()

NTSTATUS NTAPI KdDebuggerInitialize1 ( IN PLOADER_PARAMETER_BLOCK LoaderBlock  OPTIONAL)

Definition at line 236 of file kdcom.c.

237{
238 return STATUS_SUCCESS;
239}

Referenced by Phase1InitializationDiscard().

◆ KdpPollBreakIn()

KDP_STATUS NTAPI KdpPollBreakIn ( VOID  )

Definition at line 296 of file kdcom.c.

297{
298 KDP_STATUS KdStatus;
299 UCHAR Byte;
300
301 KdStatus = KdpPollByte(&Byte);
302 if ((KdStatus == KDP_PACKET_RECEIVED) && (Byte == BREAKIN_PACKET_BYTE))
303 {
304 return KDP_PACKET_RECEIVED;
305 }
306 return KDP_PACKET_TIMEOUT;
307}
unsigned char Byte
Definition: zlib.h:37
KDP_STATUS
Definition: kddll.h:26
@ KDP_PACKET_TIMEOUT
Definition: kddll.h:28
@ KDP_PACKET_RECEIVED
Definition: kddll.h:27
KDP_STATUS NTAPI KdpPollByte(OUT PUCHAR OutByte)
Definition: kdcom.c:252
#define BREAKIN_PACKET_BYTE
Definition: windbgkd.h:31
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by KdReceivePacket().

◆ KdpPollByte()

KDP_STATUS NTAPI KdpPollByte ( OUT PUCHAR  OutByte)

Definition at line 252 of file kdcom.c.

253{
255
256 /* Poll the byte */
257 Status = CpGetByte(&KdComPort, OutByte, FALSE, FALSE);
258 switch (Status)
259 {
260 case CP_GET_SUCCESS:
261 return KDP_PACKET_RECEIVED;
262
263 case CP_GET_NODATA:
264 return KDP_PACKET_TIMEOUT;
265
266 case CP_GET_ERROR:
267 default:
268 return KDP_PACKET_RESEND;
269 }
270}
USHORT NTAPI CpGetByte(_Inout_ PCPPORT Port, _Out_ PUCHAR Byte, _In_ BOOLEAN Wait, _In_ BOOLEAN Poll)
Definition: cport.c:82
#define CP_GET_SUCCESS
Definition: cportlib.h:17
#define CP_GET_NODATA
Definition: cportlib.h:18
#define CP_GET_ERROR
Definition: cportlib.h:19
#define FALSE
Definition: types.h:117
@ KDP_PACKET_RESEND
Definition: kddll.h:29
Status
Definition: gdiplustypes.h:25
CPPORT KdComPort
Definition: kdcom.c:20
unsigned short USHORT
Definition: pedump.c:61

Referenced by gdb_receive_packet(), and KdpPollBreakIn().

◆ KdpPortInitialize()

NTSTATUS NTAPI KdpPortInitialize ( _In_ PUCHAR  PortAddress,
_In_ ULONG  BaudRate 
)

Definition at line 97 of file kdcom.c.

100{
102
103 Status = CpInitialize(&KdComPort, PortAddress, BaudRate);
104 if (!NT_SUCCESS(Status))
106
108 return STATUS_SUCCESS;
109}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
PUCHAR KdComPortInUse
Definition: usage.c:17
PUCHAR Address
Definition: cportlib.h:28

Referenced by KdDebuggerInitialize0().

◆ KdpReceiveByte()

KDP_STATUS NTAPI KdpReceiveByte ( OUT PUCHAR  OutByte)

Definition at line 274 of file kdcom.c.

275{
277
278 /* Get the byte */
279 Status = CpGetByte(&KdComPort, OutByte, TRUE, FALSE);
280 switch (Status)
281 {
282 case CP_GET_SUCCESS:
283 return KDP_PACKET_RECEIVED;
284
285 case CP_GET_NODATA:
286 return KDP_PACKET_TIMEOUT;
287
288 case CP_GET_ERROR:
289 default:
290 return KDP_PACKET_RESEND;
291 }
292}
#define TRUE
Definition: types.h:120

Referenced by finish_gdb_packet(), gdb_receive_packet(), KdpReceiveBuffer(), and KdpReceivePacketLeader().

◆ KdpSendByte()

VOID NTAPI KdpSendByte ( IN UCHAR  Byte)

Definition at line 244 of file kdcom.c.

245{
246 /* Send the byte */
248}
VOID NTAPI CpPutByte(_Inout_ PCPPORT Port, _In_ UCHAR Byte)
Definition: cport.c:93

Referenced by finish_gdb_packet(), gdb_receive_packet(), KdpPollBreakIn(), KdpSendBuffer(), KdSendPacket(), send_gdb_partial_binary(), send_gdb_partial_packet(), and start_gdb_packet().

◆ KdRestore()

NTSTATUS NTAPI KdRestore ( IN BOOLEAN  SleepTransition)

Definition at line 89 of file kdcom.c.

90{
91 /* Nothing to do on COM ports */
92 return STATUS_SUCCESS;
93}

Referenced by KdExitDebugger(), and KdReportProcessorChange().

◆ KdSave()

NTSTATUS NTAPI KdSave ( IN BOOLEAN  SleepTransition)

Definition at line 81 of file kdcom.c.

82{
83 /* Nothing to do on COM ports */
84 return STATUS_SUCCESS;
85}

Referenced by KdEnterDebugger(), and KdReportProcessorChange().

Variable Documentation

◆ KdComPort

CPPORT KdComPort

Definition at line 20 of file kdcom.c.

Referenced by KdpPollByte(), KdpPortInitialize(), KdpReceiveByte(), and KdpSendByte().