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