File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifdef HAVE_CONFIG_H
0018 #include "config.h"
0019 #endif
0020
0021 #include <ctype.h>
0022 #include <stdio.h>
0023 #include <inttypes.h>
0024 #include <string.h>
0025
0026 #include <rtems.h>
0027 #include <rtems/shell.h>
0028 #include <rtems/stringto.h>
0029 #include "internal.h"
0030
0031 static int args_parse(int argc, char* argv[], void** addr, int* max, int* sz);
0032
0033 static void mdumpB(void* addr, int m);
0034 static void mdumpW(void* addr, int m);
0035 static void mdumpL(void* addr, int m);
0036 static void mdumpC(void* addr, int m);
0037
0038 int rtems_mdump(void* addr, int max, int sz);
0039
0040 static int rtems_shell_main_mdump(
0041 int argc,
0042 char *argv[]
0043 )
0044 {
0045 void *addr;
0046 int max;
0047 int sz;
0048
0049 if (args_parse(argc, argv, &addr, &max, &sz))
0050 return -1;
0051 return rtems_mdump(addr, max, sz);
0052 }
0053
0054 static int rtems_shell_main_wdump(
0055 int argc,
0056 char *argv[]
0057 )
0058 {
0059 void *addr;
0060 int max;
0061 int sz;
0062
0063 if (args_parse(argc, argv, &addr, &max, &sz))
0064 return -1;
0065 return rtems_mdump(addr, max, 2);
0066 }
0067
0068
0069 static int rtems_shell_main_ldump(
0070 int argc,
0071 char *argv[]
0072 )
0073 {
0074 void *addr;
0075 int max;
0076 int sz;
0077
0078 if (args_parse(argc, argv, &addr, &max, &sz))
0079 return -1;
0080 return rtems_mdump(addr, max, 4);
0081 }
0082
0083
0084 int args_parse(int argc,
0085 char* argv[],
0086 void** addr,
0087 int* max,
0088 int* sz)
0089 {
0090 *addr = NULL;
0091 *max = 320;
0092 *sz = 1;
0093
0094 if (argc > 1) {
0095 if ( rtems_string_to_pointer(argv[1], addr, NULL) ) {
0096 printf( "Address argument (%s) is not a number\n", argv[1] );
0097 return -1;
0098 }
0099
0100 if (argc > 2) {
0101 if ( rtems_string_to_int(argv[2], max, NULL, 0) ) {
0102 printf( "Length argument (%s) is not a number\n", argv[2] );
0103 return -1;
0104 }
0105
0106 if (argc > 3) {
0107 if ( rtems_string_to_int(argv[3], sz, NULL, 0) ) {
0108 printf( "Size argument (%s) is not a valid number\n", argv[3] );
0109 return -1;
0110 }
0111 }
0112 }
0113 }
0114 return 0;
0115 }
0116
0117
0118 int rtems_mdump(void* addr, int max, int sz)
0119 {
0120 unsigned char m;
0121 unsigned char *pb;
0122 int res;
0123 int cnt;
0124
0125 if (!((sz == 1) || (sz == 2) || (sz == 4))) {
0126 printf( "Size argument (%d) is not one of 1 (bytes), "
0127 " 2 (words) or 4 (longwords)\n", sz);
0128 return -1;
0129 }
0130
0131 if (max <= 0) {
0132 max = 1;
0133 res = 0;
0134 } else {
0135 max--;
0136 res = max & 0xf;
0137 max >>= 4;
0138 max++;
0139 if (max > 64) {
0140 max = 64;
0141 res = 0xf;
0142 }
0143 }
0144
0145 pb = addr;
0146 for (m=0; m<max; m++) {
0147 cnt = m==(max-1)?res:0xf;
0148 printf("%10p ", pb);
0149 if (sz == 1) mdumpB(pb, cnt);
0150 else if (sz == 2) mdumpW(pb, cnt);
0151 else if (sz == 4) mdumpL(pb, cnt);
0152 mdumpC(pb, cnt);
0153 printf("\n");
0154 pb += 16;
0155 }
0156
0157 return 0;
0158 }
0159
0160
0161 void mdumpB(void* addr, int m)
0162 {
0163 volatile unsigned char* pb = addr;
0164 int n;
0165 for (n=0;n<=m;n++)
0166 printf("%02X%c",*pb++,n==7?'-':' ');
0167 for (;n<=0xf;n++)
0168 printf(" %c",n==7?'-':' ');
0169 }
0170
0171
0172 void mdumpW(void* addr, int m)
0173 {
0174 volatile unsigned short* pb = addr;
0175 int n;
0176 for (n=0;n<=m;n+=2)
0177 printf("%04X%c",*pb++,n==6?'-':' ');
0178 for (;n<=0xf;n+=2)
0179 printf(" %c", n==6?'-':' ');
0180 }
0181
0182
0183 void mdumpL(void* addr, int m)
0184 {
0185 volatile unsigned int* pb = addr;
0186 int n;
0187 for (n=0;n<=m;n+=4)
0188 printf("%08X%c",*pb++,n==4?'-':' ');
0189 for (;n<=0xf;n+=4)
0190 printf(" %c", n==4?'-':' ');
0191 }
0192
0193
0194 void mdumpC(void* addr, int m)
0195 {
0196 volatile unsigned char* pb = addr;
0197 int n;
0198 for (n=0;n<=m;n++)
0199 printf("%c", isprint(pb[n]) ? pb[n] : '.');
0200 }
0201
0202
0203 rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
0204 "mdump",
0205 "mdump [address [length [size]]]",
0206 "mem",
0207 rtems_shell_main_mdump,
0208 NULL,
0209 NULL
0210 };
0211
0212
0213 rtems_shell_cmd_t rtems_shell_WDUMP_Command = {
0214 "wdump",
0215 "wdump [address [length]]",
0216 "mem",
0217 rtems_shell_main_wdump,
0218 NULL,
0219 NULL
0220 };
0221
0222
0223 rtems_shell_cmd_t rtems_shell_LDUMP_Command = {
0224 "ldump",
0225 "ldump [address [length]]",
0226 "mem",
0227 rtems_shell_main_ldump,
0228 NULL,
0229 NULL
0230 };
0231