]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
This checkin addresses the compatibility issue of passing arguments of type VA_LIST...
[mirror_edk2.git] / UnixPkg / Library / DxeUnixOemHookStatusCodeLib / UnixOemHookStatusCodeLib.c
CommitLineData
804405e7 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#include "PiDxe.h"\r
17#include <Guid/StatusCodeDataTypeId.h>\r
18#include "UnixDxe.h"\r
19#include <Library/OemHookStatusCodeLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/HobLib.h>\r
22#include <Library/PrintLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/ReportStatusCodeLib.h>\r
25#include <FrameworkModuleBase.h>\r
26#include <DebugInfo.h>\r
27\r
28//\r
29// Cache of UnixThunk protocol \r
30//\r
804405e7 31EFI_UNIX_THUNK_PROTOCOL *mUnix;\r
32\r
33//\r
34// Cache of standard output handle . \r
35//\r
804405e7 36int mStdOut;\r
37\r
38/**\r
39\r
40 Initialize OEM status code device .\r
41\r
42 @return Always return EFI_SUCCESS.\r
43\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47OemHookStatusCodeInitialize (\r
48 VOID\r
49 )\r
50{\r
51 EFI_HOB_GUID_TYPE *GuidHob;\r
52\r
53 //\r
54 // Retrieve UnixThunkProtocol from GUID'ed HOB\r
55 //\r
56 GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
57 ASSERT (GuidHob != NULL);\r
58 mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
59 ASSERT (mUnix != NULL);\r
60\r
61 //\r
62 // Cache standard output handle.\r
63 //\r
64 mStdOut = 1;
65\r
66 return EFI_SUCCESS;\r
67}\r
68\r
69/**\r
70 Report status code to OEM device.\r
71 \r
72 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
73 \r
74 @param Value Describes the current status of a hardware or software entity. \r
75 This included information about the class and subclass that is used to classify the entity \r
76 as well as an operation. For progress codes, the operation is the current activity. \r
77 For error codes, it is the exception. For debug codes, it is not defined at this time. \r
78 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. \r
79 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
80 \r
81 @param Instance The enumeration of a hardware or software entity within the system. \r
82 A system may contain multiple entities that match a class/subclass pairing. \r
83 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, \r
84 not meaningful, or not relevant. Valid instance numbers start with 1.\r
85\r
86\r
87 @param CallerId This optional parameter may be used to identify the caller. \r
88 This parameter allows the status code driver to apply different rules to different callers. \r
89 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
90\r
91\r
92 @param Data This optional parameter may be used to pass additional data\r
93 \r
94 @return The function always return EFI_SUCCESS.\r
95\r
96**/\r
97EFI_STATUS\r
98EFIAPI\r
99OemHookStatusCodeReport (\r
100 IN EFI_STATUS_CODE_TYPE CodeType,\r
101 IN EFI_STATUS_CODE_VALUE Value,\r
102 IN UINT32 Instance,\r
103 IN EFI_GUID *CallerId, OPTIONAL\r
104 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
105 )\r
106{\r
107 CHAR8 *Filename;\r
108 CHAR8 *Description;\r
109 CHAR8 *Format;\r
110 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
111 UINT32 ErrorLevel;\r
112 UINT32 LineNumber;\r
113 UINTN CharCount;\r
114 VA_LIST Marker;\r
115 EFI_DEBUG_INFO *DebugInfo;\r
116\r
117 Buffer[0] = '\0';\r
118\r
119 if (Data != NULL &&\r
120 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
121 //\r
122 // Print ASSERT() information into output buffer.\r
123 //\r
124 CharCount = AsciiSPrint (\r
125 Buffer,\r
126 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
127 "\n\rASSERT!: %a (%d): %a\n\r",\r
128 Filename,\r
129 LineNumber,\r
130 Description\r
131 );\r
132\r
133 //\r
134 // Callout to standard output.\r
135 //\r
136 mUnix->Write (\r
137 mStdOut,\r
138 Buffer,\r
139 CharCount\r
140 );
141\r
142 return EFI_SUCCESS;\r
143\r
144 } else if (Data != NULL &&\r
145 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
146 //\r
147 // Print DEBUG() information into output buffer.\r
148 //\r
149 CharCount = AsciiVSPrint (\r
150 Buffer, \r
151 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
152 Format, \r
153 Marker\r
154 );\r
155 } else if (Data != NULL && \r
156 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
157 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
158 //\r
159 // Print specific data into output buffer.\r
160 //\r
161 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
162 Marker = (VA_LIST) (DebugInfo + 1);\r
163 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
164\r
165 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
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
171 Buffer, \r
172 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
173 "ERROR: C%x:V%x I%x", \r
174 CodeType, \r
175 Value, \r
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
182 \r
183 if (CallerId != NULL) {\r
184 CharCount += AsciiSPrint (\r
185 &Buffer[CharCount - 1],\r
186 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
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
195 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
196 " %x",\r
197 Data\r
198 );\r
199 }\r
200\r
201 CharCount += AsciiSPrint (\r
202 &Buffer[CharCount - 1],\r
203 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
204 "\n\r"\r
205 );\r
206 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
207 CharCount = AsciiSPrint (\r
208 Buffer, \r
209 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
210 "PROGRESS CODE: V%x I%x\n\r", \r
211 Value, \r
212 Instance\r
213 );\r
214 } else {\r
215 CharCount = AsciiSPrint (\r
216 Buffer, \r
217 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
218 "Undefined: C%x:V%x I%x\n\r", \r
219 CodeType, \r
220 Value, \r
221 Instance\r
222 );\r
223 }\r
224\r
225 //\r
226 // Callout to standard output.\r
227 //\r
228 mUnix->Write (\r
229 mStdOut,\r
230 Buffer,\r
231 CharCount\r
232 );\r
233\r
234 return EFI_SUCCESS;\r
235}\r
236\r