1 | /* $Id: VBoxDebugLib.c 26438 2010-02-11 15:38:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxDebugLib.c - Debug logging and assertions support routines using DevEFI.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009,2010 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /*******************************************************************************
|
---|
32 | * Header Files *
|
---|
33 | *******************************************************************************/
|
---|
34 | #include <Base.h>
|
---|
35 | #include <Library/PrintLib.h>
|
---|
36 | #include <Library/DebugLib.h>
|
---|
37 |
|
---|
38 | #include "VBoxDebugLib.h"
|
---|
39 | #include "DevEFI.h"
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | VOID EFIAPI
|
---|
44 | DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format, ...)
|
---|
45 | {
|
---|
46 | CHAR8 szBuf[256];
|
---|
47 | VA_LIST va;
|
---|
48 | UINTN cch;
|
---|
49 | RTCCUINTREG SavedFlags;
|
---|
50 |
|
---|
51 | /* No pool noise, please. */
|
---|
52 | if (ErrorLevel == DEBUG_POOL)
|
---|
53 | return;
|
---|
54 |
|
---|
55 | VA_START(va, Format);
|
---|
56 | cch = AsciiVSPrint(szBuf, sizeof(szBuf), Format, va);
|
---|
57 | VA_END(va);
|
---|
58 |
|
---|
59 | /* make sure it's terminated and doesn't end with a newline */
|
---|
60 | if (cch >= sizeof(szBuf))
|
---|
61 | cch = sizeof(szBuf) - 1;
|
---|
62 | while (cch > 0 && (szBuf[cch - 1] == '\n' || szBuf[cch - 1] == '\r'))
|
---|
63 | cch--;
|
---|
64 | szBuf[cch] = '\0';
|
---|
65 |
|
---|
66 | SavedFlags = ASMIntDisableFlags();
|
---|
67 |
|
---|
68 | VBoxPrintString("dbg/");
|
---|
69 | VBoxPrintHex(ErrorLevel, sizeof(ErrorLevel));
|
---|
70 | VBoxPrintChar(' ');
|
---|
71 | VBoxPrintString(szBuf);
|
---|
72 | VBoxPrintChar('\n');
|
---|
73 |
|
---|
74 | ASMSetFlags(SavedFlags);
|
---|
75 |
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | VOID EFIAPI
|
---|
80 | DebugAssert(IN CONST CHAR8 *FileName, IN UINTN LineNumber, IN CONST CHAR8 *Description)
|
---|
81 | {
|
---|
82 | RTCCUINTREG SavedFlags = ASMIntDisableFlags();
|
---|
83 |
|
---|
84 | VBoxPrintString("EFI Assertion failed! File=");
|
---|
85 | VBoxPrintString(FileName ? FileName : "<NULL>");
|
---|
86 | VBoxPrintString(" line=0x");
|
---|
87 | VBoxPrintHex(LineNumber, sizeof(LineNumber));
|
---|
88 | VBoxPrintString("\nDescription: ");
|
---|
89 | VBoxPrintString(Description ? Description : "<NULL>");
|
---|
90 |
|
---|
91 | ASMOutU8(EFI_PANIC_PORT, 2); /** @todo fix this. */
|
---|
92 |
|
---|
93 | ASMSetFlags(SavedFlags);
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | VOID * EFIAPI
|
---|
98 | DebugClearMemory(OUT VOID *Buffer, IN UINTN Length)
|
---|
99 | {
|
---|
100 | return Buffer;
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | BOOLEAN EFIAPI
|
---|
105 | DebugAssertEnabled(VOID)
|
---|
106 | {
|
---|
107 | return TRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | BOOLEAN EFIAPI
|
---|
112 | DebugPrintEnabled(VOID)
|
---|
113 | {
|
---|
114 | /** @todo some PCD for this so we can disable it in release builds. */
|
---|
115 | return TRUE;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | BOOLEAN EFIAPI
|
---|
120 | DebugCodeEnabled(VOID)
|
---|
121 | {
|
---|
122 | /** @todo ditto */
|
---|
123 | return TRUE;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | BOOLEAN EFIAPI
|
---|
128 | DebugClearMemoryEnabled(VOID)
|
---|
129 | {
|
---|
130 | return FALSE;
|
---|
131 | }
|
---|
132 |
|
---|