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