2 EFI Debug Library that installs Debug Level Protocol.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 STATIC BOOLEAN mDebugLevelInstalled
= FALSE
;
16 STATIC EFI_DEBUG_LEVEL_PROTOCOL mDebugLevel
= { 0 };
19 Installs Debug Level Protocol.
21 The constructor function installs Debug Level Protocol on the ImageHandle.
22 It will ASSERT() if the installation fails and will always return EFI_SUCCESS.
24 @param ImageHandle The firmware allocated handle for the EFI image.
25 @param SystemTable A pointer to the EFI System Table.
27 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
33 IN EFI_HANDLE ImageHandle
,
34 IN EFI_SYSTEM_TABLE
*SystemTable
40 // Initialize Debug Level Protocol.
42 mDebugLevel
.DebugLevel
= PcdGet32(PcdDebugPrintErrorLevel
);
45 // Install Debug Level Protocol.
47 Status
= gBS
->InstallMultipleProtocolInterfaces (
49 &gEfiDebugLevelProtocolGuid
,
53 ASSERT_EFI_ERROR (Status
);
56 // Set flag to show that the Debug Level Protocol has been installed.
58 mDebugLevelInstalled
= TRUE
;
65 Prints a debug message to the debug output device if the specified error level is enabled.
67 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
68 the message specified by Format and the associated variable argument list to
69 the debug output device.
71 If Format is NULL, then ASSERT().
73 @param ErrorLevel The error level of the debug message.
74 @param Format Format string for the debug message to print.
81 IN CONST CHAR8
*Format
,
85 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
86 EFI_DEBUG_INFO
*DebugInfo
;
90 UINT64
*ArgumentPointer
;
93 // If Format is NULL, then ASSERT().
95 ASSERT (Format
!= NULL
);
98 // Check driver Debug Level value and global debug level
100 if (mDebugLevelInstalled
) {
101 if ((ErrorLevel
& mDebugLevel
.DebugLevel
) == 0) {
105 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
110 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
111 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
116 // Then EFI_DEBUG_INFO
118 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
119 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
122 // 256 byte mini Var Arg stack. That is followed by the format string.
124 VA_START (Marker
, Format
);
125 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
126 *ArgumentPointer
= VA_ARG (Marker
, UINT64
);
129 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
131 REPORT_STATUS_CODE_EX (
133 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
136 &gEfiStatusCodeDataTypeDebugGuid
,
145 Prints an assert message containing a filename, line number, and description.
146 This may be followed by a breakpoint or a dead loop.
148 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
149 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
150 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
151 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
152 CpuDeadLoop() is called. If neither of these bits are set, then this function
153 returns immediately after the message is printed to the debug output device.
154 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
155 processing another DebugAssert(), then DebugAssert() must return immediately.
157 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
159 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
161 @param FileName Pointer to the name of the source file that generated the assert condition.
162 @param LineNumber The line number in the source file that generated the assert condition
163 @param Description Pointer to the description of the assert condition.
169 IN CONST CHAR8
*FileName
,
171 IN CONST CHAR8
*Description
174 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
175 EFI_DEBUG_ASSERT_DATA
*AssertData
;
180 // Make sure it will all fit in the passed in buffer.
182 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + AsciiStrLen (FileName
) + 1 + AsciiStrLen (Description
) + 1;
183 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
185 // Fill in EFI_DEBUG_ASSERT_DATA
187 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
188 AssertData
->LineNumber
= (UINT32
)LineNumber
;
191 // Copy Ascii FileName including NULL.
193 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
196 // Copy Ascii Description.
198 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
200 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
201 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
202 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
209 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
211 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
213 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
221 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
223 This function fills Length bytes of Buffer with the value specified by
224 PcdDebugClearMemoryValue, and returns Buffer.
226 If Buffer is NULL, then ASSERT().
228 If Length is greater than (MAX_ADDRESS \96 Buffer + 1), then ASSERT().
230 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
231 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
244 // If Buffer is NULL, then ASSERT().
246 ASSERT (Buffer
!= NULL
);
249 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
251 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
257 Returns TRUE if ASSERT() macros are enabled.
259 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
260 PcdDebugProperyMask is set. Otherwise FALSE is returned.
262 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
263 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
272 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
278 Returns TRUE if DEBUG()macros are enabled.
280 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
281 PcdDebugProperyMask is set. Otherwise FALSE is returned.
283 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
284 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
293 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
299 Returns TRUE if DEBUG_CODE()macros are enabled.
301 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
302 PcdDebugProperyMask is set. Otherwise FALSE is returned.
304 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
305 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
314 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
320 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
322 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
323 PcdDebugProperyMask is set. Otherwise FALSE is returned.
325 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
326 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
331 DebugClearMemoryEnabled (
335 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);