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