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