date and time created 88/10/21 13:47:49 by bostic
[unix-history] / usr / src / old / as.vax / asjxxx.c
index b3e07e0..b3d6157 100644 (file)
@@ -1,5 +1,13 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char sccsid[] = "@(#)asjxxx.c 4.3 %G%";
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)asjxxx.c   5.4 (Berkeley) %G%";
+#endif not lint
+
 #include       <stdio.h>
 #include       "as.h"
 #include       "assyms.h"
 #include       <stdio.h>
 #include       "as.h"
 #include       "assyms.h"
@@ -42,8 +50,10 @@ initijxxx()
 /*
  *     Handle jxxx instructions
  */
 /*
  *     Handle jxxx instructions
  */
-ijxout(op,ap,nact)
-       struct arg *ap;
+ijxout(opcode, ap, nact)
+       struct  Opcode  opcode;
+       struct  arg     *ap;
+       int     nact;
 {
        if (passno == 1){
                /*
 {
        if (passno == 1){
                /*
@@ -56,11 +66,11 @@ ijxout(op,ap,nact)
                /*
                 *      We assume the MINIMAL length
                 */
                /*
                 *      We assume the MINIMAL length
                 */
-               putins(op,ap,nact); 
+               putins(opcode, ap, nact); 
                jumpfrom = lastjxxx;
                jumpfrom->s_tag = JXACTIVE;
                jumpfrom->s_jxbump = 0;
                jumpfrom = lastjxxx;
                jumpfrom->s_tag = JXACTIVE;
                jumpfrom->s_jxbump = 0;
-               if (op == JBR)
+               if (opcode.Op_popcode == JBR)
                        jumpfrom->s_jxfear = jbrfsize;
                else
                        jumpfrom->s_jxfear = jxxxfsize;
                        jumpfrom->s_jxfear = jbrfsize;
                else
                        jumpfrom->s_jxfear = jxxxfsize;
@@ -69,9 +79,13 @@ ijxout(op,ap,nact)
                jumpfrom->s_dest = lastnam;
                jumpfrom->s_type = dotp->e_xtype;       /*only TEXT or DATA*/
                jumpfrom->s_index = dotp-usedot;
                jumpfrom->s_dest = lastnam;
                jumpfrom->s_type = dotp->e_xtype;       /*only TEXT or DATA*/
                jumpfrom->s_index = dotp-usedot;
+#ifdef DEBUG
+               jumpfrom->s_name = ITABFETCH(opcode)->i_name;
+               jumpfrom->s_jxline = lineno;
+#endif
                /*
                 *      value ALWAYS (ALWAYS!!!) indexes the next instruction
                /*
                 *      value ALWAYS (ALWAYS!!!) indexes the next instruction
-                *      after the jump, even in the jump must be exploded
+                *      after the jump, even if the jump must be exploded
                 *      (bumped)
                 */
                jumpfrom->s_value = dotp->e_xvalue;
                 *      (bumped)
                 */
                jumpfrom->s_value = dotp->e_xvalue;
@@ -80,10 +94,11 @@ ijxout(op,ap,nact)
                /*
                 *      READ THIS AFTER LOOKING AT jxxxfix()
                 */
                /*
                 *      READ THIS AFTER LOOKING AT jxxxfix()
                 */
-               register long           oxvalue;
-               register struct exp     *xp; 
-               register struct symtab  *tunnel;
-               register struct arg     *aplast;
+               reg     long            oxvalue;
+               reg     struct  exp     *xp; 
+               reg     struct  symtab  *tunnel;
+               reg     struct  arg     *aplast;
+                       struct  Opcode  nopcode;
 
                aplast = ap + nact - 1;
                xp = aplast->a_xp;
 
                aplast = ap + nact - 1;
                xp = aplast->a_xp;
@@ -97,35 +112,80 @@ ijxout(op,ap,nact)
                                                        /*non bumped branch byteis only 2 back*/
                }
                if (lastjxxx->s_jxbump == 0){   /*wasn't bumped, so is short form*/
                                                        /*non bumped branch byteis only 2 back*/
                }
                if (lastjxxx->s_jxbump == 0){   /*wasn't bumped, so is short form*/
-                       putins(op, ap, nact);
+                       putins(opcode, ap, nact);
                } else {
                } else {
-                       if (op != JBR){ /*branch reverse conditional byte over 
-                                         branch unconditional word*/
+                       if (opcode.Op_popcode != JBR){
+                               /*
+                                *      branch reverse conditional byte over
+                                *      branch unconditional word
+                                */
                                oxvalue = xp->e_xvalue;
                                xp->e_xvalue = lastjxxx->s_value;
                                oxvalue = xp->e_xvalue;
                                xp->e_xvalue = lastjxxx->s_value;
-                               putins(op^1, ap, nact);
+                               nopcode = opcode;
+                               nopcode.Op_popcode ^= 1;
+                               putins(nopcode, ap, nact);
                                xp->e_xvalue = oxvalue;
                        }
                                xp->e_xvalue = oxvalue;
                        }
-                       putins(jxxxJUMP ? JMP : BRW, aplast, 1);
+                       nopcode.Op_eopcode = CORE;
+                       nopcode.Op_popcode = jxxxJUMP ? JMP : BRW;
+                       putins(nopcode, aplast, 1);
                }
        }
                }
        }
