]>
Commit | Line | Data |
---|---|---|
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 | |
19 | \r | |
20 | EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL;\r | |
21 | UINTN gTimeOut = 0;\r | |
22 | \r | |
23 | /**\r | |
24 | The constructor function initializes the UART.\r | |
25 | \r | |
26 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
27 | @param SystemTable A pointer to the EFI System Table.\r | |
28 | \r | |
29 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
30 | \r | |
31 | **/\r | |
32 | RETURN_STATUS\r | |
33 | EFIAPI\r | |
34 | GdbSerialLibDebugPortConstructor (\r | |
35 | IN EFI_HANDLE ImageHandle,\r | |
36 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
37 | )\r | |
38 | {\r | |
39 | EFI_STATUS Status;\r | |
40 | \r | |
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 | |
46 | \r | |
47 | return Status;\r | |
48 | }\r | |
49 | \r | |
50 | \r | |
51 | \r | |
52 | /**\r | |
53 | Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,\r | |
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 | |
62 | value of 0 will use the device's default data bit setting.\r | |
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 | |
68 | @retval EFI_DEVICE_ERROR The serial device could not be configured.\r | |
69 | \r | |
70 | **/\r | |
71 | RETURN_STATUS\r | |
72 | EFIAPI\r | |
73 | GdbSerialInit (\r | |
74 | IN UINT64 BaudRate,\r | |
75 | IN UINT8 Parity,\r | |
76 | IN UINT8 DataBits,\r | |
77 | IN UINT8 StopBits\r | |
78 | )\r | |
79 | {\r | |
80 | EFI_STATUS Status;\r | |
81 | \r | |
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 | |
91 | @return TRUE - Character available\r | |
92 | @return FALSE - Character not available\r | |
93 | \r | |
94 | **/\r | |
95 | BOOLEAN\r | |
96 | EFIAPI\r | |
97 | GdbIsCharAvailable (\r | |
98 | VOID\r | |
99 | )\r | |
100 | {\r | |
101 | EFI_STATUS Status;\r | |
102 | \r | |
103 | Status = gDebugPort->Poll (gDebugPort);\r | |
104 | \r | |
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 | |
113 | \r | |
114 | **/\r | |
115 | CHAR8\r | |
116 | EFIAPI\r | |
117 | GdbGetChar (\r | |
118 | VOID\r | |
119 | )\r | |
120 | {\r | |
121 | EFI_STATUS Status;\r | |
122 | CHAR8 Char;\r | |
123 | UINTN BufferSize;\r | |
124 | \r | |
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 | |
129 | \r | |
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 | |
142 | VOID\r | |
143 | EFIAPI\r | |
144 | GdbPutChar (\r | |
145 | IN CHAR8 Char\r | |
146 | )\r | |
147 | {\r | |
148 | EFI_STATUS Status;\r | |
149 | UINTN BufferSize;\r | |
150 | \r | |
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 | |
155 | \r | |
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 | |
167 | VOID\r | |
168 | GdbPutString (\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 |