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