diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index 2a7ba78d41..4f4e67192f 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -1,5 +1,4 @@ ## -## $Id$ ## include $(top_srcdir)/automake/compile.am @@ -77,7 +76,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \ shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \ shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \ shell/main_mmove.c shell/main_msdosfmt.c \ - shell/main_mv.c shell/main_mwdump.c shell/main_perioduse.c \ + shell/main_mv.c shell/main_perioduse.c \ shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \ shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \ shell/main_unmount.c shell/main_blksync.c shell/main_whoami.c \ diff --git a/cpukit/libmisc/shell/main_mdump.c b/cpukit/libmisc/shell/main_mdump.c index d196711363..156a6f262e 100644 --- a/cpukit/libmisc/shell/main_mdump.c +++ b/cpukit/libmisc/shell/main_mdump.c @@ -5,11 +5,11 @@ * Work: fernando.ruiz@ctv.es * Home: correo@fernando-ruiz.com * + * Reworked by Ric Claus at SLAC.Stanford.edu + * * 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 @@ -26,71 +26,197 @@ #include #include "internal.h" +static int args_parse(int argc, char* argv[], void** addr, int* max, int* sz); + +static void mdumpB(void* addr, int m); +static void mdumpW(void* addr, int m); +static void mdumpL(void* addr, int m); + +int rtems_mdump(void* addr, int max, int sz); + int rtems_shell_main_mdump( int argc, char *argv[] ) { - unsigned char n; - unsigned char m; - int max; - int res; - void *addr = NULL; - unsigned char *pb; + void *addr; + int max; + int sz; + + if (args_parse(argc, argv, &addr, &max, &sz)) + return -1; + return rtems_mdump(addr, max, sz); +} + +int rtems_shell_main_wdump( + int argc, + char *argv[] +) +{ + void *addr; + int max; + int sz; + + if (args_parse(argc, argv, &addr, &max, &sz)) + return -1; + return rtems_mdump(addr, max, 2); +} + + +int rtems_shell_main_ldump( + int argc, + char *argv[] +) +{ + void *addr; + int max; + int sz; + + if (args_parse(argc, argv, &addr, &max, &sz)) + return -1; + return rtems_mdump(addr, max, 4); +} + + +int args_parse(int argc, + char* argv[], + void** addr, + int* max, + int* sz) +{ + *addr = NULL; + *max = 320; + *sz = 1; if (argc > 1) { - if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) { + if ( rtems_string_to_pointer(argv[1], addr, NULL) ) { printf( "Address argument (%s) is not a number\n", argv[1] ); return -1; } - } + if (argc > 2) { + if ( rtems_string_to_int(argv[2], max, NULL, 0) ) { + printf( "Length argument (%s) is not a number\n", argv[2] ); + return -1; + } - if (argc > 2) { - if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) { - printf( "Length argument (%s) is not a number\n", argv[1] ); - return -1; - } - if (max <= 0) { - max = 1; /* print 1 item if 0 or neg. */ - res = 0; - } else { - max--; - res = max & 0xf;/* num bytes in last row */ - max >>= 4; /* div by 16 */ - max++; /* num of rows to print */ - if (max > 20) { /* limit to 20 */ - max = 20; - res = 0xf; /* 16 bytes print in last row */ + if (argc > 3) { + if ( rtems_string_to_int(argv[3], sz, NULL, 0) ) { + printf( "Size argument (%s) is not a valid number\n", argv[3] ); + return -1; + } } } + } + return 0; +} + + +int rtems_mdump(void* addr, int max, int sz) +{ + unsigned char n; + unsigned char m; + volatile unsigned char *pb; + int res; + int cnt; + + if (!((sz == 1) || (sz == 2) || (sz == 4))) { + printf( "Size argument (%d) is not one of 1 (bytes), " + " 2 (words) or 4 (longwords)\n", sz); + return -1; + } + + if (max <= 0) { + max = 1; /* print 1 item if 0 or neg. */ + res = 0; } else { - max = 20; - res = 0xf; + max--; + res = max & 0xf; /* num bytes in last row */ + max >>= 4; /* div by 16 */ + max++; /* num of rows to print */ + if (max > 64) { /* limit to 64 lines */ + max = 64; + res = 0xf; /* 16 bytes print in last row */ + } } pb = addr; for (m=0; m