]>
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 | |
52 | UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];\r | |
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 |
78 | //\r | |
79 | // If the TotalSize is larger than the maximum record size, then ASSERT()\r | |
80 | //\r | |
1ca88083 | 81 | ASSERT (TotalSize <= sizeof (Buffer));\r |
ca9938b8 | 82 | \r |
83 | //\r | |
84 | // If the TotalSize is larger than the maximum record size, then return\r | |
85 | //\r | |
1ca88083 | 86 | if (TotalSize > sizeof (Buffer)) {\r |
2287f237 | 87 | return;\r |
88 | }\r | |
89 | \r | |
90 | //\r | |
ca9938b8 | 91 | // Fill in EFI_DEBUG_INFO\r |
2287f237 | 92 | //\r |
ca9938b8 | 93 | DebugInfo = (EFI_DEBUG_INFO *)Buffer;\r |
2287f237 | 94 | DebugInfo->ErrorLevel = (UINT32)ErrorLevel;\r |
ca9938b8 | 95 | BaseListMarker = (BASE_LIST)(DebugInfo + 1);\r |
3d7dfb38 | 96 | FormatString = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);\r |
ca9938b8 | 97 | \r |
98 | //\r | |
99 | // Copy the Format string into the record\r | |
100 | //\r | |
101 | AsciiStrCpy (FormatString, Format);\r | |
2287f237 | 102 | \r |
103 | //\r | |
104 | // 256 byte mini Var Arg stack. That is followed by the format string.\r | |
105 | //\r | |
ca9938b8 | 106 | VA_START (VaListMarker, Format);\r |
107 | for (; *Format != '\0'; Format++) {\r | |
108 | if (*Format != '%') {\r | |
109 | continue;\r | |
110 | }\r | |
111 | Long = FALSE;\r | |
112 | //\r | |
113 | // Parse Flags and Width\r | |
114 | //\r | |
115 | for (Done = FALSE; !Done; ) {\r | |
116 | Format++;\r | |
117 | switch (*Format) {\r | |
118 | case '.': \r | |
119 | case '-': \r | |
120 | case '+': \r | |
121 | case ' ': \r | |
122 | case ',': \r | |
123 | case '0':\r | |
124 | case '1':\r | |
125 | case '2':\r | |
126 | case '3':\r | |
127 | case '4':\r | |
128 | case '5':\r | |
129 | case '6':\r | |
130 | case '7':\r | |
131 | case '8':\r | |
132 | case '9':\r | |
133 | break;\r | |
134 | case 'L':\r | |
135 | case 'l': \r | |
136 | Long = TRUE;\r | |
137 | break;\r | |
138 | case '*':\r | |
139 | BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r | |
140 | break;\r | |
141 | case '\0':\r | |
142 | //\r | |
143 | // Make no output if Format string terminates unexpectedly when\r | |
144 | // looking up for flag, width, precision and type. \r | |
145 | //\r | |
146 | Format--;\r | |
147 | //\r | |
148 | // break skipped on purpose.\r | |
149 | //\r | |
150 | default:\r | |
151 | Done = TRUE;\r | |
152 | break;\r | |
153 | }\r | |
154 | } \r | |
155 | \r | |
156 | //\r | |
157 | // Handle each argument type\r | |
158 | //\r | |
159 | switch (*Format) {\r | |
160 | case 'p':\r | |
161 | if (sizeof (VOID *) > 4) {\r | |
162 | Long = TRUE;\r | |
163 | }\r | |
164 | case 'X':\r | |
165 | case 'x':\r | |
166 | case 'd':\r | |
167 | if (Long) {\r | |
168 | BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r | |
169 | } else {\r | |
170 | BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r | |
171 | }\r | |
172 | break;\r | |
173 | case 's':\r | |
174 | case 'S':\r | |
175 | case 'a':\r | |
176 | case 'g':\r | |
177 | case 't':\r | |
178 | BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r | |
179 | break;\r | |
180 | case 'c':\r | |
181 | BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r | |
182 | break;\r | |
183 | case 'r':\r | |
184 | BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r | |
185 | break;\r | |
186 | }\r | |
187 | \r | |
188 | //\r | |
189 | // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then ASSERT()\r | |
190 | // This indicates that the DEBUG() macro is passing in more argument than can be handled by \r | |
191 | // the EFI_DEBUG_INFO record\r | |
192 | //\r | |
3d7dfb38 | 193 | ASSERT ((CHAR8 *)BaseListMarker <= FormatString);\r |
ca9938b8 | 194 | \r |
195 | //\r | |
196 | // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return\r | |
197 | //\r | |
3d7dfb38 | 198 | if ((CHAR8 *)BaseListMarker > FormatString) {\r |
ca9938b8 | 199 | return;\r |
200 | }\r | |
2287f237 | 201 | }\r |
ca9938b8 | 202 | VA_END (VaListMarker);\r |
2287f237 | 203 | \r |
ca9938b8 | 204 | //\r |
205 | // Send the DebugInfo record\r | |
206 | //\r | |
2287f237 | 207 | REPORT_STATUS_CODE_EX (\r |
208 | EFI_DEBUG_CODE,\r | |
209 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),\r | |
210 | 0,\r | |
211 | NULL,\r | |
212 | &gEfiStatusCodeDataTypeDebugGuid,\r | |
213 | DebugInfo,\r | |
214 | TotalSize\r | |
215 | );\r | |
216 | }\r | |
217 | \r | |
2287f237 | 218 | /**\r |
219 | \r | |
220 | Prints an assert message containing a filename, line number, and description.\r | |
221 | This may be followed by a breakpoint or a dead loop.\r | |
222 | \r | |
223 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r | |
224 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r | |
225 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
226 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
227 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
228 | returns immediately after the message is printed to the debug output device.\r | |
584125bc | 229 | DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r |
2287f237 | 230 | processing another DebugAssert(), then DebugAssert() must return immediately.\r |
231 | \r | |
232 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
233 | \r | |
234 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
235 | \r | |
236 | @param FileName Pointer to the name of the source file that generated the assert condition.\r | |
237 | @param LineNumber The line number in the source file that generated the assert condition\r | |
238 | @param Description Pointer to the description of the assert condition.\r | |
239 | \r | |
240 | **/\r | |
241 | VOID\r | |
242 | EFIAPI\r | |
243 | DebugAssert (\r | |
244 | IN CONST CHAR8 *FileName,\r | |
245 | IN UINTN LineNumber,\r | |
246 | IN CONST CHAR8 *Description\r | |
247 | )\r | |
248 | {\r | |
249 | UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];\r | |
250 | EFI_DEBUG_ASSERT_DATA *AssertData;\r | |
251 | UINTN TotalSize;\r | |
252 | CHAR8 *Temp;\r | |
253 | UINTN FileNameLength;\r | |
254 | UINTN DescriptionLength;\r | |
255 | \r | |
256 | //\r | |
257 | // Make sure it will all fit in the passed in buffer\r | |
258 | //\r | |
259 | FileNameLength = AsciiStrLen (FileName);\r | |
260 | DescriptionLength = AsciiStrLen (Description);\r | |
261 | TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameLength + 1 + DescriptionLength + 1;\r | |
1ca88083 | 262 | if (TotalSize <= sizeof (Buffer)) {\r |
2287f237 | 263 | //\r |
264 | // Fill in EFI_DEBUG_ASSERT_DATA\r | |
265 | //\r | |
266 | AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r | |
267 | AssertData->LineNumber = (UINT32)LineNumber;\r | |
268 | \r | |
269 | //\r | |
270 | // Copy Ascii FileName including NULL.\r | |
271 | //\r | |
272 | Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);\r | |
273 | \r | |
274 | //\r | |
275 | // Copy Ascii Description\r | |
276 | //\r | |
277 | AsciiStrCpy (Temp + AsciiStrLen (FileName) + 1, Description);\r | |
278 | \r | |
8191cd5e | 279 | REPORT_STATUS_CODE_EX (\r |
2287f237 | 280 | (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r |
281 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r | |
8191cd5e LG |
282 | 0,\r |
283 | NULL,\r | |
1872ccab | 284 | NULL,\r |
2287f237 | 285 | AssertData,\r |
286 | TotalSize\r | |
287 | );\r | |
288 | }\r | |
289 | \r | |
290 | //\r | |
291 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
292 | //\r | |
293 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
294 | CpuBreakpoint ();\r | |
295 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
296 | CpuDeadLoop ();\r | |
297 | }\r | |
298 | }\r | |
299 | \r | |
300 | \r | |
301 | /**\r | |
302 | \r | |
303 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r | |
304 | \r | |
305 | This function fills Length bytes of Buffer with the value specified by\r | |
306 | PcdDebugClearMemoryValue, and returns Buffer.\r | |
307 | \r | |
308 | If Buffer is NULL, then ASSERT().\r | |
309 | \r | |
310 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r | |
311 | \r | |
312 | @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r | |
313 | @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r | |
314 | \r | |
315 | @return Buffer\r | |
316 | \r | |
317 | **/\r | |
318 | VOID *\r | |
319 | EFIAPI\r | |
320 | DebugClearMemory (\r | |
321 | OUT VOID *Buffer,\r | |
322 | IN UINTN Length\r | |
323 | )\r | |
324 | {\r | |
325 | //\r | |
326 | // If Buffer is NULL, then ASSERT().\r | |
327 | //\r | |
328 | ASSERT (Buffer != NULL);\r | |
329 | \r | |
330 | //\r | |
331 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
332 | //\r | |
333 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r | |
334 | }\r | |
335 | \r | |
336 | \r | |
337 | /**\r | |
338 | \r | |
339 | Returns TRUE if ASSERT() macros are enabled.\r | |
340 | \r | |
341 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r | |
342 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
343 | \r | |
344 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
345 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
346 | \r | |
347 | **/\r | |
348 | BOOLEAN\r | |
349 | EFIAPI\r | |
350 | DebugAssertEnabled (\r | |
351 | VOID\r | |
352 | )\r | |
353 | {\r | |
354 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r | |
355 | }\r | |
356 | \r | |
357 | \r | |
358 | /**\r | |
359 | \r | |
360 | Returns TRUE if DEBUG()macros are enabled.\r | |
361 | \r | |
362 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r | |
363 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
364 | \r | |
365 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
366 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
367 | \r | |
368 | **/\r | |
369 | BOOLEAN\r | |
370 | EFIAPI\r | |
371 | DebugPrintEnabled (\r | |
372 | VOID\r | |
373 | )\r | |
374 | {\r | |
375 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r | |
376 | }\r | |
377 | \r | |
378 | \r | |
379 | /**\r | |
380 | \r | |
381 | Returns TRUE if DEBUG_CODE()macros are enabled.\r | |
382 | \r | |
383 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r | |
384 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
385 | \r | |
386 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
387 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
388 | \r | |
389 | **/\r | |
390 | BOOLEAN\r | |
391 | EFIAPI\r | |
392 | DebugCodeEnabled (\r | |
393 | VOID\r | |
394 | )\r | |
395 | {\r | |
396 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
397 | }\r | |
398 | \r | |
399 | \r | |
400 | /**\r | |
401 | \r | |
402 | Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r | |
403 | \r | |
404 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of\r | |
405 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r | |
406 | \r | |
407 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r | |
408 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
409 | \r | |
410 | **/\r | |
411 | BOOLEAN\r | |
412 | EFIAPI\r | |
413 | DebugClearMemoryEnabled (\r | |
414 | VOID\r | |
415 | )\r | |
416 | {\r | |
417 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r | |
418 | }\r |