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
9 /* INCLUDES *******************************************************************/
21 #include <arm/peripherals/pl011.h>
23 /* GLOBALS ********************************************************************/
25 typedef struct _KD_PORT_INFORMATION
30 } KD_PORT_INFORMATION
, *PKD_PORT_INFORMATION
;
32 KD_PORT_INFORMATION DefaultPort
= {0, 0, 0};
35 // We need to build this in the configuration root and use KeFindConfigurationEntry
36 // to recover it later.
40 /* REACTOS FUNCTIONS **********************************************************/
44 KdPortInitializeEx(IN PKD_PORT_INFORMATION PortInformation
,
48 ULONG Divider
, Remainder
, Fraction
;
49 ULONG Baudrate
= PortInformation
->BaudRate
;
52 // Calculate baudrate clock divider and remainder
54 Divider
= HACK
/ (16 * Baudrate
);
55 Remainder
= HACK
% (16 * Baudrate
);
58 // Calculate the fractional part
60 Fraction
= (8 * Remainder
/ Baudrate
) >> 1;
61 Fraction
+= (8 * Remainder
/ Baudrate
) & 1;
66 WRITE_REGISTER_ULONG(UART_PL011_CR
, 0);
71 WRITE_REGISTER_ULONG(UART_PL011_IBRD
, Divider
);
72 WRITE_REGISTER_ULONG(UART_PL011_FBRD
, Fraction
);
75 // Set 8 bits for data, 1 stop bit, no parity, FIFO enabled
77 WRITE_REGISTER_ULONG(UART_PL011_LCRH
,
78 UART_PL011_LCRH_WLEN_8
| UART_PL011_LCRH_FEN
);
81 // Clear and enable FIFO
83 WRITE_REGISTER_ULONG(UART_PL011_CR
,
84 UART_PL011_CR_UARTEN
|
96 KdPortInitialize(IN PKD_PORT_INFORMATION PortInformation
,
101 // Call the extended version
103 return KdPortInitializeEx(PortInformation
, Unknown1
, Unknown2
);
108 KdPortGetByteEx(IN PKD_PORT_INFORMATION PortInformation
,
109 OUT PUCHAR ByteReceived
)
118 KdPortGetByte(OUT PUCHAR ByteReceived
)
121 // Call the extended version
123 return KdPortGetByteEx(&DefaultPort
, ByteReceived
);
128 KdPortPollByteEx(IN PKD_PORT_INFORMATION PortInformation
,
129 OUT PUCHAR ByteReceived
)
138 KdPortPollByte(OUT PUCHAR ByteReceived
)
141 // Call the extended version
143 return KdPortPollByteEx(&DefaultPort
, ByteReceived
);
148 KdPortPutByteEx(IN PKD_PORT_INFORMATION PortInformation
,
154 while ((READ_REGISTER_ULONG(UART_PL01x_FR
) & UART_PL01x_FR_TXFF
) != 0);
157 // Send the character
159 WRITE_REGISTER_ULONG(UART_PL01x_DR
, ByteToSend
);
164 KdPortPutByte(IN UCHAR ByteToSend
)
167 // Call the extended version
169 KdPortPutByteEx(&DefaultPort
, ByteToSend
);
190 KdPortDisableInterrupts(VOID
)
199 KdPortEnableInterrupts(VOID
)
206 /* WINDOWS FUNCTIONS **********************************************************/
210 KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL
)
213 return STATUS_NOT_IMPLEMENTED
;
218 KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL
)
221 return STATUS_NOT_IMPLEMENTED
;
226 KdSave(IN BOOLEAN SleepTransition
)
230 return STATUS_SUCCESS
;
235 KdRestore(IN BOOLEAN SleepTransition
)
239 return STATUS_SUCCESS
;
244 KdSendPacket(IN ULONG PacketType
,
245 IN PSTRING MessageHeader
,
246 IN PSTRING MessageData
,
247 IN OUT PKD_CONTEXT Context
)
256 KdReceivePacket(IN ULONG PacketType
,
257 OUT PSTRING MessageHeader
,
258 OUT PSTRING MessageData
,
259 OUT PULONG DataLength
,
260 IN OUT PKD_CONTEXT Context
)