]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/Nt32OemHookStatusCodeLib.c
Nt32Pkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / Nt32Pkg / Library / PeiNt32OemHookStatusCodeLib / Nt32OemHookStatusCodeLib.c
1 /** @file
2 OEM hook status code library functions with no library constructor/destructor
3
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 Module Name: Nt32OemHookStatusCodeLib.c
8
9 **/
10
11 //
12 // The package level header files this module uses
13 //
14 #include <WinNtPeim.h>
15
16 //
17 // The protocols, PPI and GUID defintions for this module
18 //
19 #include <Guid/StatusCodeDataTypeId.h>
20 #include <Guid/StatusCodeDataTypeDebug.h>
21 #include <Ppi/NtThunk.h>
22 //
23 // The Library classes this module consumes
24 //
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>
31
32 //
33 // Cache of WinNtThunk protocol
34 //
35 EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;
36
37 //
38 // Cache of standard output handle .
39 //
40 HANDLE mStdOut;
41
42 /**
43
44 Initialize OEM status code device .
45
46 @return Always return EFI_SUCCESS.
47
48 **/
49 EFI_STATUS
50 EFIAPI
51 OemHookStatusCodeInitialize (
52 VOID
53 )
54 {
55 PEI_NT_THUNK_PPI *NtThunkPpi;
56 EFI_STATUS Status;
57
58
59 //
60 // Locate NtThunkPpi for retrieving standard output handle
61 //
62 Status = PeiServicesLocatePpi (
63 &gPeiNtThunkPpiGuid,
64 0,
65 NULL,
66 (VOID **) &NtThunkPpi
67 );
68
69 ASSERT_EFI_ERROR (Status);
70
71 mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();
72
73
74 //
75 // Cache standard output handle.
76 //
77 mStdOut = mWinNt->GetStdHandle (STD_OUTPUT_HANDLE);
78
79 return EFI_SUCCESS;
80 }
81
82 /**
83 Report status code to OEM device.
84
85 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
86
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.
93
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.
98
99
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.
103
104
105 @param Data This optional parameter may be used to pass additional data
106
107 @return The function always return EFI_SUCCESS.
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 OemHookStatusCodeReport (
113 IN EFI_STATUS_CODE_TYPE CodeType,
114 IN EFI_STATUS_CODE_VALUE Value,
115 IN UINT32 Instance,
116 IN EFI_GUID *CallerId, OPTIONAL
117 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
118 )
119 {
120 CHAR8 *Filename;
121 CHAR8 *Description;
122 CHAR8 *Format;
123 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
124 UINT32 ErrorLevel;
125 UINT32 LineNumber;
126 UINTN CharCount;
127 BASE_LIST Marker;
128
129 Buffer[0] = '\0';
130
131 if (Data != NULL &&
132 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
133 //
134 // Print ASSERT() information into output buffer.
135 //
136 CharCount = AsciiSPrint (
137 Buffer,
138 sizeof (Buffer),
139 "\n\rASSERT!: %a (%d): %a\n\r",
140 Filename,
141 LineNumber,
142 Description
143 );
144
145 //
146 // Callout to standard output.
147 //
148 mWinNt->WriteFile (
149 mStdOut,
150 Buffer,
151 (DWORD)CharCount,
152 (LPDWORD)&CharCount,
153 NULL
154 );
155
156 return EFI_SUCCESS;
157
158 } else if (Data != NULL &&
159 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
160 //
161 // Print DEBUG() information into output buffer.
162 //
163 CharCount = AsciiBSPrint (
164 Buffer,
165 sizeof (Buffer),
166 Format,
167 Marker
168 );
169 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
170 //
171 // Print ERROR information into output buffer.
172 //
173 CharCount = AsciiSPrint (
174 Buffer,
175 sizeof (Buffer),
176 "ERROR: C%x:V%x I%x",
177 CodeType,
178 Value,
179 Instance
180 );
181
182 //
183 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
184 //
185
186 if (CallerId != NULL) {
187 CharCount += AsciiSPrint (
188 &Buffer[CharCount - 1],
189 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
190 " %g",
191 CallerId
192 );
193 }
194
195 if (Data != NULL) {
196 CharCount += AsciiSPrint (
197 &Buffer[CharCount - 1],
198 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
199 " %p",
200 Data
201 );
202 }
203
204 CharCount += AsciiSPrint (
205 &Buffer[CharCount - 1],
206 (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),
207 "\n\r"
208 );
209 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
210 CharCount = AsciiSPrint (
211 Buffer,
212 sizeof (Buffer),
213 "PROGRESS CODE: V%x I%x\n\r",
214 Value,
215 Instance
216 );
217 } else {
218 CharCount = AsciiSPrint (
219 Buffer,
220 sizeof (Buffer),
221 "Undefined: C%x:V%x I%x\n\r",
222 CodeType,
223 Value,
224 Instance
225 );
226 }
227
228 //
229 // Callout to standard output.
230 //
231 mWinNt->WriteFile (
232 mStdOut,
233 Buffer,
234 (DWORD)CharCount,
235 (LPDWORD)&CharCount,
236 NULL
237 );
238
239 return EFI_SUCCESS;
240 }
241