diff options
author | Robert de Bath <rdebath@poboxes.com> | 2002-01-12 20:42:42 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:48:46 +0200 |
commit | d91fa39567f5659e3931cf61517d62fddcd87570 (patch) | |
tree | 20583acd4f345a4f5c9a7772870ef972cb8a3b14 /as | |
parent | bff547eabb6678ec8e71ffbcfbf9a4f05c94d949 (diff) | |
download | dev86-d91fa39567f5659e3931cf61517d62fddcd87570.tar.gz |
Import Dev86src-0.16.1.tar.gzv0.16.1
Diffstat (limited to 'as')
-rw-r--r-- | as/Makefile | 4 | ||||
-rw-r--r-- | as/alloc.c | 100 | ||||
-rw-r--r-- | as/as.c | 28 | ||||
-rw-r--r-- | as/assemble.c | 2 | ||||
-rw-r--r-- | as/const.h | 119 | ||||
-rw-r--r-- | as/error.c | 102 | ||||
-rw-r--r-- | as/errors.c | 107 | ||||
-rw-r--r-- | as/errors.h | 105 | ||||
-rw-r--r-- | as/express.c | 12 | ||||
-rw-r--r-- | as/genbin.c | 6 | ||||
-rw-r--r-- | as/genlist.c | 57 | ||||
-rw-r--r-- | as/genobj.c | 27 | ||||
-rw-r--r-- | as/gensym.c | 25 | ||||
-rw-r--r-- | as/globvar.h | 4 | ||||
-rw-r--r-- | as/keywords.c | 8 | ||||
-rw-r--r-- | as/macro.c | 44 | ||||
-rw-r--r-- | as/mops.c | 26 | ||||
-rw-r--r-- | as/opcode.h | 2 | ||||
-rw-r--r-- | as/pops.c | 12 | ||||
-rw-r--r-- | as/proto.h | 19 | ||||
-rw-r--r-- | as/readsrc.c | 9 | ||||
-rw-r--r-- | as/scan.c | 4 | ||||
-rw-r--r-- | as/scan.h | 2 | ||||
-rw-r--r-- | as/table.c | 14 | ||||
-rw-r--r-- | as/type.h | 1 | ||||
-rw-r--r-- | as/typeconv.c | 4 |
26 files changed, 483 insertions, 360 deletions
diff --git a/as/Makefile b/as/Makefile index bc62091..4dedc8d 100644 --- a/as/Makefile +++ b/as/Makefile @@ -4,10 +4,10 @@ LDFLAGS=-s LIBDIR=/usr/bin BINDIR=/usr/bin -OBJS =as.o assemble.o error.o express.o \ +OBJS =as.o assemble.o errors.o express.o \ genbin.o genlist.o genobj.o gensym.o \ keywords.o macro.o mops.o pops.o readsrc.o \ - scan.o table.o typeconv.o + scan.o table.o typeconv.o alloc.o all: as86 as86_encap diff --git a/as/alloc.c b/as/alloc.c new file mode 100644 index 0000000..6f64ccc --- /dev/null +++ b/as/alloc.c @@ -0,0 +1,100 @@ + +#include "syshead.h" +#include "const.h" +#include "type.h" +#include "align.h" + +PRIVATE char NOMEMEORY[] = "Cannot allocate sufficient memory"; + +#ifdef USE_FIXED_HEAP +PRIVATE char *heapend; /* end of free space for symbol list */ +PRIVATE char *heapptr; /* next free space in symbol list */ +#endif + +#ifndef USE_FIXED_HEAP +PRIVATE char tempbuf[2048]; +#endif + +void +init_heap() +{ +#ifdef USE_FIXED_HEAP +#ifndef USERMEM +#define USERMEM (unsigned) 0xAC00U +#endif + +#ifdef __AS386_16__ + heapptr = sbrk(0); + heapend = ((char*)&argc) - STAKSIZ - 16; + brk(heapend); + if(sbrk(0) != heapend) + as_abort(NOMEMEORY); +#else +#ifdef SOS_EDOS + heapend = stackreg() - STAKSIZ; +#else + heapptr = malloc(USERMEM); + heapend = heapptr + USERMEM; + if (heapptr == 0) + as_abort(NOMEMEORY); +#endif +#endif +#endif +} + +void * temp_buf() +{ +#ifdef USE_FIXED_HEAP + return heapptr; +#else + return tempbuf; +#endif +} + +void * +asalloc(size) +unsigned int size; +{ + void * rv; +#ifdef USE_FIXED_HEAP + align(heapptr); + if (heapptr+size < heapend) + { + rv = heapptr; + heapptr += size; + } + else + rv = 0; +#else + rv = malloc(size); +#endif + + if (rv == 0) as_abort(NOMEMEORY); + return rv; +} + + +void * +asrealloc(oldptr, size) +void * oldptr; +unsigned int size; +{ + void * rv; +#ifdef USE_FIXED_HEAP + if (oldptr == 0) return asalloc(size); + + if ((char*)oldptr+size < heapend) + { + heapptr = oldptr + size; + rv = oldptr; + } + else + rv = 0; +#else + rv = realloc(oldptr, size); +#endif + + if (rv == 0) as_abort(NOMEMEORY); + return rv; +} + @@ -32,30 +32,11 @@ FORWARD void summary P((fd_t fd)); FORWARD void summ_number P((unsigned num)); FORWARD void usage P((void)); -#ifndef USERMEM -#define USERMEM (sizeof(int) <= 2 ? (unsigned) 0xAC00 : (unsigned) 0x28000L) -#endif - PUBLIC int main(argc, argv) int argc; char **argv; { -#ifdef __AS386_16__ - heapptr = sbrk(0); - heapend = ((char*)&argc) - STAKSIZ - 16; - brk(heapend); - if(sbrk(0) != heapend) - as_abort("Cannot allocate memory"); -#else -#ifdef SOS_EDOS - heapend = stackreg() - STAKSIZ; -#else - heapptr = malloc(USERMEM); - heapend = heapptr + USERMEM; - if (heapptr == 0) - as_abort("cannot allocate memory"); -#endif -#endif + init_heap(); initp1(); initp1p2(); inst_keywords(); @@ -321,9 +302,10 @@ int fd; PRIVATE void summ_number(num) unsigned num; { - /* format number like line numbers, build it at free spot heapptr */ - *build_number(num, LINUM_LEN, heapptr) = 0; - writes(heapptr); + /* format number like line numbers */ + char buf[16]; + *build_number(num, LINUM_LEN, buf) = 0; + writes(buf); } PRIVATE void usage() diff --git a/as/assemble.c b/as/assemble.c index 175d5cc..5af954e 100644 --- a/as/assemble.c +++ b/as/assemble.c @@ -38,7 +38,9 @@ PRIVATE pfv rout_table[] = pfcb, pfcc, pfdb, +#if SIZEOF_OFFSET_T > 2 pfqb, +#endif pget, pglobl, pident, @@ -7,14 +7,14 @@ #define S_ALIGNMENT sizeof(long) #endif -#include "align.h" - /* const.h - constants for assembler */ /* major switches */ +/* #define MC6809 */ /* generate 6809 code */ +#ifndef MC6809 #define I80386 /* generate 80386 code */ -#undef MC6809 /* generate 6809 code */ +#endif #define MNSIZE /* allow byte size in mnemonic, e.g. "movb" */ #undef SOS_EDOS /* source OS is EDOS */ @@ -215,116 +215,6 @@ enum COLON }; -enum -{ -/* Error codes. */ - -/* Syntax errors. */ - COMEXP, - DELEXP, - FACEXP, - IREGEXP, - LABEXP, - LPEXP, - OPEXP, - RBEXP, - REGEXP, - RPEXP, - SPEXP, - -/* Expression errors. */ - ABSREQ, - NONIMPREQ, - RELBAD, - -/* Label errors. */ - ILLAB, - MACUID, - MISLAB, - MNUID, - REGUID, - RELAB, - UNBLAB, - UNLAB, - VARLAB, - -/* Addressing errors. */ - ABOUNDS, - DBOUNDS, - ILLMOD, - ILLREG, - -/* Control structure errors. */ - ELSEBAD, -#define ELSEIFBAD ELSEBAD - ENDBBAD, -#define ENDIFBAD ELSEBAD - EOFBLOCK, - EOFIF, - EOFLC, - EOFMAC, - FAILERR, - -/* Overflow errors. */ - BLOCKOV, - BWRAP, - COUNTOV, - COUNTUN, - GETOV, - IFOV, - - LINLONG, - MACOV, - OBJSYMOV, - OWRITE, - PAROV, - SYMOV, - SYMOUTOV, - -/* I/O errors. */ - OBJOUT, - -/* Miscellaneous errors. */ - AL_AX_EAX_EXP, - CTLINS, - FURTHER, - ILL_IMM_MODE, - ILL_IND_TO_IND, - ILL_IND, - ILL_IND_PTR, - ILL_SCALE, - ILL_SECTION, - ILL_SEG_REG, - ILL_SOURCE_EA, - ILL_SIZE, - IMM_REQ, - INDEX_REG_EXP, - IND_REQ, - MISMATCHED_SIZE, - NOIMPORT, - REENTER, - REL_REQ, - REPEATED_DISPL, - SEGREL, - SEG_REG_REQ, - SIZE_UNK, - UNKNOWN_ESCAPE_SEQUENCE, - - FP_REG_REQ, - FP_REG_NOT_ALLOWED, - ILL_FP_REG, - ILL_FP_REG_PAIR, - JUNK_AFTER_OPERANDS, - - ALREADY, - UNSTABLE_LABEL, - -/* Warnings. */ -#define MINWARN CPUCLASH - CPUCLASH, - SHORTB -}; - /* symbol table entry */ /* type entry contains following flags */ @@ -423,3 +313,6 @@ oops - ENTBIT misplaced #define DPLOC 2 #define STRLOC 1 #define TEXTLOC 0 + +#include "errors.h" + diff --git a/as/error.c b/as/error.c deleted file mode 100644 index 3088ec4..0000000 --- a/as/error.c +++ /dev/null @@ -1,102 +0,0 @@ -/* error.c - error routines for assembler */ - -#include "syshead.h" -#include "const.h" -#include "type.h" - -PRIVATE char *errormessage[] = -{ - "comma expected", - "delimiter expected", - "factor expected", - "index register expected", - "label expected", - "left parentheses expected", - "opcode expected", - "right bracket expected", - "register expected", - "right parentheses expected", - "space expected", - "absolute expression required", - "non-imported expression required", - "relocation impossible", - "illegal label", - "MACRO used as identifier", - "missing label", - "opcode used as identifier", - "register used as identifier", - "redefined label", - "unbound label", - "undefined label", - "variable used as label", - "address out of bounds", - "data out of bounds", - "illegal address mode", - "illegal register", - "no matching IF", - "no matching BLOCK", - "end of file in BLOCK", - "end of file in IF", - "location counter was undefined at end", - "end of file in MACRO", - "user-generated error", - "BLOCK stack overflow", - "binary file wrap-around", - "counter overflow", - "counter underflow", - "GET stack overflow", - "IF stack overflow", - "line too long", - "MACRO stack overflow", - "object symbol table overflow", - "program overwrite", - "parameter table overflow", - "symbol table overflow", - "output symbol table overflow", - "error writing object file", - "al, ax or eax expected", - "control character in string", - "futher errors suppressed", - "illegal immediate mode", - "illegal indirect to indirect", - "illegal indirection", - "illegal indirection from previous 'ptr'", - "illegal scale", - "illegal section", - "illegal segment register", - "illegal source effective address", - "illegal size", - "immediate expression expected", - "index register expected", - "indirect expression required", - "mismatched size", - "no imports with binary file output", - "multiple ENTER pseudo-ops", - "relative expression required", - "repeated displacement", - "segment or relocatability redefined", - "segment register required", - "size unknown", - "unknown escape sequence", - "FP register required", - "FP register not allowed", - "illegal FP register", - "illegal FP register pair", - "junk after operands", - "already defined", - "label moved in last pass, add -O?", - "instruction illegal for current cpu", - "short branch would do", - "unknown error", -}; - -/* build null-terminated error message for given error at given spot */ - -PUBLIC char *build_error_message(errnum, buf) -error_pt errnum; -char *buf; -{ - if (errnum >= sizeof errormessage / sizeof errormessage[0]) - errnum = sizeof errormessage / sizeof errormessage[0] - 1; - return strcpy(buf, errormessage[errnum]); -} diff --git a/as/errors.c b/as/errors.c new file mode 100644 index 0000000..0f2558a --- /dev/null +++ b/as/errors.c @@ -0,0 +1,107 @@ + +#include "syshead.h" +#include "const.h" + +/* Error codes. */ + +/* Syntax errors. */ +PUBLIC char * COMEXP = "comma expected"; +PUBLIC char * DELEXP = "delimiter expected"; +PUBLIC char * FACEXP = "factor expected"; +PUBLIC char * IREGEXP = "index register expected"; +PUBLIC char * LABEXP = "label expected"; +PUBLIC char * LPEXP = "left parentheses expected"; +PUBLIC char * OPEXP = "opcode expected"; +PUBLIC char * RBEXP = "right bracket expected"; +PUBLIC char * REGEXP = "register expected"; +PUBLIC char * RPEXP = "right parentheses expected"; +PUBLIC char * SPEXP = "space expected"; + +/* Expression errors. */ +PUBLIC char * ABSREQ = "absolute expression required"; +PUBLIC char * NONIMPREQ = "non-imported expression required"; +PUBLIC char * RELBAD = "relocation impossible"; + +/* Label errors. */ +PUBLIC char * ILLAB = "illegal label"; +PUBLIC char * MACUID = "MACRO used as identifier"; +PUBLIC char * MISLAB = "missing label"; +PUBLIC char * MNUID = "opcode used as identifier"; +PUBLIC char * REGUID = "register used as identifier"; +PUBLIC char * RELAB = "redefined label"; +PUBLIC char * UNBLAB = "unbound label"; +PUBLIC char * UNLAB = "undefined label"; +PUBLIC char * VARLAB = "variable used as label"; + +/* Addressing errors. */ +PUBLIC char * ABOUNDS = "address out of bounds"; +PUBLIC char * DBOUNDS = "data out of bounds"; +PUBLIC char * ILLMOD = "illegal address mode"; +PUBLIC char * ILLREG = "illegal register"; + +/* Control structure errors. */ +PUBLIC char * ELSEBAD = "no matching IF"; +PUBLIC char * ENDBBAD = "no matching BLOCK"; +PUBLIC char * EOFBLOCK = "end of file in BLOCK"; +PUBLIC char * EOFIF = "end of file in IF"; +PUBLIC char * EOFLC = "location counter was undefined at end"; +PUBLIC char * EOFMAC = "end of file in MACRO"; +PUBLIC char * FAILERR = "user-generated error"; + +/* Overflow errors. */ +PUBLIC char * BLOCKOV = "BLOCK stack overflow"; +PUBLIC char * BWRAP = "binary file wrap-around"; +PUBLIC char * COUNTOV = "counter overflow"; +PUBLIC char * COUNTUN = "counter underflow"; +PUBLIC char * GETOV = "GET stack overflow"; +PUBLIC char * IFOV = "IF stack overflow"; + +PUBLIC char * LINLONG = "line too long"; +PUBLIC char * MACOV = "MACRO stack overflow"; +PUBLIC char * OBJSYMOV = "object symbol table overflow"; +PUBLIC char * OWRITE = "program overwrite"; +PUBLIC char * PAROV = "parameter table overflow"; +PUBLIC char * SYMOV = "symbol table overflow"; +PUBLIC char * SYMOUTOV = "output symbol table overflow"; + +/* I/O errors. */ +PUBLIC char * OBJOUT = "error writing object file"; + +/* Miscellaneous errors. */ +PUBLIC char * AL_AX_EAX_EXP = "al ax or eax expected"; +PUBLIC char * CTLINS = "control character in string"; +PUBLIC char * FURTHER = "futher errors suppressed"; +PUBLIC char * ILL_IMM_MODE = "illegal immediate mode"; +PUBLIC char * ILL_IND_TO_IND = "illegal indirect to indirect"; +PUBLIC char * ILL_IND = "illegal indirection"; +PUBLIC char * ILL_IND_PTR = "illegal indirection from previous 'ptr'"; +PUBLIC char * ILL_SCALE = "illegal scale"; +PUBLIC char * ILL_SECTION = "illegal section"; +PUBLIC char * ILL_SEG_REG = "illegal segment register"; +PUBLIC char * ILL_SOURCE_EA = "illegal source effective address"; +PUBLIC char * ILL_SIZE = "illegal size"; +PUBLIC char * IMM_REQ = "immediate expression expected"; +PUBLIC char * INDEX_REG_EXP = "index register expected"; +PUBLIC char * IND_REQ = "indirect expression required"; +PUBLIC char * MISMATCHED_SIZE = "mismatched size"; +PUBLIC char * NOIMPORT = "no imports with binary file output"; +PUBLIC char * REENTER = "multiple ENTER pseudo-ops"; +PUBLIC char * REL_REQ = "relative expression required"; +PUBLIC char * REPEATED_DISPL = "repeated displacement"; +PUBLIC char * SEGREL = "segment or relocatability redefined"; +PUBLIC char * SEG_REG_REQ = "segment register required"; +PUBLIC char * SIZE_UNK = "size unknown"; +PUBLIC char * UNKNOWN_ESCAPE_SEQUENCE = "unknown escape sequence"; + +PUBLIC char * FP_REG_REQ = "FP register required"; +PUBLIC char * FP_REG_NOT_ALLOWED = "FP register not allowed"; +PUBLIC char * ILL_FP_REG = "illegal FP register"; +PUBLIC char * ILL_FP_REG_PAIR = "illegal FP register pair"; +PUBLIC char * JUNK_AFTER_OPERANDS = "junk after operands"; + +PUBLIC char * ALREADY = "already defined"; +PUBLIC char * UNSTABLE_LABEL = "label moved in last pass add -O?"; + +/* Warnings. */ +PUBLIC char * CPUCLASH = "instruction illegal for current cpu"; +PUBLIC char * SHORTB = "short branch would do"; diff --git a/as/errors.h b/as/errors.h new file mode 100644 index 0000000..28e1a58 --- /dev/null +++ b/as/errors.h @@ -0,0 +1,105 @@ +/* Error codes. */ + +/* Syntax errors. */ +EXTERN char * COMEXP; /* "comma expected" */ +EXTERN char * DELEXP; /* "delimiter expected" */ +EXTERN char * FACEXP; /* "factor expected" */ +EXTERN char * IREGEXP; /* "index register expected" */ +EXTERN char * LABEXP; /* "label expected" */ +EXTERN char * LPEXP; /* "left parentheses expected" */ +EXTERN char * OPEXP; /* "opcode expected" */ +EXTERN char * RBEXP; /* "right bracket expected" */ +EXTERN char * REGEXP; /* "register expected" */ +EXTERN char * RPEXP; /* "right parentheses expected" */ +EXTERN char * SPEXP; /* "space expected" */ + +/* Expression errors. */ +EXTERN char * ABSREQ; /* "absolute expression required" */ +EXTERN char * NONIMPREQ; /* "non-imported expression required" */ +EXTERN char * RELBAD; /* "relocation impossible" */ + +/* Label errors. */ +EXTERN char * ILLAB; /* "illegal label" */ +EXTERN char * MACUID; /* "MACRO used as identifier" */ +EXTERN char * MISLAB; /* "missing label" */ +EXTERN char * MNUID; /* "opcode used as identifier" */ +EXTERN char * REGUID; /* "register used as identifier" */ +EXTERN char * RELAB; /* "redefined label" */ +EXTERN char * UNBLAB; /* "unbound label" */ +EXTERN char * UNLAB; /* "undefined label" */ +EXTERN char * VARLAB; /* "variable used as label" */ + +/* Addressing errors. */ +EXTERN char * ABOUNDS; /* "address out of bounds" */ +EXTERN char * DBOUNDS; /* "data out of bounds" */ +EXTERN char * ILLMOD; /* "illegal address mode" */ +EXTERN char * ILLREG; /* "illegal register" */ + +/* Control structure errors. */ +EXTERN char * ELSEBAD; /* "no matching IF" */ +#define ELSEIFBAD ELSEBAD +EXTERN char * ENDBBAD; /* "no matching BLOCK" */ +#define ENDIFBAD ELSEBAD +EXTERN char * EOFBLOCK; /* "end of file in BLOCK" */ +EXTERN char * EOFIF; /* "end of file in IF" */ +EXTERN char * EOFLC; /* "location counter was undefined at end" */ +EXTERN char * EOFMAC; /* "end of file in MACRO" */ +EXTERN char * FAILERR; /* "user-generated error" */ + +/* Overflow errors. */ +EXTERN char * BLOCKOV; /* "BLOCK stack overflow" */ +EXTERN char * BWRAP; /* "binary file wrap-around" */ +EXTERN char * COUNTOV; /* "counter overflow" */ +EXTERN char * COUNTUN; /* "counter underflow" */ +EXTERN char * GETOV; /* "GET stack overflow" */ +EXTERN char * IFOV; /* "IF stack overflow" */ + +EXTERN char * LINLONG; /* "line too long" */ +EXTERN char * MACOV; /* "MACRO stack overflow" */ +EXTERN char * OBJSYMOV; /* "object symbol table overflow" */ +EXTERN char * OWRITE; /* "program overwrite" */ +EXTERN char * PAROV; /* "parameter table overflow" */ +EXTERN char * SYMOV; /* "symbol table overflow" */ +EXTERN char * SYMOUTOV; /* "output symbol table overflow" */ + +/* I/O errors. */ +EXTERN char * OBJOUT; /* "error writing object file" */ + +/* Miscellaneous errors. */ +EXTERN char * AL_AX_EAX_EXP; /* "al ax or eax expected" */ +EXTERN char * CTLINS; /* "control character in string" */ +EXTERN char * FURTHER; /* "futher errors suppressed" */ +EXTERN char * ILL_IMM_MODE; /* "illegal immediate mode" */ +EXTERN char * ILL_IND_TO_IND; /* "illegal indirect to indirect" */ +EXTERN char * ILL_IND; /* "illegal indirection" */ +EXTERN char * ILL_IND_PTR; /* "illegal indirection from previous 'ptr'" */ +EXTERN char * ILL_SCALE; /* "illegal scale" */ +EXTERN char * ILL_SECTION; /* "illegal section" */ +EXTERN char * ILL_SEG_REG; /* "illegal segment register" */ +EXTERN char * ILL_SOURCE_EA; /* "illegal source effective address" */ +EXTERN char * ILL_SIZE; /* "illegal size" */ +EXTERN char * IMM_REQ; /* "immediate expression expected" */ +EXTERN char * INDEX_REG_EXP; /* "index register expected" */ +EXTERN char * IND_REQ; /* "indirect expression required" */ +EXTERN char * MISMATCHED_SIZE; /* "mismatched size" */ +EXTERN char * NOIMPORT; /* "no imports with binary file output" */ +EXTERN char * REENTER; /* "multiple ENTER pseudo-ops" */ +EXTERN char * REL_REQ; /* "relative expression required" */ +EXTERN char * REPEATED_DISPL; /* "repeated displacement" */ +EXTERN char * SEGREL; /* "segment or relocatability redefined" */ +EXTERN char * SEG_REG_REQ; /* "segment register required" */ +EXTERN char * SIZE_UNK; /* "size unknown" */ +EXTERN char * UNKNOWN_ESCAPE_SEQUENCE; /* "unknown escape sequence" */ + +EXTERN char * FP_REG_REQ; /* "FP register required" */ +EXTERN char * FP_REG_NOT_ALLOWED; /* "FP register not allowed" */ +EXTERN char * ILL_FP_REG; /* "illegal FP register" */ +EXTERN char * ILL_FP_REG_PAIR; /* "illegal FP register pair" */ +EXTERN char * JUNK_AFTER_OPERANDS; /* "junk after operands" */ + +EXTERN char * ALREADY; /* "already defined" */ +EXTERN char * UNSTABLE_LABEL; /* "label moved in last pass add -O?" */ + +/* Warnings. */ +EXTERN char * CPUCLASH; /* "instruction illegal for current cpu" */ +EXTERN char * SHORTB; /* "short branch would do" */ diff --git a/as/express.c b/as/express.c index 65923b5..51537c3 100644 --- a/as/express.c +++ b/as/express.c @@ -8,7 +8,7 @@ #include "scan.h" #include "source.h" -FORWARD void experror P((error_pt errnum)); +FORWARD void experror P((char * err_str)); FORWARD void expundefined P((void)); FORWARD void simple2 P((void)); FORWARD void simple P((void)); @@ -33,10 +33,10 @@ PUBLIC void chkabs() } } -PRIVATE void experror(errnum) -error_pt errnum; +PRIVATE void experror(err_str) +char * err_str; { - error(errnum); + error(err_str); expundefined(); } @@ -312,6 +312,7 @@ PUBLIC void factor() getsym(); return; } +#ifndef MC6809 case LBRACKET: if (!asld_compatible) break; /* error, LPAREN is the grouping symbol */ @@ -322,9 +323,12 @@ PUBLIC void factor() else getsym(); return; +#endif case LPAREN: +#ifndef MC6809 if (asld_compatible) break; /* error, LBRACKET is the grouping symbol */ +#endif getsym(); expres(); if (sym != RPAREN) diff --git a/as/genbin.c b/as/genbin.c index 887c921..6b4b42a 100644 --- a/as/genbin.c +++ b/as/genbin.c @@ -7,9 +7,11 @@ #include "file.h" #include "globvar.h" +#ifdef USE_FIXED_HEAP PRIVATE char *asmbeg; /* beginning of assembler code */ /* for overwrite check */ /* bss-init to zero = NULL and not changed */ +#endif /* Sneaky stuff, the start of a binary file can be _negative_ for the I80386 assembler. The -ve addresses are ones over 2GB (or "org -32") */ @@ -234,17 +236,19 @@ static PT zapptr = 0; } } } +#ifdef USE_FIXED_HEAP else if (binaryc && !(lcdata & UNDBIT)) /* memory output, and enabled */ { register char *bufptr; - if ((bufptr = (char *) binmbuf) >= asmbeg && bufptr < heapptr) + if ((bufptr = (char *) binmbuf) >= asmbeg && bufptr < temp_buf()) error(OWRITE); else *bufptr = ch; ++binmbuf; } +#endif } /* write sized offset to binary file or directly to memory */ diff --git a/as/genlist.c b/as/genlist.c index b0db41c..edeefff 100644 --- a/as/genlist.c +++ b/as/genlist.c @@ -17,7 +17,7 @@ struct error_s /* to record error info */ { - unsigned char errnum; + char * err_str; unsigned char position; }; @@ -131,36 +131,39 @@ register char *where; /* record number and position of error (or error buffer overflow) */ -PUBLIC void error(errnum) -error_pt errnum; +PUBLIC void warning(err_str) +char * err_str; +{ + if (!as_warn.current) return; + ++totwarn; + --toterr; + error(err_str); +} + +PUBLIC void error(err_str) +char * err_str; { register struct error_s *errptr; register struct error_s *errptrlow; unsigned char position; - if ((unsigned) errnum < MINWARN || as_warn.current) + if (errcount >= MAXERR) + erroverflow = TRUE; + else { - if (errcount >= MAXERR) - erroverflow = TRUE; - else + position = symname - linebuf; + for (errptr = errbuf + errcount; + errptr > errbuf && errptr->position > position; + errptr = errptrlow) { - position = symname - linebuf; - for (errptr = errbuf + errcount; - errptr > errbuf && errptr->position > position; - errptr = errptrlow) - { - errptrlow = errptr - 1; - errptr->errnum = errptrlow->errnum; - errptr->position = errptrlow->position; - } - errptr->errnum = errnum; - errptr->position = position; - ++errcount; - if ((unsigned)errnum >= MINWARN) - ++totwarn; - else - ++toterr; + errptrlow = errptr - 1; + errptr->err_str = errptrlow->err_str; + errptr->position = errptrlow->position; } + errptr->err_str = err_str; + errptr->position = position; + ++errcount; + ++toterr; } } @@ -208,7 +211,7 @@ PRIVATE void listcode() unsigned numlength; char *numptr; - listptr = (struct code_listing_s *) heapptr; + listptr = (struct code_listing_s *) temp_buf(); memset((char *) listptr, ' ', sizeof *listptr); listptr->nullterm = 0; if (macflag) @@ -354,7 +357,7 @@ PRIVATE void listerrors() { writenl(); paderrorline(1); } - writes(errmsg = build_error_message(errptr->errnum, heapptr)); + writes(errmsg = errptr->err_str); errcol = strlen(errmsg)+LINUM_LEN+1; column = 0; linep = linebuf; errcolw = CODE_LIST_LENGTH; @@ -390,7 +393,7 @@ PRIVATE void listerrors() paderrorline((unsigned) errcolw - LINUM_LEN); } writec('^'); - writes(errmsg = build_error_message(errptr->errnum, heapptr)); + writes(errmsg = errptr->err_str); errcol += strlen(errmsg); #endif ++errptr; @@ -404,7 +407,7 @@ PRIVATE void listerrors() #else paderrorline(CODE_LIST_LENGTH - LINUM_LEN); #endif - writesn(build_error_message(FURTHER, heapptr)); + writesn(FURTHER); } } diff --git a/as/genobj.c b/as/genobj.c index abe140a..588f41b 100644 --- a/as/genobj.c +++ b/as/genobj.c @@ -345,6 +345,7 @@ PUBLIC void objheader() unsigned symosiz; /* size of object symbol table */ register struct sym_s *symptr; u32_T textlength; + int symcount = 0; if ((objectc = objectg) == 0) return; @@ -362,9 +363,22 @@ PUBLIC void objheader() if ((nameptr = strrchr(module_name, '.')) != NUL_PTR) *nameptr = 0; strsiz = strlen(module_name) + 1; - align(heapptr); - for (hashptr = spt, arrext = copyptr = (struct sym_s **) heapptr; - hashptr < spt_top;) + + for (hashptr = spt; hashptr < spt_top;) + if ((symptr = *hashptr++) != NUL_PTR) + do + { + if ((symptr->type & EXPBIT || symptr->data & IMPBIT) || + (!globals_only_in_obj && symptr->name[0] != '.' && + !(symptr->type & (MNREGBIT | MACBIT | VARBIT)))) + { + symcount ++; + } + } + while ((symptr = symptr->next) != NUL_PTR); + arrext = copyptr = asalloc( sizeof(struct sym_s *) * symcount); + + for (hashptr = spt; hashptr < spt_top;) if ((symptr = *hashptr++) != NUL_PTR) do { @@ -372,11 +386,6 @@ PUBLIC void objheader() (!globals_only_in_obj && symptr->name[0] != '.' && !(symptr->type & (MNREGBIT | MACBIT | VARBIT)))) { - if (copyptr >= (struct sym_s **) heapend) - { - heapptr = (char *) copyptr; - fatalerror(OBJSYMOV); - } *copyptr++ = symptr; strsiz += symptr->length + 1; if (textseg>=0 && (symptr->data & SEGM) == textseg) @@ -399,7 +408,7 @@ PUBLIC void objheader() } } while ((symptr = symptr->next) != NUL_PTR); - heapptr = (char *) (copytop = copyptr); + copytop = copyptr; /* calculate length of text, and number of seg size bytes in header */ diff --git a/as/gensym.c b/as/gensym.c index db9dec4..646c5cd 100644 --- a/as/gensym.c +++ b/as/gensym.c @@ -29,35 +29,34 @@ PUBLIC void gensym() #ifdef BINSYM unsigned label_stringptr; /* offset of label str from start of file */ #endif + int symcount = 0; labels_length = label_count = 0; /* make copy of all relavant symbol ptrs on heap */ /* original ptrs can now be modified, but need to be an array for sort */ - align(heapptr); - for (hashptr = spt, symlptr = copyptr = (struct sym_s **) heapptr; - hashptr < spt_top;) + for (hashptr = spt; hashptr < spt_top;) + if ((symptr = *hashptr++) != NUL_PTR) + do + if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT))) + symcount++; + while ((symptr = symptr->next) != NUL_PTR); + symlptr = copyptr = asalloc( sizeof(struct sym_s *) * symcount); + + for (hashptr = spt; hashptr < spt_top;) if ((symptr = *hashptr++) != NUL_PTR) do if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT))) { - if (copyptr >= (struct sym_s **) heapend) - { - heapptr = (char *) copyptr; - error(SYMOUTOV); /* avoid recursive fatalerror */ - listline(); /* the main job is OK if here */ - goto sort_symbols; - } *copyptr++ = symptr; ++label_count; labels_length += symptr->length + 3; /* 3 for type, value */ } while ((symptr = symptr->next) != NUL_PTR); -sort_symbols: sort(symlptr, copyptr, TRUE); /* sort on name */ - heapptr = (char *) (copytop = copyptr); + copytop = copyptr; if (list.global) { outfd = lstfil; @@ -147,7 +146,7 @@ unsigned column; char *outname; char *symname; - listptr = (struct sym_listing_s *) heapptr; + listptr = (struct sym_listing_s *) temp_buf(); memset((char *) listptr, ' ', SYMLIS_LEN); listptr->nullterm = 0; if ((length = symptr->length) > SYMLIS_NAMELEN) diff --git a/as/globvar.h b/as/globvar.h index 1ea385e..edd9419 100644 --- a/as/globvar.h +++ b/as/globvar.h @@ -35,8 +35,6 @@ EXTERN char *linebuf; /* buffer */ /* for symbol table routines */ -EXTERN char *heapend; /* end of free space for symbol list */ -EXTERN char *heapptr; /* next free space in symbol list */ EXTERN unsigned char inidata; /* init sym entry data governed by "u" flag */ EXTERN struct sym_s **spt; /* symbol pointer table */ EXTERN struct sym_s **spt_top; /* top of symbol ptr table */ @@ -112,7 +110,7 @@ extern char hexdigit[]; #ifdef I80386 #ifndef __AS386_16__ #define iscpu(x) (cpuid>=(x)) -#define needcpu(x) do{ if(cpuid<(x)) {error(CPUCLASH); cpuid|=0x10;} }while(0) +#define needcpu(x) do{ if(cpuid<(x)) {warning(CPUCLASH); cpuid|=0x10;} }while(0) #define setcpu(x) (cpuid=(x)) #define cpuwarn() (cpuid&=0xF) #endif diff --git a/as/keywords.c b/as/keywords.c index b3c1615..0db0636 100644 --- a/as/keywords.c +++ b/as/keywords.c @@ -135,9 +135,13 @@ PUBLIC char ops[] = 5, '.', 'D', 'A', 'T', 'A', DATAOP, 0, 6, '.', 'D', 'A', 'T', 'A', '1', FCBOP, 0, 6, '.', 'D', 'A', 'T', 'A', '2', FDBOP, 0, +#if SIZEOF_OFFSET_T > 2 6, '.', 'D', 'A', 'T', 'A', '4', FQBOP, 0, +#endif 2, 'D', 'B', FCBOP, 0, +#if SIZEOF_OFFSET_T > 2 2, 'D', 'D', FQBOP, 0, +#endif 7, '.', 'D', 'E', 'F', 'I', 'N', 'E', EXPORTOP, 0, 2, 'D', 'W', FDBOP, 0, 3, 'E', 'N', 'D', PROCEOFOP, 0, @@ -165,7 +169,9 @@ PUBLIC char ops[] = 6, '.', 'L', 'C', 'O', 'M', 'M', LCOMMOP1, 0, 5, '.', 'L', 'I', 'S', 'T', LISTOP, 0, 3, 'L', 'O', 'C', LOCOP, 0, +#if SIZEOF_OFFSET_T > 2 5, '.', 'L', 'O', 'N', 'G', FQBOP, 0, +#endif 8, '.', 'M', 'A', 'C', 'L', 'I', 'S', 'T', MACLISTOP, 0, 5, 'M', 'A', 'C', 'R', 'O', MACROOP, 0, 4, '.', 'M', 'A', 'P', MAPOP, 0, @@ -180,8 +186,10 @@ PUBLIC char ops[] = 6, '.', 'S', 'H', 'O', 'R', 'T', FDBOP, 0, 6, '.', 'S', 'P', 'A', 'C', 'E', RMBOP, 0, 5, '.', 'T', 'E', 'X', 'T', TEXTOP, 0, +#ifndef MC6809 5, 'U', 'S', 'E', '1', '6', USE16OP, 0, 5, 'U', 'S', 'E', '3', '2', USE32OP, 0, +#endif 5, '.', 'W', 'A', 'R', 'N', WARNOP, 0, 5, '.', 'W', 'O', 'R', 'D', FDBOP, 0, 6, '.', 'Z', 'E', 'R', 'O', 'W', BLKWOP, 0, @@ -38,9 +38,12 @@ struct sym_s *symptr; macpar = (struct schain_s *) (stringptr + 1); /* TODO: alignment */ getsym(); - if (sym != LPAREN) + if (sym == EOLSYM) return; /* no other params */ - reglineptr = lineptr; + if (sym != LPAREN) + reglineptr = symname; + else + reglineptr = lineptr; stringptr = macpar->string; while (TRUE) { @@ -51,10 +54,11 @@ struct sym_s *symptr; return; } ch = *reglineptr++; - if (ch == '/') + if (ch == '\\') /* escaped means no special meaning for slash, comma, paren */ ch = *reglineptr++; - else if (ch == ',' || ch == ')') + else if (ch == ',' || ch == ')' || ch == '!' || ch == ';' + || ch == '\n' || ch == 0) { if (stringptr >= (char *) macptop) { @@ -69,7 +73,7 @@ struct sym_s *symptr; macpar = (struct schain_s *) (stringptr + 1); /* but is finished OK - TODO align */ stringptr = macpar->string; - if (ch == ')') + if (ch != ',') return; continue; } @@ -90,6 +94,9 @@ PUBLIC void pmacro() bool_t saving; bool_t savingc; struct sym_s *symptr=0; + int maclen = 8; + int macoff = 0; + char * macbuf = asalloc(8); saving = /* prepare for bad macro */ savingc = FALSE; /* normally don't save comments */ @@ -114,9 +121,7 @@ PUBLIC void pmacro() else symptr->type |= MACBIT; symptr->data = UNDBIT; /* undefined till end */ - symptr->value_reg_or_op.value = (offset_t) heapptr; - /* beginning of store for macro */ - /* value s.b. (char *) */ + symptr->value_reg_or_op.value = (offset_t) macbuf; getsym_nolookup(); /* test for "C" */ if (sym == IDENT && lineptr == symname + 1 && *symname == 'C') savingc = TRUE; @@ -147,27 +152,24 @@ PUBLIC void pmacro() if (!saving) continue; { - register char *reglineptr; - register char *regheapptr; + char * p = strchr(linebuf, EOLCHAR); + int len = (p-linebuf+1); - reglineptr = linebuf; - regheapptr = heapptr; - do + if ( macoff + len > maclen-4 ) { - if (regheapptr >= heapend) - { - heapptr = regheapptr; - fatalerror(SYMOV); /* won't fit */ - } + maclen = maclen * 2 + len; + macbuf = asrealloc(macbuf, maclen); } - while ((*regheapptr++ = *reglineptr++) != EOLCHAR); - heapptr = regheapptr; + memcpy(macbuf+macoff, linebuf, len); + macoff += len; + } } macload = FALSE; if (saving) { - *heapptr++ = ETB; + macbuf[macoff] = ETB; + symptr->value_reg_or_op.value = (offset_t) macbuf; symptr->data = 0; } } @@ -409,7 +409,7 @@ FORWARD void getimmed P((struct ea_s *eap, count_t immed_count)); FORWARD void getindirect P((struct ea_s *eap)); FORWARD void getshift P((struct ea_s *eap)); FORWARD reg_pt indregchk P((reg_pt matchreg)); -FORWARD void kgerror P((error_pt errnum)); +FORWARD void kgerror P((char * err_str)); FORWARD void lbranch P((int backamount)); FORWARD void notbytesize P((struct ea_s *eap)); FORWARD void notimmed P((struct ea_s *eap)); @@ -1050,10 +1050,10 @@ reg_pt matchreg; return reg; } -PRIVATE void kgerror(errnum) -error_pt errnum; +PRIVATE void kgerror(err_str) +char * err_str; { - error(errnum); + error(err_str); sprefix = oprefix = aprefix = mcount = 0x0; } @@ -1071,7 +1071,7 @@ int backamount; if ( last_pass<2 && backamount != 0x0 && !(lastexp.data & IMPBIT) && lastexp.offset + backamount < 0x80 + backamount) - error(SHORTB); /* -0x8? to 0x7F, warning */ + warning(SHORTB); /* -0x8? to 0x7F, warning */ } } } @@ -2427,7 +2427,7 @@ FORWARD void doaltind P((void)); FORWARD void do1altind P((void)); FORWARD void fixupind P((void)); FORWARD void getindexnopost P((void)); -FORWARD void inderror P((error_pt errnum)); +FORWARD void inderror P((char * err_str)); FORWARD reg_pt indreg P((reg_pt maxindex)); FORWARD void predec1 P((void)); FORWARD void sustack P((reg_pt stackreg)); @@ -2617,8 +2617,8 @@ PRIVATE void do1altind() inderror(ILLMOD); /* e.g. LEAX $10 */ else { - if (byteflag || !wordflag && !(lastexp.data & (FORBIT | RELBIT)) && - (lastexp.offset >> 0x8) == dirpag) + if (byteflag || (!wordflag && !(lastexp.data & (FORBIT | RELBIT)) && + (lastexp.offset >> 0x8) == dirpag)) { /* direct addressing */ if (opcode >= 0x80) opcode |= 0x10; @@ -2634,7 +2634,7 @@ PRIVATE void do1altind() !(lastexp.data & IMPBIT) && lastexp.offset + (0x81 - 0x3) < 0x101) /* JSR or JMP could be done with BSR or BRA */ - error(SHORTB); + warning(SHORTB); } } } @@ -2657,10 +2657,10 @@ PRIVATE void getindexnopost() fixupind(); } -PRIVATE void inderror(errnum) -error_pt errnum; +PRIVATE void inderror(err_str) +char * err_str; { - error(errnum); + error(err_str); if (postb & INDIRECTBIT) sym = RBRACKET; /* fake right bracket to kill further errors */ fixupind(); @@ -2754,7 +2754,7 @@ PUBLIC void mlong() lastexp.offset = lastexp.offset - lc - lcjump; if ( last_pass<2 && !(lastexp.data & IMPBIT) && lastexp.offset + 0x81 < 0x101) - error(SHORTB); /* -0x81 to 0x7F, warning */ + warning(SHORTB); /* -0x81 to 0x7F, warning */ } } } diff --git a/as/opcode.h b/as/opcode.h index 385c096..1d91dc2 100644 --- a/as/opcode.h +++ b/as/opcode.h @@ -31,7 +31,9 @@ enum FCBOP, FCCOP, FDBOP, +#if SIZEOF_OFFSET_T > 2 FQBOP, +#endif GETOP, GLOBLOP, IDENTOP, @@ -420,10 +420,10 @@ pfv func; } } -PUBLIC void fatalerror(errnum) -error_pt errnum; +PUBLIC void fatalerror(err_str) +char * err_str; { - error(errnum); + error(err_str); skipline(); listline(); finishup(); @@ -432,8 +432,8 @@ error_pt errnum; /* swap position with label position, do error, put back posn */ /* also clear label ptr */ -PUBLIC void labelerror(errnum) -error_pt errnum; +PUBLIC void labelerror(err_str) +char * err_str; { struct sym_s *oldgsymptr; char *oldlineptr; @@ -447,7 +447,7 @@ error_pt errnum; lineptr = linebuf; getsym(); /* 1st symbol is label or symbol after * missing one */ - error(errnum); + error(err_str); gsymptr = oldgsymptr; lineptr = oldlineptr; sym = oldsym; @@ -10,9 +10,6 @@ void line_zero P((void)); /* assemble.c */ void assemble P((void)); -/* error.c */ -char *build_error_message P((error_pt errnum, char *buf)); - /* express.c */ void absexpres P((void)); void chkabs P((void)); @@ -34,7 +31,8 @@ void putbin P((int ch)); /* genlist.c */ char *build_2hex_number P((unsigned num, char *where)); char *build_number P((unsigned num, unsigned width, char *where)); -void error P((error_pt errnum)); +void warning P((char * errorstr)); +void error P((char * errorstr)); void listline P((void)); void writec P((int ch)); void writenl P((void)); @@ -139,8 +137,8 @@ void mshort P((void)); bool_pt checksegrel P((struct sym_s *symptr)); void checkdatabounds P((void)); void datatoobig P((void)); -void fatalerror P((error_pt errnum)); -void labelerror P((error_pt errnum)); +void fatalerror P((char * errorstr)); +void labelerror P((char * errorstr)); void palign P((void)); void pasciz P((void)); void pblkw P((void)); @@ -163,7 +161,9 @@ void pfail P((void)); void pfcb P((void)); void pfcc P((void)); void pfdb P((void)); +#if SIZEOF_OFFSET_T > 2 void pfqb P((void)); +#endif void pglobl P((void)); void pident P((void)); void pif P((void)); @@ -216,3 +216,10 @@ void u4c4 P((char *buf, u32_T offset)); void u2cn P((char *buf, u16_pt offset, unsigned count)); void u4cn P((char *buf, u32_T offset, unsigned count)); bool_pt typeconv_init P((bool_pt big_endian, bool_pt long_big_endian)); + +/* alloc.c */ +void * asalloc P((unsigned int size)); +void * asrealloc P((void * oldptr, unsigned int size)); +void * temp_buf P((void)); +void init_heap P((void)); + diff --git a/as/readsrc.c b/as/readsrc.c index 819efb8..df69756 100644 --- a/as/readsrc.c +++ b/as/readsrc.c @@ -138,9 +138,12 @@ char *name; for(;;) { if( filelength >= memsize ) - mem_start = realloc(mem_start, (memsize+=16000)+4); - if(mem_start == 0) - as_abort("Cannot allocate memory for BIG buffer"); + { + if (memsize > 16000) + mem_start = asrealloc(mem_start, (memsize+=16384)+4); + else + mem_start = asrealloc(mem_start, (memsize+=memsize+32)+4); + } cc = read(fd, mem_start+filelength, (size_t)(memsize-filelength)); if( cc <= 0 ) break; @@ -233,6 +233,7 @@ PRIVATE void intconst() PUBLIC void initscan() { +#ifndef MC6809 if (asld_compatible) { lindirect = LPAREN; @@ -241,8 +242,11 @@ PUBLIC void initscan() } else { +#endif lindirect = LBRACKET; rindexp = RBEXP; rindirect = RBRACKET; +#ifndef MC6809 } +#endif } @@ -6,7 +6,7 @@ EXTERN struct sym_s *gsymptr; /* global symbol ptr */ EXTERN char lindirect; /* left symbol for indirect addressing */ EXTERN char *lineptr; /* current line position */ EXTERN offset_t number; /* constant number */ -EXTERN int rindexp; /* error code for missing rindirect */ +EXTERN char * rindexp; /* error code for missing rindirect */ EXTERN char rindirect; /* right symbol for indirect addressing */ EXTERN char sym; /* current symbol */ EXTERN char *symname; /* current symbol name */ @@ -168,24 +168,18 @@ PUBLIC struct sym_s *lookup() } if (!ifflag) return NUL_PTR; - align(heapptr); - if (heapptr >= heapend) - fatalerror(SYMOV); #ifdef DEBUG ++nsym; if (hashptr >= spt && hashptr < spt + SPTSIZ) ++nhash; #endif - *hashptr = symptr = (struct sym_s *) heapptr; + *hashptr = symptr = asalloc(sizeof(struct sym_s) + length); symptr->type = 0; symptr->data = inidata; symptr->length = length; symptr->value_reg_or_op.value = (offset_t) (symptr->next = NUL_PTR); - heapptr = symptr->name; - do - *heapptr++ = *nameptr++; - while (--length != 0); - *heapptr++ = 0; + memcpy(symptr->name, nameptr, length); + symptr->name[length] = 0; return symptr; } @@ -220,6 +214,6 @@ PUBLIC void statistics() weight += nx[i] * i; } printf("\n"); - printf("weight = %d%d\n", w; + printf("weight = %d%d\n", w); #endif } @@ -22,7 +22,6 @@ typedef unsigned long u4_pt; typedef unsigned char bool_t; typedef int bool_pt; typedef unsigned count_t; -typedef int error_pt; typedef int fd_t; typedef unsigned char indcount_t; #ifdef I80386 diff --git a/as/typeconv.c b/as/typeconv.c index 708d92b..d8c0c89 100644 --- a/as/typeconv.c +++ b/as/typeconv.c @@ -15,8 +15,8 @@ void xxerr(x) char * x; { write(2, x, strlen(x)); } static int no_swap = 1; -static long_off[4] = {0,1,2,3}; -static int_off[2] = {0,1}; +static int long_off[4] = {0,1,2,3}; +static int int_off[2] = {0,1}; PUBLIC bool_pt typeconv_init(big_endian, long_big_endian) bool_pt big_endian; |