2019-12-09 14:31:15 +11:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-12-10 14:01:22 +11:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-04-27 23:24:40 +10:00
|
|
|
/* Read specified number of bytes at specified memory address through a Forth
|
2019-12-09 14:31:15 +11:00
|
|
|
* remote shell and dump it to stdout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc != 4) {
|
|
|
|
fprintf(stderr, "Usage: ./memdump device memptr bytecount\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
unsigned int memptr = strtol(argv[2], NULL, 16);
|
|
|
|
unsigned int bytecount = strtol(argv[3], NULL, 16);
|
|
|
|
fprintf(stderr, "memptr: 0x%04x bytecount: 0x%04x.\n", memptr, bytecount);
|
|
|
|
if (memptr+bytecount > 0xffff) {
|
|
|
|
fprintf(stderr, "memptr+bytecount out of range.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (!bytecount) {
|
|
|
|
// nothing to spit
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = open(argv[1], O_RDWR|O_NOCTTY);
|
2019-12-13 04:04:56 +11:00
|
|
|
char s[0x30];
|
2020-04-27 23:24:40 +10:00
|
|
|
sprintf(s, ": _ 0x%04x 0x%04x DO I @ .x LOOP ; _", memptr+bytecount, memptr);
|
2019-12-09 14:31:15 +11:00
|
|
|
sendcmd(fd, s);
|
|
|
|
|
|
|
|
for (int i=0; i<bytecount; i++) {
|
2019-12-10 13:17:45 +11:00
|
|
|
read(fd, s, 2); // read hex pair
|
|
|
|
s[2] = 0; // null terminate
|
|
|
|
unsigned char c = strtol(s, NULL, 16);
|
2019-12-09 14:31:15 +11:00
|
|
|
putchar(c);
|
|
|
|
}
|
2019-12-13 04:04:56 +11:00
|
|
|
read(fd, s, 2); // read prompt
|
2020-04-27 23:24:40 +10:00
|
|
|
sendcmdp(fd, "FORGET _");
|
2019-12-09 14:31:15 +11:00
|
|
|
return 0;
|
|
|
|
}
|