]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2004, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | ReportStatusCode.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Worker functions for ReportStatusCode\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include "TianoCommon.h"\r | |
23 | #include "EfiCommonLib.h"\r | |
24 | #include EFI_GUID_DEFINITION (StatusCodeCallerId)\r | |
25 | #include EFI_GUID_DEFINITION (StatusCodeDataTypeId)\r | |
26 | \r | |
27 | \r | |
28 | VOID *\r | |
29 | EfiConstructStatusCodeData (\r | |
30 | IN UINT16 DataSize,\r | |
31 | IN EFI_GUID *TypeGuid,\r | |
32 | IN OUT EFI_STATUS_CODE_DATA *Data\r | |
33 | )\r | |
34 | /*++\r | |
35 | \r | |
36 | Routine Description:\r | |
37 | \r | |
38 | Construct stanader header for optional data passed into ReportStatusCode\r | |
39 | \r | |
40 | Arguments:\r | |
41 | \r | |
42 | DataSize - Size of optional data. Does not include EFI_STATUS_CODE_DATA header\r | |
43 | TypeGuid - GUID to place in EFI_STATUS_CODE_DATA\r | |
44 | Data - Buffer to use.\r | |
45 | \r | |
46 | Returns:\r | |
47 | \r | |
48 | Return pointer to Data buffer pointing past the end of EFI_STATUS_CODE_DATA\r | |
49 | \r | |
50 | --*/\r | |
51 | {\r | |
52 | Data->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r | |
53 | Data->Size = (UINT16)(DataSize - sizeof (EFI_STATUS_CODE_DATA));\r | |
54 | EfiCommonLibCopyMem (&Data->Type, TypeGuid, sizeof (EFI_GUID));\r | |
55 | \r | |
56 | return (VOID *)(Data + 1); \r | |
57 | }\r | |
58 | \r | |
59 | EFI_STATUS\r | |
60 | EfiDebugVPrintWorker (\r | |
61 | IN UINTN ErrorLevel,\r | |
62 | IN CHAR8 *Format,\r | |
63 | IN VA_LIST Marker,\r | |
64 | IN UINTN BufferSize,\r | |
65 | IN OUT VOID *Buffer\r | |
66 | )\r | |
67 | /*++\r | |
68 | \r | |
69 | Routine Description:\r | |
70 | \r | |
71 | Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT\r | |
72 | information. If Error Logging hub is not loaded do nothing.\r | |
73 | \r | |
74 | The Format string might be truncated to fit into the status code struture\r | |
75 | which has the max size of EFI_STATUS_CODE_DATA_MAX_SIZE.\r | |
76 | \r | |
77 | We use UINT64 buffers due to IPF alignment concerns.\r | |
78 | \r | |
79 | Arguments:\r | |
80 | \r | |
81 | ErrorLevel - If error level is set do the debug print.\r | |
82 | \r | |
83 | Format - String to use for the print, followed by Print arguments.\r | |
84 | \r | |
85 | Marker - VarArgs\r | |
86 | \r | |
87 | BufferSize - Size of Buffer.\r | |
88 | \r | |
89 | Buffer - Caller allocated buffer, contains ReportStatusCode extended data\r | |
90 | \r | |
91 | Returns:\r | |
92 | \r | |
93 | Status code\r | |
94 | \r | |
95 | EFI_SUCCESS - Successfully printed\r | |
96 | \r | |
97 | --*/\r | |
98 | {\r | |
99 | UINTN Index;\r | |
100 | UINTN FormatStrLen;\r | |
101 | UINTN RemainingStrLen;\r | |
102 | UINT64 *Ptr;\r | |
103 | EFI_DEBUG_INFO *EfiDebug;\r | |
104 | \r | |
105 | \r | |
106 | //\r | |
107 | // Build the type specific EFI_STATUS_CODE_DATA in order\r | |
108 | //\r | |
109 | \r | |
110 | //\r | |
111 | // Fill in EFI_STATUS_CODE_DATA to Buffer.\r | |
112 | //\r | |
113 | EfiDebug = (EFI_DEBUG_INFO *)EfiConstructStatusCodeData (\r | |
114 | (UINT16)BufferSize, \r | |
115 | &gEfiStatusCodeDataTypeDebugGuid, \r | |
116 | Buffer\r | |
117 | );\r | |
118 | \r | |
119 | //\r | |
120 | // Then EFI_DEBUG_INFO\r | |
121 | //\r | |
122 | EfiDebug->ErrorLevel = (UINT32)ErrorLevel;\r | |
123 | \r | |
124 | //\r | |
125 | // 12 * sizeof (UINT64) byte mini Var Arg stack.\r | |
126 | // That is followed by the format string.\r | |
127 | //\r | |
128 | for (Index = 0, Ptr = (UINT64 *)(EfiDebug + 1); Index < 12; Index++, Ptr++) {\r | |
129 | *Ptr = VA_ARG (Marker, UINT64);\r | |
130 | }\r | |
131 | \r | |
132 | //\r | |
133 | // Place Ascii Format string at the end\r | |
134 | // Truncate it to fit into the status code structure\r | |
135 | //\r | |
136 | FormatStrLen = EfiAsciiStrLen (Format);\r | |
137 | RemainingStrLen = EFI_STATUS_CODE_DATA_MAX_SIZE\r | |
138 | - sizeof (EFI_STATUS_CODE_DATA)\r | |
139 | - sizeof (EFI_DEBUG_INFO)\r | |
140 | - 12 * sizeof (UINT64) - 1;\r | |
141 | if (FormatStrLen > RemainingStrLen) {\r | |
142 | FormatStrLen = RemainingStrLen;\r | |
143 | }\r | |
144 | EfiCommonLibCopyMem (Ptr, Format, FormatStrLen);\r | |
145 | *((CHAR8 *) Ptr + FormatStrLen) = '\0';\r | |
146 | \r | |
147 | return EFI_SUCCESS;\r | |
148 | }\r | |
149 | \r | |
150 | \r | |
151 | \r | |
152 | EFI_STATUS\r | |
153 | EfiDebugAssertWorker (\r | |
154 | IN CHAR8 *Filename,\r | |
155 | IN INTN LineNumber,\r | |
156 | IN CHAR8 *Description,\r | |
157 | IN UINTN BufferSize,\r | |
158 | IN OUT VOID *Buffer\r | |
159 | )\r | |
160 | /*++\r | |
161 | \r | |
162 | Routine Description:\r | |
163 | \r | |
164 | Worker function for ASSERT (). If Error Logging hub is loaded log ASSERT\r | |
165 | information. If Error Logging hub is not loaded DEADLOOP ().\r | |
166 | \r | |
167 | We use UINT64 buffers due to IPF alignment concerns.\r | |
168 | \r | |
169 | Arguments:\r | |
170 | \r | |
171 | Filename - File name of failing routine.\r | |
172 | \r | |
173 | LineNumber - Line number of failing ASSERT().\r | |
174 | \r | |
175 | Description - Description, usually the assertion,\r | |
176 | \r | |
177 | BufferSize - Size of Buffer.\r | |
178 | \r | |
179 | Buffer - Caller allocated buffer, contains ReportStatusCode extendecd data\r | |
180 | \r | |
181 | Returns:\r | |
182 | \r | |
183 | Status code\r | |
184 | \r | |
185 | EFI_BUFFER_TOO_SMALL - Buffer not large enough\r | |
186 | \r | |
187 | EFI_SUCCESS - Function successfully done.\r | |
188 | \r | |
189 | --*/\r | |
190 | {\r | |
191 | EFI_DEBUG_ASSERT_DATA *AssertData;\r | |
192 | UINTN TotalSize;\r | |
193 | CHAR8 *EndOfStr;\r | |
194 | \r | |
195 | //\r | |
196 | // Make sure it will all fit in the passed in buffer\r | |
197 | //\r | |
198 | TotalSize = sizeof (EFI_STATUS_CODE_DATA) + sizeof (EFI_DEBUG_ASSERT_DATA);\r | |
4cb43192 | 199 | TotalSize += EfiAsciiStrLen (Filename);\r |
200 | TotalSize += EfiAsciiStrLen (Description);\r | |
3eb9473e | 201 | if (TotalSize > BufferSize) {\r |
202 | return EFI_BUFFER_TOO_SMALL;\r | |
203 | }\r | |
204 | \r | |
205 | //\r | |
206 | // Fill in EFI_STATUS_CODE_DATA\r | |
207 | //\r | |
208 | AssertData = (EFI_DEBUG_ASSERT_DATA *)\r | |
209 | EfiConstructStatusCodeData (\r | |
210 | (UINT16)(TotalSize - sizeof (EFI_STATUS_CODE_DATA)),\r | |
211 | &gEfiStatusCodeDataTypeAssertGuid, \r | |
212 | Buffer\r | |
213 | );\r | |
214 | \r | |
215 | //\r | |
216 | // Fill in EFI_DEBUG_ASSERT_DATA\r | |
217 | //\r | |
218 | AssertData->LineNumber = (UINT32)LineNumber;\r | |
219 | \r | |
220 | //\r | |
221 | // Copy Ascii FileName including NULL.\r | |
222 | //\r | |
223 | EndOfStr = EfiAsciiStrCpy ((CHAR8 *)(AssertData + 1), Filename);\r | |
224 | \r | |
225 | //\r | |
226 | // Copy Ascii Description \r | |
227 | //\r | |
228 | EfiAsciiStrCpy (EndOfStr, Description);\r | |
229 | return EFI_SUCCESS;\r | |
230 | }\r | |
231 | \r | |
232 | \r | |
233 | \r | |
234 | BOOLEAN\r | |
235 | ReportStatusCodeExtractAssertInfo (\r | |
236 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
237 | IN EFI_STATUS_CODE_VALUE Value, \r | |
238 | IN EFI_STATUS_CODE_DATA *Data, \r | |
239 | OUT CHAR8 **Filename,\r | |
240 | OUT CHAR8 **Description,\r | |
241 | OUT UINT32 *LineNumber\r | |
242 | )\r | |
243 | /*++\r | |
244 | \r | |
245 | Routine Description:\r | |
246 | \r | |
247 | Extract assert information from status code data.\r | |
248 | \r | |
249 | Arguments:\r | |
250 | \r | |
251 | CodeType - Code type\r | |
252 | Value - Code value\r | |
253 | Data - Optional data associated with this status code.\r | |
254 | Filename - Filename extracted from Data\r | |
255 | Description - Description extracted from Data\r | |
256 | LineNumber - Line number extracted from Data\r | |
257 | \r | |
258 | Returns:\r | |
259 | \r | |
260 | TRUE - Successfully extracted\r | |
261 | \r | |
262 | FALSE - Extraction failed\r | |
263 | \r | |
264 | --*/\r | |
265 | {\r | |
266 | EFI_DEBUG_ASSERT_DATA *AssertData;\r | |
267 | \r | |
268 | if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) && \r | |
269 | ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED)) {\r | |
270 | //\r | |
271 | // Assume if we have an uncontained unrecoverable error that the data hub\r | |
272 | // may not work. So we will print out data here. If we had an IPMI controller,\r | |
273 | // or error log we could wack the hardware here.\r | |
274 | //\r | |
275 | if ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE && (Data != NULL)) {\r | |
276 | //\r | |
277 | // ASSERT (Expresion) - \r | |
278 | // ExtendedData == FileName\r | |
279 | // Instance == Line Nuber\r | |
280 | // NULL == String of Expresion\r | |
281 | //\r | |
282 | AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r | |
283 | *Filename = (CHAR8 *)(AssertData + 1);\r | |
284 | *Description = *Filename + EfiAsciiStrLen (*Filename) + 1;\r | |
285 | *LineNumber = AssertData->LineNumber;\r | |
286 | return TRUE;\r | |
287 | } \r | |
288 | }\r | |
289 | return FALSE;\r | |
290 | }\r | |
291 | \r | |
292 | \r | |
293 | BOOLEAN\r | |
294 | ReportStatusCodeExtractDebugInfo (\r | |
295 | IN EFI_STATUS_CODE_DATA *Data,\r | |
296 | OUT UINT32 *ErrorLevel,\r | |
297 | OUT VA_LIST *Marker,\r | |
298 | OUT CHAR8 **Format\r | |
299 | )\r | |
300 | /*++\r | |
301 | \r | |
302 | Routine Description:\r | |
303 | \r | |
304 | Extract debug information from status code data.\r | |
305 | \r | |
306 | Arguments:\r | |
307 | \r | |
308 | Data - Optional data associated with status code.\r | |
309 | ErrorLevel - Error level extracted from Data\r | |
310 | Marker - VA_LIST extracted from Data\r | |
311 | Format - Format string extracted from Data\r | |
312 | \r | |
313 | Returns:\r | |
314 | \r | |
315 | TRUE - Successfully extracted\r | |
316 | \r | |
317 | FALSE - Extraction failed\r | |
318 | \r | |
319 | --*/\r | |
320 | {\r | |
321 | EFI_DEBUG_INFO *DebugInfo;\r | |
322 | \r | |
323 | if ((Data == NULL) || (!EfiCompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid))) {\r | |
324 | return FALSE;\r | |
325 | }\r | |
326 | \r | |
327 | DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r | |
328 | \r | |
329 | *ErrorLevel = DebugInfo->ErrorLevel;\r | |
330 | \r | |
331 | //\r | |
332 | // The first 12 * UINTN bytes of the string are really an \r | |
333 | // arguement stack to support varargs on the Format string.\r | |
334 | //\r | |
335 | *Marker = (VA_LIST) (DebugInfo + 1);\r | |
336 | *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r | |
337 | \r | |
338 | return TRUE;\r | |
339 | }\r |