/* mopcopy - Convert a Unix format kernel into something that
* can be transferred via MOP.
*
* This code was written while referring to the NetBSD/vax boot
* loader. Therefore anything that can be booted by the Vax
* should be convertible with this program.
*
* If necessary, the a.out header is stripped, and the program
* segments are padded out. The BSS segment is zero filled.
* A header is prepended that looks like an IHD header. In
* particular the Unix machine ID is placed where mopd expects
* the image type to be (offset is IHD_W_ALIAS). If the machine
* ID could be mistaken for a DEC image type, then the conversion
* is aborted. The original a.out header is copied into the front
* of the header so that once we have detected the Unix machine
* ID we can haul the load address and the xfer address out.
*/
/*
* Copyright (c) 1996 Lloyd Parkes. 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 Lloyd Parkes.
* 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.
*/
#if defined (HAVE_NBTOOL_CONFIG_H)
# include "nbtool_config.h"
#else
# include "port.h"
#endif /* defined (HAVE_NBTOOL_CONFIG_H) */
#ifndef lint
__RCSID("$NetBSD: mopcopy.c,v 1.14 2024/12/03 05:57:02 kalvisd Exp $");
#endif
dl.ldfd = open (argv[1], O_RDONLY);
if (dl.ldfd == -1)
err(2, "open `%s'", argv[1]);
if (GetFileInfo(&dl) == -1)
errx(3, "`%s' is an unknown file type", argv[1]);
switch (dl.image_type) {
case IMAGE_TYPE_MOP:
errx(3, "`%s' is already a MOP image", argv[1]);
break;
#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 && dl.a_mid != MID_VAX1K)
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));
}