merge in hp300 support from Utah
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Wed, 9 May 1990 13:46:14 +0000 (05:46 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Wed, 9 May 1990 13:46:14 +0000 (05:46 -0800)
SCCS-vsn: sys/deprecated/netrmp/rmp.h 7.1
SCCS-vsn: sys/deprecated/netrmp/rmp_var.h 7.1
SCCS-vsn: sys/deprecated/netrmp/rmp.c 7.1
SCCS-vsn: sys/deprecated/netrmp/rmp_proto.c 7.1
SCCS-vsn: sys/hp/hpux/hpux.h 7.1
SCCS-vsn: sys/hp/hpux/hpux_exec.h 7.1
SCCS-vsn: sys/hp/hpux/hpux_termio.h 7.1
SCCS-vsn: sys/hp/hpux/hpux_compat.c 7.1
SCCS-vsn: sys/hp/hpux/hpux_net.c 7.1
SCCS-vsn: sys/hp/hpux/hpux_sig.c 7.1
SCCS-vsn: sys/hp/hpux/hpux_tty.c 7.1
SCCS-vsn: sys/hp300/stand/hpibvar.h 7.1
SCCS-vsn: sys/hp300/stand/rominfo.h 7.1
SCCS-vsn: sys/hp300/stand/saio.h 7.1
SCCS-vsn: sys/hp300/stand/samachdep.h 7.1
SCCS-vsn: sys/hp300/stand/volhdr.h 7.1
SCCS-vsn: sys/hp300/stand/autoconf.c 7.1
SCCS-vsn: sys/hp300/stand/boot.c 7.1
SCCS-vsn: sys/hp300/stand/conf.c 7.1
SCCS-vsn: sys/hp300/stand/cons.c 7.1
SCCS-vsn: sys/hp300/stand/copy.c 7.1
SCCS-vsn: sys/hp300/stand/ct.c 7.1
SCCS-vsn: sys/hp300/stand/dca.c 7.1
SCCS-vsn: sys/hp300/stand/fhpib.c 7.1
SCCS-vsn: sys/hp300/stand/hil.c 7.1
SCCS-vsn: sys/hp300/stand/hpib.c 7.1
SCCS-vsn: sys/hp300/stand/installboot.c 7.1
SCCS-vsn: sys/hp300/stand/ite.c 7.1
SCCS-vsn: sys/hp300/stand/ite_dv.c 7.1
SCCS-vsn: sys/hp300/stand/ite_gb.c 7.1
SCCS-vsn: sys/hp300/stand/ite_rb.c 7.1
SCCS-vsn: sys/hp300/stand/ite_subr.c 7.1
SCCS-vsn: sys/hp300/stand/ite_tc.c 7.1
SCCS-vsn: sys/hp300/stand/machdep.c 7.1
SCCS-vsn: sys/hp300/stand/mkboot.c 7.1
SCCS-vsn: sys/hp300/stand/nhpib.c 7.1
SCCS-vsn: sys/hp300/stand/prf.c 7.1
SCCS-vsn: sys/hp300/stand/rd.c 7.1
SCCS-vsn: sys/hp300/stand/scsi.c 7.1
SCCS-vsn: sys/hp300/stand/sd.c 7.1
SCCS-vsn: sys/hp300/stand/srt0.c 7.1
SCCS-vsn: sys/hp300/stand/sys.c 7.1

42 files changed:
usr/src/sys/deprecated/netrmp/rmp.c [new file with mode: 0644]
usr/src/sys/deprecated/netrmp/rmp.h [new file with mode: 0644]
usr/src/sys/deprecated/netrmp/rmp_proto.c [new file with mode: 0644]
usr/src/sys/deprecated/netrmp/rmp_var.h [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux.h [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux_compat.c [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux_exec.h [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux_net.c [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux_sig.c [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux_termio.h [new file with mode: 0644]
usr/src/sys/hp/hpux/hpux_tty.c [new file with mode: 0644]
usr/src/sys/hp300/stand/autoconf.c [new file with mode: 0644]
usr/src/sys/hp300/stand/boot.c [new file with mode: 0644]
usr/src/sys/hp300/stand/conf.c [new file with mode: 0644]
usr/src/sys/hp300/stand/cons.c [new file with mode: 0644]
usr/src/sys/hp300/stand/copy.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ct.c [new file with mode: 0644]
usr/src/sys/hp300/stand/dca.c [new file with mode: 0644]
usr/src/sys/hp300/stand/fhpib.c [new file with mode: 0644]
usr/src/sys/hp300/stand/hil.c [new file with mode: 0644]
usr/src/sys/hp300/stand/hpib.c [new file with mode: 0644]
usr/src/sys/hp300/stand/hpibvar.h [new file with mode: 0644]
usr/src/sys/hp300/stand/installboot.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ite.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ite_dv.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ite_gb.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ite_rb.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ite_subr.c [new file with mode: 0644]
usr/src/sys/hp300/stand/ite_tc.c [new file with mode: 0644]
usr/src/sys/hp300/stand/machdep.c [new file with mode: 0644]
usr/src/sys/hp300/stand/mkboot.c [new file with mode: 0644]
usr/src/sys/hp300/stand/nhpib.c [new file with mode: 0644]
usr/src/sys/hp300/stand/prf.c [new file with mode: 0644]
usr/src/sys/hp300/stand/rd.c [new file with mode: 0644]
usr/src/sys/hp300/stand/rominfo.h [new file with mode: 0644]
usr/src/sys/hp300/stand/saio.h [new file with mode: 0644]
usr/src/sys/hp300/stand/samachdep.h [new file with mode: 0644]
usr/src/sys/hp300/stand/scsi.c [new file with mode: 0644]
usr/src/sys/hp300/stand/sd.c [new file with mode: 0644]
usr/src/sys/hp300/stand/srt0.c [new file with mode: 0644]
usr/src/sys/hp300/stand/sys.c [new file with mode: 0644]
usr/src/sys/hp300/stand/volhdr.h [new file with mode: 0644]

diff --git a/usr/src/sys/deprecated/netrmp/rmp.c b/usr/src/sys/deprecated/netrmp/rmp.c
new file mode 100644 (file)
index 0000000..27f48ac
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: rmp.c 1.3 89/06/07$
+ *
+ *     @(#)rmp.c       7.1 (Berkeley) %G%
+ */
+
+#include "param.h"
+#include "mbuf.h"
+#include "socket.h"
+#include "socketvar.h"
+
+#include "../net/if.h"
+#include "../net/route.h"
+#include "../net/raw_cb.h"
+
+#include "../netrmp/rmp.h"
+#include "../netrmp/rmp_var.h"
+
+/*
+**  rmp_output: route packet to proper network interface.
+*/
+
+rmp_output(m, so)
+struct mbuf *m;
+struct socket *so;
+{
+       struct ifnet *ifp;
+       struct rawcb *rp = sotorawcb(so);
+       struct rmp_packet *rmp;
+
+       /*
+        *  Convert the mbuf back to an RMP packet so we can get the
+        *  address of the "ifnet struct" specifying the interface it
+        *  should go out on.
+        */
+       rmp = mtod(m, struct rmp_packet *);
+       ifp = rmp->ifp;
+
+       /*
+        *  Strip off the "ifnet struct ptr" from the packet leaving
+        *  us with a complete IEEE 802.2 packet.
+        */
+       m_adj(m, sizeof(struct ifnet *));
+
+       /*
+        *  Send the packet.
+        */
+       return ((*ifp->if_output) (ifp, m, &rp->rcb_faddr));
+}
diff --git a/usr/src/sys/deprecated/netrmp/rmp.h b/usr/src/sys/deprecated/netrmp/rmp.h
new file mode 100644 (file)
index 0000000..26ebf18
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: rmp.h 1.3 89/06/07$
+ *
+ *     @(#)rmp.h       7.1 (Berkeley) %G%
+ */
+
+/*
+ *  Define MIN/MAX sizes of RMP (ethernet) packet.  For ease of computation,
+ *  the 4 octet CRC field is not included.
+ */
+
+#define        RMP_MAX_PACKET  1514
+#define        RMP_MIN_PACKET  60
+
+
+/*
+ *  Define IEEE802.2 (Logical Link Control) information.
+ */
+
+#define        ETHERTYPE_IEEE  0       /* hack hack hack */
+
+#define        IEEE802LEN_MIN  40
+#define IEEE802LEN_MAX 1500
+
+#define        IEEE_DSAP_HP    0xF8    /* Destination Service Access Point */
+#define        IEEE_SSAP_HP    0xF8    /* Source Service Access Point */
+#define        IEEE_CNTL_HP    0x0300  /* Type 1 / I format control information */
+
+#define        HPEXT_DXSAP     0x608   /* HP Destination Service Access Point */
+#define        HPEXT_SXSAP     0x609   /* HP Source Service Access Point */
+
+/*
+ * HP uses 802.2 LLC with their own local extensions.  This struct makes
+ * sence out of this data (encapsulated in the 802.3 packet).
+ */
+
+struct hp_llc {
+       u_char  dsap;           /* 802.2 DSAP */
+       u_char  ssap;           /* 802.2 SSAP */
+       u_short cntrl;          /* 802.2 control field */
+       u_short filler;         /* HP filler (must be zero) */
+       u_short dxsap;          /* HP extended DSAP */
+       u_short sxsap;          /* HP extended SSAP */
+};
+
+
+/*
+ * Protocol(s)
+ */
+
+#define RMPPROTO_BOOT  1               /* RMP boot protocol */
+
+#if    defined(KERNEL) & defined(RMP)
+extern struct  domain rmpdomain;
+extern struct  protosw rmpsw[];
+#endif
diff --git a/usr/src/sys/deprecated/netrmp/rmp_proto.c b/usr/src/sys/deprecated/netrmp/rmp_proto.c
new file mode 100644 (file)
index 0000000..18f3f08
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: rmp_proto.c 1.3 89/06/07$
+ *
+ *     @(#)rmp_proto.c 7.1 (Berkeley) %G%
+ */
+
+#include "param.h"
+#include "socket.h"
+#include "protosw.h"
+#include "domain.h"
+
+#include "rmp.h"
+
+#ifdef RMP
+/*
+ * HP Remote Maintenance Protocol (RMP) family: BOOT
+ */
+
+extern struct domain   rmpdomain;
+extern int             raw_usrreq(), rmp_output();
+
+struct protosw rmpsw[] = {
+  {    SOCK_RAW,       &rmpdomain,     RMPPROTO_BOOT,  PR_ATOMIC|PR_ADDR,
+       0,              rmp_output,     0,              0,
+       raw_usrreq,
+       0,              0,              0,              0,
+  },
+};
+
+struct domain rmpdomain = {
+       AF_RMP, "RMP", 0, 0, 0, rmpsw, &rmpsw[sizeof(rmpsw)/sizeof(rmpsw[0])]
+};
+
+#endif
diff --git a/usr/src/sys/deprecated/netrmp/rmp_var.h b/usr/src/sys/deprecated/netrmp/rmp_var.h
new file mode 100644 (file)
index 0000000..d84788e
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: rmp_var.h 1.3 89/06/07$
+ *
+ *     @(#)rmp_var.h   7.1 (Berkeley) %G%
+ */
+
+/*
+ *  WARNING: rmp_packet is defined assuming alignment on 16-bit boundaries.
+ *  Data will be contiguous on HP's (MC68000), but there may be holes if
+ *  this is used elsewhere (e.g. VAXen).  Or, in other words:
+ *
+ *  if (sizeof(struct rmp_packet) != 1504) error("AlignmentProblem");
+ */
+
+/*
+ *  Possible values for "rmp_type" fields.
+ */
+
+#define        RMP_BOOT_REQ    1       /* boot request packet */
+#define        RMP_BOOT_REPL   129     /* boot reply packet */
+#define        RMP_READ_REQ    2       /* read request packet */
+#define        RMP_READ_REPL   130     /* read reply packet */
+#define        RMP_BOOT_DONE   3       /* boot complete packet */
+
+/*
+ *  Useful constants.
+ */
+
+#define RMP_VERSION    2       /* protocol version */
+#define RMP_TIMEOUT    600     /* timeout connection after ten minutes */
+#define        RMP_PROBESID    0xffff  /* session ID for probes */
+#define        RMP_HOSTLEN     13      /* max length of server's name */
+
+/*
+ *  RMP error codes
+ */
+
+#define        RMP_E_OKAY      0
+#define        RMP_E_EOF       2       /* read reply: returned end of file */
+#define        RMP_E_ABORT     3       /* abort operation */
+#define        RMP_E_BUSY      4       /* boot reply: server busy */
+#define        RMP_E_TIMEOUT   5       /* lengthen time out (not implemented) */
+#define        RMP_E_NOFILE    16      /* boot reply: file does not exist */
+#define RMP_E_OPENFILE 17      /* boot reply: file open failed */
+#define        RMP_E_NODFLT    18      /* boot reply: default file does not exist */
+#define RMP_E_OPENDFLT 19      /* boot reply: default file open failed */
+#define        RMP_E_BADSID    25      /* read reply: bad session ID */
+#define RMP_E_BADPACKET        27      /* Bad packet detected */
+
+/*
+ *  Assorted field sizes.
+ */
+
+#define        RMPADDRLEN      6       /* size of ethernet address */
+#define RMPLENGTHLEN   2       /* size of ethernet length field (802.3) */
+#define        RMPMACHLEN      20      /* length of machine type field */
+
+/*
+ *  RMPDATALEN is the maximum number of data octets that can be stuffed
+ *  into an RMP packet.  This excludes the 802.2 LLC w/HP extensions.
+ */
+
+#define RMPDATALEN     (RMP_MAX_PACKET - (2*RMPADDRLEN + RMPLENGTHLEN + \
+                                          sizeof(struct hp_llc)) )
+
+/*
+ *  Define sizes of packets we send.  Boot and Read replies are variable
+ *  in length depending on the length of `s'.
+ *
+ *  Also, define how much space `restofpkt' can take up for outgoing
+ *  Boot and Read replies.  Boot Request packets are effectively
+ *  limited to 255 bytes due to the preceding 1-byte length field.
+ */
+
+#define        RMPBOOTSIZE(s)  (sizeof(struct hp_llc) + sizeof(struct ifnet *) + \
+                        sizeof(struct rmp_boot_repl) + s - \
+                        sizeof(restofpkt))
+#define        RMPREADSIZE(s)  (sizeof(struct hp_llc) + sizeof(struct ifnet *) + \
+                        sizeof(struct rmp_read_repl) + s - \
+                        sizeof(restofpkt) - sizeof(u_char))
+#define        RMPDONESIZE     (sizeof(struct hp_llc) + sizeof(struct ifnet *) + \
+                        sizeof(struct rmp_boot_done))
+#define        RMPBOOTDATA     255
+#define        RMPREADDATA     (RMPDATALEN - \
+                        (2*sizeof(u_char)+sizeof(u_short)+sizeof(u_long)))
+
+
+/*
+ * This protocol defines some field sizes as "rest of ethernet packet".
+ * There is no easy way to specify this in C, so we use a one character
+ * field to denote it, and index past it to the end of the packet.
+ */
+
+typedef char   restofpkt;
+
+/*
+ * Packet structures.
+ */
+
+struct rmp_raw {
+       u_char  rmp_type;               /* packet type */
+       u_char  rmp_rawdata[RMPDATALEN-1];
+};
+
+struct rmp_boot_req {          /* boot request */
+       u_char  rmp_type;               /* packet type (RMP_BOOT_REQ) */
+       u_char  rmp_retcode;            /* return code (0) */
+       u_long  rmp_seqno;              /* sequence number (real time clock) */
+       u_short rmp_session;            /* session id (normally 0) */
+       u_short rmp_version;            /* protocol version (RMP_VERSION) */
+       char    rmp_machtype[RMPMACHLEN];       /* machine type */
+       u_char  rmp_flnmsize;           /* length of rmp_flnm */
+       restofpkt rmp_flnm;             /* name of file to be read */
+};
+
+struct rmp_boot_repl {         /* boot reply */
+       u_char  rmp_type;               /* packet type (RMP_BOOT_REPL) */
+       u_char  rmp_retcode;            /* return code (normally 0) */
+       u_long  rmp_seqno;              /* sequence number (from boot req) */
+       u_short rmp_session;            /* session id (generated) */
+       u_short rmp_version;            /* protocol version (RMP_VERSION) */
+       u_char  rmp_flnmsize;           /* length of rmp_flnm */
+       restofpkt rmp_flnm;             /* name of file (from boot req) */
+};
+
+struct rmp_read_req {          /* read request */
+       u_char  rmp_type;               /* packet type (RMP_READ_REQ) */
+       u_char  rmp_retcode;            /* return code (0) */
+       u_long  rmp_offset;             /* file relative byte offset */
+       u_short rmp_session;            /* session id (from boot repl) */
+       u_short rmp_size;               /* max no of bytes to send */
+};
+
+struct rmp_read_repl {         /* read reply */
+       u_char  rmp_type;               /* packet type (RMP_READ_REPL) */
+       u_char  rmp_retcode;            /* return code (normally 0) */
+       u_long  rmp_offset;             /* byte offset (from read req) */
+       u_short rmp_session;            /* session id (from read req) */
+       restofpkt rmp_data;             /* data (max size from read req) */
+       u_char  rmp_unused;             /* padding to 16-bit boundary */
+};
+
+struct rmp_boot_done {         /* boot complete */
+       u_char  rmp_type;               /* packet type (RMP_BOOT_DONE) */
+       u_char  rmp_retcode;            /* return code (0) */
+       u_long  rmp_unused;             /* not used (0) */
+       u_short rmp_session;            /* session id (from read repl) */
+};
+
+struct rmp_packet {
+       struct ifnet *ifp;      /* ptr to intf packet arrived on */
+       struct hp_llc hp_llc;
+       union {
+               struct rmp_boot_req     rmp_brq;        /* boot request */
+               struct rmp_boot_repl    rmp_brpl;       /* boot reply */
+               struct rmp_read_req     rmp_rrq;        /* read request */
+               struct rmp_read_repl    rmp_rrpl;       /* read reply */
+               struct rmp_boot_done    rmp_done;       /* boot complete */
+               struct rmp_raw          rmp_raw;        /* raw data */
+       } rmp_proto;
+};
+
+/*
+ *  Make life easier...
+ */
+
+#define        r_type  rmp_proto.rmp_raw.rmp_type
+#define        r_data  rmp_proto.rmp_raw.rmp_data
+#define        r_brq   rmp_proto.rmp_brq
+#define        r_brpl  rmp_proto.rmp_brpl
+#define        r_rrq   rmp_proto.rmp_rrq
+#define        r_rrpl  rmp_proto.rmp_rrpl
+#define        r_done  rmp_proto.rmp_done
+
+/*
+ *  RMP socket address: just family & destination addr.
+ */
+
+struct sockaddr_rmp {
+       short   srmp_family;            /* address family (AF_RMP) */
+       u_char  srmp_dhost[RMPADDRLEN]; /* ethernet destination addr */
+};
diff --git a/usr/src/sys/hp/hpux/hpux.h b/usr/src/sys/hp/hpux/hpux.h
new file mode 100644 (file)
index 0000000..2b38f36
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux.h 1.15 89/09/25$
+ *
+ *     @(#)hpux.h      7.1 (Berkeley) %G%
+ */
+
+#include "hpux_exec.h"
+
+/* HP-UX style UTSNAME struct used by uname syscall */
+
+struct hpuxutsname {
+       char    sysname[9];
+       char    nodename[9];
+       char    release[9];
+       char    version[9];
+       char    machine[9];
+       char    idnumber[15];
+};
+
+/* HP-UX style "old" IOCTLs */
+
+struct hpuxsgttyb {
+       char    sg_ispeed;
+       char    sg_ospeed;
+       char    sg_erase;
+       char    sg_kill;
+       int     sg_flags;       /* only a short in BSD */
+};
+
+#define V7_HUPCL       00001
+#define V7_XTABS       00002
+#define V7_NOAL                04000
+
+#define        HPUXTIOCGETP    _IOR('t', 8, struct hpuxsgttyb)
+#define        HPUXTIOCSETP    _IOW('t', 9, struct hpuxsgttyb)
+
+/* 6.5 job control related ioctls which need to be mapped */
+
+#define        HPUXTIOCSLTC    _IOW('T', 23, struct ltchars)
+#define        HPUXTIOCGLTC    _IOR('T', 24, struct ltchars)
+#define        HPUXTIOCLBIS    _IOW('T', 25, int)
+#define        HPUXTIOCLBIC    _IOW('T', 26, int)
+#define        HPUXTIOCLSET    _IOW('T', 27, int)
+#define        HPUXTIOCLGET    _IOR('T', 28, int)
+#      define HPUXLTOSTOP      0000001
+#define        HPUXTIOCSPGRP   _IOW('T', 29, int)
+#define        HPUXTIOCGPGRP   _IOR('T', 30, int)
+#define HPUXTIOCCONS   _IO('t', 104)
+
+/* HP-UX directory stuff */
+
+#define HPUXNSIZ       14
+#define HPUXPSIZ       10
+#define HPUXDSIZ       sizeof(struct hpuxdirect)
+
+struct hpuxdirect {
+       u_long  hpuxd_ino;
+       u_short hpuxd_reclen;
+       u_short hpuxd_namlen;
+       char    hpuxd_name[HPUXNSIZ];
+       char    hpuxd_pad[HPUXPSIZ];
+};
+
+/* HP-UX stat structure */
+
+#define bsdtohpuxdev(d)        ((major(d) << 24) | minor(d))
+
+struct hpuxstat {
+       long    hst_dev;
+       u_long  hst_ino;
+       u_short hst_mode;
+       short   hst_nlink;
+       u_short hst_uid;
+       u_short hst_gid;
+       long    hst_rdev;
+       off_t   hst_size;
+       time_t  hst_atime;
+       int     hst_spare1;
+       time_t  hst_mtime;
+       int     hst_spare2;
+       time_t  hst_ctime;
+       int     hst_spare3;
+       long    hst_blksize;
+       long    hst_blocks;
+       u_int   hst_remote;
+       long    hst_netdev;     
+       u_long  hst_netino;
+       long    hst_spare4[9];
+};
+
+/*
+ * Skeletal 6.X HP-UX user structure info for ptrace() mapping.
+ * Yes, this is as bogus as it gets...
+ */
+
+/* 6.0/6.2 offsets */
+#define oHU_AROFF      0x004
+#define oHU_TSOFF      0x092
+#define oHU_EDOFF      0x91E
+#define oHU_FPOFF      0xA66
+
+/* 6.5 offsets */
+#define HU_AROFF       0x004
+#define HU_TSOFF       0x0B2
+#define HU_EDOFF       0x93A
+#define HU_FPOFF       0xA86
+
+#define HU_PAD1        (HU_AROFF)
+#define HU_PAD2        (HU_TSOFF-HU_AROFF-4)
+#define HU_PAD3        (HU_EDOFF-HU_TSOFF-12)
+#define HU_PAD4        (HU_FPOFF-HU_EDOFF-sizeof(struct hpux_exec))
+
+struct hpuxuser {
+       u_char  whocares1[HU_PAD1];     /* +0x000 */
+       int     *hpuxu_ar0;             /* +0x004 */
+       u_char  whocares2[HU_PAD2];     /* +0x008 */
+       int     hpuxu_tsize;            /* +0x0B2 */
+       int     hpuxu_dsize;            /* +0x0B6 */
+       int     hpuxu_ssize;            /* +0x0BA */
+       u_char  whocares3[HU_PAD3];     /* +0x0BE */
+       struct  hpux_exec hpuxu_exdata; /* +0x93A */
+       u_char  whocares4[HU_PAD4];     /* +0x95E */
+       struct  hpuxfp {                /* +0xA66 */
+               int hpfp_save[54];
+               int hpfp_ctrl[3];
+               int hpfp_reg[24];
+       } hpuxu_fp;
+       short   hpuxu_dragon;           /* +0xBCA */
+};
+
+/* HP-UX compat file flags */
+#define HPUXFCREAT     00000400
+#define        HPUXFTRUNC      00001000
+#define        HPUXFEXCL       00002000
+#define HPUXFSYNCIO    00100000
+#define HPUXFREMOTE    01000000
+#define FUSECACHE      04000000
+
+/* HP-UX only sysV shmctl() commands */
+#define SHM_LOCK       3       /* Lock segment in core */
+#define SHM_UNLOCK     4       /* Unlock segment */
+
+/* HP-UX rtprio values */
+#define RTPRIO_MIN     0
+#define RTPRIO_MAX     127
+#define RTPRIO_NOCHG   1000
+#define RTPRIO_RTOFF   1001
+
+/* HP-UX only sigvec sv_flags values */
+#define HPUXSV_RESET   000000004
+
+/*
+ * HP-UX returns SIGILL instead of SIGFPE for the CHK and TRAPV exceptions.
+ * It also returns different u_code values for certain illegal instruction
+ * and floating point exceptions.  Here are the proper HP-UX u_code values
+ * (numbers from hpux 6.2 manual pages).
+ */
+
+/* SIGILL codes */
+#define        HPUX_ILL_ILLINST_TRAP   0       /* T_ILLINST+USER */
+#define        HPUX_ILL_CHK_TRAP       6       /* T_CHKINST+USER */
+#define        HPUX_ILL_TRAPV_TRAP     7       /* T_TRAPVINST+USER */
+#define        HPUX_ILL_PRIV_TRAP      8       /* T_PRIVINST+USER */
+
+/* SIGFPE codes */
+#define        HPUX_FPE_INTDIV_TRAP    5       /* T_ZERODIV+USER */
diff --git a/usr/src/sys/hp/hpux/hpux_compat.c b/usr/src/sys/hp/hpux/hpux_compat.c
new file mode 100644 (file)
index 0000000..923ce1b
--- /dev/null
@@ -0,0 +1,1409 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux_compat.c 1.33 89/08/23$
+ *
+ *     @(#)hpux_compat.c       7.1 (Berkeley) %G%
+ */
+
+/*
+ * Various HPUX compatibility routines
+ */
+
+#ifdef HPUXCOMPAT
+
+#include "param.h"
+#include "systm.h"
+#include "syscontext.h"
+#include "kernel.h"
+#include "proc.h"
+#include "buf.h"
+#include "wait.h"
+#include "file.h"
+#include "vnode.h"
+#include "ioctl.h"
+#include "uio.h"
+#include "ptrace.h"
+#include "stat.h"
+#include "syslog.h"
+#include "malloc.h"
+#include "mount.h"
+#include "ipc.h"
+
+#include "machine/cpu.h"
+#include "machine/reg.h"
+#include "machine/psl.h"
+#include "machine/vmparam.h"
+#include "hpux.h"
+#include "hpux_termio.h"
+
+#ifdef DEBUG
+int unimpresponse = 0;
+#endif
+
+/* "tick" value for HZ==50 */
+int hpuxtick = 1000000 / 50;
+
+/* SYS5 style UTSNAME info */
+struct hpuxutsname protoutsname = {
+       "4.4bsd", "", "2.0", "B", "9000/3?0", ""
+};
+
+/* 6.0 and later style context */
+#ifdef FPCOPROC
+char hpuxcontext[] =
+       "standalone HP-MC68881 HP-MC68020 HP-MC68010 localroot default";
+#else
+char hpuxcontext[] =
+       "standalone HP-MC68020 HP-MC68010 localroot default";
+#endif
+
+/* YP domainname */
+char   domainname[MAXHOSTNAMELEN] = "unknown";
+int    domainnamelen = 7;
+
+#define NERR   79
+#define BERR   1000
+
+/* indexed by BSD errno */
+short bsdtohpuxerrnomap[NERR] = {
+/*00*/   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
+/*10*/  10,  45,  12,  13,  14,  15,  16,  17,  18,  19,
+/*20*/  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
+/*30*/  30,  31,  32,  33,  34, 246, 245, 244, 216, 217,
+/*40*/ 218, 219, 220, 221, 222, 223, 224, 225, 226, 227,
+/*50*/ 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
+/*60*/ 238, 239, 249, 248, 241, 242, 247,BERR,BERR,BERR,
+/*70*/   70,  71,BERR,BERR,BERR,BERR,BERR,  46,BERR
+};
+
+notimp(code, nargs)
+{
+#ifdef DEBUG
+       int *argp = u.u_ap;
+       extern char *hpuxsyscallnames[];
+
+       printf("HPUX %s(", hpuxsyscallnames[code]);
+       if (nargs)
+               while (nargs--)
+                       printf("%x%c", *argp++, nargs? ',' : ')');
+       else
+               printf(")");
+       printf("\n");
+       switch (unimpresponse) {
+       case 0:
+               nosys();
+               break;
+       case 1:
+               u.u_error = EINVAL;
+               break;
+       }
+#else
+       nosys();
+#endif
+       uprintf("HPUX system call %d not implemented\n", code);
+}
+
+/*
+ * HPUX versions of wait and wait3 actually pass the parameters
+ * (status pointer, options, rusage) into the kernel rather than
+ * handling it in the C library stub.  We also need to map any
+ * termination signal from BSD to HPUX.
+ */
+hpuxwait3()
+{
+       struct a {
+               int     *status;
+               int     options;
+               int     rusage;
+       } *uap = (struct a *)u.u_ap;
+
+       /* rusage pointer must be zero */
+       if (uap->rusage) {
+               u.u_error = EINVAL;
+               return;
+       }
+       u.u_ar0[PS] = PSL_ALLCC;
+       u.u_ar0[R0] = uap->options;
+       u.u_ar0[R1] = uap->rusage;
+       hpuxwait();
+}
+
+hpuxwait()
+{
+       int sig, *statp;
+       struct a {
+               int     *status;
+       } *uap = (struct a *)u.u_ap;
+
+       statp = uap->status;    /* owait clobbers first arg */
+       owait();
+       /*
+        * HP-UX wait always returns EINTR when interrupted by a signal
+        * (well, unless its emulating a BSD process, but we don't bother...)
+        */
+       if (u.u_eosys == RESTARTSYS) {
+               u.u_eosys = NORMALRETURN;
+               u.u_error = EINTR;
+       }
+       if (u.u_error)
+               return;
+       sig = u.u_r.r_val2 & 0xFF;
+       if (sig == WSTOPPED) {
+               sig = (u.u_r.r_val2 >> 8) & 0xFF;
+               u.u_r.r_val2 = (bsdtohpuxsig(sig) << 8) | WSTOPPED;
+       } else if (sig)
+               u.u_r.r_val2 = (u.u_r.r_val2 & 0xFF00) |
+                       bsdtohpuxsig(sig & 0x7F) | (sig & 0x80);
+       if (statp)
+               if (suword((caddr_t)statp, u.u_r.r_val2))
+                       u.u_error = EFAULT;
+}
+
+/*
+ * Must remap some bits in the mode mask.
+ * O_CREAT, O_TRUNC, and O_EXCL must be remapped,
+ * O_SYNCIO (0100000) is removed entirely.
+ */
+hpuxopen(scp)
+       register struct syscontext *scp;
+{
+       struct a {
+               char    *fname;
+               int     mode;
+               int     crtmode;
+       } *uap = (struct a *) scp->sc_ap;
+       struct nameidata *ndp = &scp->sc_nd;
+       int mode;
+
+       mode = uap->mode;
+       uap->mode &= ~(HPUXFSYNCIO|HPUXFEXCL|HPUXFTRUNC|HPUXFCREAT);
+       if (mode & HPUXFCREAT) {
+               /*
+                * simulate the pre-NFS behavior that opening a
+                * file for READ+CREATE ignores the CREATE (unless
+                * EXCL is set in which case we will return the
+                * proper error).
+                */
+               if ((mode & HPUXFEXCL) || ((mode-FOPEN) & FWRITE))
+                       uap->mode |= FCREAT;
+       }
+       if (mode & HPUXFTRUNC)
+               uap->mode |= FTRUNC;
+       if (mode & HPUXFEXCL)
+               uap->mode |= FEXCL;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = uap->fname;
+       RETURN (copen(scp, uap->mode-FOPEN, uap->crtmode &~ scp->sc_cmask, ndp,
+               &scp->sc_retval1));
+}
+
+hpuxfcntl()
+{
+       register struct a {
+               int     fdes;
+               int     cmd;
+               int     arg;
+       } *uap = (struct a *)u.u_ap;
+       int mode;
+
+       switch (uap->cmd) {
+       case F_SETFL:
+               uap->arg &= ~(HPUXFSYNCIO|HPUXFREMOTE|FUSECACHE);
+               break;
+       case F_GETFL:
+       case F_DUPFD:
+       case F_GETFD:
+       case F_SETFD:
+               break;
+       default:
+               u.u_error = EINVAL;
+               return;
+       }
+       fcntl();
+       if (u.u_error == 0 && uap->arg == F_GETFL) {
+               mode = u.u_r.r_val1;
+               u.u_r.r_val1 &= ~(FCREAT|FTRUNC|FEXCL|FUSECACHE);
+               if (mode & FCREAT)
+                       u.u_r.r_val1 |= HPUXFCREAT;
+               if (mode & FTRUNC)
+                       u.u_r.r_val1 |= HPUXFTRUNC;
+               if (mode & FEXCL)
+                       u.u_r.r_val1 |= HPUXFEXCL;
+       }
+}
+
+/*
+ * Read and write should return a 0 count when an operation
+ * on a VNODE would block, not an error.  Sockets appear to
+ * return EWOULDBLOCK (at least in 6.2).  This is probably
+ * not entirely correct, since the behavior is only defined
+ * for pipes and tty type devices.
+ */
+hpuxread()
+{
+       struct a {
+               int     fd;
+       } *uap = (struct a *)u.u_ap;
+
+       read();
+       if (u.u_error == EWOULDBLOCK &&
+           u.u_ofile[uap->fd]->f_type == DTYPE_VNODE) {
+               u.u_error = 0;
+               u.u_r.r_val1 = 0;
+       }
+}
+
+hpuxwrite()
+{
+       struct a {
+               int     fd;
+       } *uap = (struct a *)u.u_ap;
+
+       write();
+       if (u.u_error == EWOULDBLOCK &&
+           u.u_ofile[uap->fd]->f_type == DTYPE_VNODE) {
+               u.u_error = 0;
+               u.u_r.r_val1 = 0;
+       }
+}
+
+hpuxreadv()
+{
+       struct a {
+               int     fd;
+       } *uap = (struct a *)u.u_ap;
+
+       readv();
+       if (u.u_error == EWOULDBLOCK &&
+           u.u_ofile[uap->fd]->f_type == DTYPE_VNODE) {
+               u.u_error = 0;
+               u.u_r.r_val1 = 0;
+       }
+}
+
+hpuxwritev()
+{
+       struct a {
+               int     fd;
+       } *uap = (struct a *)u.u_ap;
+
+       writev();
+       if (u.u_error == EWOULDBLOCK &&
+           u.u_ofile[uap->fd]->f_type == DTYPE_VNODE) {
+               u.u_error = 0;
+               u.u_r.r_val1 = 0;
+       }
+}
+
+/*
+ * 4.3bsd dup allows dup2 to come in on the same syscall entry
+ * and hence allows two arguments.  HPUX dup has only one arg.
+ */
+hpuxdup()
+{
+       register struct a {
+               int     i;
+       } *uap = (struct a *)u.u_ap;
+       struct file *fp;
+       int j;
+
+       if ((unsigned)uap->i >= NOFILE || (fp = u.u_ofile[uap->i]) == NULL) {
+               u.u_error = EBADF;
+               return;
+       }
+       u.u_error = ufalloc(0, &j);
+       if (u.u_error)
+               return;
+       u.u_r.r_val1 = j;
+       dupit(j, fp, u.u_pofile[uap->i] &~ UF_EXCLOSE);
+}
+
+hpuxuname()
+{
+       register struct a {
+               struct hpuxutsname *uts;
+               int dev;
+               int request;
+       } *uap = (struct a *)u.u_ap;
+       register int i;
+
+       switch (uap->request) {
+       /* uname */
+       case 0:
+               /* fill in machine type */
+               switch (machineid) {
+               case HP_320:
+                       protoutsname.machine[6] = '2';
+                       break;
+               /* includes 318 and 319 */
+               case HP_330:
+                       protoutsname.machine[6] = '3';
+                       break;
+               case HP_340:
+                       protoutsname.machine[6] = '4';
+                       break;
+               case HP_350:
+                       protoutsname.machine[6] = '5';
+                       break;
+               case HP_360:
+                       protoutsname.machine[6] = '6';
+                       break;
+               case HP_370:
+                       protoutsname.machine[6] = '7';
+                       break;
+               }
+               /* copy hostname (sans domain) to nodename */
+               for (i = 0; i < 9 && hostname[i] != '.'; i++)
+                       protoutsname.nodename[i] = hostname[i];
+               u.u_error = copyout((caddr_t)&protoutsname, (caddr_t)uap->uts,
+                                   sizeof(struct hpuxutsname));
+               break;
+       /* ustat - who cares? */
+       case 2:
+       default:
+               u.u_error = EINVAL;
+               break;
+       }
+}
+
+hpuxstat()
+{
+       struct a {
+               char    *fname;
+               struct hpuxstat *hsb;
+       } *uap = (struct a *)u.u_ap;
+
+       u.u_error = hpuxstat1(uap->fname, uap->hsb, FOLLOW);
+}
+
+hpuxlstat()
+{
+       struct a {
+               char    *fname;
+               struct  hpuxstat *hsb;
+       } *uap = (struct a *) u.u_ap;
+
+       u.u_error = hpuxstat1(uap->fname, uap->hsb, NOFOLLOW);
+}
+
+hpuxfstat()
+{
+       register struct file *fp;
+       register struct a {
+               int     fdes;
+               struct  hpuxstat *hsb;
+       } *uap = (struct a *)u.u_ap;
+       struct stat sb;
+
+       if ((unsigned)uap->fdes >= NOFILE ||
+           (fp = u.u_ofile[uap->fdes]) == NULL) {
+               u.u_error = EBADF;
+               return;
+       }
+       switch (fp->f_type) {
+
+       case DTYPE_VNODE:
+               u.u_error = vn_stat((struct vnode *)fp->f_data, &sb);
+               break;
+
+       case DTYPE_SOCKET:
+               u.u_error = soo_stat((struct socket *)fp->f_data, &sb);
+               break;
+
+       default:
+               panic("fstat");
+               /*NOTREACHED*/
+       }
+       /* is this right for sockets?? */
+       if (u.u_error == 0)
+               u.u_error = bsdtohpuxstat(&sb, uap->hsb);
+}
+
+hpuxulimit()
+{
+       struct a {
+               int     cmd;
+               long    newlimit;
+       } *uap = (struct a *)u.u_ap;
+       struct rlimit *limp;
+
+       limp = &u.u_rlimit[RLIMIT_FSIZE];
+       switch (uap->cmd) {
+       case 2:
+               uap->newlimit *= 512;
+               if (uap->newlimit > limp->rlim_max &&
+                   (u.u_error = suser(u.u_cred, &u.u_acflag)))
+                       break;
+               limp->rlim_cur = limp->rlim_max = uap->newlimit;
+               /* else fall into... */
+
+       case 1:
+               u.u_r.r_off = limp->rlim_max / 512;
+               break;
+
+       case 3:
+               limp = &u.u_rlimit[RLIMIT_DATA];
+               u.u_r.r_off = ctob(u.u_tsize) + limp->rlim_max;
+               break;
+
+       default:
+               u.u_error = EINVAL;
+               break;
+       }
+}
+
+/*
+ * Map "real time" priorities 0 (high) thru 127 (low) into nice
+ * values -16 (high) thru -1 (low).
+ */
+hpuxrtprio()
+{
+       register struct a {
+               int pid;
+               int prio;
+       } *uap = (struct a *)u.u_ap;
+       struct proc *p;
+       int nice;
+
+       if (uap->prio < RTPRIO_MIN && uap->prio > RTPRIO_MAX &&
+           uap->prio != RTPRIO_NOCHG && uap->prio != RTPRIO_RTOFF) {
+               u.u_error = EINVAL;
+               return;
+       }
+       if (uap->pid == 0)
+               p = u.u_procp;
+       else if ((p = pfind(uap->pid)) == 0) {
+               u.u_error = ESRCH;
+               return;
+       }
+       nice = p->p_nice;
+       if (nice < NZERO)
+               u.u_r.r_val1 = (nice + 16) << 3;
+       else
+               u.u_r.r_val1 = RTPRIO_RTOFF;
+       switch (uap->prio) {
+
+       case RTPRIO_NOCHG:
+               return;
+
+       case RTPRIO_RTOFF:
+               if (nice >= NZERO)
+                       return;
+               nice = NZERO;
+               break;
+
+       default:
+               nice = (uap->prio >> 3) - 16;
+               break;
+       }
+       donice(p, nice);
+       if (u.u_error == EACCES)
+               u.u_error = EPERM;
+}
+
+/*
+ * Kudos to HP folks for using such mnemonic names so I could figure
+ * out what this guy does.
+ */
+hpuxadvise()
+{
+       struct a {
+               int     arg;
+       } *uap = (struct a *) u.u_ap;
+
+       switch (uap->arg) {
+       case 0:
+               u.u_pcb.pcb_flags |= PCB_HPUXMMAP;
+               break;
+       case 1:
+               ICIA();
+               break;
+       case 2:
+               DCIA();
+               break;
+       default:
+               u.u_error = EINVAL;
+               break;
+       }
+}
+
+hpuxptrace()
+{
+       struct a {
+               int     req;
+               int     pid;
+               int     *addr;
+               int     data;
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->req == PT_STEP || uap->req == PT_CONTINUE) {
+               if (uap->data) {
+                       uap->data = hpuxtobsdsig(uap->data);
+                       if (uap->data == 0)
+                               uap->data = NSIG;
+               }
+       }
+       ptrace();
+}
+
+hpuxgetdomainname()
+{
+       register struct a {
+               char    *domainname;
+               u_int   len;
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->len > domainnamelen + 1)
+               uap->len = domainnamelen + 1;
+       u.u_error = copyout(domainname, uap->domainname, uap->len);
+}
+
+hpuxsetdomainname()
+{
+       register struct a {
+               char    *domainname;
+               u_int   len;
+       } *uap = (struct a *)u.u_ap;
+
+       if (u.u_error = suser(u.u_cred, &u.u_acflag))
+               return;
+       if (uap->len > sizeof (domainname) - 1) {
+               u.u_error = EINVAL;
+               return;
+       }
+       domainnamelen = uap->len;
+       u.u_error = copyin(uap->domainname, domainname, uap->len);
+       domainname[domainnamelen] = 0;
+}
+
+#ifdef SYSVSHM
+hpuxshmat()
+{
+       shmat(u.u_ap);
+}
+
+hpuxshmctl()
+{
+       shmctl(u.u_ap);
+}
+
+hpuxshmdt()
+{
+       shmdt(u.u_ap);
+}
+
+hpuxshmget()
+{
+       shmget(u.u_ap);
+}
+#endif
+
+/*
+ * Fake semaphore routines, just don't return an error.
+ * Should be adequate for starbase to run.
+ */
+hpuxsemctl()
+{
+       struct a {
+               int semid;
+               u_int semnum;
+               int cmd;
+               int arg;
+       } *uap = (struct a *)u.u_ap;
+
+       /* XXX: should do something here */
+}
+
+hpuxsemget()
+{
+       struct a {
+               key_t key;
+               int nsems;
+               int semflg;
+       } *uap = (struct a *)u.u_ap;
+
+       /* XXX: should do something here */
+}
+
+hpuxsemop()
+{
+       struct a {
+               int semid;
+               struct sembuf *sops;
+               u_int nsops;
+       } *uap = (struct a *)u.u_ap;
+
+       /* XXX: should do something here */
+}
+
+/* convert from BSD to HPUX errno */
+bsdtohpuxerrno(err)
+       int err;
+{
+       if (err < 0 || err >= NERR)
+               return(BERR);
+       return((int)bsdtohpuxerrnomap[err]);
+}
+
+hpuxstat1(fname, hsb, follow)
+       char *fname;
+       struct hpuxstat *hsb;
+       int follow;
+{
+       register struct nameidata *ndp = &u.u_nd;
+       struct stat sb;
+       int error;
+
+       ndp->ni_nameiop = LOOKUP | LOCKLEAF | follow;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = fname;
+       if (error = namei(ndp))
+               return (error);
+       error = vn_stat(ndp->ni_vp, &sb);
+       vput(ndp->ni_vp);
+       if (error == 0)
+               error = bsdtohpuxstat(&sb, hsb);
+       return (error);
+}
+
+#include "grf.h"
+
+bsdtohpuxstat(sb, hsb)
+       struct stat *sb;
+       struct hpuxstat *hsb;
+{
+       struct hpuxstat ds;
+
+       bzero((caddr_t)&ds, sizeof(ds));
+       ds.hst_dev = sb->st_dev;
+       ds.hst_ino = (u_long)sb->st_ino;
+       ds.hst_mode = sb->st_mode;
+       ds.hst_nlink = sb->st_nlink;
+       ds.hst_uid = (u_short)sb->st_uid;
+       ds.hst_gid = (u_short)sb->st_gid;
+#if NGRF > 0
+       /* XXX: I don't want to talk about it... */
+       if ((sb->st_mode & S_IFMT) == S_IFCHR && major(sb->st_rdev) == 10)
+               ds.hst_rdev = grfdevno(sb->st_rdev);
+       else
+#endif
+               ds.hst_rdev = bsdtohpuxdev(sb->st_rdev);
+       ds.hst_size = sb->st_size;
+       ds.hst_atime = sb->st_atime;
+       ds.hst_mtime = sb->st_mtime;
+       ds.hst_ctime = sb->st_ctime;
+       ds.hst_blksize = sb->st_blksize;
+       ds.hst_blocks = sb->st_blocks;
+       return(copyout((caddr_t)&ds, (caddr_t)hsb, sizeof(ds)));
+}
+
+hpuxtobsdioctl(com)
+       int com;
+{
+       switch (com) {
+       case HPUXTIOCSLTC:
+               com = TIOCSLTC; break;
+       case HPUXTIOCGLTC:
+               com = TIOCGLTC; break;
+       case HPUXTIOCSPGRP:
+               com = TIOCSPGRP; break;
+       case HPUXTIOCGPGRP:
+               com = TIOCGPGRP; break;
+       case HPUXTIOCLBIS:
+               com = TIOCLBIS; break;
+       case HPUXTIOCLBIC:
+               com = TIOCLBIC; break;
+       case HPUXTIOCLSET:
+               com = TIOCLSET; break;
+       case HPUXTIOCLGET:
+               com = TIOCLGET; break;
+       }
+       return(com);
+}
+
+/*
+ * HPUX ioctl system call.  The differences here are:
+ *     IOC_IN also means IOC_VOID if the size portion is zero.
+ *     no FIOCLEX/FIONCLEX/FIONBIO/FIOASYNC/FIOGETOWN/FIOSETOWN
+ *     the sgttyb struct is 2 bytes longer
+ */
+hpuxioctl()
+{
+       register struct file *fp;
+       struct a {
+               int     fdes;
+               int     cmd;
+               caddr_t cmarg;
+       } *uap = (struct a *)u.u_ap;
+       register int com;
+       register u_int size;
+       caddr_t memp = 0;
+#define STK_PARAMS     128
+       char stkbuf[STK_PARAMS];
+       caddr_t data = stkbuf;
+
+       com = uap->cmd;
+
+       /* XXX */
+       if (com == HPUXTIOCGETP || com == HPUXTIOCSETP) {
+               getsettty(uap->fdes, com, uap->cmarg);
+               return;
+       }
+
+       if ((unsigned)uap->fdes >= NOFILE ||
+           (fp = u.u_ofile[uap->fdes]) == NULL) {
+               u.u_error = EBADF;
+               return;
+       }
+       if ((fp->f_flag & (FREAD|FWRITE)) == 0) {
+               u.u_error = EBADF;
+               return;
+       }
+
+       /*
+        * Interpret high order word to find
+        * amount of data to be copied to/from the
+        * user's address space.
+        */
+       size = IOCPARM_LEN(com);
+       if (size > IOCPARM_MAX) {
+               u.u_error = EFAULT;
+               return;
+       }
+       if (size > sizeof (stkbuf)) {
+               memp = (caddr_t)malloc((u_long)IOCPARM_MAX, M_IOCTLOPS,
+                   M_WAITOK);
+               data = memp;
+       }
+       if (com&IOC_IN) {
+               if (size) {
+                       u.u_error = copyin(uap->cmarg, data, (u_int)size);
+                       if (u.u_error) {
+                               if (memp)
+                                       free(memp, M_IOCTLOPS);
+                               return;
+                       }
+               } else
+                       *(caddr_t *)data = uap->cmarg;
+       } else if ((com&IOC_OUT) && size)
+               /*
+                * Zero the buffer on the stack so the user
+                * always gets back something deterministic.
+                */
+               bzero(data, size);
+       else if (com&IOC_VOID)
+               *(caddr_t *)data = uap->cmarg;
+
+       switch (com) {
+
+       case HPUXTIOCCONS:
+               *(int *)data = 1;
+               u.u_error = (*fp->f_ops->fo_ioctl)(fp, TIOCCONS, data);
+               break;
+
+       /* BSD-style job control ioctls */
+       case HPUXTIOCLBIS:
+       case HPUXTIOCLBIC:
+       case HPUXTIOCLSET:
+               *(int *)data &= HPUXLTOSTOP;
+               if (*(int *)data & HPUXLTOSTOP)
+                       *(int *)data = LTOSTOP;
+               /* fall into */
+       case HPUXTIOCLGET:
+       case HPUXTIOCSLTC:
+       case HPUXTIOCGLTC:
+       case HPUXTIOCSPGRP:
+       case HPUXTIOCGPGRP:
+               u.u_error = (*fp->f_ops->fo_ioctl)(fp, hpuxtobsdioctl(com), data);
+               if (u.u_error == 0 && com == HPUXTIOCLGET) {
+                       *(int *)data &= LTOSTOP;
+                       if (*(int *)data & LTOSTOP)
+                               *(int *)data = HPUXLTOSTOP;
+               }
+               break;
+
+       /* SYS 5 termio */
+       case HPUXTCGETA:
+       case HPUXTCSETA:
+       case HPUXTCSETAW:
+       case HPUXTCSETAF:
+               u.u_error = hpuxtermio(fp, com, data);
+               break;
+
+       default:
+               u.u_error = (*fp->f_ops->fo_ioctl)(fp, com, data);
+               break;
+       }
+       /*
+        * Copy any data to user, size was
+        * already set and checked above.
+        */
+       if (u.u_error == 0 && (com&IOC_OUT) && size)
+               u.u_error = copyout(data, uap->cmarg, (u_int)size);
+       if (memp)
+               free(memp, M_IOCTLOPS);
+}
+
+/*
+ * Man page lies, behaviour here is based on observed behaviour.
+ */
+hpuxgetcontext()
+{
+       struct a {
+               char *buf;
+               int len;
+       } *uap = (struct a *)u.u_ap;
+       int error = 0;
+       register int len;
+
+       len = MIN(uap->len, sizeof(hpuxcontext));
+       if (len)
+               error = copyout(hpuxcontext, uap->buf, (u_int)len);
+       if (!error)
+               u.u_r.r_val1 = sizeof(hpuxcontext);
+       return(error);
+}
+
+/*
+ * XXX: simple recognition hack to see if we can make grmd work.
+ */
+hpuxlockf()
+{
+       struct a {
+               int fd;
+               int func;
+               long size;
+       } *uap = (struct a *)u.u_ap;
+#ifdef DEBUG
+       log(LOG_DEBUG, "%d: lockf(%d, %d, %d)\n",
+           u.u_procp->p_pid, uap->fd, uap->func, uap->size);
+#endif
+       return(0);
+}
+
+/*
+ * This is the equivalent of BSD getpgrp but with more restrictions.
+ * Note we do not check the real uid or "saved" uid.
+ */
+hpuxgetpgrp2()
+{
+       register struct proc *p;
+       register struct a {
+               int pid;
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->pid == 0)
+               uap->pid = u.u_procp->p_pid;
+       p = pfind(uap->pid);
+       if (p == 0) {
+               u.u_error = ESRCH;
+               return;
+       }
+       if (u.u_uid && p->p_uid != u.u_uid && !inferior(p)) {
+               u.u_error = EPERM;
+               return;
+       }
+       u.u_r.r_val1 = p->p_pgid;
+}
+
+/*
+ * This is the equivalent of BSD setpgrp but with more restrictions.
+ * Note we do not check the real uid or "saved" uid or pgrp.
+ */
+hpuxsetpgrp2()
+{
+       struct a {
+               int     pid;
+               int     pgrp;
+       } *uap = (struct a *)u.u_ap;
+
+       /* empirically determined */
+       if (uap->pgrp < 0 || uap->pgrp >= 30000) {
+               u.u_error = EINVAL;
+               return;
+       }
+       setpgrp();
+}
+
+/*
+ * Brutal hack!  Map HPUX u-area offsets into BSD u offsets.
+ * No apologies offered, if you don't like it, rewrite it!
+ */
+
+#define UOFF(f)                ((int)&((struct user *)0)->f)
+#define HPUOFF(f)      ((int)&((struct hpuxuser *)0)->f)
+
+/* simplified FP structure */
+struct bsdfp {
+       int save[54];
+       int reg[24];
+       int ctrl[3];
+};
+
+hpuxtobsduoff(off)
+       int *off;
+{
+       struct hpuxfp *hp;
+       struct bsdfp *bp;
+       register u_int raddr;
+
+       /* u_ar0 field */
+       if ((int)off == HPUOFF(hpuxu_ar0))
+               return(UOFF(u_ar0));
+
+#ifdef FPCOPROC
+       /* 68881 registers from PCB */
+       hp = (struct hpuxfp *)HPUOFF(hpuxu_fp);
+       bp = (struct bsdfp *)UOFF(u_pcb.pcb_fpregs);
+       if (off >= hp->hpfp_ctrl && off < &hp->hpfp_ctrl[3])
+               return((int)&bp->ctrl[off - hp->hpfp_ctrl]);
+       if (off >= hp->hpfp_reg && off < &hp->hpfp_reg[24])
+               return((int)&bp->reg[off - hp->hpfp_reg]);
+#endif
+
+       /*
+        * Everything else we recognize comes from the kernel stack,
+        * so we convert off to an absolute address (if not already)
+        * for simplicity.
+        */
+       if (off < (int *)ctob(UPAGES))
+               off = (int *)((u_int)off + (u_int)&u);
+
+       /*
+        * 68020 registers.
+        * We know that the HPUX registers are in the same order as ours.
+        * The only difference is that their PS is 2 bytes instead of a
+        * padded 4 like ours throwing the alignment off.
+        */
+       if (off >= u.u_ar0 && off < &u.u_ar0[18]) {
+               /*
+                * PS: return low word and high word of PC as HP-UX would
+                * (e.g. &u.u_ar0[16.5]).
+                */
+               if (off == &u.u_ar0[PS])
+                       raddr = (u_int) &((short *)u.u_ar0)[PS*2+1];
+               /*
+                * PC: off will be &u.u_ar0[16.5]
+                */
+               else if (off == (int *)&(((short *)u.u_ar0)[PS*2+1]))
+                       raddr = (u_int) &u.u_ar0[PC];
+               /*
+                * D0-D7, A0-A7: easy
+                */
+               else
+                       raddr = (u_int) &u.u_ar0[(int)(off - u.u_ar0)];
+               return((int)(raddr - (u_int)&u));
+       }
+
+       /* everything else */
+       return(-1);
+}
+
+/*
+ * Kludge up a uarea dump so that HPUX debuggers can find out
+ * what they need.  IMPORTANT NOTE: we do not EVEN attempt to
+ * convert the entire user struct.
+ */
+hpuxdumpu(vp, cred)
+       struct vnode *vp;
+       struct ucred *cred;
+{
+       int error;
+       struct hpuxuser *faku;
+       struct bsdfp *bp;
+       short *foop;
+
+       faku = (struct hpuxuser *)malloc((u_long)ctob(1), M_TEMP, M_WAITOK);
+       /*
+        * Make sure there is no mistake about this
+        * being a real user structure.
+        */
+       bzero((caddr_t)faku, ctob(1));
+       /*
+        * Fill in the process sizes.
+        */
+       faku->hpuxu_tsize = u.u_tsize;
+       faku->hpuxu_dsize = u.u_dsize;
+       faku->hpuxu_ssize = u.u_ssize;
+       /*
+        * Fill in the exec header for CDB.
+        * This was saved back in exec().  As far as I can tell CDB
+        * only uses this information to verify that a particular
+        * core file goes with a particular binary.
+        */
+       bcopy((caddr_t)u.u_pcb.pcb_exec,
+             (caddr_t)&faku->hpuxu_exdata, sizeof (struct hpux_exec));
+       /*
+        * Adjust user's saved registers (on kernel stack) to reflect
+        * HPUX order.  Note that HPUX saves the SR as 2 bytes not 4
+        * so we have to move it up.
+        */
+       faku->hpuxu_ar0 = u.u_ar0;
+       foop = (short *) u.u_ar0;
+       foop[32] = foop[33];
+       foop[33] = foop[34];
+       foop[34] = foop[35];
+#ifdef FPCOPROC
+       /*
+        * Copy 68881 registers from our PCB format to HPUX format
+        */
+       bp = (struct bsdfp *) &u.u_pcb.pcb_fpregs;
+       bcopy((caddr_t)bp->save, (caddr_t)faku->hpuxu_fp.hpfp_save,
+             sizeof(bp->save));
+       bcopy((caddr_t)bp->ctrl, (caddr_t)faku->hpuxu_fp.hpfp_ctrl,
+             sizeof(bp->ctrl));
+       bcopy((caddr_t)bp->reg, (caddr_t)faku->hpuxu_fp.hpfp_reg,
+             sizeof(bp->reg));
+#endif
+       /*
+        * Slay the dragon
+        */
+       faku->hpuxu_dragon = -1;
+       /*
+        * Dump this artfully constructed page in place of the
+        * user struct page.
+        */
+       error = vn_rdwr(UIO_WRITE, vp,
+                       (caddr_t)faku, ctob(1), (off_t)0,
+                       UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, (int *)0);
+       /*
+        * Dump the remaining UPAGES-1 pages normally
+        */
+       if (!error) 
+               error = vn_rdwr(UIO_WRITE, vp, ((caddr_t)&u)+ctob(1),
+                               ctob(UPAGES-1), (off_t)ctob(1), UIO_SYSSPACE,
+                               IO_NODELOCKED|IO_UNIT, cred, (int *)0);
+       free((caddr_t)faku, M_TEMP);
+       return(error);
+}
+
+/*
+ * The remaining routines are essentially the same as those in kern_xxx.c
+ * and vfs_xxx.c as defined under "#ifdef COMPAT".  We replicate them here
+ * to avoid HPUXCOMPAT dependencies in those files and to make sure that
+ * HP-UX compatibility still works even when COMPAT is not defined.
+ */
+/* #ifdef COMPAT */
+
+#include "../h/times.h"
+
+/* from old timeb.h */
+struct hpuxtimeb {
+       time_t  time;
+       u_short millitm;
+       short   timezone;
+       short   dstflag;
+};
+
+/* ye ole stat structure */
+struct ohpuxstat {
+       dev_t   ohst_dev;
+       u_short ohst_ino;
+       u_short ohst_mode;
+       short   ohst_nlink;
+       short   ohst_uid;
+       short   ohst_gid;
+       dev_t   ohst_rdev;
+       int     ohst_size;
+       int     ohst_atime;
+       int     ohst_mtime;
+       int     ohst_ctime;
+};
+
+/*
+ * Right now the following two routines are the same as the 4.3
+ * osetuid/osetgid calls.  Eventually they need to be changed to
+ * implement the notion of "saved" ids (whatever that means).
+ */
+ohpuxsetuid()
+{
+       register uid;
+       register struct a {
+               int     uid;
+       } *uap = (struct a *)u.u_ap;
+
+       uid = uap->uid;
+       if (uid != u.u_procp->p_ruid && uid != u.u_cred->cr_uid &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag)))
+               return;
+       if (u.u_cred->cr_ref > 1)
+               u.u_cred = crcopy(u.u_cred);
+       u.u_cred->cr_uid = uid;
+       u.u_procp->p_uid = uid;
+       u.u_procp->p_ruid = uid;
+}
+
+ohpuxsetgid()
+{
+       register gid;
+       register struct a {
+               int     gid;
+       } *uap = (struct a *)u.u_ap;
+
+       gid = uap->gid;
+       if (u.u_procp->p_rgid != gid && u.u_cred->cr_groups[0] != gid &&
+           (u.u_error = suser(u.u_cred, &u.u_acflag)))
+               return;
+       if (u.u_cred->cr_ref > 1)
+               u.u_cred = crcopy(u.u_cred);
+       u.u_procp->p_rgid = gid;
+       u.u_cred->cr_groups[0] = gid;
+}
+
+/*
+ * SYS V style setpgrp()
+ */
+ohpuxsetpgrp()
+{
+       register struct proc *p = u.u_procp;
+
+       if (p->p_pid != p->p_pgid)
+               pgmv(p, p->p_pid, 0);
+       u.u_r.r_val1 = p->p_pgid;
+}
+
+ohpuxtime()
+{
+       register struct a {
+               long    *tp;
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->tp)
+               u.u_error = copyout((caddr_t)&time.tv_sec, (caddr_t)uap->tp,
+                                   sizeof (long));
+       u.u_r.r_time = time.tv_sec;
+}
+
+ohpuxstime()
+{
+       register struct a {
+               int     time;
+       } *uap = (struct a *)u.u_ap;
+       struct timeval tv;
+       int s;
+
+       tv.tv_sec = uap->time;
+       tv.tv_usec = 0;
+       u.u_error = suser(u.u_cred, &u.u_acflag);
+       if (u.u_error)
+               return;
+
+       /* WHAT DO WE DO ABOUT PENDING REAL-TIME TIMEOUTS??? */
+       boottime.tv_sec += tv.tv_sec - time.tv_sec;
+       s = splhigh(); time = tv; splx(s);
+       resettodr();
+}
+
+ohpuxftime()
+{
+       register struct a {
+               struct  hpuxtimeb *tp;
+       } *uap;
+       struct hpuxtimeb tb;
+       int s;
+
+       uap = (struct a *)u.u_ap;
+       s = splhigh();
+       tb.time = time.tv_sec;
+       tb.millitm = time.tv_usec / 1000;
+       splx(s);
+       tb.timezone = tz.tz_minuteswest;
+       tb.dstflag = tz.tz_dsttime;
+       u.u_error = copyout((caddr_t)&tb, (caddr_t)uap->tp, sizeof (tb));
+}
+
+ohpuxalarm()
+{
+       register struct a {
+               int     deltat;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p = u.u_procp;
+       int s = splhigh();
+
+       untimeout(realitexpire, (caddr_t)p);
+       timerclear(&p->p_realtimer.it_interval);
+       u.u_r.r_val1 = 0;
+       if (timerisset(&p->p_realtimer.it_value) &&
+           timercmp(&p->p_realtimer.it_value, &time, >))
+               u.u_r.r_val1 = p->p_realtimer.it_value.tv_sec - time.tv_sec;
+       if (uap->deltat == 0) {
+               timerclear(&p->p_realtimer.it_value);
+               splx(s);
+               return;
+       }
+       p->p_realtimer.it_value = time;
+       p->p_realtimer.it_value.tv_sec += uap->deltat;
+       timeout(realitexpire, (caddr_t)p, hzto(&p->p_realtimer.it_value));
+       splx(s);
+}
+
+ohpuxnice()
+{
+       register struct a {
+               int     niceness;
+       } *uap = (struct a *)u.u_ap;
+       register struct proc *p = u.u_procp;
+
+       donice(p, (p->p_nice-NZERO)+uap->niceness);
+       u.u_r.r_val1 = p->p_nice - NZERO;
+}
+
+ohpuxtimes()
+{
+       register struct a {
+               struct  tms *tmsb;
+       } *uap = (struct a *)u.u_ap;
+       struct tms atms;
+
+       atms.tms_utime = scale50(&u.u_ru.ru_utime);
+       atms.tms_stime = scale50(&u.u_ru.ru_stime);
+       atms.tms_cutime = scale50(&u.u_cru.ru_utime);
+       atms.tms_cstime = scale50(&u.u_cru.ru_stime);
+       u.u_error = copyout((caddr_t)&atms, (caddr_t)uap->tmsb, sizeof (atms));
+       if (u.u_error == 0)
+               u.u_r.r_time = scale50(&time) - scale50(&boottime);
+}
+
+scale50(tvp)
+       register struct timeval *tvp;
+{
+       extern int hpuxtick;
+
+       /*
+        * Doesn't exactly do what the documentation says.
+        * What we really do is return 50th of a second since that
+        * is what HZ is on all bobcats I know of.
+        */
+       return ((tvp->tv_sec * 50 + tvp->tv_usec / hpuxtick));
+}
+
+/*
+ * Set IUPD and IACC times on file.
+ * Can't set ICHG.
+ */
+ohpuxutime()
+{
+       register struct a {
+               char    *fname;
+               time_t  *tptr;
+       } *uap = (struct a *)u.u_ap;
+       struct vattr vattr;
+       time_t tv[2];
+       register struct vnode *vp;
+       register struct nameidata *ndp = &u.u_nd;
+
+       if (uap->tptr) {
+               u.u_error =
+                       copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv));
+               if (u.u_error)
+                       return;
+       } else
+               tv[0] = tv[1] = time.tv_sec;
+       ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = uap->fname;
+       vattr_null(&vattr);
+       vattr.va_atime.tv_sec = tv[0];
+       vattr.va_atime.tv_usec = 0;
+       vattr.va_mtime.tv_sec = tv[1];
+       vattr.va_mtime.tv_usec = 0;
+       if (u.u_error = namei(ndp))
+               return;
+       vp = ndp->ni_vp;
+       if (vp->v_mount->m_flag & M_RDONLY)
+               u.u_error = EROFS;
+       else
+               u.u_error = VOP_SETATTR(vp, &vattr, ndp->ni_cred);
+       vput(vp);
+}
+
+ohpuxpause()
+{
+
+       for (;;)
+               sleep((caddr_t)&u, PSLEP);
+}
+
+/*
+ * The old fstat system call.
+ */
+ohpuxfstat()
+{
+       register struct a {
+               int     fd;
+               struct ohpuxstat *sb;
+       } *uap = (struct a *)u.u_ap;
+       struct file *fp;
+       extern struct file *getinode();
+
+       if ((unsigned)uap->fd >= NOFILE || (fp = u.u_ofile[uap->fd]) == NULL) {
+               u.u_error = EBADF;
+               return;
+       }
+       if (fp->f_type != DTYPE_VNODE) {
+               u.u_error = EINVAL;
+               return;
+       }
+       u.u_error = ohpuxstat1((struct vnode *)fp->f_data, uap->sb);
+}
+
+/*
+ * Old stat system call.  This version follows links.
+ */
+ohpuxstat()
+{
+       register struct a {
+               char    *fname;
+               struct ohpuxstat *sb;
+       } *uap = (struct a *)u.u_ap;
+       register struct nameidata *ndp = &u.u_nd;
+
+       ndp->ni_nameiop = LOOKUP | LOCKLEAF | FOLLOW;
+       ndp->ni_segflg = UIO_USERSPACE;
+       ndp->ni_dirp = uap->fname;
+       if (u.u_error = namei(ndp))
+               return;
+       u.u_error = ohpuxstat1(ndp->ni_vp, uap->sb);
+       vput(ndp->ni_vp);
+}
+
+int
+ohpuxstat1(vp, ub)
+       register struct vnode *vp;
+       struct ohpuxstat *ub;
+{
+       struct ohpuxstat ds;
+       struct vattr vattr;
+       register int error;
+
+       error = VOP_GETATTR(vp, &vattr, u.u_cred);
+       if (error)
+               return(error);
+       /*
+        * Copy from inode table
+        */
+       ds.ohst_dev = vattr.va_fsid;
+       ds.ohst_ino = (short)vattr.va_fileid;
+       ds.ohst_mode = (u_short)vattr.va_mode;
+       ds.ohst_nlink = vattr.va_nlink;
+       ds.ohst_uid = (short)vattr.va_uid;
+       ds.ohst_gid = (short)vattr.va_gid;
+       ds.ohst_rdev = (dev_t)vattr.va_rdev;
+       ds.ohst_size = (int)vattr.va_size;
+       ds.ohst_atime = (int)vattr.va_atime.tv_sec;
+       ds.ohst_mtime = (int)vattr.va_mtime.tv_sec;
+       ds.ohst_ctime = (int)vattr.va_ctime.tv_sec;
+       return (copyout((caddr_t)&ds, (caddr_t)ub, sizeof(ds)));
+}
+/* #endif */
+
+#endif
diff --git a/usr/src/sys/hp/hpux/hpux_exec.h b/usr/src/sys/hp/hpux/hpux_exec.h
new file mode 100644 (file)
index 0000000..703e9ac
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux_exec.h 1.4 88/05/24$
+ *
+ *     @(#)hpux_exec.h 7.1 (Berkeley) %G%
+ */
+
+/*
+ * HPUX a.out header format
+ */
+struct hpux_exec {
+       long    ha_magic;       /* magic number */
+       short   ha_version;     /* version ID */
+       short   ha_pad0;        /* doesn't matter */
+       long    ha_pad1;        /* ditto */
+unsigned long  ha_text;        /* size of text segment */
+unsigned long  ha_data;        /* size of initialized data */
+unsigned long  ha_bss;         /* size of uninitialized data */
+unsigned long  ha_pad2[5];     /* doesn't matter */
+unsigned long  ha_entry;       /* entry point */
+unsigned long  ha_pad3[4];     /* doesn't matter */
+};
+
+/*
+ * If the HPUX object file version number is BSDVNUM the file was built
+ * with the HPUX SGS but linked with the BSD libraries.
+ */
+#define BSDVNUM                0x2BAD
diff --git a/usr/src/sys/hp/hpux/hpux_net.c b/usr/src/sys/hp/hpux/hpux_net.c
new file mode 100644 (file)
index 0000000..c4774c0
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux_net.c 1.33 89/08/23$
+ *
+ *     @(#)hpux_net.c  7.1 (Berkeley) %G%
+ */
+
+/*
+ * Network related HP-UX compatibility routines
+ */
+
+#ifdef HPUXCOMPAT
+
+#include "param.h"
+#include "systm.h"
+#include "user.h"
+#include "kernel.h"
+#include "proc.h"
+#include "file.h"
+#include "mbuf.h"
+#include "socket.h"
+#include "socketvar.h"
+#include "ktrace.h"
+#include "hpux.h"
+
+#define MINBSDIPCCODE  0x3EE
+#define NUMBSDIPC      32
+
+/*
+ * HPUX netioctl() to BSD syscall map.
+ * Indexed by callno - MINBSDIPCCODE
+ */
+extern int socket(), listen(), bind(), accept(), connect(), orecv();
+extern int osend(), shutdown(), getsockname(), sendto();
+extern int recvfrom(), getpeername();
+int hpuxgetsockopt(), hpuxsetsockopt();
+struct file *getsock();
+
+struct hpuxtobsdipc {
+       int (*rout)();
+       int nargs;
+} hpuxtobsdipc[NUMBSDIPC] = {
+       socket,         3, /* 3ee */    listen,         2, /* 3ef */
+       bind,           3, /* 3f0 */    accept,         3, /* 3f1 */
+       connect,        3, /* 3f2 */    orecv,          4, /* 3f3 */
+       osend,          4, /* 3f4 */    shutdown,       2, /* 3f5 */
+       getsockname,    3, /* 3f6 */    hpuxsetsockopt, 5, /* 3f7 */
+       sendto,         6, /* 3f8 */    recvfrom,       6, /* 3f9 */
+       getpeername,    3, /* 3fa */    NULL,           0, /* 3fb */
+       NULL,           0, /* 3fc */    NULL,           0, /* 3fd */
+       NULL,           0, /* 3fe */    NULL,           0, /* 3ff */
+       NULL,           0, /* 400 */    NULL,           0, /* 401 */
+       NULL,           0, /* 402 */    NULL,           0, /* 403 */
+       NULL,           0, /* 404 */    NULL,           0, /* 405 */
+       NULL,           0, /* 406 */    NULL,           0, /* 407 */
+       NULL,           0, /* 408 */    NULL,           0, /* 409 */
+       NULL,           0, /* 40a */    hpuxgetsockopt, 5, /* 40b */
+       NULL,           0, /* 40c */    NULL,           0, /* 40d */
+};
+
+/*
+ * Single system call entry to BSD style IPC.
+ * Gleened from disassembled libbsdipc.a syscall entries.
+ */
+hpuxnetioctl()
+{
+       struct a {
+               int     call;
+               int     *args;
+       } *uap = (struct a *)u.u_ap;
+       int *args, i;
+       register int code;
+
+       args = uap->args;
+       code = uap->call - MINBSDIPCCODE;
+       if (code < 0 || code >= NUMBSDIPC || hpuxtobsdipc[code].rout == NULL) {
+               u.u_error = EINVAL;
+               return;
+       }
+       if ((i = hpuxtobsdipc[code].nargs * sizeof (int)) &&
+           (u.u_error = copyin((caddr_t)args, (caddr_t)u.u_arg, (u_int)i))) {
+#ifdef KTRACE
+                if (KTRPOINT(u.u_procp, KTR_SYSCALL))
+                        ktrsyscall(u.u_procp->p_tracep, code + MINBSDIPCCODE,
+                                  hpuxtobsdipc[code].nargs);
+#endif
+               return;
+       }
+#ifdef KTRACE
+        if (KTRPOINT(u.u_procp, KTR_SYSCALL))
+                ktrsyscall(u.u_procp->p_tracep, code + MINBSDIPCCODE,
+                          hpuxtobsdipc[code].nargs);
+#endif
+       (*hpuxtobsdipc[code].rout)();
+}
+
+hpuxsetsockopt()
+{
+       struct a {
+               int     s;
+               int     level;
+               int     name;
+               caddr_t val;
+               int     valsize;
+       } *uap = (struct a *)u.u_ap;
+       struct file *fp;
+       struct mbuf *m = NULL;
+       int tmp;
+
+       fp = getsock(uap->s);
+       if (fp == 0)
+               return;
+       if (uap->valsize > MLEN) {
+               u.u_error = EINVAL;
+               return;
+       }
+       if (uap->val) {
+               m = m_get(M_WAIT, MT_SOOPTS);
+               if (m == NULL) {
+                       u.u_error = ENOBUFS;
+                       return;
+               }
+               u.u_error =
+                   copyin(uap->val, mtod(m, caddr_t), (u_int)uap->valsize);
+               if (u.u_error) {
+                       (void) m_free(m);
+                       return;
+               }
+               if (uap->name == SO_LINGER) {
+                       tmp = *mtod(m, int *);
+                       mtod(m, struct linger *)->l_onoff = 1;
+                       mtod(m, struct linger *)->l_linger = tmp;
+                       m->m_len = sizeof(struct linger);
+               } else
+                       m->m_len = uap->valsize;
+       } else if (uap->name == ~SO_LINGER) {
+               m = m_get(M_WAIT, MT_SOOPTS);
+               if (m) {
+                       uap->name = SO_LINGER;
+                       mtod(m, struct linger *)->l_onoff = 0;
+                       m->m_len = sizeof(struct linger);
+               }
+       }
+       u.u_error =
+           sosetopt((struct socket *)fp->f_data, uap->level, uap->name, m);
+}
+
+hpuxgetsockopt()
+{
+       struct a {
+               int     s;
+               int     level;
+               int     name;
+               caddr_t val;
+               int     *avalsize;
+       } *uap = (struct a *)u.u_ap;
+       struct file *fp;
+       struct mbuf *m = NULL;
+       int valsize;
+
+       fp = getsock(uap->s);
+       if (fp == 0)
+               return;
+       if (uap->val) {
+               u.u_error = copyin((caddr_t)uap->avalsize, (caddr_t)&valsize,
+                       sizeof (valsize));
+               if (u.u_error)
+                       return;
+       } else
+               valsize = 0;
+       u.u_error =
+           sogetopt((struct socket *)fp->f_data, uap->level, uap->name, &m);
+       if (u.u_error)
+               goto bad;
+       if (uap->val && valsize && m != NULL) {
+               if (uap->name == SO_LINGER) {
+                       if (mtod(m, struct linger *)->l_onoff)
+                               *mtod(m, int *) = mtod(m, struct linger *)->l_linger;
+                       else
+                               *mtod(m, int *) = 0;
+                       m->m_len = sizeof(int);
+               }
+               if (valsize > m->m_len)
+                       valsize = m->m_len;
+               u.u_error = copyout(mtod(m, caddr_t), uap->val, (u_int)valsize);
+               if (u.u_error)
+                       goto bad;
+               u.u_error = copyout((caddr_t)&valsize, (caddr_t)uap->avalsize,
+                   sizeof (valsize));
+       }
+bad:
+       if (m != NULL)
+               (void) m_free(m);
+}
+#endif
diff --git a/usr/src/sys/hp/hpux/hpux_sig.c b/usr/src/sys/hp/hpux/hpux_sig.c
new file mode 100644 (file)
index 0000000..782336c
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux_compat.c 1.33 89/08/23$
+ *
+ *     @(#)hpux_sig.c  7.1 (Berkeley) %G%
+ */
+
+/*
+ * Signal related HPUX compatibility routines
+ */
+
+#ifdef HPUXCOMPAT
+
+#include "param.h"
+#include "systm.h"
+#include "user.h"
+#include "kernel.h"
+#include "proc.h"
+#include "hpux.h"
+
+/* indexed by HPUX signal number - 1 */
+char hpuxtobsdsigmap[NSIG] = {
+/*01*/ SIGHUP,  SIGINT, SIGQUIT, SIGILL,   SIGTRAP, SIGIOT,  SIGEMT,   SIGFPE,
+/*09*/  SIGKILL, SIGBUS, SIGSEGV, SIGSYS,   SIGPIPE, SIGALRM, SIGTERM,  SIGUSR1,
+/*17*/  SIGUSR2, SIGCHLD, 0,      SIGVTALRM,SIGPROF, SIGIO,   SIGWINCH, SIGSTOP,
+/*25*/ SIGTSTP, SIGCONT,SIGTTIN, SIGTTOU,  SIGURG,  0,       0,        0
+};
+
+/* indexed by BSD signal number - 1 */
+char bsdtohpuxsigmap[NSIG] = {
+/*01*/  1,  2,  3,  4,  5,  6,  7,  8,
+/*09*/   9, 10, 11, 12, 13, 14, 15, 29,
+/*17*/  24, 25, 26, 18, 27, 28, 22,  0,
+/*25*/  0, 20, 21, 23,  0, 16, 17,  0
+};
+
+/*
+ * XXX: In addition to mapping the signal number we also have
+ * to see if the "old" style signal mechinism is needed.
+ * If so, we set the OUSIG flag.  This is not really correct
+ * as under HP-UX "old" style handling can be set on a per
+ * signal basis and we are setting it for all signals in one
+ * swell foop.  I suspect we can get away with this since I
+ * doubt any program of interest mixes the two semantics.
+ */
+hpuxsigvec()
+{
+       register struct a {
+               int     signo;
+               struct  sigvec *nsv;
+               struct  sigvec *osv;
+       } *uap = (struct a  *)u.u_ap;
+       struct sigvec vec;
+       register struct sigvec *sv;
+       register int sig;
+       int bit;
+
+       sig = hpuxtobsdsig(uap->signo);
+       if (sig <= 0 || sig >= NSIG || sig == SIGKILL || sig == SIGSTOP) {
+               u.u_error = EINVAL;
+               return;
+       }
+       sv = &vec;
+       if (uap->osv) {
+               sv->sv_handler = u.u_signal[sig];
+               sv->sv_mask = u.u_sigmask[sig];
+               bit = sigmask(sig);
+               sv->sv_flags = 0;
+               if ((u.u_sigonstack & bit) != 0)
+                       sv->sv_flags |= SV_ONSTACK;
+               if ((u.u_sigintr & bit) != 0)
+                       sv->sv_flags |= SV_INTERRUPT;
+#if 0
+/* XXX -- SOUSIG no longer exists, do something here */
+               if (u.u_procp->p_flag & SOUSIG)
+                       sv->sv_flags |= HPUXSV_RESET;           /* XXX */
+#endif
+               u.u_error =
+                   copyout((caddr_t)sv, (caddr_t)uap->osv, sizeof (vec));
+               if (u.u_error)
+                       return;
+       }
+       if (uap->nsv) {
+               u.u_error =
+                   copyin((caddr_t)uap->nsv, (caddr_t)sv, sizeof (vec));
+               if (u.u_error)
+                       return;
+               if (sig == SIGCONT && sv->sv_handler == SIG_IGN) {
+                       u.u_error = EINVAL;
+                       return;
+               }
+               setsigvec(sig, (struct sigaction *)sv);
+#if 0
+/* XXX -- SOUSIG no longer exists, do something here */
+               if (sv->sv_flags & HPUXSV_RESET)
+                       u.u_procp->p_flag |= SOUSIG;            /* XXX */
+#endif
+       }
+}
+
+hpuxsigblock()
+{
+       struct a {
+               int     mask;
+       } *uap = (struct a *)u.u_ap;
+
+       (void) splhigh();
+       u.u_r.r_val1 = bsdtohpuxmask(u.u_procp->p_sigmask);
+       u.u_procp->p_sigmask |= hpuxtobsdmask(uap->mask) &~ sigcantmask;
+       (void) spl0();
+}
+
+hpuxsigsetmask()
+{
+       struct a {
+               int     mask;
+       } *uap = (struct a *)u.u_ap;
+
+       (void) splhigh();
+       u.u_r.r_val1 = bsdtohpuxmask(u.u_procp->p_sigmask);
+       u.u_procp->p_sigmask = hpuxtobsdmask(uap->mask) &~ sigcantmask;
+       (void) spl0();
+}
+
+hpuxsigpause()
+{
+       struct a {
+               int     mask;
+       } *uap = (struct a *)u.u_ap;
+
+       uap->mask = hpuxtobsdmask(uap->mask);
+       sigsuspend();
+}
+
+/* not totally correct, but close enuf' */
+hpuxkill()
+{
+       struct a {
+               int     pid;
+               int     signo;
+       } *uap = (struct a *)u.u_ap;
+
+       if (uap->signo) {
+               uap->signo = hpuxtobsdsig(uap->signo);
+               if (uap->signo == 0)
+                       uap->signo = NSIG;
+       }
+       kill();
+}
+
+ohpuxssig()
+{
+       struct a {
+               int     signo;
+               sig_t   fun;
+       } *uap = (struct a *)u.u_ap;
+       register int a;
+       struct sigvec vec;
+       register struct sigvec *sv = &vec;
+       struct proc *p = u.u_procp;
+
+       a = hpuxtobsdsig(uap->signo);
+       sv->sv_handler = uap->fun;
+       /*
+        * Kill processes trying to use job control facilities
+        * (this'll help us find any vestiges of the old stuff).
+        */
+       if ((a &~ 0377) ||
+           (sv->sv_handler != SIG_DFL && sv->sv_handler != SIG_IGN &&
+            ((int)sv->sv_handler) & 1)) {
+               psignal(p, SIGSYS);
+               return;
+       }
+       if (a <= 0 || a >= NSIG || a == SIGKILL || a == SIGSTOP ||
+           a == SIGCONT && sv->sv_handler == SIG_IGN) {
+               u.u_error = EINVAL;
+               return;
+       }
+       sv->sv_mask = 0;
+       sv->sv_flags = SV_INTERRUPT;
+       u.u_r.r_val1 = (int)u.u_signal[a];
+       setsigvec(a, (struct sigaction *)sv);
+#if 0
+       p->p_flag |= SOUSIG;            /* mark as simulating old stuff */
+#endif
+}
+
+/* signal numbers: convert from HPUX to BSD */
+hpuxtobsdsig(sig)
+       register int sig;
+{
+       if (--sig < 0 || sig >= NSIG)
+               return(0);
+       return((int)hpuxtobsdsigmap[sig]);
+}
+
+/* signal numbers: convert from BSD to HPUX */
+bsdtohpuxsig(sig)
+       register int sig;
+{
+       if (--sig < 0 || sig >= NSIG)
+               return(0);
+       return((int)bsdtohpuxsigmap[sig]);
+}
+
+/* signal masks: convert from HPUX to BSD (not pretty or fast) */
+hpuxtobsdmask(mask)
+       register int mask;
+{
+       register int nmask, sig, nsig;
+
+       if (mask == 0 || mask == -1)
+               return(mask);
+       nmask = 0;
+       for (sig = 1; sig < NSIG; sig++)
+               if ((mask & sigmask(sig)) && (nsig = hpuxtobsdsig(sig)))
+                       nmask |= sigmask(nsig);
+       return(nmask);
+}
+
+bsdtohpuxmask(mask)
+       register int mask;
+{
+       register int nmask, sig, nsig;
+
+       if (mask == 0 || mask == -1)
+               return(mask);
+       nmask = 0;
+       for (sig = 1; sig < NSIG; sig++)
+               if ((mask & sigmask(sig)) && (nsig = bsdtohpuxsig(sig)))
+                       nmask |= sigmask(nsig);
+       return(nmask);
+}
+#endif
diff --git a/usr/src/sys/hp/hpux/hpux_termio.h b/usr/src/sys/hp/hpux/hpux_termio.h
new file mode 100644 (file)
index 0000000..2afbabd
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux.h 1.15 89/09/25$
+ *
+ *     @(#)hpux_termio.h       7.1 (Berkeley) %G%
+ */
+
+/* HP-UX termio stuff */
+
+#define        HPUXNCC 8
+
+/* control characters */
+#define        HPUXVINTR       0
+#define        HPUXVQUIT       1
+#define        HPUXVERASE      2
+#define        HPUXVKILL       3
+#define        HPUXVEOF        4
+#define        HPUXVEOL        5
+#define        HPUXVMIN        4
+#define        HPUXVTIME       5
+
+/* input modes */
+#define        TIO_IGNBRK      0000001
+#define        TIO_BRKINT      0000002
+#define        TIO_IGNPAR      0000004
+#define        TIO_PARMRK      0000010
+#define        TIO_INPCK       0000020
+#define        TIO_ISTRIP      0000040
+#define        TIO_INLCR       0000100
+#define        TIO_IGNCR       0000200
+#define        TIO_ICRNL       0000400
+#define        TIO_IUCLC       0001000
+#define        TIO_IXON        0002000
+#define        TIO_IXANY       0004000
+#define        TIO_IXOFF       0010000
+#define        TIO_IENQAK      0020000
+
+/* output modes */
+#define        TIO_OPOST       0000001
+#define        TIO_OLCUC       0000002
+#define        TIO_ONLCR       0000004
+#define        TIO_OCRNL       0000010
+#define        TIO_ONOCR       0000020
+#define        TIO_ONLRET      0000040
+#define        TIO_OFILL       0000100
+#define        TIO_OFDEL       0000200
+#define        TIO_NLDLY       0000400
+#define        TIO_NL0         0
+#define        TIO_NL1         0000400
+#define        TIO_CRDLY       0003000
+#define        TIO_CR0         0
+#define        TIO_CR1         0001000
+#define        TIO_CR2         0002000
+#define        TIO_CR3         0003000
+#define        TIO_TABDLY      0014000
+#define        TIO_TAB0        0
+#define        TIO_TAB1        0004000
+#define        TIO_TAB2        0010000
+#define        TIO_TAB3        0014000
+#define        TIO_BSDLY       0020000
+#define        TIO_BS0         0
+#define        TIO_BS1         0020000
+#define        TIO_VTDLY       0040000
+#define        TIO_VT0         0
+#define        TIO_VT1         0040000
+#define        TIO_FFDLY       0100000
+#define        TIO_FF0         0
+#define        TIO_FF1         0100000
+
+/* control modes */
+#define        TIO_CBAUD       0000037
+#define        TIO_B0          0
+#define        TIO_B50         0000001
+#define        TIO_B75         0000002
+#define        TIO_B110        0000003
+#define        TIO_B134        0000004
+#define        TIO_B150        0000005
+#define        TIO_B200        0000006
+#define        TIO_B300        0000007
+#define        TIO_B600        0000010
+#define        TIO_B900        0000011
+#define        TIO_B1200       0000012
+#define        TIO_B1800       0000013
+#define        TIO_B2400       0000014
+#define        TIO_B3600       0000015
+#define        TIO_B4800       0000016
+#define        TIO_B7200       0000017
+#define        TIO_B9600       0000020
+#define        TIO_B19200      0000021
+#define        TIO_B38400      0000022
+#define        TIO_EXTA        0000036
+#define        TIO_EXTB        0000037
+#define        TIO_CSIZE       0000140
+#define        TIO_CS5         0
+#define        TIO_CS6         0000040
+#define        TIO_CS7         0000100
+#define        TIO_CS8         0000140
+#define        TIO_CSTOPB      0000200
+#define        TIO_CREAD       0000400
+#define        TIO_PARENB      0001000
+#define        TIO_PARODD      0002000
+#define        TIO_HUPCL       0004000
+#define        TIO_CLOCAL      0010000
+#define TIO_CRTS       0020000 /* Obsolete */
+
+/* line discipline 0 modes */
+#define        TIO_ISIG        0000001
+#define        TIO_ICANON      0000002
+#define        TIO_XCASE       0000004
+#define        TIO_ECHO        0000010
+#define        TIO_ECHOE       0000020
+#define        TIO_ECHOK       0000040
+#define        TIO_ECHONL      0000100
+#define        TIO_NOFLSH      0000200
+
+struct hpuxtermio {
+       u_short c_iflag;        /* input modes */
+       u_short c_oflag;        /* output modes */
+       u_short c_cflag;        /* control modes */
+       u_short c_lflag;        /* line discipline modes */
+       char    c_line;         /* line discipline */
+       u_char  c_cc[HPUXNCC];  /* control chars */
+};
+
+#define        HPUXTCGETA      _IOR('T', 1, struct hpuxtermio)
+#define        HPUXTCSETA      _IOW('T', 2, struct hpuxtermio)
+#define        HPUXTCSETAW     _IOW('T', 3, struct hpuxtermio)
+#define        HPUXTCSETAF     _IOW('T', 4, struct hpuxtermio)
diff --git a/usr/src/sys/hp/hpux/hpux_tty.c b/usr/src/sys/hp/hpux/hpux_tty.c
new file mode 100644 (file)
index 0000000..e158860
--- /dev/null
@@ -0,0 +1,371 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hpux_tty.c 1.7 89/04/11$
+ *
+ *     @(#)hpux_tty.c  7.1 (Berkeley) %G%
+ */
+
+/*
+ * stty/gtty/termio emulation stuff
+ */
+#ifdef HPUXCOMPAT
+
+#include "param.h"
+#include "systm.h"
+#include "user.h"
+#include "ioctl.h"
+#include "tty.h"
+#include "proc.h"
+#include "file.h"
+#include "conf.h"
+#include "buf.h"
+#include "uio.h"
+#include "kernel.h"
+
+#include "hpux.h"
+#include "hpux_termio.h"
+
+char hpuxtobsdbaud[32] = {
+       B0,     B50,    B75,    B110,   B134,   B150,   B200,   B300,
+       B600,   B0,     B1200,  B1800,  B2400,  B0,     B4800,  B0,
+       B9600,  EXTA,   EXTB,   B0,     B0,     B0,     B0,     B0,
+       B0,     B0,     B0,     B0,     B0,     B0,     B0,     B0
+};
+
+char bsdtohpuxbaud[16] = {
+       TIO_B0,         TIO_B50,        TIO_B75,        TIO_B110,
+       TIO_B134,       TIO_B150,       TIO_B200,       TIO_B300,
+       TIO_B600,       TIO_B1200,      TIO_B1800,      TIO_B2400,
+       TIO_B4800,      TIO_B9600,      TIO_B19200,     TIO_B38400
+};
+
+/*
+ * Map BSD style sgtty info to and from SYS5 style termio stuff.
+ * Map BSD style sgtty info to and from V7 style sgtty stuff.
+ */
+hpuxtermio(fp, com, data)
+       struct file *fp;
+       caddr_t data;
+{
+       struct sgttyb sg;
+       struct bsdtchars {      /* avoid problem with ttychars.h */
+               char bsdt_intrc;
+               char bsdt_quitc;
+               char bsdt_startc;
+               char bsdt_stopc;
+               char bsdt_eofc;
+               char bsdt_brkc;
+       } tc;
+       struct bsdltchars {     /* avoid problem with ttychars.h */
+               char bsdt_suspc;
+               char bsdt_dsuspc;
+               char bsdt_rprntc;
+               char bsdt_flushc;
+               char bsdt_werasc;
+               char bsdt_lnextc;
+       } ltc;
+       int lmode, (*ioctlrout)();
+       register u_short flag;
+       register struct hpuxtermio *tiop;
+
+       ioctlrout = fp->f_ops->fo_ioctl;
+       tiop = (struct hpuxtermio *)data;
+       switch (com) {
+       case HPUXTCGETA:
+               /* get everything we might need */
+               bzero(data, sizeof(struct hpuxtermio));
+               if (u.u_error = ioctlrout(fp, TIOCGETP, (caddr_t)&sg))
+                       break;
+               (void) ioctlrout(fp, TIOCGETC, (caddr_t)&tc);
+               (void) ioctlrout(fp, TIOCLGET, (caddr_t)&lmode);
+
+               /* set baud rate */
+               tiop->c_cflag = (u_short)bsdtohpuxbaud[sg.sg_ispeed&0xF];
+
+               /* set editing chars except for EOF/EOL (set below) */
+               tiop->c_cc[HPUXVINTR] = tc.bsdt_intrc;
+               tiop->c_cc[HPUXVQUIT] = tc.bsdt_quitc;
+               tiop->c_cc[HPUXVERASE] = sg.sg_erase;
+               tiop->c_cc[HPUXVKILL] = sg.sg_kill;
+
+               /* set flags */
+               flag = sg.sg_flags;
+               if ((flag & TBDELAY) == XTABS)
+                       tiop->c_oflag |= TIO_TAB3;
+               else if (flag & TBDELAY)
+                       tiop->c_oflag |= TIO_TAB1;
+               if (flag & LCASE) {
+                       tiop->c_iflag |= TIO_IUCLC;
+                       tiop->c_oflag |= TIO_OLCUC;
+                       tiop->c_lflag |= TIO_XCASE;
+               }
+               if (flag & ECHO)
+                       tiop->c_lflag |= TIO_ECHO;
+               if (flag & CRMOD) {
+                       tiop->c_iflag |= TIO_ICRNL;
+                       tiop->c_oflag |= TIO_ONLCR;
+                       if (flag & CR1)
+                               tiop->c_oflag |= TIO_CR1;
+                       if (flag & CR2)
+                               tiop->c_oflag |= TIO_CR2|TIO_ONOCR;
+               } else {
+                       tiop->c_oflag |= TIO_ONLRET;
+                       if (flag & NL1)
+                               tiop->c_oflag |= TIO_CR1;
+                       if (flag & NL2)
+                               tiop->c_oflag |= TIO_CR2;
+               }
+               if (flag & RAW) {
+                       tiop->c_cflag |= TIO_CS8;
+                       tiop->c_iflag &= ~(TIO_ICRNL|TIO_IUCLC);
+                       tiop->c_cc[HPUXVMIN] = 6;
+                       tiop->c_cc[HPUXVTIME] = 1;
+               } else {
+                       tiop->c_iflag |= TIO_BRKINT;
+                       if (tc.bsdt_startc == CSTART && tc.bsdt_stopc == CSTOP)
+                               tiop->c_iflag |= TIO_IXON;
+                       if (flag & TANDEM)
+                               tiop->c_iflag |= TIO_IXOFF;
+                       else if ((lmode & LDECCTQ) == 0)
+                               tiop->c_iflag |= TIO_IXANY;
+                       if ((lmode & LLITOUT) == 0) {
+                               tiop->c_iflag |= TIO_IGNPAR;
+                               tiop->c_oflag |= TIO_OPOST;
+                       }
+                       if (lmode & LPASS8)
+                               tiop->c_cflag |= TIO_CS8;
+                       else
+                               tiop->c_iflag |= TIO_ISTRIP;
+                       tiop->c_cflag |= TIO_CS7|TIO_PARENB;
+                       tiop->c_lflag |= TIO_ISIG;
+                       if (flag & CBREAK) {
+                               tiop->c_cc[HPUXVMIN] = 6;
+                               tiop->c_cc[HPUXVTIME] = 1;
+                       } else {
+                               tiop->c_lflag |= TIO_ICANON|TIO_ECHOK;
+                               if (lmode & LCRTERA)
+                                       tiop->c_lflag |= TIO_ECHOE;
+                               tiop->c_cc[HPUXVEOF] = tc.bsdt_eofc;
+                               tiop->c_cc[HPUXVEOL] = tc.bsdt_brkc;
+                       }
+               }
+               tiop->c_cflag |= TIO_PARENB;
+               if (flag & ODDP) {
+                       if (flag & EVENP)
+                               tiop->c_cflag &= ~TIO_PARENB;
+                       tiop->c_cflag |= TIO_PARODD;
+               }
+               if (tiop->c_cflag & TIO_PARENB)
+                       tiop->c_iflag |= TIO_INPCK;
+               if (flag & VTDELAY)
+                       tiop->c_oflag |= TIO_FFDLY;
+               if (flag & BSDELAY)
+                       tiop->c_oflag |= TIO_BSDLY;
+               break;
+
+       case HPUXTCSETA:
+       case HPUXTCSETAW:
+       case HPUXTCSETAF:
+               /* get old lmode and determine if we are a tty */
+               if (u.u_error = ioctlrout(fp, TIOCLGET, (caddr_t)&lmode))
+                       break;
+               (void) ioctlrout(fp, TIOCGLTC, (caddr_t)&ltc);
+
+               /* set baud rate */
+               sg.sg_ispeed = hpuxtobsdbaud[tiop->c_cflag&TIO_CBAUD];
+               sg.sg_ospeed = sg.sg_ispeed;
+
+               /* set special chars to defaults for cooked mode */
+               sg.sg_erase = tiop->c_cc[HPUXVERASE];
+               sg.sg_kill = tiop->c_cc[HPUXVKILL];
+               tc.bsdt_intrc = tiop->c_cc[HPUXVINTR];
+               tc.bsdt_quitc = tiop->c_cc[HPUXVQUIT];
+               tc.bsdt_startc = CSTART;
+               tc.bsdt_stopc = CSTOP;
+               tc.bsdt_eofc = tiop->c_cc[HPUXVEOF];
+               tc.bsdt_brkc = tiop->c_cc[HPUXVEOL];
+               ltc.bsdt_suspc = CSUSP;
+               ltc.bsdt_dsuspc = CDSUSP;
+               ltc.bsdt_flushc = CFLUSH;
+               ltc.bsdt_lnextc = CLNEXT;
+
+               /* set flags */
+               flag = 0;
+               if (tiop->c_oflag & TIO_BSDLY)
+                       flag |= BSDELAY;
+               if (tiop->c_oflag & TIO_FFDLY)
+                       flag |= VTDELAY;
+               if (tiop->c_oflag & TIO_TAB1) {
+                       if (tiop->c_oflag & TIO_TAB2)
+                               flag |= XTABS;
+                       else
+                               flag |= TAB1;
+               } else if (tiop->c_oflag & TIO_TAB2)
+                       flag |= TAB2;
+               if (tiop->c_oflag & TIO_CR1) {
+                       flag |= CR1;
+                       if (tiop->c_oflag & TIO_ONLRET)
+                               flag |= NL1;
+               }
+               if (tiop->c_oflag & TIO_CR2) {
+                       flag |= CR2;
+                       if (tiop->c_oflag & TIO_ONLRET)
+                               flag |= NL2;
+               }
+               if ((tiop->c_oflag & (TIO_NLDLY|TIO_ONLRET)) == TIO_NLDLY)
+                       flag |= NL2;
+               if ((tiop->c_cflag & TIO_PARENB) == 0)
+                       flag |= ODDP|EVENP;
+               else if (tiop->c_cflag & TIO_PARODD)
+                       flag |= ODDP;
+               else
+                       flag |= EVENP;
+               if ((tiop->c_iflag & TIO_ICRNL) || (tiop->c_oflag & TIO_ONLCR))
+                       flag |= CRMOD;
+               if (tiop->c_lflag & TIO_ECHO)
+                       flag |= ECHO;
+               if (tiop->c_iflag & TIO_IUCLC)
+                       flag |= LCASE;
+               if (tiop->c_iflag & TIO_IXOFF)
+                       flag |= TANDEM;
+               if ((tiop->c_lflag & TIO_ICANON) == 0) {
+                       if (tiop->c_lflag & TIO_ISIG)
+                               flag |= CBREAK;
+                       else
+                               flag |= RAW;
+               }
+               if (flag & CBREAK) {
+                       ltc.bsdt_suspc = ltc.bsdt_dsuspc = -1;
+                       ltc.bsdt_flushc = ltc.bsdt_lnextc = -1;
+                       if ((tiop->c_iflag & TIO_IXON) == 0)
+                               tc.bsdt_startc = tc.bsdt_stopc = -1;
+               }
+               sg.sg_flags = flag;
+               lmode &= ~(LCRTERA|LLITOUT|LDECCTQ|LPASS8);
+               if (tiop->c_lflag & TIO_ECHOE)
+                       lmode |= LCRTERA;
+               if ((tiop->c_oflag & TIO_OPOST) == 0)
+                       lmode |= LLITOUT;
+               if ((tiop->c_iflag & TIO_IXANY) == 0)
+                       lmode |= LDECCTQ;
+               if ((tiop->c_cflag & TIO_CS8) &&
+                   (tiop->c_iflag & TIO_ISTRIP) == 0)
+                       lmode |= LPASS8;
+
+               /* set the new stuff */
+               if (com == HPUXTCSETA)
+                       com = TIOCSETN;
+               else
+                       com = TIOCSETP;
+               (void) ioctlrout(fp, com, (caddr_t)&sg);
+               (void) ioctlrout(fp, TIOCSETC, (caddr_t)&tc);
+               (void) ioctlrout(fp, TIOCSLTC, (caddr_t)&ltc);
+               (void) ioctlrout(fp, TIOCLSET, (caddr_t)&lmode);
+               if (tiop->c_cflag & TIO_HUPCL)
+                       (void) ioctlrout(fp, TIOCHPCL, (caddr_t)0);
+               break;
+
+       case HPUXTIOCGETP:
+               u.u_error = ioctlrout(fp, TIOCGETP, (caddr_t)&sg);
+               if (u.u_error)
+                       break;
+               flag = sg.sg_flags;
+               sg.sg_flags &= ~(V7_HUPCL|V7_XTABS|V7_NOAL);
+               if (flag & XTABS)
+                       sg.sg_flags |= V7_XTABS;
+               bcopy((caddr_t)&sg, data, sizeof sg);
+               break;
+
+       case HPUXTIOCSETP:
+               bcopy(data, (caddr_t)&sg, sizeof sg);
+               flag = sg.sg_flags;
+               sg.sg_flags &= ~(V7_HUPCL|V7_XTABS|V7_NOAL);
+               if (flag & V7_XTABS)
+                       sg.sg_flags |= XTABS;
+               u.u_error = ioctlrout(fp, TIOCSETP, (caddr_t)&sg);
+               if (flag & V7_HUPCL)
+                       (void) ioctlrout(fp, TIOCHPCL, (caddr_t)0);
+               break;
+
+       default:
+               break;
+       }
+       return(u.u_error);
+}
+
+/* #ifdef COMPAT */
+ohpuxgtty()
+{
+       struct a {
+               int     fdes;
+               caddr_t cmarg;
+       } *uap = (struct a *)u.u_ap;
+
+       getsettty(uap->fdes, HPUXTIOCGETP, uap->cmarg);
+}
+
+ohpuxstty()
+{
+       struct a {
+               int     fdes;
+               caddr_t cmarg;
+       } *uap = (struct a *)u.u_ap;
+
+       getsettty(uap->fdes, HPUXTIOCSETP, uap->cmarg);
+}
+
+/*
+ * Simplified version of ioctl() for use by
+ * gtty/stty and TIOCGETP/TIOCSETP.
+ */
+getsettty(fdes, com, cmarg)
+       int fdes, com;
+       caddr_t cmarg;
+{
+       register struct file *fp;
+       struct hpuxsgttyb hsb;
+       struct sgttyb sb;
+
+       if ((unsigned)fdes >= NOFILE || (fp = u.u_ofile[fdes]) == NULL) {
+               u.u_error = EBADF;
+               return;
+       }
+       if ((fp->f_flag & (FREAD|FWRITE)) == 0) {
+               u.u_error = EBADF;
+               return;
+       }
+       if (com == HPUXTIOCSETP) {
+               u.u_error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb);
+               if (u.u_error)
+                       return;
+               sb.sg_ispeed = hsb.sg_ispeed;
+               sb.sg_ospeed = hsb.sg_ospeed;
+               sb.sg_erase = hsb.sg_erase;
+               sb.sg_kill = hsb.sg_kill;
+               sb.sg_flags = (short) hsb.sg_flags;
+               com = TIOCSETP;
+       } else {
+               bzero((caddr_t)&hsb, sizeof hsb);
+               com = TIOCGETP;
+       }
+       u.u_error = (*fp->f_ops->fo_ioctl)(fp, com, (caddr_t)&sb);
+       if (u.u_error == 0 && com == TIOCGETP) {
+               hsb.sg_ispeed = sb.sg_ispeed;
+               hsb.sg_ospeed = sb.sg_ospeed;
+               hsb.sg_erase = sb.sg_erase;
+               hsb.sg_kill = sb.sg_kill;
+               hsb.sg_flags = (int) sb.sg_flags;
+               u.u_error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
+       }
+}
+/* #endif */
+#endif
diff --git a/usr/src/sys/hp300/stand/autoconf.c b/usr/src/sys/hp300/stand/autoconf.c
new file mode 100644 (file)
index 0000000..982276e
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: autoconf.c 1.9 89/10/07$
+ *
+ *     @(#)autoconf.c  7.1 (Berkeley) %G%
+ */
+
+#include "samachdep.h"
+#include "param.h"
+
+#include "../hpdev/device.h"
+#include "../hpdev/grfvar.h"
+
+struct hp_hw sc_table[MAX_CTLR];
+
+configure()
+{
+       find_devs();
+       cninit();
+       hpibinit();
+       scsiinit();
+}
+
+sctoaddr(sc)
+       int sc;
+{
+       extern int internalhpib;
+
+       if (sc == -2)
+               return(0x1000000);
+       if (sc == -1)
+               return(GRFIADDR);
+       if (sc == 7)
+               return(internalhpib);
+       if (sc < 32)
+               return(0x600000+(0x10000*sc));
+       return(sc);
+}
+
+/*
+ * Probe all select codes (0 - 32) and internal display address.
+ * Note that we only care about displays, SCSIs and HP-IBs.
+ */
+find_devs()
+{
+       u_char *id_reg;
+       register short sc;
+       register int addr;
+       register struct hp_hw *hw;
+
+       hw = sc_table;
+       for (sc = -2; sc < 32; sc++) {
+               addr = sctoaddr(sc);
+               if (badaddr(addr))
+                       continue;
+
+               id_reg = (u_char *) addr;
+               hw->hw_addr = (char *) addr;
+               hw->hw_id = id_reg[1] & 0xff;
+               hw->hw_sc = sc;
+
+               switch (hw->hw_id) {
+               case 8:         /* 98625B */
+               case 128:       /* 98624A */
+                       hw->hw_type = HPIB;
+                       break;
+               case 57:        /* Displays */
+                       hw->hw_type = BITMAP;
+                       hw->hw_id2 = id_reg[0x15];
+                       switch (hw->hw_id2) {
+                       case 4: /* renaissance */
+                       case 8: /* davinci */
+                               sc++;           /* occupy 2 select codes */
+                               break;
+                       }
+                       break;
+               case 9:
+                       hw->hw_type = KEYBOARD;
+                       break;
+               case 7:
+               case 39:
+               case 71:
+               case 103:
+                       hw->hw_type = SCSI;
+                       break;
+               default:        /* who cares */
+                       hw->hw_type = MISC;
+                       break;
+               }
+               hw++;
+       }
+}
diff --git a/usr/src/sys/hp300/stand/boot.c b/usr/src/sys/hp300/stand/boot.c
new file mode 100644 (file)
index 0000000..924ed0b
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)boot.c      7.1 (Berkeley) %G%
+ */
+
+#include <a.out.h>
+#include "saio.h"
+#include "../sys/reboot.h"
+
+#ifndef INSECURE
+#include "../sys/stat.h"
+struct stat sb;
+#endif
+
+#define B_MAKEDEV(a,u,p,t) \
+       (((a) << B_ADAPTORSHIFT) | ((u) << B_UNITSHIFT) | \
+        ((p) << B_PARTITIONSHIFT) | ((t) << B_TYPESHIFT))
+
+/*
+ * Boot program... arguments in `devtype' and `howto' determine
+ * whether boot stops to ask for system name and which device
+ * boot comes from.
+ */
+
+/* Types in `devtype' specifying major device */
+char   devname[][2] = {
+       0,0,            /* 0 = ct */
+       0,0,            /* 1 = fd */
+       'r','d',        /* 2 = rd */
+       0,0,            /* 3 = sw */
+       's','d',        /* 4 = sd */
+};
+#define        MAXTYPE (sizeof(devname) / sizeof(devname[0]))
+
+#define        UNIX    "vmunix"
+char line[100];
+
+int    retry = 0;
+extern char *lowram;
+extern int noconsole;
+extern int howto, devtype;
+
+#define        MSUS (0xfffffedc)
+
+char rom2mdev[] = {
+       0,      /*  0 - none */
+       0,      /*  1 - none */
+       0,      /*  2 - none */
+       0,      /*  3 - none */
+       0,      /*  4 - none */
+       0,      /*  5 - none */
+       0,      /*  6 - none */
+       0,      /*  7 - none */
+       0,      /*  8 - none */
+       0,      /*  9 - none */
+       0,      /* 10 - none */
+       0,      /* 11 - none */
+       0,      /* 12 - none */
+       0,      /* 13 - none */
+       4,      /* 14 - SCSI disk */
+       0,      /* 15 - none */
+       2,      /* 16 - CS/80 device on HPIB */
+       2,      /* 17 - CS/80 device on HPIB */
+       0,      /* 18 - none */
+       0,      /* 19 - none */
+       0,      /* 20 - none */
+       0,      /* 21 - none */
+       0,      /* 22 - none */
+       0,      /* 23 - none */
+       0,      /* 24 - none */
+       0,      /* 25 - none */
+       0,      /* 26 - none */
+       0,      /* 27 - none */
+       0,      /* 28 - none */
+       0,      /* 29 - none */
+       0,      /* 30 - none */
+       0,      /* 31 - none */
+};
+
+main()
+{
+       register type, part, unit, io;
+       register char *cp;
+
+       printf("\nBoot\n");
+#ifdef JUSTASK
+       howto = RB_ASKNAME|RB_SINGLE;
+#else
+       type = (devtype >> B_TYPESHIFT) & B_TYPEMASK;
+       unit = (devtype >> B_UNITSHIFT) & B_UNITMASK;
+       unit += 8 * ((devtype >> B_ADAPTORSHIFT) & B_ADAPTORMASK);
+       part = (devtype >> B_PARTITIONSHIFT) & B_PARTITIONMASK;
+       if ((howto & RB_ASKNAME) == 0) {
+               if ((devtype & B_MAGICMASK) != B_DEVMAGIC) {
+                       /*
+                        * we have to map the ROM device type codes
+                        * to Unix major device numbers.
+                        */
+                       type = rom2mdev[*(char *)MSUS & 0x1f];
+                       devtype = (devtype &~ (B_TYPEMASK << B_TYPESHIFT))
+                                 | (type << B_TYPESHIFT);
+               }
+               if (type >= 0 && type <= MAXTYPE && devname[type][0]) {
+                       cp = line;
+                       *cp++ = devname[type][0];
+                       *cp++ = devname[type][1];
+                       *cp++ = '(';
+                       if (unit >= 10)
+                               *cp++ = unit / 10 + '0';
+                       *cp++ = unit % 10 + '0';
+                       *cp++ = ',';
+                       *cp++ = part + '0';
+                       *cp++ = ')';
+                       strcpy(cp, UNIX);
+               } else
+                       howto = RB_SINGLE|RB_ASKNAME;
+       }
+#endif
+       for (;;) {
+               if (!noconsole && (howto & RB_ASKNAME)) {
+                       printf(": ");
+                       gets(line);
+               } else
+                       printf(": %s\n", line);
+               io = open(line, 0);
+               if (io >= 0) {
+#ifndef INSECURE
+                       (void) fstat(io, &sb);
+                       if (sb.st_uid || (sb.st_mode & 2)) {
+                               printf("non-secure file, will not load\n");
+                               howto = RB_SINGLE|RB_ASKNAME;
+                               continue;
+                       }
+#endif
+                       if (howto & RB_ASKNAME) {
+                               /*
+                                * Build up devtype register to pass on to
+                                * booted program.
+                                */ 
+                               cp = line;
+                               for (type = 0; type <= MAXTYPE; type++)
+                                       if ((devname[type][0] == cp[0]) && 
+                                           (devname[type][1] == cp[1]))
+                                               break;
+                               if (type <= MAXTYPE) {
+                                       cp += 3;
+                                       unit = *cp++ - '0';
+                                       if (*cp >= '0' && *cp <= '9')
+                                               unit = unit * 10 + *cp++ - '0';
+                                       cp++;
+                                       part = atol(cp);
+                                       devtype = B_MAKEDEV(unit >> 3, unit & 7, part, type);
+                               }
+                       }
+                       devtype |= B_DEVMAGIC;
+                       copyunix(howto, devtype, io);
+                       close(io);
+                       howto = RB_SINGLE|RB_ASKNAME;
+               }
+       bad:
+               if (++retry > 2)
+                       howto = RB_SINGLE|RB_ASKNAME;
+       }
+}
+
+/*ARGSUSED*/
+copyunix(howto, devtype, io)
+       register howto;         /* d7 contains boot flags */
+       register devtype;       /* d6 contains boot device */
+       register io;
+{
+       struct exec x;
+       register int i;
+       register char *load;    /* a5 contains load addr for unix */
+       register char *addr;
+
+       i = read(io, (char *)&x, sizeof x);
+       if (i != sizeof x ||
+           (x.a_magic != 0407 && x.a_magic != 0413 && x.a_magic != 0410))
+               _stop("Bad format\n");
+       printf("%d", x.a_text);
+       if (x.a_magic == 0413 && lseek(io, 0x400, 0) == -1)
+               goto shread;
+       load = addr = lowram;
+       if (read(io, (char *)addr, x.a_text) != x.a_text)
+               goto shread;
+       addr += x.a_text;
+       if (x.a_magic == 0413 || x.a_magic == 0410)
+               while ((int)addr & CLOFSET)
+                       *addr++ = 0;
+       printf("+%d", x.a_data);
+       if (read(io, addr, x.a_data) != x.a_data)
+               goto shread;
+       addr += x.a_data;
+       printf("+%d", x.a_bss);
+       x.a_bss += 128*512;     /* slop */
+       for (i = 0; i < x.a_bss; i++)
+               *addr++ = 0;
+       x.a_entry += (int)lowram;
+       printf(" start 0x%x\n", x.a_entry);
+#ifdef __GNUC__
+       asm("   movl %0,d7" : : "m" (howto));
+       asm("   movl %0,d6" : : "m" (devtype));
+       asm("   movl %0,a5" : : "a" (load));
+#endif
+       (*((int (*)()) x.a_entry))();
+       exit();
+shread:
+       _stop("Short read\n");
+}
diff --git a/usr/src/sys/hp300/stand/conf.c b/usr/src/sys/hp300/stand/conf.c
new file mode 100644 (file)
index 0000000..37fd2dc
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)conf.c      7.1 (Berkeley) %G%
+ */
+
+#include "saio.h"
+
+devread(io)
+       register struct iob *io;
+{
+       int cc;
+
+       /* check for interrupt */
+       (void) peekchar();
+
+       io->i_flgs |= F_RDDATA;
+       io->i_error = 0;
+       cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, READ);
+       io->i_flgs &= ~F_TYPEMASK;
+       return (cc);
+}
+
+devwrite(io)
+       register struct iob *io;
+{
+       int cc;
+
+       io->i_flgs |= F_WRDATA;
+       io->i_error = 0;
+       cc = (*devsw[io->i_ino.i_dev].dv_strategy)(io, WRITE);
+       io->i_flgs &= ~F_TYPEMASK;
+       return (cc);
+}
+
+devopen(io)
+       register struct iob *io;
+{
+
+       (*devsw[io->i_ino.i_dev].dv_open)(io);
+}
+
+devclose(io)
+       register struct iob *io;
+{
+
+       (*devsw[io->i_ino.i_dev].dv_close)(io);
+}
+
+devioctl(io, cmd, arg)
+       register struct iob *io;
+       int cmd;
+       caddr_t arg;
+{
+
+       return ((*devsw[io->i_ino.i_dev].dv_ioctl)(io, cmd, arg));
+}
+
+/*ARGSUSED*/
+nullsys(io)
+       struct iob *io;
+{
+
+       ;
+}
+
+/*ARGSUSED*/
+nullioctl(io, cmd, arg)
+       struct iob *io;
+       int cmd;
+       caddr_t arg;
+{
+
+       return (ECMD);
+}
+
+int    nullsys(), nullioctl();
+int    rdstrategy(), rdopen(), rdioctl();
+int    sdstrategy(), sdopen(), sdioctl();
+#ifndef BOOT
+int    ctstrategy(), ctopen(), ctclose();
+#endif
+
+struct devsw devsw[] = {
+       { "rd", rdstrategy,     rdopen,         nullsys,        nullioctl },
+       { "sd", sdstrategy,     sdopen,         nullsys,        nullioctl },
+#ifndef BOOT
+       { "ct", ctstrategy,     ctopen,         ctclose,        nullioctl },
+#endif
+       { 0, 0, 0, 0, 0 },
+};
diff --git a/usr/src/sys/hp300/stand/cons.c b/usr/src/sys/hp300/stand/cons.c
new file mode 100644 (file)
index 0000000..e6778e7
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: cons.c 1.5 89/08/22$
+ *
+ *     @(#)cons.c      7.1 (Berkeley) %G%
+ */
+
+#include "param.h"
+#include "samachdep.h"
+#include "machine/cons.h"
+
+int    nodev();
+#ifdef ITECONSOLE
+int    iteprobe(), iteinit(), itegetchar(), iteputchar();
+#endif
+#ifdef DCACONSOLE
+int    dcaprobe(), dcainit(), dcagetchar(), dcaputchar();
+#endif
+
+struct consdev constab[] = {
+#ifdef ITECONSOLE
+       { iteprobe,     iteinit,        itegetchar,     iteputchar },
+#endif
+#ifdef DCACONSOLE
+       { dcaprobe,     dcainit,        dcagetchar,     dcaputchar },
+#endif
+       { 0 },
+};
+
+struct consdev *cn_tab;
+int noconsole;
+
+cninit()
+{
+       register struct consdev *cp;
+
+       cn_tab = NULL;
+       noconsole = 1;
+       for (cp = constab; cp->cn_probe; cp++) {
+               (*cp->cn_probe)(cp);
+               if (cp->cn_pri > CN_DEAD &&
+                   (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
+                       cn_tab = cp;
+       }
+       if (cn_tab) {
+               (*cn_tab->cn_init)(cn_tab);
+               noconsole = 0;
+       }
+}
+
+cngetc()
+{
+       if (cn_tab)
+               return((*cn_tab->cn_getc)());
+       return(0);
+}
+
+cnputc(c)
+       int c;
+{
+       if (cn_tab)
+               (*cn_tab->cn_putc)(c);
+}
diff --git a/usr/src/sys/hp300/stand/copy.c b/usr/src/sys/hp300/stand/copy.c
new file mode 100644 (file)
index 0000000..bde9439
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)copy.c      7.1 (Berkeley) %G%
+ */
+
+/*
+ * Copy from to in 10K units.
+ * Intended for use in system
+ * installation.
+ */
+main()
+{
+       int from, to;
+       char fbuf[50], tbuf[50];
+       char buffer[10240];
+       register int record;
+       extern int errno;
+
+       from = getdev("From", fbuf, 0);
+       to = getdev("To", tbuf, 1);
+       for (record = 0; ; record++) {
+               int rcc, wcc;
+
+               rcc = read(from, buffer, sizeof (buffer));
+               if (rcc == 0)
+                       break;
+               if (rcc < 0) {
+                       printf("Record %d: read error, errno=%d\n",
+                               record, errno);
+                       break;
+               }
+               if (rcc < sizeof (buffer))
+                       printf("Record %d: read short; expected %d, got %d\n",
+                               record, sizeof (buffer), rcc);
+               /*
+                * For bug in ht driver.
+                */
+               if (rcc > sizeof (buffer))
+                       rcc = sizeof (buffer);
+               wcc = write(to, buffer, rcc);
+               if (wcc < 0) {
+                       printf("Record %d: write error: errno=%d\n",
+                               record, errno);
+                       break;
+               }
+               if (wcc < rcc) {
+                       printf("Record %d: write short; expected %d, got %d\n",
+                               record, rcc, wcc);
+                       break;
+               }
+       }
+       printf("Copy completed: %d records copied\n", record);
+       /* can't call exit here */
+}
+
+getdev(prompt, buf, mode)
+       char *prompt, *buf;
+       int mode;
+{
+       register int i;
+
+       do {
+               printf("%s: ", prompt);
+               gets(buf);
+               i = open(buf, mode);
+       } while (i <= 0);
+       return (i);
+}
diff --git a/usr/src/sys/hp300/stand/ct.c b/usr/src/sys/hp300/stand/ct.c
new file mode 100644 (file)
index 0000000..a4f775f
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)ct.c        7.1 (Berkeley) %G%
+ */
+
+/*
+ * CS80 tape driver
+ */
+#include "../sys/types.h"
+#include "../hpdev/ctreg.h"
+
+#include "saio.h"
+#include "samachdep.h"
+
+struct ct_iocmd ct_ioc;
+struct ct_rscmd ct_rsc;
+struct ct_stat ct_stat;
+struct ct_ssmcmd ct_ssmc;
+
+struct ct_softc {
+       char    sc_retry;
+       char    sc_alive;
+       short   sc_punit;
+       int     sc_blkno;
+} ct_softc[NCT];
+
+#define        CTRETRY         5
+#define        MTFSF           10
+#define        MTREW           11
+
+struct ctinfo {
+       short   hwid;
+       short   punit;
+} ctinfo[] = {
+       CT7946ID,       1,
+       CT7912PID,      1,
+       CT7914PID,      1,
+       CT9144ID,       0,
+       CT9145ID,       0,
+};
+int    nctinfo = sizeof(ctinfo) / sizeof(ctinfo[0]);
+
+ctinit(unit)
+       register int unit;
+{
+       register struct ct_softc *rs = &ct_softc[unit];
+       u_char stat;
+       register int type;
+
+       if (hpibrecv(unit, C_QSTAT, &stat, 1) != 1 || stat)
+               return (0);
+       if (ctident(unit) < 0)
+               return (0);
+       ct_ssmc.unit = C_SUNIT(rs->sc_punit);
+       ct_ssmc.cmd = C_SSM;
+       ct_ssmc.fefm = FEF_MASK;
+       ct_ssmc.refm = REF_MASK;
+       ct_ssmc.aefm = AEF_MASK;
+       ct_ssmc.iefm = IEF_MASK;
+       hpibsend(unit, C_CMD, &ct_ssmc, sizeof(ct_ssmc));
+       hpibswait(unit);
+       hpibrecv(unit, C_QSTAT, &stat, 1);
+       rs->sc_alive = 1;
+       return (1);
+}
+
+ctident(unit)
+       int unit;
+{
+       struct ct_describe desc;
+       u_char stat, cmd[3];
+       char name[7];
+       int id, i;
+
+       id = hpibid(unit);
+       if ((id & 0x200) == 0)
+               return(-1);
+       for (i = 0; i < nctinfo; i++)
+               if (id == ctinfo[i].hwid)
+                       break;
+       if (i == nctinfo)
+               return(-1);
+       ct_softc[unit].sc_punit = ctinfo[i].punit;
+       id = i;
+
+       /*
+        * Collect device description.
+        * Right now we only need this to differentiate 7945 from 7946.
+        * Note that we always issue the describe command to unit 0.
+        */
+       cmd[0] = C_SUNIT(0);
+       cmd[1] = C_SVOL(0);
+       cmd[2] = C_DESC;
+       hpibsend(unit, C_CMD, cmd, sizeof(cmd));
+       hpibrecv(unit, C_EXEC, &desc, 37);
+       hpibrecv(unit, C_QSTAT, &stat, sizeof(stat));
+       bzero(name, sizeof(name));
+       if (!stat) {
+               register int n = desc.d_name;
+               for (i = 5; i >= 0; i--) {
+                       name[i] = (n & 0xf) + '0';
+                       n >>= 4;
+               }
+       }
+       switch (ctinfo[id].hwid) {
+       case CT7946ID:
+               if (bcmp(name, "079450", 6) == 0)
+                       id = -1;                /* not really a 7946 */
+               break;
+       default:
+               break;
+       }
+       return(id);
+}
+
+ctopen(io)
+       struct iob *io;
+{
+       register int unit = io->i_unit;
+       register struct ct_softc *rs = &ct_softc[unit];
+       register int skip;
+
+       if (hpibalive(unit) == 0)
+               _stop("ct controller not configured");
+       if (rs->sc_alive == 0)
+               if (ctinit(unit) == 0)
+                       _stop("ct init failed");
+       ctstrategy(io, MTREW);
+       skip = io->i_boff;
+       while (skip--)
+               ctstrategy(io, MTFSF);
+}
+
+ctclose(io)
+       struct iob *io;
+{
+       ctstrategy(io, MTREW);
+}
+
+ctstrategy(io, func)
+       register struct iob *io;
+       register int func;
+{
+       register int unit = io->i_unit;
+       register struct ct_softc *rs = &ct_softc[unit];
+       char stat;
+
+       rs->sc_retry = 0;
+       ct_ioc.unit = C_SUNIT(rs->sc_punit);
+       ct_ioc.saddr = C_SADDR;
+       ct_ioc.nop2 = C_NOP;
+       ct_ioc.slen = C_SLEN;
+       ct_ioc.nop3 = C_NOP;
+top:
+       if (func == READ) {
+               ct_ioc.cmd = C_READ;
+               ct_ioc.addr = rs->sc_blkno;
+               ct_ioc.len = io->i_cc;
+       }
+       else if (func == WRITE) {
+               ct_ioc.cmd = C_WRITE;
+               ct_ioc.addr = rs->sc_blkno;
+               ct_ioc.len = io->i_cc;
+       }
+       else if (func == MTFSF) {
+               ct_ioc.cmd = C_READ;
+               ct_ioc.addr = rs->sc_blkno;
+               ct_ioc.len = io->i_cc = MAXBSIZE;
+               io->i_ma = io->i_buf;
+       }
+       else {
+               ct_ioc.cmd = C_READ;
+               ct_ioc.addr = 0;
+               ct_ioc.len = 0;
+               rs->sc_blkno = 0;
+               io->i_cc = 0;
+       }
+retry:
+       hpibsend(unit, C_CMD, &ct_ioc, sizeof(ct_ioc));
+       if (func != MTREW) {
+               hpibswait(unit);
+               hpibgo(unit, C_EXEC, io->i_ma, io->i_cc,
+                       func != WRITE ? READ : WRITE);
+               hpibswait(unit);
+       }
+       else {
+               while (hpibswait(unit) < 0)
+                       ;
+       }
+       hpibrecv(unit, C_QSTAT, &stat, 1);
+       if (stat) {
+               stat = cterror(unit);
+               if (stat == 0)
+                       return (-1);
+               if (stat == 2)
+                       return (0);
+               if (++rs->sc_retry > CTRETRY)
+                       return (-1);
+               else
+                       goto retry;
+       }
+       rs->sc_blkno += CTBTOK(io->i_cc);
+       if (func == MTFSF)
+               goto top;
+       return (io->i_cc);
+}
+
+cterror(unit)
+       register int unit;
+{
+       register struct ct_softc *ct = &ct_softc[unit];
+       char stat;
+
+       ct_rsc.unit = C_SUNIT(ct->sc_punit);
+       ct_rsc.cmd = C_STATUS;
+       hpibsend(unit, C_CMD, &ct_rsc, sizeof(ct_rsc));
+       hpibrecv(unit, C_EXEC, &ct_stat, sizeof(ct_stat));
+       hpibrecv(unit, C_QSTAT, &stat, 1);
+       if (stat) {
+               printf("ct%d: request status fail %d\n", unit, stat);
+               return(0);
+       }
+       if (ct_stat.c_aef & AEF_EOF) {
+               /* 9145 drives don't increment block number at EOF */
+               if ((ct_stat.c_blk - ct->sc_blkno) == 0)
+                       ct->sc_blkno++;
+               else
+                       ct->sc_blkno = ct_stat.c_blk;
+               return (2);
+       }
+       printf("ct%d err: vu 0x%x, pend 0x%x, bn%d", unit,
+               ct_stat.c_vu, ct_stat.c_pend, ct_stat.c_blk);
+       printf(", R 0x%x F 0x%x A 0x%x I 0x%x\n", ct_stat.c_ref,
+               ct_stat.c_fef, ct_stat.c_aef, ct_stat.c_ief);
+       return (1);
+}
diff --git a/usr/src/sys/hp300/stand/dca.c b/usr/src/sys/hp300/stand/dca.c
new file mode 100644 (file)
index 0000000..b102b24
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)dca.c       7.1 (Berkeley) %G%
+ */
+
+#ifdef DCACONSOLE
+#include "../sys/param.h"
+#include "../hpdev/dcareg.h"
+#include "machine/cpu.h"
+#include "machine/cons.h"
+
+#define CONSDEV        (0)
+#define CONSOLE ((struct dcadevice *)(EXTIOBASE + (9 * IOCARDSIZE)))
+
+dcaprobe(cp)
+       struct consdev *cp;
+{
+       register struct dcadevice *dca = CONSOLE;
+
+       if (badaddr((char *)CONSOLE)) {
+               cp->cn_pri = CN_DEAD;
+               return;
+       }
+       switch (dca->dca_irid) {
+       case DCAID0:
+       case DCAID1:
+               cp->cn_pri = CN_NORMAL;
+               break;
+       case DCAREMID0:
+       case DCAREMID1:
+               cp->cn_pri = CN_REMOTE;
+               break;
+       default:
+               cp->cn_pri = CN_DEAD;
+               break;
+       }
+}
+
+dcainit(cp)
+       struct consdev *cp;
+{
+       register struct dcadevice *dca = CONSOLE;
+
+       dca->dca_irid = 0xFF;
+       DELAY(100);
+       dca->dca_ic = 0;
+       dca->dca_cfcr = CFCR_DLAB;
+       dca->dca_data = DCABRD(9600) & 0xFF;
+       dca->dca_ier = DCABRD(9600) >> 8;
+       dca->dca_cfcr = CFCR_8BITS;
+}
+
+#ifndef SMALL
+dcagetchar()
+{
+       register struct dcadevice *dca = CONSOLE;
+       short stat;
+       int c;
+
+       if (((stat = dca->dca_lsr) & LSR_RXRDY) == 0)
+               return(0);
+       c = dca->dca_data;
+       return(c);
+}
+#else
+dcagetchar()
+{
+       return(0);
+}
+#endif
+
+dcaputchar(c)
+       register int c;
+{
+       register struct dcadevice *dca = CONSOLE;
+       register int timo;
+       short stat;
+
+       /* wait a reasonable time for the transmitter to come ready */
+       timo = 50000;
+       while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
+               ;
+       dca->dca_data = c;
+       /* wait for this transmission to complete */
+       timo = 1000000;
+       while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
+               ;
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/fhpib.c b/usr/src/sys/hp300/stand/fhpib.c
new file mode 100644 (file)
index 0000000..97a6ac3
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)fhpib.c     7.1 (Berkeley) %G%
+ */
+
+/*
+ * 98625A/B HPIB driver
+ */
+
+#include "param.h"
+#include "../hpdev/fhpibreg.h"
+#include "hpibvar.h"
+
+fhpibinit(unit)
+       register int unit;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct fhpibdevice *hd = (struct fhpibdevice *)hs->sc_addr;
+
+       if (hd->hpib_cid != HPIBC)
+               return(0);
+       hs->sc_type = HPIBC;
+       hs->sc_ba = HPIBC_BA;
+       fhpibreset(unit);
+       return(1);
+}
+
+fhpibreset(unit)
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct fhpibdevice *hd;
+
+       hd = (struct fhpibdevice *)hs->sc_addr;
+       hd->hpib_cid = 0xFF;
+       DELAY(100);
+       hd->hpib_cmd = CT_8BIT;
+       hd->hpib_ar = AR_ARONC;
+       hd->hpib_cmd |= CT_IFC;
+       hd->hpib_cmd |= CT_INITFIFO;
+       DELAY(100);
+       hd->hpib_cmd &= ~CT_IFC;
+       hd->hpib_cmd |= CT_REN;
+       hd->hpib_stat = ST_ATN;
+       hd->hpib_data = C_DCL;
+       DELAY(100000);
+}
+
+fhpibsend(unit, slave, sec, buf, cnt)
+       register char *buf;
+       register int cnt;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct fhpibdevice *hd;
+       int origcnt = cnt;
+
+       hd = (struct fhpibdevice *)hs->sc_addr;
+       hd->hpib_stat = 0;
+       hd->hpib_imask = IM_IDLE | IM_ROOM;
+       fhpibwait(hd, IM_IDLE);
+       hd->hpib_stat = ST_ATN;
+       hd->hpib_data = C_UNL;
+       hd->hpib_data = C_TAG + hs->sc_ba;
+       hd->hpib_data = C_LAG + slave;
+       if (sec != -1)
+               hd->hpib_data = C_SCG + sec;
+       fhpibwait(hd, IM_IDLE);
+       hd->hpib_stat = ST_WRITE;
+       if (cnt) {
+               while (--cnt) {
+                       hd->hpib_data = *buf++;
+                       if (fhpibwait(hd, IM_ROOM) < 0)
+                               break;
+               }
+               hd->hpib_stat = ST_EOI;
+               hd->hpib_data = *buf;
+               if (fhpibwait(hd, IM_ROOM) < 0)
+                       cnt++;
+               hd->hpib_stat = ST_ATN;
+               /* XXX: HP-UX claims bug with CS80 transparent messages */
+               if (sec == 0x12)
+                       DELAY(150);
+               hd->hpib_data = C_UNL;
+               fhpibwait(hd, IM_IDLE);
+       }
+       hd->hpib_imask = 0;
+       return(origcnt - cnt);
+}
+
+fhpibrecv(unit, slave, sec, buf, cnt)
+       register char *buf;
+       register int cnt;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct fhpibdevice *hd;
+       int origcnt = cnt;
+
+       hd = (struct fhpibdevice *)hs->sc_addr;
+       hd->hpib_stat = 0;
+       hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
+       fhpibwait(hd, IM_IDLE);
+       hd->hpib_stat = ST_ATN;
+       hd->hpib_data = C_UNL;
+       hd->hpib_data = C_LAG + hs->sc_ba;
+       hd->hpib_data = C_TAG + slave;
+       if (sec != -1)
+               hd->hpib_data = C_SCG + sec;
+       fhpibwait(hd, IM_IDLE);
+       hd->hpib_stat = ST_READ0;
+       hd->hpib_data = 0;
+       if (cnt) {
+               while (--cnt >= 0) {
+                       if (fhpibwait(hd, IM_BYTE) < 0)
+                               break;
+                       *buf++ = hd->hpib_data;
+               }
+               cnt++;
+               fhpibwait(hd, IM_ROOM);
+               hd->hpib_stat = ST_ATN;
+               hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
+               fhpibwait(hd, IM_IDLE);
+       }
+       hd->hpib_imask = 0;
+       return(origcnt - cnt);
+}
+
+fhpibppoll(unit)
+       register int unit;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct fhpibdevice *hd;
+       register int ppoll;
+
+       hd = (struct fhpibdevice *)hs->sc_addr;
+       hd->hpib_stat = 0;
+       hd->hpib_psense = 0;
+       hd->hpib_pmask = 0xFF;
+       hd->hpib_imask = IM_PPRESP | IM_PABORT;
+       DELAY(25);
+       hd->hpib_intr = IM_PABORT;
+       ppoll = hd->hpib_data;
+       if (hd->hpib_intr & IM_PABORT)
+               ppoll = 0;
+       hd->hpib_imask = 0;
+       hd->hpib_pmask = 0;
+       hd->hpib_stat = ST_IENAB;
+       return(ppoll);
+}
+
+fhpibwait(hd, x)
+       register struct fhpibdevice *hd;
+{
+       register int timo = 100000;
+
+       while ((hd->hpib_intr & x) == 0 && --timo)
+               ;
+       if (timo == 0)
+               return(-1);
+       return(0);
+}
diff --git a/usr/src/sys/hp300/stand/hil.c b/usr/src/sys/hp300/stand/hil.c
new file mode 100644 (file)
index 0000000..c67b6fc
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: hil.c 1.1 89/08/22$
+ *
+ *     @(#)hil.c       7.1 (Berkeley) %G%
+ */
+
+/*
+ * Keyboard routines for the standalone ITE.
+ */
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+#include "../hpdev/hilreg.h"
+#include "../hpdev/kbdmap.h"
+#include "../hpdev/itevar.h"
+
+#ifndef SMALL
+
+/*
+ * HIL cooked keyboard keymaps.
+ * Supports only unshifted, shifted and control keys.
+ */
+char   us_keymap[] = {
+       NULL,   '`',    '\\',   ESC,    NULL,   DEL,    NULL,   NULL,  
+       '\n',   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,  
+       NULL,   '\n',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,  
+       NULL,   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   '\b',   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       ESC,    '\r',   NULL,   '\n',   '0',    '.',    ',',    '+',
+       '1',    '2',    '3',    '-',    '4',    '5',    '6',    '*',
+       '7',    '8',    '9',    '/',    'E',    '(',    ')',    '^',
+       '1',    '2',    '3',    '4',    '5',    '6',    '7',    '8',
+       '9',    '0',    '-',    '=',    '[',    ']',    ';',    '\'',
+       ',',    '.',    '/',    '\040', 'o',    'p',    'k',    'l',
+       'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
+       'a',    's',    'd',    'f',    'g',    'h',    'j',    'm',
+       'z',    'x',    'c',    'v',    'b',    'n',    NULL,   NULL
+};
+
+char   us_shiftmap[] = {
+       NULL,   '~',    '|',    DEL,    NULL,   DEL,    NULL,   NULL,
+       '\n',   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\n',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   DEL,    NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       ESC,    '\r',   NULL,   '\n',   '0',    '.',    ',',    '+',
+       '1',    '2',    '3',    '-',    '4',    '5',    '6',    '*',
+       '7',    '8',    '9',    '/',    '`',    '|',    '\\',   '~',
+       '!',    '@',    '#',    '$',    '%',    '^',    '&',    '*',
+       '(',    ')',    '_',    '+',    '{',    '}',    ':',    '\"',
+       '<',    '>',    '?',    '\040', 'O',    'P',    'K',    'L',
+       'Q',    'W',    'E',    'R',    'T',    'Y',    'U',    'I',
+       'A',    'S',    'D',    'F',    'G',    'H',    'J',    'M',
+       'Z',    'X',    'C',    'V',    'B',    'N',    NULL,   NULL
+};
+
+char   us_ctrlmap[] = {
+       NULL,   '`',    '\034', ESC,    NULL,   DEL,    NULL,   NULL,
+       '\n',   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\n',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   '\b',   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       ESC,    '\r',   NULL,   '\n',   '0',    '.',    ',',    '+',
+       '1',    '2',    '3',    '-',    '4',    '5',    '6',    '*',
+       '7',    '8',    '9',    '/',    'E',    '(',    ')',    '\036',
+       '1',    '2',    '3',    '4',    '5',    '6',    '7',    '8',
+       '9',    '0',    '-',    '=',    '\033', '\035', ';',    '\'',
+       ',',    '.',    '/',    '\040', '\017', '\020', '\013', '\014',
+       '\021', '\027', '\005', '\022', '\024', '\031', '\025', '\011',
+       '\001', '\023', '\004', '\006', '\007', '\010', '\012', '\015',
+       '\032', '\030', '\003', '\026', '\002', '\016', NULL,   NULL
+};
+
+#ifdef UK_KEYBOARD
+char   uk_keymap[] = {
+       NULL,   '`',    '<',    ESC,    NULL,   DEL,    NULL,   NULL,  
+       '\n',   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,  
+       NULL,   '\n',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,  
+       NULL,   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   '\b',   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       ESC,    '\r',   NULL,   '\n',   '0',    '.',    ',',    '+',
+       '1',    '2',    '3',    '-',    '4',    '5',    '6',    '*',
+       '7',    '8',    '9',    '/',    'E',    '(',    ')',    '^',
+       '1',    '2',    '3',    '4',    '5',    '6',    '7',    '8',
+       '9',    '0',    '+',    '\'',   '[',    ']',    '*',    '\\',
+       ',',    '.',    '-',    '\040', 'o',    'p',    'k',    'l',
+       'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
+       'a',    's',    'd',    'f',    'g',    'h',    'j',    'm',
+       'z',    'x',    'c',    'v',    'b',    'n',    NULL,   NULL
+};
+
+char   uk_shiftmap[] = {
+       NULL,   '~',    '>',    DEL,    NULL,   DEL,    NULL,   NULL,
+       '\n',   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\n',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   DEL,    NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       ESC,    '\r',   NULL,   '\n',   '0',    '.',    ',',    '+',
+       '1',    '2',    '3',    '-',    '4',    '5',    '6',    '*',
+       '7',    '8',    '9',    '/',    '`',    '|',    '\\',   '~',
+       '!',    '\"',   '#',    '$',    '%',    '&',    '^',    '(',
+       ')',    '=',    '?',    '/',    '{',    '}',    '@',    '|',
+       ';',    ':',    '_',    '\040', 'O',    'P',    'K',    'L',
+       'Q',    'W',    'E',    'R',    'T',    'Y',    'U',    'I',
+       'A',    'S',    'D',    'F',    'G',    'H',    'J',    'M',
+       'Z',    'X',    'C',    'V',    'B',    'N',    NULL,   NULL
+};
+
+char   uk_ctrlmap[] = {
+       NULL,   '`',    '<',    ESC,    NULL,   DEL,    NULL,   NULL,
+       '\n',   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\n',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   '\t',   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   '\b',   NULL,
+       NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,   NULL,
+       ESC,    '\r',   NULL,   '\n',   '0',    '.',    ',',    '+',
+       '1',    '2',    '3',    '-',    '4',    '5',    '6',    '*',
+       '7',    '8',    '9',    '/',    'E',    '(',    ')',    '\036',
+       '1',    '2',    '3',    '4',    '5',    '6',    '7',    '8',
+       '9',    '0',    '+',    '\'',   '\033', '\035', '*',    '\034',
+       ',',    '.',    '/',    '\040', '\017', '\020', '\013', '\014',
+       '\021', '\027', '\005', '\022', '\024', '\031', '\025', '\011',
+       '\001', '\023', '\004', '\006', '\007', '\010', '\012', '\015',
+       '\032', '\030', '\003', '\026', '\002', '\016', NULL,   NULL
+};
+#endif
+
+/*
+ * The keyboard map table.
+ * Lookup is by hardware returned language code.
+ */
+struct kbdmap kbd_map[] = {
+       KBD_US,         NULL,
+       us_keymap,      us_shiftmap,    us_ctrlmap,     NULL,   NULL,
+
+#ifdef UK_KEYBOARD
+       KBD_UK,         NULL,
+       uk_keymap,      uk_shiftmap,    uk_ctrlmap,     NULL,   NULL,
+#endif
+
+       0,              NULL,
+       NULL,           NULL,           NULL,           NULL,   NULL,
+};
+
+char   *kbd_keymap = us_keymap;
+char   *kbd_shiftmap = us_shiftmap;
+char   *kbd_ctrlmap = us_ctrlmap;
+
+kbdgetc()
+{
+       register int status, c;
+       register struct hil_dev *hiladdr = HILADDR;
+
+       status = hiladdr->hil_stat;
+       if ((status & HIL_DATA_RDY) == 0)
+               return(0);
+       c = hiladdr->hil_data;
+       switch ((status>>KBD_SSHIFT) & KBD_SMASK) {
+       case KBD_SHIFT:
+               c = kbd_shiftmap[c & KBD_CHARMASK];
+               break;
+       case KBD_CTRL:
+               c = kbd_ctrlmap[c & KBD_CHARMASK];
+               break;
+       case KBD_KEY:
+               c = kbd_keymap[c & KBD_CHARMASK];
+               break;
+       default:
+               c = 0;
+               break;
+       }
+       return(c);
+}
+#endif
+
+kbdnmi()
+{
+       register struct hil_dev *hiladdr = HILADDR;
+
+       HILWAIT(hiladdr);
+       hiladdr->hil_cmd = HIL_CNMT;
+       HILWAIT(hiladdr);
+       hiladdr->hil_cmd = HIL_CNMT;
+       HILWAIT(hiladdr);
+       printf("\nboot interrupted\n");
+}
+
+kbdinit()
+{
+       register struct hil_dev *hiladdr = HILADDR;
+       register struct kbdmap *km;
+       u_char lang;
+
+       HILWAIT(hiladdr);
+       hiladdr->hil_cmd = HIL_SETARR;
+       HILWAIT(hiladdr);
+       hiladdr->hil_data = ar_format(KBD_ARR);
+       HILWAIT(hiladdr);
+       hiladdr->hil_cmd = HIL_READKBDLANG;
+       HILDATAWAIT(hiladdr);
+       lang = hiladdr->hil_data;
+       for (km = kbd_map; km->kbd_code; km++)
+               if (km->kbd_code == lang) {
+                       kbd_keymap = km->kbd_keymap;
+                       kbd_shiftmap = km->kbd_shiftmap;
+                       kbd_ctrlmap = km->kbd_ctrlmap;
+               }
+       HILWAIT(hiladdr);
+       hiladdr->hil_cmd = HIL_INTON;
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/hpib.c b/usr/src/sys/hp300/stand/hpib.c
new file mode 100644 (file)
index 0000000..8fc56eb
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)hpib.c      7.1 (Berkeley) %G%
+ */
+
+/*
+ * HPIB driver
+ */
+#include "../h/reboot.h"
+#include "../hpdev/device.h"
+#include "hpibvar.h"
+
+#include "saio.h"
+#include "samachdep.h"
+
+int    internalhpib = 0x478000;
+int    fhpibppoll(), nhpibppoll();
+
+struct hpib_softc hpib_softc[NHPIB];
+
+#define        hpibunit(x)     ((x) >> 3)
+#define        hpibslave(x)    ((x) & 7)
+
+hpibinit()
+{
+       extern struct hp_hw sc_table[];
+       register struct hp_hw *hw;
+       register struct hpib_softc *hs;
+       register int i, addr;
+       static int first = 1;
+       
+       i = 0;
+       for (hw = sc_table; i < NHPIB && hw < &sc_table[MAX_CTLR]; hw++) {
+               if (hw->hw_type != HPIB)
+                       continue;
+               hs = &hpib_softc[i];
+               hs->sc_addr = hw->hw_addr;
+               if (nhpibinit(i) == 0)
+                       if (fhpibinit(i) == 0)
+                               continue;
+               if (howto & RB_ASKNAME)
+                       printf("hpib%d at sc%d\n", i, hw->hw_sc);
+               /*
+                * Adjust devtype on first call.  This routine assumes that
+                * adaptor is in the high byte of devtype.
+                */
+               if (first && ((devtype >> 24) & 0xff) == hw->hw_sc) {
+                       devtype = (devtype & 0x00ffffff) | (i << 24);
+                       first = 0;
+               }
+               hs->sc_alive = 1;
+               i++;
+       }
+}
+
+hpibalive(unit)
+       register int unit;
+{
+       unit = hpibunit(unit);
+       if (unit >= NHPIB || hpib_softc[unit].sc_alive == 0)
+               return (0);
+       return (1);
+}
+
+hpibid(unit)
+       register int unit;
+{
+       register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
+       register int slave;
+       short id;
+
+       slave = hpibslave(unit);
+       unit = hpibunit(unit);
+       if (hs->sc_type == HPIBC)
+               slave = fhpibrecv(unit, 31, slave, &id, 2);
+       else
+               slave = nhpibrecv(unit, 31, slave, &id, 2);
+       if (slave != 2)
+               return (0);
+       return (id);
+}
+
+hpibsend(unit, sec, buf, cnt)
+       register char *buf;
+       register int cnt;
+{
+       register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
+       register int slave;
+
+       slave = hpibslave(unit);
+       unit = hpibunit(unit);
+       if (hs->sc_type == HPIBC)
+               return (fhpibsend(unit, slave, sec, buf, cnt));
+       else
+               return (nhpibsend(unit, slave, sec, buf, cnt));
+}
+
+hpibrecv(unit, sec, buf, cnt)
+       register char *buf;
+       register int cnt;
+{
+       register struct hpib_softc *hs = &hpib_softc[hpibunit(unit)];
+       register int slave;
+
+       slave = hpibslave(unit);
+       unit = hpibunit(unit);
+       if (hs->sc_type == HPIBC)
+               return (fhpibrecv(unit, slave, sec, buf, cnt));
+       else
+               return (nhpibrecv(unit, slave, sec, buf, cnt));
+}
+
+hpibswait(unit)
+       register int unit;
+{
+       register int timo = 1000000;
+       register int slave = 0x80 >> hpibslave(unit);
+       register int (*poll)();
+
+       unit = hpibunit(unit);
+       if (hpib_softc[unit].sc_type == HPIBC)
+               poll = fhpibppoll;
+       else
+               poll = nhpibppoll;
+       while (((*poll)(unit) & slave) == 0)
+               if (--timo == 0)
+                       break;
+       if (timo == 0)
+               return (-1);
+       return (0);
+}
+
+hpibgo(unit, sec, addr, count, flag)
+       register int unit;
+       char *addr;
+{
+       register int slave;
+
+       slave = hpibslave(unit);
+       unit = hpibunit(unit);
+       if (hpib_softc[unit].sc_type == HPIBC)
+               if (flag == READ)
+                       fhpibrecv(unit, slave, sec, addr, count);
+               else
+                       fhpibsend(unit, slave, sec, addr, count);
+       else
+               if (flag == READ)
+                       nhpibrecv(unit, slave, sec, addr, count);
+               else
+                       nhpibsend(unit, slave, sec, addr, count);
+}
diff --git a/usr/src/sys/hp300/stand/hpibvar.h b/usr/src/sys/hp300/stand/hpibvar.h
new file mode 100644 (file)
index 0000000..62eee32
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)hpibvar.h   7.1 (Berkeley) %G%
+ */
+
+#define        HPIBA           32
+#define        HPIBB           1
+#define        HPIBC           8
+#define        HPIBA_BA        21
+#define        HPIBC_BA        30
+
+#define        CSA_BA          0x1F
+
+#define        C_DCL           20
+#define        C_LAG           32
+#define        C_UNL           63
+#define        C_TAG           64
+#define        C_UNA           94
+#define        C_UNT           95
+#define        C_SCG           96
+
+struct hpib_softc {
+       char    sc_alive;
+       char    sc_type;
+       int     sc_ba;
+       char    *sc_addr;
+};
+
+extern struct hpib_softc hpib_softc[];
diff --git a/usr/src/sys/hp300/stand/installboot.c b/usr/src/sys/hp300/stand/installboot.c
new file mode 100644 (file)
index 0000000..1b7ae90
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)installboot.c       7.1 (Berkeley) %G%
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980, 1986, 1990 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)installboot.c      7.1 (Berkeley) %G%";
+#endif /* not lint */
+
+#include "../sys/param.h"
+#include "../ufs/fs.h"
+
+char block[1024];
+int maxbootsize = 16 * 7 * 512;                /* XXX */
+
+/*
+ * HPs are a kludge.
+ * The boot program won't fit in the boot area of a file system so we
+ * have to place it outside the file systems.  By convention, this means
+ * that if the 'a' partition is being used for '/', it is offset one
+ * cylinder into the disk and the boot program goes into that one cylinder.
+ * Also by convention, the 'c' partition is defined to be the entire disk
+ * including this boot cylinder.  If these conventions are not adhered to,
+ * the potential for disaster is enormous.
+ */
+main(argc, argv)
+       int argc;
+       char *argv[];
+{
+       int ifd, ofd, len;
+       char *dev, *standalonecode;
+       int bsize = 1024;
+
+       if (argc != 3)
+               usage();
+       dev = argv[2];
+       len = strlen(dev);
+       if (dev[len-1] != 'c')
+               usage();
+       standalonecode = argv[1];
+       ifd = open(standalonecode, 0);
+       if (ifd < 0) {
+               perror(standalonecode);
+               exit(1);
+       }
+       ofd = open(dev, 1);
+       if (ofd < 0) {
+               perror(dev);
+               exit(1);
+       }
+       while ((len = read(ifd, block, bsize)) > 0) {
+               if ((maxbootsize -= bsize) < 0) {
+                       printf("%s: too big\n", standalonecode);
+                       exit(2);
+               }
+               if (len < bsize)
+                       bzero(&block[len], bsize-len);
+               if (write(ofd, block, bsize) != bsize) {
+                       perror(dev);
+                       exit(2);
+               }
+       }
+       if (len < 0) {
+               perror(standalonecode);
+               exit(2);
+       }
+       exit(0);
+}
+
+usage()
+{
+       printf("Usage: installboot bootprog device\n");
+       printf("where:\n");
+       printf("\t\"bootprog\" is a LIF format file < %d bytes long\n",
+              maxbootsize);
+       printf("\t\"device\" must be the 'c' partition of a bootable disk\n");
+       printf("WARNING!!  If the 'c' partition contains a file system, %s\n",
+              "DON'T RUN THIS!!");
+       exit(1);
+}
diff --git a/usr/src/sys/hp300/stand/ite.c b/usr/src/sys/hp300/stand/ite.c
new file mode 100644 (file)
index 0000000..f57c2f0
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: ite.c 1.19 89/08/22$
+ *
+ *     @(#)ite.c       7.1 (Berkeley) %G%
+ */
+
+/*
+ * Standalone Internal Terminal Emulator (CRT and keyboard)
+ */
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+#include "machine/cons.h"
+#include "../hpdev/device.h"
+#include "../hpdev/itevar.h"
+#include "../hpdev/grfvar.h"
+
+int nodev();
+
+int topcat_init(), topcat_putc();
+int topcat_clear(), topcat_cursor(), topcat_scroll();
+int gatorbox_init(), gatorbox_clear();
+int gatorbox_putc(), gatorbox_cursor(), gatorbox_scroll();
+int rbox_init(), rbox_clear();
+int rbox_putc(), rbox_cursor(), rbox_scroll();
+int dvbox_init(), dvbox_clear();
+int dvbox_putc(), dvbox_cursor(), dvbox_scroll();
+
+struct itesw itesw[] = {
+       topcat_init,            nodev,                  topcat_clear,
+       topcat_putc,            topcat_cursor,          topcat_scroll,
+
+       gatorbox_init,          nodev,                  gatorbox_clear,
+       gatorbox_putc,          gatorbox_cursor,        gatorbox_scroll,
+
+       rbox_init,              nodev,                  rbox_clear,
+       rbox_putc,              rbox_cursor,            rbox_scroll,
+
+       dvbox_init,             nodev,                  dvbox_clear,
+       dvbox_putc,             dvbox_cursor,           dvbox_scroll,
+};
+
+/* these guys need to be in initialized data */
+int itecons = -1;
+struct  ite_softc ite_softc[NITE] = { 0 };
+
+/*
+ * Locate all bitmapped displays
+ */
+iteconfig()
+{
+       extern struct hp_hw sc_table[];
+       int dtype, fboff, i;
+       struct hp_hw *hw;
+       struct grfreg *gr;
+       struct ite_softc *ip;
+
+       i = 0;
+       for (hw = sc_table; hw < &sc_table[MAX_CTLR]; hw++) {
+               if (hw->hw_type != BITMAP)
+                       continue;
+               gr = (struct grfreg *) hw->hw_addr;
+               /* XXX: redundent but safe */
+               if (badaddr((caddr_t)gr) || gr->gr_id != GRFHWID)
+                       continue;
+               switch (gr->gr_id2) {
+               case GID_GATORBOX:
+                       dtype = ITE_GATORBOX;
+                       break;
+               case GID_TOPCAT:
+               case GID_LRCATSEYE:
+               case GID_HRCCATSEYE:
+               case GID_HRMCATSEYE:
+                       dtype = ITE_TOPCAT;
+                       break;
+               case GID_RENAISSANCE:
+                       dtype = ITE_RENAISSANCE;
+                       break;
+               case GID_DAVINCI:
+                       dtype = ITE_DAVINCI;
+                       break;
+               default:
+                       continue;
+               }
+               if (i >= NITE)
+                       break;
+               ip = &ite_softc[i];
+               ip->regbase = (caddr_t) gr;
+               fboff = (gr->gr_fbomsb << 8) | gr->gr_fbolsb;
+               ip->fbbase = (caddr_t) (*((u_char *)ip->regbase+fboff) << 16);
+               /* DIO II: FB offset is relative to select code space */
+               if (ip->regbase >= (caddr_t)0x1000000)
+                       ip->fbbase += (int)ip->regbase;
+               ip->flags = ITE_ALIVE|ITE_CONSOLE;
+               ip->type = dtype;
+               i++;
+       }
+}
+
+#ifdef CONSDEBUG
+/*
+ * Allows us to cycle through all possible consoles (NITE ites and serial port)
+ * by using SHIFT-RESET on the keyboard.
+ */
+int    whichconsole = -1;
+#endif
+
+iteprobe(cp)
+       struct consdev *cp;
+{
+       register int ite;
+       register struct ite_softc *ip;
+       int unit, pri;
+
+#ifdef CONSDEBUG
+       whichconsole = ++whichconsole % (NITE+1);
+#endif
+
+       if (itecons != -1)
+               return(1);
+
+       iteconfig();
+       unit = -1;
+       pri = CN_DEAD;
+       for (ite = 0; ite < NITE; ite++) {
+#ifdef CONSDEBUG
+               if (ite < whichconsole)
+                       continue;
+#endif
+               ip = &ite_softc[ite];
+               if ((ip->flags & (ITE_ALIVE|ITE_CONSOLE))
+                   != (ITE_ALIVE|ITE_CONSOLE))
+                       continue;
+               if ((int)ip->regbase == GRFIADDR) {
+                       pri = CN_INTERNAL;
+                       unit = ite;
+               } else if (unit < 0) {
+                       pri = CN_NORMAL;
+                       unit = ite;
+               }
+       }
+       cp->cn_dev = unit;
+       cp->cn_pri = pri;
+}
+
+iteinit(cp)
+       struct consdev *cp;
+{
+       int ite = cp->cn_dev;
+       struct ite_softc *ip;
+
+       if (itecons != -1)
+               return(1);
+
+       ip = &ite_softc[ite];
+
+       ip->curx = 0;
+       ip->cury = 0;
+       ip->cursorx = 0;
+       ip->cursory = 0;
+
+       (*itesw[ip->type].ite_init)(ip);
+       (*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
+
+       itecons = ite;
+       kbdinit();
+}
+
+iteputchar(c)
+       register int c;
+{
+       register struct ite_softc *ip = &ite_softc[itecons];
+       register struct itesw *sp = &itesw[ip->type];
+
+       c &= 0x7F;
+       switch (c) {
+
+       case '\n':
+               if (++ip->cury == ip->rows) {
+                       ip->cury--;
+                       (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
+                       ite_clrtoeol(ip, sp, ip->cury, 0);
+               }
+               else
+                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+               break;
+
+       case '\r':
+               ip->curx = 0;
+               (*sp->ite_cursor)(ip, MOVE_CURSOR);
+               break;
+
+       case '\b':
+               if (--ip->curx < 0)
+                       ip->curx = 0;
+               else
+                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+               break;
+
+       default:
+               if (c < ' ' || c == 0177)
+                       break;
+               (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
+               (*sp->ite_cursor)(ip, DRAW_CURSOR);
+               itecheckwrap(ip, sp);
+               break;
+       }
+}
+
+itecheckwrap(ip, sp)
+     register struct ite_softc *ip;
+     register struct itesw *sp;
+{
+       if (++ip->curx == ip->cols) {
+               ip->curx = 0;
+               if (++ip->cury == ip->rows) {
+                       --ip->cury;
+                       (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
+                       ite_clrtoeol(ip, sp, ip->cury, 0);
+                       return;
+               }
+       }
+       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+}
+
+ite_clrtoeol(ip, sp, y, x)
+     register struct ite_softc *ip;
+     register struct itesw *sp;
+     register int y, x;
+{
+       (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
+       (*sp->ite_cursor)(ip, DRAW_CURSOR);
+}
+
+itegetchar()
+{
+#ifdef SMALL
+       return (0);
+#else
+       return (kbdgetc());
+#endif
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/ite_dv.c b/usr/src/sys/hp300/stand/ite_dv.c
new file mode 100644 (file)
index 0000000..e6eef80
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: ite_dv.c 1.1 89/02/28$
+ *
+ *     @(#)ite_dv.c    7.1 (Berkeley) %G%
+ */
+
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+#include "../hpdev/itevar.h"
+#include "../hpdev/itereg.h"
+#include "../hpdev/grfvar.h"
+#include "../hpdev/grf_dvreg.h"
+
+#define REGBASE                ((struct dvboxfb *)(ip->regbase))
+#define WINDOWMOVER    dvbox_windowmove
+
+dvbox_init(ip)
+       struct ite_softc *ip;
+{
+       int i;
+       
+       dv_reset(REGADDR);
+       DELAY(4000);
+
+       /*
+        * Turn on frame buffer, turn on overlay planes, set replacement
+        * rule, enable top overlay plane writes for ite, disable all frame
+        * buffer planes, set byte per pixel, and display frame buffer 0.
+        * Lastly, turn on the box.
+        */
+       REGBASE->interrupt = 0x04;
+       REGBASE->drive     = 0x10;              
+       REGBASE->rep_rule  = RR_COPY << 4 | RR_COPY;
+       REGBASE->opwen     = 0x01;
+       REGBASE->fbwen     = 0x0;
+       REGBASE->fold      = 0x01;
+       REGBASE->vdrive    = 0x0;
+       REGBASE->dispen    = 0x01;
+
+       /*
+        * Video enable top overlay plane.
+        */
+       REGBASE->opvenp = 0x01;
+       REGBASE->opvens = 0x01;
+
+       /*
+        * Make sure that overlay planes override frame buffer planes.
+        */
+       REGBASE->ovly0p  = 0x0;
+       REGBASE->ovly0s  = 0x0;
+       REGBASE->ovly1p  = 0x0;
+       REGBASE->ovly1s  = 0x0;
+       REGBASE->fv_trig = 0x1;
+       DELAY(400);
+
+       /*
+        * Setup the overlay colormaps. Need to set the 0,1 (black/white)
+        * color for both banks.
+        */
+
+       for (i = 0; i <= 1; i++) {
+               REGBASE->cmapbank = i;
+               REGBASE->rgb[0].red   = 0x00;
+               REGBASE->rgb[0].green = 0x00;
+               REGBASE->rgb[0].blue  = 0x00;
+               REGBASE->rgb[1].red   = 0xFF;
+               REGBASE->rgb[1].green = 0xFF;
+               REGBASE->rgb[1].blue  = 0xFF;
+       }
+       REGBASE->cmapbank = 0;
+       
+       db_waitbusy(REGADDR);
+
+       ite_devinfo(ip);
+       ite_fontinit(ip);
+
+       /*
+        * Clear the (visible) framebuffer.
+        */
+       dvbox_windowmove(ip, 0, 0, 0, 0, ip->dheight, ip->dwidth, RR_CLEAR);
+       db_waitbusy(REGADDR);
+
+       /*
+        * Stash the inverted cursor.
+        */
+       dvbox_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
+                        ip->cblanky, ip->cblankx, ip->ftheight,
+                        ip->ftwidth, RR_COPYINVERTED);
+       db_waitbusy(REGADDR);
+}
+
+dvbox_putc(ip, c, dy, dx, mode)
+       register struct ite_softc *ip;
+        register int dy, dx;
+       int c, mode;
+{
+       dvbox_windowmove(ip, charY(ip, c), charX(ip, c),
+                        dy * ip->ftheight, dx * ip->ftwidth,
+                        ip->ftheight, ip->ftwidth, RR_COPY);
+}
+
+dvbox_cursor(ip, flag)
+       register struct ite_softc *ip;
+        register int flag;
+{
+       if (flag == DRAW_CURSOR)
+               draw_cursor(ip)
+       else if (flag == MOVE_CURSOR) {
+               erase_cursor(ip)
+               draw_cursor(ip)
+       }
+       else
+               erase_cursor(ip)
+}
+
+dvbox_clear(ip, sy, sx, h, w)
+       struct ite_softc *ip;
+       register int sy, sx, h, w;
+{
+       dvbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                        sy * ip->ftheight, sx * ip->ftwidth, 
+                        h  * ip->ftheight, w  * ip->ftwidth,
+                        RR_CLEAR);
+}
+
+dvbox_scroll(ip, sy, sx, count, dir)
+        register struct ite_softc *ip;
+        register int sy, count;
+        int dir, sx;
+{
+       register int dy = sy - count;
+       register int height = ip->rows - sy;
+
+       dvbox_cursor(ip, ERASE_CURSOR);
+
+       dvbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                        dy * ip->ftheight, sx * ip->ftwidth,
+                        height * ip->ftheight,
+                        ip->cols * ip->ftwidth, RR_COPY);
+}
+
+dvbox_windowmove(ip, sy, sx, dy, dx, h, w, func)
+       struct ite_softc *ip;
+       int sy, sx, dy, dx, h, w, func;
+{
+       register struct dvboxfb *dp = REGBASE;
+       if (h == 0 || w == 0)
+               return;
+       
+       db_waitbusy(REGADDR);
+       dp->rep_rule = func << 4 | func;
+       dp->source_y = sy;
+       dp->source_x = sx;
+       dp->dest_y   = dy;
+       dp->dest_x   = dx;
+       dp->wheight  = h;
+       dp->wwidth   = w;
+       dp->wmove    = 1;
+}
+
+dv_reset(dbp)
+       register struct dvboxfb *dbp;
+{
+       dbp->reset = 0x80;
+       DELAY(400);
+
+       dbp->interrupt = 0x04;
+       dbp->en_scan   = 0x01;
+       dbp->fbwen     = ~0;
+       dbp->opwen     = ~0;
+       dbp->fold      = 0x01;
+       dbp->drive     = 0x01;
+       dbp->rep_rule  = 0x33;
+       dbp->alt_rr    = 0x33;
+       dbp->zrr       = 0x33;
+
+       dbp->fbvenp    = 0xFF;
+       dbp->dispen    = 0x01;
+       dbp->fbvens    = 0x0;
+       dbp->fv_trig   = 0x01;
+       DELAY(400);
+       dbp->vdrive    = 0x0;
+       dbp->zconfig   = 0x0;
+
+       while (dbp->wbusy & 0x01)
+         DELAY(400);
+
+       /*
+        * Start of missing ROM code.
+        */
+       dbp->cmapbank = 0;
+
+       dbp->red0   = 0;
+       dbp->red1   = 0;
+       dbp->green0 = 0;
+       dbp->green1 = 0;
+       dbp->blue0  = 0;
+       dbp->blue1  = 0;
+
+       dbp->panxh   = 0;
+       dbp->panxl   = 0;
+       dbp->panyh   = 0;
+       dbp->panyl   = 0;
+       dbp->zoom    = 0;
+       dbp->cdwidth = 0x50;
+       dbp->chstart = 0x52;
+       dbp->cvwidth = 0x22;
+       dbp->pz_trig = 1;
+       /*
+        * End of missing ROM code.
+        */
+}
+
+#endif
diff --git a/usr/src/sys/hp300/stand/ite_gb.c b/usr/src/sys/hp300/stand/ite_gb.c
new file mode 100644 (file)
index 0000000..f9d80fd
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: ite_gb.c 1.8 89/02/23$
+ *
+ *     @(#)ite_gb.c    7.1 (Berkeley) %G%
+ */
+
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+
+#include "../hpdev/itevar.h"
+#include "../hpdev/itereg.h"
+#include "../hpdev/grfvar.h"
+#include "../hpdev/grf_gbreg.h"
+
+#define REGBASE        ((struct gboxfb *)(ip->regbase))
+#define WINDOWMOVER    gatorbox_windowmove
+
+gatorbox_init(ip)
+       register struct ite_softc *ip;
+{
+       REGBASE->write_protect = 0x0;
+       REGBASE->interrupt = 0x4;
+       REGBASE->rep_rule = RR_COPY;
+       REGBASE->blink1 = 0xff;
+       REGBASE->blink2 = 0xff;
+       REGBASE->sec_interrupt = 0x01;
+
+       /*
+        * Set up the color map entries. We use three entries in the
+        * color map. The first, is for black, the second is for
+        * white, and the very last entry is for the inverted cursor.
+        */
+       REGBASE->creg_select = 0x00;
+       REGBASE->cmap_red    = 0x00;
+       REGBASE->cmap_grn    = 0x00;
+       REGBASE->cmap_blu    = 0x00;
+       REGBASE->cmap_write  = 0x00;
+       gbcm_waitbusy(REGADDR);
+       
+       REGBASE->creg_select = 0x01;
+       REGBASE->cmap_red    = 0xFF;
+       REGBASE->cmap_grn    = 0xFF;
+       REGBASE->cmap_blu    = 0xFF;
+       REGBASE->cmap_write  = 0x01;
+       gbcm_waitbusy(REGADDR);
+
+       REGBASE->creg_select = 0xFF;
+       REGBASE->cmap_red    = 0xFF;
+       REGBASE->cmap_grn    = 0xFF;
+       REGBASE->cmap_blu    = 0xFF;
+       REGBASE->cmap_write  = 0x01;
+       gbcm_waitbusy(REGADDR);
+
+       ite_devinfo(ip);
+       ite_fontinit(ip);
+
+       /*
+        * Clear the display. This used to be before the font unpacking
+        * but it crashes. Figure it out later.
+        */
+       gatorbox_windowmove(ip, 0, 0, 0, 0, ip->dheight, ip->dwidth, RR_CLEAR);
+       tile_mover_waitbusy(REGADDR);
+
+       /*
+        * Stash the inverted cursor.
+        */
+       gatorbox_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
+                           ip->cblanky, ip->cblankx, ip->ftheight,
+                           ip->ftwidth, RR_COPYINVERTED);
+}
+
+gatorbox_putc(ip, c, dy, dx, mode)
+       register struct ite_softc *ip;
+        register int dy, dx;
+       int c, mode;
+{
+       gatorbox_windowmove(ip, charY(ip, c), charX(ip, c),
+                           dy * ip->ftheight, dx * ip->ftwidth,
+                           ip->ftheight, ip->ftwidth, RR_COPY);
+}
+
+gatorbox_cursor(ip, flag)
+       register struct ite_softc *ip;
+        register int flag;
+{
+       if (flag == DRAW_CURSOR)
+               draw_cursor(ip)
+       else if (flag == MOVE_CURSOR) {
+               erase_cursor(ip)
+               draw_cursor(ip)
+       }
+       else
+               erase_cursor(ip)
+}
+
+gatorbox_clear(ip, sy, sx, h, w)
+       struct ite_softc *ip;
+       register int sy, sx, h, w;
+{
+       gatorbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                           sy * ip->ftheight, sx * ip->ftwidth, 
+                           h  * ip->ftheight, w  * ip->ftwidth,
+                           RR_CLEAR);
+}
+
+#define        gatorbox_blockmove(ip, sy, sx, dy, dx, h, w) \
+       gatorbox_windowmove((ip), \
+                           (sy) * ip->ftheight, \
+                           (sx) * ip->ftwidth, \
+                           (dy) * ip->ftheight, \
+                           (dx) * ip->ftwidth, \
+                           (h)  * ip->ftheight, \
+                           (w)  * ip->ftwidth, \
+                           RR_COPY)
+
+gatorbox_scroll(ip, sy, sx, count, dir)
+        register struct ite_softc *ip;
+        register int sy;
+        int dir, sx, count;
+{
+       register int height, dy, i;
+       
+       tile_mover_waitbusy(REGADDR);
+       REGBASE->write_protect = 0x0;
+
+       gatorbox_cursor(ip, ERASE_CURSOR);
+
+       dy = sy - count;
+       height = ip->rows - sy;
+       for (i = 0; i < height; i++)
+               gatorbox_blockmove(ip, sy + i, sx, dy + i, 0, 1, ip->cols);
+}
+
+gatorbox_windowmove(ip, sy, sx, dy, dx, h, w, mask)
+     register struct ite_softc *ip;
+     int sy, sx, dy, dx, mask;
+     register int h, w;
+{
+       register int src, dest;
+
+       src  = (sy * 1024) + sx;        /* upper left corner in pixels */
+       dest = (dy * 1024) + dx;
+
+       tile_mover_waitbusy(REGADDR);
+       REGBASE->width = -(w / 4);
+       REGBASE->height = -(h / 4);
+       if (src < dest)
+               REGBASE->rep_rule = MOVE_DOWN_RIGHT|mask;
+       else {
+               REGBASE->rep_rule = MOVE_UP_LEFT|mask;
+               /*
+                * Adjust to top of lower right tile of the block.
+                */
+               src = src + ((h - 4) * 1024) + (w - 4);
+               dest= dest + ((h - 4) * 1024) + (w - 4);
+       }
+       FBBASE[dest] = FBBASE[src];
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/ite_rb.c b/usr/src/sys/hp300/stand/ite_rb.c
new file mode 100644 (file)
index 0000000..4288c6e
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: ite_rb.c 1.5 89/02/20$
+ *
+ *     @(#)ite_rb.c    7.1 (Berkeley) %G%
+ */
+
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+#include "../hpdev/itevar.h"
+#include "../hpdev/itereg.h"
+#include "../hpdev/grfvar.h"
+#include "../hpdev/grf_rbreg.h"
+
+#define REGBASE                ((struct rboxfb *)(ip->regbase))
+#define WINDOWMOVER    rbox_windowmove
+
+rbox_init(ip)
+       struct ite_softc *ip;
+{
+       int i;
+       
+       rb_waitbusy(REGADDR);
+       DELAY(3000);
+
+       REGBASE->interrupt = 0x04;
+       REGBASE->display_enable = 0x01;
+       REGBASE->video_enable = 0x01;
+       REGBASE->drive = 0x01;
+       REGBASE->vdrive = 0x0;
+
+       ite_devinfo(ip);
+       
+       REGBASE->opwen = 0xFF;
+
+       /*
+        * Clear the framebuffer.
+        */
+       rbox_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
+       rb_waitbusy(REGADDR);
+       
+       for(i = 0; i < 16; i++) {
+               *(REGADDR + 0x63c3 + i*4) = 0x0;
+               *(REGADDR + 0x6403 + i*4) = 0x0;
+               *(REGADDR + 0x6803 + i*4) = 0x0;
+               *(REGADDR + 0x6c03 + i*4) = 0x0;
+               *(REGADDR + 0x73c3 + i*4) = 0x0;
+               *(REGADDR + 0x7403 + i*4) = 0x0;
+               *(REGADDR + 0x7803 + i*4) = 0x0;
+               *(REGADDR + 0x7c03 + i*4) = 0x0;
+       }
+
+       REGBASE->rep_rule = 0x33;
+       
+       /*
+        * I cannot figure out how to make the blink planes stop. So, we
+        * must set both colormaps so that when the planes blink, and
+        * the secondary colormap is active, we still get text.
+        */
+       CM1RED[0x00].value = 0x00;
+       CM1GRN[0x00].value = 0x00;
+       CM1BLU[0x00].value = 0x00;
+       CM1RED[0x01].value = 0xFF;
+       CM1GRN[0x01].value = 0xFF;
+       CM1BLU[0x01].value = 0xFF;
+
+       CM2RED[0x00].value = 0x00;
+       CM2GRN[0x00].value = 0x00;
+       CM2BLU[0x00].value = 0x00;
+       CM2RED[0x01].value = 0xFF;
+       CM2GRN[0x01].value = 0xFF;
+       CM2BLU[0x01].value = 0xFF;
+
+       REGBASE->blink = 0x00;
+       REGBASE->write_enable = 0x01;
+       REGBASE->opwen = 0x00;
+       
+       ite_fontinit(ip);
+
+       /*
+        * Stash the inverted cursor.
+        */
+       rbox_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
+                           ip->cblanky, ip->cblankx, ip->ftheight,
+                           ip->ftwidth, RR_COPYINVERTED);
+}
+
+rbox_putc(ip, c, dy, dx, mode)
+       register struct ite_softc *ip;
+        register int dy, dx;
+       int c, mode;
+{
+       rbox_windowmove(ip, charY(ip, c), charX(ip, c),
+                       dy * ip->ftheight, dx * ip->ftwidth,
+                       ip->ftheight, ip->ftwidth, RR_COPY);
+}
+
+rbox_cursor(ip, flag)
+       register struct ite_softc *ip;
+        register int flag;
+{
+       if (flag == DRAW_CURSOR)
+               draw_cursor(ip)
+       else if (flag == MOVE_CURSOR) {
+               erase_cursor(ip)
+               draw_cursor(ip)
+       }
+       else
+               erase_cursor(ip)
+}
+
+rbox_clear(ip, sy, sx, h, w)
+       struct ite_softc *ip;
+       register int sy, sx, h, w;
+{
+       rbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                       sy * ip->ftheight, sx * ip->ftwidth, 
+                       h  * ip->ftheight, w  * ip->ftwidth,
+                       RR_CLEAR);
+}
+
+rbox_scroll(ip, sy, sx, count, dir)
+        register struct ite_softc *ip;
+        register int sy, count;
+        int dir, sx;
+{
+       register int dy = sy - count;
+       register int height = ip->rows - sy;
+
+       rbox_cursor(ip, ERASE_CURSOR);
+
+       rbox_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                       dy * ip->ftheight, sx * ip->ftwidth,
+                       height * ip->ftheight,
+                       ip->cols * ip->ftwidth, RR_COPY);
+}
+
+rbox_windowmove(ip, sy, sx, dy, dx, h, w, func)
+       struct ite_softc *ip;
+       int sy, sx, dy, dx, h, w, func;
+{
+       register struct rboxfb *rp = REGBASE;
+       if (h == 0 || w == 0)
+               return;
+       
+       rb_waitbusy(REGADDR);
+       rp->rep_rule = func << 4 | func;
+       rp->source_y = sy;
+       rp->source_x = sx;
+       rp->dest_y = dy;
+       rp->dest_x = dx;
+       rp->wheight = h;
+       rp->wwidth  = w;
+       rp->wmove = 1;
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/ite_subr.c b/usr/src/sys/hp300/stand/ite_subr.c
new file mode 100644 (file)
index 0000000..b9aac27
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: ite_subr.c 1.1 89/02/17$
+ *
+ *     @(#)ite_subr.c  7.1 (Berkeley) %G%
+ */
+
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+#include "../hpdev/itevar.h"
+#include "../hpdev/itereg.h"
+
+ite_devinfo(ip)
+       struct ite_softc *ip;
+{
+       struct fontinfo *fi;
+       struct font *fd;
+
+       fi = (struct fontinfo *) ((*FONTROM << 8 | *(FONTROM + 2)) + REGADDR);
+       fd = (struct font *) ((fi->haddr << 8 | fi->laddr) + REGADDR);
+
+       ip->ftheight = fd->fh;
+       ip->ftwidth  = fd->fw;
+       ip->fbwidth  = ITEREGS->fbwidth_h << 8 | ITEREGS->fbwidth_l;
+       ip->fbheight = ITEREGS->fbheight_h << 8 | ITEREGS->fbheight_l;
+       ip->dwidth   = ITEREGS->dispwidth_h << 8 | ITEREGS->dispwidth_l;
+       ip->dheight  = ITEREGS->dispheight_h << 8 | ITEREGS->dispheight_l;
+       ip->rows     = ip->dheight / ip->ftheight;
+       ip->cols     = ip->dwidth / ip->ftwidth;
+
+       if (ip->fbwidth > ip->dwidth) {
+               /*
+                * Stuff goes to right of display.
+                */
+               ip->fontx    = ip->dwidth;
+               ip->fonty    = 0;
+               ip->cpl      = (ip->fbwidth - ip->dwidth) / ip->ftwidth;
+               ip->cblankx  = ip->dwidth;
+               ip->cblanky  = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight;
+       }
+       else {
+               /*
+                * Stuff goes below the display.
+                */
+               ip->fontx   = 0;
+               ip->fonty   = ip->dheight;
+               ip->cpl     = ip->fbwidth / ip->ftwidth;
+               ip->cblankx = 0;
+               ip->cblanky = ip->fonty + ((128 / ip->cpl) + 1) * ip->ftheight;
+       }
+}
+
+ite_fontinit(ip)
+       register struct ite_softc *ip;
+{
+       struct fontinfo *fi;
+       struct font *fd;
+       register u_char *fbmem, *dp;
+       register int bn;
+       int c, l, b;
+
+       fi = (struct fontinfo *) ((*FONTROM << 8 | *(FONTROM + 2)) + REGADDR);
+       fd = (struct font *) ((fi->haddr << 8 | fi->laddr) + REGADDR);
+
+       dp = fd->data;
+
+       for (c = 0; c < 128; c++) {
+               fbmem = (u_char *) FBBASE +
+                       (ip->fonty + (c / ip->cpl) * ip->ftheight) *
+                       ip->fbwidth;
+               fbmem += ip->fontx + (c % ip->cpl) * ip->ftwidth;
+               for (l = 0; l < ip->ftheight; l++) {
+                       bn = 7;
+                       for (b = 0; b < ip->ftwidth; b++) {
+                               if ((1 << bn) & *dp)
+                                       *fbmem++ = 1;
+                               else
+                                       *fbmem++ = 0;
+                               if (--bn < 0) {
+                                       bn = 7;
+                                       dp += 2;
+                               }
+                       }
+                       if (bn < 7)
+                               dp += 2;
+                       fbmem -= ip->ftwidth;
+                       fbmem += ip->fbwidth;
+               }
+       }
+
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/ite_tc.c b/usr/src/sys/hp300/stand/ite_tc.c
new file mode 100644 (file)
index 0000000..647db6a
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: ite_tc.c 1.9 89/02/20$
+ *
+ *     @(#)ite_tc.c    7.1 (Berkeley) %G%
+ */
+
+#include "samachdep.h"
+
+#ifdef ITECONSOLE
+
+#include "param.h"
+#include "../hpdev/itevar.h"
+#include "../hpdev/itereg.h"
+#include "../hpdev/grfvar.h"
+#include "../hpdev/grf_tcreg.h"
+
+#define REGBASE                ((struct tcboxfb *)(ip->regbase))
+#define WINDOWMOVER    topcat_windowmove
+
+topcat_init(ip)
+       register struct ite_softc *ip;
+{
+
+       /*
+        * Determine the number of planes by writing to the first frame
+        * buffer display location, then reading it back. 
+        */
+       REGBASE->wen = ~0;
+       REGBASE->fben = ~0;
+       REGBASE->prr = RR_COPY;
+       *FBBASE = 0xFF;
+       ip->planemask = *FBBASE;
+
+       /*
+        * Enable reading/writing of all the planes.
+        */
+       REGBASE->fben = ip->planemask;
+       REGBASE->wen  = ip->planemask;
+       REGBASE->ren  = ip->planemask;
+       REGBASE->prr  = RR_COPY;
+
+       ite_devinfo(ip);
+
+       /*
+        * Clear the framebuffer on all planes.
+        */
+       topcat_windowmove(ip, 0, 0, 0, 0, ip->fbheight, ip->fbwidth, RR_CLEAR);
+       tc_waitbusy(REGADDR, ip->planemask);
+
+       ite_fontinit(ip);
+
+       /*
+        * Stash the inverted cursor.
+        */
+       topcat_windowmove(ip, charY(ip, ' '), charX(ip, ' '),
+                         ip->cblanky, ip->cblankx, ip->ftheight,
+                         ip->ftwidth, RR_COPYINVERTED);
+}
+
+topcat_putc(ip, c, dy, dx, mode)
+       register struct ite_softc *ip;
+        register int dy, dx;
+       int c, mode;
+{
+       topcat_windowmove(ip, charY(ip, c), charX(ip, c),
+                         dy * ip->ftheight, dx * ip->ftwidth,
+                         ip->ftheight, ip->ftwidth, RR_COPY);
+}
+
+topcat_cursor(ip, flag)
+       register struct ite_softc *ip;
+        register int flag;
+{
+       if (flag == DRAW_CURSOR)
+               draw_cursor(ip)
+       else if (flag == MOVE_CURSOR) {
+               erase_cursor(ip)
+               draw_cursor(ip)
+       }
+       else
+               erase_cursor(ip)
+}
+
+topcat_clear(ip, sy, sx, h, w)
+       struct ite_softc *ip;
+       register int sy, sx, h, w;
+{
+       topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                         sy * ip->ftheight, sx * ip->ftwidth, 
+                         h  * ip->ftheight, w  * ip->ftwidth,
+                         RR_CLEAR);
+}
+
+topcat_scroll(ip, sy, sx, count, dir)
+        register struct ite_softc *ip;
+        register int sy, count;
+        int dir, sx;
+{
+       register int dy = sy - count;
+       register int height = ip->rows - sy;
+
+       topcat_cursor(ip, ERASE_CURSOR);
+
+       topcat_windowmove(ip, sy * ip->ftheight, sx * ip->ftwidth,
+                         dy * ip->ftheight, sx * ip->ftwidth,
+                         height * ip->ftheight,
+                         ip->cols  * ip->ftwidth, RR_COPY);
+}
+
+topcat_windowmove(ip, sy, sx, dy, dx, h, w, func)
+       struct ite_softc *ip;
+       int sy, sx, dy, dx, h, w, func;
+{
+       register struct tcboxfb *rp = REGBASE;
+       
+       if (h == 0 || w == 0)
+               return;
+       tc_waitbusy(REGADDR, ip->planemask);
+       rp->wmrr     = func;
+       rp->source_y = sy;
+       rp->source_x = sx;
+       rp->dest_y   = dy;
+       rp->dest_x   = dx;
+       rp->wheight  = h;
+       rp->wwidth   = w;
+       rp->wmove    = ip->planemask;
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/machdep.c b/usr/src/sys/hp300/stand/machdep.c
new file mode 100644 (file)
index 0000000..e11b88e
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: machdep.c 1.6 88/05/24$
+ *
+ *     @(#)machdep.c   7.1 (Berkeley) %G%
+ */
+
+#include "param.h"
+
+/*
+ * Copy bytes within kernel
+ */
+bcopy(from, to, count)
+       register caddr_t from, to;
+       register unsigned count;
+{
+       while (count--)
+               *to++ = *from++;
+}
+
+bzero(to, count)
+       register caddr_t to;
+       register unsigned count;
+{
+       while (count--)
+               *to++ = 0;
+}
+
+bcmp(s1, s2, len)
+       register char *s1, *s2;
+       register int len;
+{
+       while (len--)
+               if (*s1++ != *s2++)
+                       return (1);
+       return (0);
+}
+
+trap(fp)
+ struct frame {
+        int dregs[8];
+        int aregs[8];
+        int whoknows;
+        short sr;
+        int pc;
+        short frame;
+ } *fp;
+{
+       static int intrap = 0;
+
+       if (intrap)
+               return;
+       intrap = 1;
+       romprintf("Got unexpected trap, vector = %x, ps = %x, pc = %x\n",
+              fp->frame&0xFFF, fp->sr, fp->pc);
+       romprintf("dregs: %x %x %x %x %x %x %x %x\n",
+              fp->dregs[0], fp->dregs[1], fp->dregs[2], fp->dregs[3], 
+              fp->dregs[4], fp->dregs[5], fp->dregs[6], fp->dregs[7]);
+       romprintf("aregs: %x %x %x %x %x %x %x %x\n",
+              fp->aregs[0], fp->aregs[1], fp->aregs[2], fp->aregs[3], 
+              fp->aregs[4], fp->aregs[5], fp->aregs[6], fp->aregs[7]);
+       intrap = 0;
+}
+
+nodev()
+{
+       return(0);
+}
+
+#ifdef ROMPRF
+#define ROWS   46
+#define COLS   128
+
+romputchar(c)
+ register int c;
+{
+       static char buf[COLS];
+       static int col = 0, row = 0;
+       register int i;
+
+       switch (c) {
+       case '\0':
+               break;
+       case '\r':
+       case '\n':
+               for (i = col; i < COLS-1; i++)
+                       buf[i] = ' ';
+               buf[i] = '\0';
+               romout(row, buf);
+               col = 0;
+               if (++row == ROWS)
+                       row = 0;
+               break;
+
+       case '\t':
+               do {
+                       romputchar(' ');
+               } while (col & 7);
+               break;
+
+       default:
+               buf[col] = c;
+               if (++col == COLS-1)
+                       romputchar('\n');
+               break;
+       }
+}
+#endif
diff --git a/usr/src/sys/hp300/stand/mkboot.c b/usr/src/sys/hp300/stand/mkboot.c
new file mode 100644 (file)
index 0000000..e3d279f
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)mkboot.c    7.1 (Berkeley) %G%
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)mkboot.c   7.1 (Berkeley) %G%";
+#endif /* not lint */
+
+#include "machine/machparam.h"
+#include "volhdr.h"
+#include <sys/exec.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <ctype.h>
+
+int lpflag;
+int loadpoint;
+struct load ld;
+struct lifvol lifv;
+struct lifdir lifd[8];
+struct exec ex;
+char buf[10240];
+
+main(argc, argv)
+       char **argv;
+{
+       int ac;
+       char **av;
+       int from1, from2, to;
+       register int n;
+       char *n1, *n2, *lifname();
+
+       ac = --argc;
+       av = ++argv;
+       if (ac == 0)
+               usage();
+       if (!strcmp(av[0], "-l")) {
+               av++;
+               ac--;
+               if (ac == 0)
+                       usage();
+               sscanf(av[0], "0x%x", &loadpoint);
+               lpflag++;
+               av++;
+               ac--;
+       }
+       if (ac == 0)
+               usage();
+       from1 = open(av[0], O_RDONLY, 0);
+       if (from1 < 0) {
+               perror("open");
+               exit(1);
+       }
+       n1 = av[0];
+       av++;
+       ac--;
+       if (ac == 0)
+               usage();
+       if (ac == 2) {
+               from2 = open(av[0], O_RDONLY, 0);
+               if (from2 < 0) {
+                       perror("open");
+                       exit(1);
+               }
+               n2 = av[0];
+               av++;
+               ac--;
+       } else
+               from2 = -1;
+       to = open(av[0], O_WRONLY | O_TRUNC | O_CREAT, 0644);
+       if (to < 0) {
+               perror("open");
+               exit(1);
+       }
+       /* clear possibly unused directory entries */
+       strncpy(lifd[1].dir_name, "          ", 10);
+       lifd[1].dir_type = -1;
+       lifd[1].dir_addr = 0;
+       lifd[1].dir_length = 0;
+       lifd[1].dir_flag = 0xFF;
+       lifd[1].dir_exec = 0;
+       lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1];
+       /* record volume info */
+       lifv.vol_id = VOL_ID;
+       strncpy(lifv.vol_label, "BOOT43", 6);
+       lifv.vol_addr = 2;
+       lifv.vol_oct = VOL_OCT;
+       lifv.vol_dirsize = 1;
+       lifv.vol_version = 1;
+       /* output bootfile one */
+       lseek(to, 3 * SECTSIZE, 0);
+       putfile(from1, to);
+       n = (ld.count + sizeof(ld) + (SECTSIZE - 1)) / SECTSIZE;
+       strcpy(lifd[0].dir_name, lifname(n1));
+       lifd[0].dir_type = DIR_TYPE;
+       lifd[0].dir_addr = 3;
+       lifd[0].dir_length = n;
+       lifd[0].dir_flag = DIR_FLAG;
+       lifd[0].dir_exec = lpflag? loadpoint + ex.a_entry : ex.a_entry;
+       lifv.vol_length = lifd[0].dir_addr + lifd[0].dir_length;
+       /* if there is an optional second boot program, output it */
+       if (from2 >= 0) {
+               lseek(to, (3 + n) * SECTSIZE, 0);
+               putfile(from2, to);
+               n = (ld.count + sizeof(ld) + (SECTSIZE - 1)) / SECTSIZE;
+               strcpy(lifd[1].dir_name, lifname(n2));
+               lifd[1].dir_type = DIR_TYPE;
+               lifd[1].dir_addr = 3 + lifd[0].dir_length;
+               lifd[1].dir_length = n;
+               lifd[1].dir_flag = DIR_FLAG;
+               lifd[1].dir_exec = lpflag? loadpoint + ex.a_entry : ex.a_entry;
+               lifv.vol_length = lifd[1].dir_addr + lifd[1].dir_length;
+       }
+       /* output volume/directory header info */
+       lseek(to, 0 * SECTSIZE, 0);
+       write(to, &lifv, sizeof(lifv));
+       lseek(to, 2 * SECTSIZE, 0);
+       write(to, lifd, sizeof(lifd));
+       exit(0);
+}
+
+putfile(from, to)
+{
+       register int n, tcnt, dcnt;
+
+       n = read(from, &ex, sizeof(ex));
+       if (n != sizeof(ex)) {
+               fprintf(stderr, "error reading file header\n");
+               exit(1);
+       }
+       if (ex.a_magic == OMAGIC) {
+               tcnt = ex.a_text;
+               dcnt = ex.a_data;
+       }
+       else if (ex.a_magic == NMAGIC) {
+               tcnt = (ex.a_text + PGOFSET) & ~PGOFSET;
+               dcnt = ex.a_data;
+       }
+       else {
+               fprintf(stderr, "bad magic number\n");
+               exit(1);
+       }
+       ld.address = lpflag ? loadpoint : ex.a_entry;
+       ld.count = tcnt + dcnt;
+       write(to, &ld, sizeof(ld));
+       while (tcnt) {
+               n = sizeof(buf);
+               if (n > tcnt)
+                       n = tcnt;
+               n = read(from, buf, n);
+               if (n < 0) {
+                       perror("read");
+                       exit(1);
+               }
+               if (n == 0) {
+                       fprintf(stderr, "short read\n");
+                       exit(1);
+               }
+               if (write(to, buf, n) < 0) {
+                       perror("write");
+                       exit(1);
+               }
+               tcnt -= n;
+       }
+       while (dcnt) {
+               n = sizeof(buf);
+               if (n > dcnt)
+                       n = dcnt;
+               n = read(from, buf, n);
+               if (n < 0) {
+                       perror("read");
+                       exit(1);
+               }
+               if (n == 0) {
+                       fprintf(stderr, "short read\n");
+                       exit(1);
+               }
+               if (write(to, buf, n) < 0) {
+                       perror("write");
+                       exit(1);
+               }
+               dcnt -= n;
+       }
+}
+
+usage()
+{
+       fprintf(stderr,
+               "usage:  mkboot [-l loadpoint] prog1 [ prog2 ] outfile\n");
+       exit(1);
+}
+
+char *
+lifname(str)
+ char *str;
+{
+       static char lname[10] = "SYS_XXXXX";
+       register int i;
+
+       for (i = 4; i < 9; i++) {
+               if (islower(*str))
+                       lname[i] = toupper(*str);
+               else if (isalnum(*str) || *str == '_')
+                       lname[i] = *str;
+               else
+                       break;
+               str++;
+       }
+       for ( ; i < 10; i++)
+               lname[i] = '\0';
+       return(lname);
+}
diff --git a/usr/src/sys/hp300/stand/nhpib.c b/usr/src/sys/hp300/stand/nhpib.c
new file mode 100644 (file)
index 0000000..46cd62e
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)nhpib.c     7.1 (Berkeley) %G%
+ */
+
+/*
+ * Internal/98624 HPIB driver
+ */
+
+#include "param.h"
+#include "../hpdev/nhpibreg.h"
+#include "hpibvar.h"
+
+nhpibinit(unit)
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct nhpibdevice *hd = (struct nhpibdevice *)hs->sc_addr;
+       extern int internalhpib;
+
+       if ((int)hd == internalhpib) {
+               hs->sc_type = HPIBA;
+               hs->sc_ba = HPIBA_BA;
+       }
+       else if (hd->hpib_cid == HPIBB) {
+               hs->sc_type = HPIBB;
+               hs->sc_ba = hd->hpib_csa & CSA_BA;
+       }
+       else
+               return(0);
+       nhpibreset(unit);
+       return(1);
+}
+
+nhpibreset(unit)
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct nhpibdevice *hd;
+
+       hd = (struct nhpibdevice *)hs->sc_addr;
+       hd->hpib_acr = AUX_SSWRST;
+       hd->hpib_ar = hs->sc_ba;
+       hd->hpib_lim = 0;
+       hd->hpib_mim = 0;
+       hd->hpib_acr = AUX_CDAI;
+       hd->hpib_acr = AUX_CSHDW;
+       hd->hpib_acr = AUX_SSTD1;
+       hd->hpib_acr = AUX_SVSTD1;
+       hd->hpib_acr = AUX_CPP;
+       hd->hpib_acr = AUX_CHDFA;
+       hd->hpib_acr = AUX_CHDFE;
+       hd->hpib_acr = AUX_RHDF;
+       hd->hpib_acr = AUX_CSWRST;
+       hd->hpib_acr = AUX_TCA;
+       hd->hpib_acr = AUX_CSRE;
+       hd->hpib_acr = AUX_SSIC;
+       DELAY(100);
+       hd->hpib_acr = AUX_CSIC;
+       hd->hpib_acr = AUX_SSRE;
+       hd->hpib_data = C_DCL;
+       DELAY(100000);
+}
+
+nhpibsend(unit, slave, sec, buf, cnt)
+       register char *buf;
+       register int cnt;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct nhpibdevice *hd;
+       register int origcnt = cnt;
+
+       hd = (struct nhpibdevice *)hs->sc_addr;
+       hd->hpib_acr = AUX_TCA;
+       hd->hpib_data = C_UNL;
+       nhpibowait(hd);
+       hd->hpib_data = C_TAG + hs->sc_ba;
+       hd->hpib_acr = AUX_STON;
+       nhpibowait(hd);
+       hd->hpib_data = C_LAG + slave;
+       nhpibowait(hd);
+       if (sec != -1) {
+               hd->hpib_data = C_SCG + sec;
+               nhpibowait(hd);
+       }
+       hd->hpib_acr = AUX_GTS;
+       if (cnt) {
+               while (--cnt) {
+                       hd->hpib_data = *buf++;
+                       if (nhpibowait(hd) < 0)
+                               break;
+               }
+               hd->hpib_acr = AUX_EOI;
+               hd->hpib_data = *buf;
+               if (nhpibowait(hd) < 0)
+                       cnt++;
+               hd->hpib_acr = AUX_TCA;
+       }
+       return(origcnt - cnt);
+}
+
+nhpibrecv(unit, slave, sec, buf, cnt)
+       register char *buf;
+       register int cnt;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct nhpibdevice *hd;
+       register int origcnt = cnt;
+
+       hd = (struct nhpibdevice *)hs->sc_addr;
+       hd->hpib_acr = AUX_TCA;
+       hd->hpib_data = C_UNL;
+       nhpibowait(hd);
+       hd->hpib_data = C_LAG + hs->sc_ba;
+       hd->hpib_acr = AUX_SLON;
+       nhpibowait(hd);
+       hd->hpib_data = C_TAG + slave;
+       nhpibowait(hd);
+       if (sec != -1) {
+               hd->hpib_data = C_SCG + sec;
+               nhpibowait(hd);
+       }
+       hd->hpib_acr = AUX_RHDF;
+       hd->hpib_acr = AUX_GTS;
+       if (cnt) {
+               while (--cnt >= 0) {
+                       if (nhpibiwait(hd) < 0)
+                               break;
+                       *buf++ = hd->hpib_data;
+               }
+               cnt++;
+               hd->hpib_acr = AUX_TCA;
+       }
+       return(origcnt - cnt);
+}
+
+nhpibppoll(unit)
+       register int unit;
+{
+       register struct hpib_softc *hs = &hpib_softc[unit];
+       register struct nhpibdevice *hd;
+       register int ppoll;
+
+       hd = (struct nhpibdevice *)hs->sc_addr;
+       hd->hpib_acr = AUX_SPP;
+       DELAY(25);
+       ppoll = hd->hpib_cpt;
+       hd->hpib_acr = AUX_CPP;
+       return(ppoll);
+}
+
+nhpibowait(hd)
+       register struct nhpibdevice *hd;
+{
+       register int timo = 100000;
+
+       while ((hd->hpib_mis & MIS_BO) == 0 && --timo)
+               ;
+       if (timo == 0)
+               return(-1);
+       return(0);
+}
+
+nhpibiwait(hd)
+       register struct nhpibdevice *hd;
+{
+       register int timo = 100000;
+
+       while ((hd->hpib_mis & MIS_BI) == 0 && --timo)
+               ;
+       if (timo == 0)
+               return(-1);
+       return(0);
+}
diff --git a/usr/src/sys/hp300/stand/prf.c b/usr/src/sys/hp300/stand/prf.c
new file mode 100644 (file)
index 0000000..4946d8a
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)prf.c       7.1 (Berkeley) %G%
+ */
+
+#include "../h/param.h"
+
+/*
+ * Scaled down version of C Library printf.
+ * Used to print diagnostic information directly on console tty.
+ * Since it is not interrupt driven, all system activities are
+ * suspended.  Printf should not be used for chit-chat.
+ *
+ * One additional format: %b is supported to decode error registers.
+ * Usage is:
+ *     printf("reg=%b\n", regval, "<base><arg>*");
+ * Where <base> is the output base expressed as a control character,
+ * e.g. \10 gives octal; \20 gives hex.  Each arg is a sequence of
+ * characters, the first of which gives the bit number to be inspected
+ * (origin 1), and the next characters (up to a control character, i.e.
+ * a character <= 32), give the name of the register.  Thus
+ *     printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
+ * would produce output:
+ *     reg=2<BITTWO,BITONE>
+ */
+/*VARARGS1*/
+printf(fmt, x1)
+       char *fmt;
+       unsigned x1;
+{
+
+       prf(0, fmt, &x1);
+}
+
+/*VARARGS1*/
+romprintf(fmt, x1)
+       char *fmt;
+       unsigned x1;
+{
+
+       prf(1, fmt, &x1);
+}
+
+prf(userom, fmt, adx)
+       register char *fmt;
+       register u_int *adx;
+{
+       register int b, c, i;
+       char *s;
+       int any;
+
+loop:
+       while ((c = *fmt++) != '%') {
+               if(c == '\0')
+                       return;
+               putchar(userom, c);
+       }
+again:
+       c = *fmt++;
+       /* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */
+       switch (c) {
+
+       case 'l':
+               goto again;
+       case 'x': case 'X':
+               b = 16;
+               goto number;
+       case 'd': case 'D':
+       case 'u':               /* what a joke */
+               b = 10;
+               goto number;
+       case 'o': case 'O':
+               b = 8;
+number:
+               printn(userom, (u_long)*adx, b);
+               break;
+       case 'c':
+               b = *adx;
+               for (i = 24; i >= 0; i -= 8)
+                       if (c = (b >> i) & 0x7f)
+                               putchar(userom, c);
+               break;
+       case 'b':
+               b = *adx++;
+               s = (char *)*adx;
+               printn(userom, (u_long)b, *s++);
+               any = 0;
+               if (b) {
+                       while (i = *s++) {
+                               if (b & (1 << (i-1))) {
+                                       putchar(userom, any? ',' : '<');
+                                       any = 1;
+                                       for (; (c = *s) > 32; s++)
+                                               putchar(userom, c);
+                               } else
+                                       for (; *s > 32; s++)
+                                               ;
+                       }
+                       if (any)
+                               putchar(userom, '>');
+               }
+               break;
+
+       case 's':
+               s = (char *)*adx;
+               while (c = *s++)
+                       putchar(userom, c);
+               break;
+       }
+       adx++;
+       goto loop;
+}
+
+/*
+ * Printn prints a number n in base b.
+ * We don't use recursion to avoid deep kernel stacks.
+ */
+printn(userom, n, b)
+       u_long n;
+{
+       char prbuf[11];
+       register char *cp;
+
+       if (b == 10 && (int)n < 0) {
+               putchar(userom, '-');
+               n = (unsigned)(-(int)n);
+       }
+       cp = prbuf;
+       do {
+               *cp++ = "0123456789abcdef"[n%b];
+               n /= b;
+       } while (n);
+       do
+               putchar(userom, *--cp);
+       while (cp > prbuf);
+}
+
+/*
+ * Print a character on console.
+ */
+putchar(userom, c)
+       register c;
+{
+#ifdef ROMPRF
+       if (userom) {
+               romputchar(c);
+               return;
+       }
+#endif
+       cnputc(c);
+       if(c == '\n')
+               cnputc('\r');
+}
+
+peekchar()
+{
+       register c;
+
+       c = cngetc();
+       if (c == ('c'&037)) {
+               printf("^C");
+               _stop("");
+               /* NOTREACHED */
+       }
+       return(c);
+}
+
+getchar()
+{
+       register c;
+
+       while((c = cngetc()) == 0)
+               ;
+       if (c == '\r')
+               c = '\n';
+       else if (c == ('c'&037)) {
+               printf("^C");
+               _stop("");
+               /* NOTREACHED */
+       }
+       putchar(0, c);
+       return(c);
+}
+
+gets(buf)
+       char *buf;
+{
+       register char *lp;
+       register c;
+
+       lp = buf;
+       for (;;) {
+               c = getchar() & 0177;
+               switch(c) {
+               case '\n':
+               case '\r':
+                       c = '\n';
+                       *lp++ = '\0';
+                       return;
+               case '\b':
+                       if (lp > buf) {
+                               lp--;
+                               putchar(0, ' ');
+                               putchar(0, '\b');
+                       }
+                       continue;
+               case '#':
+               case '\177':
+                       lp--;
+                       if (lp < buf)
+                               lp = buf;
+                       continue;
+               case '@':
+               case 'u'&037:
+                       lp = buf;
+                       putchar(0, '\n');
+                       continue;
+               default:
+                       *lp++ = c;
+               }
+       }
+}
+
diff --git a/usr/src/sys/hp300/stand/rd.c b/usr/src/sys/hp300/stand/rd.c
new file mode 100644 (file)
index 0000000..843eafd
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: rd.c 1.14 89/02/27$
+ *
+ *     @(#)rd.c        7.1 (Berkeley) %G%
+ */
+
+/*
+ * CS80/SS80 disk driver
+ */
+#include "saio.h"
+#include "samachdep.h"
+
+#include "../hpdev/rdreg.h"
+
+struct rd_iocmd rd_ioc;
+struct rd_rscmd rd_rsc;
+struct rd_stat rd_stat;
+struct rd_ssmcmd rd_ssmc;
+
+struct rd_softc {
+       char    sc_retry;
+       char    sc_alive;
+       short   sc_type;
+} rd_softc[NRD];
+
+#define        RDRETRY         5
+
+int rdcyloff[][8] = {
+       { 1, 143, 0, 143, 0,   0,   323, 503, },        /* 7945A */
+       { 1, 167, 0, 0,   0,   0,   0,   0,   },        /* 9134D */
+       { 0, 0,   0, 0,   0,   0,   0,   0,   },        /* 9122S */
+       { 0, 71,  0, 221, 292, 542, 221, 0,   },        /* 7912P */
+       { 1, 72,  0, 72,  362, 802, 252, 362, },        /* 7914P */
+       { 1, 28,  0, 140, 167, 444, 140, 721, },        /* 7933H */
+       { 1, 200, 0, 200, 0,   0,   450, 600, },        /* 9134L */
+       { 1, 105, 0, 105, 380, 736, 265, 380, },        /* 7957A */
+       { 1, 65,  0, 65,  257, 657, 193, 257, },        /* 7958A */
+       { 1, 128, 0, 128, 518, 918, 388, 518, },        /* 7957B */
+       { 1, 44,  0, 44,  174, 496, 131, 174, },        /* 7958B */
+       { 1, 44,  0, 44,  218, 918, 174, 218, },        /* 7959B */
+       { 1, 20,  0, 98,  117, 256, 98,  397, },        /* 7936H */
+       { 1, 11,  0, 53,  63,  217, 53,  371, },        /* 7937H */
+};
+
+struct rdinfo {
+       int     nbpc;
+       int     hwid;
+       int     *cyloff;
+} rdinfo[] = {
+       NRD7945ABPT*NRD7945ATRK, RD7946AID, rdcyloff[0],
+       NRD9134DBPT*NRD9134DTRK, RD9134DID, rdcyloff[1],
+       NRD9122SBPT*NRD9122STRK, RD9134LID, rdcyloff[2],
+       NRD7912PBPT*NRD7912PTRK, RD7912PID, rdcyloff[3],
+       NRD7914PBPT*NRD7914PTRK, RD7914PID, rdcyloff[4],
+       NRD7958ABPT*NRD7958ATRK, RD7958AID, rdcyloff[8],
+       NRD7957ABPT*NRD7957ATRK, RD7957AID, rdcyloff[7],
+       NRD7933HBPT*NRD7933HTRK, RD7933HID, rdcyloff[5],
+       NRD9134LBPT*NRD9134LTRK, RD9134LID, rdcyloff[6],
+       NRD7936HBPT*NRD7936HTRK, RD7936HID, rdcyloff[12],
+       NRD7937HBPT*NRD7937HTRK, RD7937HID, rdcyloff[13],
+       NRD7914PBPT*NRD7914PTRK, RD7914CTID,rdcyloff[4],
+       NRD7945ABPT*NRD7945ATRK, RD7946AID, rdcyloff[0],
+       NRD9122SBPT*NRD9122STRK, RD9134LID, rdcyloff[2],
+       NRD7957BBPT*NRD7957BTRK, RD7957BID, rdcyloff[9],
+       NRD7958BBPT*NRD7958BTRK, RD7958BID, rdcyloff[10],
+       NRD7959BBPT*NRD7959BTRK, RD7959BID, rdcyloff[11],
+};
+int    nrdinfo = sizeof(rdinfo) / sizeof(rdinfo[0]);
+                                       
+rdinit(unit)
+       register int unit;
+{
+       register struct rd_softc *rs;
+       u_char stat;
+
+       if (unit > NRD)
+               return (0);
+       rs = &rd_softc[unit];
+       rs->sc_type = rdident(unit);
+       if (rs->sc_type < 0)
+               return (0);
+       rs->sc_alive = 1;
+       return (1);
+}
+
+rdreset(unit)
+{
+       u_char stat;
+
+       rd_ssmc.c_unit = C_SUNIT(0);
+       rd_ssmc.c_cmd = C_SSM;
+       rd_ssmc.c_refm = REF_MASK;
+       rd_ssmc.c_fefm = FEF_MASK;
+       rd_ssmc.c_aefm = AEF_MASK;
+       rd_ssmc.c_iefm = IEF_MASK;
+       hpibsend(unit, C_CMD, &rd_ssmc, sizeof(rd_ssmc));
+       hpibswait(unit);
+       hpibrecv(unit, C_QSTAT, &stat, 1);
+}
+
+rdident(unit)
+{
+       struct rd_describe desc;
+       u_char stat, cmd[3];
+       char name[7];
+       register int id, i;
+
+       id = hpibid(unit);
+       if ((id & 0x200) == 0)
+               return(-1);
+       for (i = 0; i < nrdinfo; i++)
+               if (id == rdinfo[i].hwid)
+                       break;
+       if (i == nrdinfo)
+               return(-1);
+       id = i;
+       rdreset(unit);
+       cmd[0] = C_SUNIT(0);
+       cmd[1] = C_SVOL(0);
+       cmd[2] = C_DESC;
+       hpibsend(unit, C_CMD, cmd, sizeof(cmd));
+       hpibrecv(unit, C_EXEC, &desc, 37);
+       hpibrecv(unit, C_QSTAT, &stat, sizeof(stat));
+       bzero(name, sizeof(name));
+       if (!stat) {
+               register int n = desc.d_name;
+               for (i = 5; i >= 0; i--) {
+                       name[i] = (n & 0xf) + '0';
+                       n >>= 4;
+               }
+       }
+       /*
+        * Take care of a couple of anomolies:
+        * 1. 7945A and 7946A both return same HW id
+        * 2. 9122S and 9134D both return same HW id
+        * 3. 9122D and 9134L both return same HW id
+        */
+       switch (rdinfo[id].hwid) {
+       case RD7946AID:
+               if (bcmp(name, "079450", 6) == 0)
+                       id = RD7945A;
+               else
+                       id = RD7946A;
+               break;
+
+       case RD9134LID:
+               if (bcmp(name, "091340", 6) == 0)
+                       id = RD9134L;
+               else
+                       id = RD9122D;
+               break;
+
+       case RD9134DID:
+               if (bcmp(name, "091220", 6) == 0)
+                       id = RD9122S;
+               else
+                       id = RD9134D;
+               break;
+       }
+       return(id);
+}
+
+rdopen(io)
+       struct iob *io;
+{
+       register int unit = io->i_unit;
+       register struct rd_softc *rs = &rd_softc[unit];
+       struct rdinfo *ri;
+
+       if (hpibalive(unit) == 0)
+               _stop("rd controller not configured");
+       if (rs->sc_alive == 0)
+               if (rdinit(unit) == 0)
+                       _stop("rd init failed");
+       if (io->i_boff < 0 || io->i_boff > 7)
+               _stop("rd bad minor");
+       ri = &rdinfo[rs->sc_type];
+       io->i_boff = ri->cyloff[io->i_boff] * ri->nbpc;
+}
+
+rdstrategy(io, func)
+       register struct iob *io;
+       register int func;
+{
+       register int unit = io->i_unit;
+       register struct rd_softc *rs = &rd_softc[unit];
+       char stat;
+
+       rs->sc_retry = 0;
+       rd_ioc.c_unit = C_SUNIT(0);
+       rd_ioc.c_volume = C_SVOL(0);
+       rd_ioc.c_saddr = C_SADDR;
+       rd_ioc.c_hiaddr = 0;
+       rd_ioc.c_addr = RDBTOS(io->i_bn);
+       rd_ioc.c_nop2 = C_NOP;
+       rd_ioc.c_slen = C_SLEN;
+       rd_ioc.c_len = io->i_cc;
+       rd_ioc.c_cmd = func == READ ? C_READ : C_WRITE;
+retry:
+       hpibsend(unit, C_CMD, &rd_ioc.c_unit, sizeof(rd_ioc)-2);
+       hpibswait(unit);
+       hpibgo(unit, C_EXEC, io->i_ma, io->i_cc, func);
+       hpibswait(unit);
+       hpibrecv(unit, C_QSTAT, &stat, 1);
+       if (stat) {
+               if (rderror(unit) == 0)
+                       return(-1);
+               if (++rs->sc_retry > RDRETRY)
+                       return(-1);
+               else
+                       goto retry;
+       }
+       return(io->i_cc);
+}
+
+rderror(unit)
+       register int unit;
+{
+       register struct rd_softc *rd = &rd_softc[unit];
+       char stat;
+
+       rd_rsc.c_unit = C_SUNIT(0);
+       rd_rsc.c_sram = C_SRAM;
+       rd_rsc.c_ram = C_RAM;
+       rd_rsc.c_cmd = C_STATUS;
+       hpibsend(unit, C_CMD, &rd_rsc, sizeof(rd_rsc));
+       hpibrecv(unit, C_EXEC, &rd_stat, sizeof(rd_stat));
+       hpibrecv(unit, C_QSTAT, &stat, 1);
+       if (stat) {
+               printf("rd(%d,?): request status fail %d\n", unit, stat);
+               return(0);
+       }
+       printf("rd(%d,?) err: vu 0x%x", unit, rd_stat.c_vu);
+       if ((rd_stat.c_aef & AEF_UD) || (rd_stat.c_ief & (IEF_MD|IEF_RD)))
+               printf(", block %d", rd_stat.c_blk);
+       printf(", R0x%x F0x%x A0x%x I0x%x\n",
+              rd_stat.c_ref, rd_stat.c_fef, rd_stat.c_aef, rd_stat.c_ief);
+       return(1);
+}
diff --git a/usr/src/sys/hp300/stand/rominfo.h b/usr/src/sys/hp300/stand/rominfo.h
new file mode 100644 (file)
index 0000000..c4deca4
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: rominfo.h 1.2 88/05/24$
+ *
+ *     @(#)rominfo.h   7.1 (Berkeley) %G%
+ */
+
+#define ROMADDR        0xFFFFF000
+
+struct jmpvec {
+       short op;       /* jmp instruction */
+       long  addr;     /* address */
+};
+
+struct rominfo {
+       char p1[0xDC0];
+       short boottype;         /* ??                           (FFFFFDC0) */
+       char  name[10];         /* HP system name, e.g. SYSHPUX (FFFFFDC2) */
+       short p2;               /* ??                           (FFFFFDCC) */
+       long  lowram;           /* lowest useable RAM location  (FFFFFDCE) */
+       char  p3[0x100];        /* ??                           (FFFFFDD2) */
+       char  sysflag;          /* HP system flags              (FFFFFED2) */
+       char  p4;               /* ??                           (FFFFFED3) */
+       long  rambase;          /* physaddr of lowest RAM       (FFFFFED4) */
+       char  ndrives;          /* number of drives             (FFFFFED8) */
+       char  p5;               /* ??                           (FFFFFED9) */
+       char  sysflag2;         /* more system flags            (FFFFFEDA) */
+       char  p6;               /* ??                           (FFFFFEDB) */
+       long  msus;             /* ??                           (FFFFFEDC) */
+       struct jmpvec jvec[48]; /* jump vectors                 (FFFFFEE0) */
+};
+
diff --git a/usr/src/sys/hp300/stand/saio.h b/usr/src/sys/hp300/stand/saio.h
new file mode 100644 (file)
index 0000000..33f9777
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)saio.h      7.1 (Berkeley) %G%
+ */
+
+/*
+ * Header file for standalone package
+ */
+
+#include "../h/types.h"
+#include "../h/param.h"
+#include "../ufs/dinode.h"
+#include "../ufs/fs.h"
+
+/*
+ * Io block: includes a
+ * dinode, cells for the use of seek, etc,
+ * and a buffer.
+ */
+struct iob {
+       int     i_flgs;         /* see F_ below */
+       struct  dinode i_ino;   /* dinode, if file */
+       int     i_unit;         /* pseudo device unit */
+       daddr_t i_boff;         /* block offset on device */
+       daddr_t i_cyloff;       /* cylinder offset on device */
+       off_t   i_offset;       /* seek offset in file */
+       daddr_t i_bn;           /* 1st block # of next read */
+       char    *i_ma;          /* memory address of i/o buffer */
+       int     i_cc;           /* character count of transfer */
+       int     i_error;        /* error # return */
+       int     i_errcnt;       /* error count for driver retries */
+       int     i_errblk;       /* block # in error for error reporting */
+       char    i_buf[MAXBSIZE];/* i/o buffer */
+       union {
+               struct fs ui_fs;        /* file system super block info */
+               char dummy[SBSIZE];
+       } i_un;
+};
+#define i_fs i_un.ui_fs
+#define NULL 0
+
+#define F_READ         0x1     /* file opened for reading */
+#define F_WRITE                0x2     /* file opened for writing */
+#define F_ALLOC                0x4     /* buffer allocated */
+#define F_FILE         0x8     /* file instead of device */
+#define F_NBSF         0x10    /* no bad sector forwarding */
+#define F_SSI          0x40    /* set skip sector inhibit */
+/* io types */
+#define        F_RDDATA        0x0100  /* read data */
+#define        F_WRDATA        0x0200  /* write data */
+#define F_HDR          0x0400  /* include header on next i/o */
+#define F_CHECK                0x0800  /* perform check of data read/write */
+#define F_HCHECK       0x1000  /* perform check of header and data */
+
+#define        F_TYPEMASK      0xff00
+
+/*
+ * Device switch.
+ */
+struct devsw {
+       char    *dv_name;
+       int     (*dv_strategy)();
+       int     (*dv_open)();
+       int     (*dv_close)();
+       int     (*dv_ioctl)();
+};
+
+struct devsw devsw[];
+
+/*
+ * Drive description table.
+ * Returned from SAIODEVDATA call.
+ */
+struct st {
+       short   nsect;          /* # sectors/track */
+       short   ntrak;          /* # tracks/surfaces/heads */
+       short   nspc;           /* # sectors/cylinder */
+       short   ncyl;           /* # cylinders */
+       short   *off;           /* partition offset table (cylinders) */
+};
+
+/*
+ * Request codes. Must be the same a F_XXX above
+ */
+#define        READ    1
+#define        WRITE   2
+
+#define        NBUFS   4
+
+char   b[NBUFS][MAXBSIZE];
+daddr_t        blknos[NBUFS];
+
+#define        NFILES  4
+struct iob iob[NFILES];
+
+extern int errno;      /* just like unix */
+
+/* error codes */
+#define        EBADF   1       /* bad file descriptor */
+#define        EOFFSET 2       /* relative seek not supported */
+#define        EDEV    3       /* improper device specification on open */
+#define        ENXIO   4       /* unknown device specified */
+#define        EUNIT   5       /* improper unit specification */
+#define        ESRCH   6       /* directory search for file failed */
+#define        EIO     7       /* generic error */
+#define        ECMD    10      /* undefined driver command */
+#define        EBSE    11      /* bad sector error */
+#define        EWCK    12      /* write check error */
+#define        EECC    13      /* uncorrectable ecc error */
+#define        EHER    14      /* hard error */
+
+/* ioctl's -- for disks just now */
+#define        SAIOHDR         (('d'<<8)|1)    /* next i/o includes header */
+#define        SAIOCHECK       (('d'<<8)|2)    /* next i/o checks data */
+#define        SAIOHCHECK      (('d'<<8)|3)    /* next i/o checks header & data */
+#define        SAIONOBAD       (('d'<<8)|4)    /* inhibit bad sector forwarding */
+#define        SAIODOBAD       (('d'<<8)|5)    /* enable bad sector forwarding */
+#define        SAIOECCLIM      (('d'<<8)|6)    /* set limit to ecc correction, bits */
+#define        SAIORETRIES     (('d'<<8)|7)    /* set retry count for unit */
+#define        SAIODEVDATA     (('d'<<8)|8)    /* get device data */
+#define        SAIOSSI         (('d'<<8)|9)    /* set skip sector inhibit */
+#define        SAIONOSSI       (('d'<<8)|10)   /* inhibit skip sector handling */
+#define        SAIOSSDEV       (('d'<<8)|11)   /* is device skip sector type? */
+#define        SAIODEBUG       (('d'<<8)|12)   /* enable/disable debugging */
+#define        SAIOGBADINFO    (('d'<<8)|13)   /* get bad-sector table */
diff --git a/usr/src/sys/hp300/stand/samachdep.h b/usr/src/sys/hp300/stand/samachdep.h
new file mode 100644 (file)
index 0000000..e90d7c3
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)samachdep.h 7.1 (Berkeley) %G%
+ */
+
+#define        NHPIB           4
+#define NITE           4
+#define        NSCSI           2
+#define NRD            (NHPIB * 8)
+#define NCT            (NHPIB * 8)
+#define NSD            (NSCSI * 8)
+
+#define IOV(x)         (x)
+
+extern int howto, devtype;
+
+/* bogon grfinfo structure to keep grf_softc happy */
+struct grfinfo {
+       int     grf_foo;
+};
diff --git a/usr/src/sys/hp300/stand/scsi.c b/usr/src/sys/hp300/stand/scsi.c
new file mode 100644 (file)
index 0000000..85389f7
--- /dev/null
@@ -0,0 +1,433 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Van Jacobson of Lawrence Berkeley Laboratory and the Systems
+ * Programming Group of the University of Utah Computer Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: scsi.c 1.3 90/01/27$
+ *
+ *     @(#)scsi.c      7.1 (Berkeley) %G%
+ */
+
+/*
+ * SCSI bus driver for standalone programs.
+ */
+
+#include "../sys/types.h"
+#include "../sys/reboot.h"
+#include "../hpdev/device.h"
+#include "../hpdev/scsireg.h"
+#include "scsivar.h"
+
+#include "saio.h"
+#include "samachdep.h"
+
+struct scsi_softc scsi_softc[NSCSI];
+
+#define        scsiunit(x)     ((x) >> 3)
+#define        scsislave(x)    ((x) & 7)
+
+void scsireset();
+int scsi_cmd_wait = 500;
+int scsi_data_wait = 300000;
+
+scsiinit()
+{
+       extern struct hp_hw sc_table[];
+       register struct hp_hw *hw;
+       register struct scsi_softc *hs;
+       register int i, addr;
+       static int first = 1;
+       
+       i = 0;
+       for (hw = sc_table; i < NSCSI && hw < &sc_table[MAX_CTLR]; hw++) {
+               if (hw->hw_type != SCSI)
+                       continue;
+               hs = &scsi_softc[i];
+               hs->sc_addr = hw->hw_addr;
+               scsireset(i);
+               if (howto & RB_ASKNAME)
+                       printf("scsi%d at sc%d\n", i, hw->hw_sc);
+               /*
+                * Adjust devtype on first call.  This routine assumes that
+                * adaptor is in the high byte of devtype.
+                */
+               if (first && ((devtype >> 24) & 0xff) == hw->hw_sc) {
+                       devtype = (devtype & 0x00ffffff) | (i << 24);
+                       first = 0;
+               }
+               hs->sc_alive = 1;
+               i++;
+       }
+}
+
+scsialive(unit)
+       register int unit;
+{
+       unit = scsiunit(unit);
+       if (unit >= NSCSI || scsi_softc[unit].sc_alive == 0)
+               return (0);
+       return (1);
+}
+
+void
+scsireset(unit)
+       register int unit;
+{
+       volatile register struct scsidevice *hd;
+       register struct scsi_softc *hs;
+       u_int i;
+
+       unit = scsiunit(unit);
+       hs = &scsi_softc[unit];
+       hd = (struct scsidevice *)hs->sc_addr;
+       hd->scsi_id = 0xFF;
+       DELAY(100);
+       /*
+        * Disable interrupts then reset the FUJI chip.
+        */
+       hd->scsi_csr  = 0;
+       hd->scsi_sctl = SCTL_DISABLE | SCTL_CTRLRST;
+       hd->scsi_scmd = 0;
+       hd->scsi_tmod = 0;
+       hd->scsi_pctl = 0;
+       hd->scsi_temp = 0;
+       hd->scsi_tch  = 0;
+       hd->scsi_tcm  = 0;
+       hd->scsi_tcl  = 0;
+       hd->scsi_ints = 0;
+
+       /*
+        * Configure the FUJI chip with its SCSI address, all
+        * interrupts enabled & appropriate parity.
+        */
+       i = (~hd->scsi_hconf) & 0x7;
+       hs->sc_scsi_addr = 1 << i;
+       hd->scsi_bdid = i;
+       if (hd->scsi_hconf & HCONF_PARITY)
+               hd->scsi_sctl = SCTL_DISABLE | SCTL_ABRT_ENAB |
+                               SCTL_SEL_ENAB | SCTL_RESEL_ENAB |
+                               SCTL_INTR_ENAB | SCTL_PARITY_ENAB;
+       else
+               hd->scsi_sctl = SCTL_DISABLE | SCTL_ABRT_ENAB |
+                               SCTL_SEL_ENAB | SCTL_RESEL_ENAB |
+                               SCTL_INTR_ENAB;
+       hd->scsi_sctl &=~ SCTL_DISABLE;
+}
+
+
+int
+scsiabort(hs, hd)
+       register struct scsi_softc *hs;
+       volatile register struct scsidevice *hd;
+{
+       printf("scsi error: scsiabort\n");
+       return (0);
+}
+
+static int
+issue_select(hd, target, our_addr)
+       volatile register struct scsidevice *hd;
+       u_char target, our_addr;
+{
+       if (hd->scsi_ssts & (SSTS_INITIATOR|SSTS_TARGET|SSTS_BUSY))
+               return (1);
+
+       if (hd->scsi_ints & INTS_DISCON)
+               hd->scsi_ints = INTS_DISCON;
+
+       hd->scsi_pctl = 0;
+       hd->scsi_temp = (1 << target) | our_addr;
+       /* select timeout is hardcoded to 2ms */
+       hd->scsi_tch = 0;
+       hd->scsi_tcm = 32;
+       hd->scsi_tcl = 4;
+
+       hd->scsi_scmd = SCMD_SELECT;
+       return (0);
+}
+
+static int
+wait_for_select(hd)
+       volatile register struct scsidevice *hd;
+{
+       u_char ints;
+
+       while ((ints = hd->scsi_ints) == 0)
+               DELAY(1);
+       hd->scsi_ints = ints;
+       return (!(hd->scsi_ssts & SSTS_INITIATOR));
+}
+
+static int
+ixfer_start(hd, len, phase, wait)
+       volatile register struct scsidevice *hd;
+       int len;
+       u_char phase;
+       register int wait;
+{
+
+       hd->scsi_tch = len >> 16;
+       hd->scsi_tcm = len >> 8;
+       hd->scsi_tcl = len;
+       hd->scsi_pctl = phase;
+       hd->scsi_tmod = 0; /*XXX*/
+       hd->scsi_scmd = SCMD_XFR | SCMD_PROG_XFR;
+
+       /* wait for xfer to start or svc_req interrupt */
+       while ((hd->scsi_ssts & SSTS_BUSY) == 0) {
+               if (hd->scsi_ints || --wait < 0)
+                       return (0);
+               DELAY(1);
+       }
+       return (1);
+}
+
+static int
+ixfer_out(hd, len, buf)
+       volatile register struct scsidevice *hd;
+       int len;
+       register u_char *buf;
+{
+       register int wait = scsi_data_wait;
+
+       for (; len > 0; --len) {
+               while (hd->scsi_ssts & SSTS_DREG_FULL) {
+                       if (hd->scsi_ints || --wait < 0)
+                               return (len);
+                       DELAY(1);
+               }
+               hd->scsi_dreg = *buf++;
+       }
+       return (0);
+}
+
+static int
+ixfer_in(hd, len, buf)
+       volatile register struct scsidevice *hd;
+       int len;
+       register u_char *buf;
+{
+       register int wait = scsi_data_wait;
+
+       for (; len > 0; --len) {
+               while (hd->scsi_ssts & SSTS_DREG_EMPTY) {
+                       if (hd->scsi_ints || --wait < 0) {
+                               while (! (hd->scsi_ssts & SSTS_DREG_EMPTY)) {
+                                       *buf++ = hd->scsi_dreg;
+                                       --len;
+                               }
+                               return (len);
+                       }
+                       DELAY(1);
+               }
+               *buf++ = hd->scsi_dreg;
+       }
+       return (len);
+}
+
+static int
+scsiicmd(hs, target, cbuf, clen, buf, len, xferphase)
+       struct scsi_softc *hs;
+       int target;
+       u_char *cbuf;
+       int clen;
+       u_char *buf;
+       int len;
+       u_char xferphase;
+{
+       volatile register struct scsidevice *hd =
+                               (struct scsidevice *)hs->sc_addr;
+       int i;
+       u_char phase, ints;
+       register int wait;
+
+       /* select the SCSI bus (it's an error if bus isn't free) */
+       if (issue_select(hd, target, hs->sc_scsi_addr))
+               return (0);
+       if (wait_for_select(hd))
+               return (0);
+       /*
+        * Wait for a phase change (or error) then let the device
+        * sequence us through the various SCSI phases.
+        */
+       phase = CMD_PHASE;
+       while (1) {
+               wait = scsi_cmd_wait;
+               switch (phase) {
+
+               case CMD_PHASE:
+                       if (ixfer_start(hd, clen, phase, wait))
+                               if (ixfer_out(hd, clen, cbuf))
+                                       goto abort;
+                       phase = xferphase;
+                       break;
+
+               case DATA_IN_PHASE:
+                       if (len <= 0)
+                               goto abort;
+                       wait = scsi_data_wait;
+                       if (ixfer_start(hd, len, phase, wait) ||
+                           !(hd->scsi_ssts & SSTS_DREG_EMPTY))
+                               ixfer_in(hd, len, buf);
+                       phase = STATUS_PHASE;
+                       break;
+
+               case DATA_OUT_PHASE:
+                       if (len <= 0)
+                               goto abort;
+                       wait = scsi_data_wait;
+                       if (ixfer_start(hd, len, phase, wait))
+                               if (ixfer_out(hd, len, buf))
+                                       goto abort;
+                       phase = STATUS_PHASE;
+                       break;
+
+               case STATUS_PHASE:
+                       wait = scsi_data_wait;
+                       if (ixfer_start(hd, sizeof(hs->sc_stat), phase, wait) ||
+                           !(hd->scsi_ssts & SSTS_DREG_EMPTY))
+                               ixfer_in(hd, sizeof(hs->sc_stat), &hs->sc_stat);
+                       phase = MESG_IN_PHASE;
+                       break;
+
+               case MESG_IN_PHASE:
+                       if (ixfer_start(hd, sizeof(hs->sc_msg), phase, wait) ||
+                           !(hd->scsi_ssts & SSTS_DREG_EMPTY)) {
+                               ixfer_in(hd, sizeof(hs->sc_msg), &hs->sc_msg);
+                               hd->scsi_scmd = SCMD_RST_ACK;
+                       }
+                       phase = BUS_FREE_PHASE;
+                       break;
+
+               case BUS_FREE_PHASE:
+                       return (1);
+
+               default:
+                       printf("unexpected scsi phase %d\n", phase);
+                       goto abort;
+               }
+               /* wait for last command to complete */
+               while ((ints = hd->scsi_ints) == 0) {
+                       if (--wait < 0)
+                               goto abort;
+                       DELAY(1);
+               }
+               hd->scsi_ints = ints;
+               if (ints & INTS_SRV_REQ)
+                       phase = hd->scsi_psns & PHASE;
+               else if (ints & INTS_DISCON)
+                       return (1);
+               else if ((ints & INTS_CMD_DONE) == 0) {
+                       goto abort;
+               }
+       }
+abort:
+       scsiabort(hs, hd);
+       return (0);
+}
+
+int
+scsi_test_unit_rdy(unit)
+{
+       int ctlr = scsiunit(unit);
+       int slave = scsislave(unit);
+       register struct scsi_softc *hs = &scsi_softc[ctlr];
+       static struct scsi_cdb6 cdb = { CMD_TEST_UNIT_READY };
+
+       if (scsiicmd(hs, slave, &cdb, sizeof(cdb), (u_char *)0, 0,
+                    STATUS_PHASE) == 0)
+               return (0);
+               
+       return (hs->sc_stat == 0);
+}
+
+int
+scsi_request_sense(unit, buf, len)
+       int unit;
+       u_char *buf;
+       unsigned len;
+{
+       int ctlr = scsiunit(unit);
+       int slave = scsislave(unit);
+       register struct scsi_softc *hs = &scsi_softc[ctlr];
+       static struct scsi_cdb6 cdb = { CMD_REQUEST_SENSE };
+
+       cdb.len = len;
+       return (scsiicmd(hs, slave, &cdb, sizeof(cdb), buf, len, DATA_IN_PHASE));
+}
+
+int
+scsi_read_capacity(unit, buf, len)
+       int unit;
+       u_char *buf;
+       unsigned len;
+{
+       int ctlr = scsiunit(unit);
+       int slave = scsislave(unit);
+       register struct scsi_softc *hs = &scsi_softc[ctlr];
+       static struct scsi_cdb10 cdb = { CMD_READ_CAPACITY };
+
+       return (scsiicmd(hs, slave, &cdb, sizeof(cdb), buf, len, DATA_IN_PHASE));
+}
+
+int
+scsi_tt_read(unit, buf, len, blk, nblk)
+       int unit;
+       u_char *buf;
+       u_int len;
+       daddr_t blk;
+       u_int nblk;
+{
+       int ctlr = scsiunit(unit);
+       int slave = scsislave(unit);
+       register struct scsi_softc *hs = &scsi_softc[ctlr];
+       struct scsi_cdb10 cdb;
+       int stat;
+
+       bzero(&cdb, sizeof(cdb));
+       cdb.cmd = CMD_READ_EXT;
+       cdb.lbah = blk >> 24;
+       cdb.lbahm = blk >> 16;
+       cdb.lbalm = blk >> 8;
+       cdb.lbal = blk;
+       cdb.lenh = nblk >> (8 + DEV_BSHIFT);
+       cdb.lenl = nblk >> DEV_BSHIFT;
+       stat = scsiicmd(hs, slave, &cdb, sizeof(cdb), buf, len, DATA_IN_PHASE);
+       if (stat == 0)
+               return (1);
+       return (hs->sc_stat);
+}
+
+int
+scsi_tt_write(unit, buf, len, blk, nblk)
+       int unit;
+       u_char *buf;
+       u_int len;
+       daddr_t blk;
+       u_int nblk;
+{
+       int ctlr = scsiunit(unit);
+       int slave = scsislave(unit);
+       register struct scsi_softc *hs = &scsi_softc[ctlr];
+       struct scsi_cdb10 cdb;
+       int stat;
+
+       bzero(&cdb, sizeof(cdb));
+       cdb.cmd = CMD_WRITE_EXT;
+       cdb.lbah = blk >> 24;
+       cdb.lbahm = blk >> 16;
+       cdb.lbalm = blk >> 8;
+       cdb.lbal = blk;
+       cdb.lenh = nblk >> (8 + DEV_BSHIFT);
+       cdb.lenl = nblk >> DEV_BSHIFT;
+       stat = scsiicmd(hs, slave, &cdb, sizeof(cdb), buf, len, DATA_OUT_PHASE);
+       if (stat == 0)
+               return (1);
+       return (hs->sc_stat);
+}
diff --git a/usr/src/sys/hp300/stand/sd.c b/usr/src/sys/hp300/stand/sd.c
new file mode 100644 (file)
index 0000000..8ef4d4a
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Van Jacobson of Lawrence Berkeley Laboratory and the Systems
+ * Programming Group of the University of Utah Computer Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: sd.c 1.2 90/01/23$
+ *
+ *     @(#)sd.c        7.1 (Berkeley) %G%
+ */
+
+/*
+ * SCSI CCS disk driver
+ */
+
+#include "saio.h"
+#include "samachdep.h"
+
+#include "../hpdev/scsireg.h"
+
+struct sd_softc {
+       char    sc_retry;
+       char    sc_alive;
+       short   sc_blkshift;
+} sd_softc[NSD];
+
+int sdpartoff[] = {
+       1024,   17408,  0,      17408,
+       115712, 218112, 82944,  0
+};
+
+#define        SDRETRY         2
+
+sdinit(unit)
+       register int unit;
+{
+       register struct sd_softc *ss;
+       u_char stat;
+       int capbuf[2];
+
+       if (unit > NSD)
+               return (0);
+       ss = &sd_softc[unit];
+       /* NB: HP6300 won't boot if next printf is removed (???) - vj */
+       printf("sd%d: ", unit);
+       if ((stat = scsi_test_unit_rdy(unit)) == 0) {
+               /* drive may be doing RTZ - wait a bit */
+               printf("not ready - retrying ... ");
+               if (stat == STS_CHECKCOND) {
+                       DELAY(1000000);
+                       if (scsi_test_unit_rdy(unit) == 0) {
+                               printf("giving up.\n");
+                               return (0);
+                       }
+               }
+       }
+       printf("unit ready.\n");
+       /*
+        * try to get the drive block size.
+        */
+       capbuf[0] = 0;
+       capbuf[1] = 0;
+       if (scsi_read_capacity(unit, (u_char *)capbuf, sizeof(capbuf)) != 0) {
+               if (capbuf[1] > DEV_BSIZE)
+                       for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1)
+                               ++ss->sc_blkshift;
+       }
+       ss->sc_alive = 1;
+       return (1);
+}
+
+sdreset(unit)
+{
+}
+
+sdopen(io)
+       struct iob *io;
+{
+       register int unit = io->i_unit;
+       register struct sd_softc *ss = &sd_softc[unit];
+       struct sdinfo *ri;
+
+       if (scsialive(unit) == 0)
+               _stop("scsi controller not configured");
+       if (ss->sc_alive == 0)
+               if (sdinit(unit) == 0)
+                       _stop("sd init failed");
+       if (io->i_boff < 0 || io->i_boff > 7)
+               _stop("sd bad minor");
+       io->i_boff = sdpartoff[io->i_boff];
+}
+
+sdstrategy(io, func)
+       register struct iob *io;
+       register int func;
+{
+       register int unit = io->i_unit;
+       register struct sd_softc *ss = &sd_softc[unit];
+       char stat;
+       daddr_t blk = io->i_bn >> ss->sc_blkshift;
+       u_int nblk = io->i_cc >> ss->sc_blkshift;
+
+       ss->sc_retry = 0;
+retry:
+       if (func == READ)
+               stat = scsi_tt_read(unit, io->i_ma, io->i_cc, blk, nblk);
+       else
+               stat = scsi_tt_write(unit, io->i_ma, io->i_cc, blk, nblk);
+       if (stat) {
+               printf("sd(%d,?) err: 0x%x", unit, stat);
+               if (++ss->sc_retry > SDRETRY)
+                       return(-1);
+               else
+                       goto retry;
+       }
+       return(io->i_cc);
+}
diff --git a/usr/src/sys/hp300/stand/srt0.c b/usr/src/sys/hp300/stand/srt0.c
new file mode 100644 (file)
index 0000000..25ecf6b
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1982, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ * from: Utah $Hdr: srt0.c 1.8 88/12/03$
+ *
+ *     @(#)srt0.c      7.1 (Berkeley) %G%
+ */
+
+/*
+ * Startup code for standalone system
+ */
+
+       .globl  begin
+       .globl  _end
+       .globl  _edata
+       .globl  _main
+       .globl  _configure
+       .globl  _openfirst
+       .globl  __rtt
+       .globl  _lowram,_howto,_devtype
+
+       STACK =    0xfffff000   | below the ROM page
+       BOOTTYPE = 0xfffffdc0
+       LOWRAM =   0xfffffdce
+       MSUS =     0xfffffedc   | MSUS (?) structure
+       VECTORS =  0xfffffee0   | beginning of jump vectors
+       NMIRESET = 0xffffff9c   | reset vector
+       BUSERR =   0xfffffffc
+       MAXADDR =  0xfffff000
+       NBPG =     4096
+
+       .data
+_lowram:
+       .long   0
+_howto:
+       .long   0
+_devtype:
+       .long   0
+
+       .text
+begin:
+       movl    #STACK,sp
+       moveq   #47,d0          | # of vectors - 1
+       movl    #VECTORS+2,a0   | addr part of first vector
+vecloop:
+       movl    #trap,a0@       | make it direct to trap
+       addql   #6,a0           | move to next vector addr
+       dbf     d0,vecloop      | go til done
+       movl    #NMIRESET,a0    | NMI keyboard reset addr
+       movl    #nmi,a0@        | catch in reset routine
+       cmpw    #12,BOOTTYPE    | is this a reboot (REQ_REBOOT)?
+       jne     notreboot       | no, skip
+       movl    #MAXADDR,a0     | find last page
+       movl    a0@+,d7         | and extract howto, devtype
+       movl    a0@+,d6         |   from where doboot() left them
+       jra     boot1
+/*
+ * At this point we do not know which logical hpib the given select
+ * code refers to.  So we just put the select code in the adaptor field
+ * where hpibinit() can replace it with the logical hpib number.
+ * Note that this may clobber the B_DEVMAGIC field but that isn't set
+ * til later anyway.
+ */
+notreboot:
+       cmpw    #18,BOOTTYPE    | does the user want to interact?
+       jeq     askme           | yes, go to it
+       movl    MSUS,d1         | no, get rom info
+       movw    d1,d6           | MSUS comes with SC in upper, unit in lower
+       swap    d6              | put in place
+       movw    #2,d6           | assume 'a' partition of rd disk
+       moveq   #0,d7           | default to RB_AUTOBOOT
+       jra     boot1
+askme:
+       moveq   #7,d6           | default to HP-IB at sc7
+       lslw    #8,d6           | position as adaptor number
+       swap    d6              | put in place (note implied unit 0)
+       movw    #2,d6           | assume 'a' partition of rd disk
+       moveq   #3,d7           | default to RB_SINGLE|RB_ASKNAME
+boot1:
+       movl    d6,_devtype     | save devtype and howto
+       movl    d7,_howto       |   globally so all can access
+       movl    LOWRAM,d0       | read lowram value from bootrom
+       addl    #NBPG,d0        | must preserve this for bootrom to reboot
+       andl    #0xfffff000,d0  | round to next page
+       movl    d0,_lowram      | stash that value
+start:
+       movl    #_edata,a2      | start of BSS
+       movl    #_end,a3        | end
+clr:
+       clrb    a2@+            | clear BSS
+       cmpl    a2,a3           | done?
+       bne     clr             | no, keep going
+       jsr     _configure      | configure critical devices
+       movl    #1,_openfirst   | mark this as the first open
+       jsr     _main           | lets go
+__rtt:
+       movl    #3,_howto       | restarts get RB_SINGLE|RB_ASKNAME
+       jmp     start
+
+/*
+ * probe a location and see if it causes a bus error
+ */
+       .globl  _badaddr
+_badaddr:
+       movl    BUSERR,__bsave  | save ROM bus error handler address
+       movl    sp,__ssave      | and current stack pointer
+       movl    #catchbad,BUSERR| plug in our handler
+       movl    sp@(4),a0       | address to probe
+       movw    a0@,d1          | do it
+       movl    __bsave,BUSERR  | if we got here, it didn't fault
+       clrl    d0              | return that this was not a bad addr
+       rts
+
+catchbad:
+       movl    __bsave,BUSERR  | got a bus error, so restore old handler
+       movl    __ssave,sp      | manually restore stack
+       moveq   #1,d0           | indicate that we got a fault
+       rts                     | return to caller of badaddr()
+
+__bsave:
+       .long   0
+__ssave:
+       .long   0
+
+       .globl  _trap
+trap:
+       moveml  #0xFFFF,sp@-    | save registers
+       movl    sp,sp@-         | push pointer to frame
+       jsr     _trap           | call C routine to deal with it
+       stop    #0x2700         | stop cold
+
+nmi:
+       movw    #18,BOOTTYPE    | mark as system switch
+       jsr     _kbdnmi         | clear the interrupt
+       jra     begin           | start over
+
+#ifdef ROMPRF
+       .globl  _romout
+_romout:
+       movl    sp@(4),d0       | line number
+       movl    sp@(8),a0       | string
+       jsr     0x150           | do it
+       rts
+#endif
diff --git a/usr/src/sys/hp300/stand/sys.c b/usr/src/sys/hp300/stand/sys.c
new file mode 100644 (file)
index 0000000..c95e597
--- /dev/null
@@ -0,0 +1,760 @@
+/*
+ * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)sys.c       7.1 (Berkeley) %G%
+ */
+
+#include "saio.h"
+#include "ufs/dir.h"
+#ifndef SMALL
+#include "sys/stat.h"
+#endif
+
+ino_t  dlook();
+
+struct dirstuff {
+       int loc;
+       struct iob *io;
+};
+
+static
+openi(n, io)
+       register struct iob *io;
+{
+       register struct dinode *dp;
+       int cc;
+
+       io->i_offset = 0;
+       io->i_bn = fsbtodb(&io->i_fs, itod(&io->i_fs, n)) + io->i_boff;
+       io->i_cc = io->i_fs.fs_bsize;
+       io->i_ma = io->i_buf;
+       cc = devread(io);
+       dp = (struct dinode *)io->i_buf;
+       io->i_ino.i_din = dp[itoo(&io->i_fs, n)];
+       return (cc);
+}
+
+static
+find(path, file)
+       register char *path;
+       struct iob *file;
+{
+       register char *q;
+       char c;
+       int n;
+
+       if (path==NULL || *path=='\0') {
+               printf("null path\n");
+               return (0);
+       }
+
+       if (openi((ino_t) ROOTINO, file) < 0) {
+               printf("can't read root inode\n");
+               return (0);
+       }
+       while (*path) {
+               while (*path == '/')
+                       path++;
+               q = path;
+               while(*q != '/' && *q != '\0')
+                       q++;
+               c = *q;
+               *q = '\0';
+               if (q == path) path = "." ;     /* "/" means "/." */
+
+               if ((n = dlook(path, file)) != 0) {
+                       if (c == '\0')
+                               break;
+                       if (openi(n, file) < 0)
+                               return (0);
+                       *q = c;
+                       path = q;
+                       continue;
+               } else {
+                       printf("%s: not found\n", path);
+                       return (0);
+               }
+       }
+       return (n);
+}
+
+static daddr_t
+sbmap(io, bn)
+       register struct iob *io;
+       daddr_t bn;
+{
+       register struct inode *ip;
+       int i, j, sh;
+       daddr_t nb, *bap;
+
+       ip = &io->i_ino;
+       if (bn < 0) {
+               printf("bn negative\n");
+               return ((daddr_t)0);
+       }
+
+       /*
+        * blocks 0..NDADDR are direct blocks
+        */
+       if(bn < NDADDR) {
+               nb = ip->i_db[bn];
+               return (nb);
+       }
+
+       /*
+        * addresses NIADDR have single and double indirect blocks.
+        * the first step is to determine how many levels of indirection.
+        */
+       sh = 1;
+       bn -= NDADDR;
+       for (j = NIADDR; j > 0; j--) {
+               sh *= NINDIR(&io->i_fs);
+               if (bn < sh)
+                       break;
+               bn -= sh;
+       }
+       if (j == 0) {
+               printf("bn ovf %D\n", bn);
+               return ((daddr_t)0);
+       }
+
+       /*
+        * fetch the first indirect block address from the inode
+        */
+       nb = ip->i_ib[NIADDR - j];
+       if (nb == 0) {
+               printf("bn void %D\n",bn);
+               return ((daddr_t)0);
+       }
+
+       /*
+        * fetch through the indirect blocks
+        */
+       for (; j <= NIADDR; j++) {
+               if (blknos[j] != nb) {
+                       io->i_bn = fsbtodb(&io->i_fs, nb) + io->i_boff;
+                       io->i_ma = b[j];
+                       io->i_cc = io->i_fs.fs_bsize;
+                       if (devread(io) != io->i_fs.fs_bsize) {
+                               if (io->i_error)
+                                       errno = io->i_error;
+                               printf("bn %D: read error\n", io->i_bn);
+                               return ((daddr_t)0);
+                       }
+                       blknos[j] = nb;
+               }
+               bap = (daddr_t *)b[j];
+               sh /= NINDIR(&io->i_fs);
+               i = (bn / sh) % NINDIR(&io->i_fs);
+               nb = bap[i];
+               if(nb == 0) {
+                       printf("bn void %D\n",bn);
+                       return ((daddr_t)0);
+               }
+       }
+       return (nb);
+}
+
+static ino_t
+dlook(s, io)
+       char *s;
+       register struct iob *io;
+{
+       register struct direct *dp;
+       register struct inode *ip;
+       struct dirstuff dirp;
+       int len;
+
+       if (s == NULL || *s == '\0')
+               return (0);
+       ip = &io->i_ino;
+       if ((ip->i_mode&IFMT) != IFDIR) {
+               printf("not a directory\n");
+               printf("%s: not a directory\n", s);
+               return (0);
+       }
+       if (ip->i_size == 0) {
+               printf("%s: zero length directory\n", s);
+               return (0);
+       }
+       len = strlen(s);
+       dirp.loc = 0;
+       dirp.io = io;
+       for (dp = readdir(&dirp); dp != NULL; dp = readdir(&dirp)) {
+               if(dp->d_ino == 0)
+                       continue;
+               if (dp->d_namlen == len && !strcmp(s, dp->d_name))
+                       return (dp->d_ino);
+       }
+       return (0);
+}
+
+/*
+ * get next entry in a directory.
+ */
+struct direct *
+readdir(dirp)
+       register struct dirstuff *dirp;
+{
+       register struct direct *dp;
+       register struct iob *io;
+       daddr_t lbn, d;
+       int off;
+
+       io = dirp->io;
+       for(;;) {
+               if (dirp->loc >= io->i_ino.i_size)
+                       return (NULL);
+               off = blkoff(&io->i_fs, dirp->loc);
+               if (off == 0) {
+                       lbn = lblkno(&io->i_fs, dirp->loc);
+                       d = sbmap(io, lbn);
+                       if(d == 0)
+                               return NULL;
+                       io->i_bn = fsbtodb(&io->i_fs, d) + io->i_boff;
+                       io->i_ma = io->i_buf;
+                       io->i_cc = blksize(&io->i_fs, &io->i_ino, lbn);
+                       if (devread(io) < 0) {
+                               errno = io->i_error;
+                               printf("bn %D: directory read error\n",
+                                       io->i_bn);
+                               return (NULL);
+                       }
+               }
+               dp = (struct direct *)(io->i_buf + off);
+               dirp->loc += dp->d_reclen;
+               if (dp->d_ino == 0)
+                       continue;
+               return (dp);
+       }
+}
+
+lseek(fdesc, addr, ptr)
+       int fdesc, ptr;
+       off_t addr;
+{
+       register struct iob *io;
+
+#ifndef        SMALL
+       if (ptr != 0) {
+               printf("Seek not from beginning of file\n");
+               errno = EOFFSET;
+               return (-1);
+       }
+#endif SMALL
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       io->i_offset = addr;
+       io->i_bn = addr / DEV_BSIZE;
+       io->i_cc = 0;
+       return (0);
+}
+
+getc(fdesc)
+       int fdesc;
+{
+       register struct iob *io;
+       register struct fs *fs;
+       register char *p;
+       int c, lbn, off, size, diff;
+
+
+       if (fdesc >= 0 && fdesc <= 2)
+               return (getchar());
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((io = &iob[fdesc])->i_flgs&F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       p = io->i_ma;
+       if (io->i_cc <= 0) {
+               if ((io->i_flgs & F_FILE) != 0) {
+                       diff = io->i_ino.i_size - io->i_offset;
+                       if (diff <= 0)
+                               return (-1);
+                       fs = &io->i_fs;
+                       lbn = lblkno(fs, io->i_offset);
+                       io->i_bn = fsbtodb(fs, sbmap(io, lbn)) + io->i_boff;
+                       off = blkoff(fs, io->i_offset);
+                       size = blksize(fs, &io->i_ino, lbn);
+               } else {
+                       io->i_bn = io->i_offset / DEV_BSIZE;
+                       off = 0;
+                       size = DEV_BSIZE;
+               }
+               io->i_ma = io->i_buf;
+               io->i_cc = size;
+               if (devread(io) < 0) {
+                       errno = io->i_error;
+                       return (-1);
+               }
+               if ((io->i_flgs & F_FILE) != 0) {
+                       if (io->i_offset - off + size >= io->i_ino.i_size)
+                               io->i_cc = diff + off;
+                       io->i_cc -= off;
+               }
+               p = &io->i_buf[off];
+       }
+       io->i_cc--;
+       io->i_offset++;
+       c = (unsigned)*p++;
+       io->i_ma = p;
+       return (c);
+}
+
+int    errno;
+
+read(fdesc, buf, count)
+       int fdesc, count;
+       char *buf;
+{
+       register i, size;
+       register struct iob *file;
+       register struct fs *fs;
+       int lbn, off;
+
+       errno = 0;
+       if (fdesc >= 0 & fdesc <= 2) {
+               i = count;
+               do {
+                       *buf = getchar();
+               } while (--i && *buf++ != '\n');
+               return (count - i);
+       }
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       if ((file->i_flgs&F_READ) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+#ifndef        SMALL
+       if ((file->i_flgs & F_FILE) == 0) {
+               file->i_cc = count;
+               file->i_ma = buf;
+               file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE);
+               i = devread(file);
+               file->i_offset += count;
+               if (i < 0)
+                       errno = file->i_error;
+               return (i);
+       }
+#endif SMALL
+       if (file->i_offset+count > file->i_ino.i_size)
+               count = file->i_ino.i_size - file->i_offset;
+       if ((i = count) <= 0)
+               return (0);
+       /*
+        * While reading full blocks, do I/O into user buffer.
+        * Anything else uses getc().
+        */
+       fs = &file->i_fs;
+       while (i) {
+               off = blkoff(fs, file->i_offset);
+               lbn = lblkno(fs, file->i_offset);
+               size = blksize(fs, &file->i_ino, lbn);
+               if (off == 0 && size <= i) {
+                       file->i_bn = fsbtodb(fs, sbmap(file, lbn)) +
+                           file->i_boff;
+                       file->i_cc = size;
+                       file->i_ma = buf;
+                       if (devread(file) < 0) {
+                               errno = file->i_error;
+                               return (-1);
+                       }
+                       file->i_offset += size;
+                       file->i_cc = 0;
+                       buf += size;
+                       i -= size;
+               } else {
+                       size -= off;
+                       if (size > i)
+                               size = i;
+                       i -= size;
+                       do {
+                               *buf++ = getc(fdesc+3);
+                       } while (--size);
+               }
+       }
+       return (count);
+}
+
+#ifndef        SMALL
+write(fdesc, buf, count)
+       int fdesc, count;
+       char *buf;
+{
+       register i;
+       register struct iob *file;
+
+       errno = 0;
+       if (fdesc >= 0 && fdesc <= 2) {
+               i = count;
+               while (i--)
+                       putchar(0, *buf++);
+               return (count);
+       }
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       if ((file->i_flgs&F_WRITE) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       file->i_cc = count;
+       file->i_ma = buf;
+       file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE);
+       i = devwrite(file);
+       file->i_offset += count;
+       if (i < 0)
+               errno = file->i_error;
+       return (i);
+}
+#endif SMALL
+
+int    openfirst = 1;
+#ifdef notyet
+int    opendev;        /* last device opened; for boot to set bootdev */
+extern int bootdev;
+#endif notyet
+
+open(str, how)
+       char *str;
+       int how;
+{
+       register char *cp;
+       int i;
+       register struct iob *file;
+       register struct devsw *dp;
+       int fdesc;
+       long atol();
+
+       if (openfirst) {
+               for (i = 0; i < NFILES; i++)
+                       iob[i].i_flgs = 0;
+               openfirst = 0;
+       }
+
+       for (fdesc = 0; fdesc < NFILES; fdesc++)
+               if (iob[fdesc].i_flgs == 0)
+                       goto gotfile;
+       _stop("No more file slots");
+gotfile:
+       (file = &iob[fdesc])->i_flgs |= F_ALLOC;
+
+#ifdef notyet
+       for (cp = str; *cp && *cp != '/' && *cp != ':'; cp++)
+                       ;
+       if (*cp != ':') {
+               /* default bootstrap unit and device */
+               file->i_ino.i_dev = bootdev;
+               cp = str;
+       } else {
+# define isdigit(n)    ((n>='0') && (n<='9'))
+               /*
+                * syntax for possible device name:
+                *      <alpha-string><digit-string><letter>:
+                */
+               for (cp = str; *cp != ':' && !isdigit(*cp); cp++)
+                       ;
+               for (dp = devsw; dp->dv_name; dp++) {
+                       if (!strncmp(str, dp->dv_name,cp-str))
+                               goto gotdev;
+               }
+               printf("unknown device\n");
+               file->i_flgs = 0;
+               errno = EDEV;
+               return (-1);
+       gotdev:
+               i = 0;
+               while (*cp >= '0' && *cp <= '9')
+                       i = i * 10 + *cp++ - '0';
+               if (i < 0 || i > 255) {
+                       printf("minor device number out of range (0-255)\n");
+                       file->i_flgs = 0;
+                       errno = EUNIT;
+                       return (-1);
+               }
+               if (*cp >= 'a' && *cp <= 'h') {
+                       if (i > 31) {
+                               printf("unit number out of range (0-31)\n");
+                               file->i_flgs = 0;
+                               errno = EUNIT;
+                               return (-1);
+                       }
+                       i = make_minor(i, *cp++ - 'a');
+               }
+
+               if (*cp++ != ':') {
+                       printf("incorrect device specification\n");
+                       file->i_flgs = 0;
+                       errno = EOFFSET;
+                       return (-1);
+               }
+               opendev = file->i_ino.i_dev = makedev(dp-devsw, i);
+       }
+       file->i_boff = 0;
+       devopen(file);
+       if (cp != str && *cp == '\0') {
+               file->i_flgs |= how+1;
+               file->i_cc = 0;
+               file->i_offset = 0;
+               return (fdesc+3);
+       }
+#else notyet
+       for (cp = str; *cp && *cp != '('; cp++)
+                       ;
+       if (*cp != '(') {
+               printf("Bad device\n");
+               file->i_flgs = 0;
+               errno = EDEV;
+               return (-1);
+       }
+       *cp = '\0';
+       for (dp = devsw; dp->dv_name; dp++)
+               if (!strcmp(str, dp->dv_name))
+                       break;
+       *cp++ = '(';
+       if (dp->dv_name == NULL) {
+               printf("Unknown device\n");
+               file->i_flgs = 0;
+               errno = ENXIO;
+               return (-1);
+       }
+       file->i_ino.i_dev = dp-devsw;
+       file->i_unit = *cp++ - '0';
+       if (*cp >= '0' && *cp <= '9')
+               file->i_unit = file->i_unit * 10 + *cp++ - '0';
+       if (file->i_unit < 0 || file->i_unit > 63) {
+               printf("Bad unit specifier\n");
+               file->i_flgs = 0;
+               errno = EUNIT;
+               return (-1);
+       }
+       if (*cp++ != ',') {
+badoff:
+               printf("Missing offset specification\n");
+               file->i_flgs = 0;
+               errno = EOFFSET;
+               return (-1);
+       }
+       file->i_boff = atol(cp);
+       for (;;) {
+               if (*cp == ')')
+                       break;
+               if (*cp++)
+                       continue;
+               goto badoff;
+       }
+       devopen(file);
+       if (*++cp == '\0') {
+               file->i_flgs |= how+1;
+               file->i_cc = 0;
+               file->i_offset = 0;
+               return (fdesc+3);
+       }
+#endif notyet
+       file->i_ma = (char *)(&file->i_fs);
+       file->i_cc = SBSIZE;
+       file->i_bn = SBLOCK + file->i_boff;
+       file->i_offset = 0;
+       if (devread(file) < 0) {
+               errno = file->i_error;
+               printf("super block read error\n");
+               return (-1);
+       }
+       if ((i = find(cp, file)) == 0) {
+               file->i_flgs = 0;
+               errno = ESRCH;
+               return (-1);
+       }
+#ifndef        SMALL
+       if (how != 0) {
+               printf("Can't write files yet.. Sorry\n");
+               file->i_flgs = 0;
+               errno = EIO;
+               return (-1);
+       }
+#endif SMALL
+       if (openi(i, file) < 0) {
+               errno = file->i_error;
+               return (-1);
+       }
+       file->i_offset = 0;
+       file->i_cc = 0;
+       file->i_flgs |= F_FILE | (how+1);
+       return (fdesc+3);
+}
+
+close(fdesc)
+       int fdesc;
+{
+       struct iob *file;
+
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       if ((file->i_flgs&F_FILE) == 0)
+               devclose(file);
+       file->i_flgs = 0;
+       return (0);
+}
+
+exit()
+{
+       _stop("Exit called");
+}
+
+_stop(s)
+       char *s;
+{
+       static int stopped = 0;
+       int i;
+
+       if (!stopped) {
+               stopped++;
+               for (i = 0; i < NFILES; i++)
+                       if (iob[i].i_flgs != 0)
+                               close(i);
+       }
+       printf("%s\n", s);
+       _rtt();
+}
+
+#ifndef        SMALL
+ioctl(fdesc, cmd, arg)
+       int fdesc, cmd;
+       char *arg;
+{
+       register struct iob *file;
+       int error = 0;
+
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((file = &iob[fdesc])->i_flgs&F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       switch (cmd) {
+
+       case SAIOHDR:
+               file->i_flgs |= F_HDR;
+               break;
+
+       case SAIOCHECK:
+               file->i_flgs |= F_CHECK;
+               break;
+
+       case SAIOHCHECK:
+               file->i_flgs |= F_HCHECK;
+               break;
+
+       case SAIONOBAD:
+               file->i_flgs |= F_NBSF;
+               break;
+
+       case SAIODOBAD:
+               file->i_flgs &= ~F_NBSF;
+               break;
+
+       default:
+               error = devioctl(file, cmd, arg);
+               break;
+       }
+       if (error < 0)
+               errno = file->i_error;
+       return (error);
+}
+
+extern char end;
+static caddr_t theend = 0;
+
+caddr_t
+brk(addr)
+ char *addr;
+{
+       char stkloc;
+
+       if (theend == (caddr_t)0)
+               theend = &end;
+       if (addr > &stkloc || addr < &end)
+               return((caddr_t)-1);
+       if (addr > theend)
+               bzero(theend, addr-theend);
+       theend = addr;
+       return(0);
+}
+
+caddr_t
+sbrk(incr)
+ int incr;
+{
+       caddr_t obrk, brk();
+
+       if (theend == (caddr_t)0)
+               theend = &end;
+       obrk = theend;
+       if (brk(theend+incr) == (caddr_t)-1)
+               return((caddr_t)-1);
+       return(obrk);
+}
+
+getpagesize()
+{
+       return(NBPG);
+}
+
+getdtablesize()
+{
+       return(NFILES);
+}
+
+fstat(fdesc, sb)
+       struct stat *sb;
+{
+       register struct iob *io;
+
+       fdesc -= 3;
+       if (fdesc < 0 || fdesc >= NFILES ||
+           ((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0) {
+               errno = EBADF;
+               return (-1);
+       }
+       /* only important stuff */
+       sb->st_mode = io->i_ino.i_mode;
+       sb->st_uid = io->i_ino.i_uid;
+       sb->st_gid = io->i_ino.i_gid;
+       sb->st_size = io->i_ino.i_size;
+       return (0);
+}
+
+stat(str, sb)
+{
+       /* the easy way */
+       int f, rv = 0;
+
+       f = open(str, 0);
+       if (f < 0 || fstat(f, sb) < 0)
+               rv = -1;
+       (void) close(f);
+       return(rv);
+}
+
+#endif SMALL
diff --git a/usr/src/sys/hp300/stand/volhdr.h b/usr/src/sys/hp300/stand/volhdr.h
new file mode 100644 (file)
index 0000000..f44fdea
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * %sccs.include.redist.c%
+ *
+ *     @(#)volhdr.h    7.1 (Berkeley) %G%
+ */
+
+/*
+ * vohldr.h: volume header for "LIF" format volumes
+ */
+
+struct lifvol {
+       short   vol_id;
+       char    vol_label[6];
+       int     vol_addr;
+       short   vol_oct;
+       short   vol_dummy;
+       int     vol_dirsize;
+       short   vol_version;
+       short   vol_zero;
+       int     vol_huh1;
+       int     vol_huh2;
+       int     vol_length;
+};
+
+struct lifdir {
+       char    dir_name[10];
+       short   dir_type;
+       int     dir_addr;
+       int     dir_length;
+       char    dir_toc[6];
+       short   dir_flag;
+       int     dir_exec;
+};
+
+/* load header for boot rom */
+struct load {
+       int address;
+       int count;
+};
+
+#define VOL_ID         -32768
+#define VOL_OCT                4096
+#define        DIR_TYPE        -5822
+#define DIR_FLAG       0x8001  /* dont ask me! */
+#define        SECTSIZE        256