mirror of
https://github.com/dreamlayers/netbsd-mopd.git
synced 2026-01-21 18:05:06 +00:00
Add Elf32 support to mopa.out (which is now quite inappropriately
named; a future commit will rename it). Thanks to uwe@netbsd.org for testing the resulting MOP image for me. Fixes port-vax/16867.
This commit is contained in:
parent
1e3eaa9c63
commit
73a369d189
@ -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 @@ struct dllist {
|
||||
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 {
|
||||
|
||||
@ -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 @@ __RCSID("$NetBSD: file.c,v 1.8 2002/02/18 22:00:36 thorpej Exp $");
|
||||
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 @@ GetElfFileInfo(dl)
|
||||
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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 @@ __RCSID("$NetBSD: mopa.out.c,v 1.8 2002/02/18 22:00:36 thorpej Exp $");
|
||||
#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 @@ int
|
||||
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 @@ main (int argc, char **argv)
|
||||
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
|
||||
|
||||
#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 = dl.a_text + dl.a_text_fill + dl.a_data + dl.a_data_fill +
|
||||
dl.a_bss + dl.a_bss_fill;
|
||||
i = (i+1) / 512;
|
||||
|
||||
dl.nloadaddr = dl.loadaddr;
|
||||
@ -128,8 +157,32 @@ main (int argc, char **argv)
|
||||
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user