OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcDebugLibSerial.c
Go to the documentation of this file.
1
16#include <Uefi.h>
17
18#include <Library/BaseLib.h>
19#include <Library/DebugLib.h>
20#include <Library/DevicePathLib.h>
22#include <Library/PrintLib.h>
23#include <Library/PcdLib.h>
24#include <Library/BaseMemoryLib.h>
25#include <Library/SerialPortLib.h>
26#include <Library/DebugPrintErrorLevelLib.h>
27
28//
29// Define the maximum debug and assert message length that this library supports
30//
31#define MAX_DEBUG_MESSAGE_LENGTH 0x100
32
33//
34// VA_LIST can not initialize to NULL for all compiler, so we use this to
35// indicate a null VA_LIST
36//
38
45RETURN_STATUS
46EFIAPI
48 VOID
49 )
50{
51 return SerialPortInitialize ();
52}
53
68VOID
69EFIAPI
71 IN UINTN ErrorLevel,
72 IN CONST CHAR8 *Format,
73 ...
74 )
75{
76 VA_LIST Marker;
77
78 VA_START (Marker, Format);
79 DebugVPrint (ErrorLevel, Format, Marker);
80 VA_END (Marker);
81}
82
100VOID
102 IN UINTN ErrorLevel,
103 IN CONST CHAR8 *Format,
104 IN VA_LIST VaListMarker,
105 IN BASE_LIST BaseListMarker
106 )
107{
109
110 //
111 // If Format is NULL, then ASSERT().
112 //
113 ASSERT (Format != NULL);
114
115 //
116 // Check driver debug mask value and global mask
117 //
118 if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
119 return;
120 }
121
122 //
123 // Convert the DEBUG() message to an ASCII String
124 //
125 if (BaseListMarker == NULL) {
126 AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
127 } else {
128 AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
129 }
130
131 //
132 // Send the print string to a Serial Port
133 //
134 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
135}
136
152VOID
153EFIAPI
155 IN UINTN ErrorLevel,
156 IN CONST CHAR8 *Format,
157 IN VA_LIST VaListMarker
158 )
159{
160 DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
161}
162
180VOID
181EFIAPI
183 IN UINTN ErrorLevel,
184 IN CONST CHAR8 *Format,
185 IN BASE_LIST BaseListMarker
186 )
187{
188 DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
189}
190
214VOID
215EFIAPI
217 IN CONST CHAR8 *FileName,
218 IN UINTN LineNumber,
219 IN CONST CHAR8 *Description
220 )
221{
223
224 //
225 // Generate the ASSERT() message in Ascii format
226 //
227 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT [%a] %a(%d): %a\n", gEfiCallerBaseName, FileName, LineNumber, Description);
228
229 //
230 // Send the print string to the Console Output device
231 //
232 SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
233
234 //
235 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
236 //
237 if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
238 CpuBreakpoint ();
239 } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
240 CpuDeadLoop ();
241 }
242}
243
258VOID *
259EFIAPI
261 OUT VOID *Buffer,
262 IN UINTN Length
263 )
264{
265 //
266 // If Buffer is NULL, then ASSERT().
267 //
268 ASSERT (Buffer != NULL);
269
270 //
271 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
272 //
273 return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));
274}
275
286BOOLEAN
287EFIAPI
289 VOID
290 )
291{
292 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
293}
294
305BOOLEAN
306EFIAPI
308 VOID
309 )
310{
311 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
312}
313
324BOOLEAN
325EFIAPI
327 VOID
328 )
329{
330 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
331}
332
343BOOLEAN
344EFIAPI
346 VOID
347 )
348{
349 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
350}
351
361BOOLEAN
362EFIAPI
364 IN CONST UINTN ErrorLevel
365 )
366{
367 return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);
368}
369
370VOID
371#if defined (__GNUC__) || defined (__clang__)
372__attribute__ ((noinline))
373#endif
375 VOID
376 ) {
377 //
378 // This function has no code, debuggers may break on it.
379 //
380}
381
382VOID
384 CONST CHAR16 *Message
385 )
386{
387}
388
389VOID
391 IN UINTN ErrorLevel,
392 IN CONST CHAR8 *Message,
393 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL
394 )
395{
396}
397
398VOID
400 IN UINTN ErrorLevel,
401 IN CONST CHAR8 *Message,
402 IN EFI_HANDLE Handle OPTIONAL
403 )
404{
405}
406
407VOID
409 IN UINTN ErrorLevel,
410 IN CONST CHAR8 *Message,
411 IN UINT8 *Bytes,
412 IN UINTN Size
413 )
414{
415}
UINT64 Length
__attribute__((packed, aligned(1)))
Definition EfiResTool.c:67
DMG_SIZE_DEVICE_PATH Size
VOID EFIAPI DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
RETURN_STATUS EFIAPI BaseDebugLibSerialPortConstructor(VOID)
VOID EFIAPI DebugVPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker)
BOOLEAN EFIAPI DebugPrintLevelEnabled(IN CONST UINTN ErrorLevel)
VOID DebugPrintMarker(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN VA_LIST VaListMarker, IN BASE_LIST BaseListMarker)
VOID EFIAPI DebugBPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, IN BASE_LIST BaseListMarker)
VOID *EFIAPI DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
VOID DebugPrintDevicePathForHandle(IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN EFI_HANDLE Handle OPTIONAL)
#define MAX_DEBUG_MESSAGE_LENGTH
VOID DebugBreak(VOID)
VOID EFIAPI DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)
VA_LIST mVaListNull
BOOLEAN EFIAPI DebugCodeEnabled(VOID)
BOOLEAN EFIAPI DebugClearMemoryEnabled(VOID)
BOOLEAN EFIAPI DebugPrintEnabled(VOID)
BOOLEAN EFIAPI DebugAssertEnabled(VOID)
VOID DebugPrintHexDump(IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN UINT8 *Bytes, IN UINTN Size)
VOID WaitForKeyPress(CONST CHAR16 *Message)
VOID DebugPrintDevicePath(IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL)
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
APPLE_EVENT_HANDLE Handle
Definition OcTypingLib.h:45
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
CONST CHAR8 * gEfiCallerBaseName
VOID EFIAPI CpuBreakpoint(VOID)
Definition UserMisc.c:13
#define ASSERT(x)
Definition coder.h:55