date and time created 88/07/22 16:08:01 by bostic
[unix-history] / usr / src / old / as.vax / as.h
index ef84371..5f8f091 100644 (file)
@@ -1,31 +1,16 @@
-/* Copyright (c) 1980 Regents of the University of California */
-/* "@(#)as.h 4.4 %G%" */
-#ifdef VMS
-# define       vax     1
-# define       VAX     1
-#endif VMS
-
-#include <sys/types.h>
-#ifdef UNIX
-
-#ifdef FLEXNAMES
-#  include <a.out.h>
-#  include <stab.h>
-#else not FLEXNAMES
-#  include <olda.out.h>
-#  include <stab.h>
-#endif FLEXNAMES
-
-#endif UNIX 
-#ifdef VMS
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)as.h        5.3 (Berkeley) %G%
+ */
 
 
-#ifdef UNIXDEVEL
-#  include <a.out.h>
-#else not UNIXDEVEL
-#  include <aout.h>
-#endif not UNIXDEVEL
+#define        reg     register
 
 
-#endif VMS
+#include <sys/types.h>
+#include <a.out.h>
+#include <stab.h>
 
 #define readonly
 #define        NINST           300
 
 #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        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       256     /* maximum length of temporary file names */
 #define        NLOC            4       /* number of location ctrs */
 #define        NLOC            4       /* number of location ctrs */
-
-#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
-# endif UNIX
-
-# ifdef VMS
-# ifdef NCPS
-#      undef   NCPS
-# endif NCPS
-#      define  NCPS    15
-# endif VMS
-
+/*
+ *     Sizes for character buffers.
+ *     what                    size #define name       comments
+ *
+ *     name assembly           NCPName 
+ *     name save               STRPOOLDALLOP   
+ *
+ *     -name saving is a simple first fit
+ */
+#ifndef STRPOOLDALLOP
+#      define STRPOOLDALLOP    8192
+#endif not STRPOOLDALLOP
+
+#define        NCPName NCPS
+#ifndef NCPS
+#      undef   NCPName
+#      define  NCPName 4096
+#endif not NCPS
+/*
+ *     Check sizes, and compiler error if sizes botch
+ */
+#if STRPOOLDALLOP < NCPName
+       $$$botch with definition sizes
+#endif test botches
 /*
  * Symbol types
  */
 /*
  * Symbol types
  */
@@ -71,7 +59,7 @@
 #define        XFORW   0x20    /* Was forward-referenced when undefined */
 
 #define        ERR     (-1)
 #define        XFORW   0x20    /* Was forward-referenced when undefined */
 
 #define        ERR     (-1)
-#define        NBPW    32      /* Bits per word */
+#define        NBWD    32      /* Bits per word */
 
 #define        AMASK   017
 
 
 #define        AMASK   017
 
 #define        AIMM    7       /* $ expr */
 #define        ASTAR   8       /* * */
 #define        AINDX   16      /* [%r] */
 #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        RELOC_PCREL     (1<<TYPLG)
+/*
+ *     reference types for loader
  */
  */
-#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
 #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     lgreflen[];     /* lg reference lengths */
+#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
-
-#ifdef VMS
-#  define PAGRND       0x1FFL
-#endif VMS
+#define        HW      0x1
+#define        FW      0x3
+#define        DW      0x7
+#define        OW      0xF
 
 #define        round(x,y)      (((x)+(y)) & ~(y))
 
 
 #define        round(x,y)      (((x)+(y)) & ~(y))
 
@@ -207,7 +185,7 @@ struct symtab{
                u_char  s_jxoveralign;  /* if a JXXX, jumped over align */
                short   s_index;        /* which segment */
                struct  symtab *s_dest; /* if JXXX, where going to */
                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 DEBUG
                short   s_jxline;       /* source line of the jump from */
 #endif
 };
                short   s_jxline;       /* source line of the jump from */
 #endif
 };
