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