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