ReactOS 0.4.16-dev-2498-g8632030
kdserial.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/kd/i386/kdbg.c
5 * PURPOSE: Serial i/o functions for the kernel debugger.
6 * PROGRAMMER: Alex Ionescu
7 * Hervé Poussineau
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include <ntoskrnl.h>
13#define NDEBUG
14#include <debug.h>
15
16//#include <cportlib/cportlib.h>
17#include <cportlib/uartinfo.h>
18
19/* STATIC VARIABLES ***********************************************************/
20
21// static CPPORT DefaultPort = {0, 0, 0};
22
23/* The COM port must only be initialized once! */
24// static BOOLEAN PortInitialized = FALSE;
25
26/* REACTOS FUNCTIONS **********************************************************/
27
32 IN ULONG ComPortNumber)
33{
35
36#if 0 // Deactivated because never used in fact (was in KdPortInitialize but we use KdPortInitializeEx)
37 /*
38 * Find the port if needed
39 */
40
41 if (!PortInitialized)
42 {
44
45 if (ComPortNumber == 0)
46 {
47 /*
48 * Enumerate COM ports from the last to the first one, and stop
49 * when we find a valid port. If we reach the first list element
50 * (the undefined COM port), no valid port was found.
51 */
52 for (ComPortNumber = MAX_COM_PORTS; ComPortNumber > 0; ComPortNumber--)
53 {
54 if (CpDoesPortExist(UlongToPtr(BaseArray[ComPortNumber])))
55 {
56 PortInformation->Address = DefaultPort.Address = BaseArray[ComPortNumber];
57 break;
58 }
59 }
60 if (ComPortNumber == 0)
61 {
62 HalDisplayString("\r\nKernel Debugger: No serial port found\r\n\r\n");
63 return FALSE;
64 }
65 }
66
67 PortInitialized = TRUE;
68 }
69#endif
70
71 /*
72 * Initialize the port
73 */
75 (ComPortNumber == 0 ? PortInformation->Address
76 : UlongToPtr(BaseArray[ComPortNumber])),
78 : PortInformation->BaudRate));
79 if (!NT_SUCCESS(Status))
80 {
81 HalDisplayString("\r\nKernel Debugger: Serial port not available\r\n\r\n");
82 return FALSE;
83 }
84 else
85 {
86#ifndef NDEBUG
87 int Length;
88 CHAR Buffer[82];
89
90 /* Print message to blue screen */
91 Length = snprintf(Buffer, sizeof(Buffer),
92 "\r\nKernel Debugger: Using COM%lu (Port 0x%p) BaudRate %lu\r\n\r\n",
93 ComPortNumber,
94 PortInformation->Address,
95 PortInformation->BaudRate);
96 if (Length == -1)
97 {
98 /* Terminate it if we went over-board */
99 Buffer[sizeof(Buffer) - 1] = ANSI_NULL;
100 }
101
103#endif /* NDEBUG */
104
105#if 0
106 /* Set global info */
108#endif
109 return TRUE;
110 }
111}
112
114NTAPI
117 OUT PUCHAR ByteReceived)
118{
119 return (CpGetByte(PortInformation, ByteReceived, FALSE, FALSE) == CP_GET_SUCCESS);
120}
121
122VOID
123NTAPI
126 IN UCHAR ByteToSend)
127{
128 CpPutByte(PortInformation, ByteToSend);
129}
130
131/* EOF */
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
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
VOID NTAPI CpPutByte(_Inout_ PCPPORT Port, _In_ UCHAR Byte)
Definition: cport.c:93
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 TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define UlongToPtr(u)
Definition: config.h:106
IN CINT OUT PVOID PortInformation
Definition: dumpinfo.c:40
Status
Definition: gdiplustypes.h:25
PUCHAR KdComPortInUse
Definition: usage.c:17
NTHALAPI VOID NTAPI HalDisplayString(PUCHAR String)
#define MAX_COM_PORTS
Definition: machpc.c:29
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
VOID NTAPI KdPortPutByteEx(IN PCPPORT PortInformation, IN UCHAR ByteToSend)
Definition: kdserial.c:91
BOOLEAN NTAPI KdPortInitializeEx(IN PCPPORT PortInformation, IN ULONG ComPortNumber)
Definition: kdserial.c:30
CPPORT DefaultPort
Definition: kdserial.c:18
BOOLEAN NTAPI KdPortGetByteEx(IN PCPPORT PortInformation, OUT PUCHAR ByteReceived)
Definition: kdserial.c:81
PUCHAR Address
Definition: cportlib.h:28
ULONG BaudRate
Definition: cportlib.h:29
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define DEFAULT_DEBUG_BAUD_RATE
Definition: uartinfo.h:17
#define snprintf
Definition: wintirpc.h:48
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175