2 UEFI Debug Library that uses PrintLib to send messages to STDERR.
4 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. 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.
18 #include <Library/DebugLib.h>
19 #include <Library/PrintLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/BaseLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/SemihostLib.h>
26 // Define the maximum debug and assert message length that this library supports
28 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
32 Prints a debug message to the debug output device if the specified error level is enabled.
34 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print
35 the message specified by Format and the associated variable argument list to
36 the debug output device.
38 If Format is NULL, then ASSERT().
40 @param ErrorLevel The error level of the debug message.
41 @param Format Format string for the debug message to print.
48 IN CONST CHAR8
*Format
,
52 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
56 // If Format is NULL, then ASSERT().
58 ASSERT (Format
!= NULL
);
61 // Check driver debug mask value and global mask
63 if ((ErrorLevel
& PcdGet32(PcdDebugPrintErrorLevel
)) == 0) {
68 // Convert the DEBUG() message to a Unicode String
70 VA_START (Marker
, Format
);
71 AsciiVSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), Format
, Marker
);
74 SemihostWriteString (AsciiBuffer
);
80 Prints an assert message containing a filename, line number, and description.
81 This may be followed by a breakpoint or a dead loop.
83 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
84 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
85 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
86 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
87 CpuDeadLoop() is called. If neither of these bits are set, then this function
88 returns immediately after the message is printed to the debug output device.
89 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while
90 processing another DebugAssert(), then DebugAssert() must return immediately.
92 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
94 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
96 @param FileName Pointer to the name of the source file that generated the assert condition.
97 @param LineNumber The line number in the source file that generated the assert condition
98 @param Description Pointer to the description of the assert condition.
104 IN CONST CHAR8
*FileName
,
106 IN CONST CHAR8
*Description
109 CHAR8 AsciiBuffer
[MAX_DEBUG_MESSAGE_LENGTH
];
112 // Generate the ASSERT() message in Unicode format
114 AsciiSPrint (AsciiBuffer
, sizeof (AsciiBuffer
), "ASSERT %a(%d): %a\n", FileName
, LineNumber
, Description
);
116 SemihostWriteString (AsciiBuffer
);
119 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
121 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
123 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
131 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
133 This function fills Length bytes of Buffer with the value specified by
134 PcdDebugClearMemoryValue, and returns Buffer.
136 If Buffer is NULL, then ASSERT().
138 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
140 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.
141 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
154 // If Buffer is NULL, then ASSERT().
156 ASSERT (Buffer
!= NULL
);
159 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
161 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
167 Returns TRUE if ASSERT() macros are enabled.
169 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
170 PcdDebugProperyMask is set. Otherwise FALSE is returned.
172 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
173 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
182 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
188 Returns TRUE if DEBUG()macros are enabled.
190 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
191 PcdDebugProperyMask is set. Otherwise FALSE is returned.
193 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
194 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
203 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
209 Returns TRUE if DEBUG_CODE()macros are enabled.
211 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
212 PcdDebugProperyMask is set. Otherwise FALSE is returned.
214 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
215 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
224 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
230 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.
232 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of
233 PcdDebugProperyMask is set. Otherwise FALSE is returned.
235 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
236 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
241 DebugClearMemoryEnabled (
245 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);