summaryrefslogtreecommitdiff
path: root/sys/arch/wgrisc/stand/boot
diff options
context:
space:
mode:
authorPer Fogelstrom <pefo@cvs.openbsd.org>1997-05-11 16:17:57 +0000
committerPer Fogelstrom <pefo@cvs.openbsd.org>1997-05-11 16:17:57 +0000
commit7ca343aa7ca2c7d3146dd87dd7845b6d261fa505 (patch)
tree701a6a6de8038a80d9d7f880b4a5827a60b30802 /sys/arch/wgrisc/stand/boot
parent03246f32eb4aa4c396840499bbfb8d22619ab092 (diff)
Boot block for the wgrisc!
Diffstat (limited to 'sys/arch/wgrisc/stand/boot')
-rw-r--r--sys/arch/wgrisc/stand/boot/Makefile29
-rw-r--r--sys/arch/wgrisc/stand/boot/boot.c149
-rw-r--r--sys/arch/wgrisc/stand/boot/conf.c59
-rw-r--r--sys/arch/wgrisc/stand/boot/filesystem.c44
-rw-r--r--sys/arch/wgrisc/stand/boot/ld.script74
-rw-r--r--sys/arch/wgrisc/stand/boot/sd.c194
-rw-r--r--sys/arch/wgrisc/stand/boot/start.S130
7 files changed, 679 insertions, 0 deletions
diff --git a/sys/arch/wgrisc/stand/boot/Makefile b/sys/arch/wgrisc/stand/boot/Makefile
new file mode 100644
index 00000000000..9979ff28502
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/Makefile
@@ -0,0 +1,29 @@
+# $OpenBSD: Makefile,v 1.1 1997/05/11 16:17:51 pefo Exp $
+
+PROG=boot
+SADIR=${.CURDIR}/..
+SRCS=start.S boot.c filesystem.c conf.c sd.c
+CFLAGS+=$(SACFLAGS) -I${.CURDIR}/../../../../lib/libsa -I${.CURDIR}/../libsa
+CFLAGS+=-D__INTERNAL_LIBSA_CREAD
+
+LD=ld
+LDFLAGS+= -T ld.script -x -e __start
+LDADD= ${LIBSA}
+
+all: machine-links boot.bin
+
+machine-links:
+ @rm -f machine wgrisc
+ @ln -fs ${.CURDIR}/../.. wgrisc
+ @ln -fs ${.CURDIR}/../../include machine
+
+${PROG}: $(OBJS) $(DPADD)
+ $(LD) $(LDFLAGS) -o $(PROG) $(OBJS) $(LDADD)
+
+${PROG}.bin: ${PROG}
+ cp ${PROG} ${PROG}.tmp
+ strip -s ${PROG}.tmp
+ dd if=${PROG}.tmp of=${PROG}.bin bs=4096 skip=1
+ rm ${PROG}.tmp
+
+.include <bsd.prog.mk>
diff --git a/sys/arch/wgrisc/stand/boot/boot.c b/sys/arch/wgrisc/stand/boot/boot.c
new file mode 100644
index 00000000000..6892d6a6a23
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/boot.c
@@ -0,0 +1,149 @@
+/* $NetBSD: boot.c,v 1.6 1995/06/28 10:22:32 jonathan Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * 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/stat.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+#include <stand.h>
+#include <errno.h>
+
+
+char line[1024];
+void gets __P((char *));
+ssize_t read __P((int, void *, size_t));
+int close __P((int));
+void prom_write __P((int, char *, int));
+
+int main __P((int, char **));
+int loadfile __P((char *));
+/*
+ * This gets arguments from the PROM, calls other routines to open
+ * and load the program to boot, and then transfers execution to that
+ * new program.
+ * Argv[0] should be something like "rz(0,0,0)vmunix" on a DECstation 3100.
+ * Argv[0,1] should be something like "boot 5/rz0/vmunix" on a DECstation 5000.
+ * The argument "-a" means vmunix should do an automatic reboot.
+ */
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ char *cp = 0;
+ int ask, entry;
+
+ ask = 1;
+
+ if(strcmp(argv[0], "man") != 0) {
+ cp = argv[0];
+ ask = 0;
+ }
+ while(1) {
+ do {
+ printf("Boot: ");
+ if (ask) {
+ gets(line);
+ cp = line;
+ argv[0] = cp;
+ argc = 1;
+ } else
+ printf("%s\n", cp);
+ } while(ask && line[0] == '\0');
+
+ entry = loadfile(cp);
+ if (entry != -1) {
+ printf("Starting at 0x%x\n\n", entry);
+ ((void (*)())entry)(argc, argv, 0, 0);
+ }
+ }
+ return(0);
+}
+
+/*
+ * Open 'filename', read in program and return the entry point or -1 if error.
+ */
+int
+loadfile(fname)
+ register char *fname;
+{
+ int fd, i;
+ Elf32_Ehdr eh;
+ Elf32_Phdr *ph;
+ u_long phsize;
+
+ if ((fd = oopen(fname, 0)) < 0) {
+ printf("open(%s) failed: %d\n", fname, errno);
+ goto err;
+ }
+
+ /* read the elf header */
+ if(oread(fd, (char *)&eh, sizeof(eh)) != sizeof(eh)) {
+ goto serr;
+ }
+
+ phsize = eh.e_phnum * sizeof(Elf32_Phdr);
+ ph = (Elf32_Phdr *) alloc(phsize);
+ olseek(fd, eh.e_phoff, 0);
+ if(oread(fd, (char *)ph, phsize) != phsize) {
+ goto serr;
+ }
+
+ for(i = 0; i < eh.e_phnum; i++) {
+ switch (ph[i].p_type) {
+ case PT_LOAD:
+ olseek(fd, ph[i].p_offset, 0);
+ if(oread(fd, (char *)ph[i].p_paddr, ph[i].p_filesz) != ph[i].p_filesz) {
+ goto serr;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ (void) oclose(fd);
+ return(eh.e_entry);
+serr:
+ printf("Read size error\n");
+err:
+ printf("Can't boot '%s'\n", fname);
+ (void) oclose(fd);
+ return (-1);
+}
diff --git a/sys/arch/wgrisc/stand/boot/conf.c b/sys/arch/wgrisc/stand/boot/conf.c
new file mode 100644
index 00000000000..fa2b4cb730c
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/conf.c
@@ -0,0 +1,59 @@
+/* $NetBSD: conf.c,v 1.5 1995/01/18 06:53:39 mellon Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * 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.
+ *
+ * @(#)conf.c 8.1 (Berkeley) 6/10/93
+ */
+
+#include <stand.h>
+
+int errno;
+
+extern void nullsys();
+extern int nodev();
+extern int noioctl();
+
+int sdstrategy __P((void *, int, daddr_t, size_t, void *, size_t *));
+int sdopen __P((struct open_file *, ...));
+int sdclose __P((struct open_file *));
+
+#define sdioctl noioctl
+
+struct devsw devsw[] = {
+ { "sd", sdstrategy, sdopen, sdclose, sdioctl }, /*0*/
+};
+
+int ndevs = (sizeof(devsw)/sizeof(devsw[0]));
diff --git a/sys/arch/wgrisc/stand/boot/filesystem.c b/sys/arch/wgrisc/stand/boot/filesystem.c
new file mode 100644
index 00000000000..b35709b9ad2
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/filesystem.c
@@ -0,0 +1,44 @@
+/* $NetBSD: filesystem.c,v 1.2 1995/02/16 02:33:05 cgd Exp $ */
+
+/*
+ * Copyright (c) 1993 Philip A. Nelson.
+ * 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 Philip A. Nelson.
+ * 4. The name of Philip A. Nelson may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY PHILIP NELSON ``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 PHILIP NELSON 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.
+ *
+ * filesystem.c
+ */
+
+#include <stand.h>
+#include <ufs.h>
+
+struct fs_ops file_system[] = {
+ { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat },
+};
+
+int nfsys = sizeof(file_system)/sizeof(struct fs_ops);
+
diff --git a/sys/arch/wgrisc/stand/boot/ld.script b/sys/arch/wgrisc/stand/boot/ld.script
new file mode 100644
index 00000000000..f81b4908653
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/ld.script
@@ -0,0 +1,74 @@
+OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips",
+ "elf32-littlemips")
+OUTPUT_ARCH(mips)
+ENTRY(_start)
+SECTIONS
+{
+ /* Read-only sections, merged into text segment: */
+ . = 0x80200000;
+ .text :
+ {
+ _ftext = . ;
+ *(.text)
+ *(.rodata)
+ *(.rodata1)
+ *(.reginfo)
+ *(.init)
+ *(.stub)
+ /* .gnu.warning sections are handled specially by elf32.em. */
+ *(.gnu.warning)
+ } =0
+ _etext = .;
+ PROVIDE (etext = .);
+ .fini : { *(.fini) } =0
+ .data :
+ {
+ _fdata = . ;
+ *(.data)
+ CONSTRUCTORS
+ }
+ .data1 : { *(.data1) }
+ .ctors : { *(.ctors) }
+ .dtors : { *(.dtors) }
+ _gp = ALIGN(16) + 0x7ff0;
+ .got :
+ {
+ *(.got.plt) *(.got)
+ }
+ /* We want the small data sections together, so single-instruction offsets
+ can access them all, and initialized data all before uninitialized, so
+ we can shorten the on-disk segment size. */
+ .sdata : { *(.sdata) }
+ .lit8 : { *(.lit8) }
+ .lit4 : { *(.lit4) }
+ _edata = .;
+ PROVIDE (edata = .);
+ __bss_start = .;
+ _fbss = .;
+ .sbss : { *(.sbss) *(.scommon) }
+ .bss :
+ {
+ *(.dynbss)
+ *(.bss)
+ *(COMMON)
+ }
+ _end = . ;
+ PROVIDE (end = .);
+ /* These are needed for ELF backends which have not yet been
+ converted to the new style linker. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ /* DWARF debug sections.
+ Symbols in the .debug DWARF section are relative to the beginning of the
+ section so we begin .debug at 0. It's not clear yet what needs to happen
+ for the others. */
+ .debug 0 : { *(.debug) }
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ .line 0 : { *(.line) }
+ /* These must appear regardless of . */
+ .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
+ .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
+}
diff --git a/sys/arch/wgrisc/stand/boot/sd.c b/sys/arch/wgrisc/stand/boot/sd.c
new file mode 100644
index 00000000000..34f8068e14a
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/sd.c
@@ -0,0 +1,194 @@
+/* $NetBSD: sd.c,v 1.6 1995/06/28 10:22:35 jonathan Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Van Jacobson of Lawrence Berkeley Laboratory and Ralph Campbell.
+ *
+ * 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.
+ *
+ * @(#)sd.c 8.1 (Berkeley) 6/10/93
+ */
+
+#include <stdarg.h>
+
+#include <stand.h>
+#include <sys/param.h>
+#include <sys/disklabel.h>
+
+int prom_seek __P((int, long, int));
+int disk_read __P((int, char *, int, int));
+int disk_open __P((char *, int));
+
+struct sd_softc {
+ int sc_fd; /* PROM file id */
+ int sc_ctlr; /* controller number */
+ int sc_unit; /* disk unit number */
+ int sc_part; /* disk partition number */
+ struct disklabel sc_label; /* disk label for this disk */
+};
+
+int
+sdstrategy(devdata, rw, bn, reqcnt, addr, cnt)
+ void *devdata;
+ int rw;
+ daddr_t bn;
+ u_int reqcnt;
+ char *addr;
+ u_int *cnt; /* out: number of bytes transfered */
+{
+ struct sd_softc *sc = (struct sd_softc *)devdata;
+ int part = sc->sc_part;
+ struct partition *pp = &sc->sc_label.d_partitions[part];
+ int s;
+ long offset;
+
+ offset = bn * DEV_BSIZE;
+
+ /*
+ * Partial-block transfers not handled.
+ */
+ if (reqcnt & (DEV_BSIZE - 1)) {
+ *cnt = 0;
+ return (EINVAL);
+ }
+
+ offset += pp->p_offset * DEV_BSIZE;
+
+ s = disk_read(sc->sc_fd, addr, offset, reqcnt);
+#if 0 /* XXX error code not returned yet... */
+ if (s <= 0)
+ return (EIO);
+#endif
+
+ *cnt = reqcnt;
+ return (0);
+}
+
+int
+sdopen(struct open_file *f, ...)
+{
+ int ctlr, unit, part;
+
+ struct sd_softc *sc;
+ struct disklabel *lp;
+ struct dos_partition dp, *dp2;
+ int i, fd;
+ char *msg;
+ char buf[DEV_BSIZE];
+ int cnt;
+ daddr_t labelsector;
+ static char device[] = "sd(0)";
+ va_list ap;
+
+ va_start(ap, f);
+
+ ctlr = va_arg(ap, int);
+ unit = va_arg(ap, int);
+ part = va_arg(ap, int);
+ if (unit >= 7 || part >= 16)
+ return (ENXIO);
+
+ device[3] = unit + '0';
+ fd = disk_open(device, 0);
+ if (fd < 0) {
+ return (ENXIO);
+ }
+
+ sc = alloc(sizeof(struct sd_softc));
+ bzero(sc, sizeof(struct sd_softc));
+ f->f_devdata = (void *)sc;
+
+ sc->sc_fd = fd;
+ sc->sc_ctlr = ctlr;
+ sc->sc_unit = unit;
+ sc->sc_part = part;
+
+ lp = &sc->sc_label;
+ lp->d_secsize = DEV_BSIZE;
+ lp->d_secpercyl = 1;
+ lp->d_npartitions = MAXPARTITIONS;
+ lp->d_partitions[part].p_offset = 0;
+ lp->d_partitions[part].p_size = 0x7fffffff;
+
+ /* First check for any DOS partition table */
+ i = sdstrategy(sc, F_READ, (daddr_t)DOSBBSECTOR, DEV_BSIZE, buf, &cnt);
+ if (i || cnt != DEV_BSIZE) {
+ printf("sd%d: error reading disk label\n", unit);
+ goto bad;
+ }
+ labelsector = 0;
+ bcopy(buf + DOSPARTOFF, &dp, NDOSPART * sizeof(dp));
+ for (dp2=&dp, i=0; i < NDOSPART; i++, dp2++) {
+ if (dp2->dp_size && dp2->dp_typ == DOSPTYP_OPENBSD) {
+ labelsector = dp2->dp_start;
+ break;
+ }
+ }
+ for (dp2=&dp, i=0; i < NDOSPART; i++, dp2++) {
+ if (dp2->dp_size && dp2->dp_typ == DOSPTYP_386BSD) {
+ labelsector = dp2->dp_start;
+ break;
+ }
+ }
+
+
+ /* try to read disk label and partition table information */
+ labelsector += LABELSECTOR;
+ i = sdstrategy(sc, F_READ, (daddr_t)labelsector, DEV_BSIZE, buf, &cnt);
+ if (i || cnt != DEV_BSIZE) {
+ printf("sd%d: error reading disk label\n", unit);
+ goto bad;
+ }
+ msg = getdisklabel(buf, lp);
+ if (msg) {
+ printf("sd%d: %s\n", unit, msg);
+ goto bad;
+ }
+
+ if (part >= lp->d_npartitions || lp->d_partitions[part].p_size == 0) {
+ bad:
+#ifndef SMALL
+ free(sc, sizeof(struct sd_softc));
+#endif
+ return (ENXIO);
+ }
+ return (0);
+}
+
+int
+sdclose(f)
+ struct open_file *f;
+{
+ free(f->f_devdata, sizeof(struct sd_softc));
+ f->f_devdata = (void *)0;
+ return (0);
+}
diff --git a/sys/arch/wgrisc/stand/boot/start.S b/sys/arch/wgrisc/stand/boot/start.S
new file mode 100644
index 00000000000..70535726c56
--- /dev/null
+++ b/sys/arch/wgrisc/stand/boot/start.S
@@ -0,0 +1,130 @@
+/* $OpenBSD: start.S,v 1.1 1997/05/11 16:17:54 pefo Exp $ */
+
+/*
+ * Copyright (c) 1997 Per Fogelstrom
+ *
+ * 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
+ * Per Fogelstrom.
+ * 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.
+ *
+ */
+
+#define ABICALLS
+
+#include <machine/regdef.h>
+#include <machine/asm.h>
+
+/*
+ * Frame required for the debugger (if we have any)
+ */
+#define START_FRAME ((4 * 4) + 4 + 4)
+
+ .globl __start
+__start:
+ .set noreorder
+ la gp, _gp
+ la sp, __start - START_FRAME # Stack below program
+ sw zero, START_FRAME - 4(sp) # Zero out old ra for debugger
+ sw zero, START_FRAME - 8(sp) # Zero out old fp for debugger
+ move s0, a0 # save argc
+ move s1, a1 # save argv
+
+ la a0, edata # clear BSS
+ li a1, 0
+ la a2, end
+ jal memset # memset(edata, 0, end - edata)
+ subu a2, a2, a0
+
+ move a0, s0 # restore argc
+ jal main # main(argc, argv)
+ move a1, s1 # restore argv
+
+ j restart # restart...
+ nop
+
+/* dummy routine for gcc2 */
+LEAF(__main)
+ j ra
+ nop
+END(__main)
+
+/*
+ * Boot rom entrypoints.
+ */
+
+#define BOOTVEC 0xbfc00500 /* Address of boot vector table */
+
+NON_LEAF(getchar, STAND_FRAME_SIZE, ra)
+ .mask 0x80000000, (STAND_RA_OFFSET - STAND_FRAME_SIZE)
+ subu sp, sp, STAND_FRAME_SIZE
+ sw ra, STAND_RA_OFFSET(sp)
+
+ move a1, sp
+ li a0, 0
+ li a2, 1
+ jal prom_read
+
+ lbu v0, 0(sp)
+ lw ra, STAND_RA_OFFSET(sp)
+ addu sp, sp, STAND_FRAME_SIZE
+ jr ra
+END(getchar)
+
+LEAF(putchar)
+ sb a0, 0(sp)
+ move a1, sp
+ li a0, 1 /* Stdout */
+ li a2, 1
+ b prom_write
+
+END(putchar)
+
+LEAF(restart)
+END(restart)
+
+LEAF(panic)
+END(panic)
+
+LEAF(disk_open)
+ lw v0, BOOTVEC+96
+ jr v0
+END(disk_open)
+
+LEAF(disk_read)
+ lw v0, BOOTVEC+100
+ jr v0
+END(disk_read)
+
+
+LEAF(prom_read)
+ lw v0, BOOTVEC+0
+ jr v0
+END(prom_read)
+
+LEAF(prom_write)
+ lw v0, BOOTVEC+4
+ jr v0
+END(prom_write)