Move a bunch of the COFF definitions into exec_coff.h, so they can be used by

other code.   XXX Not tested on SH3 yet.
This commit is contained in:
mycroft 2000-06-04 16:23:59 +00:00
parent 13ba787e60
commit e9deffe0bf
5 changed files with 165 additions and 217 deletions

View File

@ -0,0 +1,45 @@
/* $NetBSD: coff_machdep.h,v 1.1 2000/06/04 16:23:59 mycroft Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Charles M. Hannum.
*
* 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 the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
#ifndef _I386_COFF_MACHDEP_H_
#define _I386_COFF_MACHDEP_H_
#define COFF_MAGIC_I386 0x14c
#define COFF_BADMAG(ex) (ex->f_magic != COFF_MAGIC_I386)
#endif /* !_I386_COFF_MACHDEP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: coff_machdep.h,v 1.2 2000/01/02 13:39:51 msaitoh Exp $ */
/* $NetBSD: coff_machdep.h,v 1.3 2000/06/04 16:24:01 mycroft Exp $ */
/*
* Copyright (c) 1994, 1995 Scott Bartram
@ -33,49 +33,10 @@
#ifndef _SH3_COFF_MACHDEP_H_
#define _SH3_COFF_MACHDEP_H_
/*
* COFF file header
*/
struct coff_filehdr {
u_short f_magic; /* magic number */
u_short f_nscns; /* # of sections */
long f_timdat; /* timestamp */
long f_symptr; /* file offset of symbol table */
long f_nsyms; /* # of symbol table entries */
u_short f_opthdr; /* size of optional header */
u_short f_flags; /* flags */
};
/* f_magic flags */
#define COFF_MAGIC_SH3_BIG 0x500
#define COFF_MAGIC_SH3_LITTLE 0x550
/* f_flags */
#define COFF_F_RELFLG 0x1
#define COFF_F_EXEC 0x2
#define COFF_F_LNNO 0x4
#define COFF_F_LSYMS 0x8
#define COFF_F_SWABD 0x40
#define COFF_F_AR16WR 0x80
#define COFF_F_AR32WR 0x100
#define COFF_F_AR32W 0x200
/*
* COFF system header
*/
struct coff_aouthdr {
short a_magic;
short a_vstamp;
long a_tsize;
long a_dsize;
long a_bsize;
long a_entry;
long a_tstart;
long a_dstart;
};
/* magic */
#define COFF_OMAGIC 0444 /* text not write-protected; data seg
is contiguous with text */
@ -85,76 +46,6 @@ struct coff_aouthdr {
direct paging */
#define COFF_SMAGIC 0443 /* shared lib */
/*
* COFF section header
*/
struct coff_scnhdr {
char s_name[8];
long s_paddr;
long s_vaddr;
long s_size;
long s_scnptr;
long s_relptr;
long s_lnnoptr;
u_short s_nreloc;
u_short s_nlnno;
long s_flags;
};
/* s_flags */
#define COFF_STYP_REG 0x00
#define COFF_STYP_DSECT 0x01
#define COFF_STYP_NOLOAD 0x02
#define COFF_STYP_GROUP 0x04
#define COFF_STYP_PAD 0x08
#define COFF_STYP_COPY 0x10
#define COFF_STYP_TEXT 0x20
#define COFF_STYP_DATA 0x40
#define COFF_STYP_BSS 0x80
#define COFF_STYP_INFO 0x200
#define COFF_STYP_OVER 0x400
#define COFF_STYP_SHLIB 0x800
/*
* COFF shared library header
*/
struct coff_slhdr {
long entry_len; /* in words */
long path_index; /* in words */
char sl_name[1];
};
struct coff_exechdr {
struct coff_filehdr f;
struct coff_aouthdr a;
};
#define COFF_ROUND(val, by) (((val) + by - 1) & ~(by - 1))
#define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))
#define COFF_HDR_SIZE \
(sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))
#define COFF_BLOCK_ALIGN(ap, value) \
((ap)->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \
value)
#define COFF_TXTOFF(fp, ap) \
((ap)->a_magic == COFF_ZMAGIC ? 0 : \
COFF_ROUND(COFF_HDR_SIZE + (fp)->f_nscns * \
sizeof(struct coff_scnhdr), \
COFF_SEGMENT_ALIGNMENT(fp, ap)))
#define COFF_DATOFF(fp, ap) \
(COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + (ap)->a_tsize))
#define COFF_SEGMENT_ALIGN(fp, ap, value) \
(COFF_ROUND(value, ((ap)->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \
COFF_SEGMENT_ALIGNMENT(fp, ap))))
#define COFF_LDPGSZ 4096
#define COFF_SEGMENT_ALIGNMENT(fp, ap) \

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_exec.c,v 1.26 2000/04/11 04:37:49 chs Exp $ */
/* $NetBSD: ibcs2_exec.c,v 1.27 2000/06/04 16:24:02 mycroft Exp $ */
/*
* Copyright (c) 1994, 1995, 1998 Scott Bartram
@ -46,6 +46,7 @@
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/exec.h>
#include <sys/exec_coff.h>
#include <sys/exec_elf.h>
#include <sys/resourcevar.h>
#ifdef IBCS2_DEBUG
@ -357,9 +358,9 @@ exec_ibcs2_coff_prep_omagic(p, epp, fp, ap)
struct coff_filehdr *fp;
struct coff_aouthdr *ap;
{
epp->ep_taddr = COFF_SEGMENT_ALIGN(ap, ap->a_tstart);
epp->ep_taddr = COFF_SEGMENT_ALIGN(fp, ap, ap->a_tstart);
epp->ep_tsize = ap->a_tsize;
epp->ep_daddr = COFF_SEGMENT_ALIGN(ap, ap->a_dstart);
epp->ep_daddr = COFF_SEGMENT_ALIGN(fp, ap, ap->a_dstart);
epp->ep_dsize = ap->a_dsize;
epp->ep_entry = ap->a_entry;
@ -372,7 +373,7 @@ exec_ibcs2_coff_prep_omagic(p, epp, fp, ap)
/* set up command for bss segment */
if (ap->a_bsize > 0)
NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, ap->a_bsize,
COFF_SEGMENT_ALIGN(ap, ap->a_dstart + ap->a_dsize),
COFF_SEGMENT_ALIGN(fp, ap, ap->a_dstart + ap->a_dsize),
NULLVP, 0,
VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
@ -391,7 +392,7 @@ exec_ibcs2_coff_prep_nmagic(p, epp, fp, ap)
struct coff_filehdr *fp;
struct coff_aouthdr *ap;
{
epp->ep_taddr = COFF_SEGMENT_ALIGN(ap, ap->a_tstart);
epp->ep_taddr = COFF_SEGMENT_ALIGN(fp, ap, ap->a_tstart);
epp->ep_tsize = ap->a_tsize;
epp->ep_daddr = COFF_ROUND(ap->a_dstart, COFF_LDPGSZ);
epp->ep_dsize = ap->a_dsize;
@ -410,7 +411,7 @@ exec_ibcs2_coff_prep_nmagic(p, epp, fp, ap)
/* set up command for bss segment */
if (ap->a_bsize > 0)
NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, ap->a_bsize,
COFF_SEGMENT_ALIGN(ap, ap->a_dstart + ap->a_dsize),
COFF_SEGMENT_ALIGN(fp, ap, ap->a_dstart + ap->a_dsize),
NULLVP, 0,
VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_exec.h,v 1.6 2000/01/10 03:14:56 matt Exp $ */
/* $NetBSD: ibcs2_exec.h,v 1.7 2000/06/04 16:24:02 mycroft Exp $ */
/*
* Copyright (c) 1994, 1995, 1998 Scott Bartram
@ -37,43 +37,9 @@
* COFF file header
*/
struct coff_filehdr {
u_short f_magic; /* magic number */
u_short f_nscns; /* # of sections */
long f_timdat; /* timestamp */
long f_symptr; /* file offset of symbol table */
long f_nsyms; /* # of symbol table entries */
u_short f_opthdr; /* size of optional header */
u_short f_flags; /* flags */
};
/* f_magic flags */
/* defined in <machine/ibcs2_machdep.h> */
/* f_flags */
#define COFF_F_RELFLG 0x1
#define COFF_F_EXEC 0x2
#define COFF_F_LNNO 0x4
#define COFF_F_LSYMS 0x8
#define COFF_F_SWABD 0x40
#define COFF_F_AR16WR 0x80
#define COFF_F_AR32WR 0x100
/*
* COFF system header
*/
struct coff_aouthdr {
short a_magic;
short a_vstamp;
long a_tsize;
long a_dsize;
long a_bsize;
long a_entry;
long a_tstart;
long a_dstart;
};
/* magic */
#define COFF_OMAGIC 0407 /* text not write-protected; data seg
is contiguous with text */
@ -83,73 +49,9 @@ struct coff_aouthdr {
direct paging */
#define COFF_SMAGIC 0443 /* shared lib */
/*
* COFF section header
*/
struct coff_scnhdr {
char s_name[8];
long s_paddr;
long s_vaddr;
long s_size;
long s_scnptr;
long s_relptr;
long s_lnnoptr;
u_short s_nreloc;
u_short s_nlnno;
long s_flags;
};
/* s_flags */
#define COFF_STYP_REG 0x00
#define COFF_STYP_DSECT 0x01
#define COFF_STYP_NOLOAD 0x02
#define COFF_STYP_GROUP 0x04
#define COFF_STYP_PAD 0x08
#define COFF_STYP_COPY 0x10
#define COFF_STYP_TEXT 0x20
#define COFF_STYP_DATA 0x40
#define COFF_STYP_BSS 0x80
#define COFF_STYP_INFO 0x200
#define COFF_STYP_OVER 0x400
#define COFF_STYP_SHLIB 0x800
/*
* COFF shared library header
*/
struct coff_slhdr {
long entry_len; /* in words */
long path_index; /* in words */
char sl_name[1];
};
#define COFF_ROUND(val, by) (((val) + by - 1) & ~(by - 1))
#define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))
#define COFF_HDR_SIZE \
(sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))
#define COFF_BLOCK_ALIGN(ap, value) \
(ap->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \
value)
#define COFF_TXTOFF(fp, ap) \
(ap->a_magic == COFF_ZMAGIC ? 0 : \
COFF_ROUND(COFF_HDR_SIZE + fp->f_nscns * \
sizeof(struct coff_scnhdr), COFF_SEGMENT_ALIGNMENT(ap)))
#define COFF_DATOFF(fp, ap) \
(COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + ap->a_tsize))
#define COFF_SEGMENT_ALIGN(ap, value) \
(COFF_ROUND(value, (ap->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \
COFF_SEGMENT_ALIGNMENT(ap))))
#define COFF_LDPGSZ 4096
#define COFF_SEGMENT_ALIGNMENT(ap) 4
#define COFF_SEGMENT_ALIGNMENT(fp, ap) 4
#define IBCS2_HIGH_SYSCALL(n) (((n) & 0x7f) == 0x28 && ((n) >> 8) > 0)
#define IBCS2_CVT_HIGH_SYSCALL(n) (((n) >> 8) + 200)

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec_coff.h,v 1.1 2000/01/02 13:39:49 msaitoh Exp $ */
/* $NetBSD: exec_coff.h,v 1.2 2000/06/04 16:24:02 mycroft Exp $ */
/*-
* Copyright (C) 2000 SAITOH Masanobu. All rights reserved.
@ -31,6 +31,115 @@
#include <machine/coff_machdep.h>
/*
* COFF file header
*/
struct coff_filehdr {
u_short f_magic; /* magic number */
u_short f_nscns; /* # of sections */
long f_timdat; /* timestamp */
long f_symptr; /* file offset of symbol table */
long f_nsyms; /* # of symbol table entries */
u_short f_opthdr; /* size of optional header */
u_short f_flags; /* flags */
};
/* f_flags */
#define COFF_F_RELFLG 0x1
#define COFF_F_EXEC 0x2
#define COFF_F_LNNO 0x4
#define COFF_F_LSYMS 0x8
#define COFF_F_SWABD 0x40
#define COFF_F_AR16WR 0x80
#define COFF_F_AR32WR 0x100
#define COFF_F_AR32W 0x200
/*
* COFF system header
*/
struct coff_aouthdr {
short a_magic;
short a_vstamp;
long a_tsize;
long a_dsize;
long a_bsize;
long a_entry;
long a_tstart;
long a_dstart;
};
/*
* COFF section header
*/
struct coff_scnhdr {
char s_name[8];
long s_paddr;
long s_vaddr;
long s_size;
long s_scnptr;
long s_relptr;
long s_lnnoptr;
u_short s_nreloc;
u_short s_nlnno;
long s_flags;
};
/* s_flags */
#define COFF_STYP_REG 0x00
#define COFF_STYP_DSECT 0x01
#define COFF_STYP_NOLOAD 0x02
#define COFF_STYP_GROUP 0x04
#define COFF_STYP_PAD 0x08
#define COFF_STYP_COPY 0x10
#define COFF_STYP_TEXT 0x20
#define COFF_STYP_DATA 0x40
#define COFF_STYP_BSS 0x80
#define COFF_STYP_INFO 0x200
#define COFF_STYP_OVER 0x400
#define COFF_STYP_SHLIB 0x800
/*
* COFF shared library header
*/
struct coff_slhdr {
long entry_len; /* in words */
long path_index; /* in words */
char sl_name[1];
};
struct coff_exechdr {
struct coff_filehdr f;
struct coff_aouthdr a;
};
#define COFF_ROUND(val, by) (((val) + by - 1) & ~(by - 1))
#define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))
#define COFF_HDR_SIZE \
(sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))
#define COFF_BLOCK_ALIGN(ap, value) \
((ap)->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \
value)
#define COFF_TXTOFF(fp, ap) \
((ap)->a_magic == COFF_ZMAGIC ? 0 : \
COFF_ROUND(COFF_HDR_SIZE + (fp)->f_nscns * \
sizeof(struct coff_scnhdr), \
COFF_SEGMENT_ALIGNMENT(fp, ap)))
#define COFF_DATOFF(fp, ap) \
(COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + (ap)->a_tsize))
#define COFF_SEGMENT_ALIGN(fp, ap, value) \
(COFF_ROUND(value, ((ap)->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \
COFF_SEGMENT_ALIGNMENT(fp, ap))))
#ifdef _KERNEL
int exec_coff_makecmds __P((struct proc *, struct exec_package *));
int exec_coff_setup_stack __P((struct proc *, struct exec_package *));