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