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>
20 EFI_DEBUGPORT_PROTOCOL
*gDebugPort
= NULL
;
24 The constructor function initializes the UART.
26 @param ImageHandle The firmware allocated handle for the EFI image.
27 @param SystemTable A pointer to the EFI System Table.
29 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
34 GdbSerialLibDebugPortConstructor (
35 IN EFI_HANDLE ImageHandle
,
36 IN EFI_SYSTEM_TABLE
*SystemTable
41 Status
= gBS
->LocateProtocol (&gEfiDebugPortProtocolGuid
, NULL
, (VOID
**)&gDebugPort
);
42 if (!EFI_ERROR (Status
)) {
43 gTimeOut
= PcdGet32 (PcdGdbMaxPacketRetryCount
);
44 gDebugPort
->Reset (gDebugPort
);
53 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
54 data buts, and stop bits on a serial device. This call is optional as the serial
55 port will be set up with defaults base on PCD values.
57 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the
58 device's default interface speed.
59 @param Parity The type of parity to use on this serial device. A Parity value of
60 DefaultParity will use the device's default parity value.
61 @param DataBits The number of data bits to use on the serial device. A DataBits
62 value of 0 will use the device's default data bit setting.
63 @param StopBits The number of stop bits to use on this serial device. A StopBits
64 value of DefaultStopBits will use the device's default number of
67 @retval EFI_SUCCESS The device was configured.
68 @retval EFI_DEVICE_ERROR The serial device could not be configured.
82 Status
= gDebugPort
->Reset (gDebugPort
);
88 Check to see if a character is available from GDB. Do not read the character as that is
89 done via GdbGetChar().
91 @return TRUE - Character available
92 @return FALSE - Character not available
103 Status
= gDebugPort
->Poll (gDebugPort
);
105 return (Status
== EFI_SUCCESS
? TRUE
: FALSE
);
110 Get a character from GDB. This function must be able to run in interrupt context.
112 @return A character from GDB
126 BufferSize
= sizeof (Char
);
127 Status
= gDebugPort
->Read (gDebugPort
, gTimeOut
, &BufferSize
, &Char
);
128 } while (EFI_ERROR (Status
) || BufferSize
!= sizeof (Char
));
135 Send a character to GDB. This function must be able to run in interrupt context.
138 @param Char Send a character to GDB
152 BufferSize
= sizeof (Char
);
153 Status
= gDebugPort
->Write (gDebugPort
, gTimeOut
, &BufferSize
, &Char
);
154 } while (EFI_ERROR (Status
) || BufferSize
!= sizeof (Char
));
160 Send an ASCII string to GDB. This function must be able to run in interrupt context.
163 @param String Send a string to GDB
172 // We could performance enhance this function by calling gDebugPort->Write ()
173 while (*String
!= '\0') {
174 GdbPutChar (*String
);