date and time created 83/08/11 20:49:31 by sam
[unix-history] / usr / src / old / as.vax / asmain.c
index ef9c83e..53f692e 100644 (file)
@@ -1,22 +1,20 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char sccsid[] = "@(#)asmain.c 4.7 %G%";
+/*
+ *     Copyright (c) 1982 Regents of the University of California
+ */
+#ifndef lint
+static char sccsid[] = "@(#)asmain.c 4.13 %G%";
+#endif not lint
+
 #include <stdio.h>
 #include <ctype.h>
 #include <signal.h>
 
 #include "as.h"
 #include "assyms.h"
 #include <stdio.h>
 #include <ctype.h>
 #include <signal.h>
 
 #include "as.h"
 #include "assyms.h"
-#include "asexpr.h"
 #include "asscan.h"
 #include "asscan.h"
+#include "asexpr.h"
 
 
-#ifdef UNIX
-#define        unix_lang_name "VAX/UNIX Assembler V%G% 4.7"
-#endif
-
-#ifdef VMS
-#define vms_lang_name "VAX/VMS C Assembler V1.00"
-#endif VMS
-
+#define        unix_lang_name "VAX/UNIX Assembler V%G% 4.13"
 /*
  *     variables to manage reading the assembly source files
  */
 /*
  *     variables to manage reading the assembly source files
  */
@@ -31,23 +29,22 @@ int silent = 0;     /*don't complain about any errors*/
 int    savelabels = 0; /*write the labels to the a.out file*/
 int    d124 = 4;       /*default allocate 4 bytes for unknown pointers*/
 int    anyerrs = 0;    /*no errors yet*/
 int    savelabels = 0; /*write the labels to the a.out file*/
 int    d124 = 4;       /*default allocate 4 bytes for unknown pointers*/
 int    anyerrs = 0;    /*no errors yet*/
+int    anywarnings=0;  /*no warnings yet*/
 int    orgwarn = 0;    /*Bad origins*/
 int    passno = 1;     /* current pass*/
 int    jxxxJUMP = 0;   /* in jxxxes that branch too far, use jmp instead of brw */
 int    readonlydata = 0;       /* initialzed data -> text space */
 
 int    orgwarn = 0;    /*Bad origins*/
 int    passno = 1;     /* current pass*/
 int    jxxxJUMP = 0;   /* in jxxxes that branch too far, use jmp instead of brw */
 int    readonlydata = 0;       /* initialzed data -> text space */
 
+int    nGHnumbers = 0;         /* GH numbers used */
+int    nGHopcodes = 0;         /* GH opcodes used */
+int    nnewopcodes = 0;        /* new opcodes used */
+
 #ifdef DEBUG
 int    debug = 0;
 int    toktrace = 0;
 #endif
 
 #ifdef DEBUG
 int    debug = 0;
 int    toktrace = 0;
 #endif
 
-int    useVM =         /*put the temp file in virtual memory*/
-#ifdef VMS
-       1;              /*VMS has virtual memory (duh)*/
-#endif VMS
-#ifdef UNIX
-       0;
-#endif
+int    useVM = 0;
 
 char   *endcore;       /*where to get more symbol space*/
 
 
 char   *endcore;       /*where to get more symbol space*/
 
@@ -72,11 +69,19 @@ u_long      drsize;         /* total data relocation size */
 struct exp     usedot[NLOC+NLOC];      /* info about all segments */
 struct exp     *dotp;                  /* data/text location pointer */
 /*
 struct exp     usedot[NLOC+NLOC];      /* info about all segments */
 struct exp     *dotp;                  /* data/text location pointer */
 /*
- *     The inter pass temporary file is opened and closed by stdio, but
+ *     The inter pass temporary token file is opened and closed by stdio, but
  *     is written to using direct read/write, as the temporary file
  *     is composed of buffers exactly BUFSIZ long.
  */
  *     is written to using direct read/write, as the temporary file
  *     is composed of buffers exactly BUFSIZ long.
  */
-FILE   *tmpfil;                        /* interpass communication file */
+FILE   *tokfile;                       /* interpass communication file */
+char   tokfilename[TNAMESIZE];
+/*
+ *     The string file is the string table
+ *     cat'ed to the end of the built up a.out file
+ */
+FILE   *strfile;                       /* interpass string file */
+char   strfilename[TNAMESIZE];
+int    strfilepos = 0;                 /* position within the string file */
 /*
  *     a.out is created during the second pass.
  *     It is opened by stdio, but is filled with the parallel
 /*
  *     a.out is created during the second pass.
  *     It is opened by stdio, but is filled with the parallel
@@ -153,26 +158,18 @@ BFILE     *relocfile;                     /* concatnated relocation info */
  *
  *     We use relfil to output the symbol table information.
  */
  *
  *     We use relfil to output the symbol table information.
  */
