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