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