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