TianoCore EDK2 master
Loading...
Searching...
No Matches
GdbSerialDebugPortLib.c
Go to the documentation of this file.
1
10#include <Uefi.h>
12#include <Library/PcdLib.h>
13#include <Library/IoLib.h>
14#include <Library/DebugLib.h>
16
17#include <Protocol/DebugPort.h>
18
19EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL;
20UINT32 gTimeOut = 0;
21
31RETURN_STATUS
32EFIAPI
34 IN EFI_HANDLE ImageHandle,
35 IN EFI_SYSTEM_TABLE *SystemTable
36 )
37{
38 EFI_STATUS Status;
39
40 Status = gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **)&gDebugPort);
41 if (!EFI_ERROR (Status)) {
42 gTimeOut = PcdGet32 (PcdGdbMaxPacketRetryCount);
43 gDebugPort->Reset (gDebugPort);
44 }
45
46 return Status;
47}
48
68RETURN_STATUS
69EFIAPI
71 IN UINT64 BaudRate,
72 IN UINT8 Parity,
73 IN UINT8 DataBits,
74 IN UINT8 StopBits
75 )
76{
77 EFI_STATUS Status;
78
79 Status = gDebugPort->Reset (gDebugPort);
80 return Status;
81}
82
91BOOLEAN
92EFIAPI
94 VOID
95 )
96{
97 EFI_STATUS Status;
98
99 Status = gDebugPort->Poll (gDebugPort);
100
101 return (Status == EFI_SUCCESS ? TRUE : FALSE);
102}
103
110CHAR8
111EFIAPI
113 VOID
114 )
115{
116 EFI_STATUS Status;
117 CHAR8 Char;
118 UINTN BufferSize;
119
120 do {
121 BufferSize = sizeof (Char);
122 Status = gDebugPort->Read (gDebugPort, gTimeOut, &BufferSize, &Char);
123 } while (EFI_ERROR (Status) || BufferSize != sizeof (Char));
124
125 return Char;
126}
127
135VOID
136EFIAPI
138 IN CHAR8 Char
139 )
140{
141 EFI_STATUS Status;
142 UINTN BufferSize;
143
144 do {
145 BufferSize = sizeof (Char);
146 Status = gDebugPort->Write (gDebugPort, gTimeOut, &BufferSize, &Char);
147 } while (EFI_ERROR (Status) || BufferSize != sizeof (Char));
148
149 return;
150}
151
159VOID
161 IN CHAR8 *String
162 )
163{
164 // We could performance enhance this function by calling gDebugPort->Write ()
165 while (*String != '\0') {
166 GdbPutChar (*String);
167 String++;
168 }
169}
UINT64 UINTN
VOID GdbPutString(IN CHAR8 *String)
CHAR8 EFIAPI GdbGetChar(VOID)
BOOLEAN EFIAPI GdbIsCharAvailable(VOID)
RETURN_STATUS EFIAPI GdbSerialLibDebugPortConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI GdbPutChar(IN CHAR8 Char)
RETURN_STATUS EFIAPI GdbSerialInit(IN UINT64 BaudRate, IN UINT8 Parity, IN UINT8 DataBits, IN UINT8 StopBits)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS