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