VirtualBox

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

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