Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/alpha/stand abstract the prom device open/close int...



details:   https://anonhg.NetBSD.org/src/rev/654fa0d9bc82
branches:  trunk
changeset: 471469:654fa0d9bc82
user:      cgd <cgd%NetBSD.org@localhost>
date:      Fri Apr 02 03:19:08 1999 +0000

description:
abstract the prom device open/close into a separate module, which
provides the correct functions for primary, secondary, and unified
boot blocks.  actually behave correctly (e.g. expect correct arguments,
perform correct operations) depending on which you are.  also
some minor cleanup.

diffstat:

 sys/arch/alpha/stand/bootxx/bootxx.c     |  29 +-----------
 sys/arch/alpha/stand/common/boot.c       |  75 +++++++++++++++++++------------
 sys/arch/alpha/stand/common/booted_dev.c |  68 +++++++++++++++++++++++++++++
 sys/arch/alpha/stand/common/common.h     |  64 ++++++++++++++++++++++++--
 sys/arch/alpha/stand/netboot/if_prom.c   |  42 +++++------------
 5 files changed, 185 insertions(+), 93 deletions(-)

diffs (truncated from 423 to 300 lines):

diff -r e06a3559e05d -r 654fa0d9bc82 sys/arch/alpha/stand/bootxx/bootxx.c
--- a/sys/arch/alpha/stand/bootxx/bootxx.c      Fri Apr 02 03:17:28 1999 +0000
+++ b/sys/arch/alpha/stand/bootxx/bootxx.c      Fri Apr 02 03:19:08 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bootxx.c,v 1.11 1999/04/02 03:11:57 cgd Exp $ */
+/* $NetBSD: bootxx.c,v 1.12 1999/04/02 03:19:08 cgd Exp $ */
 
 /*
  * Copyright (C) 1998 by Ross Harvey
@@ -75,31 +75,6 @@
 #endif
 
 static int
-open_dev(fd)
-       int *fd;
-{
-       prom_return_t ret;
-       char devname[64];
-       int devlen;
-
-       /*
-        * XXX
-         * We don't know what device names look like yet,
-         * so we can't change them.
-         */
-        ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
-        devlen = ret.u.retval;
-
-        ret.bits = prom_open(devname, devlen);
-
-        if (ret.u.status)
-                return 0;
-       *fd = ret.u.retval;
-
-       return 1;
-}
-
-static int
 load_file(fd, bbinfop, loadaddr)
        int fd;
        struct bbinfo *bbinfop;
@@ -189,7 +164,7 @@
        bbinfop = (struct bbinfo *)&_end;
        loadaddr = (char *)SECONDARY_LOAD_ADDRESS;
 
