]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Include/Library/EdkIIGlueDebugLib.h
Add new DEBUG_VERBOSE print error level.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Include / Library / EdkIIGlueDebugLib.h
CommitLineData
3eb9473e 1/*++\r
2\r
9a8e70ce 3Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
2c7e5c2f 4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name:\r
14\r
15 EdkIIGlueDebugLib.h\r
16 \r
17Abstract: \r
18\r
19 Public include file for the Debug Library\r
20\r
21--*/\r
22\r
23#ifndef __EDKII_GLUE_DEBUG_LIB_H__\r
24#define __EDKII_GLUE_DEBUG_LIB_H__\r
25\r
26//\r
8598a1ed 27// To use EDKII code, these EDK macros are undefined\r
3eb9473e 28//\r
29#undef ASSERT\r
30#undef DEBUG\r
31#undef ASSERT_EFI_ERROR\r
32#undef ASSERT_PROTOCOL_ALREADY_INSTALLED\r
33#undef DEBUG_CODE\r
34#undef CR\r
35\r
36#undef EFI_D_INIT\r
37#undef EFI_D_WARN\r
38#undef EFI_D_LOAD\r
39#undef EFI_D_FS\r
40#undef EFI_D_POOL\r
41#undef EFI_D_PAGE\r
42#undef EFI_D_INFO\r
43#undef EFI_D_VARIABLE\r
44#undef EFI_D_BM \r
45#undef EFI_D_BLKIO\r
46#undef EFI_D_NET \r
47#undef EFI_D_UNDI\r
48#undef EFI_D_LOADFILE\r
49#undef EFI_D_EVENT\r
9a8e70ce 50#undef EFI_D_VERBOSE\r
3eb9473e 51#undef EFI_D_ERROR\r
52\r
53//\r
54// Declare bits for PcdDebugPropertyMask\r
55//\r
56#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01\r
57#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02\r
58#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04\r
59#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08\r
60#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10\r
61#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20\r
62\r
63//\r
64// Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint()\r
65//\r
66#define DEBUG_INIT 0x00000001 // Initialization\r
67#define DEBUG_WARN 0x00000002 // Warnings\r
68#define DEBUG_LOAD 0x00000004 // Load events\r
69#define DEBUG_FS 0x00000008 // EFI File system\r
70#define DEBUG_POOL 0x00000010 // Alloc & Free's\r
71#define DEBUG_PAGE 0x00000020 // Alloc & Free's\r
9a8e70ce 72#define DEBUG_INFO 0x00000040 // Informational debug messages\r
3eb9473e 73#define DEBUG_VARIABLE 0x00000100 // Variable\r
74#define DEBUG_BM 0x00000400 // Boot Manager\r
75#define DEBUG_BLKIO 0x00001000 // BlkIo Driver\r
76#define DEBUG_NET 0x00004000 // SNI Driver\r
77#define DEBUG_UNDI 0x00010000 // UNDI Driver\r
78#define DEBUG_LOADFILE 0x00020000 // UNDI Driver\r
79#define DEBUG_EVENT 0x00080000 // Event messages\r
9a8e70ce 80#define DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may significantly impact boot performance\r
3eb9473e 81#define DEBUG_ERROR 0x80000000 // Error\r
82\r
83//\r
84// Aliases of debug message mask bits\r
85//\r
86#define EFI_D_INIT DEBUG_INIT\r
87#define EFI_D_WARN DEBUG_WARN\r
88#define EFI_D_LOAD DEBUG_LOAD\r
89#define EFI_D_FS DEBUG_FS\r
90#define EFI_D_POOL DEBUG_POOL\r
91#define EFI_D_PAGE DEBUG_PAGE\r
92#define EFI_D_INFO DEBUG_INFO\r
93#define EFI_D_VARIABLE DEBUG_VARIABLE\r
94#define EFI_D_BM DEBUG_BM\r
95#define EFI_D_BLKIO DEBUG_BLKIO\r
96#define EFI_D_NET DEBUG_NET\r
97#define EFI_D_UNDI DEBUG_UNDI\r
98#define EFI_D_LOADFILE DEBUG_LOADFILE\r
99#define EFI_D_EVENT DEBUG_EVENT\r
9a8e70ce 100#define EFI_D_VERBOSE DEBUG_VERBOSE\r
3eb9473e 101#define EFI_D_ERROR DEBUG_ERROR\r
102\r
c7f33ca4 103\r
104//\r
105// Use the following 4 macros to save size\r
106//\r
107#define DebugAssertEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0))\r
108\r
109#define DebugPrintEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0))\r
110\r
111#define DebugCodeEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0))\r
112\r
113#define DebugClearMemoryEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0))\r
114\r
115\r
3eb9473e 116/**\r
117\r
118 Prints a debug message to the debug output device if the specified error level is enabled.\r
119\r
120 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
121 the message specified by Format and the associated variable argument list to \r
122 the debug output device.\r
123\r
124 If Format is NULL, then ASSERT().\r
125\r
126 @param ErrorLevel The error level of the debug message.\r
127 @param Format Format string for the debug message to print.\r
128\r
129**/\r
130VOID\r
131EFIAPI\r
132DebugPrint (\r
133 IN UINTN ErrorLevel,\r
134 IN CONST CHAR8 *Format,\r
135 ...\r
136 );\r
137\r
138\r
139/**\r
140\r
141 Prints an assert message containing a filename, line number, and description. \r
142 This may be followed by a breakpoint or a dead loop.\r
143\r
144 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
145 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
146 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
147 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
148 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
149 returns immediately after the message is printed to the debug output device.\r
150 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
151 processing another DebugAssert(), then DebugAssert() must return immediately.\r
152\r
153 If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.\r
154\r
155 If Description is NULL, then a <Description> string of ?NULL) Description?is printed.\r
156\r
157 @param FileName Pointer to the name of the source file that generated the assert condition.\r
158 @param LineNumber The line number in the source file that generated the assert condition\r
159 @param Description Pointer to the description of the assert condition.\r
160\r
161**/\r
162VOID\r
163EFIAPI\r
164DebugAssert (\r
165 IN CONST CHAR8 *FileName,\r
166 IN UINTN LineNumber,\r
167 IN CONST CHAR8 *Description\r
168 );\r
169\r
170\r
171/**\r
172\r
173 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
174\r
175 This function fills Length bytes of Buffer with the value specified by \r
176 PcdDebugClearMemoryValue, and returns Buffer.\r
177\r
178 If Buffer is NULL, then ASSERT().\r
179\r
180 If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT(). \r
181\r
182 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
183 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
184\r
185 @return Buffer\r
186\r
187**/\r
188VOID *\r
189EFIAPI\r
190DebugClearMemory (\r
191 OUT VOID *Buffer,\r
192 IN UINTN Length\r
193 );\r
194\r
195\r
3eb9473e 196/**\r
197 \r
198 Internal worker macro that calls DebugAssert().\r
199\r
200 This macro calls DebugAssert() passing in the filename, line number, and \r
201 expression that evailated to FALSE.\r
202\r
203 @param Expression Boolean expression that evailated to FALSE\r
204\r
205**/\r
c7f33ca4 206#ifdef EFI_DEBUG\r
3eb9473e 207#define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)\r
c7f33ca4 208#else\r
209#define _ASSERT(Expression)\r
3eb9473e 210\r
c7f33ca4 211#endif\r
3eb9473e 212\r
213/**\r
214 \r
215 Internal worker macro that calls DebugPrint().\r
216\r
217 This macro calls DebugPrint() passing in the debug error level, a format \r
218 string, and a variable argument list.\r
219\r
220 @param Expression Expression containing an error level, a format string, \r
221 and a variable argument list based on the format string.\r
222\r
223**/\r
c7f33ca4 224#ifdef EFI_DEBUG\r
16bd006b 225/*\r
226 EdkCompatibilityPkg\Foundation\Include\EfiDebug.h\r
227 //\r
228 // DEBUG((DebugLevel, "format string", ...)) - if DebugLevel is active do \r
229 // the a debug print.\r
230 //\r
231 #define DEBUG(arg) EfiDebugPrint arg\r
232\r
233 To pass ICC build, undef the previously defined _DEBUG.\r
234*/ \r
235#undef _DEBUG\r
3eb9473e 236#define _DEBUG(Expression) DebugPrint Expression\r
c7f33ca4 237#else\r
238#define _DEBUG(Expression)\r
3eb9473e 239\r
c7f33ca4 240#endif\r
3eb9473e 241\r
242/**\r
243 \r
244 Macro that calls DebugAssert() if a expression evaluates to FALSE.\r
245\r
246 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
247 then this macro evaluates the Boolean expression specified by Expression. If \r
248 Expression evaluates to FALSE, then DebugAssert() is called passing in the \r
249 source filename, source line number, and Expression.\r
250\r
251 @param Expression Boolean expression\r
252\r
253**/\r
254#ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION\r
255 // Glue Library internal\r
256 \r
257 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE\r
258 #ifdef EFI_DEBUG\r
259 #define ASSERT(Expression) \\r
260 do { \\r
261 if (DebugAssertEnabled ()) { \\r
262 if (!(Expression)) { \\r
263 _ASSERT (Expression); \\r
264 } \\r
265 } \\r
266 } while (FALSE)\r
267 #endif\r
268 #else\r
269 #define ASSERT(Expression) do{} while(0)\r
270 #endif \r
271\r
272#else\r
273 // External usage\r
274\r
275 #ifdef EFI_DEBUG\r
276 #define ASSERT(Expression) \\r
277 do { \\r
278 if (DebugAssertEnabled ()) { \\r
279 if (!(Expression)) { \\r
280 _ASSERT (Expression); \\r
281 } \\r
282 } \\r
283 } while (FALSE)\r
284 #else\r
285 #define ASSERT(Expression) do{} while(0)\r
286 #endif\r
287\r
288#endif\r
289\r
290/**\r
291 \r
292 Macro that calls DebugPrint().\r
293\r
294 If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set, \r
295 then this macro passes Expression to DebugPrint().\r
296\r
297 @param Expression Expression containing an error level, a format string, \r
298 and a variable argument list based on the format string.\r
299 \r
300\r
301**/\r
302#ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION\r
303 // Glue Library internal\r
304 \r
305 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE\r
306 #ifdef EFI_DEBUG\r
307 #define DEBUG(Expression) \\r
308 do { \\r
309 if (DebugPrintEnabled ()) { \\r
310 _DEBUG (Expression); \\r
311 } \\r
312 } while (FALSE)\r
313 #endif\r
314 #else\r
315 #define DEBUG(Expression) do{} while(0)\r
316 #endif \r
317\r
318#else\r
319 // External usage\r
320\r
321 #ifdef EFI_DEBUG\r
322 #define DEBUG(Expression) \\r
323 do { \\r
324 if (DebugPrintEnabled ()) { \\r
325 _DEBUG (Expression); \\r
326 } \\r
327 } while (FALSE)\r
328 #else\r
329 #define DEBUG(Expression) do{} while(0)\r
330 #endif\r
331\r
332#endif\r
333\r
334\r
335/**\r
336 \r
337 Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.\r
338\r
339 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
340 then this macro evaluates the EFI_STATUS value specified by StatusParameter. \r
341 If StatusParameter is an error code, then DebugAssert() is called passing in \r
342 the source filename, source line number, and StatusParameter.\r
343\r
344 @param StatusParameter EFI_STATUS value to evaluate.\r
345\r
346**/\r
347#ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION\r
348 // Glue Library internal\r
349 \r
350 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE\r
351 #ifdef EFI_DEBUG\r
352 #define ASSERT_EFI_ERROR(StatusParameter) \\r
353 do { \\r
354 if (DebugAssertEnabled ()) { \\r
355 if (EFI_ERROR (StatusParameter)) { \\r
356 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \\r
357 _ASSERT (!EFI_ERROR (StatusParameter)); \\r
358 } \\r
359 } \\r
360 } while (FALSE)\r
361 #endif\r
362 #else\r
363 #define ASSERT_EFI_ERROR(Expression) do{} while(0)\r
364 #endif \r
365\r
366#else\r
367 // External usage\r
368\r
369 #ifdef EFI_DEBUG\r
370 #define ASSERT_EFI_ERROR(StatusParameter) \\r
371 do { \\r
372 if (DebugAssertEnabled ()) { \\r
373 if (EFI_ERROR (StatusParameter)) { \\r
374 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \\r
375 _ASSERT (!EFI_ERROR (StatusParameter)); \\r
376 } \\r
377 } \\r
378 } while (FALSE)\r
379 #else\r
380 #define ASSERT_EFI_ERROR(Expression) do{} while(0)\r
381 #endif\r
382\r
383#endif\r
384\r
385\r
386/**\r
387 \r
388 Macro that calls DebugAssert() if a protocol is already installed in the \r
389 handle database.\r
390\r
391 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
392 then return.\r
393\r
394 If Handle is NULL, then a check is made to see if the protocol specified by Guid \r
395 is present on any handle in the handle database. If Handle is not NULL, then \r
396 a check is made to see if the protocol specified by Guid is present on the \r
397 handle specified by Handle. If the check finds the protocol, then DebugAssert() \r
398 is called passing in the source filename, source line number, and Guid.\r
399\r
400 If Guid is NULL, then ASSERT().\r
401\r
402 @param Handle The handle to check for the protocol. This is an optional \r
403 parameter that may be NULL. If it is NULL, then the entire \r
404 handle database is searched.\r
405\r
406 @param Guid Pointer to a protocol GUID.\r
407\r
408**/\r
c7f33ca4 409#ifdef EFI_DEBUG\r
3eb9473e 410#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \\r
411 do { \\r
412 if (DebugAssertEnabled ()) { \\r
413 VOID *Instance; \\r
414 ASSERT (Guid != NULL); \\r
415 if (Handle == NULL) { \\r
416 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \\r
417 _ASSERT (Guid already installed in database); \\r
418 } \\r
419 } else { \\r
420 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \\r
421 _ASSERT (Guid already installed on Handle); \\r
422 } \\r
423 } \\r
424 } \\r
425 } while (FALSE)\r
c7f33ca4 426#else\r
427#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \\r
428 do {} while(0);\r
429#endif\r
3eb9473e 430\r
431\r
432/**\r
433 Macro that marks the beginning of debug source code.\r
434\r
435 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
436 then this macro marks the beginning of source code that is included in a module.\r
437 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END() \r
438 are not included in a module.\r
439\r
440**/\r
441#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal\r
442\r
443\r
444/**\r
445 \r
446 Macro that marks the end of debug source code.\r
447\r
448 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
449 then this macro marks the end of source code that is included in a module. \r
450 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END() \r
451 are not included in a module.\r
452\r
453**/\r
454#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r
455\r
456\r
457/**\r
458 \r
459 Macro that declares a section of debug source code.\r
460\r
461 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
462 then the source code specified by Expression is included in a module. \r
463 Otherwise, the source specified by Expression is not included in a module.\r
464\r
465**/\r
466#define DEBUG_CODE(Expression) \\r
467 DEBUG_CODE_BEGIN (); \\r
468 Expression \\r
469 DEBUG_CODE_END ()\r
470\r
471\r
472/**\r
473 \r
474 Macro that calls DebugClearMemory() to clear a buffer to a default value.\r
475\r
476 If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set, \r
477 then this macro calls DebugClearMemory() passing in Address and Length.\r
478\r
479 @param Address Pointer to a buffer.\r
480 @param Length The number of bytes in the buffer to set.\r
481\r
482**/\r
483#define DEBUG_CLEAR_MEMORY(Address, Length) \\r
484 do { \\r
485 if (DebugClearMemoryEnabled ()) { \\r
486 DebugClearMemory (Address, Length); \\r
487 } \\r
488 } while (FALSE)\r
489\r
490\r
491/**\r
492\r
493 Macro that calls DebugAssert() if the containing record does not have a \r
494 matching signature. If the signatures matches, then a pointer to the data \r
495 structure that contains a specified field of that data structure is returned. \r
496 This is a light weight method hide information by placing a public data \r
497 structure inside a larger private data structure and using a pointer to the \r
498 public data structure to retrieve a pointer to the private data structure.\r
499\r
500 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
501 then this macro computes the offset, in bytes, of field specified by Field \r
502 from the beginning of the data structure specified by TYPE. This offset is \r
503 subtracted from Record, and is used to return a pointer to a data structure \r
504 of the type specified by TYPE.\r
505\r
506 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
507 then this macro computes the offset, in bytes, of field specified by Field from \r
508 the beginning of the data structure specified by TYPE. This offset is \r
509 subtracted from Record, and is used to compute a pointer to a data structure of \r
510 the type specified by TYPE. The Signature field of the data structure specified \r
511 by TYPE is compared to TestSignature. If the signatures match, then a pointer \r
512 to the pointer to a data structure of the type specified by TYPE is returned. \r
513 If the signatures do not match, then DebugAssert() is called with a description \r
514 of "CR has a bad signature" and Record is returned. \r
515\r
516 If the data type specified by TYPE does not contain the field specified by Field, \r
517 then the module will not compile.\r
518\r
519 If TYPE does not contain a field called Signature, then the module will not \r
520 compile.\r
521\r
522 @param Record Pointer to the field specified by Field within a data \r
523 structure of type TYPE.\r
524\r
525 @param TYPE The name of the data structure type to return This \r
526 data structure must contain the field specified by Field. \r
527\r
528 @param Field The name of the field in the data structure specified \r
529 by TYPE to which Record points.\r
530\r
531 @param TestSignature The 32-bit signature value to match.\r
532\r
533**/\r
c7f33ca4 534#ifdef EFI_DEBUG\r
535 #define CR(Record, TYPE, Field, TestSignature) \\r
536 (DebugAssertEnabled () && (_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \\r
537 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \\r
538 _CR (Record, TYPE, Field)\r
539#else\r
540 #define CR(Record, TYPE, Field, TestSignature) \\r
541 _CR (Record, TYPE, Field)\r
542#endif\r
543\r
544\r
3eb9473e 545#endif\r