summaryrefslogtreecommitdiff
path: root/sys/arch/mvme68k/stand/libsa
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/mvme68k/stand/libsa')
-rw-r--r--sys/arch/mvme68k/stand/libsa/Makefile.inc12
-rw-r--r--sys/arch/mvme68k/stand/libsa/bug.c107
-rw-r--r--sys/arch/mvme68k/stand/libsa/dev_disk.c132
-rw-r--r--sys/arch/mvme68k/stand/libsa/dev_disk.h6
-rw-r--r--sys/arch/mvme68k/stand/libsa/dvma.c68
-rw-r--r--sys/arch/mvme68k/stand/libsa/dvma.h6
-rw-r--r--sys/arch/mvme68k/stand/libsa/exec_sun.c183
-rw-r--r--sys/arch/mvme68k/stand/libsa/netif_sun.c284
-rw-r--r--sys/arch/mvme68k/stand/libsa/promboot.c92
-rw-r--r--sys/arch/mvme68k/stand/libsa/promboot.h5
-rw-r--r--sys/arch/mvme68k/stand/libsa/promcons.c61
-rw-r--r--sys/arch/mvme68k/stand/libsa/promdev.c193
-rw-r--r--sys/arch/mvme68k/stand/libsa/promdev.h4
13 files changed, 1153 insertions, 0 deletions
diff --git a/sys/arch/mvme68k/stand/libsa/Makefile.inc b/sys/arch/mvme68k/stand/libsa/Makefile.inc
new file mode 100644
index 00000000000..c402951fa76
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/Makefile.inc
@@ -0,0 +1,12 @@
+LIB_SA_DIR=${S}/arch/${MACHINE}/stand/libsa
+
+LIBSA_DIR!= cd ${LIB_SA_DIR}; \
+ printf "xxx:\n\techo \$${.OBJDIR}\n" | ${MAKE} -r -s -f - xxx
+
+LIBSA=${LIBSA_DIR}/libsa.a
+
+$(LIBSA): .NOTMAIN __always_make_libsa
+ @echo making sure the libsa is up to date...
+ @(cd ${LIB_SA_DIR}; ${MAKE})
+
+__always_make_libsa: .NOTMAIN
diff --git a/sys/arch/mvme68k/stand/libsa/bug.c b/sys/arch/mvme68k/stand/libsa/bug.c
new file mode 100644
index 00000000000..9b817b7e7a7
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/bug.c
@@ -0,0 +1,107 @@
+/*
+ * bug routines -- assumes that the necessary sections of memory
+ * are preserved.
+ */
+#include <sys/types.h>
+#include <machine/prom.h>
+
+#define MVMEPROM_CALL(x) \
+ asm volatile (__CONCAT("trap #15; .short ", __STRING(x)) )
+
+/* returns 0 if no characters ready to read */
+int
+mvmeprom_instat()
+{
+ u_short ret;
+
+ MVMEPROM_CALL(MVMEPROM_INSTAT);
+ asm volatile ("movew ccr,%0": "=d" (ret));
+ return (!(ret & 0x4));
+}
+
+void
+mvmeprom_outstr(start, end)
+ char *start, *end;
+{
+ asm volatile ("movl %0, sp@-" : "=a" (start));
+ asm volatile ("movl %0, sp@-" : "=a" (end));
+ MVMEPROM_CALL(MVMEPROM_OUTSTR);
+}
+
+void
+mvmeprom_outln(start, end)
+ char *start, *end;
+{
+ asm volatile ("movl %0, sp@-" : "=a" (start));
+ asm volatile ("movl %0, sp@-" : "=a" (end));
+ MVMEPROM_CALL(MVMEPROM_OUTSTRCRLF);
+}
+
+/* returns 0: success, nonzero: error */
+int
+mvmeprom_diskrd(arg)
+ struct mvmeprom_dskio *arg;
+{
+ int ret;
+
+ asm volatile ("movel %0, sp@-"::"d" (arg));
+ MVMEPROM_CALL(MVMEPROM_DSKRD);
+ asm volatile ("movew ccr,%0": "=d" (ret));
+ return (!(ret & 0x4));
+}
+
+/* returns 0: success, nonzero: error */
+int
+mvmeprom_diskwr(arg)
+ struct mvmeprom_dskio *arg;
+{
+ int ret;
+
+ asm volatile ("movel %0, sp@-"::"d" (arg));
+ MVMEPROM_CALL(MVMEPROM_DSKWR);
+ asm volatile ("movew ccr,%0": "=d" (ret));
+ return (!(ret & 0x4));
+}
+
+#ifdef NOTYET
+mvmeprom_diskcfig() {}
+mvmeprom_diskfmt(){}
+mvmeprom_diskctrl(){}
+#endif
+
+/* BUG - timing routine */
+void
+mvmeprom_delay(msec)
+ int msec;
+{
+ asm volatile ("movel %0,sp@-" : :"d" (msec));
+ MVMEPROM_CALL(MVMEPROM_DELAY);
+}
+
+/* BUG - return to bug routine */
+void
+mvmeprom_return()
+{
+ MVMEPROM_CALL(MVMEPROM_EXIT);
+ /*NOTREACHED*/
+}
+
+/* BUG - query board routines */
+struct mvmeprom_brdid *
+mvmeprom_getbrdid()
+{
+ struct mvmeprom_brdid *id;
+
+ asm volatile ("clrl sp@-");
+ MVMEPROM_CALL(MVMEPROM_GETBRDID);
+ asm volatile ("movel sp@+,%0": "=d" (id):);
+ return (id);
+}
+
+void
+mvmeprom_rtc_rd(ptime)
+ struct mvmeprom_time *ptime;
+{
+ asm volatile ("movel %0,sp@-" : :"a" (ptime));
+ MVMEPROM_CALL(MVMEPROM_RTC_RD);
+}
diff --git a/sys/arch/mvme68k/stand/libsa/dev_disk.c b/sys/arch/mvme68k/stand/libsa/dev_disk.c
new file mode 100644
index 00000000000..8f38c06dab6
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/dev_disk.c
@@ -0,0 +1,132 @@
+/* $NetBSD: dev_disk.c,v 1.1.1.1 1995/06/01 20:38:07 gwr Exp $ */
+
+/*
+ * Copyright (c) 1993 Paul Kranenburg
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This module implements a "raw device" interface suitable for
+ * use by the stand-alone I/O library UFS file-system code, and
+ * possibly for direct access (i.e. boot from tape).
+ *
+ * The implementation is deceptively simple because it uses the
+ * drivers provided by the Sun PROM monitor. Note that only the
+ * PROM driver used to load the boot program is available here.
+ */
+
+#include <sys/types.h>
+#include <machine/mon.h>
+#include <machine/saio.h>
+
+#include "stand.h"
+
+#include "dvma.h"
+#include "promdev.h"
+
+int
+disk_open(f, devname)
+ struct open_file *f;
+ char *devname; /* Device part of file name (or NULL). */
+{
+ struct saioreq *sip;
+ int error;
+
+#ifdef DEBUG_PROM
+ printf("disk_open: %s\n", devname);
+#endif
+
+ if ((error = prom_iopen(&sip)) != 0)
+ return (error);
+
+ f->f_devdata = sip;
+ return 0;
+}
+
+int
+disk_close(f)
+ struct open_file *f;
+{
+ struct saioreq *sip;
+
+ sip = f->f_devdata;
+ prom_iclose(sip);
+ f->f_devdata = NULL;
+ return 0;
+}
+
+int
+disk_strategy(devdata, flag, dblk, size, buf, rsize)
+ void *devdata;
+ int flag;
+ daddr_t dblk;
+ u_int size;
+ char *buf;
+ u_int *rsize;
+{
+ struct saioreq *si;
+ struct boottab *ops;
+ char *dmabuf;
+ int si_flag, xcnt;
+
+ si = devdata;
+ ops = si->si_boottab;
+
+#ifdef DEBUG_PROM
+ printf("disk_strategy: size=%d dblk=%d\n", size, dblk);
+#else
+ twiddle();
+#endif
+
+ dmabuf = dvma_mapin(buf, size);
+
+ si->si_bn = dblk;
+ si->si_ma = dmabuf;
+ si->si_cc = size;
+
+ si_flag = (flag == F_READ) ? SAIO_F_READ : SAIO_F_WRITE;
+ xcnt = (*ops->b_strategy)(si, si_flag);
+ dvma_mapout(dmabuf, size);
+
+#ifdef DEBUG_PROM
+ printf("disk_strategy: xcnt = %x\n", xcnt);
+#endif
+
+ if (xcnt <= 0)
+ return (EIO);
+
+ *rsize = xcnt;
+ return (0);
+}
+
+int
+disk_ioctl()
+{
+ return EIO;
+}
+
diff --git a/sys/arch/mvme68k/stand/libsa/dev_disk.h b/sys/arch/mvme68k/stand/libsa/dev_disk.h
new file mode 100644
index 00000000000..9f05f74bd82
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/dev_disk.h
@@ -0,0 +1,6 @@
+
+int disk_open __P((struct open_file *, ...));
+int disk_close __P((struct open_file *));
+int disk_strategy __P((void *, int, daddr_t, u_int, char *, u_int *));
+int disk_ioctl();
+
diff --git a/sys/arch/mvme68k/stand/libsa/dvma.c b/sys/arch/mvme68k/stand/libsa/dvma.c
new file mode 100644
index 00000000000..11526106c2a
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/dvma.c
@@ -0,0 +1,68 @@
+
+/*
+ * The easiest way to deal with the need for DVMA mappings is
+ * to just map the first four megabytes of RAM into DVMA space.
+ * That way, dvma_mapin can just compute the DVMA alias address,
+ * and dvma_mapout does nothing.
+ */
+
+#include <sys/param.h>
+
+#define DVMA_BASE 0x00000000
+#define DVMA_MASK 0x00ffFFff
+#define DVMA_MAPLEN 0x400000 /* 4 MB */
+
+void
+dvma_init()
+{
+#if 0
+ int segva, sme;
+
+ for (segva = 0; segva < DVMA_MAPLEN; segva += NBSG) {
+ sme = get_segmap(segva);
+ set_segmap((DVMA_BASE | segva), sme);
+ }
+#endif
+}
+
+/* Convert a local address to a DVMA address. */
+char *
+dvma_mapin(char *addr, int len)
+{
+ int va = (int)addr;
+
+ va |= DVMA_BASE;
+ return ((char *) va);
+}
+
+/* Convert a DVMA address to a local address. */
+char *
+dvma_mapout(char *dmabuf, int len)
+{
+ if (dmabuf < (char*)DVMA_BASE)
+ panic("dvma_mapout");
+ return (dmabuf - DVMA_BASE);
+}
+
+extern char *alloc(int len);
+char *
+dvma_alloc(int len)
+{
+ char *mem;
+
+ mem = alloc(len);
+ if (!mem)
+ return(mem);
+ return(dvma_mapin(mem, len));
+}
+
+extern void free(void *ptr, int len);
+void
+dvma_free(char *dvma, int len)
+{
+ char *mem;
+
+ mem = dvma_mapout(dvma, len);
+ if (mem)
+ free(mem, len);
+}
diff --git a/sys/arch/mvme68k/stand/libsa/dvma.h b/sys/arch/mvme68k/stand/libsa/dvma.h
new file mode 100644
index 00000000000..2b8be37cbe0
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/dvma.h
@@ -0,0 +1,6 @@
+
+char * dvma_mapin(char *pkt, int len);
+void dvma_mapout(char *dmabuf, int len);
+
+char * dvma_alloc(int len);
+
diff --git a/sys/arch/mvme68k/stand/libsa/exec_sun.c b/sys/arch/mvme68k/stand/libsa/exec_sun.c
new file mode 100644
index 00000000000..d58c6ce0cde
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/exec_sun.c
@@ -0,0 +1,183 @@
+/* $NetBSD: exec_sun.c,v 1.3 1995/06/09 22:23:01 gwr Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)boot.c 8.1 (Berkeley) 6/10/93
+ */
+
+#include <sys/param.h>
+#include <sys/reboot.h>
+#include <a.out.h>
+
+#include "stand.h"
+
+extern int debug;
+
+extern u_int bootdev;
+
+/*ARGSUSED*/
+exec_sun(file, loadaddr, howto)
+ char *file;
+ char *loadaddr;
+ int howto;
+{
+ register int io;
+ struct exec x;
+ int cc, magic;
+ void (*entry)();
+ register char *cp;
+ register int *ip;
+ int textlen;
+
+#ifdef DEBUG
+ printf("exec_sun: file=%s loadaddr=0x%x\n", file, loadaddr);
+#endif
+
+ io = open(file, 0);
+ if (io < 0)
+ return(-1);
+
+ /*
+ * Read in the exec header, and validate it.
+ */
+ if (read(io, (char *)&x, sizeof(x)) != sizeof(x))
+ goto shread;
+ if (N_BADMAG(x)) {
+ errno = EFTYPE;
+ goto closeout;
+ }
+
+ cp = loadaddr;
+ textlen = x.a_text;
+ magic = N_GETMAGIC(x);
+ if (magic == ZMAGIC) {
+ cp += sizeof(x);
+ textlen -= sizeof(x);
+ }
+ entry = (void (*)())cp;
+
+ /*
+ * Leave a copy of the exec header before the text.
+ * The sun3 kernel uses this to verify that the
+ * symbols were loaded by this boot program.
+ */
+ bcopy(&x, cp - sizeof(x), sizeof(x));
+
+ /*
+ * Read in the text segment.
+ */
+ printf("%x", x.a_text);
+ if (read(io, cp, textlen) != textlen)
+ goto shread;
+ cp += textlen;
+
+ /*
+ * NMAGIC may have a gap between text and data.
+ */
+ if (magic == NMAGIC) {
+ register int mask = N_PAGSIZ(x) - 1;
+ while ((int)cp & mask)
+ *cp++ = 0;
+ }
+
+ /*
+ * Read in the data segment.
+ */
+ printf("+%x", x.a_data);
+ if (read(io, cp, x.a_data) != x.a_data)
+ goto shread;
+ cp += x.a_data;
+
+ /*
+ * Zero out the BSS section.
+ * (Kernel does not do it itself)
+ */
+ printf("+%x", x.a_bss);
+ cc = x.a_bss;
+ while ((int)cp & 3) {
+ *cp++ = 0;
+ --cc;
+ }
+ ip = (int *)cp;
+ cp += cc;
+ while ((char *)ip < cp)
+ *ip++ = 0;
+
+ /*
+ * Read in the symbol table and strings.
+ * (Always set the symtab size word.)
+ */
+ *ip++ = x.a_syms;
+ cp = (char *)ip;
+
+ if (x.a_syms > 0) {
+
+ /* Symbol table and string table length word. */
+ cc = x.a_syms;
+ printf("+[%x", cc);
+ cc += sizeof(int); /* strtab length too */
+ if (read(io, cp, cc) != cc)
+ goto shread;
+ cp += x.a_syms;
+ ip = (int *)cp; /* points to strtab length */
+ cp += sizeof(int);
+
+ /* String table. Length word includes itself. */
+ cc = *ip;
+ printf("+%x]", cc);
+ cc -= sizeof(int);
+ if (cc <= 0)
+ goto shread;
+ if (read(io, cp, cc) != cc)
+ goto shread;
+ cp += cc;
+ }
+ printf("=%x\n", cp - loadaddr);
+ close(io);
+
+ if (debug) {
+ printf("Debug mode - enter c to continue\n");
+ asm(" trap #0");
+ }
+
+ printf("Starting program at 0x%x\n", (int)entry);
+ (*entry)(howto, bootdev, cp, 0, 0);
+ panic("exec returned");
+
+shread:
+ printf("exec: short read\n");
+ errno = EIO;
+closeout:
+ close(io);
+ return(-1);
+}
diff --git a/sys/arch/mvme68k/stand/libsa/netif_sun.c b/sys/arch/mvme68k/stand/libsa/netif_sun.c
new file mode 100644
index 00000000000..db5d203b4fa
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/netif_sun.c
@@ -0,0 +1,284 @@
+/* $NetBSD: netif_sun.c,v 1.1 1995/06/09 22:19:26 gwr Exp $ */
+
+/*
+ * Copyright (c) 1995 Gordon W. Ross
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ * 4. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Gordon W. Ross
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * The Sun PROM has a fairly general set of network drivers,
+ * so it is easiest to just replace the netif module with
+ * this adaptation to the PROM network interface.
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <time.h>
+
+#include <net/if.h>
+
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <netinet/in_systm.h>
+
+#include <machine/control.h>
+#include <machine/idprom.h>
+#include <machine/mon.h>
+#include <machine/saio.h>
+
+#include "stand.h"
+#include "net.h"
+#include "netif.h"
+
+#include "clock.h"
+#include "dvma.h"
+#include "promdev.h"
+
+static struct netif netif_prom;
+
+#ifdef NETIF_DEBUG
+int netif_debug;
+#endif
+
+struct iodesc sockets[SOPEN_MAX];
+
+struct iodesc *
+socktodesc(sock)
+ int sock;
+{
+ if (sock != 0) {
+ return(NULL);
+ }
+ return (sockets);
+}
+
+int
+netif_open(machdep_hint)
+ void *machdep_hint;
+{
+ struct saioreq *si;
+ struct iodesc *io;
+ int fd, error;
+
+ /* find a free socket */
+ io = sockets;
+ if (io->io_netif) {
+#ifdef DEBUG
+ printf("netif_open: device busy\n");
+#endif
+ return (-1);
+ }
+ bzero(io, sizeof(*io));
+
+ /*
+ * Note: Sun PROMs will do RARP on open, but does not tell
+ * you the IP address it gets, so it is just noise to us...
+ */
+ if ((error = prom_iopen(&si)) != 0) {
+#ifdef DEBUG
+ printf("netif_open: prom_iopen, error=%d\n", error);
+#endif
+ return (-1);
+ }
+ if (si->si_sif == NULL) {
+#ifdef DEBUG
+ printf("netif_open: not a network device\n");
+#endif
+ prom_iclose(si);
+ return (-1);
+ }
+
+ netif_prom.devdata = si;
+ io->io_netif = &netif_prom;
+
+ /* Put our ethernet address in io->myea */
+ sun3_getether(io->myea);
+
+ return(0);
+}
+
+int
+netif_close(fd)
+ int fd;
+{
+ struct iodesc *io;
+ struct netif *ni;
+
+ if (fd != 0) {
+ errno = EBADF;
+ return(-1);
+ }
+
+ io = sockets;
+ ni = io->io_netif;
+ if (ni != NULL) {
+ prom_iclose(ni->devdata);
+ ni->devdata = NULL;
+ io->io_netif = NULL;
+ }
+ return(0);
+}
+
+/*
+ * Send a packet. The ether header is already there.
+ * Return the length sent (or -1 on error).
+ */
+int
+netif_put(desc, pkt, len)
+ struct iodesc *desc;
+ void *pkt;
+ int len;
+{
+ struct saioreq *si;
+ struct saif *sif;
+ char *dmabuf;
+ int rv, sendlen;
+
+#ifdef NETIF_DEBUG
+ if (netif_debug) {
+ struct ether_header *eh;
+
+ printf("netif_put: desc=0x%x pkt=0x%x len=%d\n",
+ desc, pkt, len);
+ eh = pkt;
+ printf("dst: %s ", ether_sprintf(eh->ether_dhost));
+ printf("src: %s ", ether_sprintf(eh->ether_shost));
+ printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
+ }
+#endif
+
+ si = desc->io_netif->devdata;
+ sif = si->si_sif;
+ sendlen = len;
+ if (sendlen < 60) {
+ sendlen = 60;
+#ifdef NETIF_DEBUG
+ printf("netif_put: length padded to %d\n", sendlen);
+#endif
+ }
+
+#ifdef PARANOID
+ if (sif == NULL)
+ panic("netif_put: no saif ptr\n");
+#endif
+
+ dmabuf = dvma_mapin(pkt, sendlen);
+ rv = sif->sif_xmit(si->si_devdata, dmabuf, sendlen);
+ dvma_mapout(dmabuf, sendlen);
+
+#ifdef NETIF_DEBUG
+ if (netif_debug)
+ printf("netif_put: xmit returned %d\n", rv);
+#endif
+ if (rv == 0) rv = len;
+ else rv = -1;
+
+ return rv;
+}
+
+/*
+ * Receive a packet, including the ether header.
+ * Return the total length received (or -1 on error).
+ */
+int
+netif_get(desc, pkt, maxlen, timo)
+ struct iodesc *desc;
+ void *pkt;
+ int maxlen;
+ time_t timo;
+{
+ struct saioreq *si;
+ struct saif *sif;
+ char *dmabuf;
+ int tick0, tmo_ticks;
+ int len;
+
+#ifdef NETIF_DEBUG
+ if (netif_debug)
+ printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",
+ pkt, maxlen, timo);
+#endif
+
+ si = desc->io_netif->devdata;
+ sif = si->si_sif;
+
+#ifdef PARANOID
+ if (sif == NULL)
+ panic("netif_get: no saif ptr\n");
+#endif
+
+ tmo_ticks = timo * hz;
+ tick0 = getticks();
+
+ dmabuf = dvma_mapin(pkt, maxlen);
+ do len = sif->sif_poll(si->si_devdata, dmabuf);
+ while ((len == 0) && ((getticks() - tick0) < tmo_ticks));
+ dvma_mapout(dmabuf, maxlen);
+
+#ifdef NETIF_DEBUG
+ if (netif_debug)
+ printf("netif_get: received len=%d\n", len);
+#endif
+
+ if (len < 12)
+ return -1;
+
+#ifdef NETIF_DEBUG
+ if (netif_debug) {
+ struct ether_header *eh = pkt;
+
+ printf("dst: %s ", ether_sprintf(eh->ether_dhost));
+ printf("src: %s ", ether_sprintf(eh->ether_shost));
+ printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
+ }
+#endif
+
+ return len;
+}
+
+static struct idprom sun3_idprom;
+
+sun3_getether(ea)
+ u_char *ea;
+{
+ u_char *src, *dst;
+ int len, x;
+
+ if (sun3_idprom.idp_format == 0) {
+ dst = (char*)&sun3_idprom;
+ src = (char*)IDPROM_BASE;
+ len = IDPROM_SIZE;
+ do {
+ x = get_control_byte(src++);
+ *dst++ = x;
+ } while (--len > 0);
+ }
+ MACPY(sun3_idprom.idp_etheraddr, ea);
+}
+
diff --git a/sys/arch/mvme68k/stand/libsa/promboot.c b/sys/arch/mvme68k/stand/libsa/promboot.c
new file mode 100644
index 00000000000..157385447e9
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/promboot.c
@@ -0,0 +1,92 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 1995 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Theo de Raadt
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/reboot.h>
+#include "stand.h"
+#include "promboot.h"
+
+char prom_bootdev[32];
+char prom_bootfile[32];
+int prom_boothow;
+int debug;
+
+void
+prom_get_boot_info()
+{
+ char c, *src, *dst;
+ extern int devlun, ctrlun;
+ extern char *oparg, *opargend;
+
+#ifdef DEBUG
+ printf("prom_get_boot_info\n");
+#endif
+
+ /* Get kernel filename */
+ src = oparg;
+ while (src && (*src == ' ' || *src == '\t'))
+ src++;
+
+ dst = prom_bootfile;
+ if (src && *src != '-') {
+ while (src && *src) {
+ if (*src == ' ' || *src == '\t')
+ break;
+ *dst++ = *src++;
+ }
+ }
+ *dst = '\0';
+
+ /* Get boothowto flags */
+ while (src && (*src == ' ' || *src == '\t'))
+ src++;
+ if (src && (*src == '-')) {
+ while (*src) {
+ switch (*src++) {
+ case 'a':
+ prom_boothow |= RB_ASKNAME;
+ break;
+ case 's':
+ prom_boothow |= RB_SINGLE;
+ break;
+ case 'd':
+ prom_boothow |= RB_KDB;
+ debug = 1;
+ break;
+ }
+ }
+ }
+#ifdef DEBUG
+ printf("promboot: device=\"%s\" file=\"%s\" how=0x%x\n",
+ prom_bootdev, prom_bootfile, prom_boothow);
+#endif
+}
diff --git a/sys/arch/mvme68k/stand/libsa/promboot.h b/sys/arch/mvme68k/stand/libsa/promboot.h
new file mode 100644
index 00000000000..86b5aace21c
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/promboot.h
@@ -0,0 +1,5 @@
+
+extern char prom_bootdev[];
+extern char prom_bootfile[];
+extern int prom_boothow;
+
diff --git a/sys/arch/mvme68k/stand/libsa/promcons.c b/sys/arch/mvme68k/stand/libsa/promcons.c
new file mode 100644
index 00000000000..ceffe9e6c39
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/promcons.c
@@ -0,0 +1,61 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 1995 Theo de Raadt
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Theo de Raadt
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdarg.h>
+#include <sys/types.h>
+
+int
+getchar()
+{
+ char c;
+
+ __asm("movb #0,sp@-; trap #15; .short 0x0; movb sp@+, %0" : : "d" (c));
+ return (c);
+}
+
+peekchar()
+{
+ int have = 0;
+
+ __asm("trap #15; .short 0x1; beq 1f; movl #1, %0\n1:" : : "d" (have));
+ return (have);
+}
+
+void
+putchar(c)
+ int c;
+{
+ if (c == '\n')
+ putchar('\r');
+ __asm("movb %0,sp@-; trap #15; .short 0x20" : : "d" (c));
+}
+
diff --git a/sys/arch/mvme68k/stand/libsa/promdev.c b/sys/arch/mvme68k/stand/libsa/promdev.c
new file mode 100644
index 00000000000..6f733d6bc81
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/promdev.c
@@ -0,0 +1,193 @@
+/* $NetBSD: promdev.c,v 1.2 1995/06/09 22:23:04 gwr Exp $ */
+
+/*
+ * Copyright (c) 1995 Gordon W. Ross
+ * Copyright (c) 1993 Paul Kranenburg
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <machine/mon.h>
+#include <machine/pte.h>
+#include <machine/saio.h>
+
+#include <dvma.h>
+#include <stand.h>
+
+struct saioreq prom_si;
+static int promdev_inuse;
+
+static char *
+prom_mapin(u_long physaddr, int length, int maptype);
+
+int
+prom_iopen(void **devdatap)
+{
+ struct bootparam *bp;
+ struct boottab *ops;
+ struct devinfo *dip;
+ struct saioreq *si;
+ char *p;
+ int error;
+
+ if (promdev_inuse)
+ return(EMFILE);
+
+ bp = *romp->bootParam;
+ ops = bp->bootDevice;
+ dip = ops->b_devinfo;
+
+#ifdef DEBUG_PROM
+ printf("Boot device type: %s\n", ops->b_desc);
+#endif
+
+ dvma_init();
+
+ si = &prom_si;
+ bzero((caddr_t)si, sizeof(*si));
+ si->si_boottab = ops;
+ si->si_ctlr = bp->ctlrNum;
+ si->si_unit = bp->unitNum;
+ si->si_boff = bp->partNum;
+
+ if (si->si_ctlr > dip->d_stdcount) {
+ printf("Invalid controller number\n");
+ return(ENXIO);
+ }
+
+ if (dip->d_devbytes) {
+ si->si_devaddr = prom_mapin(dip->d_stdaddrs[si->si_ctlr],
+ dip->d_devbytes, dip->d_devtype);
+#ifdef DEBUG_PROM
+ printf("prom_iopen: devaddr=0x%x pte=0x%x\n",
+ si->si_devaddr, get_pte(si->si_devaddr));
+#endif
+ }
+
+ if (dip->d_dmabytes) {
+ si->si_dmaaddr = dvma_alloc(dip->d_dmabytes);
+#ifdef DEBUG_PROM
+ printf("prom_iopen: dmaaddr=0x%x\n", si->si_dmaaddr);
+#endif
+ }
+
+ /* OK, call the PROM device open routine. */
+ error = (*ops->b_open)(si);
+ if (error != 0) {
+ printf("prom_iopen: \"%s\" error=%d\n",
+ ops->b_desc, error);
+ return (ENXIO);
+ }
+#ifdef DEBUG_PROM
+ printf("prom_iopen: succeeded, error=%d\n", error);
+#endif
+
+ *devdatap = si;
+ promdev_inuse++;
+ return (0);
+}
+
+void
+prom_iclose(void *devdata)
+{
+ struct boottab *ops;
+ struct devinfo *dip;
+ struct saioreq *si;
+
+ if (promdev_inuse == 0)
+ return;
+
+ si = devdata;
+ ops = si->si_boottab;
+ dip = ops->b_devinfo;
+
+ (*ops->b_close)(si);
+
+ if (si->si_dmaaddr) {
+ dvma_free(si->si_dmaaddr, dip->d_dmabytes);
+ si->si_dmaaddr = NULL;
+ }
+
+ promdev_inuse = 0;
+}
+
+struct mapinfo {
+ int maptype;
+ int pgtype;
+ int base;
+};
+
+static struct mapinfo
+prom_mapinfo[] = {
+ { MAP_MAINMEM, PGT_OBMEM, 0 },
+ { MAP_OBIO, PGT_OBIO, 0 },
+ { MAP_MBMEM, PGT_OBMEM, 0 }, /* XXX - Sun2 Multibus? */
+ { MAP_MBIO, PGT_OBIO, 0 }, /* XXX - Sun2 Multibus? */
+ { MAP_VME16A16D, PGT_VME_D16, 0xFFFF0000 },
+ { MAP_VME16A32D, PGT_VME_D32, 0xFFFF0000 },
+ { MAP_VME24A16D, PGT_VME_D16, 0xFF000000 },
+ { MAP_VME24A32D, PGT_VME_D32, 0xFF000000 },
+ { MAP_VME32A16D, PGT_VME_D16, 0 },
+ { MAP_VME32A32D, PGT_VME_D32, 0 },
+};
+static prom_mapinfo_cnt = sizeof(prom_mapinfo) / sizeof(prom_mapinfo[0]);
+
+/* The virtual address we will use for PROM device mappings. */
+static int prom_devmap = MONSHORTSEG;
+
+static char *
+prom_mapin(physaddr, length, maptype)
+ u_long physaddr;
+ int length, maptype;
+{
+ int i, pa, pte, va;
+
+ if (length > (4*NBPG))
+ panic("prom_mapin: length=%d\n", length);
+
+ for (i = 0; i < prom_mapinfo_cnt; i++)
+ if (prom_mapinfo[i].maptype == maptype)
+ goto found;
+ panic("prom_mapin: invalid maptype %d\n", maptype);
+found:
+
+ pte = prom_mapinfo[i].pgtype;
+ pte |= PG_PERM;
+ pa = prom_mapinfo[i].base;
+ pa += physaddr;
+ pte |= PA_PGNUM(pa);
+
+ va = prom_devmap;
+ do {
+ set_pte(va, pte);
+ va += NBPG;
+ pte += 1;
+ length -= NBPG;
+ } while (length > 0);
+ return ((char*)prom_devmap);
+}
diff --git a/sys/arch/mvme68k/stand/libsa/promdev.h b/sys/arch/mvme68k/stand/libsa/promdev.h
new file mode 100644
index 00000000000..e3ae5ba2d7c
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/promdev.h
@@ -0,0 +1,4 @@
+
+int prom_iopen(struct saioreq **sipp);
+void prom_iclose(struct saioreq *sip);
+