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