Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2KB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include "common.h"
  6. /* Read specified number of bytes at specified memory address through a Forth
  7. * remote shell and dump it to stdout.
  8. */
  9. int main(int argc, char **argv)
  10. {
  11. if (argc != 4) {
  12. fprintf(stderr, "Usage: ./memdump device memptr bytecount\n");
  13. return 1;
  14. }
  15. unsigned int memptr = strtol(argv[2], NULL, 16);
  16. unsigned int bytecount = strtol(argv[3], NULL, 16);
  17. fprintf(stderr, "memptr: 0x%04x bytecount: 0x%04x.\n", memptr, bytecount);
  18. if (memptr+bytecount > 0xffff) {
  19. fprintf(stderr, "memptr+bytecount out of range.\n");
  20. return 1;
  21. }
  22. if (!bytecount) {
  23. // nothing to spit
  24. return 0;
  25. }
  26. int fd = ttyopen(argv[1]);
  27. if (fd < 0) {
  28. fprintf(stderr, "Could not open %s\n", argv[1]);
  29. return 1;
  30. }
  31. char s[0x30];
  32. sprintf(s, ": _ 0x%04x 0x%04x DO I @ .x LOOP ; _", memptr+bytecount, memptr);
  33. sendcmd(fd, s);
  34. for (int i=0; i<bytecount; i++) {
  35. mread(fd, s, 2); // read hex pair
  36. s[2] = 0; // null terminate
  37. unsigned char c = strtol(s, NULL, 16);
  38. putchar(c);
  39. }
  40. readprompt(fd);
  41. sendcmdp(fd, "FORGET _");
  42. return 0;
  43. }