ack/mach/m68k2/dl/dl.c

127 lines
2.1 KiB
C
Raw Permalink Normal View History

1987-03-09 19:15:41 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1994-06-24 14:02:31 +00:00
static char rcsid[] = "$Id$";
1984-07-19 11:50:28 +00:00
#define MAXBYTE 24
#include <stdio.h>
1987-02-26 19:54:57 +00:00
#include <out.h>
1984-07-19 11:50:28 +00:00
char hex[] = "0123456789ABCDEF";
FILE *fp, *fopen();
char **s;
int bytes, bytcnt, checksum;
long pc;
1987-02-26 19:54:57 +00:00
struct outhead ohead;
struct outsect sect[MAXSECT];
1984-07-19 11:50:28 +00:00
main (argc,argv)
int argc;
char *argv[];
{
if (argc != 2) fatal ("usage: %s filename\n",argv[0]);
1987-02-26 19:54:57 +00:00
if (! rd_open (*++argv))
1984-07-19 11:50:28 +00:00
fatal ("can't open %s\n",*argv);
else {
s = argv;
convert ();
}
}
convert ()
{
1987-02-26 19:54:57 +00:00
int i;
rd_ohead(&ohead);
if (ohead.oh_flags & HF_LINK) {
fatal("%s contains unresolved references\n",s);
}
rd_sect(sect, ohead.oh_nsect);
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 > 0) {
int p = bytcnt = sz < MAXBYTE ? sz : MAXBYTE;
checksum = 0;
sz -= p;
if (pc > 0xffffL)
S2record (buf);
else S1record (buf);
buf += p;
1984-07-19 11:50:28 +00:00
}
1987-02-26 19:54:57 +00:00
free(pbuf);
1984-07-19 11:50:28 +00:00
}
1987-02-26 19:54:57 +00:00
}
1984-07-19 11:50:28 +00:00
printf ("S9030000FC\n");
}
1987-02-26 19:54:57 +00:00
S2record (buf)
char *buf;
1984-07-19 11:50:28 +00:00
{
printf ("S2");
bytcnt += 4;
outbyte (bytcnt);
1987-02-26 19:54:57 +00:00
outbyte ((int) (pc >> 16));
outbyte ((int) (pc >> 8));
outbyte ((int) pc);
1987-07-30 16:04:29 +00:00
record (buf);
1984-07-19 11:50:28 +00:00
}
1987-02-26 19:54:57 +00:00
S1record (buf)
char *buf;
1984-07-19 11:50:28 +00:00
{
printf ("S1");
bytcnt += 3;
outbyte (bytcnt);
1987-02-26 19:54:57 +00:00
outbyte ((int) (pc >> 8));
outbyte((int) pc);
record (buf);
1984-07-19 11:50:28 +00:00
}
1987-02-26 19:54:57 +00:00
record (buf)
register char *buf;
1984-07-19 11:50:28 +00:00
{
while (bytcnt != 0)
{
1987-02-26 19:54:57 +00:00
outbyte (*buf++);
1984-07-19 11:50:28 +00:00
pc ++;
}
outbyte (~checksum);
putchar ('\n');
putchar (0);
putchar (0);
}
outbyte (b)
int b;
{
checksum = (checksum + b) & 0377;
putchar (hex[(b>>4) & 017]);
putchar (hex[b & 017]);
-- bytcnt;
}
1987-02-26 19:54:57 +00:00
rd_fatal() { fatal("Read error\n"); }
1984-07-19 11:50:28 +00:00
fatal (s,a)
{
printf (s,a);
exit (-1);
}