Giter VIP home page Giter VIP logo

mmio's People

Contributors

valinskas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mmio's Issues

display 32-bit words in binary

Hi,

I stumbled across your utility and it's great. I wanted to dump some gpio registers in binary so I hacked that into the utility. I'm not sure it's 100% correct, but it works for me. Here's the patch.

diff --git a/src/mmio.c b/src/mmio.c
index cd48237..c8bd7a5 100644
--- a/src/mmio.c
+++ b/src/mmio.c
@@ -38,6 +38,7 @@ static const char *usage =
" -a - 8bit hex + ascii output\n"
" -b - 8bit hex output\n"
" -h - 16bit hex output\n"
+" -n - 32bit binary output\n"
" -x - 32bit hex output\n"
" -k - use /dev/kmem instead of /dev/mem (default)\n"
"\n"
@@ -95,7 +96,7 @@ static void mmio_parse(struct mmio_options *mo, int argc, char *argv[])
for (;;) {
int ch;

  •   ch = getopt(argc, argv, "abhxk");
    
  •   ch = getopt(argc, argv, "abhnxk");
    if (ch == -1)
        break;
    

@@ -112,6 +113,10 @@ static void mmio_parse(struct mmio_options *mo, int argc, char *argv[])
mo->flags = HEXDUMP_16BIT;
break;

  •   case 'n':
    
  •       mo->flags = HEXDUMP_BIN;
    
  •       break;
    
    • case 'x':
      mo->flags = HEXDUMP_32BIT;
      break;
      diff --git a/src/utils.c b/src/utils.c
      index a3aaa82..956588a 100644
      --- a/src/utils.c
      +++ b/src/utils.c
      @@ -28,6 +28,26 @@ static void hexdump_eol(void)
      printf("\n");
      }

+static void hexdump_bin(const void *data, size_t length, size_t count)
+{

  • const unsigned char *ptr = data;
  • int i;
  • for (i = 0; i < length; ++i) {
  • int bits = 8;
  • unsigned char bit = *ptr++;
  • for (;bits--; bit >>= 1) {
  •     printf("%c", bit & 1 ? '1' : '0');
    
  • }
  • printf(" ");
  • }
  • for (i = length; i < count; ++i) {
  •   printf("   ");
    
  • }
    +}

static void hexdump_8bit(const void *data, size_t length, size_t count)
{
const unsigned char *ptr = data;
@@ -98,8 +118,12 @@ void __hexdump(unsigned long base, const void *data,
int nleft;

count = HEXDUMP_COUNT(flags);

  • if (count == 0)
  •   count = 16; /\* default */
    
  • if (count == 0) {
  • if (HEXDUMP_ISSET(flags, HEXDUMP_BIN))
  •  count = 4;
    
  • else
  •     count = 16;   /\* default */
    
  • }
    if (count > 32)
    count = 32; /* max allowed */

@@ -111,7 +135,9 @@ void __hexdump(unsigned long base, const void *data,

    hexdump_addr(base);
  •   if (HEXDUMP_ISSET(flags, HEXDUMP_8BIT)) {
    
  • if (HEXDUMP_ISSET(flags, HEXDUMP_BIN)) {
  •  hexdump_bin(data, nleft, count);
    
  • } else if (HEXDUMP_ISSET(flags, HEXDUMP_8BIT)) {
    hexdump_8bit(data, nleft, count);
    } else if (HEXDUMP_ISSET(flags, HEXDUMP_16BIT)) {
    hexdump_16bit(data, nleft, count);
    diff --git a/src/utils.h b/src/utils.h
    index 6763be9..82c91f8 100644
    --- a/src/utils.h
    +++ b/src/utils.h
    @@ -17,11 +17,12 @@
  • @arg number of columns and flags (0 - means default).
    */
    #define HEXDUMP_32BIT 0x8000
    +#define HEXDUMP_BIN 0x10000
    #define HEXDUMP_16BIT 0x4000
    #define HEXDUMP_8BIT 0x2000
    #define HEXDUMP_ASCII 0x1000
    -#define HEXDUMP_SIZEMASK (HEXDUMP_32BIT|HEXDUMP_16BIT|HEXDUMP_8BIT)
    -#define HEXDUMP_FLAGMASK (HEXDUMP_ASCII|HEXDUMP_32BIT|HEXDUMP_16BIT|HEXDUMP_8BIT)
    +#define HEXDUMP_SIZEMASK (HEXDUMP_32BIT|HEXDUMP_16BIT|HEXDUMP_8BIT|HEXDUMP_BIN)
    +#define HEXDUMP_FLAGMASK (HEXDUMP_ASCII|HEXDUMP_32BIT|HEXDUMP_16BIT|HEXDUMP_8BIT|HEXDUMP_BIN)
    #define HEXDUMP_ISSET(__x, __f) (((__x) & HEXDUMP_SIZEMASK) == (__f))

define HEXDUMP_COUNT(x) ((x) & 0xFF)

Thanks,

Seth

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.