1985-01-07 13:08:48 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
*
|
|
|
|
* This product is part of the Amsterdam Compiler Kit.
|
|
|
|
*
|
|
|
|
* Permission to use, sell, duplicate or disclose this software must be
|
|
|
|
* obtained in writing. Requests for such permissions may be sent to
|
|
|
|
*
|
|
|
|
* Dr. Andrew S. Tanenbaum
|
|
|
|
* Wiskundig Seminarium
|
|
|
|
* Vrije Universiteit
|
|
|
|
* Postbox 7161
|
|
|
|
* 1007 MC Amsterdam
|
|
|
|
* The Netherlands
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
1987-02-26 19:54:57 +00:00
|
|
|
#include <out.h>
|
1985-01-07 13:08:48 +00:00
|
|
|
|
|
|
|
#define DATTYPE 0
|
|
|
|
#define EOFTYPE 1
|
|
|
|
#define SEGTYPE 2
|
|
|
|
#define PCTYPE 3
|
|
|
|
|
|
|
|
#define MAXBYTE 0x18
|
|
|
|
|
|
|
|
int check;
|
|
|
|
int records;
|
|
|
|
int echo;
|
|
|
|
int bytecount;
|
|
|
|
int ttyfd;
|
|
|
|
|
|
|
|
char *progname;
|
|
|
|
|
|
|
|
char hex[] = "0123456789ABCDEF";
|
|
|
|
|
1987-02-26 19:54:57 +00:00
|
|
|
struct outhead ohead;
|
|
|
|
struct outsect sect[MAXSECT];
|
|
|
|
|
1985-01-07 13:08:48 +00:00
|
|
|
main(argc,argv) char **argv; {
|
1987-02-26 19:54:57 +00:00
|
|
|
int i,nd,pc,first;
|
1985-01-07 13:08:48 +00:00
|
|
|
register char *s;
|
|
|
|
|
1987-02-26 19:54:57 +00:00
|
|
|
|
1985-01-07 13:08:48 +00:00
|
|
|
progname = argv[0];
|
|
|
|
if (argc > 3)
|
|
|
|
fatal("usage: %s [object [tty]]\n",argv[0]);
|
|
|
|
s = "a.out";
|
|
|
|
if (argc >= 2)
|
|
|
|
s = argv[1];
|
1987-02-26 19:54:57 +00:00
|
|
|
if (! rd_open(s)) {
|
|
|
|
fprintf(stderr,"%s: can't open %s\n",progname,s);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
rd_ohead(&ohead);
|
|
|
|
if (ohead.oh_flags & HF_LINK) {
|
|
|
|
fprintf(stderr,"%s: %s contains unresolved references\n",progname,s);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
rd_sect(sect, ohead.oh_nsect);
|
1985-01-07 13:08:48 +00:00
|
|
|
ttyfd = 1;
|
1987-02-26 19:54:57 +00:00
|
|
|
first = 1;
|
|
|
|
for (i = 0; i < ohead.oh_nsect; i++) {
|
|
|
|
rd_outsect(i);
|
|
|
|
pc = sect[i].os_base;
|
|
|
|
while (sect[i].os_size) {
|
|
|
|
unsigned int sz = 8096, fl;
|
|
|
|
extern char *calloc();
|
|
|
|
register char *buf;
|
|
|
|
char *pbuf;
|
|
|
|
|
|
|
|
if (sz > sect[i].os_size) sz = sect[i].os_size;
|
|
|
|
sect[i].os_size -= sz;
|
|
|
|
pbuf = buf = calloc(sz, 1);
|
|
|
|
if (fl = sect[i].os_flen) {
|
|
|
|
if (fl > sz) fl = sz;
|
|
|
|
sect[i].os_flen -= fl;
|
|
|
|
|
|
|
|
rd_emit(buf, (long) fl);
|
|
|
|
}
|
|
|
|
while (sz >= MAXBYTE) {
|
|
|
|
data(MAXBYTE, (int) pc, buf);
|
|
|
|
sz -= MAXBYTE;
|
|
|
|
buf += MAXBYTE;
|
|
|
|
pc += MAXBYTE;
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
if (sz > 0) {
|
|
|
|
data(sz, (int) pc, buf);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
free(pbuf);
|
1985-01-07 13:08:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (first == 0)
|
|
|
|
eof();
|
|
|
|
if (echo)
|
|
|
|
for (;;)
|
|
|
|
reply();
|
|
|
|
}
|
|
|
|
|
1987-02-26 19:54:57 +00:00
|
|
|
data(nd,pc, buf)
|
|
|
|
register char *buf;
|
|
|
|
{
|
1985-01-07 13:08:48 +00:00
|
|
|
|
|
|
|
newline(nd,pc,DATTYPE);
|
|
|
|
do
|
1987-02-26 19:54:57 +00:00
|
|
|
byte(*buf++);
|
1985-01-07 13:08:48 +00:00
|
|
|
while (--nd);
|
|
|
|
endline();
|
|
|
|
}
|
|
|
|
|
|
|
|
eof() {
|
|
|
|
|
|
|
|
newline(0,records,EOFTYPE);
|
|
|
|
endline();
|
|
|
|
}
|
|
|
|
|
|
|
|
newline(n,pc,typ) {
|
|
|
|
|
|
|
|
records++;
|
|
|
|
put(';');
|
|
|
|
byte(n);
|
|
|
|
check = 0;
|
|
|
|
bytecount = n+4;
|
|
|
|
word(pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
endline() {
|
|
|
|
|
|
|
|
word(check);
|
|
|
|
put('\r');
|
|
|
|
put('\n');
|
|
|
|
assert(bytecount == 0);
|
|
|
|
put(0);
|
|
|
|
put(0);
|
|
|
|
put(0);
|
|
|
|
put(0);
|
|
|
|
put(0);
|
|
|
|
put(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
word(w) {
|
|
|
|
|
|
|
|
byte(w>>8);
|
|
|
|
byte(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte(b) {
|
|
|
|
|
|
|
|
b &= 0377;
|
|
|
|
check += b;
|
|
|
|
--bytecount;
|
|
|
|
put(hex[(b>>4) & 017]);
|
|
|
|
put(hex[b & 017]);
|
|
|
|
}
|
|
|
|
|
1987-02-26 19:54:57 +00:00
|
|
|
put(c)
|
|
|
|
char c;
|
|
|
|
{
|
1985-01-07 13:08:48 +00:00
|
|
|
|
|
|
|
write(ttyfd,&c,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
reply() {
|
|
|
|
register i;
|
1987-02-26 19:54:57 +00:00
|
|
|
char c;
|
1985-01-07 13:08:48 +00:00
|
|
|
|
|
|
|
if (echo == 0)
|
|
|
|
return;
|
|
|
|
i = read(ttyfd,&c,1);
|
|
|
|
assert(i > 0);
|
|
|
|
write(1,&c,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fatal(s,a) {
|
|
|
|
|
|
|
|
fprintf(stderr,"%s: ",progname);
|
|
|
|
fprintf(stderr,s,a);
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
1987-02-26 19:54:57 +00:00
|
|
|
|
|
|
|
rd_fatal() { fatal("read error"); }
|