Albert Koelmans newest version

This commit is contained in:
ceriel 1990-11-13 11:46:48 +00:00
parent 03a25ece8a
commit ff117d9f0b
2 changed files with 234 additions and 85 deletions

View file

@ -4,13 +4,13 @@ OBJLIB=$(EMHOME)/modules/lib/libobject.a
head: cv head: cv
cv: cv.c cv: cv.c
$(CC) -I$(EMHOME)/h -o cv cv.c $(OBJLIB) $(CC) $(CFLAGS) $(LDFLAGS) -I$(EMHOME)/h -o cv cv.c $(OBJLIB)
install: head install: head
@echo Nothing is installed ../../install cv
cmp: head cmp: head
@echo Nothing is compared ../../compare cv
clean: clean:
rm -f *.o rm -f *.o

View file

@ -1,96 +1,245 @@
/*
* Conversion from ack a.out to Arthur output format.
* All this really does is to output the sections, text first,
* with no header or symbol table information.
*
* Mostly pinched from the code for the m68k2 cv.
* V1.0, 08-Mar-89 AJM
*/
#include <stdio.h> #include <stdio.h>
#include <out.h> #include "out.h"
#include "arm.h" #include "arm.h"
struct outhead ohead;
struct outsect sect[NSECT]; #define ASSERT(x) switch (2) { case 0: case (x): ; }
struct armhead ahead;
struct chunkhead chead; /*
struct areadec area[NSECT]; * Header and section table of ack object file.
int fd; */
struct outhead outhead;
struct outsect outsect[S_MAX];
char *stringarea ;
char *ofile;
int ofile_created;
char *program ;
char flag ;
#define readf(a, b, c) fread((a), (b), (int)(c), input)
#define writef(a, b, c) fwrite((a), (b), (int)(c), output)
/* Output file definitions and such */
#define HDR_LENGTH 32
char hdr[HDR_LENGTH] ;
#define TEXT 0
#define ROM 1
#define DATA 2
#define BSS 3
#define LSECT BSS+1
#define NSECT LSECT+1
main (argc,argv) #define N_EXT 040
int argc; #define N_UNDEF 00
char *argv[]; #define N_ABS 01
#define N_TEXT 02
#define N_DATA 03
#define N_BSS 04
#define N_FN 037
FILE *input;
FILE *output;
long align(a,b)
long a,b;
{ {
if (argc != 3) fatal ("usage: dl ackobj armobj\n"); a += b - 1;
if (! rd_open (*++argv)) return a - a % b;
fatal ("can't open \n"); }
if ((fd = open(*++argv, 1)) <0)
fatal ("can't open \n"); int
else { follows(pa, pb)
convert (); register struct outsect *pa, *pb;
} {
/* return 1 if pa follows pb */
return pa->os_base == align(pb->os_base+pb->os_size, pa->os_lign);
} }
convert () main(argc, argv)
int argc;
char *argv[];
{ {
int i,areasize=0; register int nsect;
char buf[4]; long magic ;
int cnt; long textsize ;
long datasize ;
long ss;
rd_ohead(&ohead); ASSERT(sizeof(struct outhead) == SZ_HEAD);
if (ohead.oh_flags & HF_LINK) { ASSERT(sizeof(struct outsect) == SZ_SECT);
fatal("unresolved references\n");
} input = stdin; output = stdout;
ahead.chunkfileid = 0xC3CBC6C5; program= argv[0] ;
ahead.maxchunks = MAXCHUNK; if ( argc>1 && argv[1][0]=='-' ) {
ahead.numchunks = MAXCHUNK; flag=argv[1][1] ;
strncpy(ahead.entries[0].chunkid , "OBJ_HEAD", 8); argc-- ; argv++ ;
strncpy(ahead.entries[1].chunkid , "OBJ_AREA", 8); }
strncpy(ahead.entries[2].chunkid , "OBJ_IDFN", 8); switch (argc) {
strncpy(ahead.entries[3].chunkid , "OBJ_SYMT", 8); case 1: break;
strncpy(ahead.entries[4].chunkid , "OBJ_STRT", 8); case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0)
ahead.entries[0].offset = sizeof(struct armhead); fatal("Can't write %s.\n", argv[2]);
ahead.entries[0].size = sizeof(struct chunkhead) + ohead.oh_nsect * ofile = argv[2];
sizeof(struct areadec); ofile_created = 1;
ahead.entries[1].offset = ahead.entries[0].offset+ahead.entries[0].size; /* FALLTHROUGH */
chead.objtype = 0xC5E2D080; case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0)
chead.versionid = 110; fatal("Can't read %s.\n", argv[1]);
chead.narea = ohead.oh_nsect; break;
chead.nsymb = ohead.oh_nname; default:fatal("Usage: %s <ack object> <riscos object>.\n", argv[0]);
chead.entrya = 0; }
chead.entryo = 0; if ( !rhead(input,&outhead) )
lseek(fd, ahead.entries[1].offset, 0); fatal("Reading header failed.\n");
rd_sect(sect, ohead.oh_nsect); if (BADMAGIC(outhead))
for (i = 0; i < ohead.oh_nsect; i++) { fatal("Not an ack object file.\n");
area[i].name=0; if (outhead.oh_nrelo > 0)
area[i].atal=2|1<<7|(i=0?(1<<8):0); fprintf(stderr, "Warning: relocation information present.\n");
area[i].size=sect[i].os_size; if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT )
area[i].nrel=0; fatal("Input file must have %d sections, not %ld\n",
area[i].base=sect[i].os_base; NSECT,outhead.oh_nsect) ;
rd_outsect(i); for ( nsect=0 ; nsect<outhead.oh_nsect ; nsect++ )
cnt = sect[i].os_flen; if ( !rsect(input,&outsect[nsect]) )
areasize += cnt; fatal("Reading section table failed.\n");
if (cnt!=sect[i].os_size)
area[i].atal |= 1<<11; /* A few checks */
if (cnt & 3)
fatal("alignment error\n"); if ( outsect[TEXT].os_base != 0x8000 )
while (cnt){ fatal("text must start at 0x8000 not at 0x%lx\n",
rd_emit(buf, (long)4); outsect[TEXT].os_base) ;
write(fd, buf, 4);
cnt -= 4; if ( outsect[BSS].os_flen != 0 )
} fatal("bss space contains initialized data\n") ;
}
ahead.entries[1].size = areasize; if ( ! follows(&outsect[BSS], &outsect[DATA]))
lseek(fd, 0, 0); fatal("bss segment must follow data segment\n") ;
write(fd, &ahead, sizeof(struct armhead));
write(fd, &chead, sizeof(struct chunkhead)); if ( ! follows(& outsect[ROM], &outsect[TEXT]))
for(i=1; i<NSECT; i++) fatal("rom segment must follow text\n") ;
write(fd, &area[i], sizeof(struct areadec));
close(fd); if ( ! follows(& outsect[DATA], &outsect[ROM]))
fatal("data segment must follow rom\n") ;
if ( outhead.oh_nsect==NSECT ) {
if (! follows(&outsect[LSECT], &outsect[BSS]))
fatal("end segment must follow bss\n") ;
if ( outsect[LSECT].os_size != 0 )
fatal("end segment must be empty\n") ;
}
/* Action at last */
fseek(output,0L,0); /* Start of output file */
emits(&outsect[TEXT]) ; /* Write out the text segment */
emits(&outsect[ROM]) ; /* Then the rom */
emits(&outsect[DATA]) ; /* Then the data */
if ( ferror(output) ) {
fatal("output write error\n") ;
}
if ( ofile_created ) chmod(argv[2],0755);
ss = 0;
printf(" text = %ld\n",outsect[TEXT].os_size);
printf(" rom = %ld\n",outsect[ROM].os_size);
printf(" data = %ld\n",outsect[DATA].os_size);
printf(" bss = %ld\n",outsect[BSS].os_size);
ss += outsect[TEXT].os_size;
ss += outsect[ROM].os_size;
ss += outsect[DATA].os_size;
ss += outsect[BSS].os_size;
printf("Total memory %ld bytes, plus heap and stack\n",ss);
return 0;
} }
fatal(s) /*
char *s; * Transfer the emitted byted from one file to another.
{ * and zero fill the uninitialized space
printf (s); */
exit (-1); emits(section) struct outsect *section ; {
register long n ;
register int blk;
char buffer[BUFSIZ];
n= section->os_flen ;
while (n > 0) {
blk = n > BUFSIZ ? BUFSIZ : n;
readf(buffer, 1, blk);
writef(buffer, 1, blk);
n -= blk;
}
if ( section->os_flen!=section->os_size ) {
for ( n=BUFSIZ-1 ; n ; n-- ) buffer[n]=0 ;
n= section->os_size - section->os_flen ;
while (n > 0) {
blk = n > BUFSIZ ? BUFSIZ : n;
writef(buffer, 1, blk);
n -= blk;
}
}
} }
rd_fatal(s)
char *s; rhead(f,head) struct outhead *head ; FILE *f ; {
{ char buf[SZ_HEAD] ;
printf (s); if ( fread(buf,SZ_HEAD,1,f)!=1 ) return 0 ;
exit (-1); iconvert(buf,(char *)head,SF_HEAD) ;
return 1 ;
}
rsect(f,sect) struct outsect *sect ; FILE *f ; {
char buf[SZ_SECT] ;
if ( fread(buf,SZ_SECT,1,f)!=1 ) return 0 ;
iconvert(buf,(char *)sect,SF_SECT) ;
return 1 ;
}
iconvert(buf,str,fmt) char *buf, *str, *fmt ; {
register char *nf, *ni, *no ;
int last, i ;
long value ;
ni=buf ; no=str ; nf=fmt ;
while ( last = *nf++ ) {
last -= '0' ;
if ( last<1 || last >9 ) fatal("illegal out.h format string\n");
value=0 ;
i=last ;
while ( i-- ) {
value = (value<<8) + (ni[i]&0xFF) ;
}
switch ( last ) {
case 0 : break ;
case 1 : *no= value ; break ;
case 2 : *(unsigned short *)no = value ; break ;
case 4 : *(long *)no = value ; break ;
default :
fatal("illegal out.h format string\n");
}
ni += last ; no += last ;
}
}
/* VARARGS1 */
fatal(s, a1, a2)
char *s;
{
fprintf(stderr,"%s: ",program) ;
fprintf(stderr, s, a1, a2);
if (ofile_created)
unlink(ofile);
exit(-1);
} }