]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
eceb3a4c | 2 | UEFI Debug Library that sends messages to the Console Output Device in the EFI System Table.\r |
e386b444 | 3 | \r |
ec81dba5 | 4 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e386b444 | 6 | \r |
7 | **/\r | |
8 | \r | |
c7d265a9 | 9 | #include <Uefi.h>\r |
c892d846 | 10 | \r |
c7d265a9 | 11 | #include <Library/DebugLib.h>\r |
c7d265a9 | 12 | #include <Library/PrintLib.h>\r |
13 | #include <Library/PcdLib.h>\r | |
14 | #include <Library/BaseLib.h>\r | |
15 | #include <Library/BaseMemoryLib.h>\r | |
2891fc8b | 16 | #include <Library/DebugPrintErrorLevelLib.h>\r |
c7d265a9 | 17 | \r |
e386b444 | 18 | //\r |
9095d37b | 19 | // Define the maximum debug and assert message length that this library supports\r |
e386b444 | 20 | //\r |
21 | #define MAX_DEBUG_MESSAGE_LENGTH 0x100\r | |
22 | \r | |
ec81dba5 BB |
23 | //\r |
24 | // VA_LIST can not initialize to NULL for all compiler, so we use this to\r | |
25 | // indicate a null VA_LIST\r | |
26 | //\r | |
27 | VA_LIST mVaListNull;\r | |
28 | \r | |
452702d0 AA |
29 | extern BOOLEAN mPostEBS;\r |
30 | extern EFI_SYSTEM_TABLE *mDebugST;\r | |
31 | \r | |
e386b444 | 32 | /**\r |
e386b444 | 33 | Prints a debug message to the debug output device if the specified error level is enabled.\r |
34 | \r | |
9095d37b LG |
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 | |
2891fc8b | 37 | associated variable argument list to the debug output device.\r |
e386b444 | 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 | |
9095d37b | 43 | @param ... A variable argument list whose contents are accessed\r |
285010e7 | 44 | based on the format string specified by Format.\r |
e386b444 | 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 | |
54 | {\r | |
e386b444 | 55 | VA_LIST Marker;\r |
56 | \r | |
ec81dba5 BB |
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 | |
87 | {\r | |
88 | CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
89 | \r | |
452702d0 AA |
90 | if (!mPostEBS) {\r |
91 | //\r | |
92 | // If Format is NULL, then ASSERT().\r | |
93 | //\r | |
94 | ASSERT (Format != NULL);\r | |
95 | \r | |
96 | //\r | |
97 | // Check driver debug mask value and global mask\r | |
98 | //\r | |
99 | if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {\r | |
100 | return;\r | |
101 | }\r | |
102 | \r | |
103 | //\r | |
104 | // Convert the DEBUG() message to a Unicode String\r | |
105 | //\r | |
106 | if (BaseListMarker == NULL) {\r | |
107 | UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, VaListMarker);\r | |
108 | } else {\r | |
109 | UnicodeBSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, BaseListMarker);\r | |
110 | }\r | |
111 | \r | |
112 | \r | |
113 | //\r | |
114 | // Send the print string to the Console Output device\r | |
115 | //\r | |
116 | if ((mDebugST != NULL) && (mDebugST->ConOut != NULL)) {\r | |
117 | mDebugST->ConOut->OutputString (mDebugST->ConOut, Buffer);\r | |
118 | }\r | |
e386b444 | 119 | }\r |
120 | }\r | |
121 | \r | |
122 | \r | |
ec81dba5 BB |
123 | /**\r |
124 | Prints a debug message to the debug output device if the specified\r | |
125 | error level is enabled.\r | |
126 | \r | |
127 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
128 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
129 | the associated variable argument list to the debug output device.\r | |
130 | \r | |
131 | If Format is NULL, then ASSERT().\r | |
132 | \r | |
133 | @param ErrorLevel The error level of the debug message.\r | |
134 | @param Format Format string for the debug message to print.\r | |
135 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
136 | \r | |
137 | **/\r | |
138 | VOID\r | |
139 | EFIAPI\r | |
140 | DebugVPrint (\r | |
141 | IN UINTN ErrorLevel,\r | |
142 | IN CONST CHAR8 *Format,\r | |
143 | IN VA_LIST VaListMarker\r | |
144 | )\r | |
145 | {\r | |
146 | DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r | |
147 | }\r | |
148 | \r | |
149 | \r | |
150 | /**\r | |
151 | Prints a debug message to the debug output device if the specified\r | |
152 | error level is enabled.\r | |
153 | This function use BASE_LIST which would provide a more compatible\r | |
154 | service than VA_LIST.\r | |
155 | \r | |
156 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
157 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
158 | the associated variable argument list to the debug output device.\r | |
159 | \r | |
160 | If Format is NULL, then ASSERT().\r | |
161 | \r | |
162 | @param ErrorLevel The error level of the debug message.\r | |
163 | @param Format Format string for the debug message to print.\r | |
164 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
165 | \r | |
166 | **/\r | |
167 | VOID\r | |
168 | EFIAPI\r | |
169 | DebugBPrint (\r | |
170 | IN UINTN ErrorLevel,\r | |
171 | IN CONST CHAR8 *Format,\r | |
172 | IN BASE_LIST BaseListMarker\r | |
173 | )\r | |
174 | {\r | |
175 | DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r | |
176 | }\r | |
177 | \r | |
178 | \r | |
e386b444 | 179 | /**\r |
9095d37b | 180 | Prints an assert message containing a filename, line number, and description.\r |
e386b444 | 181 | This may be followed by a breakpoint or a dead loop.\r |
182 | \r | |
3e5c3238 | 183 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r |
9095d37b LG |
184 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r |
185 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
186 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
187 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
e386b444 | 188 | returns immediately after the message is printed to the debug output device.\r |
3e5c3238 | 189 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r |
e386b444 | 190 | processing another DebugAssert(), then DebugAssert() must return immediately.\r |
191 | \r | |
192 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
e386b444 | 193 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r |
194 | \r | |
9095d37b | 195 | @param FileName The pointer to the name of the source file that generated\r |
58380e9c | 196 | the assert condition.\r |
9095d37b | 197 | @param LineNumber The line number in the source file that generated the\r |
58380e9c | 198 | assert condition\r |
2fc59a00 | 199 | @param Description The pointer to the description of the assert condition.\r |
e386b444 | 200 | \r |
201 | **/\r | |
202 | VOID\r | |
203 | EFIAPI\r | |
204 | DebugAssert (\r | |
205 | IN CONST CHAR8 *FileName,\r | |
206 | IN UINTN LineNumber,\r | |
207 | IN CONST CHAR8 *Description\r | |
208 | )\r | |
209 | {\r | |
210 | CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
211 | \r | |
452702d0 AA |
212 | if (!mPostEBS) {\r |
213 | //\r | |
214 | // Generate the ASSERT() message in Unicode format\r | |
215 | //\r | |
216 | UnicodeSPrintAsciiFormat (\r | |
217 | Buffer,\r | |
218 | sizeof (Buffer),\r | |
219 | "ASSERT [%a] %a(%d): %a\n",\r | |
220 | gEfiCallerBaseName,\r | |
221 | FileName,\r | |
222 | LineNumber,\r | |
223 | Description\r | |
224 | );\r | |
225 | \r | |
226 | //\r | |
227 | // Send the print string to the Console Output device\r | |
228 | //\r | |
229 | if ((mDebugST != NULL) && (mDebugST->ConOut != NULL)) {\r | |
230 | mDebugST->ConOut->OutputString (mDebugST->ConOut, Buffer);\r | |
231 | }\r | |
232 | \r | |
233 | //\r | |
234 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
235 | //\r | |
236 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
237 | CpuBreakpoint ();\r | |
238 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
239 | CpuDeadLoop ();\r | |
240 | }\r | |
e386b444 | 241 | }\r |
242 | }\r | |
243 | \r | |
244 | \r | |
245 | /**\r | |
e386b444 | 246 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r |
247 | \r | |
9095d37b | 248 | This function fills Length bytes of Buffer with the value specified by\r |
e386b444 | 249 | PcdDebugClearMemoryValue, and returns Buffer.\r |
250 | \r | |
251 | If Buffer is NULL, then ASSERT().\r | |
9095d37b | 252 | If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r |
e386b444 | 253 | \r |
2fc59a00 | 254 | @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r |
9095d37b | 255 | @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r |
e386b444 | 256 | \r |
2fc59a00 | 257 | @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.\r |
e386b444 | 258 | \r |
259 | **/\r | |
260 | VOID *\r | |
261 | EFIAPI\r | |
262 | DebugClearMemory (\r | |
263 | OUT VOID *Buffer,\r | |
264 | IN UINTN Length\r | |
265 | )\r | |
266 | {\r | |
267 | //\r | |
268 | // If Buffer is NULL, then ASSERT().\r | |
269 | //\r | |
270 | ASSERT (Buffer != NULL);\r | |
271 | \r | |
272 | //\r | |
273 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
274 | //\r | |
275 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r | |
276 | }\r | |
277 | \r | |
278 | \r | |
279 | /**\r | |
e386b444 | 280 | Returns TRUE if ASSERT() macros are enabled.\r |
281 | \r | |
9095d37b | 282 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r |
e386b444 | 283 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
284 | \r | |
285 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
286 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
287 | \r | |
288 | **/\r | |
289 | BOOLEAN\r | |
290 | EFIAPI\r | |
291 | DebugAssertEnabled (\r | |
292 | VOID\r | |
293 | )\r | |
294 | {\r | |
295 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r | |
296 | }\r | |
297 | \r | |
298 | \r | |
9095d37b | 299 | /**\r |
3e5c3238 | 300 | Returns TRUE if DEBUG() macros are enabled.\r |
e386b444 | 301 | \r |
9095d37b | 302 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r |
e386b444 | 303 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
304 | \r | |
305 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
306 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
307 | \r | |
308 | **/\r | |
309 | BOOLEAN\r | |
310 | EFIAPI\r | |
311 | DebugPrintEnabled (\r | |
312 | VOID\r | |
313 | )\r | |
314 | {\r | |
315 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r | |
316 | }\r | |
317 | \r | |
318 | \r | |
9095d37b | 319 | /**\r |
3e5c3238 | 320 | Returns TRUE if DEBUG_CODE() macros are enabled.\r |
e386b444 | 321 | \r |
9095d37b | 322 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r |
e386b444 | 323 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
324 | \r | |
325 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
326 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
327 | \r | |
328 | **/\r | |
329 | BOOLEAN\r | |
330 | EFIAPI\r | |
331 | DebugCodeEnabled (\r | |
332 | VOID\r | |
333 | )\r | |
334 | {\r | |
335 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
336 | }\r | |
337 | \r | |
338 | \r | |
9095d37b | 339 | /**\r |
3e5c3238 | 340 | Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r |
e386b444 | 341 | \r |
9095d37b | 342 | This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of\r |
e386b444 | 343 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
344 | \r | |
eceb3a4c LG |
345 | @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r |
346 | @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
e386b444 | 347 | \r |
348 | **/\r | |
349 | BOOLEAN\r | |
350 | EFIAPI\r | |
351 | DebugClearMemoryEnabled (\r | |
352 | VOID\r | |
353 | )\r | |
354 | {\r | |
355 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r | |
356 | }\r | |
dfbe4d27 LG |
357 | \r |
358 | /**\r | |
359 | Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
360 | \r | |
361 | This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.\r | |
362 | \r | |
363 | @retval TRUE Current ErrorLevel is supported.\r | |
364 | @retval FALSE Current ErrorLevel is not supported.\r | |
365 | \r | |
366 | **/\r | |
367 | BOOLEAN\r | |
368 | EFIAPI\r | |
369 | DebugPrintLevelEnabled (\r | |
370 | IN CONST UINTN ErrorLevel\r | |
371 | )\r | |
372 | {\r | |
373 | return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);\r | |
374 | }\r |