-
-char   *tmpdirprefix =
-#ifdef UNIX
-                       "/tmp/";
-#else VMS
-                       "/usr/tmp/";
-#endif
-
-#define                TMP_SUFFIX      "asXXXXXX"
-char           tmpn1[TNAMESIZE];
-
+char   *tmpdirprefix = "/tmp/";
 int delexit();
 
 main(argc, argv)
        int     argc;
        char    **argv;
 {
 int delexit();
 
 main(argc, argv)
        int     argc;
        char    **argv;
 {
+       char    *sbrk();
 
 
-       tmpn1[0] = 0;
-       endcore = (char *)sbrk(0);
+       tokfilename[0] = 0;
+       strfilename[0] = 0;
+       endcore = sbrk(0);
 
        argprocess(argc, argv);         /* process argument lists */
        if (anyerrs) exit(1);
 
        argprocess(argc, argv);         /* process argument lists */
        if (anyerrs) exit(1);
@@ -190,14 +187,14 @@ main(argc, argv)
        if (anyerrs) delexit();
 
        open_a_out();                   /* open a.out */
        if (anyerrs) delexit();
 
        open_a_out();                   /* open a.out */
-       roundsegments();                /* round segments to DW */
+       roundsegments();                /* round segments to FW */
        build_hdr();                    /* build initial header, and output */
        
        i_pass2();                      /* reopen temporary file, etc */
        pass2();                        /* second pass through the virtual .s */
        if (anyerrs) delexit();
 
        build_hdr();                    /* build initial header, and output */
        
        i_pass2();                      /* reopen temporary file, etc */
        pass2();                        /* second pass through the virtual .s */
        if (anyerrs) delexit();
 
-       fillsegments();                 /* fill segments with 0 to DW */
+       fillsegments();                 /* fill segments with 0 to FW */
        reloc_syms();                   /* dump relocation and symbol table */
 
        delete();                       /* remove tmp file */
        reloc_syms();                   /* dump relocation and symbol table */
 
        delete();                       /* remove tmp file */
@@ -206,8 +203,18 @@ main(argc, argv)
 
        if (anyerrs == 0 && orgwarn)
                yyerror("Caution: absolute origins.\n");
 
        if (anyerrs == 0 && orgwarn)
                yyerror("Caution: absolute origins.\n");
+
+       if (nGHnumbers)
+               yywarning("Caution: G or H format floating point numbers");
+       if (nGHopcodes)
+               yywarning("Caution: G or H format floating point operators");
+       if (nnewopcodes)
+               yywarning("Caution: New Opcodes");
+       if (nGHnumbers || nGHopcodes || nnewopcodes)
+               yywarning("These are not defined for all implementations of the VAX architecture.\n");
+
        exit(anyerrs != 0);
        exit(anyerrs != 0);
-}      /*end of UNIX main*/
+}
 
 argprocess(argc, argv)
        int     argc;
 
 argprocess(argc, argv)
        int     argc;
@@ -238,6 +245,9 @@ argprocess(argc, argv)
                                        yyerror("Unknown flag: %c", *--cp);
                                        cp++;
                                        break;
                                        yyerror("Unknown flag: %c", *--cp);
                                        cp++;
                                        break;
+                                case 'v':
+                                       selfwhat(stdout);
+                                       exit(1);
                                 case 'd':
                                        d124 = *cp++ - '0';
                                        if ( (d124 != 1) && (d124 != 2) && 
                                 case 'd':
                                        d124 = *cp++ - '0';
                                        if ( (d124 != 1) && (d124 != 2) && 
@@ -296,6 +306,37 @@ argprocess(argc, argv)
        }
        /* innames[ninfiles] = 0; */
 }
        }
        /* innames[ninfiles] = 0; */
 }
