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