1 /* $Id: cv.c,v 2.8 1994/06/24 13:21:19 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
9 * Fortunately we sold our PMDS machine. Unfortunately, we also sold the
10 * documentation that came with it, so I don't know the a.out format
11 * of the machine. This program is written partly by guessing, and partly from
12 * an older conversion program for the PMDS, which put the whole program
13 * in data. The produced object file does not contain a namelist.
19 #define ASSERT(x) switch (2) { case 0: case (x): ; }
22 * Header and section table of new format object file.
24 struct outhead outhead;
25 struct outsect outsect[S_MAX];
28 int outputfile_created;
36 #define writef(a, b, c) fwrite((a), (b), (int)(c), output)
38 /* Output file definitions and such */
65 register struct outsect *pa, *pb;
67 /* return 1 if pa follows pb */
69 return pa->os_base == align(pb->os_base+pb->os_size, pa->os_lign);
86 if ( argc>1 && argv[1][0]=='-' ) {
91 case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0)
92 fatal("Can't write %s.\n", argv[2]);
93 output_file = argv[2];
94 outputfile_created = 1;
95 if (! rd_open(argv[1]))
96 fatal("Can't read %s.\n", argv[1]);
98 default:fatal("Usage: %s <ACK object> <Mantra object>.\n", argv[0]);
101 if (BADMAGIC(outhead))
102 fatal("Not an ack object file.\n");
103 if (outhead.oh_flags & HF_LINK)
104 fatal("Contains unresolved references.\n");
105 if (outhead.oh_nrelo > 0)
106 fprintf(stderr, "Warning: relocation information present.\n");
107 if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT )
108 fatal("Input file must have %d sections, not %ld\n",
109 NSECT,outhead.oh_nsect) ;
110 rd_sect(outsect, outhead.oh_nsect);
112 if ( outsect[TEXTSG].os_base != ENTRY)
113 fatal("text must start at %d not at 0x%lx\n", ENTRY,
114 outsect[TEXTSG].os_base) ;
115 if ( outsect[BSSSG].os_flen != 0 )
116 fatal("bss space contains initialized data\n") ;
117 if (! follows(&outsect[BSSSG], &outsect[DATASG]))
118 fatal("bss segment must follow data segment\n") ;
119 if ( outsect[ROMSG].os_lign == 0x8000 ) {
120 /* 410 file with ROMSG in data space */
123 if (! follows(&outsect[DATASG], &outsect[ROMSG]))
124 fatal("data segment must follow rom\n") ;
125 textsize= outsect[TEXTSG].os_size ;
126 outsect[ROMSG].os_size = outsect[DATASG].os_base - outsect[ROMSG].os_base;
127 outsect[DATASG].os_size = outsect[BSSSG].os_base - outsect[DATASG].os_base;
128 datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ;
130 if ( outsect[DATASG].os_lign == 0x8000 ) {
131 /* 410 file with ROMSG in instruction space */
134 if (! follows(&outsect[ROMSG], &outsect[TEXTSG]))
135 fatal("rom segment must follow text\n") ;
136 outsect[TEXTSG].os_size = outsect[ROMSG].os_base - outsect[TEXTSG].os_base;
137 textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ;
138 outsect[DATASG].os_size = outsect[BSSSG].os_base - outsect[DATASG].os_base;
139 datasize= outsect[DATASG].os_size ;
144 if (! follows(&outsect[ROMSG], &outsect[TEXTSG]))
145 fatal("rom segment must follow text\n") ;
146 if (! follows(&outsect[DATASG], &outsect[ROMSG]))
147 fatal("data segment must follow rom\n") ;
148 outsect[TEXTSG].os_size = outsect[ROMSG].os_base - outsect[TEXTSG].os_base;
149 outsect[ROMSG].os_size = outsect[DATASG].os_base - outsect[ROMSG].os_base;
150 outsect[DATASG].os_size = outsect[BSSSG].os_base - outsect[DATASG].os_base;
151 textsize= outsect[TEXTSG].os_size ;
152 datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ;
154 bsssize = outsect[BSSSG].os_size;
155 if ( outhead.oh_nsect==NSECT ) {
156 if (! follows(&outsect[LSECT], &outsect[BSSSG]))
157 fatal("end segment must follow bss\n") ;
158 if ( outsect[LSECT].os_size != 0 )
159 fatal("end segment must be empty\n") ;
163 fseek(output,(long) HDRSIZE,0);
164 emits(&outsect[TEXTSG]) ;
165 emits(&outsect[ROMSG]) ;
166 emits(&outsect[DATASG]) ;
168 sethdr(0, (long) magic);
173 if ( ferror(output) ) {
174 fatal("output write error\n") ;
176 if ( outputfile_created ) chmod(argv[2],0755);
181 sethdr(off,val) long val ; {
183 hdr[off+1] = val>>16 ;
184 hdr[off+2] = val>>8 ;
189 * Transfer the emitted byted from one file to another.
191 emits(section) struct outsect *section ; {
194 long length = section->os_size;
196 rd_outsect(section - outsect);
197 while (section->os_size > 0) {
198 int i = section->os_size > 10*1024 ? 10*1024 : section->os_size;
200 section->os_size -= i;
201 if (!(p = calloc(i, 1))) {
202 fatal("No memory.\n");
204 rd_emit(p, i >= section->os_flen ? section->os_flen:(long) i);
205 section->os_flen -= i;
215 fprintf(stderr,"%s: ",program) ;
216 fprintf(stderr, s, a1, a2);
217 if (outputfile_created)
222 rd_fatal() { fatal("read error.\n"); }