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