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