2 Base Debug library instance for QEMU debug port.
3 It uses PrintLib to send debug messages to a fixed I/O port.
5 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
6 Copyright (c) 2012, Red Hat, Inc.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/DebugLib.h>
19 #include <Library/BaseLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/PrintLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/DebugPrintErrorLevelLib.h>
25 #include "DebugLibDetect.h"
28 // Define the maximum debug and assert message length that this library supports
30 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
33 // VA_LIST can not initialize to NULL for all compiler, so we use this to
34 // indicate a null VA_LIST
39 Prints a debug message to the debug output device if the specified error level is enabled.
41 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
42 GetDebugPrintErrorLevel (), then print the message specified by Format and the
43 associated variable argument list to the debug output device.
45 If Format is NULL, then ASSERT().
47 @param ErrorLevel The error level of the debug message.
48 @param Format Format string for the debug message to print.
49 @param ... Variable argument list whose contents are accessed
50 based on the format string specified by Format.
57 IN CONST CHAR8
*Format
,
63 VA_START (Marker
, Format
);
64 DebugVPrint (ErrorLevel
, Format
, Marker
);
70 Prints a debug message to the debug output device if the specified
71 error level is enabled base on Null-terminated format string and a
72 VA_LIST argument list or a BASE_LIST argument list.
74 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
75 GetDebugPrintErrorLevel (), then print the message specified by Format and
76 the associated variable argument list to the debug output device.
78 If Format is NULL, then ASSERT().
80 @param ErrorLevel The error level of the debug message.
81 @param Format Format string for the debug message to print.
82 @param VaListMarker VA_LIST marker for the variable argument list.
83 @param BaseListMarker BASE_LIST marker for the variable argument list.
89 IN CONST CHAR8
*Format
,
90 IN VA_LIST VaListMarker
,
91 IN BASE_LIST BaseListMarker
94 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
98 // If Format is NULL, then ASSERT().
100 ASSERT (Format
!= NULL
);
103 // Check if the global mask disables this message or the device is inactive
105 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0 ||
106 !PlatformDebugLibIoPortFound ()) {
111 // Convert the DEBUG() message to an ASCII String
113 if (BaseListMarker
== NULL
) {
114 Length
= AsciiVSPrint (Buffer
, sizeof (Buffer
), Format
, VaListMarker
);
116 Length
= AsciiBSPrint (Buffer
, sizeof (Buffer
), Format
, BaseListMarker
);
120 // Send the print string to the debug I/O port
122 IoWriteFifo8 (PcdGet16 (PcdDebugIoPort
), Length
, Buffer
);
127 Prints a debug message to the debug output device if the specified
128 error level is enabled.
130 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
131 GetDebugPrintErrorLevel (), then print the message specified by Format and
132 the associated variable argument list to the debug output device.
134 If Format is NULL, then ASSERT().
136 @param ErrorLevel The error level of the debug message.
137 @param Format Format string for the debug message to print.
138 @param VaListMarker VA_LIST marker for the variable argument list.
145 IN CONST CHAR8
*Format
,
146 IN VA_LIST VaListMarker
149 DebugPrintMarker (ErrorLevel
, Format
, VaListMarker
, NULL
);
154 Prints a debug message to the debug output device if the specified
155 error level is enabled.
156 This function use BASE_LIST which would provide a more compatible
157 service than VA_LIST.
159 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
160 GetDebugPrintErrorLevel (), then print the message specified by Format and
161 the associated variable argument list to the debug output device.
163 If Format is NULL, then ASSERT().
165 @param ErrorLevel The error level of the debug message.
166 @param Format Format string for the debug message to print.
167 @param BaseListMarker BASE_LIST marker for the variable argument list.
174 IN CONST CHAR8
*Format
,
175 IN BASE_LIST BaseListMarker
178 DebugPrintMarker (ErrorLevel
, Format
, mVaListNull
, BaseListMarker
);
183 Prints an assert message containing a filename, line number, and description.
184 This may be followed by a breakpoint or a dead loop.
186 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
187 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
188 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
189 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
190 CpuDeadLoop() is called. If neither of these bits are set, then this function
191 returns immediately after the message is printed to the debug output device.
192 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
193 processing another DebugAssert(), then DebugAssert() must return immediately.
195 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
196 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
198 @param FileName The pointer to the name of the source file that generated the assert condition.
199 @param LineNumber The line number in the source file that generated the assert condition
200 @param Description The pointer to the description of the assert condition.
206 IN CONST CHAR8
*FileName
,
208 IN CONST CHAR8
*Description
211 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
215 // Generate the ASSERT() message in Ascii format
217 Length
= AsciiSPrint (Buffer
, sizeof Buffer
, "ASSERT %a(%Lu): %a\n",
218 FileName
, (UINT64
)LineNumber
, Description
);
221 // Send the print string to the debug I/O port, if present
223 if (PlatformDebugLibIoPortFound ()) {
224 IoWriteFifo8 (PcdGet16 (PcdDebugIoPort
), Length
, Buffer
);
228 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
230 if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED
) != 0) {
232 } else if ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED
) != 0) {
239 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
241 This function fills Length bytes of Buffer with the value specified by
242 PcdDebugClearMemoryValue, and returns Buffer.
244 If Buffer is NULL, then ASSERT().
245 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
247 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
248 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
250 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
261 // If Buffer is NULL, then ASSERT().
263 ASSERT (Buffer
!= NULL
);
266 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
268 return SetMem (Buffer
, Length
, PcdGet8(PcdDebugClearMemoryValue
));
273 Returns TRUE if ASSERT() macros are enabled.
275 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
276 PcdDebugProperyMask is set. Otherwise FALSE is returned.
278 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
279 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
288 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
293 Returns TRUE if DEBUG() macros are enabled.
295 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
296 PcdDebugProperyMask is set. Otherwise FALSE is returned.
298 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
299 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
308 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
313 Returns TRUE if DEBUG_CODE() macros are enabled.
315 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
316 PcdDebugProperyMask is set. Otherwise FALSE is returned.
318 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
319 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
328 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
333 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
335 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
336 PcdDebugProperyMask is set. Otherwise FALSE is returned.
338 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
339 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
344 DebugClearMemoryEnabled (
348 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);
352 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
354 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
356 @retval TRUE Current ErrorLevel is supported.
357 @retval FALSE Current ErrorLevel is not supported.
362 DebugPrintLevelEnabled (
363 IN CONST UINTN ErrorLevel
366 return (BOOLEAN
) ((ErrorLevel
& PcdGet32(PcdFixedDebugPrintErrorLevel
)) != 0);
370 Return the result of detecting the debug I/O port device.
372 @retval TRUE if the debug I/O port device was detected.
373 @retval FALSE otherwise
378 PlatformDebugLibIoPortDetect (
382 return IoRead8 (PcdGet16 (PcdDebugIoPort
)) == BOCHS_DEBUG_PORT_MAGIC
;