[4e5299f] | 1 | /* |
---|
| 2 | * MDUMP Shell Command Implmentation |
---|
| 3 | * |
---|
| 4 | * Author: Fernando RUIZ CASAS |
---|
| 5 | * Work: fernando.ruiz@ctv.es |
---|
| 6 | * Home: correo@fernando-ruiz.com |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
| 10 | * http://www.rtems.com/license/LICENSE. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
| 19 | #include <ctype.h> |
---|
| 20 | #include <stdio.h> |
---|
[dfe0e58] | 21 | #include <inttypes.h> |
---|
[4e5299f] | 22 | #include <string.h> |
---|
| 23 | |
---|
| 24 | #include <rtems.h> |
---|
| 25 | #include <rtems/shell.h> |
---|
| 26 | #include "internal.h" |
---|
| 27 | |
---|
| 28 | /*----------------------------------------------------------------------------* |
---|
| 29 | * RAM MEMORY COMMANDS |
---|
| 30 | *----------------------------------------------------------------------------*/ |
---|
| 31 | |
---|
[dfe0e58] | 32 | int rtems_shell_main_mdump( |
---|
| 33 | int argc, |
---|
| 34 | char *argv[] |
---|
| 35 | ) |
---|
| 36 | { |
---|
[caf0e53] | 37 | unsigned char n, m; |
---|
| 38 | int max; |
---|
| 39 | int res; |
---|
[dfe0e58] | 40 | uintptr_t addr = 0; |
---|
[4e5299f] | 41 | unsigned char *pb; |
---|
| 42 | |
---|
| 43 | if (argc>1) |
---|
[2eeb648c] | 44 | addr = rtems_shell_str2int(argv[1]); |
---|
[dfe0e58] | 45 | |
---|
| 46 | if (argc>2) { |
---|
[2eeb648c] | 47 | max = rtems_shell_str2int(argv[2]); |
---|
[caf0e53] | 48 | if (max <= 0) { |
---|
| 49 | max = 1; /* print 1 item if 0 or neg. */ |
---|
| 50 | res = 0; |
---|
| 51 | } |
---|
| 52 | else { |
---|
| 53 | max--; |
---|
| 54 | res = max & 0xf;/* num bytes in last row */ |
---|
| 55 | max >>= 4; /* div by 16 */ |
---|
| 56 | max++; /* num of rows to print */ |
---|
| 57 | if (max > 20) { /* limit to 20 */ |
---|
| 58 | max = 20; |
---|
| 59 | res = 0xf; /* 16 bytes print in last row */ |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | else { |
---|
| 64 | max = 20; |
---|
| 65 | res = 0xf; |
---|
[dfe0e58] | 66 | } |
---|
[4e5299f] | 67 | |
---|
[dfe0e58] | 68 | for (m=0; m<max; m++) { |
---|
| 69 | printf("0x%08" PRIXPTR " ", addr); |
---|
[4e5299f] | 70 | pb = (unsigned char*) addr; |
---|
[caf0e53] | 71 | for (n=0;n<=(m==(max-1)?res:0xf);n++) |
---|
| 72 | printf("%02X%c",pb[n],n==7?'-':' '); |
---|
| 73 | for (;n<=0xf;n++) |
---|
| 74 | printf(" %c",n==7?'-':' '); |
---|
| 75 | for (n=0;n<=(m==(max-1)?res:0xf);n++) { |
---|
[dfe0e58] | 76 | printf("%c", isprint(pb[n]) ? pb[n] : '.'); |
---|
[4e5299f] | 77 | } |
---|
[dfe0e58] | 78 | printf("\n"); |
---|
[4e5299f] | 79 | addr += 16; |
---|
| 80 | } |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
| 83 | |
---|
[55216fa] | 84 | rtems_shell_cmd_t rtems_shell_MDUMP_Command = { |
---|
[4e5299f] | 85 | "mdump", /* name */ |
---|
[dfe0e58] | 86 | "mdump [address [length]]", /* usage */ |
---|
[4e5299f] | 87 | "mem", /* topic */ |
---|
[2eeb648c] | 88 | rtems_shell_main_mdump, /* command */ |
---|
[4e5299f] | 89 | NULL, /* alias */ |
---|
| 90 | NULL /* next */ |
---|
| 91 | }; |
---|
| 92 | |
---|