Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/mopd Add Elf32 support to mopa.out (which is now qu...



details:   https://anonhg.NetBSD.org/src/rev/843bcf3dd83d
branches:  trunk
changeset: 532409:843bcf3dd83d
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Thu Jun 06 22:52:25 2002 +0000

description:
Add Elf32 support to mopa.out (which is now quite inappropriately
named; a future commit will rename it).

Thanks to uwe%netbsd.org@localhost for testing the resulting MOP image for me.

Fixes port-vax/16867.

diffstat:

 usr.sbin/mopd/common/common.h     |   5 +-
 usr.sbin/mopd/common/file.c       |  24 +++++++++-
 usr.sbin/mopd/common/file.h       |   6 +-
 usr.sbin/mopd/mopa.out/mopa.out.c |  87 +++++++++++++++++++++++++++++++-------
 4 files changed, 99 insertions(+), 23 deletions(-)

diffs (239 lines):

diff -r 55f266bfb784 -r 843bcf3dd83d usr.sbin/mopd/common/common.h
--- a/usr.sbin/mopd/common/common.h     Thu Jun 06 21:45:19 2002 +0000
+++ b/usr.sbin/mopd/common/common.h     Thu Jun 06 22:52:25 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.h,v 1.5 2002/02/18 22:00:36 thorpej Exp $       */
+/*     $NetBSD: common.h,v 1.6 2002/06/06 22:52:25 thorpej Exp $       */
 
 /*
  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
@@ -28,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $NetBSD: common.h,v 1.5 2002/02/18 22:00:36 thorpej Exp $
+ *     $NetBSD: common.h,v 1.6 2002/06/06 22:52:25 thorpej Exp $
  *
  */
 
@@ -92,6 +92,7 @@
        mopd_imagetype  image_type;     /* what type of image is it?    */
 
        /* For Elf32 files */
+       int             e_machine;      /* Machine ID                   */
        int             e_nsec;         /* number of program sections   */
 #define        SEC_MAX 4
        struct {
diff -r 55f266bfb784 -r 843bcf3dd83d usr.sbin/mopd/common/file.c
--- a/usr.sbin/mopd/common/file.c       Thu Jun 06 21:45:19 2002 +0000
+++ b/usr.sbin/mopd/common/file.c       Thu Jun 06 22:52:25 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file.c,v 1.8 2002/02/18 22:00:36 thorpej Exp $ */
+/*     $NetBSD: file.c,v 1.9 2002/06/06 22:52:25 thorpej Exp $ */
 
 /*
  * Copyright (c) 1995-96 Mats O Jansson.  All rights reserved.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: file.c,v 1.8 2002/02/18 22:00:36 thorpej Exp $");
+__RCSID("$NetBSD: file.c,v 1.9 2002/06/06 22:52:25 thorpej Exp $");
 #endif
 
 #include "os.h"
@@ -66,6 +66,25 @@
 int    getCLBYTES __P((int));
 int    getMID __P((int, int));
 
+const char *
+FileTypeName(type)
+       mopd_imagetype type;
+{
+
+       switch (type) {
+       case IMAGE_TYPE_MOP:
+               return ("MOP");
+
+       case IMAGE_TYPE_ELF32:
+               return ("Elf32");
+
+       case IMAGE_TYPE_AOUT:
+               return ("a.out");
+       }
+
+       abort();
+}
+
 void
 mopFilePutLX(buf, index, value, cnt)
        u_char         *buf;
@@ -603,6 +622,7 @@
                printf(" S%d Pad Size:       %08x\n", i,
                    dl->e_sections[i].s_pad);
        }
+       dl->e_machine = e_machine;
 
        dl->e_curpos = 0;
        dl->e_cursec = 0;
diff -r 55f266bfb784 -r 843bcf3dd83d usr.sbin/mopd/common/file.h
--- a/usr.sbin/mopd/common/file.h       Thu Jun 06 21:45:19 2002 +0000
+++ b/usr.sbin/mopd/common/file.h       Thu Jun 06 22:52:25 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file.h,v 1.4 2002/02/18 22:00:36 thorpej Exp $ */
+/*     $NetBSD: file.h,v 1.5 2002/06/06 22:52:25 thorpej Exp $ */
 
 /*
  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
@@ -28,7 +28,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $NetBSD: file.h,v 1.4 2002/02/18 22:00:36 thorpej Exp $
+ *     $NetBSD: file.h,v 1.5 2002/06/06 22:52:25 thorpej Exp $
  *
  */
 
@@ -36,6 +36,8 @@
 #define _FILE_H_
 
 __BEGIN_DECLS
+const char     *FileTypeName(mopd_imagetype);
+
 void           mopFilePutLX(u_char *, int, u_int32_t, int);
 void           mopFilePutBX(u_char *, int, u_int32_t, int);
 u_int32_t      mopFileGetLX(u_char *, int, int);
diff -r 55f266bfb784 -r 843bcf3dd83d usr.sbin/mopd/mopa.out/mopa.out.c
--- a/usr.sbin/mopd/mopa.out/mopa.out.c Thu Jun 06 21:45:19 2002 +0000
+++ b/usr.sbin/mopd/mopa.out/mopa.out.c Thu Jun 06 22:52:25 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mopa.out.c,v 1.8 2002/02/18 22:00:36 thorpej Exp $     */
+/*     $NetBSD: mopa.out.c,v 1.9 2002/06/06 22:52:26 thorpej Exp $     */
 
 /* mopa.out - Convert a Unix format kernel into something that
  * can be transfered via MOP.
@@ -49,7 +49,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mopa.out.c,v 1.8 2002/02/18 22:00:36 thorpej Exp $");
+__RCSID("$NetBSD: mopa.out.c,v 1.9 2002/06/06 22:52:26 thorpej Exp $");
 #endif
 
 #include "os.h"
@@ -70,6 +70,17 @@
 #define MID_VAX 140
 #endif
 
+#ifndef NOELF
+# if defined(__NetBSD__)
+#  include <sys/exec_elf.h>
+# else
+#  define NOELF
+# endif
+# if !defined(EM_VAX)
+#  define EM_VAX 75
+# endif
+#endif /* NOELF */
+
 u_char header[512];            /* The VAX header we generate is 1 block. */
 struct exec ex, ex_swap;
 
@@ -77,13 +88,9 @@
 main (int argc, char **argv)
 {
        FILE   *out;            /* A FILE because that is easier. */
-       int     i;
+       int     i, j;
        struct dllist dl;
 
-#ifdef NOAOUT
-       errx(1, "has no function in NetBSD");
-#endif 
-
        if (argc != 3) {
                fprintf (stderr, "usage: %s kernel-in sys-out\n",
                    getprogname());
@@ -94,17 +101,39 @@
        if (dl.ldfd == -1)
                err(2, "open `%s'", argv[1]);
        
-       GetFileInfo(&dl);
+       if (GetFileInfo(&dl) == -1)
+               errx(3, "`%s' is an unknown file type", argv[1]);
 
-       if (dl.image_type != IMAGE_TYPE_AOUT)
-               errx(3, "`%s' is not an a.out file", argv[1]);
+       switch (dl.image_type) {
+       case IMAGE_TYPE_MOP:
+               errx(3, "`%s' is already a MOP image", argv[1]);
+               break;
 
-       if (dl.a_mid != MID_VAX)
-               printf("WARNING: `%s' is not a VAX image (mid=%d)\n",
-                   argv[1], dl.a_mid);
+#ifndef NOELF
+       case IMAGE_TYPE_ELF32:
+               if (dl.e_machine != EM_VAX)
+                       printf("WARNING: `%s' is not a VAX image "
+                           "(machine=%d)\n", argv[1], dl.e_machine);
+               for (i = 0, j = 0; j < dl.e_nsec; j++)
+                       i += dl.e_sections[j].s_fsize + dl.e_sections[j].s_pad;
+               break;
+#endif
 
-       i = dl.a_text + dl.a_text_fill + dl.a_data + dl.a_data_fill +
-           dl.a_bss  + dl.a_bss_fill;
+#ifndef NOAOUT
+       case IMAGE_TYPE_AOUT:
+               if (dl.a_mid != MID_VAX)
+                       printf("WARNING: `%s' is not a VAX image (mid=%d)\n",
+                           argv[1], dl.a_mid);
+               i = dl.a_text + dl.a_text_fill + dl.a_data + dl.a_data_fill +
+                   dl.a_bss  + dl.a_bss_fill;
+               break;
+#endif
+
+       default:
+               errx(3, "Image type `%s' not supported",
+                   FileTypeName(dl.image_type));
+       }
+
        i = (i+1) / 512;
 
        dl.nloadaddr = dl.loadaddr;
@@ -128,8 +157,32 @@
        
        fwrite (header, sizeof (header), 1, out);
 
-       fprintf(stderr, "copying %u+%u+%u->%u\n", dl.a_text,
-           dl.a_data, dl.a_bss, dl.xferaddr);
+       switch (dl.image_type) {
+       case IMAGE_TYPE_MOP:
+               abort();
+
+       case IMAGE_TYPE_ELF32:
+#ifdef NOELF
+               abort();
+#else
+               fprintf(stderr, "copying ");
+               for (j = 0; j < dl.e_nsec; j++)
+                       fprintf(stderr, "%s%u+%u", j == 0 ? "" : "+",
+                           dl.e_sections[j].s_fsize,
+                           dl.e_sections[j].s_pad);
+               fprintf(stderr, "->%u\n", dl.xferaddr);
+#endif
+               break;
+
+       case IMAGE_TYPE_AOUT:
+#ifdef NOAOUT
+               abort();
+#else
+               fprintf(stderr, "copying %u+%u+%u->%u\n", dl.a_text,
+                   dl.a_data, dl.a_bss, dl.xferaddr);
+#endif
+               break;
+       }
        
        while ((i = mopFileRead(&dl,header)) > 0) {
                (void)fwrite(header, i, 1, out);



Home | Main Index | Thread Index | Old Index