@@ -222,12 +200,13 @@ struct symtab{
  *     one saves typing, and so that they conform 
  *     with the old naming conventions.
  */
  *     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_name  s_nm.n_un.n_name
+#define        i_name  s_name
+#define        FETCHNAME(sp)   (((struct strdesc *)(sp)->s_name)->sd_string)
+#define        STRLEN(sp)      (((struct strdesc *)(sp)->s_name)->sd_strlen)
+#define        STROFF(sp)      (((struct strdesc *)(sp)->s_name)->sd_stroff)
+#define        STRPLACE(sp)    (((struct strdesc *)(sp)->s_name)->sd_place)
 #define        s_nmx   s_nm.n_un.n_strx        /* string table index */
 #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_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 */
@@ -236,7 +215,10 @@ struct symtab{
 struct instab{
        struct  nlist   s_nm;           /* instruction name, type (opcode) */
        u_char  s_tag;                  
 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.
 /*
  *     The fields nm.n_desc and nm.n_value total 6 bytes; this is
  *     just enough for the 6 bytes describing the argument types.
@@ -244,25 +226,70 @@ struct    instab{
  *     they are allocated adjacently.
  *     IF THE FORMAT OF STRUCT nlist CHANGES, THESE MAY HAVE TO BE CHANGED.
  *
  *     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 the combination of
+ *     Instab is cleverly declared to look very much like the combination of
  *     a struct symtab and a struct nlist.
  */
  *     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;
+};
+
+#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]
+
 struct Instab{
 struct Instab{
-#ifdef FLEXNAMES
        char    *I_name;
        char    *I_name;
-#else not FLEXNAMES
-       char    I_name[NCPS];
-#endif
-       u_char  I_opcode;
+       u_char  I_popcode;              /* basic op code */
        char    I_nargs;
        char    I_args[6];
        u_char  I_s_tag;
        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
  */
 };
 /*
  *     Redefinitions of fields in the struct nlist for instructions so that
  *     one saves typing, and conforms to the old naming conventions
  */
-#define        i_opcode        s_nm.n_type     /* use the same field as symtab.type */
+#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]
 
 #define        i_nargs         s_nm.n_other    /* number of arguments */
 #define        fetcharg(ptr, n) ((struct Instab *)ptr)->I_args[n]
 
@@ -273,54 +300,63 @@ struct    arg {                           /*one argument to an instruction*/
        char    a_dispsize;             /*usually d124, unless have B^, etc*/
        struct  exp *a_xp;
 };
        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    e_xvalue;               /* MUST be the first field (look at union Double) */
-       long    e_yvalue;               /* MUST be second field; least sig word of a double */
+       Bignum  e_number;       /* 128 bits of #, plus tag */
        char    e_xtype;
        char    e_xloc;
        char    e_xtype;
        char    e_xloc;
-       struct  symtab *e_xname;
+       struct  symtab          *e_xname;
 };
 };
-
-#define doub_MSW e_xvalue
-#define doub_LSW e_yvalue
-
-union  Double {
-       struct{
-               long    doub_MSW;
-               long    doub_LSW;
-       } dis_dvalue;
-       double  dvalue;
-};
-
-struct Quad {
-       long    quad_low_long;
-       long    quad_high_long;
-};
-
+#define        e_xvalue        e_number.num_num.numIl_int.Il_long
+
+#define                MINLIT          0
+#define                MAXLIT          63
+
+#define                MINBYTE         -128
+#define                MAXBYTE         127
+#define                MINUBYTE        0
+#define                MAXUBYTE        255
+
+#define                MINWORD         -32768
+#define                MAXWORD         32767
+#define                MINUWORD        0
+#define                MAXUWORD        65535
+
+#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))
 /*
 /*
- *     Magic layout macros
+ *     Definitions for strings.
+ *
+ *     Strings are stored in the string pool; see strsave(str, length)
+ *     Strings are known by their length and values.
+ *     A string pointer points to the beginning of the value bytes;
+ *
+ *     If this structure is changed, change insts also.
  */
  */
-#define        MINBYTE -128
-#define                MAXBYTE 127
-#define                MINWORD -32768
-#define                MAXWORD 32767
-
-#define                LITFLTMASK 0x000043F0   /*really magic*/
+struct strdesc{
+       int     sd_stroff;      /* offset into string file */
+       short   sd_place;       /* where string is */
+       u_short sd_strlen;      /* string length */
+       char    sd_string[1];   /* the string itself, flexible length */
+};
 /*
 /*
- *             Is the floating point double word in xp a
- *             short literal floating point number?
+ *     Where a string can be.  If these are changed, also change instrs.
  */
  */
-#define        slitflt(xp) \
-                       (    (xp->doub_LSW == 0) \
-                        &&  ( (xp->doub_MSW & LITFLTMASK) \
-                             == xp->doub_MSW) )
+#define        STR_FILE        0x1
+#define        STR_CORE        0x2
+#define        STR_BOTH        0x3
+
+struct strdesc *savestr();
+\f
 /*
 /*
- *     If it is a slitflt, then extract the 6 interesting bits
+ *     Global variables
  */
  */
-#define                extlitflt(xp) \
-                       xp->doub_MSW >> 4
-
        extern  struct  arg     arglist[NARG];  /*building operands in instructions*/
        extern  struct  exp     explist[NEXP];  /*building up a list of expressions*/
        extern  struct  exp     *xp;            /*current free expression*/
        extern  struct  arg     arglist[NARG];  /*building operands in instructions*/
        extern  struct  exp     explist[NEXP];  /*building up a list of expressions*/
        extern  struct  exp     *xp;            /*current free expression*/
@@ -332,13 +368,6 @@ struct     Quad {
         */
        extern  struct  symtab  *lastnam;
        extern  struct  symtab  *lastjxxx;      
         */
        extern  struct  symtab  *lastnam;
        extern  struct  symtab  *lastjxxx;      
-
-#ifdef VMS
-       extern  char    *vms_obj_ptr;           /* object buffer pointer */
-       extern  char    sobuf[];                /* object buffer         */
-       extern  int     objfil;                 /* VMS object file descriptor */
-#endif VMS
-
        /*
         *      Lgensym is used to make up funny names for local labels.
         *      lgensym[i] is the current funny number to put after
        /*
         *      Lgensym is used to make up funny names for local labels.
         *      lgensym[i] is the current funny number to put after
@@ -351,7 +380,6 @@ struct      Quad {
        extern  int     lgensym[10];
        extern  char    genref[10];
 
        extern  int     lgensym[10];
        extern  char    genref[10];
 
-       extern  char    tmpn1[TNAMESIZE];       /* Interpass temporary */
        extern  struct  exp     *dotp;          /* the current dot location */
        extern  int     loctr;
 
        extern  struct  exp     *dotp;          /* the current dot location */
        extern  int     loctr;
 
@@ -372,23 +400,32 @@ 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
         */
        extern  int     lineno;                 /*the line number*/
        extern  char    *dotsname;              /*the name of the as source*/
 
        /*
         *      Variables to manage the input assembler source file
         */
        extern  int     lineno;                 /*the line number*/
        extern  char    *dotsname;              /*the name of the as source*/
 
-       extern  FILE    *tmpfil;                /* interpass communication*/
+       extern  FILE    *tokfile;               /* temp token communication*/
+       extern  FILE    *strfile;               /* temp string file*/
+       extern  char    tokfilename[TNAMESIZE]; /* token file name */
+       extern  char    strfilename[TNAMESIZE]; /* string file name */
+       extern  int     strfilepos;             /* position in string file */
 
        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     jxxxJUMP;               /*use jmp instead of brw for jxxx */
        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;
@@ -396,19 +433,24 @@ struct    Quad {
        /*
         *      Information about the instructions
         */
        /*
         *      Information about the instructions
         */
-       extern  struct  instab  *itab[NINST];   /*maps opcodes to instructions*/
+       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  readonly struct Instab instab[];
 
        extern  int     curlen;                 /*current literal storage size*/
        extern  int     d124;                   /*current pointer storage size*/
+       extern  int     maxalign;               /*maximum .align allowed*/
        
        struct  symtab  **lookup();             /*argument in yytext*/
        struct  symtab  *symalloc();
 
        
        struct  symtab  **lookup();             /*argument in yytext*/
        struct  symtab  *symalloc();
 
+       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))
 
 #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))
 
+#define        Outb(o) outb(o)
 /*
  *     Most of the time, the argument to flushfield is a power of two constant,
  *     the calculations involving it can be optimized to shifts.
 /*
  *     Most of the time, the argument to flushfield is a power of two constant,
  *     the calculations involving it can be optimized to shifts.
@@ -427,7 +469,7 @@ struct      biobuf {
        short   b_nleft;                /* Number free spaces left in b_buf */
 /* Initialize to be less than BUFSIZ initially, to boundary align in file */
        char    *b_ptr;                 /* Next place to stuff characters */
        short   b_nleft;                /* Number free spaces left in b_buf */
 /* Initialize to be less than BUFSIZ initially, to boundary align in file */
        char    *b_ptr;                 /* Next place to stuff characters */
-       char    b_buf[BUFSIZ];          /* The buffer itself */
+       char    *b_buf;                 /* Pointer to the buffer */
        off_t   b_off;                  /* Current file offset */
        struct  biobuf *b_link;         /* Link in chain for bflush() */
 };
        off_t   b_off;                  /* Current file offset */
        struct  biobuf *b_link;         /* Link in chain for bflush() */
 };
@@ -437,6 +479,7 @@ struct      biobuf {
 
        extern  BFILE   *biobufs;       /* head of the block I/O buffer chain */
        extern  int     biofd;          /* file descriptor for block I/O file */
 
        extern  BFILE   *biobufs;       /* head of the block I/O buffer chain */
        extern  int     biofd;          /* file descriptor for block I/O file */
+       extern  int     biobufsize;     /* optimal block size for I/O */
        extern  off_t   boffset;        /* physical position in logical file */
 
        /*
        extern  off_t   boffset;        /* physical position in logical file */
 
        /*