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