VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/Library/VBoxDebugLib/VBoxDebugLib.c@ 105681

Last change on this file since 105681 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: VBoxDebugLib.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxDebugLib.c - Debug logging and assertions support routines using DevEFI.
4 */
5
6/*
7 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <Base.h>
42#include <Library/BaseLib.h>
43#include <Library/PrintLib.h>
44#include <Library/DebugLib.h>
45
46#include "VBoxDebugLib.h"
47#include <Protocol/DevicePath.h>
48#include <Protocol/DevicePathToText.h>
49#include <Uefi/UefiSpec.h>
50#include <Library/UefiBootServicesTableLib.h>
51#include "DevEFI.h"
52#include "iprt/asm.h"
53
54
55VOID EFIAPI
56DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ...)
57{
58 CHAR8 szBuf[256];
59 VA_LIST va;
60 UINTN cch;
61 BOOLEAN InterruptState;
62
63 /* No pool noise, please. */
64 if (ErrorLevel == DEBUG_POOL)
65 return;
66
67 VA_START(va, Format);
68 cch = AsciiVSPrint(szBuf, sizeof(szBuf), Format, va);
69 VA_END(va);
70
71 /* make sure it's terminated and doesn't end with a newline */
72 if (cch >= sizeof(szBuf))
73 cch = sizeof(szBuf) - 1;
74 while (cch > 0 && (szBuf[cch - 1] == '\n' || szBuf[cch - 1] == '\r'))
75 cch--;
76 szBuf[cch] = '\0';
77
78 InterruptState = SaveAndDisableInterrupts();
79
80 /* Output the log string. */
81 VBoxPrintString("dbg/");
82 VBoxPrintHex(ErrorLevel, sizeof(ErrorLevel));
83 VBoxPrintChar(' ');
84 VBoxPrintString(szBuf);
85 VBoxPrintChar('\n');
86
87 SetInterruptState(InterruptState);
88}
89
90/**
91 * Our own log worker function, avoid the dbg/00000xxx prefix and makes it clear
92 * which log statements we added..
93 *
94 * @param pszFormat Format string. EFI style!
95 * @param ... Argument referneced in the format string.
96 */
97VOID EFIAPI
98VBoxLogWorker(const char *pszFormat, ...)
99{
100 CHAR8 szBuf[384];
101 VA_LIST va;
102 BOOLEAN InterruptState;
103
104 /* Format it. */
105 VA_START(va, pszFormat);
106 AsciiVSPrint(szBuf, sizeof(szBuf), pszFormat, va);
107 VA_END(va);
108 szBuf[sizeof(szBuf) - 1] = '\0';
109
110 InterruptState = SaveAndDisableInterrupts();
111
112 /* Output the log string. */
113 VBoxPrintString(szBuf);
114 VBoxPrintChar('\n');
115
116 SetInterruptState(InterruptState);
117}
118
119/**
120 * Adds a character to the panic message.
121 *
122 * @param ch The ASCII char to add.
123 */
124static void
125VBoxPanicMsgChar(int ch)
126{
127 ASMOutU16(EFI_PANIC_PORT, EFI_PANIC_CMD_MSG_FROM_CHAR(ch));
128}
129
130/**
131 * Adds a string to the panic message.
132 *
133 * @param pszString The string to add.
134 */
135static void
136VBoxPanicMsgString(const char *pszString)
137{
138 char ch;
139 while ((ch = *pszString++) != '\0')
140 VBoxPanicMsgChar(ch);
141}
142
143/**
144 * Adds a unsigned decimal number to the panic message.
145 *
146 * @param uValue The value.
147 */
148static void
149VBoxPanicMsgDecimalU32(uint32_t uValue)
150{
151 char szTmp[32];
152 unsigned off = sizeof(szTmp) - 1;
153
154 szTmp[off] = '\0';
155 do
156 {
157 char chDigit = uValue % 10;
158 uValue /= 10;
159 szTmp[--off] = chDigit + '0';
160 } while (uValue != 0 && off > 0);
161
162 VBoxPanicMsgString(&szTmp[off]);
163}
164
165VOID EFIAPI
166DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
167{
168 BOOLEAN InterruptState = SaveAndDisableInterrupts();
169
170 ASMOutU8(EFI_PANIC_PORT, EFI_PANIC_CMD_START_MSG);
171 VBoxPanicMsgString("EFI Assertion failed!"
172 "\nFile: ");
173 VBoxPanicMsgString(FileName ? FileName : "<NULL>");
174 VBoxPanicMsgString("\nLine: ");
175 VBoxPanicMsgDecimalU32((uint32_t)LineNumber);
176 VBoxPanicMsgString("\nDescription: ");
177 VBoxPanicMsgString(Description ? Description : "<NULL>");
178 ASMOutU8(EFI_PANIC_PORT, EFI_PANIC_CMD_END_MSG);
179
180 SetInterruptState(InterruptState);
181}
182
183
184VOID * EFIAPI
185DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
186{
187 return Buffer;
188}
189
190
191BOOLEAN EFIAPI
192DebugAssertEnabled(VOID)
193{
194 return TRUE;
195}
196
197
198BOOLEAN EFIAPI
199DebugPrintEnabled(VOID)
200{
201 /** @todo some PCD for this so we can disable it in release builds. */
202 return TRUE;
203}
204
205
206BOOLEAN EFIAPI
207DebugPrintLevelEnabled(IN CONST UINTN ErrorLevel)
208{
209 /** @todo some PCD for this so we can disable it in release builds. */
210 return TRUE;
211}
212
213
214BOOLEAN EFIAPI
215DebugCodeEnabled(VOID)
216{
217 /** @todo ditto */
218 return TRUE;
219}
220
221
222BOOLEAN EFIAPI
223DebugClearMemoryEnabled(VOID)
224{
225 return FALSE;
226}
227
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