Skip to content

Commit

Permalink
[cmds] Add 'disasm -' option to read from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Nov 28, 2024
1 parent cb18136 commit eb20df6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions elkscmd/debug/dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

char f_ksyms;
char f_syms;
char f_fdinput;
unsigned short textseg, ftextseg, dataseg;

char * noinstrument getsymbol(int seg, int offset)
Expand Down Expand Up @@ -134,9 +135,26 @@ int disasm_file(char *filename)
return 0;
}

int disasm_fd(int fd)
{
int ip = 0;
int nextip;

infp = fdopen(fd, "r");
if (!infp)
return 1;

while (!feof(infp)) {
if (!f_asmout) printf("%04hx ", ip);
nextip = disasm(textseg, ip, nextbyte_file, dataseg);
ip = nextip;
}
return 0;
}

void usage(void)
{
printf("Usage: disasm [-k] [-a] [-s symfile] [[seg:off[#size] | filename]\n");
printf("Usage: disasm [-k][-a][-s symfile] [[seg:off[#size] | filename | -]\n");
exit(1);
}

Expand Down Expand Up @@ -166,7 +184,9 @@ int main(int ac, char **av)
}
ac -= optind;
av += optind;
if (ac < 1)
if (ac == 1 && **av == '-')
f_fdinput = 1;
else if (ac < 1)
usage();

if (symfile && !sym_read_symbols(symfile)) {
Expand All @@ -188,6 +208,8 @@ int main(int ac, char **av)
}
#endif

if (f_fdinput)
return disasm_fd(0);
if (strchr(*av, ':')) {
sscanf(*av, "%lx:%lx#%ld", &seg, &off, &count);

Expand Down

0 comments on commit eb20df6

Please sign in to comment.