Add additional defines for compilation.

This commit is contained in:
carl 2019-03-24 17:08:45 +08:00
parent b3814af1ba
commit c5f5bace63
22 changed files with 250 additions and 237 deletions

View file

@ -13,15 +13,24 @@ static char rcsid[] = "$Id$";
#include "arch.h" #include "arch.h"
#include "out.h" #include "out.h"
#include "ranlib.h" #include "ranlib.h"
#include "object.h"
#include "const.h" #include "const.h"
#include "debug.h" #include "debug.h"
#include "finish.h"
#include "extract.h"
#include "defs.h" #include "defs.h"
#include "memory.h" #include "memory.h"
#include "scan.h"
#include "error.h"
#include "save.h"
#define ENDLIB ((long)0) #define ENDLIB ((long)0)
static struct ar_hdr arhdr; static struct ar_hdr arhdr;
void notelib(long pos);
/* /*
* First read a long telling how many ranlib structs there are, then * First read a long telling how many ranlib structs there are, then
* the structs themselves. Second read a long telling how many chars there are * the structs themselves. Second read a long telling how many chars there are
@ -29,15 +38,14 @@ static struct ar_hdr arhdr;
* We keep only one ranlib table in core, so this table always starts at offset * We keep only one ranlib table in core, so this table always starts at offset
* (ind_t)0 from its base. * (ind_t)0 from its base.
*/ */
static long static long getsymdeftable(void)
getsymdeftable()
{ {
register ind_t off; register ind_t off;
register struct ranlib *ran; register struct ranlib *ran;
register long count; register long count;
register long nran, nchar; register long nran, nchar;
extern long rd_long(); extern long rd_long();
extern int infile; extern FILE* infile;
count = nran = rd_long(infile); count = nran = rd_long(infile);
debug("%ld ranlib structs, ", nran, 0, 0, 0); debug("%ld ranlib structs, ", nran, 0, 0, 0);
@ -81,7 +89,7 @@ extern char *modulname;
* scan the table again. We perform these actions as long as new symbols * scan the table again. We perform these actions as long as new symbols
* are defined. * are defined.
*/ */
arch() void arch(void)
{ {
long nran; long nran;
bool resolved; bool resolved;
@ -143,8 +151,7 @@ arch()
* An archive member that will be loaded is remembered by storing its position * An archive member that will be loaded is remembered by storing its position
* in the archive into the table of positions. * in the archive into the table of positions.
*/ */
notelib(pos) void notelib(long pos)
long pos;
{ {
register ind_t off; register ind_t off;
@ -165,7 +172,7 @@ static ind_t posindex = (ind_t)0;
* that we've processed all needed modules in this archive. Each group of * that we've processed all needed modules in this archive. Each group of
* positions of an archive is terminated with ENDLIB. * positions of an archive is terminated with ENDLIB.
*/ */
arch2() void arch2(void)
{ {
register long *pos; register long *pos;
register ind_t localpos; register ind_t localpos;

View file

@ -2,8 +2,10 @@ cprogram {
name = "led", name = "led",
srcs = { "./*.c" }, srcs = { "./*.c" },
deps = { deps = {
"./const.h", "./debug.h", "./defs.h", "./mach.h", "./archive.h", "./const.h", "./debug.h", "./defs.h",
"./memory.h", "./orig.h", "./scan.h", "./error.h", "./extract.h", "./finish.h", "./mach.h",
"./memory.h", "./orig.h", "./output.h", "./relocate.h",
"./save.h", "./scan.h", "./sym.h", "./write.h",
"modules/src/string+lib", "modules/src/string+lib",
"modules/src/object+lib", "modules/src/object+lib",
"h+emheaders", "h+emheaders",

View file

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __CONST_H_INCLUDED__
#define __CONST_H_INCLUDED__
#define FALSE 0 #define FALSE 0
#define TRUE 1 #define TRUE 1
@ -22,3 +25,5 @@
#define SECOND 2 /* Idem. */ #define SECOND 2 /* Idem. */
#define BADOFF ((ind_t)-1) #define BADOFF ((ind_t)-1)
#endif /* __CONST_H_INCLUDED__ */

View file

@ -4,6 +4,10 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __DEBUG_H_INCLUDED__
#define __DEBUG_H_INCLUDED__
#ifdef NDEBUG #ifdef NDEBUG
#define debug(s, a1, a2, a3, a4) #define debug(s, a1, a2, a3, a4)
@ -19,3 +23,5 @@ extern int Verbose;
#define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4)) #define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4))
extern void fatal(char* format, ...); extern void fatal(char* format, ...);
#endif /* __DEBUG_H_INCLUDED__ */

View file

@ -3,6 +3,9 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __DEFS_H_INCLUDED__
#define __DEFS_H_INCLUDED__
/* /*
* We need the S_EXT because we leave locals alone. * We need the S_EXT because we leave locals alone.
@ -12,3 +15,6 @@
#define ISCOMMON(n) (((n)->on_type & (S_COM | S_EXT)) == (S_COM | S_EXT)) #define ISCOMMON(n) (((n)->on_type & (S_COM | S_EXT)) == (S_COM | S_EXT))
#define mustsavelocal(name) (!((name)->on_type & S_SCT)) #define mustsavelocal(name) (!((name)->on_type & S_SCT))
#endif /* __DEFS_H_INCLUDED__ */

View file

@ -17,13 +17,13 @@ static char rcsid[] = "$Id$";
static short nerrors = 0; static short nerrors = 0;
static void diag(char *, char *, va_list); static void diag(char *, char *, va_list);
stop() void stop(void)
{ {
extern char *outputname; extern char *outputname;
extern int exitstatus; extern int exitstatus;
if (nerrors) { if (nerrors) {
unlink(outputname); remove(outputname);
exit(nerrors); exit(nerrors);
} }
@ -31,8 +31,7 @@ stop()
} }
/* VARARGS1 */ /* VARARGS1 */
void void fatal(char *format, ...)
fatal(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@ -42,8 +41,7 @@ fatal(char *format, ...)
} }
/* VARARGS1 */ /* VARARGS1 */
void void warning(char *format, ...)
warning(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@ -52,8 +50,7 @@ warning(char *format, ...)
} }
/* VARARGS1 */ /* VARARGS1 */
void void error(char *format, ...)
error(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@ -63,17 +60,16 @@ error(char *format, ...)
} }
/* VARARGS1 */ /* VARARGS1 */
void int do_verbose(char *format, ...)
do_verbose(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
diag((char *) 0, format, ap); diag((char *) 0, format, ap);
va_end(ap); va_end(ap);
return 1;
} }
static void static void diag(char *tail, char *format, va_list ap)
diag(char *tail, char *format, va_list ap)
{ {
extern char *progname, *archname, *modulname; extern char *progname, *archname, *modulname;

View file

@ -17,22 +17,27 @@ static char rcsid[] = "$Id$";
#include "memory.h" #include "memory.h"
#include "orig.h" #include "orig.h"
#include "scan.h" #include "scan.h"
#include "save.h"
#include "sym.h" #include "sym.h"
#include "error.h"
static void getexternal(register struct outname *);
static void get_names(register struct outhead *);
static void process(register struct outhead *);
static void redefine(register struct outname *, register struct outname *);
static void transfer(register struct outname *, register struct outname *);
static void process(register struct outhead *);
static get_names();
static process();
static getexternal();
static redefine();
static transfer();
extern ind_t savechar(); extern ind_t savechar();
extern struct orig relorig[];
void namerelocate(); void namerelocate();
/* /*
* Get section sizes and symboltable information from present module. * Get section sizes and symboltable information from present module.
*/ */
extract() void extract(void)
{ {
struct outhead head; struct outhead head;
@ -52,9 +57,7 @@ extract()
* appear in the final output file if this module is linked. * appear in the final output file if this module is linked.
* That number will be returned. * That number will be returned.
*/ */
static static void get_names(register struct outhead *head)
get_names(head)
register struct outhead *head;
{ {
register int nnames; register int nnames;
register ind_t nameindex, charindex; register ind_t nameindex, charindex;
@ -106,11 +109,9 @@ get_names(head)
} }
} }
extern struct orig relorig[];
static
process(head) static void process(register struct outhead *head)
register struct outhead *head;
{ {
register struct outsect *sects; register struct outsect *sects;
register struct outsect *outsp; register struct outsect *outsp;
@ -152,9 +153,7 @@ process(head)
* Otherwise we just add the accumulated size of all normal parts in preceding * Otherwise we just add the accumulated size of all normal parts in preceding
* sections with the same size. * sections with the same size.
*/ */
void void namerelocate(register struct outname *name)
namerelocate(name)
register struct outname *name;
{ {
register int type = name->on_type; register int type = name->on_type;
register int sct = type & S_TYP; register int sct = type & S_TYP;
@ -174,9 +173,7 @@ namerelocate(name)
* we might need it later on. Otherwise it must confirm to what we already * we might need it later on. Otherwise it must confirm to what we already
* know about it, and eventually add to that knowledge. * know about it, and eventually add to that knowledge.
*/ */
static static void getexternal(register struct outname *name)
getexternal(name)
register struct outname *name;
{ {
register char *string; register char *string;
register int h; register int h;
@ -216,9 +213,7 @@ getexternal(name)
* greatest value so that the common declared name always has enough space. * greatest value so that the common declared name always has enough space.
* If a common is defined as a not-common, the old definition is ignored. * If a common is defined as a not-common, the old definition is ignored.
*/ */
static static void redefine(register struct outname *new, register struct outname *old)
redefine(new, old)
register struct outname *new, *old;
{ {
if (!ISCOMMON(old)) { if (!ISCOMMON(old)) {
if (!ISCOMMON(new)) if (!ISCOMMON(new))
@ -244,9 +239,7 @@ redefine(new, old)
/* /*
* Transfer things we want to know from `src' to `dst'. * Transfer things we want to know from `src' to `dst'.
*/ */
static static void transfer(register struct outname *src, register struct outname *dst)
transfer(src, dst)
register struct outname *src, *dst;
{ {
debug("%s defined here\n", src->on_mptr, 0, 0, 0); debug("%s defined here\n", src->on_mptr, 0, 0, 0);
dst->on_valu = src->on_valu; dst->on_valu = src->on_valu;

View file

@ -10,21 +10,30 @@ static char rcsid[] = "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <out.h> #include "out.h"
#include "arch.h"
#include "const.h" #include "const.h"
#include "defs.h" #include "defs.h"
#include "memory.h" #include "memory.h"
#include "orig.h" #include "orig.h"
#include "scan.h" #include "scan.h"
#include "sym.h"
#include "object.h"
#include "write.h"
#include "relocate.h"
#include "extract.h"
#include "finish.h"
extern bool incore;
extern unsigned short NLocals; extern unsigned short NLocals;
extern int flagword; extern int flagword;
extern struct outname *searchname(); extern struct outname *searchname();
extern void addbase(struct outname *name);
static adjust_names(); static void adjust_names(register struct outname *, struct outhead *, register char *);
static handle_relos(); static void handle_relos(struct outhead *, struct outsect *, struct outname *);
static put_locals(); static void put_locals(struct outname *, register unsigned int);
static compute_origins(); static void compute_origins(register struct outsect *, register unsigned int);
/* /*
* We know all there is to know about the current module. * We know all there is to know about the current module.
@ -32,7 +41,7 @@ static compute_origins();
* those to the final output file. Then we compute the relative origins * those to the final output file. Then we compute the relative origins
* for the next module. * for the next module.
*/ */
finish() void finish(void)
{ {
struct outhead *head; struct outhead *head;
struct outsect *sects; struct outsect *sects;
@ -59,11 +68,8 @@ finish()
/* /*
* Adjust all local names for the move into core. * Adjust all local names for the move into core.
*/ */
static static void adjust_names(register struct outname *name, struct outhead *head, register char *chars)
adjust_names(name, head, chars)
register struct outname *name;
struct outhead *head;
register char *chars;
{ {
register int cnt; register int cnt;
register long charoff; register long charoff;
@ -81,9 +87,7 @@ adjust_names(name, head, chars)
} }
} }
do_crs(base, count) void do_crs(struct outname *base, unsigned int count)
struct outname *base;
unsigned count;
{ {
register struct outname *name = base; register struct outname *name = base;
@ -116,16 +120,14 @@ do_crs(base, count)
* the relocation table again, because the relocation entries of one section * the relocation table again, because the relocation entries of one section
* need not be consecutive. * need not be consecutive.
*/ */
static static void handle_relos(struct outhead *head, struct outsect *sects, struct outname *names)
handle_relos(head, sects, names)
struct outhead *head;
struct outsect *sects;
struct outname *names;
{ {
register struct outrelo *relo; register struct outrelo *relo;
register int sectindex; register int sectindex;
register int nrelo; register int nrelo;
register char *emit; register char *emit;
extern char *getemit();
extern struct outrelo *nextrelo();
static long zeros[MAXSECT]; static long zeros[MAXSECT];
if (incore) { if (incore) {
@ -166,6 +168,7 @@ handle_relos(head, sects, names)
long sz = sects[sectindex].os_flen; long sz = sects[sectindex].os_flen;
long sf = 0; long sf = 0;
long blksz; long blksz;
char *getblk();
emit = getblk(sz, &blksz, sectindex); emit = getblk(sz, &blksz, sectindex);
while (sz) { while (sz) {
@ -206,10 +209,8 @@ handle_relos(head, sects, names)
/* /*
* Write out the local names that must be saved. * Write out the local names that must be saved.
*/ */
static static void put_locals(struct outname *name, register unsigned int nnames)
put_locals(name, nnames)
struct outname *name;
register unsigned nnames;
{ {
register struct outname *oname = name; register struct outname *oname = name;
register struct outname *iname = oname; register struct outname *iname = oname;
@ -230,10 +231,7 @@ put_locals(name, nnames)
* Add all flen's and all (size - flen == zero)'s of preceding sections * Add all flen's and all (size - flen == zero)'s of preceding sections
* with the same number. * with the same number.
*/ */
static static void compute_origins(register struct outsect *sect, register unsigned int nsect)
compute_origins(sect, nsect)
register struct outsect *sect;
register unsigned nsect;
{ {
extern struct orig relorig[]; extern struct orig relorig[];
register struct orig *orig = relorig; register struct orig *orig = relorig;
@ -250,9 +248,7 @@ compute_origins(sect, nsect)
* Write out what is after the string area. This is likely to be * Write out what is after the string area. This is likely to be
* debugging information. * debugging information.
*/ */
static static void put_dbug(long offdbug)
put_dbug(offdbug)
long offdbug;
{ {
char buf[512]; char buf[512];
register int nbytes; register int nbytes;

View file

@ -9,8 +9,11 @@
* Values depend on the machine on which this program should run. * Values depend on the machine on which this program should run.
* Now for Vax 11/750. * Now for Vax 11/750.
*/ */
#ifndef __MACH_H_INCLUDED__
#define __MACH_H_INCLUDED__
#include <local.h>
#include "local.h"
#define K 1024L #define K 1024L
@ -49,3 +52,5 @@
mems[ALLOMODL].mem_left = 12 * K; mems[ALLOMODL].mem_left = 12 * K;
mems[ALLORANL].mem_left = 4 * K; mems[ALLORANL].mem_left = 4 * K;
#endif #endif
#endif /* __MACH_H_INCLUDED__ */

View file

@ -22,8 +22,15 @@ static char rcsid[] = "$Id$";
#include "defs.h" #include "defs.h"
#include "memory.h" #include "memory.h"
#include "orig.h" #include "orig.h"
#include "scan.h"
#include "sym.h" #include "sym.h"
#include "extract.h"
#include "error.h"
#include "output.h"
#include "finish.h"
#include "archive.h"
extern bool incore;
#ifndef NOSTATISTICS #ifndef NOSTATISTICS
int statistics; int statistics;
#endif #endif
@ -32,30 +39,29 @@ int DEB = 0;
#endif #endif
int Verbose = 0; int Verbose = 0;
static initializations(); static void initializations(int, char*[]);
static first_pass(); static void first_pass(char**);
static uint32_t number(const char *); static uint32_t number(const char *);
static void setlign(int, uint32_t); static void setlign(int, uint32_t);
static void setbase(int, uint32_t); static void setbase(int, uint32_t);
static void enterundef(const char *, int); static struct outname *makename(char*);
static pass1(); static void pass1(char*);
static evaluate(); static void evaluate(void);
static void norm_commons(); static void norm_commons();
static complete_sections(); static void complete_sections(void);
static void change_names(); static void change_names(void);
static bool setbit(); static void enterundef(const char *, int);
static bool tstbit(); static bool setbit(int, char[]);
static second_pass(); static bool tstbit(int, char[]);
static pass2(); static void second_pass(char**);
static void pass2(char*);
#ifndef NOSTATISTICS #ifndef NOSTATISTICS
static do_statistics(); static void do_statistics(void);
#endif #endif
void addbase(); void addbase(struct outname *);
main(argc, argv) int main(int argc, char **argv)
int argc;
char **argv;
{ {
initializations(argc, argv); initializations(argc, argv);
first_pass(argv); first_pass(argv);
@ -71,8 +77,7 @@ main(argc, argv)
} }
#ifndef NOSTATISTICS #ifndef NOSTATISTICS
static static void do_statistics(void)
do_statistics()
{ {
register struct memory *m = mems; register struct memory *m = mems;
@ -92,10 +97,7 @@ struct outhead outhead; /* Header of final output file. */
struct outsect outsect[MAXSECT];/* Its section table. */ struct outsect outsect[MAXSECT];/* Its section table. */
/* ARGSUSED */ /* ARGSUSED */
static static void initializations(int argc, char *argv[])
initializations(argc, argv)
int argc;
char *argv[];
{ {
/* /*
* Avoid malloc()s. * Avoid malloc()s.
@ -123,9 +125,7 @@ int exitstatus = 0;
* If the argument starts with a '-', it's a flag, else it is either * If the argument starts with a '-', it's a flag, else it is either
* a plain file to be loaded, or an archive. * a plain file to be loaded, or an archive.
*/ */
static static void first_pass(register char **argv)
first_pass(argv)
register char **argv;
{ {
register char *argp; register char *argp;
int sectno; int sectno;
@ -255,8 +255,7 @@ first_pass(argv)
* else if it starts with 0, it's octal, * else if it starts with 0, it's octal,
* else it's decimal. * else it's decimal.
*/ */
static uint32_t static uint32_t number(const char *s)
number(const char *s)
{ {
register int digit; register int digit;
register uint32_t value = 0; register uint32_t value = 0;
@ -273,7 +272,7 @@ number(const char *s)
s++; s++;
} }
} }
while (digit = *s++) { while ((digit = *s++)) {
if (digit >= 'A' && digit <= 'F') if (digit >= 'A' && digit <= 'F')
digit = digit - 'A' + 10; digit = digit - 'A' + 10;
else if (digit >= 'a' && digit <= 'f') else if (digit >= 'a' && digit <= 'f')
@ -298,13 +297,11 @@ static uint32_t sect_base[MAXSECT];
static char lignmap[MAXSECT / WIDTH]; static char lignmap[MAXSECT / WIDTH];
static uint32_t sect_lign[MAXSECT]; static uint32_t sect_lign[MAXSECT];
/*
/* /*
* Set the alignment of section `sectno' to `lign', if this doesn't * Set the alignment of section `sectno' to `lign', if this doesn't
* conflict with earlier alignment. * conflict with earlier alignment.
*/ */
static void static void setlign(int sectno, uint32_t lign)
setlign(int sectno, uint32_t lign)
{ {
extern bool setbit(); extern bool setbit();
@ -332,8 +329,7 @@ setbase(int sectno, uint32_t base)
/* /*
* Do -u name by entering the undefined name in the symbol table. * Do -u name by entering the undefined name in the symbol table.
*/ */
static void static void enterundef(const char *string, int hashval)
enterundef(const char *string, int hashval)
{ {
struct outname namebuf; struct outname namebuf;
size_t len; size_t len;
@ -364,9 +360,7 @@ enterundef(const char *string, int hashval)
* extracted. If it is an archive it is examined to see if it defines any * extracted. If it is an archive it is examined to see if it defines any
* undefined symbols. * undefined symbols.
*/ */
static static void pass1(char* file)
pass1(file)
char *file;
{ {
if (getfile(file) == PLAIN) { if (getfile(file) == PLAIN) {
debug("%s: plain file\n", file, 0, 0, 0); debug("%s: plain file\n", file, 0, 0, 0);
@ -388,8 +382,7 @@ pass1(file)
* sections. We then add the section bases to the values of names in * sections. We then add the section bases to the values of names in
* corresponding sections. * corresponding sections.
*/ */
static static void evaluate(void)
evaluate()
{ {
norm_commons(); norm_commons();
complete_sections(); complete_sections();
@ -411,8 +404,7 @@ long sect_comm[MAXSECT];
* just like "normal" names. We also count the total size of common names * just like "normal" names. We also count the total size of common names
* within each section to be able to compute the final size in the machine. * within each section to be able to compute the final size in the machine.
*/ */
static void static void norm_commons(void)
norm_commons()
{ {
register struct outname *name; register struct outname *name;
register int cnt; register int cnt;
@ -470,8 +462,7 @@ struct orig relorig[MAXSECT];
* Compute the offsets in file and machine that the sections will have. * Compute the offsets in file and machine that the sections will have.
* Also set the origins to 0. * Also set the origins to 0.
*/ */
static static void complete_sections(void)
complete_sections()
{ {
register uint32_t base = 0; register uint32_t base = 0;
register uint32_t foff; register uint32_t foff;
@ -508,8 +499,7 @@ complete_sections()
* For each name we add the base of its section to its value, unless * For each name we add the base of its section to its value, unless
* the output has to be able to be linked again, as indicated by RFLAG. * the output has to be able to be linked again, as indicated by RFLAG.
*/ */
static void static void change_names(void)
change_names()
{ {
register int cnt; register int cnt;
register struct outname *name; register struct outname *name;
@ -539,10 +529,7 @@ change_names()
* This function sets a bit with index `indx' in string. * This function sets a bit with index `indx' in string.
* It returns whether it was already set. * It returns whether it was already set.
*/ */
bool bool setbit(int indx, char string[])
setbit(indx, string)
int indx;
char string[];
{ {
register int byte_index, bit_index; register int byte_index, bit_index;
register int byte; register int byte;
@ -562,10 +549,7 @@ setbit(indx, string)
/* /*
* This function returns whether the bit given by `indx' is set in `string'. * This function returns whether the bit given by `indx' is set in `string'.
*/ */
static bool static bool tstbit(int indx, char string[])
tstbit(indx, string)
int indx;
char string[];
{ {
register int byte_index, bit_index; register int byte_index, bit_index;
register int byte; register int byte;
@ -581,9 +565,7 @@ tstbit(indx, string)
/* /*
* Add the base of the section of a name to its value. * Add the base of the section of a name to its value.
*/ */
void void addbase(struct outname *name)
addbase(name)
struct outname *name;
{ {
register int type = name->on_type & S_TYP; register int type = name->on_type & S_TYP;
register int sectindex = type - S_MIN; register int sectindex = type - S_MIN;
@ -607,9 +589,7 @@ addbase(name)
/* /*
* Flags have already been processed, so we ignore them here. * Flags have already been processed, so we ignore them here.
*/ */
static static void second_pass(char **argv)
second_pass(argv)
char **argv;
{ {
passnumber = SECOND; passnumber = SECOND;
while (*++argv) { while (*++argv) {
@ -628,9 +608,7 @@ second_pass(argv)
} }
} }
static static void pass2(char* file)
pass2(file)
char *file;
{ {
if (getfile(file) == PLAIN) { if (getfile(file) == PLAIN) {
debug("%s: plain file\n", file, 0, 0, 0); debug("%s: plain file\n", file, 0, 0, 0);

View file

@ -40,6 +40,8 @@ static char rcsid[] = "$Id$";
#include "memory.h" #include "memory.h"
#include "object.h" #include "object.h"
#include "sym.h" #include "sym.h"
#include "finish.h"
#include "write.h"
#ifndef USEMALLOC #ifndef USEMALLOC
static void copy_down(struct memory* mem, ind_t dist); static void copy_down(struct memory* mem, ind_t dist);
@ -655,8 +657,7 @@ void core_free(int piece, char* p)
* Reset index into piece of memory for modules and * Reset index into piece of memory for modules and
* take care that the allocated pieces will not be moved. * take care that the allocated pieces will not be moved.
*/ */
void void freeze_core(void)
freeze_core()
{ {
register int i; register int i;

View file

@ -4,6 +4,9 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __MEMORY_H_INCLUDED__
#define __MEMORY_H_INCLUDED__
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@ -35,6 +38,8 @@ struct memory {
}; };
extern struct memory mems[]; extern struct memory mems[];
struct outname;
#define address(piece,offset) (mems[(piece)].mem_base+(offset)) #define address(piece,offset) (mems[(piece)].mem_base+(offset))
#define modulptr(offset) (mems[ALLOMODL].mem_base+core_position+(offset)) #define modulptr(offset) (mems[ALLOMODL].mem_base+core_position+(offset))
@ -49,4 +54,7 @@ extern void dealloc(int piece);
extern char *core_alloc(int piece, size_t size); extern char *core_alloc(int piece, size_t size);
extern void core_free(int piece, char* p); extern void core_free(int piece, char* p);
extern void write_bytes(void); extern void write_bytes(void);
extern void freeze_core(void);
extern void namecpy(struct outname* name, unsigned nname, long offchar); extern void namecpy(struct outname* name, unsigned nname, long offchar);
#endif /* #ifndef __MEMORY_H_INCLUDED__ */

View file

@ -3,7 +3,11 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __ORIG_H_INCLUDED__
#define __ORIG_H_INCLUDED__
struct orig { struct orig {
long org_size; /* Accumulated length of preceding sections. */ long org_size; /* Accumulated length of preceding sections. */
}; };
#endif /* __ORIG_H_INCLUDED__ */

View file

@ -10,14 +10,19 @@ static char rcsid[] = "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <out.h> #include "out.h"
#include "object.h"
#include "const.h" #include "const.h"
#include "output.h"
#include "memory.h" #include "memory.h"
#include "error.h"
#include "write.h"
#include "sym.h" #include "sym.h"
static void generate_section_names(); static void generate_section_names(void);
extern struct outhead outhead; extern struct outhead outhead;
extern bool incore;
extern int flagword; extern int flagword;
/* /*
@ -26,7 +31,7 @@ extern int flagword;
* flag was given. * flag was given.
* If this flag is given we don't need the string table either. * If this flag is given we don't need the string table either.
*/ */
beginoutput() void beginoutput(void)
{ {
extern long NLChars, NGChars; extern long NLChars, NGChars;
extern char *outputname; extern char *outputname;
@ -54,8 +59,7 @@ beginoutput()
* Generate names for all sections and put them after the global names. * Generate names for all sections and put them after the global names.
* Section names are used for relocation. * Section names are used for relocation.
*/ */
static void static void generate_section_names(void)
generate_section_names()
{ {
register struct outname *name; register struct outname *name;
register int sectindex; register int sectindex;
@ -80,7 +84,7 @@ generate_section_names()
* written out, and we just finish that. * written out, and we just finish that.
* If we did, we write out our pieces of core. * If we did, we write out our pieces of core.
*/ */
endoutput() void endoutput(void)
{ {
if (!incore) { if (!incore) {
if (!(flagword & SFLAG)) if (!(flagword & SFLAG))

View file

@ -10,10 +10,11 @@ static char rcsid[] = "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "error.h"
int infile; /* The current input file. */ int infile; /* The current input file. */
rd_fatal() void rd_fatal(void)
{ {
fatal("read error"); fatal("read error");
} }

View file

@ -17,6 +17,7 @@ static char rcsid[] = "$Id$";
#include "defs.h" #include "defs.h"
#include "orig.h" #include "orig.h"
#include "sym.h" #include "sym.h"
#include "relocate.h"
#define UBYTE(x) ((x)&BYTEMASK) #define UBYTE(x) ((x)&BYTEMASK)
@ -443,7 +444,7 @@ static void put_mips_valu(char* addr, uint32_t value)
* significance should be attributed to each byte. * significance should be attributed to each byte.
* We do not check for overflow. * We do not check for overflow.
*/ */
static putvalu(uint32_t valu, char* addr, uint16_t type) static void putvalu(uint32_t valu, char* addr, uint16_t type)
{ {
switch (type & RELSZ) switch (type & RELSZ)
@ -547,11 +548,7 @@ long* valu_out; /* Out variable. */
* which the header is pointed to by `head'. Relocation is relative to the * which the header is pointed to by `head'. Relocation is relative to the
* names in `names'; `relo' tells how to relocate. * names in `names'; `relo' tells how to relocate.
*/ */
relocate(head, emit, names, relo, off) struct outhead* head; void relocate(struct outhead *head, char* emit, struct outname names[], struct outrelo *relo, long off)
char* emit;
struct outname names[];
struct outrelo* relo;
long off;
{ {
long valu; long valu;
int sectindex = relo->or_sect - S_MIN; int sectindex = relo->or_sect - S_MIN;

View file

@ -17,51 +17,51 @@ static char rcsid[] = "$Id$";
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include "arch.h" #include "arch.h"
#include "save.h"
#include "out.h" #include "out.h"
#include "const.h" #include "const.h"
#include "memory.h" #include "memory.h"
void extern bool incore;
savemagic() extern char *core_alloc();
long NLChars = 0; /* Size of string area for local names. */
long NGChars = 0; /* Idem for global names. */
void savemagic(void)
{ {
register char *p; register char *p;
if (!incore) if (!incore)
return; return;
if ((p = core_alloc(ALLOMODL, sizeof(int))) != (char *)0) { if ((p = core_alloc(ALLOMODL, (long)sizeof(int))) != (char *)0) {
*(unsigned short *)p = AALMAG; *(unsigned short *)p = AALMAG;
core_position += sizeof(int); core_position += sizeof(int);
} }
} }
void void savehdr(struct ar_hdr *hdr)
savehdr(hdr)
struct ar_hdr *hdr;
{ {
register char *p; register char *p;
if (!incore) if (!incore)
return; return;
if ((p=core_alloc(ALLOMODL, sizeof(struct ar_hdr)))!=(char *)0) { if ((p=core_alloc(ALLOMODL,(long)sizeof(struct ar_hdr)))!=(char *)0) {
*(struct ar_hdr *)p = *hdr; *(struct ar_hdr *)p = *hdr;
core_position += int_align(sizeof(struct ar_hdr)); core_position += int_align(sizeof(struct ar_hdr));
} }
} }
long NLChars = 0; /* Size of string area for local names. */
long NGChars = 0; /* Idem for global names. */
/* /*
* Put the string in cp into the block allocated for the string area. * Put the string in cp into the block allocated for the string area.
* Return its offset in this area. We don't use the first char of the string * Return its offset in this area. We don't use the first char of the string
* area, so that empty strings can be distinguished from the first string. * area, so that empty strings can be distinguished from the first string.
*/ */
ind_t ind_t savechar(register int piece, register ind_t off)
savechar(piece, off)
register int piece;
register ind_t off;
{ {
register size_t len; register size_t len;
register ind_t newoff; register ind_t newoff;
@ -90,9 +90,7 @@ savechar(piece, off)
* allocation, but the string of which name->on_foff is the offset may be * allocation, but the string of which name->on_foff is the offset may be
* destroyed, so we save that first. * destroyed, so we save that first.
*/ */
void void savelocal(struct outname *name)
savelocal(name)
struct outname *name;
{ {
ind_t savindex; ind_t savindex;
struct outname *new; struct outname *new;
@ -101,7 +99,7 @@ savelocal(name)
return; return;
new = (struct outname *) new = (struct outname *)
core_alloc(ALLOLOCL, sizeof(struct outname)); core_alloc(ALLOLOCL, (long)sizeof(struct outname));
if (new != (struct outname *)0) { if (new != (struct outname *)0) {
*new = *name; *new = *name;
new->on_foff = savindex; new->on_foff = savindex;

View file

@ -35,7 +35,7 @@ static char rcsid[] = "$Id$";
#define IND_DBUG(x) (IND_RELO(x) + sizeof(ind_t)) #define IND_DBUG(x) (IND_RELO(x) + sizeof(ind_t))
#endif /* SYMDBUG */ #endif /* SYMDBUG */
extern int infile; extern FILE* infile;
extern int passnumber; extern int passnumber;
char *archname; /* Name of archive, if reading from archive. */ char *archname; /* Name of archive, if reading from archive. */
@ -66,9 +66,7 @@ static void scan_modul(void);
* In case of a plain file, the file pointer is repositioned after the * In case of a plain file, the file pointer is repositioned after the
* examination. Otherwise it is at the beginning of the table of contents. * examination. Otherwise it is at the beginning of the table of contents.
*/ */
int int getfile(char* filename)
getfile(filename)
char *filename;
{ {
unsigned int rd_unsigned2(); unsigned int rd_unsigned2();
struct ar_hdr archive_header; struct ar_hdr archive_header;
@ -81,7 +79,7 @@ getfile(filename)
modulname = (char *)0; modulname = (char *)0;
if (passnumber == FIRST || !incore) { if (passnumber == FIRST || !incore) {
if ((infile = open(filename, READ)) < 0) if ((infile = fopen(filename, "rb")) == NULL)
fatal("can't read %s", filename); fatal("can't read %s", filename);
magic_number = rd_unsigned2(infile); magic_number = rd_unsigned2(infile);
} else { } else {
@ -122,7 +120,7 @@ getfile(filename)
void closefile(char* filename) void closefile(char* filename)
{ {
if (passnumber == FIRST || !incore) if (passnumber == FIRST || !incore)
close(infile); fclose(infile);
} }
void get_archive_header(struct ar_hdr* archive_header) void get_archive_header(struct ar_hdr* archive_header)
@ -156,8 +154,7 @@ void get_modul(void)
* to keep everything in core is abandoned, but we will always put the header, * to keep everything in core is abandoned, but we will always put the header,
* the section table, and the name and string table into core. * the section table, and the name and string table into core.
*/ */
static void static void scan_modul(void)
scan_modul(void)
{ {
bool space; bool space;
struct outhead *head; struct outhead *head;
@ -188,8 +185,7 @@ scan_modul(void)
* If possible, allocate space for the rest of the module. Return whether * If possible, allocate space for the rest of the module. Return whether
* this was possible. * this was possible.
*/ */
static bool static bool all_alloc(void)
all_alloc(void)
{ {
struct outhead head; struct outhead head;
@ -208,9 +204,7 @@ all_alloc(void)
* First allocate the section table and read it in, then allocate the rest * First allocate the section table and read it in, then allocate the rest
* and return whether this succeeded. * and return whether this succeeded.
*/ */
static bool static bool direct_alloc(struct outhead *head)
direct_alloc(head)
struct outhead *head;
{ {
ind_t sectindex = IND_SECT(*head); ind_t sectindex = IND_SECT(*head);
register struct outsect *sects; register struct outsect *sects;
@ -245,9 +239,7 @@ direct_alloc(head)
* Allocate space for the indirectly accessed pieces: the section contents and * Allocate space for the indirectly accessed pieces: the section contents and
* the relocation table, and put their indices in the right place. * the relocation table, and put their indices in the right place.
*/ */
static bool static bool indirect_alloc(struct outhead *head)
indirect_alloc(head)
struct outhead *head;
{ {
register int allopiece; register int allopiece;
unsigned short nsect = head->oh_nsect; unsigned short nsect = head->oh_nsect;
@ -283,8 +275,7 @@ indirect_alloc(head)
* at offset `sectindex'. Put the offset of the allocated piece at offset * at offset `sectindex'. Put the offset of the allocated piece at offset
* `emitoff'. * `emitoff'.
*/ */
static bool static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
{ {
long flen; long flen;
ind_t emitindex; ind_t emitindex;
@ -358,8 +349,7 @@ putdbugindex(ind_t dbugoff, size_t ndbugbytes)
* Compute addresses and read in. Remember that the contents of the sections * Compute addresses and read in. Remember that the contents of the sections
* and also the relocation table are accessed indirectly. * and also the relocation table are accessed indirectly.
*/ */
static void static void get_indirect(struct outhead* head, struct outsect* sect)
get_indirect(struct outhead* head, struct outsect* sect)
{ {
register ind_t *emitindex; register ind_t *emitindex;
register int nsect; register int nsect;
@ -385,7 +375,7 @@ get_indirect(struct outhead* head, struct outsect* sect)
void seek(long pos) void seek(long pos)
{ {
if (passnumber == FIRST || !incore) if (passnumber == FIRST || !incore)
lseek(infile, pos, 0); fseek(infile, pos, SEEK_SET);
} }
/* /*
@ -410,8 +400,7 @@ void skip_modul(struct outhead* head)
/* /*
* Read in what we need in pass 2, because we couldn't keep it in core. * Read in what we need in pass 2, because we couldn't keep it in core.
*/ */
static void static void read_modul(void)
read_modul(void)
{ {
struct outhead *head; struct outhead *head;
register struct outsect *sects; register struct outsect *sects;
@ -544,11 +533,7 @@ struct outrelo* nextrelo(void)
* Get the section contents in core of which the describing struct has index * Get the section contents in core of which the describing struct has index
* `sectindex'. `Head' points to the header of the module. * `sectindex'. `Head' points to the header of the module.
*/ */
char * char *getemit(struct outhead *head, struct outsect *sects, int sectindex)
getemit(head, sects, sectindex)
struct outhead *head;
struct outsect *sects;
int sectindex;
{ {
char *ret; char *ret;
ind_t off; ind_t off;
@ -573,11 +558,7 @@ getemit(head, sects, sectindex)
return address(ALLOEMIT + sectindex, off); return address(ALLOEMIT + sectindex, off);
} }
char * char *getblk(long totalsz, long *pblksz, int sectindex)
getblk(totalsz, pblksz, sectindex)
long totalsz;
long *pblksz;
int sectindex;
{ {
char *ret; char *ret;
long sz = (1L << 30); long sz = (1L << 30);
@ -596,7 +577,7 @@ getblk(totalsz, pblksz, sectindex)
sz >>= 1; sz >>= 1;
} }
fatal("no space for section contents"); fatal("no space for section contents");
return (char *) 0; return (char *) NULL;
} }
void endemit(char* emit) void endemit(char* emit)

View file

@ -4,6 +4,11 @@
*/ */
/* $Id$ */ /* $Id$ */
#ifndef __SCAN_H_INCLUDED__
#define __SCAN_H_INCLUDED__
#include "arch.h"
/* /*
* Offsets of the pieces of the input module in core. * Offsets of the pieces of the input module in core.
*/ */
@ -26,3 +31,12 @@ extern struct outrelo* nextrelo(void);
extern char* getemit(struct outhead* head, struct outsect* sects, int sectindex); extern char* getemit(struct outhead* head, struct outsect* sects, int sectindex);
extern char* getblk(long totalsz, long* pblksz, int sectindex); extern char* getblk(long totalsz, long* pblksz, int sectindex);
extern void endemit(char* emit); extern void endemit(char* emit);
/*
* Open the file with name `filename' (if necessary) and examine the first
* few bytes to see if it's a plain file or an archive.
* In case of a plain file, the file pointer is repositioned after the
* examination. Otherwise it is at the beginning of the table of contents.
*/
int getfile(char* filename);
#endif /* __SCAN_H_INCLUDED__ */

View file

@ -16,6 +16,7 @@ static char rcsid[] = "$Id$";
#include <stdbool.h> #include <stdbool.h>
#include "out.h" #include "out.h"
#include "const.h" #include "const.h"
#include "error.h"
#include "memory.h" #include "memory.h"
#include "debug.h" #include "debug.h"
#include "sym.h" #include "sym.h"
@ -41,7 +42,7 @@ unsigned short NGlobals = 0; /* Number of global names. */
/* /*
* Initialize the symbol table. All indices should be noticeably invalid. * Initialize the symbol table. All indices should be noticeably invalid.
*/ */
init_symboltable() void init_symboltable(void)
{ {
register ind_t *rap; register ind_t *rap;
@ -56,10 +57,7 @@ init_symboltable()
* in this element of the list is returned. When a match cannot be found, * in this element of the list is returned. When a match cannot be found,
* NIL is returned. * NIL is returned.
*/ */
struct outname * struct outname *searchname(char *string, int hashval)
searchname(string, hashval)
char *string;
int hashval;
{ {
register char *rcp; register char *rcp;
register char *namestring; register char *namestring;
@ -105,9 +103,9 @@ void entername(struct outname* name, int hashval)
debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc); debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc);
savindex = savechar(ALLOGCHR, (ind_t)name->on_foff); savindex = savechar(ALLOGCHR, (ind_t)name->on_foff);
symindex = hard_alloc(ALLOSYMB, sizeof(struct symbol)); symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol));
debug("; %ld\n", symindex, 0, 0, 0); debug("; %ld\n", symindex, 0, 0, 0);
namindex = hard_alloc(ALLOGLOB, sizeof(struct outname)); namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname));
if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF) if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF)
fatal("symbol table overflow"); fatal("symbol table overflow");
sym = (struct symbol *)address(ALLOSYMB, symindex); sym = (struct symbol *)address(ALLOSYMB, symindex);
@ -124,9 +122,7 @@ void entername(struct outname* name, int hashval)
* Return the index of `name' in the symbol table in the order in which * Return the index of `name' in the symbol table in the order in which
* it was entered. We need a REAL index, not a byte offset. * it was entered. We need a REAL index, not a byte offset.
*/ */
unsigned unsigned int indexof(struct outname *name)
indexof(name)
struct outname *name;
{ {
return name - (struct outname *)address(ALLOGLOB, (ind_t)0); return name - (struct outname *)address(ALLOGLOB, (ind_t)0);
} }
@ -136,9 +132,7 @@ indexof(name)
* 0 <= hash(p) < NHASH, so it can - and will - be used * 0 <= hash(p) < NHASH, so it can - and will - be used
* as index in a hash table. * as index in a hash table.
*/ */
int int hash(register char* p)
hash(p)
register char *p;
{ {
register unsigned short h = 0; register unsigned short h = 0;
register int c; register int c;

View file

@ -1,9 +1,27 @@
#ifndef SYM_H
#define SYM_H #ifndef __SYM_H_INCLUDED__
#define __SYM_H_INCLUDED__
extern unsigned short NLocals; /* Number of local names to be saved. */ extern unsigned short NLocals; /* Number of local names to be saved. */
extern unsigned short NGlobals; /* Number of global names. */ extern unsigned short NGlobals; /* Number of global names. */
extern void entername(struct outname* name, int hashval); /** Enter a new name in the symbol table.*/
void entername(struct outname* name, int hashval);
/** Initialize the symbol table. All indices should be noticeably invalid. */
void init_symboltable(void);
/** Return the hash value of the string represented in p. */
int hash(register char* p);
/** Return the index of `name' in the symbol table. */
unsigned int indexof(struct outname *name);
/*
* Search for `string' in the symboltable. The hash value of `string' is in
* `hashval'. The linked list belonging to the entry of hashval
* in the hash table is followed. If the names match, a pointer to the outname
* in this element of the list is returned. When a match cannot be found,
* NIL is returned.
*/
struct outname *searchname(char *string, int hashval);
#endif
#endif /* __SYM_H_INCLUDED__ */

View file

@ -13,26 +13,32 @@ static char rcsid[] = "$Id$";
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include "out.h" #include "out.h"
#include "object.h"
#include "const.h" #include "const.h"
#include "memory.h" #include "memory.h"
#include "sym.h" #include "sym.h"
#include "error.h"
#include "write.h"
extern struct outhead outhead; extern struct outhead outhead;
extern struct outsect outsect[]; extern struct outsect outsect[];
extern int flagword; extern int flagword;
extern bool incore;
wr_fatal() static long off_char;
void wr_fatal(void)
{ {
fatal("write error"); fatal("write error");
} }
static long off_char;
/* /*
* Open the output file according to the chosen strategy. * Open the output file according to the chosen strategy.
* Write away the header and section table: they will not change anymore. * Write away the header and section table: they will not change anymore.
*/ */
begin_write() void begin_write(void)
{ {
register struct outhead *hd = &outhead; register struct outhead *hd = &outhead;
@ -42,9 +48,7 @@ begin_write()
off_char = OFF_CHAR(*hd); off_char = OFF_CHAR(*hd);
} }
static struct outname * static struct outname *sectname(int sectindex)
sectname(sectindex)
int sectindex;
{ {
static struct outname namebuf; static struct outname namebuf;
@ -59,7 +63,7 @@ sectname(sectindex)
/* /*
* Write out the symbol table and the section names. * Write out the symbol table and the section names.
*/ */
end_write() void end_write(void)
{ {
register struct outname *name; register struct outname *name;
register int sectindex; register int sectindex;
@ -77,18 +81,14 @@ end_write()
wrt_name(sectname(sectindex), 1); wrt_name(sectname(sectindex), 1);
} }
wrt_emit(emit, sectindex, cnt) void wrt_emit(char *emit, int sectindex, long cnt)
char *emit;
int sectindex;
long cnt;
{ {
wr_outsect(sectindex); wr_outsect(sectindex);
wr_emit(emit, cnt); wr_emit(emit, cnt);
} }
wrt_nulls(sectindex, cnt) void wrt_nulls(int sectindex, register long cnt)
register long cnt;
{ {
static char nullbuf[BUFSIZ]; static char nullbuf[BUFSIZ];
@ -100,8 +100,7 @@ wrt_nulls(sectindex, cnt)
} }
} }
wrt_name(name, writename) void wrt_name(register struct outname *name, int writename)
register struct outname *name;
{ {
assert(!incore); assert(!incore);
assert(!(flagword & SFLAG)); assert(!(flagword & SFLAG));