+/*
+ *     poke through the data space and find all sccs identifiers.
+ *     We assume:
+ *     a) that extern char **environ; is the first thing in the bss
+ *     segment (true, if one is using the new version of cmgt.crt0.c)
+ *     b) that the sccsid's have not been put into text space.
+ */
+selfwhat(place)
+       FILE    *place;
+{
+       extern  char **environ;
+       register        char    *ub;
+       register        char *cp;
+       register        char    *pat;
+       char    *sbrk();
+
+       for (cp = (char *)&environ, ub = sbrk(0); cp < ub; cp++){
+               if (cp[0] != '@') continue;
+               if (cp[1] != '(') continue;
+               if (cp[2] != '#') continue;
+               if (cp[3] != ')') continue;
+               fputc('\t', place);
+               for (cp += 4; cp < ub; cp++){
+                       if (*cp == 0) break;
+                       if (*cp == '>') break;
+                       if (*cp == '\n') break;
+                       fputc(*cp, place);
+               }
+               fputc('\n', place);
+       }
+}
 
 initialize()
 {
 
 initialize()
 {
@@ -324,8 +365,6 @@ zeroorigins()
                usedot[NLOC + locindex].e_xtype = XDATA;
                usedot[locindex].e_xvalue = 0;
                usedot[NLOC + locindex].e_xvalue = 0;
                usedot[NLOC + locindex].e_xtype = XDATA;
                usedot[locindex].e_xvalue = 0;
                usedot[NLOC + locindex].e_xvalue = 0;
-               usedot[locindex].e_yvalue = 0;
-               usedot[NLOC + locindex].e_yvalue = 0;
        }
 }
 
        }
 }
 
@@ -341,23 +380,40 @@ zerolocals()
 
 i_pass1()
 {
 
 i_pass1()
 {
-       if (useVM == 0){
-               strcat(tmpn1, tmpdirprefix);
-               if (tmpdirprefix[strlen(tmpdirprefix)-1] != '/')
-                       strcat(tmpn1, "/");
-               strcat(tmpn1, TMP_SUFFIX);
-               mktemp(tmpn1);
-               tmpfil = fopen(tmpn1, "w");
-               if (tmpfil==NULL) {
-                 yyerror("Bad pass 1 temporary file for writing %s", tmpn1);
-                 delexit();
-               }
-       }
+       FILE    *tempopen();
+       if (useVM == 0)
+               tokfile = tempopen(tokfilename, "T");
+       strfile = tempopen(strfilename, "S");
+       /*
+        *      write out the string length.
+        *      This will be overwritten when the
+        *      strings are tacked onto the growing a.out file
+        */
+       strfilepos = sizeof(int);
+       fwrite(&strfilepos, sizeof(int), 1, strfile);
 
 
-       inittmpfile();
+       inittokfile();
        initijxxx();
 }
 
        initijxxx();
 }
 
+FILE *tempopen(tname, part)
+       char    *tname;
+       char    *part;
+{
+       FILE    *file;
+       sprintf(tname, "%s%sas%s%05d",
+               tmpdirprefix,
+               (tmpdirprefix[strlen(tmpdirprefix)-1] != '/') ? "/" : 0,
+               part,
+               getpid());
+       file = fopen(tname, "w");
+       if (file == NULL) {
+               yyerror("Bad pass 1 temporary file for writing %s", tname);
+               delexit();
+       }
+       return(file);
+}
+
 pass1()
 {
        register        int     i;
 pass1()
 {
        register        int     i;
@@ -386,7 +442,7 @@ pass1()
                }
        }
 
                }
        }
 
-       closetmpfile();         /*kick out the last buffered intermediate text*/
+       closetokfile();         /*kick out the last buffered intermediate text*/
 }
 
 testlocals()
 }
 
 testlocals()
