2 PEI debug lib instance base on gEdkiiDebugPpiGuid to save PEIM size.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Ppi/Debug.h>
12 #include <Library/DebugLib.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/PeiServicesLib.h>
16 #include <Library/DebugPrintErrorLevelLib.h>
17 #include <Library/BaseLib.h>
20 Prints a debug message to the debug output device if the specified
21 error level is enabled.
23 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
24 GetDebugPrintErrorLevel (), then print the message specified by Format and
25 the associated variable argument list to the debug output device.
27 If Format is NULL, then ASSERT().
29 @param ErrorLevel The error level of the debug message.
30 @param Format Format string for the debug message to print.
31 @param ... Variable argument list whose contents are accessed
32 based on the format string specified by Format.
39 IN CONST CHAR8
*Format
,
45 VA_START (Marker
, Format
);
46 DebugVPrint (ErrorLevel
, Format
, Marker
);
51 Prints a debug message to the debug output device if the specified
52 error level is enabled.
53 This function use BASE_LIST which would provide a more compatible
56 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
57 GetDebugPrintErrorLevel (), then print the message specified by Format and
58 the associated variable argument list to the debug output device.
60 If Format is NULL, then ASSERT().
62 @param ErrorLevel The error level of the debug message.
63 @param Format Format string for the debug message to print.
64 @param BaseListMarker BASE_LIST marker for the variable argument list.
71 IN CONST CHAR8
*Format
,
72 IN BASE_LIST BaseListMarker
76 EDKII_DEBUG_PPI
*DebugPpi
;
79 // If Format is NULL, then ASSERT().
81 ASSERT (Format
!= NULL
);
84 // Check driver Debug Level value and global debug level
86 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
90 Status
= PeiServicesLocatePpi (
96 if (EFI_ERROR (Status
)) {
100 DebugPpi
->DebugBPrint (
108 Worker function that convert a VA_LIST to a BASE_LIST based on a
109 Null-terminated format string.
111 @param Format Null-terminated format string.
112 @param VaListMarker VA_LIST style variable argument list consumed
113 by processing Format.
114 @param BaseListMarker BASE_LIST style variable argument list consumed
115 by processing Format.
116 @param Size The size, in bytes, of the BaseListMarker buffer.
118 @return TRUE The VA_LIST has been converted to BASE_LIST.
119 @return FALSE The VA_LIST has not been converted to BASE_LIST.
124 IN CONST CHAR8
*Format
,
125 IN VA_LIST VaListMarker
,
126 OUT BASE_LIST BaseListMarker
,
130 BASE_LIST BaseListStart
;
133 ASSERT (Format
!= NULL
);
135 ASSERT (BaseListMarker
!= NULL
);
137 BaseListStart
= BaseListMarker
;
139 for ( ; *Format
!= '\0'; Format
++) {
141 // Only format with prefix % is processed.
143 if (*Format
!= '%') {
150 // Parse Flags and Width
152 for (Format
++; TRUE
; Format
++) {
153 if ((*Format
== '.') || (*Format
== '-') || (*Format
== '+') || (*Format
== ' ')) {
155 // These characters in format field are omitted.
160 if ((*Format
>= '0') && (*Format
<= '9')) {
162 // These characters in format field are omitted.
167 if ((*Format
== 'L') || (*Format
== 'l')) {
169 // 'L" or "l" in format field means the number being printed is a UINT64
175 if (*Format
== '*') {
177 // '*' in format field means the precision of the field is specified by
178 // a UINTN argument in the argument list.
180 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
184 if (*Format
== '\0') {
186 // Make no output if Format string terminates unexpectedly when
187 // looking up for flag, width, precision and type.
193 // When valid argument type detected or format string terminates unexpectedly,
194 // the inner loop is done.
200 // Pack variable arguments into the storage area following EFI_DEBUG_INFO.
202 if ((*Format
== 'p') && (sizeof (VOID
*) > 4)) {
206 if ((*Format
== 'p') || (*Format
== 'X') || (*Format
== 'x') || (*Format
== 'd') || (*Format
== 'u')) {
208 BASE_ARG (BaseListMarker
, INT64
) = VA_ARG (VaListMarker
, INT64
);
210 BASE_ARG (BaseListMarker
, int) = VA_ARG (VaListMarker
, int);
212 } else if ((*Format
== 's') || (*Format
== 'S') || (*Format
== 'a') || (*Format
== 'g') || (*Format
== 't')) {
213 BASE_ARG (BaseListMarker
, VOID
*) = VA_ARG (VaListMarker
, VOID
*);
214 } else if (*Format
== 'c') {
215 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
216 } else if (*Format
== 'r') {
217 BASE_ARG (BaseListMarker
, RETURN_STATUS
) = VA_ARG (VaListMarker
, RETURN_STATUS
);
221 // If the converted BASE_LIST is larger than the size of BaseListMarker, then return FALSE
223 if (((UINTN
)BaseListMarker
- (UINTN
)BaseListStart
) > Size
) {
232 Prints a debug message to the debug output device if the specified
233 error level is enabled.
235 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
236 GetDebugPrintErrorLevel (), then print the message specified by Format and
237 the associated variable argument list to the debug output device.
239 If Format is NULL, then ASSERT().
241 @param ErrorLevel The error level of the debug message.
242 @param Format Format string for the debug message to print.
243 @param VaListMarker VA_LIST marker for the variable argument list.
250 IN CONST CHAR8
*Format
,
251 IN VA_LIST VaListMarker
254 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
258 // Convert the VaList to BaseList
260 Converted
= VaListToBaseList (
263 (BASE_LIST
)BaseListMarker
,
264 sizeof (BaseListMarker
) - 8
271 DebugBPrint (ErrorLevel
, Format
, (BASE_LIST
)BaseListMarker
);
275 Prints an assert message containing a filename, line number, and description.
276 This may be followed by a breakpoint or a dead loop.
278 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
279 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
280 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
281 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
282 CpuDeadLoop() is called. If neither of these bits are set, then this function
283 returns immediately after the message is printed to the debug output device.
284 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
285 processing another DebugAssert(), then DebugAssert() must return immediately.
287 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
288 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
290 @param FileName The pointer to the name of the source file that generated the assert condition.
291 @param LineNumber The line number in the source file that generated the assert condition
292 @param Description The pointer to the description of the assert condition.
298 IN CONST CHAR8
*FileName
,
300 IN CONST CHAR8
*Description
304 EDKII_DEBUG_PPI
*DebugPpi
;
306 Status
= PeiServicesLocatePpi (
312 if (EFI_ERROR (Status
)) {
314 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
316 if ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
318 } else if ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
322 DebugPpi
->DebugAssert (
331 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
333 This function fills Length bytes of Buffer with the value specified by
334 PcdDebugClearMemoryValue, and returns Buffer.
336 If Buffer is NULL, then ASSERT().
337 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
339 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
340 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
342 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
352 ASSERT (Buffer
!= NULL
);
354 return SetMem (Buffer
, Length
, PcdGet8 (PcdDebugClearMemoryValue
));
358 Returns TRUE if ASSERT() macros are enabled.
360 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
361 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
363 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
364 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
373 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
377 Returns TRUE if DEBUG() macros are enabled.
379 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
380 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
382 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
383 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
392 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
396 Returns TRUE if DEBUG_CODE() macros are enabled.
398 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
399 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
401 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
402 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
411 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
415 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
417 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
418 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
420 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
421 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
426 DebugClearMemoryEnabled (
430 return (BOOLEAN
)((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
434 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
436 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
438 @retval TRUE Current ErrorLevel is supported.
439 @retval FALSE Current ErrorLevel is not supported.
444 DebugPrintLevelEnabled (
445 IN CONST UINTN ErrorLevel
448 return (BOOLEAN
)((ErrorLevel
& PcdGet32 (PcdFixedDebugPrintErrorLevel
)) != 0);