BSD 4_4 release
[unix-history] / usr / src / usr.bin / pascal / pdx / machine / nextaddr.c
index 641702f..dc0ac5c 100644 (file)
@@ -1,6 +1,39 @@
-/* Copyright (c) 1982 Regents of the University of California */
+/*-
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 
 
-static char sccsid[] = "@(#)nextaddr.c 1.4 %G%";
+#ifndef lint
+static char sccsid[] = "@(#)nextaddr.c 8.1 (Berkeley) 6/6/93";
+#endif /* not lint */
 
 /*
  * Calculate the next address that will be executed from the current one.
 
 /*
  * Calculate the next address that will be executed from the current one.
@@ -25,6 +58,12 @@ static char sccsid[] = "@(#)nextaddr.c 1.4 %G%";
 #include "process/pxinfo.h"
 #include "process/process.rep"
 
 #include "process/pxinfo.h"
 #include "process/process.rep"
 
+#ifdef tahoe
+#define EVEN 3
+#else
+#define EVEN 1
+#endif
+
 LOCAL ADDRESS docase(), dofor();
 
 ADDRESS nextaddr(beginaddr, isnext)
 LOCAL ADDRESS docase(), dofor();
 
 ADDRESS nextaddr(beginaddr, isnext)
@@ -41,6 +80,9 @@ BOOLEAN isnext;
        char byte[2];
     } o;
 
        char byte[2];
     } o;
 
+#ifdef tahoe
+    doret(process);
+#endif
     addr = beginaddr;
     iread(&o.word, addr, sizeof(o.word));
     op = (PXOP) o.byte[0];
     addr = beginaddr;
     iread(&o.word, addr, sizeof(o.word));
     op = (PXOP) o.byte[0];
@@ -48,27 +90,29 @@ BOOLEAN isnext;
     addr += sizeof(short);
     switch(op) {
 
     addr += sizeof(short);
     switch(op) {
 
-#   if (isvaxpx)
     /*
     /*
-     * The version of px on the VAX assumes that the instruction
+     * The version of px we are using assumes that the instruction
      * at the entry point of a function is a TRA4 to the beginning
      * of the block.
      */
      * at the entry point of a function is a TRA4 to the beginning
      * of the block.
      */
