summaryrefslogtreecommitdiff
path: root/sys/arch/sun3/stand/tapeboot
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-10-18 08:53:40 +0000
commitd6583bb2a13f329cf0332ef2570eb8bb8fc0e39c (patch)
treeece253b876159b39c620e62b6c9b1174642e070e /sys/arch/sun3/stand/tapeboot
initial import of NetBSD tree
Diffstat (limited to 'sys/arch/sun3/stand/tapeboot')
-rw-r--r--sys/arch/sun3/stand/tapeboot/Makefile13
-rw-r--r--sys/arch/sun3/stand/tapeboot/boot.c166
-rw-r--r--sys/arch/sun3/stand/tapeboot/conf.c11
-rw-r--r--sys/arch/sun3/stand/tapeboot/dev_tape.c150
-rw-r--r--sys/arch/sun3/stand/tapeboot/dev_tape.h7
-rw-r--r--sys/arch/sun3/stand/tapeboot/version.c7
6 files changed, 354 insertions, 0 deletions
diff --git a/sys/arch/sun3/stand/tapeboot/Makefile b/sys/arch/sun3/stand/tapeboot/Makefile
new file mode 100644
index 00000000000..4e0a3635516
--- /dev/null
+++ b/sys/arch/sun3/stand/tapeboot/Makefile
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $
+
+SA_PROG= tapeboot
+SRCS= boot.c conf.c dev_tape.c version.c
+
+all: ${SA_PROG}.bin
+
+.include <bsd.prog.mk>
+
+install: ${SA_PROG}.bin
+ install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+ ${SA_PROG}.bin ${DESTDIR}${MDEC_DIR}/${SA_PROG}
+
diff --git a/sys/arch/sun3/stand/tapeboot/boot.c b/sys/arch/sun3/stand/tapeboot/boot.c
new file mode 100644
index 00000000000..c6a24287299
--- /dev/null
+++ b/sys/arch/sun3/stand/tapeboot/boot.c
@@ -0,0 +1,166 @@
+/* $NetBSD: boot.c,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
+
+/*
+ * Copyright (c) 1994 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 is a generic "first-stage" boot program.
+ *
+ * Note that this program has absolutely no filesystem knowledge!
+ *
+ * Instead, this uses a table of disk block numbers that are
+ * filled in by the installboot program such that this program
+ * can load the "second-stage" boot program.
+ */
+
+#include <sys/param.h>
+#include <sys/reboot.h>
+#include <sys/exec.h>
+
+#include <machine/mon.h>
+
+#include "stand.h"
+#include "promboot.h"
+
+/*
+ * Boot device is derived from ROM provided information.
+ */
+#define LOADADDR 0x4000
+
+extern int debug;
+extern char *version;
+
+char line[80];
+
+int block_size = 512;
+
+
+main()
+{
+ struct open_file f;
+ struct bootparam *bp;
+ void (*entry)();
+ char *addr;
+ int n, error;
+
+ printf(">> NetBSD tapeboot [%s]\n", version);
+ prom_get_boot_info();
+
+ /*
+ * Set the tape file number to the next one, because
+ * the boot program is first, then the kernel.
+ */
+ bp = *romp->bootParam;
+ bp->partNum += 1;
+
+ for (;;) {
+ if (prom_boothow & RB_ASKNAME) {
+ printf("tapeboot: segment? [%d] ", bp->partNum);
+ gets(line);
+ if (('0' <= line[0]) && (line[0] <= '9')) {
+ bp->partNum = line[0] - '0';
+ }
+ }
+
+ printf("tapeboot: opening segment %d\n", bp->partNum);
+ f.f_flags = F_RAW;
+ if ((error = devopen(&f, 0, &addr)) != 0) {
+ printf("tapeboot: open failed, error=%d\n", error);
+ goto ask;
+ }
+
+ addr = (char*)LOADADDR;
+ error = loadfile(&f, addr);
+
+ printf("tapeboot: close (rewind)...\n");
+ f.f_dev->dv_close(&f);
+ if (error == 0)
+ break;
+
+ printf("tapeboot: load failed, error=%d\n", error);
+ ask:
+ prom_boothow |= RB_ASKNAME;
+ }
+
+ if (debug) {
+ printf("Debug mode - enter c to continue...");
+ /* This will print "\nAbort at ...\n" */
+ asm(" trap #0");
+ }
+
+ printf("Starting program at 0x%x\n", (long)addr);
+ entry = (void (*)())addr;
+ (*entry)();
+}
+
+int
+loadfile(fp, addr)
+ struct open_file *fp;
+ char *addr;
+{
+ char *buf;
+ int n, blknum;
+ int error = 0;
+ /*
+ * Loading a kernel. It WILL have an a.out header.
+ * XXX - This assumes OMAGIC format!
+ */
+ addr -= sizeof(struct exec); /* XXX */
+
+ /* Need to use a buffer that can be mapped into DVMA space. */
+ buf = alloc(block_size);
+ if (!buf)
+ panic("tapeboot: alloc failed");
+
+ printf("tapeboot: loading ... ");
+ /* limit program size to < 2MB */
+ for (blknum = 0; blknum < 4096; blknum++) {
+
+ error = (fp->f_dev->dv_strategy)(fp->f_devdata, F_READ,
+ blknum, block_size, buf, &n);
+ if (error) {
+ printf("(error=%d)\n", error);
+ return EIO;
+ }
+ if (n == 0)
+ break; /* end of tape */
+ if (n != block_size) {
+ printf(" (short read)\n");
+ return EIO;
+ }
+
+ bcopy(buf, addr, block_size);
+ addr += block_size;
+ }
+
+ printf("(%d blocks)\n", blknum);
+ return 0;
+}
+
diff --git a/sys/arch/sun3/stand/tapeboot/conf.c b/sys/arch/sun3/stand/tapeboot/conf.c
new file mode 100644
index 00000000000..a62f7d1f6cb
--- /dev/null
+++ b/sys/arch/sun3/stand/tapeboot/conf.c
@@ -0,0 +1,11 @@
+/* $NetBSD: conf.c,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
+
+#include <stand.h>
+#include <dev_tape.h>
+
+struct devsw devsw[] = {
+ { "tape", tape_strategy, tape_open, tape_close, tape_ioctl },
+};
+int ndevs = 1;
+
+int debug;
diff --git a/sys/arch/sun3/stand/tapeboot/dev_tape.c b/sys/arch/sun3/stand/tapeboot/dev_tape.c
new file mode 100644
index 00000000000..021db6c5fe0
--- /dev/null
+++ b/sys/arch/sun3/stand/tapeboot/dev_tape.c
@@ -0,0 +1,150 @@
+/* $NetBSD: dev_tape.c,v 1.1.1.1 1995/10/13 21:27:30 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"
+/* #include "dev_tape.h" XXX - needs stdarg.h */
+
+struct saioreq tape_ioreq;
+
+int
+tape_open(f, devname)
+ struct open_file *f;
+ char *devname; /* Device part of file name (or NULL). */
+{
+ struct bootparam *bp;
+ struct saioreq *si;
+ int error;
+
+#ifdef DEBUG_PROM
+ printf("tape_open: %s\n", devname);
+#endif
+
+ /*
+ * Setup our part of the saioreq.
+ * (determines what gets opened)
+ */
+ si = &tape_ioreq;
+ bzero((caddr_t)si, sizeof(*si));
+ bp = *romp->bootParam;
+
+ si->si_boottab = bp->bootDevice;
+ si->si_ctlr = bp->ctlrNum;
+ si->si_unit = bp->unitNum;
+ si->si_boff = bp->partNum;
+
+ if ((error = prom_iopen(si)) != 0)
+ return (error);
+
+ f->f_devdata = si;
+ return 0;
+}
+
+int
+tape_close(f)
+ struct open_file *f;
+{
+ struct saioreq *si;
+
+ si = f->f_devdata;
+ prom_iclose(si);
+ f->f_devdata = NULL;
+ return 0;
+}
+
+int
+tape_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("tape_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("tape_strategy: xcnt = %x\n", xcnt);
+#endif
+
+ /* At end of tape, xcnt == 0 (not an error) */
+ if (xcnt < 0)
+ return (EIO);
+
+ *rsize = xcnt;
+ return (0);
+}
+
+int
+tape_ioctl()
+{
+ return EIO;
+}
+
diff --git a/sys/arch/sun3/stand/tapeboot/dev_tape.h b/sys/arch/sun3/stand/tapeboot/dev_tape.h
new file mode 100644
index 00000000000..0e43954af69
--- /dev/null
+++ b/sys/arch/sun3/stand/tapeboot/dev_tape.h
@@ -0,0 +1,7 @@
+/* $NetBSD: dev_tape.h,v 1.1.1.1 1995/10/13 21:27:30 gwr Exp $ */
+
+int tape_open __P((struct open_file *, ...));
+int tape_close __P((struct open_file *));
+int tape_strategy __P((void *, int, daddr_t, size_t, void *, size_t *));
+int tape_ioctl();
+
diff --git a/sys/arch/sun3/stand/tapeboot/version.c b/sys/arch/sun3/stand/tapeboot/version.c
new file mode 100644
index 00000000000..be75f0869bf
--- /dev/null
+++ b/sys/arch/sun3/stand/tapeboot/version.c
@@ -0,0 +1,7 @@
+/* $NetBSD: version.c,v 1.2 1995/10/13 21:33:23 gwr Exp $ */
+
+/*
+ * NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.
+ */
+
+char *version = "$Revision: 1.1 $";