2 PEI debug lib instance base on gEdkiiDebugPpiGuid to save PEIM size.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Ppi/Debug.h>
18 #include <Library/DebugLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/PeiServicesLib.h>
22 #include <Library/DebugPrintErrorLevelLib.h>
23 #include <Library/BaseLib.h>
26 Prints a debug message to the debug output device if the specified
27 error level is enabled.
29 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
30 GetDebugPrintErrorLevel (), then print the message specified by Format and
31 the associated variable argument list to 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.
37 @param ... Variable argument list whose contents are accessed
38 based on the format string specified by Format.
45 IN CONST CHAR8
*Format
,
51 VA_START (Marker
, Format
);
52 DebugVPrint (ErrorLevel
, Format
, Marker
);
58 Prints a debug message to the debug output device if the specified
59 error level is enabled.
60 This function use BASE_LIST which would provide a more compatible
63 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
64 GetDebugPrintErrorLevel (), then print the message specified by Format and
65 the associated variable argument list to the debug output device.
67 If Format is NULL, then ASSERT().
69 @param ErrorLevel The error level of the debug message.
70 @param Format Format string for the debug message to print.
71 @param BaseListMarker BASE_LIST marker for the variable argument list.
78 IN CONST CHAR8
*Format
,
79 IN BASE_LIST BaseListMarker
83 EDKII_DEBUG_PPI
*DebugPpi
;
86 // If Format is NULL, then ASSERT().
88 ASSERT (Format
!= NULL
);
91 // Check driver Debug Level value and global debug level
93 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
97 Status
= PeiServicesLocatePpi (
103 if (EFI_ERROR (Status
)) {
107 DebugPpi
->DebugBPrint (
116 Worker function that convert a VA_LIST to a BASE_LIST based on a
117 Null-terminated format string.
119 @param Format Null-terminated format string.
120 @param VaListMarker VA_LIST style variable argument list consumed
121 by processing Format.
122 @param BaseListMarker BASE_LIST style variable argument list consumed
123 by processing Format.
124 @param Size The size, in bytes, of the BaseListMarker buffer.
126 @return TRUE The VA_LIST has been converted to BASE_LIST.
127 @return FALSE The VA_LIST has not been converted to BASE_LIST.
132 IN CONST CHAR8
*Format
,
133 IN VA_LIST VaListMarker
,
134 OUT BASE_LIST BaseListMarker
,
138 BASE_LIST BaseListStart
;
141 ASSERT (Format
!= NULL
);
143 ASSERT (BaseListMarker
!= NULL
);
145 BaseListStart
= BaseListMarker
;
147 for (; *Format
!= '\0'; Format
++) {
149 // Only format with prefix % is processed.
151 if (*Format
!= '%') {
158 // Parse Flags and Width
160 for (Format
++; TRUE
; Format
++) {
161 if (*Format
== '.' || *Format
== '-' || *Format
== '+' || *Format
== ' ') {
163 // These characters in format field are omitted.
167 if (*Format
>= '0' && *Format
<= '9') {
169 // These characters in format field are omitted.
173 if (*Format
== 'L' || *Format
== 'l') {
175 // 'L" or "l" in format field means the number being printed is a UINT64
180 if (*Format
== '*') {
182 // '*' in format field means the precision of the field is specified by
183 // a UINTN argument in the argument list.
185 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
188 if (*Format
== '\0') {
190 // Make no output if Format string terminates unexpectedly when
191 // looking up for flag, width, precision and type.
196 // When valid argument type detected or format string terminates unexpectedly,
197 // the inner loop is done.
203 // Pack variable arguments into the storage area following EFI_DEBUG_INFO.
205 if ((*Format
== 'p') && (sizeof (VOID
*) > 4)) {
208 if (*Format
== 'p' || *Format
== 'X' || *Format
== 'x' || *Format
== 'd' || *Format
== 'u') {
210 BASE_ARG (BaseListMarker
, INT64
) = VA_ARG (VaListMarker
, INT64
);
212 BASE_ARG (BaseListMarker
, int) = VA_ARG (VaListMarker
, int);
214 } else if (*Format
== 's' || *Format
== 'S' || *Format
== 'a' || *Format
== 'g' || *Format
== 't') {
215 BASE_ARG (BaseListMarker
, VOID
*) = VA_ARG (VaListMarker
, VOID
*);
216 } else if (*Format
== 'c') {
217 BASE_ARG (BaseListMarker
, UINTN
) = VA_ARG (VaListMarker
, UINTN
);
218 } else if (*Format
== 'r') {
219 BASE_ARG (BaseListMarker
, RETURN_STATUS
) = VA_ARG (VaListMarker
, RETURN_STATUS
);
223 // If the converted BASE_LIST is larger than the size of BaseListMarker, then return FALSE
225 if (((UINTN
)BaseListMarker
- (UINTN
)BaseListStart
) > Size
) {
235 Prints a debug message to the debug output device if the specified
236 error level is enabled.
238 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
239 GetDebugPrintErrorLevel (), then print the message specified by Format and
240 the associated variable argument list to the debug output device.
242 If Format is NULL, then ASSERT().
244 @param ErrorLevel The error level of the debug message.
245 @param Format Format string for the debug message to print.
246 @param VaListMarker VA_LIST marker for the variable argument list.
253 IN CONST CHAR8
*Format
,
254 IN VA_LIST VaListMarker
257 UINT64 BaseListMarker
[256 / sizeof (UINT64
)];
261 // Convert the VaList to BaseList
263 Converted
= VaListToBaseList (
266 (BASE_LIST
)BaseListMarker
,
267 sizeof (BaseListMarker
) - 8
274 DebugBPrint (ErrorLevel
, Format
, (BASE_LIST
)BaseListMarker
);
279 Prints an assert message containing a filename, line number, and description.
280 This may be followed by a breakpoint or a dead loop.
282 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
283 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
284 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
285 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
286 CpuDeadLoop() is called. If neither of these bits are set, then this function
287 returns immediately after the message is printed to the debug output device.
288 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
289 processing another DebugAssert(), then DebugAssert() must return immediately.
291 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
292 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
294 @param FileName The pointer to the name of the source file that generated the assert condition.
295 @param LineNumber The line number in the source file that generated the assert condition
296 @param Description The pointer to the description of the assert condition.
302 IN CONST CHAR8
*FileName
,
304 IN CONST CHAR8
*Description
308 EDKII_DEBUG_PPI
*DebugPpi
;
310 Status
= PeiServicesLocatePpi (
316 if (EFI_ERROR (Status
)) {
318 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
320 if ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
322 } else if ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
326 DebugPpi
->DebugAssert (
336 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
338 This function fills Length bytes of Buffer with the value specified by
339 PcdDebugClearMemoryValue, and returns Buffer.
341 If Buffer is NULL, then ASSERT().
342 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
344 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
345 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
347 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
357 ASSERT (Buffer
!= NULL
);
359 return SetMem (Buffer
, Length
, PcdGet8 (PcdDebugClearMemoryValue
));
364 Returns TRUE if ASSERT() macros are enabled.
366 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
367 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
369 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
370 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
379 return (BOOLEAN
) ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
384 Returns TRUE if DEBUG() macros are enabled.
386 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
387 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
389 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
390 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
399 return (BOOLEAN
) ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
404 Returns TRUE if DEBUG_CODE() macros are enabled.
406 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
407 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
409 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
410 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
419 return (BOOLEAN
) ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
424 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
426 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
427 PcdDebugProperyMask is set. Otherwise, FALSE is returned.
429 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
430 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
435 DebugClearMemoryEnabled (
439 return (BOOLEAN
) ((PcdGet8 (PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
444 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
446 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
448 @retval TRUE Current ErrorLevel is supported.
449 @retval FALSE Current ErrorLevel is not supported.
454 DebugPrintLevelEnabled (
455 IN CONST UINTN ErrorLevel
458 return (BOOLEAN
) ((ErrorLevel
& PcdGet32(PcdFixedDebugPrintErrorLevel
)) != 0);