-}      /*end of ijxout*/
+}
 
 jalign(xp, sp)
        register struct exp *xp;
        register struct symtab *sp;
 {
        register        int     mask;
 
 jalign(xp, sp)
        register struct exp *xp;
        register struct symtab *sp;
 {
        register        int     mask;
-       if (xp->e_xtype != XABS || xp->e_xvalue < 0 || xp->e_xvalue > 16) {
+#ifdef DEBUG
+       static struct strdesc noname;
+#endif
+       /*
+        *      Problem with .align
+        *
+        *      When the loader constructs an executable file from
+        *      a number of objects, it effectively concatnates
+        *      together all of the text segments from all objects,
+        *      and then all of the data segments.
+        *
+        *      If we do an align by a large value, we can align
+        *      within the a.out this assembly produces, but
+        *      after the loader concatnates, the alignment can't
+        *      be guaranteed if the objects preceding this one
+        *      in the load are also aligned to the same size.
+        *
+        *      Currently, the loader guarantees full word alignment.
+        *      So, ridiculous aligns are caught here and converted
+        *      to a .align (maxalign), if possible, where maxalign
+        *      is set in the command line, and defaults to 2.
+        */
+       if (   ( (xp->e_xtype & XTYPE) != XABS)
+           || (xp->e_xvalue < 0)
+           || (xp->e_xvalue > 16)
+           ) {
                yyerror("Illegal `align' argument");
                return;
        }
                yyerror("Illegal `align' argument");
                return;
        }
-       flushfield(NBPW/4);
+       if (xp->e_xvalue > maxalign){
+               if (passno == 1){
+                       yywarning(".align %d is NOT preserved by the loader",
+                               xp->e_xvalue);
+                       yywarning(".align %d converted to .align %d",
+                               xp->e_xvalue, maxalign);
+               }
+               xp->e_xvalue = maxalign;
+       }
+       flushfield(NBWD/4);
        if (passno == 1) {
                sp->s_tag = JXALIGN;
                sp->s_jxfear = (1 << xp->e_xvalue) - 1;
                sp->s_type = dotp->e_xtype;
                sp->s_index = dotp-usedot;
        if (passno == 1) {
                sp->s_tag = JXALIGN;
                sp->s_jxfear = (1 << xp->e_xvalue) - 1;
                sp->s_type = dotp->e_xtype;
                sp->s_index = dotp-usedot;
+#ifdef DEBUG
+               sp->s_name = (char *)&noname;
+               sp->s_jxline = lineno;
+#endif
                /*
                 *      We guess that the align will take up at least one
                 *      byte in the code output.  We will correct for this
                /*
                 *      We guess that the align will take up at least one
                 *      byte in the code output.  We will correct for this
@@ -144,16 +204,8 @@ jalign(xp, sp)
                njxxx++;
        } else {
                mask = (1 << xp->e_xvalue) - 1;
                njxxx++;
        } else {
                mask = (1 << xp->e_xvalue) - 1;
-               while (dotp->e_xvalue & mask){
-#ifdef UNIX
-                       outb(0);
-#endif UNIX
-#ifdef VMS
-                       *vms_obj_ptr++ = -1;
-                       *vms_obj_ptr++ = 0;
-                       dotp->e_xvalue += 1;
-#endif VMS
-               }
+               while (dotp->e_xvalue & mask)
+                       Outb(0);
        }
 }
 
        }
 }
 
@@ -184,6 +236,9 @@ jxxxfix()
             *  Do a lazy topological sort.
             */
            for (topono = 1, nchange = 1; nchange != 0; topono++){
             *  Do a lazy topological sort.
             */
            for (topono = 1, nchange = 1; nchange != 0; topono++){
+#ifdef lint
+               topno = topno;
+#endif lint
 #ifdef DEBUG
                if (debug)
                        printf("\nSegment %d, topo iteration %d\n",
 #ifdef DEBUG
                if (debug)
                        printf("\nSegment %d, topo iteration %d\n",
@@ -261,7 +316,8 @@ jxxxfix()
 #ifdef DEBUG
                                                if(debug)
                                                printf("Tunnel from %s from line %d\n",
 #ifdef DEBUG
                                                if(debug)
                                                printf("Tunnel from %s from line %d\n",
-                                                       jumpfrom->s_name, lineno);
+                                                       FETCHNAME(jumpfrom),
+                                                       jumpfrom->s_jxline);
 #endif
                                                continue;
                                } else {        /*tunneling not possible*/
 #endif
                                                continue;
                                } else {        /*tunneling not possible*/
@@ -283,7 +339,7 @@ jxxxfix()
                        if (displ >= 0) {
                                SEGITERATE(segno, cojumpfrom + 1,0,cointdest,
                                                intdest, ubintdest, ++){
                        if (displ >= 0) {
                                SEGITERATE(segno, cojumpfrom + 1,0,cointdest,
                                                intdest, ubintdest, ++){
-                                       if (intdest->s_value > dest->s_value) 
+                                       if (intdest == dest)
                                                break; /* beyond destination */
                                        if (intdest->s_tag <= JXQUESTIONABLE)
                                                continue;       /*frozen solid*/
                                                break; /* beyond destination */
                                        if (intdest->s_tag <= JXQUESTIONABLE)
                                                continue;       /*frozen solid*/
@@ -313,7 +369,7 @@ jxxxfix()
                         */
                                SEGITERATE(segno, cojumpfrom - 1,1,cointdest,
                                  intdest, ubintdest, --){
                         */
                                SEGITERATE(segno, cojumpfrom - 1,1,cointdest,
                                  intdest, ubintdest, --){
-                                       if (intdest->s_value <= dest->s_value) 
+                                       if (intdest == dest)
                                                break; /* beyond destination */
                                        if (intdest->s_tag <= JXQUESTIONABLE)
                                                continue;       /*frozen solid*/
                                                break; /* beyond destination */
                                        if (intdest->s_tag <= JXQUESTIONABLE)
                                                continue;       /*frozen solid*/
@@ -436,9 +492,10 @@ jxxxbump(segno, starthint)
                        if (debug){
                        if (sp->s_dest != 0)
                                printf("Explode jump to %s on line %d\n",
                        if (debug){
                        if (sp->s_dest != 0)
                                printf("Explode jump to %s on line %d\n",
-                                       sp->s_dest->s_name, lineno);
+                                       FETCHNAME(sp->s_dest), sp->s_jxline);
                        else
                        else
-                               printf("Explode an align!\n");
+                               printf("Explode an align! on line %d\n",
+                                       sp->s_jxline);
                        }
 #endif
                        sp->s_tag = JXINACTIVE;
                        }
 #endif
                        sp->s_tag = JXINACTIVE;