2 Basic serial IO abstraction for GDB
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/GdbSerialLib.h>
12 #include <Library/PcdLib.h>
13 #include <Library/IoLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
17 #include <Protocol/DebugPort.h>
19 EFI_DEBUGPORT_PROTOCOL
*gDebugPort
= NULL
;
23 The constructor function initializes the UART.
25 @param ImageHandle The firmware allocated handle for the EFI image.
26 @param SystemTable A pointer to the EFI System Table.
28 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
33 GdbSerialLibDebugPortConstructor (
34 IN EFI_HANDLE ImageHandle
,
35 IN EFI_SYSTEM_TABLE
*SystemTable
40 Status
= gBS
->LocateProtocol (&gEfiDebugPortProtocolGuid
, NULL
, (VOID
**)&gDebugPort
);
41 if (!EFI_ERROR (Status
)) {
42 gTimeOut
= PcdGet32 (PcdGdbMaxPacketRetryCount
);
43 gDebugPort
->Reset (gDebugPort
);
50 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
51 data buts, and stop bits on a serial device. This call is optional as the serial
52 port will be set up with defaults base on PCD values.
54 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the
55 device's default interface speed.
56 @param Parity The type of parity to use on this serial device. A Parity value of
57 DefaultParity will use the device's default parity value.
58 @param DataBits The number of data bits to use on the serial device. A DataBits
59 value of 0 will use the device's default data bit setting.
60 @param StopBits The number of stop bits to use on this serial device. A StopBits
61 value of DefaultStopBits will use the device's default number of
64 @retval EFI_SUCCESS The device was configured.
65 @retval EFI_DEVICE_ERROR The serial device could not be configured.
79 Status
= gDebugPort
->Reset (gDebugPort
);
84 Check to see if a character is available from GDB. Do not read the character as that is
85 done via GdbGetChar().
87 @return TRUE - Character available
88 @return FALSE - Character not available
99 Status
= gDebugPort
->Poll (gDebugPort
);
101 return (Status
== EFI_SUCCESS
? TRUE
: FALSE
);
105 Get a character from GDB. This function must be able to run in interrupt context.
107 @return A character from GDB
121 BufferSize
= sizeof (Char
);
122 Status
= gDebugPort
->Read (gDebugPort
, gTimeOut
, &BufferSize
, &Char
);
123 } while (EFI_ERROR (Status
) || BufferSize
!= sizeof (Char
));
129 Send a character to GDB. This function must be able to run in interrupt context.
132 @param Char Send a character to GDB
145 BufferSize
= sizeof (Char
);
146 Status
= gDebugPort
->Write (gDebugPort
, gTimeOut
, &BufferSize
, &Char
);
147 } while (EFI_ERROR (Status
) || BufferSize
!= sizeof (Char
));
153 Send an ASCII string to GDB. This function must be able to run in interrupt context.
156 @param String Send a string to GDB
164 // We could performance enhance this function by calling gDebugPort->Write ()
165 while (*String
!= '\0') {
166 GdbPutChar (*String
);