2 OEM hook status code library functions with no library constructor/destructor
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 Module Name: Nt32OemHookStatusCodeLib.c
12 // The package level header files this module uses
14 #include <WinNtPeim.h>
17 // The protocols, PPI and GUID defintions for this module
19 #include <Guid/StatusCodeDataTypeId.h>
20 #include <Guid/StatusCodeDataTypeDebug.h>
21 #include <Ppi/NtThunk.h>
23 // The Library classes this module consumes
25 #include <Library/OemHookStatusCodeLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/PrintLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/PeiServicesLib.h>
33 // Cache of WinNtThunk protocol
35 EFI_WIN_NT_THUNK_PROTOCOL
*mWinNt
;
38 // Cache of standard output handle .
44 Initialize OEM status code device .
46 @return Always return EFI_SUCCESS.
51 OemHookStatusCodeInitialize (
55 PEI_NT_THUNK_PPI
*NtThunkPpi
;
60 // Locate NtThunkPpi for retrieving standard output handle
62 Status
= PeiServicesLocatePpi (
69 ASSERT_EFI_ERROR (Status
);
71 mWinNt
= (EFI_WIN_NT_THUNK_PROTOCOL
*) NtThunkPpi
->NtThunk ();
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 UEFI 2.0 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
];
132 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
134 // Print ASSERT() information into output buffer.
136 CharCount
= AsciiSPrint (
139 "\n\rASSERT!: %a (%d): %a\n\r",
146 // Callout to standard output.
158 } else if (Data
!= NULL
&&
159 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
161 // Print DEBUG() information into output buffer.
163 CharCount
= AsciiBSPrint (
169 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
171 // Print ERROR information into output buffer.
173 CharCount
= AsciiSPrint (
176 "ERROR: C%x:V%x I%x",
183 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
186 if (CallerId
!= NULL
) {
187 CharCount
+= AsciiSPrint (
188 &Buffer
[CharCount
- 1],
189 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
196 CharCount
+= AsciiSPrint (
197 &Buffer
[CharCount
- 1],
198 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
204 CharCount
+= AsciiSPrint (
205 &Buffer
[CharCount
- 1],
206 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
209 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
210 CharCount
= AsciiSPrint (
213 "PROGRESS CODE: V%x I%x\n\r",
218 CharCount
= AsciiSPrint (
221 "Undefined: C%x:V%x I%x\n\r",
229 // Callout to standard output.