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