Commit | Line | Data |
---|---|---|
2287f237 | 1 | /** @file\r |
2 | Debug Library that fowards all messages to ReportStatusCode()\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | \r | |
16 | \r | |
17 | #include <FrameworkPei.h>\r | |
551ed06f | 18 | #include <FrameworkModuleBase.h>\r |
2287f237 | 19 | #include <Guid/StatusCodeDataTypeId.h>\r |
3a6064fa | 20 | #include <Guid/StatusCodeDataTypeDebug.h>\r |
2287f237 | 21 | \r |
22 | #include <Library/DebugLib.h>\r | |
23 | #include <Library/BaseLib.h>\r | |
24 | #include <Library/BaseMemoryLib.h>\r | |
25 | #include <Library/ReportStatusCodeLib.h>\r | |
26 | #include <Library/PcdLib.h>\r | |
27 | \r | |
2287f237 | 28 | /**\r |
29 | \r | |
30 | Prints a debug message to the debug output device if the specified error level is enabled.\r | |
31 | \r | |
32 | If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print\r | |
33 | the message specified by Format and the associated variable argument list to\r | |
34 | the debug output device.\r | |
35 | \r | |
36 | If Format is NULL, then ASSERT().\r | |
37 | \r | |
38 | @param ErrorLevel The error level of the debug message.\r | |
39 | @param Format Format string for the debug message to print.\r | |
967c09fa | 40 | @param ... Variable argument list whose contents are accessed \r |
41 | based on the format string specified by Format.\r | |
2287f237 | 42 | \r |
43 | **/\r | |
44 | VOID\r | |
45 | EFIAPI\r | |
46 | DebugPrint (\r | |
47 | IN UINTN ErrorLevel,\r | |
48 | IN CONST CHAR8 *Format,\r | |
49 | ...\r | |
50 | )\r | |
51 | {\r | |
6916d99c | 52 | UINT64 Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];\r |
2287f237 | 53 | EFI_DEBUG_INFO *DebugInfo;\r |
54 | UINTN TotalSize;\r | |
ca9938b8 | 55 | VA_LIST VaListMarker;\r |
56 | BASE_LIST BaseListMarker;\r | |
57 | CHAR8 *FormatString;\r | |
58 | BOOLEAN Long;\r | |
59 | BOOLEAN Done;\r | |
2287f237 | 60 | \r |
61 | //\r | |
62 | // If Format is NULL, then ASSERT().\r | |
63 | //\r | |
64 | ASSERT (Format != NULL);\r | |
65 | \r | |
66 | //\r | |
67 | // Check driver Debug Level value and global debug level\r | |
68 | //\r | |
69 | if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r | |
70 | return;\r | |
71 | }\r | |
72 | \r | |
ca9938b8 | 73 | //\r |
74 | // Compute the total size of the record\r | |
75 | //\r | |
2287f237 | 76 | TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrLen (Format) + 1;\r |
ca9938b8 | 77 | \r |
ca9938b8 | 78 | //\r |
79 | // If the TotalSize is larger than the maximum record size, then return\r | |
80 | //\r | |
1ca88083 | 81 | if (TotalSize > sizeof (Buffer)) {\r |
2287f237 | 82 | return;\r |
83 | }\r | |
84 | \r | |
85 | //\r | |
ca9938b8 | 86 | // Fill in EFI_DEBUG_INFO\r |
2287f237 | 87 | //\r |
6916d99c | 88 | DebugInfo = (EFI_DEBUG_INFO *)(Buffer) + 1;\r |
2287f237 | 89 | DebugInfo->ErrorLevel = (UINT32)ErrorLevel;\r |
ca9938b8 | 90 | BaseListMarker = (BASE_LIST)(DebugInfo + 1);\r |
3d7dfb38 | 91 | FormatString = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);\r |
ca9938b8 | 92 | \r |
93 | //\r | |
94 | // Copy the Format string into the record\r | |
95 | //\r | |
96 | AsciiStrCpy (FormatString, Format);\r | |
2287f237 | 97 | \r |
98 | //\r | |
99 | // 256 byte mini Var Arg stack. That is followed by the format string.\r | |
100 | //\r | |
ca9938b8 | 101 | VA_START (VaListMarker, Format);\r |
102 | for (; *Format != '\0'; Format++) {\r | |
103 | if (*Format != '%') {\r | |
104 | continue;\r | |
105 | }\r | |
106 | Long = FALSE;\r | |
107 | //\r | |
108 | // Parse Flags and Width\r | |
109 | //\r | |
110 | for (Done = FALSE; !Done; ) {\r | |
111 | Format++;\r | |
112 | switch (*Format) {\r | |
113 | case '.': \r | |
114 | case '-': \r | |
115 | case '+': \r | |
116 | case ' ': \r | |
117 | case ',': \r | |
118 | case '0':\r | |
119 | case '1':\r | |
120 | case '2':\r | |
121 | case '3':\r | |
122 | case '4':\r | |
123 | case '5':\r | |
124 | case '6':\r | |
125 | case '7':\r | |
126 | case '8':\r | |
127 | case '9':\r | |
128 | break;\r | |
129 | case 'L':\r | |
130 | case 'l': \r | |
131 | Long = TRUE;\r | |
132 | break;\r | |
133 | case '*':\r | |
134 | BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r | |
135 | break;\r | |
136 | case '\0':\r | |
137 | //\r | |
138 | // Make no output if Format string terminates unexpectedly when\r | |
139 | // looking up for flag, width, precision and type. \r | |
140 | //\r | |
141 | Format--;\r | |
142 | //\r | |
143 | // break skipped on purpose.\r | |
144 | //\r | |
145 | default:\r | |
146 | Done = TRUE;\r | |
147 | break;\r | |
148 | }\r | |
149 | } \r | |
150 | \r | |
151 | //\r | |
152 | // Handle each argument type\r | |
153 | //\r | |
154 | switch (*Format) {\r | |
155 | case 'p':\r | |
156 | if (sizeof (VOID *) > 4) {\r | |
157 | Long = TRUE;\r | |
158 | }\r | |
159 | case 'X':\r | |
160 | case 'x':\r | |
161 | case 'd':\r | |
162 | if (Long) {\r | |
163 | BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r | |
164 | } else {\r | |
165 | BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r | |
166 | }\r | |
167 | break;\r | |
168 | case 's':\r | |
169 | case 'S':\r | |
170 | case 'a':\r | |
171 | case 'g':\r | |
172 | case 't':\r | |
173 | BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r | |
174 | break;\r | |
175 | case 'c':\r | |
176 | BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r | |
177 | break;\r | |
178 | case 'r':\r | |
179 | BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r | |
180 | break;\r | |
181 | }\r | |
182 | \r | |
183 | //\r | |
184 | // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then ASSERT()\r | |
185 | // This indicates that the DEBUG() macro is passing in more argument than can be handled by \r | |
186 | // the EFI_DEBUG_INFO record\r | |
187 | //\r | |
3d7dfb38 | 188 | ASSERT ((CHAR8 *)BaseListMarker <= FormatString);\r |
ca9938b8 | 189 | \r |
190 | //\r | |
191 | // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return\r | |
192 | //\r | |
3d7dfb38 | 193 | if ((CHAR8 *)BaseListMarker > FormatString) {\r |
ca9938b8 | 194 | return;\r |
195 | }\r | |
2287f237 | 196 | }\r |
ca9938b8 | 197 | VA_END (VaListMarker);\r |
2287f237 | 198 | \r |
ca9938b8 | 199 | //\r |
200 | // Send the DebugInfo record\r | |
201 | //\r | |
2287f237 | 202 | REPORT_STATUS_CODE_EX (\r |
203 | EFI_DEBUG_CODE,\r | |
204 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),\r | |
205 | 0,\r | |
206 | NULL,\r | |
207 | &gEfiStatusCodeDataTypeDebugGuid,\r | |
208 | DebugInfo,\r | |
209 | TotalSize\r | |
210 | );\r | |
211 | }\r | |
212 | \r | |
2287f237 | 213 | /**\r |
214 | \r | |
215 | Prints an assert message containing a filename, line number, and description.\r | |
216 | This may be followed by a breakpoint or a dead loop.\r | |
217 | \r | |
218 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r | |
219 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r | |
220 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
221 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
222 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
223 | returns immediately after the message is printed to the debug output device.\r | |
584125bc | 224 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r |
2287f237 | 225 | processing another DebugAssert(), then DebugAssert() must return immediately.\r |
226 | \r | |
227 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
228 | \r | |
229 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
230 | \r | |
231 | @param FileName Pointer to the name of the source file that generated the assert condition.\r | |
232 | @param LineNumber The line number in the source file that generated the assert condition\r | |
233 | @param Description Pointer to the description of the assert condition.\r | |
234 | \r | |
235 | **/\r | |
236 | VOID\r | |
237 | EFIAPI\r | |
238 | DebugAssert (\r | |
239 | IN CONST CHAR8 *FileName,\r | |
240 | IN UINTN LineNumber,\r | |
241 | IN CONST CHAR8 *Description\r | |
242 | )\r | |
243 | {\r | |
244 | UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];\r | |
245 | EFI_DEBUG_ASSERT_DATA *AssertData;\r | |
246 | UINTN TotalSize;\r | |
247 | CHAR8 *Temp;\r | |
248 | UINTN FileNameLength;\r | |
249 | UINTN DescriptionLength;\r | |
250 | \r | |
251 | //\r | |
252 | // Make sure it will all fit in the passed in buffer\r | |
253 | //\r | |
254 | FileNameLength = AsciiStrLen (FileName);\r | |
255 | DescriptionLength = AsciiStrLen (Description);\r | |
256 | TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameLength + 1 + DescriptionLength + 1;\r | |
1ca88083 | 257 | if (TotalSize <= sizeof (Buffer)) {\r |
2287f237 | 258 | //\r |
259 | // Fill in EFI_DEBUG_ASSERT_DATA\r | |
260 | //\r | |
261 | AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r | |
262 | AssertData->LineNumber = (UINT32)LineNumber;\r | |
263 | \r | |
264 | //\r | |
265 | // Copy Ascii FileName including NULL.\r | |
266 | //\r | |
267 | Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);\r | |
268 | \r | |
269 | //\r | |
270 | // Copy Ascii Description\r | |
271 | //\r | |
272 | AsciiStrCpy (Temp + AsciiStrLen (FileName) + 1, Description);\r | |
273 | \r | |
8191cd5e | 274 | REPORT_STATUS_CODE_EX (\r |
2287f237 | 275 | (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r |
276 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r | |
8191cd5e LG |
277 | 0,\r |
278 | NULL,\r | |
1872ccab | 279 | NULL,\r |
2287f237 | 280 | AssertData,\r |
281 | TotalSize\r | |
282 | );\r | |
283 | }\r | |
284 | \r | |
285 | //\r | |
286 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
287 | //\r | |
288 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
289 | CpuBreakpoint ();\r | |
290 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
291 | CpuDeadLoop ();\r | |
292 | }\r | |
293 | }\r | |
294 | \r | |
295 | \r | |
296 | /**\r | |
297 | \r | |
298 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r | |
299 | \r | |
300 | This function fills Length bytes of Buffer with the value specified by\r | |
301 | PcdDebugClearMemoryValue, and returns Buffer.\r | |
302 | \r | |
303 | If Buffer is NULL, then ASSERT().\r | |
304 | \r | |
305 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r | |
306 | \r | |
307 | @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r | |
308 | @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r | |
309 | \r | |
310 | @return Buffer\r | |
311 | \r | |
312 | **/\r | |
313 | VOID *\r | |
314 | EFIAPI\r | |
315 | DebugClearMemory (\r | |
316 | OUT VOID *Buffer,\r | |
317 | IN UINTN Length\r | |
318 | )\r | |
319 | {\r | |
320 | //\r | |
321 | // If Buffer is NULL, then ASSERT().\r | |
322 | //\r | |
323 | ASSERT (Buffer != NULL);\r | |
324 | \r | |
325 | //\r | |
326 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
327 | //\r | |
328 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r | |
329 | }\r | |
330 | \r | |
331 | \r | |
332 | /**\r | |
333 | \r | |
334 | Returns TRUE if ASSERT() macros are enabled.\r | |
335 | \r | |
336 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r | |
337 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
338 | \r | |
339 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
340 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
341 | \r | |
342 | **/\r | |
343 | BOOLEAN\r | |
344 | EFIAPI\r | |
345 | DebugAssertEnabled (\r | |
346 | VOID\r | |
347 | )\r | |
348 | {\r | |
349 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r | |
350 | }\r | |
351 | \r | |
352 | \r | |
353 | /**\r | |
354 | \r | |
355 | Returns TRUE if DEBUG()macros are enabled.\r | |
356 | \r | |
357 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r | |
358 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
359 | \r | |
360 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
361 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
362 | \r | |
363 | **/\r | |
364 | BOOLEAN\r | |
365 | EFIAPI\r | |
366 | DebugPrintEnabled (\r | |
367 | VOID\r | |
368 | )\r | |
369 | {\r | |
370 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r | |
371 | }\r | |
372 | \r | |
373 | \r | |
374 | /**\r | |
375 | \r | |
376 | Returns TRUE if DEBUG_CODE()macros are enabled.\r | |
377 | \r | |
378 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
379 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
380 | \r | |
381 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
382 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
383 | \r | |
384 | **/\r | |
385 | BOOLEAN\r | |
386 | EFIAPI\r | |
387 | DebugCodeEnabled (\r | |
388 | VOID\r | |
389 | )\r | |
390 | {\r | |
391 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
392 | }\r | |
393 | \r | |
394 | \r | |
395 | /**\r | |
396 | \r | |
397 | Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r | |
398 | \r | |
399 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of\r | |
400 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
401 | \r | |
402 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r | |
403 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
404 | \r | |
405 | **/\r | |
406 | BOOLEAN\r | |
407 | EFIAPI\r | |
408 | DebugClearMemoryEnabled (\r | |
409 | VOID\r | |
410 | )\r | |
411 | {\r | |
412 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r | |
413 | }\r |