First try at cross toolchain, compiles but not tested yet
authorNick Downing <downing.nick@gmail.com>
Mon, 2 Jan 2017 04:36:48 +0000 (15:36 +1100)
committerNick Downing <downing.nick@gmail.com>
Mon, 2 Jan 2017 04:36:48 +0000 (15:36 +1100)
91 files changed:
.gitignore [new file with mode: 0644]
bin/ar/Makefile
bin/ar/append.c
bin/ar/ar.c
bin/ar/archive.c
bin/ar/archive.h
bin/ar/contents.c
bin/ar/delete.c
bin/ar/extern.h
bin/ar/extract.c
bin/ar/include/ar.h [new symlink]
bin/ar/krcompat.h [new file with mode: 0644]
bin/ar/misc.c
bin/ar/move.c
bin/ar/n.sh [new file with mode: 0755]
bin/ar/print.c
bin/ar/replace.c
bin/ar/strmode.c
bin/as/Makefile
bin/as/as0.c [new file with mode: 0644]
bin/as/as0.h [new file with mode: 0644]
bin/as/as0_old.s [moved from bin/as/as0.s with 100% similarity]
bin/as/as2.c [new file with mode: 0644]
bin/as/as2.h [new file with mode: 0644]
bin/as/as2_old.s [moved from bin/as/as2.s with 100% similarity]
bin/as/krcompat.h [new file with mode: 0644]
bin/as/n.sh [new file with mode: 0755]
bin/cc/Makefile [new file with mode: 0644]
bin/cc/cc.c [moved from bin/cc.c with 81% similarity]
bin/cc/cc.h [new file with mode: 0644]
bin/cc/krcompat.h [new file with mode: 0644]
bin/cc/n.sh [new file with mode: 0755]
bin/ld/Makefile
bin/ld/include/a.out.h [new symlink]
bin/ld/include/ar.h [new symlink]
bin/ld/include/nlist.h [new symlink]
bin/ld/include/ranlib.h [new symlink]
bin/ld/include/sys/exec.h [new symlink]
bin/ld/include/vmf.h [new symlink]
bin/ld/krcompat.h [new file with mode: 0644]
bin/ld/ld.c
bin/ld/n.sh [new file with mode: 0755]
bin/nm/Makefile
bin/nm/include/a.out.h [new symlink]
bin/nm/include/ar.h [new symlink]
bin/nm/include/nlist.h [new symlink]
bin/nm/include/sys/exec.h [new symlink]
bin/nm/krcompat.h [new file with mode: 0644]
bin/nm/n.sh [new file with mode: 0755]
bin/nm/nm.c
include/a.out.h
include/stdio.h
include/vmf.h
lib/c2/c2.h
lib/c2/c20.c
lib/c2/c21.c
lib/c2/krcompat.h [new file with mode: 0644]
lib/c2/n.sh [new file with mode: 0755]
lib/ccom/Makefile
lib/ccom/c0.h
lib/ccom/c00.c
lib/ccom/c01.c
lib/ccom/c02.c
lib/ccom/c03.c
lib/ccom/c04.c
lib/ccom/c05.c
lib/ccom/c1.h
lib/ccom/c10.c
lib/ccom/c11.c
lib/ccom/c12.c
lib/ccom/c13.c
lib/ccom/cvopt.c
lib/ccom/krcompat.h [new file with mode: 0644]
lib/ccom/n.sh [new file with mode: 0755]
lib/ccom/pdp11_atof.c [new file with mode: 0644]
lib/ccom/pdp11_fp.c [new file with mode: 0644]
lib/ccom/pdp11_ldexp.c [new file with mode: 0644]
lib/cpp/Makefile
lib/cpp/cpp.c
lib/cpp/cpp.h [new file with mode: 0644]
lib/cpp/cpy.y
lib/cpp/krcompat.h [new file with mode: 0644]
lib/cpp/n.sh [new file with mode: 0755]
lib/cpp/yylex.c
lib/libc/pdp/gen/nsym.c
n.sh [new file with mode: 0755]
sys/h/exec.h
usr.lib/libvmf/include/vmf.h [new symlink]
usr.lib/libvmf/makefile
usr.lib/libvmf/n.sh [new file with mode: 0755]
usr.lib/libvmf/vmf.c

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..bb05c7d
--- /dev/null
@@ -0,0 +1,18 @@
+*.[0-9]
+*.a
+*.o
+host
+stage
+bin/cc/cc
+bin/ar/ar
+bin/as/as
+bin/ld/ld
+bin/nm/nm
+lib/c2/c2
+lib/ccom/c0
+lib/ccom/c1
+lib/ccom/cvopt
+lib/cpp/cpp
+lib/cpp/y.tab.c
+usr.lib/libvmf/genlib
+usr.lib/libvmf/genlib_p
index 0046ad9..897bc67 100644 (file)
@@ -1,7 +1,8 @@
 #      @(#)Makefile    5.8 (Berkeley) 3/10/91
 
-CFLAGS=        -I. -O
-LFLAGS=        -z
+CFLAGS=-O
+CPPFLAGS=-Iinclude -I.
+SEPFLAG=-i
 
 SRCS=  append.c ar.c archive.c contents.c delete.c extract.c misc.c \
        move.c print.c replace.c 
@@ -16,7 +17,7 @@ EXTRAOBJ= strmode.o # strftime.o ctime.o
 all: ar ar.1.0 ar.5.0
 
 ar: ${OBJS} ${EXTRAOBJ}
-       cc ${LFLAGS} -o ar ${OBJS} ${EXTRAOBJ}
+       cc ${SEPFLAG} -o ar ${OBJS} ${EXTRAOBJ}
 
 ar.1.0: ar.1
        nroff -man ar.1 > ar.1.0
@@ -24,10 +25,12 @@ ar.1.0: ar.1
 ar.5.0: ar.5.5
        nroff -man ar.5.5 > ar.5.0
 
-install:
+install: all
        install -s -m 755 ar ${DESTDIR}/bin/ar
-       install -c -o bin -g bin -m 444 ar.1.0 ${DESTDIR}/usr/man/cat1/ar.0
-       install -c -o bin -g bin -m 444 ar.5.0 ${DESTDIR}/usr/man/cat5/ar.0
+#      install -c -o bin -g bin -m 444 ar.1.0 ${DESTDIR}/usr/man/cat1/ar.0
+#      install -c -o bin -g bin -m 444 ar.5.0 ${DESTDIR}/usr/man/cat5/ar.0
+       install -c -m 444 ar.1.0 ${DESTDIR}/usr/man/cat1/ar.0
+       install -c -m 444 ar.5.0 ${DESTDIR}/usr/man/cat5/ar.0
 
 lint:
        lint -havx -I. ${SRCS} ${EXTRASRCS}
index 1893ef7..a3c3b4f 100644 (file)
@@ -56,9 +56,7 @@ extern int errno;
  *     Append files to the archive - modifies original archive or creates
  *     a new archive if named archive does not exist.
  */
-append(argv)
-       char **argv;
-{
+int append(argv) char **argv; {
        register int fd, afd;
        register char *file;
        struct stat sb;
index 63c1f15..99b0b8a 100644 (file)
@@ -52,13 +52,11 @@ static char sccsid[] = "@(#)ar.c    5.11 (Berkeley) 3/21/91";
 #include "archive.h"
 #include "extern.h"
 
-extern char *malloc();
-extern int errno;
-
 CHDR chdr;
 u_int options;
 char *archive, *envtmp, *posarg, *posname;
-static void badoptions(), usage();
+static void badoptions PARAMS((char *arg));
+static void usage PARAMS((void));
 
 /*
  * main --
@@ -66,10 +64,7 @@ static void badoptions(), usage();
  *     functions.  Some hacks that let us be backward compatible with 4.3 ar
  *     option parsing and sanity checking.
  */
-main(argc, argv)
-       int argc;
-       char **argv;
-{
+int main(argc, argv) int argc; char **argv; {
        extern int optind;
        int c;
        char *p;
@@ -213,18 +208,13 @@ main(argc, argv)
        exit((*fcall)(argv));
 }
 
-static void
-badoptions(arg)
-       char *arg;
-{
+static void badoptions(arg) char *arg; {
        (void)fprintf(stderr,
            "ar: illegal option combination for %s.\n", arg);
        usage();
 }
 
-static void
-usage()
-{
+static void usage() {
        (void)fprintf(stderr, "usage:  ar -d [-Tv] archive file ...\n");
        (void)fprintf(stderr, "\tar -m [-Tv] archive file ...\n");
        (void)fprintf(stderr, "\tar -m [-abiTv] position archive file ...\n");
index af69d54..e16c643 100644 (file)
@@ -56,9 +56,7 @@ extern int errno;
 typedef struct ar_hdr HDR;
 static char hb[sizeof(HDR) + 1];       /* real header */
 
-open_archive(mode)
-       int mode;
-{
+int open_archive(mode) int mode; {
        int created, fd, nr;
        char buf[SARMAG];
        
@@ -105,10 +103,7 @@ opened:    if (flock(fd, LOCK_EX|LOCK_NB) && errno != EOPNOTSUPP)
        return(fd);
 }
 
-void
-close_archive(fd)
-       int fd;
-{
+void close_archive(fd) int fd; {
        (void)close(fd);                        /* Implicit unlock. */
 }
 
@@ -123,9 +118,7 @@ close_archive(fd)
  * get_arobj --
  *     read the archive header for this member
  */
-get_arobj(fd)
-       int fd;
-{
+int get_arobj(fd) int fd; {
        struct ar_hdr *hdr;
        register int len, nr;
        register char *p;
@@ -191,10 +184,7 @@ static int already_written;
  * put_arobj --
  *     Write an archive member to a file.
  */
-put_arobj(cfp, sb)
-       CF *cfp;
-       struct stat *sb;
-{
+void put_arobj(cfp, sb) CF *cfp; struct stat *sb; {
        register int lname;
        register char *name;
        struct ar_hdr *hdr;
@@ -267,10 +257,7 @@ put_arobj(cfp, sb)
  *     because 16-bit word addressed copies were faster?)  Anyhow, it should
  *     have been ripped out long ago.
  */
-copy_ar(cfp, size)
-       CF *cfp;
-       off_t size;
-{
+void copy_ar(cfp, size) CF *cfp; off_t size; {
        static char pad = '\n';
        off_t sz;
        register int from, nr, nw, off, to;
@@ -311,10 +298,7 @@ copy_ar(cfp, size)
  * skip_arobj -
  *     Skip over an object -- taking care to skip the pad bytes.
  */
-void
-skip_arobj(fd)
-       int fd;
-{
+void skip_arobj(fd) int fd; {
        off_t len;
 
        len = chdr.size + (chdr.size + chdr.lname & 1);
index b513aad..30feca9 100644 (file)
  *     @(#)archive.h   5.8 (Berkeley) 4/12/91
  */
 
+#ifndef _ARCHIVE_H
+#define _ARCHIVE_H 1
+
+#include <sys/stat.h>
+#include "krcompat.h"
+
 /* Ar(1) options. */
 #define        AR_A    0x0001
 #define        AR_B    0x0002
@@ -92,10 +98,11 @@ typedef struct {
 #define        OLDARMAXNAME    15
 #define        HDR3    "%-16.15s%-12ld%-6u%-6u%-8o%-10ld%2s"
 
+int open_archive PARAMS((int mode));
+void close_archive PARAMS((int fd));
+int get_arobj PARAMS((int fd));
+void put_arobj PARAMS((CF *cfp, struct stat *sb));
+void copy_ar PARAMS((CF *cfp, off_t size));
+void skip_arobj PARAMS((int fd));
 
-void   close_archive();
-void   skip_arobj();
-int    copy_ar();
-int    get_arobj();
-int    open_archive();
-int    put_arobj();
+#endif
index 82ad098..20467bd 100644 (file)
@@ -40,9 +40,9 @@ static char sccsid[] = "@(#)contents.c        5.6 (Berkeley) 3/12/91";
 
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <sys/time.h>
+#include <time.h> /*<sys/time.h>*/
 #include <fcntl.h>
-#include <tzfile.h>
+/*#include <tzfile.h>*/
 #include <sys/dir.h>
 #include <ar.h>
 #include <stdio.h>
@@ -58,9 +58,7 @@ extern char *archive;                 /* archive name */
  *     Handles t[v] option - opens the archive and then reads headers,
  *     skipping member contents.
  */
-contents(argv)
-       register char **argv;
-{
+int contents(argv) register char **argv; {
        register int afd, all;
        struct tm *tp;
        char *file, buf[25];
index 477472b..26c2dc7 100644 (file)
@@ -57,9 +57,7 @@ extern char *tname;                     /* temporary file "name" */
  * delete --
  *     Deletes named members from the archive.
  */
-delete(argv)
-       register char **argv;
-{
+int delete(argv) register char **argv; {
        CF cf;
        off_t size;
        int afd, tfd;
index 3b4bde0..6e2dc9e 100644 (file)
  *     @(#)extern.h    5.1 (Berkeley) 4/3/91
  */
 
-void    badfmt();
-void    error();
-void    orphans();
-int     compare();
-int     tmp();
-char   *files();
-char   *rname();
-void   strmode();
-extern  long strtol();
-extern off_t lseek();
-extern char *getenv();
+#ifndef _EXTERN_H
+#define _EXTERN_H 1
+
+#include <stdlib.h>
+#include <unistd.h>
+#include "krcompat.h"
+
+/* append.c */
+int append PARAMS((char **argv));
+/* ar.c */
+int main PARAMS((int argc, char **argv));
+/* contents.c */
+int contents PARAMS((register char **argv));
+/* delete.c */
+int delete PARAMS((register char **argv));
+/* extract.c */
+int extract PARAMS((char **argv));
+/* misc.c */
+int tmp PARAMS((void));
+char *files PARAMS((char **argv));
+void orphans PARAMS((char **argv));
+char *rname PARAMS((char *path));
+int compare PARAMS((char *dest));
+void badfmt PARAMS((void));
+void error PARAMS((char *name));
+/* move.c */
+int move PARAMS((char **argv));
+/* print.c */
+int print PARAMS((char **argv));
+/* replace.c */
+int replace PARAMS((char **argv));
+/* strmode.c */
+void strmode PARAMS((register mode_t mode, register char *p));
+
+#endif
index 71491e8..cdaf2b9 100644 (file)
@@ -61,9 +61,7 @@ extern char *archive;                 /* archive name */
  *     members date otherwise date is time of extraction.  Does not modify
  *     archive.
  */
-extract(argv)
-       char **argv;
-{
+int extract(argv) char **argv; {
        register int afd, all, tfd;
        struct timeval tv[2];
        struct stat sb;
diff --git a/bin/ar/include/ar.h b/bin/ar/include/ar.h
new file mode 120000 (symlink)
index 0000000..7245d58
--- /dev/null
@@ -0,0 +1 @@
+../../../include/ar.h
\ No newline at end of file
diff --git a/bin/ar/krcompat.h b/bin/ar/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
index ccbbb3c..7c62d4d 100644 (file)
@@ -52,8 +52,7 @@ extern CHDR chdr;                     /* converted header */
 extern char *archive;                  /* archive name */
 char *tname = "temporary file";                /* temporary file "name" */
 
-tmp()
-{
+int tmp() {
        extern char *envtmp;
        sigset_t set, oset;
        static int first;
@@ -84,10 +83,7 @@ tmp()
  *     See if the current file matches any file in the argument list; if it
  *     does, remove it from the argument list.
  */
-char *
-files(argv)
-       char **argv;
-{
+char *files(argv) char **argv; {
        register char **list;
        char *p;
 
@@ -100,43 +96,30 @@ files(argv)
        return(NULL);
 }
 
-void
-orphans(argv)
-       char **argv;
-{
+void orphans(argv) char **argv; {
        for (; *argv; ++argv)
                (void)fprintf(stderr,
                    "ar: %s: not found in archive.\n", *argv);
 }
 
-char *
-rname(path)
-       char *path;
-{
+char *rname(path) char *path; {
        register char *ind;
 
        return((ind = rindex(path, '/')) ? ind + 1 : path);
 }
 
-compare(dest)
-       char *dest;
-{
+int compare(dest) char *dest; {
        if (options & AR_TR)
                return(!strncmp(chdr.name, rname(dest), OLDARMAXNAME));
        return(!strcmp(chdr.name, rname(dest)));
 }
 
-void
-badfmt()
-{
+void badfmt() {
        errno = EINVAL;
        error(archive);
 }
 
-void
-error(name)
-       char *name;
-{
+void error(name) char *name; {
        (void)fprintf(stderr, "ar: %s: %s\n", name, strerror(errno));
        exit(1);
 }
index ee7dcf5..1328a6b 100644 (file)
@@ -60,9 +60,7 @@ extern char *tname;                     /* temporary file "name" */
  *     option selected members go after 'posname'.  If no options, members
  *     are moved to end of archive.
  */
-move(argv)
-       char **argv;
-{
+int move(argv) char **argv; {
        extern char *posarg, *posname;  /* positioning file names */
        CF cf;
        off_t size, tsize;
diff --git a/bin/ar/n.sh b/bin/ar/n.sh
new file mode 100755 (executable)
index 0000000..bbc913b
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/bin\/ar$//'`"
+DESTDIR="$ROOT/host"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/bin"
+mkdir --parents "$DESTDIR/usr/man/cat1"
+mkdir --parents "$DESTDIR/usr/man/cat5"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" LDFLAGS="-L$DESTDIR/usr/lib" install
index 1b404ba..79b8886 100644 (file)
@@ -53,9 +53,7 @@ extern char *archive;                 /* archive name */
  *     Prints archive members on stdout - if member names given only
  *     print those members, otherwise print all members.
  */
-print(argv)
-       char **argv;
-{
+int print(argv) char **argv; {
        CF cf;
        register int afd, all;
        char *file;
index fdbdb50..155ce8d 100644 (file)
@@ -62,9 +62,7 @@ extern char *tname;                     /* temporary file "name" */
  *     the key entry, based on the a, b and i options.  If the u option
  *     is specified, modification dates select for replacement.
  */
-replace(argv)
-       char **argv;
-{
+int replace(argv) char **argv; {
        extern char *posarg, *posname;  /* positioning file name */
        register char *file;
        register int afd, curfd, mods, sfd;
index 2bdcf1f..33a6fe7 100644 (file)
@@ -38,11 +38,7 @@ static char sccsid[] = "@(#)strmode.c        5.3.2 (2.11BSD GTE) 1996/1/27";
 #include <sys/types.h>
 #include <sys/stat.h>
 
-void
-strmode(mode, p)
-       register mode_t mode;
-       register char *p;
-{
+void strmode(mode, p) register mode_t mode; register char *p; {
         /* print type */
        switch (mode & S_IFMT) {
        case S_IFDIR:                   /* directory */
index a22c1aa..6e76721 100644 (file)
@@ -2,13 +2,15 @@
 # makefile for as
 #
 
-AS=    /bin/as
-SEPFLAG= -i -X
+#AS=   /bin/as
+#SEPFLAG= -i -X
+SEPFLAG=-i
 
 all: as
 
 as: as0.o as2.o
-       ld ${SEPFLAG} -o $@ /lib/crt0.o as0.o as2.o -lc
+#      ld ${SEPFLAG} -o $@ /lib/crt0.o as0.o as2.o -lc
+       cc ${SEPFLAG} -o $@ as0.o as2.o
 
 install: all
        install -s as ${DESTDIR}/bin
diff --git a/bin/as/as0.c b/bin/as/as0.c
new file mode 100644 (file)
index 0000000..ab74f8a
--- /dev/null
@@ -0,0 +1,3933 @@
+/* as0.c */
+
+#include <stdio.h> /* temp */
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#ifdef PDP11
+typedef int intptr_t;
+#endif
+#include "as0.h"
+#include "as2.h"
+
+/*     .globl  _main, _write, _close, _execl, __exit, _brk */
+/*     .globl  _read, _signal, _stat, _open, _mkstemp, _calloc, _realloc */
+
+/*     .globl  error, errore, errora, checkeos, pass1, aexit, argb */
+/*     .globl  overlaid, defund, a.outp, errflg, passno, filerr, outmod */
+/*     .globl  wrterr, argb, hshsiz, dot, dotdot, savdot, ch, outbuf */
+/*     .globl  line, savop, inbuf, fbptr, fbtbl, symnum, hshtab, symblk */
+/*     .globl  symleft, dotrel, symtab, fin, fout, curfb, nxtfb, ibufp */
+/*     .globl  ibufc, a.tmp1, usymtab, SYMENTSZ, SYMBLKSZ, PSTENTSZ */
+/*     .globl  obufp, Newsym, symbol,csv */
+
+/* This assembler supports _both_ the old style object files (with */
+/* fixed 8 character symbols) and the new style (with a strings table). */
+/* The variable 'Newsym' defined below specifies which format will be */
+/* emitted, if the value is '0' the old style is output, if non-zero */
+/* then the new 'string table' format is output. */
+
+/* The old style on disc symbol table entries looked like this: */
+/*   struct symbol */
+/*     { */
+/*     char name[8]; */
+/*     short type; */
+/*     short value; */
+/*     }; */
+
+/* The new style of on disc symbol table entry looks like: */
+/*   struct symbol */
+/*     { */
+/*     off_t offset_in_string_table; */
+/*     short type; */
+/*     short value; */
+/*     }; */
+
+/*     .data */
+/* Newsym:     1 */
+/*     .text */
+
+char Newsym = 1;
+
+struct symbol *pdot = symtab;
+struct symbol *pdotdot = symtab + 1;
+intptr_t numbertoken; /* r0 */
+int numbervalue; /* r0 */
+int endflag; /* r1 */
+int indirect; /* r0 */
+int optoken; /* (sp) */
+int rightflags; /* r0 */
+int rightvalue; /* r1 */
+int leftvalue; /* r2 */
+int leftflags; /* r3 */
+intptr_t token; /* r4 */
+
+/* PDP-11 assembler */
+/* _main: */
+/*     jsr     r5,csv */
+
+int main(argc, argv) int argc; char **argv; {
+       sig_t oldsig;
+       char *p;
+       struct symbol *psymbol;
+       int hash, c;
+       struct symbol **ppsymbol;
+
+/*     mov     $1,-(sp)                / signal(SIGINT, SIG_IGN) */
+/*     mov     $2,-(sp) */
+/*     jsr     pc,_signal */
+/*     cmp     (sp)+,(sp)+ */
+/*     ror     r0 */
+/*     bcs     1f */
+
+/*     mov     $aexit,-(sp)            / signal(SIGINT, aexit) */
+/*     mov     $2,-(sp) */
+/*     jsr     pc,_signal */
+/*     cmp     (sp)+,(sp)+ */
+
+       oldsig = signal(SIGINT, SIG_IGN);
+       if (oldsig != SIG_IGN) /*((int)oldsig & 1) == 0)*/
+               signal(SIGINT, (sig_t)aexit);
+
+/* 1: */
+/*     mov     4(r5),r0                / argc */
+/*     mov     6(r5),curarg            / argv */
+
+       curarg = argv;
+       nargs = argc;
+       while (nargs) {
+
+/* 9: */
+/*     dec     r0                      / argc-- */
+/*     add     $2,curarg               / argv++ */
+
+               curarg++;
+               nargs--;
+               if (nargs == 0)
+                       break;
+
+/* 1: */
+/*     mov     *curarg,r1 */
+
+               p = *curarg;
+
+/*     cmpb    (r1)+,$'- */
+/*     bne     1f */
+
+               if (*p++ != '-')
+                       break;
+
+/*     cmpb    (r1),$'-                / is this "--"? */
+/*     bne     8f                      / no - br */
+/*     tstb    1(r1)                   / check for null terminator */
+/*     beq     1f                      / got it, the "--" means read 'stdin' */
+
+               if (*p == '-' && p[1] == 0)
+                       break;
+
+/* 8: */
+/*     add     $2,curarg               / argv++ */
+/*     dec     r0                      / argc-- */
+/*     cmpb    (r1),$'u */
+/*     beq     3f */
+/*     cmpb    (r1), $'V */
+/*     bne     2f */
+/*     inc     overlaid */
+/*     br      1b */
+/* 2: */
+
+               if (*p == 'V') {
+                       overlaid = 1;
+                       continue;
+               }
+
+/*     tstb    (r1) */
+/*     bne     2f */
+/* 3: */
+/*     mov     $40,defund */
+/*     br      1b */
+/* 2: */
+
+               if (*p == 'u' || *p == 0) {
+                       defund = FGLOBAL;
+                       continue;
+               }
+
+/*     cmpb    (r1),$'o */
+/*     bne     1f */
+/*     mov     *curarg,a.outp */
+/*     br      9b */
+/* 1: */
+
+               if (*p == 'o') {
+                       curarg++;
+                       a_outp = *curarg;
+                       nargs--;
+                       continue;
+               }
+               break;
+       }
+
+/* The new object file format puts a ceiling of 32 characters on symbols. */
+/* If it is desired to raise this limit all that need be done is increase */
+/* the same ceiling in the C compiler and linker (ld). */
+
+/*     tst     Newsym */
+/*     beq     1f */
+/*     movb    $32.,Ncps */
+/* 1: */
+
+       if (Newsym)
+               Ncps = 32;
+
+/*     mov     r0,nargs                / # of remaining args */
+/*     bne     8f                      / br if any left */
+/*     inc     nargs                   / fake at least one arg */
+/*     mov     $dash, curarg           / of '-' so we read stdin */
+/* 8: */
+
+       if (nargs == 0) {
+               nargs = 1;
+               curarg = &dash;
+       }
+
+/*     mov     $a.tmp1,-(sp) */
+/*     jsr     pc,_mkstemp             / fout = mkstemp(a.tmp1); */
+/*     tst     (sp)+ */
+/*     mov     r0,fout */
+/*     bmi     oops */
+
+       fout = mkstemp(a_tmp1);
+       if (fout < 0)
+               oops();
+
+/* the symbol table is a single linked list of dynamically allocated */
+/* 'SYMBLKSZ' byte blocks.  Allocate the first one now. */
+/*     mov     $SYMBLKSZ+2,-(sp)       / symblk = calloc(1, SYMBLKSZ+2) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_calloc */
+/*     cmp     (sp)+,(sp)+ */
+/*     mov     r0,symblk */
+/*     mov     r0,usymtab              / pointer to first block */
+/*     tst     (r0)+                   / skip link word */
+/*     mov     r0,symend               / current end in block */
+/*     mov     $SYMBLKSZ,symleft       / number of bytes left in block */
+
+       symblk = calloc(1, sizeof(struct symblk));
+       if (symblk == NULL)
+               nomem(); /* don't use oops(), want to delete temp file */
+       usymtab = symblk;
+       symend = symblk->data;
+       symleft = SYMBLKSZ;
+
+/* The string portion of symbol table entries is now allocated dynamically. */
+/* We allocate the strings in 1kb chunks to cut down the number of times */
+/* the string table needs to be extended (besides, long variable names are */
+/* coming real soon now). */
+
+/* NOTE: the string blocks are linked together for debugging purposes only, */
+/* nothing depends on the link. */
+
+/*     mov     $STRBLKSZ+2,-(sp) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_calloc              / strblk = calloc(1, STRBLKSZ+2) */
+/*     / check for failure??? */
+/*     cmp     (sp)+,(sp)+ */
+/*     mov     r0,strblk               / save pointer to string block */
+/*     tst     (r0)+                   / skip link word */
+/*     mov     r0,strend               / set available string pointer */
+/*     mov     $STRBLKSZ,strleft       / set amount left in block */
+
+       strblk = calloc(1, sizeof(struct strblk));
+       if (strblk == NULL)
+               nomem(); /* don't use oops(), want to delete temp file */
+       strend = strblk->data;
+       strleft = STRBLKSZ;
+
+/* the hash table is now dynamically allocated so that it can be */
+/* reused in pass 2 and re-alloced if necessary. */
+/*     mov     $2,-(sp)                / hshtab = calloc($hshsiz, sizeof(int)) */
+/*     mov     $hshsiz,-(sp) */
+/*     jsr     pc,_calloc */
+/*     cmp     (sp)+,(sp)+ */
+/*     mov     r0, hshtab */
+
+       hshtab = calloc(hshsiz, sizeof(struct symbol *));
+       if (hshtab == NULL)
+               nomem(); /* don't use oops(), want to delete temp file */
+
+/*     mov     $symtab,r1 */
+
+       psymbol = symtab;
+       do {
+
+/* 1: */
+/*     clr     r3 */
+/*     mov     (r1),r2                 / pointer to PST symbol's string */
+
+               hash = 0;
+               p = psymbol->name;
+
+/* 2: */
+/*     movb    (r2)+,r4 */
+/*     beq     2f */
+/*     add     r4,r3 */
+/*     swab    r3 */
+/*     br      2b */
+/* 2: */
+
+               while (1) {
+                       c = *p++;
+                       if (c == 0)
+                               break;
+                       hash += c;
+                       hash = ((hash >> 8) & 0377) | ((hash & 0377) << 8);
+               }
+
+/*     clr     r2 */
+/*     div     $hshsiz,r2 */
+/*     ashc    $1,r2 */
+/*     add     hshtab,r3 */
+
+               ppsymbol = hshtab + (hash % hshsiz);
+               hash /= hshsiz;
+
+/* 4: */
+/*     sub     r2,r3 */
+/*     cmp     r3,hshtab */
+/*     bhi     3f */
+/*     add     $2*hshsiz,r3 */
+/* 3: */
+/*     tst     -(r3) */
+/*     bne     4b */
+/*     mov     r1,(r3) */
+/*     add     $PSTENTSZ,r1 */
+/*     cmp     r1,$ebsymtab */
+/*     blo     1b */
+
+               do {
+                       ppsymbol -= hash;
+                       if (ppsymbol <= hshtab)
+                               ppsymbol += hshsiz;
+               } while (*--ppsymbol);
+               *ppsymbol = psymbol++;
+       } while (psymbol < symtab + ebsymtab);
+
+/* perform pass 0 processing */
+/*     jsr     pc,pass0 */
+
+#ifdef LISTING
+       printf("pass 0\n");
+#endif
+       pass0();
+
+/* flush the intermediate object file */
+/*     mov     $1024.,-(sp)            / write(fout, outbuf, 1024) */
+/*     mov     $outbuf,-(sp) */
+/*     mov     fout,-(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+
+       write(fout, outbuf, 512 * sizeof(short));
+
+/*     tst     errflg                  / any errors? */
+/*     beq     1f                      / yes - br */
+/*     jsr     pc,aexit */
+/* not reached */
+/* 1: */
+
+       if (errflg)
+               aexit();
+
+/*     inc     passno                  / go from -1 to 0 */
+/*     clr     line                    / reset line number */
+/*     jmp     pass1                   / pass1 does both passes 1, 2, exit */
+
+#ifdef LISTING
+       printf("pass 1\n");
+#endif
+       passno++;
+       line = 0;
+       pass1();
+}
+
+/* oops: */
+/*     mov     $9f-8f,-(sp)            / write(fileno(stderr),8f,strlen()) */
+/*     mov     $8f,-(sp) */
+/*     mov     $2,-(sp) */
+/*     jsr     pc,_write */
+/*     mov     $2,(sp) */
+/*     jsr     pc,__exit */
+/*     .data */
+/* 8: */
+/*     <as: can't create tmpfile\n> */
+/* 9: */
+/*     .even */
+/*     .text */
+
+int oops() {
+       write(2, "as: can't create tmpfile\n", 25);
+       exit(2);
+}
+
+void nomem() {
+       write(2, "as: out of memory\n", 18);
+       aexit();
+}
+
+/* error: */
+
+void error(code) int code; {
+       int i, j;
+       static char report[] = "f xxxx\n";
+
+/*     tst     passno                  / on pass1,2 ? */
+/*     bpl     errorp2 */
+
+/* putchar('\n'); */
+ fflush(stdout);
+       if (passno < 0) {
+
+/*     inc     errflg */
+
+               errflg = 1;
+
+/*     mov     r0,-(sp) */
+/*     mov     r1,-(sp) */
+/*     mov     r5,r0 */
+/*     tst     *curarg */
+/*     beq     1f */
+/*     mov     r0,-(sp) */
+/*     mov     *curarg,-(sp) */
+/*     clr     *curarg */
+/*     jsr     pc,filerr */
+/*     tst     (sp)+ */
+/*     mov     (sp)+,r0 */
+/* 1: */
+
+               if (*curarg) {
+                       filerr(*curarg);
+                       *curarg = NULL;
+               }
+
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+/*     jsr     pc,errcmn */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+/*     mov     (sp)+,r1 */
+/*     mov     (sp)+,r0 */
+/*     rts     pc */
+
+       }
+       else {
+
+/* errorp2: */
+/*     mov     pc,errflg */
+/*     mov     $666,outmod             / make nonexecutable */
+
+               errflg = 2;
+               outmod = 0666;
+
+/*     mov     r3,-(sp) */
+/*     mov     r2,-(sp) */
+/*     mov     r1,-(sp) */
+/*     mov     r0,-(sp) */
+/*     tst     -(sp)                   / write(1, argb, strlen(argb)) */
+/*     mov     $argb,-(sp) */
+/*     mov     $1,-(sp) */
+/*     mov     $argb,r1 */
+/*     clr     r0 */
+/* 1: */
+/*     tstb    (r1)+ */
+/*     beq     2f */
+/*     inc     r0 */
+/*     br      1b */
+/* 2: */
+/*     mov     r0,4(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+
+               if (*argb) {
+                       write(1, argb, strlen(argb));
+                       *argb = 0; /* a nick innovation */
+               }
+
+/*     movb    12(sp),r0 */
+/*     jsr     pc,errcmn */
+/*     mov     (sp)+,r0 */
+/*     mov     (sp)+,r1 */
+/*     mov     (sp)+,r2 */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,(sp) */
+/*     rts     pc */
+
+       }
+
+/* errcmn: */
+/*     mov     line,r3 */
+/*     movb    r0,9f */
+
+       j = line;
+       *report = code;
+
+/*     mov     $9f+6,r0 */
+/*     mov     $4,r1 */
+/* 2: */
+/*     clr     r2 */
+/*     div     $10.,r2 */
+/*     add     $'0,r3 */
+/*     movb    r3,-(r0) */
+/*     mov     r2,r3 */
+/*     sob     r1,2b */
+
+       for (i = 0; i < 4; i++) {
+               report[5 - i] = (j % 10) + '0';
+               j /= 10;
+       }
+
+/*     mov     $7,-(sp)                / write(1, 9f, 7) */
+/*     mov     $9f,-(sp) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+
+       write (1, report, 7);
+
+/*     rts     pc */
+
+}
+
+/*     .data */
+/* 9:  <f xxxx\n> */
+/*     .even */
+/*     .text */
+
+/* p0putw: */
+
+void p0putw(word) int word; {
+
+/*     tst     ifflg */
+/*     beq     1f */
+/*     cmp     r4,$'\n */
+/*     bne     2f */
+/* 1: */
+
+/* printf("p0putw(0%o)\n", word); */
+       if (ifflg == 0 || word == TNEWLINE)
+               {
+
+/*     mov     r4,*obufp */
+/*     add     $2,obufp */
+/*     cmp     obufp,$outbuf+1024. */
+/*     blo     2f */
+/*     mov     $outbuf,obufp */
+
+               *obufp++ = word;
+               if (obufp >= outbuf + 512) {
+                       obufp = outbuf;
+
+/*     mov     r1,-(sp)                / protect r1 from library */
+/*     mov     $1024.,-(sp)            / write(fout, outbuf, 1024) */
+/*     mov     $outbuf,-(sp) */
+/*     mov     fout,-(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+/*     mov     (sp)+,r1 */
+/*     tst     r0 */
+/*     bpl     2f */
+/*     jmp     wrterr */
+
+                       if (write(fout, outbuf, 512 * sizeof(short)) < 0)
+                               wrterr();
+               }
+       }
+
+/* 2: */
+/*     rts     pc */
+
+}
+
+/* Pass 0. */
+
+/* pass0: */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,checkeos */
+/*             br 7f */
+
+void pass0() {
+       intptr_t tokensave;
+       struct symbol *psymbol;
+       int label;
+
+       while (1) {
+               p0readop();
+               if (checkeos())
+                       goto ealoop;
+
+/*     tst     ifflg */
+/*     beq     3f */
+/*     cmp     r4,$200 */
+/*     blos    pass0 */
+/*     cmpb    (r4),$21                /if */
+/*     bne     2f */
+/*     inc     ifflg */
+/* 2: */
+/*     cmpb    (r4),$22                /endif */
+/*     bne     pass0 */
+/*     dec     ifflg */
+/*     br      pass0 */
+/* 3: */
+
+               if (ifflg) {
+                       if (token < 0 || token >= TASCII) {
+                               psymbol = (struct symbol *)token;
+                               switch (psymbol->flags) {
+                               case FDOTIF:
+                                       ifflg++;
+                                       break;
+                               case FDOTENDIF:
+                                       ifflg--;
+                                       break;
+                               }
+                       }
+                       continue;
+               }
+
+/*     mov     r4,-(sp) */
+/*     jsr     pc,p0readop */
+/*     cmp     r4,$'= */
+/*     beq     4f */
+/*     cmp     r4,$': */
+/*     beq     1f */
+/*     mov     r4,savop */
+/*     mov     (sp)+,r4 */
+/*     jsr     pc,opline */
+/*     br      ealoop */
+
+               tokensave = token;
+               p0readop();
+               if (token == TEQUAL)
+                       goto equal;
+               if (token == TCOLON)
+                       goto colon;
+               savop = token;
+               token = tokensave;
+               p0opline();
+               goto ealoop;
+
+/* 1: */
+/*     mov     (sp)+,r4 */
+/*     cmp     r4,$200 */
+/*     bhis    1f */
+/*     cmp     r4,$1                   / digit */
+/*     beq     3f */
+/*     mov     $'x,r5 */
+/*     jsr     pc,error */
+/*     br      pass0 */
+/* 1: */
+
+       colon:
+               if (tokensave >= 0 && tokensave < TASCII) {
+                       if (tokensave != TABS) {
+                               error('x');
+                               continue;
+                       }
+                       goto digit;
+               }
+
+/*     bitb    $37,(r4) */
+/*     beq     1f */
+/*     mov     $'m,r5 */
+/*     jsr     pc,error */
+/* 1: */
+
+               psymbol = (struct symbol *)tokensave;
+               if (psymbol->flags & 037)
+                       error('m');
+
+/*     bisb    dot-2,(r4) */
+/*     mov     dot,2(r4) */
+/*     br      pass0 */
+
+               psymbol->flags |= pdot->flags;
+               psymbol->value = pdot->value;
+               continue;
+
+/* 3: */
+/*     mov     numval,r0 */
+/*     jsr     pc,fbcheck */
+/*     movb    dotrel,curfbr(r0) */
+/*     asl     r0 */
+/*     movb    dotrel,nxtfb */
+/*     mov     dot,nxtfb+2 */
+/*     movb    r0,nxtfb+1 */
+/*     mov     dot,curfb(r0) */
+
+       digit:
+               label = fbcheck(numval);
+               curfbr[label] = pdot->flags;
+               curfb[label] = pdot->value;
+
+/*     cmp     fbfree,$4               / room for another fb entry? */
+/*     bge     5f                      / yes - br */
+/*     jsr     pc,growfb               / no - grow the table */
+/* 5: */
+               if (fbfree == 0)
+                       growfb();
+
+/*     sub     $4,fbfree               / four bytes less available */
+/*     mov     nxtfb,*fbptr            / store first word */
+/*     add     $2,fbptr                / advance to next */
+/*     mov     nxtfb+2,*fbptr          / store second word */
+/*     add     $2,fbptr                / point to next entry */
+/*     br      pass0 */
+
+               fbfree--;
+               fbptr->name = NULL;
+               fbptr->flags = pdot->flags;
+               fbptr->value = pdot->value;
+               fbptr->number = label;
+               fbptr++;
+               continue;
+
+/* 4: */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     mov     (sp)+,r1 */
+/*     cmp     r1,$200 */
+/*     bhis    1f */
+/*     mov     $'x,r5 */
+/*     jsr     pc,error */
+/* 7: */
+/*     br      ealoop */
+
+       equal:
+               p0readop();
+               p0expres();
+               if (tokensave >= 0 && tokensave < TASCII) {
+                       error('x');
+                       goto ealoop;
+               }
+
+/* 1: */
+/*     cmp     r1,$dotrel */
+/*     bne     2f */
+/*     bic     $40,r3 */
+/*     cmp     r3,dotrel */
+/*     bne     1f */
+/* 2: */
+
+               psymbol = (struct symbol *)tokensave;
+               if (psymbol == pdot) {
+                       leftflags &= ~FGLOBAL;
+/* printf("leftflags 0%o pdot->flags 0%o\n", leftflags, pdot->flags); */
+                       if (leftflags != pdot->flags)
+                               goto doterr;
+               }
+
+/*     bicb    $37,(r1) */
+/*     bic     $!37,r3 */
+/*     bne     2f */
+/*     clr     r2 */
+/* 2: */
+
+               psymbol->flags &= ~037;
+               leftflags &= 037;
+               if (leftflags == 0)
+                       leftvalue = 0;
+
+/*     bisb    r3,(r1) */
+/*     mov     r2,2(r1) */
+/*     br      ealoop */
+
+               psymbol->flags |= leftflags;
+               psymbol->value = leftvalue;
+               goto ealoop;
+
+/* 1: */
+/*     mov     $'.,r5 */
+/*     jsr     pc,error */
+/*     movb    $2,dotrel */
+
+       doterr:
+               error('.');
+               pdot->flags = FTEXT;
+
+/* ealoop: */
+/*     cmp     r4,$'; */
+/*     beq     9f */
+/*     cmp     r4,$'\n */
+/*     bne     1f */
+/*     inc     line */
+/*     br      9f */
+/* 1: */
+
+       ealoop:
+/* printf("ealoop token = 0x%08x\n", token); */
+               if (token == TSEMICOLON)
+                       continue;
+               if (token == TNEWLINE) {
+                       line++;
+                       continue;
+               }
+
+/*     cmp     r4,$'\e */
+/*     bne     2f */
+/*     tst     ifflg */
+/*     beq     1f */
+/*     mov     $'x,r5 */
+/*     jsr     pc,error */
+/* 1: */
+/*     rts     pc */
+/* 2: */
+/*     mov     $'x,r5 */
+/*     jsr     pc,error */
+
+               if (token == TENDFILE) {
+                       if (ifflg)
+                               error('x');
+                       break;
+               }
+               error('x');
+
+/* 2: */
+/*     jsr     pc,checkeos */
+/*             br 9f */
+/*     jsr     pc,p0readop */
+/*     br      2b */
+/* 9: */
+/*     jmp     pass0 */
+
+               while (checkeos() == 0)
+                       p0readop();
+       }
+}
+
+/* fbcheck: */
+/*     cmp     r0,$9. */
+/*     bhi     1f */
+/*     rts     pc */
+/* 1: */
+/*     mov     $'f,r5 */
+/*     jsr     pc,error */
+/*     clr     r0 */
+/*     rts     pc */
+
+int fbcheck(label) int label; {
+       if (label < 10)
+               return label;
+       error('f');
+       return 0;
+}
+
+/* the 'fb' table never grows to be large.  In fact all of the assemblies */
+/* of C compiler generated code which were processed by 'c2' never */
+/* produced a table larger than 0 bytes.  So we 'realloc' because */
+/* this is not done enough to matter. */
+
+/* growfb: */
+/*     mov     r1,-(sp)                / save r1 from library */
+/*     add     $256.,fbtblsz           / new size of fb table */
+/*     mov     $256.,fbfree            / number available now */
+
+void growfb() {
+       fbtblsz += 64;
+       fbfree = 64;
+
+/*     mov     fbtblsz,-(sp)           / fbtbl = realloc(fbtbl, fbtblsz); */
+/*     mov     fbtbl,-(sp) */
+/*     bne     1f                      / extending table - br */
+/*     mov     $1,(sp)                 / r0 = calloc(1, fbtblsz); */
+/*     jsr     pc,_calloc */
+/*     br      2f */
+/* 1: */
+/*     jsr     pc,_realloc */
+/* 2: */
+/*     cmp     (sp)+,(sp)+ */
+/*     mov     r0,fbtbl */
+
+       if (fbtbl == NULL)
+               fbtbl = calloc(fbtblsz, sizeof(struct symbol));
+       else
+               fbtbl = realloc(fbtbl, fbtblsz * sizeof(struct symbol));
+
+/*     bne     1f */
+/*     iot                             / Can never happen (I hope) */
+/* 1: */
+
+       if (fbtbl == NULL)
+               nomem();
+
+/*     add     fbtblsz,r0              / fbptr starts 256 bytes from */
+/*     sub     $256.,r0                / end of new region */
+/*     mov     r0,fbptr */
+/*     mov     (sp)+,r1                / restore register */
+/*     rts     pc */
+
+       fbptr = fbtbl + fbtblsz - 64;
+}
+
+/* Symbol table lookup and hashtable maintenance. */
+
+/* rname: */
+/*     mov     r1,-(sp) */
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+
+void rname() {
+       int count;
+       char *p;
+       int local;
+       int hash, c;
+       int timesaround;
+       struct symbol *psymbol;
+       struct symbol **ppsymbol;
+       int len;
+
+/*     movb    Ncps,r5                 / Max num of chars to accept */
+/*     mov     $symbol,r2 */
+/*     clr     (r2) */
+
+/* printf("rname()\n"); */
+       count = Ncps;
+       p = symbol;
+       *p = 0;
+
+/*     clr     -(sp) */
+/*     clr     -(sp) */
+
+       local = 0;
+       hash = 0;
+
+/*     cmp     r0,$'~                  / symbol not for hash table? */
+/*     bne     1f                      / no - br */
+/*     inc     2(sp) */
+/*     clr     ch */
+
+       if (ch == '~') {
+               local = 1;
+               ch = 0;
+       }
+
+/* 1: */
+/*     jsr     pc,rch */
+/*     movb    chartab(r0),r3 */
+/*     ble     1f */
+/*     add     r3,(sp) */
+/*     swab    (sp) */
+/*     dec     r5 */
+/*     blt     1b */
+/*     movb    r3,(r2)+ */
+/*     br      1b */
+/* 1: */
+
+       while (1) {
+               c = rch();
+               if (chartab[c] <= 0)
+                       break;
+               hash += c;
+               hash = ((hash >> 8) & 0377) | ((hash & 0377) << 8);
+               if (count) {
+                       count--;
+                       *p++ = c;
+               }
+ /* bug!! should stop accumulating hash when count == 0 */
+       }
+
+/*     clrb    (r2)+                   / null terminate string */
+/*     movb    r0,ch */
+
+       *p++ = 0;
+/* printf("symbol = \"%s\"\n", symbol); */
+       ch = c;
+/* if (ch) printf("a push 0x%02x\n", ch); */
+
+/*     mov     (sp)+,r1 */
+/*     clr     r0 */
+/*     tst     (sp)+ */
+/*     beq     1f */
+/*     mov     symend,r4 */
+/*     br      4f                      / go insert into symtable (!hashtbl) */
+/* 1: */
+
+       if (local) {
+               psymbol = isroom(symend); /* symend; */
+               goto insert;
+       }
+
+/*     div     $hshsiz,r0 */
+/*     ashc    $1,r0 */
+/*     add     hshtab,r1 */
+/*     clr     timesaround */
+
+       ppsymbol = hshtab + (hash % hshsiz);
+       hash /= hshsiz;
+       timesaround = 0;
+
+/* 1: */
+/*     sub     r0,r1 */
+/*     cmp     r1,hshtab */
+/*     bhi     2f */
+/*     add     $2*hshsiz,r1 */
+
+       while (1) {
+               ppsymbol -= hash;
+               if (ppsymbol <= hshtab) {
+                       ppsymbol += hshsiz;
+
+/*     tst     timesaround */
+/*     beq     3f */
+/*     mov     $8f-9f,-(sp)            / write(fileno(stdout),9f,8f-9f); */
+/*     mov     $9f,-(sp) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+/*     jsr     pc,aexit */
+/* not reached */
+
+                       if (timesaround) {
+                               write(2, "as: symbol table overflow\n", 26);
+                               aexit();
+                       }
+
+/*     .data */
+/* timesaround: 0 */
+/* 9: */
+/*     <as: symbol table overflow\n> */
+/* 8: */
+/*     .even */
+/*     .text */
+/* 3: */
+/*     inc     timesaround */
+
+                       timesaround = 1;
+               }
+
+/* 2: */
+/*     mov     $symbol,r2 */
+/*     mov     -(r1),r4 */
+/*     beq     3f */
+/*     mov     (r4)+,r3                / ptr to symbol's name */
+/* 9: */
+/*     cmpb    (r2),(r3)+ */
+/*     bne     1b                      / not the right symbol - br */
+/*     tstb    (r2)+                   / at end of symbol? */
+/*     bne     9b                      / nope - keep looking */
+/*     br      1f                      / yep - br */
+
+               psymbol = *--ppsymbol;
+               if (psymbol == NULL)
+                       break;
+               if (!strcmp(symbol, psymbol->name))
+                       goto found;
+       }
+
+/* 3: */
+/*     mov     symend,r4 */
+/*     jsr     pc,isroom               / make sure there's room in block */
+/*     mov     r4,(r1) */
+/* 4: */
+/*     jsr     pc,isroom               / check for room in current block */
+
+       psymbol = isroom(symend);
+       *ppsymbol = psymbol;
+insert:
+       /* isroom(psymbol); */
+
+/*     mov     $symbol,r2              / length of string (including null) */
+/* 8 : */
+/*     tstb    (r2)+ */
+/*     bne     8b */
+/*     sub     $symbol,r2 */
+/*     jsr     pc,astring              / allocate string space */
+/*     mov     r0,(r4)+                / save string pointer in symtab entry */
+/*     mov     $symbol,r1 */
+/* 9: */
+/*     movb    (r1)+,(r0)+             / copy symbol name to string block */
+/*     bne     9b */
+/*     sub     $SYMENTSZ,symleft */
+
+       len = strlen(symbol) + 1;
+       p = astring(len);
+       psymbol->name = p;
+       memcpy(p, symbol, len);
+       symleft--;
+
+/* each new symbol is assigned a unique one up number.  This is done because */
+/* the user symbol table is no longer contiguous - the symbol number can */
+/* not be calculated by subtracting a base address and dividing by the */
+/* size of a symbol. */
+
+/*     clr     (r4)+                   / flags word */
+/*     clr     (r4)+                   / value word */
+/*     mov     symnum,(r4)+ */
+/*     inc     symnum */
+/*     mov     r4,symend */
+/*     sub     $6,r4                   / point to flags word */
+
+       psymbol->flags = 0; /* redundant */
+       psymbol->value = 0; /* redundant */
+       psymbol->number = symnum++;
+       symend = psymbol + 1;
+
+/* 1: */
+/*     mov     r4,-(sp) */
+/*     mov     r4,r3 */
+/*     tst     -(r3)                   / back to beginning of entry */
+/*     cmp     r3,$ebsymtab            / Permanent Symbol Table(opcode, etc)? */
+/*     blo     1f                      / yes - br */
+/*     mov     6(r3),r4                / get symbol number */
+/*     add     $4000,r4                / user symbol flag */
+/*     br      2f */
+/* 1: */
+
+/* PST entries are PSTENTSZ bytes each because they do not have a 'symnum' */
+/* entry associated with them. */
+
+/*     sub     $symtab,r3 */
+/*     clr     r2 */
+/*     div     $PSTENTSZ,r2 */
+/*     mov     r2,r4 */
+/*     add     $1000,r4                / builtin symbol */
+
+/* 2: */
+/*     jsr     pc,p0putw */
+
+found:
+       if (psymbol >= symtab + ebsymtab)
+               p0putw(04000 + psymbol->number);
+       else
+               p0putw(01000 + (psymbol - symtab));
+
+/*     mov     (sp)+,r4 */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+/*     mov     (sp)+,r1 */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+       token = (intptr_t)psymbol;
+}
+
+/* isroom: */
+/*     cmp     symleft,$SYMENTSZ       / room for another symbol? */
+/*     bge     1f                      / yes - br */
+
+struct symbol *isroom(psymbol) struct symbol *psymbol; {
+       struct symblk *psymblk;
+
+/* printf("isroom(0x%08x) symleft = %d\n", psymbol, symleft); */
+       if (symleft == 0) {
+
+/*     mov     r1,-(sp)                / save from library */
+/*     mov     $SYMBLKSZ+2,-(sp)       / size of sym block plus link word */
+/*     mov     $1,-(sp)                / number of blocks to allocate */
+/*     jsr     pc,_calloc              / calloc(1, SYMBLKSZ+2); */
+/*     cmp     (sp)+,(sp)+ */
+/*     / check for failure? */
+
+               psymblk = calloc(1, sizeof(struct symblk));
+               if (psymblk == NULL)
+                       nomem();
+
+/*     mov     r0,*symblk              / link new block to old */
+/*     mov     r0,symblk               / this is now the current block */
+/*     tst     (r0)+                   / skip link word */
+/*     mov     $SYMBLKSZ,symleft       / number of bytes available */
+/*     mov     r0,r4                   / put where it's expected */
+
+               symblk->next = psymblk;
+               symblk = psymblk;
+               symleft = SYMBLKSZ;
+               return psymblk->data;
+
+/*     mov     (sp)+,r1                / restore saved register */
+/* 1: */
+/*     rts     pc                      / return */
+
+       }
+       return psymbol;
+}
+
+/* allocate room for a string, the length is in R2 and includes room for */
+/* a terminating null byte. */
+
+/* astring: */
+/*     cmp     r2,strleft              / room in current block? */
+/*     ble     1f                      / yes - go carve out a chunk */
+
+char *astring(len) int len; {
+       struct strblk *pstrblk;
+       char *p;
+
+/* printf("astring(%d) strleft = %d\n", len, strleft); */
+       if (len > strleft) {
+
+/*     mov     $STRBLKSZ+2,-(sp) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_calloc              / symblk = calloc(1,STRBLKSZ+2) */
+/*     / check for failure? */
+/*     cmp     (sp)+,(sp)+ */
+
+               pstrblk = calloc(1, sizeof(struct strblk));
+               if (pstrblk == NULL)
+                       nomem();
+
+/*     mov     r0,*strblk              / update forward link between blocks */
+/*     mov     r0,strblk               / update current string block pointer */
+/*     tst     (r0)+                   / skip link word */
+/*     mov     r0,strend               / current data pointer */
+/*     mov     $STRBLKSZ,strleft       / amount of space left */
+
+               strblk->next = pstrblk;
+               strblk = pstrblk;
+               strleft = STRBLKSZ;
+               strend = strblk->data;
+
+/* 1: */
+/*     mov     strend,r0               / string address */
+/*     add     r2,strend               / update current end point */
+/*     sub     r2,strleft              / update amount of space left */
+/*     rts     pc */
+
+       }
+       p = strend;
+       strend += len;
+       strleft -= len;
+       return p;
+}
+
+/* number: */
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+/*     mov     r5,-(sp) */
+/*     clr     r1 */
+/*     clr     r5 */
+
+int number() {
+       int octal;
+       int decimal;
+       int c;
+
+       octal = 0;
+       decimal = 0;
+
+/* 1: */
+/*     jsr     pc,rch */
+/*     cmp     r0,$'0 */
+/*     blt     1f */
+/*     cmp     r0,$'9 */
+/*     bgt     1f */
+/*     sub     $'0,r0 */
+/*     mul     $10.,r5 */
+/*     add     r0,r5 */
+/*     ash     $3,r1 */
+/*     add     r0,r1 */
+/*     br      1b */
+
+       while (1) {
+               c = rch();
+               if (c < '0' || c > '9')
+                       break;
+               c -= '0';
+               decimal = decimal * 10 + c;
+               octal = octal * 8 + c;
+       }
+
+/* 1: */
+/*     cmp     r0,$'b */
+/*     beq     1f */
+/*     cmp     r0,$'f */
+/*     beq     1f */
+/*     cmp     r0,$'. */
+/*     bne     2f */
+/*     mov     r5,r1 */
+/*     clr     r0 */
+/* 2: */
+
+       if (c == 'b' || c == 'f')
+               goto label;
+       if (c == '.') {
+               octal = decimal;
+               c = 0;
+       }
+
+/*     movb    r0,ch */
+/*     mov     r1,r0 */
+
+       ch = c;
+/* if (ch) printf("b push 0x%02x\n", ch); */
+       numbervalue = octal;
+
+/*     mov     (sp)+,r5 */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+/*     rts     pc */
+
+       return 1;
+
+/* 1: */
+/*     mov     r0,r3 */
+/*     mov     r5,r0 */
+/*     jsr     pc,fbcheck */
+/*     add     $141,r0 */
+/*     cmp     r3,$'b */
+/*     beq     1f */
+/*     add     $10.,r0 */
+/* 1: */
+
+label:
+       numbertoken = fbcheck(decimal) + TLABEL;
+       if (c != 'b')
+               numbertoken += 10;
+
+/*     mov     r0,r4 */
+/*     mov     (sp)+,r5 */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+/*     add     $2,(sp) */
+/*     rts     pc */
+
+       return 0;
+}
+
+/* rch: */
+/*     movb    ch,r0 */
+/*     beq     1f */
+/*     clrb    ch */
+/*     rts     pc */
+
+int rch() {
+       int c;
+       char *p;
+
+/* printf("rch() ch = 0x%02x\n", ch); */
+       if (ch) {
+               c = ch;
+               ch = 0;
+               return c;
+       }
+
+/* 1: */
+/*     dec     ibufc */
+/*     blt     2f */
+/*     movb    *ibufp,r0 */
+/*     inc     ibufp */
+/*     bic     $!177,r0 */
+/*     beq     1b */
+/*     rts     pc */
+
+       while (1) {
+               ibufc--;
+               if (ibufc < 0)
+                       goto refill;
+               c = *p0ibufp++ & 0177;
+/* putchar(c); */
+               if (c == 0)
+                       continue;
+               return c;
+
+/* 2: */
+/*     mov     fin,r0 */
+/*     bmi     3f */
+
+       refill:
+               if (fin >= 0) {
+
+/*     mov     r1,-(sp)                / protect r1 from library */
+/*     mov     $1024.,-(sp)            / read(fin, inbuf, 1024) */
+/*     mov     $inbuf,-(sp) */
+/*     mov     r0,-(sp) */
+/*     jsr     pc,_read */
+/*     add     $6,sp */
+/*     mov     (sp)+,r1 */
+
+                       ibufc = read(fin, inbuf, 1024);
+
+/*     tst     r0 */
+/*     ble     2f */
+/*     mov     r0,ibufc */
+/*     mov     $inbuf,ibufp */
+/*     br      1b */
+/* 2: */
+
+                       if (ibufc > 0) {
+                               p0ibufp = inbuf;
+                               continue;
+                       }
+
+/*     mov     r1,-(sp)                / protect r1 from library */
+/*     mov     fin,-(sp)               / close(r0) */
+/*     jsr     pc,_close */
+/*     tst     (sp)+ */
+/*     mov     $-1,fin */
+/*     mov     (sp)+,r1 */
+
+                       close(fin);
+                       fin = -1;
+               }
+
+/* 3: */
+/*     dec     nargs */
+/*     bge     2f */
+/*     mov     $'\e,r0 */
+/*     rts     pc */
+/* 2: */
+
+               if (nargs == 0)
+                       return 004;
+               nargs--;
+
+/*     tst     ifflg */
+/*     beq     2f */
+/*     mov     $'i,r5 */
+/*     jsr     pc,error */
+/*     jsr     pc,aexit */
+/* not reached */
+/* 2: */
+
+               if (ifflg) {
+                       error('i');
+                       aexit();
+               }
+
+/* check for the filename arguments of "-" or "--", these mean to read 'stdin'. */
+/* Additional filenames are permitted and will be processed when EOF */
+/* is detected on stdin. */
+/*     mov     *curarg,r0 */
+/*     cmpb    (r0)+,$'- */
+/*     bne     5f                      / not the special case - br */
+/*     tstb    (r0)                    / must be '-' by itself */
+/*     beq     4f */
+/*     cmpb    (r0)+,$'-               / check for "--" */
+/*     bne     5f                      / not a double -, must be a filename */
+/*     tstb    (r0)                    / null terminated? */
+/*     bne     5f                      / no - must be a filename */
+/* 4: */
+/*     clr     fin                     / file descriptor is 0 for stdin */
+/*     br      2f */
+/* 5: */
+
+               p = *curarg;
+               if (*p++ == '-' && (*p == 0 || (*p++ == '-' && *p == 0))) {
+                       fin = 0;
+                       goto reset;
+               }
+
+/*     mov     r1,-(sp)                / protect r1 from library */
+/*     clr     -(sp)                   / open((r0), O_RDONLY, 0) */
+/*     clr     -(sp) */
+/*     mov     *curarg,-(sp) */
+/*     jsr     pc,_open */
+/*     add     $6,sp */
+/*     mov     (sp)+,r1 */
+
+               fin = open(*curarg, O_RDONLY);
+
+/*     mov     r0,fin */
+/*     bpl     2f */
+/*     mov     *curarg,-(sp) */
+/*     jsr     pc,filerr */
+/*     tst     (sp)+ */
+/*     jsr     pc,aexit */
+/*not reached */
+
+               if (fin < 0) {
+                       filerr(*curarg);
+                       aexit();
+               }
+
+/* 2: */
+/*     mov     $1,line */
+/*     mov     r4,-(sp) */
+/*     mov     r1,-(sp) */
+/*     mov     $5,r4 */
+/*     jsr     pc,p0putw */
+
+       reset:
+               line = 1;
+               token = TNEWFILE;
+               p0putw(token);
+
+/*     mov     *curarg,r1 */
+/* 2: */
+/*     movb    (r1)+,r4 */
+/*     beq     2f */
+/*     jsr     pc,p0putw */
+/*     br      2b */
+/* 2: */
+/*     add     $2,curarg */
+/*     mov     $-1,r4 */
+/*     jsr     pc,p0putw */
+
+               p = *curarg++;
+               while (1) {
+                       c = *p++;
+                       if (c == 0)
+                               break;
+                       p0putw(c);
+               }
+               p0putw(-1);
+
+/*     mov     (sp)+,r1 */
+/*     mov     (sp)+,r4 */
+/*     br      1b */
+
+       }
+}
+
+/* p0readop: */
+/*     mov     savop,r4 */
+/*     beq     1f */
+/*     clr     savop */
+/*     rts     pc */
+/* 1: */
+/*     jsr     pc,8f */
+/*     jsr     pc,p0putw */
+/*     rts     pc */
+
+void p0readop() {
+       int c;
+
+/* printf("p0readop() savop = 0x%08x\n", savop); */
+       if (savop) {
+               token = savop;
+               savop = 0;
+               return;
+       }
+
+/* 8: */
+/*     jsr     pc,rch */
+/*     mov     r0,r4 */
+/*     movb    chartab(r0),r1 */
+/*     bgt     rdname */
+/*     jmp     *1f-2(r1) */
+
+       while (1) {
+               c = rch();
+               switch (chartab[c]) {
+               default:
+                       rdname(c);
+                       return;
+
+
+/*     .data */
+/*     fixor */
+
+               case -026:
+#if 1 /* modifications for dec syntax */
+                       if (c == '#')
+                               retread(TDOLL);
+                       else if (c == '@')
+                               retread(TSTAR);
+                       else
+#endif
+                       fixor();
+                       return;
+
+/*     escp */
+
+               case -024:
+                       escp();
+                       return;
+
+/*     8b */
+
+               case -022:
+                       break;
+
+/*     retread */
+
+               case -020:
+                       retread(c);
+                       return;
+
+/*     dquote */
+
+               case -016:
+                       dquote();
+                       return;
+
+/*     garb */
+
+               case -014:
+                       garb();
+                       break;
+
+/*     squote */
+
+               case -012:
+                       squote();
+                       return;
+
+/*     rdname */
+
+               case -010:
+                       rdname(c);
+                       return;
+
+/*     skip */
+
+               case -006:
+                       skip();
+                       return;
+
+/*     rdnum */
+
+               case -004: /* can never get here */
+                       rdnum();
+                       return;
+
+/*     retread */
+
+               case -002:
+                       retread(c);
+                       return;
+
+/*     string */
+
+               case -000:
+                       string();
+                       return;
+
+/* 1: */
+/*     .text */
+
+               }
+       }
+}
+
+/* escp: */
+/*     jsr     pc,rch */
+/*     mov     $esctab,r1 */
+/* 1: */
+/*     cmpb    r0,(r1)+ */
+/*     beq     1f */
+/*     tstb    (r1)+ */
+/*     bne     1b */
+/*     rts     pc */
+/* 1: */
+/*     movb    (r1),r4 */
+/*     rts     pc */
+
+void escp() {
+       int c;
+
+       c = rch();
+       switch (c) {
+
+/*     .data */
+/* esctab: */
+/*     .byte '/, '/ */
+/*     .byte '\<, 035 */
+
+       case '<':
+               return retread(TLSH);
+
+/*     .byte '>, 036 */
+
+       case '>':
+               retread(TRSH);
+               return;
+
+/*     .byte '%, 037 */
+
+       case '%':
+               retread(TOR);
+               return;
+
+/*     .byte 0, 0 */
+/*     .text */
+
+       }
+       retread(c);
+}
+
+/* fixor: */
+/*     mov     $037,r4 */
+/* retread: */
+/*     rts     pc */
+
+void fixor() {
+       retread(TOR);
+}
+
+void retread(c) int c; {
+       token = c;
+       p0putw(token);
+}
+
+/* rdname: */
+/*     movb    r0,ch */
+/*     cmp     r1,$'0 */
+/*     blo     1f */
+/*     cmp     r1,$'9 */
+/*     blos    rdnum */
+/* 1: */
+/*     jmp     rname */
+
+void rdname(c) int c; {
+       ch = c;
+/* if (ch) printf("c push 0x%02x\n", ch); */
+       if (c >= '0' && c <= '9')
+               rdnum();
+       else
+               rname();
+}
+
+/* rdnum: */
+/*     jsr     pc,number */
+/*             br 1f */
+/*     rts     pc */
+
+void rdnum() {
+       if (number())
+               retnum(numbervalue);
+       else
+               retread(numbertoken);
+}
+
+/* squote: */
+/*     jsr     pc,rsch */
+/*     br      1f */
+
+void squote() {
+       retnum(rsch());
+}
+
+/* dquote: */
+/*     jsr     pc,rsch */
+/*     mov     r0,-(sp) */
+/*     jsr     pc,rsch */
+/*     swab    r0 */
+/*     bis     (sp)+,r0 */
+
+void dquote() {
+       int c;
+
+       c = rsch();
+       retnum(rsch() | (c << 8));
+}
+
+/* 1: */
+/*     mov     r0,numval */
+/*     mov     $1,r4 */
+/*     jsr     pc,p0putw */
+/*     mov     numval,r4 */
+/*     jsr     pc,p0putw */
+/*     mov     $1,r4 */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void retnum(value) int value; {
+       numval = value;
+       token = TABS;
+       p0putw(token);
+       p0putw(numval);
+}
+
+/* skip: */
+/*     jsr     pc,rch */
+/*     mov     r0,r4 */
+/*     cmp     r0,$'\e */
+/*     beq     1f */
+/*     cmp     r0,$'\n */
+/*     bne     skip */
+/* 1: */
+/*     rts     pc */
+
+void skip() {
+       int c;
+
+       do {
+               c = rch();
+               if (c == '\e') {
+                       retread(TENDFILE);
+                       return;
+               }
+       } while (c != '\n');
+       retread(TNEWLINE);
+}
+
+/* garb: */
+/*     mov     $'g,r5 */
+/*     jsr     pc,error */
+/*     br      8b */
+
+void garb() {
+       error('g');
+}
+
+/* string: */
+/*     mov     $'<,r4 */
+/*     jsr     pc,p0putw */
+
+void string() {
+       int c;
+
+       token = TSTRING;
+       p0putw(token);
+
+/*     clr     numval */
+/* 1: */
+/*     jsr     pc,rsch */
+/*     tst     r1 */
+/*     bne     1f */
+/*     mov     r0,r4 */
+/*     bis     $400,r4 */
+/*     jsr     pc,p0putw */
+/*     inc     numval */
+/*     br      1b */
+/* 1: */
+
+       numval = 0;
+       while (1) {
+               c = rsch();
+               if (endflag)
+                       break;
+               p0putw(0400 | c);
+               numval++;
+       }
+
+/*     mov     $-1,r4 */
+/*     jsr     pc,p0putw */
+/*     mov     $'<,r4 */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+       p0putw(-1);
+}
+
+/* rsch: */
+/*     jsr     pc,rch */
+
+int rsch() {
+       int c;
+
+       c = rch();
+
+/*     cmp     r0,$'\e */
+/*     beq     4f */
+/*     cmp     r0,$'\n */
+/*     beq     4f */
+
+       endflag = 0;
+       if (c != 004 && c != '\n') {
+
+/*     clr     r1 */
+/*     cmp     r0,$'\\ */
+/*     bne     3f */
+/*     jsr     pc,rch */
+
+               if (c == '\\') {
+                       c = rch();
+
+/*     mov     $schar,r2 */
+/* 1: */
+/*     cmpb    (r2)+,r0 */
+/*     beq     2f */
+/*     tstb    (r2)+ */
+/*     bpl     1b */
+/*     rts     pc */
+/* 2: */
+/*     movb    (r2)+,r0 */
+/*     clr     r1 */
+/*     rts     pc */
+
+                       switch (c) {
+                       case 'n':
+                               return 012;
+                       case 's':
+                               return 040;
+                       case 't':
+                               return 011;
+                       case 'e':
+                               return 004;
+                       case '0':
+                               return 000;
+                       case 'r':
+                               return 015;
+                       case 'a':
+                               return 006;
+                       case 'p':
+                               return 033;
+                       }
+                       return c;
+
+/* 3: */
+/*     cmp     r0,$'> */
+/*     bne     1f */
+/*     inc     r1 */
+/* 1: */
+/*     rts     pc */
+
+               }
+               if (c == '>')
+                       endflag = 1;
+               return c;
+
+/* 4: */
+/*     mov     $'<,r5 */
+/*     jsr     pc,error */
+/*     jsr     pc,aexit */
+/* not reached */
+
+       }
+       error('<');
+       aexit();
+       return 0; /* keep compiler happy */
+}
+
+/*     .data */
+/* schar: */
+/*     .byte 'n, 012 */
+/*     .byte 's, 040 */
+/*     .byte 't, 011 */
+/*     .byte 'e, 004 */
+/*     .byte '0, 000 */
+/*     .byte 'r, 015 */
+/*     .byte 'a, 006 */
+/*     .byte 'p, 033 */
+/*     .byte 0,  -1 */
+/*     .text */
+
+/* opline: */
+/*     mov     r4,r0 */
+/*     bmi     1f */
+/*     cmp     r0,$200 */
+/*     bgt     1f */
+/*     cmp     r0,$'< */
+/*     bne     xpr */
+/*     jmp     opl17 */
+/* xpr: */
+/*     jsr     pc,expres */
+/*     add     $2,dot */
+/*     rts     pc */
+/* 1: */
+
+void p0xpr() {
+       p0expres();
+       pdot->value += 2;
+}
+
+void p0opline() {
+       struct symbol *psymbol;
+       int flags;
+
+/* printf("p0opline() token 0x%08x\n", token); */
+       if (token >= 0 && token < TASCII) {
+               if (token == TSTRING)
+                       p0opl17();
+               else
+                       p0xpr();
+               return;
+       }
+
+/*     movb    (r4),r0 */
+/*     cmp     r0,$24 */
+/*     beq     xpr */
+/*     cmp     r0,$5 */
+/*     blt     xpr */
+/*     cmp     r0,$36 */
+/*     bgt     xpr */
+
+       psymbol = (struct symbol *)token;
+       flags = psymbol->flags;
+       if (flags <= FBSS || flags == FREGISTER || flags > FJCOND) {
+               p0xpr();
+               return;
+       }
+
+/*     mov     r0,-(sp) */
+/*     jsr     pc,p0readop */
+/*     mov     (sp)+,r0 */
+/*     asl     r0 */
+/*     jmp     *1f-12(r0) */
+
+       p0readop();
+       switch (flags) {
+
+/*     .data */
+/* 1: */
+/*     opl13                   / map fop freg,fdst to double */
+
+       case FMOVFO:
+               p0opl13();
+               return;
+
+/*     opl6 */
+
+       case FBRANCH:
+               p0opl6();
+               return;
+
+/*     opl7 */
+
+       case FJSR:
+               p0opl7();
+               return;
+
+/*     opl10 */
+
+       case FRTS:
+               p0opl10();
+               return;
+
+/*     opl11 */
+
+       case FSYSTRAP:
+               p0opl11();
+               return;
+
+/*     opl13                   / map fld/fst to double */
+/*     opl13 */
+/*     opl13                   / map fop fsrc,freg to double */
+
+       case FMOVF:
+       case FDOUBLE:
+       case FFLOP:
+               p0opl13();
+               return;
+
+/*     opl15 */
+
+       case FSINGLE:
+               p0opl15();
+               return;
+
+/*     opl16 */
+
+       case FDOTBYTE:
+               p0opl16();
+               return;
+
+#if 1 /* modifications for dec syntax */
+       case FDOTWORD:
+               p0opldotword();
+               return;
+#endif
+
+/*     opl17 */
+
+       case FSTRING:
+               p0opl17();
+               return;
+
+/*     opl20 */
+
+       case FDOTEVEN:
+               p0opl20();
+               return;
+
+/*     opl21 */
+
+       case FDOTIF:
+               p0opl21();
+               return;
+
+/*     opl22 */
+
+       case FDOTENDIF:
+               p0opl22();
+               return;
+
+/*     opl23 */
+
+       case FDOTGLOBL:
+               p0opl23();
+               return;
+
+/*     xpr */
+
+       case FREGISTER: /* can never get here */
+               p0xpr();
+               return;
+
+/*     opl25 */
+
+       case FDOTTEXT:
+               p0opl25();
+               return;
+
+/*     opl26 */
+
+       case FDOTDATA:
+               p0opl26();
+               return;
+
+/*     opl27 */
+
+       case FDOTBSS:
+               p0opl27();
+               return;
+
+/*     opl13                   / map mul s,r to double */
+
+       case FMULDIV:
+               p0opl13();
+               return;
+
+/*     opl31 */
+
+       case FSOB:
+               p0opl31();
+               return;
+
+/*     opl32 */
+
+       case FDOTCOMM:
+               p0opl32();
+               return;
+
+/*     xpr */
+/*     xpr */
+
+       case FESTTEXT:
+       case FESTDATA:
+               p0xpr();
+               return;
+
+/*     opl35 */
+
+       case FJBR:
+               p0opl35();
+               return;
+
+/*     opl36 */
+
+       case FJCOND:
+               p0opl36();
+               return;
+
+/*     .text */
+
+       }
+}
+
+/* opl35:                                      / jbr */
+/*     mov     $4,-(sp) */
+/*     br      1f */
+
+void p0opl35() {
+       relative(4);
+}
+
+/* opl36:                                      / jeq, etc */
+/*     mov     $6,-(sp) */
+
+void p0opl36() {
+       relative(6);
+}
+
+/* 1: */
+/*     jsr     pc,expres */
+/*     cmp     r3,dotrel */
+/*     bne     1f */
+/*     sub     dot,r2 */
+/*     bge     1f */
+/*     cmp     r2,$-376 */
+/*     blt     1f */
+/*     mov     $2,(sp) */
+/* 1: */
+/*     add     (sp)+,dot */
+/*     rts     pc */
+
+void relative(size) int size; {
+       p0expres();
+       if (leftflags == pdot->flags) {
+               leftvalue -= pdot->value;
+               if (leftvalue < 0 && leftvalue >= -0376)
+                       size = 2;
+       }
+       pdot->value += size;
+}
+
+/* opl13: */
+
+void p0opl13() {
+       p0opl7();
+}
+
+/* opl7:                                       /double */
+/*     jsr     pc,addres */
+
+void p0opl7() {
+       p0addres();
+
+/* op2: */
+/*     cmp     r4,$', */
+/*     beq     1f */
+/*     jsr     pc,errora */
+/*     rts     pc */
+/* 1: */
+/*     jsr     pc,p0readop */
+
+       if (token != TCOMMA) {
+               error('a');
+               return;
+       }
+       p0readop();
+       p0opl15();
+}
+
+/* opl15:                              / single operand */
+/*     jsr     pc,addres */
+/*     add     $2,dot */
+/*     rts     pc */
+
+void p0opl15() {
+       p0addres();
+       pdot->value += 2;
+}
+
+/* opl31:                                      / sob */
+/*     jsr     pc,expres */
+/*     cmp     r4,$', */
+/*     beq     1f */
+/*     jsr     pc,errora */
+/* 1: */
+/*     jsr     pc,p0readop */
+
+void p0opl31() {
+       p0expres();
+       if (token != TCOMMA) {
+               error('a');
+               return;
+       }
+       p0readop();
+       p0opl11();
+}
+
+/* opl6: */
+
+void p0opl6() {
+       p0opl11();
+}
+
+/* opl10: */
+
+void p0opl10() {
+       p0opl11();
+}
+
+/* opl11:                                      /branch */
+/*     jsr     pc,expres */
+/*     add     $2,dot */
+/*     rts     pc */
+
+void p0opl11() {
+       p0expres();
+       pdot->value += 2;
+}
+
+/* opl16:                                      / .byte */
+/*     jsr     pc,expres */
+/*     inc     dot */
+/*     cmp     r4,$', */
+/*     bne     1f */
+/*     jsr     pc,p0readop */
+/*     br      opl16 */
+/* 1: */
+/*     rts     pc */
+
+void p0opl16() {
+       while (1) {
+               p0expres();
+               pdot->value++;
+               if (token != TCOMMA)
+                       break;
+               p0readop();
+       }
+}
+
+#if 1 /* modifications for dec syntax */
+void p0opldotword() {
+       while (1) {
+               p0expres();
+               pdot->value += 2;
+               if (token != TCOMMA)
+                       break;
+               p0readop();
+       }
+}
+#endif
+
+/* opl17:                                      / < (.ascii) */
+/*     add     numval,dot */
+/*     jsr     pc,p0readop */
+/*     rts     pc */
+
+void p0opl17() {
+       pdot->value += numval;
+       p0readop();
+}
+
+/* opl20:                                      /.even */
+/*     inc     dot */
+/*     bic     $1,dot */
+/*     rts     pc */
+
+void p0opl20() {
+       pdot->value = (pdot->value + 1) & ~1;
+}
+
+/* opl21:                                      /.if */
+/*     jsr     pc,expres */
+/*     tst     r3 */
+/*     bne     1f */
+/*     mov     $'U,r5 */
+/*     jsr     pc,error */
+/* 1: */
+/*     tst     r2 */
+/*     bne     opl22 */
+/*     inc     ifflg */
+/* opl22:                                      /endif */
+/*     rts     pc */
+
+void p0opl21() {
+       p0expres();
+       if (leftflags == 0)
+               error('U');
+       if (leftvalue == 0)
+               ifflg++;
+}
+
+void p0opl22() {
+}
+
+/* opl23:                                      /.globl */
+/*     cmp     r4,$200 */
+/*     blo     1f */
+/*     bisb    $40,(r4) */
+/*     jsr     pc,p0readop */
+/*     cmp     r4,$', */
+/*     bne     1f */
+/*     jsr     pc,p0readop */
+/*     br      opl23 */
+/* 1: */
+/*     rts     pc */
+
+void p0opl23() {
+       struct symbol *psymbol;
+
+       while (1) {
+               if (token >= 0 && token < TASCII)
+                       break;
+               psymbol = (struct symbol *)token;
+               psymbol->flags |= FGLOBAL;
+               p0readop();
+               if (token != TCOMMA)
+                       break;
+               p0readop();
+       }
+}
+
+/* opl25: */
+/* opl26: */
+/* opl27: */
+/*     mov     dotrel,r1 */
+/*     asl     r1 */
+/*     mov     dot,savdot-4(r1) */
+/*     mov     savdot-[2*25](r0),dot */
+/*     asr     r0 */
+/*     sub     $25-2,r0 */
+/*     mov     r0,dotrel */
+/*     rts     pc */
+
+void p0opl25() {
+       savdot[pdot->flags - FTEXT] = pdot->value;
+       pdot->value = savdot[0];
+       pdot->flags = FTEXT;
+}
+
+void p0opl26() {
+       savdot[pdot->flags - FTEXT] = pdot->value;
+       pdot->value = savdot[1];
+       pdot->flags = FDATA;
+}
+
+void p0opl27() {
+       savdot[pdot->flags - FTEXT] = pdot->value;
+       pdot->value = savdot[2];
+       pdot->flags = FBSS;
+}
+
+/* opl32:                                      / .common */
+/*     cmp     r4,$200 */
+/*     blo     1f */
+/*     bis     $40,(r4) */
+/*     jsr     pc,p0readop */
+/*     cmp     r4,$', */
+/*     bne     1f */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     rts     pc */
+/* 1: */
+/*     mov     $'x,r5 */
+/*     jsr     pc,error */
+/*     rts     pc */
+
+void p0opl32() {
+       struct symbol *psymbol;
+
+       if (token >= 0 && token < TASCII) {
+               error('x');
+               return;
+       }
+       psymbol = (struct symbol *)token;
+       psymbol->flags |= FGLOBAL;
+       p0readop();
+       if (token != TCOMMA) {
+               error('x');
+               return;
+       }
+       p0readop();
+       p0expres();
+}
+
+/* addres: */
+/*     cmp     r4,$'( */
+/*     beq     alp */
+/*     cmp     r4,$'- */
+/*     beq     amin */
+/*     cmp     r4,$'$ */
+/*     beq     adoll */
+/*     cmp     r4,$'* */
+/*     beq     astar */
+
+void p0addres() {
+/* printf("p0addres() token = 0x%08x\n", token); */
+       switch (token) {
+       case TLPAREN:
+               p0alp();
+               return;
+       case TMIN:
+               p0amin();
+               return;
+       case TDOLL:
+               p0adoll();
+               return;
+       case TSTAR:
+               p0astar();
+               return;
+       }
+       p0getx();
+}
+
+/* getx: */
+/*     jsr     pc,expres */
+/*     cmp     r4,$'( */
+/*     bne     2f */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkreg */
+/*     jsr     pc,checkrp */
+/* 1: */
+/*     add     $2,dot */
+/*     clr     r0 */
+/*     rts     pc */
+/* 2: */
+/*     cmp     r3,$24                  / register type */
+/*     bne     1b */
+/*     jsr     pc,checkreg */
+/*     clr     r0 */
+/*     rts     pc */
+
+void p0getx() {
+       p0expres();
+       if (token == TLPAREN) {
+               p0readop();
+               p0expres();
+               p0checkreg();
+               p0checkrp();
+               pdot->value += 2;
+       }
+       else if (leftflags == FREGISTER)
+               p0checkreg();
+       else
+               pdot->value += 2;
+       indirect = 0;
+}
+
+/* alp: */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkrp */
+/*     jsr     pc,checkreg */
+/*     cmp     r4,$'+ */
+/*     bne     1f */
+/*     jsr     pc,p0readop */
+/*     clr     r0 */
+/*     rts     pc */
+/* 1: */
+/*     mov     $2,r0 */
+/*     rts     pc */
+
+void p0alp() {
+       p0readop();
+       p0expres();
+       p0checkrp();
+       p0checkreg();
+       if (token == TPLUS) {
+               p0readop();
+               indirect = 0;
+       }
+       else
+               indirect = 2;
+}
+
+/* amin: */
+/*     jsr     pc,p0readop */
+/*     cmp     r4,$'( */
+/*     beq     1f */
+/*     mov     r4,savop */
+/*     mov     $'-,r4 */
+/*     br      getx */
+/* 1: */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkrp */
+/*     jsr     pc,checkreg */
+/*     clr     r0 */
+/*     rts     pc */
+
+void p0amin() {
+       p0readop();
+       if (token != TLPAREN) {
+               savop = token;
+               token = TMIN;
+               p0getx();
+       }
+       else {
+               p0readop();
+               p0expres();
+               p0checkrp();
+               p0checkreg();
+               indirect = 0;
+       }
+}
+
+/* adoll: */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     add     $2,dot */
+/*     clr     r0 */
+/*     rts     pc */
+
+void p0adoll() {
+       p0readop();
+       p0expres();
+       pdot->value += 2;
+       indirect = 0;
+}
+
+/* astar: */
+/*     jsr     pc,p0readop */
+/*     cmp     r4,$'* */
+/*     bne     1f */
+/*     mov     $'*,r5 */
+/*     jsr     pc,error */
+/* 1: */
+/*     jsr     pc,addres */
+/*     add     r0,dot */
+/*     rts     pc */
+
+void p0astar() {
+       p0readop();
+       if (token == TSTAR)
+               error('*');
+       p0addres();
+       pdot->value += indirect;
+}
+
+/* errora: */
+/*     mov     $'a,r5 */
+/*     jsr     pc,error */
+/*     rts     pc */
+
+void errora() {
+       error('a');
+}
+
+/* checkreg: */
+/*     cmp     r2,$7 */
+/*     bhi     1f */
+/*     cmp     r3,$1 */
+/*     beq     2f */
+/*     cmp     r3,$4 */
+/*     bhi     2f */
+/* 1: */
+/*     jsr     pc,errora */
+/* 2: */
+/*     rts     pc */
+
+void p0checkreg() {
+       if (leftvalue > 7 || (leftflags != FABS && leftflags <= FBSS))
+               errora();
+}
+
+/* errore: */
+/*     mov     $'e,r5 */
+/*     jsr     pc,error */
+/*     rts     pc */
+
+void errore() {
+       error('e');
+}
+
+/* checkrp: */
+/*     cmp     r4,$') */
+/*     beq     1f */
+/*     mov     $'),r5 */
+/*     jsr     pc,error */
+/*     rts     pc */
+/* 1: */
+/*     jsr     pc,p0readop */
+/*     rts     pc */
+
+void p0checkrp() {
+       if (token != TRPAREN)
+               error(')');
+       else
+               p0readop();
+}
+
+/* expres: */
+/*     mov     r5,-(sp) */
+/*     mov     $'+,-(sp) */
+/*     clr     opfound */
+/*     clr     r2 */
+/*     mov     $1,r3 */
+/*     br      1f */
+
+void p0expres() {
+       struct symbol *psymbol;
+
+/* printf("p0expres()\n"); */
+       optoken = TPLUS;
+       opfound = 0;
+       leftvalue = 0;
+       leftflags = FABS;
+       goto entry;
+
+/* advanc: */
+/*     jsr     pc,p0readop */
+/* 1: */
+/*     mov     r4,r0 */
+/*     tst     r0 */
+/*     blt     6f */
+/*     cmp     r0,$177 */
+/*     ble     7f */
+/* 6: */
+/*     movb    (r4),r0 */
+/*     mov     2(r4),r1 */
+/*     br      oprand */
+/* 7: */
+
+       while (1) {
+               p0readop();
+       entry:
+               rightflags = token;
+               if (token < 0 || token >= TASCII) {
+                       psymbol = (struct symbol *)token;
+                       rightflags = psymbol->flags;
+                       rightvalue = psymbol->value;
+                       p0oprand();
+                       continue;
+               }
+
+/*     cmp     r4,$141 */
+/*     blo     1f */
+/*     cmp     r4,$141+10. */
+/*     bhis    2f */
+/*     movb    curfbr-141(r4),r0 */
+/*     asl     r4 */
+/*     mov     curfb-[2*141](r4),r2 */
+/*     cmp     r2,$-1 */
+/*     bne     oprand */
+/*     mov     $'f,r5 */
+/*     jsr     pc,error */
+/*     br      oprand */
+/* 2: */
+/*     clr     r3 */
+/*     clr     r2 */
+/*     br      oprand */
+/* 1: */
+
+               if (token >= TLABEL) {
+                       if (token < TLABEL + 10) {
+                               rightflags = curfbr[token - TLABEL];
+ /* bug!! should be rightvalue / rightflags below: */
+                               leftvalue = curfb[token - TLABEL];
+                               if (leftvalue == -1)
+                                       error('f');
+                       }
+                       else {
+                               leftflags = 0;
+                               leftvalue = 0;
+                       }
+                       p0oprand();
+                       continue;
+               }
+
+/*     mov     $esw1,r1 */
+/* 1: */
+/*     cmp     (r1)+,r4 */
+/*     beq     1f */
+/*     tst     (r1)+ */
+/*     bne     1b */
+/*     tst     opfound */
+/*     bne     2f */
+/*     jsr     pc,errore */
+/* 2: */
+/*     tst     (sp)+ */
+/*     mov     (sp)+,r5 */
+/*     rts     pc */
+/* 1: */
+/*     jmp     *(r1) */
+
+               switch (token) {
+               default:
+                       if (opfound == 0)
+                               error('e');
+                       return;
+
+/*     .data */
+/* esw1: */
+/*     '+;     binop */
+/*     '-;     binop */
+/*     '*;     binop */
+/*     '/;     binop */
+/*     '&;     binop */
+/*     037;    binop */
+/*     035;    binop */
+/*     036;    binop */
+/*     '%;     binop */
+
+               case TPLUS:
+               case TMIN:
+               case TSTAR:
+               case TSLASH:
+               case TAND:
+               case TOR:
+               case TLSH:
+               case TRSH:
+               case TMOD:
+                       p0binop();
+                       break;
+
+/*     '[;     brack */
+
+               case TLBRACK:
+                       p0brack();
+                       break;
+
+/*     '^;     binop */
+
+               case TCARET:
+                       p0binop();
+                       break;
+
+/*     1;      exnum */
+
+               case TABS:
+                       p0exnum();
+                       break;
+
+/*     '!;     binop */
+
+               case TNOT:
+                       p0binop();
+                       break;
+
+/*     0;      0 */
+/*     .text */
+
+               }
+       }
+}
+
+/* binop: */
+/*     cmpb    (sp),$'+ */
+/*     beq     1f */
+/*     jsr     pc,errore */
+/* 1: */
+/*     movb    r4,(sp) */
+/*     br      advanc */
+
+void p0binop() {
+       if (optoken != TPLUS)
+               error('e');
+       optoken = token;
+}
+
+/* exnum: */
+/*     mov     numval,r1 */
+/*     mov     $1,r0 */
+/*     br      oprand */
+
+void p0exnum() {
+/* printf("p0exnum() numval = 0%o\n", numval); */
+       rightvalue = numval;
+       rightflags = FABS;
+       p0oprand();
+}
+
+/* brack: */
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+/*     jsr     pc,p0readop */
+/*     jsr     pc,expres */
+/*     cmp     r4,$'] */
+/*     beq     1f */
+/*     mov     $'],r5 */
+/*     jsr     pc,error */
+/* 1: */
+/*     mov     r3,r0 */
+/*     mov     r2,r1 */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+
+void p0brack() {
+       int tempvalue;
+       int tempflags;
+       int temptoken;
+
+       tempvalue = leftvalue;
+       tempflags = leftflags;
+       temptoken = optoken;
+       p0readop();
+       p0expres();
+       if (token != TRBRACK)
+               error(']');
+       rightflags = leftflags;
+       rightvalue = leftvalue;
+       leftflags = tempflags;
+       leftvalue = tempvalue;
+       optoken = temptoken;
+       p0oprand();
+}
+
+/* oprand: */
+/*     inc     opfound */
+/*     mov     $exsw2,r5 */
+/* 1: */
+/*     cmp     (sp),(r5)+ */
+/*     beq     1f */
+/*     tst     (r5)+ */
+/*     bne     1b */
+/*     br      eoprnd */
+/* 1: */
+/*     jmp     *(r5) */
+
+void p0oprand() {
+       opfound = 1;
+       switch (optoken) {
+       default:
+               p0eoprnd();
+               return;
+
+/*     .data */
+/* exsw2: */
+/*     '+; exadd */
+
+       case TPLUS:
+               p0exadd();
+               return;
+
+/*     '-; exsub */
+
+       case TMIN:
+               p0exsub();
+               return;
+
+/*     '*; exmul */
+
+       case TSTAR:
+               p0exmul();
+               return;
+
+/*     '/; exdiv */
+
+       case TSLASH:
+               p0exdiv();
+               return;
+
+/*     037; exor */
+
+       case TOR:
+               p0exor();
+               return;
+
+/*     '&; exand */
+
+       case TAND:
+               p0exand();
+               return;
+
+/*     035;exlsh */
+
+       case TLSH:
+               p0exlsh();
+               return;
+
+/*     036;exrsh */
+
+       case TRSH:
+               p0exrsh();
+               return;
+
+/*     '%; exmod */
+
+       case TMOD:
+               p0exmod();
+               return;
+
+/*     '!; exnot */
+
+       case TNOT:
+               p0exnot();
+               return;
+
+/*     '^; excmbin */
+
+       case TCARET:
+               p0excmbin();
+               return;
+
+/*     0;  0 */
+/*     .text */
+
+       }
+}
+
+/* excmbin: */
+/*     mov     r0,r3                   / give left flag of right */
+/*     br      eoprnd */
+
+void p0excmbin() {
+       leftflags = rightflags;
+       p0eoprnd();
+}
+
+/* exrsh: */
+/*     neg     r1 */
+/*     beq     exlsh */
+/*     inc     r1 */
+/*     clc */
+/*     ror     r2 */
+/* exlsh: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     ash     r1,r2 */
+/*     br      eoprnd */
+
+void p0exrsh() {
+       p0combin(0);
+       leftvalue = ((unsigned int)leftvalue & 0177777) >> rightvalue;
+       p0eoprnd();
+}
+
+void p0exlsh() {
+       p0combin(0);
+       leftvalue <<= rightvalue;
+       p0eoprnd();
+}
+
+/* exmod: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     mov     r1,-(sp) */
+/*     mov     r2,r1 */
+/*     clr     r0 */
+/*     div     (sp)+,r0 */
+/*     mov     r1,r2 */
+/*     br      eoprnd */
+
+void p0exmod() {
+       int temp;
+
+       p0combin(0);
+       temp = rightvalue & 0177777;
+       if (temp)
+               leftvalue = (leftvalue & 0177777) % temp;
+       else {
+               error('0'); /* a nick innovation */
+               leftvalue = 0;
+       }
+       p0eoprnd();
+}
+
+/* exadd: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     add     r1,r2 */
+/*     br      eoprnd */
+
+void p0exadd() {
+       p0combin(0);
+       leftvalue += rightvalue;
+       p0eoprnd();
+}
+
+/* exsub: */
+/*     mov     $1,r5 */
+/*     jsr     pc,combin */
+/*     sub     r1,r2 */
+/*     br      eoprnd */
+
+void p0exsub() {
+       p0combin(1);
+       leftvalue -= rightvalue;
+       p0eoprnd();
+}
+
+/* exand: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     com     r1 */
+/*     bic     r1,r2 */
+/*     br      eoprnd */
+
+void p0exand() {
+       p0combin(0);
+       leftvalue &= rightvalue;
+       p0eoprnd();
+}
+
+/* exor: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     bis     r1,r2 */
+/*     br      eoprnd */
+
+void p0exor() {
+       p0combin(0);
+       leftvalue |= rightvalue;
+       p0eoprnd();
+}
+
+/* exmul: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     mul     r2,r1 */
+/*     mov     r1,r2 */
+/*     br      eoprnd */
+
+void p0exmul() {
+       p0combin(0);
+       leftvalue *= rightvalue;
+       p0eoprnd();
+}
+
+/* exdiv: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     mov     r1,-(sp) */
+/*     mov     r2,r1 */
+/*     clr     r0 */
+/*     div     (sp)+,r0 */
+/*     mov     r0,r2 */
+/*     br      eoprnd */
+
+void p0exdiv() {
+       int temp;
+
+       p0combin(0);
+       temp = rightvalue & 0177777;
+       if (temp)
+               leftvalue = (leftvalue & 0177777) / temp;
+       else {
+               error('0'); /* a nick innovation */
+               leftvalue = 0;
+       }
+       p0eoprnd();
+}
+
+/* exnot: */
+/*     clr     r5 */
+/*     jsr     pc,combin */
+/*     com     r1 */
+/*     add     r1,r2 */
+/*     br      eoprnd */
+
+void p0exnot() {
+       p0combin(0);
+       leftvalue += ~rightvalue;
+       p0eoprnd();
+}
+
+/* eoprnd: */
+/*     mov     $'+,(sp) */
+/*     jmp     advanc */
+
+void p0eoprnd() {
+       optoken = TPLUS;
+}
+
+/* combin: */
+/*     mov     r0,-(sp) */
+/*     bis     r3,(sp) */
+/*     bic     $!40,(sp) */
+/*     bic     $!37,r0 */
+/*     bic     $!37,r3 */
+/*     cmp     r0,r3 */
+/*     ble     1f */
+/*     mov     r0,-(sp) */
+/*     mov     r3,r0 */
+/*     mov     (sp)+,r3 */
+/* 1: */
+
+void p0combin(minflag) int minflag; {
+       int global;
+       int flags;
+
+       global = (rightflags | leftflags) & FGLOBAL;
+       rightflags &= 037;
+       leftflags &= 037;
+       if (rightflags > leftflags) {
+               flags = rightflags;
+               rightflags = leftflags;
+               leftflags = flags;
+       }
+
+/*     tst     r0 */
+/*     beq     1f */
+/*     tst     r5 */
+/*     beq     2f */
+/*     cmp     r0,r3 */
+/*     bne     2f */
+/*     mov     $1,r3 */
+/*     br      2f */
+/* 1: */
+/*     clr     r3 */
+/* 2: */
+/*     bis     (sp)+,r3 */
+/*     rts     pc */
+
+       if (rightflags) {
+               if (minflag && rightflags == leftflags)
+                       leftflags = TABS;
+       }
+       else {
+               leftflags = 0;
+       }
+       leftflags |= global;
+}
+
+/*     .data */
+/* chartab: */
+/*     .byte -14,-14,-14,-14,-02,-14,-14,-14 */
+/*     .byte -14,-22, -2,-14,-14,-22,-14,-14 */
+/*     .byte -14,-14,-14,-14,-14,-14,-14,-14 */
+/*     .byte -14,-14,-14,-14,-14,-14,-14,-14 */
+/*     .byte -22,-20,-16,-14,-20,-20,-20,-12 */
+/*     .byte -20,-20,-20,-20,-20,-20,056,-06 */
+/*     .byte 060,061,062,063,064,065,066,067 */
+/*     .byte 070,071,-20,-02,-00,-20,-14,-14 */
+/*     .byte -14,101,102,103,104,105,106,107 */
+/*     .byte 110,111,112,113,114,115,116,117 */
+/*     .byte 120,121,122,123,124,125,126,127 */
+/*     .byte 130,131,132,-20,-24,-20,-20,137 */
+/*     .byte -14,141,142,143,144,145,146,147 */
+/*     .byte 150,151,152,153,154,155,156,157 */
+/*     .byte 160,161,162,163,164,165,166,167 */
+/*     .byte 170,171,172,-14,-26,-14,176,-14 */
+
+char chartab[TASCII] = {
+       -014,-014,-014,-014,-002,-014,-014,-014,
+       -014,-022,0 -2,-014,-014,-022,-014,-014,
+       -014,-014,-014,-014,-014,-014,-014,-014,
+       -014,-014,-014,-014,-014,-014,-014,-014,
+#if 1 /* modifications for dec syntax */
+       -022,-020,-016,-026,-020,-020,-020,-012,
+#else
+       -022,-020,-016,-014,-020,-020,-020,-012,
+#endif
+       -020,-020,-020,-020,-020,-020,0056,-006,
+       0060,0061,0062,0063,0064,0065,0066,0067,
+       0070,0071,-020,-002,-000,-020,-014,-014,
+#if 1 /* modifications for dec syntax */
+       -026,0101,0102,0103,0104,0105,0106,0107,
+#else
+       -014,0101,0102,0103,0104,0105,0106,0107,
+#endif
+       0110,0111,0112,0113,0114,0115,0116,0117,
+       0120,0121,0122,0123,0124,0125,0126,0127,
+       0130,0131,0132,-020,-024,-020,-020,0137,
+       -014,0141,0142,0143,0144,0145,0146,0147,
+       0150,0151,0152,0153,0154,0155,0156,0157,
+       0160,0161,0162,0163,0164,0165,0166,0167,
+       0170,0171,0172,-014,-026,-014,0176,-014
+};
+
+/* a.tmp1:     </tmp/atm1XX\0> */
+
+char a_tmp1[] = "/tmp/atm1XXXXXX"; /* linux requires 6 X's */
+
+/* Ncps:       .byte 8. */
+
+char Ncps = 8;
+
+/* 1:  <-\0> */
+/*     .even */
+/* dash:       1b */
+
+char *dash = "-";
+
+/* fin:        -1 */
+
+int fin = -1;
+
+/* fout:       -1 */
+
+int fout = -1;
+
+/* The next two _must_ be adjacent!  Not sure why, but then this whole */
+/* assembler is weird beyond belief. */
+/* curfb:      -1;-1;-1;-1;-1;-1;-1;-1;-1;-1 */
+
+/* THEY HAD TO BE ADJACENT BECAUSE PASS 2 p0expres() READS curfb[token - 0141] */
+/* THIS HAS BEEN SPLIT INTO curfb[token - 0141], nxtfb[token - (0141 + 10)] */
+/* BY THE WAY, THE ASSEMBLER IS NOT REALLY WEIRD, IT'S KIND OF ELEGANT !!! */
+intptr_t curfb[10] = {
+       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+/* nxtfb:      .=.+20.                 / first 4 used by pass0, all 20. by pass1+2 */
+
+/* FIRST 4 AREN'T USED BY PASS 0 ANYMORE, IT WAS ONLY TEMPORARY SCRATCH !!!! */
+intptr_t nxtfb[10];
+
+/*     .bss */
+/* curfbr:     .=.+10. */
+
+int curfbr[10];
+
+/* savdot:     .=.+6 */
+
+int savdot[3];
+
+/* hshtab:     .=.+2                   / dynamically allocated */
+
+struct symbol **hshtab;
+
+/* ch: .=.+2 */
+
+int ch;
+
+/* symnum:     .=.+2                   / symbol number */
+
+int symnum;
+
+/* symbol:     .=.+32.                 / XXX */
+/*     .=.+2                   / paranoia to make sure a null is present */
+
+char symbol[33];
+
+/* inbuf:  .=.+1024. */
+
+char inbuf[1024];
+
+/* line:       .=.+2 */
+
+int line;
+
+/* ifflg:      .=.+2 */
+
+int ifflg;
+
+/* nargs:      .=.+2 */
+
+int nargs;
+
+/* curarg:     .=.+2 */
+
+char **curarg;
+
+/* opfound:.=.+2 */
+
+int opfound;
+
+/* savop:      .=.+2 */
+
+int savop;
+
+/* numval:     .=.+2 */
+
+int numval;
+
+/* fbtblsz:.=.+2 */
+
+int fbtblsz;
+
+/* fbfree: .=.+2 */
+
+int fbfree;
+
+/* fbptr:  .=.+2 */
+
+struct symbol *fbptr;
+
+/* fbtbl:  .=.+2 */
+
+struct symbol *fbtbl;
+
+/* usymtab:.=.+2                       / ptr to first block of symbols */
+
+struct symblk *usymtab;
+
+/* symleft:.=.+2                       / bytes left in current symbol block */
+
+int symleft;
+
+/* symend: .=.+2                       / ptr to next symbol space in block */
+
+struct symbol *symend;
+
+/* symblk: .=.+2                       / ptr to beginning of current sym block */
+
+struct symblk *symblk;
+
+/* strleft:.=.+2                       / amount left in string block */
+
+int strleft;
+
+/* strend:     .=.+2                   / ptr to next available string byte */
+
+char *strend;
+
+/* strblk:     .=.+2                   / ptr to current string block link word */
+
+struct strblk *strblk;
+
+/* key to types */
+
+/*     0       undefined */
+/*     1       absolute (nop, reset, bpt, ...) */
+/*     2       text */
+/*     3       data */
+/*     4       bss */
+/*     5       flop freg,dst (movfo, = stcfd) */
+/*     6       branch */
+/*     7       jsr */
+/*     10      rts */
+/*     11      sys, trap */
+/*     12      movf (=ldf,stf) */
+/*     13      double operand (mov) */
+/*     14      flop fsrc,freg (addf) */
+/*     15      single operand (clr) */
+/*     16      .byte */
+/*     17      string (.ascii, "<") */
+/*     20      .even */
+/*     21      .if */
+/*     22      .endif */
+/*     23      .globl */
+/*     24      register */
+/*     25      .text */
+/*     26      .data */
+/*     27      .bss */
+/*     30      mul,div, etc */
+/*     31      sob */
+/*     32      .comm */
+/*     33      estimated text */
+/*     34      estimated data */
+/*     35      jbr */
+/*     36      jeq, jne, etc */
+
+/*     .data */
+/* the format of PST entries was changed.  rather than fixed 8 byte strings */
+/* (often with many trailing nulls) a pointer to a null terminated string */
+/* is now used.  This saves quite a bit of space since most PST entries are */
+/* only 3 or 4 characters long.  we had to do this the hard way since there */
+/* is no macro capability in the assembler and i'd chuck out the SDI [Span */
+/* Dependent Instruction] stuff and use my own assembler before trying to */
+/* add macros to this one.  Symbols beginning with 'L' are used since the */
+/* linker can be told to discard those. */
+
+/* symtab: */
+/* special symbols */
+
+/* L1; dotrel: 02;    dot: 0000000 */
+/* L2;     01; dotdot: 0000000 */
+
+/* register */
+
+/* L3; 24;     000000 */
+/* L4; 24;     000001 */
+/* L5; 24;     000002 */
+/* L6; 24;     000003 */
+/* L7; 24;     000004 */
+/* L8; 24;     000005 */
+/* L9; 24;     000006 */
+/* L10;        24;     000007 */
+
+/* double operand */
+
+/* L11;        13;     0010000 */
+/* L12;        13;     0110000 */
+/* L13;        13;     0020000 */
+/* L14;        13;     0120000 */
+/* L15;        13;     0030000 */
+/* L16;        13;     0130000 */
+/* L17;        13;     0040000 */
+/* L18;        13;     0140000 */
+/* L19;        13;     0050000 */
+/* L20;        13;     0150000 */
+/* L21;        13;     0060000 */
+/* L22;        13;     0160000 */
+
+/* branch */
+
+/* L23;        06;     0000400 */
+/* L24;        06;     0001000 */
+/* L25;        06;     0001400 */
+/* L26;        06;     0002000 */
+/* L27;        06;     0002400 */
+/* L28;        06;     0003000 */
+/* L29;        06;     0003400 */
+/* L30;        06;     0100000 */
+/* L31;        06;     0100400 */
+/* L32;        06;     0101000 */
+/* L33;        06;     0101400 */
+/* L34;        06;     0102000 */
+/* L35;        06;     0102400 */
+/* L36;        06;     0103000 */
+/* L37;        06;     0103000 */
+/* L38;        06;     0103000 */
+/* L39;        06;     0103400 */
+/* L40;        06;     0103400 */
+/* L41;        06;     0103400 */
+
+/* jump/branch type */
+
+/* L42;        35;     0000400 */
+/* L43;        36;     0001000 */
+/* L44;        36;     0001400 */
+/* L45;        36;     0002000 */
+/* L46;        36;     0002400 */
+/* L47;        36;     0003000 */
+/* L48;        36;     0003400 */
+/* L49;        36;     0100000 */
+/* L50;        36;     0100400 */
+/* L51;        36;     0101000 */
+/* L52;        36;     0101400 */
+/* L53;        36;     0102000 */
+/* L54;        36;     0102400 */
+/* L55;        36;     0103000 */
+/* L56;        36;     0103000 */
+/* L57;        36;     0103000 */
+/* L58;        36;     0103400 */
+/* L59;        36;     0103400 */
+/* L60;        36;     0103400 */
+
+/* single operand */
+
+/* L61;        15;     0005000 */
+/* L62;        15;     0105000 */
+/* L63;        15;     0005100 */
+/* L64;        15;     0105100 */
+/* L65;        15;     0005200 */
+/* L66;        15;     0105200 */
+/* L67;        15;     0005300 */
+/* L68;        15;     0105300 */
+/* L69;        15;     0005400 */
+/* L70;        15;     0105400 */
+/* L71;        15;     0005500 */
+/* L72;        15;     0105500 */
+/* L73;        15;     0005600 */
+/* L74;        15;     0105600 */
+/* L75;        15;     0005700 */
+/* L76;        15;     0105700 */
+/* L77;        15;     0006000 */
+/* L78;        15;     0106000 */
+/* L79;        15;     0006100 */
+/* L80;        15;     0106100 */
+/* L81;        15;     0006200 */
+/* L82;        15;     0106200 */
+/* L83;        15;     0006300 */
+/* L84;        15;     0106300 */
+/* L85;        15;     0000100 */
+/* L86;        15;     0000300 */
+/* L87;        15;     0006500 */
+/* L88;        15;     0006600 */
+/* L89;        15;     0106500 */
+/* L90;        15;     0106600 */
+/* L91;        15;     0170300 */
+/* L92;        15;     0106700 */
+/* L93;        15;     0106400 */
+/* L94;        15;     0007000 */
+/* L95;        15;     0007200 */
+/* L96;        15;     0007300 */
+
+/* jsr */
+
+/* L97;        07;     0004000 */
+
+/* rts */
+
+/* L98;        010;    000200 */
+
+/* simple operand */
+
+/* L99;        011;    104400 */
+/* L102;       011;    000230 */
+
+/* flag-setting */
+
+/* L103;       01;     0000240 */
+/* L104;       01;     0000241 */
+/* L105;       01;     0000242 */
+/* L106;       01;     0000244 */
+/* L107;       01;     0000250 */
+/* L108;       01;     0000257 */
+/* L109;       01;     0000261 */
+/* L110;       01;     0000262 */
+/* L111;       01;     0000264 */
+/* L112;       01;     0000270 */
+/* L113;       01;     0000277 */
+/* L114;       01;     0000000 */
+/* L115;       01;     0000001 */
+/* L116;       01;     0000002 */
+/* L117;       01;     0000003 */
+/* L118;       01;     0000004 */
+/* L119;       01;     0000005 */
+/* L120;       01;     0000006 */
+/* L121;       01;     0000007 */
+
+/* floating point ops */
+
+/* L122;       01;     170000 */
+/* L123;       01;     170001 */
+/* L124;       01;     170011 */
+/* L125;       01;     170002 */
+/* L126;       01;     170012 */
+/* L127;       15;     170400 */
+/* L128;       15;     170700 */
+/* L129;       15;     170600 */
+/* L130;       15;     170500 */
+/* L131;       12;     172400 */
+/* L132;       14;     177000 */
+/* L133;       05;     175400 */
+/* L134;       14;     177400 */
+/* L135;       05;     176000 */
+/* L136;       14;     172000 */
+/* L137;       14;     173000 */
+/* L138;       14;     171000 */
+/* L139;       14;     174400 */
+/* L140;       14;     173400 */
+/* L141;       14;     171400 */
+/* L142;       14;     176400 */
+/* L143;       05;     175000 */
+/* L144;       15;     170100 */
+/* L145;       15;     170200 */
+/* L146;       24;     000000 */
+/* L147;       24;     000001 */
+/* L148;       24;     000002 */
+/* L149;       24;     000003 */
+/* L150;       24;     000004 */
+/* L151;       24;     000005 */
+
+/* L152;       30;     070000 */
+/* L153;       30;     071000 */
+/* L154;       30;     072000 */
+/* L155;       30;     073000 */
+/* L156;       07;     074000 */
+/* L157;       15;     006700 */
+/* L158;       11;     006400 */
+/* L159;       31;     077000 */
+
+/* pseudo ops */
+
+/* L160;       16;     000000 */
+/* L161;       20;     000000 */
+/* L162;       21;     000000 */
+/* L163;       22;     000000 */
+/* L164;       23;     000000 */
+/* L165;       25;     000000 */
+/* L166;       26;     000000 */
+/* L167;       27;     000000 */
+/* L168;       32;     000000 */
+
+/* ebsymtab: */
+
+/* L1: <.\0> */
+/* L2: <..\0> */
+/* L3: <r0\0> */
+/* L4: <r1\0> */
+/* L5: <r2\0> */
+/* L6: <r3\0> */
+/* L7: <r4\0> */
+/* L8: <r5\0> */
+/* L9: <sp\0> */
+/* L10:        <pc\0> */
+/* L11:        <mov\0> */
+/* L12:        <movb\0> */
+/* L13:        <cmp\0> */
+/* L14:        <cmpb\0> */
+/* L15:        <bit\0> */
+/* L16:        <bitb\0> */
+/* L17:        <bic\0> */
+/* L18:        <bicb\0> */
+/* L19:        <bis\0> */
+/* L20:        <bisb\0> */
+/* L21:        <add\0> */
+/* L22:        <sub\0> */
+/* L23:        <br\0> */
+/* L24:        <bne\0> */
+/* L25:        <beq\0> */
+/* L26:        <bge\0> */
+/* L27:        <blt\0> */
+/* L28:        <bgt\0> */
+/* L29:        <ble\0> */
+/* L30:        <bpl\0> */
+/* L31:        <bmi\0> */
+/* L32:        <bhi\0> */
+/* L33:        <blos\0> */
+/* L34:        <bvc\0> */
+/* L35:        <bvs\0> */
+/* L36:        <bhis\0> */
+/* L37:        <bec\0> */
+/* L38:        <bcc\0> */
+/* L39:        <blo\0> */
+/* L40:        <bcs\0> */
+/* L41:        <bes\0> */
+/* L42:        <jbr\0> */
+/* L43:        <jne\0> */
+/* L44:        <jeq\0> */
+/* L45:        <jge\0> */
+/* L46:        <jlt\0> */
+/* L47:        <jgt\0> */
+/* L48:        <jle\0> */
+/* L49:        <jpl\0> */
+/* L50:        <jmi\0> */
+/* L51:        <jhi\0> */
+/* L52:        <jlos\0> */
+/* L53:        <jvc\0> */
+/* L54:        <jvs\0> */
+/* L55:        <jhis\0> */
+/* L56:        <jec\0> */
+/* L57:        <jcc\0> */
+/* L58:        <jlo\0> */
+/* L59:        <jcs\0> */
+/* L60:        <jes\0> */
+/* L61:        <clr\0> */
+/* L62:        <clrb\0> */
+/* L63:        <com\0> */
+/* L64:        <comb\0> */
+/* L65:        <inc\0> */
+/* L66:        <incb\0> */
+/* L67:        <dec\0> */
+/* L68:        <decb\0> */
+/* L69:        <neg\0> */
+/* L70:        <negb\0> */
+/* L71:        <adc\0> */
+/* L72:        <adcb\0> */
+/* L73:        <sbc\0> */
+/* L74:        <sbcb\0> */
+/* L75:        <tst\0> */
+/* L76:        <tstb\0> */
+/* L77:        <ror\0> */
+/* L78:        <rorb\0> */
+/* L79:        <rol\0> */
+/* L80:        <rolb\0> */
+/* L81:        <asr\0> */
+/* L82:        <asrb\0> */
+/* L83:        <asl\0> */
+/* L84:        <aslb\0> */
+/* L85:        <jmp\0> */
+/* L86:        <swab\0> */
+/* L87:        <mfpi\0> */
+/* L88:        <mtpi\0> */
+/* L89:        <mfpd\0> */
+/* L90:        <mtpd\0> */
+/* L91:        <stst\0> */
+/* L92:        <mfps\0> */
+/* L93:        <mtps\0> */
+/* L94:        <csm\0> */
+/* L95:        <tstset\0> */
+/* L96:        <wrtlck\0> */
+/* L97:        <jsr\0> */
+/* L98:        <rts\0> */
+/* L99:        <sys\0> */
+/* L102:       <spl\0> */
+/* L103:       <nop\0> */
+/* L104:       <clc\0> */
+/* L105:       <clv\0> */
+/* L106:       <clz\0> */
+/* L107:       <cln\0> */
+/* L108:       <ccc\0> */
+/* L109:       <sec\0> */
+/* L110:       <sev\0> */
+/* L111:       <sez\0> */
+/* L112:       <sen\0> */
+/* L113:       <scc\0> */
+/* L114:       <halt\0> */
+/* L115:       <wait\0> */
+/* L116:       <rti\0> */
+/* L117:       <bpt\0> */
+/* L118:       <iot\0> */
+/* L119:       <reset\0> */
+/* L120:       <rtt\0> */
+/* L121:       <mfpt\0> */
+/* L122:       <cfcc\0> */
+/* L123:       <setf\0> */
+/* L124:       <setd\0> */
+/* L125:       <seti\0> */
+/* L126:       <setl\0> */
+/* L127:       <clrf\0> */
+/* L128:       <negf\0> */
+/* L129:       <absf\0> */
+/* L130:       <tstf\0> */
+/* L131:       <movf\0> */
+/* L132:       <movif\0> */
+/* L133:       <movfi\0> */
+/* L134:       <movof\0> */
+/* L135:       <movfo\0> */
+/* L136:       <addf\0> */
+/* L137:       <subf\0> */
+/* L138:       <mulf\0> */
+/* L139:       <divf\0> */
+/* L140:       <cmpf\0> */
+/* L141:       <modf\0> */
+/* L142:       <movie\0> */
+/* L143:       <movei\0> */
+/* L144:       <ldfps\0> */
+/* L145:       <stfps\0> */
+/* L146:       <fr0\0> */
+/* L147:       <fr1\0> */
+/* L148:       <fr2\0> */
+/* L149:       <fr3\0> */
+/* L150:       <fr4\0> */
+/* L151:       <fr5\0> */
+/* L152:       <mul\0> */
+/* L153:       <div\0> */
+/* L154:       <ash\0> */
+/* L155:       <ashc\0> */
+/* L156:       <xor\0> */
+/* L157:       <sxt\0> */
+/* L158:       <mark\0> */
+/* L159:       <sob\0> */
+/* L160:       <.byte\0> */
+/* L161:       <.even\0> */
+/* L162:       <.if\0> */
+/* L163:       <.endif\0> */
+/* L164:       <.globl\0> */
+/* L165:       <.text\0> */
+/* L166:       <.data\0> */
+/* L167:       <.bss\0> */
+/* L168:       <.comm\0> */
+/*     .text */
+
+struct symbol symtab[] = {
+       { ".",          FTEXT,          0000000,        0 },
+       { "..",         FABS,           0000000,        0 },
+
+/* register */
+
+       { "r0",         FREGISTER,      0000000,        0 },
+       { "r1",         FREGISTER,      0000001,        0 },
+       { "r2",         FREGISTER,      0000002,        0 },
+       { "r3",         FREGISTER,      0000003,        0 },
+       { "r4",         FREGISTER,      0000004,        0 },
+       { "r5",         FREGISTER,      0000005,        0 },
+       { "sp",         FREGISTER,      0000006,        0 },
+       { "pc",         FREGISTER,      0000007,        0 },
+
+/* double operand */
+
+       { "mov",        FDOUBLE,        0010000,        0 },
+       { "movb",       FDOUBLE,        0110000,        0 },
+       { "cmp",        FDOUBLE,        0020000,        0 },
+       { "cmpb",       FDOUBLE,        0120000,        0 },
+       { "bit",        FDOUBLE,        0030000,        0 },
+       { "bitb",       FDOUBLE,        0130000,        0 },
+       { "bic",        FDOUBLE,        0040000,        0 },
+       { "bicb",       FDOUBLE,        0140000,        0 },
+       { "bis",        FDOUBLE,        0050000,        0 },
+       { "bisb",       FDOUBLE,        0150000,        0 },
+       { "add",        FDOUBLE,        0060000,        0 },
+       { "sub",        FDOUBLE,        0160000,        0 },
+
+/* branch */
+
+       { "br",         FBRANCH,        0000400,        0 },
+       { "bne",        FBRANCH,        0001000,        0 },
+       { "beq",        FBRANCH,        0001400,        0 },
+       { "bge",        FBRANCH,        0002000,        0 },
+       { "blt",        FBRANCH,        0002400,        0 },
+       { "bgt",        FBRANCH,        0003000,        0 },
+       { "ble",        FBRANCH,        0003400,        0 },
+       { "bpl",        FBRANCH,        0100000,        0 },
+       { "bmi",        FBRANCH,        0100400,        0 },
+       { "bhi",        FBRANCH,        0101000,        0 },
+       { "blos",       FBRANCH,        0101400,        0 },
+       { "bvc",        FBRANCH,        0102000,        0 },
+       { "bvs",        FBRANCH,        0102400,        0 },
+       { "bhis",       FBRANCH,        0103000,        0 },
+       { "bec",        FBRANCH,        0103000,        0 },
+       { "bcc",        FBRANCH,        0103000,        0 },
+       { "blo",        FBRANCH,        0103400,        0 },
+       { "bcs",        FBRANCH,        0103400,        0 },
+       { "bes",        FBRANCH,        0103400,        0 },
+
+/* jump/branch type */
+
+       { "jbr",        FJBR,           0000400,        0 },
+       { "jne",        FJCOND,         0001000,        0 },
+       { "jeq",        FJCOND,         0001400,        0 },
+       { "jge",        FJCOND,         0002000,        0 },
+       { "jlt",        FJCOND,         0002400,        0 },
+       { "jgt",        FJCOND,         0003000,        0 },
+       { "jle",        FJCOND,         0003400,        0 },
+       { "jpl",        FJCOND,         0100000,        0 },
+       { "jmi",        FJCOND,         0100400,        0 },
+       { "jhi",        FJCOND,         0101000,        0 },
+       { "jlos",       FJCOND,         0101400,        0 },
+       { "jvc",        FJCOND,         0102000,        0 },
+       { "jvs",        FJCOND,         0102400,        0 },
+       { "jhis",       FJCOND,         0103000,        0 },
+       { "jec",        FJCOND,         0103000,        0 },
+       { "jcc",        FJCOND,         0103000,        0 },
+       { "jlo",        FJCOND,         0103400,        0 },
+       { "jcs",        FJCOND,         0103400,        0 },
+       { "jes",        FJCOND,         0103400,        0 },
+
+/* single operand */
+
+       { "clr",        FSINGLE,        0005000,        0 },
+       { "clrb",       FSINGLE,        0105000,        0 },
+       { "com",        FSINGLE,        0005100,        0 },
+       { "comb",       FSINGLE,        0105100,        0 },
+       { "inc",        FSINGLE,        0005200,        0 },
+       { "incb",       FSINGLE,        0105200,        0 },
+       { "dec",        FSINGLE,        0005300,        0 },
+       { "decb",       FSINGLE,        0105300,        0 },
+       { "neg",        FSINGLE,        0005400,        0 },
+       { "negb",       FSINGLE,        0105400,        0 },
+       { "adc",        FSINGLE,        0005500,        0 },
+       { "adcb",       FSINGLE,        0105500,        0 },
+       { "sbc",        FSINGLE,        0005600,        0 },
+       { "sbcb",       FSINGLE,        0105600,        0 },
+       { "tst",        FSINGLE,        0005700,        0 },
+       { "tstb",       FSINGLE,        0105700,        0 },
+       { "ror",        FSINGLE,        0006000,        0 },
+       { "rorb",       FSINGLE,        0106000,        0 },
+       { "rol",        FSINGLE,        0006100,        0 },
+       { "rolb",       FSINGLE,        0106100,        0 },
+       { "asr",        FSINGLE,        0006200,        0 },
+       { "asrb",       FSINGLE,        0106200,        0 },
+       { "asl",        FSINGLE,        0006300,        0 },
+       { "aslb",       FSINGLE,        0106300,        0 },
+       { "jmp",        FSINGLE,        0000100,        0 },
+       { "swab",       FSINGLE,        0000300,        0 },
+       { "mfpi",       FSINGLE,        0006500,        0 },
+       { "mtpi",       FSINGLE,        0006600,        0 },
+       { "mfpd",       FSINGLE,        0106500,        0 },
+       { "mtpd",       FSINGLE,        0106600,        0 },
+       { "stst",       FSINGLE,        0170300,        0 },
+       { "mfps",       FSINGLE,        0106700,        0 },
+       { "mtps",       FSINGLE,        0106400,        0 },
+       { "csm",        FSINGLE,        0007000,        0 },
+       { "tstset",     FSINGLE,        0007200,        0 },
+       { "wrtlck",     FSINGLE,        0007300,        0 },
+
+/* jsr */
+
+       { "jsr",        FJSR,           0004000,        0 },
+
+/* rts */
+
+       { "rts",        FRTS,           0000200,        0 },
+
+/* simple operand */
+
+       { "sys",        FSYSTRAP,       0104400,        0 },
+       { "spl",        FSYSTRAP,       0000230,        0 },
+
+/* flag-setting */
+
+       { "nop",        FABS,           0000240,        0 },
+       { "clc",        FABS,           0000241,        0 },
+       { "clv",        FABS,           0000242,        0 },
+       { "clz",        FABS,           0000244,        0 },
+       { "cln",        FABS,           0000250,        0 },
+       { "ccc",        FABS,           0000257,        0 },
+       { "sec",        FABS,           0000261,        0 },
+       { "sev",        FABS,           0000262,        0 },
+       { "sez",        FABS,           0000264,        0 },
+       { "sen",        FABS,           0000270,        0 },
+       { "scc",        FABS,           0000277,        0 },
+       { "halt",       FABS,           0000000,        0 },
+       { "wait",       FABS,           0000001,        0 },
+       { "rti",        FABS,           0000002,        0 },
+       { "bpt",        FABS,           0000003,        0 },
+       { "iot",        FABS,           0000004,        0 },
+       { "reset",      FABS,           0000005,        0 },
+       { "rtt",        FABS,           0000006,        0 },
+       { "mfpt",       FABS,           0000007,        0 },
+
+/* floating point ops */
+
+       { "cfcc",       FABS,           0170000,        0 },
+       { "setf",       FABS,           0170001,        0 },
+       { "setd",       FABS,           0170011,        0 },
+       { "seti",       FABS,           0170002,        0 },
+       { "setl",       FABS,           0170012,        0 },
+       { "clrf",       FSINGLE,        0170400,        0 },
+       { "negf",       FSINGLE,        0170700,        0 },
+       { "absf",       FSINGLE,        0170600,        0 },
+       { "tstf",       FSINGLE,        0170500,        0 },
+       { "movf",       FMOVF,          0172400,        0 },
+       { "movif",      FFLOP,          0177000,        0 },
+       { "movfi",      FMOVFO,         0175400,        0 },
+       { "movof",      FFLOP,          0177400,        0 },
+       { "movfo",      FMOVFO,         0176000,        0 },
+       { "addf",       FFLOP,          0172000,        0 },
+       { "subf",       FFLOP,          0173000,        0 },
+       { "mulf",       FFLOP,          0171000,        0 },
+       { "divf",       FFLOP,          0174400,        0 },
+       { "cmpf",       FFLOP,          0173400,        0 },
+       { "modf",       FFLOP,          0171400,        0 },
+       { "movie",      FFLOP,          0176400,        0 },
+       { "movei",      FMOVFO,         0175000,        0 },
+       { "ldfps",      FSINGLE,        0170100,        0 },
+       { "stfps",      FSINGLE,        0170200,        0 },
+       { "fr0",        FREGISTER,      0000000,        0 },
+       { "fr1",        FREGISTER,      0000001,        0 },
+       { "fr2",        FREGISTER,      0000002,        0 },
+       { "fr3",        FREGISTER,      0000003,        0 },
+       { "fr4",        FREGISTER,      0000004,        0 },
+       { "fr5",        FREGISTER,      0000005,        0 },
+
+       { "mul",        FMULDIV,        0070000,        0 },
+       { "div",        FMULDIV,        0071000,        0 },
+       { "ash",        FMULDIV,        0072000,        0 },
+       { "ashc",       FMULDIV,        0073000,        0 },
+       { "xor",        FJSR,           0074000,        0 },
+       { "sxt",        FSINGLE,        0006700,        0 },
+       { "mark",       FSYSTRAP,       0006400,        0 },
+       { "sob",        FSOB,           0077000,        0 },
+
+/* pseudo ops */
+
+       { ".byte",      FDOTBYTE,       0000000,        0 },
+#if 1 /* modifications for dec syntax */
+       { ".word",      FDOTWORD,       0000000,        0 },
+#endif
+       { ".even",      FDOTEVEN,       0000000,        0 },
+       { ".if",        FDOTIF,         0000000,        0 },
+       { ".endif",     FDOTENDIF,      0000000,        0 },
+       { ".globl",     FDOTGLOBL,      0000000,        0 },
+       { ".text",      FDOTTEXT,       0000000,        0 },
+       { ".data",      FDOTDATA,       0000000,        0 },
+       { ".bss",       FDOTBSS,        0000000,        0 },
+       { ".comm",      FDOTCOMM,       0000000,        0 }
+};
+
+int ebsymtab = sizeof(symtab) / sizeof(struct symbol);
+
diff --git a/bin/as/as0.h b/bin/as/as0.h
new file mode 100644 (file)
index 0000000..85fe820
--- /dev/null
@@ -0,0 +1,244 @@
+#ifndef _AS0_H
+#define _AS0_H 1
+
+#include "krcompat.h"
+
+/* PSTENTSZ = 6. */
+/* SYMENTSZ = 8. */
+
+struct symbol {
+       char    *name;
+       int     flags;
+       int     value;
+       int     number;
+};
+
+/* User symbols and Permanent Symbol Table entries used to have the */
+/* same 12 byte format.  Merging the two phases of the assembler, moving */
+/* the symbol name characters to an externally allocated heap and */
+/* using a non-contiguous user symbol table meant that the symbol number */
+/* could no longer be calculated by subtracting the base of the symbol */
+/* table and dividing by the size of an entry.  What was done was to */
+/* expand the symbol table entry by another word and keep the symbol number */
+/* in that.  The new internal symbol structure is: */
+
+/*     char    *name; */
+/*     u_short flags; */
+/*     u_short value; */
+/*     u_short number; */
+
+/* SYMBLKSZ = 512. */
+
+#define SYMBLKSZ (512 / sizeof(struct symbol))
+
+struct symblk {
+       struct symblk *next;
+       struct symbol data[SYMBLKSZ];
+};
+
+/* STRBLKSZ = 1024. */
+
+#define STRBLKSZ 1024
+
+struct strblk {
+       struct strblk *next;
+       char data[STRBLKSZ];
+};
+
+/* hshsiz = 3001. */
+
+#define hshsiz 3001
+
+#define TABS 1
+#define TABS2 2
+#define TENDFILE 4
+#define TNEWFILE 5
+#define TNEWLINE '\n'
+#define TEQUAL '='
+#define TCOLON ':'
+#define FGLOBAL 040
+#define TSEMICOLON ';'
+#define TLABEL 0141
+#define TLSH 035
+#define TRSH 036
+#define TOR 037
+#define TSTRING '<'
+#define TCOMMA ','
+#define TLPAREN '('
+#define TMIN '-'
+#define TDOLL '$'
+#define TSTAR '*'
+#define TPLUS '+'
+#define TRPAREN ')'
+#define TSLASH '/'
+#define TAND '&'
+#define TMOD '%'
+#define TLBRACK '['
+#define TCARET '^'
+#define TNOT '!'
+#define TRBRACK ']'
+#define TASCII 0200
+
+#define FABS 1
+#define FTEXT 2
+#define FDATA 3
+#define FBSS 4
+#define FMOVFO 5
+#define FBRANCH 6
+#define FJSR 7
+#define FRTS 010
+#define FSYSTRAP 011
+#define FMOVF 012
+#define FDOUBLE 013
+#define FFLOP 014
+#define FSINGLE 015
+#define FDOTBYTE 016
+#define FSTRING 017
+#define FDOTEVEN 020
+#define FDOTIF 021
+#define FDOTENDIF 022
+#define FDOTGLOBL 023
+#define FREGISTER 024
+#define FDOTTEXT 025
+#define FDOTDATA 026
+#define FDOTBSS 027
+#define FMULDIV 030
+#define FSOB 031
+#define FDOTCOMM 032
+#define FESTTEXT 033
+#define FESTDATA 034
+#define FJBR 035
+#define FJCOND 036
+#if 1 /* modifications for dec syntax */
+#define FDOTWORD 037
+#endif
+
+extern char Newsym;
+extern struct symbol *pdot;
+extern struct symbol *pdotdot;
+extern intptr_t numbertoken;
+extern int numbervalue;
+extern int indirect;
+extern int optoken; /* (sp) */
+extern int rightflags; /* r0 */
+extern int rightvalue; /* r1 */
+extern int leftvalue; /* r2 */
+extern int leftflags; /* r3 */
+extern intptr_t token; /* r4 */
+extern char chartab[TASCII];
+extern char a_tmp1[];
+extern char Ncps;
+extern char *dash;
+extern int fin;
+extern int fout;
+extern intptr_t curfb[10];
+extern intptr_t nxtfb[10];
+extern int curfbr[10];
+extern int savdot[3];
+extern struct symbol **hshtab;
+extern int ch;
+extern int symnum;
+extern char symbol[33];
+extern char inbuf[1024];
+extern int line;
+extern int ifflg;
+extern int nargs;
+extern char **curarg;
+extern int opfound;
+extern int savop;
+extern int numval;
+extern int fbtblsz;
+extern int fbfree;
+extern struct symbol *fbptr;
+extern struct symbol *fbtbl;
+extern struct symblk *usymtab;
+extern int symleft;
+extern struct symbol *symend;
+extern struct symblk *symblk;
+extern int strleft;
+extern char *strend;
+extern struct strblk *strblk;
+extern struct symbol symtab[];
+extern int ebsymtab;
+
+int main PARAMS((int argc, char **argv));
+int oops PARAMS((void));
+void nomem PARAMS((void));
+void error PARAMS((int code));
+void p0putw PARAMS((int word));
+void pass0 PARAMS((void));
+int fbcheck PARAMS((int label));
+void growfb PARAMS((void));
+void rname PARAMS((void));
+struct symbol *isroom PARAMS((struct symbol *psymbol));
+char *astring PARAMS((int len));
+int number PARAMS((void));
+int rch PARAMS((void));
+void p0readop PARAMS((void));
+void escp PARAMS((void));
+void fixor PARAMS((void));
+void retread PARAMS((int c));
+void rdname PARAMS((int c));
+void rdnum PARAMS((void));
+void squote PARAMS((void));
+void dquote PARAMS((void));
+void retnum PARAMS((int value));
+void skip PARAMS((void));
+void garb PARAMS((void));
+void string PARAMS((void));
+int rsch PARAMS((void));
+void p0xpr PARAMS((void));
+void p0opline PARAMS((void));
+void p0opl35 PARAMS((void));
+void p0opl36 PARAMS((void));
+void relative PARAMS((int size));
+void p0opl13 PARAMS((void));
+void p0opl7 PARAMS((void));
+void p0opl15 PARAMS((void));
+void p0opl31 PARAMS((void));
+void p0opl6 PARAMS((void));
+void p0opl10 PARAMS((void));
+void p0opl11 PARAMS((void));
+void p0opl16 PARAMS((void));
+#if 1 /* modifications for dec syntax */
+void p0opldotword PARAMS((void));
+#endif
+void p0opl17 PARAMS((void));
+void p0opl20 PARAMS((void));
+void p0opl21 PARAMS((void));
+void p0opl22 PARAMS((void));
+void p0opl23 PARAMS((void));
+void p0opl25 PARAMS((void));
+void p0opl26 PARAMS((void));
+void p0opl27 PARAMS((void));
+void p0opl32 PARAMS((void));
+void p0addres PARAMS((void));
+void p0getx PARAMS((void));
+void p0alp PARAMS((void));
+void p0amin PARAMS((void));
+void p0adoll PARAMS((void));
+void p0astar PARAMS((void));
+void errora PARAMS((void));
+void p0checkreg PARAMS((void));
+void errore PARAMS((void));
+void p0checkrp PARAMS((void));
+void p0expres PARAMS((void));
+void p0binop PARAMS((void));
+void p0exnum PARAMS((void));
+void p0brack PARAMS((void));
+void p0oprand PARAMS((void));
+void p0excmbin PARAMS((void));
+void p0exrsh PARAMS((void));
+void p0exlsh PARAMS((void));
+void p0exmod PARAMS((void));
+void p0exadd PARAMS((void));
+void p0exsub PARAMS((void));
+void p0exand PARAMS((void));
+void p0exor PARAMS((void));
+void p0exmul PARAMS((void));
+void p0exdiv PARAMS((void));
+void p0exnot PARAMS((void));
+void p0eoprnd PARAMS((void));
+void p0combin PARAMS((int minflag));
+
+#endif
similarity index 100%
rename from bin/as/as0.s
rename to bin/as/as0_old.s
diff --git a/bin/as/as2.c b/bin/as/as2.c
new file mode 100644 (file)
index 0000000..51d4a93
--- /dev/null
@@ -0,0 +1,3705 @@
+/* as2.c */
+
+#include <stdio.h> /* temp */
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef PDP11
+typedef int intptr_t;
+#include <sys/file.h>
+#define SEEK_SET L_SET
+#endif
+#include "as0.h"
+#include "as2.h"
+
+/* Sept 10, 1997 - fix coredump caused by using wrong error reporting */
+/*     calling convention in three places. */
+
+/*     .globl  _signal, _close, _lseek, _unlink, _umask, _chmod, __exit */
+/*     .globl  _write, _read, _brk, _end, _open, _realloc, _fchmod */
+/*     .globl  pass1, hshsiz, outmod, dot, dotdot, error */
+/*     .globl  checkeos, curfb, savdot, ch, line, savop, inbuf, errflg */
+/*     .globl  fbptr, fbtbl, symnum, hshtab, symblk, symleft, dotrel */
+/*     .globl  symtab, aexit, overlaid, defund, a.outp, passno, filerr */
+/*     .globl  wrterr, argb, curfb, nxtfb, usymtab */
+/*     .globl  fin, fout, a.tmp1, ibufc, ibufp, obufp, outbuf, symbol */
+/*     .globl  PSTENTSZ, SYMENTSZ, SYMBLKSZ, Newsym */
+
+intptr_t *adrptr; /* r5 */
+int opcode; /* (sp) or 2(sp) if rvalue is present */
+int rvalue; /* (sp) */
+#ifdef LISTING
+FILE *argfp;
+#endif
+
+/* pass1: */
+/*     mov     fout,fin                / tmp file is now input file */
+/*     mov     $666,-(sp)              / mode */
+/*     mov     $3001 ,-(sp)            / O_WRONLY|O_CREAT|O_TRUNC */
+/*     mov     a.outp,-(sp)            / filename */
+/*     jsr     pc,_open */
+/*     add     $6,sp */
+/*     mov     r0,fout                 / file descriptor any good? */
+/*     bpl     1f                      / yes - br */
+/*     mov     a.outp,-(sp) */
+/*     jsr     pc,filerr */
+/* 1: */
+
+void pass1() {
+       int symtot;
+       struct symbol *psymbol;
+       struct symbol **ppsymbol;
+       int flags;
+
+       fin = fout;
+       fout = open(a_outp, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+       if (fout < 0)
+               filerr(a_outp);
+
+/* 'symnum' has number of symbols.  The hashtable from pass 0 is no */
+/* longer needed - we can reuse it directly for 'usymtab' if there are less  */
+/* than 'hshsiz' symbols.  If there are more than 'hshsiz' (currently */
+/* 1500) symbols we have to realloc. */
+
+/* The 'fb' table (usually 0 long) is appended to the 'usymtab' (4 byte */
+/* entries per symbol). */
+
+/*     mov     fbptr,r0 */
+/*     sub     fbtbl,r0                / # bytes in 'fb' table */
+/*     asr     r0                      / convert to number of words */
+/*     add     symnum,r0               / add in number of symbols twice */
+/*     add     symnum,r0               / because we need 2 words per symbol */
+/*     inc     r0                      / one more for terminator word */
+
+       symtot = (fbptr - fbtbl) + symnum + 1;
+
+/*     cmp     r0,$hshsiz              / is hashtable big enough already? */
+/*     blo     1f                      / yes -br */
+/*     asl     r0                      / convert to bytes */
+/*     mov     r0,-(sp) */
+/*     mov     hshtab,-(sp) */
+/*     jsr     pc,_realloc             / hshtab = realloc(hshtab, r0) */
+/*     mov     r0,hshtab */
+/*     bne     1f */
+/*     iot                             / should never happen */
+/* 1: */
+
+       if (symtot > hshsiz) {
+               hshtab = realloc(hshtab, symtot * sizeof(struct symbol *));
+               if (hshtab == NULL)
+                       nomem();
+       }
+
+/*     mov     hshtab,r1 */
+/*     mov     usymtab,r2 */
+/* 9: */
+/*     mov     r2,symblk               / save ptr to start of block */
+/*     tst     (r2)+                   / skip link word */
+/*     mov     $SYMBLKSZ,symleft       / init amount left in block */
+
+       ppsymbol = hshtab;
+       symblk = usymtab;
+       do {
+               psymbol = symblk->data;
+               symleft = SYMBLKSZ;
+
+/* 1: */
+/*     tst     (r2)                    / end of symbol table block */
+/*     beq     4f                      / yes - br */
+/*     add     $8.,symsiz              / size of symbol table */
+/*     tst     Newsym                  / are we doing new style? */
+/*     bne     8f                      / yes - br */
+/*     add     $4,symsiz               / no, symbol table entries are bigger */
+/* 8: */
+
+               do {
+                       if (psymbol->name == NULL)
+                               break;
+/* printf("%s\n", psymbol->name); */
+                       siz[3] += Newsym ? 8 : 12;
+
+/*     mov     2(r2),r0                / flags word */
+/*     bic     $!37,r0 */
+/*     cmp     r0,$2                   /text */
+/*     blo     2f */
+/*     cmp     r0,$3                   /data */
+/*     bhi     2f */
+/*     add     $31,r0                  /mark "estimated" */
+/*     mov     r0,(r1)+                / store flags word */
+/*     mov     4(r2),(r1)+             / copy value word */
+/*     br      3f */
+/* 2: */
+/*     clr     (r1)+ */
+/*     clr     (r1)+ */
+/* 3: */
+
+                       flags = psymbol->flags & 037;
+                       if (flags == FTEXT || flags == FDATA)
+                               psymbol->flags = flags + FESTTEXT - FTEXT;
+                       else {
+                               psymbol->flags = 0;
+                               psymbol->value = 0;
+                       }
+
+/*     add     $SYMENTSZ,r2            / skip to next symbol entry */
+/*     sub     $SYMENTSZ,symleft       / one symbol less in block */
+/*     cmp     symleft,$SYMENTSZ       / room for another symbol? */
+/*     bge     1b                      / yes - br */
+
+/* printf("0x%08x 0x%08x\n", (ppsymbol - hshtab), psymbol->number); */
+                       *ppsymbol++ = psymbol++;
+                       symleft--;
+               } while (symleft);
+
+/* 4: */
+/*     mov     *symblk,r2              / follow link to next block */
+/*     bne     9b                      / if not at end */
+/* 1: */
+
+               symblk = symblk->next;
+       } while (symblk);
+
+/* The 'fb' table needs to be appended to the 'usymtab' table now */
+
+/*     mov     fbtbl,r0 */
+/*     mov     r1,fbbufp               / save start of 'fb' table */
+/* 1: */
+/*     cmp     r0,fbptr                / at end of table? */
+/*     bhis    2f                      / yes - br */
+/*     mov     (r0)+,r4 */
+/*     add     $31,r4                  / "estimated" */
+/*     mov     r4,(r1)+ */
+/*     mov     (r0)+,(r1)+ */
+/*     br      1b */
+/* 2: */
+
+       psymbol = fbtbl;
+       fbbufp = ppsymbol;
+       while (psymbol < fbptr) {
+               psymbol->flags += FESTTEXT - FTEXT; /* FESTBSS ??? */
+               *ppsymbol++ = psymbol++;
+       }
+
+/*     mov     r1,endtable */
+/*     mov     $100000,(r1)+ */
+
+       endtable = ppsymbol;
+       *ppsymbol++ = NULL;
+
+/*     mov     $savdot,r0              / reset the 'psect' (text,data,bss) */
+/*     clr     (r0)+                   / counters for the next pass */
+/*     clr     (r0)+ */
+/*     clr     (r0)+ */
+/*     jsr     pc,setup                / init fb stuff */
+
+       savdot[0] = 0;
+       savdot[1] = 0;
+       savdot[2] = 0;
+       setup();
+
+/*     jsr     pc,pass1_2              / do pass 1 */
+
+       pass1_2();
+
+/* prepare for pass 2 */
+/*     inc     passno */
+/*     cmp     outmod,$777 */
+/*     beq     1f */
+/*     jsr     pc,aexit */
+/* not reached */
+/* 1: */
+
+#ifdef LISTING
+       printf("pass 2\n");
+#endif
+       passno++;
+       if (outmod != 0777)
+               aexit();
+
+/*     jsr     pc,setup */
+/*     inc     bsssiz */
+/*     bic     $1,bsssiz */
+/*     mov     txtsiz,r1 */
+/*     inc     r1 */
+/*     bic     $1,r1 */
+/*     mov     r1,txtsiz */
+/*     mov     datsiz,r2 */
+/*     inc     r2 */
+/*     bic     $1,r2 */
+/*     mov     r2,datsiz */
+
+       setup();
+       siz[0] = (siz[0] + 1) & ~1;
+       siz[1] = (siz[1] + 1) & ~1;
+       siz[2] = (siz[2] + 1) & ~1;
+
+/*     mov     r1,r3 */
+/*     mov     r3,datbase              / txtsiz */
+/*     mov     r3,savdot+2 */
+/*     add     r2,r3 */
+/*     mov     r3,bssbase              / txtsiz+datsiz */
+/*     mov     r3,savdot+4 */
+
+       base[1] = siz[0];
+       savdot[1] = base[1];
+       base[2] = base[1] + siz[1];
+       savdot[2] = base[2];
+
+/*     clr     r0 */
+/*     asl     r3 */
+/*     adc     r0 */
+/*     add     $20,r3 */
+/*     adc     r0 */
+/*     mov     r3,symseek+2            / 2*txtsiz+2*datsiz+20 */
+/*     mov     r0,symseek */
+
+       seek[6] = (off_t)base[2] * 2 + 020;
+
+/*     sub     r2,r3 */
+/*     sbc     r0 */
+/*     mov     r3,drelseek+2           / 2*txtsiz+datsiz */
+/*     mov     r0,drelseek */
+
+       seek[4] = seek[6] - siz[1];
+
+/*     sub     r1,r3 */
+/*     sbc     r0 */
+/*     mov     r3,trelseek+2           / txtsiz+datsiz+20 */
+/*     mov     r0,trelseek */
+
+       seek[3] = seek[4] - siz[0];
+
+/*     sub     r2,r3 */
+/*     sbc     r0 */
+/*     mov     r0,datseek */
+/*     mov     r3,datseek+2            / txtsiz+20 */
+
+       seek[1] = seek[3] - siz[1];
+       seek[0] = 020;
+
+/*     mov     hshtab,r1 */
+/* 1: */
+/*     jsr     pc,doreloc */
+/*     add     $4,r1 */
+/*     cmp     r1,endtable */
+/*     blo     1b */
+
+       for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++)
+               doreloc(*ppsymbol);
+
+/*     clr     r0 */
+/*     clr     r1 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,oset */
+/*     mov     trelseek,r0 */
+/*     mov     trelseek+2,r1 */
+/*     mov     $relp,-(sp) */
+/*     jsr     pc,oset */
+
+       oset(&txtp, 0L);
+       oset(&relp, seek[3]);
+
+/*     mov     $8.,r2 */
+/*     mov     $txtmagic,r1 */
+/* 1: */
+/*     mov     (r1)+,r0 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+/*     sob     r2,1b */
+
+       p1putw(&txtp, 0407);
+       p1putw(&txtp, siz[0]);
+       p1putw(&txtp, siz[1]);
+       p1putw(&txtp, siz[2]);
+       p1putw(&txtp, siz[3]);
+       p1putw(&txtp, 0);
+       p1putw(&txtp, 0);
+       p1putw(&txtp, 0);
+
+/*     jsr     pc,pass1_2                      / do pass 2 */
+
+       pass1_2();
+#ifdef LISTING
+       if (argfp)
+               fclose(argfp);
+#endif
+
+/*polish off text and relocation */
+
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,flush */
+/*     mov     $relp,-(sp) */
+/*     jsr     pc,flush */
+
+       flush(&txtp);
+       flush(&relp);
+
+/* append full symbol table */
+/*     mov     symseek,r0 */
+/*     mov     symseek+2,r1 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,oset */
+
+       oset(&txtp, seek[6]);
+
+/*     mov     usymtab,r2              / pointer to first symbol block */
+/*     mov     hshtab,r1               / 'type' and 'value' array */
+/*     tst     Newsym */
+/*     beq     8f */
+/*     jsr     pc,nsymout */
+/*     br      9f */
+/* 8: */
+/*     jsr     pc,osymout */
+/* 9: */
+
+       if (Newsym)
+               nsymout();
+       else
+               osymout();
+
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,flush */
+/*     jsr     pc,aexit */
+/* not reached */
+
+       flush(&txtp);
+       aexit();
+}
+
+/* saexit: */
+/*     mov     pc,errflg */
+
+void saexit() {
+       errflg = 3;
+       aexit();
+}
+
+/* aexit: */
+/*     mov     $a.tmp1,-(sp)           / unlink(a.tmp1) */
+/*     jsr     pc,_unlink */
+
+int aexit() {
+#if 1
+       unlink(a_tmp1);
+#endif
+
+/*     tst     errflg */
+/*     bne     2f */
+
+       if (errflg == 0) {
+
+/*     clr     (sp) */
+/*     jsr     pc,_umask */
+
+/*     bic     r0,outmod               / fchmod(fout, outmod&umask(0)) */
+/*     mov     outmod,(sp) */
+/*     mov     fout,-(sp) */
+/*     jsr     pc,_fchmod */
+/*     tst     (sp)+ */
+/*     clr     (sp) */
+/*     br      1f */
+
+               fchmod(fout, outmod & ~umask(0));
+               exit(0);
+       }
+
+/* 2: */
+/*     mov     $2,(sp) */
+/* 1: */
+/*     jsr     pc,__exit               / _exit(errflg ? 2 : 0) */
+
+       exit(2);
+}
+
+/* filerr: */
+/*     mov     2(sp),r0                / filename string.  no need to clean */
+/*     tst     -(sp)                   / stack, this routine goes to saexit. */
+/*     mov     r0,-(sp) */
+/*     mov     $1,-(sp) */
+/* 1: */
+/*     tstb    (r0)+ */
+/*     bne     1b */
+/*     sub     2(sp),r0 */
+/*     dec     r0 */
+/*     mov     r0,4(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+
+void filerr(p) char *p; {
+       write(1, p, strlen(p));
+
+/*     mov     $2,-(sp)                / write(1, "?\n", 2) */
+/*     mov     $qnl,-(sp) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+/*     tst     passno */
+/*     bpl     saexit */
+/*     rts     pc */
+
+       write(1, "?\n", 2);
+       if (passno >= 0)
+               saexit();
+}
+
+/* osymout: */
+/* 9: */
+/*     mov     r2,symblk               / save ptr to current sym block */
+/*     tst     (r2)+                   / skip link word */
+/*     mov     $SYMBLKSZ,symleft       / space left in symbol block */
+/* 1: */
+/*     mov     (r2),r4                 / pointer to symbol name */
+/*     beq     4f                      / end of block - br */
+
+void osymout() {
+       struct symbol **ppsymbol;
+       struct symbol *psymbol;
+       char *p;
+
+       for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++) {
+               psymbol = *ppsymbol;
+               p = psymbol->name;
+               if (p == NULL)
+                       break; /* reached the start of the fbtab */
+
+/*     mov     $8.,r5                  / max number to copy */
+/*     mov     $symbol,r0              / destination buffer */
+/* 2: */
+/*     movb    (r4),(r0)+              / copy a byte */
+/*     beq     6f */
+/*     inc     r4                      / non null - bump source ptr */
+/* 6: */
+/*     sob     r5,2b */
+
+               strncpy(symbol, p, 8);
+
+/* Now put four words of symbol name to the object file */
+/*     mov     $4,r5                   / number of words to do */
+/*     mov     $symbol,r4 */
+/* 6: */
+/*     mov     (r4)+,r0                / word (2 chars) of symbol name */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+/*     sob     r5,6b */
+
+               p1putw(&txtp, (symbol[0] & 0377) | ((symbol[1] & 0377) << 8));
+               p1putw(&txtp, (symbol[2] & 0377) | ((symbol[3] & 0377) << 8));
+               p1putw(&txtp, (symbol[4] & 0377) | ((symbol[5] & 0377) << 8));
+               p1putw(&txtp, (symbol[6] & 0377) | ((symbol[7] & 0377) << 8));
+
+/* values from 'hshtab' (parallel array to symbol table) are retrieved now, */
+/* they take the place of the flags and value entries of the symbol table. */
+/*     mov     (r1)+,r0 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+/*     mov     (r1)+,r0 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+
+               p1putw(&txtp, psymbol->flags);
+               p1putw(&txtp, psymbol->value);
+
+/*     add     $SYMENTSZ,r2            / skip to next symbol */
+/*     sub     $SYMENTSZ,symleft       / one less symbol in block */
+/*     cmp     symleft,$SYMENTSZ       / room for another? */
+/*     bge     1b                      / yes - br */
+/* 4: */
+/*     mov     *symblk,r2              / no, follow link to next block */
+/*     bne     9b                      / unless it's end of list */
+/*     rts     pc */
+
+       }
+}
+
+/* nsymout: */
+/*     clr     totalsz */
+/*     mov     $4,totalsz+2            / string table min size is 4 */
+
+void nsymout() {
+       struct symbol **ppsymbol;
+       struct symbol *psymbol;
+       char *p;
+
+       totalsz = 4;
+
+/* 9: */
+/*     mov     r2,symblk               / save ptr to current symbol block */
+/*     tst     (r2)+                   / skip link word */
+/*     mov     $SYMBLKSZ,symleft       / amount of space left in block */
+/* 1: */
+/*     mov     (r2),r4                 / pointer to symbol's string */
+/*     beq     4f                      / end of block - br */
+
+       for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++) {
+               psymbol = *ppsymbol;
+               p = psymbol->name;
+               if (p == NULL)
+                       break; /* reached the start of the fbtab */
+
+/*     mov     totalsz,r0              / now output the... */
+/*     mov     $txtp,-(sp)             / high order of the string index... */
+/*     jsr     pc,putw                 / to the object file */
+/*     mov     totalsz+2,r0 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw                 / and the low order word */
+/* 2: */
+/*     tstb    (r4)+                   / find the end of the string */
+/*     bne     2b */
+/*     sub     (r2),r4                 / compute length including the null */
+/*     add     r4,totalsz+2            / offset of next string */
+/*     adc     totalsz */
+
+               p1putw(&txtp, (int)(totalsz >> 16) & 0177777);
+               p1putw(&txtp, (int)totalsz & 0177777);
+               totalsz += strlen(p) + 1;
+
+/*     mov     (r1)+,r0                / 'type' word of symbol */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+/*     mov     (r1)+,r0                / 'value' word of symbol */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+
+               p1putw(&txtp, psymbol->flags);
+               p1putw(&txtp, psymbol->value);
+
+/*     add     $SYMENTSZ,r2            / advance to next symbol */
+/*     sub     $SYMENTSZ,symleft       / adjust amount left in symbol block */
+/*     cmp     symleft,$SYMENTSZ       / is there enough for another symbol? */
+/*     bge     1b                      / yes - br */
+/* 4: */
+/*     mov     *symblk,r2              / follow link to next symbol block */
+/*     bne     9b                      / more - br */
+
+       }
+
+/*     mov     totalsz,r0              / now output the string table length */
+/*     mov     $txtp,-(sp)             / high order word first */
+/*     jsr     pc,putw */
+/*     mov     totalsz+2,r0            / followed by the low order */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+
+       p1putw(&txtp, (int)(totalsz >> 16) & 0177777);
+       p1putw(&txtp, (int)totalsz & 0177777);
+
+/* Now write the strings out */
+
+/*     mov     usymtab,r2              / start at beginning of symbols */
+/* 9: */
+/*     mov     r2,symblk               / save pointer to current block */
+/*     tst     (r2)+                   / skip link word */
+/*     mov     $SYMBLKSZ,symleft       / amount left in block */
+/* 1: */
+/*     mov     (r2),r4                 / pointer to symbol's string */
+/*     beq     4f                      / at end of block - br */
+
+       for (ppsymbol = hshtab; ppsymbol < endtable; ppsymbol++) {
+               psymbol = *ppsymbol;
+               p = psymbol->name;
+               if (p == NULL)
+                       break; /* reached the start of the fbtab */
+
+/*     jsr     pc,putstring            / write out the string */
+
+               putstring(p);
+
+/*     add     $SYMENTSZ,r2            / advance to next symbol */
+/*     sub     $SYMENTSZ,symleft       / adjust amount left in block */
+/*     cmp     symleft,$SYMENTSZ       / enough for another symbol? */
+/*     bge     1b                      / yes - br */
+/* 4: */
+/*     mov     *symblk,r2              / move to next block of symbols */
+/*     bne     9b                      / any left - br */
+
+       }
+
+/* probably not necessary but let us leave the file size on an even */
+/* byte boundary. */
+
+/*     bit     $1,totalsz+2            / odd number of bytes in string table? */
+/*     beq     5f                      / no - br */
+/*     mov     symblk,r4               / we know 'symblk' points to a null */
+/*     jsr     pc,putstring            / output a single null */
+/* 5: */
+/*     rts     pc */
+
+       if (totalsz & 1) {
+               putstring("");
+       }
+}
+
+/* R4 has the address of a null terminated string to write to the output */
+/* file.  The terminating null is included in the output.  This routine */
+/* "inlines" the 'txtp seek structure' manipulation because the 'putw' */
+/* routine was 1) not suitable to byte output and 2) symbol strings are */
+/* only written using the 'txtp' (as opposed to 'relp' - relocation info) */
+/* structure. */
+
+/* putstring: */
+
+void putstring(p) char *p; {
+       while (1) {
+
+/*     cmp     txtp,txtp+2             / room for another byte? */
+/*     bhis    1f                      / no - br */
+/* 3: */
+/*     movb    (r4),*txtp              / put byte in buffer */
+/*     inc     txtp                    / advance output position */
+/*     tstb    (r4)+                   / did we just do the null? */
+/*     bne     putstring               / no - go again */
+/*     rts     pc                      / yes - we're done, return */
+
+               while (txtp.append < txtp.limit) {
+                       *txtp.append++ = *p;
+                       if (*p++ == 0)
+                               return;
+               }
+
+/* 1: */
+/*     mov     r2,-(sp)                / save r2 from being destroyed */
+/*     mov     $txtp,-(sp)             / flush buffered output and... */
+/*     jsr     pc,flush                / reset the pointers */
+/*     mov     (sp)+,r2                / restore symbol pointer */
+/*     br      3b                      / go output a byte */
+
+               flush(&txtp);
+       }
+}
+
+/* doreloc: */
+/*     movb    (r1),r0 */
+/*     bne     1f */
+/*     bisb    defund,(r1) */
+/* 1: */
+
+void doreloc(psymbol) struct symbol *psymbol; {
+       int flags;
+
+       flags = psymbol->flags;
+       if (flags == 0)
+               psymbol->flags = defund;
+
+/*     bic     $!37,r0 */
+/*     cmp     r0,$5 */
+/*     bhis    1f */
+/*     cmp     r0,$3 */
+/*     blo     1f */
+/*     beq     2f */
+
+       flags &= 037;
+       switch (flags) {
+
+/*     add     bssbase,2(r1) */
+/*     rts     pc */
+
+       case FBSS:
+               psymbol->value += base[2];
+               break;
+
+/* 2: */
+/*     add     datbase,2(r1) */
+/* 1: */
+/*     rts     pc */
+
+       case FDATA:
+               psymbol->value += base[1];
+               break;
+       }
+}
+
+/* setup: */
+/*     clr     dot */
+/*     mov     $2,dotrel */
+/*     mov     $..,dotdot */
+/*     clr     brtabp */
+
+void setup() {
+       int label;
+
+       pdot->value = 0;
+       pdot->flags = FTEXT;
+       pdotdot->value = 0;
+       brtabp = 0;
+
+/*     mov     $curfb,r4 */
+/* 1: */
+/*     clr     (r4)+ */
+/*     cmp     r4,$curfb+40. */
+/*     blo     1b */
+
+       memset(curfb, 0, 10 * sizeof(intptr_t));
+       memset(nxtfb, 0, 10 * sizeof(intptr_t));
+
+/*     clr     r4 */
+/* 1: */
+/*     jsr     pc,fbadv */
+/*     inc     r4 */
+/*     cmp     r4,$10. */
+/*     blt     1b */
+
+       for (label = 0; label < 10; label++)
+               fbadv(label);
+
+/* just rewind /tmp/atm1xx rather than close and re-open */
+/*     clr     -(sp) */
+/*     clr     -(sp) */
+/*     clr     -(sp) */
+/*     mov     fin,-(sp) */
+/*     jsr     pc,_lseek               / lseek(fin, 0L, 0) */
+/*     add     $8.,sp */
+
+       lseek(fin, 0L, SEEK_SET);
+
+/*     clr     ibufc */
+/*     rts     pc */
+
+       ibufc = 0;
+}
+
+/* outw: */
+/*     cmp     dot-2,$4 */
+/*     beq     9f */
+
+void outw(value, flags) int value; int flags; {
+       int relocate;
+
+#ifdef LISTING
+       if (passno)
+               printf("0%06o: 0%06o (0%06o)\n", pdot->value, value & 0177777,
+                               flags);
+#endif
+       if (pdot->flags != FBSS) {
+
+/*     bit     $1,dot */
+/*     bne     1f */
+
+               if ((pdot->value & 1) == 0) {
+
+/*     add     $2,dot */
+/*     tst     passno */
+/*     beq     8f */
+
+                       pdot->value += 2;
+                       if (passno == 0)
+                               return;
+
+/*     clr     -(sp) */
+/*     rol     r3 */
+/*     adc     (sp) */
+/*     asr     r3                      / get relative pc bit */
+/*     cmp     r3,$40 */
+/*     bne     2f */
+
+                       relocate = (flags >> 15) & 1;
+                       flags &= 077777;
+                       if (flags == FGLOBAL) {
+
+/* external references */
+/*     mov     $666,outmod             / make nonexecutable */
+/*     mov     xsymbol,r3 */
+/*     sub     hshtab,r3 */
+/*     asl     r3 */
+/*     bis     $4,r3                   / external relocation */
+/*     br      3f */
+/* 2: */
+
+                               outmod = 0666;
+                               flags = (xsymbol->number << 3) | 4;
+                       }
+
+/*     bic     $40,r3                  / clear any ext bits */
+/*     cmp     r3,$5 */
+/*     blo     4f */
+/*     cmp     r3,$33                  / est. text, data */
+/*     beq     6f */
+/*     cmp     r3,$34 */
+/*     bne     7f */
+/* 6: */
+/*     mov     $'r,-(sp) */
+/*     jsr     pc,error */
+/* 7: */
+/*     mov     $1,r3                   / make absolute */
+/* 4: */
+
+                       else {
+                               flags &= ~FGLOBAL;
+                               if (flags > FBSS) {
+                                       if (flags == FESTTEXT ||
+                                                       flags == FESTDATA)
+                                               error('r');
+                                       flags = FABS;
+                               }
+
+/*     cmp     r3,$2 */
+/*     blo     5f */
+/*     cmp     r3,$4 */
+/*     bhi     5f */
+/*     tst     (sp) */
+/*     bne     4f */
+/*     add     dotdot,r2 */
+/*     br      4f */
+/* 5: */
+
+                               if (flags >= FTEXT && flags <= FBSS) {
+                                       if (!relocate)
+                                               value += pdotdot->value;
+                               }
+
+/*     tst     (sp) */
+/*     beq     4f */
+/*     sub     dotdot,r2 */
+/* 4: */
+
+                               else {
+                                       if (relocate)
+                                               value -= pdotdot->value;
+                               }
+
+/*     dec     r3 */
+/*     bpl     3f */
+/*     clr     r3 */
+
+                               if (flags)
+                                       flags--;
+                       }
+
+/* 3: */
+/*     asl     r3 */
+/*     bis     (sp)+,r3 */
+
+                       flags = (flags << 1) | relocate;
+
+/*     mov     r2,r0 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+/*     mov     tseekp,r0 */
+/*     add     $2,2(r0) */
+/*     adc     (r0) */
+
+                       p1putw(&txtp, value);
+                       *tseekp += 2;
+
+/*     mov     r3,r0 */
+/*     mov     $relp,-(sp) */
+/*     jsr     pc,putw */
+/*     mov     rseekp,r0 */
+/*     add     $2,2(r0) */
+/*     adc     (r0) */
+
+                       p1putw(&relp, flags);
+                       *rseekp += 2;
+
+/* 8: */
+/*     rts     pc */
+
+               }
+
+/* 1: */
+/*     mov     $'o,-(sp) */
+/*     jsr     pc,error */
+/*     clr     r3 */
+/*     jsr     pc,outb */
+/*     rts     pc */
+
+               else {
+                       error('o');
+                       outb(value, 0);
+               }
+
+/* 9: */
+/*     mov     $'x,-(sp) */
+/*     jsr     pc,error */
+/*     rts     pc */
+
+       }
+       else
+               error('x');
+}
+
+/* outb: */
+/*     cmp     dot-2,$4                / test bss mode */
+/*     beq     9b */
+
+void outb(value, flags) int value; int flags; {
+#ifdef LISTING
+       if (passno)
+               printf("0%06o:    0%03o (0%06o)\n", pdot->value, value & 0377,
+                               flags);
+#endif
+       if (pdot->flags == FBSS) {
+               error('x');
+               return;
+ /* bug!! didn't increment dot's value */
+       }
+
+/*     cmp     r3,$1 */
+/*     blos    1f */
+/*     mov     $'r,-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+
+       if (flags > FABS)
+               error('r');
+
+/*     tst     passno */
+/*     beq     2f */
+
+       if (passno) {
+
+/*     mov     r2,r0 */
+/*     bit     $1,dot */
+/*     bne     1f */
+
+               if ((pdot->value & 1) == 0) {
+
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,putw */
+/*     clr     r0 */
+/*     mov     $relp,-(sp) */
+/*     jsr     pc,putw */
+
+                       p1putw(&txtp, value);
+                       p1putw(&relp, 0);
+
+/*     mov     tseekp,r0 */
+/*     add     $2,2(r0) */
+/*     adc     (r0) */
+/*     mov     rseekp,r0 */
+/*     add     $2,2(r0) */
+/*     adc     (r0) */
+/*     br      2f */
+
+                       *tseekp += 2;
+                       *rseekp += 2;
+               }
+
+/* 1: */
+/*     mov     txtp,r0 */
+/*     movb    r2,-1(r0) */
+
+               else
+                       *(txtp.append - 1) = (char)value;
+       }
+
+/* 2: */
+/*     inc     dot */
+/*     rts     pc */
+
+       pdot->value++;
+}
+
+/* pass 1 and 2 common code */
+
+/* pass1_2: */
+/*     jsr     pc,readop */
+/*     cmp     r4,$5 */
+/*     beq     2f */
+/*     cmp     r4,$'< */
+/*     beq     2f */
+/*     jsr     pc,checkeos */
+/*             br eal1 */
+
+void pass1_2() {
+       intptr_t tokensave;
+       int flags;
+       struct symbol *psymbol;
+       int label;
+#ifdef LISTING
+       int argch;
+#endif
+
+       while (1) {
+               readop();
+               if (token != TNEWFILE && token != TSTRING) {
+                       if (checkeos())
+                               goto eal1;
+
+/*     mov     r4,-(sp) */
+/*     cmp     (sp),$1 */
+/*     bne     1f */
+/*     mov     $2,(sp) */
+/*     jsr     pc,getw */
+/*     mov     r4,numval */
+/* 1: */
+
+                       tokensave = token;
+                       if (token == TABS) {
+                               tokensave = TABS2;
+                               p1getw();
+                               numval = token;
+                       }
+
+/*     jsr     pc,readop */
+/*     cmp     r4,$'= */
+/*     beq     4f */
+/*     cmp     r4,$': */
+/*     beq     1f */
+/*     mov     r4,savop */
+/*     mov     (sp)+,r4 */
+/* 2: */
+/*     jsr     pc,opline */
+
+                       readop();
+                       if (token == TEQUAL)
+                               goto equal;
+                       if (token == TCOLON)
+                               goto colon;
+                       savop = token;
+                       token = tokensave;
+               }
+               opline();
+
+/* dotmax: */
+/*     tst     passno */
+/*     bne     eal1 */
+/*     movb    dotrel,r0 */
+/*     asl     r0 */
+/*     cmp     dot,txtsiz-4(r0) */
+/*     bhi     8f */
+/*     jmp     ealoop */
+/* 8: */
+/*     mov     dot,txtsiz-4(r0) */
+/* eal1: */
+/*     jmp     ealoop */
+
+       dotmax:
+               if (passno == 0) {
+                       flags = pdot->flags - FTEXT;
+                       if (siz[flags] < pdot->value)
+                               siz[flags] = pdot->value;
+               }
+       eal1:
+               goto ealoop;
+
+/* 1: */
+/*     mov     (sp)+,r4 */
+/*     cmp     r4,$200 */
+/*     bhis    1f */
+/*     cmp     r4,$2 */
+/*     beq     3f */
+/*     mov     $'x,-(sp) */
+/*     jsr     pc,error */
+/*     br      pass1_2 */
+/* 1: */
+
+       colon:
+               if (tokensave >= 0 && tokensave < TASCII) {
+                       if (tokensave != TABS2) {
+                               error('x');
+                               continue;
+                       }
+                       goto digit;
+               }
+
+/*     tst     passno */
+/*     bne     2f */
+/*     movb    (r4),r0 */
+/*     bic     $!37,r0 */
+/*     beq     5f */
+/*     cmp     r0,$33 */
+/*     blt     6f */
+/*     cmp     r0,$34 */
+/*     ble     5f */
+/* 6: */
+/*     mov     $'m,-(sp) */
+/*     jsr     pc,error */
+/* 5: */
+
+               psymbol = (struct symbol *)tokensave;
+               if (passno == 0) {
+                       flags = psymbol->flags & 037;
+                       if (flags && (flags < FESTTEXT || flags > FESTDATA))
+                               error('m');
+
+/*     bic     $37,(r4) */
+/*     bis     dotrel,(r4) */
+/*     mov     2(r4),brdelt */
+/*     sub     dot,brdelt */
+/*     mov     dot,2(r4) */
+/*     br      pass1_2 */
+
+                       psymbol->flags = (psymbol->flags & ~037) | pdot->flags;
+                       brdelt = psymbol->value - pdot->value;
+                       psymbol->value = pdot->value;
+                       continue;
+               }
+
+/* 2: */
+/*     cmp     dot,2(r4) */
+/*     beq     pass1_2 */
+/*     mov     $'p,-(sp) */
+/*     jsr     pc,error */
+/*     br      pass1_2 */
+
+               if (psymbol->value != pdot->value)
+                       error('p');
+#ifdef LISTING
+               printf("0%06o: %s\n", psymbol->value & 0177777, psymbol->name);
+#endif
+               continue;
+
+/* 3: */
+/*     mov     numval,r4 */
+/*     jsr     pc,fbadv */
+/*     asl     r4 */
+/*     mov     curfb(r4),r0 */
+/*     movb    dotrel,(r0) */
+/*     mov     2(r0),brdelt */
+/*     sub     dot,brdelt */
+/*     mov     dot,2(r0) */
+/*     br      pass1_2 */
+
+       digit:
+               label = numval;
+               fbadv(label);
+               psymbol = *(struct symbol **)curfb[label];
+               psymbol->flags = pdot->flags;
+               brdelt = psymbol->value - pdot->value;
+               psymbol->value = pdot->value;
+#ifdef LISTING
+               if (passno)
+                       printf("0%06o: %d\n", psymbol->value & 0177777, label);
+#endif
+               continue;
+
+/* 4: */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres */
+/*     mov     (sp)+,r1 */
+/*     cmp     r1,$dotrel              /test for dot */
+/*     bne     1f */
+/*     bic     $40,r3 */
+/*     cmp     r3,dotrel               / can't change relocation */
+/*     bne     2f */
+
+       equal:
+               readop();
+               expres();
+               psymbol = (struct symbol *)tokensave;
+               if (psymbol == pdot) {
+                       leftflags &= ~FGLOBAL;
+/* printf("leftflags 0%o pdot->flags 0%o\n", leftflags, pdot->flags); */
+                       if (leftflags != pdot->flags)
+                               goto doterr;
+
+/*     cmp     r3,$4                   / bss */
+/*     bne     3f */
+/*     mov     r2,dot */
+/*     br      dotmax */
+/* 3: */
+
+                       if (leftflags == FBSS) {
+                               pdot->value = leftvalue;
+#ifdef LISTING
+                       if (passno)
+                               printf("0%06o: .\n", pdot->value & 0177777);
+#endif
+                               goto dotmax;
+                       }
+
+/*     sub     dot,r2 */
+/*     bmi     2f */
+/*     mov     r2,-(sp) */
+/* 3: */
+/*     dec     (sp) */
+/*     bmi     3f */
+/*     clr     r2 */
+/*     mov     $1,r3 */
+/*     jsr     pc,outb */
+/*     br      3b */
+/* 3: */
+/*     tst     (sp)+ */
+/*     br      dotmax */
+
+                       leftvalue -= pdot->value;
+                       if (leftvalue < 0)
+                               goto doterr;
+                       while (leftvalue) {
+                               leftvalue--;
+                               outb(0, FABS);
+                       }
+                       goto dotmax;
+
+/* 2: */
+/*     mov     $'.,-(sp) */
+/*     jsr     pc,error */
+/*     br      ealoop */
+/* 1: */
+
+               doterr:
+                       error('.');
+                       goto ealoop;
+               }
+
+/*     cmp     r3,$40 */
+/*     bne     1f */
+/*     mov     $'r,-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+
+               if (leftflags == FGLOBAL)
+                       error('r');
+
+/*     bic     $37,(r1) */
+/*     bic     $!37,r3 */
+/*     bne     1f */
+/*     clr     r2 */
+/* 1: */
+
+               psymbol->flags &= ~037;
+               leftflags &= 037;
+               if (leftflags == 0)
+                       leftvalue = 0;
+
+/*     bisb    r3,(r1) */
+/*     mov     r2,2(r1) */
+
+               psymbol->flags |= leftflags;
+               psymbol->value = leftvalue;
+#ifdef LISTING
+               if (passno)
+                       printf("0%06o: %s\n", psymbol->value & 0177777,
+                                       psymbol->name);
+#endif
+
+/* ealoop: */
+/*     cmp     r4,$'\n */
+/*     beq     1f */
+/*     cmp     r4,$'\e */
+/*     bne     9f */
+/*     rts     pc */
+/* 1: */
+/*     inc     line */
+/* 9: */
+/*     jmp     pass1_2 */
+
+       ealoop:
+/* printf("ealoop token = 0x%08x\n", token); */
+               if (token == TNEWLINE) {
+                       line++;
+#ifdef LISTING
+                       if (argfp)
+                               while ((argch = getc(argfp)) != EOF) {
+                                       putchar(argch);
+                                       if (argch == '\n')
+                                               break;
+                               }
+#endif
+               }
+               else if (token == TENDFILE)
+                       break;
+       }
+}
+
+/* checkeos: */
+/*     cmp     r4,$'\n */
+/*     beq     1f */
+/*     cmp     r4,$'; */
+/*     beq     1f */
+/*     cmp     r4,$'\e */
+/*     beq     1f */
+/*     add     $2,(sp) */
+/* 1: */
+/*     rts     pc */
+
+int checkeos() {
+       return token == TNEWLINE || token == TSEMICOLON || token == TENDFILE;
+}
+
+/* fbadv: */
+/*     asl     r4 */
+/*     mov     nxtfb(r4),r1 */
+/*     mov     r1,curfb(r4) */
+/*     bne     1f */
+/*     mov     fbbufp,r1 */
+/*     br      2f */
+/* 1: */
+/*     add     $4,r1 */
+
+void fbadv(label) int label; {
+       struct symbol **ppsymbol;
+       struct symbol *psymbol;
+
+       ppsymbol = (struct symbol **)nxtfb[label];
+       curfb[label] = (intptr_t)ppsymbol;
+       if (ppsymbol == NULL) {
+               ppsymbol = fbbufp;
+               goto entry;
+       }
+       do {
+               ppsymbol++;
+
+/* 2: */
+/*     cmpb    1(r1),r4 */
+/*     beq     1f */
+/*     tst     (r1) */
+/*     bpl     1b */
+/* 1: */
+
+       entry:
+               psymbol = *ppsymbol;
+       } while (psymbol && psymbol->number != label);
+
+/*     mov     r1,nxtfb(r4) */
+/*     asr     r4 */
+/*     rts     pc */
+
+       nxtfb[label] = (intptr_t)ppsymbol;
+}
+
+/* oset: */
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+/*     mov     6(sp),r3 */
+/*     mov     r1,r2 */
+/*     bic     $!1777,r1 */
+/*     add     r3,r1 */
+/*     add     $8,r1 */
+/*     mov     r1,(r3)+                / next slot */
+
+void oset(pstream, offset) struct stream *pstream; off_t offset; {
+       pstream->append = pstream->data + ((int)offset & 01777);
+
+/*     mov     r3,r1 */
+/*     add     $2006,r1 */
+/*     mov     r1,(r3)+                / buf max */
+
+       pstream->limit = pstream->data + 02000;
+
+/*     mov     r0,(r3)+ */
+/*     mov     r2,(r3)+                / seek addr */
+
+       pstream->offset = offset;
+
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+/*     mov     (sp)+,(sp) */
+/*     rts     pc */
+
+}
+
+/* putw: */
+/*     mov     r1,-(sp) */
+/*     mov     r2,-(sp) */
+/*     mov     6(sp),r2 */
+/*     mov     (r2)+,r1                / slot */
+/*     cmp     r1,(r2)                 / buf max */
+/*     bhis    1f */
+/*     mov     r0,(r1)+ */
+/*     mov     r1,-(r2) */
+/*     br      2f */
+/* 1: */
+/*     tst     (r2)+ */
+/*     mov     r0,-(sp) */
+/*     jsr     pc,flush1 */
+/*     mov     (sp)+,r0 */
+/*     mov     r0,*(r2)+ */
+/*     add     $2,-(r2) */
+/* 2: */
+/*     mov     (sp)+,r2 */
+/*     mov     (sp)+,r1 */
+/*     mov     (sp)+,(sp) */
+/* ret: */
+/*     rts     pc */
+
+void p1putw(pstream, word) struct stream *pstream; int word; {
+/* printf("p1putw 0x%08x 0%06o\n", pstream, word); */
+       if (pstream->append >= pstream->limit)
+ /* note!! should be pstream->limit - 1, but it never makes any difference */
+               flush(pstream);
+       *pstream->append++ = (char)word;
+       *pstream->append++ = (char)(word >> 8);
+}
+
+/* flush: */
+/*     mov     2(sp),r2 */
+/*     mov     (sp)+,(sp) */
+/*     cmp     (r2)+,(r2)+ */
+/* flush1: */
+/*     clr     -(sp)                   / lseek(fout, (r2)L+, L_SET) */
+/*     mov     2(r2),-(sp) */
+/*     mov     (r2)+,-(sp) */
+/*     tst     (r2)+ */
+/*     mov     fout,-(sp) */
+/*     jsr     pc,_lseek */
+/*     add     $8.,sp */
+
+void flush(pstream) struct stream *pstream; {
+       char *start;
+       int count;
+
+       lseek(fout, pstream->offset, SEEK_SET);
+
+/*     cmp     -(sp),-(sp)             / write(fout, <buf>, <len>) */
+/*     bic     $!1777,r1 */
+/*     add     r2,r1                   / write address */
+
+       start = pstream->data + ((int)pstream->offset & 01777);
+
+/*     mov     r1,-(sp)                / { <buf> } */
+/*     mov     r2,r0 */
+/*     bis     $1777,-(r2) */
+/*     add     $1,(r2)                 / new seek addr */
+/*     adc     -(r2) */
+/*     cmp     -(r2),-(r2) */
+
+       pstream->offset = (pstream->offset | 01777) + 1;
+
+/*     sub     (r2),r1 */
+/*     neg     r1 */
+/*     mov     r1,2(sp)                / count */
+/*     mov     r0,(r2)                 / new next slot */
+
+       count = pstream->append - start;
+       pstream->append = pstream->data;
+
+/*     mov     fout,-(sp) */
+/*     mov     r1,6(sp)                / protect r1 from library */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+/*     mov     (sp)+,r1 */
+/*     tst     r0 */
+/*     bpl     ret */
+/* fall thru to wrterr */
+
+       if (write(fout, start, count) < 0)
+               wrterr();
+}
+
+/* wrterr: */
+/*     mov     $8f-9f,-(sp)            / write(1, 9f, 8f-9f) */
+/*     mov     $9f,-(sp) */
+/*     mov     $1,-(sp) */
+/*     jsr     pc,_write */
+/*     add     $6,sp */
+/*     jsr     pc,saexit */
+/* not reached */
+
+void wrterr() {
+       write(1, "as: write error\n", 16);
+       saexit();
+}
+
+/*     .data */
+/* 9: */
+/*     <as: write error\n> */
+/* 8: */
+/*     .even */
+/*     .text */
+
+/* readop: */
+/*     mov     savop,r4 */
+/*     beq     1f */
+/*     clr     savop */
+/*     rts     pc */
+/* 1: */
+
+void readop() {
+       int word;
+
+/* printf("readop() savop = 0x%08x\n", savop); */
+       if (savop) {
+               token = savop;
+               savop = 0;
+               return;
+       }
+
+/*     jsr     pc,getw1 */
+/*     cmp     r4,$200 */
+/*     blo     1f */
+/*     cmp     r4,$4000 */
+/*     blo     2f */
+/*     sub     $4000,r4 */
+/*     asl     r4 */
+/*     asl     r4 */
+/*     add     hshtab,r4 */
+/*     rts     pc */
+/* 2: */
+
+       word = getw1();
+       if (word >= 0 && word < TASCII)
+               token = word;
+       else {
+               if (word >= 04000)
+                       token = (intptr_t)hshtab[word - 04000];
+
+/* remove PST flag (1000) then multiply by PSTENTSZ.  In pass 0 the PST */
+/* symbol number was divided by PSTENTSZ(to make it fit) - we now reverse */
+/* that process. */
+/*     mov     r5,-(sp) */
+/*     mov     r4,r5 */
+/*     sub     $1000,r5 */
+/*     mul     $PSTENTSZ,r5 */
+/*     mov     r5,r4 */
+/*     mov     (sp)+,r5 */
+/*     add     $dotrel,r4              / point at dot's flag field */
+/* 1: */
+/*     rts     pc */
+
+               else
+                       token = (intptr_t)(symtab + (word - 01000));
+       }
+}
+
+/* getw: */
+/*     mov     savop,r4 */
+/*     beq     getw1 */
+/*     clr     savop */
+/*     rts     pc */
+
+void p1getw() {
+       if (savop) {
+               token = savop;
+               savop = 0;
+               return;
+       }
+       token = getw1();
+}
+
+/* getw1: */
+/*     dec     ibufc */
+/*     bgt     1f */
+
+int getw1() {
+       ibufc--;
+       if (ibufc <= 0) {
+
+/*     mov     r1,-(sp)                / protect r1 from library */
+/*     mov     $1024.,-(sp)            / read(fin, inbuf, 1024) */
+/*     mov     $inbuf,-(sp) */
+/*     mov     fin,-(sp) */
+/*     jsr     pc,_read */
+/*     add     $6,sp */
+/*     mov     (sp)+,r1 */
+
+               ibufc = read(fin, inbuf, 1024);
+               if (ibufc <= 0)
+                       return TENDFILE;
+
+/*     asr     r0 */
+/*     mov     r0,ibufc */
+/*     bgt     2f */
+/*     mov     $4,r4 */
+/*     sev */
+/*     rts     pc */
+/* 2: */
+/*     mov     $inbuf,ibufp */
+/* 1: */
+
+               ibufc /= sizeof(short);
+               ibufp = (short *)inbuf;
+ /* note!! rather silly, ibufc doesn't get decremented through this path */
+       }
+
+/*     mov     *ibufp,r4 */
+/*     add     $2,ibufp */
+/*     rts     pc */
+
+       return *ibufp++;
+}
+
+/* opline: */
+/*     mov     r4,r0 */
+/*     bmi     2f */
+/*     cmp     r0,$177 */
+/*     bgt     2f */
+/*     cmp     r4,$5 */
+/*     beq     opeof */
+/*     cmp     r4,$'< */
+/*     bne     xpr */
+/*     jmp     opl17 */
+/* xxpr: */
+/*     tst     (sp)+ */
+/* xpr: */
+/*     jsr     pc,expres */
+/*     jsr     pc,outw */
+/*     rts     pc */
+/* 2: */
+
+void xpr() {
+       expres();
+       outw(leftvalue, leftflags);
+}
+
+void opline() {
+       struct symbol *psymbol;
+       int flags;
+
+/* printf("opline() token 0x%08x\n", token); */
+       if (token >= 0 && token < TASCII) {
+               if (token == TNEWFILE)
+                       opeof();
+               else if (token == TSTRING)
+                       opl17();
+               else
+                       xpr();
+               return;
+       }
+
+/*     movb    (r4),r0 */
+/*     cmp     r0,$24                  /reg */
+/*     beq     xpr */
+/*     cmp     r0,$33                  /est text */
+/*     beq     xpr */
+/*     cmp     r0,$34                  / est data */
+/*     beq     xpr */
+/*     cmp     r0,$5 */
+/*     blt     xpr */
+/*     cmp     r0,$36 */
+/*     bgt     xpr */
+
+       psymbol = (struct symbol *)token;
+       flags = psymbol->flags;
+       if (flags <= FBSS || flags == FREGISTER || flags == FESTTEXT ||
+                       flags == FESTDATA || flags > FJCOND) {
+               xpr();
+               return;
+       }
+
+/*     mov     2(r4),-(sp) */
+/*     mov     r0,-(sp) */
+/*     jsr     pc,readop */
+/*     mov     (sp)+,r0 */
+/*     asl     r0 */
+/*     mov     $adrbuf,r5 */
+/*     clr     swapf */
+/*     mov     $-1,rlimit */
+/*     jmp     *1f-10.(r0) */
+
+       opcode = psymbol->value;
+       readop();
+       adrptr = adrbuf;
+       swapf = 0;
+       rlimit = 0177777;
+       switch (flags) {
+
+/*     .data */
+/* 1: */
+/*     opl5 */
+
+       case FMOVFO:
+               opl5();
+               return;
+
+/*     opl6 */
+
+       case FBRANCH:
+               opl6();
+               return;
+
+/*     opl7 */
+
+       case FJSR:
+               opl7();
+               return;
+
+/*     opl10 */
+
+       case FRTS:
+               opl10();
+               return;
+
+/*     opl11 */
+
+       case FSYSTRAP:
+               opl11();
+               return;
+
+/*     opl12 */
+
+       case FMOVF:
+               opl12();
+               return;
+
+/*     opl13 */
+
+       case FDOUBLE:
+               opl13();
+               return;
+
+/*     opl14 */
+
+       case FFLOP:
+               opl14();
+               return;
+
+/*     opl15 */
+
+       case FSINGLE:
+               opl15();
+               return;
+
+/*     opl16 */
+
+       case FDOTBYTE:
+               opl16();
+               return;
+
+#if 1 /* modifications for dec syntax */
+       case FDOTWORD:
+               opldotword();
+               return;
+#endif
+
+/*     opl17 */
+
+       case FSTRING:
+               opl17();
+               return;
+
+/*     opl20 */
+
+       case FDOTEVEN:
+               opl20();
+               return;
+
+/*     opl21 */
+
+       case FDOTIF:
+               opl21();
+               return;
+
+/*     opl22 */
+
+       case FDOTENDIF:
+               opl22();
+               return;
+
+/*     opl23 */
+
+       case FDOTGLOBL:
+               opl23();
+               return;
+
+/*     xxpr */
+
+       case FREGISTER: /* can never get here */
+               xpr();
+               return;
+
+/*     opl25 */
+
+       case FDOTTEXT:
+               opl25();
+               return;
+
+/*     opl26 */
+
+       case FDOTDATA:
+               opl26();
+               return;
+
+/*     opl27 */
+
+       case FDOTBSS:
+               opl27();
+               return;
+
+/*     opl30 */
+
+       case FMULDIV:
+               opl30();
+               return;
+
+/*     opl31 */
+
+       case FSOB:
+               opl31();
+               return;
+
+/*     opl32 */
+
+       case FDOTCOMM:
+               opl32();
+               return;
+
+/*     xxpr */
+/*     xxpr */
+
+       case FESTTEXT:
+       case FESTDATA:
+               xpr();
+               return;
+
+/*     opl35 */
+
+       case FJBR:
+               opl35();
+               return;
+
+/*     opl36 */
+
+       case FJCOND:
+               opl36();
+               return;
+
+/*     .text */
+
+       }
+}
+
+/* opeof: */
+/*     mov     $1,line */
+/*     mov     $20,-(sp) */
+/*     mov     $argb,r1 */
+/* 1: */
+/*     jsr     pc,getw */
+/*     tst     r4 */
+/*     bmi     1f */
+/*     movb    r4,(r1)+ */
+/*     dec     (sp) */
+/*     bgt     1b */
+/*     tstb    -(r1) */
+/*     br      1b */
+/* 1: */
+/*     movb    $'\n,(r1)+ */
+/*     clrb    (r1)+ */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opeof() {
+       int count;
+       char *p;
+#ifdef LISTING
+       int argch;
+#endif
+
+       line = 1;
+       count = 20;
+       p = argb;
+       while (1) {
+               p1getw();
+               if (token == -1)
+                       break;
+               if (count) {
+                       count--;
+                       *p++ = (char)token;
+               }
+       }
+#ifdef LISTING
+       if (passno) {
+               if (argfp)
+                       fclose(argfp);
+               *p = 0;
+               argfp = fopen(argb, "r");
+               if (argfp)
+                       while ((argch = getc(argfp)) != EOF) {
+                               putchar(argch);
+                               if (argch == '\n')
+                                       break;
+                       }
+       }
+#endif
+       *p++ = '\n';
+       *p = 0;
+}
+
+/* opl30:                                      / mul, div etc */
+/*     inc     swapf */
+/*     mov     $1000,rlimit */
+/*     br      opl13 */
+
+void opl30() {
+       swapf = 1;
+       rlimit = 01000;
+       opl13();
+}
+
+/* opl14:                                      / flop freg,fsrc */
+/*     inc     swapf */
+
+void opl14() {
+       swapf = 1;
+       opl5();
+}
+
+/* opl5:                                       / flop src,freg */
+/*     mov     $400,rlimit */
+
+void opl5() {
+       rlimit = 0400;
+       opl13();
+}
+
+/* opl13:                                      /double */
+/*     jsr     pc,addres */
+
+void opl13() {
+       addres();
+       op2a();
+}
+
+/* op2a: */
+/*     mov     r2,-(sp) */
+/*     jsr     pc,readop */
+
+void op2a() {
+       rvalue = leftvalue;
+       readop();
+       op2b();
+}
+
+/* op2b: */
+/*     jsr     pc,addres */
+/*     tst     swapf */
+/*     beq     1f */
+/*     mov     (sp),r0 */
+/*     mov     r2,(sp) */
+/*     mov     r0,r2 */
+/* 1: */
+
+void op2b() {
+       int tempvalue;
+       intptr_t *adrtmp;
+
+       addres();
+/* printf("op2b %d 0x%08x 0x%08x\n", swapf, rvalue, leftvalue); */
+       if (swapf) {
+               tempvalue = rvalue;
+               rvalue = leftvalue;
+               leftvalue = tempvalue;
+       }
+
+/*     swab    (sp) */
+/*     asr     (sp) */
+/*     asr     (sp) */
+/*     cmp     (sp),rlimit */
+/*     blo     1f */
+/*     mov     $'x,-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+
+#if 1
+ rvalue <<= 6;
+#else
+       rvalue = (rvalue & 0377) << 6; /* seems a bit stupid */
+#endif
+       if ((unsigned int)rvalue >= (unsigned int)rlimit)
+ {
+ printf("a 0x%08x 0x%08x\n", rvalue, rlimit);
+               error('x');
+ }
+
+/*     bis     (sp)+,r2 */
+/*     bis     (sp)+,r2 */
+/*     clr     r3 */
+/*     jsr     pc,outw */
+
+       outw(leftvalue | rvalue | opcode, 0);
+
+/*     mov     $adrbuf,r1 */
+/* 1: */
+/*     cmp     r1,r5 */
+/*     bhis    1f */
+/*     mov     (r1)+,r2 */
+/*     mov     (r1)+,r3 */
+/*     mov     (r1)+,xsymbol */
+/*     jsr     pc,outw */
+/*     br      1b */
+/* 1: */
+/*     rts     pc */
+
+       adrtmp = adrbuf;
+       while (adrtmp < adrptr) {
+               leftvalue = *adrtmp++;
+               leftflags = *adrtmp++;
+               xsymbol = (struct symbol *)*adrtmp++;
+               outw(leftvalue, leftflags);
+       }
+}
+
+/* opl15:                                      / single operand */
+/*     clr     -(sp) */
+/*     br      op2b */
+
+void opl15() {
+       rvalue = 0;
+       op2b();
+}
+
+/* opl12:                                      / movf */
+/*     mov     $400,rlimit */
+/*     jsr     pc,addres */
+/*     cmp     r2,$4                   / see if source is fregister */
+/*     blo     1f */
+/*     inc     swapf */
+/*     br      op2a */
+/* 1: */
+/*     mov     $174000,(sp) */
+/*     br      op2a */
+
+void opl12() {
+       rlimit = 0400;
+       addres();
+       if (leftvalue >= 4)
+               swapf = 1;
+       else
+               opcode = 0174000;
+       op2a();
+}
+
+/* opl35:                                      / jbr */
+/* opl36:                                      / jeq, jne, etc */
+/*     jsr     pc,expres */
+/*     tst     passno */
+/*     bne     1f */
+/*     mov     r2,r0 */
+/*     jsr     pc,setbr */
+/*     tst     r2 */
+/*     beq     2f */
+/*     cmp     (sp),$br */
+/*     beq     2f */
+/*     add     $2,r2 */
+/* 2: */
+/*     add     r2,dot                  / if doesn't fit */
+/*     add     $2,dot */
+/*     tst     (sp)+ */
+/*     rts     pc */
+/* 1: */
+/*     jsr     pc,getbr */
+/*     bcc     dobranch */
+/*     mov     (sp)+,r0 */
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+/*     cmp     r0,$br */
+/*     beq     2f */
+/*     mov     $402,r2 */
+/*     xor     r0,r2                   / flip cond, add ".+6" */
+/*     mov     $1,r3 */
+/*     jsr     pc,outw */
+/* 2: */
+/*     mov     $1,r3 */
+/*     mov     $jmp+37,r2 */
+/*     jsr     pc,outw */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+/*     jsr     pc,outw */
+/*     rts     pc */
+
+void opl35() {
+       expres();
+       if (passno == 0)
+               pdot->value += setbr(leftvalue) ? 4 : 2;
+       else {
+               if (getbr() == 0)
+                       dobranch();
+               else {
+                       outw(0000137, FABS); /* jmp */
+                       outw(leftvalue, leftflags);
+               }
+       }
+}
+
+void opl36() {
+       expres();
+       if (passno == 0)
+               pdot->value += setbr(leftvalue) ? 6 : 2;
+       else {
+               if (getbr() == 0)
+                       dobranch();
+               else {
+                       outw(opcode ^ 0402, FABS); /* jne, jeq, etc .+6 */
+                       outw(0000137, FABS); /* jmp */
+                       outw(leftvalue, leftflags);
+               }
+       }
+}
+
+/* opl31:                                      / sob */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkreg */
+/*     swab    r2 */
+/*     asr     r2 */
+/*     asr     r2 */
+/*     bis     r2,(sp) */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres */
+/*     tst     passno */
+/*     beq     3f */
+/*     sub     dot,r2 */
+/*     neg     r2 */
+/*     mov     r2,r0 */
+/*     cmp     r0,$-2 */
+/*     blt     2f */
+/*     cmp     r0,$175 */
+/*     bgt     2f */
+/*     add     $4,r2 */
+/*     br      1f */
+
+void opl31() {
+       expres();
+       checkreg();
+       opcode |= leftvalue << 6;
+       readop();
+       expres();
+       if (passno == 0)
+               binstr();
+       else {
+               leftvalue = pdot->value - leftvalue;
+               if (leftvalue < -2 || leftvalue > 0175)
+                       errorb();
+               else {
+                       leftvalue += 4;
+                       branch();
+               }
+       }
+}
+
+/* opl6:                                       /branch */
+/*     jsr     pc,expres */
+/*     tst     passno */
+/*     beq     3f */
+
+void opl6() {
+       expres();
+       if (passno == 0)
+               binstr();
+       else
+               dobranch();
+}
+
+/* dobranch: */
+/*     sub     dot,r2 */
+/*     mov     r2,r0 */
+/*     cmp     r0,$-254. */
+/*     blt     2f */
+/*     cmp     r0,$256. */
+/*     bgt     2f */
+
+void dobranch() {
+       leftvalue -= pdot->value;
+       if (leftvalue < -254 || leftvalue > 256)
+               errorb();
+       else
+               branch();
+}
+
+/* 1: */
+/*     bit     $1,r2 */
+/*     bne     2f */
+/*     cmp     r3,dot-2                / same relocation as . */
+/*     bne     2f */
+/*     asr     r2 */
+/*     dec     r2 */
+/*     bic     $177400,r2 */
+
+void branch() {
+       if (leftvalue & 1)
+               errorb();
+       else {
+               leftvalue = ((leftvalue >> 1) - 1) & 0377;
+               binstr();
+       }
+}
+
+/* 3: */
+/*     bis     (sp)+,r2 */
+/*     clr     r3 */
+/*     jsr     pc,outw */
+/*     rts     pc */
+
+void binstr() {
+       outw(leftvalue | opcode, 0);
+}
+
+/* 2: */
+/*     mov     $'b,-(sp) */
+/*     jsr     pc,error */
+/*     clr     r2 */
+/*     br      3b */
+
+void errorb() {
+       error('b');
+       leftvalue = 0;
+       branch();
+}
+
+/* opl7:                                       /jsr */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkreg */
+/*     jmp     op2a */
+
+void opl7() {
+       expres();
+       checkreg();
+       op2a();
+}
+
+/* opl10:                                      / rts */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkreg */
+/*     br      1f */
+
+void opl10() {
+       expres();
+       checkreg();
+       rinstr();
+}
+
+/* opl11:                                      / sys */
+/*     jsr     pc,expres */
+/*     cmp     r2,$256. */
+/*     bhis    0f */
+/*     cmp     r3,$1 */
+/*     ble     1f */
+/* 0: */
+/*     mov     $'a,-(sp) */
+/*     jsr     pc,error */
+
+void opl11() {
+       expres();
+       if (leftvalue < 0 || leftvalue >= 256)
+               error('a');
+       rinstr();
+}
+
+/* 1: */
+/*     bis     (sp)+,r2 */
+/*     jsr     pc,outw */
+/*     rts     pc */
+
+void rinstr() {
+       outw(leftvalue | opcode, leftflags);
+}
+
+/* opl16:                                      / .byte */
+/*     jsr     pc,expres */
+/*     jsr     pc,outb */
+/*     cmp     r4,$', */
+/*     bne     1f */
+/*     jsr     pc,readop */
+/*     br      opl16 */
+/* 1: */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opl16() {
+       while (1) {
+               expres();
+               outb(leftvalue, leftflags);
+               if (token != TCOMMA)
+                       break;
+               readop();
+       }
+}
+
+#if 1 /* modifications for dec syntax */
+void opldotword() {
+       while (1) {
+               expres();
+               outw(leftvalue, leftflags);
+               if (token != TCOMMA)
+                       break;
+               readop();
+       }
+}
+#endif
+
+/* opl17:                                      / < (.ascii) */
+/*     jsr     pc,getw */
+/*     mov     $1,r3 */
+/*     mov     r4,r2 */
+/*     bmi     2f */
+/*     bic     $!377,r2 */
+/*     jsr     pc,outb */
+/*     br      opl17 */
+/* 2: */
+/*     jsr     pc,getw */
+/*     rts     pc */
+
+void opl17() {
+       while (1) {
+               p1getw();
+               if (token == -1)
+                       break;
+               outb(token & 0377, FABS);
+       }
+       p1getw();
+}
+
+/* opl20:                                      /.even */
+/*     bit     $1,dot */
+/*     beq     1f */
+/*     cmp     dot-2,$4 */
+/*     beq     2f                      / bss mode */
+/*     clr     r2 */
+/*     clr     r3 */
+/*     jsr     pc,outb */
+/*     br      1f */
+/* 2: */
+/*     inc     dot */
+/* 1: */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opl20() {
+       if (pdot->value & 1) {
+               if (pdot->flags != FBSS)
+                       outb(0, 0);
+               else
+                       pdot->value++;
+       }
+}
+
+/* opl21:                                      /if */
+/*     jsr     pc,expres */
+
+void opl21() {
+       expres();
+}
+
+/* opl22: */
+/* oplret: */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opl22() {
+}
+
+void oplret() {
+}
+
+/* opl23:                                      /.globl */
+/*     cmp     r4,$200 */
+/*     blo     1f */
+/*     bisb    $40,(r4) */
+/*     jsr     pc,readop */
+/*     cmp     r4,$', */
+/*     bne     1f */
+/*     jsr     pc,readop */
+/*     br      opl23 */
+/* 1: */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opl23() {
+       struct symbol *psymbol;
+
+       while (1) {
+               if (token >= 0 && token < TASCII)
+                       break;
+               psymbol = (struct symbol *)token;
+               psymbol->flags |= FGLOBAL;
+               readop();
+               if (token != TCOMMA)
+                       break;
+               readop();
+       }
+}
+
+/* opl25:                                      / .text, .data, .bss */
+/* opl26: */
+/* opl27: */
+/*     inc     dot */
+/*     bic     $1,dot */
+/*     mov     r0,-(sp) */
+/*     mov     dot-2,r1 */
+/*     asl     r1 */
+/*     mov     dot,savdot-4(r1) */
+/*     tst     passno */
+/*     beq     1f */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,flush */
+/*     mov     $relp,-(sp) */
+/*     jsr     pc,flush */
+/*     mov     (sp),r2 */
+/*     asl     r2 */
+/*     add     $txtseek-[4*25],r2 */
+/*     mov     r2,tseekp */
+/*     mov     (r2),r0 */
+/*     mov     2(r2),r1 */
+/*     mov     $txtp,-(sp) */
+/*     jsr     pc,oset */
+/*     add     $trelseek-txtseek,r2 */
+/*     mov     (r2),r0 */
+/*     mov     2(r2),r1 */
+/*     mov     r2,rseekp */
+/*     mov     $relp,-(sp) */
+/*     jsr     pc,oset */
+/* 1: */
+/*     mov     (sp)+,r0 */
+/*     mov     savdot-[2*25](r0),dot */
+/*     asr     r0 */
+/*     sub     $25-2,r0 */
+/*     mov     r0,dot-2                / new . relocation */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opl25() {
+       pdot->value = (pdot->value + 1) & ~1;
+       savdot[pdot->flags - FTEXT] = pdot->value;
+       if (passno) {
+               flush(&txtp);
+               flush(&relp);
+               tseekp = seek;
+               oset(&txtp, seek[0]);
+               rseekp = seek + 3;
+               oset(&relp, seek[3]);
+       }
+       pdot->value = savdot[0];
+       pdot->flags = FTEXT;
+}
+
+void opl26() {
+       pdot->value = (pdot->value + 1) & ~1;
+       savdot[pdot->flags - FTEXT] = pdot->value;
+       if (passno) {
+               flush(&txtp);
+               flush(&relp);
+               tseekp = seek + 1;
+               oset(&txtp, seek[1]);
+               rseekp = seek + 4;
+               oset(&relp, seek[4]);
+       }
+       pdot->value = savdot[1];
+       pdot->flags = FDATA;
+}
+
+void opl27() {
+       pdot->value = (pdot->value + 1) & ~1;
+       savdot[pdot->flags - FTEXT] = pdot->value;
+       if (passno) { /* this is not really needed: */
+               flush(&txtp);
+               flush(&relp);
+               tseekp = seek + 2;
+               oset(&txtp, seek[2]);
+               rseekp = seek + 5;
+               oset(&relp, seek[5]);
+       }
+       pdot->value = savdot[2];
+       pdot->flags = FBSS;
+}
+
+/* opl32: */
+/*     cmp     r4,$200 */
+/*     blo     1f */
+/*     mov     r4,-(sp) */
+/*     jsr     pc,readop */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres */
+/*     mov     (sp)+,r0 */
+/*     bit     $37,(r0) */
+/*     bne     1f */
+/*     bis     $40,(r0) */
+/*     mov     r2,2(r0) */
+/* 1: */
+/*     tst     (sp)+ */
+/*     rts     pc */
+
+void opl32() {
+       struct symbol *psymbol;
+
+       if (token >= 0 && token < TASCII)
+               return;
+       psymbol = (struct symbol *)token;
+       readop();
+       readop();
+       expres();
+       if ((psymbol->flags & 037) == 0) {
+               psymbol->flags |= FGLOBAL;
+               psymbol->value = leftvalue;
+       }
+}
+
+/* addres: */
+/*     clr     -(sp) */
+
+void addres() {
+/* printf("addres() token = 0x%08x\n", token); */
+       indirect = 0; /* it has a different meaning on pass 1/2 */
+       addres1();
+}
+
+/* 4: */
+/*     cmp     r4,$'( */
+/*     beq     alp */
+/*     cmp     r4,$'- */
+/*     beq     amin */
+/*     cmp     r4,$'$ */
+/*     beq     adoll */
+/*     cmp     r4,$'* */
+/*     bne     getx */
+/*     jmp     astar */
+
+void addres1() {
+       switch (token) {
+       case TLPAREN:
+               alp();
+               return;
+       case TMIN:
+               amin();
+               return;
+       case TDOLL:
+               adoll();
+               return;
+       case TSTAR:
+               astar();
+               return;
+       }
+       getx();
+}
+
+/* getx: */
+/*     jsr     pc,expres */
+/*     cmp     r4,$'( */
+/*     bne     2f */
+/*     jsr     pc,readop */
+/*     mov     r2,(r5)+ */
+/*     mov     r3,(r5)+ */
+/*     mov     xsymbol,(r5)+ */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkreg */
+/*     jsr     pc,checkrp */
+/*     bis     $60,r2 */
+/*     bis     (sp)+,r2 */
+/*     rts     pc */
+/* 2: */
+
+void getx() {
+       expres();
+       if (token == TLPAREN) {
+               readop();
+               *adrptr++ = leftvalue;
+               *adrptr++ = leftflags;
+               *adrptr++ = (intptr_t)xsymbol;
+               expres();
+               checkreg();
+               checkrp();
+               leftvalue |= 060 | indirect;
+       }
+
+/*     cmp     r3,$24 */
+/*     bne     1f */
+/*     jsr     pc,checkreg */
+/*     bis     (sp)+,r2 */
+/*     rts     pc */
+/* 1: */
+
+       else if (leftflags == FREGISTER) {
+               checkreg();
+               leftvalue |= indirect;
+       }
+
+/*     mov     r3,-(sp) */
+/*     bic     $40,r3 */
+/*     mov     (sp)+,r3 */
+/*     bis     $100000,r3 */
+/*     sub     dot,r2 */
+/*     sub     $4,r2 */
+/*     cmp     r5,$adrbuf */
+/*     beq     1f */
+/*     sub     $2,r2 */
+/* 1: */
+
+       else {
+               leftflags |= 0100000; /* relocate flag */
+               leftvalue -= (pdot->value + 4);
+               if (adrptr != adrbuf)
+                       leftvalue -= 2;
+
+/*     mov     r2,(r5)+                / index */
+/*     mov     r3,(r5)+                / index reloc. */
+/*     mov     xsymbol,(r5)+           / index global */
+/*     mov     $67,r2                  / address mode */
+/*     bis     (sp)+,r2 */
+/*     rts     pc */
+
+               *adrptr++ = leftvalue;
+               *adrptr++ = leftflags;
+               *adrptr++ = (intptr_t)xsymbol;
+               leftvalue = 067 | indirect;
+       }
+}
+
+/* alp: */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkrp */
+/*     jsr     pc,checkreg */
+/*     cmp     r4,$'+ */
+/*     beq     1f */
+
+void alp() {
+       readop();
+       expres();
+       checkrp();
+       checkreg();
+       if (token != TPLUS) {
+
+/*     tst     (sp)+ */
+/*     beq     2f */
+/*     bis     $70,r2 */
+/*     clr     (r5)+ */
+/*     clr     (r5)+ */
+/*     mov     xsymbol,(r5)+ */
+/*     rts     pc */
+/* 2: */
+
+               if (indirect) {
+                       leftvalue |= 070;
+                       *adrptr++ = 0;
+                       *adrptr++ = 0;
+                       *adrptr++ = (intptr_t)xsymbol;
+               }
+
+/*     bis     $10,r2 */
+/*     rts     pc */
+
+               else
+                       leftvalue |= 010;
+
+/* 1: */
+/*     jsr     pc,readop */
+/*     bis     $20,r2 */
+/*     bis     (sp)+,r2 */
+/*     rts     pc */
+
+       }
+       else {
+               readop();
+               leftvalue |= 020 | indirect;
+       }
+}
+
+/* amin: */
+/*     jsr     pc,readop */
+/*     cmp     r4,$'( */
+/*     beq     1f */
+/*     mov     r4,savop */
+/*     mov     $'-,r4 */
+/*     br      getx */
+/* 1: */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres */
+/*     jsr     pc,checkrp */
+/*     jsr     pc,checkreg */
+/*     bis     (sp)+,r2 */
+/*     bis     $40,r2 */
+/*     rts     pc */
+
+
+void amin() {
+       readop();
+       if (token != TLPAREN) {
+               savop = token;
+               token = TMIN;
+               getx();
+       }
+       else {
+               readop();
+               expres();
+               checkrp();
+               checkreg();
+               leftvalue |= indirect | 040;
+       }
+}
+
+/* adoll: */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres */
+/*     mov     r2,(r5)+ */
+/*     mov     r3,(r5)+ */
+/*     mov     xsymbol,(r5)+ */
+/*     mov     (sp)+,r2 */
+/*     bis     $27,r2 */
+/*     rts     pc */
+
+void adoll() {
+       readop();
+       expres();
+       *adrptr++ = leftvalue;
+       *adrptr++ = leftflags;
+       *adrptr++ = (intptr_t)xsymbol;
+       leftvalue = indirect | 027; /* means (pc)+ */
+}
+
+/* astar: */
+/*     tst     (sp) */
+/*     beq     1f */
+/*     mov     $'*,-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+/*     mov     $10,(sp) */
+/*     jsr     pc,readop */
+/*     jmp     4b */
+
+void astar() {
+       if (indirect)
+               error('*');
+       indirect = 010;
+       readop();
+       addres1();
+}
+
+/* checkreg: */
+/*     cmp     r2,$7 */
+/*     bhi     1f */
+/*     cmp     r1,$1 */
+/*     blos    2f */
+/*     cmp     r3,$5 */
+/*     blo     1f */
+/* 2: */
+/*     rts     pc */
+/* 1: */
+/*     mov     $'a,-(sp) */
+/*     jsr     pc,error */
+/*     clr     r2 */
+/*     clr     r3 */
+/*     rts     pc */
+
+void checkreg() {
+       if (leftvalue > 7 || (leftflags >= FTEXT && leftflags <= FBSS)) {
+               error('a');
+               leftvalue = 0;
+               leftflags = 0;
+       }
+}
+
+/* checkrp: */
+/*     cmp     r4,$') */
+/*     beq     1f */
+/*     mov     $'),-(sp) */
+/*     jsr     pc,error */
+/*     rts     pc */
+/* 1: */
+/*     jsr     pc,readop */
+/*     rts     pc */
+
+void checkrp() {
+       if (token != TRPAREN)
+               error(')');
+       else
+               readop();
+}
+
+/* setbr: */
+/*     mov     brtabp,r1 */
+/*     cmp     r1,$brlen */
+/*     blt     1f */
+/*     mov     $2,r2 */
+/*     rts     pc */
+/* 1: */
+
+int setbr(value) int value; {
+       int index;
+
+       if (brtabp >= brlen)
+               return 2;
+
+/*     inc     brtabp */
+/*     clr     -(sp) */
+/*     sub     dot,r0 */
+/*     ble     1f */
+/*     sub     brdelt,r0 */
+/* 1: */
+
+       index = brtabp++;
+       value -= pdot->value;
+       if (value > 0)
+               value -= brdelt;
+
+/*     cmp     r0,$-254. */
+/*     blt     1f */
+/*     cmp     r0,$256. */
+/*     ble     2f */
+/* 1: */
+
+       if (value < -254 || value > 256) {
+
+/*     mov     r1,-(sp) */
+/*     bic     $!7,(sp) */
+/*     mov     $1,r0 */
+/*     ash     (sp)+,r0 */
+/*     ash     $-3,r1 */
+/*     bisb    r0,brtab(r1) */
+/*     mov     $2,(sp) */
+
+               brtab[index >> 3] |= 1 << (index & 7);
+               return 2;
+
+/* 2: */
+/*     mov     (sp)+,r2 */
+/*     rts     pc */
+
+       }
+       return 0;
+}
+
+/* getbr: */
+/*     mov     brtabp,r1 */
+/*     cmp     r1,$brlen */
+/*     blt     1f */
+/*     sec */
+/*     rts     pc */
+/* 1: */
+
+int getbr() {
+       int index;
+
+       if (brtabp >= brlen)
+               return 1;
+
+/*     mov     r1,-(sp) */
+/*     bic     $!7,(sp) */
+/*     neg     (sp) */
+/*     inc     brtabp */
+/*     ash     $-3,r1 */
+/*     movb    brtab(r1),r1 */
+/*     ash     (sp)+,r1 */
+/*     ror     r1                      / 0-bit into c-bit */
+/*     rts     pc */
+
+       index = brtabp++;
+       return brtab[index >> 3] & (1 << (index & 7));
+}
+
+/* expres: */
+/*     clr     xsymbol */
+
+void expres() {
+       xsymbol = NULL;
+       expres1();
+}
+
+/* expres1: */
+/*     mov     r5,-(sp) */
+/*     mov     $'+,-(sp) */
+/*     clr     r2 */
+/*     mov     $1,r3 */
+/*     br      1f */
+
+void expres1() {
+       struct symbol *psymbol;
+
+/* printf("expres()\n"); */
+       optoken = TPLUS;
+       opfound = 0;
+       leftvalue = 0;
+       leftflags = FABS;
+       goto entry;
+
+/* advanc: */
+/*     jsr     pc,readop */
+/* 1: */
+/*     mov     r4,r0 */
+/*     blt     6f */
+/*     cmp     r0,$177 */
+/*     ble     7f */
+/* 6: */
+/*     movb    (r4),r0 */
+/*     bne     1f */
+/*     tst     passno */
+/*     beq     1f */
+/*     mov     $'u,-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+
+       while (1) {
+               readop();
+       entry:
+               rightflags = token;
+               if (token < 0 || token >= TASCII) {
+                       psymbol = (struct symbol *)token;
+                       rightflags = psymbol->flags;
+                       if (rightflags == 0 && passno)
+                               error('u');
+
+/*     tst     overlaid */
+/*     beq     0f */
+
+/* Bill Shannon's hack to the assembler to force globl text */
+/* references to remain undefined so that the link editor may */
+/* resolve them. This is necessary if a function is used as an */
+/* arg in an overlay located piece of code, and the function is */
+/* actually in another overlay. Elsewise, the assembler fix's up */
+/* the reference before the link editor changes the globl refrence */
+/* to the thunk. -wfj 5/80 */
+/*     cmp     r0,$42                  / is it globl text ? */
+/*     bne     0f                      / nope */
+/*     mov     $40,r0                  / yes, treat it as undefined external */
+/* 0: */
+
+                       if (overlaid && rightflags == (FTEXT | FGLOBAL))
+                               rightflags = FGLOBAL;
+
+/*     cmp     r0,$40 */
+/*     bne     1f */
+/*     mov     r4,xsymbol */
+/*     clr     r1 */
+/*     br      oprand */
+/* 1: */
+
+                       if (rightflags == FGLOBAL) {
+                               xsymbol = (struct symbol *)token;
+                               rightvalue = 0;
+                       }
+
+/*     mov     2(r4),r1 */
+/*     br      oprand */
+
+                       else
+                               rightvalue = psymbol->value;
+                       oprand();
+                       continue;
+               }
+
+/* 7: */
+/*     cmp     r4,$141 */
+/*     blo     1f */
+/*     asl     r4 */
+/*     mov     curfb-[2*141](r4),r0 */
+/*     mov     2(r0),r1 */
+/*     movb    (r0),r0 */
+/*     br      oprand */
+/* 1: */
+
+               if (token >= TLABEL) {
+                       if (token < TLABEL + 10)
+                               psymbol = *(struct symbol **)
+                                               curfb[token - TLABEL];
+                       else
+                               psymbol = *(struct symbol **)
+                                               nxtfb[token - (TLABEL + 10)];
+                       rightvalue = psymbol->value;
+                       rightflags = psymbol->flags;
+                       oprand();
+                       continue;
+               }
+
+/*     mov     $esw1,r1 */
+/* 1: */
+/*     cmp     (r1)+,r4 */
+/*     beq     1f */
+/*     tst     (r1)+ */
+/*     bne     1b */
+/*     tst     (sp)+ */
+/*     mov     (sp)+,r5 */
+/*     rts     pc */
+/* 1: */
+/*     jmp     *(r1) */
+
+               switch (token) {
+               default:
+                       return;
+
+/*     .data */
+/* esw1: */
+/*     '+;     binop */
+/*     '-;     binop */
+/*     '*;     binop */
+/*     '/;     binop */
+/*     '&;     binop */
+/*     037;    binop */
+/*     035;    binop */
+/*     036;    binop */
+/*     '%;     binop */
+
+               case TPLUS:
+               case TMIN:
+               case TSTAR:
+               case TSLASH:
+               case TAND:
+               case TOR:
+               case TLSH:
+               case TRSH:
+               case TMOD:
+                       binop();
+                       break;
+
+/*     '[;     brack */
+
+               case TLBRACK:
+                       brack();
+                       break;
+
+/*     '^;     binop */
+
+               case TCARET:
+                       binop();
+                       break;
+
+/*     1;      exnum */
+
+               case TABS:
+                       exnum();
+                       break;
+
+/*     2;      exnum1 */
+
+               case TABS2:
+                       exnum1();
+                       break;
+
+/*     '!;     binop */
+
+               case TNOT:
+                       binop();
+                       break;
+
+/*     200;    0 */
+/*     .text */
+
+               }
+       }
+}
+
+/* binop: */
+/*     cmpb    (sp),$'+ */
+/*     beq     1f */
+/*     mov     $'e,-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+/*     movb    r4,(sp) */
+/*     br      advanc */
+
+
+void binop() {
+       if (optoken != TPLUS)
+               error('e');
+       optoken = token;
+}
+
+/* exnum1: */
+/*     mov     numval,r1 */
+/*     br      1f */
+
+/* exnum: */
+/*     jsr     pc,getw */
+/*     mov     r4,r1 */
+/* 1: */
+/*     mov     $1,r0 */
+/*     br      oprand */
+
+void exnum1() {
+/* printf("exnum1() numval = 0%o\n", numval); */
+       rightvalue = numval;
+       rightflags = FABS;
+       oprand();
+}
+
+void exnum() {
+       p1getw();
+/* printf("exnum() token = 0%o\n", rightvalue); */
+       rightvalue = token;
+       rightflags = FABS;
+       oprand();
+}
+
+/* brack: */
+/*     mov     r2,-(sp) */
+/*     mov     r3,-(sp) */
+/*     jsr     pc,readop */
+/*     jsr     pc,expres1 */
+/*     cmp     r4,$'] */
+/*     beq     1f */
+/*     mov     $'],-(sp) */
+/*     jsr     pc,error */
+/* 1: */
+/*     mov     r3,r0 */
+/*     mov     r2,r1 */
+/*     mov     (sp)+,r3 */
+/*     mov     (sp)+,r2 */
+
+void brack() {
+       int tempvalue;
+       int tempflags;
+       int temptoken;
+
+       tempvalue = leftvalue;
+       tempflags = leftflags;
+       temptoken = optoken;
+       readop();
+       expres1();
+       if (token != TRBRACK)
+               error(']');
+       rightflags = leftflags;
+       rightvalue = leftvalue;
+       leftflags = tempflags;
+       leftvalue = tempvalue;
+       optoken = temptoken;
+       oprand();
+}
+
+/* oprand: */
+/*     mov     $exsw2,r5 */
+/* 1: */
+/*     cmp     (sp),(r5)+ */
+/*     beq     1f */
+/*     tst     (r5)+ */
+/*     bne     1b */
+/*     br      eoprnd */
+/* 1: */
+/*     jmp     *(r5) */
+
+
+void oprand() {
+       opfound = 1;
+       switch (optoken) {
+       default:
+               eoprnd();
+               return;
+
+/*     .data */
+/* exsw2: */
+/*     '+; exadd */
+
+       case TPLUS:
+               exadd();
+               return;
+
+/*     '-; exsub */
+
+       case TMIN:
+               exsub();
+               return;
+
+/*     '*; exmul */
+
+       case TSTAR:
+               exmul();
+               return;
+
+/*     '/; exdiv */
+
+       case TSLASH:
+               exdiv();
+               return;
+
+/*     037; exor */
+
+       case TOR:
+               exor();
+               return;
+
+/*     '&; exand */
+
+       case TAND:
+               exand();
+               return;
+
+/*     035;exlsh */
+
+       case TLSH:
+               exlsh();
+               return;
+
+/*     036;exrsh */
+
+       case TRSH:
+               exrsh();
+               return;
+
+/*     '%; exmod */
+
+       case TMOD:
+               exmod();
+               return;
+
+/*     '^; excmbin */
+
+       case TCARET:
+               excmbin();
+               return;
+
+/*     '!; exnot */
+
+       case TNOT:
+               exnot();
+               return;
+
+/*     200;  0 */
+/*     .text */
+
+       }
+}
+
+/* excmbin: */
+/*     mov     r0,r3 */
+/*     br      eoprnd */
+
+void excmbin() {
+       leftflags = rightflags;
+       eoprnd();
+}
+
+/* exrsh: */
+/*     neg     r1 */
+/*     beq     exlsh */
+/*     inc     r1 */
+/*     clc */
+/*     ror     r2 */
+/* exlsh: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     ash     r1,r2 */
+/*     br      eoprnd */
+
+
+void exrsh() {
+       combin(relte2);
+       leftvalue = ((unsigned int)leftvalue & 0177777) >> rightvalue;
+       eoprnd();
+}
+
+void exlsh() {
+       combin(relte2);
+       leftvalue <<= rightvalue;
+       eoprnd();
+}
+
+/* exmod: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     mov     r3,r0 */
+/*     mov     r2,r3 */
+/*     clr     r2 */
+/*     div     r1,r2 */
+/*     mov     r3,r2 */
+/*     mov     r0,r3 */
+/*     br      eoprnd */
+
+void exmod() {
+       int temp;
+
+       combin(relte2);
+       temp = rightvalue & 0177777;
+       if (temp)
+               leftvalue = (leftvalue & 0177777) % temp;
+       else {
+               error('0'); /* a nick innovation */
+               leftvalue = 0;
+       }
+       eoprnd();
+}
+
+/* exadd: */
+/*     mov     $reltp2,r5 */
+/*     jsr     pc,combin */
+/*     add     r1,r2 */
+/*     br      eoprnd */
+
+
+void exadd() {
+       combin(reltp2);
+       leftvalue += rightvalue;
+       eoprnd();
+}
+
+/* exsub: */
+/*     mov     $reltm2,r5 */
+/*     jsr     pc,combin */
+/*     sub     r1,r2 */
+/*     br      eoprnd */
+
+void exsub() {
+       combin(reltm2);
+       leftvalue -= rightvalue;
+       eoprnd();
+}
+
+/* exand: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     com     r1 */
+/*     bic     r1,r2 */
+/*     br      eoprnd */
+
+void exand() {
+       combin(relte2);
+       leftvalue &= rightvalue;
+       eoprnd();
+}
+
+/* exor: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     bis     r1,r2 */
+/*     br      eoprnd */
+
+void exor() {
+       combin(relte2);
+       leftvalue |= rightvalue;
+       eoprnd();
+}
+
+/* exmul: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     mul     r2,r1 */
+/*     mov     r1,r2 */
+/*     br      eoprnd */
+
+void exmul() {
+       combin(relte2);
+       leftvalue *= rightvalue;
+       eoprnd();
+}
+
+/* exdiv: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     mov     r3,r0 */
+/*     mov     r2,r3 */
+/*     clr     r2 */
+/*     div     r1,r2 */
+/*     mov     r0,r3 */
+/*     br      eoprnd */
+
+void exdiv() {
+       int temp;
+
+       combin(relte2);
+       temp = rightvalue & 0177777;
+       if (temp)
+               leftvalue = (leftvalue & 0177777) / temp;
+       else {
+               error('0'); /* a nick innovation */
+               leftvalue = 0;
+       }
+       eoprnd();
+}
+
+/* exnot: */
+/*     mov     $relte2,r5 */
+/*     jsr     pc,combin */
+/*     com     r1 */
+/*     add     r1,r2 */
+/*     br      eoprnd */
+
+void exnot() {
+       combin(relte2);
+       leftvalue += ~rightvalue;
+       eoprnd();
+}
+
+/* eoprnd: */
+/*     mov     $'+,(sp) */
+/*     jmp     advanc */
+
+void eoprnd() {
+       optoken = TPLUS;
+}
+
+/* combin: */
+/*     tst     passno */
+/*     bne     combin1 */
+
+void combin(table) char *table; {
+       int global;
+       int flags;
+
+       if (passno == 0) {
+
+/*     mov     r0,-(sp) */
+/*     bis     r3,(sp) */
+/*     bic     $!40,(sp) */
+/*     bic     $!37,r0 */
+/*     bic     $!37,r3 */
+/*     cmp     r0,r3 */
+/*     ble     1f */
+/*     mov     r0,-(sp) */
+/*     mov     r3,r0 */
+/*     mov     (sp)+,r3 */
+/* 1: */
+
+               global = (rightflags | leftflags) & FGLOBAL;
+               rightflags &= 037;
+               leftflags &= 037;
+               if (rightflags > leftflags) {
+                       flags = rightflags;
+                       rightflags = leftflags;
+                       leftflags = flags;
+               }
+
+/*     tst     r0 */
+/*     beq     1f */
+/*     cmp     r5,$reltm2 */
+/*     bne     2f */
+/*     cmp     r0,r3 */
+/*     bne     2f */
+/*     mov     $1,r3 */
+/*     br      2f */
+/* 1: */
+/*     clr     r3 */
+/* 2: */
+/*     bis     (sp)+,r3 */
+/*     rts     pc */
+
+               if (rightflags) {
+                       if (table == reltm2 && rightflags == leftflags)
+                               leftflags = TABS;
+               }
+               else {
+                       leftflags = 0;
+               }
+               leftflags |= global;
+       }
+
+/* combin1: */
+/*     mov     r1,-(sp) */
+/*     clr     maxtyp */
+
+       else {
+               maxtyp = 0;
+
+/*     jsr     pc,maprel */
+/*     mov     r0,r1 */
+/*     mul     $6,r1 */
+/*     mov     r3,r0 */
+/*     jsr     pc,maprel */
+/*     add     r5,r0 */
+/*     add     r1,r0 */
+/*     movb    (r0),r3 */
+
+               leftflags = table[maprel(rightflags) * 6 + maprel(leftflags)];
+
+/*     bpl     1f */
+/*     cmp     r3,$-1 */
+/*     beq     2f */
+/*     mov     $'r,-(sp) */
+/*     jsr     pc,error */
+/* 2: */
+/*     mov     maxtyp,r3 */
+/* 1: */
+
+               if (leftflags < 0) {
+                       if (leftflags != M)
+                               error('r');
+                       leftflags = maxtyp;
+               }
+
+/*     mov     (sp)+,r1 */
+/*     rts     pc */
+
+       }
+}
+
+/* maprel: */
+/*     cmp     r0,$40 */
+/*     bne     1f */
+/*     mov     $5,r0 */
+/*     rts     pc */
+/* 1: */
+/*     bic     $!37,r0 */
+/*     cmp     r0,maxtyp */
+/*     blos    1f */
+/*     mov     r0,maxtyp */
+/* 1: */
+/*     cmp     r0,$5 */
+/*     blo     1f */
+/*     mov     $1,r0 */
+/* 1: */
+/*     rts     pc */
+
+int maprel(flags) int flags; {
+       if (flags == FGLOBAL)
+               return 5;
+       flags &= 037;
+       if (maxtyp < flags)
+               maxtyp = flags;
+       if (flags > FBSS)
+               flags = FABS;
+       return flags;
+}
+
+/*     .data */
+/* X = -2 */
+/* M = -1 */
+/* reltp2: */
+/*     .byte 0, 0, 0, 0, 0, 0 */
+/*     .byte 0, M, 2, 3, 4,40 */
+/*     .byte 0, 2, X, X, X, X */
+/*     .byte 0, 3, X, X, X, X */
+/*     .byte 0, 4, X, X, X, X */
+/*     .byte 0,40, X, X, X, X */
+
+char reltp2[36] = {
+       0,  0, 0, 0, 0,  0,
+       0,  M, 2, 3, 4,040,
+       0,  2, X, X, X,  X,
+       0,  3, X, X, X,  X,
+       0,  4, X, X, X,  X,
+       0,040, X, X, X,  X
+};
+
+/* reltm2: */
+/*     .byte 0, 0, 0, 0, 0, 0 */
+/*     .byte 0, M, 2, 3, 4,40 */
+/*     .byte 0, X, 1, X, X, X */
+/*     .byte 0, X, X, 1, X, X */
+/*     .byte 0, X, X, X, 1, X */
+/*     .byte 0, X, X, X, X, X */
+
+char reltm2[36] = {
+       0, 0, 0, 0, 0,  0,
+       0, M, 2, 3, 4,040,
+       0, X, 1, X, X,  X,
+       0, X, X, 1, X,  X,
+       0, X, X, X, 1,  X,
+       0, X, X, X, X,  X
+};
+
+/* relte2: */
+/*     .byte 0, 0, 0, 0, 0, 0 */
+/*     .byte 0, M, X, X, X, X */
+/*     .byte 0, X, X, X, X, X */
+/*     .byte 0, X, X, X, X, X */
+/*     .byte 0, X, X, X, X, X */
+/*     .byte 0, X, X, X, X, X */
+
+char relte2[36] = {
+       0, 0, 0, 0, 0, 0,
+       0, M, X, X, X, X,
+       0, X, X, X, X, X,
+       0, X, X, X, X, X,
+       0, X, X, X, X, X,
+       0, X, X, X, X, X
+};
+
+/* qnl:        <?\n> */
+/* a.out:      <a.out\0> */
+/*     .even */
+/* a.outp:     a.out */
+
+char *a_outp = "a.out";
+
+/* obufp:      outbuf */
+
+short *obufp = outbuf;
+
+/* passno: -1 */
+
+int passno = -1;
+
+/* outmod:     0777 */
+
+int outmod = 0777;
+
+/* tseekp:     txtseek */
+
+off_t *tseekp = seek;
+
+/* rseekp:     trelseek */
+
+off_t *rseekp = seek + 3;
+
+/* txtmagic: */
+/*     br      .+20 */
+/* txtsiz:     .=.+2 */
+/* datsiz:     .=.+2 */
+/* bsssiz:     .=.+2 */
+/* symsiz:     .=.+2 */
+/*     .=.+6 */
+
+int siz[4];
+
+/* txtseek:0; 20 */
+/* datseek:.=.+4 */
+/*     .=.+4 */
+/* trelseek:.=.+4 */
+/* drelseek:.=.+4 */
+/*     .=.+4 */
+/* symseek:.=.+4 */
+
+off_t seek[7];
+
+/*     .bss */
+/* brlen       = 1024. */
+/* brtab:      .=.+[brlen\/8.] */
+
+char brtab[brlen / 8];
+
+/* brtabp:     .=.+2 */
+
+int brtabp;
+
+/* brdelt:     .=.+2 */
+
+int brdelt;
+
+/* fbbufp: .=.+2 */
+
+struct symbol **fbbufp;
+
+/* defund:     .=.+2 */
+
+int defund;
+
+/* datbase:.=.+2 */
+/* bssbase:.=.+2 */
+
+int base[3];
+
+/* ibufc:      .=.+2 */
+
+int ibufc;
+
+/* overlaid: .=.+2 */
+
+int overlaid;
+
+/* adrbuf:     .=.+12. */
+
+intptr_t adrbuf[6];
+
+/* xsymbol:.=.+2 */
+
+struct symbol *xsymbol;
+
+/* errflg:     .=.+2 */
+
+int errflg;
+
+/* argb:       .=.+22. */
+
+char argb[22];
+
+#if 0
+/* numval:     .=.+2 */
+
+int numval;
+#endif
+
+/* maxtyp:     .=.+2 */
+
+int maxtyp;
+
+/* ibufp:      .=.+2 */
+
+short *ibufp;
+char *p0ibufp;
+
+/* txtp:       .=.+8. */
+/*     .=.+1024. */
+
+struct stream txtp;
+
+/* relp:       .=.+8. */
+/* outbuf: */
+/*     .=.+1024. */
+
+struct stream relp;
+
+/* swapf:      .=.+2 */
+
+int swapf;
+
+/* rlimit:     .=.+2 */
+
+int rlimit;
+
+/* endtable:.=.+2 */
+
+struct symbol **endtable;
+
+/* totalsz:                    / string table length */
+/*     .=.+4 */
+/*     .text */
+
+off_t totalsz;
+
diff --git a/bin/as/as2.h b/bin/as/as2.h
new file mode 100644 (file)
index 0000000..c14867f
--- /dev/null
@@ -0,0 +1,149 @@
+#ifndef _AS2_H
+#define _AS2_H 1
+
+#include "krcompat.h"
+
+#define brlen 1024
+
+#define X -2
+#define M -1
+
+#define outbuf ((short *)relp.data)
+
+struct stream {
+       char *append;
+       char *limit;
+       off_t offset;
+       char data[02000];
+};
+
+extern intptr_t *adrptr; /* r5 */
+extern int opcode; /* (sp) or 2(sp) if rvalue is present */
+extern int rvalue; /* (sp) */
+extern char reltp2[36];
+extern char reltm2[36];
+extern char relte2[36];
+extern char *a_outp;
+extern short *obufp;
+extern int passno;
+extern int outmod;
+extern off_t *tseekp;
+extern off_t *rseekp;
+extern int siz[4];
+extern off_t seek[7];
+extern char brtab[brlen / 8];
+extern int brtabp;
+extern int brdelt;
+extern struct symbol **fbbufp;
+extern int defund;
+extern int base[3];
+extern int ibufc;
+extern int overlaid;
+extern intptr_t adrbuf[6];
+extern struct symbol *xsymbol;
+extern int errflg;
+extern char argb[22];
+extern int numval;
+extern int maxtyp;
+extern short *ibufp;
+extern char *p0ibufp;
+extern struct stream txtp;
+extern struct stream relp;
+extern int swapf;
+extern int rlimit;
+extern struct symbol **endtable;
+extern off_t totalsz;
+
+void pass1 PARAMS((void));
+void saexit PARAMS((void));
+int aexit PARAMS((void));
+void filerr PARAMS((char *p));
+void osymout PARAMS((void));
+void nsymout PARAMS((void));
+void putstring PARAMS((char *p));
+void doreloc PARAMS((struct symbol *psymbol));
+void setup PARAMS((void));
+void outw PARAMS((int value, int flags));
+void outb PARAMS((int value, int flags));
+void pass1_2 PARAMS((void));
+int checkeos PARAMS((void));
+void fbadv PARAMS((int label));
+void oset PARAMS((struct stream *pstream, off_t offset));
+void p1putw PARAMS((struct stream *pstream, int word));
+void flush PARAMS((struct stream *pstream));
+void wrterr PARAMS((void));
+void readop PARAMS((void));
+void p1getw PARAMS((void));
+int getw1 PARAMS((void));
+void xpr PARAMS((void));
+void opline PARAMS((void));
+void opeof PARAMS((void));
+void opl30 PARAMS((void));
+void opl14 PARAMS((void));
+void opl5 PARAMS((void));
+void opl13 PARAMS((void));
+void op2a PARAMS((void));
+void op2b PARAMS((void));
+void opl15 PARAMS((void));
+void opl12 PARAMS((void));
+void opl35 PARAMS((void));
+void opl36 PARAMS((void));
+void opl31 PARAMS((void));
+void opl6 PARAMS((void));
+void dobranch PARAMS((void));
+void branch PARAMS((void));
+void binstr PARAMS((void));
+void errorb PARAMS((void));
+void opl7 PARAMS((void));
+void opl10 PARAMS((void));
+void opl11 PARAMS((void));
+void rinstr PARAMS((void));
+void opl16 PARAMS((void));
+#if 1 /* modifications for dec syntax */
+void opldotword PARAMS((void));
+#endif
+void opl17 PARAMS((void));
+void opl20 PARAMS((void));
+void opl21 PARAMS((void));
+void opl22 PARAMS((void));
+void oplret PARAMS((void));
+void opl23 PARAMS((void));
+void opl25 PARAMS((void));
+void opl26 PARAMS((void));
+void opl27 PARAMS((void));
+void opl32 PARAMS((void));
+void addres PARAMS((void));
+void addres1 PARAMS((void));
+void getx PARAMS((void));
+void alp PARAMS((void));
+void amin PARAMS((void));
+void adoll PARAMS((void));
+void astar PARAMS((void));
+void checkreg PARAMS((void));
+void checkrp PARAMS((void));
+int setbr PARAMS((int value));
+int getbr PARAMS((void));
+void expres PARAMS((void));
+void expres1 PARAMS((void));
+void binop PARAMS((void));
+void exnum1 PARAMS((void));
+void exnum PARAMS((void));
+void brack PARAMS((void));
+void oprand PARAMS((void));
+void excmbin PARAMS((void));
+void exrsh PARAMS((void));
+void exlsh PARAMS((void));
+void exmod PARAMS((void));
+void exadd PARAMS((void));
+void exsub PARAMS((void));
+void exand PARAMS((void));
+void exor PARAMS((void));
+void exmul PARAMS((void));
+void exdiv PARAMS((void));
+void exnot PARAMS((void));
+void eoprnd PARAMS((void));
+void combin PARAMS((char *table));
+int maprel PARAMS((int flags));
+
+#endif
+
similarity index 100%
rename from bin/as/as2.s
rename to bin/as/as2_old.s
diff --git a/bin/as/krcompat.h b/bin/as/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
diff --git a/bin/as/n.sh b/bin/as/n.sh
new file mode 100755 (executable)
index 0000000..9b9317a
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/bin\/as$//'`"
+DESTDIR="$ROOT/host"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/bin"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install
diff --git a/bin/cc/Makefile b/bin/cc/Makefile
new file mode 100644 (file)
index 0000000..13079ff
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# makefile for cc
+#
+
+SEPFLAG=-i
+CPPFLAGS=-DDESTDIR=\"${DESTDIR}\" -DSTAGEDIR=\"${STAGEDIR}\"
+
+all: cc
+
+cc: cc.o
+       cc ${SEPFLAG} -o $@ cc.o
+
+install: all
+       install -s cc ${DESTDIR}/bin
+
+clean:
+       rm -f *.o a.out cc core errs
similarity index 81%
rename from bin/cc.c
rename to bin/cc/cc.c
index 59aaae2..650ab49 100644 (file)
--- a/bin/cc.c
@@ -1,4 +1,6 @@
+#if    !defined(lint) && defined(DOSCCS)
 static char sccsid[] = "@(#)cc.c 4.13 9/18/85";
+#endif
 /*
  * cc - front end for C compiler
  */
@@ -6,21 +8,28 @@ static        char sccsid[] = "@(#)cc.c 4.13 9/18/85";
 #include <stdio.h>
 #include <ctype.h>
 #include <signal.h>
+#ifdef PDP11
 #include <sys/dir.h>
+#else
+#define MAXNAMLEN 255
+#endif
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "krcompat.h"
 
-char   *cpp = "/lib/cpp";
-char   *ccom = "/lib/c0";
-char   *ccom1 = "/lib/c1";
-char   *c2 = "/lib/c2";
-char   *as = "/bin/as";
-char   *ld = "/bin/ld";
-char   *crt0 = "/lib/crt0.o";
+char   *cpp = DESTDIR "/lib/cpp";
+char   *ccom = DESTDIR "/lib/c0";
+char   *ccom1 = DESTDIR "/lib/c1";
+char   *c2 = DESTDIR "/lib/c2";
+char   *as = DESTDIR "/bin/as";
+char   *ld = DESTDIR "/bin/ld";
+char   *crt0 = DESTDIR "/lib/crt0.o";
 
 char   tmp0[30];               /* big enough for /tmp/ctm%05.5d */
 char   *tmp1, *tmp2, *tmp3, *tmp4, *tmp5;
 char   *outfile;
-char   *savestr(), *strspl(), *setsuf();
-int    idexit();
 char   **av, **clist, **llist, **plist;
 int    cflag, eflag, oflag, pflag, sflag, wflag, exflag, proflag;
 int    Mflag, debug;
@@ -30,15 +39,32 @@ char        *npassname;
 
 int    nc, nl, np, nxo, na;
 
-#define        cunlink(s)      if (s) unlink(s)
+#if 0
+#define cunlink(fn)    /*if (fn) printf("temp %s\n", fn)*/;
+#define unlink cunlink
+#else
+#define        cunlink(fn)     if (fn) unlink(fn)
+#endif
 
-main(argc, argv)
-       char **argv;
-{
+int main PARAMS((int argc, char **argv));
+int idexit PARAMS((void));
+void dexit PARAMS((void)) NORETURN;
+void error PARAMS((char *s, char *x));
+int getsuf PARAMS((char as[]));
+char *setsuf PARAMS((char *as, int ch));
+int callsys PARAMS((char *f, char **v));
+int nodup PARAMS((char **l, char *os));
+char *savestr PARAMS((register char *cp));
+char *strspl PARAMS((char *left, char *right));
+
+int main(argc, argv) int argc; char **argv; {
        char *t;
        char *assource;
        int i, j, c;
 
+#if 0
+       debug = 1;
+#endif
        /* ld currently adds upto 5 args; 10 is room to spare */
        av = (char **)calloc(argc+10, sizeof (char **));
        clist = (char **)calloc(argc, sizeof (char **));
@@ -68,9 +94,9 @@ main(argc, argv)
                        continue;
                case 'p':
                        proflag++;
-                       crt0 = "/lib/mcrt0.o";
+                       crt0 = STAGEDIR "/lib/mcrt0.o";
                        if (argv[i][2] == 'g')
-                               crt0 = "/usr/lib/gcrt0.o";
+                               crt0 = STAGEDIR "/usr/lib/gcrt0.o";
                        continue;
                case 'w':
                        wflag++;
@@ -158,11 +184,11 @@ main(argc, argv)
        if (nc==0)
                goto nocom;
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-               signal(SIGINT, idexit);
+               signal(SIGINT, (sig_t)idexit);
        if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
-               signal(SIGTERM, idexit);
+               signal(SIGTERM, (sig_t)idexit);
        if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
-               signal(SIGHUP, idexit);
+               signal(SIGHUP, (sig_t)idexit);
        if (pflag==0)
                sprintf(tmp0, "/tmp/ctm%05.5d", getpid());
        tmp1 = strspl(tmp0, "1");
@@ -274,16 +300,13 @@ nocom:
        dexit();
 }
 
-idexit()
-{
-
+int idexit() {
        eflag = 100;
        dexit();
+       /*NOTREACHED*/
 }
 
-dexit()
-{
-
+void dexit() {
        if (!pflag) {
                cunlink(tmp1);
                cunlink(tmp2);
@@ -295,9 +318,7 @@ dexit()
        exit(eflag);
 }
 
-error(s, x)
-       char *s, *x;
-{
+void error(s, x) char *s; char *x; {
        FILE *diag = exflag ? stderr : stdout;
 
        fprintf(diag, "cc: ");
@@ -308,9 +329,7 @@ error(s, x)
        eflag++;
 }
 
-getsuf(as)
-char as[];
-{
+int getsuf(as) char as[]; {
        register int c;
        register char *s;
        register int t;
@@ -328,10 +347,7 @@ char as[];
        return (0);
 }
 
-char *
-setsuf(as, ch)
-       char *as;
-{
+char *setsuf(as, ch) char *as; int ch; {
        register char *s, *s1;
 
        s = s1 = savestr(as);
@@ -342,15 +358,18 @@ setsuf(as, ch)
        return (s1);
 }
 
-callsys(f, v)
-       char *f, **v;
-{
+int callsys(f, v) char *f; char **v; {
        int t, status;
        char **cpp;
 
        if (debug) {
+#if 1
+               fprintf(stderr, "%s", f);
+               for (cpp = v + 1; *cpp != 0; cpp++)
+#else
                fprintf(stderr, "%s:", f);
                for (cpp = v; *cpp != 0; cpp++)
+#endif
                        fprintf(stderr, " %s", *cpp);
                fprintf(stderr, "\n");
        }
@@ -377,9 +396,7 @@ callsys(f, v)
        return ((status>>8) & 0377);
 }
 
-nodup(l, os)
-       char **l, *os;
-{
+int nodup(l, os) char **l; char *os; {
        register char *t, *s;
        register int c;
 
@@ -401,10 +418,7 @@ nodup(l, os)
 char   *savetab;
 int    saveleft;
 
-char *
-savestr(cp)
-       register char *cp;
-{
+char * savestr(cp) register char *cp; {
        register int len;
 
        len = strlen(cp) + 1;
@@ -425,10 +439,7 @@ savestr(cp)
        return (cp);
 }
 
-char *
-strspl(left, right)
-       char *left, *right;
-{
+char *strspl(left, right) char *left, *right; {
        char buf[BUFSIZ];
 
        strcpy(buf, left);
diff --git a/bin/cc/cc.h b/bin/cc/cc.h
new file mode 100644 (file)
index 0000000..97d490b
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _CC_H
+#define _CC_H 1
+
+#ifndef PARAMS
+#ifdef PDP11
+#define PARAMS(params) ()
+#else
+#define PARAMS(params) params
+#endif
+#endif
+
+int main PARAMS((int argc, char **argv));
+int idexit PARAMS((void));
+void dexit PARAMS((void));
+void error PARAMS((char *s, char *x));
+int getsuf PARAMS((char as[]));
+char *setsuf PARAMS((char *as, int ch));
+int callsys PARAMS((char *f, char **v));
+int nodup PARAMS((char **l, char *os));
+char *savestr PARAMS((register char *cp));
+char *strspl PARAMS((char *left, char *right));
+
+#endif
diff --git a/bin/cc/krcompat.h b/bin/cc/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
diff --git a/bin/cc/n.sh b/bin/cc/n.sh
new file mode 100755 (executable)
index 0000000..195dff1
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/bin\/cc$//'`"
+DESTDIR="$ROOT/host"
+STAGEDIR="$ROOT/stage"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/bin"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" STAGEDIR="$STAGEDIR" CFLAGS="$CFLAGS" install
index 7e95042..f94ca66 100644 (file)
@@ -1,19 +1,25 @@
 # Version 2.2 January 24, 1998
 
-SRCS=  ld.c
-OBJS=  ld.o
-MAN=   ld.0
-MANSRC=        ld.1
-CFLAGS=        -O -I../ar -DNUM_VM_PAGES=20
+VPATH=../../lib/libc/pdp/gen
+SRCS=ld.c nsym.c
+OBJS=ld.o nsym.o
+MAN=ld.0
+MANSRC=ld.1
+
+CFLAGS=-O
+CPPFLAGS=-Iinclude -I../ar -DNUM_VM_PAGES=20
+SEPFLAG=-i
 
 all:   ld ld.0
 
 ld: ${OBJS}
-       cc -i -o ld ${OBJS} -lvmf
+       ${CC} ${SEPFLAG} ${LDFLAGS} -o ld ${OBJS} -lvmf
 
 install: all
-       install -c -s -o bin -g bin -m 755 ld ${DESTDIR}/bin/ld
-       install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat1
+#      install -c -s -o bin -g bin -m 755 ld ${DESTDIR}/bin/ld
+#      install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat1
+       install -c -s -m 755 ld ${DESTDIR}/bin/ld
+       install -c -m 444 ${MAN} ${DESTDIR}/usr/man/cat1
 
 lint:
        lint -havx -I../ar ${SRCS}
@@ -22,4 +28,5 @@ clean:
        rm -f ${OBJS} ${MAN} ld
 
 ${MAN}: ${MANSRC}
-       /usr/man/manroff ${MANSRC} > ${MAN}
+#      /usr/man/manroff ${MANSRC} > ${MAN}
+       nroff -man ${MANSRC} > ${MAN}
diff --git a/bin/ld/include/a.out.h b/bin/ld/include/a.out.h
new file mode 120000 (symlink)
index 0000000..9dd9aa8
--- /dev/null
@@ -0,0 +1 @@
+../../../include/a.out.h
\ No newline at end of file
diff --git a/bin/ld/include/ar.h b/bin/ld/include/ar.h
new file mode 120000 (symlink)
index 0000000..7245d58
--- /dev/null
@@ -0,0 +1 @@
+../../../include/ar.h
\ No newline at end of file
diff --git a/bin/ld/include/nlist.h b/bin/ld/include/nlist.h
new file mode 120000 (symlink)
index 0000000..0c27973
--- /dev/null
@@ -0,0 +1 @@
+../../../include/nlist.h
\ No newline at end of file
diff --git a/bin/ld/include/ranlib.h b/bin/ld/include/ranlib.h
new file mode 120000 (symlink)
index 0000000..bce4b4b
--- /dev/null
@@ -0,0 +1 @@
+../../../include/ranlib.h
\ No newline at end of file
diff --git a/bin/ld/include/sys/exec.h b/bin/ld/include/sys/exec.h
new file mode 120000 (symlink)
index 0000000..0f3c005
--- /dev/null
@@ -0,0 +1 @@
+../../../../sys/h/exec.h
\ No newline at end of file
diff --git a/bin/ld/include/vmf.h b/bin/ld/include/vmf.h
new file mode 120000 (symlink)
index 0000000..9594a15
--- /dev/null
@@ -0,0 +1 @@
+../../../include/vmf.h
\ No newline at end of file
diff --git a/bin/ld/krcompat.h b/bin/ld/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
index ec98e5e..84a9d6a 100644 (file)
@@ -66,7 +66,9 @@ static char *sccsid = "@(#)ld.c       4.6 1998/01/19";
 #include <vmf.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <string.h>
 #include "archive.h"
+#include "krcompat.h"
 
 /*
  *     Layout of standard part of a.out file header:
@@ -291,16 +293,49 @@ u_int     ovbase;                 /* The base address of the overlays */
 
        struct  vspace  Vspace; /* The virtual address space for symbols */
 
-       short   *lookup(), *slookup(), *lookloc();
        char    *rstrtab;       /* ranlib string table pointer */
-       u_int   add();
-       int     delexit();
-       VADDR   sym2va();
-       off_t   skip();
-
-main(argc, argv)
-char **argv;
-{
+
+int main PARAMS((int argc, char **argv));
+int delexit PARAMS((void));
+void endload PARAMS((int argc, char **argv));
+VADDR sym2va PARAMS((int x));
+void load1arg PARAMS((register char *cp, int flag));
+int step PARAMS((off_t nloc));
+int ldrand PARAMS((int totnum, off_t sloc));
+void mgets PARAMS((register char *buf, int maxlen, int which));
+int load1 PARAMS((int libflg, off_t loc));
+void middle PARAMS((void));
+void ldrsym PARAMS((int ix, u_int val, int type));
+void setupout PARAMS((void));
+void load2arg PARAMS((char *acp, int flag));
+void load2 PARAMS((long loc));
+void load2td PARAMS((struct local *lp, u_int creloc, FILE *b1, FILE *b2));
+void finishout PARAMS((void));
+long rnd8k PARAMS((u_int siz));
+void mkfsym PARAMS((char *s));
+void mget PARAMS((register int *loc, int an, int which));
+void dseek PARAMS((int which, off_t aloc, int s));
+int get PARAMS((int which));
+int getfile PARAMS((char *acp, int flag, int phase));
+int libopen PARAMS((char *name, int oflags));
+short *lookup PARAMS((void));
+short *slookup PARAMS((char *s));
+int enter PARAMS((short *hp));
+void error PARAMS((int n, char *s));
+void readhdr PARAMS((off_t loc));
+void tcreat PARAMS((FILE **fpp, int tempflg));
+int adrof PARAMS((char *s));
+void copy PARAMS((register FILE *fp));
+short *lookloc PARAMS((struct local *alp, int r));
+void roundov PARAMS((void));
+u_int add PARAMS((int a, int b, char *s));
+int get_arobj PARAMS((int fd));
+off_t skip PARAMS((void));
+void inistr PARAMS((int which));
+
+static void hreset PARAMS((void));
+       
+int main(argc, argv) int argc; char **argv; {
        register int c, i;
        int num;
        register char *ap, **p;
@@ -325,8 +360,8 @@ char **argv;
        Input[SYMBOLS].bsize = 512;
 
        if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
-               signal(SIGINT, delexit);
-               signal(SIGTERM, delexit);
+               signal(SIGINT, (sig_t)delexit);
+               signal(SIGTERM, (sig_t)delexit);
        }
        if (argc == 1)
                exit(4);
@@ -494,9 +529,7 @@ next:
        exit(0);
 }
 
-delexit()
-       {
-
+int delexit() {
        unlink("l.out");
        if (delarg==0)
                chmod(ofilename, 0777 & ~umask(0));
@@ -504,12 +537,9 @@ delexit()
                printf("ld: nswaps: %ld, nmapsegs: %ld sbrk(0): %u\n", nswaps, 
                        nmapsegs, sbrk(0));
        exit(delarg);
-       }
+}
 
-endload(argc, argv)
-       int argc;
-       char **argv;
-{
+void endload(argc, argv) int argc; char **argv; {
        register int c, i;
        int dnum;
        register char *ap, **p;
@@ -581,24 +611,18 @@ next:
  * size does not divide evenly by the size of a symbol.
 */
 
-VADDR
-sym2va(x)
-       u_short x;
-       {
+VADDR sym2va(x) u_short        x; {
        register u_short i, j;
 
        i = (x % SYMSPERSEG) * sizeof (SYMBOL);
        j = x / SYMSPERSEG;
        return(SYMTAB+ i + ((long)j << LOG2BPS));
-       }
+}
 
 /*
  * Scan file to find defined symbols.
  */
-load1arg(cp, flag)
-       register char *cp;
-       int flag;
-       {
+void load1arg(cp, flag) register char *cp; int flag; {
        off_t nloc;
        int kind, tnum;
        long    ltnum, strsize;
@@ -698,10 +722,7 @@ load1arg(cp, flag)
  * is useful, record its location in the liblist structure
  * for use in pass2.  Mark the end of the archive in libilst with a -1.
  */
-step(nloc)
-       off_t nloc;
-       {
-
+int step(nloc) off_t nloc; {
        lseek(infil, nloc, L_SET);
        if      (get_arobj(infil) <= 0)
                {
@@ -717,12 +738,9 @@ step(nloc)
                        printf("\t%s\n", chdr.name);
                }
        return (1);
-       }
+}
 
-ldrand(totnum, sloc)
-       int     totnum;
-       off_t   sloc;
-       {
+int ldrand(totnum, sloc) int totnum; off_t sloc; {
        register int ntab;
        SYMBOL  *sp;
        short   *hp;
@@ -785,12 +803,9 @@ ldrand(totnum, sloc)
                        }
                }
        return(oldp != libp);
-       }
+}
 
-mgets(buf, maxlen, which)
-       register char *buf;
-       int     maxlen, which;
-       {
+void mgets(buf, maxlen, which) register char *buf; int maxlen; int which; {
        register STREAM *sp;
        register int n;
 
@@ -805,14 +820,12 @@ mgets(buf, maxlen, which)
                if      ((*buf++ = *sp->Cptr++) == 0)
                        break;
                }
-       }
+}
 
 /*
  * Examine a single file or archive member on pass 1.
  */
-load1(libflg, loc)
-       off_t loc;
-{
+int load1(libflg, loc) int libflg; off_t loc; {
        register SYMBOL *sp;
        int savindex;
        int ndef, type, mtype;
@@ -822,7 +835,7 @@ load1(libflg, loc)
        off_t   strloc;
        long    strsize;
        char    *strtab;
-register struct vseg *seg;
+       register struct vseg *seg;
 
        readhdr(loc);
        if (filhdr.e.a_syms == 0) {
@@ -960,9 +973,7 @@ register struct vseg *seg;
        return(0);
 }
 
-static
-hreset()
-       {
+static void hreset() {
        register u_short *sp, i;
        u_short j;
        register u_short mask;
@@ -982,10 +993,9 @@ hreset()
                        mask <<= 1;
                        }
                }
-       }
+}
 
-middle()
-{
+void middle() {
        VADDR   vsym;
        register SYMBOL *sp;
        register int    i;
@@ -1152,11 +1162,7 @@ middle()
        nsym = ssize / (sizeof cursym);
 }
 
-ldrsym(ix, val, type)
-       short   ix;
-       u_int   val;
-       int     type;
-{
+void ldrsym(ix, val, type) int ix; u_int val; int type; {
        VADDR   vsym;
        register struct vseg *seg;
        register SYMBOL *sp;
@@ -1176,13 +1182,14 @@ ldrsym(ix, val, type)
        VMMODIFY(seg);
 }
 
-setupout()
-{
+void setupout() {
        VADDR   vsym;
        register SYMBOL *sp;
 
        tcreat(&toutb, 0);
+#if 0 /* see tcreat */
        mktemp(tfname);
+#endif
        tcreat(&doutb, 1);
        if (sflag==0 || xflag==0)
                tcreat(&soutb, 1);
@@ -1225,10 +1232,7 @@ setupout()
                fwrite(&filhdr.o, sizeof (filhdr.o), 1, toutb);
 }
 
-load2arg(acp, flag)
-       char *acp;
-       int flag;
-{
+void load2arg(acp, flag) char *acp; int flag; {
        register char *cp;
        register LIBLIST *lp;
 
@@ -1259,9 +1263,7 @@ load2arg(acp, flag)
        close(infil);
 }
 
-load2(loc)
-long loc;
-{
+void load2(loc) long loc; {
        register SYMBOL *sp;
        register struct local *lp;
        register int symno;
@@ -1395,11 +1397,7 @@ long loc;
        borigin += filhdr.e.a_bss;
 }
 
-load2td(lp, creloc, b1, b2)
-       struct local *lp;
-       u_int creloc;
-       FILE *b1, *b2;
-{
+void load2td(lp, creloc, b1, b2) struct local *lp; u_int creloc; FILE *b1; FILE *b2; {
        register u_int r, t;
        register SYMBOL *sp;
        short   i;
@@ -1479,8 +1477,7 @@ load2td(lp, creloc, b1, b2)
        }
 }
 
-finishout()
-{
+void finishout() {
        register u_int n;
        register SYMBOL *sp;
        struct  nlist objsym;
@@ -1654,38 +1651,29 @@ finishout()
        delexit();
 }
 
-long
-rnd8k(siz)
-       u_int siz;
-       {
+long rnd8k(siz) u_int siz; {
        long l = siz;
 
        return((l + 017777) & ~017777L);
-       }
-
-mkfsym(s)
-       char *s;
-       {
+}
 
+void mkfsym(s) char *s; {
        if (sflag || xflag)
                return;
        strncpy(cursym.n_name, s, NNAMESIZE);
        cursym.n_type = N_FN;
        cursym.n_value = torigin;
        fwrite(&cursym, sizeof (cursym), 1, soutb);
-       }
+}
 
-mget(loc, an, which)
-       register int *loc;
-       int an, which;
-{
+void mget(loc, an, which) register int *loc; int an; int which; {
        register int n;
        register STREAM *tp = &Input[which];
 
        n = an >> 1;
        if ((tp->nibuf -= n) >= 0) {
                if ((tp->nsize -= n) > 0) {
-                       bcopy(tp->ptr, loc, an);
+                       bcopy(tp->ptr.cptr, loc, an);
                        tp->Iptr += n;
                        return;
                }
@@ -1697,11 +1685,7 @@ mget(loc, an, which)
        } while (--n);
 }
 
-dseek(which, aloc, s)
-       int which;
-       off_t aloc;
-       int s;
-       {
+void dseek(which, aloc, s) int which; off_t aloc; int s; {
        register STREAM *sp = &Input[which];
        register u_int b, o;
        int n;
@@ -1724,11 +1708,9 @@ dseek(which, aloc, s)
                sp->nsize = (s >> 1) & 077777;
        if      (sp->nibuf <= 0)
                sp->nsize = 0;
-       }
+}
 
-get(which)
-       int which;
-{
+int get(which) int which; {
        register STREAM *sp = &Input[which];
 
        if (--sp->nibuf < 0) {
@@ -1742,10 +1724,7 @@ get(which)
        return(*sp->Iptr++);
 }
 
-getfile(acp, flag, phase)
-char *acp;
-       int flag;       /* 1 = fatal if file not found, -1 = not fatal */
-{
+int getfile(acp, flag, phase) char *acp; int flag; int phase; { /* flag 1 = fatal if file not found, -1 = not fatal */
        char arcmag[SARMAG+1];
        struct stat stb;
 
@@ -1768,7 +1747,7 @@ char *acp;
        dseek(TEXT, 0L, SARMAG);
        if (Input[TEXT].nsize <= 0)
                error(1, "premature EOF#2");
-       mget((char *)arcmag, SARMAG, TEXT);
+       mget((int *)arcmag, SARMAG, TEXT);
        arcmag[SARMAG] = 0;
        if (strcmp(arcmag, ARMAG))
                return(0);
@@ -1784,10 +1763,7 @@ char *acp;
  * Search for a library with given name
  * using the directory search array.
  */
-libopen(name, oflags)
-       char *name;
-       int oflags;
-{
+int libopen(name, oflags) char *name; int oflags; {
        register char *p, *cp;
        register int i;
        static char buf[100];
@@ -1815,9 +1791,7 @@ libopen(name, oflags)
        return(-1);
 }
 
-short *
-lookup()
-       {
+short *lookup() {
        register short *hp;
        register char *cp;
        SYMBOL  *sp;
@@ -1844,22 +1818,16 @@ lookup()
                        hp = hshtab;
                }
        return(hp);
-       }
-
-short *
-slookup(s)
-       char *s;
-       {
+}
 
+short *slookup(s) char *s; {
        strncpy(cursym.n_name, s, NNAMESIZE);
        cursym.n_type = N_EXT+N_UNDF;
        cursym.n_value = 0;
        return(lookup());
-       }
+}
 
-enter(hp)
-       short   *hp;
-       {
+int enter(hp) short *hp; {
        register SYMBOL *sp;
        u_int word, bit, hnum;
        VADDR   vsym;
@@ -1894,11 +1862,9 @@ enter(hp)
                }
        lastsym = *hp;
        return(0);
-       }
+}
 
-error(n, s)
-char *s;
-{
+void error(n, s) int n; char *s; {
        if (!s)
                delexit();
        if (errlev==0)
@@ -1917,9 +1883,7 @@ char *s;
        errlev = 2;
 }
 
-readhdr(loc)
-off_t loc;
-{
+void readhdr(loc) off_t loc; {
        dseek(TEXT, loc, sizeof filhdr);
        mget((int *)&filhdr.e, sizeof filhdr.e, TEXT);
        if (filhdr.e.a_magic != A_MAGIC1)
@@ -1934,24 +1898,31 @@ off_t loc;
        cbrel = cdrel - filhdr.e.a_data;
 }
 
-tcreat(fpp, tempflg)
-       FILE    **fpp;
-       int     tempflg;
-       {
+void tcreat(fpp, tempflg) FILE **fpp; int tempflg; {
        register int ufd;
+#if 0
        char    *nam;
+#endif
 
+#if 1
+       if (tempflg) {
+               if ((ufd = mkstemp(tfname)) < 0)
+                       error(2, "cannot create temp");
+               unlink(tfname);
+       }
+       else if ((ufd = open(ofilename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
+               error(2, "cannot create output");
+#else
        nam = (tempflg ? tfname : ofilename);
        if      ((ufd = open(nam, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
                error(2, tempflg?"cannot create temp":"cannot create output");
        if      (tempflg)
                unlink(tfname);
+#endif
        *fpp = fdopen(ufd, "r+");
-       }
+}
 
-adrof(s)
-       char *s;
-       {
+int adrof(s) char *s; {
        register short *p;
        register SYMBOL *sp;
        VADDR   vsym;
@@ -1965,11 +1936,9 @@ adrof(s)
        vsym = sym2va(*p);
        sp = (SYMBOL *)(vmmapseg(&Vspace, VSEG(vsym))->s_cinfo + VOFF(vsym));
        return(sp->n_value);
-       }
+}
 
-copy(fp)
-       register FILE   *fp;
-       {
+void copy(fp) register FILE *fp; {
        register int c;
 
        fflush(fp);
@@ -1977,12 +1946,9 @@ copy(fp)
        while   ((c = getc(fp)) != EOF)
                putc(c, toutb);
        fclose(fp);
-       }
+}
 
-short *
-lookloc(alp, r)
-struct local *alp;
-{
+short *lookloc(alp, r) struct local *alp; int r; {
        register struct local *clp, *lp;
        register int sn;
 
@@ -1993,23 +1959,18 @@ struct local *alp;
                        return(&clp->locsymbol);
        error(1, "local symbol botch");
        /*NOTREACHED*/
+       return NULL; /* keep the compiler happy */
 }
 
-roundov()
-       {
-
+void roundov() {
        while   (torigin & 077)
                {
                putw(0, voutb);
                torigin += sizeof (int);
                }
-       }
+}
 
-u_int
-add(a,b,s)
-int a, b;
-char *s;
-{
+u_int add(a,b,s) int a; int b; char *s; {
        long r;
        register char *ap;
 
@@ -2045,9 +2006,7 @@ static char hb[sizeof(HDR) + 1];  /* real header */
  * get_arobj --
  *     read the archive header for this member
  */
-get_arobj(fd)
-       int fd;
-{
+int get_arobj(fd) int fd; {
        HDR *hdr;
        register int len, nr;
        register char *p;
@@ -2102,19 +2061,15 @@ get_arobj(fd)
 /*
  * skip - where to seek for next archive member.
  */
-off_t
-skip()
-       {
+off_t skip() {
        off_t len;
 
        len = chdr.size + (chdr.size + chdr.lname & 1);
        len += sizeof (HDR);
        return(len);
-       }
+}
 
-inistr(which)
-       int     which;
-       {
+void inistr(which) int which; {
        register STREAM *sp = &Input[which];
        register int    size = 4096;
 
@@ -2132,4 +2087,4 @@ inistr(which)
                        }
                error(1, "No memory for strings");
                }
-       }
+}
diff --git a/bin/ld/n.sh b/bin/ld/n.sh
new file mode 100755 (executable)
index 0000000..dd60a00
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/bin\/ld$//'`"
+DESTDIR="$ROOT/host"
+STAGEDIR="$ROOT/stage"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/bin"
+mkdir --parents "$DESTDIR/usr/man/cat1"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" STAGEDIR="$STAGEDIR" CFLAGS="$CFLAGS" LDFLAGS="-L$DESTDIR/usr/lib" install
index d497478..19f09ee 100644 (file)
@@ -1,14 +1,19 @@
-SRCS=  nm.c
-OBJS=  nm.o
-CFLAGS=        -O -I../ar
+VPATH=../../lib/libc/pdp/gen
+SRCS=nm.c nsym.c
+OBJS=nm.o nsym.o
+
+CFLAGS=-O
+CPPFLAGS=-Iinclude -I../ar
+SEPFLAG=-i
 
 all:   nm
 
 nm: ${OBJS}
-       cc -z -o nm ${OBJS}
+       cc ${SEPFLAG} -o nm ${OBJS}
 
-install:
-       install -c -s -o bin -g bin -m 755 nm ${DESTDIR}/bin/nm
+install: all
+#      install -c -s -o bin -g bin -m 755 nm ${DESTDIR}/bin/nm
+       install -c -s -m 755 nm ${DESTDIR}/bin/nm
 
 lint:
        lint -havx -I../ar ${SRCS}
diff --git a/bin/nm/include/a.out.h b/bin/nm/include/a.out.h
new file mode 120000 (symlink)
index 0000000..9dd9aa8
--- /dev/null
@@ -0,0 +1 @@
+../../../include/a.out.h
\ No newline at end of file
diff --git a/bin/nm/include/ar.h b/bin/nm/include/ar.h
new file mode 120000 (symlink)
index 0000000..7245d58
--- /dev/null
@@ -0,0 +1 @@
+../../../include/ar.h
\ No newline at end of file
diff --git a/bin/nm/include/nlist.h b/bin/nm/include/nlist.h
new file mode 120000 (symlink)
index 0000000..0c27973
--- /dev/null
@@ -0,0 +1 @@
+../../../include/nlist.h
\ No newline at end of file
diff --git a/bin/nm/include/sys/exec.h b/bin/nm/include/sys/exec.h
new file mode 120000 (symlink)
index 0000000..0f3c005
--- /dev/null
@@ -0,0 +1 @@
+../../../../sys/h/exec.h
\ No newline at end of file
diff --git a/bin/nm/krcompat.h b/bin/nm/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
diff --git a/bin/nm/n.sh b/bin/nm/n.sh
new file mode 100755 (executable)
index 0000000..ec4a716
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/bin\/nm$//'`"
+DESTDIR="$ROOT/host"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/bin"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install
index 62343ab..ea0e9fd 100644 (file)
@@ -1,4 +1,4 @@
-#if    !defined(lint) && !defined(DOSCCS)
+#if    !defined(lint) && defined(DOSCCS)
 static char sccsid[] = "@(#)nm.c 2.11BSD 1/22/94";
 #endif
 /*
@@ -12,7 +12,9 @@ static        char sccsid[] = "@(#)nm.c 2.11BSD 1/22/94";
 #include <a.out.h>
 #include <sys/file.h>
 #include "archive.h"
+#include <stdlib.h>
 #include <string.h>
+#include "krcompat.h"
 
        CHDR    chdr;
 
@@ -26,17 +28,18 @@ static      char sccsid[] = "@(#)nm.c 2.11BSD 1/22/94";
                struct  xexec mag_exp;
        } mag_un;
 
-       off_t   off, skip();
-extern off_t   ftell();
-extern char    *malloc();
-extern long    strtol();
-       int     compare(), narg, errs;
+       off_t   off;
+       int     narg, errs;
 
-main(argc, argv)
-       int     argc;
-       char    **argv;
-{
+int main PARAMS((int argc, char **argv));
+void namelist PARAMS((void));
+void psyms PARAMS((register struct nlist *symp, int nsyms));
+int compare PARAMS((register struct nlist *p1, register struct nlist *p2));
+int nextel PARAMS((FILE *af));
+void error PARAMS((int n, char *s));
+int _get_arobj PARAMS((FILE *fp));
 
+int main(argc, argv) int argc; char **argv; {
        if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
                argv++;
                while (*++*argv) switch (**argv) {
@@ -82,8 +85,7 @@ main(argc, argv)
        exit(errs);
 }
 
-namelist()
-{
+void namelist() {
        char    ibuf[BUFSIZ];
        register FILE   *fi;
 
@@ -115,7 +117,7 @@ namelist()
        do {
                off_t   o, curpos, stroff;
                long    strsiz;
-               register i, n;
+               register int i, n;
                struct nlist *symp = NULL;
                struct  nlist sym;
 
@@ -175,7 +177,7 @@ namelist()
                        symp[n].n_un.n_name = strp + (int)symp[n].n_un.n_strx;
 
                if (pflg==0)
-                       qsort(symp, i, sizeof(struct nlist), compare);
+                       qsort(symp, i, sizeof(struct nlist), (int (*) PARAMS((const void *, const void *)))compare);
                if ((archive || narg>1) && oflg==0)
                        printf("\n%s:\n", SELECT);
                psyms(symp, i);
@@ -188,10 +190,7 @@ out:
        fclose(fi);
 }
 
-psyms(symp, nsyms)
-       register struct nlist *symp;
-       int nsyms;
-{
+void psyms(symp, nsyms) register struct nlist *symp; int nsyms; {
        register int n, c;
 
        for (n=0; n<nsyms; n++) {
@@ -248,10 +247,7 @@ psyms(symp, nsyms)
        }
 }
 
-compare(p1, p2)
-register struct nlist *p1, *p2;
-{
-
+int compare(p1, p2) register struct nlist *p1; register struct nlist *p2; {
        if (nflg) {
                if (p1->n_value > p2->n_value)
                        return(rflg);
@@ -261,21 +257,16 @@ register struct nlist *p1, *p2;
        return (rflg * strcmp(p1->n_un.n_name, p2->n_un.n_name));
 }
 
-nextel(af)
-FILE *af;
-{
-       
+int nextel(af) FILE *af; {
        fseek(af, off, L_SET);
-       if (get_arobj(af) < 0)
+       if (_get_arobj(af) < 0)
                return(0);
        off += (sizeof (struct ar_hdr) + chdr.size + 
                (chdr.size + chdr.lname & 1));
        return(1);
 }
 
-error(n, s)
-char *s;
-{
+void error(n, s) int n; char *s; {
        fprintf(stderr, "nm: %s:", *xargv);
        if (archive) {
                fprintf(stderr, "(%s)", chdr.name);
@@ -309,9 +300,7 @@ static char hb[sizeof(HDR) + 1];    /* real header */
  *     read the archive header for this member.  Use a file pointer 
  *     rather than a file descriptor.
  */
-get_arobj(fp)
-       FILE *fp;
-{
+int _get_arobj(fp) FILE *fp; {
        HDR *hdr;
        register int len, nr;
        register char *p;
index 50f1754..3b5c60d 100644 (file)
  * must pass an extended header ('xexec') as the argument.
 */
 
+#ifdef pdp11
 #include <sys/types.h>
+#else
+#define off_t long
+#endif
 
-off_t  n_stroff(), n_symoff(), n_datoff(), n_dreloc(), n_treloc();
+#undef PARAMS
+#ifdef __STDC__
+#define PARAMS(args) args
+#else
+#define PARAMS(args) ()
+#endif
 
-#define        N_STROFF(e) (n_stroff(&e))
-#define        N_SYMOFF(e) (n_symoff(&e))
-#define        N_DATOFF(e) (n_datoff(&e))
-#define        N_DRELOC(e) (n_dreloc(&e))
-#define        N_TRELOC(e) (n_treloc(&e))
+long n_stroff PARAMS((register struct xexec *ep));
+long n_datoff PARAMS((register struct xexec *ep));
+long n_dreloc PARAMS((register struct xexec *ep));
+long n_treloc PARAMS((register struct xexec *ep));
+long n_symoff PARAMS((register struct xexec *ep));
+
+#ifndef pdp11
+#undef off_t
+#endif
+
+#define        N_STROFF(e) (n_stroff((struct xexec *)&e))
+#define        N_SYMOFF(e) (n_symoff((struct xexec *)&e))
+#define        N_DATOFF(e) (n_datoff((struct xexec *)&e))
+#define        N_DRELOC(e) (n_dreloc((struct xexec *)&e))
+#define        N_TRELOC(e) (n_treloc((struct xexec *)&e))
 
 #define        _AOUT_INCLUDE_
 #include <nlist.h>
index 2001be8..40d6ce2 100644 (file)
@@ -35,7 +35,7 @@ extern        struct  _iobuf {
 #define        stderr  (&_iob[2])
 #ifndef lint
 #define        getc(p)         (--(p)->_cnt>=0? (int)(*(unsigned char *)(p)->_ptr++):_filbuf(p))
-#endif not lint
+#endif /* not lint */
 #define        getchar()       getc(stdin)
 #ifndef lint
 #define putc(x, p)     (--(p)->_cnt >= 0 ?\
@@ -45,7 +45,7 @@ extern        struct  _iobuf {
                        (int)(*(unsigned char *)(p)->_ptr++) :\
                        _flsbuf(*(unsigned char *)(p)->_ptr, p)) :\
                _flsbuf((unsigned char)(x), p)))
-#endif not lint
+#endif /* not lint */
 #define        putchar(x)      putc(x,stdout)
 #define        feof(p)         (((p)->_flag&_IOEOF)!=0)
 #define        ferror(p)       (((p)->_flag&_IOERR)!=0)
index 17d7fc5..1d4e59b 100644 (file)
@@ -50,13 +50,25 @@ struct      vseg {                    /* structure of a segment in memory */
 /* masks for s_flags */
 #define S_DIRTY 01                     /* segment has been modified */
 
-       long    nswaps;                 /* number of swaps */
-       long    nmapsegs;               /* number of mapseg calls */
+extern long nswaps;            /* number of swaps */
+extern long nmapsegs;          /* number of mapseg calls */
 
-       int     vminit(), vmopen();
-       struct  vseg    *vmmapseg();
-       void    vmlock(), vmunlock(), vmclrseg(), vmmodify();
-       void    vmflush(), vmclose();
+#undef PARAMS
+#ifdef __STDC__
+#define PARAMS(args) args
+#else
+#define PARAMS(args) ()
+#endif
+
+int vminit PARAMS((int n));
+struct vseg *vmmapseg PARAMS((struct vspace *vspace, int segno));
+void vmclrseg PARAMS((register struct vseg *seg));
+void vmlock PARAMS((register struct vseg *seg));
+void vmunlock PARAMS((register struct vseg *seg));
+void vmmodify PARAMS((register struct vseg *seg));
+void vmflush PARAMS((void));
+int vmopen PARAMS((register struct vspace *vs, char *filename));
+void vmclose PARAMS((register struct vspace *vs));
 
 typedef        long    VADDR;
 #define        VMMODIFY(seg) (seg->s_flags |= S_DIRTY)
index 8d0ad2e..6942bda 100644 (file)
@@ -6,7 +6,11 @@
  *     larger symbols passed thru from the compiler.
  */
 
+#ifndef _C2_H
+#define _C2_H 1
+
 #include <stdio.h>
+#include "krcompat.h"
 
 #define        MAXCPS  32
 
@@ -89,45 +93,45 @@ struct node {
        int     refc;
 };
 
-struct optab {
+extern struct optab {
        char    *opstring;
        int     opcode;
 } optab[];
 
-char   line[LSIZE];
-struct node    first;
-char   *curlp;
-int    nbrbr;
-int    nsaddr;
-int    redunm;
-int    iaftbr;
-int    njp1;
-int    nrlab;
-int    nxjump;
-int    ncmot;
-int    nrevbr;
-int    loopiv;
-int    nredunj;
-int    nskip;
-int    ncomj;
-int    nsob;
-int    nrtst;
-int    nlit;
+extern char line[LSIZE];
+extern struct node first;
+extern char *curlp;
+extern int nbrbr;
+extern int nsaddr;
+extern int redunm;
+extern int iaftbr;
+extern int njp1;
+extern int nrlab;
+extern int nxjump;
+extern int ncmot;
+extern int nrevbr;
+extern int loopiv;
+extern int nredunj;
+extern int nskip;
+extern int ncomj;
+extern int nsob;
+extern int nrtst;
+extern int nlit;
 
-int    nchange;
-int    isn;
-int    debug;
-int    lastseg;
-char   *lasta;
-char   *lastr;
-char   *alasta;
-char   *alastr;
-char   *firstr;
-char   revbr[];
-char   regs[12][MAXCPS + 1];
-char   conloc[MAXCPS + 1];
-char   conval[MAXCPS + 1];
-char   ccloc[MAXCPS + 1];
+extern int nchange;
+extern int isn;
+extern int debug;
+extern int lastseg;
+extern char *lasta;
+extern char *lastr;
+extern char *alasta;
+extern char *alastr;
+extern char *firstr;
+extern char revbr[];
+extern char regs[12][MAXCPS + 1];
+extern char conloc[MAXCPS + 1];
+extern char conval[MAXCPS + 1];
+extern char ccloc[MAXCPS + 1];
 
 #define        RT1     10
 #define        RT2     11
@@ -136,12 +140,57 @@ char      ccloc[MAXCPS + 1];
 #define        LABHS   127
 #define        OPHS    57
 
-struct optab *ophash[OPHS];
-struct node *nonlab();
-char   *copy();
-char   *sbrk();
-char   *findcon();
-struct node *insertl();
-struct node *codemove();
-char   *sbrk();
-char   *alloc();
+extern struct optab *ophash[OPHS];
+
+/* c20.c */
+int main PARAMS((int argc, char **argv));
+int input PARAMS((void));
+int _getline PARAMS((void));
+int getnum PARAMS((char *ap));
+void output PARAMS((void));
+void reducelit PARAMS((struct node *at));
+char *copy PARAMS((int na, ...));
+void opsetup PARAMS((void));
+int oplook PARAMS((void));
+void refcount PARAMS((void));
+void iterate PARAMS((void));
+void xjump PARAMS((register struct node *p1));
+struct node *insertl PARAMS((register struct node *oldp));
+struct node *codemove PARAMS((struct node *p));
+void comjump PARAMS((void));
+void backjmp PARAMS((struct node *ap1, struct node *ap2));
+/* c21.c */
+void rmove PARAMS((void));
+void fixupbr PARAMS((register struct node *p));
+int jumpsw PARAMS((void));
+void addsob PARAMS((void));
+int toofar PARAMS((struct node *p));
+int ilen PARAMS((register struct node *p));
+int adrlen PARAMS((register char *s));
+int abs PARAMS((register int x));
+int equop PARAMS((struct node *ap1, struct node *p2));
+void decref PARAMS((register struct node *p));
+struct node *nonlab PARAMS((register struct node *p));
+char *alloc PARAMS((register int n));
+void clearreg PARAMS((void));
+void savereg PARAMS((int ai, char *as));
+void dest PARAMS((char *as, int flt));
+void singop PARAMS((struct node *ap));
+void dualop PARAMS((struct node *ap));
+int findrand PARAMS((char *as, int flt));
+int isreg PARAMS((char *as));
+void check PARAMS((void));
+int source PARAMS((char *ap));
+void repladdr PARAMS((struct node *p, int f, int flt));
+void movedat PARAMS((void));
+void redunbr PARAMS((register struct node *p));
+char *findcon PARAMS((int i));
+int compare PARAMS((int oper, register char *cp1, register char *cp2));
+void setcon PARAMS((char *ar1, char *ar2));
+int equstr PARAMS((char *ap1, char *ap2));
+void setcc PARAMS((char *ap));
+int natural PARAMS((char *ap));
+int xnatural PARAMS((char *ap));
+int not_sp PARAMS((register char *ap));
+
+#endif
index 2a2a32d..f36c4a1 100644 (file)
  *     @(#)    c20.c   2.0     (2.11BSD)       1996/6/12
  */
 
+#include <stdlib.h>
+#include <unistd.h>
 #include "c2.h"
 
 struct optab optab[] = {
-       "jbr",  JBR,
-       "jeq",  CBR | JEQ<<8,
-       "jne",  CBR | JNE<<8,
-       "jle",  CBR | JLE<<8,
-       "jge",  CBR | JGE<<8,
-       "jlt",  CBR | JLT<<8,
-       "jgt",  CBR | JGT<<8,
-       "jlo",  CBR | JLO<<8,
-       "jhi",  CBR | JHI<<8,
-       "jlos", CBR | JLOS<<8,
-       "jhis", CBR | JHIS<<8,
-       "jpl",  CBR | JPL << 8,
-       "jmi",  CBR | JMI << 8,
-       "jmp",  JMP,
-       ".globl",EROU,
-       "mov",  MOV,
-       "clr",  CLR,
-       "com",  COM,
-       "inc",  INC,
-       "dec",  DEC,
-       "neg",  NEG,
-       "tst",  TST,
-       "asr",  ASR,
-       "asl",  ASL,
-       "sxt",  SXT,
-       "cmp",  CMP,
-       "add",  ADD,
-       "sub",  SUB,
-       "bit",  BIT,
-       "bic",  BIC,
-       "bis",  BIS,
-       "mul",  MUL,
-       "div",  DIV,
-       "ash",  ASH,
-       "xor",  XOR,
-       ".text",TEXT,
-       ".data",DATA,
-       ".bss", BSS,
-       ".even",EVEN,
-       "movf", MOVF,
-       "movof",MOVOF,
-       "movfo",MOVFO,
-       "addf", ADDF,
-       "subf", SUBF,
-       "divf", DIVF,
-       "mulf", MULF,
-       "clrf", CLRF,
-       "cmpf", CMPF,
-       "negf", NEGF,
-       "tstf", TSTF,
-       "cfcc", CFCC,
-       "sob",  SOB,
-       "jsr",  JSR,
-       "swab", SWAB,
-       ".end", END,
-       0,      0};
+       {"jbr",         JBR},
+       {"jeq",         CBR | JEQ<<8},
+       {"jne",         CBR | JNE<<8},
+       {"jle",         CBR | JLE<<8},
+       {"jge",         CBR | JGE<<8},
+       {"jlt",         CBR | JLT<<8},
+       {"jgt",         CBR | JGT<<8},
+       {"jlo",         CBR | JLO<<8},
+       {"jhi",         CBR | JHI<<8},
+       {"jlos",        CBR | JLOS<<8},
+       {"jhis",        CBR | JHIS<<8},
+       {"jpl",         CBR | JPL << 8},
+       {"jmi",         CBR | JMI << 8},
+       {"jmp",         JMP},
+       {".globl",      EROU},
+       {"mov",         MOV},
+       {"clr",         CLR},
+       {"com",         COM},
+       {"inc",         INC},
+       {"dec",         DEC},
+       {"neg",         NEG},
+       {"tst",         TST},
+       {"asr",         ASR},
+       {"asl",         ASL},
+       {"sxt",         SXT},
+       {"cmp",         CMP},
+       {"add",         ADD},
+       {"sub",         SUB},
+       {"bit",         BIT},
+       {"bic",         BIC},
+       {"bis",         BIS},
+       {"mul",         MUL},
+       {"div",         DIV},
+       {"ash",         ASH},
+       {"xor",         XOR},
+       {".text",       TEXT},
+       {".data",       DATA},
+       {".bss",        BSS},
+       {".even",       EVEN},
+       {"movf",        MOVF},
+       {"movof",       MOVOF},
+       {"movfo",       MOVFO},
+       {"addf",        ADDF},
+       {"subf",        SUBF},
+       {"divf",        DIVF},
+       {"mulf",        MULF},
+       {"clrf",        CLRF},
+       {"cmpf",        CMPF},
+       {"negf",        NEGF},
+       {"tstf",        TSTF},
+       {"cfcc",        CFCC},
+       {"sob",         SOB},
+       {"jsr",         JSR},
+       {"swab",        SWAB},
+       {".end",        END},
+       {0,             0}
+};
 
 char revbr[] = {JNE, JEQ, JGT, JLT, JGE, JLE, JHIS, JLOS, JHI, JLO, JMI, JPL};
 int    isn     = 20000;
 int    lastseg = -1;
 
+char   line[LSIZE];
+struct node    first;
+char   *curlp;
+int    nbrbr;
+int    nsaddr;
+int    redunm;
+int    iaftbr;
+int    njp1;
+int    nrlab;
+int    nxjump;
+int    ncmot;
+int    nrevbr;
+int    loopiv;
+int    nredunj;
+int    nskip;
+int    ncomj;
+int    nsob;
+int    nrtst;
+int    nlit;
+
+int    nchange;
+int    debug;
+char   *lasta;
+char   *lastr;
+char   *alasta;
+char   *alastr;
+char   *firstr;
+char   regs[12][MAXCPS + 1];
+char   conloc[MAXCPS + 1];
+char   conval[MAXCPS + 1];
+char   ccloc[MAXCPS + 1];
+
+struct optab *ophash[OPHS];
+
 #define        NSTK    5000
 
-main(argc, argv)
-char **argv;
-{
+int main(argc, argv) int argc; char **argv; {
        register int niter, maxiter, isend;
-       extern end;
+       /*extern int end;*/
        int nflag;
        char    stspace[NSTK],
                buf1[BUFSIZ],
@@ -114,20 +149,31 @@ char **argv;
        do {
        alasta = stspace;
        alastr = &stspace[NSTK];
+ /*fprintf(stderr, "a\n"); fflush(stderr);*/
                isend = input();
+ /*fprintf(stderr, "b\n"); fflush(stderr);*/
                movedat();
                niter = 0;
                do {
+ /*fprintf(stderr, "c\n"); fflush(stderr);*/
                        refcount();
                        do {
+ /*fprintf(stderr, "d\n"); fflush(stderr);*/
                                iterate();
+ /*fprintf(stderr, "e\n"); fflush(stderr);*/
                                clearreg();
+ /*fprintf(stderr, "f\n"); fflush(stderr);*/
                                niter++;
                        } while (nchange);
+ /*fprintf(stderr, "g\n"); fflush(stderr);*/
                        comjump();
+ /*fprintf(stderr, "h\n"); fflush(stderr);*/
                        rmove();
+ /*fprintf(stderr, "i\n"); fflush(stderr);*/
                } while (nchange || jumpsw());
+ /*fprintf(stderr, "j\n"); fflush(stderr);*/
                addsob();
+ /*fprintf(stderr, "k\n"); fflush(stderr);*/
                output();
                if (niter > maxiter)
                        maxiter = niter;
@@ -151,19 +197,20 @@ char **argv;
                fprintf(stderr, "%d sob's added\t\t\t", nsob);
                fprintf(stderr, "%d redundant tst's\n", nrtst);
                fprintf(stderr, "%d literals eliminated\t\t", nlit);
+#ifdef PDP11
                fprintf(stderr, "%dK core\n", (((int)lastr+01777)>>10)&077);
+#endif
        }
        exit(0);
 }
 
-input()
-{
+int input() {
        register struct node *p, *lastp;
        register int oper;
 
        lastp = &first;
        for (;;) {
-               oper = getline();
+               oper = _getline();
                switch (oper&0377) {
 
                case LABEL:
@@ -217,10 +264,9 @@ input()
        }
 }
 
-getline()
-{
+int _getline() {
        register char *lp;
-       register c;
+       register int c;
 
        lp = line;
        while ((c = getchar())==' ' || c=='\t')
@@ -244,11 +290,9 @@ getline()
        return(END);
 }
 
-getnum(ap)
-char *ap;
-{
+int getnum(ap) char *ap; {
        register char *p;
-       register n, c;
+       register int n, c;
 
        p = ap;
        n = 0;
@@ -259,8 +303,7 @@ char *ap;
        return(n);
 }
 
-output()
-{
+void output() {
        register struct node *t;
        register struct optab *oper;
        register int byte;
@@ -329,9 +372,7 @@ output()
  * and replace them with (pc),xx(r)
  *     -- Thanx and a tip of the Hatlo hat to Bliss-11.
  */
-reducelit(at)
-struct node *at;
-{
+void reducelit(at) struct node *at; {
        register char *c1, *c2;
        char *c2s;
        register struct node *t;
@@ -355,13 +396,12 @@ struct node *at;
        nlit++;
 }
 
-char *
-copy(na, ap)
-char *ap;
-{
+#ifdef PDP11
+/* VARARGS1 */
+char *copy(na, ap) int na; int ap; {
        register char *p, *np;
        char *onp;
-       register n;
+       register int n;
 
        p = ap;
        n = 0;
@@ -386,9 +426,44 @@ char *ap;
        }
        return(onp);
 }
+#else
+char *copy(int na, ...) {
+       va_list ap;
+       char *a0, *a1;
+       register char *p, *np;
+       char *onp;
+       register int n;
+
+       va_start(ap, na);
+       a0 = va_arg(ap, char *);
+       p = a0;
+       n = 0;
+       if (*p==0)
+               return(0);
+       do
+               n++;
+       while (*p++);
+       if (na>1) {
+               a1 = va_arg(ap, char *);
+               p = a1;
+               while (*p++)
+                       n++;
+       }
+       onp = np = alloc(n);
+       p = a0;
+       while (*np++ = *p++)
+               ;
+       if (na>1) {
+               p = a1;
+               np--;
+               while (*np++ = *p++);
+       }
+       return(onp);
+}
+
+#endif
 
-opsetup()
-{
+void opsetup() {
        register struct optab *optp, **ophp;
        register char *p;
 
@@ -401,8 +476,7 @@ opsetup()
        }
 }
 
-oplook()
-{
+int oplook() {
        register struct optab *optp;
        register char *lp, *np;
        static char tmpop[32];
@@ -444,8 +518,7 @@ oplook()
        return(0);
 }
 
-refcount()
-{
+void refcount() {
        register struct node *p, *lp;
        static struct node *labhash[LABHS];
        register struct node **hp, *tp;
@@ -483,8 +556,7 @@ refcount()
                        decref(p);
 }
 
-iterate()
-{
+void iterate() {
        register struct node *p, *rp, *p1;
 
        nchange = 0;
@@ -560,9 +632,7 @@ iterate()
        }
 }
 
-xjump(p1)
-register struct node *p1;
-{
+void xjump(p1) register struct node *p1; {
        register struct node *p2, *p3;
 
        if ((p2 = p1->ref)==0)
@@ -584,10 +654,7 @@ register struct node *p1;
        }
 }
 
-struct node *
-insertl(oldp)
-register struct node *oldp;
-{
+struct node *insertl(oldp) register struct node *oldp; {
        register struct node *lp;
 
        if (oldp->op == LABEL) {
@@ -614,10 +681,7 @@ register struct node *oldp;
        return(lp);
 }
 
-struct node *
-codemove(p)
-struct node *p;
-{
+struct node *codemove(p) struct node *p; {
        register struct node *p1, *p2, *p3;
        struct node *t, *tl;
        int n;
@@ -693,8 +757,7 @@ ivloop:
        return(p3);
 }
 
-comjump()
-{
+void comjump() {
        register struct node *p1, *p2, *p3;
 
        for (p1 = first.forw; p1!=0; p1 = p1->forw)
@@ -704,9 +767,7 @@ comjump()
                                        backjmp(p1, p3);
 }
 
-backjmp(ap1, ap2)
-struct node *ap1, *ap2;
-{
+void backjmp(ap1, ap2) struct node *ap1; struct node *ap2; {
        register struct node *p1, *p2, *p3;
 
        p1 = ap1;
index 9a6300e..44db5fd 100644 (file)
@@ -3,16 +3,20 @@
  * C object code improver-- second part
  */
 
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include "c2.h"
 
-rmove()
-{
+void rmove() {
        register struct node *p;
        register int r;
-       register  r1, flt;
+       register int r1, flt;
 
        for (p=first.forw; p!=0; p = p->forw) {
        flt = 0;
+ /*fprintf(stderr, "p = 0x%08x p->op = 0x%08x p->code = 0x%08x\n",
+   p, p->op, p->code); fflush(stderr);*/
        switch (p->op) {
 
        case MOVF:
@@ -368,7 +372,11 @@ out:               dualop(p);      /* restore banged up parsed operands */
  * we check for the first character being a tilde.
 */
        case 0:
+#if 1 /* bugfix, it didn't seem to cause problems on the PDP11 */
+               if (p->code && *p->code != '~')
+#else
                if (p->code[0] != '~')
+#endif
                        clearreg();
                continue;
 
@@ -409,11 +417,9 @@ out:               dualop(p);      /* restore banged up parsed operands */
 /* jmi */ {JLE ,JNE ,JLE ,JBR ,JLT ,JNE ,JLT ,JNE ,JLE ,JLT ,JBR ,JLT}
          };
 
-fixupbr(p)
-       register struct node *p;
-{
+void fixupbr(p) register struct node *p; {
        register struct node *p1, *p2;
-       int op;
+       /*int op;*/
 
        p1 = p->back;
        p2 = p1->back;
@@ -429,12 +435,11 @@ ok:       p->subop = brtable[p->subop][p1->subop];
        nredunj++;
        p2->forw = p;
        p->back = p1->back;
-       }
+}
 
-jumpsw()
-{
+int jumpsw() {
        register struct node *p, *p1;
-       register t;
+       register int t;
        register struct node *tp;
        int nj;
 
@@ -462,17 +467,20 @@ jumpsw()
        return(nj);
 }
 
-addsob()
-{
+void addsob() {
        register struct node *p, *p1;
 
        for (p = &first; (p1 = p->forw)!=0; p = p1) {
+ /*fprintf(stderr, "A\n"); fflush(stderr);*/
                if (p->op==DEC && isreg(p->code)>=0
                 && p1->op==CBR && p1->subop==JNE) {
+ /*fprintf(stderr, "B\n"); fflush(stderr);*/
                        if (p->refc < p1->ref->refc)
                                continue;
+ /*fprintf(stderr, "C\n"); fflush(stderr);*/
                        if (toofar(p1))
                                continue;
+ /*fprintf(stderr, "D\n"); fflush(stderr);*/
                        p->labno = p1->labno;
                        p->op = SOB;
                        p->subop = 0;
@@ -480,27 +488,27 @@ addsob()
                        p->forw = p1->forw;
                        nsob++;
                }
+ /*fprintf(stderr, "E\n"); fflush(stderr);*/
        }
 }
 
-toofar(p)
-struct node *p;
-{
+int toofar(p) struct node *p; {
        register struct node *p1;
        int len;
 
        len = 0;
        for (p1 = p->ref; p1 && p1!=p; p1 = p1->forw)
+ {
+ /*fprintf(stderr, "p1 = 0x%08x\n", p1); fflush(stderr);*/
                len += ilen(p1);
+ }
+ /*fprintf(stderr, "len = 0x%08x\n", len); fflush(stderr);*/
        if (len < 128)
                return(0);
        return(1);
 }
 
-ilen(p)
-register struct node *p;
-{
-
+int ilen(p) register struct node *p; {
        switch (p->op) {
        case LABEL:
        case DLABEL:
@@ -513,14 +521,15 @@ register struct node *p;
                return(6);
 
        default:
+ /*fprintf(stderr, "X\n"); fflush(stderr);*/
                dualop(p);
+ /*fprintf(stderr, "Y\n"); fflush(stderr);*/
                return(2 + adrlen(regs[RT1]) + adrlen(regs[RT2]));
        }
 }
 
-adrlen(s)
-register char *s;
-{
+int adrlen(s) register char *s; {
+ /*fprintf(stderr, "Z\n"); fflush(stderr);*/
        if (*s == 0)
                return(0);
        if (*s=='r')
@@ -532,15 +541,11 @@ register char *s;
        return(2);
 }
 
-abs(x)
-register int x;
-{
+int abs(x) register int x; {
        return(x<0? -x: x);
 }
 
-equop(ap1, p2)
-struct node *ap1, *p2;
-{
+int equop(ap1, p2) struct node *ap1; struct node *p2; {
        register char *cp1, *cp2;
        register struct node *p1;
 
@@ -561,9 +566,7 @@ struct node *ap1, *p2;
        return(0);
 }
 
-decref(p)
-register struct node *p;
-{
+void decref(p) register struct node *p; {
        if (--p->refc <= 0) {
                nrlab++;
                p->back->forw = p->forw;
@@ -571,20 +574,14 @@ register struct node *p;
        }
 }
 
-struct node *
-nonlab(p)
-register struct node *p;
-{
+struct node *nonlab(p) register struct node *p; {
        CHECK(10);
        while (p && p->op==LABEL)
                p = p->forw;
        return(p);
 }
 
-char *
-alloc(n)
-register n;
-{
+char *alloc(n) register int n; {
        register char *p;
 
 #define round(a,b) ((((a)+(b)-1)/(b))*(b))
@@ -606,8 +603,7 @@ register n;
        return(p);
 }
 
-clearreg()
-{
+void clearreg() {
        register int i;
 
        for (i=0; i<2*NREG; i++)
@@ -616,9 +612,7 @@ clearreg()
        ccloc[0] = 0;
 }
 
-savereg(ai, as)
-char *as;
-{
+void savereg(ai, as) int ai; char *as; {
        register char *p, *s, *sp;
 
        sp = p = regs[ai];
@@ -636,9 +630,7 @@ char *as;
        *--p = '\0';
 }
 
-dest(as, flt)
-char *as;
-{
+void dest(as, flt) char *as; int flt; {
        register char *s;
        register int i;
 
@@ -671,9 +663,7 @@ char *as;
        }
 }
 
-singop(ap)
-struct node *ap;
-{
+void singop(ap) struct node *ap; {
        register char *p1, *p2;
 
        p1 = ap->code;
@@ -683,31 +673,40 @@ struct node *ap;
 }
 
 
-dualop(ap)
-struct node *ap;
-{
+void dualop(ap) struct node *ap; {
        register char *p1, *p2;
        register struct node *p;
 
+ /*fprintf(stderr, "ap->code = \"%s\"\n", ap->code); fflush(stderr);*/
        p = ap;
        p1 = p->code;
        p2 = regs[RT1];
-       while (*p1 && *p1!=',')
-               *p2++ = *p1++;
+#if 1 /* bugfix, it didn't seem to cause problems on the PDP11 */
+       if (p1) {
+#endif
+               while (*p1 && *p1!=',')
+                       *p2++ = *p1++;
+#if 1 /* bugfix, it didn't seem to cause problems on the PDP11 */
+       }
+#endif
        *p2++ = 0;
        p2 = regs[RT2];
        *p2 = 0;
-       if (*p1++ !=',')
-               return;
-       while (*p1==' ' || *p1=='\t')
-               p1++;
-       while (*p2++ = *p1++)
-               ;
+#if 1 /* bugfix, it didn't seem to cause problems on the PDP11 */
+       if (p1) {
+#endif
+               if (*p1++ !=',')
+                       return;
+               while (*p1==' ' || *p1=='\t')
+                       p1++;
+               while (*p2++ = *p1++)
+                       ;
+#if 1 /* bugfix, it didn't seem to cause problems on the PDP11 */
+       }
+#endif
 }
 
-findrand(as, flt)
-char *as;
-{
+int findrand(as, flt) char *as; int flt; {
        register int i;
        for (i = flt; i<NREG+flt; i++) {
                if (equstr(regs[i], as))
@@ -716,9 +715,7 @@ char *as;
        return(-1);
 }
 
-isreg(as)
-char *as;
-{
+int isreg(as) char *as; {
        register char *s;
 
        s = as;
@@ -727,25 +724,30 @@ char *as;
        return(-1);
 }
 
-check()
-{
+void check() {
        register struct node *p, *lp;
-       register count;
+       register int count;
 
        lp = &first;
        count = 0;
        for (p=first.forw; p!=0; p = p->forw) {
                if (++count > 10000)
+#ifdef PDP11
                        abort(0);
+#else
+                       abort();
+#endif
                if (p->back != lp)
+#ifdef PDP11
                        abort(1);
+#else
+                       abort();
+#endif
                lp = p;
        }
 }
 
-source(ap)
-char *ap;
-{
+int source(ap) char *ap; {
        register char *p1, *p2;
 
        p1 = ap;
@@ -764,10 +766,8 @@ char *ap;
        return(0);
 }
 
-repladdr(p, f, flt)
-struct node *p;
-{
-       register r;
+void repladdr(p, f, flt) struct node *p; int f; int flt; {
+       register int r;
        int r1;
        register char *p1, *p2;
        static char rt1[50], rt2[50];
@@ -808,11 +808,10 @@ struct node *p;
        }
 }
 
-movedat()
-{
+void movedat() {
        register struct node *p1, *p2;
        struct node *p3;
-       register seg;
+       register int seg;
        struct node data;
        struct node *datp;
 
@@ -870,9 +869,7 @@ movedat()
        }
 }
 
-redunbr(p)
-register struct node *p;
-{
+void redunbr(p) register struct node *p; {
        register struct node *p1;
        register char *ap1;
        char *ap2;
@@ -902,11 +899,9 @@ register struct node *p;
        }
 }
 
-char *
-findcon(i)
-{
+char *findcon(i) int i; {
        register char *p;
-       register r;
+       register int r;
 
        p = regs[i];
        if (*p=='$')
@@ -918,9 +913,7 @@ findcon(i)
        return(p);
 }
 
-compare(oper, cp1, cp2)
-register char *cp1, *cp2;
-{
+int compare(oper, cp1, cp2) int oper; register char *cp1; register char *cp2; {
        register unsigned n1, n2;
 
        if (*cp1++ != '$' || *cp2++ != '$')
@@ -970,9 +963,7 @@ register char *cp1, *cp2;
        return(-1);
 }
 
-setcon(ar1, ar2)
-char *ar1, *ar2;
-{
+void setcon(ar1, ar2) char *ar1; char *ar2; {
        register char *cl, *cv, *p;
 
        cl = ar2;
@@ -987,9 +978,7 @@ char *ar1, *ar2;
        while (*p++ = *cv++);
 }
 
-equstr(ap1, ap2)
-char *ap1, *ap2;
-{
+int equstr(ap1, ap2) char *ap1; char *ap2; {
        register char *p1, *p2;
 
        p1 = ap1;
@@ -1001,9 +990,7 @@ char *ap1, *ap2;
        return(1);
 }
 
-setcc(ap)
-char *ap;
-{
+void setcc(ap) char *ap; {
        register char *p, *p1;
 
        p = ap;
@@ -1015,9 +1002,7 @@ char *ap;
        while (*p1++ = *p++);
 }
 
-natural(ap)
-char *ap;
-{
+int natural(ap) char *ap; {
        register char *p;
 
        p = ap;
@@ -1030,17 +1015,13 @@ char *ap;
        return(1);
 }
 
-xnatural(ap)
-       char *ap;
-{
+int xnatural(ap) char *ap; {
        if (natural(ap))
                return(1);
        return(equstr("(sp)", ap));
 }
 
-not_sp(ap)
-       register char *ap;
-{
+int not_sp(ap) register char *ap; {
        char c;
 
        while (c = *ap++)
diff --git a/lib/c2/krcompat.h b/lib/c2/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
diff --git a/lib/c2/n.sh b/lib/c2/n.sh
new file mode 100755 (executable)
index 0000000..4d2408c
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/lib\/c2$//'`"
+DESTDIR="$ROOT/host"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/lib"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install
index 032f9df..118a554 100644 (file)
@@ -1,6 +1,8 @@
 CFLAGS = -O
 LDC0FLAGS= -i
 LDC1FLAGS= -n
+# this is used for cvopt:
+PURFLAG=-n
 
 DESTDIR =
 LIB=/lib
@@ -11,8 +13,8 @@ c0: c00.o c01.o c02.o c03.o c04.o c05.o
 
 c00.o c01.o c02.o c03.o c04.o c05.o: c0.h
 
-c1: c10.o c11.o c12.o c13.o table.o
-       ${CC} ${LDC1FLAGS} ${CFLAGS} -o c1 c10.o c11.o c12.o c13.o table.o
+c1: c10.o c11.o c12.o c13.o pdp11_atof.o pdp11_fp.o pdp11_ldexp.o table.o
+       ${CC} ${LDC1FLAGS} ${CFLAGS} -o c1 c10.o c11.o c12.o c13.o pdp11_atof.o pdp11_fp.o pdp11_ldexp.o table.o
 
 c10.o c11.o c12.o c13.o: c1.h
 
@@ -24,7 +26,7 @@ table.o: optable cvopt
        rm -f junk.i junk.c junk.s
 
 cvopt: cvopt.c
-       ${CC} -n -s -O -o cvopt cvopt.c
+       ${CC} ${PURFLAG} -s -O -o cvopt cvopt.c
 
 install: c0 c1
        -mv ${DESTDIR}${LIB}/c0 ${DESTDIR}${LIB}/oc0
index 05c95fe..b31ecc7 100644 (file)
@@ -2,7 +2,12 @@
  *     C compiler-- first pass header
  */
 
+#ifndef _C0_H
+#define _C0_H 1
+
+#include <stdint.h>
 #include <stdio.h>
+#include "krcompat.h"
 
 /*
  * This parameter is the _only_ one which affects the recognized length
@@ -38,6 +43,12 @@ int  STAUTO;
 #define        STARG   4       /* offset of first argument */
 #define        DCLSLOP 512     /* Amount trees lie above declaration stuff */
 
+/* Nick */
+#ifdef pdp11
+#define MAXPATHLEN 64
+#else
+#define MAXPATHLEN 1024
+#endif
 
 /*
  * # bytes in primitive types
@@ -161,58 +172,58 @@ struct swtab {
 
 #define        TNULL   (union tree *)NULL
 
-char   cvtab[4][4];
-char   filename[64];
-int    opdope[];
-char   ctab[];
-char   symbuf[MAXCPS+2];
-struct nmlist  *hshtab[HSHSIZ];
-int    kwhash[(HSHSIZ+LNBPW-1)/LNBPW];
-union  tree **cp;
-int    isn;
-struct swtab   swtab[SWSIZ];
-int    unscflg;
-struct swtab   *swp;
-int    contlab;
-int    brklab;
-int    retlab;
-int    deflab;
-unsigned autolen;              /* make these int if necessary */
-unsigned maxauto;              /* ... will only cause trouble rarely */
-int    peeksym;
-int    peekc;
-int    eof;
-int    line;
-char   *locbase;
-char   *treebase;
-char   *treebot;
-char   *coremax;
-struct nmlist  *defsym;
-struct nmlist  *funcsym;
-int    proflg;
-struct nmlist  *csym;
-int    cval;
-LTYPE  lcval;
-int    nchstr;
-int    nerror;
-struct nmlist *paraml;
-struct nmlist *parame;
-int    strflg;
-int    mosflg;
-int    initflg;
-char   sbuf[BUFSIZ];
-FILE   *sbufp;
-int    regvar;
-int    bitoffs;
-struct tnode   funcblk;
-char   cvntab[];
-char   numbuf[64];
-struct nmlist **memlist;
-union  str *sparent;
-int    nmems;
-struct nmlist  structhole;
-int    blklev;
-int    mossym;
+extern char cvtab[4][4];
+extern char filename[MAXPATHLEN]; /* Nick */
+extern int opdope[];
+extern char ctab[];
+extern char symbuf[MAXCPS+2];
+extern struct nmlist   *hshtab[HSHSIZ];
+extern int kwhash[(HSHSIZ+LNBPW-1)/LNBPW];
+extern union tree **cp;
+extern int isn;
+extern struct swtab swtab[SWSIZ];
+extern int unscflg;
+extern struct swtab *swp;
+extern int contlab;
+extern int brklab;
+extern int retlab;
+extern int deflab;
+extern unsigned autolen;       /* make these int if necessary */
+extern unsigned maxauto;       /* ... will only cause trouble rarely */
+extern int peeksym;
+extern int peekc;
+extern int eof;
+extern int line;
+extern char *locbase;
+extern char *treebase;
+extern char *treebot;
+extern char *coremax;
+extern struct nmlist *defsym;
+extern struct nmlist *funcsym;
+extern int proflg;
+extern struct nmlist *csym;
+extern int cval;
+extern LTYPE lcval;
+extern int nchstr;
+extern int nerror;
+extern struct nmlist *paraml;
+extern struct nmlist *parame;
+extern int strflg;
+extern int mosflg;
+extern int initflg;
+extern char sbuf[BUFSIZ];
+extern FILE *sbufp;
+extern int regvar;
+extern int bitoffs;
+extern struct tnode funcblk;
+extern char cvntab[];
+extern char numbuf[64];
+extern struct nmlist **memlist;
+extern union str *sparent;
+extern int nmems;
+extern struct nmlist structhole;
+extern int blklev;
+extern int mossym;
 
 /*
   operators
@@ -464,26 +475,172 @@ int      mossym;
 #define        FINIT   040
 #define        FLABL   0100
 
-/*
- * functions
- */
-char   *sbrk();
-union  tree *tree();
-char   *copnum();
-union  tree *convert();
-union  tree *chkfun();
-union  tree *disarray();
-union  tree *block();
-union  tree *cblock();
-union  tree *fblock();
-char   *Dblock();
-char   *Tblock();
-char   *starttree();
-union  tree *pexpr();
-union  str *strdec();
-union  tree *xprtype();
-struct nmlist *pushdecl();
-unsigned hash();
-union  tree *structident();
-struct nmlist *gentemp();
-union  tree *nblock();
+/* c00.c */
+int main PARAMS((int argc, char *argv[]));
+int lookup PARAMS((void));
+int findkw PARAMS((void));
+int symbol PARAMS((void));
+int getnum PARAMS((void));
+int subseq PARAMS((int c, int a, int b));
+void putstr PARAMS((int lab, register int max));
+void cntstr PARAMS((void));
+int getcc PARAMS((void));
+int mapch PARAMS((int ac));
+union tree *tree PARAMS((int eflag));
+union tree *xprtype PARAMS((void));
+char *copnum PARAMS((int len));
+/* c01.c */
+void build PARAMS((int op));
+union tree *structident PARAMS((register union tree *p1, register union tree *p2));
+union tree *convert PARAMS((union tree *p, int t, int cvn, int len));
+void setype PARAMS((register union tree *p, register int t, register union tree *newp));
+union tree *chkfun PARAMS((register union tree *p));
+union tree *disarray PARAMS((register union tree *p));
+void chkw PARAMS((union tree *p, int okt));
+int lintyp PARAMS((int t));
+void werror PARAMS((char *s, ...));
+void error PARAMS((char *s, ...));
+union tree *block PARAMS((int op, int t, int *subs, union str *str, union tree *p1, union tree *p2));
+union tree *nblock PARAMS((register struct nmlist *ds));
+union tree *cblock PARAMS((int v));
+union tree *fblock PARAMS((int t, char *string));
+char *Tblock PARAMS((int n));
+char *starttree PARAMS((void));
+void endtree PARAMS((char *tp));
+char *Dblock PARAMS((int n));
+void chklval PARAMS((register union tree *p));
+int fold PARAMS((int op, register union tree *p1, union tree *p2));
+int conexp PARAMS((void));
+void assignop PARAMS((int op, register union tree *p1, register union tree *p2));
+struct nmlist *gentemp PARAMS((int type));
+/* c02.c */
+void extdef PARAMS((void));
+void cfunc PARAMS((void));
+int cinit PARAMS((struct nmlist *anp, int flex, int sclass));
+void strinit PARAMS((struct nmlist *np, int sclass));
+void setinit PARAMS((register struct nmlist *np));
+void statement PARAMS((void));
+int forstmt PARAMS((void));
+union tree *pexpr PARAMS((int eflag));
+void pswitch PARAMS((void));
+void funchead PARAMS((void));
+void blockhead PARAMS((void));
+void blkend PARAMS((void));
+void nameconflict PARAMS((register struct nmlist *ocs, register struct nmlist *cs));
+void prste PARAMS((struct nmlist *cs));
+void errflush PARAMS((int ao));
+/* c03.c */
+int declist PARAMS((int sclass));
+int getkeywords PARAMS((int *scptr, struct nmlist *tptr));
+union str *strdec PARAMS((int mosf, int kind));
+int declare PARAMS((int askw, struct nmlist *tptr, int offset));
+int decl1 PARAMS((int askw, struct nmlist *atptr, int offset, struct nmlist *absname));
+struct nmlist *pushdecl PARAMS((register struct nmlist *sp));
+int getype PARAMS((register struct tdim *dimp, struct nmlist *absname));
+void typov PARAMS((void));
+int align PARAMS((int type, int offset, int aflen));
+void decsyn PARAMS((int o));
+void redec PARAMS((void));
+int goodreg PARAMS((struct nmlist *hp));
+/* c04.c */
+int decref PARAMS((register int t));
+int incref PARAMS((register int t));
+void cbranch PARAMS((union tree *t, int lbl, int cond));
+void rcexpr PARAMS((register union tree *tp));
+void treeout PARAMS((register union tree *tp, int isstruct));
+void branch PARAMS((int lab));
+void label PARAMS((int l));
+int plength PARAMS((register union tree *p));
+int length PARAMS((union tree *cs));
+int rlength PARAMS((union tree *cs));
+int simplegoto PARAMS((void));
+int nextchar PARAMS((void));
+int spnextchar PARAMS((void));
+void chconbrk PARAMS((int l));
+void dogoto PARAMS((void));
+void doret PARAMS((void));
+void outcode PARAMS((char *s, ...));
+unsigned int hash PARAMS((register char *sp));
+int main PARAMS((int argc, char *argv[]));
+int lookup PARAMS((void));
+int findkw PARAMS((void));
+int symbol PARAMS((void));
+int getnum PARAMS((void));
+int subseq PARAMS((int c, int a, int b));
+void putstr PARAMS((int lab, register int max));
+void cntstr PARAMS((void));
+int getcc PARAMS((void));
+int mapch PARAMS((int ac));
+union tree *tree PARAMS((int eflag));
+union tree *xprtype PARAMS((void));
+char *copnum PARAMS((int len));
+void build PARAMS((int op));
+union tree *structident PARAMS((register union tree *p1, register union tree *p2));
+union tree *convert PARAMS((union tree *p, int t, int cvn, int len));
+void setype PARAMS((register union tree *p, register int t, register union tree *newp));
+union tree *chkfun PARAMS((register union tree *p));
+union tree *disarray PARAMS((register union tree *p));
+void chkw PARAMS((union tree *p, int okt));
+int lintyp PARAMS((int t));
+void werror PARAMS((char *s, ...));
+void error PARAMS((char *s, ...));
+union tree *block PARAMS((int op, int t, int *subs, union str *str, union tree *p1, union tree *p2));
+union tree *nblock PARAMS((register struct nmlist *ds));
+union tree *cblock PARAMS((int v));
+union tree *fblock PARAMS((int t, char *string));
+char *Tblock PARAMS((int n));
+char *starttree PARAMS((void));
+void endtree PARAMS((char *tp));
+char *Dblock PARAMS((int n));
+void chklval PARAMS((register union tree *p));
+int fold PARAMS((int op, register union tree *p1, union tree *p2));
+int conexp PARAMS((void));
+void assignop PARAMS((int op, register union tree *p1, register union tree *p2));
+struct nmlist *gentemp PARAMS((int type));
+void extdef PARAMS((void));
+void cfunc PARAMS((void));
+int cinit PARAMS((struct nmlist *anp, int flex, int sclass));
+void strinit PARAMS((struct nmlist *np, int sclass));
+void setinit PARAMS((register struct nmlist *np));
+void statement PARAMS((void));
+int forstmt PARAMS((void));
+union tree *pexpr PARAMS((int eflag));
+void pswitch PARAMS((void));
+void funchead PARAMS((void));
+void blockhead PARAMS((void));
+void blkend PARAMS((void));
+void nameconflict PARAMS((register struct nmlist *ocs, register struct nmlist *cs));
+void prste PARAMS((struct nmlist *cs));
+void errflush PARAMS((int ao));
+int declist PARAMS((int sclass));
+int getkeywords PARAMS((int *scptr, struct nmlist *tptr));
+union str *strdec PARAMS((int mosf, int kind));
+int declare PARAMS((int askw, struct nmlist *tptr, int offset));
+int decl1 PARAMS((int askw, struct nmlist *atptr, int offset, struct nmlist *absname));
+struct nmlist *pushdecl PARAMS((register struct nmlist *sp));
+int getype PARAMS((register struct tdim *dimp, struct nmlist *absname));
+void typov PARAMS((void));
+int align PARAMS((int type, int offset, int aflen));
+void decsyn PARAMS((int o));
+void redec PARAMS((void));
+int goodreg PARAMS((struct nmlist *hp));
+int decref PARAMS((register int t));
+int incref PARAMS((register int t));
+void cbranch PARAMS((union tree *t, int lbl, int cond));
+void rcexpr PARAMS((register union tree *tp));
+void treeout PARAMS((register union tree *tp, int isstruct));
+void branch PARAMS((int lab));
+void label PARAMS((int l));
+int plength PARAMS((register union tree *p));
+int length PARAMS((union tree *cs));
+int rlength PARAMS((union tree *cs));
+int simplegoto PARAMS((void));
+int nextchar PARAMS((void));
+int spnextchar PARAMS((void));
+void chconbrk PARAMS((int l));
+void dogoto PARAMS((void));
+void doret PARAMS((void));
+void outcode PARAMS((char *s, ...));
+unsigned int hash PARAMS((register char *sp));
+
+#endif
index 326c997..240d482 100644 (file)
@@ -8,6 +8,9 @@
  * strings are put on temp2, which c1 reads after temp1.
  */
 
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include "c0.h"
 
 int    isn     = 1;
@@ -19,47 +22,44 @@ struct kwtab {
        char    *kwname;
        int     kwval;
 } kwtab[] = {
-       "int",          INT,
-       "char",         CHAR,
-       "float",        FLOAT,
-       "double",       DOUBLE,
-       "struct",       STRUCT,
-       "long",         LONG,
-       "unsigned",     UNSIGN,
-       "union",        UNION,
-       "short",        INT,
-       "void",         VOID,
-       "auto",         AUTO,
-       "extern",       EXTERN,
-       "static",       STATIC,
-       "register",     REG,
-       "goto",         GOTO,
-       "return",       RETURN,
-       "if",           IF,
-       "while",        WHILE,
-       "else",         ELSE,
-       "switch",       SWITCH,
-       "case",         CASE,
-       "break",        BREAK,
-       "continue",     CONTIN,
-       "do",           DO,
-       "default",      DEFAULT,
-       "for",          FOR,
-       "sizeof",       SIZEOF,
-       "typedef",      TYPEDEF,
-       "enum",         ENUM,
-       "asm",          ASM,
-       0,              0,
+       {"int",         INT},
+       {"char",        CHAR},
+       {"float",       FLOAT},
+       {"double",      DOUBLE},
+       {"struct",      STRUCT},
+       {"long",        LONG},
+       {"unsigned",    UNSIGN},
+       {"union",       UNION},
+       {"short",       INT},
+       {"void",        VOID},
+       {"auto",        AUTO},
+       {"extern",      EXTERN},
+       {"static",      STATIC},
+       {"register",    REG},
+       {"goto",        GOTO},
+       {"return",      RETURN},
+       {"if",          IF},
+       {"while",       WHILE},
+       {"else",        ELSE},
+       {"switch",      SWITCH},
+       {"case",        CASE},
+       {"break",       BREAK},
+       {"continue",    CONTIN},
+       {"do",          DO},
+       {"default",     DEFAULT},
+       {"for",         FOR},
+       {"sizeof",      SIZEOF},
+       {"typedef",     TYPEDEF},
+       {"enum",        ENUM},
+       {"asm",         ASM},
+       {0,             0}
 };
 
 union  tree *cmst[CMSIZ];
 union  tree **cp = cmst;
 int    Wflag;                  /* print warning messages */
 
-main(argc, argv)
-int    argc;
-char   *argv[];
-{
+int main(argc, argv) int argc; char *argv[]; {
        register unsigned i;
        register struct kwtab *ip;
        char    buf1[BUFSIZ],
@@ -130,8 +130,7 @@ char        *argv[];
  * first.
  * Return is a ptr to the symbol table entry.
  */
-lookup()
-{
+int lookup() {
        unsigned ihash;
        register struct nmlist *rp;
 
@@ -170,8 +169,7 @@ lookup()
 /*
  * Search the keyword table.
  */
-findkw()
-{
+int findkw() {
        register struct kwtab *kp;
 
        for (kp=kwtab; kp->kwname; kp++) {
@@ -191,11 +189,10 @@ findkw()
  * mosflg means that the next symbol, if an identifier,
  * is a member of structure or a structure tag or an enum tag
  */
-symbol()
-{
-       register c;
+int symbol() {
+       register int c;
        register char *sp;
-       register tline;
+       register int tline;
 
        if (peeksym>=0) {
                c = peeksym;
@@ -229,7 +226,7 @@ loop:
                        peekc = getchar();
                if (peekc=='"') {
                        sp = filename;
-                       while ((c = mapch('"')) >= 0)
+                       while (sp < filename + MAXPATHLEN - 1 && (c = mapch('"')) >= 0) /* Nick */
                                *sp++ = c;
                        *sp++ = 0;
                        peekc = getchar();
@@ -344,10 +341,9 @@ loop:
 /*
  * Read a number.  Return kind.
  */
-getnum()
-{
+int getnum() {
        register char *np;
-       register c, base;
+       register int c, base;
        int expseen, sym, ndigit;
        char *nsyn;
        int maxdigit;
@@ -433,8 +429,7 @@ getnum()
  * If the next input character is c, return b and advance.
  * Otherwise push back the character and return a.
  */
-subseq(c,a,b)
-{
+int subseq(c, a, b) int c; int a; int b; {
        if (spnextchar() != c)
                return(a);
        peekc = 0;
@@ -446,9 +441,7 @@ subseq(c,a,b)
  * or in the string temp file labelled by
  * lab.
  */
-putstr(lab, max)
-register max;
-{
+void putstr(lab, max) int lab; register int max; {
        register int c;
 
        nchstr = 0;
@@ -474,8 +467,7 @@ register max;
        strflg = 0;
 }
 
-cntstr()
-{
+void cntstr() {
        register int c;
 
        nchstr = 1;
@@ -489,23 +481,42 @@ cntstr()
  * The routine is sensitive to the layout of
  * characters in a word.
  */
-getcc()
-{
+int getcc() {
        register int c, cc;
+#ifdef pdp11
        register char *ccp;
        char realc;
+#else
+       register int shift;
+#endif
 
        cval = 0;
+#ifdef pdp11
        ccp = (char *)&cval;
+#else
+       shift = 0;
+#endif
        cc = 0;
        while((c=mapch('\'')) >= 0)
-               if(cc++ < LNCPW)
+               if(cc++ < LNCPW) {
+#ifdef pdp11
                        *ccp++ = c;
+#else
+                       cval |= (c & 0377) << shift;
+                       shift += 8;
+#endif
+               }
        if (cc>LNCPW)
                error("Long character constant");
        if (cc==1) {
+#ifdef pdp11
                realc = cval;
                cval = realc;
+#else
+               /* we default to signed char */
+               if (cval & 0200)
+                       cval |= ~0377;
+#endif
        }
        return(CON);
 }
@@ -515,10 +526,9 @@ getcc()
  * detecting the end of the string.
  * It implements the escape sequences.
  */
-mapch(ac)
-{
+int mapch(ac) int ac; {
        register int a, c, n;
-       static mpeek;
+       static int mpeek;
 
        c = ac;
        if (a = mpeek)
@@ -585,9 +595,7 @@ loop:
  * "," or ":" because those delimiters are special
  * in initializer (and some other) expressions.
  */
-union tree *
-tree(eflag)
-{
+union tree *tree(eflag) int eflag; {
        int *op, opst[SSIZE], *pp, prst[SSIZE];
        register int andflg, o;
        register struct nmlist *cs;
@@ -867,9 +875,7 @@ syntax:
        return((union tree *) &garbage);
 }
 
-union tree *
-xprtype()
-{
+union tree *xprtype() {
        struct nmlist typer, absname;
        int sc;
        register union tree **scp;
@@ -888,9 +894,7 @@ xprtype()
           absname.hstrp, TNULL, TNULL));
 }
 
-char *
-copnum(len)
-{
+char *copnum(len) int len; {
        register char *s1;
 
        s1 = Tblock((len+LNCPW-1) & ~(LNCPW-1));
index feb0c44..7e3e375 100644 (file)
@@ -2,6 +2,9 @@
  * C compiler
  */
 
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 #include "c0.h"
 
 /*
@@ -11,8 +14,7 @@
  * Essentially all the work is in inserting
  * appropriate conversions.
  */
-build(op)
-{
+void build(op) int op; {
        register int t1;
        int t2, t;
        register union tree *p1, *p2, *p3;
@@ -187,8 +189,13 @@ build(op)
                   p1, cblock(p2->t.tr1->n.hoffset));
                build(STAR);
                if (p2->t.tr1->n.hflag&FFIELD)
+#if 1
+                       cp[-1] = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL, 
+                           cp[-1], (union tree *)p2->t.tr1->n.hstrp);
+#else
                        *cp++ = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL, 
-                           *--cp, p2->t.tr1->n.hstrp);
+                           *--cp, (union tree *)p2->t.tr1->n.hstrp);
+#endif
                return;
        }
        if ((dope&LVALUE)!=0)
@@ -371,10 +378,7 @@ build(op)
        }
 }
 
-union tree *
-structident(p1, p2)
-register union tree *p1, *p2;
-{
+union tree *structident(p1, p2) register union tree *p1; register union tree *p2; {
        register struct nmlist *np;
        int vartypes = 0, namesame = 1;
 
@@ -410,10 +414,7 @@ register union tree *p1, *p2;
 /*
  * Generate the appropriate conversion operator.
  */
-union tree *
-convert(p, t, cvn, len)
-union tree *p;
-{
+union tree *convert(p, t, cvn, len) union tree *p; int t; int cvn; int len; {
        register int op;
 
        if (cvn==0)
@@ -434,10 +435,7 @@ union tree *p;
  * type at.
  * Used with structure references.
  */
-setype(p, t, newp)
-register union tree *p, *newp;
-register t;
-{
+void setype(p, t, newp) register union tree *p; register int t; register union tree *newp; {
        for (;; p = p->t.tr1) {
                p->t.subsp = newp->t.subsp;
                p->t.strp = newp->t.strp;
@@ -455,10 +453,7 @@ register t;
  * A mention of a function name is turned into
  * a pointer to that function.
  */
-union tree *
-chkfun(p)
-register union tree *p;
-{
+union tree *chkfun(p) register union tree *p; {
        register int t;
 
        if (((t = p->t.type)&XTYPE)==FUNC && p->t.op!=ETYPE)
@@ -470,10 +465,7 @@ register union tree *p;
  * A mention of an array is turned into
  * a pointer to the base of the array.
  */
-union tree *
-disarray(p)
-register union tree *p;
-{
+union tree *disarray(p) register union tree *p; {
        register int t;
 
        if (p==NULL)
@@ -496,9 +488,7 @@ register union tree *p;
  * okt might be nonexistent or 'long'
  * (e.g. for <<).
  */
-chkw(p, okt)
-union tree *p;
-{
+void chkw(p, okt) union tree *p; int okt; {
        register int t = p->t.type;
 
        if (t == UNLONG)
@@ -512,8 +502,7 @@ union tree *p;
  *'linearize' a type for looking up in the
  * conversion table
  */
-lintyp(t)
-{
+int lintyp(t) int t; {
        switch(t) {
 
        case INT:
@@ -539,30 +528,42 @@ lintyp(t)
  * Report an error.
  */
 
-extern int Wflag = 0;  /* Non-zero means do not print warnings */
+extern int Wflag;      /* Non-zero means do not print warnings */
 
-/* VARARGS1 */
-werror(s, p1, p2, p3, p4, p5, p6)
-char *s;
+#ifdef __STDC__
+void werror(char *s, ...)
+#else
+void werror(s, va_alist) char *s; va_dcl
+#endif
 {
+       va_list ap;
+
        if (Wflag)
                return;
        if (filename[0])
                fprintf(stderr, "%s:", filename);
        fprintf(stderr, "%d: warning: ", line);
-       fprintf(stderr, s, p1, p2, p3, p4, p5, p6);
+       va_start(ap, s);
+       vfprintf(stderr, s, ap);
+       va_end(ap);
        fprintf(stderr, "\n");
 }
 
-/* VARARGS1 */
-error(s, p1, p2, p3, p4, p5, p6)
-char *s;
+#ifdef __STDC__
+void error(char *s, ...)
+#else
+void error(s, va_alist) char *s; va_dcl
+#endif
 {
+       va_list ap;
+
        nerror++;
        if (filename[0])
                fprintf(stderr, "%s:", filename);
        fprintf(stderr, "%d: ", line);
-       fprintf(stderr, s, p1, p2, p3, p4, p5, p6);
+       va_start(ap, s);
+       vfprintf(stderr, s, ap);
+       va_end(ap);
        fprintf(stderr, "\n");
 }
 
@@ -571,14 +572,14 @@ char *s;
  * setting the operator, type, dimen/struct table ptrs,
  * and the operands.
  */
-union tree *
-block(op, t, subs, str, p1,p2)
-int *subs;
-union str *str;
-union tree *p1, *p2;
-{
+union tree *block(op, t, subs, str, p1,p2) int op; int t; int *subs; union str *str; union tree *p1; union tree *p2; {
        register union tree *p;
 
+ /*fprintf(stderr, "block(%d, %d, {%d, %d}, {%d, %d})\n", op, t,
+   (op == NAME) ? -2 : (p1 ? (int)(int16_t)p1->t.op : -1),
+   (op == NAME) ? -2 : (p1 ? (int)(int16_t)p1->t.type : -1),
+   (op == FSEL) ? -3 : (p2 ? (int)(int16_t)p2->t.op : -1),
+   (op == FSEL) ? -3 : (p2 ? (int)(int16_t)p2->t.type : -1));*/
        p = (union tree *)Tblock(sizeof(struct tnode));
        p->t.op = op;
        p->t.type = t;
@@ -592,21 +593,17 @@ union tree *p1, *p2;
        return(p);
 }
 
-union tree *
-nblock(ds)
-register struct nmlist *ds;
-{
+union tree *nblock(ds) register struct nmlist *ds; {
        return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (union tree *)ds, TNULL));
 }
 
 /*
  * Generate a block for a constant
  */
-union tree *
-cblock(v)
-{
+union tree *cblock(v) int v; {
        register union tree *p;
 
+ /*fprintf(stderr, "cblock(0%06o)\n", v & 0177777);*/
        p = (union tree *)Tblock(sizeof(struct cnode));
        p->c.op = CON;
        p->c.type = INT;
@@ -619,12 +616,10 @@ cblock(v)
 /*
  * A block for a float constant
  */
-union tree *
-fblock(t, string)
-char *string;
-{
+union tree *fblock(t, string) int t; char *string; {
        register union tree *p;
 
+ /*fprintf(stderr, "fblock(%d, \"%s\")\n", t, string);*/
        p = (union tree *)Tblock(sizeof(struct fnode));
        p->f.op = FCON;
        p->f.type = t;
@@ -638,18 +633,22 @@ char *string;
  * Assign a block for use in the
  * expression tree.
  */
-char *
-Tblock(n)
-{
+char *Tblock(n) int n; {
        register char *p;
 
+ /*fprintf(stderr, "treebase=%p n=%p coremax=%p\n", treebase, n, coremax);*/
        p = treebase;
        if (p==NULL) {
                error("c0 internal error: Tblock");
                exit(1);
        }
        if ((treebase += n) >= coremax) {
+#ifdef pdp11
                if (sbrk(1024) == (char *)-1) {
+#else
+ /*fprintf(stderr, "sbrk\n");*/
+               if (sbrk(1024) != coremax) {
+#endif
                        error("Out of space");
                        exit(1);
                }
@@ -658,33 +657,31 @@ Tblock(n)
        return(p);
 }
 
-char *
-starttree()
-{
+char *starttree() {
        register char *st;
 
+ /*fprintf(stderr, "starttree() locbase=%p coremax=%p\n", locbase, coremax);*/
        st = treebase;
        if (st==NULL)
                treebot = treebase = locbase+DCLSLOP;
+ /*fprintf(stderr, "starttree() treebase=%p treebot=%p\n", treebase, treebot);*/
        return(st);
 }
 
-endtree(tp)
-char *tp;
-{
+void endtree(tp) char *tp; {
        treebase = tp;
        if (tp==NULL)
                treebot = NULL;
+ /*fprintf(stderr, "endtree() treebase=%p treebot=%p\n", treebase, treebot);*/
 }
 
 /*
  * Assign a block for use in a declaration
  */
-char *
-Dblock(n)
-{
+char *Dblock(n) int n; {
        register char *p;
 
+ /*fprintf(stderr, "locbase=%p n=%d treebot=%p coremax=%p\n", locbase, n, treebot, coremax);*/
        p = locbase;
        locbase += n;
        if (treebot && locbase > treebot) {
@@ -692,7 +689,12 @@ Dblock(n)
                exit(1);
        }
        if (locbase > coremax) {
+#ifdef pdp11
                if (sbrk(1024) == (char *)-1) {
+#else
+ /*fprintf(stderr, "sbrk\n");*/
+               if (sbrk(1024) != coremax) {
+#endif
                        error("out of space");
                        exit(1);
                }
@@ -704,9 +706,7 @@ Dblock(n)
 /*
  * Check that a tree can be used as an lvalue.
  */
-chklval(p)
-register union tree *p;
-{
+void chklval(p) register union tree *p; {
        if (p->t.op==FSEL)
                p = p->t.tr1;
        if (p->t.op!=NAME && p->t.op!=STAR)
@@ -719,10 +719,7 @@ register union tree *p;
  * but this is used to allow constant expressions
  * to be used in switches and array bounds.
  */
-fold(op, p1, p2)
-register union tree *p1;
-union tree *p2;
-{
+int fold(op, p1, p2) int op; register union tree *p1; union tree *p2; {
        register int v1, v2;
        int unsignf;
 
@@ -768,10 +765,10 @@ union tree *p2;
                        if (v2==1)
                                break;
                        if (v2<0) {
-                               v1 = (unsigned)v1 >= (unsigned)v2;
+                               v1 = (uint16_t)v1 >= (uint16_t)v2;
                                break;
                        }
-                       v1 = (unsigned)v1 / v2;
+                       v1 = (uint16_t)v1 / v2;
                        break;
                }
                v1 /= v2;
@@ -786,11 +783,11 @@ union tree *p2;
                                break;
                        }
                        if (v2<0) {
-                               if ((unsigned)v1 >= (unsigned)v2)
+                               if ((uint16_t)v1 >= (uint16_t)v2)
                                        v1 -= v2;
                                break;
                        }
-                       v1 = (unsigned)v1 % v2;
+                       v1 = (uint16_t)v1 % v2;
                        break;
                }
                v1 %= v2;
@@ -822,7 +819,7 @@ union tree *p2;
 
        case RSHIFT:
                if (unsignf) {
-                       v1 = (unsigned)v1 >> v2;
+                       v1 = (uint16_t)v1 >> v2;
                        break;
                }
                v1 >>= v2;
@@ -853,19 +850,19 @@ union tree *p2;
                break;
 
        case LESSP:
-               v1 = (unsigned)v1<v2;
+               v1 = (uint16_t)v1<v2;
                break;
 
        case GREATP:
-               v1 = (unsigned)v1>v2;
+               v1 = (uint16_t)v1>v2;
                break;
 
        case LESSEQP:
-               v1 = (unsigned)v1<=v2;
+               v1 = (uint16_t)v1<=v2;
                break;
 
        case GREATQP:
-               v1 = (unsigned)v1>=v2;
+               v1 = (uint16_t)v1>=v2;
                break;
 
        divchk:
@@ -885,8 +882,7 @@ union tree *p2;
  * Compile an expression expected to have constant value,
  * for example an array bound or a case value.
  */
-conexp()
-{
+int conexp() {
        register union tree *t;
 
        initflg++;
@@ -894,15 +890,14 @@ conexp()
                if (t->t.op != CON)
                        error("Constant required");
        initflg--;
+ /*fprintf(stderr, "conexp() %d\n", t->c.value);*/
        return(t->c.value);
 }
 
 /*
  * Handle peculiar assignment ops that need a temporary.
  */
-assignop(op, p1, p2)
-register union tree *p1, *p2;
-{
+void assignop(op, p1, p2) int op; register union tree *p1; register union tree *p2; {
        register struct nmlist *np;
 
        op += PLUS - ASPLUS;
@@ -933,9 +928,7 @@ register union tree *p1, *p2;
  * Generate an automatic temporary for
  * use in certain assignment ops
  */
-struct nmlist *
-gentemp(type)
-{
+struct nmlist *gentemp(type) int type; {
        register struct nmlist *tp;
 
        tp = (struct nmlist *)Tblock(sizeof(struct nmlist));
index e92c38b..d361fb4 100644 (file)
@@ -2,14 +2,14 @@
  * C compiler
  */
 
+#include <string.h>
 #include "c0.h"
 
 /*
  * Process a single external definition
  */
-extdef()
-{
-       register o;
+void extdef() {
+       register int o;
        int sclass, scflag;
        struct nmlist typer;
        register struct nmlist *ds;
@@ -92,10 +92,9 @@ syntax:
 /*
  * Process a function definition.
  */
-cfunc()
-{
+void cfunc() {
        register char *cb;
-       register sloc;
+       register int sloc;
 
        sloc = isn;
        isn += 2;
@@ -122,17 +121,16 @@ cfunc()
 /* add STAUTO; overlay bug fix, coupled with section in c11.c */
        outcode("BN", SETSTK, -maxauto+STAUTO);
        branch(sloc+1);
+ /*fprintf(stderr, "cb=%p\n", cp);*/
        locbase = cb;
 }
 
 /*
  * Process the initializers for an external definition.
  */
-cinit(anp, flex, sclass)
-struct nmlist *anp;
-{
+int cinit(anp, flex, sclass) struct nmlist *anp; int flex; int sclass; {
        struct nmlist np;
-       register nel, ninit;
+       register int nel, ninit;
        int width, isarray, o, brace, realtype;
        union tree *s;
 
@@ -233,9 +231,7 @@ struct nmlist *anp;
 /*
  * Initialize a structure
  */
-strinit(np, sclass)
-struct nmlist *np;
-{
+void strinit(np, sclass) struct nmlist *np; int sclass; {
        static struct nmlist junk;
        register struct nmlist **mlp;
        static struct nmlist *zerloc = NULL;
@@ -282,9 +278,7 @@ struct nmlist *np;
 /*
  * Mark already initialized
  */
-setinit(np)
-register struct nmlist *np;
-{
+void setinit(np) register struct nmlist *np; {
 
        if (np->hflag&FINIT)
                error("%s multiply defined", np->name);
@@ -294,9 +288,8 @@ register struct nmlist *np;
 /*
  * Process one statement in a function.
  */
-statement()
-{
-       register o, o1;
+void statement() {
+       register int o, o1;
        int sauto, sreg;
 
 stmt:
@@ -357,7 +350,7 @@ stmt:
                }
 
                case IF: {
-                       register o2;
+                       register int o2;
                        register union tree *np;
 
                        np = pexpr(1);
@@ -416,7 +409,7 @@ stmt:
                }
 
                case WHILE: {
-                       register o2;
+                       register int o2;
                        o1 = contlab;
                        o2 = brklab;
                        label(contlab = isn++);
@@ -561,11 +554,10 @@ syntax:
 /*
  * Process a for statement.
  */
-forstmt()
-{
+int forstmt() {
        register int o;
        register union tree *st;
-       register l;
+       register int l;
        char *ss;
 
        if ((o=symbol()) != LPARN)
@@ -619,10 +611,8 @@ forstmt()
  * A parenthesized expression,
  * as after "if".
  */
-union tree *
-pexpr(eflag)
-{
-       register o;
+union tree *pexpr(eflag) int eflag; {
+       register int o;
        register union tree *t;
 
        if ((o=symbol())!=LPARN)
@@ -643,8 +633,7 @@ syntax:
  * The switch statement, which involves collecting the
  * constants and labels for the cases.
  */
-pswitch()
-{
+void pswitch() {
        register struct swtab *cswp, *sswp;
        int dl, swlab;
 
@@ -680,9 +669,8 @@ pswitch()
  */
 struct nmlist  hreg    = { REG, 0, 0, NULL, NULL, 0 };
 struct tnode   areg    = { NAME, 0, NULL, NULL, (union tree *)&hreg};
-funchead()
-{
-       register pl;
+void funchead() {
+       register int pl;
        register struct nmlist *cs;
        register char *st;
 
@@ -724,9 +712,8 @@ funchead()
        outcode("BN", SETREG, regvar);
 }
 
-blockhead()
-{
-       register r;
+void blockhead() {
+       register int r;
 
        r = regvar;
        blklev++;
@@ -740,10 +727,9 @@ blockhead()
  * symbols;
  * Also complain about undefined labels.
  */
-blkend()
-{
+void blkend() {
        register struct nmlist *cs, **lcs;
-       register i;
+       register int i;
 
        blklev--;
        for (i = 0; i < HSHSIZ; i++) {
@@ -764,9 +750,7 @@ blkend()
        }
 }
 
-nameconflict(ocs, cs)
-register struct nmlist *ocs, *cs;
-{
+void nameconflict(ocs, cs) register struct nmlist *ocs; register struct nmlist *cs; {
 
        for (; ocs!=NULL; ocs = ocs->nextnm) 
                if (ocs!=cs && ocs->hclass==EXTERN && 
@@ -779,10 +763,8 @@ register struct nmlist *ocs, *cs;
  * benefit of the debugger.  None of these are used
  * by the assembler except to save them.
  */
-prste(cs)
-struct nmlist *cs;
-{
-       register nkind;
+void prste(cs) struct nmlist *cs; {
+       register int nkind;
 
        switch (cs->hclass) {
        case REG:
@@ -808,9 +790,8 @@ struct nmlist *cs;
  * In case of error, skip to the next
  * statement delimiter.
  */
-errflush(ao)
-{
-       register o;
+void errflush(ao) int ao; {
+       register int o;
 
        o = ao;
        while(o>RBRACE) {       /* ; { } */
index d0bd0eb..bfa3a16 100644 (file)
@@ -5,14 +5,14 @@
  * externals.
  */
 
+#include <string.h>
 #include "c0.h"
 
 /*
  * Process a sequence of declaration statements
  */
-declist(sclass)
-{
-       register sc, offset;
+int declist(sclass) int sclass; {
+       register int sc, offset;
        struct nmlist typer;
 
        offset = 0;
@@ -29,11 +29,8 @@ declist(sclass)
  * Store back the storage class, and fill in the type
  * entry, which looks like a hash table entry.
  */
-getkeywords(scptr, tptr)
-int *scptr;
-struct nmlist *tptr;
-{
-       register skw, tkw, longf;
+int getkeywords(scptr, tptr) int *scptr; struct nmlist *tptr; {
+       register int skw, tkw, longf;
        int o, isadecl, ismos, unsignf;
 
        isadecl = 0;
@@ -144,10 +141,8 @@ struct nmlist *tptr;
  * Process a structure, union, or enum declaration; a subroutine
  * of getkeywords.
  */
-union str *
-strdec(mosf, kind)
-{
-       register elsize, o;
+union str *strdec(mosf, kind) int mosf; int kind; {
+       register int elsize, o;
        register struct nmlist *ssym;
        int savebits;
        struct nmlist **savememlist;
@@ -217,9 +212,17 @@ strdec(mosf, kind)
                } else
                        elsize = declist(kind==UNION?MOU:MOS);
                bitoffs = savebits;
+#if 1 /* just save a bit of string space */
+               if (strp->S.ssize) {
+                       defsym = ssym;
+                       redec();
+               }
+               defsym = ds;
+#else
                defsym = ds;
                if (strp->S.ssize)
                        error("%s redeclared", ssym->name);
+#endif
                strp->S.ssize = elsize;
                *memlist++ = NULL;
                strp->S.memlist = (struct nmlist **)Dblock((memlist-mems)*sizeof(*memlist));
@@ -240,9 +243,7 @@ strdec(mosf, kind)
 /*
  * Process a comma-separated list of declarators
  */
-declare(askw, tptr, offset)
-struct nmlist *tptr;
-{
+int declare(askw, tptr, offset) int askw; struct nmlist *tptr; int offset; {
        register unsigned o;
        register int skw, isunion;
        struct nmlist abs, *aptr;
@@ -298,9 +299,7 @@ struct nmlist *tptr;
 /*
  * Process a single declarator
  */
-decl1(askw, atptr, offset, absname)
-struct nmlist *atptr, *absname;
-{
+int decl1(askw, atptr, offset, absname) int askw; struct nmlist *atptr; int offset; struct nmlist *absname; {
        int t1, a, elsize;
        register int skw;
        int type;
@@ -534,10 +533,7 @@ syntax:
  * Push down an outer-block declaration
  * after redeclaration in an inner block.
  */
-struct nmlist *
-pushdecl(sp)
-register struct nmlist *sp;
-{
+struct nmlist *pushdecl(sp) register struct nmlist *sp; {
        register struct nmlist *nsp, **hsp;
 
        nsp = (struct nmlist *)Dblock(sizeof(struct nmlist));
@@ -559,10 +555,7 @@ register struct nmlist *sp;
 /*
  * Read a declarator and get the implied type
  */
-getype(dimp, absname)
-register struct tdim *dimp;
-struct nmlist *absname;
-{
+int getype(dimp, absname) register struct tdim *dimp; struct nmlist *absname; {
        static struct nmlist argtype;
        int type;
        register int o;
@@ -656,8 +649,7 @@ syntax:
 /*
  * More bits required for type than allowed.
  */
-typov()
-{
+void typov() {
        error("Type is too complicated");
 }
 
@@ -665,9 +657,8 @@ typov()
  * Enforce alignment restrictions in structures,
  * including bit-field considerations.
  */
-align(type, offset, aflen)
-{
-       register a, t, flen;
+int align(type, offset, aflen) int type; int offset; int aflen; {
+       register int a, t, flen;
        char *ftl;
 
        flen = aflen;
@@ -709,8 +700,7 @@ align(type, offset, aflen)
 /*
  * Complain about syntax error in declaration
  */
-decsyn(o)
-{
+void decsyn(o) int o; {
        error("Declaration syntax");
        errflush(o);
 }
@@ -718,8 +708,7 @@ decsyn(o)
 /*
  * Complain about a redeclaration
  */
-redec()
-{
+void redec() {
        error("%s redeclared", defsym->name);
 }
 
@@ -727,9 +716,7 @@ redec()
  * Determine if a variable is suitable for storage in
  * a register; if so return the register number
  */
-goodreg(hp)
-struct nmlist *hp;
-{
+int goodreg(hp) struct nmlist *hp; {
        int type;
 
        type = hp->htype;
index f0da829..47ef77e 100644 (file)
@@ -2,15 +2,14 @@
  * C compiler
  */
 
+#include <stdlib.h>
 #include "c0.h"
 
 /*
  * Reduce the degree-of-reference by one.
  * e.g. turn "ptr-to-int" into "int".
  */
-decref(t)
-register int t;
-{
+int decref(t) register int t; {
        if ((t & ~TYPE) == 0) {
                error("Illegal indirection");
                return(t);
@@ -22,9 +21,7 @@ register int t;
  * Increase the degree of reference by
  * one; e.g. turn "int" to "ptr-to-int".
  */
-incref(t)
-register int t;
-{
+int incref(t) register int t; {
        return(((t&~TYPE)<<TYLEN) | (t&TYPE) | PTR);
 }
 
@@ -32,9 +29,7 @@ register int t;
  * Make a tree that causes a branch to lbl
  * if the tree's value is non-zero together with the cond.
  */
-cbranch(t, lbl, cond)
-union tree *t;
-{
+void cbranch(t, lbl, cond) union tree *t; int lbl; int cond; {
        treeout(t, 0);
        outcode("BNNN", CBRANCH, lbl, cond, line);
 }
@@ -42,9 +37,7 @@ union tree *t;
 /*
  * Write out a tree.
  */
-rcexpr(tp)
-register union tree *tp;
-{
+void rcexpr(tp) register union tree *tp; {
        /*
         * Special optimization
         */
@@ -61,11 +54,9 @@ register union tree *tp;
        outcode("BN", EXPR, line);
 }
 
-treeout(tp, isstruct)
-register union tree *tp;
-{
+void treeout(tp, isstruct) register union tree *tp; int isstruct; {
        register struct nmlist *hp;
-       register nextisstruct;
+       register int nextisstruct;
 
        if (tp == NULL || tp->t.op==NULLOP) {
                outcode("B", XNULLOP);
@@ -86,8 +77,8 @@ register union tree *tp;
                break;
 
        case LCON:
-               outcode("BNNN", tp->l.op, tp->l.type, (unsigned short)(tp->l.lvalue>>16),
-                  (unsigned short)tp->l.lvalue);
+               outcode("BNNN", tp->l.op, tp->l.type, (uint16_t)(tp->l.lvalue>>16),
+                  (uint16_t)tp->l.lvalue);
                break;
 
        case CON:
@@ -138,16 +129,14 @@ register union tree *tp;
 /*
  * Generate a branch
  */
-branch(lab)
-{
+void branch(lab) int lab; {
        outcode("BN", BRANCH, lab);
 }
 
 /*
  * Generate a label
  */
-label(l)
-{
+void label(l) int l; {
        outcode("BN", LABEL, l);
 }
 
@@ -156,10 +145,8 @@ label(l)
  * is some kind of pointer; return the size of the object
  * to which the pointer points.
  */
-plength(p)
-register union tree *p;
-{
-       register t, l;
+int plength(p) register union tree *p; {
+       register int t, l;
 
        if (p==0 || ((t=p->t.type)&~TYPE) == 0)         /* not a reference */
                return(1);
@@ -173,10 +160,8 @@ register union tree *p;
  * return the number of bytes in the object
  * whose tree node is acs.
  */
-length(cs)
-union tree *cs;
-{
-       register t, elsz;
+int length(cs) union tree *cs; {
+       register int t, elsz;
        long n;
        int nd;
 
@@ -229,7 +214,7 @@ union tree *cs;
                return(0);
        }
        n *= elsz;
-       if (n >= (unsigned)50000)
+       if (n >= (uint16_t)50000)
                werror("very large data structure");
        return(n);
 }
@@ -237,9 +222,7 @@ union tree *cs;
 /*
  * The number of bytes in an object, rounded up to a word.
  */
-rlength(cs)
-union tree *cs;
-{
+int rlength(cs) union tree *cs; {
        return((length(cs)+ALIGN) & ~ALIGN);
 }
 
@@ -247,8 +230,7 @@ union tree *cs;
  * After an "if (...) goto", look to see if the transfer
  * is to a simple label.
  */
-simplegoto()
-{
+int simplegoto() {
        register struct nmlist *csp;
 
        if ((peeksym=symbol())==NAME && nextchar()==';') {
@@ -273,8 +255,7 @@ simplegoto()
 /*
  * Return the next non-white-space character
  */
-nextchar()
-{
+int nextchar() {
        while (spnextchar()==' ')
                peekc = 0;
        return(peekc);
@@ -284,9 +265,8 @@ nextchar()
  * Return the next character, translating all white space
  * to blank and handling line-ends.
  */
-spnextchar()
-{
-       register c;
+int spnextchar() {
+       register int c;
 
        if ((c = peekc)==0)
                c = getchar();
@@ -303,8 +283,7 @@ spnextchar()
 /*
  * is a break or continue legal?
  */
-chconbrk(l)
-{
+void chconbrk(l) int l; {
        if (l==0)
                error("Break/continue error");
 }
@@ -312,8 +291,7 @@ chconbrk(l)
 /*
  * The goto statement.
  */
-dogoto()
-{
+void dogoto() {
        register union tree *np;
        register char *st;
 
@@ -329,8 +307,7 @@ dogoto()
  * The return statement, which has to convert
  * the returned object to the function's type.
  */
-doret()
-{
+void doret() {
        if (nextchar() != ';') {
                register char *st;
 
@@ -357,37 +334,42 @@ doret()
  *   1: number 1
  *   0: number 0
  */
-/* VARARGS1 */
-outcode(s, a)
-char *s;
+#ifdef __STDC__
+void outcode(char *s, ...)
+#else
+void outcode(s, va_alist) char *s; va_dcl
+#endif
 {
-       register *ap;
+       va_list ap;
        register FILE *bufp;
+       register int ni;
        register char *np;
        int n;
 
        bufp = stdout;
        if (strflg)
                bufp = sbufp;
-       ap = &a;
+       va_start(ap, s);
        for (;;) switch(*s++) {
        case 'B':
-               fputc(*ap++, bufp);
+               ni = va_arg(ap, int);
+               fputc(ni, bufp);
                fputc(0376, bufp);
                continue;
 
        case 'N':
-               fputc(*ap, bufp);
-               fputc(*ap++>>8, bufp);
+               ni = va_arg(ap, int);
+               fputc(ni, bufp);
+               fputc(ni>>8, bufp);
                continue;
 
        case 'F':
-               np = (char *)*ap++;
+               np = va_arg(ap, char *);
                n = 1000;
                goto str;
 
        case 'S':
-               np = (char *)*ap++;
+               np = va_arg(ap, char *);
                n = MAXCPS-1;
                if (*np)
                        fputc('_', bufp);
@@ -409,6 +391,7 @@ char *s;
                continue;
 
        case '\0':
+               va_end(ap);
                if (ferror(bufp)) {
                        error("Write error on temp");
                        exit(1);
@@ -420,10 +403,7 @@ char *s;
        }
 }
 
-unsigned int
-hash(sp)
-register char *sp;
-{
+unsigned int hash(sp) register char *sp; {
        register unsigned int h;
 
        h = 0;
index 7f859f4..0b9ae94 100644 (file)
@@ -167,10 +167,10 @@ int opdope[] = {
  */
 char cvtab[4][4] = {
 /*             int     double          long            ptr */
-/* int */      0,      (FTI<<4)+ITF,   (LTI<<4)+ITL,   (ITP<<4)+ITP,   
-/* double */   ITF,    0,              LTF,            XX,
-/* long */     ITL,    (FTL<<4)+LTF,   0,              (LTP<<4)+LTP,
-/* ptr */      ITP,    XX,             LTP,            PTI,
+/* int */      {0,     (FTI<<4)+ITF,   (LTI<<4)+ITL,   (ITP<<4)+ITP},
+/* double */   {ITF,   0,              LTF,            XX},
+/* long */     {ITL,   (FTL<<4)+LTF,   0,              (LTP<<4)+LTP},
+/* ptr */      {ITP,   XX,             LTP,            PTI}
 };
 
 /*
@@ -201,3 +201,50 @@ char ctab[] = {
        LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER,
        LETTER, LETTER, LETTER, LBRACE, OR,     RBRACE, COMPL,  UNKN
 };
+
+int    STAUTO;
+char   cvtab[4][4];
+char   filename[MAXPATHLEN];
+char   symbuf[MAXCPS+2];
+struct nmlist  *hshtab[HSHSIZ];
+int    kwhash[(HSHSIZ+LNBPW-1)/LNBPW];
+struct swtab   swtab[SWSIZ];
+int    unscflg;
+struct swtab   *swp;
+int    contlab;
+int    brklab;
+int    retlab;
+int    deflab;
+unsigned autolen;              /* make these int if necessary */
+unsigned maxauto;              /* ... will only cause trouble rarely */
+int    peekc;
+int    eof;
+char   *locbase;
+char   *treebase;
+char   *treebot;
+char   *coremax;
+struct nmlist  *defsym;
+struct nmlist  *funcsym;
+int    proflg;
+struct nmlist  *csym;
+int    cval;
+LTYPE  lcval;
+int    nchstr;
+int    nerror;
+struct nmlist *paraml;
+struct nmlist *parame;
+int    strflg;
+int    mosflg;
+int    initflg;
+char   sbuf[BUFSIZ];
+FILE   *sbufp;
+int    regvar;
+int    bitoffs;
+char   cvntab[];
+char   numbuf[64];
+struct nmlist **memlist;
+union  str *sparent;
+int    nmems;
+struct nmlist  structhole;
+int    blklev;
+int    mossym;
index 0548049..6d7d5e6 100644 (file)
@@ -2,11 +2,18 @@
  * C code generator header
  */
 
+#ifndef _C1_H
+#define _C1_H 1
+
+#include <stdint.h>
 #include <stdio.h>
 #include <setjmp.h>
+#include "krcompat.h"
 
 #define        LTYPE   long    /* change to int for no long consts */
+#ifndef NULL
 #define        NULL    0
+#endif
 #define        TNULL   (union tree *)NULL
 #define        UNS(x)  ((unsigned short)(x))
 
@@ -51,7 +58,7 @@ struct        xtname {
 struct tconst {
        int     op;
        int     type;
-       int     value;
+       int16_t value;
 };
 
 /*
@@ -60,7 +67,11 @@ struct       tconst {
 struct lconst {
        int     op;
        int     type;
+#if pdp11
        LTYPE   lvalue;
+#else
+       uint16_t lvalue[2];
+#endif
 };
 
 /*
@@ -70,7 +81,11 @@ struct       ftconst {
        int     op;
        int     type;
        int     value;
+#ifdef pdp11
        double  fvalue;
+#else
+       uint16_t fvalue[4];
+#endif
 };
 
 /*
@@ -119,56 +134,111 @@ struct   swtab {
        int     swval;
 };
 
-char   maprel[];
-char   notrel[];
-int    nreg;
-int    isn;
-int    line;
-int    nerror;                 /* number of hard errors */
-struct table   cctab[];
-struct table   efftab[];
-struct table   regtab[];
-struct table   sptab[];
-struct table   lsptab[1];
-struct instab  instab[];
-struct instab  branchtab[];
-int    opdope[];
-char   *opntab[];
-int    nstack;
-int    nfloat;
-struct tname   sfuncr;
-char   *funcbase;
-char   *curbase;
-char   *coremax;
-struct tconst czero, cone;
-long   totspace;
-int    regpanic;               /* set when SU register alg. fails */
-int    panicposs;              /* set when there might be need for regpanic */
-jmp_buf        jmpbuf;
-long   ftell();
-char   *sbrk();
-struct optab *match();
-union  tree *optim();
-union  tree *unoptim();
-union  tree *pow2();
-union  tree *tnode();
-union  tree *sdelay();
-union  tree *ncopy();
-union  tree *getblk();
-union  tree *strfunc();
-union  tree *isconstant();
-union  tree *tconst();
-union  tree *hardlongs();
-union  tree *lconst();
-union  tree *acommute();
-union  tree *lvfield();
-union  tree *paint();
-long   ftell();
+extern char maprel[];
+extern char notrel[];
+extern int nreg;
+extern int isn;
+extern int line;
+extern int nerror;                     /* number of hard errors */
+extern struct table cctab[];
+extern struct table efftab[];
+extern struct table regtab[];
+extern struct table sptab[];
+extern struct table lsptab[1];
+extern char mov[];
+extern char clr[];
+extern char cmp[];
+extern char tst[];
+extern char add[];
+extern char sub[];
+extern char inc[];
+extern char dec[];
+extern char mul[];
+extern char _div[];
+extern char asr[];
+extern char ash[];
+extern char asl[];
+extern char bic[];
+extern char bic1[];
+extern char bit[];
+extern char bit1[];
+extern char bis[];
+extern char bis1[];
+extern char xor[];
+extern char neg[];
+extern char com[];
+extern char stdol[];
+extern char ashc[];
+extern char slmul[];
+extern char sldiv[];
+extern char slrem[];
+extern char uldiv[];
+extern char ulrem[];
+extern char ualdiv[];
+extern char ualrem[];
+extern char ultof[];
+extern char ulsh[];
+extern char ualsh[];
+extern char almul[];
+extern char aldiv[];
+extern char alrem[];
+extern char udiv[];
+extern char urem[];
+extern char jeq[];
+extern char jne[];
+extern char jle[];
+extern char jgt[];
+extern char jlt[];
+extern char jge[];
+extern char jlos[];
+extern char jhi[];
+extern char jlo[];
+extern char jhis[];
+extern char nop[];
+extern char jbr[];
+extern char jpl[];
+extern char jmi[];
+extern char jmijne[];
+extern char jmijeq[];
+extern struct instab instab[];
+extern struct instab branchtab[];
+extern int opdope[];
+extern char *opntab[];
+extern int nstack;
+extern int nfloat;
+extern struct tname sfuncr;
+extern char *funcbase;
+extern char *curbase;
+extern char *coremax;
+extern struct tconst czero, cone;
+extern long totspace;
+extern int regpanic;           /* set when SU register alg. fails */
+extern int panicposs;          /* set when there might be need for regpanic */
+extern jmp_buf jmpbuf;
+extern long ftell();
+extern char *sbrk();
+extern struct optab *match();
+extern union tree *optim();
+extern union tree *unoptim();
+extern union tree *pow2();
+extern union tree *tnode();
+extern union tree *sdelay();
+extern union tree *ncopy();
+extern union tree *getblk();
+extern union tree *strfunc();
+extern union tree *isconstant();
+extern union tree *tconst();
+extern union tree *hardlongs();
+extern union tree *lconst();
+extern union tree *acommute();
+extern union tree *lvfield();
+extern union tree *paint();
+extern long ftell();
 
 /*
  * Some special stuff for long comparisons
  */
-int    xlab1, xlab2, xop, xzero;
+extern int xlab1, xlab2, xop, xzero;
 
 /*
        operators
@@ -269,9 +339,9 @@ int xlab1, xlab2, xop, xzero;
 #define        LASMOD  88
 
 #define        QUEST   90
-/* #define     MAX     93      /* not used; wanted macros in param.h */
+/* #define     MAX     93      not used; wanted macros in param.h */
 #define        MAXP    94
-/* #define     MIN     95      /* not used; wanted macros in param.h */
+/* #define     MIN     95      not used; wanted macros in param.h */
 #define        MINP    96
 #define        LLSHIFT 91
 #define        ASLSHL  92
@@ -385,3 +455,112 @@ int       xlab1, xlab2, xop, xzero;
 #define        RASSOC  0200
 #define        LEAF    0400
 #define        CNVRT   01000
+
+#if 1 /* moved here from c12.c */
+#define        LSTSIZ  20
+struct acl {
+       int nextl;
+       int nextn;
+       union tree *nlist[LSTSIZ];
+       union tree *llist[LSTSIZ+1];
+};
+#endif
+
+#ifndef pdp11
+extern int32_t FEC;
+extern int32_t FPS;
+extern int N, Z, V, C;
+extern int R[8];
+#endif
+
+/* c10.c */
+int main PARAMS((int argc, char *argv[]));
+struct optab *match PARAMS((union tree *tree, struct table *table, int nrleft, int nocvt));
+int rcexpr PARAMS((union tree *atree, struct table *atable, int reg));
+int cexpr PARAMS((register union tree *tree, struct table *table, int areg));
+int reorder PARAMS((union tree **treep, struct table *table, int reg));
+int sreorder PARAMS((union tree **treep, struct table *table, int reg, int recurf));
+int delay PARAMS((union tree **treep, struct table *table, int reg));
+union tree *sdelay PARAMS((union tree **ap));
+union tree *paint PARAMS((register union tree *tp, register int type));
+union tree *ncopy PARAMS((register union tree *p));
+int chkleaf PARAMS((register union tree *tree, struct table *table, int reg));
+int comarg PARAMS((register union tree *tree, int *flagp));
+union tree *strfunc PARAMS((register union tree *tp));
+void doinit PARAMS((register int type, register union tree *tree));
+void movreg PARAMS((int r0, int r1, union tree *tree));
+/* c11.c */
+int degree PARAMS((register union tree *t));
+void pname PARAMS((register union tree *p, int flag));
+void pbase PARAMS((register union tree *p));
+int xdcalc PARAMS((register union tree *p, int nrleft));
+int dcalc PARAMS((register union tree *p, int nrleft));
+int notcompat PARAMS((register union tree *p, int ast, int deg, int op));
+int prins PARAMS((int op, int c, struct instab *itable, int lbl));
+int collcon PARAMS((register union tree *p));
+int isfloat PARAMS((register union tree *t));
+int oddreg PARAMS((register union tree *t, register int reg));
+int arlength PARAMS((int t));
+void pswitch PARAMS((struct swtab *afp, struct swtab *alp, int deflab));
+void breq PARAMS((int v, int l));
+int sort PARAMS((struct swtab *afp, struct swtab *alp));
+int ispow2 PARAMS((register union tree *tree));
+union tree *pow2 PARAMS((register union tree *tree));
+void cbranch PARAMS((union tree *atree, register int lbl, int cond, register int reg));
+void branch PARAMS((int lbl, int aop, int c));
+void longrel PARAMS((union tree *atree, int lbl, int cond, int reg));
+int xlongrel PARAMS((int f));
+void label PARAMS((int l));
+void popstk PARAMS((int a));
+void werror PARAMS((char *s));
+void error PARAMS((char *s, ...));
+void psoct PARAMS((int an));
+void getree PARAMS((void));
+int geti PARAMS((void));
+void strasg PARAMS((union tree *atp));
+int decref PARAMS((register int t));
+int incref PARAMS((register int t));
+/* c12.c */
+union tree *optim PARAMS((register union tree *tree));
+union tree *unoptim PARAMS((register union tree *tree));
+union tree *lvfield PARAMS((register union tree *t));
+union tree *acommute PARAMS((register union tree *tree));
+int sideeffects PARAMS((register union tree *tp));
+void distrib PARAMS((struct acl *list));
+void squash PARAMS((union tree **p, union tree **maxp));
+void _const PARAMS((int op, register int16_t *vp, int v, int type));
+union tree *lconst PARAMS((int op, register union tree *lp, register union tree *rp));
+void insert PARAMS((int op, register union tree *tree, register struct acl *list));
+union tree *tnode PARAMS((int op, int type, union tree *tr1, union tree *tr2));
+union tree *tconst PARAMS((int val, int type));
+union tree *getblk PARAMS((int size));
+int islong PARAMS((int t));
+union tree *isconstant PARAMS((register union tree *t));
+union tree *hardlongs PARAMS((register union tree *t));
+int uns PARAMS((union tree *tp));
+/* c13.c */
+/* pdp11_atof.c */
+void pdp11_atof PARAMS((char *p));
+/* pdp11_fp.c */
+void pdp11_cfcc PARAMS((void));
+void pdp11_seti PARAMS((void));
+void pdp11_setl PARAMS((void));
+void pdp11_clrf PARAMS((uint16_t *va, int dstspec));
+void pdp11_negf PARAMS((uint16_t *va, int dstspec));
+void pdp11_ldf PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_stf PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_ldcfo PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_stcfo PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_cmpf PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_movie PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_movei PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_movif PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_movfi PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_mulf PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_addf PARAMS((int ac, uint16_t *va, int dstspec));
+void pdp11_divf PARAMS((int ac, uint16_t *va, int dstspec));
+int32_t fpnotrap PARAMS((int32_t code));
+/* pdp11_ldexp.c */
+void pdp11_ldexp PARAMS((uint16_t *value, int exp));
+
+#endif
index cc436d9..78ed26a 100644 (file)
@@ -9,6 +9,7 @@
 static char    sccsid[] = "@(#)c10.c   2.1 (2.11BSD GTE) 10/4/94";
 #endif
 
+#include <stdlib.h>
 #include "c1.h"
 
 #ifdef DEBUG
@@ -17,8 +18,6 @@ static        char    sccsid[] = "@(#)c10.c   2.1 (2.11BSD GTE) 10/4/94";
 #define        dbprint(op)     /* */
 #endif
 
-static int debug = 0;
-
 char   maprel[] = {    EQUAL, NEQUAL, GREATEQ, GREAT, LESSEQ,
                        LESS, GREATQP, GREATP, LESSEQP, LESSP
 };
@@ -37,10 +36,7 @@ struct       table   *cregtab;
 int    nreg    = 3;
 int    isn     = 10000;
 
-main(argc, argv)
-int    argc;
-char   *argv[];
-{
+int main(argc, argv) int argc; char *argv[]; {
        char    buf1[BUFSIZ],
                buf2[BUFSIZ];
 
@@ -79,7 +75,7 @@ char  *argv[];
                setbuf(stdin,buf1);     /* sbrk problems */
                getree();
        }
-       if (totspace >= (unsigned)56000)
+       if (totspace >= (uint16_t)56000)
                werror("possibly too much data");
        exit(nerror!=0);
 }
@@ -92,11 +88,7 @@ char *argv[];
  * required is not too large.
  * Return a ptr to the table entry or 0 if none found.
  */
-struct optab *
-match(tree, table, nrleft, nocvt)
-union tree *tree;
-struct table *table;
-{
+struct optab *match(tree, table, nrleft, nocvt) union tree *tree; struct table *table; int nrleft; int nocvt; {
 #define        NOCVL   1
 #define        NOCVR   2
        int op, d1, d2, dope;
@@ -184,15 +176,13 @@ struct table *table;
  * A number of special cases are recognized, and
  * there is an interaction with the optimizer routines.
  */
-rcexpr(atree, atable, reg)
-union tree *atree;
-struct table *atable;
-{
-       register r;
+int rcexpr(atree, atable, reg) union tree *atree; struct table *atable; int reg; {
+       register int r;
        int modf, nargs, recurf;
        register union tree *tree;
        register struct table *table;
 
+ /*fprintf(stderr, "rcexpr(0x%08x, 0x%08x, 0x%08x)\n", atree, atable, reg);*/
        table = atable;
        recurf = 0;
        if (reg<0) {
@@ -461,10 +451,7 @@ again:
  * Most of the work is the macro-expansion of the
  * code table.
  */
-cexpr(tree, table, areg)
-register union tree *tree;
-struct table *table;
-{
+int cexpr(tree, table, areg) register union tree *tree; struct table *table; int areg; {
        int c, r;
        register union tree *p, *p1;
        struct table *ctable;
@@ -580,24 +567,38 @@ struct table *table;
        string = opt->tabstring;
        p1 = tree->t.tr1;
        if (p1->t.op==FCON && p1->f.value>0) {
+#if 1
+               printf(".data\nL%d:%o;%o;%o;%o\n.text\n", p1->f.value,
+                       p1->f.fvalue[0], p1->f.fvalue[1],
+                       p1->f.fvalue[2], p1->f.fvalue[3]);
+               p1->f.value = -p1->f.value;
+#else
 /* nonportable */
                printf(".data\nL%d:%o;%o;%o;%o\n.text\n", p1->f.value,
-                       ((unsigned short *)&(p1->f.fvalue))[0],
-                       ((unsigned short *)&(p1->f.fvalue))[1],
-                       ((unsigned short *)&(p1->f.fvalue))[2],
-                       ((unsigned short *)&(p1->f.fvalue))[3] );
+                       ((uint16_t *)&(p1->f.fvalue))[0],
+                       ((uint16_t *)&(p1->f.fvalue))[1],
+                       ((uint16_t *)&(p1->f.fvalue))[2],
+                       ((uint16_t *)&(p1->f.fvalue))[3]);
+/* this did not cause problems because c.value is overlaid on f.value */
                p1->c.value = -p1->c.value;
+#endif
        }
        p2 = 0;
        if (opdope[tree->t.op]&BINARY) {
                p2 = tree->t.tr2;
                if (p2->t.op==FCON && p2->f.value>0) {
+#if 1
+                       printf(".data\nL%d:%o;%o;%o;%o\n.text\n", p2->f.value,
+                               p2->f.fvalue[0], p2->f.fvalue[1],
+                               p2->f.fvalue[2], p2->f.fvalue[3]);
+#else
 /* nonportable */
                        printf(".data\nL%d:%o;%o;%o;%o\n.text\n", p2->f.value,
-                               ((unsigned short *)&(p2->f.fvalue))[0],
-                               ((unsigned short *)&(p2->f.fvalue))[1],
-                               ((unsigned short *)&(p2->f.fvalue))[2],
-                               ((unsigned short *)&(p2->f.fvalue))[3] );
+                               ((uint16_t *)&(p2->f.fvalue))[0],
+                               ((uint16_t *)&(p2->f.fvalue))[1],
+                               ((uint16_t *)&(p2->f.fvalue))[2],
+                               ((uint16_t *)&(p2->f.fvalue))[3]);
+#endif
                        p2->f.value = -p2->f.value;
                }
        }
@@ -907,11 +908,8 @@ loop:
  * on the subtrees and then on the tree itself.
  * It returns non-zero if anything changed.
  */
-reorder(treep, table, reg)
-union tree **treep;
-struct table *table;
-{
-       register r, o;
+int reorder(treep, table, reg) union tree **treep; struct table *table; int reg; {
+       register int r, o;
        register union tree *p;
 
        p = *treep;
@@ -941,10 +939,7 @@ struct table *table;
  * Moreover, expressions like "reg = x+y" are best done as
  * "reg = x; reg += y" (so long as "reg" and "y" are not the same!).
  */
-sreorder(treep, table, reg, recurf)
-union tree **treep;
-struct table *table;
-{
+int sreorder(treep, table, reg, recurf) union tree **treep; struct table *table; int reg; int recurf; {
        register union tree *p, *p1;
 
        p = *treep;
@@ -1038,12 +1033,9 @@ struct table *table;
  * Otherwise it uses sdelay to search for inc/dec
  * among the operands.
  */
-delay(treep, table, reg)
-union tree **treep;
-struct table *table;
-{
+int delay(treep, table, reg) union tree **treep; struct table *table; int reg; {
        register union tree *p, *p1;
-       register r;
+       register int r;
 
        p = *treep;
        if ((p->t.op==INCAFT||p->t.op==DECAFT)
@@ -1083,10 +1075,7 @@ struct table *table;
        return(0);
 }
 
-union tree *
-sdelay(ap)
-union tree **ap;
-{
+union tree *sdelay(ap) union tree **ap; {
        register union tree *p, *p1;
 
        if ((p = *ap)==TNULL)
@@ -1106,11 +1095,7 @@ union tree **ap;
 /*
  * Propagate possible implicit type-changing operation
  */
-union tree *
-paint(tp, type)
-register union tree *tp;
-register type;
-{
+union tree *paint(tp, type) register union tree *tp; register int type; {
 
        if (tp->t.type==type)
                return(tp);
@@ -1137,10 +1122,7 @@ register type;
  * be changed to some offset class, accidentally
  * modifying the reg--.
  */
-union tree *
-ncopy(p)
-register union tree *p;
-{
+union tree *ncopy(p) register union tree *p; {
        register union tree *q;
 
        q = getblk(sizeof(struct xtname));
@@ -1160,18 +1142,19 @@ register union tree *p;
  * If the tree can be immediately loaded into a register,
  * produce code to do so and return success.
  */
-chkleaf(tree, table, reg)
-register union tree *tree;
-struct table *table;
-{
+int chkleaf(tree, table, reg) register union tree *tree; struct table *table; int reg; {
        struct tnode lbuf;
 
+ /*fprintf(stderr, "chkleaf(0x%08x, 0x%08x, 0x%08x)\n", tree, table, reg);*/
        if (tree->t.op!=STAR && dcalc(tree, nreg-reg) > 12)
                return(-1);
        lbuf.op = LOAD;
        lbuf.type = tree->t.type;
        lbuf.degree = tree->t.degree;
        lbuf.tr1 = tree;
+#if 1 /* can't have garbage in lbuf.tr2, cexpr() will deref it if non-NULL */
+       lbuf.tr2 = NULL;
+#endif
        return(rcexpr((union tree *)&lbuf, table, reg));
 }
 
@@ -1182,11 +1165,8 @@ struct table *table;
  * Return the number of bytes pushed,
  * for future popping.
  */
-comarg(tree, flagp)
-register union tree *tree;
-int *flagp;
-{
-       register retval;
+int comarg(tree, flagp) register union tree *tree; int *flagp; {
+       register int retval;
        int i;
        int size;
 
@@ -1194,11 +1174,11 @@ int *flagp;
                size = tree->F.mask;
                tree = tree->t.tr1;
                tree = strfunc(tree);
-               if (size <= sizeof(short)) {
+               if (size <= sizeof(int16_t)) {
                        paint(tree, INT);
                        goto normal;
                }
-               if (size <= sizeof(long)) {
+               if (size <= sizeof(int32_t)) {
                        paint(tree, LONG);
                        goto normal;
                }
@@ -1236,10 +1216,7 @@ normal:
        return(retval);
 }
 
-union tree *
-strfunc(tp)
-register union tree *tp;
-{
+union tree *strfunc(tp) register union tree *tp; {
        if (tp->t.op != CALL)
                return(tp);
        paint(tp, STRUCT+PTR);
@@ -1249,13 +1226,17 @@ register union tree *tp;
 /*
  * Compile an initializing expression
  */
-doinit(type, tree)
-register type;
-register union tree *tree;
-{
+void doinit(type, tree) register int type; register union tree *tree; {
+#if 1
+       uint16_t sfval[2];
+       uint16_t fval[4];
+       uint16_t lval[2];
+       int16_t sign;
+#else
        float sfval;
        double fval;
-       long lval;
+       int32_t lval;
+#endif
 
        if (type==CHAR || type==UNCHAR) {
                printf(".byte ");
@@ -1272,15 +1253,39 @@ register union tree *tree;
                        if (tree->t.tr1->t.op!=FCON && tree->t.tr1->t.op!=SFCON)
                                goto illinit;
                        tree = tree->t.tr1;
+#if 1
+#ifdef pdp11
+                       tree->c.value = *(double *)tree->f.fvalue;
+#else
+                       /* movf 6(r3),r0 */
+                       pdp11_ldf(0, tree->f.fvalue, 063);
+                       /* movfi r0, 4(r3) */
+                       pdp11_movfi(0, (uint16_t *)&tree->c.value, 063);
+#endif
+#else
                        tree->c.value = tree->f.fvalue;
+#endif
                        tree->t.op = CON;
                } else if (tree->t.op==LTOI) {
                        if (tree->t.tr1->t.op!=LCON)
                                goto illinit;
                        tree = tree->t.tr1;
+#if 1
+#ifdef pdp11
+                       *(int32_t *)lval = *(int32_t *)tree->l.lvalue;
+#else
+                       lval[0] = tree->l.lvalue[0];
+                       lval[1] = tree->l.lvalue[1];
+#endif
+#else
                        lval = tree->l.lvalue;
+#endif
                        tree->t.op = CON;
+#if 1
+                       tree->c.value = lval[1];
+#else
                        tree->c.value = lval;
+#endif
                }
                if (tree->t.op == CON)
                        printf("%o\n", UNS(tree->c.value));
@@ -1295,29 +1300,84 @@ register union tree *tree;
        case FLOAT:
                if (tree->t.op==ITOF) {
                        if (tree->t.tr1->t.op==CON) {
+#if 1 /* note: this should be changed to respect the signedness of the int */
+#ifdef pdp11
+                               *(double *)fval = tree->t.tr1->c.value;
+#else
+                               /* movif 4(r0),r0 */
+                               pdp11_movif(0, (uint16_t *)&tree->t.tr1->c.value,
+                                       060);
+#endif
+#else
                                fval = tree->t.tr1->c.value;
+#endif
                        } else
                                goto illinit;
-               } else if (tree->t.op==FCON || tree->t.op==SFCON)
+               } else if (tree->t.op==FCON || tree->t.op==SFCON) {
+#if 1
+#ifdef pdp11
+                       *(double *)fval = *(double *)tree->f.fvalue;
+#else
+                       /* movf 6(r3),r0 */
+                       pdp11_ldf(0, tree->f.fvalue, 063);
+#endif
+#else
                        fval = tree->f.fvalue;
-               else if (tree->t.op==LTOF) {
+#endif
+               } else if (tree->t.op==LTOF) {
                        if (tree->t.tr1->t.op!=LCON)
                                goto illinit;
+#if 1 /* note: this should be changed to respect the signedness of the long */
+#ifdef pdp11
+                       *(double *)fval = *(long *)tree->t.tr1->l.lvalue;
+#else
+                       /* setl */
+                       pdp11_setl();
+                       /* movif 4(r0),r0 */
+                       pdp11_movif(0, tree->t.tr1->l.lvalue, 060);
+                       /* seti */
+                       pdp11_seti();
+#endif
+#else
                        fval = tree->t.tr1->l.lvalue;
+#endif
                } else
                        goto illinit;
+#if 1
+#ifndef PDP11
+               /* movf r0,-24(r5) */
+               pdp11_stf(0, fval, 065);
+#endif
+#endif
                if (type==FLOAT) {
+#if 1
+#ifdef pdp11
+                       *(float *)sfval = *(double *)fval;
+#else
+                       /* movfo r0,-14(r5) */
+                       pdp11_stcfo(0, sfval, 065);
+#endif
+                       printf("%o; %o\n", sfval[0], sfval[1]);
+#else
                        sfval = fval;
-/* nonportable */
+/*nonportable*/
                        printf("%o; %o\n",
-                               ((unsigned short *)&sfval)[0],
-                               ((unsigned short *)&sfval)[1] );
-               } else
+                               ((uint16_t *)&sfval)[0],
+                               ((uint16_t *)&sfval)[1]);
+#endif
+               } else {
+#if 1
+                       printf("%o; %o; %o; %o\n",
+                               fval[0], fval[1], fval[2], fval[3]);
+#else
+/* nonportable */
                        printf("%o; %o; %o; %o\n",
-                               ((unsigned short *)&fval)[0],
-                               ((unsigned short *)&fval)[1],
-                               ((unsigned short *)&fval)[2],
-                               ((unsigned short *)&fval)[3] );
+                               ((uint16_t *)&fval)[0],
+                               ((uint16_t *)&fval)[1],
+                               ((uint16_t *)&fval)[2],
+                               ((uint16_t *)&fval)[3]);
+#endif
+               }
                return;
 
        case UNLONG:
@@ -1328,29 +1388,70 @@ register union tree *tree;
                                tree->t.op = FCON;
                        if (tree->t.op!= FCON)
                                goto illinit;
+#if 1
+#ifdef pdp11
+                       *(int32_t *)lval = *(double *)tree->f.fvalue;
+#else
+                       /* movf 6(r3),r0 */
+                       pdp11_ldf(0, tree->f.fvalue, 063);
+                       /* setl */
+                       pdp11_setl();
+                       /* movfi r0,-30(r5) */
+                       pdp11_movfi(0, lval, 065);
+                       /* seti */
+                       pdp11_seti();
+#endif
+#else
                        lval = tree->f.fvalue;
+#endif
                } else if (tree->t.op==ITOL) {
                        if (tree->t.tr1->t.op != CON)
                                goto illinit;
+#if 1
+#ifdef pdp11
+                       if (uns(tree->t.tr1))
+                               *(int32_t *)lval = (uint16_t)
+                                       tree->t.tr1->c.value;
+                       else
+                               *(int32_t *)lval = tree->t.tr1->c.value;
+#else
+                       sign = uns(tree->t.tr1) ?
+                               0 : (tree->t.tr1->c.value < 0);
+                       lval[1] = tree->t.tr1->c.value;
+                       lval[0] = -sign;
+#endif
+#else
                        if (uns(tree->t.tr1))
-                               lval = (unsigned)tree->t.tr1->c.value;
+                               lval = (uint16_t)tree->t.tr1->c.value;
                        else
                                lval = tree->t.tr1->c.value;
-               } else if (tree->t.op==LCON)
+#endif
+               } else if (tree->t.op==LCON) {
+#if 1
+#ifdef pdp11
+                       *(int32_t *)lval = *(int32_t *)tree->l.lvalue;
+#else
+                       lval[0] = tree->l.lvalue[0];
+                       lval[1] = tree->l.lvalue[1];
+#endif
+#else
                        lval = tree->l.lvalue;
-               else
+#endif
+               } else
                        goto illinit;
 /* nonportable */
+#if 1
+               printf("%o; %o\n", lval[0], lval[1]);
+#else
                printf("%o; %o\n", UNS((lval>>16)), UNS(lval));
+#endif
                return;
        }
 illinit:
        error("Illegal initialization");
 }
 
-movreg(r0, r1, tree)
-union tree *tree;
-{
+void movreg(r0, r1, tree) int r0; int r1; union tree *tree; {
        register char *s;
        char c;
 
index 8decf6d..a332266 100644 (file)
@@ -2,11 +2,14 @@
  *  C compiler
  */
 
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
 #include "c1.h"
 
-degree(t)
-register union tree *t;
-{
+static void outname PARAMS((char *s));
+
+int degree(t) register union tree *t; {
        register union tree *t1;
 
        if (t==NULL || t->t.op==0)
@@ -29,17 +32,19 @@ register union tree *t;
        return(t->t.degree);
 }
 
-pname(p, flag)
-register union tree *p;
-{
-       register i;
+void pname(p, flag) register union tree *p; int flag; {
+       register int i;
 
 loop:
        switch(p->t.op) {
 
        case LCON:
+#if 1
+               printf("$%o", p->l.lvalue[(flag<=10) ? 0 : 1]);
+#else
                printf("$%o", flag<=10? UNS(p->l.lvalue>>16):
                   UNS(p->l.lvalue));
+#endif
                return;
 
        case SFCON:
@@ -110,9 +115,7 @@ loop:
        error("compiler error: bad pname");
 }
 
-pbase(p)
-register union tree *p;
-{
+void pbase(p) register union tree *p; {
 
        if (p->n.class==SOFFS || p->n.class==STATIC)
                printf("L%d", p->n.nloc);
@@ -120,10 +123,8 @@ register union tree *p;
                printf("%s", p->x.name);
 }
 
-xdcalc(p, nrleft)
-register union tree *p;
-{
-       register d;
+int xdcalc(p, nrleft) register union tree *p; int nrleft; {
+       register int d;
 
        if (p==NULL)
                return(0);
@@ -137,9 +138,7 @@ register union tree *p;
        return(d);
 }
 
-dcalc(p, nrleft)
-register union tree *p;
-{
+int dcalc(p, nrleft) register union tree *p; int nrleft; {
        register union tree *p1;
 
        if (p==NULL)
@@ -178,9 +177,7 @@ register union tree *p;
        return(p->t.degree <= nrleft? 20: 24);
 }
 
-notcompat(p, ast, deg, op)
-register union tree *p;
-{
+int notcompat(p, ast, deg, op) register union tree *p; int ast; int deg; int op; {
        unsigned register at, st;
 
        at = p->t.type;
@@ -209,10 +206,7 @@ register union tree *p;
        return(st != at);
 }
 
-prins(op, c, itable, lbl)
-struct instab *itable;
-{
-       extern char     jmijne[];
+int prins(op, c, itable, lbl) int op; int c; struct instab *itable; int lbl; {
        register struct instab  *insp;
        register char   *ip;
        register int    skip;
@@ -237,10 +231,8 @@ struct instab *itable;
        return(skip);
 }
 
-collcon(p)
-register union tree *p;
-{
-       register op;
+int collcon(p) register union tree *p; {
+       register int op;
 
        if (p==NULL)
                return(0);
@@ -257,9 +249,7 @@ register union tree *p;
        return(0);
 }
 
-isfloat(t)
-register union tree *t;
-{
+int isfloat(t) register union tree *t; {
 
        if ((opdope[t->t.op]&RELAT)!=0)
                t = t->t.tr1;
@@ -270,10 +260,7 @@ register union tree *t;
        return(0);
 }
 
-oddreg(t, reg)
-register union tree *t;
-register reg;
-{
+int oddreg(t, reg) register union tree *t; register int reg; {
 
        if (!isfloat(t)) {
                if (opdope[t->t.op]&RELAT) {
@@ -305,8 +292,7 @@ register reg;
        return(reg);
 }
 
-arlength(t)
-{
+int arlength(t) int t; {
        if (t>=PTR)
                return(2);
        switch(t) {
@@ -363,9 +349,7 @@ L%d:\
  * try using the calls to lrem and ldiv.
  */
 
-pswitch(afp, alp, deflab)
-struct swtab *afp, *alp;
-{
+void pswitch(afp, alp, deflab) struct swtab *afp; struct swtab *alp; int deflab; {
        int ncase, i, j, tabs, worst, best, range;
        register struct swtab *swp, *fp, *lp;
        int *poctab;
@@ -415,7 +399,7 @@ struct swtab *afp, *alp;
                        poctab[j] = 0;
                for (swp=fp; swp<=lp; swp++)
                        /* lrem(0, swp->swval, i) */
-                       poctab[(unsigned)swp->swval%i]++;
+                       poctab[(uint16_t)swp->swval%i]++;
                worst = 0;
                for (j=0; j<i; j++)
                        if (poctab[j]>worst)
@@ -435,17 +419,16 @@ struct swtab *afp, *alp;
                printf("L%d:", isn++);
                for (swp=fp; swp<=lp; swp++) {
                        /* lrem(0, swp->swval, tabs) */
-                       if ((unsigned)swp->swval%tabs == i) {
+                       if ((uint16_t)swp->swval%tabs == i) {
                                /* ldiv(0, swp->swval, tabs) */
-                               breq((int)((unsigned)swp->swval/tabs), swp->swlab);
+                               breq((int)((uint16_t)swp->swval/tabs), swp->swlab);
                        }
                }
                printf("jbr     L%d\n", deflab);
        }
 }
 
-breq(v, l)
-{
+void breq(v, l) int v; int l; {
        if (v==0)
                printf("tst     r0\n");
        else
@@ -453,9 +436,7 @@ breq(v, l)
        printf("jeq     L%d\n", l);
 }
 
-sort(afp, alp)
-struct swtab *afp, *alp;
-{
+int sort(afp, alp) struct swtab *afp; struct swtab *alp; {
        register struct swtab *cp, *fp, *lp;
        int intch, t;
 
@@ -484,9 +465,7 @@ struct swtab *afp, *alp;
        return(0);
 }
 
-ispow2(tree)
-register union tree *tree;
-{
+int ispow2(tree) register union tree *tree; {
        register int d;
 
        if (!isfloat(tree) && tree->t.tr2->t.op==CON) {
@@ -497,10 +476,7 @@ register union tree *tree;
        return(0);
 }
 
-union tree *
-pow2(tree)
-register union tree *tree;
-{
+union tree *pow2(tree) register union tree *tree; {
        register int d, i;
 
        if (d = ispow2(tree)) {
@@ -557,10 +533,7 @@ register union tree *tree;
        return(tree);
 }
 
-cbranch(atree, lbl, cond, reg)
-union tree *atree;
-register lbl, reg;
-{
+void cbranch(atree, lbl, cond, reg) union tree *atree; register int lbl; int cond; register int reg; {
        int l1, op;
        register union tree *tree;
 
@@ -647,8 +620,7 @@ again:
        branch(lbl, op, !cond);
 }
 
-branch(lbl, aop, c)
-{
+void branch(lbl, aop, c) int lbl; int aop; int c; {
        register int    op,
                        skip;
 
@@ -664,9 +636,7 @@ branch(lbl, aop, c)
                printf("\tL%d\n", lbl);
 }
 
-longrel(atree, lbl, cond, reg)
-union tree *atree;
-{
+void longrel(atree, lbl, cond, reg) union tree *atree; int lbl; int cond; int reg; {
        int xl1, xl2, xo, xz;
        register int op, isrel;
        register union tree *tree;
@@ -733,17 +703,19 @@ union tree *atree;
  * Third dimension (lrtab[][][x]) indexed by "x - EQUAL".
  */
 char   lrtab[2][3][10] = {
-       0, NEQUAL, LESS, LESS, GREAT, GREAT, LESSP, LESSP, GREATP, GREATP,
-       NEQUAL, 0, GREAT, GREAT, LESS, LESS, GREATP, GREATP, LESSP, LESSP,
-       EQUAL,NEQUAL,LESSEQP,LESSP, GREATQP,GREATP,LESSEQP,LESSP,GREATQP,GREATP,
-
-       0, NEQUAL, LESS, LESS,  GREATEQ,GREAT, LESSP, LESSP, GREATQP, GREATP,
-       NEQUAL, 0, GREAT, 0, 0, LESS, GREATP, 0, 0, LESSP,
-       EQUAL,  NEQUAL, EQUAL,  0, 0, NEQUAL, EQUAL, 0, 0, NEQUAL,
+       {
+               {0, NEQUAL, LESS, LESS, GREAT, GREAT, LESSP, LESSP, GREATP, GREATP},
+               {NEQUAL,        0, GREAT, GREAT, LESS, LESS, GREATP, GREATP, LESSP, LESSP},
+               {EQUAL,NEQUAL,LESSEQP,LESSP, GREATQP,GREATP,LESSEQP,LESSP,GREATQP,GREATP}
+       },
+       {
+               {0, NEQUAL, LESS, LESS, GREATEQ,GREAT, LESSP, LESSP, GREATQP, GREATP},
+               {NEQUAL,        0, GREAT, 0, 0, LESS, GREATP, 0, 0, LESSP},
+               {EQUAL, NEQUAL, EQUAL,  0, 0, NEQUAL, EQUAL, 0, 0, NEQUAL}
+       }
 };
 
-xlongrel(f)
-{
+int xlongrel(f) int f; {
        register int op, bno;
 
        op = xop;
@@ -764,13 +736,11 @@ xlongrel(f)
        return(0);
 }
 
-label(l)
-{
+void label(l) int l; {
        printf("L%d:", l);
 }
 
-popstk(a)
-{
+void popstk(a) int a; {
        switch(a) {
 
        case 0:
@@ -787,26 +757,28 @@ popstk(a)
        printf("add     $%o,sp\n", UNS(a));
 }
 
-werror(s)
-char *s;
-{
+void werror(s) char *s; {
 
        fprintf(stderr, "%d: %s\n",line,s);
 }
 
-/* VARARGS1 */
-error(s, p1, p2, p3, p4, p5, p6)
-char *s;
+#ifdef __STDC__
+void error(char *s, ...)
+#else
+void error(s, va_alist) char *s; va_dcl
+#endif
 {
+       va_list ap;
 
        nerror++;
        fprintf(stderr, "%d: ", line);
-       fprintf(stderr, s, p1, p2, p3, p4, p5, p6);
+       va_start(ap, s);
+       vfprintf(stderr, s, ap);
+       va_end(ap);
        putc('\n', stderr);
-}
+}      
 
-psoct(an)
-{
+void psoct(an) int an; {
        register int n;
        register char *sign;
 
@@ -822,8 +794,7 @@ psoct(an)
  * Read in an intermediate file.
  */
 #define        STKS    100
-getree()
-{
+void getree() {
        union tree *expstack[STKS], **sp;
        register union tree *tp;
        register int t, op;
@@ -831,7 +802,6 @@ getree()
        struct swtab *swp;
        long outloc;
        int lbl, cond, lbl2, lbl3;
-       double atof();
 
        curbase = funcbase;
        sp = expstack;
@@ -895,7 +865,7 @@ getree()
 
        case SSPACE:
                printf(".=.+%o\n", UNS(t=geti()));
-               totspace += (unsigned)t;
+               totspace += (uint16_t)t;
                break;
 
        case EVEN:
@@ -1033,7 +1003,12 @@ getree()
                tp = getblk(sizeof(struct lconst));
                tp->t.op = LCON;
                tp->t.type = LONG;
-               tp->l.lvalue = ((long)t<<16) + UNS(op); /* nonportable */
+#if 1
+               tp->l.lvalue[0] = t;
+               tp->l.lvalue[1] = op;
+#else
+               tp->l.lvalue = ((int32_t)t<<16) + UNS(op); /* nonportable */
+#endif
                *sp++ = tp;
                break;
 
@@ -1044,7 +1019,13 @@ getree()
                tp->t.op = FCON;
                tp->t.type = t;
                tp->f.value = isn++;
-               tp->f.fvalue = atof(s);
+#ifdef pdp11
+               *(long *)tp->f.fvalue = atof(s);
+#else
+               pdp11_atof(s);
+               /* movf r0,6(r4) */
+               pdp11_stf(0, tp->f.fvalue, 064);
+#endif
                *sp++ = tp;
                break;
 
@@ -1100,7 +1081,11 @@ getree()
                                exit(1);
                        }
                        tp = *--sp;
+#if 1
+                       sp[-1] = tnode(op, geti(), sp[-1], tp);
+#else
                        *sp++ = tnode(op, geti(), *--sp, tp);
+#endif
                } else
                        sp[-1] = tnode(op, geti(), sp[-1], TNULL);
                break;
@@ -1108,19 +1093,15 @@ getree()
        }
 }
 
-geti()
-{
-       register short i;
+int geti() {
+       register int16_t i;
 
        i = getchar() & 0xff;
        i |= (getchar() & 0xff) << 8;
        return(i);
 }
 
-static
-outname(s)
-register char *s;
-{
+static void outname(s) register char *s; {
        register int c;
 
        while (c = getchar())
@@ -1128,13 +1109,11 @@ register char *s;
        *s++ = '\0';
 }
 
-strasg(atp)
-union tree *atp;
-{
+void strasg(atp) union tree *atp; {
        register union tree *tp;
-       register nwords, i;
+       register int nwords, i;
 
-       nwords = atp->F.mask/sizeof(short);
+       nwords = atp->F.mask/sizeof(int16_t);
        tp = atp->t.tr1;
        while (tp->t.op == SEQNC) {
                rcexpr(tp->t.tr1, efftab, 0);
@@ -1145,7 +1124,7 @@ union tree *atp;
                        if (sfuncr.nloc==0) {
                                sfuncr.nloc = isn++;
                                printf(".bss\nL%d:.=.+%o\n.text\n", sfuncr.nloc,
-                                       UNS(nwords*sizeof(short)));
+                                       UNS(nwords*sizeof(int16_t)));
                        }
                        atp->t.tr1 = tnode(ASSIGN, STRUCT, (union tree *)&sfuncr, tp->t.tr1);
                        strasg(atp);
@@ -1162,7 +1141,7 @@ union tree *atp;
        tp->t.tr2 = strfunc(tp->t.tr2);
        if (nwords==1)
                paint(tp, INT);
-       else if (nwords==sizeof(short))
+       else if (nwords==sizeof(int16_t))
                paint(tp, LONG);
        else {
                if (tp->t.tr1->t.op!=NAME && tp->t.tr1->t.op!=STAR
@@ -1197,21 +1176,18 @@ union tree *atp;
  * Reduce the degree-of-reference by one.
  * e.g. turn "ptr-to-int" into "int".
  */
-decref(t)
-register t;
-{
+int decref(t) register int t; {
        if ((t & ~TYPE) == 0) {
                error("Illegal indirection");
                return(t);
        }
-       return(((unsigned)t>>TYLEN) & ~TYPE | t&TYPE);
+       return(((uint16_t)t>>TYLEN) & ~TYPE | t&TYPE);
 }
 
 /*
  * Increase the degree of reference by
  * one; e.g. turn "int" to "ptr-to-int".
  */
-incref(t)
-{
+int incref(t) register int t; {
        return(((t&~TYPE)<<TYLEN) | (t&TYPE) | PTR);
 }
index fe127d1..27d7c93 100644 (file)
@@ -2,17 +2,18 @@
  *             C compiler part 2 -- expression optimizer
  */
 
+#include <stdlib.h>
 #include "c1.h"
 #include <sys/param.h>         /* for MAX */
 
-union tree *
-optim(tree)
-register union tree *tree;
-{
-       register op, dope;
+union tree *optim(tree) register union tree *tree; {
+       register int op, dope;
        int d1, d2;
        union tree *t;
-       union { double dv; int iv[4];} fp11;
+#if 0
+/* nonportable */
+       union { double dv; int16_t iv[4];} fp11;
+#endif
 
        if (tree==NULL)
                return(NULL);
@@ -26,6 +27,15 @@ register union tree *tree;
        dope = opdope[op];
        if ((dope&LEAF) != 0) {
                if (op==FCON) {
+#if 1
+                       if (tree->f.fvalue[1]==0
+                        && tree->f.fvalue[2]==0
+                        && tree->f.fvalue[3]==0) {
+                               tree->t.op = SFCON;
+                               tree->f.value = tree->f.fvalue[0];
+                       }
+#else
+/* nonportable */
                        fp11.dv = tree->f.fvalue;
                        if (fp11.iv[1]==0
                         && fp11.iv[2]==0
@@ -33,6 +43,7 @@ register union tree *tree;
                                tree->t.op = SFCON;
                                tree->f.value = fp11.iv[0];
                        }
+#endif
                }
                return(tree);
        }
@@ -65,12 +76,19 @@ register union tree *tree;
 
        case MINUS:
                if ((t = isconstant(tree->t.tr2)) && (!uns(t) || tree->t.type!=LONG)
-                && (t->t.type!=INT || t->c.value!=0100000)) {
+                && (t->t.type!=INT || t->c.value!=(int16_t)0100000)) {
                        tree->t.op = PLUS;
-                       if (t->t.type==DOUBLE)
+                       if (t->t.type==DOUBLE) {
+#if 1
+                               if (t->f.value)
+                                       t->f.value ^= 0100000;
+#else
+/* this did not cause problems because f.value is overlaid on c.value */
+/* this should have been checking for f.value == 0 to preserve clean zeros */
                                /* PDP-11 FP representation */
                                t->c.value ^= 0100000;
-                       else
+#endif
+                       } else
                                t->c.value = -t->c.value;
                }
                break;
@@ -264,7 +282,7 @@ register union tree *tree;
 
        constant:
                if (tree->t.tr1->t.op==CON && tree->t.tr2->t.op==CON) {
-                       const(op, &tree->t.tr1->c.value, tree->t.tr2->c.value, tree->t.type);
+                       _const(op, &tree->t.tr1->c.value, tree->t.tr2->c.value, tree->t.type);
                        return(tree->t.tr1);
                }
 
@@ -295,11 +313,14 @@ register union tree *tree;
        return(tree);
 }
 
-union tree *
-unoptim(tree)
-register union tree *tree;
-{
+union tree *unoptim(tree) register union tree *tree; {
        register union tree *subtre, *p;
+#if 1
+#ifndef PDP11
+       int16_t sign;
+       uint16_t temp[2];
+#endif
+#endif
 
        if (tree==NULL)
                return(NULL);
@@ -323,7 +344,17 @@ register union tree *tree;
                        subtre = getblk(sizeof(struct lconst));
                        subtre->t.op = LCON;
                        subtre->t.type = LONG;
+#if 1
+#ifdef pdp11
+                       *(int32_t *)subtre->l.lvalue = tree->t.tr1->c.value;
+#else
+                       sign = (tree->t.tr1->c.value < 0);
+                       subtre->l.lvalue[1] = tree->t.tr1->c.value;
+                       subtre->l.lvalue[0] = -sign;
+#endif
+#else
                        subtre->l.lvalue = tree->t.tr1->c.value;
+#endif
                        return(subtre);
                }
                break;
@@ -342,7 +373,23 @@ register union tree *tree;
                        tree->t.op = FCON;
                        tree->t.type = DOUBLE;
                        tree->c.value = isn++;
+#if 1
+#ifdef pdp11
+                       *(double *)tree->f.fvalue =
+                               *(int32_t *)subtre->l.lvalue;
+#else
+                       /* setl */
+                       pdp11_setl();
+                       /* movif 4(r3),r0 */
+                       pdp11_movif(0, subtre->l.lvalue, 063);
+                       /* seti */
+                       pdp11_seti();
+                       /* movf r0,6(r4) */
+                       pdp11_stf(0, tree->f.fvalue, 064);
+#endif
+#else
                        tree->f.fvalue = subtre->l.lvalue;
+#endif
                        return(optim(tree));
                }
                if (subtre->t.type==UNLONG) 
@@ -355,10 +402,32 @@ register union tree *tree;
                        tree->t.op = FCON;
                        tree->t.type = DOUBLE;
                        tree->f.value = isn++;
+#if 1
+#ifdef pdp11
+                       if (uns(subtre))
+                               *(double *)tree->f.fvalue =
+                                       (uint16_t)subtre->c.value;
+                       else
+                               *(double *)tree->f.fvalue = subtre->c.value;
+#else
+                       sign = uns(subtre) ? 0 : (subtre->c.value < 0);
+                       temp[1] = subtre->c.value;
+                       temp[0] = -sign;
+                       /* setl */
+                       pdp11_setl();
+                       /* movif (sp)+,r0 */
+                       pdp11_movif(0, temp, 026);
+                       /* seti */
+                       pdp11_seti();
+                       /* movf r0,6(r4) */
+                       pdp11_stf(0, tree->f.fvalue, 064);
+#endif
+#else
                        if (uns(subtre))
-                               tree->f.fvalue = (unsigned)subtre->c.value;
+                               tree->f.fvalue = (uint16_t)subtre->c.value;
                        else
                                tree->f.fvalue = subtre->c.value;
+#endif
                        return(optim(tree));
                }
                if (uns(subtre)) {
@@ -390,7 +459,15 @@ register union tree *tree;
                case LCON:
                        subtre->t.op = CON;
                        subtre->t.type = tree->t.type;
+#if 1
+#ifdef pdp11
+                       subtre->c.value = *(int32_t *)subtre->l.lvalue;
+#else
+                       subtre->c.value = subtre->l.lvalue[1];
+#endif
+#else
                        subtre->c.value = subtre->l.lvalue;
+#endif
                        return(subtre);
 
                case NAME:
@@ -524,7 +601,17 @@ register union tree *tree;
                        return(paint(subtre, tree->t.type));
                }
                if (subtre->t.op==LCON) {
+#if 1
+#ifdef pdp11
+                       *(int32_t *)subtre->l.lvalue =
+                               ~*(int32_t *)subtre->l.lvalue;
+#else
+                       subtre->l.lvalue[0] = ~subtre->l.lvalue[0];
+                       subtre->l.lvalue[1] = ~subtre->l.lvalue[1];
+#endif
+#else
                        subtre->l.lvalue = ~subtre->l.lvalue;
+#endif
                        return(subtre);
                }
                if (subtre->t.op==ITOL) {
@@ -532,10 +619,30 @@ register union tree *tree;
                                tree = getblk(sizeof(struct lconst));
                                tree->t.op = LCON;
                                tree->t.type = LONG;
+#if 1
+#ifdef pdp11
+                               if (uns(subtre->t.tr1)) {
+                                       *(int32_t *)tree->l.lvalue =
+                                               ~(int32_t)(uint16_t)
+                                               subtre->t.tr1->c.value;
+                               } else {
+                                       *(int32_t *)tree->l.lvalue =
+                                               ~subtre->t.tr1->c.value;
+                               }
+#else
+                               sign = uns(subtre->t.tr1) ?
+                                       0 : (subtre->t.tr1->c.value < 0);
+                               tree->l.lvalue[1] = ~subtre->t.tr1->c.value;
+                               tree->l.lvalue[0] = ~-sign;
+#endif
+#else
                                if (uns(subtre->t.tr1))
-                                       tree->l.lvalue = ~(long)(unsigned)subtre->t.tr1->c.value;
+                                       tree->l.lvalue = ~(int32_t)(uint16_t)
+                                               subtre->t.tr1->c.value;
                                else
-                                       tree->l.lvalue = ~subtre->t.tr1->c.value;
+                                       tree->l.lvalue =
+                                               ~subtre->t.tr1->c.value;
+#endif
                                return(tree);
                        }
                        if (uns(subtre->t.tr1))
@@ -557,29 +664,84 @@ register union tree *tree;
                        return(paint(subtre, tree->t.type));
                }
                if (subtre->t.op==LCON) {
+#if 1
+#ifdef pdp11
+                       *(int32_t *)subtre->l.lvalue =
+                               -*(int32_t *)subtre->l.lvalue;
+#else
+                       subtre->l.lvalue[1] = -subtre->l.lvalue[1];
+                       subtre->l.lvalue[0] = ~subtre->l.lvalue[0];
+                       if (subtre->l.lvalue[1] == 0)
+                               subtre->l.lvalue[0]++;
+#endif
+#else
                        subtre->l.lvalue = -subtre->l.lvalue;
+#endif
                        return(subtre);
                }
                if (subtre->t.op==ITOL && subtre->t.tr1->t.op==CON) {
                        tree = getblk(sizeof(struct lconst));
                        tree->t.op = LCON;
                        tree->t.type = LONG;
+#if 1
+#ifdef pdp11
+                       if (uns(subtre->t.tr1)) {
+                               *(int32_t *)tree->l.lvalue =
+                                       -(int32_t)(uint16_t)
+                                       subtre->t.tr1->c.value;
+                       } else {
+                               *(int32_t *)tree->l.lvalue =
+                                       -subtre->t.tr1->c.value;
+                       }
+#else
+                       sign = uns(subtre->t.tr1) ?
+                               0 : (subtre->t.tr1->c.value < 0);
+                       tree->l.lvalue[1] = -subtre->t.tr1->c.value;
+                       tree->l.lvalue[0] = ~-sign;
+                       if (tree->l.lvalue[1] == 0)
+                               tree->l.lvalue[0]++;
+#endif
+#else
                        if (uns(subtre->t.tr1))
-                               tree->l.lvalue = -(long)(unsigned)subtre->t.tr1->c.value;
+                               tree->l.lvalue = -(int32_t)(uint16_t)
+                                       subtre->t.tr1->c.value;
                        else
                                tree->l.lvalue = -subtre->t.tr1->c.value;
+#endif
                        return(tree);
                }
                /*
                 * PDP-11 FP negation
                 */
                if (subtre->t.op==SFCON) {
+#if 1
+                       if (subtre->f.value)
+                               subtre->f.value ^= 0100000;
+#ifdef pdp11
+                       *(double *)subtre->f.fvalue =
+                               -*(double *)subtre->f.fvalue;
+#else
+                       pdp11_negf(subtre->f.fvalue, 065);
+#endif
+#else
+/* this did not cause problems because f.value is overlaid on c.value */
+/* this should have been checking for f.value == 0 to preserve clean zeros */
                        subtre->c.value ^= 0100000;
                        subtre->f.fvalue = -subtre->f.fvalue;
+#endif
                        return(subtre);
                }
                if (subtre->t.op==FCON) {
+#if 1
+#ifdef pdp11
+                       *(double *)subtre->f.fvalue =
+                               -*(double *)subtre->f.fvalue;
+#else
+                       pdp11_negf(subtre->f.fvalue, 065);
+#endif
+#else
                        subtre->f.fvalue = -subtre->f.fvalue;
+#endif
                        return(subtre);
                }
        }
@@ -598,10 +760,7 @@ register union tree *tree;
  * Pure assignment is handled specially.
  */
 
-union tree *
-lvfield(t)
-register union tree *t;
-{
+union tree *lvfield(t) register union tree *t; {
        register union tree *t1, *t2;
 
        switch (t->t.op) {
@@ -640,6 +799,7 @@ register union tree *t;
        return(t);
 }
 
+#if 0 /* now moved to c1.h */
 #define        LSTSIZ  20
 struct acl {
        int nextl;
@@ -647,11 +807,9 @@ struct acl {
        union tree *nlist[LSTSIZ];
        union tree *llist[LSTSIZ+1];
 };
+#endif
 
-union tree *
-acommute(tree)
-register union tree *tree;
-{
+union tree *acommute(tree) register union tree *tree; {
        struct acl acl;
        int d, i, op, flt, d1, type;
        register union tree *t1, **t2;
@@ -672,7 +830,7 @@ register union tree *tree;
                        if (t2[0]->t.op==CON && t2[-1]->t.op==CON) {
                                acl.nextl--;
                                t2--;
-                               const(op, &t2[0]->c.value, t2[1]->c.value, d);
+                               _const(op, &t2[0]->c.value, t2[1]->c.value, d);
                                t2[0]->t.type = d;
                        } else if (t = lconst(op, t2[-1], t2[0])) {
                                acl.nextl--;
@@ -684,7 +842,12 @@ register union tree *tree;
        if (op==PLUS || op==OR) {
                /* toss out "+0" */
                if (acl.nextl>0 && ((t1 = isconstant(*t2)) && t1->c.value==0
+#if 1
+                || (*t2)->t.op==LCON
+                && ((*t2)->l.lvalue[0]==0 && (*t2)->l.lvalue[1]==0))) {
+#else
                 || (*t2)->t.op==LCON && (*t2)->l.lvalue==0)) {
+#endif
                        acl.nextl--;
                        t2--;
                }
@@ -761,10 +924,8 @@ register union tree *tree;
        return(tree);
 }
 
-sideeffects(tp)
-register union tree *tp;
-{
-       register dope;
+int sideeffects(tp) register union tree *tp; {
+       register int dope;
 
        if (tp==NULL)
                return(0);
@@ -789,9 +950,7 @@ register union tree *tp;
        return(0);
 }
 
-distrib(list)
-struct acl *list;
-{
+void distrib(list) struct acl *list; {
 /*
  * Find a list member of the form c1c2*x such
  * that c1c2 divides no other such constant, is divided by
@@ -862,22 +1021,18 @@ struct acl *list;
        goto loop;
 }
 
-squash(p, maxp)
-union tree **p, **maxp;
-{
+void squash(p, maxp) union tree **p; union tree **maxp; {
        register union tree **np;
 
        for (np = p; np < maxp; np++)
                *np = *(np+1);
 }
 
-const(op, vp, v, type)
-register int *vp, v;
-{
+void _const(op, vp, v, type) int op; register int16_t *vp; register int16_t v; int type; {
        switch (op) {
 
        case PTOI:
-               (*vp) /= (unsigned)v;
+               (*vp) /= (uint16_t)v;
                return;
 
        case PLUS:
@@ -909,14 +1064,14 @@ register int *vp, v;
                        if (op==UDIV || op==DIVIDE) {
                                if (v==1)
                                        return;
-                               *vp = *(unsigned *)vp >= (unsigned)v;
+                               *vp = *(uint16_t *)vp >= (uint16_t)v;
                                return;
                        } else {
                                if (v==1) {
                                        *vp = 0;
                                        return;
                                }
-                               if (*(unsigned *)vp >= (unsigned)v)
+                               if (*(uint16_t *)vp >= (uint16_t)v)
                                        *vp -= v;
                                return;
                        }
@@ -931,9 +1086,9 @@ register int *vp, v;
                                        *vp %= v;
                        else
                                if (op==DIVIDE || op==UDIV)
-                                       *(unsigned *)vp /= (unsigned)v;
+                                       *(uint16_t *)vp /= (uint16_t)v;
                                else
-                                       *(unsigned *)vp %= (unsigned)v;
+                                       *(uint16_t *)vp %= (uint16_t)v;
                        return;
 
        case RSHIFT:
@@ -945,7 +1100,7 @@ register int *vp, v;
                if (type==INT)
                        *vp >>= v;
                else
-                       *(unsigned *)vp >>= (unsigned)v;
+                       *(uint16_t *)vp >>= (uint16_t)v;
                return;
 
        case ULSH:
@@ -960,7 +1115,7 @@ register int *vp, v;
                if (type==INT)
                        *vp <<= v;
                else
-                       *(unsigned *)vp <<= (unsigned)v;
+                       *(uint16_t *)vp <<= (uint16_t)v;
                return;
 
        case ANDN:
@@ -970,28 +1125,43 @@ register int *vp, v;
        error("C error: const");
 }
 
-union tree *
-lconst(op, lp, rp)
-register union tree *lp, *rp;
-{
-       long l, r;
+union tree *lconst(op, lp, rp) int op; register union tree *lp; register union tree *rp; {
+       uint32_t l, r;
 
        if (lp->t.op==LCON)
+#if 1
+#ifdef pdp11
+               l = *(int32_t *)lp->l.lvalue;
+#else
+               l = ((int32_t)lp->l.lvalue[0] << 16) |
+                       (int32_t)lp->l.lvalue[1];
+#endif
+#else
                l = lp->l.lvalue;
+#endif
        else if (lp->t.op==ITOL && lp->t.tr1->t.op==CON) {
                if (lp->t.tr1->t.type==INT)
                        l = lp->t.tr1->c.value;
                else
-                       l = (unsigned)lp->t.tr1->c.value;
+                       l = (uint16_t)lp->t.tr1->c.value;
        } else
                return(0);
        if (rp->t.op==LCON)
+#if 1
+#ifdef pdp11
+               r = *(int32_t *)rp->l.lvalue;
+#else
+               r = ((int32_t)rp->l.lvalue[0] << 16) |
+                       (int32_t)rp->l.lvalue[1];
+#endif
+#else
                r = rp->l.lvalue;
+#endif
        else if (rp->t.op==ITOL && rp->t.tr1->t.op==CON) {
                if (rp->t.tr1->t.type==INT)
                        r = rp->t.tr1->c.value;
                else
-                       r = (unsigned)rp->t.tr1->c.value;
+                       r = (uint16_t)rp->t.tr1->c.value;
        } else
                return(0);
        switch (op) {
@@ -1052,6 +1222,19 @@ register union tree *lp, *rp;
        default:
                return(0);
        }
+#if 1
+       if (lp->t.op!=LCON) {
+               lp = getblk(sizeof(struct lconst));
+               lp->t.op = LCON;
+               lp->t.type = LONG;
+       }
+#ifdef pdp11
+       *(int32_t *)lp->l.lvalue = l;
+#else
+       lp->l.lvalue[0] = (uint16_t)((l >> 16) & 0177777);
+       lp->l.lvalue[1] = (uint16_t)(l & 0177777);
+#endif
+#else
        if (lp->t.op==LCON) {
                lp->l.lvalue = l;
                return(lp);
@@ -1060,14 +1243,12 @@ register union tree *lp, *rp;
        lp->t.op = LCON;
        lp->t.type = LONG;
        lp->l.lvalue = l;
+#endif
        return(lp);
 }
 
-insert(op, tree, list)
-register union tree *tree;
-register struct acl *list;
-{
-       register d;
+void insert(op, tree, list) int op; register union tree *tree; register struct acl *list; {
+       register int d;
        int d1, i;
        union tree *t;
 
@@ -1110,10 +1291,7 @@ ins:
        list->llist[list->nextl++] = tree;
 }
 
-union tree *
-tnode(op, type, tr1, tr2)
-union tree *tr1, *tr2;
-{
+union tree *tnode(op, type, tr1, tr2) int op; int type; union tree *tr1; union tree *tr2; {
        register union tree *p;
 
        p = getblk(sizeof(struct tnode));
@@ -1125,9 +1303,7 @@ union tree *tr1, *tr2;
        return(p);
 }
 
-union tree *
-tconst(val, type)
-{
+union tree *tconst(val, type) int val; int type; {
        register union tree *p;
 
        p = getblk(sizeof(struct tconst));
@@ -1137,16 +1313,18 @@ tconst(val, type)
        return(p);
 }
 
-union tree *
-getblk(size)
-{
+union tree *getblk(size) int size; {
        register union tree *p;
 
        if (size&01)
                size++;
        p = (union tree *)curbase;
        if ((curbase += size) >= coremax) {
+#ifdef pdp11
                if (sbrk(1024) == (char *)-1) {
+#else
+               if (sbrk(1024) != coremax) {
+#endif
                        error("Out of space-- c1");
                        exit(1);
                }
@@ -1155,17 +1333,13 @@ getblk(size)
        return(p);
 }
 
-islong(t)
-{
+int islong(t) int t; {
        if (t==LONG || t==UNLONG)
                return(2);
        return(1);
 }
 
-union tree *
-isconstant(t)
-register union tree *t;
-{
+union tree *isconstant(t) register union tree *t; {
        if (t->t.op==CON || t->t.op==SFCON)
                return(t);
        if (t->t.op==ITOL && t->t.tr1->t.op==CON)
@@ -1173,10 +1347,7 @@ register union tree *t;
        return(NULL);
 }
 
-union tree *
-hardlongs(t)
-register union tree *t;
-{
+union tree *hardlongs(t) register union tree *t; {
        switch(t->t.op) {
 
        case TIMES:
@@ -1207,10 +1378,8 @@ register union tree *t;
 /*
  * Is tree of unsigned type?
  */
-uns(tp)
-union tree *tp;
-{
-       register t;
+int uns(tp) union tree *tp; {
+       register int t;
 
        t = tp->t.type;
        if (t==UNSIGN || t==UNCHAR || t==UNLONG || t&XTYPE)
index a92f0b9..77024ec 100644 (file)
@@ -279,61 +279,61 @@ char      *opntab[] = {
 /*
  * Strings for instruction tables.
  */
-char   mov[]   = "mov";
-char   clr[]   = "clr";
-char   cmp[]   = "cmp";
-char   tst[]   = "tst";
-char   add[]   = "add";
-char   sub[]   = "sub";
-char   inc[]   = "inc";
-char   dec[]   = "dec";
-char   mul[]   = "mul";
-char   div[]   = "div";
-char   asr[]   = "asr";
-char   ash[]   = "ash";
-char   asl[]   = "asl";
-char   bic[]   = "bic";
-char   bic1[]  = "bic $1,";
-char   bit[]   = "bit";
-char   bit1[]  = "bit $1,";
-char   bis[]   = "bis";
-char   bis1[]  = "bis $1,";
-char   xor[]   = "xor";
-char   neg[]   = "neg";
-char   com[]   = "com";
-char   stdol[] = "*$";
-char   ashc[]  = "ashc";
-char   slmul[] = "lmul";
-char   sldiv[] = "ldiv";
-char   slrem[] = "lrem";
-char   uldiv[] = "uldiv";
-char   ulrem[] = "ulrem";
-char   ualdiv[] = "ualdiv";
-char   ualrem[] = "ualrem";
-char   ultof[] = "ultof";
-char   ulsh[] = "ulsh";
-char   ualsh[] = "ualsh";
-char   almul[] = "almul";
-char   aldiv[] = "aldiv";
-char   alrem[] = "alrem";
-char   udiv[]  = "udiv";
-char   urem[]  = "urem";
-char   jeq[]   = "jeq";
-char   jne[]   = "jne";
-char   jle[]   = "jle";
-char   jgt[]   = "jgt";
-char   jlt[]   = "jlt";
-char   jge[]   = "jge";
-char   jlos[]  = "jlos";
-char   jhi[]   = "jhi";
-char   jlo[]   = "jlo";
-char   jhis[]  = "jhis";
-char   nop[]   = "/nop";
-char   jbr[]   = "jbr";
-char   jpl[] = "jpl";
-char   jmi[] = "jmi";
-char   jmijne[] = "jmi\tL%d\njne";
-char   jmijeq[] = "jmi\tL%d\njeq";
+char mov[] = "mov";
+char clr[] = "clr";
+char cmp[] = "cmp";
+char tst[] = "tst";
+char add[] = "add";
+char sub[] = "sub";
+char inc[] = "inc";
+char dec[] = "dec";
+char mul[] = "mul";
+char _div[] = "div";
+char asr[] = "asr";
+char ash[] = "ash";
+char asl[] = "asl";
+char bic[] = "bic";
+char bic1[] = "bic $1,";
+char bit[] = "bit";
+char bit1[] = "bit $1,";
+char bis[] = "bis";
+char bis1[] = "bis $1,";
+char xor[] = "xor";
+char neg[] = "neg";
+char com[] = "com";
+char stdol[] = "*$";
+char ashc[] = "ashc";
+char slmul[] = "lmul";
+char sldiv[] = "ldiv";
+char slrem[] = "lrem";
+char uldiv[] = "uldiv";
+char ulrem[] = "ulrem";
+char ualdiv[] = "ualdiv";
+char ualrem[] = "ualrem";
+char ultof[] = "ultof";
+char ulsh[] = "ulsh";
+char ualsh[] = "ualsh";
+char almul[] = "almul";
+char aldiv[] = "aldiv";
+char alrem[] = "alrem";
+char udiv[] = "udiv";
+char urem[] = "urem";
+char jeq[] = "jeq";
+char jne[] = "jne";
+char jle[] = "jle";
+char jgt[] = "jgt";
+char jlt[] = "jlt";
+char jge[] = "jge";
+char jlos[] = "jlos";
+char jhi[] = "jhi";
+char jlo[] = "jlo";
+char jhis[] = "jhis";
+char nop[] = "/nop";
+char jbr[] = "jbr";
+char jpl[] = "jpl";
+char jmi[] = "jmi";
+char jmijne[] = "jmi\tL%d\njne";
+char jmijeq[] = "jmi\tL%d\njeq";
 
 /*
  * Instruction tables, accessed by
@@ -341,73 +341,74 @@ char      jmijeq[] = "jmi\tL%d\njeq";
  */
 
 struct instab instab[] = {
-       LOAD,   mov,    tst,
-       ASSIGN, mov,    clr,
-       EQUAL,  cmp,    tst,
-       NEQUAL, cmp,    tst,
-       LESSEQ, cmp,    tst,
-       LESS,   cmp,    tst,
-       GREATEQ,cmp,    tst,
-       GREAT,  cmp,    tst,
-       LESSEQP,cmp,    tst,
-       LESSP,  cmp,    tst,
-       GREATQP,cmp,    tst,
-       GREATP, cmp,    tst,
-       PLUS,   add,    inc,
-       ASPLUS, add,    inc,
-       MINUS,  sub,    dec,
-       ASMINUS,sub,    dec,
-       INCBEF, add,    inc,
-       DECBEF, sub,    dec,
-       INCAFT, add,    inc,
-       DECAFT, sub,    dec,
-       TIMES,  mul,    mul,
-       ASTIMES,mul,    mul,
-       DIVIDE, div,    div,
-       ASDIV,  div,    div,
-       MOD,    div,    div,
-       ASMOD,  div,    div,
-       PTOI,   div,    div,
-       RSHIFT, ash,    asr,
-       ASRSH,  ash,    asr,
-       LSHIFT, ash,    asl,
-       ASLSH,  ash,    asl,
-       AND,    bic,    bic1,
-       ANDN,   bic,    bic1,
-       ASANDN, bic,    bic1,
-       TAND,   bit,    bit1,
-       OR,     bis,    bis1,
-       ASOR,   bis,    bis1,
-       EXOR,   xor,    xor,
-       ASXOR,  xor,    xor,
-       NEG,    neg,    neg,
-       COMPL,  com,    com,
-       CALL1,  stdol,  stdol,
-       CALL2,  "",     "",
-       LLSHIFT,ashc,   ashc,
-       ASLSHL, ashc,   ashc,
-       LTIMES, slmul,  slmul,
-       LDIV,   sldiv,  sldiv,
-       LMOD,   slrem,  slrem,
-       LASTIMES,almul, almul,
-       LASDIV, aldiv,  aldiv,
-       LASMOD, alrem,  alrem,
-       ULSH,   ashc,   ashc,
-       ASULSH, ashc,   ashc,
-       UDIV,   udiv,   udiv,
-       UMOD,   urem,   urem,
-       ASUDIV, udiv,   udiv,
-       ASUMOD, urem,   urem,
-       ULTIMES,slmul,  slmul,          /* symmetry */
-       ULDIV,  uldiv,  uldiv,
-       ULMOD,  ulrem,  ulrem,
-       ULASTIMES,almul,almul,          /* symmetry */
-       ULASDIV,ualdiv, ualdiv,
-       ULASMOD,ualrem, ualrem,
-       ULTOF,  ultof,  ultof,
-       ULLSHIFT, ulsh, ulsh,
-       UASLSHL, ualsh, ualsh,
-       0,      0,      0};
+       {LOAD,          mov,    tst},
+       {ASSIGN,        mov,    clr},
+       {EQUAL,         cmp,    tst},
+       {NEQUAL,        cmp,    tst},
+       {LESSEQ,        cmp,    tst},
+       {LESS,          cmp,    tst},
+       {GREATEQ,       cmp,    tst},
+       {GREAT,         cmp,    tst},
+       {LESSEQP,       cmp,    tst},
+       {LESSP,         cmp,    tst},
+       {GREATQP,       cmp,    tst},
+       {GREATP,        cmp,    tst},
+       {PLUS,          add,    inc},
+       {ASPLUS,        add,    inc},
+       {MINUS,         sub,    dec},
+       {ASMINUS,       sub,    dec},
+       {INCBEF,        add,    inc},
+       {DECBEF,        sub,    dec},
+       {INCAFT,        add,    inc},
+       {DECAFT,        sub,    dec},
+       {TIMES,         mul,    mul},
+       {ASTIMES,       mul,    mul},
+       {DIVIDE,        _div,   _div},
+       {ASDIV,         _div,   _div},
+       {MOD,           _div,   _div},
+       {ASMOD,         _div,   _div},
+       {PTOI,          _div,   _div},
+       {RSHIFT,        ash,    asr},
+       {ASRSH,         ash,    asr},
+       {LSHIFT,        ash,    asl},
+       {ASLSH,         ash,    asl},
+       {AND,           bic,    bic1},
+       {ANDN,          bic,    bic1},
+       {ASANDN,        bic,    bic1},
+       {TAND,          bit,    bit1},
+       {OR,            bis,    bis1},
+       {ASOR,          bis,    bis1},
+       {EXOR,          xor,    xor},
+       {ASXOR,         xor,    xor},
+       {NEG,           neg,    neg},
+       {COMPL,         com,    com},
+       {CALL1,         stdol,  stdol},
+       {CALL2,         "",     ""},
+       {LLSHIFT,       ashc,   ashc},
+       {ASLSHL,        ashc,   ashc},
+       {LTIMES,        slmul,  slmul},
+       {LDIV,          sldiv,  sldiv},
+       {LMOD,          slrem,  slrem},
+       {LASTIMES,      almul,  almul},
+       {LASDIV,        aldiv,  aldiv},
+       {LASMOD,        alrem,  alrem},
+       {ULSH,          ashc,   ashc},
+       {ASULSH,        ashc,   ashc},
+       {UDIV,          udiv,   udiv},
+       {UMOD,          urem,   urem},
+       {ASUDIV,        udiv,   udiv},
+       {ASUMOD,        urem,   urem},
+       {ULTIMES,       slmul,  slmul},         /* symmetry */
+       {ULDIV,         uldiv,  uldiv},
+       {ULMOD,         ulrem,  ulrem},
+       {ULASTIMES,     almul,  almul},         /* symmetry */
+       {ULASDIV,       ualdiv, ualdiv},
+       {ULASMOD,       ualrem, ualrem},
+       {ULTOF,         ultof,  ultof},
+       {ULLSHIFT,      ulsh,   ulsh},
+       {UASLSHL,       ualsh,  ualsh},
+       {0,             0,      0}
+};
 
 /*
  * Similar table for relationals.
@@ -419,24 +420,40 @@ struct instab instab[] = {
  * the c-bit so ptr tests are funny.
  */
 struct instab branchtab[] = {
-       EQUAL,  jeq,    jne,
-       NEQUAL, jne,    jeq,
-       LESSEQ, jle,    jgt,
-       LESS,   jlt,    jge,
-       GREATEQ,jge,    jlt,
-       GREAT,  jgt,    jle,
-       LESSEQP,jlos,   jhi,
-       LESSP,  jlo,    jhis,
-       GREATQP,jhis,   jlo,
-       GREATP, jhi,    jlos,
-       200+EQUAL,      jeq,    jne,
-       200+NEQUAL,     jne,    jeq,
-       200+LESSEQ,     jmijeq, jmijne,
-       200+LESS,       jmi,    jpl,
-       200+GREATEQ,    jpl,    jmi,
-       200+GREAT,      jmijne, jmijeq,
-       200+LESSEQP,    jeq,    jne,
-       200+LESSP,      nop,    jbr,
-       200+GREATQP,    jbr,    nop,
-       200+GREATP,     jne,    jeq,
-       0,      0,      0 };
+       {EQUAL,         jeq,    jne},
+       {NEQUAL,        jne,    jeq},
+       {LESSEQ,        jle,    jgt},
+       {LESS,          jlt,    jge},
+       {GREATEQ,       jge,    jlt},
+       {GREAT,         jgt,    jle},
+       {LESSEQP,       jlos,   jhi},
+       {LESSP,         jlo,    jhis},
+       {GREATQP,       jhis,   jlo},
+       {GREATP,        jhi,    jlos},
+       {200+EQUAL,     jeq,    jne},
+       {200+NEQUAL,    jne,    jeq},
+       {200+LESSEQ,    jmijeq, jmijne},
+       {200+LESS,      jmi,    jpl},
+       {200+GREATEQ,   jpl,    jmi},
+       {200+GREAT,     jmijne, jmijeq},
+       {200+LESSEQP,   jeq,    jne},
+       {200+LESSP,     nop,    jbr},
+       {200+GREATQP,   jbr,    nop},
+       {200+GREATP,    jne,    jeq},
+       {0,             0,      0}
+};
+
+int    line;
+int    nerror;                 /* number of hard errors */
+struct table   lsptab[1];
+int    nstack;
+int    nfloat;
+char   *funcbase;
+char   *curbase;
+char   *coremax;
+long   totspace;
+int    regpanic;               /* set when SU register alg. fails */
+int    panicposs;              /* set when there might be need for regpanic */
+jmp_buf        jmpbuf;
+
+int    xlab1, xlab2, xop, xzero;
index ffbdc7e..4b88284 100644 (file)
@@ -1,4 +1,7 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "krcompat.h"
 
 int    tabflg;
 int    labno   = 1;
@@ -11,9 +14,12 @@ char ooname[]="/tmp/cvoptbXXXXXX";
 char lbuf[BUFSIZ];
 char *lbufp = lbuf;
 
-main(argc, argv)
-char **argv;
-{
+int main PARAMS((int argc, char **argv));
+int flag PARAMS((void));
+void put PARAMS((int c));
+void comment PARAMS((int c));
+
+int main(argc, argv) int argc; char **argv; {
 /*
        A1 -> A
        A2    B
@@ -46,6 +52,9 @@ char **argv;
 */
 
        int c, snlflg, nlflg, t, smode, m, ssmode, peekc, side;
+#ifndef pdp11
+       int fd;
+#endif
 
        smode = nlflg = snlflg = ssmode = 0;
        if (argc>1)
@@ -58,6 +67,7 @@ char **argv;
                        fprintf(stderr, "%s?\n", argv[2]);
                        return(1);
                }
+#ifdef pdp11
        mktemp(oname);
        if ((obuf = fopen(oname, "w")) == NULL) {
                fprintf(stderr, "%s?\n", oname);
@@ -68,6 +78,18 @@ char **argv;
                fprintf(stderr, "%s?\n", ooname);
                exit(1);
        }
+#else
+       fd = mkstemp(oname);
+       if (fd < 0 || (obuf = fdopen(fd, "w")) == NULL) {
+               fprintf(stderr, "%s?\n", oname);
+               exit(1);
+       }
+       fd = mkstemp(ooname);
+       if (fd < 0 || (oobuf = fdopen(fd, "w")) == NULL) {
+               fprintf(stderr, "%s?\n", ooname);
+               exit(1);
+       }
+#endif
        printf("#include \"c1.h\"");
        curbuf = obuf;
 loop:
@@ -354,8 +376,8 @@ pf:
        goto loop;
 }
 
-flag() {
-       register c, f;
+int flag() {
+       register int c, f;
 
        f = 0;
 l1:
@@ -412,8 +434,7 @@ l1:
        return(f);
 }
 
-put(c)
-{
+void put(c) int c; {
        if (tabflg) {
                tabflg = 0;
                fprintf(curbuf, "\\%o", c+0200);
@@ -423,9 +444,7 @@ put(c)
        }
 }
 
-comment(c)
-register char c;
-{
+void comment(c) int c; {
        putc(c,curbuf);
        if ((c=getchar())=='*') for (;;) {
                do putc(c,curbuf); while ((c=getchar())!='*');
diff --git a/lib/ccom/krcompat.h b/lib/ccom/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
diff --git a/lib/ccom/n.sh b/lib/ccom/n.sh
new file mode 100755 (executable)
index 0000000..77367a3
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/lib\/ccom$//'`"
+DESTDIR="$ROOT/host"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/lib"
+make clean && make LDC0FLAGS= LDC1FLAGS= PURFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install
diff --git a/lib/ccom/pdp11_atof.c b/lib/ccom/pdp11_atof.c
new file mode 100644 (file)
index 0000000..8abd30c
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)atof.c     2.2 (Berkeley) 1/22/87";
+#endif
+
+/*
+ *     C library - ascii to floating
+ */
+
+#ifndef pdp11
+#include <math.h>
+#include <ctype.h>
+#include "c1.h"
+
+/*#define HUGE 1.701411733192644270e38*/
+#define LOGHUGE 39
+
+void pdp11_atof(p) char *p; {
+       register int c;
+#if 1
+       uint16_t fl[4], flexp[4], exp5[4];
+       uint16_t big[4], temp;
+#else
+       double fl, flexp, exp5;
+       double big = 72057594037927936.;  /*2^56*/
+#endif
+       int nd;
+       register int eexp, exp, neg, negexp, bexp;
+
+#if 1
+       /* movf $56200,r0 */
+       temp = 056200;
+       pdp11_ldf(0, &temp, 027);
+       /* movf r0,-50(r5) */
+       pdp11_stf(0, big, 065);
+#endif
+       neg = 1;
+       while((c = *p++) == ' ')
+               ;
+       if (c == '-')
+               neg = -1;
+       else if (c=='+')
+               ;
+       else
+               --p;
+
+       exp = 0;
+#if 1
+       /* clrf -20(r5) */
+       pdp11_clrf(fl, 065);
+#else
+       fl = 0;
+#endif
+       nd = 0;
+       while ((c = *p++), isdigit(c)) {
+#if 1
+               /* movf -20(r5),r0 */
+               pdp11_ldf(0, fl, 065);
+               /* cmpf -50(r5),r0 */
+               pdp11_cmpf(0, big, 065);
+               /* cfcc */
+               pdp11_cfcc();
+               /* jle L12 */
+               if ((Z | (N ^ V)) == 0) {
+#else
+               if (fl<big) {
+#endif
+#if 1
+                       /* movf $41040,r0 */
+                       temp = 041040;
+                       pdp11_ldf(0, &temp, 027);
+                       /* mulf -20(r5),r0 */
+                       pdp11_mulf(0, fl, 065);
+                       /* mov r3,r1 */
+                       /* add $-60,r1 */
+                       R[1] = c - '0';
+                       /* movif r1,r1 */
+                       pdp11_movif(1, NULL, 1);
+                       /* addf r1,r0 */
+                       pdp11_addf(0, NULL, 1);
+                       /* movf r0,-20(r5) */
+                       pdp11_stf(0, fl, 065);
+#else
+                       fl = 10*fl + (c-'0');
+#endif
+               } else
+                       exp++;
+               nd++;
+       }
+
+       if (c == '.') {
+               while ((c = *p++), isdigit(c)) {
+#if 1
+                       /* movf -20(r5),r0 */
+                       pdp11_ldf(0, fl, 065);
+                       /* cmpf -50(r5),r0 */
+                       pdp11_cmpf(0, big, 065);
+                       /* cfcc */
+                       pdp11_cfcc();
+                       /* jle L17 */
+                       if ((Z | (N ^ V)) == 0) {
+#else
+                       if (fl<big) {
+#endif
+#if 1
+                               /* movf $41040,r0 */
+                               temp = 041040;
+                               pdp11_ldf(0, &temp, 027);
+                               /* mulf -20(r5),r0 */
+                               pdp11_mulf(0, fl, 065);
+                               /* mov r3,r1 */
+                               /* add $-60,r1 */
+                               R[1] = c - '0';
+                               /* movif r1,r1 */
+                               pdp11_movif(1, NULL, 1);
+                               /* addf r1,r0 */
+                               pdp11_addf(0, NULL, 1);
+                               /* movf r0,-20(r5) */
+                               pdp11_stf(0, fl, 065);
+#else
+                               fl = 10*fl + (c-'0');
+#endif
+                               exp--;
+                       }
+               nd++;
+               }
+       }
+
+       negexp = 1;
+       eexp = 0;
+       if ((c == 'E') || (c == 'e')) {
+               if ((c= *p++) == '+')
+                       ;
+               else if (c=='-')
+                       negexp = -1;
+               else
+                       --p;
+
+               while ((c = *p++), isdigit(c)) {
+                       eexp = 10*eexp+(c-'0');
+               }
+               if (negexp<0)
+                       eexp = -eexp;
+               exp = exp + eexp;
+       }
+
+       negexp = 1;
+       if (exp<0) {
+               negexp = -1;
+               exp = -exp;
+       }
+
+
+       if((nd+exp*negexp) < -LOGHUGE){
+#if 1
+               /* clf -20(r5) */
+               pdp11_clrf(fl, 065);
+#else
+               fl = 0;
+#endif
+               exp = 0;
+       }
+#if 1
+       /* movf $40200,r0 */
+       temp = 040200;
+       pdp11_ldf(0, &temp, 027);
+       /* movf r0,-30(r5) */
+       pdp11_stf(0, flexp, 065);
+#else
+       flexp = 1;
+#endif
+#if 1
+       /* movf $40640,r0 */
+       temp = 040640;
+       pdp11_ldf(0, &temp, 027);
+       /* movf r0,-40(r5) */
+       pdp11_stf(0, exp5, 065);
+#else
+       exp5 = 5;
+#endif
+       bexp = exp;
+       for (;;) {
+               if (exp&01) {
+#if 1
+                       /* movf -30(r5),r0 */
+                       pdp11_ldf(0, flexp, 065);
+                       /* mulf -40(r5),r0 */
+                       pdp11_mulf(0, exp5, 065);
+                       /* movf r0,-30(r5) */
+                       pdp11_stf(0, flexp, 065);
+#else
+                       flexp *= exp5;
+#endif
+               }
+               exp >>= 1;
+               if (exp==0)
+                       break;
+#if 1
+               /* movf -40(r5),r0 */
+               pdp11_ldf(0, exp5, 065);
+               /* mulf r0,r0 */
+               pdp11_mulf(0, NULL, 0);
+               /* movf r0,-40(r5) */
+               pdp11_stf(0, exp5, 065);
+#else
+               exp5 *= exp5;
+#endif
+       }
+#if 1
+       /* movf -20(r5),r0 */
+       pdp11_ldf(0, fl, 065);
+#endif
+       if (negexp<0)
+#if 1
+               /* divf -30(r5),r0 */
+               pdp11_divf(0, flexp, 065);
+#else
+               fl /= flexp;
+#endif
+       else
+#if 1
+               /* mulf -30(r5),r0 */
+               pdp11_mulf(0, flexp, 065);
+#else
+               fl *= flexp;
+#endif
+#if 1
+       /* movf r0,-20(r5) */
+       pdp11_stf(0, fl, 065);
+#endif
+#if 1
+       pdp11_ldexp(fl, negexp * bexp);
+#else
+       fl = ldexp(fl, negexp*bexp);
+#endif
+       if (neg<0) {
+#if 1
+               /* negf r0 */
+               pdp11_negf(NULL, 0);
+#else
+               fl = -fl;
+#endif
+       }
+#if 0
+       return(fl);
+#endif
+}
+#endif
diff --git a/lib/ccom/pdp11_fp.c b/lib/ccom/pdp11_fp.c
new file mode 100644 (file)
index 0000000..e254a87
--- /dev/null
@@ -0,0 +1,1293 @@
+/* pdp11_fp.c: PDP-11 floating point simulator (32b version)
+
+   Copyright (c) 1993-2004, Robert M Supnik
+
+   Permission is hereby granted, free of charge, to any person obtaining a
+   copy of this software and associated documentation files (the "Software"),
+   to deal in the Software without restriction, including without limitation
+   the rights to use, copy, modify, merge, publish, distribute, sublicense,
+   and/or sell copies of the Software, and to permit persons to whom the
+   Software is furnished to do so, subject to the following conditions:
+
+   The above copyright notice and this permission notice shall be included in
+   all copies or substantial portions of the Software.
+
+   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+   ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+   Except as contained in this notice, the name of Robert M Supnik shall not
+   be used in advertising or otherwise to promote the sale, use or other dealings
+   in this Software without prior written authorization from Robert M Supnik.
+
+   04-Oct-04   RMS     Added FIS instructions
+   19-Jan-03   RMS     Changed mode definitions for Apple Dev Kit conflict
+   08-Oct-02   RMS     Fixed macro definitions
+   05-Jun-98   RMS     Fixed implementation specific shift bugs
+   20-Apr-98   RMS     Fixed bug in MODf integer truncation
+   17-Apr-98   RMS     Fixed bug in STCfi range check
+   16-Apr-98   RMS     Fixed bugs in STEXP, STCfi, round/pack
+   09-Apr-98   RMS     Fixed bug in LDEXP
+   04-Apr-98   RMS     Fixed bug in MODf condition codes
+       
+   This module simulates the PDP-11 floating point unit (FP11 series).
+   It is called from the instruction decoder for opcodes 170000:177777.
+
+   The floating point unit recognizes three instruction formats:
+
+   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+   no operand
+   | 1  1  1  1| 0  0  0  0  0  0|      opcode     |   170000:
+   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+   170077
+
+   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+   one operand
+   | 1  1  1  1| 0  0  0| opcode |    dest spec    |   170100:
+   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+   170777
+
+   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+   register + operand
+   | 1  1  1  1|   opcode  | fac |    dest spec    |   171000:
+   +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+   177777
+
+   The instruction space is further extended through use of the floating
+   point status register (FPS) mode bits.  Three mode bits affect how
+   instructions are interpreted:
+
+       FPS_D           if 0, floating registers are single precision
+                       if 1, floating registers are double precision
+
+       FPS_L           if 0, integer operands are word
+                       if 1, integer operands are longword
+
+       FPS_T           if 0, floating operations are rounded
+                       if 1, floating operations are truncated
+
+   FPS also contains the condition codes for the floating point unit,
+   and exception enable bits for individual error conditions.  Exceptions
+   cause a trap through 0244, unless the individual exception, or all
+   exceptions, are disabled.  Illegal address mode, undefined variable,
+   and divide by zero abort the current instruction; all other exceptions
+   permit the instruction to complete.  (Aborts are implemented as traps
+   that request an "interrupt" trap.  If an interrupt is pending, it is
+   serviced; if not, trap_req is updated and processing continues.)
+
+   Floating point specifiers are similar to integer specifiers, with
+   the length of the operand being up to 8 bytes.  In two specific cases,
+   the floating point unit reads or writes only two bytes, rather than
+   the length specified by the operand type:
+
+       register        for integers, only 16b are accessed; if the
+                       operand is 32b, these are the high order 16b
+                       of the operand
+
+       immediate       for integers or floating point, only 16b are
+                       accessed;  if the operand is 32b or 64b, these
+                       are the high order 16b of the operand
+*/
+
+#ifndef pdp11
+#include "c1.h"
+
+/* Ultra hacks to be fixed later */
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 1
+#endif
+#define ABORT(arg) return
+
+/* Floating point accumulators */
+
+struct fpac {
+       uint32_t                l;                              /* low 32b */
+       uint32_t                h;                              /* high 32b */
+};
+typedef struct fpac fpac_t;
+
+/* PSW */
+
+#define        PSW_V_C         0                               /* condition codes */
+#define PSW_V_V                1
+#define PSW_V_Z                2
+#define PSW_V_N        3
+#
+/* FPS */
+
+#define        FPS_V_C         0                               /* condition codes */
+#define FPS_V_V                1
+#define FPS_V_Z                2
+#define FPS_V_N        3
+#define FPS_V_T                5                               /* truncate */
+#define FPS_V_L                6                               /* long */
+#define FPS_V_D                7                               /* double */
+#define FPS_V_IC       8                               /* ic err int */
+#define FPS_V_IV       9                               /* overflo err int */
+#define FPS_V_IU       10                              /* underflo err int */
+#define FPS_V_IUV      11                              /* undef var err int */
+#define FPS_V_ID       14                              /* int disable */
+#define FPS_V_ER       15                              /* error */
+
+/* Floating point status register */
+
+#define FPS_ER         (1u << FPS_V_ER)                /* error */
+#define FPS_ID         (1u << FPS_V_ID)                /* interrupt disable */
+#define FPS_IUV                (1u << FPS_V_IUV)               /* int on undef var */
+#define FPS_IU         (1u << FPS_V_IU)                /* int on underflow */
+#define FPS_IV         (1u << FPS_V_IV)                /* int on overflow */
+#define FPS_IC         (1u << FPS_V_IC)                /* int on conv error */
+#define FPS_D          (1u << FPS_V_D)                 /* single/double */
+#define FPS_L          (1u << FPS_V_L)                 /* word/long */
+#define FPS_T          (1u << FPS_V_T)                 /* round/truncate */
+#define FPS_N          (1u << FPS_V_N)
+#define FPS_Z          (1u << FPS_V_Z)
+#define FPS_V          (1u << FPS_V_V)
+#define FPS_C          (1u << FPS_V_C)
+#define FPS_CC         (FPS_N + FPS_Z + FPS_V + FPS_C)
+#define FPS_RW         (FPS_ER + FPS_ID + FPS_IUV + FPS_IU + FPS_IV + \
+                       FPS_IC + FPS_D + FPS_L + FPS_T + FPS_CC)
+
+/* Floating point exception codes */
+
+#define FEC_OP         2                               /* illegal op/mode */
+#define FEC_DZRO       4                               /* divide by zero */
+#define FEC_ICVT       6                               /* conversion error */
+#define FEC_OVFLO      8                               /* overflow */
+#define FEC_UNFLO      10                              /* underflow */
+#define FEC_UNDFV      12                              /* undef variable */
+
+/* Floating point format, all assignments 32b relative */
+
+#define FP_V_SIGN      (63 - 32)                       /* high lw: sign */
+#define FP_V_EXP       (55 - 32)                       /* exponent */
+#define FP_V_HB                FP_V_EXP                        /* hidden bit */
+#define FP_V_F0                (48 - 32)                       /* fraction 0 */
+#define FP_V_F1                (32 - 32)                       /* fraction 1 */
+#define FP_V_FROUND    (31 - 32)                       /* f round point */
+#define FP_V_F2                16                              /* low lw: fraction 2 */
+#define FP_V_F3                0                               /* fraction 3 */
+#define FP_V_DROUND    (-1)                            /* d round point */
+#define FP_M_EXP       0377
+#define FP_SIGN                (1u << FP_V_SIGN)
+#define FP_EXP         (FP_M_EXP << FP_V_EXP)
+#define FP_HB          (1u << FP_V_HB)
+#define FP_FRACH       ((1u << FP_V_HB) - 1)
+#define FP_FRACL       0xFFFFFFFF
+#define FP_BIAS                0200                            /* exponent bias */
+#define FP_GUARD       3                               /* guard bits */
+
+/* Data lengths */
+
+#define NICK_WORD      2
+#define NICK_LONG      4
+#define NICK_QUAD      8
+
+/* Double precision operations on 64b quantities */
+
+#define F_LOAD(qd,ac,ds) ds.h = ac.h; ds.l = (qd)? ac.l: 0
+#define F_LOAD_P(qd,ac,ds) ds->h = ac.h; ds->l = (qd)? ac.l: 0
+#define F_LOAD_FRAC(qd,ac,ds) ds.h = (ac.h & FP_FRACH) | FP_HB; \
+       ds.l = (qd)? ac.l: 0
+#define F_STORE(qd,sr,ac) ac.h = sr.h; if ((qd)) ac.l = sr.l
+#define F_STORE_P(qd,sr,ac) ac.h = sr->h; if ((qd)) ac.l = sr->l
+#define F_GET_FRAC_P(sr,ds) ds.l = sr->l; \
+       ds.h = (sr->h & FP_FRACH) | FP_HB
+#define F_ADD(s2,s1,ds) ds.l = (s1.l + s2.l) & 0xFFFFFFFF; \
+       ds.h = (s1.h + s2.h + (ds.l < s2.l)) & 0xFFFFFFFF
+#define F_SUB(s2,s1,ds) ds.h = (s1.h - s2.h - (s1.l < s2.l)) & 0xFFFFFFFF; \
+       ds.l = (s1.l - s2.l) & 0xFFFFFFFF
+#define F_LT(x,y) ((x.h < y.h) || ((x.h == y.h) && (x.l < y.l)))
+#define F_LT_AP(x,y) (((x->h & ~FP_SIGN) < (y->h & ~FP_SIGN)) || \
+       (((x->h & ~FP_SIGN) == (y->h & ~FP_SIGN)) && (x->l < y->l)))
+#define F_LSH_V(sr,n,ds) \
+       ds.h = (((n) >= 32)? (sr.l << ((n) - 32)): \
+               (sr.h << (n)) | ((sr.l >> (32 - (n))) & and_mask[n])) \
+               & 0xFFFFFFFF; \
+       ds.l = ((n) >= 32)? 0: (sr.l << (n)) & 0xFFFFFFFF
+#define F_RSH_V(sr,n,ds) \
+       ds.l = (((n) >= 32)? (sr.h >> ((n) - 32)) & and_mask[64 - (n)]: \
+               ((sr.l >> (n)) & and_mask[32 - (n)]) | \
+               (sr.h << (32 - (n)))) & 0xFFFFFFFF; \
+       ds.h = ((n) >= 32)? 0: \
+               ((sr.h >> (n)) & and_mask[32 - (n)]) & 0xFFFFFFFF
+
+/* For the constant shift macro, arguments must in the range [2,31] */
+
+#define F_LSH_1(ds) ds.h = ((ds.h << 1) | ((ds.l >> 31) & 1)) & 0xFFFFFFFF; \
+       ds.l = (ds.l << 1) & 0xFFFFFFFF
+#define F_RSH_1(ds) ds.l = ((ds.l >> 1) & 0x7FFFFFFF) | ((ds.h & 1) << 31); \
+       ds.h = ((ds.h >> 1) & 0x7FFFFFFF)
+#define F_LSH_K(sr,n,ds) \
+       ds.h =  ((sr.h << (n)) | ((sr.l >> (32 - (n))) & and_mask[n])) \
+               & 0xFFFFFFFF; \
+       ds.l = (sr.l << (n)) & 0xFFFFFFFF
+#define F_RSH_K(sr,n,ds) \
+       ds.l =  (((sr.l >> (n)) & and_mask[32 - (n)]) | \
+               (sr.h << (32 - (n)))) & 0xFFFFFFFF; \
+       ds.h =  ((sr.h >> (n)) & and_mask[32 - (n)]) & 0xFFFFFFFF
+#define F_LSH_GUARD(ds) F_LSH_K(ds,FP_GUARD,ds)
+#define F_RSH_GUARD(ds) F_RSH_K(ds,FP_GUARD,ds)
+
+#define GET_BIT(ir,n)  (((ir) >> (n)) & 1)
+#define GET_SIGN(ir)   GET_BIT((ir), FP_V_SIGN)
+#define GET_EXP(ir)    (((ir) >> FP_V_EXP) & FP_M_EXP)
+#define GET_SIGN_L(ir) GET_BIT((ir), 31)
+#define GET_SIGN_W(ir) GET_BIT((ir), 15)
+
+#if 1
+int32_t FEC = 0;
+int32_t FPS = FPS_D; /* default to double precision */
+int N, Z, V, C;
+int R[8];
+fpac_t FR[6];
+#else
+extern jmp_buf save_env;
+extern int32_t cpu_type;
+extern int32_t FEC, FEA, FPS;
+extern int32_t CPUERR, trap_req;
+extern int32_t N, Z, V, C;
+extern int32_t R[8];
+extern int32_t STKLIM;
+extern int32_t cm, isenable, dsenable, MMR0, MMR1;
+extern fpac_t FR[6];
+#endif
+
+fpac_t zero_fac = { 0, 0 };
+fpac_t one_fac = { 1, 0 };
+fpac_t fround_fac = { (1u << (FP_V_FROUND + 32)), 0 };
+fpac_t fround_guard_fac = { 0, (1u << (FP_V_FROUND + FP_GUARD)) };
+fpac_t dround_guard_fac = { (1u << (FP_V_DROUND + FP_GUARD)), 0 };
+fpac_t fmask_fac = { 0xFFFFFFFF, (1u << (FP_V_HB + FP_GUARD + 1)) - 1 };
+static const uint32_t and_mask[33] = { 0,
+       0x1, 0x3, 0x7, 0xF,
+       0x1F, 0x3F, 0x7F, 0xFF,
+       0x1FF, 0x3FF, 0x7FF, 0xFFF,
+       0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,
+       0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF,
+       0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF,
+       0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF,
+       0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF };
+#if 0
+int32_t backup_PC;
+#endif
+int32_t fpnotrap PARAMS((int32_t code));
+int32_t GeteaFP PARAMS((int32_t spec, int32_t len));
+
+static uint32_t ReadI PARAMS((uint16_t *va, int32_t spec, int32_t len));
+static void ReadFP PARAMS((fpac_t *fac, uint16_t *va, int32_t spec, int32_t len));
+static void WriteI PARAMS((int32_t data, uint16_t *va, int32_t spec, int32_t len));
+static void WriteFP PARAMS((fpac_t *data, uint16_t *va, int32_t spec, int32_t len));
+static int32_t setfcc PARAMS((int32_t old_status, int32_t result_high, int32_t newV));
+static int32_t addfp11 PARAMS((fpac_t *src1, fpac_t *src2));
+static int32_t mulfp11 PARAMS((fpac_t *src1, fpac_t *src2));
+static int32_t divfp11 PARAMS((fpac_t *src1, fpac_t *src2));
+#if 0
+static int32_t modfp11 PARAMS((fpac_t *src1, fpac_t *src2, fpac_t *frac));
+#endif
+static void frac_mulfp11 PARAMS((fpac_t *src1, fpac_t *src2));
+static int32_t roundfp11 PARAMS((fpac_t *src));
+static int32_t round_and_pack PARAMS((fpac_t *fac, int32_t exp, fpac_t *frac, int r));
+
+#if 0
+extern int32_t GeteaW (int32_t spec);
+extern int32_t ReadW (int32_t addr);
+extern void WriteW (int32_t data, int32_t addr);
+extern void set_stack_trap (int32_t adr);
+#endif
+
+/* Set up for instruction decode and execution */
+
+#if 0
+void fp11 (int32_t IR)
+{
+int32_t dst, ea, ac, dstspec;
+int32_t i, qdouble, lenf, leni;
+int32_t newV, exp, sign;
+fpac_t fac, fsrc, modfrac;
+static const uint32_t i_limit[2][2] =
+       { { 0x80000000, 0x80010000 }, { 0x80000000, 0x80000001 } };
+
+backup_PC = PC;                                                /* save PC for FEA */
+ac = (IR >> 6) & 03;                                   /* fac is IR<7:6> */
+dstspec = IR & 077;
+qdouble = FPS & FPS_D;
+lenf = qdouble? NICK_QUAD: NICK_LONG;
+switch ((IR >> 8) & 017) {                             /* decode IR<11:8> */
+case 0:
+       switch (ac) {                                   /* decode IR<7:6> */
+       case 0:                                         /* specials */
+           if (IR == 0170000) {                        /* CFCC */
+#endif
+
+void pdp11_cfcc() {
+       N = (FPS >> PSW_V_N) & 1;
+       Z = (FPS >> PSW_V_Z) & 1;
+       V = (FPS >> PSW_V_V) & 1;
+       C = (FPS >> PSW_V_C) & 1;
+}
+
+#if 0
+           }
+           else if (IR == 0170001)                     /* SETF */
+               FPS = FPS & ~FPS_D;
+           else if (IR == 0170002)                     /* SETI */
+#endif
+
+void pdp11_seti() {
+       FPS = FPS & ~FPS_L;
+}
+
+#if 0
+           else if (IR == 0170011)                     /* SETD */
+               FPS = FPS | FPS_D;
+           else if (IR == 0170012)                     /* SETL */
+#endif
+
+void pdp11_setl() {
+       FPS = FPS | FPS_L;
+}
+
+#if 0
+           else fpnotrap (FEC_OP);
+           break;
+       case 1:                                         /* LDFPS */
+           dst = (dstspec <= 07)? R[dstspec]: ReadW (GeteaW (dstspec));
+           FPS = dst & FPS_RW;
+           break;
+       case 2:                                         /* STFPS */
+           FPS = FPS & FPS_RW;
+           if (dstspec <= 07) R[dstspec] = FPS;
+           else WriteW (FPS, GeteaW (dstspec));
+           break;
+       case 3:                                         /* STST */
+           if (dstspec <= 07) R[dstspec] = FEC;
+           else WriteI ((FEC << 16) | FEA, GeteaFP (dstspec, NICK_LONG),
+                dstspec, NICK_LONG);
+           break;  }                           /* end switch <7:6> */
+       break;                                          /* end case 0 */
+
+/* "Easy" instructions */
+
+case 1:
+       switch (ac) {                                   /* decode IR<7:6> */
+       case 0:                                         /* CLRf */
+#endif
+
+void pdp11_clrf(va, dstspec) uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       WriteFP (&zero_fac, va, dstspec, lenf);
+       FPS = (FPS & ~FPS_CC) | FPS_Z;
+}
+
+#if 0
+           break;
+       case 1:                                         /* TSTf */
+           ReadFP (&fsrc, GeteaFP (dstspec, lenf), dstspec, lenf);
+           FPS = setfcc (FPS, fsrc.h, 0);
+           break;
+       case 2:                                         /* ABSf */
+           ReadFP (&fsrc, ea = GeteaFP (dstspec, lenf), dstspec, lenf);
+           if (GET_EXP (fsrc.h) == 0) fsrc = zero_fac;
+           else fsrc.h = fsrc.h & ~FP_SIGN;
+           WriteFP (&fsrc, ea, dstspec, lenf);
+           FPS = setfcc (FPS, fsrc.h, 0);
+           break;
+       case 3:                                         /* NEGf */
+#endif
+
+void pdp11_negf(va, dstspec) uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       fpac_t fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, lenf);
+       if (GET_EXP (fsrc.h) == 0) fsrc = zero_fac;
+       else fsrc.h = fsrc.h ^ FP_SIGN;
+       WriteFP (&fsrc, va, dstspec, lenf);
+       FPS = setfcc (FPS, fsrc.h, 0);
+}
+
+#if 0
+           break;  }                                   /* end switch <7:6> */
+       break;                                          /* end case 1 */
+case 5:                                                        /* LDf */
+#endif
+
+void pdp11_ldf(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       fpac_t fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, lenf);
+       F_STORE (qdouble, fsrc, FR[ac]);
+       FPS = setfcc (FPS, fsrc.h, 0);
+}
+
+#if 0
+       break;
+case 010:                                              /* STf */
+#endif
+
+void pdp11_stf(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       fpac_t fac;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       F_LOAD (qdouble, FR[ac], fac);
+       WriteFP (&fac, va, dstspec, lenf);
+}
+
+#if 0
+       break;
+case 017:                                              /* LDCff' */
+#endif
+
+void pdp11_ldcfo(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       int32_t newV;
+       fpac_t fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, 12 - lenf);
+       if (GET_EXP (fsrc.h) == 0) fsrc = zero_fac;
+       if ((FPS & (FPS_D + FPS_T)) == 0) newV = roundfp11 (&fsrc);
+       else newV = 0;
+       F_STORE (qdouble, fsrc, FR[ac]);
+       FPS = setfcc (FPS, fsrc.h, newV);
+}
+
+#if 0
+       break;
+case 014:                                              /* STCff' */
+#endif
+
+void pdp11_stcfo(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       int32_t newV;
+       fpac_t fac;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       F_LOAD (qdouble, FR[ac], fac);
+       if (GET_EXP (fac.h) == 0) fac = zero_fac;
+       if ((FPS & (FPS_D + FPS_T)) == FPS_D) newV = roundfp11 (&fac);
+       else newV = 0;
+       WriteFP (&fac, va, dstspec, 12 - lenf);
+       FPS = setfcc (FPS, fac.h, newV);
+}
+
+#if 0
+       break;
+
+/* Compare instruction */
+
+case 7:                                                        /* CMPf */
+#endif
+
+void pdp11_cmpf(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       fpac_t fac, fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, lenf);
+       F_LOAD (qdouble, FR[ac], fac);
+       if (GET_EXP (fsrc.h) == 0) fsrc = zero_fac;
+       if (GET_EXP (fac.h) == 0) fac = zero_fac;
+       if ((fsrc.h == fac.h) && (fsrc.l == fac.l)) {   /* equal? */
+           FPS = (FPS & ~FPS_CC) | FPS_Z;
+           if ((fsrc.h | fsrc.l) == 0) {               /* zero? */
+               F_STORE (qdouble, zero_fac, FR[ac]);  }
+           return;  }
+       FPS = (FPS & ~FPS_CC) | ((fsrc.h >> (FP_V_SIGN - PSW_V_N)) & FPS_N);
+       if ((GET_SIGN (fsrc.h ^ fac.h) == 0) && (fac.h != 0) &&
+           F_LT (fsrc, fac)) FPS = FPS ^ FPS_N;
+}
+
+#if 0
+       break;
+
+/* Load and store exponent instructions */
+
+case 015:                                              /* LDEXP */
+#endif
+
+void pdp11_movie(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t dst;
+       int32_t qdouble;
+       int32_t newV;
+       fpac_t fac;
+
+       qdouble = FPS & FPS_D;
+       dst = (dstspec <= 07)? R[dstspec]: va[0];
+       F_LOAD (qdouble, FR[ac], fac);
+       fac.h = (fac.h & ~FP_EXP) | (((dst + FP_BIAS) & FP_M_EXP) << FP_V_EXP);
+       newV = 0;
+       if ((dst > 0177) && (dst <= 0177600)) {
+           if (dst < 0100000) {
+               if (fpnotrap (FEC_OVFLO)) fac = zero_fac;
+               newV = FPS_V;  }
+           else {
+               if (fpnotrap (FEC_UNFLO)) fac = zero_fac;  }  }
+       F_STORE (qdouble, fac, FR[ac]);
+       FPS = setfcc (FPS, fac.h, newV);
+}
+
+#if 0
+       break;  
+case 012:                                              /* STEXP */
+#endif
+
+void pdp11_movei(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t dst;
+       /*int32_t qdouble;*/
+       /*int32_t newV;*/
+       /*fpac_t fac;*/
+
+       /*qdouble = FPS & FPS_D;*/
+       dst = (GET_EXP (FR[ac].h) - FP_BIAS) & 0177777;
+       N = GET_SIGN_W (dst);
+       Z = (dst == 0);
+       V = 0;
+       C = 0;
+       FPS = (FPS & ~FPS_CC) | (N << PSW_V_N) | (Z << PSW_V_Z);
+       if (dstspec <= 07) R[dstspec] = dst;
+       else va[0] = dst;
+}
+
+#if 0
+       break;
+
+/* Integer convert instructions */
+
+case 016:                                              /* LDCif */
+#endif
+
+void pdp11_movif(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t i, qdouble, leni;
+       int32_t exp, sign;
+       fpac_t fac;
+
+       qdouble = FPS & FPS_D;
+       leni = FPS & FPS_L? NICK_LONG: NICK_WORD;
+       if (dstspec <= 07) fac.l = R[dstspec] << 16;
+       else fac.l = ReadI (va, dstspec, leni);
+       fac.h = 0;
+       if (fac.l) {
+           if (sign = GET_SIGN_L (fac.l)) fac.l = (fac.l ^ 0xFFFFFFFF) + 1;
+           for (i = 0; GET_SIGN_L (fac.l) == 0; i++) fac.l = fac.l << 1;
+           exp = ((FPS & FPS_L)? FP_BIAS + 32: FP_BIAS + 16) - i;
+           fac.h = (sign << FP_V_SIGN) | (exp << FP_V_EXP) |
+               ((fac.l >> (31 - FP_V_HB)) & FP_FRACH);
+           fac.l = (fac.l << (FP_V_HB + 1)) & FP_FRACL;
+           if ((FPS & (FPS_D + FPS_T)) == 0) roundfp11 (&fac);  }
+       F_STORE (qdouble, fac, FR[ac]);
+       FPS = setfcc (FPS, fac.h, 0);
+}
+
+#if 0
+       break;
+case 013:                                              /* STCfi */
+#endif
+
+void pdp11_movfi(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t dst;
+       int32_t i, qdouble, leni;
+       int32_t exp, sign;
+       fpac_t fac, fsrc;
+       static const uint32_t i_limit[2][2] =
+               { { 0x80000000, 0x80010000 }, { 0x80000000, 0x80000001 } };
+
+       qdouble = FPS & FPS_D;
+       sign = GET_SIGN (FR[ac].h);                     /* get sign, */
+       exp = GET_EXP (FR[ac].h);                       /* exponent, */
+       F_LOAD_FRAC (qdouble, FR[ac], fac);             /* fraction */
+       if (FPS & FPS_L) {
+           leni = NICK_LONG;
+           i = FP_BIAS + 32;  }
+       else {
+           leni = NICK_WORD;
+           i = FP_BIAS + 16;  }
+       C = 0;
+       if (exp <= FP_BIAS) dst = 0;
+       else if (exp > i) {
+           dst = 0;
+           C = 1;  }
+       else {
+           F_RSH_V (fac, FP_V_HB + 1 + i - exp, fsrc);
+           if (leni == NICK_WORD) fsrc.l = fsrc.l & ~0177777;
+           if (fsrc.l >= i_limit[leni == NICK_LONG][sign]) {
+               dst = 0;
+               C = 1;  }  
+           else {
+               dst = fsrc.l;
+               if (sign) dst = -dst;  }  }
+       N = GET_SIGN_L (dst);
+       Z = (dst == 0);
+       V = 0;
+       if (C) fpnotrap (FEC_ICVT);
+       FPS = (FPS & ~FPS_CC) | (N << PSW_V_N) |
+           (Z << PSW_V_Z) | (C << PSW_V_C);
+       if (dstspec <= 07) R[dstspec] = (dst >> 16) & 0177777;
+       else WriteI (dst, va, dstspec, leni);
+}
+
+#if 0
+       break;
+
+/* Calculation instructions */
+
+case 2:                                                        /* MULf */
+#endif
+
+void pdp11_mulf(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       int32_t newV;
+       fpac_t fac, fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, lenf);
+       F_LOAD (qdouble, FR[ac], fac);
+       newV = mulfp11 (&fac, &fsrc);
+       F_STORE (qdouble, fac, FR[ac]);
+       FPS = setfcc (FPS, fac.h, newV);
+}
+
+#if 0
+       break;
+case 3:                                                        /* MODf */
+       ReadFP (&fsrc, GeteaFP (dstspec, lenf), dstspec, lenf);
+       F_LOAD (qdouble, FR[ac], fac);
+       newV = modfp11 (&fac, &fsrc, &modfrac);
+       F_STORE (qdouble, fac, FR[ac | 1]);
+       F_STORE (qdouble, modfrac, FR[ac]);
+       FPS = setfcc (FPS, modfrac.h, newV);
+       break;
+case 4:                                                        /* ADDf */
+#endif
+
+void pdp11_addf(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       int32_t newV;
+       fpac_t fac, fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, lenf);
+       F_LOAD (qdouble, FR[ac], fac);
+       newV = addfp11 (&fac, &fsrc);
+       F_STORE (qdouble, fac, FR[ac]);
+       FPS = setfcc (FPS, fac.h, newV);
+}
+
+#if 0
+       break;
+case 6:                                                        /* SUBf */
+       ReadFP (&fsrc, GeteaFP (dstspec, lenf), dstspec, lenf);
+       F_LOAD (qdouble, FR[ac], fac);
+       if (GET_EXP (fsrc.h) != 0) fsrc.h = fsrc.h ^ FP_SIGN;
+       newV = addfp11 (&fac, &fsrc);
+       F_STORE (qdouble, fac, FR[ac]);
+       FPS = setfcc (FPS, fac.h, newV);
+       break;
+case 011:                                              /* DIVf */
+#endif
+
+void pdp11_divf(ac, va, dstspec) int ac; uint16_t *va; int dstspec; {
+       int32_t qdouble, lenf;
+       int32_t newV;
+       fpac_t fac, fsrc;
+
+       qdouble = FPS & FPS_D;
+       lenf = qdouble? NICK_QUAD: NICK_LONG;
+       ReadFP (&fsrc, va, dstspec, lenf);
+       F_LOAD (qdouble, FR[ac], fac);
+       if (GET_EXP (fsrc.h) == 0) {                    /* divide by zero? */
+           fpnotrap (FEC_DZRO); ABORT (TRAP_INT);  }
+       newV = divfp11 (&fac, &fsrc);
+       F_STORE (qdouble, fac, FR[ac]);
+       FPS = setfcc (FPS, fac.h, newV);
+}
+
+#if 0
+       break;  }                                       /* end switch fop */
+return;
+}
+
+/* Effective address calculation for fp operands
+
+   Inputs:
+       spec    =       specifier
+       len     =       length
+   Outputs:
+       VA      =       virtual address
+
+   Warnings:
+       - Do not call this routine for integer mode 0 operands
+       - Do not call this routine more than once per instruction
+*/
+
+int32_t GeteaFP(spec, len) int32_t spec; int32_t len; {
+int32_t adr, reg, ds;
+
+reg = spec & 07;                                       /* reg number */
+ds = (reg == 7)? isenable: dsenable;                   /* dspace if not PC */
+switch (spec >> 3) {                                   /* case on spec */
+case 0:                                                        /* floating AC */
+       if (reg >= 06) { fpnotrap (FEC_OP); ABORT (TRAP_INT);  }
+       return 0;
+case 1:                                                        /* (R) */
+       return (R[reg] | ds);
+case 2:                                                        /* (R)+ */
+       if (reg == 7) len = 2;
+       R[reg] = ((adr = R[reg]) + len) & 0177777;
+       if (update_MM) MMR1 = (len << 3) | reg;
+       return (adr | ds);
+case 3:                                                        /* @(R)+ */
+       R[reg] = ((adr = R[reg]) + 2) & 0177777;
+       if (update_MM) MMR1 = 020 | reg;
+       adr = ReadW (adr | ds);
+       return (adr | dsenable);
+case 4:                                                        /* -(R) */
+       adr = R[reg] = (R[reg] - len) & 0177777;
+       if (update_MM) MMR1 = (((-len) & 037) << 3) | reg;
+       if ((reg == 6) && (cm == MD_KER) && (adr < (STKLIM + STKL_Y)))
+           set_stack_trap (adr);
+       return (adr | ds);
+case 5:                                                        /* @-(R) */
+       adr = R[reg] = (R[reg] - 2) & 0177777;
+       if (update_MM) MMR1 = 0360 | reg;
+       if ((reg == 6) && (cm == MD_KER) && (adr < (STKLIM + STKL_Y)))
+           set_stack_trap (adr);
+       adr = ReadW (adr | ds);
+       return (adr | dsenable);
+case 6:                                                        /* d(r) */
+       adr = ReadW (PC | isenable);
+       PC = (PC + 2) & 0177777;
+       return (((R[reg] + adr) & 0177777) | dsenable);
+case 7:                                                        /* @d(R) */
+       adr = ReadW (PC | isenable);
+       PC = (PC + 2) & 0177777;
+       adr = ReadW (((R[reg] + adr) & 0177777) | dsenable);
+       return (adr | dsenable);  }                     /* end switch */
+return 0;
+}
+#endif
+
+/* Read integer operand
+
+   Inputs:
+       VA      =       virtual address, VA<18:16> = mode, I/D space
+       spec    =       specifier
+       len     =       length (2/4 bytes)
+   Outputs:
+       data    =       data read from memory or I/O space
+*/
+
+static uint32_t ReadI(va, spec, len) uint16_t *va; int32_t spec; int32_t len; {
+if ((len == NICK_WORD) || (spec == 027)) return ((int32_t)va[0] << 16);
+return (((int32_t)va[0] << 16) | (int32_t)va[1]);
+}
+
+/* Read floating operand
+
+   Inputs:
+       fptr    =       pointer to output
+       VA      =       virtual address, VA<18:16> = mode, I/D space
+       spec    =       specifier
+       len     =       length (4/8 bytes)
+*/
+
+static void ReadFP(fptr, va, spec, len) fpac_t *fptr; uint16_t *va; int32_t spec; int32_t len; {
+if (spec <= 07) {
+       F_LOAD_P (len == NICK_QUAD, FR[spec], fptr);
+       return;  }
+if (spec == 027) {
+       fptr->h = (va[0] << FP_V_F0);
+       fptr->l = 0;  }
+else { fptr->h = ((int32_t)va[0] << FP_V_F0) | ((int32_t)va[1] << FP_V_F1);
+       if (len == NICK_QUAD) fptr->l =
+               ((int32_t)va[2] << FP_V_F2) | ((int32_t)va[3] << FP_V_F3);
+       else fptr->l = 0;  }
+if ((GET_SIGN (fptr->h) != 0) && (GET_EXP (fptr->h) == 0) &&
+       (fpnotrap (FEC_UNDFV) == 0)) ABORT (TRAP_INT);
+return;
+}
+
+/* Write integer result
+
+   Inputs:
+       data    =       data to be written
+       VA      =       virtual address, VA<18:16> = mode, I/D space
+       spec    =       specifier
+       len     =       length
+   Outputs: none
+*/
+
+static void WriteI(data, va, spec, len) int32_t data; uint16_t *va; int32_t spec; int32_t len; {
+va[0] = (uint16_t)((data >> 16) & 0177777);
+if ((len == NICK_WORD) || (spec == 027)) return;
+va[1] = (uint16_t)(data & 0177777);
+return;
+}
+
+/* Write floating result
+
+   Inputs:
+       fptr    =       pointer to data to be written
+       VA      =       virtual address, VA<18:16> = mode, I/D space
+       spec    =       specifier
+       len     =       length
+   Outputs: none
+*/
+
+static void WriteFP(fptr, va, spec, len) fpac_t *fptr; uint16_t *va; int32_t spec; int32_t len; {
+if (spec <= 07) {
+       F_STORE_P (len == NICK_QUAD, fptr, FR[spec]);
+       return;  }
+va[0] = (uint16_t)((fptr->h >> FP_V_F0) & 0177777);
+if (spec == 027) return;
+va[1] = (uint16_t)((fptr->h >> FP_V_F1) & 0177777);
+if (len == NICK_LONG) return;
+va[2] = (uint16_t)((fptr->l >> FP_V_F2) & 0177777);
+va[3] = (uint16_t)((fptr->l >> FP_V_F3) & 0177777);
+return;
+}
+
+#if 0
+/* FIS instructions */
+
+t_stat fis11(IR) int32_t IR; {
+int32_t reg, exta;
+fpac_t fac, fsrc;
+
+reg = IR & 07;                                         /* isolate reg */
+if (reg == 7) exta = isenable;                         /* choose I,D */
+else exta = dsenable;
+if (IR & 000740) {                                     /* defined? */
+       if (CPUT (CPUT_03)) ReadW (exta | R[reg]);      /* 11/03 reads word */
+       ABORT (TRAP_ILL);  }
+FEC = 0;                                               /* no errors */
+FPS = FPS_IU|FPS_IV;                                   /* trap ovf,unf */
+
+fsrc.h = (ReadW (exta | R[reg]) << FP_V_F0) |
+       (ReadW (exta | ((R[reg] + 2) & 0177777)) << FP_V_F1);
+fsrc.l = 0;
+fac.h = (ReadW (exta | ((R[reg] + 4) & 0177777)) << FP_V_F0) |
+       (ReadW (exta | ((R[reg] + 6) & 0177777)) << FP_V_F1);
+fac.l = 0;
+if (GET_SIGN (fsrc.h) && (GET_EXP (fsrc.h) == 0))      /* clean 0's */
+       fsrc.h = fsrc.l = 0;
+if (GET_SIGN (fac.h) && (GET_EXP (fac.l) == 0))
+       fac.h = fac.l = 0;
+
+N = Z = V = C = 0;                                     /* clear cc's */
+switch ((IR >> 3) & 3) {                               /* case IR<5:3> */
+
+case 0:                                                        /* FAD */
+       addfp11 (&fac, &fsrc);
+       break;
+case 1:                                                        /* FSUB */
+       if (fsrc.h != 0) fsrc.h = fsrc.h ^ FP_SIGN;     /* invert sign */
+       addfp11 (&fac, &fsrc);
+       break;
+case 2:                                                        /* FMUL */
+       mulfp11 (&fac, &fsrc);
+       break;
+case 3:                                                        /* FDIV */
+       if (fsrc.h == 0) {                              /* div by 0? */
+           V = N = C = 1;                              /* set cc's */
+           setTRAP (TRAP_FPE);                         /* set trap */
+           return SCPE_OK;  }
+       else divfp11 (&fac, &fsrc);
+       break;  }
+
+if (FEC == 0) {                                                /* no err? */
+       WriteW ((fac.h >> FP_V_F0) & 0177777, exta | ((R[reg] + 4) & 0177777));
+       WriteW ((fac.h >> FP_V_F1) & 0177777, exta | ((R[reg] + 6) & 0177777));
+       R[reg] = (R[reg] + 4) & 0177777;                /* pop stack */
+       N = (GET_SIGN (fac.h) != 0);                    /* set N,Z */
+       Z = (fac.h == 0);  }
+else if (FEC == FEC_OVFLO) V = 1;                      /* ovf? trap set */
+else if (FEC == FEC_UNFLO) V = N = 1;                  /* unf? trap set */
+else return SCPE_IERR;                                 /* what??? */
+return SCPE_OK;
+}
+#endif
+
+/* Floating point add
+
+   Inputs:
+       facp    =       pointer to src1 (output)
+       fsrcp   =       pointer to src2
+   Outputs:
+       ovflo   =       overflow variable
+*/
+
+static int32_t addfp11(facp, fsrcp) fpac_t *facp; fpac_t *fsrcp; {
+int32_t facexp, fsrcexp, ediff;
+fpac_t facfrac, fsrcfrac;
+
+if (F_LT_AP (facp, fsrcp)) {                           /* if !fac! < !fsrc! */
+       facfrac = *facp;
+       *facp = *fsrcp;                                 /* swap operands */
+       *fsrcp = facfrac;  }
+facexp = GET_EXP (facp->h);                            /* get exponents */
+fsrcexp = GET_EXP (fsrcp->h);
+if (facexp == 0) {                                     /* fac = 0? */
+       *facp = fsrcexp? *fsrcp: zero_fac;              /* result fsrc or 0 */
+       return 0;  }
+if (fsrcexp == 0) return 0;                            /* fsrc = 0? no op */
+ediff = facexp - fsrcexp;                              /* exponent diff */
+if (ediff >= 60) return 0;                             /* too big? no op */
+F_GET_FRAC_P (facp, facfrac);                          /* get fractions */
+F_GET_FRAC_P (fsrcp, fsrcfrac);
+F_LSH_GUARD (facfrac);                                 /* guard fractions */
+F_LSH_GUARD (fsrcfrac);
+if (GET_SIGN (facp->h) != GET_SIGN (fsrcp->h)) {       /* signs different? */
+       if (ediff) { F_RSH_V (fsrcfrac, ediff, fsrcfrac);  } /* sub, shf fsrc */
+       F_SUB (fsrcfrac, facfrac, facfrac);             /* sub fsrc from fac */
+       if ((facfrac.h | facfrac.l) == 0)  {            /* result zero? */
+           *facp = zero_fac;                           /* no overflow */
+           return 0;  }
+       if (ediff <= 1) {                               /* big normalize? */
+           if ((facfrac.h & (0x00FFFFFF << FP_GUARD)) == 0) {
+               F_LSH_K (facfrac, 24, facfrac);
+               facexp = facexp - 24;  }
+           if ((facfrac.h & (0x00FFF000 << FP_GUARD)) == 0) {
+               F_LSH_K (facfrac, 12, facfrac);
+               facexp = facexp - 12;  }
+           if ((facfrac.h & (0x00FC0000 << FP_GUARD)) == 0) {
+               F_LSH_K (facfrac, 6, facfrac);
+               facexp = facexp - 6;  }  }
+       while (GET_BIT (facfrac.h, FP_V_HB + FP_GUARD) == 0) {
+           F_LSH_1 (facfrac);
+           facexp = facexp - 1;  }  }
+else { if (ediff) { F_RSH_V (fsrcfrac, ediff, fsrcfrac);  } /* add, shf fsrc */
+       F_ADD (fsrcfrac, facfrac, facfrac);             /* add fsrc to fac */
+       if (GET_BIT (facfrac.h, FP_V_HB + FP_GUARD + 1)) {
+           F_RSH_1 (facfrac);                          /* carry out, shift */
+           facexp = facexp + 1;  }  }
+return round_and_pack (facp, facexp, &facfrac, 1);
+}
+
+/* Floating point multiply
+
+   Inputs:
+       facp    =       pointer to src1 (output)
+       fsrcp   =       pointer to src2
+   Outputs:
+       ovflo   =       overflow indicator
+*/
+
+static int32_t mulfp11(facp, fsrcp) fpac_t *facp; fpac_t *fsrcp; {
+int32_t facexp, fsrcexp;
+fpac_t facfrac, fsrcfrac;
+
+facexp = GET_EXP (facp->h);                            /* get exponents */
+fsrcexp = GET_EXP (fsrcp->h);
+if ((facexp == 0) || (fsrcexp == 0)) {                 /* test for zero */
+       *facp = zero_fac;
+       return 0;  }
+F_GET_FRAC_P (facp, facfrac);                          /* get fractions */
+F_GET_FRAC_P (fsrcp, fsrcfrac);
+facexp = facexp + fsrcexp - FP_BIAS;                   /* calculate exp */
+facp->h = facp->h  ^ fsrcp->h;                         /* calculate sign */
+frac_mulfp11 (&facfrac, &fsrcfrac);                    /* multiply fracs */
+
+/* Multiplying two numbers in the range [.5,1) produces a result in the
+   range [.25,1).  Therefore, at most one bit of normalization is required
+   to bring the result back to the range [.5,1).
+*/
+
+if (GET_BIT (facfrac.h, FP_V_HB + FP_GUARD) == 0) {
+       F_LSH_1 (facfrac);
+       facexp = facexp - 1;  }
+return round_and_pack (facp, facexp, &facfrac, 1);
+}
+
+#if 0
+/* Floating point mod
+
+   Inputs:
+       facp    =       pointer to src1 (integer result)
+       fsrcp   =       pointer to src2
+       fracp   =       pointer to fractional result
+   Outputs:
+       ovflo   =       overflow indicator
+
+   See notes on multiply for initial operation
+*/
+
+static int32_t modfp11(facp, fsrcp, fracp) fpac_t *facp; fpac_t *fsrcp; fpac_t *fracp; {
+int32_t facexp, fsrcexp;
+fpac_t facfrac, fsrcfrac, fmask;
+
+facexp = GET_EXP (facp->h);                            /* get exponents */
+fsrcexp = GET_EXP (fsrcp->h);
+if ((facexp == 0) || (fsrcexp == 0)) {                 /* test for zero */
+       *fracp = zero_fac;
+       *facp = zero_fac;
+       return 0;  }
+F_GET_FRAC_P (facp, facfrac);                          /* get fractions */
+F_GET_FRAC_P (fsrcp, fsrcfrac);
+facexp = facexp + fsrcexp - FP_BIAS;                   /* calculate exp */
+fracp->h = facp->h = facp->h ^ fsrcp->h;               /* calculate sign */
+frac_mulfp11 (&facfrac, &fsrcfrac);                    /* multiply fracs */
+
+/* Multiplying two numbers in the range [.5,1) produces a result in the
+   range [.25,1).  Therefore, at most one bit of normalization is required
+   to bring the result back to the range [.5,1).
+*/
+
+if (GET_BIT (facfrac.h, FP_V_HB + FP_GUARD) == 0) {
+       F_LSH_1 (facfrac);
+       facexp = facexp - 1;  }
+
+/* There are three major cases of MODf:
+
+   1. Exp <= FP_BIAS (all fraction).  Return 0 as integer, product as
+      fraction.  Underflow can occur.
+   2. Exp > FP_BIAS + #fraction bits (all integer).  Return product as
+      integer, 0 as fraction.  Overflow can occur.
+   3. FP_BIAS < exp <= FP_BIAS + #fraction bits.  Separate integer and
+      fraction and return both.  Neither overflow nor underflow can occur.
+*/
+
+       if (facexp <= FP_BIAS) {                        /* case 1 */
+           *facp = zero_fac;
+           return round_and_pack (fracp, facexp, &facfrac, 1);  }
+       if (facexp > ((FPS & FPS_D)? FP_BIAS + 56: FP_BIAS + 24)) {
+           *fracp = zero_fac;                          /* case 2 */
+           return round_and_pack (facp, facexp, &facfrac, 0);  }
+       F_RSH_V (fmask_fac, facexp - FP_BIAS, fmask);   /* shift mask */
+       fsrcfrac.l = facfrac.l & fmask.l;               /* extract fraction */
+       fsrcfrac.h = facfrac.h & fmask.h;
+       if ((fsrcfrac.h | fsrcfrac.l) == 0) *fracp = zero_fac;
+       else {
+           F_LSH_V (fsrcfrac, facexp - FP_BIAS, fsrcfrac);
+           fsrcexp = FP_BIAS;
+           if ((fsrcfrac.h & (0x00FFFFFF << FP_GUARD)) == 0) {
+               F_LSH_K (fsrcfrac, 24, fsrcfrac);
+               fsrcexp = fsrcexp - 24;  }
+           if ((fsrcfrac.h & (0x00FFF000 << FP_GUARD)) == 0) {
+               F_LSH_K (fsrcfrac, 12, fsrcfrac);
+               fsrcexp = fsrcexp - 12;  }
+           if ((fsrcfrac.h & (0x00FC0000 << FP_GUARD)) == 0) {
+               F_LSH_K (fsrcfrac, 6, fsrcfrac);
+               fsrcexp = fsrcexp - 6;  }
+           while (GET_BIT (fsrcfrac.h, FP_V_HB + FP_GUARD) == 0) {
+               F_LSH_1 (fsrcfrac);
+               fsrcexp = fsrcexp - 1;  }
+           round_and_pack (fracp, fsrcexp, &fsrcfrac, 1);  }
+       facfrac.l = facfrac.l & ~fmask.l;
+       facfrac.h = facfrac.h & ~fmask.h;
+       return round_and_pack (facp, facexp, &facfrac, 0);
+}
+#endif
+
+/* Fraction multiply
+
+   Inputs:
+       f1p     =       pointer to multiplier (output)
+       f2p     =       pointer to multiplicand fraction
+
+   Note: the inputs are unguarded; the output is guarded.
+
+   This routine performs a classic shift-and-add multiply.  The low
+   order bit of the multiplier is tested; if 1, the multiplicand is
+   added into the high part of the double precision result.  The
+   result and the multiplier are both shifted right 1.
+
+   For the 24b x 24b case, this routine develops 48b of result.
+   For the 56b x 56b case, this routine only develops the top 64b
+   of the the result.  Because the inputs are normalized fractions,
+   the interesting part of the result is the high 56+guard bits.
+   Everything shifted off to the right, beyond 64b, plays no part
+   in rounding or the result.
+
+   There are many possible optimizations in this routine: scanning
+   for groups of zeroes, particularly in the 56b x 56b case; using
+   "extended multiply" capability if available in the hardware.
+*/
+
+static void frac_mulfp11(f1p, f2p) fpac_t *f1p; fpac_t *f2p; {
+fpac_t result, mpy, mpc;
+int32_t i;
+
+result = zero_fac;                                     /* clear result */
+mpy = *f1p;                                            /* get operands */
+mpc = *f2p;
+F_LSH_GUARD (mpc);                                     /* guard multipicand */
+if ((mpy.l | mpc.l) == 0) {                            /* 24b x 24b? */
+       for (i = 0; i < 24; i++) {
+           if (mpy.h & 1) result.h = result.h + mpc.h;
+           F_RSH_1 (result);
+           mpy.h = mpy.h >> 1;  }  }
+else { if (mpy.l != 0) {                               /* 24b x 56b? */
+           for (i = 0; i < 32; i++) {
+               if (mpy.l & 1) { F_ADD (mpc, result, result);  }
+               F_RSH_1 (result);
+               mpy.l = mpy.l >> 1;  }  }
+       for (i = 0; i < 24; i++) {
+           if (mpy.h & 1) { F_ADD (mpc, result, result);  }
+           F_RSH_1 (result);
+           mpy.h = mpy.h >> 1;  }  }
+*f1p = result;
+return;
+}
+
+/* Floating point divide
+
+   Inputs:
+       facp    =       pointer to dividend (output)
+       fsrcp   =       pointer to divisor
+   Outputs:
+       ovflo   =       overflow indicator
+
+   Source operand must be checked for zero by caller!
+*/
+
+static int32_t divfp11(facp, fsrcp) fpac_t *facp; fpac_t *fsrcp; {
+int32_t facexp, fsrcexp, i, count, qd;
+fpac_t facfrac, fsrcfrac, quo;
+
+fsrcexp = GET_EXP (fsrcp->h);                          /* get divisor exp */
+facexp = GET_EXP (facp->h);                            /* get dividend exp */
+if (facexp == 0) {                                     /* test for zero */
+       *facp = zero_fac;                               /* result zero */
+       return 0;  }
+F_GET_FRAC_P (facp, facfrac);                          /* get fractions */
+F_GET_FRAC_P (fsrcp, fsrcfrac);
+F_LSH_GUARD (facfrac);                                 /* guard fractions */
+F_LSH_GUARD (fsrcfrac);
+facexp = facexp - fsrcexp + FP_BIAS + 1;               /* calculate exp */
+facp->h = facp->h ^ fsrcp->h;                          /* calculate sign */
+qd = FPS & FPS_D;
+count = FP_V_HB + FP_GUARD + (qd? 33: 1);              /* count = 56b/24b */
+
+quo = zero_fac;
+for (i = count; (i > 0) && ((facfrac.h | facfrac.l) != 0); i--) {
+       F_LSH_1 (quo);                                  /* shift quotient */
+       if (!F_LT (facfrac, fsrcfrac)) {                /* divd >= divr? */
+           F_SUB (fsrcfrac, facfrac, facfrac);         /* divd - divr */
+           if (qd) quo.l = quo.l | 1;                  /* double or single? */
+           else quo.h = quo.h | 1;  }
+       F_LSH_1 (facfrac);  }                           /* shift divd */
+if (i > 0) { F_LSH_V (quo, i, quo);  }                 /* early exit? */
+
+/* Dividing two numbers in the range [.5,1) produces a result in the
+   range [.5,2).  Therefore, at most one bit of normalization is required
+   to bring the result back to the range [.5,1).  The choice of counts
+   and quotient bit positions makes this work correctly.
+*/
+
+if (GET_BIT (quo.h, FP_V_HB + FP_GUARD) == 0) {
+       F_LSH_1 (quo);
+       facexp = facexp - 1;  }
+return round_and_pack (facp, facexp, &quo, 1);
+}
+
+/* Update floating condition codes
+   Note that FC is only set by STCfi via the integer condition codes
+
+   Inputs:
+       oldst   =       current status
+       result  =       high result
+       newV    =       new V
+   Outputs:
+       newst   =       new status
+*/
+
+static int32_t setfcc(oldst, result, newV) int32_t oldst; int32_t result; int32_t newV; {
+oldst = (oldst & ~FPS_CC) | newV;
+if (GET_SIGN (result)) oldst = oldst | FPS_N;
+if (GET_EXP (result) == 0) oldst = oldst | FPS_Z;
+return oldst;
+}
+
+/* Round (in place) floating point number to f_floating
+
+   Inputs:
+       fptr    =       pointer to floating number
+   Outputs:
+       ovflow  =       overflow
+*/
+
+static int32_t roundfp11(fptr) fpac_t *fptr; {
+fpac_t outf;
+
+outf = *fptr;                                          /* get argument */
+F_ADD (fround_fac, outf, outf);                                /* round */
+if (GET_SIGN (outf.h ^ fptr->h)) {                     /* flipped sign? */
+       outf.h = (outf.h ^ FP_SIGN) & 0xFFFFFFFF;       /* restore sign */
+       if (fpnotrap (FEC_OVFLO)) *fptr = zero_fac;     /* if no int, clear */
+       else *fptr = outf;                              /* return rounded */
+       return FPS_V;  }                                /* overflow */
+else { *fptr = outf;                                   /* round was ok */
+       return 0;  }                                    /* no overflow */
+}
+
+/* Round result of calculation, test overflow, pack
+
+   Input:
+       facp    =       pointer to result, sign in place
+       exp     =       result exponent, right justified
+       fracp   =       pointer to result fraction, right justified with
+                       guard bits
+       r       =       round (1) or truncate (0)
+   Outputs:
+       ovflo   =       overflow indicator
+*/
+
+static int32_t round_and_pack(facp, exp, fracp, r) fpac_t *facp; int32_t exp; fpac_t *fracp; int r; {
+fpac_t frac;
+
+frac = *fracp;                                         /* get fraction */
+if (r && ((FPS & FPS_T) == 0)) { 
+       if (FPS & FPS_D) { F_ADD (dround_guard_fac, frac, frac);  }
+       else { F_ADD (fround_guard_fac, frac, frac);  }
+       if (GET_BIT (frac.h, FP_V_HB + FP_GUARD + 1)) {
+           F_RSH_1 (frac);
+           exp = exp + 1;  }  }
+F_RSH_GUARD (frac);
+facp->l = frac.l & FP_FRACL;
+facp->h = (facp->h & FP_SIGN) | ((exp & FP_M_EXP) << FP_V_EXP) |
+       (frac.h & FP_FRACH);
+if (exp > 0377) {
+       if (fpnotrap (FEC_OVFLO)) *facp = zero_fac;
+       return FPS_V;  }
+if ((exp <= 0) && (fpnotrap (FEC_UNFLO))) *facp = zero_fac;
+return 0;
+}
+
+/* Process floating point exception
+
+   Inputs:
+       code    =       exception code
+   Outputs:
+       int     =       FALSE if interrupt enabled, TRUE if disabled
+*/
+
+int32_t fpnotrap(code) int32_t code; {
+static const int32_t test_code[] = { 0, 0, 0, FPS_IC, FPS_IV, FPS_IU, FPS_IUV };
+
+if ((code >= FEC_ICVT) && (code <= FEC_UNDFV) &&
+    ((FPS & test_code[code >> 1]) == 0)) return TRUE;
+FPS = FPS | FPS_ER;
+FEC = code;
+/*FEA = (backup_PC - 2) & 0177777;*/
+/*if ((FPS & FPS_ID) == 0) setTRAP (TRAP_FPE);*/
+return FALSE;
+}
+#endif
diff --git a/lib/ccom/pdp11_ldexp.c b/lib/ccom/pdp11_ldexp.c
new file mode 100644 (file)
index 0000000..3bba1b4
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)ldexp.c    2.3 (Berkeley) 6/12/88";
+#endif
+
+/*
+ * double
+ * ldexp (value, exp)
+ *     double value;
+ *     int exp;
+ *
+ * Ldexp returns value*2**exp, if that result is in range.
+ * If underflow occurs, it returns zero.  If overflow occurs,
+ * it returns a value of appropriate sign and largest
+ * possible magnitude.  In case of either overflow or underflow,
+ * errno is set to ERANGE.  Note that errno is not modified if
+ * no error occurs.  Note also that the code assumes that both
+ * FIV and FIU are disabled in the floating point processor:
+ * FIV disabled prevents a trap from ocurring on floating overflow;
+ * FIU disabled cause a floating zero to be generated on floating underflow.
+ */
+
+/* #include "DEFS.h" */
+
+/* ERANGE = 34.                        / can't include <errno.h> because of the */
+/* .comm _errno,2              /   comments on each line ... (sigh) */
+
+#ifndef pdp11
+#include <math.h>
+#include <errno.h>
+#include "c1.h"
+
+/* .data */
+/* huge: 077777; 0177777; 0177777; 0177777 */
+uint16_t huge[4] = { 077777, 0177777, 0177777, 0177777 };
+/* .text */
+
+
+/* ENTRY(ldexp) */
+void pdp11_ldexp(value, exp) uint16_t *value; int exp; {
+       /* movf 2(sp),fr0 */
+       /* / fr0 = value */
+       pdp11_ldf(0, value, 066);
+       /* cfcc */
+       pdp11_cfcc();
+       /* beq 2f */
+       /* / done if zero */
+       if (Z == 0) {
+               /* movei fr0,r0 */
+               /* / r0 = log2(value) */
+               pdp11_movei(0, NULL, 0);
+               /* add 10.(sp),r0 */
+               /* / add exp to log2(value) and stuff result */
+               R[0] += exp;
+               /* movie r0,fr0 */
+               /* /   back as new exponent for fr0 */
+               pdp11_movie(0, NULL, 0);
+               /* cfcc */
+               /* / Overflow? */
+               pdp11_cfcc();
+               /* bvc 2f */
+               if (V) {
+                       /* movf huge,fr0 */
+                       /* / yes, fr0 = (value < 0.0) ? -huge : huge; */
+                       pdp11_ldf(0, huge, 067);                        
+                       /* bpl 1f */
+                       if (N)
+                               /* negf fr0 */
+                               pdp11_negf(NULL, 0);
+                       /* 1: */
+                       /* mov $ERANGE,_errno */
+                       /* /   and errno = ERANGE */
+                       errno = ERANGE;
+               }
+       }
+       /* 2: */
+       /* rts pc */
+}
+#endif
index 3714ce6..769a5eb 100644 (file)
@@ -1,39 +1,24 @@
 #      Makefile        1.3     (2.11BSD) 96/7/11
 #
 
-# Defined SHARED_DATA to be whatever will make your compiler make initialized
-# variables shared and read only.  Don't do this on a PDP-11 if you're also
-# compiling separate I&D since doing so puts the shared data in text space
-# which can't be accessed normally.
-#
-#SHARED_DATA=-R
-
-# CFLAGS=-O -Dunix=1 -DFLEXNAMES
-# If you don't have split I/D, you'll have to edit the constant
-# SBSIZE in cpp.c to reflect this.
-
-CFLAGS=-O -Dpdp11=1 -DFLEXNAMES -DBSD2_11 -UBSD2_10
+CPPFLAGS=-DSTAGEDIR=\"${STAGEDIR}\" -DFLEXNAMES -DTARGET_unix -DTARGET_pdp11 -DTARGET_BSD2_11
+CFLAGS=-O
 SEPFLAG=-i
 
-cpp :  cpp.o cpy.o rodata.o
-       $(CC) $(CFLAGS) $(SEPFLAG) -o cpp rodata.o cpp.o cpy.o
+cpp:   cpp.o y.tab.o
+       $(CC) $(CFLAGS) $(SEPFLAG) -o cpp cpp.o y.tab.o
 
-cpy.c : cpy.y
+y.tab.c: cpy.y
        yacc cpy.y
-       ../pcc/:yyfix yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef
-       mv y.tab.c cpy.c
-
-cpy.o :        cpy.c yylex.c
 
-rodata.o : cpy.c
-       $(CC) $(CFLAGS) ${SHARED_DATA} -c rodata.c
+y.tab.o: y.tab.c yylex.c
 
-clean :
-       rm -f *.s *.o cpy.c rodata.c cpp
+clean:
+       rm -f *.s *.o y.tab.c cpp
 
-install : cpp
+install: cpp
        install -s cpp $(DESTDIR)/lib
 
-sources : cpp.c cpy.y yylex.c README
-cpp.c cpy.y yylex.c README :
+sources: cpp.c cpy.y yylex.c README
+cpp.c cpy.y yylex.c README:
        sccs get $@
index aff3022..4687faf 100644 (file)
 /* static char sccsid[] = "@(#)cpp.c   1.8.2 1996/7/11"; */
 
-#ifdef FLEXNAMES
-#define        NCPS    128
-#else
-#define        NCPS    8
-#endif
+#include <ctype.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "cpp.h"
 
-# include "stdio.h"
-# include "ctype.h"
 /* C command
-/* written by John F. Reiser
-/* July/August 1978
-*/
-
-#define STATIC
-
-#define STDIN 0
-#define STDOUT 1
-#define STDERR 2
-#define READ 0
-#define WRITE 1
-#define SALT '#'
-#ifndef BUFSIZ
-#define BUFSIZ 512
-#endif
+ * written by John F. Reiser
+ * July/August 1978
+ */
 
 char *pbeg,*pbuf,*pend;
 char *outp,*inp;
 char *newp;
 char cinit;
 
-/* some code depends on whether characters are sign or zero extended */
-/*     #if '\377' < 0          not used here, old cpp doesn't understand */
-#if pdp11 | vax | mc68000
-#define COFF 128
-#else
-#define COFF 0
-#endif
-
-# if gcos
-#define ALFSIZ 512     /* alphabet size */
-# else
-#define ALFSIZ 256     /* alphabet size */
-# endif
 char macbit[ALFSIZ+11];
 char toktyp[ALFSIZ];
-#define BLANK 1
-#define IDENT 2
-#define NUMBR 3
-
-/* a superimposed code is used to reduce the number of calls to the
-/* symbol table lookup routine.  (if the kth character of an identifier
-/* is 'a' and there are no macro names whose kth character is 'a'
-/* then the identifier cannot be a macro name, hence there is no need
-/* to look in the symbol table.)  'scw1' enables the test based on
-/* single characters and their position in the identifier.  'scw2'
-/* enables the test based on adjacent pairs of characters and their
-/* position in the identifier.  scw1 typically costs 1 indexed fetch,
-/* an AND, and a jump per character of identifier, until the identifier
-/* is known as a non-macro name or until the end of the identifier.
-/* scw1 is inexpensive.  scw2 typically costs 4 indexed fetches,
-/* an add, an AND, and a jump per character of identifier, but it is also
-/* slightly more effective at reducing symbol table searches.
-/* scw2 usually costs too much because the symbol table search is
-/* usually short; but if symbol table search should become expensive,
-/* the code is here.
-/* using both scw1 and scw2 is of dubious value.
-*/
-#define scw1 1
-#define scw2 0
 
 #if scw2
 char t21[ALFSIZ],t22[ALFSIZ],t23[ALFSIZ+NCPS];
 #endif
 
-#if scw1
-#define b0 1
-#define b1 2
-#define b2 4
-#define b3 8
-#define b4 16
-#define b5 32
-#define b6 64
-#define b7 128
-#endif
-
-#define IB 1
-#define SB 2
-#define NB 4
-#define CB 8
-#define QB 16
-#define WB 32
 char fastab[ALFSIZ];
 char slotab[ALFSIZ];
 char *ptrtab;
-#define isslo (ptrtab==(slotab+COFF))
-#define isid(a)  ((fastab+COFF)[a]&IB)
-#define isspc(a) (ptrtab[a]&SB)
-#define isnum(a) ((fastab+COFF)[a]&NB)
-#define iscom(a) ((fastab+COFF)[a]&CB)
-#define isquo(a) ((fastab+COFF)[a]&QB)
-#define iswarn(a) ((fastab+COFF)[a]&WB)
-
-#define eob(a) ((a)>=pend)
-#define bob(a) (pbeg>=(a))
-
-# define cputc(a,b)    if(!flslvl) putc(a,b)
 
 char buffer[NCPS+BUFSIZ+BUFSIZ+NCPS];
 
 #ifdef pdp11
-# define SBSIZE ((unsigned)0114130)    /* PDP compiler doesn't like 39024 */
 short  sbff[SBSIZE/2];
-# define sbf ((char *)sbff)
-#else !pdp11
-# define SBSIZE 60000          /* std = 12000, wnj aug 1979 */
+#else /* !pdp11 */
 char   sbf[SBSIZE];
-#endif pdp11
+#endif /* pdp11 */
 char   *savch  = sbf;
 
-# define DROP 0xFE     /* special character not legal ASCII or EBCDIC */
-# define WARN DROP
-# define SAME 0
-# define MAXINC 10
-# define MAXFRE 14     /* max buffers of macro pushback */
-# define MAXFRM 31     /* max number of formals/actuals to a macro */
-
 static char warnc = WARN;
 
 int mactop,fretop;
@@ -143,38 +55,37 @@ int macdam;        /* offset to macforw due to buffer shifting */
 int tgpscan;   /* flag for dump(); */
 #endif
 
-STATIC int     inctop[MAXINC];
-STATIC char    *fnames[MAXINC];
-STATIC char    *dirnams[MAXINC];       /* actual directory of #include files */
-STATIC int     fins[MAXINC];
-STATIC int     lineno[MAXINC];
-
-STATIC char    *dirs[10];      /* -I and <> directories */
-char *strdex(), *copy(), *subst(), *trmdir();
-struct symtab *stsym();
-STATIC int     fin     = STDIN;
-STATIC FILE    *fout   = stdout;
-STATIC int     nd      = 1;
-STATIC int     pflag;  /* don't put out lines "# 12 foo.c" */
+static int     inctop[MAXINC];
+static char    *fnames[MAXINC];
+static char    *dirnams[MAXINC];       /* actual directory of #include files */
+static int     fins[MAXINC];
+static int     lineno[MAXINC];
+
+static char    *dirs[10];      /* -I and <> directories */
+static int     fin     = STDIN;
+#ifdef pdp11
+static FILE    *fout   = stdout;
+#else
+static FILE    *fout;
+#endif
+static int     nd      = 1;
+static int     pflag;  /* don't put out lines "# 12 foo.c" */
 int    passcom;        /* don't delete comments */
-STATIC int rflag;      /* allow macro recursion */
-STATIC int mflag;      /* generate makefile dependencies */
-STATIC char *infile;   /* name of .o file to build dependencies from */
-STATIC         FILE *mout;     /* file to place dependencies on */
+static int rflag;      /* allow macro recursion */
+static int mflag;      /* generate makefile dependencies */
+static char *infile;   /* name of .o file to build dependencies from */
+static FILE *mout;     /* file to place dependencies on */
 #define START 1
 #define CONT  2
 #define BACK  3
-STATIC int     ifno;
+static int     ifno;
 # define NPREDEF 30
-STATIC char *prespc[NPREDEF];
-STATIC char **predef = prespc;
-STATIC char *punspc[NPREDEF];
-STATIC char **prund = punspc;
-STATIC int     exfail;
-struct symtab {
-       char    *name;
-       char    *value;
-} *lastsym, *lookup(), *slookup();
+static char *prespc[NPREDEF];
+static char **predef = prespc;
+static char *punspc[NPREDEF];
+static char **prund = punspc;
+static int     exfail;
+static struct symtab *lastsym;
 
 # if gcos
 #include <setjmp.h>
@@ -189,91 +100,91 @@ extern FILE *_f[];
 # else
 # define symsiz 2000           /* std = 500, wnj aug 1979 */
 # endif
-STATIC struct symtab stab[symsiz];
-
-STATIC struct symtab *defloc;
-STATIC struct symtab *udfloc;
-STATIC struct symtab *incloc;
-STATIC struct symtab *ifloc;
-STATIC struct symtab *elsloc;
-STATIC struct symtab *eifloc;
-STATIC struct symtab *ifdloc;
-STATIC struct symtab *ifnloc;
-STATIC struct symtab *ysysloc;
-STATIC struct symtab *varloc;
-STATIC struct symtab *lneloc;
-STATIC struct symtab *ulnloc;
-STATIC struct symtab *uflloc;
-STATIC int     trulvl;
-STATIC int     flslvl;
-
-sayline(where)
-       int where;
-{
+static struct symtab stab[symsiz];
+
+static struct symtab *defloc;
+static struct symtab *udfloc;
+static struct symtab *incloc;
+static struct symtab *ifloc;
+static struct symtab *elsloc;
+static struct symtab *eifloc;
+static struct symtab *ifdloc;
+static struct symtab *ifnloc;
+static struct symtab *ysysloc;
+static struct symtab *varloc;
+static struct symtab *lneloc;
+static struct symtab *ulnloc;
+static struct symtab *uflloc;
+static int     trulvl;
+int    flslvl;
+
+static char *copy PARAMS((register char *s));
+
+void sayline(where) int where; {
        if (mflag && where==START) fprintf(mout, "%s: %s\n", infile, fnames[ifno]);
        if (pflag==0) fprintf(fout,"# %d \"%s\"\n", lineno[ifno], fnames[ifno]);
 }
 
 /* data structure guide
-/*
-/* most of the scanning takes place in the buffer:
-/*
-/*  (low address)                                             (high address)
-/*  pbeg                           pbuf                                 pend
-/*  |      <-- BUFSIZ chars -->      |         <-- BUFSIZ chars -->        |
-/*  _______________________________________________________________________
-/* |_______________________________________________________________________|
-/*          |               |               |
-/*          |<-- waiting -->|               |<-- waiting -->
-/*          |    to be      |<-- current -->|    to be
-/*          |    written    |    token      |    scanned
-/*          |               |               |
-/*          outp            inp             p
-/*
-/*  *outp   first char not yet written to output file
-/*  *inp    first char of current token
-/*  *p      first char not yet scanned
-/*
-/* macro expansion: write from *outp to *inp (chars waiting to be written),
-/* ignore from *inp to *p (chars of the macro call), place generated
-/* characters in front of *p (in reverse order), update pointers,
-/* resume scanning.
-/*
-/* symbol table pointers point to just beyond the end of macro definitions;
-/* the first preceding character is the number of formal parameters.
-/* the appearance of a formal in the body of a definition is marked by
-/* 2 chars: the char WARN, and a char containing the parameter number.
-/* the first char of a definition is preceded by a zero character.
-/*
-/* when macro expansion attempts to back up over the beginning of the
-/* buffer, some characters preceding *pend are saved in a side buffer,
-/* the address of the side buffer is put on 'instack', and the rest
-/* of the main buffer is moved to the right.  the end of the saved buffer
-/* is kept in 'endbuf' since there may be nulls in the saved buffer.
-/*
-/* similar action is taken when an 'include' statement is processed,
-/* except that the main buffer must be completely emptied.  the array
-/* element 'inctop[ifno]' records the last side buffer saved when
-/* file 'ifno' was included.  these buffers remain dormant while
-/* the file is being read, and are reactivated at end-of-file.
-/*
-/* instack[0 : mactop] holds the addresses of all pending side buffers.
-/* instack[inctop[ifno]+1 : mactop-1] holds the addresses of the side
-/* buffers which are "live"; the side buffers instack[0 : inctop[ifno]]
-/* are dormant, waiting for end-of-file on the current file.
-/*
-/* space for side buffers is obtained from 'savch' and is never returned.
-/* bufstack[0:fretop-1] holds addresses of side buffers which
-/* are available for use.
-*/
-
-dump() {
+ *
+ * most of the scanning takes place in the buffer:
+ *
+ *  (low address)                                             (high address)
+ *  pbeg                           pbuf                                 pend
+ *  |      <-- BUFSIZ chars -->      |         <-- BUFSIZ chars -->        |
+ *  _______________________________________________________________________
+ * |_______________________________________________________________________|
+ *          |               |               |
+ *          |<-- waiting -->|               |<-- waiting -->
+ *          |    to be      |<-- current -->|    to be
+ *          |    written    |    token      |    scanned
+ *          |               |               |
+ *          outp            inp             p
+ *
+ *  *outp   first char not yet written to output file
+ *  *inp    first char of current token
+ *  *p      first char not yet scanned
+ *
+ * macro expansion: write from *outp to *inp (chars waiting to be written),
+ * ignore from *inp to *p (chars of the macro call), place generated
+ * characters in front of *p (in reverse order), update pointers,
+ * resume scanning.
+ *
+ * symbol table pointers point to just beyond the end of macro definitions;
+ * the first preceding character is the number of formal parameters.
+ * the appearance of a formal in the body of a definition is marked by
+ * 2 chars: the char WARN, and a char containing the parameter number.
+ * the first char of a definition is preceded by a zero character.
+ *
+ * when macro expansion attempts to back up over the beginning of the
+ * buffer, some characters preceding *pend are saved in a side buffer,
+ * the address of the side buffer is put on 'instack', and the rest
+ * of the main buffer is moved to the right.  the end of the saved buffer
+ * is kept in 'endbuf' since there may be nulls in the saved buffer.
+ *
+ * similar action is taken when an 'include' statement is processed,
+ * except that the main buffer must be completely emptied.  the array
+ * element 'inctop[ifno]' records the last side buffer saved when
+ * file 'ifno' was included.  these buffers remain dormant while
+ * the file is being read, and are reactivated at end-of-file.
+ *
+ * instack[0 : mactop] holds the addresses of all pending side buffers.
+ * instack[inctop[ifno]+1 : mactop-1] holds the addresses of the side
+ * buffers which are "live"; the side buffers instack[0 : inctop[ifno]]
+ * are dormant, waiting for end-of-file on the current file.
+ *
+ * space for side buffers is obtained from 'savch' and is never returned.
+ * bufstack[0:fretop-1] holds addresses of side buffers which
+ * are available for use.
+ */
+
+void dump() {
 /* write part of buffer which lies between  outp  and  inp .
-/* this should be a direct call to 'write', but the system slows to a crawl
-/* if it has to do an unaligned copy.  thus we buffer.  this silly loop
-/* is 15% of the total time, thus even the 'putc' macro is too slow.
-*/
-       register char *p1,*p2; register FILE *f;
+ * this should be a direct call to 'write', but the system slows to a crawl
+ * if it has to do an unaligned copy.  thus we buffer.  this silly loop
+ * is 15% of the total time, thus even the 'putc' macro is too slow.
+ */
+       register char *p1/*,*p2*/; register FILE *f;
        if ((p1=outp)==inp || flslvl!=0) return;
 #if tgp
 #define MAXOUT 80
@@ -312,8 +223,8 @@ dump() {
 char *
 refill(p) register char *p; {
 /* dump buffer.  save chars from inp to p.  read into buffer at pbuf,
-/* contiguous with p.  update pointers, return new p.
-*/
+ * contiguous with p.  update pointers, return new p.
+ */
        register char *np,*op; register int ninbuf;
        dump(); np=pbuf-(p-inp); op=inp;
        if (bob(np+1)) {pperror("token too long"); np=pbeg; p=inp+BUFSIZ;}
@@ -519,17 +430,15 @@ prevlf:
 } /* end of infinite loop */
 }
 
-char *
-skipbl(p) register char *p; {/* get next non-blank token */
+char *skipbl(p) register char *p; {/* get next non-blank token */
        do {outp=inp=p; p=cotoken(p);} while ((toktyp+COFF)[*inp]==BLANK);
        return(p);
 }
 
-char *
-unfill(p) register char *p; {
+char *unfill(p) register char *p; {
 /* take <= BUFSIZ chars from right end of buffer and put them on instack .
-/* slide rest of buffer to the right, update pointers, return new p.
-*/
+ * slide rest of buffer to the right, update pointers, return new p.
+ */
        register char *np,*op; register int d;
        if (mactop>=MAXFRE) {
                pperror("%s: too much pushback",macnam);
@@ -551,8 +460,7 @@ unfill(p) register char *p; {
        d=np-outp; outp+=d; inp+=d; macdam+=d; return(p+d);
 }
 
-char *
-doincl(p) register char *p; {
+char *doincl(p) register char *p; {
        int filok,inctype;
        register char *cp; char **dirp,*nfil; char filname[BUFSIZ];
 
@@ -609,6 +517,7 @@ doincl(p) register char *p; {
                        strcat(nfil,filname);
                }
                if (0<(fins[ifno+1]=open(nfil,READ))) {
+ /*fprintf(stderr, "include \"%s\"\n", nfil);*/
                        filok=1; fin=fins[++ifno]; break;
                }
        }
@@ -624,14 +533,13 @@ doincl(p) register char *p; {
        return(p);
 }
 
-equfrm(a,p1,p2) register char *a,*p1,*p2; {
+int equfrm(a, p1, p2) register char *a; register char *p1; register char *p2; {
        register char c; int flag;
        c= *p2; *p2='\0';
        flag=strcmp(a,p1); *p2=c; return(flag==SAME);
 }
 
-char *
-dodef(p) char *p; {/* process '#define' */
+char *dodef(p) char *p; {/* process '#define' */
        register char *pin,*psav,*cf;
        char **pf,**qf; int b,c,params; struct symtab *np;
        char *oldval,*oldsavch;
@@ -676,8 +584,8 @@ dodef(p) char *p; {/* process '#define' */
                if (params==0) --params; /* #define foo() ... */
        } else if (*pin=='\n') {--lineno[ifno]; --p;}
        /* remember beginning of macro body, so that we can
-       /* warn if a redefinition is different from old value.
-       */
+        * warn if a redefinition is different from old value.
+        */
        oldsavch=psav=savch;
        for (;;) {/* accumulate definition until linefeed */
                outp=inp=p; p=cotoken(p); pin=inp;
@@ -725,8 +633,7 @@ dodef(p) char *p; {/* process '#define' */
 #define fasscan() ptrtab=fastab+COFF
 #define sloscan() ptrtab=slotab+COFF
 
-char *
-control(p) register char *p; {/* find and handle preprocessor control lines */
+char *control(p) register char *p; {/* find and handle preprocessor control lines */
        register struct symtab *np;
 for (;;) {
        fasscan(); p=cotoken(p); if (*inp=='\n') ++inp; dump();
@@ -795,10 +702,7 @@ for (;;) {
 }
 }
 
-char *
-savestring(start, finish)
-       register char *start, *finish;
-{
+char *savestring(start, finish) register char *start; register char *finish; {
        char *retbuf;
        register char *cp;
 
@@ -810,8 +714,7 @@ savestring(start, finish)
        return(retbuf);
 }
 
-struct symtab *
-stsym(s) register char *s; {
+struct symtab *stsym(s) register char *s; {
        char buf[BUFSIZ]; register char *p;
 
        /* make definition look exactly like end of #define line */
@@ -824,14 +727,12 @@ stsym(s) register char *s; {
        sloscan(); dodef(buf); return(lastsym);
 }
 
-struct symtab *
-ppsym(s) char *s; {/* kluge */
+struct symtab *ppsym(s) char *s; {/* kluge */
        register struct symtab *sp;
        cinit=SALT; *savch++=SALT; sp=stsym(s); --sp->name; cinit=0; return(sp);
 }
 
-/* VARARGS1 */
-pperror(s,x,y) char *s; {
+void vpperror(s, ap) char *s; va_list ap; {
        if (fnames[ifno][0]) fprintf(stderr,
 # if gcos
                        "*%c*   \"%s\", line ", exfail >= 0 ? 'F' : 'W',
@@ -840,26 +741,57 @@ pperror(s,x,y) char *s; {
 # endif
                                 fnames[ifno]);
        fprintf(stderr, "%d: ",lineno[ifno]);
-       fprintf(stderr, s, x, y);
+       vfprintf(stderr, s, ap);
        fprintf(stderr,"\n");
        ++exfail;
 }
 
-yyerror(s,a,b) char *s; {
-       pperror(s,a,b);
+/* VARARGS1 */
+#ifdef __STDC__
+void pperror(char *s, ...)
+#else
+void pperror(s, va_alist) char *s; va_dcl
+#endif
+{
+       va_list ap;
+
+       va_start(ap, s);
+       vpperror(s, ap);
+       va_end(ap);
 }
 
-ppwarn(s,x) char *s; {
+/* VARARGS1 */
+#ifdef __STDC__
+void yyerror(char *s, ...)
+#else
+void yyerror(s, va_alist) char *s; va_dcl
+#endif
+{
+       va_list ap;
+
+       va_start(ap, s);
+       vpperror(s, ap);
+       va_end(ap);
+}
+
+/* VARARGS1 */
+#ifdef __STDC__
+void ppwarn(char *s, ...)
+#else
+void ppwarn(s, va_alist) char *s; va_dcl
+#endif
+{
+       va_list ap;
+
        int fail = exfail;
        exfail = -1;
-       pperror(s,x);
+       va_start(ap, s);
+       vpperror(s, ap);
+       va_end(ap);
        exfail = fail;
 }
 
-struct symtab *
-lookup(namep, enterf)
-char *namep;
-{
+struct symtab *lookup(namep, enterf) char *namep; int enterf; {
        register char *np, *snp;
        register int c, i; int around;
        register struct symtab *sp;
@@ -883,8 +815,7 @@ char *namep;
        return(lastsym=sp);
 }
 
-struct symtab *
-slookup(p1,p2,enterf) register char *p1,*p2; int enterf;{
+struct symtab *slookup(p1, p2, enterf) register char *p1; register char *p2; int enterf; {
        register char *p3; char c2,c3; struct symtab *np;
                 c2= *p2; *p2='\0';     /* mark end of token */
        if ((p2-p1)>NCPS) p3=p1+NCPS; else p3=p2;
@@ -896,8 +827,7 @@ slookup(p1,p2,enterf) register char *p1,*p2; int enterf;{
        return(np);
 }
 
-char *
-subst(p,sp) register char *p; struct symtab *sp; {
+char *subst(p, sp) register char *p; struct symtab *sp; {
        static char match[]="%s: argument mismatch";
        register char *ca,*vp; int params;
        char *actual[MAXFRM]; /* actual[n] is text of nth actual   */
@@ -981,8 +911,7 @@ subst(p,sp) register char *p; struct symtab *sp; {
 
 
 
-char *
-trmdir(s) register char *s; {
+char *trmdir(s) register char *s; {
        register char *p = s;
        while (*p++); --p; while (p>s && *--p!='/');
 # if unix
@@ -992,29 +921,28 @@ trmdir(s) register char *s; {
        return(s);
 }
 
-STATIC char *
-copy(s) register char *s; {
+static char *copy(s) register char *s; {
        register char *old;
 
        old = savch; while (*savch++ = *s++);
        return(old);
 }
 
-char *
-strdex(s,c) char *s,c; {
+char *strdex(s, c) char *s; int c; {
        while (*s) if (*s++==c) return(--s);
        return(0);
 }
 
-yywrap(){ return(1); }
+int yywrap(){ return(1); }
 
-main(argc,argv)
-       char *argv[];
-{
+int main(argc,argv) int argc; char *argv[]; {
        register int i,c;
        register char *p;
        char *tf,**cp2, obuf[BUFSIZ];
 
+#ifndef pdp11
+       fout = stdout;
+#endif
 # if gcos
        if (setjmp(env)) return (exfail);
 # endif
@@ -1024,9 +952,9 @@ main(argc,argv)
                        (fastab+COFF)[c] |= IB|NB|SB; (toktyp+COFF)[c]=IDENT;
 #if scw2
                        /* 53 == 63-10; digits rarely appear in identifiers,
-                       /* and can never be the first char of an identifier.
-                       /* 11 == 53*53/sizeof(macbit) .
-                       */
+                        * and can never be the first char of an identifier.
+                        * 11 == 53*53/sizeof(macbit) .
+                        */
                        ++i; (t21+COFF)[c]=(53*i)/11; (t22+COFF)[c]=i%11;
 #endif
                }
@@ -1158,7 +1086,7 @@ main(argc,argv)
        exfail = 0;
                /* after user -I files here are the standard include libraries */
 # if unix
-       dirs[nd++] = "/usr/include";
+       dirs[nd++] = STAGEDIR "/usr/include";
 # endif
 # if gcos
        dirs[nd++] = "cc/include";
@@ -1183,46 +1111,46 @@ main(argc,argv)
        ifloc=ppsym("if");
        lneloc=ppsym("line");
        for (i=sizeof(macbit)/sizeof(macbit[0]); --i>=0; ) macbit[i]=0;
-# if unix
+# if TARGET_unix
        ysysloc=stsym("unix");
 # endif
-# if gcos
+# if TARGET_gcos
        ysysloc=stsym ("gcos");
 # endif
-# if ibm
+# if TARGET_ibm
        ysysloc=stsym ("ibm");
 # endif
-# if pdp11
+# if TARGET_pdp11
        varloc=stsym("pdp11");
 # endif
-# if vax
+# if TARGET_vax
        varloc=stsym("vax");
 # endif
-# if interdata
+# if TARGET_interdata
        varloc=stsym ("interdata");
 # endif
-# if tss
+# if TARGET_tss
        varloc=stsym ("tss");
 # endif
-# if os
+# if TARGET_os
        varloc=stsym ("os");
 # endif
-# if mert
+# if TARGET_mert
        varloc=stsym ("mert");
 # endif
-# if mc68000
+# if TARGET_mc68000
        varloc=stsym("mc68000");
 # endif
-# if sun
+# if TARGET_sun
        varloc=stsym("sun");
 # endif
-# if BSD2_11
+# if TARGET_BSD2_11
        varloc=stsym("BSD2_11");
 # endif
-# if BSD2_10
+# if TARGET_BSD2_10
        varloc=stsym("BSD2_10");
 # endif
-# if BSD2_9
+# if TARGET_BSD2_9
        varloc=stsym("BSD2_9");
 # endif
        ulnloc=stsym ("__LINE__");
diff --git a/lib/cpp/cpp.h b/lib/cpp/cpp.h
new file mode 100644 (file)
index 0000000..fb923db
--- /dev/null
@@ -0,0 +1,172 @@
+#ifndef _CPP_H
+#define _CPP_H 1
+
+#ifdef FLEXNAMES
+#define        NCPS    128
+#else
+#define        NCPS    8
+#endif
+
+#include <stdio.h>
+#include "krcompat.h"
+
+#define STDIN 0
+#define STDOUT 1
+#define STDERR 2
+#define READ 0
+#define WRITE 1
+#define SALT '#'
+
+extern char *pbeg,*pbuf,*pend;
+extern char *outp,*inp;
+extern char *newp;
+extern char cinit;
+
+/* some code depends on whether characters are sign or zero extended */
+/*     #if '\377' < 0          not used here, old cpp doesn't understand */
+#if pdp11 | vax | mc68000
+#define COFF 128
+#else
+#define COFF 0
+#endif
+
+# if gcos
+#define ALFSIZ 512     /* alphabet size */
+# else
+#define ALFSIZ 256     /* alphabet size */
+# endif
+extern char macbit[ALFSIZ+11];
+extern char toktyp[ALFSIZ];
+#define BLANK 1
+#define IDENT 2
+#define NUMBR 3
+
+/* a superimposed code is used to reduce the number of calls to the
+ * symbol table lookup routine.  (if the kth character of an identifier
+ * is 'a' and there are no macro names whose kth character is 'a'
+ * then the identifier cannot be a macro name, hence there is no need
+ * to look in the symbol table.)  'scw1' enables the test based on
+ * single characters and their position in the identifier.  'scw2'
+ * enables the test based on adjacent pairs of characters and their
+ * position in the identifier.  scw1 typically costs 1 indexed fetch,
+ * an AND, and a jump per character of identifier, until the identifier
+ * is known as a non-macro name or until the end of the identifier.
+ * scw1 is inexpensive.  scw2 typically costs 4 indexed fetches,
+ * an add, an AND, and a jump per character of identifier, but it is also
+ * slightly more effective at reducing symbol table searches.
+ * scw2 usually costs too much because the symbol table search is
+ * usually short; but if symbol table search should become expensive,
+ * the code is here.
+ * using both scw1 and scw2 is of dubious value.
+ */
+#define scw1 1
+#define scw2 0
+
+#if scw2
+extern char t21[ALFSIZ],t22[ALFSIZ],t23[ALFSIZ+NCPS];
+#endif
+
+#if scw1
+#define b0 1
+#define b1 2
+#define b2 4
+#define b3 8
+#define b4 16
+#define b5 32
+#define b6 64
+#define b7 128
+#endif
+
+#define IB 1
+#define SB 2
+#define NB 4
+#define CB 8
+#define QB 16
+#define WB 32
+extern char fastab[ALFSIZ];
+extern char slotab[ALFSIZ];
+extern char *ptrtab;
+#define isslo (ptrtab==(slotab+COFF))
+#define isid(a)  ((fastab+COFF)[a]&IB)
+#define isspc(a) (ptrtab[a]&SB)
+#define isnum(a) ((fastab+COFF)[a]&NB)
+#define iscom(a) ((fastab+COFF)[a]&CB)
+#define isquo(a) ((fastab+COFF)[a]&QB)
+#define iswarn(a) ((fastab+COFF)[a]&WB)
+
+#define eob(a) ((a)>=pend)
+#define bob(a) (pbeg>=(a))
+
+# define cputc(a,b)    if(!flslvl) putc(a,b)
+
+extern char buffer[NCPS+BUFSIZ+BUFSIZ+NCPS];
+
+#ifdef pdp11
+# define SBSIZE ((unsigned)0114130)    /* PDP compiler doesn't like 39024 */
+extern short sbff[SBSIZE/2];
+# define sbf ((char *)sbff)
+#else /* !pdp11 */
+# define SBSIZE 60000*(BUFSIZ/512)     /* Nick... std = 12000, wnj aug 1979 */
+extern char sbf[SBSIZE];
+#endif /* pdp11 */
+extern char *savch;
+
+# define DROP 0xFE     /* special character not legal ASCII or EBCDIC */
+# define WARN DROP
+# define SAME 0
+# define MAXINC 10
+# define MAXFRE 14     /* max buffers of macro pushback */
+# define MAXFRM 31     /* max number of formals/actuals to a macro */
+
+extern int mactop,fretop;
+extern char *instack[MAXFRE],*bufstack[MAXFRE],*endbuf[MAXFRE];
+
+extern int plvl;       /* parenthesis level during scan for macro actuals */
+extern int maclin;     /* line number of macro call requiring actuals */
+extern char *macfil;   /* file name of macro call requiring actuals */
+extern char *macnam;   /* name of macro requiring actuals */
+extern int maclvl;     /* # calls since last decrease in nesting level */
+extern char *macforw;  /* pointer which must be exceeded to decrease nesting level */
+extern int macdam;     /* offset to macforw due to buffer shifting */
+
+#if tgp
+extern int tgpscan;    /* flag for dump(); */
+#endif
+
+extern int passcom;    /* don't delete comments */
+
+struct symtab {
+       char    *name;
+       char    *value;
+};
+
+extern int flslvl;     /* formerly static but now referenced in yylex.c */
+
+void sayline PARAMS((int where));
+void dump PARAMS((void));
+char *refill PARAMS((register char *p));
+char *cotoken PARAMS((register char *p));
+char *skipbl PARAMS((register char *p));
+char *unfill PARAMS((register char *p));
+char *doincl PARAMS((register char *p));
+int equfrm PARAMS((register char *a, register char *p1, register char *p2));
+char *dodef PARAMS((char *p));
+char *control PARAMS((register char *p));
+char *savestring PARAMS((register char *start, register char *finish));
+struct symtab *stsym PARAMS((register char *s));
+struct symtab *ppsym PARAMS((char *s));
+void vpperror PARAMS((char *s, va_list ap));
+void pperror PARAMS((char *s, ...));
+void yyerror PARAMS((char *s, ...));
+void ppwarn PARAMS((char *s, ...));
+struct symtab *lookup PARAMS((char *namep, int enterf));
+struct symtab *slookup PARAMS((register char *p1, register char *p2, int enterf));
+char *subst PARAMS((register char *p, struct symtab *sp));
+char *trmdir PARAMS((register char *s));
+char *strdex PARAMS((char *s, int c));
+int yywrap PARAMS((void));
+int main PARAMS((int argc, char *argv[]));
+int yylex PARAMS((void));
+int yyparse PARAMS((void));
+
+#endif
index d593a16..6fc9f6c 100644 (file)
@@ -1,6 +1,11 @@
 /*
  * @(#)cpy.y 1.2 1/2/83
  */
+
+%{
+#include "cpp.h"
+%}
+
 %term number stop DEFINED
 %term EQ NE LE GE LS RS
 %term ANDAND OROR
 %right '!' '~' UMINUS
 %left '(' '.'
 %%
-S:     e stop  ={return($1);}
+S:     e stop  {return($1);}
 
 
 e:       e '*' e
-               ={$$ = $1 * $3;}
+               {$$ = $1 * $3;}
        | e '/' e
-               ={$$ = $1 / $3;}
+               {$$ = $1 / $3;}
        | e '%' e
-               ={$$ = $1 % $3;}
+               {$$ = $1 % $3;}
        | e '+' e
-               ={$$ = $1 + $3;}
+               {$$ = $1 + $3;}
        | e '-' e
-               ={$$ = $1 - $3;}
+               {$$ = $1 - $3;}
        | e LS e
-               ={$$ = $1 << $3;}
+               {$$ = $1 << $3;}
        | e RS e
-               ={$$ = $1 >> $3;}
+               {$$ = $1 >> $3;}
        | e '<' e
-               ={$$ = $1 < $3;}
+               {$$ = $1 < $3;}
        | e '>' e
-               ={$$ = $1 > $3;}
+               {$$ = $1 > $3;}
        | e LE e
-               ={$$ = $1 <= $3;}
+               {$$ = $1 <= $3;}
        | e GE e
-               ={$$ = $1 >= $3;}
+               {$$ = $1 >= $3;}
        | e EQ e
-               ={$$ = $1 == $3;}
+               {$$ = $1 == $3;}
        | e NE e
-               ={$$ = $1 != $3;}
+               {$$ = $1 != $3;}
        | e '&' e
-               ={$$ = $1 & $3;}
+               {$$ = $1 & $3;}
        | e '^' e
-               ={$$ = $1 ^ $3;}
+               {$$ = $1 ^ $3;}
        | e '|' e
-               ={$$ = $1 | $3;}
+               {$$ = $1 | $3;}
        | e ANDAND e
-               ={$$ = $1 && $3;}
+               {$$ = $1 && $3;}
        | e OROR e
-               ={$$ = $1 || $3;}
+               {$$ = $1 || $3;}
        | e '?' e ':' e
-               ={$$ = $1 ? $3 : $5;}
+               {$$ = $1 ? $3 : $5;}
        | e ',' e
-               ={$$ = $3;}
+               {$$ = $3;}
        | term
-               ={$$ = $1;}
+               {$$ = $1;}
 term:
          '-' term %prec UMINUS
-               ={$$ = -$2;}
+               {$$ = -$2;}
        | '!' term
-               ={$$ = !$2;}
+               {$$ = !$2;}
        | '~' term
-               ={$$ = ~$2;}
+               {$$ = ~$2;}
        | '(' e ')'
-               ={$$ = $2;}
+               {$$ = $2;}
        | DEFINED '(' number ')'
-               ={$$= $3;}
+               {$$= $3;}
        | DEFINED number
-               ={$$ = $2;}
+               {$$ = $2;}
        | number
-               ={$$= $1;}
+               {$$= $1;}
 %%
 # include "yylex.c"
diff --git a/lib/cpp/krcompat.h b/lib/cpp/krcompat.h
new file mode 100644 (file)
index 0000000..62f9848
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _KRCOMPAT_H
+#define _KRCOMPAT_H 1
+
+#undef PARAMS
+#ifdef __STDC__
+#include <stdarg.h>
+#define PARAMS(args) args
+#else
+#include <varargs.h>
+#define PARAMS(args) ()
+#endif
+
+#ifdef __GNUC__
+#define NORETURN __attribute__ ((noreturn))
+#else
+#define NORETURN
+#endif
+
+#endif
diff --git a/lib/cpp/n.sh b/lib/cpp/n.sh
new file mode 100755 (executable)
index 0000000..c1bd4cd
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/lib\/cpp$//'`"
+DESTDIR="$ROOT/host"
+STAGEDIR="$ROOT/stage"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/lib"
+make clean && make SEPFLAG= DESTDIR="$DESTDIR" STAGEDIR="$STAGEDIR" CFLAGS="$CFLAGS" install
index a3f5e52..463d9ee 100644 (file)
@@ -1,5 +1,8 @@
 /* static char sccsid[] = "@(#)yylex.c 1.3 7/1/83"; */
 
+#include <string.h>
+#include "cpp.h"
+
 #define isid(a)  ((fastab+COFF)[a]&IB)
 #define IB 1
 /*     #if '\377' < 0          it would be nice if this worked properly!!!!! */
 #define COFF 0
 #endif
 
-yylex() {
+static int tobinary PARAMS((char *st, int b));
+
+int yylex() {
        static int ifdef=0;
        static char *op2[]={"||",  "&&" , ">>", "<<", ">=", "<=", "!=", "=="};
        static int  val2[]={OROR, ANDAND,  RS,   LS,   GE,   LE,   NE,   EQ};
        static char *opc="b\bt\tn\nf\fr\r\\\\";
-       extern char fastab[];
-       extern char *outp,*inp,*newp; extern int flslvl;
        register char savc, *s; char *skipbl(); int val;
        register char **p2;
-       struct symtab {
+       struct symtab /*{
                char *name;
                char *value;
-       } *sp, *lookup();
+       }*/ *sp/*, *lookup()*/;
 
 for (;;) {
-       extern int passcom;             /* this crap makes #if's work */
        int opt_passcom = passcom;      /* even with -C option */
        passcom = 0;                    /* (else comments make syntax errs) */
        newp=skipbl(newp);
@@ -66,7 +68,7 @@ ret:
 }
 }
 
-tobinary(st, b) char *st; {
+static int tobinary(st, b) char *st; int b; {
        int n, c, t;
        char *s;
        n=0;
index 48f12e7..b937336 100644 (file)
 
 #include <a.out.h>
 
+#ifndef pdp11
+#define off_t long
+#endif
+
 off_t
 n_stroff(ep)
        register struct xexec *ep;
diff --git a/n.sh b/n.sh
new file mode 100755 (executable)
index 0000000..ea4a011
--- /dev/null
+++ b/n.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+ROOT="`pwd`"
+DESTDIR="$ROOT/host"
+STAGEDIR="$ROOT/stage"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/bin"
+mkdir --parents "$DESTDIR/lib"
+mkdir --parents "$DESTDIR/usr/lib"
+mkdir --parents "$DESTDIR/usr/man/cat1"
+mkdir --parents "$DESTDIR/usr/man/cat3"
+mkdir --parents "$DESTDIR/usr/man/cat5"
+(cd bin/ar && make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" LDFLAGS="-L$DESTDIR/usr/lib" install)
+(cd bin/as && make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install)
+(cd bin/cc && make clean && make SEPFLAG= DESTDIR="$DESTDIR" STAGEDIR="$STAGEDIR" CFLAGS="$CFLAGS" install)
+(cd usr.lib/libvmf && make clean && make DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install)
+(cd bin/ld && make clean && make SEPFLAG= DESTDIR="$DESTDIR" STAGEDIR="$STAGEDIR" CFLAGS="$CFLAGS" LDFLAGS="-L$DESTDIR/usr/lib" install)
+(cd bin/nm && make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install)
+(cd lib/c2 && make clean && make SEPFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install)
+(cd lib/ccom && make clean && make LDC0FLAGS= LDC1FLAGS= PURFLAG= DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install)
+(cd lib/cpp && make clean && make SEPFLAG= DESTDIR="$DESTDIR" STAGEDIR="$STAGEDIR" CFLAGS="$CFLAGS" install)
index 139e838..ab9e894 100644 (file)
@@ -8,26 +8,40 @@
 
 #ifndef _EXEC_
 #define _EXEC_
+
+#ifdef pdp11
+#define int16_t int
+#define uint16_t unsigned int
+#else
+/* assume cross compiling so take pdp-11 sizes for granted */
+#include <stdint.h>
+#endif
+
 /*
  * Header prepended to each a.out file.
  */
 struct exec {
-       int     a_magic;        /* magic number */
-unsigned int   a_text;         /* size of text segment */
-unsigned int   a_data;         /* size of initialized data */
-unsigned int   a_bss;          /* size of uninitialized data */
-unsigned int   a_syms;         /* size of symbol table */
-unsigned int   a_entry;        /* entry point */
-unsigned int   a_unused;       /* not used */
-unsigned int   a_flag;         /* relocation info stripped */
+       int16_t a_magic;        /* magic number */
+       uint16_t a_text;        /* size of text segment */
+       uint16_t a_data;        /* size of initialized data */
+       uint16_t a_bss;         /* size of uninitialized data */
+       uint16_t a_syms;        /* size of symbol table */
+       uint16_t a_entry;       /* entry point */
+       uint16_t a_unused;      /* not used */
+       uint16_t a_flag;        /* relocation info stripped */
 };
 
 #define        NOVL    15              /* number of overlays */
 struct ovlhdr {
-       int     max_ovl;        /* maximum overlay size */
-unsigned int   ov_siz[NOVL];   /* size of i'th overlay */
+       int16_t max_ovl;        /* maximum overlay size */
+       uint16_t ov_siz[NOVL];  /* size of i'th overlay */
 };
 
+#ifdef pdp11
+#undef int16_t
+#undef uint16_t
+#endif
+
 /*
  * eXtended header definition for use with the new macros in a.out.h
 */
diff --git a/usr.lib/libvmf/include/vmf.h b/usr.lib/libvmf/include/vmf.h
new file mode 120000 (symlink)
index 0000000..9594a15
--- /dev/null
@@ -0,0 +1 @@
+../../../include/vmf.h
\ No newline at end of file
index 72eb6eb..8e6ef73 100644 (file)
@@ -1,34 +1,33 @@
+CPPFLAGS=-Iinclude
 OBJECTS = vmf.o
 
 all:  genlib genlib_p vmf.0
 
 CFLAGS = -O
 
-all:   genlib genlib_p
-
 vmf.0: vmf.3
        nroff -man vmf.3 > vmf.0
 
-install:
-       install -c -m 644 genlib /usr/lib/libvmf.a
-       ranlib /usr/lib/libvmf.a
-       install -c -m 644 genlib_p /usr/lib/libvmf_p.a
-       ranlib /usr/lib/libvmf_p.a
-       install -c -m 444 vmf.0 /usr/man/cat3/vmf.0
+install: all
+       install -c -m 644 genlib ${DESTDIR}/usr/lib/libvmf.a
+       ranlib ${DESTDIR}/usr/lib/libvmf.a
+       install -c -m 644 genlib_p ${DESTDIR}/usr/lib/libvmf_p.a
+       ranlib ${DESTDIR}/usr/lib/libvmf_p.a
+       install -c -m 444 vmf.0 ${DESTDIR}/usr/man/cat3/vmf.0
 
 clean:
        rm -f ${OBJECTS} profiled/${OBJECTS} genlib genlib_p vmf.0
 
 .c.o:
-       ${CC} -p ${CFLAGS} -c $*.c
-       -ld -X -r $*.o
+       ${CC} -p ${CPPFLAGS} ${CFLAGS} -c $*.c
+       -${LD} -X -r $*.o
        mv a.out profiled/$*.o
-       ${CC} ${CFLAGS} -c $*.c
-       -ld -X -r $*.o
+       ${CC} ${CPPFLAGS} ${CFLAGS} -c $*.c
+       -${LD} -X -r $*.o
        mv a.out $*.o
 
 genlib genlib_p: ${OBJECTS}
        @echo "building profiled genlib"
-       @cd profiled; ar cru ../genlib_p ${OBJECTS}
+       @cd profiled; ${AR} cru ../genlib_p ${OBJECTS}
        @echo "buiding normal genlib"
-       @ar cru genlib ${OBJECTS}
+       @${AR} cru genlib ${OBJECTS}
diff --git a/usr.lib/libvmf/n.sh b/usr.lib/libvmf/n.sh
new file mode 100755 (executable)
index 0000000..16a5bc6
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+ROOT="`pwd |sed -e 's/\/usr\.lib\/libvmf$//'`"
+DESTDIR="$ROOT/host"
+CFLAGS="-Wall -Wno-char-subscripts -Wno-format -Wno-parentheses"
+mkdir --parents "$DESTDIR/usr/lib"
+mkdir --parents "$DESTDIR/usr/man/cat3"
+make clean && make DESTDIR="$DESTDIR" CFLAGS="$CFLAGS" install
index fae4b6f..6b490b6 100644 (file)
 #include <vmf.h>
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/file.h>
+#include <unistd.h>
+
 
 /*
  * Choose ONE and only one of the following swap policies
  */
-/* #define LRU                  /* Least Recently Used */
-/* #define PERC 3               /* Percolation */
+/* #define LRU                  Least Recently Used */
+/* #define PERC 3               Percolation */
 #define LRS                     /* Least Recently Swapped */
 
 #ifndef DEBUG
 #define debugseg(s,m)           /* do nothing */
 #else
-static void debugseg();
+static void debugseg PARAMS((register struct vseg *s, char *msg));
 #endif
 
 /*
- * This is vfm.c, the file of virtual memory management primitives.
+ * This is vmf.c, the file of virtual memory management primitives.
  * Call vminit first to get the in memory segments set up.
  * Then call vmopen for each virtual space to be used.
  * Normal transactions against segments are handled via vmmapseg.
@@ -42,20 +46,18 @@ static void debugseg();
 
 #define NOSEGNO (-1)            /* can never match a segment number */
 
-       static  struct dlink seghead[1];
-       long    nswaps, nmapsegs;      /* statistics */
-       extern  int     read(), write(), errno;
-       static  int     swap();
-       static  void    promote(), vmerror();
+static struct dlink seghead[1];
+long nswaps, nmapsegs;      /* statistics */
+
+static int swap PARAMS((register struct vseg *seg, ssize_t (*iofunc)(int fd, const void *buf, size_t size)));
+static void promote PARAMS((register struct vseg *s));
+static void vmerror PARAMS((char *msg));
 
 /*
  * vminit --- initialize virtual memory system with 'n' in-memory segments
  */
 
-int
-vminit(n)
-       int     n;
-       {
+int vminit(n) int n; {
        register struct vseg *s;
         static struct vseg *segs;
 
@@ -78,17 +80,13 @@ vminit(n)
                s->s_flags = 0;                 /* not DIRTY */
                }
        return(0);
-       }
+}
 
 /*
  * vmmapseg --- convert segment number to real memory address
  */
 
-struct vseg *
-vmmapseg(vspace, segno)
-       struct  vspace *vspace;
-       u_short segno;
-       {
+struct vseg *vmmapseg(vspace, segno) struct vspace *vspace; int segno; {
        register struct vseg *s;
 
        nmapsegs++;
@@ -129,7 +127,7 @@ vmmapseg(vspace, segno)
                        s->s_vspace = vspace;
                        s->s_segno = segno;
                        s->s_flags &= ~S_DIRTY;
-                       status = swap(s, read);
+                       status = swap(s, (ssize_t (*) PARAMS((int fd, const void *buf, size_t size)))read);
                        if      (status == -2)
                                {
                                fprintf(stderr, "can't read swap file");
@@ -166,18 +164,14 @@ vmmapseg(vspace, segno)
 #endif
        debugseg(s, "vmmapseg returns");
        return(s);
-       }
+}
 
 /*
  * swap --- swap a segment in or out
  *      (called only from this file)
  */
 
-static int
-swap(seg, iofunc)           /* used only from this file */
-       register struct vseg *seg;
-       int (*iofunc)();
-       {
+static int swap(seg, iofunc) register struct vseg *seg; ssize_t (*iofunc) PARAMS((int fd, const void *buf, size_t size)); {
        off_t file_address;
        register struct vspace *v;
 
@@ -188,7 +182,7 @@ swap(seg, iofunc)           /* used only from this file */
        file_address += v->v_foffset;
 #ifdef SWAPTRACE
        printf("fd%d blk%d\tswap %s\n", v->v_fd, file_address,
-               iofunc == read ? "in" : "out");
+               iofunc == (ssize_t (*) PARAMS((int fd, const void *buf, size_t size)))read ? "in" : "out");
 #endif
        if      (lseek(v->v_fd, file_address, L_SET) == -1L)
                return(-2);
@@ -199,99 +193,74 @@ swap(seg, iofunc)           /* used only from this file */
                        return(0);
                case 0:
                        return(-1);
-               default:
-                       return(-2);
+               /*default:
+                       return(-2);*/
                }
-       }
-
-void
-vmclrseg(seg)
-       register struct vseg *seg;
-       {
+       return(-2); /* keep compiler happy */
+}
 
+void vmclrseg(seg) register struct vseg *seg; {
        (void)bzero(seg->s_cinfo, BYTESPERSEG);
        vmmodify(seg);
-       }
+}
 
 /*
  * vmlock --- vmlock a segment into real memory
  */
 
-void
-vmlock(seg)
-       register struct vseg *seg;
-       {
-
+void vmlock(seg) register struct vseg *seg; {
        seg->s_lock_count++;
        if      (seg->s_lock_count < 0)
                vmerror("vmlock: overflow");
-       }
+}
 
 /*
  * vmunlock --- unlock a segment
  */
 
-void
-vmunlock(seg)
-       register struct vseg *seg;
-       {
-
+void vmunlock(seg) register struct vseg *seg; {
         --seg->s_lock_count;
        if      (seg->s_lock_count < 0)
                vmerror("vmlock: underflow");
-       }
+}
 
 /*
  * vmmodify --- declare a segment to have been modified
  */
 
-void
-vmmodify(seg)
-register struct vseg *seg;
-       {
-
+void vmmodify(seg) register struct vseg *seg; {
        VMMODIFY(seg);
        debugseg(seg, "vmmodify");
-       }
+}
 
 /*
  * vmflush --- flush out virtual space buffers
  */
 
-void
-vmflush()
-       {
+void vmflush() {
        register struct vseg *s;
 
        for     (s = (struct vseg *)seghead[0].fwd; s != (struct vseg *)seghead;
                 s = (struct vseg *)s->s_link.fwd)
                if      (s->s_flags & S_DIRTY)
                        swap(s, write);
-       }
+}
 
 /*
  * debugseg --- output debugging information about a seg in mem
  */
 #ifdef DEBUG
-static void
-debugseg(s, msg)
-       char    *msg;
-       register struct vseg *s;
-       {
+static void debugseg(s, msg) register struct vseg *s; char *msg; {
        fprintf(stderr, "seg%o vspace%o segno%d flags%o vmlock%d %s\r\n",
                s, s->s_vspace, s->s_segno, s->s_flags, s->s_lock_count, msg);
-       }
+}
 #endif
 
 /*
  * vmopen --- open a virtual space associated with a file
  */
 
-int
-vmopen(vs, filename)
-       register struct vspace *vs;
-       char *filename;
-       {
+int vmopen(vs, filename) register struct vspace *vs; char *filename; {
        register int    fd;
        char    junk[32];
 
@@ -311,17 +280,14 @@ vmopen(vs, filename)
                vs->v_maxsegno = MAXSEGNO;
                }
        return(fd);
-       }
+}
 
 /*
  * vmclose --- closes a virtual space associated with a file
  * invalidates all segments associated with that file
  */
 
-void
-vmclose(vs)
-       register struct vspace *vs;
-       {
+void vmclose(vs) register struct vspace *vs; {
        register struct vseg *s;
 
        vmflush();
@@ -338,24 +304,20 @@ vmclose(vs)
                        }
                }
        close(vs->v_fd);
-       }
+}
 
 /*
  * promote --- put a segment at the top of the list
  */
 
-static void
-promote(s)
-       register struct vseg *s;
-       {
-
+static void promote(s) register struct vseg *s; {
         s->s_link.fwd->back = s->s_link.back;         /* delete */
        s->s_link.back->fwd = s->s_link.fwd;
 
        s->s_link.fwd = seghead[0].fwd;   /* insert at top of totem pole */
        s->s_link.back = seghead;
        seghead[0].fwd = s->s_link.fwd->back = (struct dlink *)s;
-       }
+}
 
 /*
  * vmerror --- print error message and commit suicide
@@ -363,10 +325,7 @@ promote(s)
  *     Example:        vmerror("In floogle: can't happen!");
  */
 
-static void
-vmerror(msg)
-       char *msg;
-       {
+static void vmerror(msg) char *msg; {
        fprintf(stderr, "%s\n", msg);
        abort();        /* terminate process with core dump */
-       }
+}