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