Original range calculation in GetNextFile() is incorrect.
[mirror_edk2.git] / EdkUnixPkg / Library / UnixOemHookStatusCodeLib / UnixOemHookStatusCodeLib.c
CommitLineData
c9093a06 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: UnixOemHookStatusCodeLib.c\r
14\r
15**/\r
16\r
17//\r
18// Cache of UnixThunk protocol \r
19//\r
20STATIC\r
21EFI_UNIX_THUNK_PROTOCOL *mUnix;\r
22\r
23//\r
24// Cache of standard output handle . \r
25//\r
26STATIC\r
27int mStdOut;\r
28\r
29/**\r
30\r
31 Initialize OEM status code device .\r
32\r
33 @return Always return EFI_SUCCESS.\r
34\r
35**/\r
36EFI_STATUS\r
37EFIAPI\r
38OemHookStatusCodeInitialize (\r
39 VOID\r
40 )\r
41{\r
42 PEI_UNIX_THUNK_PPI *UnixThunkPpi;\r
43 EFI_STATUS Status;\r
44\r
45 if (FeaturePcdGet (PcdUnixStatusCodeLibUseForPei)) {\r
46 //\r
47 // Locate NtThunkPpi for retrieving standard output handle\r
48 //\r
49 Status = PeiServicesLocatePpi (\r
50 &gPeiUnixThunkPpiGuid,\r
51 0,\r
52 NULL,\r
53 (VOID **) &UnixThunkPpi\r
54 );\r
55\r
56 ASSERT_EFI_ERROR (Status);\r
57\r
58 mUnix = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();\r
59 } else {\r
60 EFI_HOB_GUID_TYPE *GuidHob;\r
61\r
62 //\r
63 // Retrieve UnixThunkProtocol from GUID'ed HOB\r
64 //\r
65 GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
66 ASSERT (GuidHob != NULL);\r
67 mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
68 ASSERT (mUnix != NULL);\r
69 }\r
70\r
71 //\r
72 // Cache standard output handle.\r
73 //\r
74 mStdOut = 1;
75\r
76 return EFI_SUCCESS;\r
77}\r
78\r
79/**\r
80 Report status code to OEM device.\r
81 \r
82 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
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
89 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
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
94 not meaningful, or not relevant. Valid instance numbers start with 1.\r
95\r
96\r
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
99 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
100\r
101\r
102 @param Data This optional parameter may be used to pass additional data\r
103 \r
104 @return The function always return EFI_SUCCESS.\r
105\r
106**/\r
107EFI_STATUS\r
108EFIAPI\r
109OemHookStatusCodeReport (\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
124 VA_LIST Marker;\r
125 EFI_DEBUG_INFO *DebugInfo;\r
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 mUnix->Write (\r
147 mStdOut,\r
148 Buffer,\r
149 CharCount\r
150 );
151\r
152 return EFI_SUCCESS;\r
153\r
154 } else if (Data != NULL &&\r
155 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
156 //\r
157 // Print DEBUG() information into output buffer.\r
158 //\r
159 CharCount = AsciiVSPrint (\r
160 Buffer, \r
161 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
162 Format, \r
163 Marker\r
164 );\r
165 } else if (Data != NULL && \r
166 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
167 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
168 //\r
169 // Print specific data into output buffer.\r
170 //\r
171 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
172 Marker = (VA_LIST) (DebugInfo + 1);\r
173 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
174\r
175 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
176 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
177 //\r
178 // Print ERROR information into output buffer.\r
179 //\r
180 CharCount = AsciiSPrint (\r
181 Buffer, \r
182 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
183 "ERROR: C%x:V%x I%x", \r
184 CodeType, \r
185 Value, \r
186 Instance\r
187 );\r
188\r
189 //\r
190 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
191 //\r
192 \r
193 if (CallerId != NULL) {\r
194 CharCount += AsciiSPrint (\r
195 &Buffer[CharCount - 1],\r
196 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
197 " %g",\r
198 CallerId\r
199 );\r
200 }\r
201\r
202 if (Data != NULL) {\r
203 CharCount += AsciiSPrint (\r
204 &Buffer[CharCount - 1],\r
205 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
206 " %x",\r
207 Data\r
208 );\r
209 }\r
210\r
211 CharCount += AsciiSPrint (\r
212 &Buffer[CharCount - 1],\r
213 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
214 "\n\r"\r
215 );\r
216 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
217 CharCount = AsciiSPrint (\r
218 Buffer, \r
219 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
220 "PROGRESS CODE: V%x I%x\n\r", \r
221 Value, \r
222 Instance\r
223 );\r
224 } else {\r
225 CharCount = AsciiSPrint (\r
226 Buffer, \r
227 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
228 "Undefined: C%x:V%x I%x\n\r", \r
229 CodeType, \r
230 Value, \r
231 Instance\r
232 );\r
233 }\r
234\r
235 //\r
236 // Callout to standard output.\r
237 //\r
238 mUnix->Write (\r
239 mStdOut,\r
240 Buffer,\r
241 CharCount\r
242 );\r
243\r
244 return EFI_SUCCESS;\r
245}\r
246\r