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