VirtualBox

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

Last change on this file since 48674 was 48674, checked in by vboxsync, 11 years ago

EFI: Export newly imported tinaocore UEFI sources to OSE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: VBoxPrintHexDump.c 48674 2013-09-25 08:26:15Z vboxsync $ */
2/** @file
3 * VBoxPrintHex.c - Implementation of the VBoxPrintHex() debug logging routine.
4 */
5
6/*
7 * Copyright (C) 2009-2010 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 "VBoxDebugLib.h"
33#include "DevEFI.h"
34#include <iprt/ctype.h>
35
36
37/**
38 * Prints a char.
39 * @returns 1.
40 * @param ch The char to print.
41 */
42DECLINLINE(int) vboxPrintHexDumpChar(int ch)
43{
44 ASMOutU8(EFI_DEBUG_PORT, (uint8_t)ch);
45 return 1;
46}
47
48
49/**
50 * Prints a hex dump the specified memory block.
51 *
52 * @returns Number of bytes printed.
53 *
54 * @param pv The memory to dump.
55 * @param cb Number of bytes to dump.
56 */
57size_t VBoxPrintHexDump(const void *pv, size_t cb)
58{
59 size_t cchPrinted = 0;
60 uint8_t const *pb = (uint8_t const *)pv;
61 while (cb > 0)
62 {
63 unsigned i;
64
65 /* the offset */
66 cchPrinted += VBoxPrintHex((uintptr_t)pb, sizeof(pb));
67 cchPrinted += VBoxPrintString(" ");
68
69 /* the hex bytes value. */
70 for (i = 0; i < 16; i++)
71 {
72 cchPrinted += vboxPrintHexDumpChar(i == 7 ? '-' : ' ');
73 if (i < cb)
74 cchPrinted += VBoxPrintHex(pb[i], 1);
75 else
76 cchPrinted += VBoxPrintString(" ");
77 }
78
79 /* the printable chars */
80 cchPrinted += VBoxPrintString(" ");
81 for (i = 0; i < 16 && i < cb; i++)
82 cchPrinted += vboxPrintHexDumpChar(pb[i] == ' '
83 ? ' '
84 : RT_C_IS_GRAPH(pb[i])
85 ? pb[i]
86 : '.');
87
88 /* finally, the new line. */
89 cchPrinted += vboxPrintHexDumpChar('\n');
90
91 /*
92 * Advance.
93 */
94 if (cb <= 16)
95 break;
96 cb -= 16;
97 pb += 16;
98 }
99
100 return cchPrinted;
101}
102
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