assembly language source file reading now does end of buffer
[unix-history] / usr / src / old / as.vax / as.h
index 02a4f40..8558b0d 100644 (file)
@@ -1,40 +1,93 @@
-/* Copyright (c) 1980 Regents of the University of California */
-/* "@(#)as.h 4.1 %G%" */
+/*
+ *     Copyright (c) 1982 Regents of the University of California
+ *     @(#)as.h 4.14 %G%
+ */
 #ifdef VMS
 # define       vax     1
 # define       VAX     1
 #endif VMS
 
 #ifdef VMS
 # define       vax     1
 # define       VAX     1
 #endif VMS
 
-#define readonly
+#define        reg     register
+
+#include <sys/types.h>
+#ifdef UNIX
+
+#ifdef FLEXNAMES
+#  include <a.out.h>
+#  include <stab.h>
+#else not FLEXNAMES
+#  define ONLIST
+#  include "a.out.h"
+#  include <stab.h>
+#endif FLEXNAMES
+
+#endif UNIX 
+#ifdef VMS
+
+#ifdef UNIXDEVEL
+#  include <a.out.h>
+#else not UNIXDEVEL
+#  include <aout.h>
+#endif not UNIXDEVEL
 
 
+#endif VMS
+
+#define readonly
 #define        NINST           300
 
 #define        NEXP            20      /* max number of expr. terms per instruction */
 #define        NARG            6       /* max number of args per instruction */
 #define        NHASH           1103    /* hash table is dynamically extended */
 #define        NINST           300
 
 #define        NEXP            20      /* max number of expr. terms per instruction */
 #define        NARG            6       /* max number of args per instruction */
 #define        NHASH           1103    /* hash table is dynamically extended */
-#define TNAMESIZE      32      /* maximum length of temporary file names */
+#define        TNAMESIZE       32      /* maximum length of temporary file names */
 #define        NLOC            4       /* number of location ctrs */
 #define        NLOC            4       /* number of location ctrs */
-
+/*
+ *     Sizes for character buffers.
+ *     what                    size #define name       comments
+ *
+ *     source file reads       ASINBUFSIZ              integral of BUFSIZ
+ *     string assembly         NCPString               large for .stabs
+ *     name assembly           NCPName                 depends on FLEXNAMES
+ *     string save             STRPOOLDALLOP   
+ *
+ *
+ *     -source file reads should be integral of BUFSIZ for efficient reads
+ *     -string saving is a simple first fit
+ */
+#ifndef ASINBUFSIZ
+#      define  ASINBUFSIZ      4096
+#endif not ASINBUFSIZ
+#ifndef STRPOOLDALLOP
+#      define STRPOOLDALLOP    8192
+#endif not STRPOOLDALLOP
+#ifndef NCPString
+#      define  NCPString       4080
+#endif not NCPString
+
+#define        NCPName NCPS
 #ifdef UNIX
 #ifdef UNIX
-# ifndef       FLEXNAMES
-#      ifndef  NCPS
-#              define  NCPS    8       /* number of characters per symbol*/
-#      endif
-# else
-#      ifdef NCPS
-#              undef   NCPS
-#      endif
-#      define  NCPS    BUFSIZ  /* needed to allocate yytext */
-# endif
+# ifndef FLEXNAMES
+#      ifndef NCPS
+#              undef   NCPName
+#              define  NCPName 8
+#      endif not NCPS
+# else FLEXNAMES
+#      ifndef NCPS
+#              undef   NCPName
+#              define  NCPName 4096
+#      endif not NCPS
+# endif FLEXNAMES
 # endif UNIX
 
 # ifdef VMS
 # endif UNIX
 
 # ifdef VMS
-# ifdef NCPS
-#      undef   NCPS
-# endif NCPS
-#      define  NCPS    15
+#      define  NCPName 15
 # endif VMS
 
 # endif VMS
 
+/*
+ *     Check sizes, and compiler error if sizes botch
+ */
+#if ((STRPOOLDALLOP < NCPString) || (STRPOOLDALLOP < NCPName))
+       $$$botch with definition sizes
+#endif test botches
 /*
  * Symbol types
  */
 /*
  * Symbol types
  */
 /*
  * Actual argument syntax types
  */
 /*
  * Actual argument syntax types
  */
