VirtualBox

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

Last change on this file since 56292 was 56292, checked in by vboxsync, 9 years ago

Devices: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: VBoxDebugLib.c 56292 2015-06-09 14:20:46Z vboxsync $ */
2/** @file
3 * VBoxDebugLib.c - Debug logging and assertions support routines using DevEFI.
4 */
5
6/*
7 * Copyright (C) 2009-2015 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* Header Files *
29*******************************************************************************/
30#include <Base.h>
31#include <Library/PrintLib.h>
32#include <Library/DebugLib.h>
33
34#include "VBoxDebugLib.h"
35#include <Protocol/DevicePath.h>
36#include <Protocol/DevicePathToText.h>
37#include <Uefi/UefiSpec.h>
38#include <Library/UefiBootServicesTableLib.h>
39#include "DevEFI.h"
40
41#if 0
42static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *g_DevPath2Txt;
43#endif
44
45
46VOID EFIAPI
47DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ...)
48{
49 CHAR8 szBuf[256];
50 VA_LIST va;
51 UINTN cch;
52 RTCCUINTREG SavedFlags;
53
54 /* No pool noise, please. */
55 if (ErrorLevel == DEBUG_POOL)
56 return;
57
58 VA_START(va, Format);
59 cch = AsciiVSPrint(szBuf, sizeof(szBuf), Format, va);
60 VA_END(va);
61
62 /* make sure it's terminated and doesn't end with a newline */
63 if (cch >= sizeof(szBuf))
64 cch = sizeof(szBuf) - 1;
65 while (cch > 0 && (szBuf[cch - 1] == '\n' || szBuf[cch - 1] == '\r'))
66 cch--;
67 szBuf[cch] = '\0';
68
69 /* Output the log string. */
70 SavedFlags = ASMIntDisableFlags();
71
72 VBoxPrintString("dbg/");
73 VBoxPrintHex(ErrorLevel, sizeof(ErrorLevel));
74 VBoxPrintChar(' ');
75 VBoxPrintString(szBuf);
76 VBoxPrintChar('\n');
77
78 ASMSetFlags(SavedFlags);
79}
80
81/**
82 * Our own log worker function, avoid the dbg/00000xxx prefix and makes it clear
83 * which log statements we added..
84 *
85 * @param pszFormat Format string. EFI style!
86 * @param ... Argument referneced in the format string.
87 */
88VOID EFIAPI
89VBoxLogWorker(const char *pszFormat, ...)
90{
91 CHAR8 szBuf[384];
92 VA_LIST va;
93 RTCCUINTREG SavedFlags;
94
95 /* Format it. */
96 VA_START(va, pszFormat);
97 AsciiVSPrint(szBuf, sizeof(szBuf), pszFormat, va);
98 VA_END(va);
99 szBuf[sizeof(szBuf) - 1] = '\0';
100
101 /* Output the log string. */
102 SavedFlags = ASMIntDisableFlags();
103
104 VBoxPrintString(szBuf);
105 VBoxPrintChar('\n');
106
107 ASMSetFlags(SavedFlags);
108}
109
110/**
111 * Adds a character to the panic message.
112 *
113 * @param ch The ASCII char to add.
114 */
115static void
116VBoxPanicMsgChar(int ch)
117{
118 ASMOutU16(EFI_PANIC_PORT, EFI_PANIC_CMD_MSG_FROM_CHAR(ch));
119}
120
121/**
122 * Adds a string to the panic message.
123 *
124 * @param pszString The string to add.
125 */
126static void
127VBoxPanicMsgString(const char *pszString)
128{
129 char ch;
130 while ((ch = *pszString++) != '\0')
131 VBoxPanicMsgChar(ch);
132}
133
134/**
135 * Adds a unsigned decimal number to the panic message.
136 *
137 * @param uValue The value.
138 */
139static void
140VBoxPanicMsgDecimalU32(uint32_t uValue)
141{
142 char szTmp[32];
143 unsigned off = sizeof(szTmp) - 1;
144
145 szTmp[off] = '\0';
146 do
147 {
148 char chDigit = uValue % 10;
149 uValue /= 10;
150 szTmp[--off] = chDigit + '0';
151 } while (uValue != 0 && off > 0);
152
153 VBoxPanicMsgString(&szTmp[off]);
154}
155
156VOID EFIAPI
157DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
158{
159 RTCCUINTREG SavedFlags = ASMIntDisableFlags();
160
161 ASMOutU8(EFI_PANIC_PORT, EFI_PANIC_CMD_START_MSG);
162 VBoxPanicMsgString("EFI Assertion failed!"
163 "\nFile: ");
164 VBoxPanicMsgString(FileName ? FileName : "<NULL>");
165 VBoxPanicMsgString("\nLine: ");
166 VBoxPanicMsgDecimalU32((uint32_t)LineNumber);
167 VBoxPanicMsgString("\nEDescription: ");
168 VBoxPanicMsgString(Description ? Description : "<NULL>");
169 ASMOutU8(EFI_PANIC_PORT, EFI_PANIC_CMD_END_MSG);
170
171 ASMSetFlags(SavedFlags);
172}
173
174CHAR16 *VBoxDebugDevicePath2Str(IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath)
175{
176#if 0
177 EFI_STATUS rc;
178 if (!g_DevPath2Txt)
179 {
180 rc = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&g_DevPath2Txt);
181 if (EFI_ERROR(rc))
182 {
183 DEBUG((DEBUG_INFO, "gEfiDevicePathToTextProtocolGuid:%g isn't instantied\n", gEfiDevicePathToTextProtocolGuid));
184 return NULL;
185 }
186 }
187 return g_DevPath2Txt->ConvertDevicePathToText(pDevicePath, TRUE, FALSE);
188#else
189 return NULL;
190#endif
191}
192
193CHAR16 *VBoxDebugHandleDevicePath2Str(IN EFI_HANDLE hHandle)
194{
195#if 0
196 EFI_STATUS rc;
197 EFI_DEVICE_PATH_PROTOCOL *pDevicePath = NULL;
198 CHAR16 *psz16TxtDevicePath;
199 rc = gBS->OpenProtocol(hHandle,
200 &gEfiDevicePathProtocolGuid,
201 (VOID **)pDevicePath,
202 NULL,
203 hHandle,
204 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
205 if (EFI_ERROR(rc))
206 {
207 DEBUG((DEBUG_INFO, "%a:%d failed(%r) to open Device Path Protocol for Handle %p\n",
208 __FUNCTION__,
209 __LINE__,
210 rc,
211 hHandle));
212 return NULL;
213 }
214 psz16TxtDevicePath = VBoxDebugHandleDevicePath2Str(pDevicePath);
215 return psz16TxtDevicePath;
216#else
217 return NULL;
218#endif
219}
220CHAR16 *VBoxDebugPrintDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath)
221{
222#if 0
223 EFI_STATUS rc;
224 if (!g_DevPath2Txt)
225 {
226 rc = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&g_DevPath2Txt);
227 if (EFI_ERROR(rc))
228 {
229 DEBUG((DEBUG_INFO, "gEfiDevicePathToTextProtocolGuid:%g isn't instantied\n", gEfiDevicePathToTextProtocolGuid));
230 return NULL;
231 }
232 }
233 return g_DevPath2Txt->ConvertDevicePathToText(pDevicePath, TRUE, FALSE);
234#else
235 return NULL;
236#endif
237}
238
239
240VOID * EFIAPI
241DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
242{
243 return Buffer;
244}
245
246
247BOOLEAN EFIAPI
248DebugAssertEnabled(VOID)
249{
250 return TRUE;
251}
252
253
254BOOLEAN EFIAPI
255DebugPrintEnabled(VOID)
256{
257 /** @todo some PCD for this so we can disable it in release builds. */
258 return TRUE;
259}
260
261
262BOOLEAN EFIAPI
263DebugCodeEnabled(VOID)
264{
265 /** @todo ditto */
266 return TRUE;
267}
268
269
270BOOLEAN EFIAPI
271DebugClearMemoryEnabled(VOID)
272{
273 return FALSE;
274}
275
Note: See TracBrowser for help on using the repository browser.

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