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