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 <FrameworkModuleBase.h>
19 #include <Guid/StatusCodeDataTypeId.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>
27 #include <DebugInfo.h>
31 Prints a debug message to the debug output device if the specified error level is enabled.
33 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
34 the message specified by Format and the associated variable argument list to
35 the debug output device.
37 If Format is NULL, then ASSERT().
39 @param ErrorLevel The error level of the debug message.
40 @param Format Format string for the debug message to print.
41 @param ... Variable argument list whose contents are accessed
42 based on the format string specified by Format.
49 IN CONST CHAR8
*Format
,
53 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
54 EFI_DEBUG_INFO
*DebugInfo
;
58 UINT64
*ArgumentPointer
;
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) {
72 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
73 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
78 // Then EFI_DEBUG_INFO
80 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
81 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
84 // 256 byte mini Var Arg stack. That is followed by the format string.
86 VA_START (Marker
, Format
);
87 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
88 WriteUnaligned64(ArgumentPointer
, VA_ARG (Marker
, UINT64
));
91 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
93 REPORT_STATUS_CODE_EX (
95 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
98 &gEfiStatusCodeDataTypeDebugGuid
,
107 Prints an assert message containing a filename, line number, and description.
108 This may be followed by a breakpoint or a dead loop.
110 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
111 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
112 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
113 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
114 CpuDeadLoop() is called. If neither of these bits are set, then this function
115 returns immediately after the message is printed to the debug output device.
116 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
117 processing another DebugAssert(), then DebugAssert() must return immediately.
119 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
121 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
123 @param FileName Pointer to the name of the source file that generated the assert condition.
124 @param LineNumber The line number in the source file that generated the assert condition
125 @param Description Pointer to the description of the assert condition.
131 IN CONST CHAR8
*FileName
,
133 IN CONST CHAR8
*Description
136 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
137 EFI_DEBUG_ASSERT_DATA
*AssertData
;
140 UINTN FileNameLength
;
141 UINTN DescriptionLength
;
144 // Make sure it will all fit in the passed in buffer
146 FileNameLength
= AsciiStrLen (FileName
);
147 DescriptionLength
= AsciiStrLen (Description
);
148 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + FileNameLength
+ 1 + DescriptionLength
+ 1;
149 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
151 // Fill in EFI_DEBUG_ASSERT_DATA
153 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
154 AssertData
->LineNumber
= (UINT32
)LineNumber
;
157 // Copy Ascii FileName including NULL.
159 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
162 // Copy Ascii Description
164 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
166 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
167 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
168 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
175 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
177 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
179 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
187 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
189 This function fills Length bytes of Buffer with the value specified by
190 PcdDebugClearMemoryValue, and returns Buffer.
192 If Buffer is NULL, then ASSERT().
194 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
196 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
197 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
210 // If Buffer is NULL, then ASSERT().
212 ASSERT (Buffer
!= NULL
);
215 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
217 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
223 Returns TRUE if ASSERT() macros are enabled.
225 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
226 PcdDebugProperyMask is set. Otherwise FALSE is returned.
228 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
229 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
238 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
244 Returns TRUE if DEBUG()macros are enabled.
246 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
247 PcdDebugProperyMask is set. Otherwise FALSE is returned.
249 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
250 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
259 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
265 Returns TRUE if DEBUG_CODE()macros are enabled.
267 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
268 PcdDebugProperyMask is set. Otherwise FALSE is returned.
270 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
271 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
280 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
286 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
288 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
289 PcdDebugProperyMask is set. Otherwise FALSE is returned.
291 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
292 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
297 DebugClearMemoryEnabled (
301 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);