-#define AREG   1       /* %r */
-#define ABASE  2       /* (%r) */
-#define ADECR  3       /* -(%r) */
-#define AINCR  4       /* (%r)+ */
-#define ADISP  5       /* expr(%r) */
-#define AEXP   6       /* expr */
-#define AIMM   7       /* $ expr */
-#define ASTAR  8       /* * */
-#define AINDX  16      /* [%r] */
-
+#define        AREG    1       /* %r */
+#define        ABASE   2       /* (%r) */
+#define        ADECR   3       /* -(%r) */
+#define        AINCR   4       /* (%r)+ */
+#define        ADISP   5       /* expr(%r) */
+#define        AEXP    6       /* expr */
+#define        AIMM    7       /* $ expr */
+#define        ASTAR   8       /* * */
+#define        AINDX   16      /* [%r] */
 /*
 /*
- * Argument access types used to test validity of operands to operators
+ *     Definitions for the things found in ``instrs''
  */
  */
-#define ACCA   (8<<3)  /* address only */
-#define ACCR   (1<<3)  /* read */
-#define ACCW   (2<<3)  /* write */
-#define ACCM   (3<<3)  /* modify */
-#define ACCB   (4<<3)  /* branch displacement */
-#define ACCI   (5<<3)  /* XFC code */
+#define        INSTTAB 1
+#include "instrs.h"
 
 /*
 
 /*
- * Argument data types
+ *     Tells outrel what it is relocating
+ *     RELOC_PCREL is an implicit argument to outrel; it is or'ed in
+ *     with a TYPX
  */
  */
-#define TYPB   0       /* byte */
-#define TYPW   1       /* word */
-#define TYPL   2       /* long */
-#define TYPQ   3       /* quad */
-#define TYPF   4       /* floating */
-#define TYPD   5       /* double floating */
-
-#define TYPMASK 7
-
-/* reference types for loader */
-#define PCREL 1
-#define LEN1 2
-#define LEN2 4
-#define LEN4 6
-#define LEN8 8
-       /*
-        *      reflen table converts between LEN* and PCREL to numbers
-        *              of bytes.
-        *      lgreflen table is the lg base 2 of the values in reflen.
-        */
-       extern  int     reflen[];       /* reference lengths */
-       extern  int     lgrefltn[];     /* lg reference lengths */
+#define        RELOC_PCREL     (1<<TYPLG)
+/*
+ *     reference types for loader
+ */
+#define        PCREL   1
+#define        LEN1    2
+#define        LEN2    4
+#define        LEN4    6
+#define        LEN8    8
+#define        LEN16   10
+
+extern int     reflen[];       /* {LEN*+PCREL} ==> number of bytes */
+extern int     lgreflen[];     /* {LEN*+PCREL} ==> lg number of bytes */
+extern int     len124[];       /* {1,2,4,8,16} ==> {LEN1, LEN2, LEN4, LEN8} */
+extern char    mod124[];       /* {1,2,4,8,16} ==> {bits to construct operands */
+extern int     type_124[];     /* {1,2,4,8,16} ==> {TYPB,TYPW,TYPL,TYPQ,TYPO} */
+extern int     ty_NORELOC[];   /* {TYPB..TYPH} ==> {1 if relocation not OK */
+extern int     ty_float[];     /* {TYPB..TYPH} ==> {1 if floating number */
+extern int     ty_LEN[];       /* {TYPB..TYPH} ==> {LEN1..LEN16} */
+extern int     ty_nbyte[];     /* {TYPB..TYPH} ==> {1,2,4,8,16} */
+extern int     ty_nlg[];       /* {TYPB..TYPH} ==> lg{1,2,4,8,16} */
+extern char    *ty_string[];   /* {TYPB..TYPH} ==> printable */
 
 #define        TMPC    7       
 
 #define        TMPC    7       
