]>
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 | |
ac0a286f | 30 | VA_LIST mVaListNull;\r |
2fe5f2f5 | 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 | 54 | {\r |
ac0a286f | 55 | VA_LIST Marker;\r |
2fe5f2f5 BB |
56 | \r |
57 | VA_START (Marker, Format);\r | |
58 | DebugVPrint (ErrorLevel, Format, Marker);\r | |
59 | VA_END (Marker);\r | |
60 | }\r | |
61 | \r | |
2fe5f2f5 BB |
62 | /**\r |
63 | Prints a debug message to the debug output device if the specified\r | |
64 | error level is enabled base on Null-terminated format string and a\r | |
65 | VA_LIST argument list or a BASE_LIST argument list.\r | |
66 | \r | |
67 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
68 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
69 | the associated variable argument list to the debug output device.\r | |
70 | \r | |
71 | If Format is NULL, then ASSERT().\r | |
72 | \r | |
73 | @param ErrorLevel The error level of the debug message.\r | |
74 | @param Format Format string for the debug message to print.\r | |
75 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
76 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
77 | \r | |
78 | **/\r | |
79 | VOID\r | |
80 | DebugPrintMarker (\r | |
ac0a286f MK |
81 | IN UINTN ErrorLevel,\r |
82 | IN CONST CHAR8 *Format,\r | |
83 | IN VA_LIST VaListMarker,\r | |
84 | IN BASE_LIST BaseListMarker\r | |
2fe5f2f5 | 85 | )\r |
b90aefa9 | 86 | {\r |
ac0a286f MK |
87 | CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r |
88 | UINTN Length;\r | |
b90aefa9 | 89 | \r |
90 | //\r | |
91 | // If Format is NULL, then ASSERT().\r | |
92 | //\r | |
93 | ASSERT (Format != NULL);\r | |
94 | \r | |
95 | //\r | |
c09d9571 | 96 | // Check if the global mask disables this message or the device is inactive\r |
b90aefa9 | 97 | //\r |
ac0a286f MK |
98 | if (((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) ||\r |
99 | !PlatformDebugLibIoPortFound ())\r | |
100 | {\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 | |
2fe5f2f5 BB |
119 | /**\r |
120 | Prints a debug message to the debug output device if the specified\r | |
121 | error level is enabled.\r | |
122 | \r | |
123 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
124 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
125 | the associated variable argument list to the debug output device.\r | |
126 | \r | |
127 | If Format is NULL, then ASSERT().\r | |
128 | \r | |
129 | @param ErrorLevel The error level of the debug message.\r | |
130 | @param Format Format string for the debug message to print.\r | |
131 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
132 | \r | |
133 | **/\r | |
134 | VOID\r | |
135 | EFIAPI\r | |
136 | DebugVPrint (\r | |
ac0a286f MK |
137 | IN UINTN ErrorLevel,\r |
138 | IN CONST CHAR8 *Format,\r | |
139 | IN VA_LIST VaListMarker\r | |
2fe5f2f5 BB |
140 | )\r |
141 | {\r | |
142 | DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r | |
143 | }\r | |
144 | \r | |
2fe5f2f5 BB |
145 | /**\r |
146 | Prints a debug message to the debug output device if the specified\r | |
147 | error level is enabled.\r | |
148 | This function use BASE_LIST which would provide a more compatible\r | |
149 | service than VA_LIST.\r | |
150 | \r | |
151 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
152 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
153 | the associated variable argument list to the debug output device.\r | |
154 | \r | |
155 | If Format is NULL, then ASSERT().\r | |
156 | \r | |
157 | @param ErrorLevel The error level of the debug message.\r | |
158 | @param Format Format string for the debug message to print.\r | |
159 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
160 | \r | |
161 | **/\r | |
162 | VOID\r | |
163 | EFIAPI\r | |
164 | DebugBPrint (\r | |
ac0a286f MK |
165 | IN UINTN ErrorLevel,\r |
166 | IN CONST CHAR8 *Format,\r | |
167 | IN BASE_LIST BaseListMarker\r | |
2fe5f2f5 BB |
168 | )\r |
169 | {\r | |
170 | DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r | |
b90aefa9 | 171 | }\r |
172 | \r | |
b90aefa9 | 173 | /**\r |
174 | Prints an assert message containing a filename, line number, and description.\r | |
175 | This may be followed by a breakpoint or a dead loop.\r | |
176 | \r | |
177 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r | |
178 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r | |
179 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
180 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
181 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
182 | returns immediately after the message is printed to the debug output device.\r | |
183 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r | |
184 | processing another DebugAssert(), then DebugAssert() must return immediately.\r | |
185 | \r | |
186 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
187 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
188 | \r | |
189 | @param FileName The pointer to the name of the source file that generated the assert condition.\r | |
190 | @param LineNumber The line number in the source file that generated the assert condition\r | |
191 | @param Description The pointer to the description of the assert condition.\r | |
192 | \r | |
193 | **/\r | |
194 | VOID\r | |
195 | EFIAPI\r | |
196 | DebugAssert (\r | |
197 | IN CONST CHAR8 *FileName,\r | |
198 | IN UINTN LineNumber,\r | |
199 | IN CONST CHAR8 *Description\r | |
200 | )\r | |
201 | {\r | |
202 | CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
80886a69 | 203 | UINTN Length;\r |
b90aefa9 | 204 | \r |
205 | //\r | |
206 | // Generate the ASSERT() message in Ascii format\r | |
207 | //\r | |
ac0a286f MK |
208 | Length = AsciiSPrint (\r |
209 | Buffer,\r | |
210 | sizeof Buffer,\r | |
211 | "ASSERT %a(%Lu): %a\n",\r | |
212 | FileName,\r | |
213 | (UINT64)LineNumber,\r | |
214 | Description\r | |
215 | );\r | |
b90aefa9 | 216 | \r |
217 | //\r | |
c09d9571 | 218 | // Send the print string to the debug I/O port, if present\r |
b90aefa9 | 219 | //\r |
c09d9571 PB |
220 | if (PlatformDebugLibIoPortFound ()) {\r |
221 | IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);\r | |
222 | }\r | |
b90aefa9 | 223 | \r |
224 | //\r | |
225 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
226 | //\r | |
ac0a286f | 227 | if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r |
b90aefa9 | 228 | CpuBreakpoint ();\r |
ac0a286f | 229 | } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r |
b90aefa9 | 230 | CpuDeadLoop ();\r |
231 | }\r | |
232 | }\r | |
233 | \r | |
b90aefa9 | 234 | /**\r |
235 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r | |
236 | \r | |
237 | This function fills Length bytes of Buffer with the value specified by\r | |
238 | PcdDebugClearMemoryValue, and returns Buffer.\r | |
239 | \r | |
240 | If Buffer is NULL, then ASSERT().\r | |
241 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r | |
242 | \r | |
243 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r | |
244 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r | |
245 | \r | |
246 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r | |
247 | \r | |
248 | **/\r | |
249 | VOID *\r | |
250 | EFIAPI\r | |
251 | DebugClearMemory (\r | |
252 | OUT VOID *Buffer,\r | |
253 | IN UINTN Length\r | |
254 | )\r | |
255 | {\r | |
256 | //\r | |
257 | // If Buffer is NULL, then ASSERT().\r | |
258 | //\r | |
259 | ASSERT (Buffer != NULL);\r | |
260 | \r | |
261 | //\r | |
262 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
263 | //\r | |
ac0a286f | 264 | return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));\r |
b90aefa9 | 265 | }\r |
266 | \r | |
b90aefa9 | 267 | /**\r |
268 | Returns TRUE if ASSERT() macros are enabled.\r | |
269 | \r | |
270 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r | |
271 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
272 | \r | |
273 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
274 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
275 | \r | |
276 | **/\r | |
277 | BOOLEAN\r | |
278 | EFIAPI\r | |
279 | DebugAssertEnabled (\r | |
280 | VOID\r | |
281 | )\r | |
282 | {\r | |
ac0a286f | 283 | return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r |
b90aefa9 | 284 | }\r |
285 | \r | |
b90aefa9 | 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 | |
ac0a286f | 302 | return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r |
b90aefa9 | 303 | }\r |
304 | \r | |
b90aefa9 | 305 | /**\r |
306 | Returns TRUE if DEBUG_CODE() macros are enabled.\r | |
307 | \r | |
308 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
309 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
310 | \r | |
311 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
312 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
313 | \r | |
314 | **/\r | |
315 | BOOLEAN\r | |
316 | EFIAPI\r | |
317 | DebugCodeEnabled (\r | |
318 | VOID\r | |
319 | )\r | |
320 | {\r | |
ac0a286f | 321 | return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r |
b90aefa9 | 322 | }\r |
323 | \r | |
b90aefa9 | 324 | /**\r |
325 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r | |
326 | \r | |
327 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r | |
328 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
329 | \r | |
330 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r | |
331 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
332 | \r | |
333 | **/\r | |
334 | BOOLEAN\r | |
335 | EFIAPI\r | |
336 | DebugClearMemoryEnabled (\r | |
337 | VOID\r | |
338 | )\r | |
339 | {\r | |
ac0a286f | 340 | return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r |
b90aefa9 | 341 | }\r |
342 | \r | |
5e795f93 LG |
343 | /**\r |
344 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
345 | \r | |
346 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
347 | \r | |
348 | @retval TRUE Current ErrorLevel is supported.\r | |
349 | @retval FALSE Current ErrorLevel is not supported.\r | |
350 | \r | |
351 | **/\r | |
352 | BOOLEAN\r | |
353 | EFIAPI\r | |
354 | DebugPrintLevelEnabled (\r | |
ac0a286f | 355 | IN CONST UINTN ErrorLevel\r |
5e795f93 LG |
356 | )\r |
357 | {\r | |
ac0a286f | 358 | return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);\r |
5e795f93 | 359 | }\r |