xref: /csrg-svn/old/as.vax/asmain.c (revision 5826)
1*5826Srrh /*
2*5826Srrh  *	Copyright (c) 1982 Regents of the University of California
3*5826Srrh  */
4*5826Srrh #ifndef lint
5*5826Srrh static char sccsid[] = "@(#)asmain.c 4.9 02/14/82";
6*5826Srrh #endif not lint
7*5826Srrh 
8596Sbill #include <stdio.h>
9596Sbill #include <ctype.h>
10596Sbill #include <signal.h>
11596Sbill 
12596Sbill #include "as.h"
13596Sbill #include "assyms.h"
14*5826Srrh #include "asscan.h"
15596Sbill #include "asexpr.h"
16596Sbill 
17596Sbill #ifdef UNIX
18*5826Srrh #define	unix_lang_name "VAX/UNIX Assembler V02/14/82 4.9"
19596Sbill #endif
20596Sbill 
21596Sbill #ifdef VMS
22631Shenry #define vms_lang_name "VAX/VMS C Assembler V1.00"
23596Sbill #endif VMS
24596Sbill 
25596Sbill /*
26596Sbill  *	variables to manage reading the assembly source files
27596Sbill  */
28596Sbill char	*dotsname;	/*the current file name; managed by the parser*/
29596Sbill int	lineno;		/*current line number; managed by the parser*/
30643Sbill char	**innames;	/*names of the files being assembled*/
31596Sbill int	ninfiles;	/*how many interesting files there are*/
32596Sbill /*
33596Sbill  *	Flags settable from the argv process argument list
34596Sbill  */
35596Sbill int	silent = 0;	/*don't complain about any errors*/
36596Sbill int	savelabels = 0;	/*write the labels to the a.out file*/
37596Sbill int 	d124 = 4;	/*default allocate 4 bytes for unknown pointers*/
38596Sbill int	anyerrs = 0;	/*no errors yet*/
39*5826Srrh int	anywarnings=0;	/*no warnings yet*/
40596Sbill int	orgwarn = 0;	/*Bad origins*/
41596Sbill int	passno = 1;	/* current pass*/
42636Shenry int	jxxxJUMP = 0;	/* in jxxxes that branch too far, use jmp instead of brw */
43638Sbill int	readonlydata = 0;	/* initialzed data -> text space */
44596Sbill 
45*5826Srrh int	nGHnumbers = 0;		/* GH numbers used */
46*5826Srrh int	nGHopcodes = 0;		/* GH opcodes used */
47*5826Srrh int	nnewopcodes = 0;	/* new opcodes used */
48*5826Srrh 
49596Sbill #ifdef DEBUG
50596Sbill int 	debug = 0;
51596Sbill int	toktrace = 0;
52596Sbill #endif
53596Sbill 
54596Sbill int	useVM =		/*put the temp file in virtual memory*/
55596Sbill #ifdef VMS
56596Sbill 	1;		/*VMS has virtual memory (duh)*/
57596Sbill #endif VMS
58596Sbill #ifdef UNIX
59596Sbill  	0;
60596Sbill #endif
61596Sbill 
62596Sbill char	*endcore;	/*where to get more symbol space*/
63596Sbill 
64596Sbill /*
65596Sbill  *	Managers of the a.out file.
66596Sbill  */
67596Sbill struct	exec	hdr;
68638Sbill #define	MAGIC	0407
69596Sbill u_long	tsize;		/* total text size */
70596Sbill u_long	dsize;		/* total data size */
71596Sbill u_long	datbase;	/* base of the data segment */
72596Sbill u_long	trsize;		/* total text relocation size */
73596Sbill u_long	drsize;		/* total data relocation size */
74596Sbill 
75596Sbill /*
76596Sbill  *	Information about the current segment is accumulated in
77596Sbill  *	usedot; the most important information stored is the
78596Sbill  *	accumulated size of each of the text and data segments
79596Sbill  *
80596Sbill  *	dotp points to the correct usedot expression for the current segment
81596Sbill  */
82596Sbill struct	exp	usedot[NLOC+NLOC];	/* info about all segments */
83596Sbill struct	exp	*dotp;			/* data/text location pointer */
84596Sbill /*
85596Sbill  *	The inter pass temporary file is opened and closed by stdio, but
86596Sbill  *	is written to using direct read/write, as the temporary file
87596Sbill  *	is composed of buffers exactly BUFSIZ long.
88596Sbill  */
89596Sbill FILE	*tmpfil;			/* interpass communication file */
90596Sbill /*
91596Sbill  *	a.out is created during the second pass.
92596Sbill  *	It is opened by stdio, but is filled with the parallel
93596Sbill  *	block I/O library
94596Sbill  */
95596Sbill char	*outfile = "a.out";
96596Sbill FILE	*a_out_file;
97596Sbill off_t	a_out_off;			/* cumulative offsets for segments */
98596Sbill /*
99596Sbill  *	The logical files containing the assembled data for each of
100596Sbill  *	the text and data segments are
101596Sbill  *	managed by the parallel block I/O library.
102596Sbill  *	a.out is logically opened in many places at once to
103596Sbill  *	receive the assembled data from the various segments as
104596Sbill  *	it all trickles in, but is physically opened only once
105596Sbill  *	to minimize file overhead.
106596Sbill  */
107596Sbill BFILE	*usefile[NLOC+NLOC];		/* text/data files */
108596Sbill BFILE	*txtfil;			/* current text/data file */
109596Sbill /*
110596Sbill  *	Relocation information is accumulated seperately for each
111596Sbill  *	segment.  This is required by the old loader (from BTL),
112596Sbill  *	but not by the new loader (Bill Joy).
113596Sbill  *
114596Sbill  *	However, the size of the relocation information can not be computed
115596Sbill  *	during or after the 1st pass because the ''absoluteness' of values
116596Sbill  *	is unknown until all locally declared symbols have been seen.
117596Sbill  *	Thus, the size of the relocation information is only
118596Sbill  *	known after the second pass is finished.
119596Sbill  *	This obviates the use of the block I/O
120596Sbill  *	library, which requires knowing the exact offsets in a.out.
121596Sbill  *
122596Sbill  *	So, we save the relocation information internally (we don't
123596Sbill  *	go to internal files to minimize overhead).
124596Sbill  *
125596Sbill  *	Empirically, we studied 259 files composing the system,
126596Sbill  *	two compilers and a compiler generator: (all of which have
127596Sbill  *	fairly large source files)
128596Sbill  *
129596Sbill  *	Number of files = 259
130596Sbill  *		Number of non zero text reloc files: 233
131596Sbill  *		Number of non zero data reloc files: 53
132596Sbill  *	Average text relocation = 889
133596Sbill  *	Average data relocation = 346
134596Sbill  *	Number of files > BUFSIZ text relocation = 71
135596Sbill  *	Number of files > BUFSIZ data relocation = 6
136596Sbill  *
137596Sbill  *	For compiled C code, there is usually one text segment and two
138596Sbill  *	data segments; we see that allocating our own buffers and
139596Sbill  *	doing our internal handling of relocation information will,
140596Sbill  *	on the average, not use more memory than taken up by the buffers
141596Sbill  *	allocated for doing file I/O in parallel to a number of file.
142596Sbill  *
143596Sbill  *	If we are assembling with the -V option, we
144596Sbill  *	use the left over token buffers from the 2nd pass,
145596Sbill  *	otherwise, we create our own.
146596Sbill  *
147596Sbill  *	When the 2nd pass is complete, closeoutrel flushes the token
148596Sbill  *	buffers out to a BFILE.
149596Sbill  *
150596Sbill  *	The internals to relbufdesc are known only in assyms.c
151596Sbill  *
152596Sbill  *	outrel constructs the relocation information.
153596Sbill  *	closeoutrel flushes the relocation information to relfil.
154596Sbill  */
155596Sbill struct	relbufdesc	*rusefile[NLOC+NLOC];
156596Sbill struct	relbufdesc 	*relfil;	/* un concatnated relocation info */
157596Sbill BFILE	*relocfile;			/* concatnated relocation info */
158596Sbill /*
159596Sbill  *	Once the relocation information has been written,
160596Sbill  *	we can write out the symbol table using the Block I/O
161596Sbill  *	mechanisms, as we once again know the offsets into
162596Sbill  *	the a.out file.
163596Sbill  *
164596Sbill  *	We use relfil to output the symbol table information.
165596Sbill  */
166596Sbill 
167596Sbill char	*tmpdirprefix =
168596Sbill #ifdef UNIX
169596Sbill 			"/tmp/";
170596Sbill #else VMS
171596Sbill 			"/usr/tmp/";
172596Sbill #endif
173596Sbill 
174596Sbill #define		TMP_SUFFIX	"asXXXXXX"
175596Sbill char		tmpn1[TNAMESIZE];
176596Sbill 
177596Sbill int delexit();
178596Sbill 
179596Sbill main(argc, argv)
180596Sbill 	int	argc;
181596Sbill 	char 	**argv;
182596Sbill {
183*5826Srrh 	char	*sbrk();
184596Sbill 
185596Sbill 	tmpn1[0] = 0;
186*5826Srrh 	endcore = sbrk(0);
187596Sbill 
188596Sbill 	argprocess(argc, argv);		/* process argument lists */
189596Sbill 	if (anyerrs) exit(1);
190596Sbill 
191596Sbill 	initialize();
192596Sbill 	zeroorigins();			/* set origins to zero */
193596Sbill 	zerolocals();			/* fix local label counters */
194596Sbill 
195596Sbill 	i_pass1();			/* open temp files, etc */
196596Sbill 	pass1();			/* first pass through .s files */
197596Sbill 	testlocals();			/* check for undefined locals */
198596Sbill 	if (anyerrs) delexit();
199596Sbill 
200596Sbill 	pass1_5();			/* resolve jxxx */
201596Sbill 	if (anyerrs) delexit();
202596Sbill 
203596Sbill 	open_a_out();			/* open a.out */
204679Shenry 	roundsegments();		/* round segments to FW */
205596Sbill 	build_hdr();			/* build initial header, and output */
206596Sbill 
207596Sbill 	i_pass2();			/* reopen temporary file, etc */
208596Sbill 	pass2();			/* second pass through the virtual .s */
209596Sbill 	if (anyerrs) delexit();
210596Sbill 
211679Shenry 	fillsegments();			/* fill segments with 0 to FW */
212596Sbill 	reloc_syms();			/* dump relocation and symbol table */
213596Sbill 
214596Sbill 	delete();			/* remove tmp file */
215596Sbill 	bflush();			/* close off block I/O view of a.out */
216596Sbill 	fix_a_out();			/* add in text and data reloc counts */
217596Sbill 
218596Sbill 	if (anyerrs == 0 && orgwarn)
219596Sbill 		yyerror("Caution: absolute origins.\n");
220*5826Srrh 
221*5826Srrh 	if (nGHnumbers)
222*5826Srrh 		yywarning("Caution: G or H format floating point numbers");
223*5826Srrh 	if (nGHopcodes)
224*5826Srrh 		yywarning("Caution: G or H format floating point operators");
225*5826Srrh 	if (nnewopcodes)
226*5826Srrh 		yywarning("Caution: New Opcodes");
227*5826Srrh 	if (nGHnumbers || nGHopcodes || nnewopcodes)
228*5826Srrh 		yywarning("These are not defined for all implementations of the VAX architecture.\n");
229*5826Srrh 
230596Sbill 	exit(anyerrs != 0);
231596Sbill }	/*end of UNIX main*/
232596Sbill 
233596Sbill argprocess(argc, argv)
234596Sbill 	int	argc;
235596Sbill 	char	*argv[];
236596Sbill {
237596Sbill 	register	char	*cp;
238596Sbill 
239596Sbill 	ninfiles = 0;
240596Sbill 	silent = 0;
241596Sbill #ifdef DEBUG
242596Sbill 	debug = 0;
243596Sbill #endif
244643Sbill 	innames = (char **)ClearCalloc(argc+1, sizeof (innames[0]));
245596Sbill 	dotsname = "<argv error>";
246596Sbill 	while (argc > 1) {
247643Sbill 		if (argv[1][0] != '-')
248643Sbill 			innames[ninfiles++] = argv[1];
249643Sbill 		else {
250596Sbill 			cp = argv[1] + 1;
251596Sbill 			/*
252596Sbill 			 *	We can throw away single minus signs, so
253596Sbill 			 *	that make scripts for the PDP 11 assembler work
254596Sbill 			 *	on this assembler too
255596Sbill 			 */
256596Sbill 			while (*cp){
257596Sbill 				switch(*cp++){
258596Sbill 				 default:
259596Sbill 					yyerror("Unknown flag: %c", *--cp);
260596Sbill 					cp++;
261596Sbill 					break;
262596Sbill 				 case 'd':
263596Sbill 					d124 = *cp++ - '0';
264596Sbill 					if ( (d124 != 1) && (d124 != 2) &&
265596Sbill 					     (d124 != 4)){
266596Sbill 						yyerror("-d[124] only");
267596Sbill 						exit(1);
268596Sbill 					}
269596Sbill 					break;
270596Sbill 				 case 'o':
271596Sbill 					if (argc < 3){
272596Sbill 						yyerror("-o what???");
273596Sbill 						exit(1);
274596Sbill 					}
275596Sbill 					outfile = argv[2];
276596Sbill 				   bumpone:
277596Sbill 					argc -= 2;
278596Sbill 					argv += 2;
279596Sbill 					goto nextarg;
280596Sbill 
281596Sbill 				 case 't':
282596Sbill 					if (argc < 3){
283596Sbill 						yyerror("-t what???");
284596Sbill 						exit(1);
285596Sbill 					}
286596Sbill 					tmpdirprefix = argv[2];
287596Sbill 					goto bumpone;
288596Sbill 
289596Sbill 				 case 'V':
290596Sbill 					useVM = 1;
291596Sbill 					break;
292596Sbill 				 case 'W':
293596Sbill 					silent = 1;
294596Sbill 					break;
295596Sbill 				 case 'L':
296596Sbill 					savelabels = 1;
297596Sbill 					break;
298636Shenry 				 case 'J':
299636Shenry 					jxxxJUMP = 1;
300636Shenry 					break;
301596Sbill #ifdef DEBUG
302596Sbill 				 case 'D':
303596Sbill 					debug = 1;
304596Sbill 					break;
305596Sbill 				 case 'T':
306596Sbill 					toktrace = 1;
307596Sbill 					break;
308596Sbill #endif
309638Sbill 				 case 'R':
310638Sbill 					readonlydata = 1;
311638Sbill 					break;
312596Sbill 				}	/*end of the switch*/
313596Sbill 			}	/*end of pulling out all arguments*/
314596Sbill 		}	/*end of a flag argument*/
315596Sbill 		--argc; ++argv;
316596Sbill 	   nextarg:;
317596Sbill 	}
318643Sbill 	/* innames[ninfiles] = 0; */
319596Sbill }
320596Sbill 
321596Sbill initialize()
322596Sbill {
323596Sbill 	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
324596Sbill 		signal(SIGINT, delexit);
325596Sbill 	/*
326596Sbill 	 *	Install symbols in the table
327596Sbill 	 */
328596Sbill 	symtabinit();
329596Sbill 	syminstall();
330596Sbill 	/*
331596Sbill 	 *	Build the expression parser accelerator token sets
332596Sbill 	 */
333596Sbill 	buildtokensets();
334596Sbill }
335596Sbill 
336596Sbill zeroorigins()
337596Sbill {
338596Sbill 	register	int	locindex;
339596Sbill 	/*
340596Sbill 	 *	Mark usedot: the first NLOC slots are for named text segments,
341596Sbill 	 *	the next for named data segments.
342596Sbill 	 */
343596Sbill 	for (locindex = 0; locindex < NLOC; locindex++){
344631Shenry 		usedot[locindex].e_xtype = XTEXT;
345631Shenry 		usedot[NLOC + locindex].e_xtype = XDATA;
346631Shenry 		usedot[locindex].e_xvalue = 0;
347631Shenry 		usedot[NLOC + locindex].e_xvalue = 0;
348596Sbill 	}
349596Sbill }
350596Sbill 
351596Sbill zerolocals()
352596Sbill {
353596Sbill 	register	int	i;
354596Sbill 
355596Sbill 	for (i = 0; i <= 9; i++) {
356596Sbill 		lgensym[i] = 1;
357596Sbill 		genref[i] = 0;
358596Sbill 	}
359596Sbill }
360596Sbill 
361596Sbill i_pass1()
362596Sbill {
363596Sbill 	if (useVM == 0){
364596Sbill 		strcat(tmpn1, tmpdirprefix);
365644Shenry 		if (tmpdirprefix[strlen(tmpdirprefix)-1] != '/')
366644Shenry 			strcat(tmpn1, "/");
367*5826Srrh 		(void)strcat(tmpn1, TMP_SUFFIX);
368*5826Srrh 		(void)mktemp(tmpn1);
369596Sbill 		tmpfil = fopen(tmpn1, "w");
370596Sbill 		if (tmpfil==NULL) {
371596Sbill 		  yyerror("Bad pass 1 temporary file for writing %s", tmpn1);
372596Sbill 		  delexit();
373596Sbill 		}
374596Sbill 	}
375596Sbill 
376596Sbill 	inittmpfile();
377636Shenry 	initijxxx();
378596Sbill }
379596Sbill 
380596Sbill pass1()
381596Sbill {
382596Sbill 	register	int	i;
383596Sbill 
384596Sbill 	passno = 1;
385596Sbill 	dotp = &usedot[0];
386596Sbill 	txtfil = (BFILE *)0;
387596Sbill 	relfil = (struct relbufdesc *)0;
388596Sbill 
389596Sbill 	if (ninfiles == 0){		/*take the input from stdin directly*/
390596Sbill 		lineno = 1;
391596Sbill 		dotsname = "<stdin>";
392596Sbill 
393596Sbill 		yyparse();
394596Sbill 	} else {		/*we have the names tanked*/
395596Sbill 		for (i = 0; i < ninfiles; i++){
396596Sbill 			new_dot_s(innames[i]);
397596Sbill 			if (freopen(innames[i], "r", stdin) == NULL) {
398596Sbill 				yyerror( "Can't open source file %s\n",
399596Sbill 					innames[i]);
400596Sbill 				exit(2);
401596Sbill 			}
402596Sbill 			/* stdio is NOT used to read the input characters */
403596Sbill 			/* we use read directly, into our own buffers */
404596Sbill 			yyparse();
405596Sbill 		}
406596Sbill 	}
407596Sbill 
408596Sbill 	closetmpfile();		/*kick out the last buffered intermediate text*/
409596Sbill }
410596Sbill 
411596Sbill testlocals()
412596Sbill {
413596Sbill 	register	int	i;
414596Sbill 	for (i = 0; i <= 9; i++) {
415596Sbill 		if (genref[i])
416596Sbill 			yyerror("Reference to undefined local label %df", i);
417596Sbill 		lgensym[i] = 1;
418596Sbill 		genref[i] = 0;
419596Sbill 	}
420596Sbill }
421596Sbill 
422596Sbill pass1_5()
423596Sbill {
424596Sbill 	sortsymtab();
425596Sbill #ifdef DEBUG
426596Sbill 	if (debug) dumpsymtab();
427596Sbill #endif
428596Sbill 	jxxxfix();
429596Sbill #ifdef DEBUG
430596Sbill 	if (debug) dumpsymtab();
431596Sbill #endif
432596Sbill }
433596Sbill 
434596Sbill open_a_out()
435596Sbill {
436596Sbill 	/*
437596Sbill 	 *	Open up the a.out file now, and get set to build
438596Sbill 	 *	up offsets into it for all of the various text,data
439596Sbill 	 *	text relocation and data relocation segments.
440596Sbill 	 */
441596Sbill 	a_out_file = fopen(outfile, "w");
442596Sbill 	if (a_out_file == NULL) {
443596Sbill 		yyerror("Cannot create %s", outfile);
444596Sbill 		delexit();
445596Sbill 	}
446596Sbill 	biofd = a_out_file->_file;
447596Sbill 	a_out_off = 0;
448596Sbill }
449596Sbill 
450596Sbill roundsegments()
451596Sbill {
452596Sbill 	register	int	locindex;
453596Sbill 	register	long	v;
454596Sbill 	/*
455596Sbill 	 *	round and assign text segment origins
456596Sbill 	 *	the exec header always goes in usefile[0]
457596Sbill 	 */
458596Sbill 	tsize = 0;
459596Sbill 	for (locindex=0; locindex<NLOC; locindex++) {
460679Shenry 		v = round(usedot[locindex].e_xvalue, FW);
461631Shenry 		usedot[locindex].e_xvalue = tsize;
462596Sbill 		if ((locindex == 0) || (v != 0) ){
463596Sbill 			usefile[locindex] = (BFILE *)Calloc(1, sizeof(BFILE));
464596Sbill 			bopen(usefile[locindex], a_out_off);
465596Sbill 			if (locindex == 0)
466596Sbill 				a_out_off = sizeof (struct exec);
467596Sbill 		} else {
468596Sbill 			usefile[locindex] = (BFILE *)-1;
469596Sbill 		}
470596Sbill 		tsize += v;
471596Sbill 		a_out_off += v;
472596Sbill 	}
473596Sbill 	/*
474596Sbill 	 *		Round and assign data segment origins.
475596Sbill 	 */
476679Shenry 	datbase = round(tsize, FW);
477596Sbill 	for (locindex=0; locindex<NLOC; locindex++) {
478679Shenry 		v = round(usedot[NLOC+locindex].e_xvalue, FW);
479631Shenry 		usedot[NLOC+locindex].e_xvalue = datbase + dsize;
480596Sbill 		if (v != 0){
481596Sbill 			usefile[NLOC + locindex] = (BFILE *)Calloc(1,sizeof(BFILE));
482596Sbill 			bopen(usefile[NLOC + locindex], a_out_off);
483596Sbill 		} else {
484596Sbill 			usefile[NLOC + locindex] = (BFILE *)-1;
485596Sbill 		}
486596Sbill 		dsize += v;
487596Sbill 		a_out_off += v;
488596Sbill 	}
489596Sbill 	/*
490596Sbill 	 *	Assign final values to symbols
491596Sbill 	 */
492596Sbill 	hdr.a_bss = dsize;
493596Sbill 	freezesymtab();		/* this touches hdr.a_bss */
494596Sbill 	stabfix();
495596Sbill 	/*
496596Sbill 	 *	Set up the relocation information "files" to
497596Sbill 	 *	be zero; outrel takes care of the rest
498596Sbill 	 */
499596Sbill 	for (locindex = 0; locindex < NLOC + NLOC; locindex++){
500596Sbill 		rusefile[locindex] = (struct relbufdesc *)0;
501596Sbill 	}
502596Sbill }
503596Sbill 
504596Sbill build_hdr()
505596Sbill {
506596Sbill 	/*
507596Sbill 	 *	Except for the text and data relocation sizes,
508596Sbill 	 *	calculate the final values for the header
509596Sbill 	 *
510596Sbill 	 *	Write out the initial copy; we to come
511596Sbill 	 *	back later and patch up a_trsize and a_drsize,
512596Sbill 	 *	and overwrite this first version of the header.
513596Sbill 	 */
514596Sbill 	hdr.a_magic = MAGIC;
515596Sbill 	hdr.a_text = tsize;
516596Sbill 	hdr.a_data = dsize;
517596Sbill 	hdr.a_bss -= dsize;
518596Sbill 	hdr.a_syms = sizesymtab();	/* Does not include string pool length */
519596Sbill 	hdr.a_entry = 0;
520596Sbill 	hdr.a_trsize = 0;
521596Sbill 	hdr.a_drsize = 0;
522596Sbill 
523596Sbill 	bwrite((char *)&hdr, sizeof(hdr), usefile[0]);
524596Sbill }
525596Sbill 
526596Sbill i_pass2()
527596Sbill {
528596Sbill 	if (useVM == 0) {
529596Sbill 		fclose(tmpfil);
530596Sbill 		tmpfil = fopen(tmpn1, "r");
531596Sbill 		if (tmpfil==NULL) {
532596Sbill 		   yyerror("Bad pass 2 temporary file for reading %s", tmpn1);
533596Sbill 		   delexit();
534596Sbill 		}
535596Sbill 	}
536596Sbill }
537596Sbill 
538596Sbill pass2()
539596Sbill {
540596Sbill #ifdef DEBUG
541596Sbill 	if (debug)
542596Sbill 		printf("\n\n\n\t\tPASS 2\n\n\n\n");
543596Sbill #endif DEBUG
544596Sbill 	passno = 2;
545596Sbill 	lineno = 1;
546596Sbill 	dotp = &usedot[0];
547596Sbill 	txtfil = usefile[0];	/* already opened (always!) */
548596Sbill 	relfil = 0;		/* outrel takes care of the rest */
549596Sbill 	initoutrel();
550596Sbill 
551596Sbill 	inittmpfile();
552596Sbill 
553596Sbill 	yyparse();
554596Sbill 
555596Sbill 	closetmpfile();
556596Sbill }
557596Sbill 
558596Sbill fillsegments()
559596Sbill {
560596Sbill 	int	locindex;
561596Sbill 	/*
562679Shenry 	 *	Round text and data segments to FW by appending zeros
563596Sbill 	 */
564596Sbill 	for (locindex = 0; locindex < NLOC + NLOC; locindex++) {
565596Sbill 		if (usefile[locindex]) {
566596Sbill 			txtfil = usefile[locindex];
567596Sbill 			dotp = &usedot[locindex];
568679Shenry 			while (usedot[locindex].e_xvalue & FW)
569596Sbill 				outb(0);
570596Sbill 		}
571596Sbill 	}
572596Sbill }
573596Sbill 
574596Sbill reloc_syms()
575596Sbill {
576596Sbill 	u_long	closerelfil();
577596Sbill 	/*
578596Sbill 	 *	Move the relocation information to a.out
579596Sbill 	 *	a_out_off is the offset so far:
580596Sbill 	 *	exec + text segments + data segments
581596Sbill 	 */
582596Sbill 	relocfile = (BFILE *)Calloc(1,sizeof(BFILE));
583596Sbill 	bopen(relocfile, a_out_off);
584596Sbill 	a_out_off += closeoutrel(relocfile);
585596Sbill 
586596Sbill 	hdr.a_trsize = trsize;
587596Sbill 	hdr.a_drsize = drsize;
588638Sbill 	if (readonlydata) {
589638Sbill 		hdr.a_text += hdr.a_data;
590638Sbill 		hdr.a_data = 0;
591638Sbill 		hdr.a_trsize += hdr.a_drsize;
592638Sbill 		hdr.a_drsize = 0;
593638Sbill 	}
594596Sbill 	/*
595596Sbill 	 *	Output the symbol table
596596Sbill 	 *	and if FLEXNAMES is set, the string pool
597596Sbill 	 */
598596Sbill 	symwrite(relocfile);
599596Sbill }
600596Sbill 
601596Sbill fix_a_out()
602596Sbill {
603*5826Srrh 	if (lseek(a_out_file->_file, 0L, 0) < 0L)
604596Sbill 		yyerror("Reposition for header rewrite fails");
605596Sbill 	if (write(a_out_file->_file, (char *)&hdr, sizeof (struct exec)) < 0)
606596Sbill 		yyerror("Rewrite of header fails");
607596Sbill }
608596Sbill 
609596Sbill delexit()
610596Sbill {
611596Sbill 	delete();
612596Sbill 	if (passno == 2){
613596Sbill 		unlink(outfile);
614596Sbill 	}
615596Sbill 	exit(1);
616596Sbill }
617596Sbill 
618596Sbill delete()
619596Sbill {
620596Sbill 	if (useVM == 0 || tmpn1[0])
621596Sbill 		unlink(tmpn1);
622596Sbill }
623596Sbill 
624596Sbill sawabort()
625596Sbill {
626596Sbill 	char	*fillinbuffer();
627596Sbill 	while (fillinbuffer() != (char *)0)
628596Sbill 		continue;
629596Sbill 	delete();
630596Sbill 	exit(1);	/*although the previous pass will also exit non zero*/
631596Sbill }
632596Sbill 
633596Sbill panic(fmt, a1, a2, a3, a4)
634596Sbill 	char	*fmt;
635596Sbill 	/*VARARGS 1*/
636596Sbill {
637596Sbill 	yyerror("Assembler panic: bad internal data structure.");
638596Sbill 	yyerror(fmt, a1, a2, a3, a4);
639596Sbill 	delete();
640596Sbill 	abort();
641596Sbill }
642