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