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