2 Debug Library that fowards all messages to ReportStatusCode()
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.
18 Prints a debug message to the debug output device if the specified error level is enabled.
20 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
21 the message specified by Format and the associated variable argument list to
22 the debug output device.
24 If Format is NULL, then ASSERT().
26 @param ErrorLevel The error level of the debug message.
27 @param Format Format string for the debug message to print.
34 IN CONST CHAR8
*Format
,
38 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
39 EFI_DEBUG_INFO
*DebugInfo
;
43 UINT64
*ArgumentPointer
;
46 // If Format is NULL, then ASSERT().
48 ASSERT (Format
!= NULL
);
51 // Check driver Debug Level value and global debug level
53 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
57 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
58 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
63 // Then EFI_DEBUG_INFO
65 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
66 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
69 // 256 byte mini Var Arg stack. That is followed by the format string.
71 VA_START (Marker
, Format
);
72 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
73 WriteUnaligned64(ArgumentPointer
, VA_ARG (Marker
, UINT64
));
76 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
78 REPORT_STATUS_CODE_EX (
80 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
83 &gEfiStatusCodeDataTypeDebugGuid
,
92 Prints an assert message containing a filename, line number, and description.
93 This may be followed by a breakpoint or a dead loop.
95 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
96 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
97 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
98 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
99 CpuDeadLoop() is called. If neither of these bits are set, then this function
100 returns immediately after the message is printed to the debug output device.
101 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
102 processing another DebugAssert(), then DebugAssert() must return immediately.
104 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
106 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
108 @param FileName Pointer to the name of the source file that generated the assert condition.
109 @param LineNumber The line number in the source file that generated the assert condition
110 @param Description Pointer to the description of the assert condition.
116 IN CONST CHAR8
*FileName
,
118 IN CONST CHAR8
*Description
121 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
122 EFI_DEBUG_ASSERT_DATA
*AssertData
;
127 // Make sure it will all fit in the passed in buffer
129 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + AsciiStrLen (FileName
) + 1 + AsciiStrLen (Description
) + 1;
130 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
132 // Fill in EFI_DEBUG_ASSERT_DATA
134 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
135 AssertData
->LineNumber
= (UINT32
)LineNumber
;
138 // Copy Ascii FileName including NULL.
140 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
143 // Copy Ascii Description
145 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
147 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
148 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
149 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
156 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
158 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
160 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
168 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
170 This function fills Length bytes of Buffer with the value specified by
171 PcdDebugClearMemoryValue, and returns Buffer.
173 If Buffer is NULL, then ASSERT().
175 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
177 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
178 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
191 // If Buffer is NULL, then ASSERT().
193 ASSERT (Buffer
!= NULL
);
196 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
198 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
204 Returns TRUE if ASSERT() macros are enabled.
206 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
207 PcdDebugProperyMask is set. Otherwise FALSE is returned.
209 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
210 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
219 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
225 Returns TRUE if DEBUG()macros are enabled.
227 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
228 PcdDebugProperyMask is set. Otherwise FALSE is returned.
230 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
231 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
240 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
246 Returns TRUE if DEBUG_CODE()macros are enabled.
248 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
249 PcdDebugProperyMask is set. Otherwise FALSE is returned.
251 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
252 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
261 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
267 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
269 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
270 PcdDebugProperyMask is set. Otherwise FALSE is returned.
272 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
273 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
278 DebugClearMemoryEnabled (
282 return ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);