[KDCOM]
[reactos.git] / drivers / base / kdcom / arm / kdbg.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/base/kdcom/arm/kdbg.c
5 * PURPOSE: Serial Port Kernel Debugging Transport Library
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #define NOEXTAPI
12 #include <ntifs.h>
13 #define NDEBUG
14 #include <halfuncs.h>
15 #include <stdio.h>
16 #include <debug.h>
17 #include "arc/arc.h"
18 #include "windbgkd.h"
19 #include <kddll.h>
20 #include <ioaccess.h>
21 #include <arm/peripherals/pl011.h>
22
23 /* GLOBALS ********************************************************************/
24
25 typedef struct _KD_PORT_INFORMATION
26 {
27 ULONG ComPort;
28 ULONG BaudRate;
29 ULONG BaseAddress;
30 } KD_PORT_INFORMATION, *PKD_PORT_INFORMATION;
31
32 KD_PORT_INFORMATION DefaultPort = {0, 0, 0};
33
34 //
35 // We need to build this in the configuration root and use KeFindConfigurationEntry
36 // to recover it later.
37 //
38 #define HACK 24000000
39
40 /* REACTOS FUNCTIONS **********************************************************/
41
42 BOOLEAN
43 NTAPI
44 KdPortInitializeEx(IN PKD_PORT_INFORMATION PortInformation,
45 IN ULONG Unknown1,
46 IN ULONG Unknown2)
47 {
48 ULONG Divider, Remainder, Fraction;
49 ULONG Baudrate = PortInformation->BaudRate;
50
51 //
52 // Calculate baudrate clock divider and remainder
53 //
54 Divider = HACK / (16 * Baudrate);
55 Remainder = HACK % (16 * Baudrate);
56
57 //
58 // Calculate the fractional part
59 //
60 Fraction = (8 * Remainder / Baudrate) >> 1;
61 Fraction += (8 * Remainder / Baudrate) & 1;
62
63 //
64 // Disable interrupts
65 //
66 WRITE_REGISTER_ULONG(UART_PL011_CR, 0);
67
68 //
69 // Set the baud rate
70 //
71 WRITE_REGISTER_ULONG(UART_PL011_IBRD, Divider);
72 WRITE_REGISTER_ULONG(UART_PL011_FBRD, Fraction);
73
74 //
75 // Set 8 bits for data, 1 stop bit, no parity, FIFO enabled
76 //
77 WRITE_REGISTER_ULONG(UART_PL011_LCRH,
78 UART_PL011_LCRH_WLEN_8 | UART_PL011_LCRH_FEN);
79
80 //
81 // Clear and enable FIFO
82 //
83 WRITE_REGISTER_ULONG(UART_PL011_CR,
84 UART_PL011_CR_UARTEN |
85 UART_PL011_CR_TXE |
86 UART_PL011_CR_RXE);
87
88 //
89 // Done
90 //
91 return TRUE;
92 }
93
94 BOOLEAN
95 NTAPI
96 KdPortInitialize(IN PKD_PORT_INFORMATION PortInformation,
97 IN ULONG Unknown1,
98 IN ULONG Unknown2)
99 {
100 //
101 // Call the extended version
102 //
103 return KdPortInitializeEx(PortInformation, Unknown1, Unknown2);
104 }
105
106 BOOLEAN
107 NTAPI
108 KdPortGetByteEx(IN PKD_PORT_INFORMATION PortInformation,
109 OUT PUCHAR ByteReceived)
110 {
111 UNIMPLEMENTED;
112 while (TRUE);
113 return FALSE;
114 }
115
116 BOOLEAN
117 NTAPI
118 KdPortGetByte(OUT PUCHAR ByteReceived)
119 {
120 //
121 // Call the extended version
122 //
123 return KdPortGetByteEx(&DefaultPort, ByteReceived);
124 }
125
126 BOOLEAN
127 NTAPI
128 KdPortPollByteEx(IN PKD_PORT_INFORMATION PortInformation,
129 OUT PUCHAR ByteReceived)
130 {
131 UNIMPLEMENTED;
132 while (TRUE);
133 return TRUE;
134 }
135
136 BOOLEAN
137 NTAPI
138 KdPortPollByte(OUT PUCHAR ByteReceived)
139 {
140 //
141 // Call the extended version
142 //
143 return KdPortPollByteEx(&DefaultPort, ByteReceived);
144 }
145
146 VOID
147 NTAPI
148 KdPortPutByteEx(IN PKD_PORT_INFORMATION PortInformation,
149 IN UCHAR ByteToSend)
150 {
151 //
152 // Wait for ready
153 //
154 while ((READ_REGISTER_ULONG(UART_PL01x_FR) & UART_PL01x_FR_TXFF) != 0);
155
156 //
157 // Send the character
158 //
159 WRITE_REGISTER_ULONG(UART_PL01x_DR, ByteToSend);
160 }
161
162 VOID
163 NTAPI
164 KdPortPutByte(IN UCHAR ByteToSend)
165 {
166 //
167 // Call the extended version
168 //
169 KdPortPutByteEx(&DefaultPort, ByteToSend);
170 }
171
172 VOID
173 NTAPI
174 KdPortRestore(VOID)
175 {
176 UNIMPLEMENTED;
177 while (TRUE);
178 }
179
180 VOID
181 NTAPI
182 KdPortSave(VOID)
183 {
184 UNIMPLEMENTED;
185 while (TRUE);
186 }
187
188 BOOLEAN
189 NTAPI
190 KdPortDisableInterrupts(VOID)
191 {
192 UNIMPLEMENTED;
193 while (TRUE);
194 return TRUE;
195 }
196
197 BOOLEAN
198 NTAPI
199 KdPortEnableInterrupts(VOID)
200 {
201 UNIMPLEMENTED;
202 while (TRUE);
203 return TRUE;
204 }
205
206 /* WINDOWS FUNCTIONS **********************************************************/
207
208 NTSTATUS
209 NTAPI
210 KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
211 {
212 UNIMPLEMENTED;
213 return STATUS_NOT_IMPLEMENTED;
214 }
215
216 NTSTATUS
217 NTAPI
218 KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
219 {
220 UNIMPLEMENTED;
221 return STATUS_NOT_IMPLEMENTED;
222 }
223
224 NTSTATUS
225 NTAPI
226 KdSave(IN BOOLEAN SleepTransition)
227 {
228 UNIMPLEMENTED;
229 while (TRUE);
230 return STATUS_SUCCESS;
231 }
232
233 NTSTATUS
234 NTAPI
235 KdRestore(IN BOOLEAN SleepTransition)
236 {
237 UNIMPLEMENTED;
238 while (TRUE);
239 return STATUS_SUCCESS;
240 }
241
242 VOID
243 NTAPI
244 KdSendPacket(IN ULONG PacketType,
245 IN PSTRING MessageHeader,
246 IN PSTRING MessageData,
247 IN OUT PKD_CONTEXT Context)
248 {
249 UNIMPLEMENTED;
250 while (TRUE);
251 return;
252 }
253
254 KDSTATUS
255 NTAPI
256 KdReceivePacket(IN ULONG PacketType,
257 OUT PSTRING MessageHeader,
258 OUT PSTRING MessageData,
259 OUT PULONG DataLength,
260 IN OUT PKD_CONTEXT Context)
261 {
262 UNIMPLEMENTED;
263 while (TRUE);
264 return 0;
265 }
266
267 /* EOF */