]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/ReportStatusCode.c
Correct the bug to ignore the encapsulated section.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / ReportStatusCode.c
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2004, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 ReportStatusCode.c\r
15\r
16Abstract:\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
28VOID *\r
29EfiConstructStatusCodeData (\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
36Routine Description:\r
37\r
38 Construct stanader header for optional data passed into ReportStatusCode\r
39\r
40Arguments:\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
46Returns:\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
59EFI_STATUS\r
60EfiDebugVPrintWorker (\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
69Routine 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
79Arguments:\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
91Returns:\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
152EFI_STATUS\r
153EfiDebugAssertWorker (\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
162Routine 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
169Arguments:\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
181Returns:\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
199 TotalSize += EfiAsciiStrLen (Filename) + EfiAsciiStrLen (Description);\r
200 if (TotalSize > BufferSize) {\r
201 return EFI_BUFFER_TOO_SMALL;\r
202 }\r
203\r
204 //\r
205 // Fill in EFI_STATUS_CODE_DATA\r
206 //\r
207 AssertData = (EFI_DEBUG_ASSERT_DATA *)\r
208 EfiConstructStatusCodeData (\r
209 (UINT16)(TotalSize - sizeof (EFI_STATUS_CODE_DATA)),\r
210 &gEfiStatusCodeDataTypeAssertGuid, \r
211 Buffer\r
212 );\r
213\r
214 //\r
215 // Fill in EFI_DEBUG_ASSERT_DATA\r
216 //\r
217 AssertData->LineNumber = (UINT32)LineNumber;\r
218\r
219 //\r
220 // Copy Ascii FileName including NULL.\r
221 //\r
222 EndOfStr = EfiAsciiStrCpy ((CHAR8 *)(AssertData + 1), Filename);\r
223\r
224 //\r
225 // Copy Ascii Description \r
226 //\r
227 EfiAsciiStrCpy (EndOfStr, Description);\r
228 return EFI_SUCCESS;\r
229}\r
230\r
231\r
232\r
233BOOLEAN\r
234ReportStatusCodeExtractAssertInfo (\r
235 IN EFI_STATUS_CODE_TYPE CodeType,\r
236 IN EFI_STATUS_CODE_VALUE Value, \r
237 IN EFI_STATUS_CODE_DATA *Data, \r
238 OUT CHAR8 **Filename,\r
239 OUT CHAR8 **Description,\r
240 OUT UINT32 *LineNumber\r
241 )\r
242/*++\r
243\r
244Routine Description:\r
245\r
246 Extract assert information from status code data.\r
247\r
248Arguments:\r
249\r
250 CodeType - Code type\r
251 Value - Code value\r
252 Data - Optional data associated with this status code.\r
253 Filename - Filename extracted from Data\r
254 Description - Description extracted from Data\r
255 LineNumber - Line number extracted from Data\r
256\r
257Returns:\r
258\r
259 TRUE - Successfully extracted\r
260 \r
261 FALSE - Extraction failed\r
262\r
263--*/\r
264{\r
265 EFI_DEBUG_ASSERT_DATA *AssertData;\r
266\r
267 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) && \r
268 ((CodeType & EFI_STATUS_CODE_SEVERITY_MASK) == EFI_ERROR_UNRECOVERED)) {\r
269 //\r
270 // Assume if we have an uncontained unrecoverable error that the data hub\r
271 // may not work. So we will print out data here. If we had an IPMI controller,\r
272 // or error log we could wack the hardware here.\r
273 //\r
274 if ((Value & EFI_STATUS_CODE_OPERATION_MASK) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE && (Data != NULL)) {\r
275 //\r
276 // ASSERT (Expresion) - \r
277 // ExtendedData == FileName\r
278 // Instance == Line Nuber\r
279 // NULL == String of Expresion\r
280 //\r
281 AssertData = (EFI_DEBUG_ASSERT_DATA *)(Data + 1);\r
282 *Filename = (CHAR8 *)(AssertData + 1);\r
283 *Description = *Filename + EfiAsciiStrLen (*Filename) + 1;\r
284 *LineNumber = AssertData->LineNumber;\r
285 return TRUE;\r
286 } \r
287 }\r
288 return FALSE;\r
289}\r
290\r
291\r
292BOOLEAN\r
293ReportStatusCodeExtractDebugInfo (\r
294 IN EFI_STATUS_CODE_DATA *Data,\r
295 OUT UINT32 *ErrorLevel,\r
296 OUT VA_LIST *Marker,\r
297 OUT CHAR8 **Format\r
298 )\r
299/*++\r
300\r
301Routine Description:\r
302\r
303 Extract debug information from status code data.\r
304\r
305Arguments:\r
306\r
307 Data - Optional data associated with status code.\r
308 ErrorLevel - Error level extracted from Data\r
309 Marker - VA_LIST extracted from Data\r
310 Format - Format string extracted from Data\r
311\r
312Returns:\r
313\r
314 TRUE - Successfully extracted\r
315 \r
316 FALSE - Extraction failed\r
317\r
318--*/\r
319{\r
320 EFI_DEBUG_INFO *DebugInfo;\r
321\r
322 if ((Data == NULL) || (!EfiCompareGuid (&Data->Type, &gEfiStatusCodeDataTypeDebugGuid))) {\r
323 return FALSE;\r
324 }\r
325 \r
326 DebugInfo = (EFI_DEBUG_INFO *)(Data + 1);\r
327\r
328 *ErrorLevel = DebugInfo->ErrorLevel;\r
329\r
330 //\r
331 // The first 12 * UINTN bytes of the string are really an \r
332 // arguement stack to support varargs on the Format string.\r
333 //\r
334 *Marker = (VA_LIST) (DebugInfo + 1);\r
335 *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
336\r
337 return TRUE;\r
338}\r