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