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
17 // The protocols, PPI and GUID defintions for this module
19 #include <Protocol/WinNtThunk.h>
20 #include <Guid/StatusCodeDataTypeId.h>
21 #include <Guid/StatusCodeDataTypeDebug.h>
23 // The Library classes this module consumes
25 #include <Library/OemHookStatusCodeLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/HobLib.h>
28 #include <Library/PrintLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/ReportStatusCodeLib.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 EFI_HOB_GUID_TYPE
*GuidHob
;
58 // Retrieve WinNtThunkProtocol from GUID'ed HOB
60 GuidHob
= GetFirstGuidHob (&gEfiWinNtThunkProtocolGuid
);
61 ASSERT (GuidHob
!= NULL
);
62 mWinNt
= (EFI_WIN_NT_THUNK_PROTOCOL
*)(*(UINTN
*)(GET_GUID_HOB_DATA (GuidHob
)));
63 ASSERT (mWinNt
!= NULL
);
66 // Cache standard output handle.
68 mStdOut
= mWinNt
->GetStdHandle (STD_OUTPUT_HANDLE
);
74 Report status code to OEM device.
76 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
78 @param Value Describes the current status of a hardware or software entity.
79 This included information about the class and subclass that is used to classify the entity
80 as well as an operation. For progress codes, the operation is the current activity.
81 For error codes, it is the exception. For debug codes, it is not defined at this time.
82 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
83 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
85 @param Instance The enumeration of a hardware or software entity within the system.
86 A system may contain multiple entities that match a class/subclass pairing.
87 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
88 not meaningful, or not relevant. Valid instance numbers start with 1.
91 @param CallerId This optional parameter may be used to identify the caller.
92 This parameter allows the status code driver to apply different rules to different callers.
93 Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
96 @param Data This optional parameter may be used to pass additional data
98 @return The function always return EFI_SUCCESS.
103 OemHookStatusCodeReport (
104 IN EFI_STATUS_CODE_TYPE CodeType
,
105 IN EFI_STATUS_CODE_VALUE Value
,
107 IN EFI_GUID
*CallerId
, OPTIONAL
108 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
114 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
123 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
125 // Print ASSERT() information into output buffer.
127 CharCount
= AsciiSPrint (
130 "\n\rASSERT!: %a (%d): %a\n\r",
137 // Callout to standard output.
149 } else if (Data
!= NULL
&&
150 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
152 // Print DEBUG() information into output buffer.
154 CharCount
= AsciiBSPrint (
160 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
162 // Print ERROR information into output buffer.
164 CharCount
= AsciiSPrint (
167 "ERROR: C%x:V%x I%x",
174 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
177 if (CallerId
!= NULL
) {
178 CharCount
+= AsciiSPrint (
179 &Buffer
[CharCount
- 1],
180 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
187 CharCount
+= AsciiSPrint (
188 &Buffer
[CharCount
- 1],
189 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
195 CharCount
+= AsciiSPrint (
196 &Buffer
[CharCount
- 1],
197 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
200 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
201 CharCount
= AsciiSPrint (
204 "PROGRESS CODE: V%x I%x\n\r",
209 CharCount
= AsciiSPrint (
212 "Undefined: C%x:V%x I%x\n\r",
220 // Callout to standard output.