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