3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <Library/DebugLib.h>
16 #include <Library/BaseLib.h>
17 #include <Library/PrintLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/SerialPortLib.h>
21 #include <Library/DebugDeviceLib.h>
22 #include <Library/DebugPrintErrorLevelLib.h>
25 // Define the maximum debug and assert message length that this library supports
27 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
29 CONST CHAR8
*mHexTable
= "0123456789ABCDEF";
32 Get stack frame pointer of function call.
34 @return StackFramePointer stack frame pointer of function call.
38 GetStackFramePointer (
44 Prints a debug message to the debug output device if the specified error level is enabled.
46 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
47 GetDebugPrintErrorLevel (), then print the message specified by Format and the
48 associated variable argument list to the debug output device.
50 If Format is NULL, then ASSERT().
52 @param ErrorLevel The error level of the debug message.
53 @param Format Format string for the debug message to print.
54 @param ... Variable argument list whose contents are accessed
55 based on the format string specified by Format.
62 IN CONST CHAR8
*Format
,
66 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
70 // If Format is NULL, then ASSERT().
72 if (!GetDebugPrintDeviceEnable ()) {
77 // Check driver debug mask value and global mask
79 if ((ErrorLevel
& GetDebugPrintErrorLevel ()) == 0) {
84 // If Format is NULL, then ASSERT().
86 ASSERT (Format
!= NULL
);
89 // Convert the DEBUG() message to an ASCII String
91 VA_START (Marker
, Format
);
92 AsciiVSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
96 // Send the print string to a Serial Port
98 SerialPortWrite ((UINT8
*)Buffer
, AsciiStrLen (Buffer
));
102 Convert an UINT32 value into HEX string sepcified by Buffer.
104 @param Value The HEX value to convert to string
105 @param Buffer The pointer to the target buffer to be filled with HEX string
115 for (Idx
= 7; Idx
>= 0; Idx
--) {
116 Buffer
[Idx
] = mHexTable
[Value
& 0x0F];
122 Prints an assert message containing a filename, line number, and description.
123 This may be followed by a breakpoint or a dead loop.
125 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
126 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
127 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
128 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
129 CpuDeadLoop() is called. If neither of these bits are set, then this function
130 returns immediately after the message is printed to the debug output device.
131 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
132 processing another DebugAssert(), then DebugAssert() must return immediately.
134 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
135 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
139 DebugAssertInternal (
143 CHAR8 Buffer
[MAX_DEBUG_MESSAGE_LENGTH
];
146 Frame
= (UINT32
*)GetStackFramePointer ();
149 // Generate the ASSERT() message in Ascii format
151 AsciiStrnCpy (Buffer
, sizeof(Buffer
), "-> EBP:0x00000000 EIP:0x00000000\n");
152 SerialPortWrite ((UINT8
*)"ASSERT DUMP:\n", 13);
153 while (Frame
!= NULL
) {
154 FillHex ((UINT32
)Frame
, Buffer
+ 9);
155 FillHex (Frame
[1], Buffer
+ 9 + 8 + 8);
156 SerialPortWrite ((UINT8
*)Buffer
, AsciiStrLen (Buffer
));
157 if ((Frame
[0] > (UINT32
)Frame
) && (Frame
[0] < (UINT32
)Frame
+ 0x00100000)) {
158 Frame
= (UINT32
*)Frame
[0];
171 Prints an assert message containing a filename, line number, and description.
172 This may be followed by a breakpoint or a dead loop.
174 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
175 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
176 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
177 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
178 CpuDeadLoop() is called. If neither of these bits are set, then this function
179 returns immediately after the message is printed to the debug output device.
180 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
181 processing another DebugAssert(), then DebugAssert() must return immediately.
183 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
184 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
186 @param FileName The pointer to the name of the source file that generated the assert condition.
187 @param LineNumber The line number in the source file that generated the assert condition
188 @param Description The pointer to the description of the assert condition.
194 IN CONST CHAR8
*FileName
,
196 IN CONST CHAR8
*Description
199 DebugAssertInternal ();
204 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
206 This function fills Length bytes of Buffer with the value specified by
207 PcdDebugClearMemoryValue, and returns Buffer.
209 If Buffer is NULL, then ASSERT().
210 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
212 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
213 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
215 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
230 Returns TRUE if ASSERT() macros are enabled.
232 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
233 PcdDebugProperyMask is set. Otherwise FALSE is returned.
235 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
236 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
245 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
) != 0);
250 Returns TRUE if DEBUG() macros are enabled.
252 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
253 PcdDebugProperyMask is set. Otherwise FALSE is returned.
255 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
256 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
265 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
) != 0);
269 Returns TRUE if DEBUG_CODE() macros are enabled.
271 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
272 PcdDebugProperyMask is set. Otherwise FALSE is returned.
274 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
275 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
284 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED
) != 0);
289 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
291 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
292 PcdDebugProperyMask is set. Otherwise FALSE is returned.
294 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
295 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
300 DebugClearMemoryEnabled (
304 return (BOOLEAN
) ((PcdGet8(PcdDebugPropertyMask
) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
) != 0);