summaryrefslogtreecommitdiff
path: root/sys/arch/aviion/stand
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2006-05-16 22:48:19 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2006-05-16 22:48:19 +0000
commit3110269ffbbcad34c6f718b07cba98d0f2f78fcb (patch)
treeed58ad01758e3062c66fc8bc4ce95788f2f76f3b /sys/arch/aviion/stand
parentdb880270dac5c85e95cef5f94d2610c1cdf13b0b (diff)
Network bootloader for AV400 series, will load a native kernel. Still some
rough edges to sort out, but enough to successfully boot a kernel. Will not work on series 530 yet.
Diffstat (limited to 'sys/arch/aviion/stand')
-rw-r--r--sys/arch/aviion/stand/Makefile6
-rw-r--r--sys/arch/aviion/stand/Makefile.inc11
-rw-r--r--sys/arch/aviion/stand/libprom/Makefile17
-rw-r--r--sys/arch/aviion/stand/libprom/Makefile.inc14
-rw-r--r--sys/arch/aviion/stand/libprom/getc.c40
-rw-r--r--sys/arch/aviion/stand/libprom/getenaddr.c45
-rw-r--r--sys/arch/aviion/stand/libprom/halt.c36
-rw-r--r--sys/arch/aviion/stand/libprom/prom.h44
-rw-r--r--sys/arch/aviion/stand/libprom/putc.c41
-rw-r--r--sys/arch/aviion/stand/libsa/Makefile46
-rw-r--r--sys/arch/aviion/stand/libsa/Makefile.inc15
-rw-r--r--sys/arch/aviion/stand/libsa/clock.c84
-rw-r--r--sys/arch/aviion/stand/libsa/exec_aout.c174
-rw-r--r--sys/arch/aviion/stand/libsa/libsa.h10
-rw-r--r--sys/arch/aviion/stand/libsa/nvramreg.h87
-rw-r--r--sys/arch/aviion/stand/libsa/parse_args.c81
-rw-r--r--sys/arch/aviion/stand/libz/Makefile8
-rw-r--r--sys/arch/aviion/stand/libz/Makefile.inc14
-rw-r--r--sys/arch/aviion/stand/netboot/Makefile41
-rw-r--r--sys/arch/aviion/stand/netboot/boot.c92
-rw-r--r--sys/arch/aviion/stand/netboot/conf.c32
-rw-r--r--sys/arch/aviion/stand/netboot/crt.c36
-rw-r--r--sys/arch/aviion/stand/netboot/dev_net.c193
-rw-r--r--sys/arch/aviion/stand/netboot/dev_net.h7
-rw-r--r--sys/arch/aviion/stand/netboot/devopen.c31
-rw-r--r--sys/arch/aviion/stand/netboot/if_le.c449
-rw-r--r--sys/arch/aviion/stand/netboot/if_lereg.h173
-rw-r--r--sys/arch/aviion/stand/netboot/version.c3
28 files changed, 1829 insertions, 1 deletions
diff --git a/sys/arch/aviion/stand/Makefile b/sys/arch/aviion/stand/Makefile
index f046539152a..76f0bc3a34a 100644
--- a/sys/arch/aviion/stand/Makefile
+++ b/sys/arch/aviion/stand/Makefile
@@ -1,5 +1,9 @@
-# $OpenBSD: Makefile,v 1.1 2006/05/09 19:31:51 miod Exp $
+# $OpenBSD: Makefile,v 1.2 2006/05/16 22:48:16 miod Exp $
SUBDIR= a2coff
+.if ${MACHINE} == "aviion"
+SUBDIR+= libprom libsa libz netboot
+.endif
+
.include <bsd.subdir.mk>
diff --git a/sys/arch/aviion/stand/Makefile.inc b/sys/arch/aviion/stand/Makefile.inc
new file mode 100644
index 00000000000..fdeb15aac3b
--- /dev/null
+++ b/sys/arch/aviion/stand/Makefile.inc
@@ -0,0 +1,11 @@
+# $OpenBSD: Makefile.inc,v 1.1 2006/05/16 22:48:16 miod Exp $
+
+MDEC_DIR?= /usr/mdec
+
+CFLAGS+= -Wall -Werror -fno-stack-protector -mmemcpy
+
+# Load addresses for bootstrap code
+# This will work on 8MB machines, if each bootstrap code fits in 60KB
+# (not 64!)
+STAGE1_RELOC=0x7e0000
+STAGE2_RELOC=0x7f0000
diff --git a/sys/arch/aviion/stand/libprom/Makefile b/sys/arch/aviion/stand/libprom/Makefile
new file mode 100644
index 00000000000..acc02a5ad2b
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/Makefile
@@ -0,0 +1,17 @@
+# $OpenBSD: Makefile,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+LIB=prom
+
+NOPIC=
+NOPROFILE=
+
+S=${.CURDIR}/../../../..
+DIR_SA=$S/lib/libsa
+
+CFLAGS+=-I${.CURDIR}/../../include -I${DIR_SA}
+
+SRCS= getc.c getenaddr.c halt.c putc.c
+
+install:
+
+.include <bsd.lib.mk>
diff --git a/sys/arch/aviion/stand/libprom/Makefile.inc b/sys/arch/aviion/stand/libprom/Makefile.inc
new file mode 100644
index 00000000000..c09c6289bb7
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/Makefile.inc
@@ -0,0 +1,14 @@
+# $OpenBSD: Makefile.inc,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+LIB_PROM_DIR=${S}/arch/aviion/stand/libprom
+
+LIBPROM_DIR!= cd ${LIB_PROM_DIR}; \
+ printf "xxx:\n\techo \$${.OBJDIR}\n" | ${MAKE} -r -s -f - xxx
+
+LIBPROM=${LIBPROM_DIR}/libprom.a
+
+$(LIBPROM): .NOTMAIN __always_make_libprom
+ @echo making sure the libprom is up to date...
+ @(cd ${LIB_PROM_DIR}; ${MAKE})
+
+__always_make_libprom: .NOTMAIN
diff --git a/sys/arch/aviion/stand/libprom/getc.c b/sys/arch/aviion/stand/libprom/getc.c
new file mode 100644
index 00000000000..186600b5830
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/getc.c
@@ -0,0 +1,40 @@
+/* $OpenBSD: getc.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+/*
+ * Copyright (c) 2006, Miodrag Vallat
+ *
+ * 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.
+ *
+ * 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/types.h>
+
+#include "prom.h"
+
+int
+getchar(void)
+{
+ u_int ret;
+
+ SCM_CALL(SCM_CHAR);
+ __asm__ __volatile__ ("or %0, r0, r2" : "=r" (ret));
+
+ return (ret & 0xff);
+}
diff --git a/sys/arch/aviion/stand/libprom/getenaddr.c b/sys/arch/aviion/stand/libprom/getenaddr.c
new file mode 100644
index 00000000000..deba752a903
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/getenaddr.c
@@ -0,0 +1,45 @@
+/* $OpenBSD: getenaddr.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+/*
+ * Copyright (c) 2006, Miodrag Vallat
+ *
+ * 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.
+ *
+ * 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/types.h>
+
+#include "prom.h"
+
+void
+scm_getenaddr(u_char *ea)
+{
+ u_char *addr;
+
+ SCM_CALL(SCM_COMMID);
+ __asm__ __volatile__ ("or %0, r0, r2" : "=r" (addr));
+
+ ea[0] = addr[0];
+ ea[1] = addr[1];
+ ea[2] = addr[2];
+ ea[3] = addr[3];
+ ea[4] = addr[4];
+ ea[5] = addr[5];
+}
diff --git a/sys/arch/aviion/stand/libprom/halt.c b/sys/arch/aviion/stand/libprom/halt.c
new file mode 100644
index 00000000000..79994872944
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/halt.c
@@ -0,0 +1,36 @@
+/* $OpenBSD: halt.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+/*
+ * Copyright (c) 2006, Miodrag Vallat
+ *
+ * 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.
+ *
+ * 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/types.h>
+
+#include "prom.h"
+
+__dead void
+_rtt()
+{
+ SCM_CALL(SCM_HALT);
+ for (;;) ;
+}
diff --git a/sys/arch/aviion/stand/libprom/prom.h b/sys/arch/aviion/stand/libprom/prom.h
new file mode 100644
index 00000000000..41c2d03d424
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/prom.h
@@ -0,0 +1,44 @@
+/* $OpenBSD: prom.h,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+/*
+ * Copyright (c) 2006, Miodrag Vallat
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#define SCM_CHAR 0x00
+#define SCM_OCHAR 0x20
+#define SCM_OCRLF 0x26
+#define SCM_HALT 0x63
+#define SCM_COMMID 0x114
+
+void scm_getenaddr(u_char *);
+
+/*
+ * Simpler version of SCM_CALL() from aviion/prom.c since we are using
+ * in PROM context.
+ */
+
+#define SCM_CALL(x) \
+ __asm__ __volatile__ ("or r9, r0, " __STRING(x)); \
+ __asm__ __volatile__ ("tb0 0, r0, 496" ::: \
+ "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", \
+ "r9", "r10", "r11", "r12", "r13")
diff --git a/sys/arch/aviion/stand/libprom/putc.c b/sys/arch/aviion/stand/libprom/putc.c
new file mode 100644
index 00000000000..70e6982fd13
--- /dev/null
+++ b/sys/arch/aviion/stand/libprom/putc.c
@@ -0,0 +1,41 @@
+/* $OpenBSD: putc.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+/*
+ * Copyright (c) 2006, Miodrag Vallat
+ *
+ * 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.
+ *
+ * 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/types.h>
+
+#include "prom.h"
+
+void
+putchar(int c)
+{
+ if (c == '\n') {
+ SCM_CALL(SCM_OCRLF);
+ } else {
+ __asm__ __volatile__ ("or r2, r0, %0" : : "r" (c));
+ SCM_CALL(SCM_OCHAR);
+ }
+}
+
diff --git a/sys/arch/aviion/stand/libsa/Makefile b/sys/arch/aviion/stand/libsa/Makefile
new file mode 100644
index 00000000000..81f62fb4ec2
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/Makefile
@@ -0,0 +1,46 @@
+# $OpenBSD: Makefile,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+LIB=sa
+
+NOPIC=nopic
+NOPROFILE=noprofile
+
+# Logically src/sys
+S=${.CURDIR}/../../../..
+DIR_SA=$S/lib/libsa
+DIR_KERN=$S/lib/libkern
+
+SRC_net= arp.c ether.c in_cksum.c net.c netif.c rpc.c nfs.c \
+ rarp.c bootparam.c
+
+SRC_sa= alloc.c memcpy.c exit.c getfile.c gets.c globals.c \
+ printf.c strerror.c memset.c memcmp.c strncpy.c strcmp.c strlen.c \
+ strlcpy.c strlcat.c snprintf.c \
+ close.c closeall.c dev.c dkcksum.c \
+ lseek.c open.c nullfs.c read.c fstat.c \
+ ufs.c cread.c
+
+SRC_kern= ashrdi3.c bzero.c
+
+SRC_aviion= exec_aout.c
+
+SRC_here= clock.c parse_args.c
+
+SRCS= ${SRC_net} ${SRC_sa} ${SRC_aviion} ${SRC_here} ${SRC_kern}
+
+# DBG= -DDEBUG -DNETIF_DEBUG -DNFS_DEBUG -DRPC_DEBUG \
+# -DNET_DEBUG -DRARP_DEBUG -DETHER_DEBUG
+
+#DEFS= -DCOMPAT_UFS
+DEFS= -D__INTERNAL_LIBSA_CREAD
+#-DNETIF_DEBUG
+INCL= -I${.CURDIR} -I${.CURDIR}/../libprom -I${S}/lib/libsa -I${S}
+CFLAGS+= ${XCFLAGS} ${COPTS} ${DEFS} ${DBG} ${INCL}
+
+.PATH: ${DIR_SA} ${DIR_KERN}
+
+all: libsa.a
+
+install:
+
+.include <bsd.lib.mk>
diff --git a/sys/arch/aviion/stand/libsa/Makefile.inc b/sys/arch/aviion/stand/libsa/Makefile.inc
new file mode 100644
index 00000000000..e7684c0719a
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/Makefile.inc
@@ -0,0 +1,15 @@
+# $OpenBSD: Makefile.inc,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+LIB_SA_DIR=${S}/arch/aviion/stand/libsa
+
+LIBSA_DIR!= cd ${LIB_SA_DIR}; \
+ printf "xxx:\n\techo \$${.OBJDIR}\n" | ${MAKE} -r -s -f - xxx
+
+LIBSA=${LIBSA_DIR}/libsa.a
+SRTOBJ?= ${LIBSA_DIR}/SRT0.o
+
+$(LIBSA): .NOTMAIN __always_make_libsa
+ @echo making sure the libsa is up to date...
+ @(cd ${LIB_SA_DIR}; ${MAKE} "XCFLAGS=${CFLAGS}")
+
+__always_make_libsa: .NOTMAIN
diff --git a/sys/arch/aviion/stand/libsa/clock.c b/sys/arch/aviion/stand/libsa/clock.c
new file mode 100644
index 00000000000..2d87318dfec
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/clock.c
@@ -0,0 +1,84 @@
+/* $OpenBSD: clock.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+
+#include <sys/types.h>
+#include <machine/prom.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+#include "nvramreg.h"
+
+/*
+ * BCD to decimal and decimal to BCD.
+ */
+#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf))
+#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10))
+
+#define SECDAY (24 * 60 * 60)
+#define SECYR (SECDAY * 365)
+#define LEAPYEAR(y) (((y) & 3) == 0)
+
+/*
+ * This code is defunct after 2068.
+ * Will Unix still be here then??
+ */
+const int dayyr[12] =
+{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
+
+u_long
+chiptotime(sec, min, hour, day, mon, year)
+ int sec, min, hour, day, mon, year;
+{
+ int days, yr;
+
+ sec = FROMBCD(sec);
+ min = FROMBCD(min);
+ hour = FROMBCD(hour);
+ day = FROMBCD(day);
+ mon = FROMBCD(mon);
+ year = FROMBCD(year) + YEAR0;
+
+ /* simple sanity checks */
+ if (year > 164 || mon < 1 || mon > 12 || day < 1 || day > 31)
+ return (0);
+ yr = 70;
+ days = 0;
+
+ if (year < 70) {
+ for (; yr < year; yr++)
+ days += LEAPYEAR(yr) ? 366 : 365;
+ yr = 0;
+ }
+
+ for (; yr < year; yr++)
+ days += LEAPYEAR(yr) ? 366 : 365;
+
+ days += dayyr[mon - 1] + day - 1;
+
+ if (LEAPYEAR(yr) && mon > 2)
+ days++;
+
+ /* now have days since Jan 1, 1970; the rest is easy... */
+ return (days * SECDAY + hour * 3600 + min * 60 + sec);
+}
+
+time_t
+getsecs()
+{
+ int sec, min, hour, day, mon, year;
+#define TOD_BASE (0xfff80000 + AV400_NVRAM_TOD_OFF)
+
+ *(volatile u_int32_t *)(TOD_BASE + (CLK_CSR << 2)) = CLK_READ |
+ *(volatile u_int32_t *)(TOD_BASE + (CLK_CSR << 2));
+ sec = *(volatile u_int32_t *)(TOD_BASE + (CLK_SEC << 2)) & 0xff;
+ min = *(volatile u_int32_t *)(TOD_BASE + (CLK_MIN << 2)) & 0xff;
+ hour = *(volatile u_int32_t *)(TOD_BASE + (CLK_HOUR << 2)) & 0xff;
+ day = *(volatile u_int32_t *)(TOD_BASE + (CLK_DAY << 2)) & 0xff;
+ mon = *(volatile u_int32_t *)(TOD_BASE + (CLK_MONTH << 2)) & 0xff;
+ year = *(volatile u_int32_t *)(TOD_BASE + (CLK_YEAR << 2)) & 0xff;
+ *(volatile u_int32_t *)(TOD_BASE + (CLK_CSR << 2)) = ~CLK_READ &
+ *(volatile u_int32_t *)(TOD_BASE + (CLK_CSR << 2));
+
+ return (chiptotime(sec, min, hour, day, mon, year));
+}
diff --git a/sys/arch/aviion/stand/libsa/exec_aout.c b/sys/arch/aviion/stand/libsa/exec_aout.c
new file mode 100644
index 00000000000..a2f6495d9a2
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/exec_aout.c
@@ -0,0 +1,174 @@
+/* $OpenBSD: exec_aout.c,v 1.1 2006/05/16 22:48:18 miod 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. 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 <machine/prom.h>
+#include <a.out.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+#define SYM_MAGIC 0x6274ef2d
+
+/*ARGSUSED*/
+void
+exec_aout(char *file, const char *args, int bootdev, int bootunit, int bootpart)
+{
+ char *loadaddr;
+ int io;
+ struct exec x;
+ int cc, magic;
+ void (*entry)();
+ char *cp;
+ int *ip;
+
+ io = open(file, 0);
+ if (io < 0)
+ return;
+
+ /*
+ * 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;
+ }
+
+ /*
+ * note: on the mvme ports, the kernel is linked in such a way that
+ * its entry point is the first item in .text, and thus a_entry can
+ * be used to determine both the load address and the entry point.
+ * (also note that we make use of the fact that the kernel will live
+ * in a VA == PA range of memory ... otherwise we would take
+ * loadaddr as a parameter and let the kernel relocate itself!)
+ *
+ * note that ZMAGIC files included the a.out header in the text area
+ * so we must mask that off (has no effect on the other formats)
+ */
+ loadaddr = (void *)(x.a_entry & ~sizeof(x));
+
+ cp = loadaddr;
+ magic = N_GETMAGIC(x);
+ if (magic == ZMAGIC)
+ cp += sizeof(x);
+ entry = (void (*)())cp;
+
+ /*
+ * Read in the text segment.
+ */
+ printf("%d", x.a_text);
+ cc = x.a_text;
+ if (magic == ZMAGIC)
+ cc = cc - sizeof(x); /* a.out header part of text in zmagic */
+ if (read(io, cp, cc) != cc)
+ goto shread;
+ cp += cc;
+
+ /*
+ * 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("+%d", x.a_data);
+ if (read(io, cp, x.a_data) != x.a_data)
+ goto shread;
+ cp += x.a_data;
+
+ /*
+ * Zero out the BSS section.
+ */
+ printf("+%d", 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("+[%d", 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("+%d]", cc);
+ cc -= sizeof(int);
+ if (cc <= 0)
+ goto shread;
+ if (read(io, cp, cc) != cc)
+ goto shread;
+ cp += cc;
+ }
+ printf("=0x%lx\n", cp - loadaddr);
+ close(io);
+
+ (*entry)(args, bootdev, bootunit, bootpart, SYM_MAGIC);
+
+ printf("exec: kernel returned!\n");
+ return;
+
+shread:
+ printf("exec: short read\n");
+ errno = EIO;
+closeout:
+ close(io);
+ return;
+}
diff --git a/sys/arch/aviion/stand/libsa/libsa.h b/sys/arch/aviion/stand/libsa/libsa.h
new file mode 100644
index 00000000000..47e96d5636d
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/libsa.h
@@ -0,0 +1,10 @@
+/* $OpenBSD: libsa.h,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+/*
+ * libsa prototypes
+ */
+
+#include <machine/prom.h>
+
+void exec_aout(char *, const char *, int, int, int);
+int parse_args(char *, char **);
diff --git a/sys/arch/aviion/stand/libsa/nvramreg.h b/sys/arch/aviion/stand/libsa/nvramreg.h
new file mode 100644
index 00000000000..b7a2472bdb4
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/nvramreg.h
@@ -0,0 +1,87 @@
+/* $OpenBSD: nvramreg.h,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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, Lawrence Berkeley Laboratory.
+ *
+ * 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. 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.
+ *
+ * @(#)clockreg.h 8.1 (Berkeley) 6/11/93
+ */
+
+/*
+ * Mostek TOD clock/NVRAM
+ */
+
+/*
+ * Mostek MK48T08 clock.
+ *
+ * This chip is 8k in size.
+ * The first TOD clock starts at offset 0x1FF8. The following structure
+ * describes last 2K of it's 8K address space. The first 6K of the NVRAM
+ * space is used for various things as follows:
+ * 0000-0fff User Area
+ * 1000-10ff Networking Area
+ * 1100-16f7 Operating System Area
+ * 16f8-1ef7 ROM Debugger Area
+ * 1ef8-1ff7 Configuration Area (Ethernet address etc)
+ * 1ff8-1fff TOD clock
+ */
+
+/*
+ * On AV400, these offsets need shifting two bits, as they are 32 bit
+ * registers.
+ */
+#define CLK_CSR 0 /* control register */
+#define CLK_SEC 1 /* seconds (0..59; BCD) */
+#define CLK_MIN 2 /* minutes (0..59; BCD) */
+#define CLK_HOUR 3 /* hour (0..23; BCD) */
+#define CLK_WDAY 4 /* weekday (1..7) */
+#define CLK_DAY 5 /* day in month (1..31; BCD) */
+#define CLK_MONTH 6 /* month (1..12; BCD) */
+#define CLK_YEAR 7 /* year (0..99; BCD) */
+#define CLK_NREG 8
+
+/* csr bits */
+#define CLK_WRITE 0x80 /* want to write */
+#define CLK_READ 0x40 /* want to read (freeze clock) */
+
+/*
+ * Data General, following Motorola, chose the year `1900' as their base count.
+ * It has already wrapped by now...
+ */
+#define YEAR0 00
+
+#define AV400_NVRAM_TOD_OFF 0x1fe0 /* offset of tod in NVRAM space */
+#define MK48T02_SIZE 2 * 1024
diff --git a/sys/arch/aviion/stand/libsa/parse_args.c b/sys/arch/aviion/stand/libsa/parse_args.c
new file mode 100644
index 00000000000..efcb229ceb5
--- /dev/null
+++ b/sys/arch/aviion/stand/libsa/parse_args.c
@@ -0,0 +1,81 @@
+/* $OpenBSD: parse_args.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+/*-
+ * Copyright (c) 1995 Theo de Raadt
+ *
+ * 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.
+ *
+ * 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 <machine/prom.h>
+#include <a.out.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+#define KERNEL_NAME "bsd"
+
+int
+parse_args(char *line, char **filep)
+{
+ char *name = NULL, *p;
+
+ /* recognize the special ``halt'' keyword */
+ if (strcmp(line, "halt") == 0)
+ return (1);
+
+ /*
+ * The command line should be under the form
+ * devtype(...)filename args
+ * such as
+ * inen()bsd -s
+ * and we only care about the kernel name here.
+ *
+ * However, if the kernel could not be loaded, and we asked the
+ * user, he may not give the devtype() part - especially since
+ * at the moment we only support inen() anyway.
+ */
+
+ /* search for a set of braces */
+ for (p = line; *p != '\0' && *p != '('; p++) ;
+ if (*p != '\0') {
+ for (p = line; *p != '\0' && *p != ')'; p++) ;
+ if (*p != '\0')
+ name = ++p;
+ }
+
+ if (name == NULL)
+ name = line;
+
+ /* now insert a NUL before any option */
+ for (p = name; *p != '\0' && *p != ' '; p++) ;
+ *p = '\0';
+
+ /* no name, use the default */
+ if (*name == '\0')
+ name = KERNEL_NAME;
+
+ *filep = name;
+ return (0);
+}
diff --git a/sys/arch/aviion/stand/libz/Makefile b/sys/arch/aviion/stand/libz/Makefile
new file mode 100644
index 00000000000..2f50fcf7123
--- /dev/null
+++ b/sys/arch/aviion/stand/libz/Makefile
@@ -0,0 +1,8 @@
+# $OpenBSD: Makefile,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+S=${.CURDIR}/../../../..
+ZDST=${.OBJDIR}
+
+.PATH: ${S}/lib/libz
+
+.include "${S}/lib/libz/Makefile"
diff --git a/sys/arch/aviion/stand/libz/Makefile.inc b/sys/arch/aviion/stand/libz/Makefile.inc
new file mode 100644
index 00000000000..1ee745fd0f9
--- /dev/null
+++ b/sys/arch/aviion/stand/libz/Makefile.inc
@@ -0,0 +1,14 @@
+# $OpenBSD: Makefile.inc,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+LIB_Z_DIR=${S}/arch/aviion/stand/libz
+
+LIBZ_DIR!= cd ${LIB_Z_DIR}; \
+ printf "xxx:\n\techo \$${.OBJDIR}\n" | ${MAKE} -r -s -f - xxx
+
+LIBZ=${LIBZ_DIR}/libz.a
+
+$(LIBZ): .NOTMAIN __always_make_libz
+ @echo making sure the libz is up to date...
+ @(cd ${LIB_Z_DIR}; ${MAKE} "XCFLAGS=${CFLAGS}")
+
+__always_make_libz: .NOTMAIN
diff --git a/sys/arch/aviion/stand/netboot/Makefile b/sys/arch/aviion/stand/netboot/Makefile
new file mode 100644
index 00000000000..d7442fa4387
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/Makefile
@@ -0,0 +1,41 @@
+# $OpenBSD: Makefile,v 1.1 2006/05/16 22:48:18 miod Exp $
+
+SIZE?= size
+
+S= ${.CURDIR}/../../../..
+DEFS= -DSUN_BOOTPARAMS
+#DEFS+= -DNETIF_DEBUG
+INCPATH=-I${.CURDIR} -I${.CURDIR}/../libsa -I${.CURDIR}/../libprom \
+ -I${S} -I${S}/lib/libsa
+CFLAGS+=${DEFS} ${INCPATH} ${COPTS}
+CLEANFILES+=netboot netboot.aout
+
+.include "${S}/arch/aviion/stand/Makefile.inc"
+.include "${S}/arch/aviion/stand/libprom/Makefile.inc"
+.include "${S}/arch/aviion/stand/libsa/Makefile.inc"
+.include "${S}/arch/aviion/stand/libz/Makefile.inc"
+
+# Keep crt.c first in the object list for ld's sake.
+SRCS= crt.c boot.c conf.c devopen.c dev_net.c if_le.c version.c
+OBJS= ${SRCS:S/.c/.o/g}
+LIBS= ${LIBSA} ${LIBPROM} ${LIBZ}
+LDFLAGS+= -N -T ${STAGE2_RELOC}
+
+all: netboot.aout
+
+netboot: netboot.aout a2coff
+ ${DESTDIR}${MDEC_DIR}/a2coff netboot.aout netboot
+
+netboot.aout: ${OBJS} ${SINGLE} ${LIBS}
+ ${LD} ${LDFLAGS} -o $@ \
+ ${SINGLE} ${OBJS} ${LIBS} `cc -print-libgcc-file-name`
+ @${SIZE} $@
+
+a2coff: ${DESTDIR}${MDEC_DIR}/a2coff
+ cd ${S}/arch/aviion/stand/a2coff && ${MAKE} && ${MAKE} install
+
+install: netboot
+ ${INSTALL} ${INSTALL_COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ netboot ${DESTDIR}${MDEC_DIR}/netboot
+
+.include <bsd.prog.mk>
diff --git a/sys/arch/aviion/stand/netboot/boot.c b/sys/arch/aviion/stand/netboot/boot.c
new file mode 100644
index 00000000000..2971cfedde3
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/boot.c
@@ -0,0 +1,92 @@
+/* $OpenBSD: boot.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+/*-
+ * 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.
+ *
+ * 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.
+ *
+ * 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. 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 <machine/prom.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+extern const char version[];
+char line[80];
+
+void
+netboot(const char *args, int bootdev, int bootunit, int bootpart)
+{
+ char *file;
+ int ask = 0;
+ int ret;
+
+ printf(">> OpenBSD/" MACHINE " netboot %s\n", version);
+
+ ret = parse_args((char *)args, &file);
+ for (;;) {
+ if (ask) {
+ printf("boot: ");
+ gets(line);
+ if (line[0])
+ ret = parse_args(line, &file);
+ }
+ if (ret != 0)
+ return;
+
+ exec_aout(file, args, bootdev, bootunit, bootpart);
+ printf("netboot: %s: %s\n", file, strerror(errno));
+ ask = 1;
+ }
+}
diff --git a/sys/arch/aviion/stand/netboot/conf.c b/sys/arch/aviion/stand/netboot/conf.c
new file mode 100644
index 00000000000..3bb22f8a7a2
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/conf.c
@@ -0,0 +1,32 @@
+/* $OpenBSD: conf.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <stand.h>
+#include <nfs.h>
+#include <dev_net.h>
+
+struct fs_ops file_system[] = {
+ { nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat },
+};
+int nfsys = sizeof(file_system) / sizeof(file_system[0]);
+
+struct devsw devsw[] = {
+ { "net", net_strategy, net_open, net_close, net_ioctl },
+};
+int ndevs = sizeof(devsw) / sizeof(devsw[0]);
+
+extern struct netif_driver le_driver;
+
+struct netif_driver *netif_drivers[] = {
+ &le_driver,
+};
+int n_netif_drivers = sizeof(netif_drivers) / sizeof(netif_drivers[0]);
+
+
+/* XXX */
+int netif_debug;
+int debug;
+int errno;
diff --git a/sys/arch/aviion/stand/netboot/crt.c b/sys/arch/aviion/stand/netboot/crt.c
new file mode 100644
index 00000000000..bf44a1d9661
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/crt.c
@@ -0,0 +1,36 @@
+/* $OpenBSD: crt.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+#include <sys/types.h>
+#include <machine/prom.h>
+
+#include "stand.h"
+
+extern void netboot(const char *, int, int, int);
+
+void
+start(const char *args, int dev, int unit, int part)
+{
+ extern int edata, end;
+
+ /*
+ * This code enables the SFU1 and is used for single stage
+ * bootstraps or the first stage of a two stage bootstrap.
+ * Do not use any low register to enable the SFU1. This wipes out
+ * the args. Not cool at all... r25 seems free.
+ */
+ asm("| enable SFU1");
+ asm(" ldcr r25,cr1" ::: "r25");
+ asm(" clr r25,r25,1<3>"); /* bit 3 is SFU1D */
+ asm(" stcr r25,cr1");
+
+ memset(&edata, 0, ((int)&end - (int)&edata));
+
+ netboot(args, dev, unit, part);
+ _rtt();
+ /* NOTREACHED */
+}
+
+void
+__main()
+{
+}
diff --git a/sys/arch/aviion/stand/netboot/dev_net.c b/sys/arch/aviion/stand/netboot/dev_net.c
new file mode 100644
index 00000000000..1b3355605c4
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/dev_net.c
@@ -0,0 +1,193 @@
+/* $OpenBSD: dev_net.c,v 1.1 2006/05/16 22:48:18 miod 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.
+ */
+
+/*
+ * This module implements a "raw device" interface suitable for
+ * use by the stand-alone I/O library NFS code. This interface
+ * does not support any "block" access, and exists only for the
+ * purpose of initializing the network interface, getting boot
+ * parameters, and performing the NFS mount.
+ *
+ * At open time, this does:
+ *
+ * find interface - netif_open()
+ * RARP for IP address - rarp_getipaddress()
+ * RPC/bootparams - callrpc(d, RPC_BOOTPARAMS, ...)
+ * RPC/mountd - nfs_mount(sock, ip, path)
+ *
+ * the root file handle from mountd is saved in a global
+ * for use by the NFS open code (NFS/lookup).
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <netinet/in_systm.h>
+
+#include <machine/prom.h>
+
+#include "stand.h"
+#include "libsa.h"
+#include "prom.h"
+#include "net.h"
+#include "netif.h"
+#include "bootparam.h"
+#include "nfs.h"
+
+extern int nfs_root_node[]; /* XXX - get from nfs_mount() */
+
+struct in_addr myip, rootip, gateip, mask;
+char rootpath[FNAME_SIZE];
+
+int netdev_sock = -1;
+static int open_count;
+
+int net_mountroot(struct open_file *, char *);
+
+/*
+ * Called by devopen after it sets f->f_dev to our devsw entry.
+ * This opens the low-level device and sets f->f_devdata.
+ */
+int
+net_open(f, devname)
+ struct open_file *f;
+ char *devname; /* Device part of file name (or NULL). */
+{
+ int error = 0;
+
+ /* On first open, do netif open, mount, etc. */
+ if (open_count == 0) {
+ /* Find network interface. */
+ if ((netdev_sock = netif_open(devname)) < 0)
+ return (error=ENXIO);
+ if ((error = net_mountroot(f, devname)) != 0)
+ return (error);
+ }
+ open_count++;
+ f->f_devdata = nfs_root_node;
+ return (error);
+}
+
+int
+net_close(f)
+ struct open_file *f;
+{
+ /* On last close, do netif close, etc. */
+ if (open_count > 0)
+ if (--open_count == 0)
+ netif_close(netdev_sock);
+ f->f_devdata = NULL;
+ return (0);
+}
+
+int
+net_ioctl()
+{
+ return EIO;
+}
+
+int
+net_strategy()
+{
+ return EIO;
+}
+
+int
+net_mountroot(f, devname)
+ struct open_file *f;
+ char *devname; /* Device part of file name (or NULL). */
+{
+ int error;
+
+#ifdef DEBUG
+ printf("net_mountroot: %s\n", devname);
+#endif
+
+ /*
+ * Get info for NFS boot: our IP address, our hostname,
+ * server IP address, and our root path on the server.
+ * There are two ways to do this: The old, Sun way,
+ * and the more modern, BOOTP way. (RFC951, RFC1048)
+ */
+
+#ifdef SUN_BOOTPARAMS
+ /* Get boot info using RARP and Sun bootparams. */
+
+ /* Get our IP address. (rarp.c) */
+ if (rarp_getipaddress(netdev_sock) == -1)
+ return (EIO);
+ printf("boot: client IP address: %s\n", intoa(myip.s_addr));
+
+ /* Get our hostname, server IP address. */
+ if (bp_whoami(netdev_sock))
+ return (EIO);
+ printf("boot: client name: %s\n", hostname);
+
+ /* Get the root pathname. */
+ if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
+ return (EIO);
+
+#else
+
+ /* Get boot info using BOOTP way. (RFC951, RFC1048) */
+ bootp(netdev_sock);
+
+ printf("Using IP address: %s\n", intoa(myip.s_addr));
+
+ printf("myip: %s (%s)", hostname, intoa(myip));
+ if (gateip)
+ printf(", gateip: %s", intoa(gateip));
+ if (mask)
+ printf(", mask: %s", intoa(mask));
+ printf("\n");
+
+#endif
+
+ printf("root addr=%s path=%s\n", intoa(rootip.s_addr), rootpath);
+
+ /* Get the NFS file handle (mount). */
+ error = nfs_mount(netdev_sock, rootip, rootpath);
+
+ return (error);
+}
+
+/*
+ * machdep_common_ether: get ethernet address
+ */
+void
+machdep_common_ether(ether)
+ u_char *ether;
+{
+ scm_getenaddr(ether);
+}
diff --git a/sys/arch/aviion/stand/netboot/dev_net.h b/sys/arch/aviion/stand/netboot/dev_net.h
new file mode 100644
index 00000000000..40250b53f58
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/dev_net.h
@@ -0,0 +1,7 @@
+/* $OpenBSD: dev_net.h,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+int net_open(struct open_file *, ...);
+int net_close(struct open_file *);
+int net_ioctl();
+int net_strategy();
+
diff --git a/sys/arch/aviion/stand/netboot/devopen.c b/sys/arch/aviion/stand/netboot/devopen.c
new file mode 100644
index 00000000000..ff8d812a877
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/devopen.c
@@ -0,0 +1,31 @@
+/* $OpenBSD: devopen.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+#include <sys/param.h>
+#include <stand.h>
+
+/*
+ * Open the device named by the combined device/file name
+ * given as the "fname" arg, something like: "sd()bsd"
+ *
+ * However, Sun PROMs don't really let you choose which
+ * device you will talk to. You can only open the device
+ * that was used to load the boot program. Therefore, we
+ * do not accept a "device" part in the "fname" string.
+ * Pass the PROM device name to open in case it needs it.
+ */
+int
+devopen(f, fname, file)
+ struct open_file *f;
+ const char *fname;
+ char **file;
+{
+ struct devsw *dp;
+ int error;
+
+ *file = (char *)fname;
+ dp = &devsw[0];
+ f->f_dev = dp;
+ error = (*dp->dv_open)(f, NULL);
+
+ return (error);
+}
diff --git a/sys/arch/aviion/stand/netboot/if_le.c b/sys/arch/aviion/stand/netboot/if_le.c
new file mode 100644
index 00000000000..d2d7e8303a3
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/if_le.c
@@ -0,0 +1,449 @@
+/* $OpenBSD: if_le.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+/*
+ * Copyright (c) 1995 Theo de Raadt
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * Copyright (c) 1993 Adam Glass
+ * 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 Adam Glass.
+ * 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 Adam Glass ``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.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <machine/prom.h>
+
+#include "stand.h"
+#include "libsa.h"
+#include "net.h"
+#include "netif.h"
+
+#include "if_lereg.h"
+
+int le_debug = 0;
+
+void le_end(struct netif *);
+void le_error(struct netif *, char *, volatile struct lereg1 *);
+int le_get(struct iodesc *, void *, size_t, time_t);
+void le_init(struct iodesc *, void *);
+int le_match(struct netif *, void *);
+int le_poll(struct iodesc *, void *, int);
+int le_probe(struct netif *, void *);
+int le_put(struct iodesc *, void *, size_t);
+void le_reset(struct netif *, u_char *);
+extern void machdep_common_ether(u_char *);
+
+struct netif_stats le_stats;
+
+struct netif_dif le0_dif = {
+ 0, /* unit */
+ 1, /* nsel */
+ &le_stats,
+ 0,
+ 0,
+};
+
+struct netif_driver le_driver = {
+ "le", /* netif_bname */
+ le_match, /* match */
+ le_probe, /* probe */
+ le_init, /* init */
+ le_get, /* get */
+ le_put, /* put */
+ le_end, /* end */
+ &le0_dif, /* netif_ifs */
+ 1, /* netif_nifs */
+};
+
+struct le_configuration {
+ unsigned int phys_addr;
+ int used;
+} le_config[] = {
+ { 0xfff8c000, 0 } /* AV400 */
+};
+
+int nle_config = sizeof(le_config) / (sizeof(le_config[0]));
+
+struct {
+ struct lereg1 *sc_r1; /* LANCE registers */
+ struct lereg2 *sc_r2; /* RAM */
+ int next_rmd;
+ int next_tmd;
+} le_softc;
+
+int
+le_match(nif, machdep_hint)
+ struct netif *nif;
+ void *machdep_hint;
+{
+ char *name;
+ int i, val = 0;
+
+ name = machdep_hint;
+ if (name && !bcmp(le_driver.netif_bname, name, 2))
+ val += 10;
+ for (i = 0; i < nle_config; i++) {
+ if (le_config[i].used)
+ continue;
+ if (le_debug)
+ printf("le%d: le_match --> %d\n", i, val + 1);
+ le_config[i].used++;
+ return val + 1;
+ }
+ if (le_debug)
+ printf("le%d: le_match --> 0\n", i);
+ return 0;
+}
+
+int
+le_probe(nif, machdep_hint)
+ struct netif *nif;
+ void *machdep_hint;
+{
+
+ /* the set unit is the current unit */
+ if (le_debug)
+ printf("le%d: le_probe called\n", nif->nif_unit);
+
+ return 0;
+}
+
+void
+le_error(nif, str, ler1)
+ struct netif *nif;
+ char *str;
+ volatile struct lereg1 *ler1;
+{
+ /* ler1->ler1_rap = LE_CSRO done in caller */
+ if (ler1->ler1_rdp & LE_C0_BABL)
+ panic("le%d: been babbling, found by '%s'", nif->nif_unit, str);
+ if (ler1->ler1_rdp & LE_C0_CERR) {
+ le_stats.collision_error++;
+ ler1->ler1_rdp = LE_C0_CERR;
+ }
+ if (ler1->ler1_rdp & LE_C0_MISS) {
+ le_stats.missed++;
+ ler1->ler1_rdp = LE_C0_MISS;
+ }
+ if (ler1->ler1_rdp & LE_C0_MERR) {
+ printf("le%d: memory error in '%s'\n", nif->nif_unit, str);
+ panic("memory error");
+ }
+}
+
+void
+le_reset(nif, myea)
+ struct netif *nif;
+ u_char *myea;
+{
+ struct lereg1 *ler1 = le_softc.sc_r1;
+ struct lereg2 *ler2 = le_softc.sc_r2;
+ unsigned int a;
+ int timo = 100000, stat = 0, i;
+
+ if (le_debug)
+ printf("le%d: le_reset called\n", nif->nif_unit);
+ ler1->ler1_rap = LE_CSR0;
+ ler1->ler1_rdp = LE_C0_STOP; /* do nothing until we are finished */
+
+ bzero(ler2, sizeof(*ler2));
+
+ ler2->ler2_mode = LE_MODE_NORMAL;
+ ler2->ler2_padr[0] = myea[1];
+ ler2->ler2_padr[1] = myea[0];
+ ler2->ler2_padr[2] = myea[3];
+ ler2->ler2_padr[3] = myea[2];
+ ler2->ler2_padr[4] = myea[5];
+ ler2->ler2_padr[5] = myea[4];
+
+ ler2->ler2_ladrf0 = 0;
+ ler2->ler2_ladrf1 = 0;
+
+ a = (u_int) ler2->ler2_rmd;
+ ler2->ler2_rlen = LE_RLEN | (a >> 16);
+ ler2->ler2_rdra = a & LE_ADDR_LOW_MASK;
+
+ a = (u_int) ler2->ler2_tmd;
+ ler2->ler2_tlen = LE_TLEN | (a >> 16);
+ ler2->ler2_tdra = a & LE_ADDR_LOW_MASK;
+
+ ler1->ler1_rap = LE_CSR1;
+ a = (u_int) ler2;
+ ler1->ler1_rdp = a & LE_ADDR_LOW_MASK;
+ ler1->ler1_rap = LE_CSR2;
+ ler1->ler1_rdp = a >> 16;
+
+ for (i = 0; i < LERBUF; i++) {
+ a = (u_int) & ler2->ler2_rbuf[i];
+ ler2->ler2_rmd[i].rmd0 = a & LE_ADDR_LOW_MASK;
+ ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
+ ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
+ ler2->ler2_rmd[i].rmd2 = -LEMTU;
+ ler2->ler2_rmd[i].rmd3 = 0;
+ }
+ for (i = 0; i < LETBUF; i++) {
+ a = (u_int) & ler2->ler2_tbuf[i];
+ ler2->ler2_tmd[i].tmd0 = a & LE_ADDR_LOW_MASK;
+ ler2->ler2_tmd[i].tmd1_bits = 0;
+ ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
+ ler2->ler2_tmd[i].tmd2 = 0;
+ ler2->ler2_tmd[i].tmd3 = 0;
+ }
+
+ ler1->ler1_rap = LE_CSR3;
+ ler1->ler1_rdp = LE_C3_BSWP;
+
+ ler1->ler1_rap = LE_CSR0;
+ ler1->ler1_rdp = LE_C0_INIT;
+ do {
+ if (--timo == 0) {
+ printf("le%d: init timeout, stat = 0x%x\n",
+ nif->nif_unit, stat);
+ break;
+ }
+ stat = ler1->ler1_rdp;
+ } while ((stat & LE_C0_IDON) == 0);
+
+ ler1->ler1_rdp = LE_C0_IDON;
+ le_softc.next_rmd = 0;
+ le_softc.next_tmd = 0;
+ ler1->ler1_rap = LE_CSR0;
+ ler1->ler1_rdp = LE_C0_STRT;
+}
+
+int
+le_poll(desc, pkt, len)
+ struct iodesc *desc;
+ void *pkt;
+ int len;
+{
+ struct lereg1 *ler1 = le_softc.sc_r1;
+ struct lereg2 *ler2 = le_softc.sc_r2;
+ unsigned int a;
+ int length;
+ struct lermd *rmd;
+
+ ler1->ler1_rap = LE_CSR0;
+ if ((ler1->ler1_rdp & LE_C0_RINT) != 0)
+ ler1->ler1_rdp = LE_C0_RINT;
+ rmd = &ler2->ler2_rmd[le_softc.next_rmd];
+ if (rmd->rmd1_bits & LE_R1_OWN) {
+ return (0);
+ }
+ if (ler1->ler1_rdp & LE_C0_ERR)
+ le_error(desc->io_netif, "le_poll", ler1);
+ if (rmd->rmd1_bits & LE_R1_ERR) {
+ printf("le%d_poll: rmd status 0x%x\n", desc->io_netif->nif_unit,
+ rmd->rmd1_bits);
+ length = 0;
+ goto cleanup;
+ }
+ if ((rmd->rmd1_bits & (LE_R1_STP | LE_R1_ENP)) != (LE_R1_STP | LE_R1_ENP))
+ panic("le_poll: chained packet");
+
+ length = rmd->rmd3;
+ if (length >= LEMTU) {
+ length = 0;
+ panic("csr0 when bad things happen: %x", ler1->ler1_rdp);
+ goto cleanup;
+ }
+ if (!length)
+ goto cleanup;
+ length -= 4;
+ if (length > 0) {
+ /*
+ * if buffer is smaller than the packet truncate it.
+ * (is this wise?)
+ */
+ if (length > len)
+ length = len;
+
+ bcopy((void *)&ler2->ler2_rbuf[le_softc.next_rmd], pkt, length);
+ }
+cleanup:
+ a = (u_int) & ler2->ler2_rbuf[le_softc.next_rmd];
+ rmd->rmd0 = a & LE_ADDR_LOW_MASK;
+ rmd->rmd1_hadr = a >> 16;
+ rmd->rmd2 = -LEMTU;
+ le_softc.next_rmd =
+ (le_softc.next_rmd == (LERBUF - 1)) ? 0 : (le_softc.next_rmd + 1);
+ rmd->rmd1_bits = LE_R1_OWN;
+ return length;
+}
+
+int
+le_put(desc, pkt, len)
+ struct iodesc *desc;
+ void *pkt;
+ size_t len;
+{
+ volatile struct lereg1 *ler1 = le_softc.sc_r1;
+ volatile struct lereg2 *ler2 = le_softc.sc_r2;
+ volatile struct letmd *tmd;
+ int timo = 100000, stat = 0;
+ unsigned int a;
+
+ ler1->ler1_rap = LE_CSR0;
+ if (ler1->ler1_rdp & LE_C0_ERR)
+ le_error(desc->io_netif, "le_put(way before xmit)", ler1);
+ tmd = &ler2->ler2_tmd[le_softc.next_tmd];
+ while (tmd->tmd1_bits & LE_T1_OWN) {
+ printf("le%d: output buffer busy\n", desc->io_netif->nif_unit);
+ }
+ bcopy(pkt, (void *)ler2->ler2_tbuf[le_softc.next_tmd], len);
+ if (len < 64)
+ tmd->tmd2 = -64;
+ else
+ tmd->tmd2 = -len;
+ tmd->tmd3 = 0;
+ if (ler1->ler1_rdp & LE_C0_ERR)
+ le_error(desc->io_netif, "le_put(before xmit)", ler1);
+ tmd->tmd1_bits = LE_T1_STP | LE_T1_ENP | LE_T1_OWN;
+ a = (u_int) & ler2->ler2_tbuf[le_softc.next_tmd];
+ tmd->tmd0 = a & LE_ADDR_LOW_MASK;
+ tmd->tmd1_hadr = a >> 16;
+ ler1->ler1_rdp = LE_C0_TDMD;
+ if (ler1->ler1_rdp & LE_C0_ERR)
+ le_error(desc->io_netif, "le_put(after xmit)", ler1);
+ do {
+ if (--timo == 0) {
+ printf("le%d: transmit timeout, stat = 0x%x\n",
+ desc->io_netif->nif_unit, stat);
+ if (ler1->ler1_rdp & LE_C0_ERR)
+ le_error(desc->io_netif, "le_put(timeout)", ler1);
+ break;
+ }
+ stat = ler1->ler1_rdp;
+ } while ((stat & LE_C0_TINT) == 0);
+ ler1->ler1_rdp = LE_C0_TINT;
+ if (ler1->ler1_rdp & LE_C0_ERR) {
+ if ((ler1->ler1_rdp & (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS |
+ LE_C0_MERR)) !=
+ LE_C0_CERR)
+ printf("le_put: xmit error, buf %d\n", le_softc.next_tmd);
+ le_error(desc->io_netif, "le_put(xmit error)", ler1);
+ }
+ le_softc.next_tmd = 0;
+/* (le_softc.next_tmd == (LETBUF - 1)) ? 0 : le_softc.next_tmd + 1;*/
+ if (tmd->tmd1_bits & LE_T1_DEF)
+ le_stats.deferred++;
+ if (tmd->tmd1_bits & LE_T1_ONE)
+ le_stats.collisions++;
+ if (tmd->tmd1_bits & LE_T1_MORE)
+ le_stats.collisions += 2;
+ if (tmd->tmd1_bits & LE_T1_ERR) {
+ printf("le%d: transmit error, error = 0x%x\n", desc->io_netif->nif_unit,
+ tmd->tmd3);
+ return -1;
+ }
+ if (le_debug) {
+ printf("le%d: le_put() successful: sent %ld\n",
+ desc->io_netif->nif_unit, len);
+ printf("le%d: le_put(): tmd1_bits: %x tmd3: %x\n",
+ desc->io_netif->nif_unit,
+ (unsigned int) tmd->tmd1_bits,
+ (unsigned int) tmd->tmd3);
+ }
+ return len;
+}
+
+int
+le_get(desc, pkt, len, timeout)
+ struct iodesc *desc;
+ void *pkt;
+ size_t len;
+ time_t timeout;
+{
+ time_t t;
+ int cc;
+
+ t = getsecs();
+ cc = 0;
+ while (((getsecs() - t) < timeout) && !cc) {
+ cc = le_poll(desc, pkt, len);
+ }
+ return cc;
+}
+/*
+ * init le device. return 0 on failure, 1 if ok.
+ */
+void
+le_init(desc, machdep_hint)
+ struct iodesc *desc;
+ void *machdep_hint;
+{
+ u_long eram = 4*1024*1024;
+ struct netif *nif = desc->io_netif;
+
+ if (le_debug)
+ printf("le%d: le_init called\n", desc->io_netif->nif_unit);
+ machdep_common_ether(desc->myea);
+ bzero(&le_softc, sizeof(le_softc));
+ le_softc.sc_r1 =
+ (struct lereg1 *) le_config[desc->io_netif->nif_unit].phys_addr;
+ le_softc.sc_r2 = (struct lereg2 *) (eram - (1024 * 1024));
+ le_reset(desc->io_netif, desc->myea);
+ printf("device: %s%d attached to %s\n", nif->nif_driver->netif_bname,
+ nif->nif_unit, ether_sprintf(desc->myea));
+}
+
+void
+le_end(nif)
+ struct netif *nif;
+{
+ struct lereg1 *ler1 = le_softc.sc_r1;
+
+ if (le_debug)
+ printf("le%d: le_end called\n", nif->nif_unit);
+ ler1->ler1_rap = LE_CSR0;
+ ler1->ler1_rdp = LE_C0_STOP;
+}
diff --git a/sys/arch/aviion/stand/netboot/if_lereg.h b/sys/arch/aviion/stand/netboot/if_lereg.h
new file mode 100644
index 00000000000..70f4325b3d6
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/if_lereg.h
@@ -0,0 +1,173 @@
+/* $OpenBSD: if_lereg.h,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1992, 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. 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.
+ *
+ * @(#)if_lereg.h 8.2 (Berkeley) 10/30/93
+ */
+
+#define LEMTU 1518
+#define LEMINSIZE 60 /* should be 64 if mode DTCR is set */
+#define LERBUF 8
+#define LERBUFLOG2 3
+#define LE_RLEN (LERBUFLOG2 << 13)
+#define LETBUF 1
+#define LETBUFLOG2 0
+#define LE_TLEN (LETBUFLOG2 << 13)
+
+/*
+ * LANCE registers. Although there are 16 bit registers, on the AV400
+ * design, they need to be accessed as 32 bit registers. Bus magic...
+ */
+struct lereg1 {
+ volatile u_int32_t ler1_rdp; /* register data port */
+ volatile u_int32_t ler1_rap; /* register address port */
+};
+
+/* register addresses */
+#define LE_CSR0 0 /* Control and status register */
+#define LE_CSR1 1 /* low address of init block */
+#define LE_CSR2 2 /* high address of init block */
+#define LE_CSR3 3 /* Bus master and control */
+
+/* Control and status register 0 (csr0) */
+#define LE_C0_ERR 0x8000 /* error summary */
+#define LE_C0_BABL 0x4000 /* transmitter timeout error */
+#define LE_C0_CERR 0x2000 /* collision */
+#define LE_C0_MISS 0x1000 /* missed a packet */
+#define LE_C0_MERR 0x0800 /* memory error */
+#define LE_C0_RINT 0x0400 /* receiver interrupt */
+#define LE_C0_TINT 0x0200 /* transmitter interrupt */
+#define LE_C0_IDON 0x0100 /* initialization done */
+#define LE_C0_INTR 0x0080 /* interrupt condition */
+#define LE_C0_INEA 0x0040 /* interrupt enable */
+#define LE_C0_RXON 0x0020 /* receiver on */
+#define LE_C0_TXON 0x0010 /* transmitter on */
+#define LE_C0_TDMD 0x0008 /* transmit demand */
+#define LE_C0_STOP 0x0004 /* disable all external activity */
+#define LE_C0_STRT 0x0002 /* enable external activity */
+#define LE_C0_INIT 0x0001 /* begin initialization */
+
+#define LE_C0_BITS \
+ "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\
+\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT"
+
+/* Control and status register 3 (csr3) */
+#define LE_C3_BSWP 0x4 /* byte swap */
+#define LE_C3_ACON 0x2 /* ALE control, eh? */
+#define LE_C3_BCON 0x1 /* byte control */
+/*
+ * Current size is 13,758 bytes with 8 x 1518 receive buffers and
+ * 1 x 1518 transmit buffer.
+ */
+struct lereg2 {
+ /* initialization block */
+ volatile u_short ler2_mode; /* mode */
+ volatile u_char ler2_padr[6]; /* physical address */
+#ifdef new_code
+ volatile u_short ler2_ladrf[4]; /* logical address filter */
+#else
+ volatile u_long ler2_ladrf0; /* logical address filter */
+ volatile u_long ler2_ladrf1; /* logical address filter */
+#endif
+ volatile u_short ler2_rdra; /* receive descriptor addr */
+ volatile u_short ler2_rlen; /* rda high and ring size */
+ volatile u_short ler2_tdra; /* transmit descriptor addr */
+ volatile u_short ler2_tlen; /* tda high and ring size */
+ /* receive message descriptors. bits/hadr are byte order dependent. */
+ struct lermd {
+ volatile u_short rmd0; /* low address of packet */
+ volatile u_char rmd1_bits; /* descriptor bits */
+ volatile u_char rmd1_hadr; /* high address of packet */
+ volatile short rmd2; /* buffer byte count */
+ volatile u_short rmd3; /* message byte count */
+ } ler2_rmd[LERBUF];
+ /* transmit message descriptors */
+ struct letmd {
+ volatile u_short tmd0; /* low address of packet */
+ volatile u_char tmd1_bits; /* descriptor bits */
+ volatile u_char tmd1_hadr; /* high address of packet */
+ volatile short tmd2; /* buffer byte count */
+ volatile u_short tmd3; /* transmit error bits */
+ } ler2_tmd[LETBUF];
+ volatile char ler2_rbuf[LERBUF][LEMTU];
+ volatile char ler2_tbuf[LETBUF][LEMTU];
+};
+/* Initialzation block (mode) */
+#define LE_MODE_PROM 0x8000 /* promiscuous mode */
+/* 0x7f80 reserved, must be zero */
+#define LE_MODE_INTL 0x0040 /* internal loopback */
+#define LE_MODE_DRTY 0x0020 /* disable retry */
+#define LE_MODE_COLL 0x0010 /* force a collision */
+#define LE_MODE_DTCR 0x0008 /* disable transmit CRC */
+#define LE_MODE_LOOP 0x0004 /* loopback mode */
+#define LE_MODE_DTX 0x0002 /* disable transmitter */
+#define LE_MODE_DRX 0x0001 /* disable receiver */
+#define LE_MODE_NORMAL 0 /* none of the above */
+
+
+/* Receive message descriptor 1 (rmd1_bits) */
+#define LE_R1_OWN 0x80 /* LANCE owns the packet */
+#define LE_R1_ERR 0x40 /* error summary */
+#define LE_R1_FRAM 0x20 /* framing error */
+#define LE_R1_OFLO 0x10 /* overflow error */
+#define LE_R1_CRC 0x08 /* CRC error */
+#define LE_R1_BUFF 0x04 /* buffer error */
+#define LE_R1_STP 0x02 /* start of packet */
+#define LE_R1_ENP 0x01 /* end of packet */
+
+#define LE_R1_BITS \
+ "\20\10OWN\7ERR\6FRAM\5OFLO\4CRC\3BUFF\2STP\1ENP"
+
+/* Transmit message descriptor 1 (tmd1_bits) */
+#define LE_T1_OWN 0x80 /* LANCE owns the packet */
+#define LE_T1_ERR 0x40 /* error summary */
+#define LE_T1_MORE 0x10 /* multiple collisions */
+#define LE_T1_ONE 0x08 /* single collision */
+#define LE_T1_DEF 0x04 /* defferred transmit */
+#define LE_T1_STP 0x02 /* start of packet */
+#define LE_T1_ENP 0x01 /* end of packet */
+
+#define LE_T1_BITS \
+ "\20\10OWN\7ERR\6RES\5MORE\4ONE\3DEF\2STP\1ENP"
+
+/* Transmit message descriptor 3 (tmd3) */
+#define LE_T3_BUFF 0x8000 /* buffer error */
+#define LE_T3_UFLO 0x4000 /* underflow error */
+#define LE_T3_LCOL 0x1000 /* late collision */
+#define LE_T3_LCAR 0x0800 /* loss of carrier */
+#define LE_T3_RTRY 0x0400 /* retry error */
+#define LE_T3_TDR_MASK 0x03ff /* time domain reflectometry counter */
+
+#define LE_XMD2_ONES 0xf000
+
+#define LE_T3_BITS \
+ "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY"
+
+
+#define LE_ADDR_LOW_MASK (0xffff)
diff --git a/sys/arch/aviion/stand/netboot/version.c b/sys/arch/aviion/stand/netboot/version.c
new file mode 100644
index 00000000000..5a20b698bd1
--- /dev/null
+++ b/sys/arch/aviion/stand/netboot/version.c
@@ -0,0 +1,3 @@
+/* $OpenBSD: version.c,v 1.1 2006/05/16 22:48:18 miod Exp $ */
+
+const char version[] = "1.1";