-#define        HW      01
-#define        FW      03
-#define        DW      07
-
-#ifdef UNIX
-#  include <pagsiz.h>
-#endif UNIX
+#define        HW      0x1
+#define        FW      0x3
+#define        DW      0x7
+#define        OW      0xF
 
 #ifdef VMS
 #  define PAGRND       0x1FFL
 
 #ifdef VMS
 #  define PAGRND       0x1FFL
 #define        round(x,y)      (((x)+(y)) & ~(y))
 
 #define        STABTYPS        0340
 #define        round(x,y)      (((x)+(y)) & ~(y))
 
 #define        STABTYPS        0340
-#define STABFLAG       0200
+#define        STABFLAG        0200
 
 /*
  *     Follows are the definitions for the symbol table tags, which are
 
 /*
  *     Follows are the definitions for the symbol table tags, which are
  *                     must get turned into their long form.
  */
 
  *                     must get turned into their long form.
  */
 
-#define TAGMASK                0xFF
+#define        TAGMASK         0xFF
 
 #      define  JXACTIVE        0xFF    /*jxxx size unknown*/
 #      define  JXNOTYET        0xFE    /*jxxx size known, but not yet expanded*/
 #      define  JXALIGN         0xFD    /*align jxxx entry*/
 #      define  JXINACTIVE      0xFC    /*jxxx size known and expanded*/
 
 
 #      define  JXACTIVE        0xFF    /*jxxx size unknown*/
 #      define  JXNOTYET        0xFE    /*jxxx size known, but not yet expanded*/
 #      define  JXALIGN         0xFD    /*align jxxx entry*/
 #      define  JXINACTIVE      0xFC    /*jxxx size known and expanded*/
 
-#define JXQUESTIONABLE         0xFB
+#define        JXQUESTIONABLE          0xFB
 
 #      define  JXTUNNEL        0xFA    /*jxxx that jumps to another*/
 #      define  OBSOLETE        0xF9    /*erroneously entered symbol*/
 
 #      define  JXTUNNEL        0xFA    /*jxxx that jumps to another*/
 #      define  OBSOLETE        0xF9    /*erroneously entered symbol*/
  *     Symbol table entries are used for both user defined symbols,
  *     and symbol slots generated to create the jxxx jump from
  *     slots.
  *     Symbol table entries are used for both user defined symbols,
  *     and symbol slots generated to create the jxxx jump from
  *     slots.
+ *     Caution: the instructions are stored in a shorter version
+ *     of the struct symtab, using all fields in sym_nm and
+ *     tag.  The fields used in sym_nm are carefully redeclared
+ *     in struct Instab and struct instab (see below).
+ *     If struct nlist gets changed, then Instab and instab may
+ *     have to be changed.
  */
 
  */
 
-#define symfirstfields char    *name;  unsigned char tag, type
-
 struct symtab{
 struct symtab{
-               symfirstfields;
-               short   ___hole;
-               char    ptype;          /*tag == NAME*/
-
-#define                jxbump  ptype           /*tag == JX..., how far to expand*/
-
-               char    other;          /*for stab info*/
-
-               short   desc;           /*tag == NAME*/
-
-#define                jxfear  desc            /*how far needs to be bumped*/
-
-               long    value;          /*address in the segment*/
-               char    jxoveralign;    /*if a JXXX, jumped over an align*/
-               short   index;          /*which segment*/
-               struct  symtab *dest;   /*if JXXX, where going to*/
+               struct  nlist   s_nm;
+               u_char  s_tag;          /* assembler tag */
+               u_char  s_ptype;        /* if tag == NAME */
+               u_char  s_jxoveralign;  /* if a JXXX, jumped over align */
+               short   s_index;        /* which segment */
+               struct  symtab *s_dest; /* if JXXX, where going to */
 #ifdef DJXXX
 #ifdef DJXXX
-               short   jxline;         /*source line of the jump from*/
+               short   s_jxline;       /* source line of the jump from */
 #endif
 };
 #endif
 };
