+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-\r
-Module Name:\r
-\r
- EdkIIGlueDebugLib.h\r
- \r
-Abstract: \r
-\r
- Public include file for the Debug Library\r
-\r
---*/\r
-\r
-#ifndef __EDKII_GLUE_DEBUG_LIB_H__\r
-#define __EDKII_GLUE_DEBUG_LIB_H__\r
-\r
-//\r
-// To use EDKII code, these EDK macros are undefined\r
-//\r
-#undef ASSERT\r
-#undef DEBUG\r
-#undef ASSERT_EFI_ERROR\r
-#undef ASSERT_PROTOCOL_ALREADY_INSTALLED\r
-#undef DEBUG_CODE\r
-#undef CR\r
-\r
-#undef EFI_D_INIT\r
-#undef EFI_D_WARN\r
-#undef EFI_D_LOAD\r
-#undef EFI_D_FS\r
-#undef EFI_D_POOL\r
-#undef EFI_D_PAGE\r
-#undef EFI_D_INFO\r
-#undef EFI_D_VARIABLE\r
-#undef EFI_D_BM \r
-#undef EFI_D_BLKIO\r
-#undef EFI_D_NET \r
-#undef EFI_D_UNDI\r
-#undef EFI_D_LOADFILE\r
-#undef EFI_D_EVENT\r
-#undef EFI_D_VERBOSE\r
-#undef EFI_D_ERROR\r
-\r
-//\r
-// Declare bits for PcdDebugPropertyMask\r
-//\r
-#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01\r
-#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02\r
-#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04\r
-#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08\r
-#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10\r
-#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20\r
-\r
-//\r
-// Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint()\r
-//\r
-#define DEBUG_INIT 0x00000001 // Initialization\r
-#define DEBUG_WARN 0x00000002 // Warnings\r
-#define DEBUG_LOAD 0x00000004 // Load events\r
-#define DEBUG_FS 0x00000008 // EFI File system\r
-#define DEBUG_POOL 0x00000010 // Alloc & Free's\r
-#define DEBUG_PAGE 0x00000020 // Alloc & Free's\r
-#define DEBUG_INFO 0x00000040 // Informational debug messages\r
-#define DEBUG_VARIABLE 0x00000100 // Variable\r
-#define DEBUG_BM 0x00000400 // Boot Manager\r
-#define DEBUG_BLKIO 0x00001000 // BlkIo Driver\r
-#define DEBUG_NET 0x00004000 // SNI Driver\r
-#define DEBUG_UNDI 0x00010000 // UNDI Driver\r
-#define DEBUG_LOADFILE 0x00020000 // UNDI Driver\r
-#define DEBUG_EVENT 0x00080000 // Event messages\r
-#define DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may significantly impact boot performance\r
-#define DEBUG_ERROR 0x80000000 // Error\r
-\r
-//\r
-// Aliases of debug message mask bits\r
-//\r
-#define EFI_D_INIT DEBUG_INIT\r
-#define EFI_D_WARN DEBUG_WARN\r
-#define EFI_D_LOAD DEBUG_LOAD\r
-#define EFI_D_FS DEBUG_FS\r
-#define EFI_D_POOL DEBUG_POOL\r
-#define EFI_D_PAGE DEBUG_PAGE\r
-#define EFI_D_INFO DEBUG_INFO\r
-#define EFI_D_VARIABLE DEBUG_VARIABLE\r
-#define EFI_D_BM DEBUG_BM\r
-#define EFI_D_BLKIO DEBUG_BLKIO\r
-#define EFI_D_NET DEBUG_NET\r
-#define EFI_D_UNDI DEBUG_UNDI\r
-#define EFI_D_LOADFILE DEBUG_LOADFILE\r
-#define EFI_D_EVENT DEBUG_EVENT\r
-#define EFI_D_VERBOSE DEBUG_VERBOSE\r
-#define EFI_D_ERROR DEBUG_ERROR\r
-\r
-\r
-//\r
-// Use the following 4 macros to save size\r
-//\r
-#define DebugAssertEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0))\r
-\r
-#define DebugPrintEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0))\r
-\r
-#define DebugCodeEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0))\r
-\r
-#define DebugClearMemoryEnabled() ((BOOLEAN)((__EDKII_GLUE_PCD_PcdDebugPropertyMask__ & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0))\r
-\r
-\r
-/**\r
-\r
- Prints a debug message to the debug output device if the specified error level is enabled.\r
-\r
- If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
- the message specified by Format and the associated variable argument list to \r
- the debug output device.\r
-\r
- If Format is NULL, then ASSERT().\r
-\r
- @param ErrorLevel The error level of the debug message.\r
- @param Format Format string for the debug message to print.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-DebugPrint (\r
- IN UINTN ErrorLevel,\r
- IN CONST CHAR8 *Format,\r
- ...\r
- );\r
-\r
-\r
-/**\r
-\r
- Prints an assert message containing a filename, line number, and description. \r
- This may be followed by a breakpoint or a dead loop.\r
-\r
- Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r
- to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
- PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
- DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
- CpuDeadLoop() is called. If neither of these bits are set, then this function \r
- returns immediately after the message is printed to the debug output device.\r
- DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
- processing another DebugAssert(), then DebugAssert() must return immediately.\r
-\r
- If FileName is NULL, then a <FileName> string of ?NULL) Filename?is printed.\r
-\r
- If Description is NULL, then a <Description> string of ?NULL) Description?is printed.\r
-\r
- @param FileName Pointer to the name of the source file that generated the assert condition.\r
- @param LineNumber The line number in the source file that generated the assert condition\r
- @param Description Pointer to the description of the assert condition.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-DebugAssert (\r
- IN CONST CHAR8 *FileName,\r
- IN UINTN LineNumber,\r
- IN CONST CHAR8 *Description\r
- );\r
-\r
-\r
-/**\r
-\r
- Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
-\r
- This function fills Length bytes of Buffer with the value specified by \r
- PcdDebugClearMemoryValue, and returns Buffer.\r
-\r
- If Buffer is NULL, then ASSERT().\r
-\r
- If Length is greater than (MAX_ADDRESS ?Buffer + 1), then ASSERT(). \r
-\r
- @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
- @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
-\r
- @return Buffer\r
-\r
-**/\r
-VOID *\r
-EFIAPI\r
-DebugClearMemory (\r
- OUT VOID *Buffer,\r
- IN UINTN Length\r
- );\r
-\r
-\r
-/**\r
- \r
- Internal worker macro that calls DebugAssert().\r
-\r
- This macro calls DebugAssert() passing in the filename, line number, and \r
- expression that evailated to FALSE.\r
-\r
- @param Expression Boolean expression that evailated to FALSE\r
-\r
-**/\r
-#ifdef EFI_DEBUG\r
-#define _ASSERT(Expression) DebugAssert (__FILE__, __LINE__, #Expression)\r
-#else\r
-#define _ASSERT(Expression)\r
-\r
-#endif\r
-\r
-/**\r
- \r
- Internal worker macro that calls DebugPrint().\r
-\r
- This macro calls DebugPrint() passing in the debug error level, a format \r
- string, and a variable argument list.\r
-\r
- @param Expression Expression containing an error level, a format string, \r
- and a variable argument list based on the format string.\r
-\r
-**/\r
-#ifdef EFI_DEBUG\r
-/*\r
- EdkCompatibilityPkg\Foundation\Include\EfiDebug.h\r
- //\r
- // DEBUG((DebugLevel, "format string", ...)) - if DebugLevel is active do \r
- // the a debug print.\r
- //\r
- #define DEBUG(arg) EfiDebugPrint arg\r
-\r
- To pass ICC build, undef the previously defined _DEBUG.\r
-*/ \r
-#undef _DEBUG\r
-#define _DEBUG(Expression) DebugPrint Expression\r
-#else\r
-#define _DEBUG(Expression)\r
-\r
-#endif\r
-\r
-/**\r
- \r
- Macro that calls DebugAssert() if a expression evaluates to FALSE.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro evaluates the Boolean expression specified by Expression. If \r
- Expression evaluates to FALSE, then DebugAssert() is called passing in the \r
- source filename, source line number, and Expression.\r
-\r
- @param Expression Boolean expression\r
-\r
-**/\r
-#ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION\r
- // Glue Library internal\r
- \r
- #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE\r
- #ifdef EFI_DEBUG\r
- #define ASSERT(Expression) \\r
- do { \\r
- if (DebugAssertEnabled ()) { \\r
- if (!(Expression)) { \\r
- _ASSERT (Expression); \\r
- } \\r
- } \\r
- } while (FALSE)\r
- #endif\r
- #else\r
- #define ASSERT(Expression) do{} while(0)\r
- #endif \r
-\r
-#else\r
- // External usage\r
-\r
- #ifdef EFI_DEBUG\r
- #define ASSERT(Expression) \\r
- do { \\r
- if (DebugAssertEnabled ()) { \\r
- if (!(Expression)) { \\r
- _ASSERT (Expression); \\r
- } \\r
- } \\r
- } while (FALSE)\r
- #else\r
- #define ASSERT(Expression) do{} while(0)\r
- #endif\r
-\r
-#endif\r
-\r
-/**\r
- \r
- Macro that calls DebugPrint().\r
-\r
- If the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro passes Expression to DebugPrint().\r
-\r
- @param Expression Expression containing an error level, a format string, \r
- and a variable argument list based on the format string.\r
- \r
-\r
-**/\r
-#ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION\r
- // Glue Library internal\r
- \r
- #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE\r
- #ifdef EFI_DEBUG\r
- #define DEBUG(Expression) \\r
- do { \\r
- if (DebugPrintEnabled ()) { \\r
- _DEBUG (Expression); \\r
- } \\r
- } while (FALSE)\r
- #endif\r
- #else\r
- #define DEBUG(Expression) do{} while(0)\r
- #endif \r
-\r
-#else\r
- // External usage\r
-\r
- #ifdef EFI_DEBUG\r
- #define DEBUG(Expression) \\r
- do { \\r
- if (DebugPrintEnabled ()) { \\r
- _DEBUG (Expression); \\r
- } \\r
- } while (FALSE)\r
- #else\r
- #define DEBUG(Expression) do{} while(0)\r
- #endif\r
-\r
-#endif\r
-\r
-\r
-/**\r
- \r
- Macro that calls DebugAssert() if an EFI_STATUS evaluates to an error code.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro evaluates the EFI_STATUS value specified by StatusParameter. \r
- If StatusParameter is an error code, then DebugAssert() is called passing in \r
- the source filename, source line number, and StatusParameter.\r
-\r
- @param StatusParameter EFI_STATUS value to evaluate.\r
-\r
-**/\r
-#ifdef EDKII_GLUE_LIBRARY_IMPLEMENTATION\r
- // Glue Library internal\r
- \r
- #if EDKII_GLUE_LIBRARY_DEBUG_ENABLE\r
- #ifdef EFI_DEBUG\r
- #define ASSERT_EFI_ERROR(StatusParameter) \\r
- do { \\r
- if (DebugAssertEnabled ()) { \\r
- if (EFI_ERROR (StatusParameter)) { \\r
- DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \\r
- _ASSERT (!EFI_ERROR (StatusParameter)); \\r
- } \\r
- } \\r
- } while (FALSE)\r
- #endif\r
- #else\r
- #define ASSERT_EFI_ERROR(Expression) do{} while(0)\r
- #endif \r
-\r
-#else\r
- // External usage\r
-\r
- #ifdef EFI_DEBUG\r
- #define ASSERT_EFI_ERROR(StatusParameter) \\r
- do { \\r
- if (DebugAssertEnabled ()) { \\r
- if (EFI_ERROR (StatusParameter)) { \\r
- DEBUG ((EFI_D_ERROR, "\nASSERT_EFI_ERROR (Status = %r)\n", StatusParameter)); \\r
- _ASSERT (!EFI_ERROR (StatusParameter)); \\r
- } \\r
- } \\r
- } while (FALSE)\r
- #else\r
- #define ASSERT_EFI_ERROR(Expression) do{} while(0)\r
- #endif\r
-\r
-#endif\r
-\r
-\r
-/**\r
- \r
- Macro that calls DebugAssert() if a protocol is already installed in the \r
- handle database.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
- then return.\r
-\r
- If Handle is NULL, then a check is made to see if the protocol specified by Guid \r
- is present on any handle in the handle database. If Handle is not NULL, then \r
- a check is made to see if the protocol specified by Guid is present on the \r
- handle specified by Handle. If the check finds the protocol, then DebugAssert() \r
- is called passing in the source filename, source line number, and Guid.\r
-\r
- If Guid is NULL, then ASSERT().\r
-\r
- @param Handle The handle to check for the protocol. This is an optional \r
- parameter that may be NULL. If it is NULL, then the entire \r
- handle database is searched.\r
-\r
- @param Guid Pointer to a protocol GUID.\r
-\r
-**/\r
-#ifdef EFI_DEBUG\r
-#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \\r
- do { \\r
- if (DebugAssertEnabled ()) { \\r
- VOID *Instance; \\r
- ASSERT (Guid != NULL); \\r
- if (Handle == NULL) { \\r
- if (!EFI_ERROR (gBS->LocateProtocol ((EFI_GUID *)Guid, NULL, &Instance))) { \\r
- _ASSERT (Guid already installed in database); \\r
- } \\r
- } else { \\r
- if (!EFI_ERROR (gBS->HandleProtocol (Handle, (EFI_GUID *)Guid, &Instance))) { \\r
- _ASSERT (Guid already installed on Handle); \\r
- } \\r
- } \\r
- } \\r
- } while (FALSE)\r
-#else\r
-#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid) \\r
- do {} while(0);\r
-#endif\r
-\r
-\r
-/**\r
- Macro that marks the beginning of debug source code.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro marks the beginning of source code that is included in a module.\r
- Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END() \r
- are not included in a module.\r
-\r
-**/\r
-#define DEBUG_CODE_BEGIN() do { if (DebugCodeEnabled ()) { UINT8 __DebugCodeLocal\r
-\r
-\r
-/**\r
- \r
- Macro that marks the end of debug source code.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro marks the end of source code that is included in a module. \r
- Otherwise, the source lines between DEBUG_CODE_BEGIN() and DEBUG_CODE_END() \r
- are not included in a module.\r
-\r
-**/\r
-#define DEBUG_CODE_END() __DebugCodeLocal = 0; __DebugCodeLocal++; } } while (FALSE)\r
-\r
-\r
-/**\r
- \r
- Macro that declares a section of debug source code.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set, \r
- then the source code specified by Expression is included in a module. \r
- Otherwise, the source specified by Expression is not included in a module.\r
-\r
-**/\r
-#define DEBUG_CODE(Expression) \\r
- DEBUG_CODE_BEGIN (); \\r
- Expression \\r
- DEBUG_CODE_END ()\r
-\r
-\r
-/**\r
- \r
- Macro that calls DebugClearMemory() to clear a buffer to a default value.\r
-\r
- If the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro calls DebugClearMemory() passing in Address and Length.\r
-\r
- @param Address Pointer to a buffer.\r
- @param Length The number of bytes in the buffer to set.\r
-\r
-**/\r
-#define DEBUG_CLEAR_MEMORY(Address, Length) \\r
- do { \\r
- if (DebugClearMemoryEnabled ()) { \\r
- DebugClearMemory (Address, Length); \\r
- } \\r
- } while (FALSE)\r
-\r
-\r
-/**\r
-\r
- Macro that calls DebugAssert() if the containing record does not have a \r
- matching signature. If the signatures matches, then a pointer to the data \r
- structure that contains a specified field of that data structure is returned. \r
- This is a light weight method hide information by placing a public data \r
- structure inside a larger private data structure and using a pointer to the \r
- public data structure to retrieve a pointer to the private data structure.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear, \r
- then this macro computes the offset, in bytes, of field specified by Field \r
- from the beginning of the data structure specified by TYPE. This offset is \r
- subtracted from Record, and is used to return a pointer to a data structure \r
- of the type specified by TYPE.\r
-\r
- If the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, \r
- then this macro computes the offset, in bytes, of field specified by Field from \r
- the beginning of the data structure specified by TYPE. This offset is \r
- subtracted from Record, and is used to compute a pointer to a data structure of \r
- the type specified by TYPE. The Signature field of the data structure specified \r
- by TYPE is compared to TestSignature. If the signatures match, then a pointer \r
- to the pointer to a data structure of the type specified by TYPE is returned. \r
- If the signatures do not match, then DebugAssert() is called with a description \r
- of "CR has a bad signature" and Record is returned. \r
-\r
- If the data type specified by TYPE does not contain the field specified by Field, \r
- then the module will not compile.\r
-\r
- If TYPE does not contain a field called Signature, then the module will not \r
- compile.\r
-\r
- @param Record Pointer to the field specified by Field within a data \r
- structure of type TYPE.\r
-\r
- @param TYPE The name of the data structure type to return This \r
- data structure must contain the field specified by Field. \r
-\r
- @param Field The name of the field in the data structure specified \r
- by TYPE to which Record points.\r
-\r
- @param TestSignature The 32-bit signature value to match.\r
-\r
-**/\r
-#ifdef EFI_DEBUG\r
- #define CR(Record, TYPE, Field, TestSignature) \\r
- (DebugAssertEnabled () && (_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \\r
- (TYPE *) (_ASSERT (CR has Bad Signature), Record) : \\r
- _CR (Record, TYPE, Field)\r
-#else\r
- #define CR(Record, TYPE, Field, TestSignature) \\r
- _CR (Record, TYPE, Field)\r
-#endif\r
-\r
-\r
-#endif\r