]>
Commit | Line | Data |
---|---|---|
869f8e34 | 1 | /** @file\r |
2 | OEM hook status code library functions with no library constructor/destructor\r | |
3 | \r | |
f66a43b2 | 4 | Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r |
9d2eedba | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
869f8e34 | 6 | \r |
7 | Module Name: Nt32OemHookStatusCodeLib.c\r | |
8 | \r | |
9 | **/\r | |
10 | \r | |
11 | //\r | |
55206596 | 12 | // The package level header files this module uses\r |
869f8e34 | 13 | //\r |
55206596 | 14 | #include <WinNtPeim.h>\r |
2f053c92 | 15 | \r |
55206596 | 16 | //\r |
17 | // The protocols, PPI and GUID defintions for this module\r | |
18 | //\r | |
19 | #include <Guid/StatusCodeDataTypeId.h>\r | |
5e335a52 | 20 | #include <Guid/StatusCodeDataTypeDebug.h>\r |
55206596 | 21 | #include <Ppi/NtThunk.h>\r |
22 | //\r | |
23 | // The Library classes this module consumes\r | |
24 | //\r | |
25 | #include <Library/OemHookStatusCodeLib.h>\r | |
26 | #include <Library/DebugLib.h>\r | |
27 | #include <Library/PrintLib.h>\r | |
28 | #include <Library/BaseMemoryLib.h>\r | |
29 | #include <Library/ReportStatusCodeLib.h>\r | |
30 | #include <Library/PeiServicesLib.h>\r | |
869f8e34 | 31 | \r |
32 | //\r | |
55206596 | 33 | // Cache of WinNtThunk protocol\r |
869f8e34 | 34 | //\r |
869f8e34 | 35 | EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;\r |
36 | \r | |
37 | //\r | |
55206596 | 38 | // Cache of standard output handle .\r |
869f8e34 | 39 | //\r |
869f8e34 | 40 | HANDLE mStdOut;\r |
41 | \r | |
42 | /**\r | |
43 | \r | |
44 | Initialize OEM status code device .\r | |
45 | \r | |
46 | @return Always return EFI_SUCCESS.\r | |
47 | \r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | EFIAPI\r | |
51 | OemHookStatusCodeInitialize (\r | |
52 | VOID\r | |
53 | )\r | |
54 | {\r | |
55 | PEI_NT_THUNK_PPI *NtThunkPpi;\r | |
56 | EFI_STATUS Status;\r | |
57 | \r | |
55206596 | 58 | \r |
869f8e34 | 59 | //\r |
60 | // Locate NtThunkPpi for retrieving standard output handle\r | |
61 | //\r | |
62 | Status = PeiServicesLocatePpi (\r | |
63 | &gPeiNtThunkPpiGuid,\r | |
64 | 0,\r | |
65 | NULL,\r | |
66 | (VOID **) &NtThunkPpi\r | |
67 | );\r | |
68 | \r | |
69 | ASSERT_EFI_ERROR (Status);\r | |
70 | \r | |
71 | mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();\r | |
55206596 | 72 | \r |
869f8e34 | 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 | |
8a7d75b0 | 102 | Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r |
869f8e34 | 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 | |
110 | EFI_STATUS\r | |
111 | EFIAPI\r | |
112 | OemHookStatusCodeReport (\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 | |
53d74081 | 127 | BASE_LIST Marker;\r |
869f8e34 | 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 | |
be71cc9f | 138 | sizeof (Buffer),\r |
869f8e34 | 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 | |
f66a43b2 | 151 | (DWORD)CharCount,\r |
24c28238 | 152 | (LPDWORD)&CharCount,\r |
869f8e34 | 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 | |
53d74081 | 163 | CharCount = AsciiBSPrint (\r |
55206596 | 164 | Buffer,\r |
be71cc9f | 165 | sizeof (Buffer),\r |
55206596 | 166 | Format,\r |
869f8e34 | 167 | Marker\r |
168 | );\r | |
869f8e34 | 169 | } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r |
170 | //\r | |
171 | // Print ERROR information into output buffer.\r | |
172 | //\r | |
173 | CharCount = AsciiSPrint (\r | |
55206596 | 174 | Buffer,\r |
be71cc9f | 175 | sizeof (Buffer),\r |
55206596 | 176 | "ERROR: C%x:V%x I%x",\r |
177 | CodeType,\r | |
178 | Value,\r | |
869f8e34 | 179 | Instance\r |
180 | );\r | |
181 | \r | |
182 | //\r | |
183 | // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r | |
184 | //\r | |
55206596 | 185 | \r |
869f8e34 | 186 | if (CallerId != NULL) {\r |
187 | CharCount += AsciiSPrint (\r | |
188 | &Buffer[CharCount - 1],\r | |
be71cc9f | 189 | (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r |
869f8e34 | 190 | " %g",\r |
191 | CallerId\r | |
192 | );\r | |
193 | }\r | |
194 | \r | |
195 | if (Data != NULL) {\r | |
196 | CharCount += AsciiSPrint (\r | |
197 | &Buffer[CharCount - 1],\r | |
be71cc9f | 198 | (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r |
d251b34d | 199 | " %p",\r |
869f8e34 | 200 | Data\r |
201 | );\r | |
202 | }\r | |
203 | \r | |
204 | CharCount += AsciiSPrint (\r | |
205 | &Buffer[CharCount - 1],\r | |
be71cc9f | 206 | (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)),\r |
869f8e34 | 207 | "\n\r"\r |
208 | );\r | |
209 | } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r | |
210 | CharCount = AsciiSPrint (\r | |
55206596 | 211 | Buffer,\r |
be71cc9f | 212 | sizeof (Buffer),\r |
55206596 | 213 | "PROGRESS CODE: V%x I%x\n\r",\r |
214 | Value,\r | |
869f8e34 | 215 | Instance\r |
216 | );\r | |
217 | } else {\r | |
218 | CharCount = AsciiSPrint (\r | |
55206596 | 219 | Buffer,\r |
be71cc9f | 220 | sizeof (Buffer),\r |
55206596 | 221 | "Undefined: C%x:V%x I%x\n\r",\r |
222 | CodeType,\r | |
223 | Value,\r | |
869f8e34 | 224 | Instance\r |
225 | );\r | |
226 | }\r | |
227 | \r | |
228 | //\r | |
229 | // Callout to standard output.\r | |
230 | //\r | |
231 | mWinNt->WriteFile (\r | |
232 | mStdOut,\r | |
233 | Buffer,\r | |
f66a43b2 | 234 | (DWORD)CharCount,\r |
24c28238 | 235 | (LPDWORD)&CharCount,\r |
869f8e34 | 236 | NULL\r |
237 | );\r | |
238 | \r | |
239 | return EFI_SUCCESS;\r | |
240 | }\r | |
241 | \r |