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.

45 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 = open(argv[1], O_RDWR|O_NOCTTY);
  27. char s[0x30];
  28. sprintf(s, ": _ 0x%04x 0x%04x DO I @ .x LOOP ; _", memptr+bytecount, memptr);
  29. sendcmd(fd, s);
  30. for (int i=0; i<bytecount; i++) {
  31. read(fd, s, 2); // read hex pair
  32. s[2] = 0; // null terminate
  33. unsigned char c = strtol(s, NULL, 16);
  34. putchar(c);
  35. }
  36. read(fd, s, 2); // read prompt
  37. sendcmdp(fd, "FORGET _");
  38. return 0;
  39. }