+/*
+ *     Redefinitions of the fields in symtab for
+ *     use when the symbol table entry marks a jxxx instruction.
+ */
+#define        s_jxbump        s_ptype         /* tag == JX..., how far to expand */
+#define        s_jxfear        s_desc          /* how far needs to be bumped */
+/*
+ *     Redefinitions of fields in the struct nlist for symbols so that
+ *     one saves typing, and so that they conform 
+ *     with the old naming conventions.
+ */
+#ifdef FLEXNAMES
+#define        s_name  s_nm.n_un.n_name        /* name pointer */
+#define        s_nmx   s_nm.n_un.n_strx        /* string table index */
+#else  not FLEXNAMES
+#define        s_name  s_nm.n_name
+#endif
+#define        s_type  s_nm.n_type             /* type of the symbol */
+#define        s_other s_nm.n_other            /* other information for sdb */
+#define        s_desc  s_nm.n_desc             /* type descriptor */
+#define        s_value s_nm.n_value            /* value of the symbol, or sdb delta */
+
+struct instab{
+       struct  nlist   s_nm;           /* instruction name, type (opcode) */
+       u_char  s_tag;                  
+       u_char  s_eopcode;
+       char    s_pad[2];               /* round to 20 bytes */
+};
+typedef        struct  instab  *Iptr;
+/*
+ *     The fields nm.n_desc and nm.n_value total 6 bytes; this is
+ *     just enough for the 6 bytes describing the argument types.
+ *     We use a macro to define access to these 6 bytes, assuming that
+ *     they are allocated adjacently.
+ *     IF THE FORMAT OF STRUCT nlist CHANGES, THESE MAY HAVE TO BE CHANGED.
+ *
+ *     Instab is cleverly declared to look very much like the combination of
+ *     a struct symtab and a struct nlist.
+ */
+/*
+ *     With the 1981 VAX architecture reference manual,
+ *     DEC defined and named two byte opcodes. 
+ *     In addition, DEC defined four new one byte instructions for
+ *     queue manipulation.
+ *     The assembler was patched in 1982 to reflect this change.
+ *
+ *     The two byte opcodes are preceded with an escape byte
+ *     (usually an ESCD) and an opcode byte.
+ *     For one byte opcodes, the opcode is called the primary opcode.
+ *     For two byte opcodes, the second opcode is called the primary opcode.
+ *
+ *     We store the primary opcode in I_popcode,
+ *     and the escape opcode in I_eopcode.
+ *
+ *     For one byte opcodes in the basic arhitecture,
+ *             I_eopcode is CORE
+ *     For one byte opcodes in the new architecture definition,
+ *             I_eopcode is NEW
+ *     For the two byte opcodes, I_eopcode is the escape byte.
+ *
+ *     The assembler checks if a NEW or two byte opcode is used,
+ *     and issues a warning diagnostic.
+ */
+/*
+ *     For upward compatability reasons, we can't have the two opcodes
+ *     forming an operator specifier byte(s) be physically adjacent
+ *     in the instruction table.
+ *     We define a structure and a constructor that is used in
+ *     the instruction generator.
+ */
+struct Opcode{
+       u_char  Op_eopcode;
+       u_char  Op_popcode;
+};
 
 
-struct instab{
-       symfirstfields;
-
-#define                opcode type             /*use the same field as symtab.type*/
+#define        BADPOINT        0xAAAAAAAA
+/*
+ *     See if a structured opcode is bad
+ */
+#define        ITABCHECK(o)    ((itab[o.Op_eopcode] != (Iptr*)BADPOINT) && (itab[o.Op_eopcode][o.Op_popcode] != (Iptr)BADPOINT))
+/*
+ *     Index the itab by a structured opcode
+ */
+#define        ITABFETCH(o)    itab[o.Op_eopcode][o.Op_popcode]
 
 
-       char    nargs;                  /*how many arguments*/
-       char    argtype[6];             /*argument type info*/
+struct Instab{
+#ifdef FLEXNAMES
+       char    *I_name;
+#else not FLEXNAMES
+       char    I_name[NCPName];
+#endif
+       u_char  I_popcode;              /* basic op code */
+       char    I_nargs;
+       char    I_args[6];
+       u_char  I_s_tag;
+       u_char  I_eopcode;
+       char    I_pad[2];               /* round to 20 bytes */
 };
 };
