VirtualBox

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

Last change on this file since 69429 was 69429, checked in by vboxsync, 7 years ago

efi: scm updates

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