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