Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc/stand Rather than using nlist(3), use a magic...



details:   https://anonhg.NetBSD.org/src/rev/5a741962f867
branches:  trunk
changeset: 516792:5a741962f867
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Oct 30 05:13:09 2001 +0000

description:
Rather than using nlist(3), use a magic structure with a magic
number that installboot(8) can search for.  Suggested by cgd%netbsd.org@localhost.

diffstat:

 sys/arch/sparc/stand/bootxx/bootxx.c           |  30 ++++----
 sys/arch/sparc/stand/common/bbinfo.h           |  41 +++++++++++
 sys/arch/sparc/stand/installboot/Makefile      |   3 +-
 sys/arch/sparc/stand/installboot/installboot.c |  91 ++++++-------------------
 4 files changed, 82 insertions(+), 83 deletions(-)

diffs (truncated from 303 to 300 lines):

diff -r cc605244dbbd -r 5a741962f867 sys/arch/sparc/stand/bootxx/bootxx.c
--- a/sys/arch/sparc/stand/bootxx/bootxx.c      Tue Oct 30 04:58:08 2001 +0000
+++ b/sys/arch/sparc/stand/bootxx/bootxx.c      Tue Oct 30 05:13:09 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootxx.c,v 1.8 2000/03/13 23:52:33 soren Exp $ */
+/*     $NetBSD: bootxx.c,v 1.9 2001/10/30 05:13:09 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -43,6 +43,7 @@
 #include <lib/libsa/stand.h>
 
 #include <machine/promlib.h>
+#include <sparc/stand/common/bbinfo.h>
 #include <sparc/stand/common/promdev.h>
 
 int debug;
@@ -55,16 +56,17 @@
 struct open_file       io;
 
 /*
- * The contents of the block_* variables below is set by installboot(8)
+ * The contents of the bbinfo below are set by installboot(8)
  * to hold the filesystem data of the second-stage boot program
  * (typically `/boot'): filesystem block size, # of filesystem
  * blocks and the block numbers themselves.
  */
-#define MAXBLOCKNUM    256     /* enough for a 2MB boot program (bs 8K) */
-int32_t                        block_size = 0;
-int32_t                        block_count = MAXBLOCKNUM;
-daddr_t                        block_table[MAXBLOCKNUM] = { 0 };
-
+struct bbinfo bbinfo = {
+       { BBINFO_MAGIC },
+       0,
+       MAXBLOCKNUM,
+       { 0 }
+};
 
 int    main __P((void));
 void   loadboot __P((struct open_file *, caddr_t));
@@ -113,24 +115,24 @@
         * needed for sun4 architecture, but use it for all machines
         * to keep code size down as much as possible.
         */
-       buf = alloc(block_size);
+       buf = alloc(bbinfo.bbi_block_size);
        if (buf == NULL)
                panic("%s: alloc failed", progname);
 
