VirtualBox

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

Last change on this file since 106061 was 106061, checked in by vboxsync, 4 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: VBoxPrintHexDump.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 "VBoxDebugLib.h"
43#include "DevEFI.h"
44#include "iprt/asm.h"
45#include "iprt/ctype.h"
46
47
48/**
49 * Prints a char.
50 * @returns 1.
51 * @param ch The char to print.
52 */
53DECLINLINE(int) vboxPrintHexDumpChar(int ch)
54{
55 ASMOutU8(EFI_DEBUG_PORT, (uint8_t)ch);
56 return 1;
57}
58
59
60/**
61 * Prints a hex dump the specified memory block.
62 *
63 * @returns Number of bytes printed.
64 *
65 * @param pv The memory to dump.
66 * @param cb Number of bytes to dump.
67 */
68size_t VBoxPrintHexDump(const void *pv, size_t cb)
69{
70 size_t cchPrinted = 0;
71 uint8_t const *pb = (uint8_t const *)pv;
72 while (cb > 0)
73 {
74 unsigned i;
75
76 /* the offset */
77 cchPrinted += VBoxPrintHex((uintptr_t)pb, sizeof(pb));
78 cchPrinted += VBoxPrintString(" ");
79
80 /* the hex bytes value. */
81 for (i = 0; i < 16; i++)
82 {
83 cchPrinted += vboxPrintHexDumpChar(i == 7 ? '-' : ' ');
84 if (i < cb)
85 cchPrinted += VBoxPrintHex(pb[i], 1);
86 else
87 cchPrinted += VBoxPrintString(" ");
88 }
89
90 /* the printable chars */
91 cchPrinted += VBoxPrintString(" ");
92 for (i = 0; i < 16 && i < cb; i++)
93 cchPrinted += vboxPrintHexDumpChar(RT_C_IS_PRINT(pb[i])
94 ? pb[i]
95 : '.');
96
97 /* finally, the new line. */
98 cchPrinted += vboxPrintHexDumpChar('\n');
99
100 /*
101 * Advance.
102 */
103 if (cb <= 16)
104 break;
105 cb -= 16;
106 pb += 16;
107 }
108
109 return cchPrinted;
110}
111
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