📄 commands.c
字号:
default: return (-1); } if (!flags) flags = 3; if (flags & 2) flush_cache (ICACHE, NULL); if (flags & 1) flush_cache (DCACHE, NULL); return (0);}/* * Functions to store data in memory. Always use these functions * to store data that are potential instructions since these * functions will guarantee I/D cache - memory integrity. */voidstore_dword (adr, v) void *adr; int64_t v;{ *(int64_t *)adr = v; flush_cache (IADDR, adr);}voidstore_word (adr, v) void * adr; int32_t v;{ *(int32_t *)adr = v; flush_cache (IADDR, adr);}voidstore_half (adr, v) void *adr; int16_t v;{ *(int16_t *)adr = v; flush_cache (IADDR, adr);}voidstore_byte (adr, v) void *adr; int8_t v;{ *(int8_t *)adr = v; flush_cache (IADDR, adr);}#ifndef NO_SERIALconst Optdesc dump_opts[] ={ {"-B", "dump binary image"}, {"-h<port>", "send dump to host <port>"}, {0}};/** sdump(ac,av), the 'dump' command */intsdump (ac, av) int ac; char *av[];{ u_int32_t adr, siz, len, i, a; char *tmp; char *uleof, *ulcr, *hostport = 0, *eol; int fd, cs, v, binary = 0; struct termio tbuf; extern int optind; extern char *optarg; int c; optind = 0; while ((c = getopt (ac, av, "Bh:")) != EOF) switch (c) { case 'B': binary = 1; break; case 'h': hostport = optarg; break; default: return (-1); } if (optind + 2 > ac) return (-1); if (!get_rsa (&adr, av[optind++])) return (-1); if (!get_rsa (&siz, av[optind++])) return (-1); if (!hostport) hostport = (optind < ac) ? av[optind++] : getenv ("hostport"); if (optind < ac) return (-1); fd = open (hostport, 1); if (fd == -1) { printf ("can't open %s\n", hostport); return (1); } if (binary) { if (ioctl (fd, TCGETA, &tbuf) >= 0) { printf ("can't dump binary to tty\n"); return (1); } write (fd, (void *)adr, siz); } else { ioctl (fd, TCGETA, &tbuf); tbuf.c_iflag &= ~IXANY; tbuf.c_oflag &= ~ONLCR; ioctl (fd, TCSETAF, &tbuf); uleof = getenv ("uleof"); ulcr = getenv ("ulcr"); if (striequ (ulcr, "cr")) eol = "\r"; else if (striequ (ulcr, "lf")) eol = "\n"; else /* crlf */ eol = "\r\n"; while (siz > 0) { if (siz < 32) len = siz; else len = 32; cs = len + 5; for (i = 0; i < 4; i++) cs += (adr >> (i * 8)) & 0xff; sprintf (line, "S3%02X%08X", len + 5, adr); for (a = adr, tmp = line + 12, i = 0; i < len; a++, i++) { v = load_byte (a); cs += v; sprintf (tmp, "%02X", v & 0xff); tmp += 2; } sprintf (tmp, "%02X%s", (~cs) & 0xff, eol); tmp += 2 + strlen (eol); write (fd, line, tmp - line); adr += len; siz -= len; } sprintf (line, "S70500000000FA%s", eol); write (fd, line, strlen (line)); write (fd, uleof, strlen (uleof)); } close (fd); return (0);}#endif/** copy(ac,av), the 'copy' command */intcopy (ac, av) int ac; char *av[];{ u_int32_t from, to, n; if (!get_rsa (&from, av[1]) || !get_rsa (&to, av[2]) || !get_rsa (&n, av[3])) return (-1); if (to < from) while (n-- > 0) store_byte ((void *)(to++), load_byte (from++)); else for (from += n, to += n; n-- > 0;) store_byte ((void *)(--to), load_byte (--from)); return (0);}const Optdesc d_opts[] ={ {"-b", "display as bytes"}, {"-h", "display as half-words"}, {"-w", "display as words"},#ifdef HAVE_QUAD {"-d", "display as double-words"},#endif {"-s", "display a null terminated string"}, {"-r<reg>", "display as register"}, {0}};/** dump(ac,av), the 'd' command */intdump (ac, av) int ac; char *av[];{ void *adr; int32_t x; char *reg; int siz, ln, i; int datasz = -2; extern int optind; extern char *optarg; int c; static void *last_adr; optind = 0; while ((c = getopt (ac, av, "dwhbsr:")) != EOF) { if (datasz != -2) { printf ("multiple data types specified\n"); return (-1); } switch (c) {#ifdef HAVE_QUAD case 'd': datasz = 8; break;#endif case 'w': datasz = 4; break; case 'h': datasz = 2; break; case 'b': datasz = 1; break; case 's': datasz = 0; break; case 'r': reg = optarg; datasz = -1; break; default: return (-1); } } /* get <addr> */ if (optind >= ac || !get_rsa ((u_int32_t *)&adr, av[optind++])) return (-1); if( repeating_cmd ) adr = last_adr; /* get [<size>|<reg>] */ if (optind < ac) { if (get_rsa (&x, av[optind])) { /* size */ optind++; ln = x; siz = 0; } else if (md_getregaddr (0, av[optind])) { if (datasz != -2) { printf ("multiple data types specified\n"); return (-1); } reg = av[optind++]; datasz = -1; } else return (-1); } else { ln = siz = moresz; } if (optind != ac) return (-1); if (datasz == 0) { /* -s, print string */ strncpy (prnbuf, adr, 70); prnbuf[70] = '\0'; for (i = 0; prnbuf[i] != 0; i++) if (!isprint (prnbuf[i])) prnbuf[i] = '.'; printf ("%s\n", prnbuf); return (0); } ioctl (STDIN, CBREAK, NULL); if (datasz == -1) { /* -r<reg> print as register */ if (!md_disp_as_reg ((register_t *)adr, reg, &ln)) { printf ("%s: bad register name\n", reg); return (-1); } } else { if (datasz < 0) datasz = 1 << matchenv ("datasz"); while (1) { last_adr = adr; adr = dispmem (prnbuf, (void *)adr, datasz); if (more (prnbuf, &ln, siz)) break; } } return (0);}static void * dispmem (p, adr, siz) char *p; void *adr; int siz;{ int i; char v; char tmp[18]; union { double dummy; /* ensure 8-byte alignment */ unsigned char b[16]; } buf; void *w; w = adr; for (i = 0; i < 16; i++) { v = load_byte (w++); buf.b[i] = v; } sprintf (p, "%08x ", adr); for (i = 0; i < 16; i += siz) { if (i == 8) strccat (p, ' '); switch (siz) { case 1: sprintf (tmp, "%02x ", *(unsigned char *)&buf.b[i]); break; case 2: sprintf (tmp, "%04x ", *(unsigned short *)&buf.b[i]); break; case 4: sprintf (tmp, "%08x ", *(unsigned long *)&buf.b[i]); break;#ifdef HAVE_QUAD case 8: sprintf (tmp, "%016llx ", *(unsigned long long *)&buf.b[i]); break;#endif } strcat (p, tmp); } strcat (p, " "); for (i = 0; i < 16; i++) { v = buf.b[i]; strccat (p, isprint (v) ? v : '.'); } return (adr + 16);}/** fill(ac,av) the fill command */intfill (ac, av) int ac; char *av[];{ u_int32_t from, to, i, a, w; u_int8_t *p, *d; union { u_int32_t w; u_int16_t h; u_int8_t b[PATSZ]; } pat; int len; if (!get_rsa (&from, av[1]) || !get_rsa (&to, av[2])) return (-1); if (to < from) return (1); for (d = p = pat.b, i = 3; i < ac; i++) { if (strequ (av[i], "-s")) { if (++i >= ac) { printf ("bad arg count\n"); return (-1); } else { char *s; for (s = av[i]; *s; s++) { if (d >= &pat.b[PATSZ]) { printf ("pattern too long\n"); return (-1); } *d++ = *s; } } } else { if (!get_rsa (&a, av[i])) return (-1); if (d >= &pat.b[PATSZ]) { printf ("pattern too long\n"); return (-1); } *d++ = a; } } len = d - p; if ((len == 1 || len == 2 || len == 4) && (from & 3) == 0 && (to & 3) == 3) { /* special case using word writes */ switch (len) { case 1: w = pat.b[0]; w |= (w << 8); w |= (w << 16); break; case 2: w = pat.h; w |= (w << 16); break; case 4: w = pat.w; break; } for (; from <= to; from += sizeof (u_int32_t)) *(u_int32_t *)from = w; } else { /* all other cases: byte by byte */ for (; from <= to; from += sizeof (u_int8_t)) { *(u_int8_t *)from = *p; if (++p >= d) p = pat.b; } } flush_cache (ICACHE, 0); return (0);}intreboot_cmd (ac, av) int ac; char *av[];{ printf ("Rebooting...\n"); delay (1000000); tgt_reboot(); return(0); /* Shut up gcc */}#ifdef SROMconst Optdesc srom_opts[] ={ {"-n", "don't execute softROM code"}, {0}};sbd_srom (ac, av) int ac; char *av[];{ uword from, to, n; int dogo, docopy; extern int optind; int c; dogo = 1; docopy = 0; optind = 0; while ((c = getopt (ac, av, "n")) != EOF) { switch (c) { case 'n': dogo = 0; break; default: return (-1); } } from = to = 0; if (optind+3 <= ac) { if (!get_rsa (&from, av[optind++]) || !get_rsa (&to, av[optind++]) || !get_rsa (&n, av[optind++])) return (-1); } if (optind != ac) return (-1); /* copy softrom code */ sbd_softromcopy (from, to, n); if (dogo) sbd_softromgo (); return (0);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -