]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Library/Nt32OemHookStatusCodeLib/Nt32OemHookStatusCodeLib.c
Updated PeiRebase to produce a map file of the relocations done by this tool. This...
[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 EFI_WIN_NT_THUNK_PROTOCOL *mWinNt;
23
24 //
25 // Cache of standard output handle .
26 //
27 HANDLE mStdOut;
28
29 /**
30
31 Initialize OEM status code device .
32
33 **/
34 VOID
35 EFIAPI
36 OemHookStatusCodeInitialize (
37 VOID
38 )
39 {
40 PEI_NT_THUNK_PPI *NtThunkPpi;
41 EFI_STATUS Status;
42
43 if (FeaturePcdGet (PcdNt32StatusCodeLibUseForPei)) {
44 //
45 // Locate NtThunkPpi for retrieving standard output handle
46 //
47 Status = PeiServicesLocatePpi (
48 &gPeiNtThunkPpiGuid,
49 0,
50 NULL,
51 (VOID **) &NtThunkPpi
52 );
53
54 ASSERT_EFI_ERROR (Status);
55
56 mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *) NtThunkPpi->NtThunk ();
57 } else {
58 EFI_HOB_GUID_TYPE *GuidHob;
59
60 //
61 // Retrieve WinNtThunkProtocol from GUID'ed HOB
62 //
63 GuidHob = GetFirstGuidHob (&gEfiWinNtThunkProtocolGuid);
64 ASSERT (GuidHob != NULL);
65 mWinNt = (EFI_WIN_NT_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
66 ASSERT (mWinNt != NULL);
67 }
68
69 //
70 // Cache standard output handle.
71 //
72 mStdOut = mWinNt->GetStdHandle (STD_OUTPUT_HANDLE);
73
74 return;
75 }
76
77 /**
78 Report status code to OEM device.
79
80 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions¡± below.
81
82 @param Value Describes the current status of a hardware or software entity.
83 This included information about the class and subclass that is used to classify the entity
84 as well as an operation. For progress codes, the operation is the current activity.
85 For error codes, it is the exception. For debug codes, it is not defined at this time.
86 Type EFI_STATUS_CODE_VALUE is defined in ¡°Related Definitions¡± below.
87 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
88
89 @param Instance The enumeration of a hardware or software entity within the system.
90 A system may contain multiple entities that match a class/subclass pairing.
91 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
92 not meaningful, or not relevant. Valid instance numbers start with 1.
93
94
95 @param CallerId This optional parameter may be used to identify the caller.
96 This parameter allows the status code driver to apply different rules to different callers.
97 Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
98
99
100 @param Data This optional parameter may be used to pass additional data
101
102 @return The function always return EFI_SUCCESS.
103
104 **/
105 EFI_STATUS
106 EFIAPI
107 OemHookStatusCodeReport (
108 IN EFI_STATUS_CODE_TYPE CodeType,
109 IN EFI_STATUS_CODE_VALUE Value,
110 IN UINT32 Instance,
111 IN EFI_GUID *CallerId, OPTIONAL
112 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
113 )
114 {
115 CHAR8 *Filename;
116 CHAR8 *Description;
117 CHAR8 *Format;
118 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
119 UINT32 ErrorLevel;
120 UINT32 LineNumber;
121 UINTN CharCount;
122 VA_LIST Marker;
123 EFI_DEBUG_INFO *DebugInfo;
124
125 Buffer[0] = '\0';
126
127 if (Data != NULL &&
128 ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
129 //
130 // Print ASSERT() information into output buffer.
131 //
132 CharCount = AsciiSPrint (
133 Buffer,
134 EFI_STATUS_CODE_DATA_MAX_SIZE,
135 "\n\rASSERT!: %a (%d): %a\n\r",
136 Filename,
137 LineNumber,
138 Description
139 );
140
141 //
142 // Callout to standard output.
143 //
144 mWinNt->WriteFile (
145 mStdOut,
146 Buffer,
147 CharCount,
148 &CharCount,
149 NULL
150 );
151
152 CpuBreakpoint ();
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 (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "ERROR: C%x:V%x I%x", CodeType, Value, Instance);
183
184 //
185 // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
186 //
187
188 if (CallerId != NULL) {
189 CharCount += AsciiSPrint (
190 &Buffer[CharCount - 1],
191 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
192 " %g",
193 CallerId
194 );
195 }
196
197 if (Data) {
198 CharCount += AsciiSPrint (
199 &Buffer[CharCount - 1],
200 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
201 " %x",
202 Data
203 );
204 }
205
206 CharCount += AsciiSPrint (
207 &Buffer[CharCount - 1],
208 (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
209 "\n\r"
210 );
211 } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
212 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "PROGRESS CODE: V%x I%x\n\r", Value, Instance);
213 } else {
214 CharCount = AsciiSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, "Undefined: C%x:V%x I%x\n\r", CodeType, Value, Instance);
215 }
216
217 //
218 // Callout to standard output.
219 //
220 mWinNt->WriteFile (
221 mStdOut,
222 Buffer,
223 CharCount,
224 &CharCount,
225 NULL
226 );
227
228 return EFI_SUCCESS;
229 }
230