3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Debug Library that fowards all messages to ReportStatusCode()
23 #include "EdkIIGlueDxe.h"
27 Prints a debug message to the debug output device if the specified error level is enabled.
29 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
30 the message specified by Format and the associated variable argument list to
31 the debug output device.
33 If Format is NULL, then ASSERT().
35 @param ErrorLevel The error level of the debug message.
36 @param Format Format string for the debug message to print.
43 IN CONST CHAR8
*Format
,
47 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof (UINT64
)];
48 EFI_DEBUG_INFO
*DebugInfo
;
52 UINT64
*ArgumentPointer
;
55 // If Format is NULL, then ASSERT().
57 ASSERT (Format
!= NULL
);
60 // Check driver Debug Level value and global debug level
62 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
66 TotalSize
= sizeof (EFI_DEBUG_INFO
) + 12 * sizeof (UINT64
) + AsciiStrLen (Format
) + 1;
67 if (TotalSize
> EFI_STATUS_CODE_DATA_MAX_SIZE
) {
72 // Then EFI_DEBUG_INFO
74 DebugInfo
= (EFI_DEBUG_INFO
*)Buffer
;
75 DebugInfo
->ErrorLevel
= (UINT32
)ErrorLevel
;
78 // 256 byte mini Var Arg stack. That is followed by the format string.
80 VA_START (Marker
, Format
);
81 for (Index
= 0, ArgumentPointer
= (UINT64
*)(DebugInfo
+ 1); Index
< 12; Index
++, ArgumentPointer
++) {
82 WriteUnaligned64(ArgumentPointer
, VA_ARG (Marker
, UINT64
));
85 AsciiStrCpy ((CHAR8
*)ArgumentPointer
, Format
);
87 REPORT_STATUS_CODE_EX (
89 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_DC_UNSPECIFIED
),
92 &gEfiStatusCodeDataTypeDebugGuid
,
101 Prints an assert message containing a filename, line number, and description.
102 This may be followed by a breakpoint or a dead loop.
104 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
105 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
106 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
107 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
108 CpuDeadLoop() is called. If neither of these bits are set, then this function
109 returns immediately after the message is printed to the debug output device.
110 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
111 processing another DebugAssert(), then DebugAssert() must return immediately.
113 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
115 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
117 @param FileName Pointer to the name of the source file that generated the assert condition.
118 @param LineNumber The line number in the source file that generated the assert condition
119 @param Description Pointer to the description of the assert condition.
125 IN CONST CHAR8
*FileName
,
127 IN CONST CHAR8
*Description
130 UINT64 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
/ sizeof(UINT64
)];
131 EFI_DEBUG_ASSERT_DATA
*AssertData
;
134 UINTN FileNameLength
;
135 UINTN DescriptionLength
;
138 // Make sure it will all fit in the passed in buffer
140 FileNameLength
= AsciiStrLen (FileName
);
141 DescriptionLength
= AsciiStrLen (Description
);
142 TotalSize
= sizeof (EFI_DEBUG_ASSERT_DATA
) + FileNameLength
+ 1 + DescriptionLength
+ 1;
143 if (TotalSize
<= EFI_STATUS_CODE_DATA_MAX_SIZE
) {
145 // Fill in EFI_DEBUG_ASSERT_DATA
147 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)Buffer
;
148 AssertData
->LineNumber
= (UINT32
)LineNumber
;
151 // Copy Ascii FileName including NULL.
153 Temp
= AsciiStrCpy ((CHAR8
*)(AssertData
+ 1), FileName
);
156 // Copy Ascii Description
158 AsciiStrCpy (Temp
+ AsciiStrLen (FileName
) + 1, Description
);
160 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
161 (EFI_ERROR_CODE
| EFI_ERROR_UNRECOVERED
),
162 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
),
169 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
171 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
173 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
181 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
183 This function fills Length bytes of Buffer with the value specified by
184 PcdDebugClearMemoryValue, and returns Buffer.
186 If Buffer is NULL, then ASSERT().
188 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
190 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
191 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
204 // If Buffer is NULL, then ASSERT().
206 ASSERT (Buffer
!= NULL
);
209 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
211 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
217 Returns TRUE if ASSERT() macros are enabled.
219 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
220 PcdDebugProperyMask is set. Otherwise FALSE is returned.
222 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
223 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
232 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
238 Returns TRUE if DEBUG()macros are enabled.
240 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
241 PcdDebugProperyMask is set. Otherwise FALSE is returned.
243 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
244 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
253 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
259 Returns TRUE if DEBUG_CODE()macros are enabled.
261 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
262 PcdDebugProperyMask is set. Otherwise FALSE is returned.
264 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
265 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
274 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
280 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
282 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
283 PcdDebugProperyMask is set. Otherwise FALSE is returned.
285 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
286 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
291 DebugClearMemoryEnabled (
295 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);