update to run under 4.2bsd; reformat to my style (or a reasonable
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 1 Aug 1983 14:02:44 +0000 (06:02 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 1 Aug 1983 14:02:44 +0000 (06:02 -0800)
facimile thereof); major hacking on signal handling for 4.2 signal interface

SCCS-vsn: old/games.vax/compat/dosig.c 4.2
SCCS-vsn: old/games.vax/compat/runcompat.c 4.2
SCCS-vsn: old/games.vax/compat/unixtraps.c 4.2

usr/src/old/games.vax/compat/dosig.c
usr/src/old/games.vax/compat/runcompat.c
usr/src/old/games.vax/compat/unixtraps.c

index 415eba7..0dd5b5e 100644 (file)
@@ -1,22 +1,23 @@
-static char sccsid[] = "       dosig.c 4.1     82/05/12        ";
+static char sccsid[] = "@(#)dosig.c    4.2  83/07/31";
 
 
-#define FBSD
-/*     Handle signal trapping from version 6 or version 7 compatability
- *     mode programs.
+/*
+ * Handle signal trapping from version 6 or
+ * version 7 compatability mode programs.
  *     Art Wetzel      November 1979
  */
  *     Art Wetzel      November 1979
  */
+
 #ifdef TRACE
 #include <stdio.h>
 #endif
 #include <signal.h>
 #include "defs.h"
 #ifdef TRACE
 #include <stdio.h>
 #endif
 #include <signal.h>
 #include "defs.h"
+
 unsigned int  sigvals[NSIG+1];
 unsigned int  sigvals[NSIG+1];
+
 /* actual catch point for all signals */
 /* actual catch point for all signals */
-#ifdef FBSD
-sigcatch(signum,faultcode,myaddr,stpc,stps) int signum;
-#else
-sigcatch(signum) int signum;
-#endif
+sigcatch(signum, faultcode, scp)
+       int signum, faultcode;
+       struct sigcontext *scp;
 {
        unsigned short *pcptr;
        extern getregs();
 {
        unsigned short *pcptr;
        extern getregs();
@@ -31,29 +32,26 @@ sigcatch(signum) int signum;
                return(0);
        }
        /* figure out the pc */
                return(0);
        }
        /* figure out the pc */
-#ifdef FBSD
-       pcptr = (unsigned short *) &stpc;
-#else
-       pcptr = (unsigned short *)((char *)&pcptr + 20);
-#endif
+       pcptr = (unsigned short *) &scp->sc_pc;
        pc = (unsigned short *) *pcptr;
        /* get the psl with condition codes */
        pc = (unsigned short *) *pcptr;
        /* get the psl with condition codes */
-       /* requires UNIX-32V patch to not clear out condition codes */
-#ifdef FBSD
-       psl = 0x83c00000 | (stps & 017);
-#else
-       psl = 0x83c00000 | (*(pcptr - 6) & 017);
-#endif
+       psl = 0x83c00000 | (scp->sc_ps & 017);
        /* actually do the thing */
        /* actually do the thing */
-       if(sigvals[signum] != (unsigned int)SIG_DFL && (sigvals[signum] & (unsigned int)SIG_IGN) == 0)
+       if (sigvals[signum] != (unsigned int)SIG_DFL &&
+           (sigvals[signum] & (unsigned int)SIG_IGN) == 0)
                dosig(signum, pc);
        /* go back to compatability mode and the signal routine there */
                dosig(signum, pc);
        /* go back to compatability mode and the signal routine there */
+       sigsetmask(scp->sc_mask);
        incompat++;
        compat();
 }
        incompat++;
        compat();
 }
+
 /* routine to set up pdp11 space for return from a signal */
 /* routine to set up pdp11 space for return from a signal */
