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