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