1 | /* $Id: VBoxPrintHex.c 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxPrintHex.c - Implementation of the VBoxPrintHex() debug logging routine.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2024 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 | /*********************************************************************************************************************************
|
---|
40 | * Header Files *
|
---|
41 | *********************************************************************************************************************************/
|
---|
42 | #include <Library/BaseLib.h>
|
---|
43 |
|
---|
44 | #include "VBoxDebugLib.h"
|
---|
45 | #include "DevEFI.h"
|
---|
46 | #include "iprt/asm.h"
|
---|
47 |
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Prints a char.
|
---|
51 | * @param ch The char to print.
|
---|
52 | */
|
---|
53 | DECLINLINE(void) vboxPrintHexChar(int ch)
|
---|
54 | {
|
---|
55 | ASMOutU8(EFI_DEBUG_PORT, (uint8_t)ch);
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Print a hex number, up to 64-bit long.
|
---|
61 | *
|
---|
62 | * @returns Number of chars printed.
|
---|
63 | *
|
---|
64 | * @param uValue The value.
|
---|
65 | * @param cbType The size of the value type.
|
---|
66 | */
|
---|
67 | size_t VBoxPrintHex(UINT64 uValue, size_t cbType)
|
---|
68 | {
|
---|
69 | static const char s_szHex[17] = "0123456789abcdef";
|
---|
70 | switch (cbType)
|
---|
71 | {
|
---|
72 | /*
|
---|
73 | * We have to cast the result to UINTN before indexing into the array
|
---|
74 | * or cl.exe insists on generating a call to __allmul for unoptimized 32bit builds,
|
---|
75 | * see: https://patchew.org/EDK2/[email protected]/
|
---|
76 | */
|
---|
77 | #define VAL_NIBBLE_EXTRACT(a_uValue, a_iNibbleStart) (s_szHex[(UINTN)(RShiftU64((a_uValue), (a_iNibbleStart)) & 0xf)])
|
---|
78 | case 8:
|
---|
79 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 60));
|
---|
80 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 56));
|
---|
81 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 52));
|
---|
82 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 48));
|
---|
83 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 44));
|
---|
84 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 40));
|
---|
85 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 36));
|
---|
86 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 32));
|
---|
87 | case 4:
|
---|
88 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 28));
|
---|
89 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 24));
|
---|
90 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 20));
|
---|
91 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 16));
|
---|
92 | case 2:
|
---|
93 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 12));
|
---|
94 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 8));
|
---|
95 | case 1:
|
---|
96 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 4));
|
---|
97 | vboxPrintHexChar(VAL_NIBBLE_EXTRACT(uValue, 0));
|
---|
98 | break;
|
---|
99 | #undef VAL_NIBBLE_EXTRACT
|
---|
100 | }
|
---|
101 |
|
---|
102 | #if 0 /* There is no MultU32x32 for 32bit and cl insists on emitting __allmul otherwise so we just hardcode everything here... */
|
---|
103 | return cbType * 2;
|
---|
104 | #else
|
---|
105 | static size_t s_acbPrinted[9] = { 0, 2, 4, 0, 8, 0, 0, 0, 16};
|
---|
106 | if (cbType < RT_ELEMENTS(s_acbPrinted))
|
---|
107 | return s_acbPrinted[cbType];
|
---|
108 | return 0;
|
---|
109 | #endif
|
---|
110 | }
|
---|