]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
Remove an inline assembly statement added for debug
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PeiDxeDebugLibReportStatusCode / DebugLib.c
... / ...
CommitLineData
1/** @file\r
2 Debug Library based on report status code library.\r
3\r
4 Copyright (c) 2006 - 2009, 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
18#include <Guid/StatusCodeDataTypeId.h>\r
19#include <Guid/StatusCodeDataTypeDebug.h>\r
20\r
21#include <Library/DebugLib.h>\r
22#include <Library/BaseLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/ReportStatusCodeLib.h>\r
25#include <Library/PcdLib.h>\r
26\r
27/**\r
28 Prints a debug message to the debug output device if the specified error level is enabled.\r
29\r
30 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
31 the message specified by Format and the associated variable argument list to \r
32 the debug output device.\r
33\r
34 If Format is NULL, then ASSERT().\r
35\r
36 @param ErrorLevel The error level of the debug message.\r
37 @param Format Format string for the debug message to print.\r
38 @param ... Variable argument list whose contents are accessed \r
39 based on the format string specified by Format.\r
40\r
41**/\r
42VOID\r
43EFIAPI\r
44DebugPrint (\r
45 IN UINTN ErrorLevel,\r
46 IN CONST CHAR8 *Format,\r
47 ...\r
48 )\r
49{\r
50 UINT64 Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];\r
51 EFI_DEBUG_INFO *DebugInfo;\r
52 UINTN TotalSize;\r
53 VA_LIST VaListMarker;\r
54 BASE_LIST BaseListMarker;\r
55 CHAR8 *FormatString;\r
56 BOOLEAN Long;\r
57 BOOLEAN Done;\r
58\r
59 //\r
60 // If Format is NULL, then ASSERT().\r
61 //\r
62 ASSERT (Format != NULL);\r
63\r
64 //\r
65 // Check driver Debug Level value and global debug level\r
66 //\r
67 if ((ErrorLevel & PcdGet32 (PcdDebugPrintErrorLevel)) == 0) {\r
68 return;\r
69 }\r
70\r
71 //\r
72 // Compute the total size of the record\r
73 //\r
74 TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);\r
75\r
76 //\r
77 // If the TotalSize is larger than the maximum record size, then return\r
78 //\r
79 if (TotalSize > sizeof (Buffer)) {\r
80 return;\r
81 }\r
82\r
83 //\r
84 // Fill in EFI_DEBUG_INFO\r
85 //\r
86 // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is\r
87 // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause\r
88 // exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO))\r
89 // just makes addess of BaseListMarker, which follows DebugInfo, 64-bit aligned.\r
90 //\r
91 DebugInfo = (EFI_DEBUG_INFO *)(Buffer) + 1;\r
92 DebugInfo->ErrorLevel = (UINT32)ErrorLevel;\r
93 BaseListMarker = (BASE_LIST)(DebugInfo + 1);\r
94 FormatString = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);\r
95\r
96 //\r
97 // Copy the Format string into the record\r
98 //\r
99 AsciiStrCpy (FormatString, Format);\r
100\r
101 //\r
102 // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
103 // of format in DEBUG string, which is followed by the DEBUG format string.\r
104 // Here we will process the variable arguments and pack them in this area.\r
105 //\r
106 VA_START (VaListMarker, Format);\r
107 for (; *Format != '\0'; Format++) {\r
108 //\r
109 // Only format with prefix % is processed.\r
110 //\r
111 if (*Format != '%') {\r
112 continue;\r
113 }\r
114 Long = FALSE;\r
115 //\r
116 // Parse Flags and Width\r
117 //\r
118 for (Done = FALSE; !Done; ) {\r
119 Format++;\r
120 switch (*Format) {\r
121 case '.': \r
122 case '-': \r
123 case '+': \r
124 case ' ': \r
125 case ',': \r
126 case '0':\r
127 case '1':\r
128 case '2':\r
129 case '3':\r
130 case '4':\r
131 case '5':\r
132 case '6':\r
133 case '7':\r
134 case '8':\r
135 case '9':\r
136 //\r
137 // These characters in format field are omitted.\r
138 //\r
139 break;\r
140 case 'L':\r
141 case 'l': \r
142 //\r
143 // 'L" or "l" in format field means the number being printed is a UINT64\r
144 //\r
145 Long = TRUE;\r
146 break;\r
147 case '*':\r
148 //\r
149 // '*' in format field means the precision of the field is specified by\r
150 // a UINTN argument in the argument list.\r
151 //\r
152 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
153 break;\r
154 case '\0':\r
155 //\r
156 // Make no output if Format string terminates unexpectedly when\r
157 // looking up for flag, width, precision and type. \r
158 //\r
159 Format--;\r
160 //\r
161 // break skipped on purpose.\r
162 //\r
163 default:\r
164 //\r
165 // When valid argument type detected or format string terminates unexpectedly,\r
166 // the inner loop is done.\r
167 //\r
168 Done = TRUE;\r
169 break;\r
170 }\r
171 } \r
172 \r
173 //\r
174 // Pack variable arguments into the storage area following EFI_DEBUG_INFO.\r
175 //\r
176 switch (*Format) {\r
177 case 'p':\r
178 if (sizeof (VOID *) > 4) {\r
179 Long = TRUE;\r
180 }\r
181 case 'X':\r
182 case 'x':\r
183 case 'd':\r
184 if (Long) {\r
185 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r
186 } else {\r
187 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r
188 }\r
189 break;\r
190 case 's':\r
191 case 'S':\r
192 case 'a':\r
193 case 'g':\r
194 case 't':\r
195 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r
196 break;\r
197 case 'c':\r
198 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
199 break;\r
200 case 'r':\r
201 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
202 break;\r
203 }\r
204\r
205 //\r
206 // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then ASSERT()\r
207 // This indicates that the DEBUG() macro is passing in more argument than can be handled by \r
208 // the EFI_DEBUG_INFO record\r
209 //\r
210 ASSERT ((CHAR8 *)BaseListMarker <= FormatString);\r
211\r
212 //\r
213 // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return\r
214 //\r
215 if ((CHAR8 *)BaseListMarker > FormatString) {\r
216 return;\r
217 }\r
218 }\r
219 VA_END (VaListMarker);\r
220\r
221 //\r
222 // Send the DebugInfo record\r
223 //\r
224 REPORT_STATUS_CODE_EX (\r
225 EFI_DEBUG_CODE,\r
226 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),\r
227 0,\r
228 NULL,\r
229 &gEfiStatusCodeDataTypeDebugGuid,\r
230 DebugInfo,\r
231 TotalSize\r
232 );\r
233}\r
234\r
235/**\r
236 Prints an assert message containing a filename, line number, and description. \r
237 This may be followed by a breakpoint or a dead loop.\r
238\r
239 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
240 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
241 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
242 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
243 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
244 returns immediately after the message is printed to the debug output device.\r
245 DebugAssert() must actively prevent recursion. If DebugAssert() is called while\r
246 processing another DebugAssert(), then DebugAssert() must return immediately.\r
247\r
248 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
249 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
250\r
251 @param FileName Pointer to the name of the source file that generated the assert condition.\r
252 @param LineNumber The line number in the source file that generated the assert condition\r
253 @param Description Pointer to the description of the assert condition.\r
254\r
255**/\r
256VOID\r
257EFIAPI\r
258DebugAssert (\r
259 IN CONST CHAR8 *FileName,\r
260 IN UINTN LineNumber,\r
261 IN CONST CHAR8 *Description\r
262 )\r
263{\r
264 UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];\r
265 EFI_DEBUG_ASSERT_DATA *AssertData;\r
266 UINTN TotalSize;\r
267 CHAR8 *Temp;\r
268 UINTN FileNameSize;\r
269 UINTN DescriptionSize;\r
270\r
271 //\r
272 // Make sure it will all fit in the passed in buffer\r
273 //\r
274 FileNameSize = AsciiStrSize (FileName);\r
275 DescriptionSize = AsciiStrSize (Description);\r
276 TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameSize + DescriptionSize;\r
277 if (TotalSize <= sizeof (Buffer)) {\r
278 //\r
279 // Fill in EFI_DEBUG_ASSERT_DATA\r
280 //\r
281 AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r
282 AssertData->LineNumber = (UINT32)LineNumber;\r
283\r
284 //\r
285 // Copy Ascii FileName including NULL.\r
286 //\r
287 Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);\r
288\r
289 //\r
290 // Copy Ascii Description\r
291 //\r
292 AsciiStrCpy (Temp + FileNameSize, Description);\r
293\r
294 REPORT_STATUS_CODE_EX (\r
295 (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r
296 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r
297 0,\r
298 NULL,\r
299 NULL,\r
300 AssertData,\r
301 TotalSize\r
302 );\r
303 }\r
304\r
305 //\r
306 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
307 //\r
308 if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
309 CpuBreakpoint ();\r
310 } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
311 CpuDeadLoop ();\r
312 }\r
313}\r
314\r
315\r
316/**\r
317 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
318\r
319 This function fills Length bytes of Buffer with the value specified by \r
320 PcdDebugClearMemoryValue, and returns Buffer.\r
321\r
322 If Buffer is NULL, then ASSERT().\r
323 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). \r
324\r
325 @param Buffer Pointer to the target buffer to be filled with PcdDebugClearMemoryValue.\r
326 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
327\r
328 @return Buffer Pointer to the target buffer filled with PcdDebugClearMemoryValue.\r
329\r
330**/\r
331VOID *\r
332EFIAPI\r
333DebugClearMemory (\r
334 OUT VOID *Buffer,\r
335 IN UINTN Length\r
336 )\r
337{\r
338 ASSERT (Buffer != NULL);\r
339\r
340 return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));\r
341}\r
342\r
343\r
344/**\r
345 Returns TRUE if ASSERT() macros are enabled.\r
346\r
347 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
348 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
349\r
350 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
351 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
352\r
353**/\r
354BOOLEAN\r
355EFIAPI\r
356DebugAssertEnabled (\r
357 VOID\r
358 )\r
359{\r
360 return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
361}\r
362\r
363\r
364/** \r
365 Returns TRUE if DEBUG() macros are enabled.\r
366\r
367 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
368 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
369\r
370 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
371 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
372\r
373**/\r
374BOOLEAN\r
375EFIAPI\r
376DebugPrintEnabled (\r
377 VOID\r
378 )\r
379{\r
380 return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
381}\r
382\r
383\r
384/** \r
385 Returns TRUE if DEBUG_CODE() macros are enabled.\r
386\r
387 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
388 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
389\r
390 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
391 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
392\r
393**/\r
394BOOLEAN\r
395EFIAPI\r
396DebugCodeEnabled (\r
397 VOID\r
398 )\r
399{\r
400 return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
401}\r
402\r
403\r
404/** \r
405 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.\r
406\r
407 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of \r
408 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
409\r
410 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
411 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
412\r
413**/\r
414BOOLEAN\r
415EFIAPI\r
416DebugClearMemoryEnabled (\r
417 VOID\r
418 )\r
419{\r
420 return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
421}\r