-#   endif
        case O_CALL: {
            ADDRESS eaddr;
 
            if (isnext) {
                addr += sizeof(int);
        case O_CALL: {
            ADDRESS eaddr;
 
            if (isnext) {
                addr += sizeof(int);
+#ifdef tahoe
+               addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
+#endif
            } else {
            } else {
-#               if (isvaxpx)
-                   iread(&eaddr, addr, sizeof(eaddr));
-                   addr = eaddr + sizeof(short);
-                   iread(&addr, addr, sizeof(addr));
-#               else
-                   iread(&offset, addr, sizeof(offset));
-                   addr += offset;
-#               endif
+#ifdef tahoe
+               addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
+#endif
+               iread(&eaddr, addr, sizeof(eaddr));
+               addr = eaddr + sizeof(short);
+#ifdef tahoe
+               addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
+#endif
+               iread(&addr, addr, sizeof(addr));
                stepto(addr);
                if (linelookup(addr) == 0) {
                    bpact();
                stepto(addr);
                if (linelookup(addr) == 0) {
                    bpact();
@@ -85,17 +129,22 @@ BOOLEAN isnext;
            break;
        }
 
            break;
        }
 
-#   if (isvaxpx)
        case O_FCALL: {
            ADDRESS eaddr;
            ADDRESS *fparam;
 
            if (!isnext) {
                stepto(addr - sizeof(short));
        case O_FCALL: {
            ADDRESS eaddr;
            ADDRESS *fparam;
 
            if (!isnext) {
                stepto(addr - sizeof(short));
+#ifdef tahoe
+               doret(process);
+#endif
                dread(&fparam, process->sp + sizeof(ADDRESS), sizeof(fparam));
                dread(&eaddr, fparam, sizeof(eaddr));
                addr = eaddr - ENDOFF;
                stepto(addr);
                dread(&fparam, process->sp + sizeof(ADDRESS), sizeof(fparam));
                dread(&eaddr, fparam, sizeof(eaddr));
                addr = eaddr - ENDOFF;
                stepto(addr);
+#ifdef tahoe
+               doret(process);
+#endif
                if (linelookup(addr) == 0) {
                    bpact();
                    addr = pc;
                if (linelookup(addr) == 0) {
                    bpact();
                    addr = pc;
@@ -110,7 +159,6 @@ BOOLEAN isnext;
            }
            break;
        }
            }
            break;
        }
-#   endif
 
        case O_END:
            if ((addr - sizeof(short)) == lastaddr()) {
 
        case O_END:
            if ((addr - sizeof(short)) == lastaddr()) {
@@ -130,12 +178,13 @@ BOOLEAN isnext;
            }
            break;
 
            }
            break;
 
-#   if (isvaxpx)
        case O_TRA4:
        case O_GOTO:
        case O_TRA4:
        case O_GOTO:
+#ifdef tahoe
+           addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
+#endif
            iread(&addr, addr, sizeof(addr));
            break;
            iread(&addr, addr, sizeof(addr));
            break;
-#   endif
 
        case O_TRA:
            iread(&offset, addr, sizeof(offset));
 
        case O_TRA:
            iread(&offset, addr, sizeof(offset));
@@ -146,6 +195,9 @@ BOOLEAN isnext;
            short consize;
 
            if (nextbyte == 0) {
            short consize;
 
            if (nextbyte == 0) {
+#ifdef tahoe
+               addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
+#endif
                iread(&consize, addr, sizeof(consize));
                addr += sizeof(consize);
            } else {
                iread(&consize, addr, sizeof(consize));
                addr += sizeof(consize);
            } else {
@@ -193,7 +245,12 @@ BOOLEAN isnext;
 
        case O_IF:
            stepto(addr - sizeof(short));
 
        case O_IF:
            stepto(addr - sizeof(short));
+#ifdef tahoe
+           doret(process);
+           dread(&offset, process->sp+sizeof(int)-sizeof(offset), sizeof(offset));
+#else
            dread(&offset, process->sp, sizeof(offset));
            dread(&offset, process->sp, sizeof(offset));
+#endif
            if (offset == 0) {
                iread(&offset, addr, sizeof(offset));
                addr += offset;
            if (offset == 0) {
                iread(&offset, addr, sizeof(offset));
                addr += offset;
@@ -203,7 +260,6 @@ BOOLEAN isnext;
            break;
 
        default: {
            break;
 
        default: {
-#   if (isvaxpx)
            int i;
 
            for (i = 0; optab[op].argtype[i] != 0; i++) {
            int i;
 
            for (i = 0; optab[op].argtype[i] != 0; i++) {
@@ -211,6 +267,9 @@ BOOLEAN isnext;
                    case ADDR4:
                    case LWORD:
                        addr += 4;
                    case ADDR4:
                    case LWORD:
                        addr += 4;
+#ifdef tahoe
+                       addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
+#endif
                        break;
 
                    case SUBOP:
                        break;
 
                    case SUBOP:
@@ -238,9 +297,7 @@ BOOLEAN isnext;
                            addr++;
                        }
                        addr++;
                            addr++;
                        }
                        addr++;
-                       if ((addr&1) != 0) {
-                           addr++;
-                       }
+                       addr = (ADDRESS)(((int)addr + EVEN) & ~EVEN);
                        break;
                    }
 
                        break;
                    }
 
@@ -249,28 +306,6 @@ BOOLEAN isnext;
                        /*NOTREACHED*/
                }
            }
                        /*NOTREACHED*/
                }
            }
-#   else
-           int oplen;
-
-           oplen = optab[op].nargs;
-           if (oplen < 0) {
-               oplen = (-oplen) - 1;
-           } else  if (oplen > 0 && nextbyte != 0) {
-               oplen--;
-           }
-           oplen *= sizeof(int);
-           switch (op) {
-               case O_BEG:
-               case O_NODUMP:
-                   oplen += 10;
-                   break;
-
-               case O_CON:
-                   oplen += ((nextbyte + 1)&~1);
-                   break;
-           }
-           addr += oplen;
-#   endif
            break;
        }
     }
            break;
        }
     }
@@ -293,21 +328,41 @@ ADDRESS addr;
     long swtval, caseval;
 
     stepto(addr - 2);
     long swtval, caseval;
 
     stepto(addr - 2);
+#ifdef tahoe
+    doret(process);
+#endif
     if (ncases == 0) {
        iread(&ncases, addr, sizeof(ncases));
        addr += sizeof(short);
     }
     jmptable = addr;
     firstval = jmptable + ncases*sizeof(short);
     if (ncases == 0) {
        iread(&ncases, addr, sizeof(ncases));
        addr += sizeof(short);
     }
     jmptable = addr;
     firstval = jmptable + ncases*sizeof(short);
+#ifdef tahoe
+    if (size == 4) {
+       firstval = (ADDRESS)(((int)firstval + EVEN) & ~EVEN);
+    }
+#endif
     lastval = firstval + ncases*size;
     lastval = firstval + ncases*size;
+#ifdef tahoe
+    if (size <= 4) {
+       dread(&swtval, process->sp, 4);
+#else
     if (size <= 2) {
        dread(&swtval, process->sp, 2);
     if (size <= 2) {
        dread(&swtval, process->sp, 2);
+#endif
     } else {
        dread(&swtval, process->sp, size);
     }
     for (i = firstval; i < lastval; i += size) {
     } else {
        dread(&swtval, process->sp, size);
     }
     for (i = firstval; i < lastval; i += size) {
+       caseval = 0;
+#ifdef tahoe
+       iread((char *)&caseval + sizeof caseval - size, i, size);
+       if (swtval == caseval)
+#else
        iread(&caseval, i, size);
        iread(&caseval, i, size);
-       if (cmp(&swtval, &caseval, size) == 0) {
+       if (cmp(&swtval, &caseval, size) == 0)
+#endif
+       {
            i = ((i - firstval) / size) * sizeof(offset);
            iread(&offset, jmptable + i, sizeof(offset));
            addr = jmptable + offset;
            i = ((i - firstval) / size) * sizeof(offset);
            iread(&offset, jmptable + i, sizeof(offset));
            addr = jmptable + offset;
@@ -324,21 +379,27 @@ short subop;
 int incr;
 {
     register PROCESS *p;
 int incr;
 {
     register PROCESS *p;
-    long i, limit, lower;
+    long i, limit;
     ADDRESS valaddr;
     ADDRESS valaddr;
-    short offset;
 
     stepto(addr - sizeof(short));
     p = process;
 
     stepto(addr - sizeof(short));
     p = process;
+#ifdef tahoe
+    doret(p);
+#endif
     i = limit = 0;
     if (subop == 0) {
     i = limit = 0;
     if (subop == 0) {
-       addr += size;
+       dread(&subop, addr, sizeof (short));
+       addr += sizeof (short);
     }
     dread(&valaddr, p->sp, sizeof(valaddr));
     }
     dread(&valaddr, p->sp, sizeof(valaddr));
+#ifdef tahoe
+    dread((char *)&i + sizeof i - size, valaddr, size);
+#else
     dread(&i, valaddr, size);
     dread(&i, valaddr, size);
-    dread(&limit, p->sp + sizeof(valaddr), size);
-    i += (incr << (8*(sizeof(i) - size)));
-    addr += size;
+#endif
+    dread(&limit, p->sp + sizeof(valaddr), sizeof limit);
+    i += incr;
 
 /*
  * It is very slow to go through the loop again and again.
 
 /*
  * It is very slow to go through the loop again and again.
@@ -346,10 +407,9 @@ int incr;
  * should be skipped.
  */
     if ((incr > 0 && i < limit) || (incr < 0 && i > limit)) {
  * should be skipped.
  */
     if ((incr > 0 && i < limit) || (incr < 0 && i > limit)) {
-       iread(&offset, addr, sizeof(offset));
-       return(addr + offset);
+       return(addr + subop);
     } else {
     } else {
-       return(addr + sizeof(short));
+       return(addr);
     }
 }
 
     }
 }