Initial revision

This commit is contained in:
keie 1985-04-12 14:55:00 +00:00
parent fb6d291d38
commit dfcfa9883b
4 changed files with 603 additions and 0 deletions

24
util/amisc/Makefile Normal file
View file

@ -0,0 +1,24 @@
# @(#)Makefile 1.1
EM = ../..
h = $(EM)/h
CFLAGS = -O -I$h
ALL = anm asize astrip
OFILES = anm.o asize.o astrip.o
CFILES = anm.c asize.c astrip.c
all: $(ALL)
anm: anm.c
$(CC) $(CFLAGS) anm.c -o anm
asize: asize.c
$(CC) $(CFLAGS) asize.c -o asize
astrip: astrip.c
$(CC) $(CFLAGS) astrip.c -o astrip
clean:
rm -f $(ALL) $(OFILES)
print: $(CFILES)
pr -n Makefile $(CFILES) | lpr

297
util/amisc/anm.c Normal file
View file

@ -0,0 +1,297 @@
/* @(#)anm.c 1.4 */
/*
** print symbol tables for
** ACK object files
**
** anm [-gopruns] [name ...]
*/
#define ushort unsigned short
#include "out.h"
#include <stdio.h>
#include <ctype.h>
int numsort_flg;
int sectsort_flg;
int undef_flg;
int revsort_flg = 1;
int globl_flg;
int nosort_flg;
int arch_flg;
int prep_flg;
struct outhead hbuf;
struct outsect sbuf;
FILE *fi;
long off;
char *malloc();
char *realloc();
long s_base[S_MAX]; /* for specially encoded bases */
main(argc, argv)
char **argv;
{
int narg;
int compare();
if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
argv++;
while (*++*argv) switch (**argv) {
case 'n': /* sort numerically */
numsort_flg++;
continue;
case 's': /* sort in section order */
sectsort_flg++;
continue;
case 'g': /* globl symbols only */
globl_flg++;
continue;
case 'u': /* undefined symbols only */
undef_flg++;
continue;
case 'r': /* sort in reverse order */
revsort_flg = -1;
continue;
case 'p': /* don't sort -- symbol table order */
nosort_flg++;
continue;
case 'o': /* prepend a name to each line */
prep_flg++;
continue;
default: /* oops */
fprintf(stderr, "anm: invalid argument -%c\n", *argv[0]);
exit(1);
}
argc--;
}
if (argc == 0) {
argc = 1;
argv[1] = "a.out";
}
narg = argc;
while(argc--) {
struct outname *nbufp = NULL;
struct outname nbuf;
char *cbufp;
long fi_to_co;
long n;
unsigned readcount;
int i,j;
fi = fopen(*++argv,"r");
if (fi == NULL) {
fprintf(stderr, "anm: cannot open %s\n", *argv);
continue;
}
getofmt((char *)&hbuf, SF_HEAD, fi);
if (BADMAGIC(hbuf)) {
fprintf(stderr, "anm: %s-- bad format\n", *argv);
fclose(fi);
continue;
}
if (narg > 1)
printf("\n%s:\n", *argv);
n = hbuf.oh_nname;
if (n == 0) {
fprintf(stderr, "anm: %s-- no name list\n", *argv);
fclose(fi);
continue;
}
if (hbuf.oh_nchar == 0) {
fprintf(stderr, "anm: %s-- no names\n", *argv);
fclose(fi);
continue;
}
if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) {
fprintf(stderr, "anm: string area too big in %s\n", *argv);
exit(2);
}
/* store special section bases */
if (hbuf.oh_flags & HF_8086) {
for (i=0; i<hbuf.oh_nsect; i++) {
getofmt((char *)&sbuf, SF_SECT, fi);
s_base[i+S_MIN] =
(sbuf.os_base>>12) & 03777760;
}
}
if ((cbufp = (char *)malloc(readcount)) == NULL) {
fprintf(stderr, "anm: out of memory on %s\n", *argv);
exit(2);
}
fseek(fi, OFF_CHAR(hbuf), 0);
if (fread(cbufp, 1, readcount, fi) == 0) {
fprintf(stderr, "anm: read error on %s\n", *argv);
exit(2);
}
fi_to_co = cbufp - OFF_CHAR(hbuf);
fseek(fi, OFF_NAME(hbuf), 0);
i = 0;
while (--n >= 0) {
getofmt((char *)&nbuf, SF_NAME, fi);
if (nbuf.on_foff == 0)
continue; /* skip entries without names */
if (globl_flg && (nbuf.on_type&S_EXT)==0)
continue;
if (undef_flg
&&
((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0))
continue;
nbuf.on_mptr = nbuf.on_foff + fi_to_co;
/* adjust value for specially encoded bases */
if (hbuf.oh_flags & HF_8086) {
if (((nbuf.on_type&S_ETC) == 0) ||
((nbuf.on_type&S_ETC) == S_SCT)) {
j = nbuf.on_type&S_TYP;
if ((j>=S_MIN) && (j<=S_MAX))
nbuf.on_valu += s_base[j];
}
}
if (nbufp == NULL)
nbufp = (struct outname *)malloc(sizeof(struct outname));
else
nbufp = (struct outname *)realloc(nbufp, (i+1)*sizeof(struct outname));
if (nbufp == NULL) {
fprintf(stderr, "anm: out of memory on %s\n", *argv);
exit(2);
}
nbufp[i++] = nbuf;
}
if (nosort_flg==0)
qsort(nbufp, i, sizeof(struct outname), compare);
for (n=0; n<i; n++) {
char cs1[4];
char cs2[4];
if (prep_flg)
printf("%s:", *argv);
switch(nbufp[n].on_type&S_ETC) {
case S_SCT:
sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
sprintf(cs2, " S");
break;
case S_FIL:
sprintf(cs1, " -");
sprintf(cs2, " F");
break;
case S_MOD:
sprintf(cs1, " -");
sprintf(cs2, " M");
break;
case 0:
if (nbufp[n].on_type&S_EXT)
sprintf(cs2, " E");
else
sprintf(cs2, " -");
switch(nbufp[n].on_type&S_TYP) {
case S_UND:
sprintf(cs1, " U");
break;
case S_ABS:
sprintf(cs1, " A");
break;
default:
sprintf(cs1, "%2d", (nbufp[n].on_type&S_TYP) - S_MIN);
}
break;
default:
continue;
}
printf("%8lx %s %s %s\n",nbufp[n].on_valu,cs1,cs2,nbufp[n].on_mptr);
}
if (nbufp)
free((char *)nbufp);
if (cbufp)
free((char *)cbufp);
fclose(fi);
}
exit(0);
}
compare(p1, p2)
struct outname *p1, *p2;
{
int i;
if (sectsort_flg) {
if ((p1->on_type&S_TYP) > (p2->on_type&S_TYP))
return(revsort_flg);
if ((p1->on_type&S_TYP) < (p2->on_type&S_TYP))
return(-revsort_flg);
}
if (numsort_flg) {
if (p1->on_valu > p2->on_valu)
return(revsort_flg);
if (p1->on_valu < p2->on_valu)
return(-revsort_flg);
}
i = strcmp(p1->on_mptr, p2->on_mptr);
if (i > 0)
return(revsort_flg);
if (i < 0)
return(-revsort_flg);
return(0);
}
getofmt(p, s, f)
register char *p;
register char *s;
register FILE *f;
{
register i;
register long l;
for (;;) {
switch (*s++) {
/* case '0': p++; continue; */
case '1':
*p++ = getc(f);
continue;
case '2':
i = getc(f);
i |= (getc(f) << 8);
*((short *)p)++ = i;
continue;
case '4':
l = (long)getc(f);
l |= ((long)getc(f) << 8);
l |= ((long)getc(f) << 16);
l |= ((long)getc(f) << 24);
*((long *)p)++ = l;
continue;
default:
case '\0':
break;
}
break;
}
}

