]>
Commit | Line | Data |
---|---|---|
b90aefa9 | 1 | /** @file\r |
61ac4fc7 | 2 | Base Debug library instance for hypervisor debug port.\r |
b90aefa9 | 3 | It uses PrintLib to send debug messages to a fixed I/O port.\r |
4 | \r | |
2fe5f2f5 | 5 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r |
b90aefa9 | 6 | Copyright (c) 2012, Red Hat, Inc.<BR>\r |
b26f0cf9 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
b90aefa9 | 8 | \r |
9 | **/\r | |
10 | \r | |
11 | #include <Base.h>\r | |
b90aefa9 | 12 | #include <Library/DebugLib.h>\r |
13 | #include <Library/BaseLib.h>\r | |
14 | #include <Library/IoLib.h>\r | |
15 | #include <Library/PrintLib.h>\r | |
16 | #include <Library/PcdLib.h>\r | |
17 | #include <Library/BaseMemoryLib.h>\r | |
18 | #include <Library/DebugPrintErrorLevelLib.h>\r | |
c09d9571 | 19 | #include "DebugLibDetect.h"\r |
b90aefa9 | 20 | \r |
21 | //\r | |
22 | // Define the maximum debug and assert message length that this library supports\r | |
23 | //\r | |
24 | #define MAX_DEBUG_MESSAGE_LENGTH 0x100\r | |
25 | \r | |
2fe5f2f5 BB |
26 | //\r |
27 | // VA_LIST can not initialize to NULL for all compiler, so we use this to\r | |
28 | // indicate a null VA_LIST\r | |
29 | //\r | |
30 | VA_LIST mVaListNull;\r | |
31 | \r | |
b90aefa9 | 32 | /**\r |
33 | Prints a debug message to the debug output device if the specified error level is enabled.\r | |
34 | \r | |
35 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
36 | GetDebugPrintErrorLevel (), then print the message specified by Format and the\r | |
37 | associated variable argument list to the debug output device.\r | |
38 | \r | |
39 | If Format is NULL, then ASSERT().\r | |
40 | \r | |
41 | @param ErrorLevel The error level of the debug message.\r | |
42 | @param Format Format string for the debug message to print.\r | |
43 | @param ... Variable argument list whose contents are accessed\r | |
44 | based on the format string specified by Format.\r | |
45 | \r | |
46 | **/\r | |
47 | VOID\r | |
48 | EFIAPI\r | |
49 | DebugPrint (\r | |
50 | IN UINTN ErrorLevel,\r | |
51 | IN CONST CHAR8 *Format,\r | |
52 | ...\r | |
53 | )\r | |
2fe5f2f5 BB |
54 | {\r |
55 | VA_LIST Marker;\r | |
56 | \r | |
57 | VA_START (Marker, Format);\r | |
58 | DebugVPrint (ErrorLevel, Format, Marker);\r | |
59 | VA_END (Marker);\r | |
60 | }\r | |
61 | \r | |
62 | \r | |
63 | /**\r | |
64 | Prints a debug message to the debug output device if the specified\r | |
65 | error level is enabled base on Null-terminated format string and a\r | |
66 | VA_LIST argument list or a BASE_LIST argument list.\r | |
67 | \r | |
68 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
69 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
70 | the associated variable argument list to the debug output device.\r | |
71 | \r | |
72 | If Format is NULL, then ASSERT().\r | |
73 | \r | |
74 | @param ErrorLevel The error level of the debug message.\r | |
75 | @param Format Format string for the debug message to print.\r | |
76 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
77 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
78 | \r | |
79 | **/\r | |
80 | VOID\r | |
81 | DebugPrintMarker (\r | |
82 | IN UINTN ErrorLevel,\r | |
83 | IN CONST CHAR8 *Format,\r | |
84 | IN VA_LIST VaListMarker,\r | |
85 | IN BASE_LIST BaseListMarker\r | |
86 | )\r | |
b90aefa9 | 87 | {\r |
88 | CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
80886a69 | 89 | UINTN Length;\r |
b90aefa9 | 90 | \r |
91 | //\r | |
92 | // If Format is NULL, then ASSERT().\r | |
93 | //\r | |
94 | ASSERT (Format != NULL);\r | |
95 | \r | |
96 | //\r | |
c09d9571 | 97 | // Check if the global mask disables this message or the device is inactive\r |
b90aefa9 | 98 | //\r |
c09d9571 PB |
99 | if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0 ||\r |
100 | !PlatformDebugLibIoPortFound ()) {\r | |
b90aefa9 | 101 | return;\r |
102 | }\r | |
103 | \r | |
104 | //\r | |
105 | // Convert the DEBUG() message to an ASCII String\r | |
106 | //\r | |
2fe5f2f5 BB |
107 | if (BaseListMarker == NULL) {\r |
108 | Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);\r | |
109 | } else {\r | |
110 | Length = AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);\r | |
111 | }\r | |
b90aefa9 | 112 | \r |
113 | //\r | |
114 | // Send the print string to the debug I/O port\r | |
115 | //\r | |
80886a69 | 116 | IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r |
2fe5f2f5 BB |
117 | }\r |
118 | \r | |
119 | \r | |
120 | /**\r | |
121 | Prints a debug message to the debug output device if the specified\r | |
122 | error level is enabled.\r | |
123 | \r | |
124 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
125 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
126 | the associated variable argument list to the debug output device.\r | |
127 | \r | |
128 | If Format is NULL, then ASSERT().\r | |
129 | \r | |
130 | @param ErrorLevel The error level of the debug message.\r | |
131 | @param Format Format string for the debug message to print.\r | |
132 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
133 | \r | |
134 | **/\r | |
135 | VOID\r | |
136 | EFIAPI\r | |
137 | DebugVPrint (\r | |
138 | IN UINTN ErrorLevel,\r | |
139 | IN CONST CHAR8 *Format,\r | |
140 | IN VA_LIST VaListMarker\r | |
141 | )\r | |
142 | {\r | |
143 | DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r | |
144 | }\r | |
145 | \r | |
146 | \r | |
147 | /**\r | |
148 | Prints a debug message to the debug output device if the specified\r | |
149 | error level is enabled.\r | |
150 | This function use BASE_LIST which would provide a more compatible\r | |
151 | service than VA_LIST.\r | |
152 | \r | |
153 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
154 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
155 | the associated variable argument list to the debug output device.\r | |
156 | \r | |
157 | If Format is NULL, then ASSERT().\r | |
158 | \r | |
159 | @param ErrorLevel The error level of the debug message.\r | |
160 | @param Format Format string for the debug message to print.\r | |
161 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
162 | \r | |
163 | **/\r | |
164 | VOID\r | |
165 | EFIAPI\r | |
166 | DebugBPrint (\r | |
167 | IN UINTN ErrorLevel,\r | |
168 | IN CONST CHAR8 *Format,\r | |
169 | IN BASE_LIST BaseListMarker\r | |
170 | )\r | |
171 | {\r | |
172 | DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r | |
b90aefa9 | 173 | }\r |
174 | \r | |
175 | \r | |
176 | /**\r | |
177 | Prints an assert message containing a filename, line number, and description.\r | |
178 | This may be followed by a breakpoint or a dead loop.\r | |
179 | \r | |
180 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r | |
181 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r | |
182 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
183 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
184 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
185 | returns immediately after the message is printed to the debug output device.\r | |
186 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r | |
187 | processing another DebugAssert(), then DebugAssert() must return immediately.\r | |
188 | \r | |
189 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
190 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
191 | \r | |
192 | @param FileName The pointer to the name of the source file that generated the assert condition.\r | |
193 | @param LineNumber The line number in the source file that generated the assert condition\r | |
194 | @param Description The pointer to the description of the assert condition.\r | |
195 | \r | |
196 | **/\r | |
197 | VOID\r | |
198 | EFIAPI\r | |
199 | DebugAssert (\r | |
200 | IN CONST CHAR8 *FileName,\r | |
201 | IN UINTN LineNumber,\r | |
202 | IN CONST CHAR8 *Description\r | |
203 | )\r | |
204 | {\r | |
205 | CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
80886a69 | 206 | UINTN Length;\r |
b90aefa9 | 207 | \r |
208 | //\r | |
209 | // Generate the ASSERT() message in Ascii format\r | |
210 | //\r | |
80886a69 LE |
211 | Length = AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n",\r |
212 | FileName, (UINT64)LineNumber, Description);\r | |
b90aefa9 | 213 | \r |
214 | //\r | |
c09d9571 | 215 | // Send the print string to the debug I/O port, if present\r |
b90aefa9 | 216 | //\r |
c09d9571 PB |
217 | if (PlatformDebugLibIoPortFound ()) {\r |
218 | IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r | |
219 | }\r | |
b90aefa9 | 220 | \r |
221 | //\r | |
222 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
223 | //\r | |
224 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
225 | CpuBreakpoint ();\r | |
226 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
227 | CpuDeadLoop ();\r | |
228 | }\r | |
229 | }\r | |
230 | \r | |
231 | \r | |
232 | /**\r | |
233 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r | |
234 | \r | |
235 | This function fills Length bytes of Buffer with the value specified by\r | |
236 | PcdDebugClearMemoryValue, and returns Buffer.\r | |
237 | \r | |
238 | If Buffer is NULL, then ASSERT().\r | |
239 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
240 | \r | |
241 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r | |
242 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r | |
243 | \r | |
244 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r | |
245 | \r | |
246 | **/\r | |
247 | VOID *\r | |
248 | EFIAPI\r | |
249 | DebugClearMemory (\r | |
250 | OUT VOID *Buffer,\r | |
251 | IN UINTN Length\r | |
252 | )\r | |
253 | {\r | |
254 | //\r | |
255 | // If Buffer is NULL, then ASSERT().\r | |
256 | //\r | |
257 | ASSERT (Buffer != NULL);\r | |
258 | \r | |
259 | //\r | |
260 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
261 | //\r | |
262 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r | |
263 | }\r | |
264 | \r | |
265 | \r | |
266 | /**\r | |
267 | Returns TRUE if ASSERT() macros are enabled.\r | |
268 | \r | |
269 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r | |
270 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
271 | \r | |
272 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
273 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
274 | \r | |
275 | **/\r | |
276 | BOOLEAN\r | |
277 | EFIAPI\r | |
278 | DebugAssertEnabled (\r | |
279 | VOID\r | |
280 | )\r | |
281 | {\r | |
282 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r | |
283 | }\r | |
284 | \r | |
285 | \r | |
286 | /**\r | |
287 | Returns TRUE if DEBUG() macros are enabled.\r | |
288 | \r | |
289 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r | |
290 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
291 | \r | |
292 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
293 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
294 | \r | |
295 | **/\r | |
296 | BOOLEAN\r | |
297 | EFIAPI\r | |
298 | DebugPrintEnabled (\r | |
299 | VOID\r | |
300 | )\r | |
301 | {\r | |
302 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r | |
303 | }\r | |
304 | \r | |
305 | \r | |
306 | /**\r | |
307 | Returns TRUE if DEBUG_CODE() macros are enabled.\r | |
308 | \r | |
309 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
310 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
311 | \r | |
312 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
313 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
314 | \r | |
315 | **/\r | |
316 | BOOLEAN\r | |
317 | EFIAPI\r | |
318 | DebugCodeEnabled (\r | |
319 | VOID\r | |
320 | )\r | |
321 | {\r | |
322 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
323 | }\r | |
324 | \r | |
325 | \r | |
326 | /**\r | |
327 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r | |
328 | \r | |
329 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r | |
330 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
331 | \r | |
332 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r | |
333 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
334 | \r | |
335 | **/\r | |
336 | BOOLEAN\r | |
337 | EFIAPI\r | |
338 | DebugClearMemoryEnabled (\r | |
339 | VOID\r | |
340 | )\r | |
341 | {\r | |
342 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r | |
343 | }\r | |
344 | \r | |
5e795f93 LG |
345 | /**\r |
346 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
347 | \r | |
348 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
349 | \r | |
350 | @retval TRUE Current ErrorLevel is supported.\r | |
351 | @retval FALSE Current ErrorLevel is not supported.\r | |
352 | \r | |
353 | **/\r | |
354 | BOOLEAN\r | |
355 | EFIAPI\r | |
356 | DebugPrintLevelEnabled (\r | |
357 | IN CONST UINTN ErrorLevel\r | |
358 | )\r | |
359 | {\r | |
360 | return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r | |
361 | }\r | |
c09d9571 PB |
362 | \r |
363 | /**\r | |
364 | Return the result of detecting the debug I/O port device.\r | |
365 | \r | |
366 | @retval TRUE if the debug I/O port device was detected.\r | |
367 | @retval FALSE otherwise\r | |
368 | \r | |
369 | **/\r | |
370 | BOOLEAN\r | |
371 | EFIAPI\r | |
372 | PlatformDebugLibIoPortDetect (\r | |
373 | VOID\r | |
374 | )\r | |
375 | {\r | |
376 | return IoRead8 (PcdGet16 (PcdDebugIoPort)) == BOCHS_DEBUG_PORT_MAGIC;\r | |
377 | }\r |