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 <FrameworkPei.h>
21 #include <FrameworkModulePei.h>
22 #include <WinNtPeim.h>
25 // The protocols, PPI and GUID defintions for this module
27 #include <Guid/StatusCodeDataTypeId.h>
28 #include <Ppi/NtThunk.h>
30 // The Library classes this module consumes
32 #include <Library/OemHookStatusCodeLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/PrintLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/ReportStatusCodeLib.h>
37 #include <Library/PeiServicesLib.h>
38 #include <DebugInfo.h>
41 // Cache of WinNtThunk protocol
44 EFI_WIN_NT_THUNK_PROTOCOL
*mWinNt
;
47 // Cache of standard output handle .
54 Initialize OEM status code device .
56 @return Always return EFI_SUCCESS.
61 OemHookStatusCodeInitialize (
65 PEI_NT_THUNK_PPI
*NtThunkPpi
;
70 // Locate NtThunkPpi for retrieving standard output handle
72 Status
= PeiServicesLocatePpi (
79 ASSERT_EFI_ERROR (Status
);
81 mWinNt
= (EFI_WIN_NT_THUNK_PROTOCOL
*) NtThunkPpi
->NtThunk ();
85 // Cache standard output handle.
87 mStdOut
= mWinNt
->GetStdHandle (STD_OUTPUT_HANDLE
);
93 Report status code to OEM device.
95 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
97 @param Value Describes the current status of a hardware or software entity.
98 This included information about the class and subclass that is used to classify the entity
99 as well as an operation. For progress codes, the operation is the current activity.
100 For error codes, it is the exception. For debug codes, it is not defined at this time.
101 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
102 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
104 @param Instance The enumeration of a hardware or software entity within the system.
105 A system may contain multiple entities that match a class/subclass pairing.
106 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
107 not meaningful, or not relevant. Valid instance numbers start with 1.
110 @param CallerId This optional parameter may be used to identify the caller.
111 This parameter allows the status code driver to apply different rules to different callers.
112 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
115 @param Data This optional parameter may be used to pass additional data
117 @return The function always return EFI_SUCCESS.
122 OemHookStatusCodeReport (
123 IN EFI_STATUS_CODE_TYPE CodeType
,
124 IN EFI_STATUS_CODE_VALUE Value
,
126 IN EFI_GUID
*CallerId
, OPTIONAL
127 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
133 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
138 EFI_DEBUG_INFO
*DebugInfo
;
143 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
145 // Print ASSERT() information into output buffer.
147 CharCount
= AsciiSPrint (
149 EFI_STATUS_CODE_DATA_MAX_SIZE
,
150 "\n\rASSERT!: %a (%d): %a\n\r",
157 // Callout to standard output.
169 } else if (Data
!= NULL
&&
170 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
172 // Print DEBUG() information into output buffer.
174 CharCount
= AsciiVSPrint (
176 EFI_STATUS_CODE_DATA_MAX_SIZE
,
180 } else if (Data
!= NULL
&&
181 CompareGuid (&Data
->Type
, &gEfiStatusCodeSpecificDataGuid
) &&
182 (CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
184 // Print specific data into output buffer.
186 DebugInfo
= (EFI_DEBUG_INFO
*) (Data
+ 1);
187 Marker
= (VA_LIST
) (DebugInfo
+ 1);
188 Format
= (CHAR8
*) (((UINT64
*) Marker
) + 12);
190 CharCount
= AsciiVSPrint (Buffer
, EFI_STATUS_CODE_DATA_MAX_SIZE
, Format
, Marker
);
191 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
193 // Print ERROR information into output buffer.
195 CharCount
= AsciiSPrint (
197 EFI_STATUS_CODE_DATA_MAX_SIZE
,
198 "ERROR: C%x:V%x I%x",
205 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
208 if (CallerId
!= NULL
) {
209 CharCount
+= AsciiSPrint (
210 &Buffer
[CharCount
- 1],
211 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
218 CharCount
+= AsciiSPrint (
219 &Buffer
[CharCount
- 1],
220 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
226 CharCount
+= AsciiSPrint (
227 &Buffer
[CharCount
- 1],
228 (EFI_STATUS_CODE_DATA_MAX_SIZE
- (sizeof (Buffer
[0]) * CharCount
)),
231 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
232 CharCount
= AsciiSPrint (
234 EFI_STATUS_CODE_DATA_MAX_SIZE
,
235 "PROGRESS CODE: V%x I%x\n\r",
240 CharCount
= AsciiSPrint (
242 EFI_STATUS_CODE_DATA_MAX_SIZE
,
243 "Undefined: C%x:V%x I%x\n\r",
251 // Callout to standard output.