32 static unsigned char *mdAddr;
33 static unsigned char mdDs;
35 static void init_dump(
void)
37 #ifdef GSC_TARGET_SYSTEM_EMU 38 #ifdef GSC_MEMORY_HEAP_IS_NEWLIB 41 mdAddr = (
unsigned char *)MEM_START;
49 static int dump(
int argc,
uchar *argv[]);
59 .usage_str =
"[-b|w|l] [start [end]]",
60 .manual_str =
"Dump memory" 63 static int dump(
int argc,
uchar *argv[])
65 unsigned char *ed = mdAddr + 256;
69 for(i=1; i<argc; i++) {
70 if(argv[i][0] ==
'-') {
72 case 'b': mdDs = 1;
break;
73 case 'w': mdDs = 2;
break;
74 case 'l': mdDs = 4;
break;
81 mdAddr = (
unsigned char *)(
long)
hstoi(argv[i]);
86 ed = (
unsigned char *)(
long)
hstoi(argv[i]);
96 for(dp=mdAddr; dp<ed; dp+=16) {
104 for(p=dp; p<dp+8; p++) {
112 for(p=dp+8; p<dp+16; p++) {
121 for(p=dp; p<dp+16; p+=2) {
123 tprintf(
"%04X ", *(
unsigned short *)p);
131 for(p=dp; p<dp+16; p+=4) {
133 tprintf(
"%08lX ", *(
unsigned long *)p);
146 for(p=dp; p<dp+16; p++) {
148 if(((
' ' <= *p) && (*p <=
'Z'))
149 || ((
'a' <= *p) && (*p <=
'z'))) {
161 if(rd == ASCII_CTRL_D) {
174 static int fill(
int argc,
uchar *argv[]);
182 .usage_str =
"<start> <end> <val>",
183 .manual_str =
"Fill memory" 186 static int fill(
int argc,
uchar *argv[])
188 unsigned char ds = 1;
189 unsigned char *st = 0, *ed = 0;
194 for(i=1; i<argc; i++) {
195 if(argv[i][0] ==
'-') {
197 case 'b': ds = 1;
break;
198 case 'w': ds = 2;
break;
199 case 'l': ds = 4;
break;
206 st = (
unsigned char *)(
long)
hstou(argv[i]);
211 ed = (
unsigned char *)(
long)
hstou(argv[i]);
216 dt = (
unsigned int)
hstoi(argv[i]);
227 print_command_usage(&com_mem_fill);
231 tprintf(
"Fill memory %p - %p ", st, ed);
252 for(dp=st; dp<=ed; dp+=ds) {
259 *(
unsigned short *)dp = (
unsigned short)dt;
263 *(
unsigned long *)dp = (
unsigned long)dt;
280 static void init_memedit(
void)
282 #ifdef GSC_TARGET_SYSTEM_EMU 283 #ifdef GSC_MEMORY_HEAP_IS_NEWLIB 293 static int memedit(
int argc,
uchar *argv[])
296 unsigned char an = 1;
312 if(argv[1][0] ==
'-') {
331 meAddr = (
void *)(
unsigned long)
hstou(argv[an]);
340 for(i=an; i<argc; i++) {
344 *(
unsigned char *)meAddr =
345 (
unsigned char)
hstoi(argv[i]);
350 *(
unsigned short *)meAddr =
351 (
unsigned short)
hstoi(argv[i]);
356 *(
unsigned long *)meAddr =
357 (
unsigned long)
hstoi(argv[i]);
369 tprintf(
"%02X", (
int)*(
unsigned char *)meAddr);
374 tprintf(
"%04X", (
int)*(
unsigned short *)meAddr);
379 tprintf(
"%08lX", (
long)*(
unsigned long *)meAddr);
395 .init = init_memedit,
397 .attr = CMDATTR_CTAL,
398 .usage_str =
"[-b|w|l] [address] [value ...]",
399 .manual_str =
"Edit memory" 405 .attr = CMDATTR_CTAL,
406 .usage_str =
"[address] [value ...]",
407 .manual_str =
"Byte edit memory" 413 .attr = CMDATTR_CTAL,
414 .usage_str =
"[address] [value ...]",
415 .manual_str =
"Word edit memory" 421 .attr = CMDATTR_CTAL,
422 .usage_str =
"[address] [value ...]",
423 .manual_str =
"Long word edit memory" 431 static int memory_check(
unsigned long *sp,
unsigned long *ep,
438 tprintf(
"Writing %08lX...\n", data);
440 for(dp=sp; dp<=ep; dp++) {
443 if(rd == ASCII_CTRL_C) {
451 for(dp=sp; dp<=ep; dp++) {
454 tprintf(
"\nVerify Error at %p W:%08lX R:%08lX",
458 if(rd == ASCII_CTRL_C) {
474 static int memory_check_a(
unsigned long *sp,
unsigned long *ep)
480 tprintf(
"Writing address data...\n");
482 for(dp=sp; dp<=ep; dp++) {
483 *dp = (
unsigned long)dp;
485 if(rd == ASCII_CTRL_C) {
493 for(dp=sp; dp<=ep; dp++) {
494 if(*dp != (
unsigned long)dp) {
496 tprintf(
"\nVerify Error at %p W:%08lX R:%08lX", dp,
501 if(rd == ASCII_CTRL_C) {
517 static int memory_check_ar(
unsigned long *sp,
unsigned long *ep)
523 tprintf(
"Writing invert address data...\n");
525 for(dp=sp; dp<=ep; dp++) {
526 *dp = ~((
unsigned long)dp);
528 if(rd == ASCII_CTRL_C) {
536 for(dp=sp; dp<=ep; dp++) {
537 if(*dp != ~((
unsigned long)dp)) {
539 tprintf(
"\nVerify Error at %p W:%08lX R:%08lX",
541 ~((
unsigned long)dp),
545 if(rd == ASCII_CTRL_C) {
561 static int memory_check_aq(
unsigned long *sp,
unsigned long *ep)
567 tprintf(
"Write and checking address data...\n");
570 for(dp=sp; dp<=ep; dp++) {
571 *dp = (
unsigned long)dp;
572 if(*dp != (
unsigned long)dp) {
574 tprintf(
"\nVerify Error at %p W:%08lX R:%08lX",
580 if(rd == ASCII_CTRL_C) {
605 .usage_str =
"[Start [End]]",
606 .manual_str =
"Memory check" 617 #ifdef GSC_TARGET_SYSTEM_EMU 618 #ifdef GSC_MEMORY_HEAP_IS_NEWLIB 619 unsigned long *sp = 0;
620 unsigned long *ep = 0;
622 unsigned long *sp = (
unsigned long *)MEM_START;
623 unsigned long *ep = (
unsigned long *)MEM_END;
626 unsigned long *sp = 0;
627 unsigned long *ep = 0;
631 sp = (
unsigned long *)(
long)
hstoi(argv[1]);
635 ep = (
unsigned long *)(
long)
hstoi(argv[2]);
642 if(memory_check(sp, ep, 0x00000000))
goto end;
643 if(memory_check(sp, ep, 0xffffffff))
goto end;
644 if(memory_check(sp, ep, 0xaaaaaaaa))
goto end;
645 if(memory_check(sp, ep, 0x55555555))
goto end;
646 if(memory_check_a(sp, ep))
goto end;
647 if(memory_check_ar(sp, ep))
goto end;
648 if(memory_check_aq(sp, ep))
goto end;
649 if(memory_check(sp, ep, 0x55aa55aa))
goto end;
650 if(memory_check(sp, ep, 0x00ff00ff))
goto end;
651 if(memory_check(sp, ep, 0x00000000))
goto end;
671 .manual_str =
"Memory operation commands",
672 .sublist = com_mem_list
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
static const struct st_shell_command com_mem_edit
メモリを編集する
static const struct st_shell_command com_mem_dump
メモリダンプ結果を表示する
static int com_memchk(int argc, uchar *argv[])
メモリチェック
int cgetcnw(unsigned char *rd)
標準入力より1文字を取得する(待ち無し)
static const struct st_shell_command com_mem_fill
任意のメモリ範囲にメモリを任意の値を書き込む
static const struct st_shell_command com_mem_check
メモリのチェックを行う
unsigned int hstou(uchar *str)
16進数文字列 unsigned int 変換
int cputc(unsigned char td)
標準出力より1文字を出力する
int tprintf(const char *fmt,...)
簡易printf
int hstoi(uchar *str)
16進数文字列 int 変換