~ubuntu-branches/ubuntu/vivid/virtualbox-ose/vivid

« back to all changes in this revision

Viewing changes to src/VBox/Devices/EFI/Firmware2/VBoxPkg/Library/VBoxDebugLib/VBoxPrintHexDump.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2010-03-11 17:16:37 UTC
  • mfrom: (0.3.4 upstream) (0.4.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100311171637-43z64ia3ccpj8vqn
Tags: 3.1.4-dfsg-2ubuntu1
* Merge from Debian unstable (LP: #528561), remaining changes:
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
  - Replace *-source packages with transitional packages for *-dkms
* Fix crash in vboxvideo_drm with kernel 2.6.33 / backported drm code
  (LP: #535297)
* Add a list of linux-headers packages to the apport hook
* Update debian/patches/u02-lp-integration.dpatch with a
  DEP-3 compliant header
* Add ${misc:Depends} to virtualbox-ose-source and virtualbox-ose-guest-source
  Depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: VBoxPrintHexDump.c $ */
 
2
/** @file
 
3
 * VBoxPrintHex.c - Implementation of the VBoxPrintHex() debug logging routine.
 
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
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
 
18
 * Clara, CA 95054 USA or visit http://www.sun.com if you need
 
19
 * additional information or have any questions.
 
20
 */
 
21
 
 
22
 
 
23
 
 
24
/*******************************************************************************
 
25
*   Header Files                                                               *
 
26
*******************************************************************************/
 
27
#include "VBoxDebugLib.h"
 
28
#include "DevEFI.h"
 
29
#include <iprt/ctype.h>
 
30
 
 
31
 
 
32
/**
 
33
 * Prints a char.
 
34
 * @returns 1.
 
35
 * @param   ch              The char to print.
 
36
 */
 
37
DECLINLINE(int) vboxPrintHexDumpChar(int ch)
 
38
{
 
39
    ASMOutU8(EFI_DEBUG_PORT, (uint8_t)ch);
 
40
    return 1;
 
41
}
 
42
 
 
43
 
 
44
/**
 
45
 * Prints a hex dump the specified memory block.
 
46
 *
 
47
 * @returns Number of bytes printed.
 
48
 *
 
49
 * @param   pv      The memory to dump.
 
50
 * @param   cb      Number of bytes to dump.
 
51
 */
 
52
size_t VBoxPrintHexDump(const void *pv, size_t cb)
 
53
{
 
54
    size_t          cchPrinted = 0;
 
55
    uint8_t const  *pb         = (uint8_t const *)pv;
 
56
    while (cb > 0)
 
57
    {
 
58
        unsigned i;
 
59
 
 
60
        /* the offset */
 
61
        cchPrinted += VBoxPrintHex((uintptr_t)pb, sizeof(pb));
 
62
        cchPrinted += VBoxPrintString("  ");
 
63
 
 
64
        /* the hex bytes value. */
 
65
        for (i = 0; i < 16; i++)
 
66
        {
 
67
            cchPrinted += vboxPrintHexDumpChar(i == 7 ? '-' : ' ');
 
68
            if (i < cb)
 
69
                cchPrinted += VBoxPrintHex(pb[i], 1);
 
70
            else
 
71
                cchPrinted += VBoxPrintString("  ");
 
72
        }
 
73
 
 
74
        /* the printable chars */
 
75
        cchPrinted += VBoxPrintString("  ");
 
76
        for (i = 0; i < 16 && i < cb; i++)
 
77
            cchPrinted += vboxPrintHexDumpChar(pb[i] == ' '
 
78
                                               ? ' '
 
79
                                               : RT_C_IS_GRAPH(pb[i])
 
80
                                               ? pb[i]
 
81
                                               : '.');
 
82
 
 
83
        /* finally, the new line. */
 
84
        cchPrinted += vboxPrintHexDumpChar('\n');
 
85
 
 
86
        /*
 
87
         * Advance.
 
88
         */
 
89
        if (cb <= 16)
 
90
            break;
 
91
        cb -= 16;
 
92
        pb += 16;
 
93
    }
 
94
 
 
95
    return cchPrinted;
 
96
}
 
97