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