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