b51e6bc4 |
1 | /** @file\r |
2 | Debug Library that fowards all messages to ReportStatusCode()\r |
3 | \r |
4 | Copyright (c) 2006, 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 |
16 | //\r |
17 | // The package level header files this module uses\r |
18 | //\r |
19 | #include <FrameworkPei.h>\r |
20 | //\r |
21 | // The protocols, PPI and GUID defintions for this module\r |
22 | //\r |
23 | #include <Guid/StatusCodeDataTypeId.h>\r |
24 | //\r |
25 | // The Library classes this module consumes\r |
26 | //\r |
27 | #include <Library/DebugLib.h>\r |
28 | #include <Library/BaseLib.h>\r |
29 | #include <Library/BaseMemoryLib.h>\r |
30 | #include <Library/ReportStatusCodeLib.h>\r |
31 | #include <Library/PcdLib.h>\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 |
45 | \r |
46 | **/\r |
47 | VOID\r |
48 | EFIAPI\r |
49 | DebugPrint (\r |
50 | IN UINTN ErrorLevel,\r |
51 | IN CONST CHAR8 *Format,\r |
52 | ...\r |
53 | )\r |
54 | {\r |
55 | UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];\r |
56 | EFI_DEBUG_INFO *DebugInfo;\r |
57 | UINTN TotalSize;\r |
58 | UINTN Index;\r |
59 | VA_LIST Marker;\r |
60 | UINT64 *ArgumentPointer;\r |
61 | \r |
62 | //\r |
63 | // If Format is NULL, then ASSERT().\r |
64 | //\r |
65 | ASSERT (Format != NULL);\r |
66 | \r |
67 | //\r |
68 | // Check driver Debug Level value and global debug level\r |
69 | //\r |
70 | if ((ErrorLevel & PcdGet32(PcdDebugPrintErrorLevel)) == 0) {\r |
71 | return;\r |
72 | }\r |
73 | \r |
74 | TotalSize = sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrLen (Format) + 1;\r |
75 | if (TotalSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r |
76 | return;\r |
77 | }\r |
78 | \r |
79 | //\r |
80 | // Then EFI_DEBUG_INFO\r |
81 | //\r |
82 | DebugInfo = (EFI_DEBUG_INFO *)Buffer;\r |
83 | DebugInfo->ErrorLevel = (UINT32)ErrorLevel;\r |
84 | \r |
85 | //\r |
86 | // 256 byte mini Var Arg stack. That is followed by the format string.\r |
87 | //\r |
88 | VA_START (Marker, Format);\r |
89 | for (Index = 0, ArgumentPointer = (UINT64 *)(DebugInfo + 1); Index < 12; Index++, ArgumentPointer++) {\r |
90 | WriteUnaligned64(ArgumentPointer, VA_ARG (Marker, UINT64));\r |
91 | }\r |
92 | VA_END (Marker);\r |
93 | AsciiStrCpy ((CHAR8 *)ArgumentPointer, Format);\r |
94 | \r |
95 | REPORT_STATUS_CODE_EX (\r |
96 | EFI_DEBUG_CODE,\r |
97 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_DC_UNSPECIFIED),\r |
98 | 0,\r |
99 | NULL,\r |
100 | &gEfiStatusCodeDataTypeDebugGuid,\r |
101 | DebugInfo,\r |
102 | TotalSize\r |
103 | );\r |
104 | }\r |
105 | \r |
106 | \r |
107 | /**\r |
108 | \r |
109 | Prints an assert message containing a filename, line number, and description.\r |
110 | This may be followed by a breakpoint or a dead loop.\r |
111 | \r |
112 | Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"\r |
113 | to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of\r |
114 | PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if\r |
115 | DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then\r |
116 | CpuDeadLoop() is called. If neither of these bits are set, then this function\r |
117 | returns immediately after the message is printed to the debug output device.\r |
118 | DebugAssert() must actively prevent recusrsion. If DebugAssert() is called while\r |
119 | processing another DebugAssert(), then DebugAssert() must return immediately.\r |
120 | \r |
121 | If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r |
122 | \r |
123 | If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r |
124 | \r |
125 | @param FileName Pointer to the name of the source file that generated the assert condition.\r |
126 | @param LineNumber The line number in the source file that generated the assert condition\r |
127 | @param Description Pointer to the description of the assert condition.\r |
128 | \r |
129 | **/\r |
130 | VOID\r |
131 | EFIAPI\r |
132 | DebugAssert (\r |
133 | IN CONST CHAR8 *FileName,\r |
134 | IN UINTN LineNumber,\r |
135 | IN CONST CHAR8 *Description\r |
136 | )\r |
137 | {\r |
138 | UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof(UINT64)];\r |
139 | EFI_DEBUG_ASSERT_DATA *AssertData;\r |
140 | UINTN TotalSize;\r |
141 | CHAR8 *Temp;\r |
142 | UINTN FileNameLength;\r |
143 | UINTN DescriptionLength;\r |
144 | \r |
145 | //\r |
146 | // Make sure it will all fit in the passed in buffer\r |
147 | //\r |
148 | FileNameLength = AsciiStrLen (FileName);\r |
149 | DescriptionLength = AsciiStrLen (Description);\r |
150 | TotalSize = sizeof (EFI_DEBUG_ASSERT_DATA) + FileNameLength + 1 + DescriptionLength + 1;\r |
151 | if (TotalSize <= EFI_STATUS_CODE_DATA_MAX_SIZE) {\r |
152 | //\r |
153 | // Fill in EFI_DEBUG_ASSERT_DATA\r |
154 | //\r |
155 | AssertData = (EFI_DEBUG_ASSERT_DATA *)Buffer;\r |
156 | AssertData->LineNumber = (UINT32)LineNumber;\r |
157 | \r |
158 | //\r |
159 | // Copy Ascii FileName including NULL.\r |
160 | //\r |
161 | Temp = AsciiStrCpy ((CHAR8 *)(AssertData + 1), FileName);\r |
162 | \r |
163 | //\r |
164 | // Copy Ascii Description\r |
165 | //\r |
166 | AsciiStrCpy (Temp + AsciiStrLen (FileName) + 1, Description);\r |
167 | \r |
168 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r |
169 | (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED),\r |
170 | (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ILLEGAL_SOFTWARE_STATE),\r |
171 | AssertData,\r |
172 | TotalSize\r |
173 | );\r |
174 | }\r |
175 | \r |
176 | //\r |
177 | // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings\r |
178 | //\r |
179 | if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {\r |
180 | CpuBreakpoint ();\r |
181 | } else if ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {\r |
182 | CpuDeadLoop ();\r |
183 | }\r |
184 | }\r |
185 | \r |
186 | \r |
187 | /**\r |
188 | \r |
189 | Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.\r |
190 | \r |
191 | This function fills Length bytes of Buffer with the value specified by\r |
192 | PcdDebugClearMemoryValue, and returns Buffer.\r |
193 | \r |
194 | If Buffer is NULL, then ASSERT().\r |
195 | \r |
196 | If Length is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().\r |
197 | \r |
198 | @param Buffer Pointer to the target buffer to fill with PcdDebugClearMemoryValue.\r |
199 | @param Length Number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.\r |
200 | \r |
201 | @return Buffer\r |
202 | \r |
203 | **/\r |
204 | VOID *\r |
205 | EFIAPI\r |
206 | DebugClearMemory (\r |
207 | OUT VOID *Buffer,\r |
208 | IN UINTN Length\r |
209 | )\r |
210 | {\r |
211 | //\r |
212 | // If Buffer is NULL, then ASSERT().\r |
213 | //\r |
214 | ASSERT (Buffer != NULL);\r |
215 | \r |
216 | //\r |
217 | // SetMem() checks for the the ASSERT() condition on Length and returns Buffer\r |
218 | //\r |
219 | return SetMem (Buffer, Length, PcdGet8(PcdDebugClearMemoryValue));\r |
220 | }\r |
221 | \r |
222 | \r |
223 | /**\r |
224 | \r |
225 | Returns TRUE if ASSERT() macros are enabled.\r |
226 | \r |
227 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of\r |
228 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
229 | \r |
230 | @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.\r |
231 | @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.\r |
232 | \r |
233 | **/\r |
234 | BOOLEAN\r |
235 | EFIAPI\r |
236 | DebugAssertEnabled (\r |
237 | VOID\r |
238 | )\r |
239 | {\r |
240 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);\r |
241 | }\r |
242 | \r |
243 | \r |
244 | /**\r |
245 | \r |
246 | Returns TRUE if DEBUG()macros are enabled.\r |
247 | \r |
248 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of\r |
249 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
250 | \r |
251 | @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.\r |
252 | @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.\r |
253 | \r |
254 | **/\r |
255 | BOOLEAN\r |
256 | EFIAPI\r |
257 | DebugPrintEnabled (\r |
258 | VOID\r |
259 | )\r |
260 | {\r |
261 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);\r |
262 | }\r |
263 | \r |
264 | \r |
265 | /**\r |
266 | \r |
267 | Returns TRUE if DEBUG_CODE()macros are enabled.\r |
268 | \r |
269 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of\r |
270 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
271 | \r |
272 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.\r |
273 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.\r |
274 | \r |
275 | **/\r |
276 | BOOLEAN\r |
277 | EFIAPI\r |
278 | DebugCodeEnabled (\r |
279 | VOID\r |
280 | )\r |
281 | {\r |
282 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r |
283 | }\r |
284 | \r |
285 | \r |
286 | /**\r |
287 | \r |
288 | Returns TRUE if DEBUG_CLEAR_MEMORY()macro is enabled.\r |
289 | \r |
290 | This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of\r |
291 | PcdDebugProperyMask is set. Otherwise FALSE is returned.\r |
292 | \r |
293 | @retval TRUE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.\r |
294 | @retval FALSE The DEBUG_PROPERTY_DEBUG_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.\r |
295 | \r |
296 | **/\r |
297 | BOOLEAN\r |
298 | EFIAPI\r |
299 | DebugClearMemoryEnabled (\r |
300 | VOID\r |
301 | )\r |
302 | {\r |
303 | return (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);\r |
304 | }\r |