1 | /* $Id: VBoxPrintHexDump.c 67350 2017-06-12 17:42:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxPrintHex.c - Implementation of the VBoxPrintHex() debug logging routine.
|
---|
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 | /*******************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *******************************************************************************/
|
---|
32 | #include <ctype.h>
|
---|
33 | #include "VBoxDebugLib.h"
|
---|
34 | #include "DevEFI.h"
|
---|
35 | #include "iprt/asm.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Prints a char.
|
---|
40 | * @returns 1.
|
---|
41 | * @param ch The char to print.
|
---|
42 | */
|
---|
43 | DECLINLINE(int) vboxPrintHexDumpChar(int ch)
|
---|
44 | {
|
---|
45 | ASMOutU8(EFI_DEBUG_PORT, (uint8_t)ch);
|
---|
46 | return 1;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Prints a hex dump the specified memory block.
|
---|
52 | *
|
---|
53 | * @returns Number of bytes printed.
|
---|
54 | *
|
---|
55 | * @param pv The memory to dump.
|
---|
56 | * @param cb Number of bytes to dump.
|
---|
57 | */
|
---|
58 | size_t VBoxPrintHexDump(const void *pv, size_t cb)
|
---|
59 | {
|
---|
60 | size_t cchPrinted = 0;
|
---|
61 | uint8_t const *pb = (uint8_t const *)pv;
|
---|
62 | while (cb > 0)
|
---|
63 | {
|
---|
64 | unsigned i;
|
---|
65 |
|
---|
66 | /* the offset */
|
---|
67 | cchPrinted += VBoxPrintHex((uintptr_t)pb, sizeof(pb));
|
---|
68 | cchPrinted += VBoxPrintString(" ");
|
---|
69 |
|
---|
70 | /* the hex bytes value. */
|
---|
71 | for (i = 0; i < 16; i++)
|
---|
72 | {
|
---|
73 | cchPrinted += vboxPrintHexDumpChar(i == 7 ? '-' : ' ');
|
---|
74 | if (i < cb)
|
---|
75 | cchPrinted += VBoxPrintHex(pb[i], 1);
|
---|
76 | else
|
---|
77 | cchPrinted += VBoxPrintString(" ");
|
---|
78 | }
|
---|
79 |
|
---|
80 | /* the printable chars */
|
---|
81 | cchPrinted += VBoxPrintString(" ");
|
---|
82 | for (i = 0; i < 16 && i < cb; i++)
|
---|
83 | cchPrinted += vboxPrintHexDumpChar(isprint(pb[i])
|
---|
84 | ? pb[i]
|
---|
85 | : '.');
|
---|
86 |
|
---|
87 | /* finally, the new line. */
|
---|
88 | cchPrinted += vboxPrintHexDumpChar('\n');
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * Advance.
|
---|
92 | */
|
---|
93 | if (cb <= 16)
|
---|
94 | break;
|
---|
95 | cb -= 16;
|
---|
96 | pb += 16;
|
---|
97 | }
|
---|
98 |
|
---|
99 | return cchPrinted;
|
---|
100 | }
|
---|
101 |
|
---|