]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Include/Library/EdkIIGlueDebugLib.h
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Public include file for the Debug Library
23 #ifndef __EDKII_GLUE_DEBUG_LIB_H__
24 #define __EDKII_GLUE_DEBUG_LIB_H__
27 // To use EdkII code, these R8.x macros are undefined
31 #undef ASSERT_EFI_ERROR
32 #undef ASSERT_PROTOCOL_ALREADY_INSTALLED
53 // Declare bits for PcdDebugPropertyMask
55 #define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01
56 #define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02
57 #define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04
58 #define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08
59 #define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10
60 #define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20
63 // Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint()
65 #define DEBUG_INIT 0x00000001 // Initialization
66 #define DEBUG_WARN 0x00000002 // Warnings
67 #define DEBUG_LOAD 0x00000004 // Load events
68 #define DEBUG_FS 0x00000008 // EFI File system
69 #define DEBUG_POOL 0x00000010 // Alloc & Free's
70 #define DEBUG_PAGE 0x00000020 // Alloc & Free's
71 #define DEBUG_INFO 0x00000040 // Verbose
72 #define DEBUG_VARIABLE 0x00000100 // Variable
73 #define DEBUG_BM 0x00000400 // Boot Manager
74 #define DEBUG_BLKIO 0x00001000 // BlkIo Driver
75 #define DEBUG_NET 0x00004000 // SNI Driver
76 #define DEBUG_UNDI 0x00010000 // UNDI Driver
77 #define DEBUG_LOADFILE 0x00020000 // UNDI Driver
78 #define DEBUG_EVENT 0x00080000 // Event messages
79 #define DEBUG_ERROR 0x80000000 // Error
82 // Aliases of debug message mask bits
84 #define EFI_D_INIT DEBUG_INIT
85 #define EFI_D_WARN DEBUG_WARN
86 #define EFI_D_LOAD DEBUG_LOAD
87 #define EFI_D_FS DEBUG_FS
88 #define EFI_D_POOL DEBUG_POOL
89 #define EFI_D_PAGE DEBUG_PAGE
90 #define EFI_D_INFO DEBUG_INFO
91 #define EFI_D_VARIABLE DEBUG_VARIABLE
92 #define EFI_D_BM DEBUG_BM
93 #define EFI_D_BLKIO DEBUG_BLKIO
94 #define EFI_D_NET DEBUG_NET
95 #define EFI_D_UNDI DEBUG_UNDI
96 #define EFI_D_LOADFILE DEBUG_LOADFILE
97 #define EFI_D_EVENT DEBUG_EVENT
98 #define EFI_D_ERROR DEBUG_ERROR
102 // Use the following 4 macros to save size
104 #define DebugAssertEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0))
106 #define DebugPrintEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0))
108 #define DebugCodeEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0))
110 #define DebugClearMemoryEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0))
115 Prints a debug message to the debug output device if the specified error level is enabled.
117 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
118 the message specified by Format and the associated variable argument list to
119 the debug output device.
121 If Format is NULL, then ASSERT().
123 @param ErrorLevel The error level of the debug message.
124 @param Format Format string for the debug message to print.
131 IN CONST CHAR8
*Format
,
138 Prints an assert message containing a filename, line number, and description.
139 This may be followed by a breakpoint or a dead loop.
141 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
142 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
143 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
144 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
145 CpuDeadLoop() is called. If neither of these bits are set, then this function
146 returns immediately after the message is printed to the debug output device.
147 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
148 processing another DebugAssert(), then DebugAssert() must return immediately.
150 If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.
152 If Description is NULL, then a <Description> string of ?NULL) Description?is printed.
154 @param FileName Pointer to the name of the source file that generated the assert condition.
155 @param LineNumber The line number in the source file that generated the assert condition
156 @param Description Pointer to the description of the assert condition.
162 IN CONST CHAR8
*FileName
,
164 IN CONST CHAR8
*Description
170 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
172 This function fills Length bytes of Buffer with the value specified by
173 PcdDebugClearMemoryValue, and returns Buffer.
175 If Buffer is NULL, then ASSERT().
177 If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT().
179 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
180 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
195 Internal worker macro that calls DebugAssert().
197 This macro calls DebugAssert() passing in the filename, line number, and
198 expression that evailated to FALSE.
200 @param Expression Boolean expression that evailated to FALSE
204 #define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)
206 #define _ASSERT(Expression)
212 Internal worker macro that calls DebugPrint().
214 This macro calls DebugPrint() passing in the debug error level, a format
215 string, and a variable argument list.
217 @param Expression Expression containing an error level, a format string,
218 and a variable argument list based on the format string.
222 #define _DEBUG(Expression) DebugPrint Expression
224 #define _DEBUG(Expression)
230 Macro that calls DebugAssert() if a expression evaluates to FALSE.
232 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
233 then this macro evaluates the Boolean expression specified by Expression. If
234 Expression evaluates to FALSE, then DebugAssert() is called passing in the
235 source filename, source line number, and Expression.
237 @param Expression Boolean expression
240 #ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION
241 // Glue Library internal
243 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE
245 #define ASSERT(Expression) \
247 if (DebugAssertEnabled ()) { \
248 if (!(Expression)) { \
249 _ASSERT (Expression); \
255 #define ASSERT(Expression) do{} while(0)
262 #define ASSERT(Expression) \
264 if (DebugAssertEnabled ()) { \
265 if (!(Expression)) { \
266 _ASSERT (Expression); \
271 #define ASSERT(Expression) do{} while(0)
278 Macro that calls DebugPrint().
280 If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set,
281 then this macro passes Expression to DebugPrint().
283 @param Expression Expression containing an error level, a format string,
284 and a variable argument list based on the format string.
288 #ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION
289 // Glue Library internal
291 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE
293 #define DEBUG(Expression) \
295 if (DebugPrintEnabled ()) { \
296 _DEBUG (Expression); \
301 #define DEBUG(Expression) do{} while(0)
308 #define DEBUG(Expression) \
310 if (DebugPrintEnabled ()) { \
311 _DEBUG (Expression); \
315 #define DEBUG(Expression) do{} while(0)
323 Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.
325 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
326 then this macro evaluates the EFI_STATUS value specified by StatusParameter.
327 If StatusParameter is an error code, then DebugAssert() is called passing in
328 the source filename, source line number, and StatusParameter.
330 @param StatusParameter EFI_STATUS value to evaluate.
333 #ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION
334 // Glue Library internal
336 #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE
338 #define ASSERT_EFI_ERROR(StatusParameter) \
340 if (DebugAssertEnabled ()) { \
341 if (EFI_ERROR (StatusParameter)) { \
342 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
343 _ASSERT (!EFI_ERROR (StatusParameter)); \
349 #define ASSERT_EFI_ERROR(Expression) do{} while(0)
356 #define ASSERT_EFI_ERROR(StatusParameter) \
358 if (DebugAssertEnabled ()) { \
359 if (EFI_ERROR (StatusParameter)) { \
360 DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \
361 _ASSERT (!EFI_ERROR (StatusParameter)); \
366 #define ASSERT_EFI_ERROR(Expression) do{} while(0)
374 Macro that calls DebugAssert() if a protocol is already installed in the
377 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
380 If Handle is NULL, then a check is made to see if the protocol specified by Guid
381 is present on any handle in the handle database. If Handle is not NULL, then
382 a check is made to see if the protocol specified by Guid is present on the
383 handle specified by Handle. If the check finds the protocol, then DebugAssert()
384 is called passing in the source filename, source line number, and Guid.
386 If Guid is NULL, then ASSERT().
388 @param Handle The handle to check for the protocol. This is an optional
389 parameter that may be NULL. If it is NULL, then the entire
390 handle database is searched.
392 @param Guid Pointer to a protocol GUID.
396 #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
398 if (DebugAssertEnabled ()) { \
400 ASSERT (Guid != NULL); \
401 if (Handle == NULL) { \
402 if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \
403 _ASSERT (Guid already installed in database); \
406 if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \
407 _ASSERT (Guid already installed on Handle); \
413 #define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \
419 Macro that marks the beginning of debug source code.
421 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
422 then this macro marks the beginning of source code that is included in a module.
423 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
424 are not included in a module.
427 #define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal
432 Macro that marks the end of debug source code.
434 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
435 then this macro marks the end of source code that is included in a module.
436 Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END()
437 are not included in a module.
440 #define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)
445 Macro that declares a section of debug source code.
447 If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set,
448 then the source code specified by Expression is included in a module.
449 Otherwise, the source specified by Expression is not included in a module.
452 #define DEBUG_CODE(Expression) \
453 DEBUG_CODE_BEGIN (); \
460 Macro that calls DebugClearMemory() to clear a buffer to a default value.
462 If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set,
463 then this macro calls DebugClearMemory() passing in Address and Length.
465 @param Address Pointer to a buffer.
466 @param Length The number of bytes in the buffer to set.
469 #define DEBUG_CLEAR_MEMORY(Address, Length) \
471 if (DebugClearMemoryEnabled ()) { \
472 DebugClearMemory (Address, Length); \
479 Macro that calls DebugAssert() if the containing record does not have a
480 matching signature. If the signatures matches, then a pointer to the data
481 structure that contains a specified field of that data structure is returned.
482 This is a light weight method hide information by placing a public data
483 structure inside a larger private data structure and using a pointer to the
484 public data structure to retrieve a pointer to the private data structure.
486 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear,
487 then this macro computes the offset, in bytes, of field specified by Field
488 from the beginning of the data structure specified by TYPE. This offset is
489 subtracted from Record, and is used to return a pointer to a data structure
490 of the type specified by TYPE.
492 If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set,
493 then this macro computes the offset, in bytes, of field specified by Field from
494 the beginning of the data structure specified by TYPE. This offset is
495 subtracted from Record, and is used to compute a pointer to a data structure of
496 the type specified by TYPE. The Signature field of the data structure specified
497 by TYPE is compared to TestSignature. If the signatures match, then a pointer
498 to the pointer to a data structure of the type specified by TYPE is returned.
499 If the signatures do not match, then DebugAssert() is called with a description
500 of "CR has a bad signature" and Record is returned.
502 If the data type specified by TYPE does not contain the field specified by Field,
503 then the module will not compile.
505 If TYPE does not contain a field called Signature, then the module will not
508 @param Record Pointer to the field specified by Field within a data
509 structure of type TYPE.
511 @param TYPE The name of the data structure type to return This
512 data structure must contain the field specified by Field.
514 @param Field The name of the field in the data structure specified
515 by TYPE to which Record points.
517 @param TestSignature The 32-bit signature value to match.
521 #define CR(Record, TYPE, Field, TestSignature) \
522 (DebugAssertEnabled () && (_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
523 (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
524 _CR (Record, TYPE, Field)
526 #define CR(Record, TYPE, Field, TestSignature) \
527 _CR (Record, TYPE, Field)