Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: exec_ecoff.h,v 1.23 2026/01/09 09:34:30 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Adam Glass
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef	_SYS_EXEC_ECOFF_H_
     31 #define	_SYS_EXEC_ECOFF_H_
     32 
     33 #include <sys/endian.h>
     34 
     35 #include <machine/ecoff_machdep.h>
     36 
     37 #ifdef ECOFF32_PAD
     38 
     39 typedef uint32_t ecoff32_addr;
     40 typedef uint32_t ecoff32_off;
     41 typedef uint32_t ecoff32_ulong;
     42 typedef int32_t ecoff32_long;
     43 typedef uint32_t ecoff32_uint;
     44 typedef int32_t ecoff32_int;
     45 typedef uint16_t ecoff32_ushort;
     46 typedef int16_t ecoff32_short;
     47 typedef uint8_t ecoff32_ubyte;
     48 typedef int8_t ecoff32_byte;
     49 
     50 struct ecoff32_filehdr {
     51 	ecoff32_ushort  f_magic;	/* magic number */
     52 	ecoff32_ushort  f_nscns;	/* # of sections */
     53 	ecoff32_uint	f_timdat;	/* time and date stamp */
     54 	ecoff32_ulong	f_symptr;	/* file offset of symbol table */
     55 	ecoff32_uint	f_nsyms;	/* # of symbol table entries */
     56 	ecoff32_ushort	f_opthdr;	/* sizeof the optional header */
     57 	ecoff32_ushort	f_flags;	/* flags??? */
     58 };
     59 
     60 struct ecoff32_aouthdr {
     61 	ecoff32_ushort	magic;
     62 	ecoff32_ushort	vstamp;
     63 	ECOFF32_PAD
     64 	ecoff32_ulong	tsize;
     65 	ecoff32_ulong	dsize;
     66 	ecoff32_ulong	bsize;
     67 	ecoff32_ulong	entry;
     68 	ecoff32_ulong	text_start;
     69 	ecoff32_ulong	data_start;
     70 	ecoff32_ulong	bss_start;
     71 	ECOFF32_MACHDEP;
     72 };
     73 
     74 struct ecoff32_scnhdr {			/* needed for size info */
     75 	char		s_name[8];	/* name */
     76 	ecoff32_ulong	s_paddr;	/* physical addr? for ROMing?*/
     77 	ecoff32_ulong	s_vaddr;	/* virtual addr? */
     78 	ecoff32_ulong	s_size;		/* size */
     79 	ecoff32_ulong	s_scnptr;	/* file offset of raw data */
     80 	ecoff32_ulong	s_relptr;	/* file offset of reloc data */
     81 	ecoff32_ulong	s_lnnoptr;	/* file offset of line data */
     82 	ecoff32_ushort	s_nreloc;	/* # of relocation entries */
     83 	ecoff32_ushort	s_nlnno;	/* # of line entries */
     84 	ecoff32_uint	s_flags;	/* flags */
     85 };
     86 
     87 struct ecoff32_exechdr {
     88 	struct ecoff32_filehdr f;
     89 	struct ecoff32_aouthdr a;
     90 };
     91 
     92 #define ECOFF32_HDR_SIZE (sizeof(struct ecoff32_exechdr))
     93 
     94 #define ECOFF32_TXTOFF(ep) \
     95         ((ep)->a.magic == ECOFF_ZMAGIC ? 0 : \
     96 	 ECOFF_ROUND(ECOFF32_HDR_SIZE + (ep)->f.f_nscns * \
     97 		     sizeof(struct ecoff32_scnhdr), ECOFF32_SEGMENT_ALIGNMENT(ep)))
     98 
     99 #define ECOFF32_DATOFF(ep) \
    100         (ECOFF_BLOCK_ALIGN((ep), ECOFF32_TXTOFF(ep) + (ep)->a.tsize))
    101 
    102 #define ECOFF32_SEGMENT_ALIGN(ep, value) \
    103         (ECOFF_ROUND((value), ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_LDPGSZ : \
    104          ECOFF32_SEGMENT_ALIGNMENT(ep))))
    105 #endif
    106 
    107 struct ecoff_filehdr {
    108 	u_short f_magic;	/* magic number */
    109 	u_short f_nscns;	/* # of sections */
    110 	u_int   f_timdat;	/* time and date stamp */
    111 	u_long  f_symptr;	/* file offset of symbol table */
    112 	u_int   f_nsyms;	/* # of symbol table entries */
    113 	u_short f_opthdr;	/* sizeof the optional header */
    114 	u_short f_flags;	/* flags??? */
    115 };
    116 
    117 struct ecoff_aouthdr {
    118 	u_short magic;
    119 	u_short vstamp;
    120 	ECOFF_PAD
    121 	u_long  tsize;
    122 	u_long  dsize;
    123 	u_long  bsize;
    124 	u_long  entry;
    125 	u_long  text_start;
    126 	u_long  data_start;
    127 	u_long  bss_start;
    128 	ECOFF_MACHDEP;
    129 };
    130 
    131 struct ecoff_scnhdr {		/* needed for size info */
    132 	char	s_name[8];	/* name */
    133 	u_long  s_paddr;	/* physical addr? for ROMing?*/
    134 	u_long  s_vaddr;	/* virtual addr? */
    135 	u_long  s_size;		/* size */
    136 	u_long  s_scnptr;	/* file offset of raw data */
    137 	u_long  s_relptr;	/* file offset of reloc data */
    138 	u_long  s_lnnoptr;	/* file offset of line data */
    139 	u_short s_nreloc;	/* # of relocation entries */
    140 	u_short s_nlnno;	/* # of line entries */
    141 	u_int   s_flags;	/* flags */
    142 };
    143 
    144 struct ecoff_exechdr {
    145 	struct ecoff_filehdr f;
    146 	struct ecoff_aouthdr a;
    147 };
    148 
    149 #define ECOFF_HDR_SIZE (sizeof(struct ecoff_exechdr))
    150 
    151 #define ECOFF_OMAGIC 0407
    152 #define ECOFF_NMAGIC 0410
    153 #define ECOFF_ZMAGIC 0413
    154 
    155 #define ECOFF_ROUND(value, by) \
    156         (((value) + (by) - 1) & ~((by) - 1))
    157 
    158 #define ECOFF_BLOCK_ALIGN(ep, value) \
    159         ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_ROUND((value), ECOFF_LDPGSZ) : \
    160 	 (value))
    161 
    162 #define ECOFF_TXTOFF(ep) \
    163         ((ep)->a.magic == ECOFF_ZMAGIC ? 0 : \
    164 	 ECOFF_ROUND(ECOFF_HDR_SIZE + (ep)->f.f_nscns * \
    165 		     sizeof(struct ecoff_scnhdr), ECOFF_SEGMENT_ALIGNMENT(ep)))
    166 
    167 #define ECOFF_DATOFF(ep) \
    168         (ECOFF_BLOCK_ALIGN((ep), ECOFF_TXTOFF(ep) + (ep)->a.tsize))
    169 
    170 #define ECOFF_SEGMENT_ALIGN(ep, value) \
    171         (ECOFF_ROUND((value), ((ep)->a.magic == ECOFF_ZMAGIC ? ECOFF_LDPGSZ : \
    172          ECOFF_SEGMENT_ALIGNMENT(ep))))
    173 
    174 #ifdef _KERNEL
    175 int	exec_ecoff_makecmds(struct lwp *, struct exec_package *);
    176 int	cpu_exec_ecoff_probe(struct lwp *, struct exec_package *);
    177 void	cpu_exec_ecoff_setregs(struct lwp *, struct exec_package *, vaddr_t);
    178 
    179 int	exec_ecoff_prep_omagic(struct lwp *, struct exec_package *,
    180 	    struct ecoff_exechdr *, struct vnode *);
    181 int	exec_ecoff_prep_nmagic(struct lwp *, struct exec_package *,
    182 	    struct ecoff_exechdr *, struct vnode *);
    183 int	exec_ecoff_prep_zmagic(struct lwp *, struct exec_package *,
    184 	    struct ecoff_exechdr *, struct vnode *);
    185 
    186 #endif /* _KERNEL */
    187 #endif /* !_SYS_EXEC_ECOFF_H_ */
    188