]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDebugLibConOut/DebugLib.c
add in FrameworkIfrSupportLib
[mirror_edk2.git] / MdePkg / Library / UefiDebugLibConOut / DebugLib.c
CommitLineData
e386b444 1/** @file\r
2 UEFI Debug Library that uses PrintLib to send messages to CONOUT.\r
3\r
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
15//\r
c7d265a9 16// The package level header files this module uses\r
e386b444 17//\r
c7d265a9 18#include <Uefi.h>\r
19//\r
20// The protocols, PPI and GUID defintions for this module\r
21//\r
22//\r
23// The Library classes this module consumes\r
24//\r
25#include <Library/DebugLib.h>\r
26#include <Library/UefiBootServicesTableLib.h>\r
27#include <Library/PrintLib.h>\r
28#include <Library/PcdLib.h>\r
29#include <Library/BaseLib.h>\r
30#include <Library/BaseMemoryLib.h>\r
31\r
e386b444 32\r
33//\r
34// Define the maximum debug and assert message length that this library supports \r
35//\r
36#define MAX_DEBUG_MESSAGE_LENGTH 0x100\r
37\r
38\r
39/**\r
40\r
41 Prints a debug message to the debug output device if the specified error level is enabled.\r
42\r
43 If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print \r
44 the message specified by Format and the associated variable argument list to \r
45 the debug output device.\r
46\r
47 If Format is NULL, then ASSERT().\r
48\r
49 @param ErrorLevel The error level of the debug message.\r
50 @param Format Format string for the debug message to print.\r
51\r
52**/\r
53VOID\r
54EFIAPI\r
55DebugPrint (\r
56 IN UINTN ErrorLevel,\r
57 IN CONST CHAR8 *Format,\r
58 ...\r
59 )\r
60{\r
61 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
62 VA_LIST Marker;\r
63\r
64 //\r
65 // If Format is NULL, then ASSERT().\r
66 //\r
67 ASSERT (Format != NULL);\r
68\r
69 //\r
70 // Check driver debug mask value and global mask\r
71 //\r
72 if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r
73 return;\r
74 }\r
75\r
76 //\r
77 // Convert the DEBUG() message to a Unicode String\r
78 //\r
79 VA_START (Marker, Format);\r
80 UnicodeVSPrintAsciiFormat (Buffer, sizeof (Buffer), Format, Marker);\r
81 VA_END (Marker);\r
82\r
83 //\r
84 // Send the print string to the Console Output device\r
85 //\r
86 if ((gST != NULL) && (gST->ConOut != NULL)) {\r
87 gST->ConOut->OutputString (gST->ConOut, Buffer);\r
88 }\r
89}\r
90\r
91\r
92/**\r
93\r
94 Prints an assert message containing a filename, line number, and description. \r
95 This may be followed by a breakpoint or a dead loop.\r
96\r
97 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n" \r
98 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of \r
99 PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if \r
100 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then \r
101 CpuDeadLoop() is called. If neither of these bits are set, then this function \r
102 returns immediately after the message is printed to the debug output device.\r
103 DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r
104 processing another DebugAssert(), then DebugAssert() must return immediately.\r
105\r
106 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
107\r
108 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
109\r
110 @param FileName Pointer to the name of the source file that generated the assert condition.\r
111 @param LineNumber The line number in the source file that generated the assert condition\r
112 @param Description Pointer to the description of the assert condition.\r
113\r
114**/\r
115VOID\r
116EFIAPI\r
117DebugAssert (\r
118 IN CONST CHAR8 *FileName,\r
119 IN UINTN LineNumber,\r
120 IN CONST CHAR8 *Description\r
121 )\r
122{\r
123 CHAR16 Buffer[MAX_DEBUG_MESSAGE_LENGTH];\r
124\r
125 //\r
126 // Generate the ASSERT() message in Unicode format\r
127 //\r
128 UnicodeSPrintAsciiFormat (Buffer, sizeof (Buffer), "ASSERT %s(%d): %s\n", FileName, LineNumber, Description);\r
129\r
130 //\r
131 // Send the print string to the Console Output device\r
132 //\r
133 if ((gST != NULL) && (gST->ConOut != NULL)) {\r
134 gST->ConOut->OutputString (gST->ConOut, Buffer);\r
135 }\r
136\r
137 //\r
138 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r
139 //\r
140 if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r
141 CpuBreakpoint ();\r
142 } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r
143 CpuDeadLoop ();\r
144 }\r
145}\r
146\r
147\r
148/**\r
149\r
150 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r
151\r
152 This function fills Length bytes of Buffer with the value specified by \r
153 PcdDebugClearMemoryValue, and returns Buffer.\r
154\r
155 If Buffer is NULL, then ASSERT().\r
156\r
157 If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT(). \r
158\r
159 @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r
160 @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue. \r
161\r
162 @return Buffer\r
163\r
164**/\r
165VOID *\r
166EFIAPI\r
167DebugClearMemory (\r
168 OUT VOID *Buffer,\r
169 IN UINTN Length\r
170 )\r
171{\r
172 //\r
173 // If Buffer is NULL, then ASSERT().\r
174 //\r
175 ASSERT (Buffer != NULL);\r
176\r
177 //\r
178 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r
179 //\r
180 return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r
181}\r
182\r
183\r
184/**\r
185 \r
186 Returns TRUE if ASSERT() macros are enabled.\r
187\r
188 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of \r
189 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
190\r
191 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r
192 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r
193\r
194**/\r
195BOOLEAN\r
196EFIAPI\r
197DebugAssertEnabled (\r
198 VOID\r
199 )\r
200{\r
201 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r
202}\r
203\r
204\r
205/**\r
206 \r
207 Returns TRUE if DEBUG()macros are enabled.\r
208\r
209 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of \r
210 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
211\r
212 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r
213 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r
214\r
215**/\r
216BOOLEAN\r
217EFIAPI\r
218DebugPrintEnabled (\r
219 VOID\r
220 )\r
221{\r
222 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r
223}\r
224\r
225\r
226/**\r
227 \r
228 Returns TRUE if DEBUG_CODE()macros are enabled.\r
229\r
230 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of \r
231 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
232\r
233 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r
234 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r
235\r
236**/\r
237BOOLEAN\r
238EFIAPI\r
239DebugCodeEnabled (\r
240 VOID\r
241 )\r
242{\r
243 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
244}\r
245\r
246\r
247/**\r
248 \r
249 Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r
250\r
251 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of \r
252 PcdDebugProperyMask is set. Otherwise FALSE is returned.\r
253\r
254 @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r
255 @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r
256\r
257**/\r
258BOOLEAN\r
259EFIAPI\r
260DebugClearMemoryEnabled (\r
261 VOID\r
262 )\r
263{\r
264 return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r
265}\r