93
util/amisc/asize.c Normal file
View file

@ -0,0 +1,93 @@
/* @(#)asize.c 1.2 */
#define ushort unsigned short
#include <stdio.h>
#include "out.h"
/*
asize -- determine object size
*/
main(argc, argv)
char **argv;
{
struct outhead buf;
struct outsect sbuf;
ushort nrsect;
long sum;
int gorp;
FILE *f;
if (--argc == 0) {
argc = 1;
argv[1] = "a.out";
}
gorp = argc;
while(argc--) {
if ((f = fopen(*++argv, "r"))==NULL) {
fprintf(stderr, "asize: cannot open %s\n", *argv);
continue;
}
getofmt ((char *)&buf, SF_HEAD , f);
if(BADMAGIC(buf)) {
fprintf(stderr, "asize: %s-- bad format\n", *argv);
fclose(f);
continue;
}
nrsect = buf.oh_nsect;
if (nrsect == 0) {
fprintf(stderr, "asize: %s-- no sections\n", *argv);
fclose(f);
continue;
}
if (gorp > 1)
printf("%s: ", *argv);
sum = 0;
while (nrsect-- > 0) {
getofmt ((char *)&sbuf, SF_SECT , f);
printf("%ld", sbuf.os_size);
sum += sbuf.os_size;
if (nrsect > 0)
putchar('+');
}
printf(" = %ld = 0x%lx\n", sum, sum);
fclose(f);
}
}
getofmt(p, s, f)
register char *p;
register char *s;
register FILE *f;
{
register i;
register long l;
for (;;) {
switch (*s++) {
/* case '0': p++; continue; */
case '1':
*p++ = getc(f);
continue;
case '2':
i = getc(f);
i |= (getc(f) << 8);
*((short *)p)++ = i;
continue;
case '4':
l = (long)getc(f);
l |= (long)(getc(f) << 8);
l |= ((long)getc(f) << 16);
l |= ((long)getc(f) << 24);
*((long *)p)++ = l;
continue;
default:
case '\0':
break;
}
break;
}
}

