2 OEM hook status code library functions with no library constructor/destructor
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 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 <WinNtPeim.h>
23 // The protocols, PPI and GUID defintions for this module
25 #include <Guid/StatusCodeDataTypeId.h>
26 #include <Guid/StatusCodeDataTypeDebug.h>
27 #include <Ppi/NtThunk.h>
29 // The Library classes this module consumes
31 #include <Library/OemHookStatusCodeLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/PrintLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/ReportStatusCodeLib.h>
36 #include <Library/PeiServicesLib.h>
39 // Cache of WinNtThunk protocol
41 EFI_WIN_NT_THUNK_PROTOCOL
*mWinNt
;
44 // Cache of standard output handle .
50 Initialize OEM status code device .
52 @return Always return EFI_SUCCESS.
57 OemHookStatusCodeInitialize (
61 PEI_NT_THUNK_PPI
*NtThunkPpi
;
66 // Locate NtThunkPpi for retrieving standard output handle
68 Status
= PeiServicesLocatePpi (
75 ASSERT_EFI_ERROR (Status
);
77 mWinNt
= (EFI_WIN_NT_THUNK_PROTOCOL
*) NtThunkPpi
->NtThunk ();
81 // Cache standard output handle.
83 mStdOut
= mWinNt
->GetStdHandle (STD_OUTPUT_HANDLE
);
89 Report status code to OEM device.
91 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
93 @param Value Describes the current status of a hardware or software entity.
94 This included information about the class and subclass that is used to classify the entity
95 as well as an operation. For progress codes, the operation is the current activity.
96 For error codes, it is the exception. For debug codes, it is not defined at this time.
97 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
98 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
100 @param Instance The enumeration of a hardware or software entity within the system.
101 A system may contain multiple entities that match a class/subclass pairing.
102 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
103 not meaningful, or not relevant. Valid instance numbers start with 1.
106 @param CallerId This optional parameter may be used to identify the caller.
107 This parameter allows the status code driver to apply different rules to different callers.
108 Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
111 @param Data This optional parameter may be used to pass additional data
113 @return The function always return EFI_SUCCESS.
118 OemHookStatusCodeReport (
119 IN EFI_STATUS_CODE_TYPE CodeType
,
120 IN EFI_STATUS_CODE_VALUE Value
,
122 IN EFI_GUID
*CallerId
, OPTIONAL
123 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
129 CHAR8 Buffer
[EFI_STATUS_CODE_DATA_MAX_SIZE
];
138 ReportStatusCodeExtractAssertInfo (CodeType
, Value
, Data
, &Filename
, &Description
, &LineNumber
)) {
140 // Print ASSERT() information into output buffer.
142 CharCount
= AsciiSPrint (
145 "\n\rASSERT!: %a (%d): %a\n\r",
152 // Callout to standard output.
164 } else if (Data
!= NULL
&&
165 ReportStatusCodeExtractDebugInfo (Data
, &ErrorLevel
, &Marker
, &Format
)) {
167 // Print DEBUG() information into output buffer.
169 CharCount
= AsciiBSPrint (
175 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_ERROR_CODE
) {
177 // Print ERROR information into output buffer.
179 CharCount
= AsciiSPrint (
182 "ERROR: C%x:V%x I%x",
189 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
192 if (CallerId
!= NULL
) {
193 CharCount
+= AsciiSPrint (
194 &Buffer
[CharCount
- 1],
195 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
202 CharCount
+= AsciiSPrint (
203 &Buffer
[CharCount
- 1],
204 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
210 CharCount
+= AsciiSPrint (
211 &Buffer
[CharCount
- 1],
212 (sizeof (Buffer
) - (sizeof (Buffer
[0]) * CharCount
)),
215 } else if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_PROGRESS_CODE
) {
216 CharCount
= AsciiSPrint (
219 "PROGRESS CODE: V%x I%x\n\r",
224 CharCount
= AsciiSPrint (
227 "Undefined: C%x:V%x I%x\n\r",
235 // Callout to standard output.