+/*
+ *     Redefinitions of fields in the struct nlist for instructions so that
+ *     one saves typing, and conforms to the old naming conventions
+ */
+#define        i_popcode       s_nm.n_type     /* use the same field as symtab.type */
+#define        i_eopcode       s_eopcode
+#define        i_nargs         s_nm.n_other    /* number of arguments */
+#define        fetcharg(ptr, n) ((struct Instab *)ptr)->I_args[n]
 
 struct arg {                           /*one argument to an instruction*/
 
 struct arg {                           /*one argument to an instruction*/
-       char    atype;
-       char    areg1;
-       char    areg2;
-       char    dispsize;               /*usually d124, unless have B^, etc*/
-       struct  exp *xp;
+       char    a_atype;
+       char    a_areg1;
+       char    a_areg2;
+       char    a_dispsize;             /*usually d124, unless have B^, etc*/
+       struct  exp *a_xp;
 };
 };
-
+/*
+ *     Definitions for numbers and expressions.
+ */
+#include "asnumber.h"
 struct exp {
 struct exp {
-       long    xvalue;         /* MUST be the first field (look at union Double) */
-       long    yvalue;         /* MUST be second field; least sig word of a double */
-       char    xtype;
-       char    xloc;
-       struct  symtab *xname;
+       Bignum  e_number;       /* 128 bits of #, plus tag */
+       char    e_xtype;
+       char    e_xloc;
+       struct  symtab          *e_xname;
 };
 };
+#define        e_xvalue        e_number.num_num.numIl_int.Il_long
 
 
-#define doub_MSW xvalue
-#define doub_LSW yvalue
+#define                MINLIT          0
+#define                MAXLIT          63
 
 
-union Double {
-       struct{
-               long    doub_MSW;
-               long    doub_LSW;
-       } dis_dvalue;
-       double  dvalue;
-};
+#define                MINBYTE         -128
+#define                MAXBYTE         127
+#define                MINUBYTE        0
+#define                MAXUBYTE        255
 
 
-struct Quad {
-       long    quad_low_long;
-       long    quad_high_long;
-};
+#define                MINWORD         -32768
+#define                MAXWORD         32767
+#define                MINUWORD        0
+#define                MAXUWORD        65535
 
 
-/*
- *     Magic layout macros
- */
-#define        MINBYTE -128
-#define                MAXBYTE 127
-#define                MINWORD -32768
-#define                MAXWORD 32767
-
-#define                LITFLTMASK 0x000043F0   /*really magic*/
-/*
- *             Is the floating point double word in xp a
- *             short literal floating point number?
- */
-#define        slitflt(xp) \
-                       (    (xp->doub_LSW == 0) \
-                        &&  ( (xp->doub_MSW & LITFLTMASK) \
-                             == xp->doub_MSW) )
-/*
- *     If it is a slitflt, then extract the 6 interesting bits
- */
-#define                extlitflt(xp) \
-                       xp->doub_MSW >> 4
+#define                ISLIT(x)        (((x) >= MINLIT) && ((x) <= MAXLIT))
+#define                ISBYTE(x)       (((x) >= MINBYTE) && ((x) <= MAXBYTE))
+#define                ISUBYTE(x)      (((x) >= MINUBYTE) && ((x) <= MAXUBYTE))
+#define                ISWORD(x)       (((x) >= MINWORD) && ((x) <= MAXWORD))
+#define                ISUWORD(x)      (((x) >= MINUWORD) && ((x) <= MAXUWORD))
 
        extern  struct  arg     arglist[NARG];  /*building operands in instructions*/
        extern  struct  exp     explist[NEXP];  /*building up a list of expressions*/
 
        extern  struct  arg     arglist[NARG];  /*building operands in instructions*/
        extern  struct  exp     explist[NEXP];  /*building up a list of expressions*/
