summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/cmd_mdump.c
blob: efb57303fcdae1233ef6b431e2d0611f446a5a65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 *  MDUMP Shell Command Implmentation
 *
 *  Author: Fernando RUIZ CASAS
 *  Work: fernando.ruiz@ctv.es
 *  Home: correo@fernando-ruiz.com
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <ctype.h>
#include <stdio.h>
#include <string.h>

#include <rtems.h>
#include <rtems/shell.h>
#include "internal.h"

/*----------------------------------------------------------------------------*
 * RAM MEMORY COMMANDS
 *----------------------------------------------------------------------------*/

int main_mdump(int argc,char * argv[]) {
  unsigned char  n,m,max=0;
  uintptr_t      addr;
  unsigned char *pb;

  addr = current_shell_env->mdump_addr;
  if (argc>1)
    addr = str2int(argv[1]);
  if (argc>2)
    max = str2int(argv[2]);

  max /= 16;

  if (!max)
    max = 20;

  for (m=0;m<max;m++) {
    fprintf(stdout,"0x%08X ",addr);
    pb = (unsigned char*) addr;
    for (n=0;n<16;n++)
      fprintf(stdout,"%02X%c",pb[n],n==7?'-':' ');
    for (n=0;n<16;n++) {
      fprintf(stdout,"%c",isprint(pb[n])?pb[n]:'.');
    }
    fprintf(stdout,"\n");
    addr += 16;
  }
  current_shell_env->mdump_addr = addr;
  return 0;
}

shell_cmd_t Shell_MDUMP_Command = {
  "mdump",                                      /* name */
  "mdump [addr [size]]",                        /* usage */
  "mem",                                        /* topic */
  main_mdump,                                   /* command */
  NULL,                                         /* alias */
  NULL                                          /* next */
};


/*----------------------------------------------------------------------------*/
int main_mwdump(int argc,char * argv[]) {
  unsigned char n,m,max=0;
  int addr=current_shell_env->mdump_addr;
  unsigned short * pw;

  if (argc>1)
    addr = str2int(argv[1]);
  if (argc>2)
    max = str2int(argv[2]);

  max /= 16;

  if (!max)
    max = 20;

  for (m=0;m<max;m++) {
    fprintf(stdout,"0x%08X ",addr);
    pw = (unsigned short*) addr;
    for (n=0;n<8;n++)
      fprintf(stdout,"%02X %02X%c",pw[n]/0x100,pw[n]%0x100,n==3?'-':' ');
    for (n=0;n<8;n++) {
      fprintf(stdout,"%c",isprint(pw[n]/0x100)?pw[n]/0x100:'.');
      fprintf(stdout,"%c",isprint(pw[n]%0x100)?pw[n]%0x100:'.');
    }
    fprintf(stdout,"\n");
    addr += 16;
  }
  current_shell_env->mdump_addr = addr;
  return 0;
}

shell_cmd_t Shell_WDUMP_Command = {
  "wdump",                                      /* name */
  "wdump [addr [size]]",                        /* usage */
  "mem",                                        /* topic */
  main_mwdump,                                  /* command */
  NULL,                                         /* alias */
  NULL                                          /* next */
};

/*----------------------------------------------------------------------------*/
int main_medit(int argc,char * argv[]) {
  unsigned char * pb;
  int n,i;

  if (argc<3) {
    fprintf(stdout,"too few arguments\n");
    return 0;
  }

  pb = (unsigned char*)str2int(argv[1]);
  i = 2;
  n = 0;
  while (i<=argc) {
    pb[n++] = str2int(argv[i++])%0x100;
  }
  current_shell_env->mdump_addr = (int)pb;
  return main_mdump(0,NULL);
}

shell_cmd_t Shell_MEDIT_Command = {
  "medit",                                      /* name */
  "medit addr value [value ...]",               /* usage */
  "mem",                                        /* topic */
  main_medit,                                   /* command */
  NULL,                                         /* alias */
  NULL                                          /* next */
};

/*----------------------------------------------------------------------------*/
int main_mfill(int argc,char * argv[]) {
  int  addr;
  int  size;
  unsigned char value;

  if (argc<4) {
    fprintf(stdout,"too few arguments\n");
    return 0;
  }
  addr = str2int(argv[1]);
  size = str2int(argv[2]);
  value= str2int(argv[3]) % 0x100;
  memset((unsigned char*)addr,size,value);
  current_shell_env->mdump_addr = addr;
 return main_mdump(0,NULL);
}

shell_cmd_t Shell_MFILL_Command = {
  "mfill",                                      /* name */
  "mfill addr size value",                      /* usage */
  "mem",                                        /* topic */
  main_mfill,                                   /* command */
  NULL,                                         /* alias */
  NULL                                          /* next */
};

/*----------------------------------------------------------------------------*/
int main_mmove(int argc,char * argv[]) {
 int  src;
 int  dst;
 int  size;

 if (argc<4) {
  fprintf(stdout,"too few arguments\n");
  return 0;
 }
 dst  = str2int(argv[1]);
 src  = str2int(argv[2]);
 size = str2int(argv[3]);
 memcpy((unsigned char*)dst,(unsigned char*)src,size);
 current_shell_env->mdump_addr = dst;
 return main_mdump(0,NULL);
}

shell_cmd_t Shell_MMOVE_Command = {
  "mmove",                                      /* name */
  "mmove dst src size",                         /* usage */
  "mem",                                        /* topic */
  main_mmove,                                   /* command */
  NULL,                                         /* alias */
  NULL                                          /* next */
};