-       if (!open_dev(&fd)) {
+       if (!booted_dev_open()) {
                puts("Can't open boot device\n");
                return;
        }
diff -r e06a3559e05d -r 654fa0d9bc82 sys/arch/alpha/stand/common/boot.c
--- a/sys/arch/alpha/stand/common/boot.c        Fri Apr 02 03:17:28 1999 +0000
+++ b/sys/arch/alpha/stand/common/boot.c        Fri Apr 02 03:19:08 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: boot.c,v 1.16 1999/04/02 03:11:57 cgd Exp $ */
+/* $NetBSD: boot.c,v 1.17 1999/04/02 03:19:08 cgd Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -52,7 +52,10 @@
 #include <machine/pte.h>
 
 #include "common.h"
-#include "stand/boot/disk.h"
+
+#if !defined(UNIFIED_BOOTBLOCK) && !defined(SECONDARY_BOOTBLOCK)
+#error not UNIFIED_BOOTBLOCK and not SECONDARY_BOOTBLOCK
+#endif
 
 int loadfile __P((char *, u_int64_t *));
 
@@ -78,8 +81,11 @@
 };
 
 void
-main(fd)
-       int     fd;
+#if defined(UNIFIED_BOOTBLOCK)
+main(void)
+#else /* defined(SECONDARY_BOOTBLOCK) */
+main(long fd)
+#endif
 {
        char *name, **namep;
        u_int64_t entry;
@@ -87,7 +93,15 @@
 
        /* Init prom callback vector. */
        init_prom_calls();
-
+#if defined(UNIFIED_BOOTBLOCK)
+        if (!booted_dev_open()) {
+                printf("Boot device (%s) open failed.\n",
+                   booted_dev_name[0] ? booted_dev_name : "unknown");
+                goto fail;
+        }
+#else /* defined(SECONDARY_BOOTBLOCK) */
+       booted_dev_setfd(fd);
+#endif
 
        /* print a banner */
        printf("\n");
@@ -95,8 +109,6 @@
        printf("(%s, %s)\n", bootprog_maker, bootprog_date);
        printf("\n");
 
-       booted_dev_fd = fd;
-
        /* switch to OSF pal code. */
        OSFpal();
 
@@ -121,31 +133,36 @@
                    namep++)
                        win = (loadfile(name = *namep, &entry) == 0);
 
-       close_primary_device(fd);
+       booted_dev_close();
        printf("\n");
-       if (win) {
-               /*
-                * Fill in the bootinfo for the kernel.
-                */
-               bzero(&bootinfo_v1, sizeof(bootinfo_v1));
-               bootinfo_v1.ssym = ssym;
-               bootinfo_v1.esym = esym;
-               bcopy(name, bootinfo_v1.booted_kernel,
-                   sizeof(bootinfo_v1.booted_kernel));
-               bcopy(boot_flags, bootinfo_v1.boot_flags,
-                   sizeof(bootinfo_v1.boot_flags));
-               bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
-               bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
-               bootinfo_v1.cngetc = NULL;
-               bootinfo_v1.cnputc = NULL;
-               bootinfo_v1.cnpollc = NULL;
-
-               (void)printf("Entering %s at 0x%lx...\n", name, entry);
-               alpha_pal_imb();
-               (*(void (*)())entry)(ffp_save, ptbr_save,
-                   BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);
+       if (!win) {
+               goto fail;
        }
 
+       /*
+        * Fill in the bootinfo for the kernel.
+        */
+       bzero(&bootinfo_v1, sizeof(bootinfo_v1));
+       bootinfo_v1.ssym = ssym;
+       bootinfo_v1.esym = esym;
+       bcopy(name, bootinfo_v1.booted_kernel,
+           sizeof(bootinfo_v1.booted_kernel));
+       bcopy(boot_flags, bootinfo_v1.boot_flags,
+           sizeof(bootinfo_v1.boot_flags));
+       bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
+       bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
+       bootinfo_v1.cngetc = NULL;
+       bootinfo_v1.cnputc = NULL;
+       bootinfo_v1.cnpollc = NULL;
+
+       (void)printf("Entering %s at 0x%lx...\n", name, entry);
+       alpha_pal_imb();
+       (*(void (*)())entry)(ffp_save, ptbr_save, BOOTINFO_MAGIC,
+           &bootinfo_v1, 1, 0);
+
+       (void)printf("KERNEL RETURNED!\n");
+
+fail:
        (void)printf("Boot failed!  Halting...\n");
        halt();
 }
diff -r e06a3559e05d -r 654fa0d9bc82 sys/arch/alpha/stand/common/booted_dev.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/stand/common/booted_dev.c  Fri Apr 02 03:19:08 1999 +0000
@@ -0,0 +1,68 @@
+/* $NetBSD: booted_dev.c,v 1.1 1999/04/02 03:19:08 cgd Exp $ */
+
+/*
+ * Copyright (c) 1999 Christopher G. Demetriou.  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 Christopher G. Demetriou
+ *     for the NetBSD Project.
+ * 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 <lib/libsa/stand.h>
+#include <lib/libkern/libkern.h>
+
+#include <machine/prom.h>
+#include "common.h"
+
+long   booted_dev_fd;
+#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
+char   booted_dev_name[BOOTED_DEV_MAXNAMELEN];
+#endif /* defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK) */
+
+#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
+int
+booted_dev_open(void)
+{
+       prom_return_t ret;
+       int devlen;
+
+       /*
+        * XXX
+        * We don't know what device names look like yet,
+        * so we can't change them.
+        */
+       ret.bits = prom_getenv(PROM_E_BOOTED_DEV, booted_dev_name,
+           sizeof(booted_dev_name));
+       devlen = ret.u.retval;
+
+       ret.bits = prom_open(booted_dev_name, devlen);
+
+       if (ret.u.status)
+               return 0;
+       booted_dev_fd = ret.u.retval;
+
+       return 1;
+}
+#endif
diff -r e06a3559e05d -r 654fa0d9bc82 sys/arch/alpha/stand/common/common.h
--- a/sys/arch/alpha/stand/common/common.h      Fri Apr 02 03:17:28 1999 +0000
+++ b/sys/arch/alpha/stand/common/common.h      Fri Apr 02 03:19:08 1999 +0000
@@ -1,10 +1,60 @@
-/*     $NetBSD: common.h,v 1.7 1999/04/02 03:11:57 cgd Exp $   */
+/* $NetBSD: common.h,v 1.8 1999/04/02 03:19:08 cgd Exp $ */
+
+/*
+ * Copyright (c) 1999 Christopher G. Demetriou.  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 Christopher G. Demetriou
+ *     for the NetBSD Project.
+ * 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        alpha_pal_imb() __asm__("imb")
 
-void init_prom_calls __P((void));
-void OSFpal __P((void));
-void halt __P((void));
-u_int64_t prom_dispatch __P((int, ...));
-void switch_palcode __P((void));
-void close_primary_device __P((int));
+void           OSFpal __P((void));
+void           init_prom_calls __P((void));
+void           halt __P((void));
+u_int64_t      prom_dispatch __P((int, ...));
+void           putstr __P((const char *));
+void           switch_palcode __P((void));
+
+
+/*
+ * booted_dev.c
+ */
+
+#define        BOOTED_DEV_MAXNAMELEN   64



Home | Main Index | Thread Index | Old Index