-dosig(signum, from) {
+dosig(signum, from)
+       int signum, from;
+{
        unsigned short *sp;
        unsigned short *sp;
+
 #ifdef TRACE
        fprintf(stderr,"Caught sig %d from 0%o -> 0%o\n",signum,(pc-1),*(pc-1));
 #endif
 #ifdef TRACE
        fprintf(stderr,"Caught sig %d from 0%o -> 0%o\n",signum,(pc-1),*(pc-1));
 #endif
@@ -67,4 +65,5 @@ dosig(signum, from) {
        regs[6] = (unsigned short)(int)sp;
        /* reset pc to signal catching routine */
        pc = (unsigned short *)sigvals[signum];
        regs[6] = (unsigned short)(int)sp;
        /* reset pc to signal catching routine */
        pc = (unsigned short *)sigvals[signum];
+       signal(signum, SIG_DFL);
 }
 }
index 376678d..416c062 100644 (file)
@@ -1,8 +1,7 @@
-static char sccsid[] = "       runcompat.c     4.1     82/05/12        ";
+static char sccsid[] = "@(#)runcompat.c        4.2 83/07/31";
 
 
-#define FBSD
 /*
 /*
- *     Compatability mode support under UNIX-32V
+ *     Compatability mode support
  *     written by Art Wetzel during August 1979
  *     at the Interdisciplinary Dept of Information Science
  *     Room 711, LIS Bldg
  *     written by Art Wetzel during August 1979
  *     at the Interdisciplinary Dept of Information Science
  *     Room 711, LIS Bldg
@@ -12,6 +11,7 @@ static char sccsid[] = "      runcompat.c     4.1     82/05/12        ";
  *     No claims are made on the completeness of the support of any
  *     of the systems simulated under this package
  */
  *     No claims are made on the completeness of the support of any
  *     of the systems simulated under this package
  */
+
 #include <stdio.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -24,15 +24,21 @@ static char sccsid[] = "    runcompat.c     4.1     82/05/12        ";
 #ifdef RT11
 #include "rt11.h"
 #endif
 #ifdef RT11
 #include "rt11.h"
 #endif
-struct stat    stat32v;
-unsigned short regs[8];
-unsigned long psl;
-unsigned short *pc;
-int incompat;
+
+struct stat stat32v;
+u_short        regs[8];
+u_long psl;
+u_short        *pc;
+int    incompat;
 char   *progname;
 char   *nameend;
 char   *progname;
 char   *nameend;
-main(argc, argv, envp) int argc; char **argv, **envp; {
-       if(argc < 2){
+
+main(argc, argv, envp)
+       int argc;
+       char **argv, **envp;
+{
+
+       if (argc < 2) {
                fprintf(stderr,"Usage: %s [-rootdir] file args...\n",argv[0]);
                exit(1);
        }
                fprintf(stderr,"Usage: %s [-rootdir] file args...\n",argv[0]);
                exit(1);
        }
@@ -41,25 +47,25 @@ main(argc, argv, envp) int argc; char **argv, **envp; {
        nameend = envp[0]-1;
        argv++;
        /* set up alternate root directory if flagged for */
        nameend = envp[0]-1;
        argv++;
        /* set up alternate root directory if flagged for */
-       if(*argv[0] == '-') {
-               if(chroot(argv[0]+1)) {
+       if (*argv[0] == '-') {
+               if (chroot(argv[0]+1)) {
                        fprintf(stderr,"Can't change root to %s\n",argv[0]+1);
                        exit(-1);
                }
                argv++;
        }
        /* check out file stats of file to run */
                        fprintf(stderr,"Can't change root to %s\n",argv[0]+1);
                        exit(-1);
                }
                argv++;
        }
        /* check out file stats of file to run */
-       if(stat(argv[0], &stat32v)) {
+       if (stat(argv[0], &stat32v)) {
                fprintf(stderr,"%s does not exist\n",argv[0]);
                exit(1);
        }
        /* a version of SETUID and SETGID file executions */
        /* the binary of this program should be SETUID root for this to work */
        /* requires nonstandard seteuid and setegid sys calls */
                fprintf(stderr,"%s does not exist\n",argv[0]);
                exit(1);
        }
        /* a version of SETUID and SETGID file executions */
        /* the binary of this program should be SETUID root for this to work */
        /* requires nonstandard seteuid and setegid sys calls */
-       if(!(stat32v.st_mode & S_ISGID) || setegid(stat32v.st_gid))
+       if (!(stat32v.st_mode & S_ISGID) || setegid(stat32v.st_gid))
                /* if not SETGID file or error, drop back to real group */
                setgid(getgid());
                /* if not SETGID file or error, drop back to real group */
                setgid(getgid());
-       if(!(stat32v.st_mode & S_ISUID) || seteuid(stat32v.st_uid))
+       if (!(stat32v.st_mode & S_ISUID) || seteuid(stat32v.st_uid))
                /* if not SETUID file or error, drop back to real uid */
                setuid(getuid());
 #ifdef V6UNIX
                /* if not SETUID file or error, drop back to real uid */
                setuid(getuid());
 #ifdef V6UNIX
@@ -72,34 +78,38 @@ main(argc, argv, envp) int argc; char **argv, **envp; {
        fprintf(stderr,"Execution failure on %s\n",argv[0]);
        exit(1);
 }
        fprintf(stderr,"Execution failure on %s\n",argv[0]);
        exit(1);
 }
-execute(file, argv, envp) char *file, **argv, **envp; {
+
+execute(file, argv, envp)
+       char *file, **argv, **envp;
+{
        int fd, n, tloadpt, dloadpt, tloadsize, dloadsize, stacksize;
        register short *p;
        extern illtrap();
        extern char **environ;
        int fd, n, tloadpt, dloadpt, tloadsize, dloadsize, stacksize;
        register short *p;
        extern illtrap();
        extern char **environ;
+
        /* file to run should be readable */
        /* file to run should be readable */
-       if((fd = open(file, 0)) == -1) {
+       if ((fd = open(file, 0)) == -1) {
                fprintf(stderr,"Can't open %s for read access\n",file);
                return(-1);
        }
 #ifdef UNIX
                fprintf(stderr,"Can't open %s for read access\n",file);
                return(-1);
        }
 #ifdef UNIX
-       if((n = read(fd, &header, sizeof header)) != sizeof header)
+       if ((n = read(fd, &header, sizeof header)) != sizeof header)
                return(ENOEXEC);
        /* check to see if really unix file */
                return(ENOEXEC);
        /* check to see if really unix file */
-       if(header.magic != MAGIC1 && header.magic != MAGIC2 &&
-               header.magic != MAGIC3 && header.magic != MAGIC4) {
+       if (header.magic != MAGIC1 && header.magic != MAGIC2 &&
+           header.magic != MAGIC3 && header.magic != MAGIC4) {
                return(ENOEXEC);
        }
                return(ENOEXEC);
        }
-       /* if a UNIX-32V file run it */
-       if(header.textsize == 0) {
+       /* if a UNIX file run it */
+       if (header.textsize == 0) {
                close(fd);
                /* if no explicit env, pass along environ */
                close(fd);
                /* if no explicit env, pass along environ */
-               if(!envp || *envp == 0)
+               if (!envp || *envp == 0)
                        return(execve(file, argv, environ));
                return(execve(file, argv,  envp));
        }
        /* checks out OK as PDP-11 UNIX file */
                        return(execve(file, argv, environ));
                return(execve(file, argv,  envp));
        }
        /* checks out OK as PDP-11 UNIX file */
-       if(header.magic == MAGIC3) {
+       if (header.magic == MAGIC3) {
                fprintf(stderr,"%s compiled for separate I/D space\n",argv[0]);
                return(-1);
        }
                fprintf(stderr,"%s compiled for separate I/D space\n",argv[0]);
                return(-1);
        }
@@ -110,14 +120,14 @@ execute(file, argv, envp) char *file, **argv, **envp; {
        /* figure out where to load initialized data */
        dloadpt = tloadsize = header.textsize;
        /* check if alignment of data segment to 8k byte boundary */
        /* figure out where to load initialized data */
        dloadpt = tloadsize = header.textsize;
        /* check if alignment of data segment to 8k byte boundary */
-       if(header.magic == MAGIC2)
+       if (header.magic == MAGIC2)
                dloadpt = (dloadpt+8191) & (~8191);
        /* how much data */
        dloadsize = header.datasize;
        stacksize = header.bsssize;
 #endif
 #ifdef RT11
                dloadpt = (dloadpt+8191) & (~8191);
        /* how much data */
        dloadsize = header.datasize;
        stacksize = header.bsssize;
 #endif
 #ifdef RT11
-       if((n = read(fd, shortspace, RTHDRSIZ)) != RTHDRSIZ) {
+       if ((n = read(fd, shortspace, RTHDRSIZ)) != RTHDRSIZ) {
                fprintf(stderr,"Error reading 1st block\n");
                return(-1);
        }
                fprintf(stderr,"Error reading 1st block\n");
                return(-1);
        }
@@ -134,23 +144,24 @@ execute(file, argv, envp) char *file, **argv, **envp; {
        stacksize = 0;
 #endif
        /* see if it all fits into available memory space */
        stacksize = 0;
 #endif
        /* see if it all fits into available memory space */
-       if((dloadpt+dloadsize+stacksize) > (int)memsiz) {
+       if ((dloadpt+dloadsize+stacksize) > (int)memsiz) {
                fprintf(stderr,"File too big to run\n");
                return(-1);
        }
        /* read text segment */
                fprintf(stderr,"File too big to run\n");
                return(-1);
        }
        /* read text segment */
-       if((n = read(fd, tloadpt, tloadsize)) < tloadsize) {
+       if ((n = read(fd, tloadpt, tloadsize)) < tloadsize) {
                fprintf(stderr,"Text read failure\n");
                return(-1);
        }
        /* read data segment */
                fprintf(stderr,"Text read failure\n");
                return(-1);
        }
        /* read data segment */
-       if((n = read(fd, dloadpt, dloadsize)) < dloadsize) {
+       if ((n = read(fd, dloadpt, dloadsize)) < dloadsize) {
                fprintf(stderr,"Data read failure\n");
                return(-1);
        }
        /* clear out the rest of memory */
        p = (short *)(dloadpt + dloadsize);
                fprintf(stderr,"Data read failure\n");
                return(-1);
        }
        /* clear out the rest of memory */
        p = (short *)(dloadpt + dloadsize);
-       while(p < (short *)memsiz) *p++ = 0;
+       while (p < (short *)memsiz)
+               *p++ = 0;
        /* close file before starting it */
        close(fd);
        /* set up illegal instruction trapping */
        /* close file before starting it */
        close(fd);
        /* set up illegal instruction trapping */
@@ -158,25 +169,22 @@ execute(file, argv, envp) char *file, **argv, **envp; {
        /* lets give it a try */
        start(argv, envp);
 }
        /* lets give it a try */
        start(argv, envp);
 }
-#ifdef FBSD
-illtrap(signum,faultcode,myaddr,stpc,stps) int signum; {
-#else
-illtrap(){
-#endif
+
+illtrap(signum, faultcode, scp)
+       int signum, faultcode;
+       struct sigcontext *scp;
+{
        unsigned short *pcptr;
        int instr;
        register int i;
        extern getregs();
        unsigned short *pcptr;
        int instr;
        register int i;
        extern getregs();
+
        /* record the fact that we are not in compatability mode now */
        incompat = 0;
        /* get the register values before they get clobbered */
        getregs();
        /* figure out what the pc was */
        /* record the fact that we are not in compatability mode now */
        incompat = 0;
        /* get the register values before they get clobbered */
        getregs();
        /* figure out what the pc was */
-#ifdef FBSD
-       pcptr = (unsigned short *) &stpc;
-#else
-       pcptr = (unsigned short *)((char *)&pcptr + 20);
-#endif
+       pcptr = (unsigned short *) &scp->sc_pc;
        pc = (unsigned short *) *pcptr;
        /* get the instruction */
        instr = *pc;
        pc = (unsigned short *) *pcptr;
        /* get the instruction */
        instr = *pc;
@@ -186,46 +194,47 @@ illtrap(){
        regs[7] = (unsigned short)(int)pc;
        /* set up psl with condition codes */
        /* a UNIX-32V monitor patch is required to not clear condition codes */
        regs[7] = (unsigned short)(int)pc;
        /* set up psl with condition codes */
        /* a UNIX-32V monitor patch is required to not clear condition codes */
-#ifdef FBSD
-       psl = 0x83c00000 | (stps & 017);
-#else
-       psl = 0x83c00000 | (*(pcptr - 6) & 017);
-#endif
+       psl = 0x83c00000 | (scp->sc_ps & 017);
+       sigsetmask(scp->sc_mask);
        /* pick out the appropriate action for this illegal instruction */
        switch(instr>>8){
        /* pick out the appropriate action for this illegal instruction */
        switch(instr>>8){
-       case    TRAPS:
+
+       case TRAPS:
                dotrap(instr & 0377);
                break;
                dotrap(instr & 0377);
                break;
-       case    EMTS:
-               if(sigvals[SIGEMT] && ((sigvals[SIGEMT]%2) != 1)) {
+
+       case EMTS:
+               if (sigvals[SIGEMT] && ((sigvals[SIGEMT]%2) != 1)) {
                        dosig(SIGEMT, pc);
                        break;
                }
                doemt(instr & 0377);
                break;
                        dosig(SIGEMT, pc);
                        break;
                }
                doemt(instr & 0377);
                break;
+
        default:
        default:
-               if(instr >= 075000 && instr < 075040) {
+               if (instr >= 075000 && instr < 075040) {
                        /* fis instructions */
                        /* fis instructions */
-                       if(dofloat(instr) == 0)
+                       if (dofloat(instr) == 0)
                                break;
                }
                                break;
                }
-               if(instr >=  0170000) {
+               if (instr >=  0170000) {
                        /* floating point unit instructions */
                        /* floating point unit instructions */
-                       if(dofloat(instr) == 0)
+                       if (dofloat(instr) == 0)
                                break;
                }
                /* genuine illegal instruction */
                /* if signal trap set go to user's trap location */
                                break;
                }
                /* genuine illegal instruction */
                /* if signal trap set go to user's trap location */
-               if(sigvals[SIGILL] && ((sigvals[SIGILL]%2) != 1)) {
+               if (sigvals[SIGILL] && ((sigvals[SIGILL]%2) != 1)) {
                        dosig(SIGILL, pc);
                        break;
                }
                /* ignore uncaught setd instructions */
                        dosig(SIGILL, pc);
                        break;
                }
                /* ignore uncaught setd instructions */
-               if(instr == SETD)
+               if (instr == SETD)
                        break;
                /* otherwise put out a message and quit */
                        break;
                /* otherwise put out a message and quit */
-               printf("illegal instruction, psl 0x%08x, pc 0%04o\n",psl,pc-1);
-               for(i=0; i<7; i++) printf("0x%04x  ",regs[i]);
+               printf("Illegal instruction, psl 0x%08x, pc 0%04o\n",psl,pc-1);
+               for (i = 0; i < 7; i++)
+                       printf("0x%04x  ",regs[i]);
                printf("0x%04x -> 0%o\n",pc-1,instr);
                /* set up to dump on illegal instruction */
                signal(SIGILL,SIG_DFL);
                printf("0x%04x -> 0%o\n",pc-1,instr);
                /* set up to dump on illegal instruction */
                signal(SIGILL,SIG_DFL);
index 9a138f4..59813b3 100644 (file)
@@ -1,13 +1,17 @@
-#
-static char sccsid[] = "       unixtraps.c     4.1     82/05/12        ";
-/*     Function to execute version 6 and version 7 UNIX system calls from
- *     compatability mode on UNIX-32V.
+static char sccsid[] = "@(#)unixtraps.c        4.2 83/07/31";
+
+/*
+ * Function to execute version 6 and version 7 UNIX system calls from
+ * compatability mode on UNIX-32V.
  *     Art Wetzel      August 1979
  */
  *     Art Wetzel      August 1979
  */
+
 #include <stdio.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
 #ifdef V6UNIX
 #ifdef TRACE
 #define        RTSNAME "/../../../../usr/local/v6trc"
 #ifdef V6UNIX
 #ifdef TRACE
 #define        RTSNAME "/../../../../usr/local/v6trc"
@@ -43,8 +47,10 @@ static char sccsid[] = "     unixtraps.c     4.1     82/05/12        ";
 #endif
 char   argvs[ARGVLEN+ENVLEN];
 int    args[MAXSARGS];
 #endif
 char   argvs[ARGVLEN+ENVLEN];
 int    args[MAXSARGS];
+
 /* 32v type stat structure */
 extern struct  stat    stat32v;
 /* 32v type stat structure */
 extern struct  stat    stat32v;
+
 /* place for times data so we can reverse the longs */
 struct timebuf {
        long    t1;
 /* place for times data so we can reverse the longs */
 struct timebuf {
        long    t1;
@@ -52,10 +58,13 @@ struct timebuf {
        long    t3;
        long    t4;
 } timebuf;
        long    t3;
        long    t4;
 } timebuf;
+
 /* place for pipe file descriptors */
 int    pipes[2];
 /* place for pipe file descriptors */
 int    pipes[2];
+
 /* wait status */
 int    wstatus;
 /* wait status */
 int    wstatus;
+
 #ifdef V6UNIX
 /* version 6 style stat structure */
 struct v6nod {
 #ifdef V6UNIX
 /* version 6 style stat structure */
 struct v6nod {
@@ -72,17 +81,45 @@ struct v6nod {
        long    modtime;
 } *v6stat;
 #endif
        long    modtime;
 } *v6stat;
 #endif
+
+#ifdef V7UNIX
+/* version 7 style stat structure */
+struct v7stat {
+       dev_t   v7st_dev;
+       u_short v7st_ino;
+       u_short v7st_mode;
+       short   v7st_nlink;
+       short   v7st_uid;
+       short   v7st_gid;
+       dev_t   v7st_rdev;
+       int     v7st_size;
+       int     v7st_atime;
+       int     v7st_mtime;
+       int     v7st_ctime;
+} statv7;
+
+struct timeb {
+       time_t  time;
+       u_short millitm;
+       short   timezone;
+       short   dstflag;
+} timeb;
+#endif
+
 /* do the trap stuff for the trap with code */
 /* do the trap stuff for the trap with code */
-dotrap(code) int code; {
+dotrap(code)
+       int code;
+{
        register unsigned short *argp, *savp, *savep;
        register int i, j, indirflg;
        register char *avp, *oavp;
        extern sigcatch();
        extern errno;
        register unsigned short *argp, *savp, *savep;
        register int i, j, indirflg;
        register char *avp, *oavp;
        extern sigcatch();
        extern errno;
+
        /* clear out condition codes of psl */
        psl &= ~017;
        /* special case of indirect sys call */
        /* clear out condition codes of psl */
        psl &= ~017;
        /* special case of indirect sys call */
-       if(code == 0) {
+       if (code == 0) {
                /* remember this was indirect */
                indirflg = 1;
                /* point to args */
                /* remember this was indirect */
                indirflg = 1;
                /* point to args */
@@ -90,7 +127,7 @@ dotrap(code) int code; {
                /* code for indirect sys call */
                code = *argp++;
                /* is it legit */
                /* code for indirect sys call */
                code = *argp++;
                /* is it legit */
-               if(code>>8 != TRAPS) {
+               if (code>>8 != TRAPS) {
                        fprintf(stderr,"Bad indirect sys call at 0x%x\n",pc-2);
                        pc++;
                        /* set carry flag */
                        fprintf(stderr,"Bad indirect sys call at 0x%x\n",pc-2);
                        pc++;
                        /* set carry flag */
@@ -99,15 +136,14 @@ dotrap(code) int code; {
                        return(-1);
                }
                code &= 0377;
                        return(-1);
                }
                code &= 0377;
-       }
-       else {
+       } else {
                /* remember this was not indirect */
                indirflg = 0;
                /* point to args */
                argp = pc;
        }
        /* check if code too high or bad sys code */
                /* remember this was not indirect */
                indirflg = 0;
                /* point to args */
                argp = pc;
        }
        /* check if code too high or bad sys code */
-       if(code >= NSYSTRAPS || sysargs[code][0] == ILLSYS) {
+       if (code >= NSYSTRAPS || sysargs[code][0] == ILLSYS) {
                fprintf(stderr,"Unimplimented trap %d at 0x%x\n",code,argp);
                /* set carry bit */
                psl |= CARRY;
                fprintf(stderr,"Unimplimented trap %d at 0x%x\n",code,argp);
                /* set carry bit */
                psl |= CARRY;
@@ -116,38 +152,45 @@ dotrap(code) int code; {
        }
        /* copy args to known locations */
        i=0;
        }
        /* copy args to known locations */
        i=0;
-       for(j=0; j<sysargs[code][0]; j++) args[i++] = regs[j];
-       for(j=0; j<(sysargs[code][1]); j++) args[i++] = *argp++;
+       for (j=0; j<sysargs[code][0]; j++)
+               args[i++] = regs[j];
+       for (j=0; j<(sysargs[code][1]); j++)
+               args[i++] = *argp++;
 #ifdef TRACE
        fprintf(stderr,"pid %d ",getpid());
 #ifdef TRACE
        fprintf(stderr,"pid %d ",getpid());
-       if(indirflg) fprintf(stderr,"indirect ");
-       fprintf(stderr,"%s (%d) from 0%o with %d args",sysnames[code],code,pc-1,i);
-       for(j=0; j<i; j++)
+       if (indirflg)
+               fprintf(stderr,"indirect ");
+       fprintf(stderr, "%s (%d) from 0%o with %d args",
+           sysnames[code], code, pc-1, i);
+       for (j=0; j<i; j++)
                fprintf(stderr," 0%o",args[j]);
                fprintf(stderr," 0%o",args[j]);
-       if(code==OPEN||code==STAT||code==CREAT||code==EXEC||code==UNLNK||code==LINK||code==CHDIR||code==MKNOD)
+       if (code==OPEN || code==STAT || code==CREAT || code==EXEC || 
+           code==UNLNK || code==LINK || code==CHDIR || code==MKNOD)
                fprintf(stderr," (%s)",args[0]);
 #ifdef V7UNIX
                fprintf(stderr," (%s)",args[0]);
 #ifdef V7UNIX
-       if(code==EXECE)
+       if (code==EXECE)
                fprintf(stderr," (%s)",args[0]);
 #endif
                fprintf(stderr," (%s)",args[0]);
 #endif
-       if(code==LINK)
+       if (code==LINK)
                fprintf(stderr," (%s)",args[1]);
 #endif
        /* go do whatever sys call it is */
                fprintf(stderr," (%s)",args[1]);
 #endif
        /* go do whatever sys call it is */
-       switch(code) {
-       case    FORK:
+       switch (code) {
+       case FORK:
                /* indirect forks return pids on both sides - must do here */
                /* this is possibly a bug in 32V */
                i = fork();
                break;
                /* indirect forks return pids on both sides - must do here */
                /* this is possibly a bug in 32V */
                i = fork();
                break;
-       case    WAIT:
+
+       case WAIT:
                i = wait(&wstatus);
                args[0] = i;
                args[1] = wstatus;
                break;
                i = wait(&wstatus);
                args[0] = i;
                args[1] = wstatus;
                break;
-       case    EXEC:
+
+       case EXEC:
 #ifdef V7UNIX
 #ifdef V7UNIX
-       case    EXECE:
+       case EXECE:
 #endif
                /*
                 *  have to do a lot of junk here to fix up an argv
 #endif
                /*
                 *  have to do a lot of junk here to fix up an argv
@@ -160,22 +203,24 @@ dotrap(code) int code; {
                avp = &argvs[0];
                savp = (unsigned short *)args[1];
 #ifdef V6UNIX
                avp = &argvs[0];
                savp = (unsigned short *)args[1];
 #ifdef V6UNIX
-               for(i=1; args[i] = *savp++; i++)
-                       if(args[i] == 0177777) break;
+               for (i=1; args[i] = *savp++; i++)
+                       if (args[i] == 0177777)
+                               break;
 #ifdef TRACE
 #ifdef TRACE
-                       else fprintf(stderr,"argv[%d]%s ",i-1,args[i]);
+                       else
+                               fprintf(stderr,"argv[%d]%s ",i-1,args[i]);
 #endif
 #endif
 #ifdef V7UNIX
                savep = (unsigned short *)args[2];
 #endif
 #endif
 #ifdef V7UNIX
                savep = (unsigned short *)args[2];
-               for(i=1; args[i] = *savp++; i++)
+               for (i=1; args[i] = *savp++; i++)
 #ifdef TRACE
                        fprintf(stderr,"argv[%d]%s ",i-1,args[i]);
 #else
                        ;
 #endif
 #endif
 #ifdef TRACE
                        fprintf(stderr,"argv[%d]%s ",i-1,args[i]);
 #else
                        ;
 #endif
 #endif
-               if(stat(args[0], &stat32v)) {
+               if (stat(args[0], &stat32v)) {
                        /* return error here if file does not exist */
 #ifdef TRACE
                        fprintf(stderr," does not exist\n");
                        /* return error here if file does not exist */
 #ifdef TRACE
                        fprintf(stderr," does not exist\n");
@@ -184,47 +229,56 @@ dotrap(code) int code; {
                        break;
                }
                /* must have execute permission */
                        break;
                }
                /* must have execute permission */
-               if(stat32v.st_mode & (S_IEXEC>>6)) goto experm;
-               if(stat32v.st_mode & (S_IEXEC>>3)) {
-                       if(stat32v.st_gid == getegid()) goto experm;
-                       if(geteuid() == 0) goto experm;
+               if (stat32v.st_mode & (S_IEXEC>>6))
+                       goto experm;
+               if (stat32v.st_mode & (S_IEXEC>>3)) {
+                       if (stat32v.st_gid == getegid())
+                               goto experm;
+                       if (geteuid() == 0)
+                               goto experm;
                }
                }
-               if(stat32v.st_mode & S_IEXEC) {
-                       if(stat32v.st_uid == geteuid()) goto experm;
-                       if(geteuid() == 0) goto experm;
+               if (stat32v.st_mode & S_IEXEC) {
+                       if (stat32v.st_uid == geteuid())
+                               goto experm;
+                       if (geteuid() == 0)
+                               goto experm;
                }
                /* return failure if no exec permision allowed */
                i = -1;
 experm:
                /* can't exec a directory */
                }
                /* return failure if no exec permision allowed */
                i = -1;
 experm:
                /* can't exec a directory */
-               if(stat32v.st_mode & S_IFDIR)
+               if ((stat32v.st_mode&S_IFMT) == S_IFDIR)
                        i = -1;
                        i = -1;
-               if(i == -1) break;
+               if (i == -1)
+                       break;
                args[i] = 0;
                args[i] = 0;
-               for(j=0; j<i; j++) {
+               for (j=0; j<i; j++) {
                        oavp = (char *)args[j];
                        args[j] = (int)avp;
                        oavp = (char *)args[j];
                        args[j] = (int)avp;
-                       while(*avp++ = *oavp++) ;
+                       while (*avp++ = *oavp++)
+                               ;
                }
 #ifdef V7UNIX
                }
 #ifdef V7UNIX
-               if(code == EXECE) {
-                       for(j = ++i; args[j] = *savep++; j++) ;
-                       for( ; j>i; j--) {
+               if (code == EXECE) {
+                       for (j = ++i; args[j] = *savep++; j++)
+                               ;
+                       for ( ; j > i; j--) {
                                oavp = (char *)args[j];
                                args[j] = (int)avp;
                                oavp = (char *)args[j];
                                args[j] = (int)avp;
-                               while(*avp++ = *oavp++) ;
+                               while (*avp++ = *oavp++)
+                                       ;
                        }
                }
 #endif
                /* SETUID and SETGID files must be started with a fresh RTS */
                        }
                }
 #endif
                /* SETUID and SETGID files must be started with a fresh RTS */
-               if(stat32v.st_mode & S_ISGID || stat32v.st_mode & S_ISUID) {
+               if (stat32v.st_mode & S_ISGID || stat32v.st_mode & S_ISUID) {
                        /* should add a check here for good magic # in header */
                        args[1] = args[0];
                        args[0] = (int)RTSNAME;
 #ifdef TRACE
                        fprintf(stderr," SETUID-GID");
 #endif
                        /* should add a check here for good magic # in header */
                        args[1] = args[0];
                        args[0] = (int)RTSNAME;
 #ifdef TRACE
                        fprintf(stderr," SETUID-GID");
 #endif
-                       if(args[i])
+                       if (args[i])
                                i = execve(args[0], &args[0], &args[i]);
                        else
                                i = execv(args[0], &args[0]);
                                i = execve(args[0], &args[0], &args[i]);
                        else
                                i = execv(args[0], &args[0]);
@@ -234,56 +288,88 @@ experm:
                i = execute(args[0], &args[1], &args[i]);
                /* shouldn't get here if exec works */
                break;
                i = execute(args[0], &args[1], &args[i]);
                /* shouldn't get here if exec works */
                break;
-       case    SEEK:
+
+       case SEEK:
 #ifdef V6UNIX
                /* fix up negative offsets */
 #ifdef V6UNIX
                /* fix up negative offsets */
-               if(args[2] != 0 && args[2] != 3)
-                       if(args[1] >= 32768) args[1] -= 65536;
-               if(args[2] <= 2)
+               if (args[2] != 0 && args[2] != 3)
+                       if (args[1] >= 32768)
+                               args[1] -= 65536;
+               if (args[2] <= 2)
                        i = lseek(args[0], args[1], args[2]);
                else
                        i = lseek(args[0], args[1]*512, args[2]-3);
                        i = lseek(args[0], args[1], args[2]);
                else
                        i = lseek(args[0], args[1]*512, args[2]-3);
-               if(i != -1) i = 0;
+               if (i != -1)
+                       i = 0;
 #endif
 #ifdef V7UNIX
                i = lseek(args[0], (args[1]<<16)|(args[2]&0177777), args[3]);
 #endif
                break;
 #endif
 #ifdef V7UNIX
                i = lseek(args[0], (args[1]<<16)|(args[2]&0177777), args[3]);
 #endif
                break;
+
 #ifdef V6UNIX
 #ifdef V6UNIX
-       case    MKNOD:
+       case MKNOD:
                /* version 6 uses allocated bit which means regular file here */
                /* version 6 uses allocated bit which means regular file here */
-               if(args[1] & S_IFBLK)
+               if (args[1] & S_IFBLK)
                        args[1] &= ~S_IFREG;
                i = mknod(args[0], args[1], args[2]);
                break;
 #endif 
                        args[1] &= ~S_IFREG;
                i = mknod(args[0], args[1], args[2]);
                break;
 #endif 
-       case    PIPE:
+
+       case PIPE:
                i = pipe(pipes);
                args[0] = pipes[0];
                args[1] = pipes[1];
                break;
                i = pipe(pipes);
                args[0] = pipes[0];
                args[1] = pipes[1];
                break;
+
 #ifdef V6UNIX
 #ifdef V6UNIX
-       case    TELL:
+       case TELL:
                i = lseek(args[0], 0L, 1);
                break;
                i = lseek(args[0], 0L, 1);
                break;
+
+       case STTY:
+               i = stty(args[0], args[1]);
+               break;
+
+       case GTTY:
+               i = gtty(args[0], args[1]);
+               break;
 #endif
 #endif
-       case    STAT:
-       case    FSTAT:
+
+       case STAT:
+               i = stat(args[0], &stat32v);
+               goto allstat;
+
+       case FSTAT:
                /* do the syscall to a local stat buffer */
                /* do the syscall to a local stat buffer */
-               i = syscall(code, args[0], &stat32v);
+               i = fstat(args[0], &stat32v);
+
+       allstat:
                /* reverse the longs */
                stat32v.st_size = longrev(stat32v.st_size);
                stat32v.st_atime = longrev(stat32v.st_atime);
                stat32v.st_mtime = longrev(stat32v.st_mtime);
                stat32v.st_ctime = longrev(stat32v.st_ctime);
 #ifdef V7UNIX
                /* reverse the longs */
                stat32v.st_size = longrev(stat32v.st_size);
                stat32v.st_atime = longrev(stat32v.st_atime);
                stat32v.st_mtime = longrev(stat32v.st_mtime);
                stat32v.st_ctime = longrev(stat32v.st_ctime);
 #ifdef V7UNIX
+               statv7.v7st_dev = stat32v.st_dev;
+               statv7.v7st_ino = stat32v.st_ino;
+               statv7.v7st_mode = stat32v.st_mode;
+               statv7.v7st_nlink = stat32v.st_nlink;
+               statv7.v7st_uid = stat32v.st_uid;
+               statv7.v7st_gid = stat32v.st_gid;
+               statv7.v7st_rdev = stat32v.st_rdev;
+               statv7.v7st_size = stat32v.st_size;
+               statv7.v7st_atime = stat32v.st_atime;
+               statv7.v7st_mtime = stat32v.st_mtime;
+               statv7.v7st_ctime = stat32v.st_ctime;
                /* copy out otherwise unchanged stat buffer */
                /* in two pieces with st_size as the breaking point */
                /* note that st_rdev is a short but due to alingnmemt */
                /* problems the rest of the structure is out of sync */
                /* copy out otherwise unchanged stat buffer */
                /* in two pieces with st_size as the breaking point */
                /* note that st_rdev is a short but due to alingnmemt */
                /* problems the rest of the structure is out of sync */
-               j = (int)((char *)(&stat32v.st_size)-(char *)(&stat32v.st_dev));
-               bcopy(&stat32v, args[1], j);
-               bcopy(&stat32v.st_size, args[1]+j-2, sizeof(struct stat)-j);
+               j = (int)((char *)(&statv7.v7st_size) -
+                   (char *)(&statv7.v7st_dev));
+               bcopy(&statv7, args[1], j);
+               bcopy(&statv7.v7st_size, args[1]+j-2, sizeof(struct v7stat)-j);
 #endif
 #ifdef V6UNIX
                /* point to user area as v6stat structure */
 #endif
 #ifdef V6UNIX
                /* point to user area as v6stat structure */
@@ -302,91 +388,157 @@ experm:
                v6stat->modtime = stat32v.st_mtime;
                /* patch up flags */
                /* for now just set 100000 bit if not a plain file */
                v6stat->modtime = stat32v.st_mtime;
                /* patch up flags */
                /* for now just set 100000 bit if not a plain file */
-               if(v6stat->flags & 060000)
+               if (v6stat->flags & 060000)
                        v6stat->flags |= 0100000;
 #endif
                break;
                        v6stat->flags |= 0100000;
 #endif
                break;
-       case    TIMES:
+
+       case TIMES:
                i = times(&timebuf);
                timebuf.t2 = longrev(timebuf.t2) + timebuf.t1;
                timebuf.t3 = longrev(timebuf.t3);
                timebuf.t4 = longrev(timebuf.t4);
                bcopy(&timebuf.t2,args[0],sizeof(struct timebuf)-sizeof(long));
                break;
                i = times(&timebuf);
                timebuf.t2 = longrev(timebuf.t2) + timebuf.t1;
                timebuf.t3 = longrev(timebuf.t3);
                timebuf.t4 = longrev(timebuf.t4);
                bcopy(&timebuf.t2,args[0],sizeof(struct timebuf)-sizeof(long));
                break;
+
 #ifdef V6UNIX
 #ifdef V6UNIX
-       case    SLEEP:
+       case SLEEP:
                /* do a sleep function - what about pwb which has alarm? */
                sleep(args[0]);
                break;
 #endif
                /* do a sleep function - what about pwb which has alarm? */
                sleep(args[0]);
                break;
 #endif
-       case    GETUID:
+
+       case GETUID:
                args[0] = getuid();
                args[1] = geteuid();
 #ifdef V6UNIX
                args[0] = getuid();
                args[1] = geteuid();
 #ifdef V6UNIX
-               i = args[1]<<8 | args[0];
+               i = args[1]<<8 | (args[0] & 0377);
 #endif
                break;
 #endif
                break;
-       case    GETGID:
+
+       case GETGID:
                args[0] = getgid();
                args[1] = getegid();
 #ifdef V6UNIX
                args[0] = getgid();
                args[1] = getegid();
 #ifdef V6UNIX
-               i = args[1]<<8 | args[0];
+               i = args[1]<<8 | (args[0] & 0377);
 #endif
                break;
 #endif
                break;
-#ifdef V6UNIX
-       case    SETUID:
-       case    SETGID:
+
                /* uids and gids are 8 bits in version 6 */
                /* uids and gids are 8 bits in version 6 */
-               i = syscall(code,args[0]&0377);
-               break;
+       case SETUID:
+       case SETGID:
+#ifdef V6UNIX
+               args[0] &= 0377;
 #endif
 #endif
-       case    SIG:
+               if (code == SETUID)
+                       i = setuid(args[0]);
+               else
+                       i = setgid(args[0]);
+               break;
+
+       case SIG:
                /* if it is a good signal code */
                /* if it is a good signal code */
-               if(args[0] <= NSIG) {
+               if (args[0] <= NSIG) {
                        /* get the current signal value */
                        i = sigvals[args[0]];
                        /* reset the signal to the new value */
                        sigvals[args[0]] = args[1];
                        /* actually do signal except don't reset SIGILL */
                        /* get the current signal value */
                        i = sigvals[args[0]];
                        /* reset the signal to the new value */
                        sigvals[args[0]] = args[1];
                        /* actually do signal except don't reset SIGILL */
-                       if(args[0] != SIGILL) {
-                               if(args[1] == (int)SIG_DFL || args[1] & (int)SIG_IGN) {
-                                       if((int)signal(args[0],args[1]) == -1)
+                       if (args[0] != SIGILL) {
+                               if (args[1] == (int)SIG_DFL ||
+                                   args[1] & (int)SIG_IGN) {
+                                       if ((int)signal(args[0],args[1]) == -1)
                                                i = -1;
                                } else {
                                                i = -1;
                                } else {
-                                       if((int)signal(args[0], sigcatch) == -1)
+                                       if ((int)signal(args[0],sigcatch) == -1)
                                                i = -1;
                                }
                        }
                                                i = -1;
                                }
                        }
-               }
-               else i = -1;
+               } else
+                       i = -1;
                break;
                break;
-       case    BRK:
+
+       case BRK:
                /* brk is successful unless we run over the stack */
                /* brk is successful unless we run over the stack */
+               /* NB: this assumes register usage which need not be used */
                i = 0;
                i = 0;
-               if(args[0] >= regs[6]) i = -1;
+               if (args[0] >= regs[6])
+                       i = -1;
+               break;
+
+       /*
+        * the next bunch are to cope with sys calls removed from 4.2
+        */
+       case TIME:
+               i = time(0);
                break;
                break;
+
+       case STIME: {
+               struct timeval tv;
+
+               tv.tv_usec = 0;
+               tv.tv_sec = (args[0] & 0xffff) | ((args[1] & 0xffff) << 16);
+               i = settimeofday(&tv);
+               break;
+       }
+
+       case NICE:
+               i = nice(args[0]);
+               break;
+
+#ifdef V7UNIX
+       case ALARM:
+               i = alarm(args[0]);
+               break;
+
+       case PAUSE:
+               i = pause();
+               break;
+
+       case UTIME:
+               i = utime(args[0], args[1]);
+               break;
+
+       case FTIME:
+               i = ftime(&timeb);
+               timeb.time = longrev(timeb.time);
+               bcopy(&timeb, args[0], sizeof timeb - 2);
+               break;
+
+       case IOCTL:
+               args[1] = mapioctl(args[1]);
+               if (args[1] == 0)
+                       i = -1;
+               else
+                       i = ioctl(args[0], args[1], args[2]);
+               break;
+#endif
+
 #ifdef V6UNIX
 #ifdef V6UNIX
-       case    PWBSYS:
+       case PWBSYS:
                /* ignore pwbsys for now */
                /* ignore pwbsys for now */
-               switch(args[2]) {
-               case    UNAME:
+               switch (args[2]) {
+               case UNAME:
 #ifdef TRACE
                        fprintf(stderr,"UNAME with %d %d\n",args[0],args[1]);
 #endif
                        strcpy(args[0],"pwbname");
                        i = 0;
                        break;
 #ifdef TRACE
                        fprintf(stderr,"UNAME with %d %d\n",args[0],args[1]);
 #endif
                        strcpy(args[0],"pwbname");
                        i = 0;
                        break;
-               case    UDATA:
+
+               case UDATA:
 #ifdef TRACE
                        fprintf(stderr,"UDATA with %d %d\n",args[0],args[1]);
 #endif
                        i = 0;
                        break;
 #ifdef TRACE
                        fprintf(stderr,"UDATA with %d %d\n",args[0],args[1]);
 #endif
                        i = 0;
                        break;
-               case    USTAT:
+
+               case USTAT:
 fprintf(stderr,"USTAT with %d %d\n",args[0],args[1]);
                        i = 0;
                        break;
 fprintf(stderr,"USTAT with %d %d\n",args[0],args[1]);
                        i = 0;
                        break;
-               case    UTIME:
+
+               case UTIME:
 fprintf(stderr,"UTIME with %d %d\n",args[0],args[1]);
                        i = 0;
                        break;
 fprintf(stderr,"UTIME with %d %d\n",args[0],args[1]);
                        i = 0;
                        break;
@@ -397,6 +549,7 @@ fprintf(stderr,"bad PWBSYS %d\n",args[3]);
                }
                break;
 #endif
                }
                break;
 #endif
+
        default:
                /*
                 *      Many sys calls are easily done here since most
        default:
                /*
                 *      Many sys calls are easily done here since most
@@ -405,8 +558,8 @@ fprintf(stderr,"bad PWBSYS %d\n",args[3]);
                 */
                i = syscall(code,args[0],args[1],args[2],args[3],args[4]);
 #ifdef V6UNIX
                 */
                i = syscall(code,args[0],args[1],args[2],args[3],args[4]);
 #ifdef V6UNIX
-               /* allow read write access to created files for(IDIS v6 mod) */
-               if(code==CREAT) {
+               /* allow read write access to created files for (IDIS v6 mod) */
+               if (code==CREAT) {
                        /* get actual file mode after create */
                        fstat(i, &stat32v);
                        close(i);
                        /* get actual file mode after create */
                        fstat(i, &stat32v);
                        close(i);
@@ -423,28 +576,28 @@ fprintf(stderr,"bad PWBSYS %d\n",args[3]);
        fprintf(stderr," sys val -> 0%o\n",i);
 #endif
        /* set carry bit if sys error */
        fprintf(stderr," sys val -> 0%o\n",i);
 #endif
        /* set carry bit if sys error */
-       if(i == -1)
+       if (i == -1)
                psl |= CARRY;
        /* if not an indirect sys call, adjust the pc */
                psl |= CARRY;
        /* if not an indirect sys call, adjust the pc */
-       if(indirflg == 0)
+       if (indirflg == 0)
                pc = argp;
        /* do alternate return on one side of fork */
                pc = argp;
        /* do alternate return on one side of fork */
-       if(code == FORK && i != 0)
+       if (code == FORK && i != 0)
                pc++;
        /* do the various return value formats */
                pc++;
        /* do the various return value formats */
-       switch(sysargs[code][2]) {
-       case    NORMRET:
+       switch (sysargs[code][2]) {
+       case NORMRET:
                /* normal case only one return value in r0 */
                regs[0] = i;
                break;
                /* normal case only one return value in r0 */
                regs[0] = i;
                break;
-       case    LONGRET:
+       case LONGRET:
                /* return a long in r0 - r1 as in time */
                regs[1] = i;
                regs[0] = i >> 16;
                break;
                /* return a long in r0 - r1 as in time */
                regs[1] = i;
                regs[0] = i >> 16;
                break;
-       case    TWORET:
+       case TWORET:
                /* return two ints in r0 - r1 as in pipe */
                /* return two ints in r0 - r1 as in pipe */
-               if(i == -1)
+               if (i == -1)
                        regs[0] = i;
                else {
                        regs[1] = args[1];
                        regs[0] = i;
                else {
                        regs[1] = args[1];
@@ -452,10 +605,14 @@ fprintf(stderr,"bad PWBSYS %d\n",args[3]);
                }
                break;
        }
                }
                break;
        }
-       if(i== -1)
+       if (i== -1)
                regs[0] = errno;
 }
                regs[0] = errno;
 }
-long longrev(l) long l; {
+
+long
+longrev(l)
+       long l;
+{
        /* function to reverse the halves of a long */
        union {
                long    lng;
        /* function to reverse the halves of a long */
        union {
                long    lng;
@@ -468,3 +625,47 @@ long longrev(l) long l; {
        u.s[1] = t;
        return(u.lng);
 }
        u.s[1] = t;
        return(u.lng);
 }
+
+/*
+ * Note: these tables are sorted by
+ * ioctl "code" (in ascending order).
+ */
+int fctls[] = { FIOCLEX, FIONCLEX, FIOASYNC, FIONBIO, FIONREAD, 0 };
+int tctls[] = {
+       TIOCGETD, TIOCSETD, TIOCHPCL, TIOCMODG, TIOCMODS,
+       TIOCGETP, TIOCSETP, TIOCSETN, TIOCEXCL, TIOCNXCL,
+       TIOCFLUSH,TIOCSETC, TIOCGETC, TIOCREMOTE,TIOCMGET,
+       TIOCMBIC, TIOCMBIS, TIOCMSET, TIOCSTART,TIOCSTOP,
+       TIOCPKT,  TIOCNOTTY,TIOCSTI,  TIOCOUTQ, TIOCGLTC,
+       TIOCSLTC, TIOCSPGRP,TIOCGPGRP,TIOCCDTR, TIOCSDTR,
+       TIOCCBRK, TIOCSBRK, TIOCLGET, TIOCLSET, TIOCLBIC,
+       TIOCLBIS, 0
+};
+
+/*
+ * Map an old style ioctl command to new.
+ */
+mapioctl(cmd)
+       int cmd;
+{
+       register int *map, c;
+
+       switch ((cmd >> 8) & 0xff) {
+
+       case 'f':
+               map = fctls;
+               break;
+
+       case 't':
+               map = tctls;
+               break;
+
+       default:
+               return (0);
+       }
+       while ((c = *map) && (c&0xff) < (cmd&0xff))
+               map++;
+       if (c && (c&0xff) == (cmd&0xff))
+               return (c);
+       return (0);
+}