ReactOS  0.4.12-dev-685-gf36cbf7
kdbg.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 
17 #define DEFAULT_BAUD_RATE 19200
18 
19 #if defined(_M_IX86) || defined(_M_AMD64)
20 const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
21 #elif defined(_M_PPC)
22 const ULONG BaseArray[] = {0, 0x800003F8};
23 #elif defined(_M_MIPS)
24 const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
25 #elif defined(_M_ARM)
26 const ULONG BaseArray[] = {0, 0xF1012000};
27 #else
28 #error Unknown architecture
29 #endif
30 
31 #define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
32 
33 /* STATIC VARIABLES ***********************************************************/
34 
35 // static CPPORT DefaultPort = {0, 0, 0};
36 
37 /* The COM port must only be initialized once! */
38 // static BOOLEAN PortInitialized = FALSE;
39 
40 /* REACTOS FUNCTIONS **********************************************************/
41 
43 NTAPI
46 {
48 }
49 
50 BOOLEAN
51 NTAPI
54  IN ULONG ComPortNumber)
55 {
57 
58 #if 0 // Deactivated because never used in fact (was in KdPortInitialize but we use KdPortInitializeEx)
59  /*
60  * Find the port if needed
61  */
62 
63  if (!PortInitialized)
64  {
66 
67  if (ComPortNumber == 0)
68  {
69  /*
70  * Start enumerating COM ports from the last one to the first one,
71  * and break when we find a valid port.
72  * If we reach the first element of the list, the invalid COM port,
73  * then it means that no valid port was found.
74  */
75  for (ComPortNumber = MAX_COM_PORTS; ComPortNumber > 0; ComPortNumber--)
76  {
77  if (CpDoesPortExist(UlongToPtr(BaseArray[ComPortNumber])))
78  {
79  PortInformation->Address = DefaultPort.Address = BaseArray[ComPortNumber];
80  break;
81  }
82  }
83  if (ComPortNumber == 0)
84  {
85  HalDisplayString("\r\nKernel Debugger: No COM port found!\r\n\r\n");
86  return FALSE;
87  }
88  }
89 
90  PortInitialized = TRUE;
91  }
92 #endif
93 
94  /*
95  * Initialize the port
96  */
98  (ComPortNumber == 0 ? PortInformation->Address
99  : UlongToPtr(BaseArray[ComPortNumber])),
100  (PortInformation->BaudRate == 0 ? DEFAULT_BAUD_RATE
101  : PortInformation->BaudRate));
102  if (!NT_SUCCESS(Status))
103  {
104  HalDisplayString("\r\nKernel Debugger: Serial port not found!\r\n\r\n");
105  return FALSE;
106  }
107  else
108  {
109 #ifndef NDEBUG
110  CHAR buffer[80];
111 
112  /* Print message to blue screen */
113  sprintf(buffer,
114  "\r\nKernel Debugger: Serial port found: COM%ld (Port 0x%p) BaudRate %ld\r\n\r\n",
115  ComPortNumber,
116  PortInformation->Address,
117  PortInformation->BaudRate);
119 #endif /* NDEBUG */
120 
121 #if 0
122  /* Set global info */
124 #endif
125  return TRUE;
126  }
127 }
128 
129 BOOLEAN
130 NTAPI
133  OUT PUCHAR ByteReceived)
134 {
135  return (CpGetByte(PortInformation, ByteReceived, FALSE, FALSE) == CP_GET_SUCCESS);
136 }
137 
138 VOID
139 NTAPI
142  IN UCHAR ByteToSend)
143 {
144  CpPutByte(PortInformation, ByteToSend);
145 }
146 
147 /* EOF */
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
IN CINT OUT PVOID PortInformation
Definition: dumpinfo.c:39
GLuint buffer
Definition: glext.h:5915
USHORT NTAPI CpGetByte(IN PCPPORT Port, OUT PUCHAR Byte, IN BOOLEAN Wait, IN BOOLEAN Poll)
Definition: cport.c:256
#define sprintf(buf, format,...)
Definition: sprintf.c:55
BOOLEAN NTAPI CpDoesPortExist(IN PUCHAR Address)
Definition: cport.c:227
#define MAX_COM_PORTS
Definition: kdbg.c:31
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
BOOLEAN NTAPI KdPortInitializeEx(IN PCPPORT PortInformation, IN ULONG ComPortNumber)
Definition: kdbg.c:37
unsigned char BOOLEAN
NTSTATUS NTAPI KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
Definition: kdbg.c:30
#define UlongToPtr(ul)
Definition: basetsd.h:98
PUCHAR KdComPortInUse
Definition: usage.c:17
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
VOID NTAPI KdPortPutByteEx(IN PCPPORT PortInformation, IN UCHAR ByteToSend)
Definition: kdbg.c:98
BOOLEAN NTAPI KdPortGetByteEx(IN PCPPORT PortInformation, OUT PUCHAR ByteReceived)
Definition: kdbg.c:88
VOID NTAPI CpPutByte(IN PCPPORT Port, IN UCHAR Byte)
Definition: cport.c:306
unsigned char UCHAR
Definition: xmlstorage.h:181
#define DEFAULT_BAUD_RATE
Definition: kdbg.c:17
NTSTATUS NTAPI CpInitialize(IN PCPPORT Port, IN PUCHAR Address, IN ULONG BaudRate)
Definition: cport.c:88
PUCHAR Address
Definition: cportlib.h:29
Status
Definition: gdiplustypes.h:24
ULONG BaudRate
Definition: cportlib.h:30
#define CP_GET_SUCCESS
Definition: cportlib.h:18
NTHALAPI VOID NTAPI HalDisplayString(PUCHAR String)
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
CPPORT DefaultPort
Definition: kdbg.c:18
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68