VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DebugLib.c

Last change on this file was 108794, checked in by vboxsync, 3 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 10.4 KB
Line 
1/** @file
2 Originally copied from "MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c" at
3 commit f36e1ec1f0a5, and customized for:
4
5 - RAM vs. flash dependent PL011 UART initialization,
6
7 - direct PL011 UART access, with the base address taken from the device tree
8 such that the debug output be separate from the SerialPortLib / UEFI console
9 traffic.
10
11 Both of these customizations are hidden behind DebugLibFdtPL011UartWrite(),
12 which replaces SerialPortWrite().
13
14 Copyright (C) Red Hat
15 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
16
17 SPDX-License-Identifier: BSD-2-Clause-Patent
18**/
19
20#include <Base.h>
21#include <Library/DebugLib.h>
22#include <Library/BaseLib.h>
23#include <Library/PrintLib.h>
24#include <Library/PcdLib.h>
25#include <Library/BaseMemoryLib.h>
26#include <Library/DebugPrintErrorLevelLib.h>
27
28#include "Write.h"
29
30//
31// Define the maximum debug and assert message length that this library supports
32//
33#define MAX_DEBUG_MESSAGE_LENGTH 0x100
34
35//
36// VA_LIST can not initialize to NULL for all compiler, so we use this to
37// indicate a null VA_LIST
38//
39VA_LIST mVaListNull;
40
41/**
42 Prints a debug message to the debug output device if the specified error level is enabled.
43
44 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
45 GetDebugPrintErrorLevel (), then print the message specified by Format and the
46 associated variable argument list to the debug output device.
47
48 If Format is NULL, then ASSERT().
49
50 @param ErrorLevel The error level of the debug message.
51 @param Format Format string for the debug message to print.
52 @param ... Variable argument list whose contents are accessed
53 based on the format string specified by Format.
54
55**/
56VOID
57EFIAPI
58DebugPrint (
59 IN UINTN ErrorLevel,
60 IN CONST CHAR8 *Format,
61 ...
62 )
63{
64 VA_LIST Marker;
65
66 VA_START (Marker, Format);
67 DebugVPrint (ErrorLevel, Format, Marker);
68 VA_END (Marker);
69}
70
71/**
72 Prints a debug message to the debug output device if the specified
73 error level is enabled base on Null-terminated format string and a
74 VA_LIST argument list or a BASE_LIST argument list.
75
76 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
77 GetDebugPrintErrorLevel (), then print the message specified by Format and
78 the associated variable argument list to the debug output device.
79
80 If Format is NULL, then ASSERT().
81
82 @param ErrorLevel The error level of the debug message.
83 @param Format Format string for the debug message to print.
84 @param VaListMarker VA_LIST marker for the variable argument list.
85 @param BaseListMarker BASE_LIST marker for the variable argument list.
86
87**/
88VOID
89DebugPrintMarker (
90 IN UINTN ErrorLevel,
91 IN CONST CHAR8 *Format,
92 IN VA_LIST VaListMarker,
93 IN BASE_LIST BaseListMarker
94 )
95{
96 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
97
98 //
99 // If Format is NULL, then ASSERT().
100 //
101 ASSERT (Format != NULL);
102
103 //
104 // Check driver debug mask value and global mask
105 //
106 if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
107 return;
108 }
109
110 //
111 // Convert the DEBUG() message to an ASCII String
112 //
113 if (BaseListMarker == NULL) {
114 AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
115 } else {
116 AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
117 }
118
119 //
120 // Send the print string to a Serial Port
121 //
122 DebugLibFdtPL011UartWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
123}
124
125/**
126 Prints a debug message to the debug output device if the specified
127 error level is enabled.
128
129 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
130 GetDebugPrintErrorLevel (), then print the message specified by Format and
131 the associated variable argument list to the debug output device.
132
133 If Format is NULL, then ASSERT().
134
135 @param ErrorLevel The error level of the debug message.
136 @param Format Format string for the debug message to print.
137 @param VaListMarker VA_LIST marker for the variable argument list.
138
139**/
140VOID
141EFIAPI
142DebugVPrint (
143 IN UINTN ErrorLevel,
144 IN CONST CHAR8 *Format,
145 IN VA_LIST VaListMarker
146 )
147{
148 DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
149}
150
151/**
152 Prints a debug message to the debug output device if the specified
153 error level is enabled.
154 This function use BASE_LIST which would provide a more compatible
155 service than VA_LIST.
156
157 If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
158 GetDebugPrintErrorLevel (), then print the message specified by Format and
159 the associated variable argument list to the debug output device.
160
161 If Format is NULL, then ASSERT().
162
163 @param ErrorLevel The error level of the debug message.
164 @param Format Format string for the debug message to print.
165 @param BaseListMarker BASE_LIST marker for the variable argument list.
166
167**/
168VOID
169EFIAPI
170DebugBPrint (
171 IN UINTN ErrorLevel,
172 IN CONST CHAR8 *Format,
173 IN BASE_LIST BaseListMarker
174 )
175{
176 DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
177}
178
179/**
180 Prints an assert message containing a filename, line number, and description.
181 This may be followed by a breakpoint or a dead loop.
182
183 Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
184 to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
185 PcdDebugPropertyMask is set then CpuBreakpoint() is called. Otherwise, if
186 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugPropertyMask is set then
187 CpuDeadLoop() is called. If neither of these bits are set, then this function
188 returns immediately after the message is printed to the debug output device.
189 DebugAssert() must actively prevent recursion. If DebugAssert() is called while
190 processing another DebugAssert(), then DebugAssert() must return immediately.
191
192 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
193 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
194
195 @param FileName The pointer to the name of the source file that generated the assert condition.
196 @param LineNumber The line number in the source file that generated the assert condition
197 @param Description The pointer to the description of the assert condition.
198
199**/
200VOID
201EFIAPI
202DebugAssert (
203 IN CONST CHAR8 *FileName,
204 IN UINTN LineNumber,
205 IN CONST CHAR8 *Description
206 )
207{
208 CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
209
210 //
211 // Generate the ASSERT() message in Ascii format
212 //
213 AsciiSPrint (Buffer, sizeof (Buffer), "ASSERT [%a] %a(%d): %a\n", gEfiCallerBaseName, FileName, LineNumber, Description);
214
215 //
216 // Send the print string to the Console Output device
217 //
218 DebugLibFdtPL011UartWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
219
220 //
221 // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
222 //
223 if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED) != 0) {
224 CpuBreakpoint ();
225 } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
226 CpuDeadLoop ();
227 }
228}
229
230/**
231 Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
232
233 This function fills Length bytes of Buffer with the value specified by
234 PcdDebugClearMemoryValue, and returns Buffer.
235
236 If Buffer is NULL, then ASSERT().
237 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
238
239 @param Buffer The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
240 @param Length The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
241
242 @return Buffer The pointer to the target buffer filled with PcdDebugClearMemoryValue.
243
244**/
245VOID *
246EFIAPI
247DebugClearMemory (
248 OUT VOID *Buffer,
249 IN UINTN Length
250 )
251{
252 //
253 // If Buffer is NULL, then ASSERT().
254 //
255 ASSERT (Buffer != NULL);
256
257 //
258 // SetMem() checks for the the ASSERT() condition on Length and returns Buffer
259 //
260 return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));
261}
262
263/**
264 Returns TRUE if ASSERT() macros are enabled.
265
266 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
267 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
268
269 @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is set.
270 @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugPropertyMask is clear.
271
272**/
273BOOLEAN
274EFIAPI
275DebugAssertEnabled (
276 VOID
277 )
278{
279 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
280}
281
282/**
283 Returns TRUE if DEBUG() macros are enabled.
284
285 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
286 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
287
288 @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is set.
289 @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugPropertyMask is clear.
290
291**/
292BOOLEAN
293EFIAPI
294DebugPrintEnabled (
295 VOID
296 )
297{
298 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
299}
300
301/**
302 Returns TRUE if DEBUG_CODE() macros are enabled.
303
304 This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
305 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
306
307 @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is set.
308 @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPropertyMask is clear.
309
310**/
311BOOLEAN
312EFIAPI
313DebugCodeEnabled (
314 VOID
315 )
316{
317 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
318}
319
320/**
321 Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
322
323 This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
324 PcdDebugPropertyMask is set. Otherwise FALSE is returned.
325
326 @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is set.
327 @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugPropertyMask is clear.
328
329**/
330BOOLEAN
331EFIAPI
332DebugClearMemoryEnabled (
333 VOID
334 )
335{
336 return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
337}
338
339/**
340 Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
341
342 This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
343
344 @retval TRUE Current ErrorLevel is supported.
345 @retval FALSE Current ErrorLevel is not supported.
346
347**/
348BOOLEAN
349EFIAPI
350DebugPrintLevelEnabled (
351 IN CONST UINTN ErrorLevel
352 )
353{
354 return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) != 0);
355}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette