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