summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorchuck <chuck@cvs.openbsd.org>1996-05-16 02:30:39 +0000
committerchuck <chuck@cvs.openbsd.org>1996-05-16 02:30:39 +0000
commit97750c06b0d2986f4e0281b923e3d51f8480467e (patch)
treee31c3b69157c2f6c2126fca12b20353f51e6538d /sys/arch
parent1c147e3e4be7c34db0d985e42f325e8d444fcf63 (diff)
sync with sun3 port.
major reorg. & cleanup. new SRT that works with bugcrt. common parse_arg.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/mvme68k/stand/libsa/Makefile23
-rw-r--r--sys/arch/mvme68k/stand/libsa/Makefile.inc3
-rw-r--r--sys/arch/mvme68k/stand/libsa/SRT0.S122
-rw-r--r--sys/arch/mvme68k/stand/libsa/bugdev.c238
-rw-r--r--sys/arch/mvme68k/stand/libsa/clock.c37
-rw-r--r--sys/arch/mvme68k/stand/libsa/exec_mvme.c190
-rw-r--r--sys/arch/mvme68k/stand/libsa/libsa.h22
-rw-r--r--sys/arch/mvme68k/stand/libsa/parse_args.c94
8 files changed, 599 insertions, 130 deletions
diff --git a/sys/arch/mvme68k/stand/libsa/Makefile b/sys/arch/mvme68k/stand/libsa/Makefile
index 685912d01e9..dbebf11dfd3 100644
--- a/sys/arch/mvme68k/stand/libsa/Makefile
+++ b/sys/arch/mvme68k/stand/libsa/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.9 1996/05/10 20:03:49 deraadt Exp $
+# $OpenBSD: Makefile,v 1.10 1996/05/16 02:30:38 chuck Exp $
LIB=sa
-CLEANFILES+=SRT0.o SRT1.o machine
+CLEANFILES+=SRT0.o
NOPIC=nopic
NOPROFILE=noprofile
@@ -16,35 +16,30 @@ SRC_net= nfs.c rpc.c net.c ether.c arp.c in_cksum.c netif.c \
bootparam.c rarp.c
-SRC_sa = alloc.c bcopy.c memcpy.c close.c getfile.c open.c \
+SRC_sa = alloc.c bcopy.c memcpy.c close.c exit.c getfile.c gets.c open.c \
printf.c read.c strerror.c ufs.c globals.c lseek.c \
closeall.c dev.c dkcksum.c nullfs.c fstat.c
SRC_kern= ashrdi3.c bcmp.c bzero.c strcmp.c strlen.c
-SRC_sun3= exec_sun.c
+SRC_mvme= exec_mvme.c
-SRC_here= clock.c devopen.c dvma.c \
- gets.c panic.c \
- promboot.c promcons.c
+SRC_here= clock.c bugdev.c parse_args.c
-SRCS= ${SRC_net} ${SRC_sa} ${SRC_kern} ${SRC_sun3} ${SRC_here}
+SRCS= ${SRC_net} ${SRC_sa} ${SRC_kern} ${SRC_mvme} ${SRC_here}
# DBG= -DDEBUG -DNETIF_DEBUG -DNFS_DEBUG -DRPC_DEBUG \
# -DNET_DEBUG -DRARP_DEBUG -DETHER_DEBUG
#DEFS= -DCOMPAT_UFS
-INCL= -I${.CURDIR} -I${S} -I${S}/lib/libsa -I${.OBJDIR}
+INCL= -I. -I${.CURDIR}/../libbug -I${S}/lib/libsa -I${S}
COPTS= #-fno-defer-pop
CFLAGS= -O2 ${COPTS} ${DEFS} ${DBG} ${INCL}
-.PATH: ${DIR_SA} ${DIR_KERN} ../../sun3
+.PATH: ${DIR_SA} ${DIR_KERN}
-all: machine libsa.a SRT0.o SRT1.o
+all: libsa.a SRT0.o
install:
-machine:
- rm -f machine; ln -s ${.CURDIR}/../../include machine
-
.include <bsd.lib.mk>
diff --git a/sys/arch/mvme68k/stand/libsa/Makefile.inc b/sys/arch/mvme68k/stand/libsa/Makefile.inc
index acdd0379be9..31a21177236 100644
--- a/sys/arch/mvme68k/stand/libsa/Makefile.inc
+++ b/sys/arch/mvme68k/stand/libsa/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.2 1996/04/28 10:48:53 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.3 1996/05/16 02:30:38 chuck Exp $
LIB_SA_DIR=${S}/arch/${MACHINE}/stand/libsa
@@ -6,6 +6,7 @@ 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...
diff --git a/sys/arch/mvme68k/stand/libsa/SRT0.S b/sys/arch/mvme68k/stand/libsa/SRT0.S
index a938029049d..20136ffaa72 100644
--- a/sys/arch/mvme68k/stand/libsa/SRT0.S
+++ b/sys/arch/mvme68k/stand/libsa/SRT0.S
@@ -1,34 +1,5 @@
-| $OpenBSD: SRT0.S,v 1.5 1996/04/28 10:48:54 deraadt Exp $
+| $NetBSD: SRT0.S,v 1.2 1995/08/12 18:38:55 gwr 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.
-| 3. All advertising materials mentioning features or use of this software
-| must display the following acknowledgement:
-| This product includes software developed under OpenBSD by
-| Theo de Raadt for Willowglen Singapore.
-| 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.
-|
| Copyright (c) 1995 Gordon W. Ross
| All rights reserved.
|
@@ -57,74 +28,49 @@
| (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 is a pre-startup wrapper for bugcrt which relocates the
+| code to the correct place before exec()ing.
+
| SRT0.S - Stand-alone Run-Time startup code, part 0
- .file "SRT0.S"
- .text
- .globl __estack
+ .file "SRT0.S"
+ .text
+ .globl __estack
__estack:
- .globl start
-start:
-| Check to see if the code is located correctly.
-| This SHOULD do a PC-relative load into a0, but...
-| lea start, a0 | current location (0x4000)
-| XXX - GAS version 1.93 gets the above lea wrong!
- .word 0x41fa
- .word 0xfffe
-| Now force a long (not PC-relative) load to a1 and compare.
- lea start:l, a1 | desired location (LINKADDR)
- cmpl a0, a1
- beqs restart
+ .globl xstart
+xstart:
+| first, relocate code to correct place without touching critical regs
+| (args are in: d0, d1, d4, a0, a1, a2, a3, a4, a5, a6)
+| [a3 and a4 only when netbooting]
+ movl a3, d3 | SAVE a3 in d3
+ movl a4, d5 | SAVE a4 in d5
+ lea pc@(xstart:w), a3 | a3 = current addr (could be anywhere)
+ lea xstart:l, a4 | a4 = desired location (LINKADDR)
+ cmpl a3, a4 | already there?
+ beqs restart | short-circuit out
-| Relocate the code and data to where they belong.
- movl #_edata,d2 | Desired end of program
- subl a1,d2 | Calculate length, round up.
- lsrl #2,d2
-Lcp: movl a0@+, a1@+
- dbra d2, Lcp
+ | Relocate the code and data
+ movl #_edata,d2 | Desired end of program
+ subl a4,d2 | Calculate length, round up.
+ lsrl #2,d2
+Lcp:
+ movl a3@+, a4@+
+ dbra d2, Lcp
| Force a long jump to the relocated code (not pc-relative)
- lea restart:l, a0
- jmp a0@
+ lea restart:l, a3
+ jmp a3@
restart:
| now in the relocated code
| Set up stack (just before relocated text)
- lea __estack:l, a0
- movl a0, sp
- subl a6, a6
-
- movl d0, _devlun
- movl d1, _ctrlun
- movl a3, _oparg
- movl a4, _opargend
+ lea __estack:l, a3
+ movl a3, sp
-| Call the run-time startup C code, which will:
-| initialize, call main, call exit
- jsr __start:l
-
-| If _start returns, fall into abort.
- .globl _abort
-_abort:
- trap #0
-
-| If abort returns, fall into reset.
- .globl _reset
-_reset:
- reset
- jmp _reset
-
-| function to get the vector base register
- .globl _getvbr
-_getvbr:
- movc vbr, d0
- rts
+| now that we have relocated, call the bugcrt (note we skip over the special
+| bug header which has a PC and SP in it)
+ movl d3, a3 | RESTORE a3
+ movl d5, a4 | RESTORE a4
+ jmp _start
| The end.
-
- .data
- .globl _devlun, _ctrlun, _oparg, _opargend
-_devlun: .long 0
-_ctrlun: .long 0
-_oparg: .long 0
-_opargend: .long 0
diff --git a/sys/arch/mvme68k/stand/libsa/bugdev.c b/sys/arch/mvme68k/stand/libsa/bugdev.c
new file mode 100644
index 00000000000..3fe8cf36f51
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/bugdev.c
@@ -0,0 +1,238 @@
+/* $OpenBSD: bugdev.c,v 1.1 1996/05/16 02:30:36 chuck 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.
+ */
+
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <machine/prom.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+void cputobsdlabel __P((struct disklabel *lp, struct cpu_disklabel *clp));
+
+int errno;
+
+struct bugsc_softc {
+ int fd; /* Prom file descriptor */
+ int poff; /* Partition offset */
+ int psize; /* Partition size */
+ short ctrl;
+ short dev;
+} bugsc_softc[1];
+
+int
+devopen(f, fname, file)
+ struct open_file *f;
+ const char *fname;
+ char **file;
+{
+ register struct bugsc_softc *pp = &bugsc_softc[0];
+ int error, i, dn = 0, pn = 0;
+ char *dev, *cp;
+ static char iobuf[MAXBSIZE];
+ struct disklabel sdlabel;
+
+ dev = bugargs.arg_start;
+
+ /*
+ * Extract partition # from boot device string.
+ */
+ for (cp = dev; *cp; cp++) /* void */;
+ while (*cp != '/' && cp > dev) {
+ if (*cp == ':')
+ pn = *(cp+1) - 'a';
+ --cp;
+ }
+
+ pp->fd = bugscopen(f);
+
+ if (pp->fd < 0) {
+ printf("Can't open device `%s'\n", dev);
+ return (ENXIO);
+ }
+ error = bugscstrategy(pp, F_READ, LABELSECTOR, DEV_BSIZE, iobuf, &i);
+ if (error)
+ return (error);
+ if (i != DEV_BSIZE)
+ return (EINVAL);
+
+ cputobsdlabel(&sdlabel, (struct cpu_disklabel *)iobuf);
+ pp->poff = sdlabel.d_partitions[pn].p_offset;
+ pp->psize = sdlabel.d_partitions[pn].p_size;
+
+ f->f_dev = devsw;
+ f->f_devdata = (void *)pp;
+ *file = (char *)fname;
+ return (0);
+}
+
+/* silly block scale factor */
+#define BUG_BLOCK_SIZE 256
+#define BUG_SCALE (512/BUG_BLOCK_SIZE)
+int
+bugscstrategy(devdata, func, dblk, size, buf, rsize)
+ void *devdata;
+ int func;
+ daddr_t dblk;
+ size_t size;
+ void *buf;
+ size_t *rsize;
+{
+ struct mvmeprom_dskio dio;
+ register struct bugsc_softc *pp = (struct bugsc_softc *)devdata;
+ daddr_t blk = dblk + pp->poff;
+
+ twiddle();
+
+ dio.ctrl_lun = pp->ctrl;
+ dio.dev_lun = pp->dev;
+ dio.status = 0;
+ dio.pbuffer = buf;
+ dio.blk_num = blk * BUG_SCALE;
+ dio.blk_cnt = size / BUG_BLOCK_SIZE; /* assumed size in bytes */
+ dio.flag = 0;
+ dio.addr_mod = 0;
+#ifdef DEBUG
+ printf("bugscstrategy: size=%d blk=%d buf=%x\n", size, blk, buf);
+ printf("ctrl %d dev %d\n", dio.ctrl_lun, dio.dev_lun);
+#endif
+ mvmeprom_diskrd(&dio);
+
+ *rsize = dio.blk_cnt * BUG_BLOCK_SIZE;
+#ifdef DEBUG
+printf("rsize %d status %x\n", *rsize, dio.status);
+#endif
+
+ if (dio.status)
+ return (EIO);
+ return (0);
+}
+
+int
+bugscopen(f)
+ struct open_file *f;
+{
+#ifdef DEBUG
+ printf("bugscopen:\n");
+#endif
+
+ f->f_devdata = (void *)bugsc_softc;
+ bugsc_softc[0].ctrl = (short)bugargs.ctrl_lun;
+ bugsc_softc[0].dev = (short)bugargs.dev_lun;
+#ifdef DEBUG
+ printf("using mvmebug ctrl %d dev %d\n",
+ bugsc_softc[0].ctrl, bugsc_softc[0].dev);
+#endif
+ return (0);
+}
+
+int
+bugscclose(f)
+ struct open_file *f;
+{
+ return (EIO);
+}
+
+int
+bugscioctl(f, cmd, data)
+ struct open_file *f;
+ u_long cmd;
+ void *data;
+{
+ return (EIO);
+}
+
+void
+cputobsdlabel(lp, clp)
+ struct disklabel *lp;
+ struct cpu_disklabel *clp;
+{
+ int i;
+
+ lp->d_magic = clp->magic1;
+ lp->d_type = clp->type;
+ lp->d_subtype = clp->subtype;
+ bcopy(clp->vid_vd, lp->d_typename, 16);
+ bcopy(clp->packname, lp->d_packname, 16);
+ lp->d_secsize = clp->cfg_psm;
+ lp->d_nsectors = clp->cfg_spt;
+ lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */
+ lp->d_ntracks = clp->cfg_hds;
+
+ lp->d_secpercyl = clp->secpercyl;
+ lp->d_secperunit = clp->secperunit;
+ lp->d_secpercyl = clp->secpercyl;
+ lp->d_secperunit = clp->secperunit;
+ lp->d_sparespertrack = clp->sparespertrack;
+ lp->d_sparespercyl = clp->sparespercyl;
+ lp->d_acylinders = clp->acylinders;
+ lp->d_rpm = clp->rpm;
+ lp->d_interleave = clp->cfg_ilv;
+ lp->d_trackskew = clp->cfg_sof;
+ lp->d_cylskew = clp->cylskew;
+ lp->d_headswitch = clp->headswitch;
+
+ /* this silly table is for winchester drives */
+ switch (clp->cfg_ssr) {
+ case 0:
+ lp->d_trkseek = 0;
+ break;
+ case 1:
+ lp->d_trkseek = 6;
+ break;
+ case 2:
+ lp->d_trkseek = 10;
+ break;
+ case 3:
+ lp->d_trkseek = 15;
+ break;
+ case 4:
+ lp->d_trkseek = 20;
+ break;
+ default:
+ lp->d_trkseek = 0;
+ break;
+ }
+ lp->d_flags = clp->flags;
+ for (i = 0; i < NDDATA; i++)
+ lp->d_drivedata[i] = clp->drivedata[i];
+ for (i = 0; i < NSPARE; i++)
+ lp->d_spare[i] = clp->spare[i];
+ lp->d_magic2 = clp->magic2;
+ lp->d_checksum = clp->checksum;
+ lp->d_npartitions = clp->partitions;
+ lp->d_bbsize = clp->bbsize;
+ lp->d_sbsize = clp->sbsize;
+ bcopy(clp->vid_4, &(lp->d_partitions[0]),sizeof (struct partition) * 4);
+ bcopy(clp->cfg_4, &(lp->d_partitions[4]), sizeof (struct partition)
+ * ((MAXPARTITIONS < 16) ? (MAXPARTITIONS - 4) : 12));
+}
diff --git a/sys/arch/mvme68k/stand/libsa/clock.c b/sys/arch/mvme68k/stand/libsa/clock.c
index f56085c83ba..4f56fb85372 100644
--- a/sys/arch/mvme68k/stand/libsa/clock.c
+++ b/sys/arch/mvme68k/stand/libsa/clock.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: clock.c,v 1.2 1996/04/28 10:48:57 deraadt Exp $ */
+/* $OpenBSD: clock.c,v 1.3 1996/05/16 02:30:38 chuck Exp $ */
#include <sys/types.h>
+#include <machine/prom.h>
-#include "clockreg.h"
-#include "config.h"
-#include "clock.h"
+#include "stand.h"
+#include "libsa.h"
/*
* BCD to decimal and decimal to BCD.
@@ -15,6 +15,8 @@
#define SECDAY (24 * 60 * 60)
#define SECYR (SECDAY * 365)
#define LEAPYEAR(y) (((y) & 3) == 0)
+#define YEAR0 68
+
/*
* This code is defunct after 2068.
@@ -54,28 +56,9 @@ chiptotime(sec, min, hour, day, mon, year)
time_t
getsecs()
{
- extern int cputyp;
- register struct clockreg *cl;
- int sec, min, hour, day, mon, year;
-
- if (cputyp == CPU_147)
- cl = (struct clockreg *) CLOCK_ADDR_147;
- else
- cl = (struct clockreg *) CLOCK_ADDR_16x;
+ struct mvmeprom_time m;
- cl->cl_csr |= CLK_READ; /* enable read (stop time) */
- sec = cl->cl_sec;
- min = cl->cl_min;
- hour = cl->cl_hour;
- day = cl->cl_mday;
- mon = cl->cl_month;
- year = cl->cl_year;
- cl->cl_csr &= ~CLK_READ;/* time wears on */
- return (chiptotime(sec, min, hour, day, mon, year));
-}
-
-int
-getticks()
-{
- return getsecs() * 100;
+ mvmeprom_rtc_rd(&m);
+ return (chiptotime(m.sec_BCD, m.min_BCD, m.hour_BCD, m.day_BCD,
+ m.month_BCD, m.year_BCD));
}
diff --git a/sys/arch/mvme68k/stand/libsa/exec_mvme.c b/sys/arch/mvme68k/stand/libsa/exec_mvme.c
new file mode 100644
index 00000000000..d49ab6d2d0f
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/exec_mvme.c
@@ -0,0 +1,190 @@
+/* $NetBSD: exec_sun.c,v 1.5 1996/01/29 23:41:06 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 <machine/prom.h>
+#include <a.out.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+/*ARGSUSED*/
+void
+exec_mvme(file, flag)
+ char *file;
+ int flag;
+{
+ char *loadaddr;
+ register int io;
+ struct exec x;
+ int cc, magic;
+ void (*entry)();
+ register char *cp;
+ register int *ip;
+
+#ifdef DEBUG
+ printf("exec_mvme: file=%s flag=0x%x\n", file, flag);
+#endif
+
+ 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;
+
+ /*
+ * 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("%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.
+ * (Kernel doesn't care, but do it anyway.)
+ */
+ 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 && (flag & RB_NOSYM) == 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%x\n", cp - loadaddr);
+ close(io);
+
+ printf("Start @ 0x%x ...\n", (int)entry);
+ (*entry)(flag, 0, cp, 0, 0);
+ printf("exec: kernel returned!\n");
+ return;
+
+shread:
+ printf("exec: short read\n");
+ errno = EIO;
+closeout:
+ close(io);
+ return;
+}
diff --git a/sys/arch/mvme68k/stand/libsa/libsa.h b/sys/arch/mvme68k/stand/libsa/libsa.h
new file mode 100644
index 00000000000..4c5f22fd9c6
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/libsa.h
@@ -0,0 +1,22 @@
+/*
+ * libsa prototypes
+ */
+
+#include "libbug.h"
+
+/* bugdev.c */
+int bugscopen __P((struct open_file *, ...));
+int bugscclose __P((struct open_file *));
+int bugscioctl __P((struct open_file *, u_long, void *));
+int bugscstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
+
+/* exec_mvme.c */
+void exec_mvme __P((char *, int));
+
+/* parse_args.c */
+void parse_args __P((char **, int *));
+
+#ifndef RB_NOSYM
+#define RB_NOSYM 0x400
+#endif
+
diff --git a/sys/arch/mvme68k/stand/libsa/parse_args.c b/sys/arch/mvme68k/stand/libsa/parse_args.c
new file mode 100644
index 00000000000..69f678afbc4
--- /dev/null
+++ b/sys/arch/mvme68k/stand/libsa/parse_args.c
@@ -0,0 +1,94 @@
+/* $OpenBSD: parse_args.c,v 1.1 1996/05/16 02:30:37 chuck 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed under OpenBSD by
+ * Theo de Raadt for Willowglen Singapore.
+ * 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 <machine/prom.h>
+#include <a.out.h>
+
+#include "stand.h"
+#include "libsa.h"
+
+#define KERNEL_NAME "bsd"
+
+struct flags {
+ char c;
+ short bit;
+} bf[] = {
+ { 'a', RB_ASKNAME },
+ { 'b', RB_HALT },
+ { 'y', RB_NOSYM },
+ { 'd', RB_KDB },
+ { 'm', RB_MINIROOT },
+ { 'r', RB_DFLTROOT },
+ { 's', RB_SINGLE },
+};
+
+void
+parse_args(filep, flagp)
+
+char **filep;
+int *flagp;
+
+{
+ char *name = KERNEL_NAME, *ptr;
+ int i, howto = 0;
+ char c;
+
+ if (bugargs.arg_start != bugargs.arg_end) {
+ ptr = bugargs.arg_start;
+ while (c = *ptr) {
+ while (c == ' ')
+ c = *++ptr;
+ if (c == '\0')
+ return;
+ if (c != '-') {
+ name = ptr;
+ while ((c = *++ptr) && c != ' ')
+ ;
+ if (c)
+ *ptr++ = 0;
+ continue;
+ }
+ while ((c = *++ptr) && c != ' ') {
+ for (i = 0; i < sizeof(bf)/sizeof(bf[0]); i++)
+ if (bf[i].c == c) {
+ howto |= bf[i].bit;
+ }
+ }
+ }
+ }
+ *flagp = howto;
+ *filep = name;
+}