189
util/amisc/astrip.c Normal file
View file

@ -0,0 +1,189 @@
/* @(#)astrip.c 1.1 */
#define ushort unsigned short
#include "out.h"
#include <signal.h>
#include <stdio.h>
/*
astrip -- remove symbols and relocation bits
*/
char *tname;
char *mktemp();
FILE *fopen();
FILE *tf;
struct outhead buf;
main(argc, argv)
char **argv;
{
int status;
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
tname = mktemp("/tmp/sXXXXX");
while(--argc) {
if ((status = strip(argv[argc])) > 1)
break;
}
unlink(tname);
exit(status);
}
strip(name)
char *name;
{
long size;
FILE *f;
if ((f = fopen(name,"r")) == NULL) {
fprintf(stderr, "astrip: cannot open %s\n", name);
return(1);
}
getofmt ((char *)&buf, SF_HEAD , f);
if(BADMAGIC(buf)) {
fprintf(stderr, "astrip: %s-- bad format\n", name);
fclose(f);
return(1);
}
size = OFF_RELO(buf) - SZ_HEAD;
buf.oh_flags &= ~HF_LINK;
buf.oh_nrelo = 0;
buf.oh_nname = 0;
buf.oh_nchar = 0;
if ((tf = fopen(tname,"w")) == NULL) {
fprintf(stderr, "astrip: cannot create temp file %s\n", tname);
fclose(f);
return(2);
}
fseek(tf, (long)0, 0);
putofmt((char *)&buf,SF_HEAD,tf,tname);
if(copy(name, tname, f, tf, size)) {
fclose(f);
fclose(tf);
return(1);
}
fclose(f);
fclose(tf);
size += SZ_HEAD;
if ((f = fopen(name,"w")) == NULL) {
fprintf(stderr, "astrip: cannot write %s\n", name);
return(1);
}
if ((tf = fopen(tname,"r")) == NULL) {
fprintf(stderr, "astrip: cannot read temp file %s\n", tname);
fclose(f);
return(2);
}
fseek(tf, (long)0, 0);
if(copy(tname, name, tf, f, size)) {
fclose(f);
fclose(tf);
return(2);
}
fclose(f);
fclose(tf);
return(0);
}
copy(fnam, tnam, fr, to, size)
char *fnam;
char *tnam;
long size;
FILE *fr,*to;
{
register s, n;
char lbuf[512];
while(size != (long)0) {
s = 512;
if(size < 512)
s = (int) size;
n = fread(lbuf,1,s,fr);
if(n != s) {
fprintf(stderr, "astrip: unexpected eof on %s\n", fnam);
return(1);
}
n = fwrite(lbuf,1,s,to);
if(n != s) {
fprintf(stderr, "astrip: write error on %s\n", tnam);
return(1);
}
size -= (long)s;
}
return(0);
}
getofmt(p, s, f)
register char *p;
register char *s;
register FILE *f;
{
register i;
register long l;
for (;;) {
switch (*s++) {
/* case '0': p++; continue; */
case '1':
*p++ = getc(f);
continue;
case '2':
i = getc(f);
i |= (getc(f) << 8);
*((short *)p)++ = i;
continue;
case '4':
l = (long)getc(f);
l |= (long)(getc(f) << 8);
l |= ((long)getc(f) << 16);
l |= ((long)getc(f) << 24);
*((long *)p)++ = l;
continue;
default:
case '\0':
break;
}
break;
}
}
putofmt(p, s, f, fnam)
register char *p;
register char *s;
register FILE *f;
char *fnam;
{
register i,j;
register long l;
while (j = *s++) {
switch (j -= '0') {
/* case 0: p++; break; */
case 1:
i = *p++; putc(i,f);
break;
case 2:
i = *((short *)p)++; putc(i,f);
i>>=8; putc(i,f);
break;
case 4:
l = *((long *)p)++;
putc(l,f);
l >>=8; putc(l,f);
l >>=8; putc(l,f);
l >>=8; putc(l,f);
break;
default:
break;
}
if (ferror(f)) fprintf(stderr, "astrip: write error on %s\n", fnam);
}
}