@@ -274,8 +395,8 @@ struct Quad {
        extern  struct  symtab  *lastjxxx;      
 
 #ifdef VMS
        extern  struct  symtab  *lastjxxx;      
 
 #ifdef VMS
-       extern char     *vms_obj_ptr;           /* object buffer pointer */
-       extern char     sobuf[];                /* object buffer         */
+       extern  char    *vms_obj_ptr;           /* object buffer pointer */
+       extern  char    sobuf[];                /* object buffer         */
        extern  int     objfil;                 /* VMS object file descriptor */
 #endif VMS
 
        extern  int     objfil;                 /* VMS object file descriptor */
 #endif VMS
 
@@ -312,7 +433,7 @@ struct Quad {
         *      The lexical analyzer builds up symbols in yytext.  Lookup
         *      expects its argument in this buffer
         */
         *      The lexical analyzer builds up symbols in yytext.  Lookup
         *      expects its argument in this buffer
         */
-       extern  char    yytext[NCPS+2];         /* text buffer for lexical */
+       extern  char    yytext[NCPName+2];      /* text buffer for lexical */
        /*
         *      Variables to manage the input assembler source file
         */
        /*
         *      Variables to manage the input assembler source file
         */
@@ -323,11 +444,17 @@ struct Quad {
 
        extern  int     passno;                 /* 1 or 2 */
 
 
        extern  int     passno;                 /* 1 or 2 */
 
-       extern  int     anyerrs;                /*errors assembling arguments*/
+       extern  int     anyerrs;                /*errors as'ing arguments*/
+       extern  int     anywarnings;            /*warnings as'ing arguments*/
        extern  int     silent;                 /*don't mention the errors*/
        extern  int     savelabels;             /*save labels in a.out*/
        extern  int     orgwarn;                /* questionable origin ? */
        extern  int     useVM;                  /*use virtual memory temp file*/
        extern  int     silent;                 /*don't mention the errors*/
        extern  int     savelabels;             /*save labels in a.out*/
        extern  int     orgwarn;                /* questionable origin ? */
        extern  int     useVM;                  /*use virtual memory temp file*/
+       extern  int     jxxxJUMP;               /*use jmp instead of brw for jxxx */
+       extern  int     readonlydata;           /*initialized data into text space*/
+       extern  int     nGHnumbers;             /* GH numbers used */
+       extern  int     nGHopcodes;             /* GH opcodes used */
+       extern  int     nnewopcodes;            /* new opcodes used */
 #ifdef DEBUG
        extern  int     debug;
        extern  int     toktrace;
 #ifdef DEBUG
        extern  int     debug;
        extern  int     toktrace;
@@ -335,8 +462,8 @@ struct Quad {
        /*
         *      Information about the instructions
         */
        /*
         *      Information about the instructions
         */
-       extern  struct  instab  *itab[NINST];   /*maps opcodes to instructions*/
-       extern  readonly struct instab instab[];
+       extern  struct  instab  **itab[NINST];  /*maps opcodes to instructions*/
+       extern  readonly struct Instab instab[];
 
        extern  int     curlen;                 /*current literal storage size*/
        extern  int     d124;                   /*current pointer storage size*/
 
        extern  int     curlen;                 /*current literal storage size*/
        extern  int     d124;                   /*current pointer storage size*/
@@ -344,9 +471,20 @@ struct Quad {
        struct  symtab  **lookup();             /*argument in yytext*/
        struct  symtab  *symalloc();
 
        struct  symtab  **lookup();             /*argument in yytext*/
        struct  symtab  *symalloc();
 
-#define outb(val) {dotp->xvalue++; if (passno==2) bputc((val), (txtfil));}
+       char    *Calloc();
+       char    *ClearCalloc();
+
+#define outb(val) {dotp->e_xvalue++; if (passno==2) bputc((val), (txtfil));}
+
+#define outs(cp, lg) dotp->e_xvalue += (lg); if (passno == 2) bwrite((cp), (lg), (txtfil))
+
+#ifdef UNIX
+#define        Outb(o) outb(o)
+#endif UNIX
 
 
-#define outs(cp, lg) dotp->xvalue += (lg); if (passno == 2) bwrite((cp), (lg), (txtfil))
+#ifdef VMS
+#define        Outb(o) {*vms_obj_ptr++=-1;*vms_obj_ptr++=(char)o;dotp->e_xvalue+=1;}
+#endif VMS
 
 /*
  *     Most of the time, the argument to flushfield is a power of two constant,
 
 /*
  *     Most of the time, the argument to flushfield is a power of two constant,