]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/GdbSerialDebugPortLib/GdbSerialDebugPortLib.c
EmbeddedPkg: Fix various typos
[mirror_edk2.git] / EmbeddedPkg / Library / GdbSerialDebugPortLib / GdbSerialDebugPortLib.c
CommitLineData
2ef2b01e 1/** @file\r
c6a72cd7 2 Basic serial IO abstraction for GDB\r
2ef2b01e 3\r
60274cca 4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
3402aac7 5\r
878b807a 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
2ef2b01e
A
7\r
8**/\r
9\r
10#include <Uefi.h>\r
11#include <Library/GdbSerialLib.h>\r
12#include <Library/PcdLib.h>\r
13#include <Library/IoLib.h>\r
14#include <Library/DebugLib.h>\r
15#include <Library/UefiBootServicesTableLib.h>\r
16\r
17#include <Protocol/DebugPort.h>\r
18\r
19\r
20EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL;\r
21UINTN gTimeOut = 0;\r
22\r
23/**\r
24 The constructor function initializes the UART.\r
3402aac7 25\r
2ef2b01e
A
26 @param ImageHandle The firmware allocated handle for the EFI image.\r
27 @param SystemTable A pointer to the EFI System Table.\r
3402aac7 28\r
2ef2b01e
A
29 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
30\r
31**/\r
32RETURN_STATUS\r
33EFIAPI\r
34GdbSerialLibDebugPortConstructor (\r
35 IN EFI_HANDLE ImageHandle,\r
36 IN EFI_SYSTEM_TABLE *SystemTable\r
37 )\r
38{\r
39 EFI_STATUS Status;\r
3402aac7 40\r
2ef2b01e
A
41 Status = gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **)&gDebugPort);\r
42 if (!EFI_ERROR (Status)) {\r
43 gTimeOut = PcdGet32 (PcdGdbMaxPacketRetryCount);\r
44 gDebugPort->Reset (gDebugPort);\r
45 }\r
3402aac7 46\r
2ef2b01e
A
47 return Status;\r
48}\r
49\r
50\r
51\r
52/**\r
c6a72cd7 53 Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,\r
2ef2b01e
A
54 data buts, and stop bits on a serial device. This call is optional as the serial\r
55 port will be set up with defaults base on PCD values.\r
56\r
57 @param BaudRate The requested baud rate. A BaudRate value of 0 will use the the\r
58 device's default interface speed.\r
59 @param Parity The type of parity to use on this serial device. A Parity value of\r
60 DefaultParity will use the device's default parity value.\r
61 @param DataBits The number of data bits to use on the serial device. A DataBits\r
c6a72cd7 62 value of 0 will use the device's default data bit setting.\r
2ef2b01e
A
63 @param StopBits The number of stop bits to use on this serial device. A StopBits\r
64 value of DefaultStopBits will use the device's default number of\r
65 stop bits.\r
66\r
67 @retval EFI_SUCCESS The device was configured.\r
c6a72cd7 68 @retval EFI_DEVICE_ERROR The serial device could not be configured.\r
2ef2b01e
A
69\r
70**/\r
71RETURN_STATUS\r
72EFIAPI\r
73GdbSerialInit (\r
3402aac7
RC
74 IN UINT64 BaudRate,\r
75 IN UINT8 Parity,\r
76 IN UINT8 DataBits,\r
77 IN UINT8 StopBits\r
2ef2b01e
A
78 )\r
79{\r
80 EFI_STATUS Status;\r
3402aac7 81\r
2ef2b01e
A
82 Status = gDebugPort->Reset (gDebugPort);\r
83 return Status;\r
84}\r
85\r
86\r
87/**\r
88 Check to see if a character is available from GDB. Do not read the character as that is\r
89 done via GdbGetChar().\r
90\r
4f0624e8
GL
91 @return TRUE - Character available\r
92 @return FALSE - Character not available\r
3402aac7 93\r
2ef2b01e
A
94**/\r
95BOOLEAN\r
96EFIAPI\r
97GdbIsCharAvailable (\r
98 VOID\r
3402aac7 99 )\r
2ef2b01e
A
100{\r
101 EFI_STATUS Status;\r
3402aac7 102\r
2ef2b01e 103 Status = gDebugPort->Poll (gDebugPort);\r
3402aac7 104\r
2ef2b01e
A
105 return (Status == EFI_SUCCESS ? TRUE : FALSE);\r
106}\r
107\r
108\r
109/**\r
110 Get a character from GDB. This function must be able to run in interrupt context.\r
111\r
112 @return A character from GDB\r
3402aac7 113\r
2ef2b01e
A
114**/\r
115CHAR8\r
116EFIAPI\r
117GdbGetChar (\r
118 VOID\r
119 )\r
120{\r
121 EFI_STATUS Status;\r
122 CHAR8 Char;\r
123 UINTN BufferSize;\r
3402aac7 124\r
2ef2b01e
A
125 do {\r
126 BufferSize = sizeof (Char);\r
127 Status = gDebugPort->Read (gDebugPort, gTimeOut, &BufferSize, &Char);\r
128 } while (EFI_ERROR (Status) || BufferSize != sizeof (Char));\r
3402aac7 129\r
2ef2b01e
A
130 return Char;\r
131}\r
132\r
133\r
134/**\r
135 Send a character to GDB. This function must be able to run in interrupt context.\r
136\r
137\r
138 @param Char Send a character to GDB\r
139\r
140**/\r
141\r
142VOID\r
143EFIAPI\r
144GdbPutChar (\r
145 IN CHAR8 Char\r
146 )\r
147{\r
148 EFI_STATUS Status;\r
149 UINTN BufferSize;\r
3402aac7 150\r
2ef2b01e
A
151 do {\r
152 BufferSize = sizeof (Char);\r
153 Status = gDebugPort->Write (gDebugPort, gTimeOut, &BufferSize, &Char);\r
154 } while (EFI_ERROR (Status) || BufferSize != sizeof (Char));\r
3402aac7 155\r
2ef2b01e
A
156 return;\r
157}\r
158\r
159/**\r
160 Send an ASCII string to GDB. This function must be able to run in interrupt context.\r
161\r
162\r
163 @param String Send a string to GDB\r
164\r
165**/\r
166\r
167VOID\r
168GdbPutString (\r
169 IN CHAR8 *String\r
170 )\r
171{\r
172 // We could performance enhance this function by calling gDebugPort->Write ()\r
173 while (*String != '\0') {\r
174 GdbPutChar (*String);\r
175 String++;\r
176 }\r
177}\r
178\r
179\r
180\r
181\r