2 OEM hook status code library functions with no library constructor/destructor
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 Module Name: UnixOemHookStatusCodeLib.c
17 #include <Guid/StatusCodeDataTypeId.h>
19 #include <Library/OemHookStatusCodeLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/PrintLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/ReportStatusCodeLib.h>
25 #include <FrameworkModuleBase.h>
26 #include <DebugInfo.h>
29 // Cache of UnixThunk protocol
31 EFI_UNIX_THUNK_PROTOCOL
*mUnix
;
34 // Cache of standard output handle .
40 Initialize OEM status code device .
42 @return Always return EFI_SUCCESS.
47 OemHookStatusCodeInitialize (
51 EFI_HOB_GUID_TYPE
*GuidHob
;
54 // Retrieve UnixThunkProtocol from GUID'ed HOB
56 GuidHob
= GetFirstGuidHob (&gEfiUnixThunkProtocolGuid
);
57 ASSERT (GuidHob
!= NULL
);
58 mUnix
= (EFI_UNIX_THUNK_PROTOCOL
*)(*(UINTN
*)(GET_GUID_HOB_DATA (GuidHob
)));
59 ASSERT (mUnix
!= NULL
);
62 // Cache standard output handle.
70 Report status code to OEM device.
72 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
74 @param Value Describes the current status of a hardware or software entity.
75 This included information about the class and subclass that is used to classify the entity
76 as well as an operation. For progress codes, the operation is the current activity.
77 For error codes, it is the exception. For debug codes, it is not defined at this time.
78 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
79 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
81 @param Instance The enumeration of a hardware or software entity within the system.
82 A system may contain multiple entities that match a class/subclass pairing.
83 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
84 not meaningful, or not relevant. Valid instance numbers start with 1.
87 @param CallerId This optional parameter may be used to identify the caller.
88 This parameter allows the status code driver to apply different rules to different callers.
89 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
92 @param Data This optional parameter may be used to pass additional data
94 @return The function always return EFI_SUCCESS.
99 OemHookStatusCodeReport (
100 IN EFI_STATUS_CODE_TYPE CodeType
,
101 IN EFI_STATUS_CODE_VALUE Value
,
103 IN EFI_GUID
*CallerId
, OPTIONAL
104 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
110 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
115 EFI_DEBUG_INFO
*DebugInfo
;
120 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
122 // Print ASSERT() information into output buffer.
124 CharCount
= AsciiSPrint (
126 EFI_STATUS_CODE_DATA_MAX_SIZE
,
127 "\n\rASSERT!: %a (%d): %a\n\r",
134 // Callout to standard output.
144 } else if (Data
!= NULL
&&
145 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
147 // Print DEBUG() information into output buffer.
149 CharCount
= AsciiBSPrint (
151 EFI_STATUS_CODE_DATA_MAX_SIZE
,
155 } else if (Data
!= NULL
&&
156 CompareGuid (&Data
->Type
, &gEfiStatusCodeSpecificDataGuid
) &&
157 (CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
159 // Print specific data into output buffer.
161 DebugInfo
= (EFI_DEBUG_INFO
*) (Data
+ 1);
162 Marker
= (BASE_LIST
) (DebugInfo
+ 1);
163 Format
= (CHAR8
*) (((UINT64
*) Marker
) + 12);
165 CharCount
= AsciiBSPrint (Buffer
, EFI_STATUS_CODE_DATA_MAX_SIZE
, Format
, Marker
);
166 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
168 // Print ERROR information into output buffer.
170 CharCount
= AsciiSPrint (
172 EFI_STATUS_CODE_DATA_MAX_SIZE
,
173 "ERROR: C%x:V%x I%x",
180 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
183 if (CallerId
!= NULL
) {
184 CharCount
+= AsciiSPrint (
185 &Buffer
[CharCount
- 1],
186 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
193 CharCount
+= AsciiSPrint (
194 &Buffer
[CharCount
- 1],
195 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
201 CharCount
+= AsciiSPrint (
202 &Buffer
[CharCount
- 1],
203 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
206 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
207 CharCount
= AsciiSPrint (
209 EFI_STATUS_CODE_DATA_MAX_SIZE
,
210 "PROGRESS CODE: V%x I%x\n\r",
215 CharCount
= AsciiSPrint (
217 EFI_STATUS_CODE_DATA_MAX_SIZE
,
218 "Undefined: C%x:V%x I%x\n\r",
226 // Callout to standard output.