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