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.
17 #include <FrameworkPei.h>
18 #include <Guid/StatusCodeDataTypeId.h>
19 #include <Guid/StatusCodeDataTypeDebug.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/ReportStatusCodeLib.h>
25 #include <Library/PcdLib.h>
29 Prints a debug message to the debug output device if the specified error level is enabled.
31 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
32 the message specified by Format and the associated variable argument list to
33 the debug output device.
35 If Format is NULL, then ASSERT().
37 @param ErrorLevel The error level of the debug message.
38 @param Format Format string for the debug message to print.
39 @param ... Variable argument list whose contents are accessed
40 based on the format string specified by Format.
47 IN CONST CHAR8
*Format
,
51 UINT64 Buffer
[(EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)) + 1];
52 EFI_DEBUG_INFO
*DebugInfo
;
55 BASE_LIST BaseListMarker
;
61 // If Format is NULL, then ASSERT().
63 ASSERT (Format
!= NULL
);
66 // Check driver Debug Level value and global debug level
68 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
73 // Compute the total size of the record
75 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
78 // If the TotalSize is larger than the maximum record size, then return
80 if (TotalSize
> sizeof (Buffer
)) {
85 // Fill in EFI_DEBUG_INFO
87 DebugInfo
= (EFI_DEBUG_INFO
*)(Buffer
) + 1;
88 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
89 BaseListMarker
= (BASE_LIST
)(DebugInfo
+ 1);
90 FormatString
= (CHAR8
*)((UINT64
*)(DebugInfo
+ 1) + 12);
93 // Copy the Format string into the record
95 AsciiStrCpy (FormatString
, Format
);
98 // 256 byte mini Var Arg stack. That is followed by the format string.
100 VA_START (VaListMarker
, Format
);
101 for (; *Format
!= '\0'; Format
++) {
102 if (*Format
!= '%') {
107 // Parse Flags and Width
109 for (Done
= FALSE
; !Done
; ) {
133 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
137 // Make no output if Format string terminates unexpectedly when
138 // looking up for flag, width, precision and type.
142 // break skipped on purpose.
151 // Handle each argument type
155 if (sizeof (VOID
*) > 4) {
162 BASE_ARG (BaseListMarker
, INT64
) = VA_ARG (VaListMarker
, INT64
);
164 BASE_ARG (BaseListMarker
, int) = VA_ARG (VaListMarker
, int);
172 BASE_ARG (BaseListMarker
, VOID
*) = VA_ARG (VaListMarker
, VOID
*);
175 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
178 BASE_ARG (BaseListMarker
, RETURN_STATUS
) = VA_ARG (VaListMarker
, RETURN_STATUS
);
183 // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then ASSERT()
184 // This indicates that the DEBUG() macro is passing in more argument than can be handled by
185 // the EFI_DEBUG_INFO record
187 ASSERT ((CHAR8
*)BaseListMarker
<= FormatString
);
190 // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return
192 if ((CHAR8
*)BaseListMarker
> FormatString
) {
196 VA_END (VaListMarker
);
199 // Send the DebugInfo record
201 REPORT_STATUS_CODE_EX (
203 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
206 &gEfiStatusCodeDataTypeDebugGuid
,
214 Prints an assert message containing a filename, line number, and description.
215 This may be followed by a breakpoint or a dead loop.
217 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
218 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
219 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
220 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
221 CpuDeadLoop() is called. If neither of these bits are set, then this function
222 returns immediately after the message is printed to the debug output device.
223 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
224 processing another DebugAssert(), then DebugAssert() must return immediately.
226 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
228 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
230 @param FileName Pointer to the name of the source file that generated the assert condition.
231 @param LineNumber The line number in the source file that generated the assert condition
232 @param Description Pointer to the description of the assert condition.
238 IN CONST CHAR8
*FileName
,
240 IN CONST CHAR8
*Description
243 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
244 EFI_DEBUG_ASSERT_DATA
*AssertData
;
247 UINTN FileNameLength
;
248 UINTN DescriptionLength
;
251 // Make sure it will all fit in the passed in buffer
253 FileNameLength
= AsciiStrLen (FileName
);
254 DescriptionLength
= AsciiStrLen (Description
);
255 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + FileNameLength
+ 1 + DescriptionLength
+ 1;
256 if (TotalSize
<= sizeof (Buffer
)) {
258 // Fill in EFI_DEBUG_ASSERT_DATA
260 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
261 AssertData
->LineNumber
= (UINT32
)LineNumber
;
264 // Copy Ascii FileName including NULL.
266 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
269 // Copy Ascii Description
271 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
273 REPORT_STATUS_CODE_EX (
274 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
275 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
285 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
287 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
289 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
297 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
299 This function fills Length bytes of Buffer with the value specified by
300 PcdDebugClearMemoryValue, and returns Buffer.
302 If Buffer is NULL, then ASSERT().
304 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
306 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
307 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
320 // If Buffer is NULL, then ASSERT().
322 ASSERT (Buffer
!= NULL
);
325 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
327 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
333 Returns TRUE if ASSERT() macros are enabled.
335 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
336 PcdDebugProperyMask is set. Otherwise FALSE is returned.
338 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
339 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
348 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
354 Returns TRUE if DEBUG()macros are enabled.
356 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
357 PcdDebugProperyMask is set. Otherwise FALSE is returned.
359 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
360 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
369 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
375 Returns TRUE if DEBUG_CODE()macros are enabled.
377 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
378 PcdDebugProperyMask is set. Otherwise FALSE is returned.
380 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
381 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
390 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
396 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
398 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
399 PcdDebugProperyMask is set. Otherwise FALSE is returned.
401 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
402 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
407 DebugClearMemoryEnabled (
411 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);