OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
DebugPrint.c
Go to the documentation of this file.
1
16#include <Library/DevicePathLib.h>
17#include <Library/MemoryAllocationLib.h>
18
19VOID
21 IN UINTN ErrorLevel,
22 IN CONST CHAR8 *Message,
23 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL
24 )
25{
26 DEBUG_CODE_BEGIN ();
27
28 CHAR16 *TextDevicePath;
29
30 TextDevicePath = NULL;
31 if (DevicePath != NULL) {
32 TextDevicePath = ConvertDevicePathToText (DevicePath, FALSE, FALSE);
33 }
34
35 DEBUG ((ErrorLevel, "%a - %s\n", Message, OC_HUMAN_STRING (TextDevicePath)));
36 if (TextDevicePath != NULL) {
37 FreePool (TextDevicePath);
38 }
39
40 DEBUG_CODE_END ();
41}
42
43VOID
45 IN UINTN ErrorLevel,
46 IN CONST CHAR8 *Message,
47 IN EFI_HANDLE Handle OPTIONAL
48 )
49{
50 DEBUG_CODE_BEGIN ();
51
52 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
53
54 DevicePath = NULL;
55 if (Handle != NULL) {
56 DevicePath = DevicePathFromHandle (Handle);
57 }
58
59 DebugPrintDevicePath (ErrorLevel, Message, DevicePath);
60
61 DEBUG_CODE_END ();
62}
63
64VOID
66 IN UINTN ErrorLevel,
67 IN CONST CHAR8 *Message,
68 IN UINT8 *Bytes,
69 IN UINTN Size
70 )
71{
72 DEBUG_CODE_BEGIN ();
73
74 UINTN Index;
75 UINTN Index2;
76 UINTN Count;
77 UINTN SizeLeft;
78 UINTN MaxPerLine;
79 CHAR8 *HexLine;
80 CHAR8 *HexLineCurrent;
81
82 MaxPerLine = 64;
83 Count = (Size + MaxPerLine - 1) / MaxPerLine;
84
85 HexLine = AllocatePool (MaxPerLine * 3 + 1);
86 if (HexLine == NULL) {
87 return;
88 }
89
90 SizeLeft = Size;
91
92 for (Index = 0; Index < Count; ++Index) {
93 HexLineCurrent = HexLine;
94
95 for (Index2 = 0; SizeLeft > 0 && Index2 < MaxPerLine; ++Index2) {
96 if (Index2 > 0) {
97 *HexLineCurrent++ = ' ';
98 }
99
100 *HexLineCurrent++ = OC_HEX_UPPER (*Bytes);
101 *HexLineCurrent++ = OC_HEX_LOWER (*Bytes);
102 --SizeLeft;
103 ++Bytes;
104 }
105
106 *HexLineCurrent++ = '\0';
107
108 DEBUG ((
109 ErrorLevel,
110 "%a (%u/%u %u) - %a\n",
111 Message,
112 (UINT32)Index + 1,
113 (UINT32)Count,
114 (UINT32)Size,
115 HexLine
116 ));
117 }
118
119 FreePool (HexLine);
120
121 DEBUG_CODE_END ();
122}
VOID DebugPrintDevicePathForHandle(IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN EFI_HANDLE Handle OPTIONAL)
Definition DebugPrint.c:44
VOID DebugPrintHexDump(IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN UINT8 *Bytes, IN UINTN Size)
Definition DebugPrint.c:65
VOID DebugPrintDevicePath(IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL)
Definition DebugPrint.c:20
DMG_SIZE_DEVICE_PATH Size
#define OC_HUMAN_STRING(TextDevicePath)
#define OC_HEX_LOWER(x)
#define OC_HEX_UPPER(x)
APPLE_EVENT_HANDLE Handle
Definition OcTypingLib.h:45
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DevicePathFromHandle(IN EFI_HANDLE Handle)
Definition UserMisc.c:680