3 Copyright (c) 2004, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Worker functions for ReportStatusCode
22 #include "TianoCommon.h"
23 #include "EfiCommonLib.h"
24 #include EFI_GUID_DEFINITION (StatusCodeCallerId)
25 #include EFI_GUID_DEFINITION (StatusCodeDataTypeId)
29 EfiConstructStatusCodeData (
31 IN EFI_GUID
*TypeGuid
,
32 IN OUT EFI_STATUS_CODE_DATA
*Data
38 Construct stanader header for optional data passed into ReportStatusCode
42 DataSize - Size of optional data. Does not include EFI_STATUS_CODE_DATA header
43 TypeGuid - GUID to place in EFI_STATUS_CODE_DATA
48 Return pointer to Data buffer pointing past the end of EFI_STATUS_CODE_DATA
52 Data
->HeaderSize
= sizeof (EFI_STATUS_CODE_DATA
);
53 Data
->Size
= (UINT16
)(DataSize
- sizeof (EFI_STATUS_CODE_DATA
));
54 EfiCommonLibCopyMem (&Data
->Type
, TypeGuid
, sizeof (EFI_GUID
));
56 return (VOID
*)(Data
+ 1);
60 EfiDebugVPrintWorker (
71 Worker function for DEBUG(). If Error Logging hub is loaded log ASSERT
72 information. If Error Logging hub is not loaded do nothing.
74 The Format string might be truncated to fit into the status code struture
75 which has the max size of EFI_STATUS_CODE_DATA_MAX_SIZE.
77 We use UINT64 buffers due to IPF alignment concerns.
81 ErrorLevel - If error level is set do the debug print.
83 Format - String to use for the print, followed by Print arguments.
87 BufferSize - Size of Buffer.
89 Buffer - Caller allocated buffer, contains ReportStatusCode extended data
95 EFI_SUCCESS - Successfully printed
101 UINTN RemainingStrLen
;
103 EFI_DEBUG_INFO
*EfiDebug
;
107 // Build the type specific EFI_STATUS_CODE_DATA in order
111 // Fill in EFI_STATUS_CODE_DATA to Buffer.
113 EfiDebug
= (EFI_DEBUG_INFO
*)EfiConstructStatusCodeData (
115 &gEfiStatusCodeDataTypeDebugGuid
,
120 // Then EFI_DEBUG_INFO
122 EfiDebug
->ErrorLevel
= (UINT32
)ErrorLevel
;
125 // 12 * sizeof (UINT64) byte mini Var Arg stack.
126 // That is followed by the format string.
128 for (Index
= 0, Ptr
= (UINT64
*)(EfiDebug
+ 1); Index
< 12; Index
++, Ptr
++) {
129 *Ptr
= VA_ARG (Marker
, UINT64
);
133 // Place Ascii Format string at the end
134 // Truncate it to fit into the status code structure
136 FormatStrLen
= EfiAsciiStrLen (Format
);
137 RemainingStrLen
= EFI_STATUS_CODE_DATA_MAX_SIZE
138 - sizeof (EFI_STATUS_CODE_DATA
)
139 - sizeof (EFI_DEBUG_INFO
)
140 - 12 * sizeof (UINT64
) - 1;
141 if (FormatStrLen
> RemainingStrLen
) {
142 FormatStrLen
= RemainingStrLen
;
144 EfiCommonLibCopyMem (Ptr
, Format
, FormatStrLen
);
145 *((CHAR8
*) Ptr
+ FormatStrLen
) = '\0';
153 EfiDebugAssertWorker (
156 IN CHAR8
*Description
,
164 Worker function for ASSERT (). If Error Logging hub is loaded log ASSERT
165 information. If Error Logging hub is not loaded DEADLOOP ().
167 We use UINT64 buffers due to IPF alignment concerns.
171 Filename - File name of failing routine.
173 LineNumber - Line number of failing ASSERT().
175 Description - Description, usually the assertion,
177 BufferSize - Size of Buffer.
179 Buffer - Caller allocated buffer, contains ReportStatusCode extendecd data
185 EFI_BUFFER_TOO_SMALL - Buffer not large enough
187 EFI_SUCCESS - Function successfully done.
191 EFI_DEBUG_ASSERT_DATA
*AssertData
;
196 // Make sure it will all fit in the passed in buffer
198 TotalSize
= sizeof (EFI_STATUS_CODE_DATA
) + sizeof (EFI_DEBUG_ASSERT_DATA
);
199 TotalSize
+= EfiAsciiStrLen (Filename
);
200 TotalSize
+= EfiAsciiStrLen (Description
);
201 if (TotalSize
> BufferSize
) {
202 return EFI_BUFFER_TOO_SMALL
;
206 // Fill in EFI_STATUS_CODE_DATA
208 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)
209 EfiConstructStatusCodeData (
210 (UINT16
)(TotalSize
- sizeof (EFI_STATUS_CODE_DATA
)),
211 &gEfiStatusCodeDataTypeAssertGuid
,
216 // Fill in EFI_DEBUG_ASSERT_DATA
218 AssertData
->LineNumber
= (UINT32
)LineNumber
;
221 // Copy Ascii FileName including NULL.
223 EndOfStr
= EfiAsciiStrCpy ((CHAR8
*)(AssertData
+ 1), Filename
);
226 // Copy Ascii Description
228 EfiAsciiStrCpy (EndOfStr
, Description
);
235 ReportStatusCodeExtractAssertInfo (
236 IN EFI_STATUS_CODE_TYPE CodeType
,
237 IN EFI_STATUS_CODE_VALUE Value
,
238 IN EFI_STATUS_CODE_DATA
*Data
,
239 OUT CHAR8
**Filename
,
240 OUT CHAR8
**Description
,
241 OUT UINT32
*LineNumber
247 Extract assert information from status code data.
253 Data - Optional data associated with this status code.
254 Filename - Filename extracted from Data
255 Description - Description extracted from Data
256 LineNumber - Line number extracted from Data
260 TRUE - Successfully extracted
262 FALSE - Extraction failed
266 EFI_DEBUG_ASSERT_DATA
*AssertData
;
268 if (((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) &&
269 ((CodeType
& EFI_STATUS_CODE_SEVERITY_MASK
) == EFI_ERROR_UNRECOVERED
)) {
271 // Assume if we have an uncontained unrecoverable error that the data hub
272 // may not work. So we will print out data here. If we had an IPMI controller,
273 // or error log we could wack the hardware here.
275 if ((Value
& EFI_STATUS_CODE_OPERATION_MASK
) == EFI_SW_EC_ILLEGAL_SOFTWARE_STATE
&& (Data
!= NULL
)) {
277 // ASSERT (Expresion) -
278 // ExtendedData == FileName
279 // Instance == Line Nuber
280 // NULL == String of Expresion
282 AssertData
= (EFI_DEBUG_ASSERT_DATA
*)(Data
+ 1);
283 *Filename
= (CHAR8
*)(AssertData
+ 1);
284 *Description
= *Filename
+ EfiAsciiStrLen (*Filename
) + 1;
285 *LineNumber
= AssertData
->LineNumber
;
294 ReportStatusCodeExtractDebugInfo (
295 IN EFI_STATUS_CODE_DATA
*Data
,
296 OUT UINT32
*ErrorLevel
,
304 Extract debug information from status code data.
308 Data - Optional data associated with status code.
309 ErrorLevel - Error level extracted from Data
310 Marker - VA_LIST extracted from Data
311 Format - Format string extracted from Data
315 TRUE - Successfully extracted
317 FALSE - Extraction failed
321 EFI_DEBUG_INFO
*DebugInfo
;
323 if ((Data
== NULL
) || (!EfiCompareGuid (&Data
->Type
, &gEfiStatusCodeDataTypeDebugGuid
))) {
327 DebugInfo
= (EFI_DEBUG_INFO
*)(Data
+ 1);
329 *ErrorLevel
= DebugInfo
->ErrorLevel
;
332 // The first 12 * UINTN bytes of the string are really an
333 // arguement stack to support varargs on the Format string.
335 *Marker
= (VA_LIST
) (DebugInfo
+ 1);
336 *Format
= (CHAR8
*)(((UINT64
*)*Marker
) + 12);