-       for (i = 0; i < block_count; i++) {
-               if ((blk = block_table[i]) == 0)
+       for (i = 0; i < bbinfo.bbi_block_count; i++) {
+               if ((blk = bbinfo.bbi_block_table[i]) == 0)
                        panic("%s: block table corrupt", progname);
 
 #ifdef DEBUG
                printf("%s: block # %d = %d\n", progname, i, blk);
 #endif
-               if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ,
-                                           blk, block_size, buf, &n)) {
+               if ((f->f_dev->dv_strategy)(f->f_devdata, F_READ, blk,
+                   bbinfo.bbi_block_size, buf, &n)) {
                        printf("%s: read failure", progname);
                        _rtt();
                }
-               bcopy(buf, addr, block_size);
-               if (n != block_size)
+               bcopy(buf, addr, bbinfo.bbi_block_size);
+               if (n != bbinfo.bbi_block_size)
                        panic("%s: short read", progname);
                if (i == 0) {
                        int m = N_GETMAGIC(*(struct exec *)addr);
diff -r cc605244dbbd -r 5a741962f867 sys/arch/sparc/stand/common/bbinfo.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc/stand/common/bbinfo.h      Tue Oct 30 05:13:09 2001 +0000
@@ -0,0 +1,41 @@
+/*     $NetBSD: bbinfo.h,v 1.1 2001/10/30 05:13:10 thorpej Exp $       */
+
+/*
+ * Copyright (c) 1995, 1996 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ *  Software Distribution Coordinator  or  Software.Distribution%CS.CMU.EDU@localhost
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#define        MAXBLOCKNUM     256     /* enough for a 2MB boot program (bs 8K) */
+
+/* Magic string -- 32 bytes long (including the NUL) */
+#define        BBINFO_MAGIC    "NetBSD/sparc bootxx            "
+#define        BBINFO_MAGICSIZE sizeof(BBINFO_MAGIC)
+
+struct bbinfo {
+       uint8_t bbi_magic[BBINFO_MAGICSIZE];
+       int32_t bbi_block_size;
+       int32_t bbi_block_count;
+       int32_t bbi_block_table[MAXBLOCKNUM];
+};
diff -r cc605244dbbd -r 5a741962f867 sys/arch/sparc/stand/installboot/Makefile
--- a/sys/arch/sparc/stand/installboot/Makefile Tue Oct 30 04:58:08 2001 +0000
+++ b/sys/arch/sparc/stand/installboot/Makefile Tue Oct 30 05:13:09 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.13 2000/08/16 08:24:01 mrg Exp $
+#      $NetBSD: Makefile,v 1.14 2001/10/30 05:13:10 thorpej Exp $
 
 .include <bsd.own.mk>
 
@@ -13,6 +13,7 @@
 .PATH.c: ${LIBSA}
 
 CPPFLAGS+=-I${LIBSA} -I.
+CPPFLAGS+=-I${.CURDIR}/..
 
 LDSTATIC?=     -static
 
diff -r cc605244dbbd -r 5a741962f867 sys/arch/sparc/stand/installboot/installboot.c
--- a/sys/arch/sparc/stand/installboot/installboot.c    Tue Oct 30 04:58:08 2001 +0000
+++ b/sys/arch/sparc/stand/installboot/installboot.c    Tue Oct 30 05:13:09 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: installboot.c,v 1.8 2001/02/19 22:48:59 cgd Exp $ */
+/*     $NetBSD: installboot.c,v 1.9 2001/10/30 05:13:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -49,40 +49,20 @@
 #include <err.h>
 #include <a.out.h>
 #include <fcntl.h>
-#include <nlist.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stddef.h>
 #include <string.h>
 #include <unistd.h>
 
 #include "loadfile.h"
+#include "common/bbinfo.h"
 
 int    verbose, nowrite, sparc64, uflag, hflag = 1;
 char   *boot, *proto, *dev;
 
-#if 0
-#ifdef __ELF__
-#define SYMNAME(a)     a
-#else
-#define SYMNAME(a)     __CONCAT("_",a)
-#endif
-#else
-/* XXX: Hack in libc nlist works with both formats */
-#define SYMNAME(a)     __CONCAT("_",a)
-#endif
+struct bbinfo *bbinfop;                /* bbinfo in prototype image */
 
-struct nlist nl[] = {
-#define X_BLOCKTABLE   0
-       { {SYMNAME("block_table")} },
-#define X_BLOCKCOUNT   1
-       { {SYMNAME("block_count")} },
-#define X_BLOCKSIZE    2
-       { {SYMNAME("block_size")} },
-       { {NULL} }
-};
-daddr_t        *block_table;           /* block number array in prototype image */
-int32_t        *block_count_p;         /* size of this array */
-int32_t        *block_size_p;          /* filesystem block size */
 int32_t        max_block_count;
 
 char           *loadprotoblocks __P((char *, size_t *));
@@ -242,27 +222,9 @@
        size_t *size;
 {
        int     fd, sz;
-       u_long  ap, bp, st, en;
+       u_long  ap, bp, st, en, bbi;
        u_long  marks[MARK_MAX];
 
-       /* Locate block number array in proto file */
-       if (nlist(fname, nl) != 0) {
-               warnx("nlist: %s: symbols not found", fname);
-               return NULL;
-       }
-       if (nl[X_BLOCKTABLE].n_type != N_DATA + N_EXT) {
-               warnx("nlist: %s: wrong type", nl[X_BLOCKTABLE].n_un.n_name);
-               return NULL;
-       }
-       if (nl[X_BLOCKCOUNT].n_type != N_DATA + N_EXT) {
-               warnx("nlist: %s: wrong type", nl[X_BLOCKCOUNT].n_un.n_name);
-               return NULL;
-       }
-       if (nl[X_BLOCKSIZE].n_type != N_DATA + N_EXT) {
-               warnx("nlist: %s: wrong type", nl[X_BLOCKSIZE].n_un.n_name);
-               return NULL;
-       }
-
        marks[MARK_START] = 0;
        if ((fd = loadfile(fname, marks, COUNT_TEXT|COUNT_DATA)) == -1)
                return NULL;
@@ -284,28 +246,20 @@
                return NULL;
        (void)close(fd);
 
-       block_table = (daddr_t *) (bp + nl[X_BLOCKTABLE].n_value - st);
-       block_count_p = (int32_t *)(bp + nl[X_BLOCKCOUNT].n_value - st);
-       block_size_p = (int32_t *) (bp + nl[X_BLOCKSIZE].n_value - st);
-       if ((int)(u_long)block_table & 3) {
-               warn("%s: invalid address: block_table = %p",
-                    fname, block_table);
-               free((void *)bp);
+       /* Look for the bbinfo structure. */
+       for (bbi = bp; bbi < (bp + sz); bbi += sizeof(uint32_t)) {
+               bbinfop = (void *) bbi;
+               if (memcmp(bbinfop->bbi_magic, BBINFO_MAGIC,
+                   BBINFO_MAGICSIZE) == 0)
+                       break;
+       }
+       if (bbi >= (bp + sz)) {
+               warn("%s: unable to locate bbinfo structure\n", fname);
+               free((void *)ap);
                return NULL;
        }
-       if ((int)(u_long)block_count_p & 3) {
-               warn("%s: invalid address: block_count_p = %p",
-                    fname, block_count_p);
-               free((void *)bp);
-               return NULL;
-       }
-       if ((int)(u_long)block_size_p & 3) {
-               warn("%s: invalid address: block_size_p = %p",
-                    fname, block_size_p);
-               free((void *)bp);
-               return NULL;
-       }
-       max_block_count = *block_count_p;
+
+       max_block_count = bbinfop->bbi_block_count;
 
        if (verbose) {
                printf("%s: entry point %#lx\n", fname, en);
@@ -313,7 +267,8 @@
                    hflag ? "left on" : "stripped off");
                printf("proto bootblock size %d\n", sz);
                printf("room for %d filesystem blocks at %#lx\n",
-                   max_block_count, nl[X_BLOCKTABLE].n_value);
+                   max_block_count,
+                   bbi - bp + offsetof(struct bbinfo, bbi_block_table));
        }
 
        if (hflag) {
@@ -408,7 +363,7 @@
        /*
         * Register filesystem block size.
         */
-       *block_size_p = fs->fs_bsize;
+       bbinfop->bbi_block_size = fs->fs_bsize;
 
        /*
         * Get the block numbers; we don't handle fragments
@@ -420,14 +375,14 @@
        /*
         * Register block count.
         */
-       *block_count_p = ndb;
+       bbinfop->bbi_block_count = ndb;
 
        if (verbose)
                printf("%s: block numbers: ", boot);
        ap = ip->di_db;
        for (i = 0; i < NDADDR && *ap && ndb; i++, ap++, ndb--) {
                blk = fsbtodb(fs, *ap);
-               block_table[i] = blk;
+               bbinfop->bbi_block_table[i] = blk;
                if (verbose)
                        printf("%d ", blk);
        }
@@ -448,7 +403,7 @@
        ap = (daddr_t *)buf;
        for (; i < NINDIR(fs) && *ap && ndb; i++, ap++, ndb--) {
                blk = fsbtodb(fs, *ap);
-               block_table[i] = blk;
+               bbinfop->bbi_block_table[i] = blk;



Home | Main Index | Thread Index | Old Index