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>
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>
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.
45 IN CONST CHAR8
*Format
,
49 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
50 EFI_DEBUG_INFO
*DebugInfo
;
54 UINT64
*ArgumentPointer
;
57 // If Format is NULL, then ASSERT().
59 ASSERT (Format
!= NULL
);
62 // Check driver Debug Level value and global debug level
64 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
68 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
69 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
74 // Then EFI_DEBUG_INFO
76 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
77 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
80 // 256 byte mini Var Arg stack. That is followed by the format string.
82 VA_START (Marker
, Format
);
83 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
84 WriteUnaligned64(ArgumentPointer
, VA_ARG (Marker
, UINT64
));
87 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
89 REPORT_STATUS_CODE_EX (
91 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
94 &gEfiStatusCodeDataTypeDebugGuid
,
103 Prints an assert message containing a filename, line number, and description.
104 This may be followed by a breakpoint or a dead loop.
106 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
107 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
108 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
109 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
110 CpuDeadLoop() is called. If neither of these bits are set, then this function
111 returns immediately after the message is printed to the debug output device.
112 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
113 processing another DebugAssert(), then DebugAssert() must return immediately.
115 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
117 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
119 @param FileName Pointer to the name of the source file that generated the assert condition.
120 @param LineNumber The line number in the source file that generated the assert condition
121 @param Description Pointer to the description of the assert condition.
127 IN CONST CHAR8
*FileName
,
129 IN CONST CHAR8
*Description
132 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
133 EFI_DEBUG_ASSERT_DATA
*AssertData
;
136 UINTN FileNameLength
;
137 UINTN DescriptionLength
;
140 // Make sure it will all fit in the passed in buffer
142 FileNameLength
= AsciiStrLen (FileName
);
143 DescriptionLength
= AsciiStrLen (Description
);
144 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + FileNameLength
+ 1 + DescriptionLength
+ 1;
145 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
147 // Fill in EFI_DEBUG_ASSERT_DATA
149 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
150 AssertData
->LineNumber
= (UINT32
)LineNumber
;
153 // Copy Ascii FileName including NULL.
155 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
158 // Copy Ascii Description
160 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
162 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
163 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
164 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
171 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
173 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
175 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
183 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
185 This function fills Length bytes of Buffer with the value specified by
186 PcdDebugClearMemoryValue, and returns Buffer.
188 If Buffer is NULL, then ASSERT().
190 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
192 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
193 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
206 // If Buffer is NULL, then ASSERT().
208 ASSERT (Buffer
!= NULL
);
211 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
213 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
219 Returns TRUE if ASSERT() macros are enabled.
221 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
222 PcdDebugProperyMask is set. Otherwise FALSE is returned.
224 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
225 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
234 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
240 Returns TRUE if DEBUG()macros are enabled.
242 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
243 PcdDebugProperyMask is set. Otherwise FALSE is returned.
245 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
246 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
255 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
261 Returns TRUE if DEBUG_CODE()macros are enabled.
263 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
264 PcdDebugProperyMask is set. Otherwise FALSE is returned.
266 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
267 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
276 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
282 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
284 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
285 PcdDebugProperyMask is set. Otherwise FALSE is returned.
287 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
288 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
293 DebugClearMemoryEnabled (
297 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);