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 // The package level header files this module uses
19 #include <FrameworkPei.h>
21 // The protocols, PPI and GUID defintions for this module
23 #include <Guid/StatusCodeDataTypeId.h>
25 // The Library classes this module consumes
27 #include <Library/DebugLib.h>
28 #include <Library/BaseLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/PcdLib.h>
35 Prints a debug message to the debug output device if the specified error level is enabled.
37 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
38 the message specified by Format and the associated variable argument list to
39 the debug output device.
41 If Format is NULL, then ASSERT().
43 @param ErrorLevel The error level of the debug message.
44 @param Format Format string for the debug message to print.
51 IN CONST CHAR8
*Format
,
55 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
56 EFI_DEBUG_INFO
*DebugInfo
;
60 UINT64
*ArgumentPointer
;
63 // If Format is NULL, then ASSERT().
65 ASSERT (Format
!= NULL
);
68 // Check driver Debug Level value and global debug level
70 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
74 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
75 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
80 // Then EFI_DEBUG_INFO
82 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
83 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
86 // 256 byte mini Var Arg stack. That is followed by the format string.
88 VA_START (Marker
, Format
);
89 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
90 WriteUnaligned64(ArgumentPointer
, VA_ARG (Marker
, UINT64
));
93 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
95 REPORT_STATUS_CODE_EX (
97 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
100 &gEfiStatusCodeDataTypeDebugGuid
,
109 Prints an assert message containing a filename, line number, and description.
110 This may be followed by a breakpoint or a dead loop.
112 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
113 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
114 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
115 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
116 CpuDeadLoop() is called. If neither of these bits are set, then this function
117 returns immediately after the message is printed to the debug output device.
118 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
119 processing another DebugAssert(), then DebugAssert() must return immediately.
121 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
123 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
125 @param FileName Pointer to the name of the source file that generated the assert condition.
126 @param LineNumber The line number in the source file that generated the assert condition
127 @param Description Pointer to the description of the assert condition.
133 IN CONST CHAR8
*FileName
,
135 IN CONST CHAR8
*Description
138 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
139 EFI_DEBUG_ASSERT_DATA
*AssertData
;
142 UINTN FileNameLength
;
143 UINTN DescriptionLength
;
146 // Make sure it will all fit in the passed in buffer
148 FileNameLength
= AsciiStrLen (FileName
);
149 DescriptionLength
= AsciiStrLen (Description
);
150 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + FileNameLength
+ 1 + DescriptionLength
+ 1;
151 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
153 // Fill in EFI_DEBUG_ASSERT_DATA
155 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
156 AssertData
->LineNumber
= (UINT32
)LineNumber
;
159 // Copy Ascii FileName including NULL.
161 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
164 // Copy Ascii Description
166 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
168 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
169 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
170 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
177 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
179 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
181 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
189 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
191 This function fills Length bytes of Buffer with the value specified by
192 PcdDebugClearMemoryValue, and returns Buffer.
194 If Buffer is NULL, then ASSERT().
196 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
198 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
199 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
212 // If Buffer is NULL, then ASSERT().
214 ASSERT (Buffer
!= NULL
);
217 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
219 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
225 Returns TRUE if ASSERT() macros are enabled.
227 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
228 PcdDebugProperyMask is set. Otherwise FALSE is returned.
230 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
231 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
240 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
246 Returns TRUE if DEBUG()macros are enabled.
248 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
249 PcdDebugProperyMask is set. Otherwise FALSE is returned.
251 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
252 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
261 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
267 Returns TRUE if DEBUG_CODE()macros are enabled.
269 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
270 PcdDebugProperyMask is set. Otherwise FALSE is returned.
272 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
273 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
282 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
288 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
290 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
291 PcdDebugProperyMask is set. Otherwise FALSE is returned.
293 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
294 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
299 DebugClearMemoryEnabled (
303 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);