1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-01-10 13:24:36 +00:00
|
|
|
#ifndef lint
|
1994-06-24 11:31:16 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-10 13:24:36 +00:00
|
|
|
#endif
|
|
|
|
|
1986-10-20 10:17:57 +00:00
|
|
|
#include <out.h>
|
1985-01-10 13:24:36 +00:00
|
|
|
#include "const.h"
|
|
|
|
#include "memory.h"
|
|
|
|
|
1985-06-10 10:48:49 +00:00
|
|
|
static generate_section_names();
|
|
|
|
|
1985-01-10 13:24:36 +00:00
|
|
|
extern struct outhead outhead;
|
|
|
|
extern bool incore;
|
|
|
|
extern int flagword;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have counted all relocation structs but we know only now if
|
|
|
|
* these must be emitted.We add all names here,unless the -s(trip)
|
|
|
|
* flag was given.
|
|
|
|
* If this flag is given we don't need the string table either.
|
|
|
|
*/
|
|
|
|
beginoutput()
|
|
|
|
{
|
1991-12-17 15:28:58 +00:00
|
|
|
extern unsigned short NLocals, NGlobals;
|
1985-01-10 13:24:36 +00:00
|
|
|
extern long NLChars, NGChars;
|
1990-01-29 12:40:43 +00:00
|
|
|
extern char *outputname;
|
1985-01-10 13:24:36 +00:00
|
|
|
|
1990-01-29 12:40:43 +00:00
|
|
|
if (! wr_open(outputname)) {
|
|
|
|
fatal("can't create %s", outputname);
|
|
|
|
}
|
1985-01-10 13:24:36 +00:00
|
|
|
if (incore)
|
|
|
|
generate_section_names();
|
|
|
|
|
1987-08-26 13:22:44 +00:00
|
|
|
if (!(flagword & (CFLAG|RFLAG)))
|
1991-12-17 15:28:58 +00:00
|
|
|
outhead.oh_nrelo = (unsigned short)0;
|
1985-01-10 13:24:36 +00:00
|
|
|
if (flagword & SFLAG) {
|
1991-12-17 15:28:58 +00:00
|
|
|
outhead.oh_nname = (unsigned short)0;
|
1985-01-10 13:24:36 +00:00
|
|
|
outhead.oh_nchar = (long)0;
|
|
|
|
} else {
|
|
|
|
outhead.oh_nname = NLocals + NGlobals + outhead.oh_nsect;
|
|
|
|
outhead.oh_nchar = NLChars + NGChars;
|
|
|
|
}
|
|
|
|
if (!incore)
|
|
|
|
begin_write();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate names for all sections and put them after the global names.
|
|
|
|
* Section names are used for relocation.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
generate_section_names()
|
|
|
|
{
|
|
|
|
register struct outname *name;
|
|
|
|
register int sectindex;
|
|
|
|
register long size;
|
|
|
|
extern struct outsect outsect[];
|
|
|
|
extern char *core_alloc();
|
|
|
|
|
|
|
|
size = (long)outhead.oh_nsect * sizeof(struct outname);
|
|
|
|
name = (struct outname *)core_alloc(ALLOGLOB, size);
|
|
|
|
if (name == (struct outname *)0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++, name++) {
|
|
|
|
name->on_foff = (long)0; /* No string name. */
|
|
|
|
name->on_type = (S_MIN + sectindex) | S_SCT;
|
1991-12-17 15:28:58 +00:00
|
|
|
name->on_desc = (unsigned short)0;
|
1985-01-10 13:24:36 +00:00
|
|
|
name->on_valu = outsect[sectindex].os_base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we didn't keep the whole output file in core, most of it has been
|
|
|
|
* written out, and we just finish that.
|
|
|
|
* If we did, we write out our pieces of core.
|
|
|
|
*/
|
|
|
|
endoutput()
|
|
|
|
{
|
|
|
|
if (!incore) {
|
|
|
|
if (!(flagword & SFLAG))
|
|
|
|
end_write();
|
|
|
|
} else {
|
|
|
|
write_bytes();
|
|
|
|
}
|
1990-01-29 12:40:43 +00:00
|
|
|
wr_close();
|
1985-01-10 13:24:36 +00:00
|
|
|
}
|