]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/Library/PeiNt32OemHookStatusCodeLib/Nt32OemHookStatusCodeLib.c
Porting R8's PI-enabled ScsiBus driver
[mirror_edk2.git] / Nt32Pkg / Library / PeiNt32OemHookStatusCodeLib / Nt32OemHookStatusCodeLib.c
CommitLineData
869f8e34 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: Nt32OemHookStatusCodeLib.c\r
14\r
15**/\r
16\r
17//\r
18// Include common header file for this module.\r
19//\r
20#include "CommonHeader.h"\r
21\r
22//\r
23// Cache of WinNtThunk protocol \r
24//\r
25STATIC\r
26EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;\r
27\r
28//\r
29// Cache of standard output handle . \r
30//\r
31STATIC\r
32HANDLE mStdOut;\r
33\r
34/**\r
35\r
36 Initialize OEM status code device .\r
37\r
38 @return Always return EFI_SUCCESS.\r
39\r
40**/\r
41EFI_STATUS\r
42EFIAPI\r
43OemHookStatusCodeInitialize (\r
44 VOID\r
45 )\r
46{\r
47 PEI_NT_THUNK_PPI *NtThunkPpi;\r
48 EFI_STATUS Status;\r
49\r
50 \r
51 //\r
52 // Locate NtThunkPpi for retrieving standard output handle\r
53 //\r
54 Status = PeiServicesLocatePpi (\r
55 &gPeiNtThunkPpiGuid,\r
56 0,\r
57 NULL,\r
58 (VOID **) &NtThunkPpi\r
59 );\r
60\r
61 ASSERT_EFI_ERROR (Status);\r
62\r
63 mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();\r
64 \r
65\r
66 //\r
67 // Cache standard output handle.\r
68 //\r
69 mStdOut = mWinNt->GetStdHandle (STD_OUTPUT_HANDLE);\r
70\r
71 return EFI_SUCCESS;\r
72}\r
73\r
74/**\r
75 Report status code to OEM device.\r
76 \r
77 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
78 \r
79 @param Value Describes the current status of a hardware or software entity. \r
80 This included information about the class and subclass that is used to classify the entity \r
81 as well as an operation. For progress codes, the operation is the current activity. \r
82 For error codes, it is the exception. For debug codes, it is not defined at this time. \r
83 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. \r
84 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
85 \r
86 @param Instance The enumeration of a hardware or software entity within the system. \r
87 A system may contain multiple entities that match a class/subclass pairing. \r
88 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, \r
89 not meaningful, or not relevant. Valid instance numbers start with 1.\r
90\r
91\r
92 @param CallerId This optional parameter may be used to identify the caller. \r
93 This parameter allows the status code driver to apply different rules to different callers. \r
94 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
95\r
96\r
97 @param Data This optional parameter may be used to pass additional data\r
98 \r
99 @return The function always return EFI_SUCCESS.\r
100\r
101**/\r
102EFI_STATUS\r
103EFIAPI\r
104OemHookStatusCodeReport (\r
105 IN EFI_STATUS_CODE_TYPE CodeType,\r
106 IN EFI_STATUS_CODE_VALUE Value,\r
107 IN UINT32 Instance,\r
108 IN EFI_GUID *CallerId, OPTIONAL\r
109 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
110 )\r
111{\r
112 CHAR8 *Filename;\r
113 CHAR8 *Description;\r
114 CHAR8 *Format;\r
115 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
116 UINT32 ErrorLevel;\r
117 UINT32 LineNumber;\r
118 UINTN CharCount;\r
119 VA_LIST Marker;\r
120 EFI_DEBUG_INFO *DebugInfo;\r
121\r
122 Buffer[0] = '\0';\r
123\r
124 if (Data != NULL &&\r
125 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
126 //\r
127 // Print ASSERT() information into output buffer.\r
128 //\r
129 CharCount = AsciiSPrint (\r
130 Buffer,\r
131 EFI_STATUS_CODE_DATA_MAX_SIZE,\r
132 "\n\rASSERT!: %a (%d): %a\n\r",\r
133 Filename,\r
134 LineNumber,\r
135 Description\r
136 );\r
137\r
138 //\r
139 // Callout to standard output.\r
140 //\r
141 mWinNt->WriteFile (\r
142 mStdOut,\r
143 Buffer,\r
144 CharCount,\r
145 &CharCount,\r
146 NULL\r
147 );\r
148\r
149 return EFI_SUCCESS;\r
150\r
151 } else if (Data != NULL &&\r
152 ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
153 //\r
154 // Print DEBUG() information into output buffer.\r
155 //\r
156 CharCount = AsciiVSPrint (\r
157 Buffer, \r
158 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
159 Format, \r
160 Marker\r
161 );\r
162 } else if (Data != NULL && \r
163 CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
164 (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
165 //\r
166 // Print specific data into output buffer.\r
167 //\r
168 DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
169 Marker = (VA_LIST) (DebugInfo + 1);\r
170 Format = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
171\r
172 CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
173 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
174 //\r
175 // Print ERROR information into output buffer.\r
176 //\r
177 CharCount = AsciiSPrint (\r
178 Buffer, \r
179 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
180 "ERROR: C%x:V%x I%x", \r
181 CodeType, \r
182 Value, \r
183 Instance\r
184 );\r
185\r
186 //\r
187 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
188 //\r
189 \r
190 if (CallerId != NULL) {\r
191 CharCount += AsciiSPrint (\r
192 &Buffer[CharCount - 1],\r
193 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
194 " %g",\r
195 CallerId\r
196 );\r
197 }\r
198\r
199 if (Data != NULL) {\r
200 CharCount += AsciiSPrint (\r
201 &Buffer[CharCount - 1],\r
202 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
203 " %x",\r
204 Data\r
205 );\r
206 }\r
207\r
208 CharCount += AsciiSPrint (\r
209 &Buffer[CharCount - 1],\r
210 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
211 "\n\r"\r
212 );\r
213 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
214 CharCount = AsciiSPrint (\r
215 Buffer, \r
216 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
217 "PROGRESS CODE: V%x I%x\n\r", \r
218 Value, \r
219 Instance\r
220 );\r
221 } else {\r
222 CharCount = AsciiSPrint (\r
223 Buffer, \r
224 EFI_STATUS_CODE_DATA_MAX_SIZE, \r
225 "Undefined: C%x:V%x I%x\n\r", \r
226 CodeType, \r
227 Value, \r
228 Instance\r
229 );\r
230 }\r
231\r
232 //\r
233 // Callout to standard output.\r
234 //\r
235 mWinNt->WriteFile (\r
236 mStdOut,\r
237 Buffer,\r
238 CharCount,\r
239 &CharCount,\r
240 NULL\r
241 );\r
242\r
243 return EFI_SUCCESS;\r
244}\r
245\r