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: Nt32OemHookStatusCodeLib.c
18 // The package level header files this module uses
20 #include <FrameWorkDxe.h>
22 #include <DebugInfo.h>
25 // The protocols, PPI and GUID defintions for this module
27 #include <Protocol/WinNtThunk.h>
28 #include <Guid/StatusCodeDataTypeId.h>
30 // The Library classes this module consumes
32 #include <Library/OemHookStatusCodeLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/HobLib.h>
35 #include <Library/PrintLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/ReportStatusCodeLib.h>
40 // Cache of WinNtThunk protocol
43 EFI_WIN_NT_THUNK_PROTOCOL
*mWinNt
;
46 // Cache of standard output handle .
53 Initialize OEM status code device .
55 @return Always return EFI_SUCCESS.
60 OemHookStatusCodeInitialize (
64 EFI_HOB_GUID_TYPE
*GuidHob
;
67 // Retrieve WinNtThunkProtocol from GUID'ed HOB
69 GuidHob
= GetFirstGuidHob (&gEfiWinNtThunkProtocolGuid
);
70 ASSERT (GuidHob
!= NULL
);
71 mWinNt
= (EFI_WIN_NT_THUNK_PROTOCOL
*)(*(UINTN
*)(GET_GUID_HOB_DATA (GuidHob
)));
72 ASSERT (mWinNt
!= NULL
);
75 // Cache standard output handle.
77 mStdOut
= mWinNt
->GetStdHandle (STD_OUTPUT_HANDLE
);
83 Report status code to OEM device.
85 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
87 @param Value Describes the current status of a hardware or software entity.
88 This included information about the class and subclass that is used to classify the entity
89 as well as an operation. For progress codes, the operation is the current activity.
90 For error codes, it is the exception. For debug codes, it is not defined at this time.
91 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
92 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
94 @param Instance The enumeration of a hardware or software entity within the system.
95 A system may contain multiple entities that match a class/subclass pairing.
96 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
97 not meaningful, or not relevant. Valid instance numbers start with 1.
100 @param CallerId This optional parameter may be used to identify the caller.
101 This parameter allows the status code driver to apply different rules to different callers.
102 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
105 @param Data This optional parameter may be used to pass additional data
107 @return The function always return EFI_SUCCESS.
112 OemHookStatusCodeReport (
113 IN EFI_STATUS_CODE_TYPE CodeType
,
114 IN EFI_STATUS_CODE_VALUE Value
,
116 IN EFI_GUID
*CallerId
, OPTIONAL
117 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
123 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
128 EFI_DEBUG_INFO
*DebugInfo
;
133 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
135 // Print ASSERT() information into output buffer.
137 CharCount
= AsciiSPrint (
139 EFI_STATUS_CODE_DATA_MAX_SIZE
,
140 "\n\rASSERT!: %a (%d): %a\n\r",
147 // Callout to standard output.
159 } else if (Data
!= NULL
&&
160 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
162 // Print DEBUG() information into output buffer.
164 CharCount
= AsciiVSPrint (
166 EFI_STATUS_CODE_DATA_MAX_SIZE
,
170 } else if (Data
!= NULL
&&
171 CompareGuid (&Data
->Type
, &gEfiStatusCodeSpecificDataGuid
) &&
172 (CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
174 // Print specific data into output buffer.
176 DebugInfo
= (EFI_DEBUG_INFO
*) (Data
+ 1);
177 Marker
= (VA_LIST
) (DebugInfo
+ 1);
178 Format
= (CHAR8
*) (((UINT64
*) Marker
) + 12);
180 CharCount
= AsciiVSPrint (Buffer
, EFI_STATUS_CODE_DATA_MAX_SIZE
, Format
, Marker
);
181 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
183 // Print ERROR information into output buffer.
185 CharCount
= AsciiSPrint (
187 EFI_STATUS_CODE_DATA_MAX_SIZE
,
188 "ERROR: C%x:V%x I%x",
195 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
198 if (CallerId
!= NULL
) {
199 CharCount
+= AsciiSPrint (
200 &Buffer
[CharCount
- 1],
201 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
208 CharCount
+= AsciiSPrint (
209 &Buffer
[CharCount
- 1],
210 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
216 CharCount
+= AsciiSPrint (
217 &Buffer
[CharCount
- 1],
218 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
221 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
222 CharCount
= AsciiSPrint (
224 EFI_STATUS_CODE_DATA_MAX_SIZE
,
225 "PROGRESS CODE: V%x I%x\n\r",
230 CharCount
= AsciiSPrint (
232 EFI_STATUS_CODE_DATA_MAX_SIZE
,
233 "Undefined: C%x:V%x I%x\n\r",
241 // Callout to standard output.