Synchronize with trunk.
[reactos.git] / ntoskrnl / kd / i386 / kdbg.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/base/kdcom/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 /* STATIC VARIABLES ***********************************************************/
32
33 // static CPPORT DefaultPort = {0, 0, 0};
34
35 /* The COM port must only be initialized once! */
36 // static BOOLEAN PortInitialized = FALSE;
37
38
39 /* REACTOS FUNCTIONS **********************************************************/
40
41 NTSTATUS
42 NTAPI
43 KdDebuggerInitialize1(
44 IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
45 {
46 return STATUS_NOT_IMPLEMENTED;
47 }
48
49 BOOLEAN
50 NTAPI
51 KdPortInitializeEx(
52 IN PCPPORT PortInformation,
53 IN ULONG ComPortNumber)
54 {
55 NTSTATUS Status;
56 CHAR buffer[80];
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 SIZE_T i;
63
64 if (!PortInitialized)
65 {
66 DefaultPort.BaudRate = PortInformation->BaudRate;
67
68 if (ComPortNumber == 0)
69 {
70 /*
71 * Start enumerating COM ports from the last one to the first one,
72 * and break when we find a valid port.
73 * If we reach the first element of the list, the invalid COM port,
74 * then it means that no valid port was found.
75 */
76 for (i = sizeof(BaseArray) / sizeof(BaseArray[0]) - 1; i > 0; i--)
77 {
78 if (CpDoesPortExist(UlongToPtr(BaseArray[i])))
79 {
80 PortInformation->Address = DefaultPort.Address = BaseArray[i];
81 ComPortNumber = (ULONG)i;
82 break;
83 }
84 }
85 if (ComPortNumber == 0)
86 {
87 sprintf(buffer,
88 "\nKernel Debugger: No COM port found!\n\n");
89 HalDisplayString(buffer);
90 return FALSE;
91 }
92 }
93
94 PortInitialized = TRUE;
95 }
96 #endif
97
98 /*
99 * Initialize the port
100 */
101 Status = CpInitialize(PortInformation,
102 (ComPortNumber == 0 ? PortInformation->Address
103 : UlongToPtr(BaseArray[ComPortNumber])),
104 (PortInformation->BaudRate == 0 ? DEFAULT_BAUD_RATE
105 : PortInformation->BaudRate));
106 if (!NT_SUCCESS(Status))
107 {
108 sprintf(buffer,
109 "\nKernel Debugger: Serial port not found!\n\n");
110 HalDisplayString(buffer);
111 return FALSE;
112 }
113 else
114 {
115 #ifndef NDEBUG
116 /* Print message to blue screen */
117 sprintf(buffer,
118 "\nKernel Debugger: Serial port found: COM%ld (Port 0x%lx) BaudRate %ld\n\n",
119 ComPortNumber,
120 PortInformation->Address,
121 PortInformation->BaudRate);
122 HalDisplayString(buffer);
123 #endif /* NDEBUG */
124
125 #if 0
126 /* Set global info */
127 KdComPortInUse = DefaultPort.Address;
128 #endif
129 return TRUE;
130 }
131 }
132
133 BOOLEAN
134 NTAPI
135 KdPortGetByteEx(
136 IN PCPPORT PortInformation,
137 OUT PUCHAR ByteReceived)
138 {
139 return (CpGetByte(PortInformation, ByteReceived, FALSE) == CP_GET_SUCCESS);
140 }
141
142 VOID
143 NTAPI
144 KdPortPutByteEx(
145 IN PCPPORT PortInformation,
146 IN UCHAR ByteToSend)
147 {
148 CpPutByte(PortInformation, ByteToSend);
149 }
150
151 /* EOF */