]>
Commit | Line | Data |
---|---|---|
2ef2b01e A |
1 | /** @file\r |
2 | UEFI Debug Library that uses PrintLib to send messages to STDERR.\r | |
3 | \r | |
92c0bbd1 | 4 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r |
d6ebcab7 | 5 | Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r |
3402aac7 RC |
6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
2ef2b01e | 10 | \r |
3402aac7 RC |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
2ef2b01e A |
13 | \r |
14 | **/\r | |
15 | \r | |
16 | \r | |
17 | #include <Uefi.h>\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/PrintLib.h>\r | |
20 | #include <Library/PcdLib.h>\r | |
21 | #include <Library/BaseLib.h>\r | |
22 | #include <Library/BaseMemoryLib.h>\r | |
23 | #include <Library/SemihostLib.h>\r | |
24 | \r | |
25 | //\r | |
3402aac7 | 26 | // Define the maximum debug and assert message length that this library supports\r |
2ef2b01e A |
27 | //\r |
28 | #define MAX_DEBUG_MESSAGE_LENGTH 0x100\r | |
29 | \r | |
92c0bbd1 BB |
30 | //\r |
31 | // VA_LIST can not initialize to NULL for all compiler, so we use this to\r | |
32 | // indicate a null VA_LIST\r | |
33 | //\r | |
34 | VA_LIST mVaListNull;\r | |
35 | \r | |
2ef2b01e A |
36 | /**\r |
37 | \r | |
38 | Prints a debug message to the debug output device if the specified error level is enabled.\r | |
39 | \r | |
3402aac7 RC |
40 | If any bit in ErrorLevel is also set in PcdDebugPrintErrorLevel, then print\r |
41 | the message specified by Format and the associated variable argument list to\r | |
2ef2b01e A |
42 | the debug output device.\r |
43 | \r | |
44 | If Format is NULL, then ASSERT().\r | |
45 | \r | |
46 | @param ErrorLevel The error level of the debug message.\r | |
47 | @param Format Format string for the debug message to print.\r | |
48 | \r | |
49 | **/\r | |
50 | VOID\r | |
51 | EFIAPI\r | |
52 | DebugPrint (\r | |
53 | IN UINTN ErrorLevel,\r | |
54 | IN CONST CHAR8 *Format,\r | |
55 | ...\r | |
56 | )\r | |
92c0bbd1 BB |
57 | {\r |
58 | VA_LIST Marker;\r | |
59 | \r | |
60 | VA_START (Marker, Format);\r | |
61 | DebugVPrint (ErrorLevel, Format, Marker);\r | |
62 | VA_END (Marker);\r | |
63 | }\r | |
64 | \r | |
65 | \r | |
66 | /**\r | |
67 | Prints a debug message to the debug output device if the specified\r | |
68 | error level is enabled base on Null-terminated format string and a\r | |
69 | VA_LIST argument list or a BASE_LIST argument list.\r | |
70 | \r | |
71 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
72 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
73 | the associated variable argument list to the debug output device.\r | |
74 | \r | |
75 | If Format is NULL, then ASSERT().\r | |
76 | \r | |
77 | @param ErrorLevel The error level of the debug message.\r | |
78 | @param Format Format string for the debug message to print.\r | |
79 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
80 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
81 | \r | |
82 | **/\r | |
83 | VOID\r | |
84 | DebugPrintMarker (\r | |
85 | IN UINTN ErrorLevel,\r | |
86 | IN CONST CHAR8 *Format,\r | |
87 | IN VA_LIST VaListMarker,\r | |
88 | IN BASE_LIST BaseListMarker\r | |
89 | )\r | |
2ef2b01e A |
90 | {\r |
91 | CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
2ef2b01e A |
92 | \r |
93 | //\r | |
94 | // If Format is NULL, then ASSERT().\r | |
95 | //\r | |
96 | ASSERT (Format != NULL);\r | |
97 | \r | |
98 | //\r | |
99 | // Check driver debug mask value and global mask\r | |
100 | //\r | |
101 | if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r | |
102 | return;\r | |
103 | }\r | |
104 | \r | |
105 | //\r | |
106 | // Convert the DEBUG() message to a Unicode String\r | |
107 | //\r | |
92c0bbd1 BB |
108 | if (BaseListMarker == NULL) {\r |
109 | AsciiVSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, VaListMarker);\r | |
110 | } else {\r | |
111 | AsciiBSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, BaseListMarker);\r | |
112 | }\r | |
2ef2b01e A |
113 | \r |
114 | SemihostWriteString (AsciiBuffer);\r | |
115 | }\r | |
116 | \r | |
117 | \r | |
92c0bbd1 BB |
118 | /**\r |
119 | Prints a debug message to the debug output device if the specified\r | |
120 | error level is enabled.\r | |
121 | \r | |
122 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
123 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
124 | the associated variable argument list to the debug output device.\r | |
125 | \r | |
126 | If Format is NULL, then ASSERT().\r | |
127 | \r | |
128 | @param ErrorLevel The error level of the debug message.\r | |
129 | @param Format Format string for the debug message to print.\r | |
130 | @param VaListMarker VA_LIST marker for the variable argument list.\r | |
131 | \r | |
132 | **/\r | |
133 | VOID\r | |
134 | EFIAPI\r | |
135 | DebugVPrint (\r | |
136 | IN UINTN ErrorLevel,\r | |
137 | IN CONST CHAR8 *Format,\r | |
138 | IN VA_LIST VaListMarker\r | |
139 | )\r | |
140 | {\r | |
141 | DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);\r | |
142 | }\r | |
143 | \r | |
144 | \r | |
145 | /**\r | |
146 | Prints a debug message to the debug output device if the specified\r | |
147 | error level is enabled.\r | |
148 | This function use BASE_LIST which would provide a more compatible\r | |
149 | service than VA_LIST.\r | |
150 | \r | |
151 | If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function\r | |
152 | GetDebugPrintErrorLevel (), then print the message specified by Format and\r | |
153 | the associated variable argument list to the debug output device.\r | |
154 | \r | |
155 | If Format is NULL, then ASSERT().\r | |
156 | \r | |
157 | @param ErrorLevel The error level of the debug message.\r | |
158 | @param Format Format string for the debug message to print.\r | |
159 | @param BaseListMarker BASE_LIST marker for the variable argument list.\r | |
160 | \r | |
161 | **/\r | |
162 | VOID\r | |
163 | EFIAPI\r | |
164 | DebugBPrint (\r | |
165 | IN UINTN ErrorLevel,\r | |
166 | IN CONST CHAR8 *Format,\r | |
167 | IN BASE_LIST BaseListMarker\r | |
168 | )\r | |
169 | {\r | |
170 | DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);\r | |
171 | }\r | |
172 | \r | |
173 | \r | |
2ef2b01e A |
174 | /**\r |
175 | \r | |
3402aac7 | 176 | Prints an assert message containing a filename, line number, and description.\r |
2ef2b01e A |
177 | This may be followed by a breakpoint or a dead loop.\r |
178 | \r | |
3402aac7 RC |
179 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r |
180 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r | |
181 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r | |
182 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r | |
183 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r | |
2ef2b01e A |
184 | returns immediately after the message is printed to the debug output device.\r |
185 | DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r | |
186 | processing another DebugAssert(), then DebugAssert() must return immediately.\r | |
187 | \r | |
188 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r | |
189 | \r | |
190 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r | |
191 | \r | |
192 | @param FileName Pointer to the name of the source file that generated the assert condition.\r | |
193 | @param LineNumber The line number in the source file that generated the assert condition\r | |
194 | @param Description Pointer to the description of the assert condition.\r | |
195 | \r | |
196 | **/\r | |
197 | VOID\r | |
198 | EFIAPI\r | |
199 | DebugAssert (\r | |
200 | IN CONST CHAR8 *FileName,\r | |
201 | IN UINTN LineNumber,\r | |
202 | IN CONST CHAR8 *Description\r | |
203 | )\r | |
204 | {\r | |
205 | CHAR8 AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];\r | |
206 | \r | |
207 | //\r | |
208 | // Generate the ASSERT() message in Unicode format\r | |
209 | //\r | |
210 | AsciiSPrint (AsciiBuffer, sizeof (AsciiBuffer), "ASSERT %a(%d): %a\n", FileName, LineNumber, Description);\r | |
211 | \r | |
212 | SemihostWriteString (AsciiBuffer);\r | |
213 | \r | |
214 | //\r | |
215 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r | |
216 | //\r | |
217 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r | |
218 | CpuBreakpoint ();\r | |
219 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r | |
220 | CpuDeadLoop ();\r | |
221 | }\r | |
222 | }\r | |
223 | \r | |
224 | \r | |
225 | /**\r | |
226 | \r | |
227 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r | |
228 | \r | |
3402aac7 | 229 | This function fills Length bytes of Buffer with the value specified by\r |
2ef2b01e A |
230 | PcdDebugClearMemoryValue, and returns Buffer.\r |
231 | \r | |
232 | If Buffer is NULL, then ASSERT().\r | |
233 | \r | |
3402aac7 | 234 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
2ef2b01e A |
235 | \r |
236 | @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r | |
3402aac7 | 237 | @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r |
2ef2b01e A |
238 | \r |
239 | @return Buffer\r | |
240 | \r | |
241 | **/\r | |
242 | VOID *\r | |
243 | EFIAPI\r | |
244 | DebugClearMemory (\r | |
245 | OUT VOID *Buffer,\r | |
246 | IN UINTN Length\r | |
247 | )\r | |
248 | {\r | |
249 | //\r | |
250 | // If Buffer is NULL, then ASSERT().\r | |
251 | //\r | |
252 | ASSERT (Buffer != NULL);\r | |
253 | \r | |
254 | //\r | |
255 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r | |
256 | //\r | |
257 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r | |
258 | }\r | |
259 | \r | |
260 | \r | |
261 | /**\r | |
3402aac7 | 262 | \r |
2ef2b01e A |
263 | Returns TRUE if ASSERT() macros are enabled.\r |
264 | \r | |
3402aac7 | 265 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r |
2ef2b01e A |
266 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
267 | \r | |
268 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r | |
269 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
270 | \r | |
271 | **/\r | |
272 | BOOLEAN\r | |
273 | EFIAPI\r | |
274 | DebugAssertEnabled (\r | |
275 | VOID\r | |
276 | )\r | |
277 | {\r | |
278 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r | |
279 | }\r | |
280 | \r | |
281 | \r | |
282 | /**\r | |
3402aac7 | 283 | \r |
2ef2b01e A |
284 | Returns TRUE if DEBUG()macros are enabled.\r |
285 | \r | |
3402aac7 | 286 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r |
2ef2b01e A |
287 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
288 | \r | |
289 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r | |
290 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r | |
291 | \r | |
292 | **/\r | |
293 | BOOLEAN\r | |
294 | EFIAPI\r | |
295 | DebugPrintEnabled (\r | |
296 | VOID\r | |
297 | )\r | |
298 | {\r | |
299 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r | |
300 | }\r | |
301 | \r | |
302 | \r | |
303 | /**\r | |
3402aac7 | 304 | \r |
2ef2b01e A |
305 | Returns TRUE if DEBUG_CODE()macros are enabled.\r |
306 | \r | |
3402aac7 | 307 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r |
2ef2b01e A |
308 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
309 | \r | |
310 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r | |
311 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r | |
312 | \r | |
313 | **/\r | |
314 | BOOLEAN\r | |
315 | EFIAPI\r | |
316 | DebugCodeEnabled (\r | |
317 | VOID\r | |
318 | )\r | |
319 | {\r | |
320 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r | |
321 | }\r | |
322 | \r | |
323 | \r | |
324 | /**\r | |
3402aac7 | 325 | \r |
2ef2b01e A |
326 | Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r |
327 | \r | |
3402aac7 | 328 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of\r |
2ef2b01e A |
329 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
330 | \r | |
331 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r | |
332 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r | |
333 | \r | |
334 | **/\r | |
335 | BOOLEAN\r | |
336 | EFIAPI\r | |
337 | DebugClearMemoryEnabled (\r | |
338 | VOID\r | |
339 | )\r | |
340 | {\r | |
341 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r | |
342 | }\r |