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