@@ -438,7 +494,7 @@ roundsegments()
         */
        tsize = 0;
        for (locindex=0; locindex<NLOC; locindex++) {
         */
        tsize = 0;
        for (locindex=0; locindex<NLOC; locindex++) {
-               v = round(usedot[locindex].e_xvalue, DW);
+               v = round(usedot[locindex].e_xvalue, FW);
                usedot[locindex].e_xvalue = tsize;
                if ((locindex == 0) || (v != 0) ){
                        usefile[locindex] = (BFILE *)Calloc(1, sizeof(BFILE));
                usedot[locindex].e_xvalue = tsize;
                if ((locindex == 0) || (v != 0) ){
                        usefile[locindex] = (BFILE *)Calloc(1, sizeof(BFILE));
@@ -454,9 +510,9 @@ roundsegments()
        /*
         *              Round and assign data segment origins.
         */
        /*
         *              Round and assign data segment origins.
         */
-       datbase = round(tsize, DW);
+       datbase = round(tsize, FW);
        for (locindex=0; locindex<NLOC; locindex++) {
        for (locindex=0; locindex<NLOC; locindex++) {
-               v = round(usedot[NLOC+locindex].e_xvalue, DW);
+               v = round(usedot[NLOC+locindex].e_xvalue, FW);
                usedot[NLOC+locindex].e_xvalue = datbase + dsize;
                if (v != 0){
                        usefile[NLOC + locindex] = (BFILE *)Calloc(1,sizeof(BFILE));
                usedot[NLOC+locindex].e_xvalue = datbase + dsize;
                if (v != 0){
                        usefile[NLOC + locindex] = (BFILE *)Calloc(1,sizeof(BFILE));
@@ -507,13 +563,15 @@ build_hdr()
 i_pass2()
 {
        if (useVM == 0) {
 i_pass2()
 {
        if (useVM == 0) {
-               fclose(tmpfil);
-               tmpfil = fopen(tmpn1, "r");
-               if (tmpfil==NULL) {
-                  yyerror("Bad pass 2 temporary file for reading %s", tmpn1);
+               fclose(tokfile);
+               tokfile = fopen(tokfilename, "r");
+               if (tokfile==NULL) {
+                  yyerror("Bad pass 2 temporary file for reading %s", tokfilename);
                   delexit();
                }
        }
                   delexit();
                }
        }
+       fclose(strfile);
+       strfile = fopen(strfilename, "r");
 }
 
 pass2()
 }
 
 pass2()
@@ -529,24 +587,24 @@ pass2()
        relfil = 0;             /* outrel takes care of the rest */
        initoutrel();
 
        relfil = 0;             /* outrel takes care of the rest */
        initoutrel();
 
-       inittmpfile();
+       inittokfile();
 
        yyparse();
 
 
        yyparse();
 
-       closetmpfile();
+       closetokfile();
 }
 
 fillsegments()
 {
        int     locindex;
        /*
 }
 
 fillsegments()
 {
        int     locindex;
        /*
-        *      Round text and data segments to DW by appending zeros
+        *      Round text and data segments to FW by appending zeros
         */
        for (locindex = 0; locindex < NLOC + NLOC; locindex++) {
                if (usefile[locindex]) {
                        txtfil = usefile[locindex];
                        dotp = &usedot[locindex];
         */
        for (locindex = 0; locindex < NLOC + NLOC; locindex++) {
                if (usefile[locindex]) {
                        txtfil = usefile[locindex];
                        dotp = &usedot[locindex];
-                       while (usedot[locindex].e_xvalue & DW)
+                       while (usedot[locindex].e_xvalue & FW)
                                outb(0);
                }
        }
                                outb(0);
                }
        }
@@ -573,15 +631,19 @@ reloc_syms()
                hdr.a_drsize = 0;
        }
        /*
                hdr.a_drsize = 0;
        }
        /*
-        *      Output the symbol table
-        *      and if FLEXNAMES is set, the string pool
+        *      Output the symbol table and the string pool
+        *
+        *      We must first rewind the string pool file to its beginning,
+        *      in case it was seek'ed into for fetching ascii and asciz
+        *      strings.
         */
         */
+       fseek(strfile, 0, 0);
        symwrite(relocfile);
 }
 
 fix_a_out()
 {
        symwrite(relocfile);
 }
 
 fix_a_out()
 {
-       if (lseek(a_out_file->_file, 0L, 0) < 0)
+       if (lseek(a_out_file->_file, 0L, 0) < 0L)
                yyerror("Reposition for header rewrite fails");
        if (write(a_out_file->_file, (char *)&hdr, sizeof (struct exec)) < 0)
                yyerror("Rewrite of header fails");
                yyerror("Reposition for header rewrite fails");
        if (write(a_out_file->_file, (char *)&hdr, sizeof (struct exec)) < 0)
                yyerror("Rewrite of header fails");
@@ -598,8 +660,10 @@ delexit()
 
 delete()
 {
 
 delete()
 {
-       if (useVM == 0 || tmpn1[0])
-               unlink(tmpn1);
+       if (useVM == 0 || tokfilename[0])
+               unlink(tokfilename);
+       if (strfilename[0])
+               unlink(strfilename);
 }
 
 sawabort()
 }
 
 sawabort()