]>
Commit | Line | Data |
---|---|---|
804405e7 | 1 | /** @file |
2 | OEM hook status code library functions with no library constructor/destructor | |
3 | ||
4 | Copyright (c) 2006 - 2008, Intel Corporation | |
5 | All rights reserved. This program and the accompanying materials | |
6 | are licensed and made available under the terms and conditions of the BSD License | |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
12 | ||
13 | Module Name: UnixOemHookStatusCodeLib.c | |
14 | ||
15 | **/ | |
16 | #include "PiPei.h" | |
17 | #include <Guid/StatusCodeDataTypeId.h> | |
18 | #include <Ppi/UnixThunk.h> | |
19 | #include <FrameworkModuleBase.h> | |
20 | #include <Library/OemHookStatusCodeLib.h> | |
21 | #include <Library/DebugLib.h> | |
22 | #include <Library/PrintLib.h> | |
23 | #include <Library/BaseMemoryLib.h> | |
24 | #include <Library/ReportStatusCodeLib.h> | |
25 | #include <Library/PeiServicesLib.h> | |
804405e7 | 26 | |
27 | // | |
28 | // Cache of UnixThunk protocol | |
29 | // | |
804405e7 | 30 | EFI_UNIX_THUNK_PROTOCOL *mUnix; |
31 | ||
32 | // | |
33 | // Cache of standard output handle . | |
34 | // | |
804405e7 | 35 | int mStdOut; |
36 | ||
37 | /** | |
38 | ||
39 | Initialize OEM status code device . | |
40 | ||
41 | @return Always return EFI_SUCCESS. | |
42 | ||
43 | **/ | |
44 | EFI_STATUS | |
45 | EFIAPI | |
46 | OemHookStatusCodeInitialize ( | |
47 | VOID | |
48 | ) | |
49 | { | |
50 | PEI_UNIX_THUNK_PPI *UnixThunkPpi; | |
51 | EFI_STATUS Status; | |
52 | ||
53 | ||
54 | // | |
55 | // Locate Unix ThunkPpi for retrieving standard output handle | |
56 | // | |
57 | Status = PeiServicesLocatePpi ( | |
58 | &gPeiUnixThunkPpiGuid, | |
59 | 0, | |
60 | NULL, | |
61 | (VOID **) &UnixThunkPpi | |
62 | ); | |
63 | ||
64 | ASSERT_EFI_ERROR (Status); | |
65 | ||
66 | mUnix = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk (); | |
67 | ||
68 | // | |
69 | // Cache standard output handle. | |
70 | // | |
71 | mStdOut = 1; | |
72 | ||
73 | return EFI_SUCCESS; | |
74 | } | |
75 | ||
76 | /** | |
77 | Report status code to OEM device. | |
78 | ||
79 | @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below. | |
80 | ||
81 | @param Value Describes the current status of a hardware or software entity. | |
82 | This included information about the class and subclass that is used to classify the entity | |
83 | as well as an operation. For progress codes, the operation is the current activity. | |
84 | For error codes, it is the exception. For debug codes, it is not defined at this time. | |
85 | Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. | |
86 | Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification. | |
87 | ||
88 | @param Instance The enumeration of a hardware or software entity within the system. | |
89 | A system may contain multiple entities that match a class/subclass pairing. | |
90 | The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, | |
91 | not meaningful, or not relevant. Valid instance numbers start with 1. | |
92 | ||
93 | ||
94 | @param CallerId This optional parameter may be used to identify the caller. | |
95 | This parameter allows the status code driver to apply different rules to different callers. | |
96 | Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification. | |
97 | ||
98 | ||
99 | @param Data This optional parameter may be used to pass additional data | |
100 | ||
101 | @return The function always return EFI_SUCCESS. | |
102 | ||
103 | **/ | |
104 | EFI_STATUS | |
105 | EFIAPI | |
106 | OemHookStatusCodeReport ( | |
107 | IN EFI_STATUS_CODE_TYPE CodeType, | |
108 | IN EFI_STATUS_CODE_VALUE Value, | |
109 | IN UINT32 Instance, | |
110 | IN EFI_GUID *CallerId, OPTIONAL | |
111 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL | |
112 | ) | |
113 | { | |
114 | CHAR8 *Filename; | |
115 | CHAR8 *Description; | |
116 | CHAR8 *Format; | |
117 | CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE]; | |
118 | UINT32 ErrorLevel; | |
119 | UINT32 LineNumber; | |
120 | UINTN CharCount; | |
9c98c8e1 | 121 | BASE_LIST Marker; |
804405e7 | 122 | |
123 | Buffer[0] = '\0'; | |
124 | ||
125 | if (Data != NULL && | |
126 | ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) { | |
127 | // | |
128 | // Print ASSERT() information into output buffer. | |
129 | // | |
130 | CharCount = AsciiSPrint ( | |
131 | Buffer, | |
d94f1f35 | 132 | sizeof (Buffer), |
804405e7 | 133 | "\n\rASSERT!: %a (%d): %a\n\r", |
134 | Filename, | |
135 | LineNumber, | |
136 | Description | |
137 | ); | |
138 | ||
139 | // | |
140 | // Callout to standard output. | |
141 | // | |
142 | mUnix->Write ( | |
143 | mStdOut, | |
144 | Buffer, | |
145 | CharCount | |
146 | ); | |
147 | ||
148 | return EFI_SUCCESS; | |
149 | ||
150 | } else if (Data != NULL && | |
151 | ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) { | |
152 | // | |
153 | // Print DEBUG() information into output buffer. | |
154 | // | |
9c98c8e1 | 155 | CharCount = AsciiBSPrint ( |
804405e7 | 156 | Buffer, |
d94f1f35 | 157 | sizeof (Buffer), |
804405e7 | 158 | Format, |
159 | Marker | |
160 | ); | |
804405e7 | 161 | } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) { |
162 | // | |
163 | // Print ERROR information into output buffer. | |
164 | // | |
165 | CharCount = AsciiSPrint ( | |
166 | Buffer, | |
d94f1f35 | 167 | sizeof (Buffer), |
804405e7 | 168 | "ERROR: C%x:V%x I%x", |
169 | CodeType, | |
170 | Value, | |
171 | Instance | |
172 | ); | |
173 | ||
174 | // | |
175 | // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers. | |
176 | // | |
177 | ||
178 | if (CallerId != NULL) { | |
179 | CharCount += AsciiSPrint ( | |
180 | &Buffer[CharCount - 1], | |
d94f1f35 | 181 | (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), |
804405e7 | 182 | " %g", |
183 | CallerId | |
184 | ); | |
185 | } | |
186 | ||
187 | if (Data != NULL) { | |
188 | CharCount += AsciiSPrint ( | |
189 | &Buffer[CharCount - 1], | |
d94f1f35 | 190 | (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), |
804405e7 | 191 | " %x", |
192 | Data | |
193 | ); | |
194 | } | |
195 | ||
196 | CharCount += AsciiSPrint ( | |
197 | &Buffer[CharCount - 1], | |
d94f1f35 | 198 | (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), |
804405e7 | 199 | "\n\r" |
200 | ); | |
201 | } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) { | |
202 | CharCount = AsciiSPrint ( | |
203 | Buffer, | |
d94f1f35 | 204 | sizeof (Buffer), |
804405e7 | 205 | "PROGRESS CODE: V%x I%x\n\r", |
206 | Value, | |
207 | Instance | |
208 | ); | |
209 | } else { | |
210 | CharCount = AsciiSPrint ( | |
211 | Buffer, | |
d94f1f35 | 212 | sizeof (Buffer), |
804405e7 | 213 | "Undefined: C%x:V%x I%x\n\r", |
214 | CodeType, | |
215 | Value, | |
216 | Instance | |
217 | ); | |
218 | } | |
219 | ||
220 | // | |
221 | // Callout to standard output. | |
222 | // | |
223 | mUnix->Write ( | |
224 | mStdOut, | |
225 | Buffer, | |
226 | CharCount | |
227 | ); | |
228 | ||
229 | return EFI_SUCCESS; | |
230 | } | |
231 |