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> |
---|
21 | #include <inttypes.h> |
---|
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 | |
---|
32 | int rtems_shell_main_mdump( |
---|
33 | int argc, |
---|
34 | char *argv[] |
---|
35 | ) |
---|
36 | { |
---|
37 | unsigned char n, m; |
---|
38 | int max; |
---|
39 | int res; |
---|
40 | uintptr_t addr = 0; |
---|
41 | unsigned char *pb; |
---|
42 | |
---|
43 | if (argc>1) |
---|
44 | addr = rtems_shell_str2int(argv[1]); |
---|
45 | |
---|
46 | if (argc>2) { |
---|
47 | max = rtems_shell_str2int(argv[2]); |
---|
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; |
---|
66 | } |
---|
67 | |
---|
68 | for (m=0; m<max; m++) { |
---|
69 | printf("0x%08" PRIXPTR " ", addr); |
---|
70 | pb = (unsigned char*) addr; |
---|
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++) { |
---|
76 | printf("%c", isprint(pb[n]) ? pb[n] : '.'); |
---|
77 | } |
---|
78 | printf("\n"); |
---|
79 | addr += 16; |
---|
80 | } |
---|
81 | return 0; |
---|
82 | } |
---|
83 | |
---|
84 | rtems_shell_cmd_t rtems_shell_MDUMP_Command = { |
---|
85 | "mdump", /* name */ |
---|
86 | "mdump [address [length]]", /* usage */ |
---|
87 | "mem", /* topic */ |
---|
88 | rtems_shell_main_mdump, /* command */ |
---|
89 | NULL, /* alias */ |
---|
90 | NULL /* next */ |
---|
91 | }; |
---|
92 | |
---|