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