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