From: ceriel Date: Tue, 13 Nov 1990 11:46:48 +0000 (+0000) Subject: Albert Koelmans newest version X-Git-Tag: release-5-5~1423 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ff117d9f0bd6b3a2cd35135d1c4b35268f696ab4;p=ack.git Albert Koelmans newest version --- diff --git a/mach/arm/cv/Makefile b/mach/arm/cv/Makefile index 452bed2e3..40fd83624 100644 --- a/mach/arm/cv/Makefile +++ b/mach/arm/cv/Makefile @@ -4,13 +4,13 @@ OBJLIB=$(EMHOME)/modules/lib/libobject.a head: cv 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 - @echo Nothing is installed + ../../install cv cmp: head - @echo Nothing is compared + ../../compare cv clean: rm -f *.o diff --git a/mach/arm/cv/cv.c b/mach/arm/cv/cv.c index 88a711574..49e82f6f0 100644 --- a/mach/arm/cv/cv.c +++ b/mach/arm/cv/cv.c @@ -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 -#include +#include "out.h" #include "arm.h" -struct outhead ohead; -struct outsect sect[NSECT]; -struct armhead ahead; -struct chunkhead chead; -struct areadec area[NSECT]; -int fd; +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of ack object file. + */ +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) -int argc; -char *argv[]; + +#define N_EXT 040 +#define N_UNDEF 00 +#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"); - if (! rd_open (*++argv)) - fatal ("can't open \n"); - if ((fd = open(*++argv, 1)) <0) - fatal ("can't open \n"); - else { - convert (); - } + a += b - 1; + return a - a % b; } - -convert () + +int +follows(pa, pb) + register struct outsect *pa, *pb; { - int i,areasize=0; - char buf[4]; - int cnt; - - rd_ohead(&ohead); - if (ohead.oh_flags & HF_LINK) { - fatal("unresolved references\n"); - } - ahead.chunkfileid = 0xC3CBC6C5; - ahead.maxchunks = MAXCHUNK; - ahead.numchunks = MAXCHUNK; - strncpy(ahead.entries[0].chunkid , "OBJ_HEAD", 8); - strncpy(ahead.entries[1].chunkid , "OBJ_AREA", 8); - strncpy(ahead.entries[2].chunkid , "OBJ_IDFN", 8); - strncpy(ahead.entries[3].chunkid , "OBJ_SYMT", 8); - strncpy(ahead.entries[4].chunkid , "OBJ_STRT", 8); - ahead.entries[0].offset = sizeof(struct armhead); - ahead.entries[0].size = sizeof(struct chunkhead) + ohead.oh_nsect * - sizeof(struct areadec); - ahead.entries[1].offset = ahead.entries[0].offset+ahead.entries[0].size; - chead.objtype = 0xC5E2D080; - chead.versionid = 110; - chead.narea = ohead.oh_nsect; - chead.nsymb = ohead.oh_nname; - chead.entrya = 0; - chead.entryo = 0; - lseek(fd, ahead.entries[1].offset, 0); - rd_sect(sect, ohead.oh_nsect); - for (i = 0; i < ohead.oh_nsect; i++) { - area[i].name=0; - area[i].atal=2|1<<7|(i=0?(1<<8):0); - area[i].size=sect[i].os_size; - area[i].nrel=0; - area[i].base=sect[i].os_base; - rd_outsect(i); - cnt = sect[i].os_flen; - areasize += cnt; - if (cnt!=sect[i].os_size) - area[i].atal |= 1<<11; - if (cnt & 3) - fatal("alignment error\n"); - while (cnt){ - rd_emit(buf, (long)4); - write(fd, buf, 4); - cnt -= 4; - } - } - ahead.entries[1].size = areasize; - lseek(fd, 0, 0); - write(fd, &ahead, sizeof(struct armhead)); - write(fd, &chead, sizeof(struct chunkhead)); - for(i=1; ios_base == align(pb->os_base+pb->os_size, pa->os_lign); } -fatal(s) -char *s; +main(argc, argv) + int argc; + char *argv[]; { - printf (s); - exit (-1); + register int nsect; + long magic ; + long textsize ; + long datasize ; + long ss; + + ASSERT(sizeof(struct outhead) == SZ_HEAD); + ASSERT(sizeof(struct outsect) == SZ_SECT); + + input = stdin; output = stdout; + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 1: break; + case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) + fatal("Can't write %s.\n", argv[2]); + ofile = argv[2]; + ofile_created = 1; + /* FALLTHROUGH */ + case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s .\n", argv[0]); + } + if ( !rhead(input,&outhead) ) + fatal("Reading header failed.\n"); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + for ( nsect=0 ; nsectos_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; + } + } +} + + +rhead(f,head) struct outhead *head ; FILE *f ; { + char buf[SZ_HEAD] ; + if ( fread(buf,SZ_HEAD,1,f)!=1 ) return 0 ; + 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 ; + } } -rd_fatal(s) -char *s; +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; { - printf (s); - exit (-1); + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (ofile_created) + unlink(ofile); + exit(-1); }