2 UEFI Debug Library that sends messages to the Console Output Device in the EFI System Table.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/PrintLib.h>
13 #include <Library/PcdLib.h>
14 #include <Library/BaseLib.h>
15 #include <Library/BaseMemoryLib.h>
16 #include <Library/DebugPrintErrorLevelLib.h>
19 // Define the maximum debug and assert message length that this library supports
21 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
24 // VA_LIST can not initialize to NULL for all compiler, so we use this to
25 // indicate a null VA_LIST
29 extern BOOLEAN mPostEBS
;
30 extern EFI_SYSTEM_TABLE
*mDebugST
;
33 Prints a debug message to the debug output device if the specified error level is enabled.
35 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
36 GetDebugPrintErrorLevel (), then print the message specified by Format and the
37 associated variable argument list to the debug output device.
39 If Format is NULL, then ASSERT().
41 @param ErrorLevel The error level of the debug message.
42 @param Format Format string for the debug message to print.
43 @param ... A variable argument list whose contents are accessed
44 based on the format string specified by Format.
51 IN CONST CHAR8
*Format
,
57 VA_START (Marker
, Format
);
58 DebugVPrint (ErrorLevel
, Format
, Marker
);
64 Prints a debug message to the debug output device if the specified
65 error level is enabled base on Null-terminated format string and a
66 VA_LIST argument list or a BASE_LIST argument list.
68 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
69 GetDebugPrintErrorLevel (), then print the message specified by Format and
70 the associated variable argument list to the debug output device.
72 If Format is NULL, then ASSERT().
74 @param ErrorLevel The error level of the debug message.
75 @param Format Format string for the debug message to print.
76 @param VaListMarker VA_LIST marker for the variable argument list.
77 @param BaseListMarker BASE_LIST marker for the variable argument list.
83 IN CONST CHAR8
*Format
,
84 IN VA_LIST VaListMarker
,
85 IN BASE_LIST BaseListMarker
88 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
92 // If Format is NULL, then ASSERT().
94 ASSERT (Format
!= NULL
);
97 // Check driver debug mask value and global mask
99 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
104 // Convert the DEBUG() message to a Unicode String
106 if (BaseListMarker
== NULL
) {
107 UnicodeVSPrintAsciiFormat (Buffer
, sizeof (Buffer
), Format
, VaListMarker
);
109 UnicodeBSPrintAsciiFormat (Buffer
, sizeof (Buffer
), Format
, BaseListMarker
);
114 // Send the print string to the Console Output device
116 if ((mDebugST
!= NULL
) && (mDebugST
->ConOut
!= NULL
)) {
117 mDebugST
->ConOut
->OutputString (mDebugST
->ConOut
, Buffer
);
124 Prints a debug message to the debug output device if the specified
125 error level is enabled.
127 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
128 GetDebugPrintErrorLevel (), then print the message specified by Format and
129 the associated variable argument list to the debug output device.
131 If Format is NULL, then ASSERT().
133 @param ErrorLevel The error level of the debug message.
134 @param Format Format string for the debug message to print.
135 @param VaListMarker VA_LIST marker for the variable argument list.
142 IN CONST CHAR8
*Format
,
143 IN VA_LIST VaListMarker
146 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
151 Prints a debug message to the debug output device if the specified
152 error level is enabled.
153 This function use BASE_LIST which would provide a more compatible
154 service than VA_LIST.
156 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
157 GetDebugPrintErrorLevel (), then print the message specified by Format and
158 the associated variable argument list to the debug output device.
160 If Format is NULL, then ASSERT().
162 @param ErrorLevel The error level of the debug message.
163 @param Format Format string for the debug message to print.
164 @param BaseListMarker BASE_LIST marker for the variable argument list.
171 IN CONST CHAR8
*Format
,
172 IN BASE_LIST BaseListMarker
175 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
180 Prints an assert message containing a filename, line number, and description.
181 This may be followed by a breakpoint or a dead loop.
183 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
184 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
185 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
186 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
187 CpuDeadLoop() is called. If neither of these bits are set, then this function
188 returns immediately after the message is printed to the debug output device.
189 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
190 processing another DebugAssert(), then DebugAssert() must return immediately.
192 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
193 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
195 @param FileName The pointer to the name of the source file that generated
196 the assert condition.
197 @param LineNumber The line number in the source file that generated the
199 @param Description The pointer to the description of the assert condition.
205 IN CONST CHAR8
*FileName
,
207 IN CONST CHAR8
*Description
210 CHAR16 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
214 // Generate the ASSERT() message in Unicode format
216 UnicodeSPrintAsciiFormat (
219 "ASSERT [%a] %a(%d): %a\n",
227 // Send the print string to the Console Output device
229 if ((mDebugST
!= NULL
) && (mDebugST
->ConOut
!= NULL
)) {
230 mDebugST
->ConOut
->OutputString (mDebugST
->ConOut
, Buffer
);
234 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
236 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
238 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
246 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
248 This function fills Length bytes of Buffer with the value specified by
249 PcdDebugClearMemoryValue, and returns Buffer.
251 If Buffer is NULL, then ASSERT().
252 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
254 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
255 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
257 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
268 // If Buffer is NULL, then ASSERT().
270 ASSERT (Buffer
!= NULL
);
273 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
275 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
280 Returns TRUE if ASSERT() macros are enabled.
282 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
283 PcdDebugProperyMask is set. Otherwise FALSE is returned.
285 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
286 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
295 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
300 Returns TRUE if DEBUG() macros are enabled.
302 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
303 PcdDebugProperyMask is set. Otherwise FALSE is returned.
305 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
306 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
315 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
320 Returns TRUE if DEBUG_CODE() macros are enabled.
322 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
323 PcdDebugProperyMask is set. Otherwise FALSE is returned.
325 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
326 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
335 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
340 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
342 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
343 PcdDebugProperyMask is set. Otherwise FALSE is returned.
345 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
346 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
351 DebugClearMemoryEnabled (
355 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
359 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
361 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
363 @retval TRUE Current ErrorLevel is supported.
364 @retval FALSE Current ErrorLevel is not supported.
369 DebugPrintLevelEnabled (
370 IN CONST UINTN ErrorLevel
373 return (BOOLEAN
) ((ErrorLevel
& PcdGet32(PcdFixedDebugPrintErrorLevel
)) != 0);