OpenCore  1.0.4
OpenCore Bootloader
1.0.4
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OcAppleLog.c
Go to the documentation of this file.
1
15#include <Uefi.h>
17#include <Library/BaseLib.h>
18#include <Library/BaseMemoryLib.h>
19#include <Library/DebugLib.h>
20#include <Library/UefiRuntimeServicesTableLib.h>
21#include <Library/UefiBootServicesTableLib.h>
23#include <Library/OcMiscLib.h>
24
25#include "OcLogInternal.h"
26
27STATIC
28BOOLEAN
30
31STATIC
32CHAR8
34
35STATIC
38
39STATIC
40UINTN
42
43STATIC
44UINT32
46
47STATIC
48EFI_STATUS
49EFIAPI
51 IN OC_LOG_PROTOCOL *OcLog,
52 IN CONST CHAR8 *Format,
53 ...
54 )
55{
56 EFI_STATUS Status;
57 VA_LIST Marker;
58
59 VA_START (Marker, Format);
60
61 Status = OcLog->AddEntry (
62 OcLog,
63 DEBUG_INFO,
64 Format,
65 Marker
66 );
67
68 VA_END (Marker);
69
70 return Status;
71}
72
73STATIC
74EFI_STATUS
75EFIAPI
77 IN CONST CHAR8 *Message
78 )
79{
80 OC_LOG_PROTOCOL *OcLog;
81 EFI_STATUS Status;
82 UINTN Length;
83 CHAR8 *NewLinePos;
84 APPLE_PERF_ENTRY *Entry;
85 UINT32 Index;
86
88 return FALSE;
89 }
90
91 OcLog = InternalGetOcLog ();
92 if (OcLog == NULL) {
93 return EFI_NOT_FOUND;
94 }
95
96 //
97 // Flush perf data.
98 //
99 if ( (mApplePerfBuffer != NULL)
102 {
104
105 for (Index = 0; Index < mApplePerfBuffer->NumberOfEntries; ++Index) {
106 if (Index == mApplePerfDumped) {
108 OcLog,
109 "EBPF: [%u ms] %a\n",
110 (UINT32)Entry->TimestampMs,
111 Entry->EntryData
112 );
114 }
115
116 Entry = APPLE_PERF_NEXT_ENTRY (Entry);
117 }
118 }
119
120 //
121 // Concatenate with the previous message.
122 //
123 Status = AsciiStrCatS (
125 sizeof (mCurrentBuffer) - 1,
126 Message
127 );
128 if (EFI_ERROR (Status)) {
129 Length = AsciiStrLen (mCurrentBuffer);
130
131 if (Length > 0) {
132 //
133 // Flush the previous message.
134 //
135 if (mCurrentBuffer[Length - 1] != '\n') {
136 //
137 // Ensure it is terminated with a newline.
138 //
139 mCurrentBuffer[Length] = '\n';
140 mCurrentBuffer[Length+1] = '\0';
141 }
142
144 OcLog,
145 "AAPL: %a",
146 Message
147 );
148 mCurrentBuffer[0] = '\0';
149
150 //
151 // Append the new message again.
152 //
153 Status = AsciiStrCpyS (
155 sizeof (mCurrentBuffer) - 1,
156 Message
157 );
158 }
159
160 //
161 // New message does not fit, send it directly.
162 //
163 if (EFI_ERROR (Status)) {
165 OcLog,
166 "AAPL: %a",
167 Message
168 );
169 }
170 }
171
172 //
173 // New message is in the buffer, send it line-by-line.
174 //
175 while (TRUE) {
176 NewLinePos = AsciiStrStr (mCurrentBuffer, "\n");
177 if (NewLinePos == NULL) {
178 break;
179 }
180
182 OcLog,
183 "AAPL: %.*a",
184 (UINTN)(NewLinePos - mCurrentBuffer + 1),
186 );
187
188 Length = AsciiStrLen (NewLinePos + 1);
189
190 if (Length > 0) {
191 CopyMem (mCurrentBuffer, NewLinePos + 1, Length + 1);
192 } else {
193 mCurrentBuffer[0] = '\0';
194 }
195 }
196
197 return EFI_SUCCESS;
198}
199
200STATIC
201EFI_STATUS
202EFIAPI
204 IN OUT UINT32 *Position,
205 IN OUT UINTN *BufferSize,
206 OUT CHAR8 *Buffer OPTIONAL,
207 OUT UINT32 *LostCharacters OPTIONAL
208 )
209{
210 //
211 // Do nothing for now.
212 //
213 return EFI_END_OF_FILE;
214}
215
216STATIC
217EFI_STATUS
218EFIAPI
220 VOID
221 )
222{
223 //
224 // Do nothing for now.
225 //
226 return EFI_SUCCESS;
227}
228
229STATIC
230VOID
231EFIAPI
233 VOID
234 )
235{
236 //
237 // Do nothing for now.
238 //
239}
240
241STATIC
245 .Print = AppleDebugLogPrint,
246 .ExtractBuffer = AppleDebugLogExtractBuffer,
247 .WriteFiles = AppleDebugLogWriteFiles,
248 .SetupFiles = AppleDebugLogSetupFiles
249};
250
253 IN BOOLEAN Reinstall
254 )
255{
256 EFI_STATUS Status;
257
258 APPLE_DEBUG_LOG_PROTOCOL *Protocol;
259 EFI_HANDLE Handle;
260
261 if (Reinstall) {
263 if (EFI_ERROR (Status)) {
264 DEBUG ((DEBUG_ERROR, "OCL: Uninstall failed - %r\n", Status));
265 return NULL;
266 }
267 } else {
268 Status = gBS->LocateProtocol (
270 NULL,
271 (VOID *)&Protocol
272 );
273
274 if (!EFI_ERROR (Status)) {
275 return Protocol;
276 }
277 }
278
279 Handle = NULL;
280 Status = gBS->InstallMultipleProtocolInterfaces (
281 &Handle,
283 (VOID **)&mAppleDebugLogProtocol,
284 NULL
285 );
286
287 if (EFI_ERROR (Status)) {
288 return NULL;
289 }
290
292}
293
294VOID
296 IN BOOLEAN Enable
297 )
298{
299 mAppleDebugLogEnable = Enable;
300}
301
302VOID
304 IN OUT VOID *PerfBuffer,
305 IN UINTN PerfBufferSize
306 )
307{
308 DEBUG ((DEBUG_INFO, "OCL: EFI Boot performance buffer %p (%u)\n", PerfBuffer, (UINT32)PerfBufferSize));
310 ZeroMem (PerfBuffer, PerfBufferSize);
311
312 mApplePerfBuffer = PerfBuffer;
313 mApplePerfBufferSize = PerfBufferSize;
315 }
316}
EFI_GUID gAppleDebugLogProtocolGuid
#define APPLE_DEBUG_LOG_PROTOCOL_REVISION
#define APPLE_PERF_DATA_SIGNATURE
ootlefib (EfiBoot L)
#define APPLE_PERF_FIRST_ENTRY(Data)
#define APPLE_PERF_NEXT_ENTRY(Entry)
UINT64 Length
STATIC APPLE_PERF_DATA * mApplePerfBuffer
Definition OcAppleLog.c:37
STATIC EFI_STATUS EFIAPI AppleDebugLogPrintToOcLog(IN OC_LOG_PROTOCOL *OcLog, IN CONST CHAR8 *Format,...)
Definition OcAppleLog.c:50
STATIC VOID EFIAPI AppleDebugLogSetupFiles(VOID)
Definition OcAppleLog.c:232
VOID OcAppleDebugLogConfigure(IN BOOLEAN Enable)
Definition OcAppleLog.c:295
STATIC UINT32 mApplePerfDumped
Definition OcAppleLog.c:45
STATIC UINTN mApplePerfBufferSize
Definition OcAppleLog.c:41
STATIC BOOLEAN mAppleDebugLogEnable
Definition OcAppleLog.c:29
STATIC APPLE_DEBUG_LOG_PROTOCOL mAppleDebugLogProtocol
Definition OcAppleLog.c:243
STATIC EFI_STATUS EFIAPI AppleDebugLogPrint(IN CONST CHAR8 *Message)
Definition OcAppleLog.c:76
STATIC CHAR8 mCurrentBuffer[1024]
Definition OcAppleLog.c:33
STATIC EFI_STATUS EFIAPI AppleDebugLogWriteFiles(VOID)
Definition OcAppleLog.c:219
STATIC EFI_STATUS EFIAPI AppleDebugLogExtractBuffer(IN OUT UINT32 *Position, IN OUT UINTN *BufferSize, OUT CHAR8 *Buffer OPTIONAL, OUT UINT32 *LostCharacters OPTIONAL)
Definition OcAppleLog.c:203
VOID OcAppleDebugLogPerfAllocated(IN OUT VOID *PerfBuffer, IN UINTN PerfBufferSize)
Definition OcAppleLog.c:303
APPLE_DEBUG_LOG_PROTOCOL * OcAppleDebugLogInstallProtocol(IN BOOLEAN Reinstall)
Definition OcAppleLog.c:252
EFI_BOOT_SERVICES * gBS
STATIC OC_LOG_PROTOCOL * InternalGetOcLog(VOID)
EFI_STATUS OcUninstallAllProtocolInstances(EFI_GUID *Protocol)
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
APPLE_EVENT_HANDLE Handle
Definition OcTypingLib.h:45
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
CHAR8 EntryData[]
Null terminated.