]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/Nt32OemHookStatusCodeLib.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[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, 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
9
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.
12
13 Module Name: Nt32OemHookStatusCodeLib.c
14
15 **/
16
17 //
18 // The package level header files this module uses
19 //
20 #include <FrameworkPei.h>
21 #include <FrameworkModulePei.h>
22 #include <WinNtPeim.h>
23
24 //
25 // The protocols, PPI and GUID defintions for this module
26 //
27 #include <Guid/StatusCodeDataTypeId.h>
28 #include <Ppi/NtThunk.h>
29 //
30 // The Library classes this module consumes
31 //
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>
39
40 //
41 // Cache of WinNtThunk protocol
42 //
43 EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;
44
45 //
46 // Cache of standard output handle .
47 //
48 HANDLE mStdOut;
49
50 /**
51
52 Initialize OEM status code device .
53
54 @return Always return EFI_SUCCESS.
55
56 **/
57 EFI_STATUS
58 EFIAPI
59 OemHookStatusCodeInitialize (
60 VOID
61 )
62 {
63 PEI_NT_THUNK_PPI *NtThunkPpi;
64 EFI_STATUS Status;
65
66
67 //
68 // Locate NtThunkPpi for retrieving standard output handle
69 //
70 Status = PeiServicesLocatePpi (
71 &gPeiNtThunkPpiGuid,
72 0,
73 NULL,
74 (VOID **) &NtThunkPpi
75 );
76
77 ASSERT_EFI_ERROR (Status);
78
79 mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();
80
81
82 //
83 // Cache standard output handle.
84 //
85 mStdOut = mWinNt->GetStdHandle (STD_OUTPUT_HANDLE);
86
87 return EFI_SUCCESS;
88 }
89
90 /**
91 Report status code to OEM device.
92
93 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
94
95 @param Value Describes the current status of a hardware or software entity.
96 This included information about the class and subclass that is used to classify the entity
97 as well as an operation. For progress codes, the operation is the current activity.
98 For error codes, it is the exception. For debug codes, it is not defined at this time.
99 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
100 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
101
102 @param Instance The enumeration of a hardware or software entity within the system.
103 A system may contain multiple entities that match a class/subclass pairing.
104 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
105 not meaningful, or not relevant. Valid instance numbers start with 1.
106
107
108 @param CallerId This optional parameter may be used to identify the caller.
109 This parameter allows the status code driver to apply different rules to different callers.
110 Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.
111
112
113 @param Data This optional parameter may be used to pass additional data
114
115 @return The function always return EFI_SUCCESS.
116
117 **/
118 EFI_STATUS
119 EFIAPI
120 OemHookStatusCodeReport (
121 IN EFI_STATUS_CODE_TYPE CodeType,
122 IN EFI_STATUS_CODE_VALUE Value,
123 IN UINT32 Instance,
124 IN EFI_GUID *CallerId, OPTIONAL
125 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
126 )
127 {
128 CHAR8 *Filename;
129 CHAR8 *Description;
130 CHAR8 *Format;
131 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
132 UINT32 ErrorLevel;
133 UINT32 LineNumber;
134 UINTN CharCount;
135 VA_LIST Marker;
136 EFI_DEBUG_INFO *DebugInfo;
137
138 Buffer[0] = '\0';
139
140 if (Data != NULL &&
141 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
142 //
143 // Print ASSERT() information into output buffer.
144 //
145 CharCount = AsciiSPrint (
146 Buffer,
147 EFI_STATUS_CODE_DATA_MAX_SIZE,
148 "\n\rASSERT!: %a (%d): %a\n\r",
149 Filename,
150 LineNumber,
151 Description
152 );
153
154 //
155 // Callout to standard output.
156 //
157 mWinNt->WriteFile (
158 mStdOut,
159 Buffer,
160 CharCount,
161 (LPDWORD)&CharCount,
162 NULL
163 );
164
165 return EFI_SUCCESS;
166
167 } else if (Data != NULL &&
168 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
169 //
170 // Print DEBUG() information into output buffer.
171 //
172 CharCount = AsciiVSPrint (
173 Buffer,
174 EFI_STATUS_CODE_DATA_MAX_SIZE,
175 Format,
176 Marker
177 );
178 } else if (Data != NULL &&
179 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
180 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
181 //
182 // Print specific data into output buffer.
183 //
184 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
185 Marker = (VA_LIST) (DebugInfo + 1);
186 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);
187
188 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
189 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
190 //
191 // Print ERROR information into output buffer.
192 //
193 CharCount = AsciiSPrint (
194 Buffer,
195 EFI_STATUS_CODE_DATA_MAX_SIZE,
196 "ERROR: C%x:V%x I%x",
197 CodeType,
198 Value,
199 Instance
200 );
201
202 //
203 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
204 //
205
206 if (CallerId != NULL) {
207 CharCount += AsciiSPrint (
208 &Buffer[CharCount - 1],
209 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
210 " %g",
211 CallerId
212 );
213 }
214
215 if (Data != NULL) {
216 CharCount += AsciiSPrint (
217 &Buffer[CharCount - 1],
218 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
219 " %p",
220 Data
221 );
222 }
223
224 CharCount += AsciiSPrint (
225 &Buffer[CharCount - 1],
226 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
227 "\n\r"
228 );
229 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
230 CharCount = AsciiSPrint (
231 Buffer,
232 EFI_STATUS_CODE_DATA_MAX_SIZE,
233 "PROGRESS CODE: V%x I%x\n\r",
234 Value,
235 Instance
236 );
237 } else {
238 CharCount = AsciiSPrint (
239 Buffer,
240 EFI_STATUS_CODE_DATA_MAX_SIZE,
241 "Undefined: C%x:V%x I%x\n\r",
242 CodeType,
243 Value,
244 Instance
245 );
246 }
247
248 //
249 // Callout to standard output.
250 //
251 mWinNt->WriteFile (
252 mStdOut,
253 Buffer,
254 CharCount,
255 (LPDWORD)&CharCount,
256 NULL
257 );
258
259 return EFI_SUCCESS;
260 }
261