Home | History | Annotate | Line # | Download | only in include
coff_machdep.h revision 1.2
      1  1.1   itojun /*	$NetBSD: coff_machdep.h,v 1.2 2000/01/02 13:39:51 msaitoh Exp $	*/
      2  1.1   itojun 
      3  1.2  msaitoh /*
      4  1.2  msaitoh  * Copyright (c) 1994, 1995 Scott Bartram
      5  1.1   itojun  * All rights reserved.
      6  1.1   itojun  *
      7  1.2  msaitoh  * adapted from sys/sys/exec_ecoff.h
      8  1.2  msaitoh  * based on Intel iBCS2
      9  1.1   itojun  *
     10  1.1   itojun  * Redistribution and use in source and binary forms, with or without
     11  1.1   itojun  * modification, are permitted provided that the following conditions
     12  1.1   itojun  * are met:
     13  1.1   itojun  * 1. Redistributions of source code must retain the above copyright
     14  1.1   itojun  *    notice, this list of conditions and the following disclaimer.
     15  1.1   itojun  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1   itojun  *    notice, this list of conditions and the following disclaimer in the
     17  1.1   itojun  *    documentation and/or other materials provided with the distribution.
     18  1.2  msaitoh  * 3. The name of the author may not be used to endorse or promote products
     19  1.2  msaitoh  *    derived from this software without specific prior written permission
     20  1.1   itojun  *
     21  1.2  msaitoh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.2  msaitoh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.2  msaitoh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.2  msaitoh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.2  msaitoh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.2  msaitoh  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.2  msaitoh  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.2  msaitoh  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.2  msaitoh  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.2  msaitoh  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1   itojun  */
     32  1.1   itojun 
     33  1.2  msaitoh #ifndef _SH3_COFF_MACHDEP_H_
     34  1.2  msaitoh #define _SH3_COFF_MACHDEP_H_
     35  1.1   itojun 
     36  1.2  msaitoh /*
     37  1.2  msaitoh  * COFF file header
     38  1.2  msaitoh  */
     39  1.2  msaitoh 
     40  1.2  msaitoh struct coff_filehdr {
     41  1.2  msaitoh 	u_short	f_magic;	/* magic number */
     42  1.2  msaitoh 	u_short	f_nscns;	/* # of sections */
     43  1.2  msaitoh 	long	f_timdat;	/* timestamp */
     44  1.2  msaitoh 	long	f_symptr;	/* file offset of symbol table */
     45  1.2  msaitoh 	long	f_nsyms;	/* # of symbol table entries */
     46  1.2  msaitoh 	u_short	f_opthdr;	/* size of optional header */
     47  1.2  msaitoh 	u_short	f_flags;	/* flags */
     48  1.2  msaitoh };
     49  1.2  msaitoh 
     50  1.2  msaitoh /* f_magic flags */
     51  1.2  msaitoh #define COFF_MAGIC_SH3_BIG	0x500
     52  1.2  msaitoh #define COFF_MAGIC_SH3_LITTLE	0x550
     53  1.2  msaitoh 
     54  1.2  msaitoh /* f_flags */
     55  1.2  msaitoh #define COFF_F_RELFLG	0x1
     56  1.2  msaitoh #define COFF_F_EXEC	0x2
     57  1.2  msaitoh #define COFF_F_LNNO	0x4
     58  1.2  msaitoh #define COFF_F_LSYMS	0x8
     59  1.2  msaitoh #define COFF_F_SWABD	0x40
     60  1.2  msaitoh #define COFF_F_AR16WR	0x80
     61  1.2  msaitoh #define COFF_F_AR32WR	0x100
     62  1.2  msaitoh #define COFF_F_AR32W	0x200
     63  1.2  msaitoh 
     64  1.2  msaitoh /*
     65  1.2  msaitoh  * COFF system header
     66  1.2  msaitoh  */
     67  1.2  msaitoh 
     68  1.2  msaitoh struct coff_aouthdr {
     69  1.2  msaitoh 	short	a_magic;
     70  1.2  msaitoh 	short	a_vstamp;
     71  1.2  msaitoh 	long	a_tsize;
     72  1.2  msaitoh 	long	a_dsize;
     73  1.2  msaitoh 	long	a_bsize;
     74  1.2  msaitoh 	long	a_entry;
     75  1.2  msaitoh 	long	a_tstart;
     76  1.2  msaitoh 	long	a_dstart;
     77  1.2  msaitoh };
     78  1.2  msaitoh 
     79  1.2  msaitoh /* magic */
     80  1.2  msaitoh #define COFF_OMAGIC	0444	/* text not write-protected; data seg
     81  1.2  msaitoh 				   is contiguous with text */
     82  1.2  msaitoh #define COFF_NMAGIC	0410	/* text is write-protected; data starts
     83  1.2  msaitoh 				   at next seg following text */
     84  1.2  msaitoh #define COFF_ZMAGIC	0000	/* text and data segs are aligned for
     85  1.2  msaitoh 				   direct paging */
     86  1.2  msaitoh #define COFF_SMAGIC	0443	/* shared lib */
     87  1.2  msaitoh 
     88  1.2  msaitoh /*
     89  1.2  msaitoh  * COFF section header
     90  1.2  msaitoh  */
     91  1.2  msaitoh 
     92  1.2  msaitoh struct coff_scnhdr {
     93  1.2  msaitoh 	char	s_name[8];
     94  1.2  msaitoh 	long	s_paddr;
     95  1.2  msaitoh 	long	s_vaddr;
     96  1.2  msaitoh 	long	s_size;
     97  1.2  msaitoh 	long	s_scnptr;
     98  1.2  msaitoh 	long	s_relptr;
     99  1.2  msaitoh 	long	s_lnnoptr;
    100  1.2  msaitoh 	u_short	s_nreloc;
    101  1.2  msaitoh 	u_short	s_nlnno;
    102  1.2  msaitoh 	long	s_flags;
    103  1.2  msaitoh };
    104  1.2  msaitoh 
    105  1.2  msaitoh /* s_flags */
    106  1.2  msaitoh #define COFF_STYP_REG		0x00
    107  1.2  msaitoh #define COFF_STYP_DSECT		0x01
    108  1.2  msaitoh #define COFF_STYP_NOLOAD	0x02
    109  1.2  msaitoh #define COFF_STYP_GROUP		0x04
    110  1.2  msaitoh #define COFF_STYP_PAD		0x08
    111  1.2  msaitoh #define COFF_STYP_COPY		0x10
    112  1.2  msaitoh #define COFF_STYP_TEXT		0x20
    113  1.2  msaitoh #define COFF_STYP_DATA		0x40
    114  1.2  msaitoh #define COFF_STYP_BSS		0x80
    115  1.2  msaitoh #define COFF_STYP_INFO		0x200
    116  1.2  msaitoh #define COFF_STYP_OVER		0x400
    117  1.2  msaitoh #define COFF_STYP_SHLIB		0x800
    118  1.2  msaitoh 
    119  1.2  msaitoh /*
    120  1.2  msaitoh  * COFF shared library header
    121  1.2  msaitoh  */
    122  1.2  msaitoh 
    123  1.2  msaitoh struct coff_slhdr {
    124  1.2  msaitoh 	long	entry_len;	/* in words */
    125  1.2  msaitoh 	long	path_index;	/* in words */
    126  1.2  msaitoh 	char	sl_name[1];
    127  1.2  msaitoh };
    128  1.2  msaitoh 
    129  1.2  msaitoh struct coff_exechdr {
    130  1.2  msaitoh 	struct coff_filehdr f;
    131  1.2  msaitoh 	struct coff_aouthdr a;
    132  1.2  msaitoh };
    133  1.2  msaitoh 
    134  1.2  msaitoh #define COFF_ROUND(val, by)     (((val) + by - 1) & ~(by - 1))
    135  1.2  msaitoh 
    136  1.2  msaitoh #define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))
    137  1.2  msaitoh 
    138  1.2  msaitoh #define COFF_HDR_SIZE \
    139  1.2  msaitoh 	(sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))
    140  1.2  msaitoh 
    141  1.2  msaitoh #define COFF_BLOCK_ALIGN(ap, value) \
    142  1.2  msaitoh         ((ap)->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \
    143  1.2  msaitoh          value)
    144  1.2  msaitoh 
    145  1.2  msaitoh #define COFF_TXTOFF(fp, ap) \
    146  1.2  msaitoh         ((ap)->a_magic == COFF_ZMAGIC ? 0 : \
    147  1.2  msaitoh          COFF_ROUND(COFF_HDR_SIZE + (fp)->f_nscns * \
    148  1.2  msaitoh 		    sizeof(struct coff_scnhdr), \
    149  1.2  msaitoh 		    COFF_SEGMENT_ALIGNMENT(fp, ap)))
    150  1.2  msaitoh 
    151  1.2  msaitoh #define COFF_DATOFF(fp, ap) \
    152  1.2  msaitoh         (COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + (ap)->a_tsize))
    153  1.2  msaitoh 
    154  1.2  msaitoh #define COFF_SEGMENT_ALIGN(fp, ap, value) \
    155  1.2  msaitoh         (COFF_ROUND(value, ((ap)->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \
    156  1.2  msaitoh          COFF_SEGMENT_ALIGNMENT(fp, ap))))
    157  1.2  msaitoh 
    158  1.2  msaitoh #define COFF_LDPGSZ 4096
    159  1.2  msaitoh 
    160  1.2  msaitoh #define COFF_SEGMENT_ALIGNMENT(fp, ap) \
    161  1.2  msaitoh     (((fp)->f_flags & COFF_F_EXEC) == 0 ? 4 : 16)
    162  1.2  msaitoh 
    163  1.2  msaitoh #ifndef BYTE_ORDER
    164  1.2  msaitoh #error Define BYTE_ORDER!
    165  1.1   itojun #endif
    166  1.1   itojun 
    167  1.2  msaitoh #if BYTE_ORDER == BIG_ENDIAN
    168  1.2  msaitoh #define COFF_BADMAG(ex) ((ex)->f_magic != COFF_MAGIC_SH3_BIG)
    169  1.2  msaitoh #endif
    170  1.2  msaitoh #if BYTE_ORDER == LITTLE_ENDIAN
    171  1.2  msaitoh #define COFF_BADMAG(ex) ((ex)->f_magic != COFF_MAGIC_SH3_LITTLE)
    172  1.2  msaitoh #endif
    173  1.2  msaitoh 
    174  1.2  msaitoh #define IBCS2_HIGH_SYSCALL(n)		(((n) & 0x7f) == 0x28)
    175  1.2  msaitoh #define IBCS2_CVT_HIGH_SYSCALL(n)	(((n) >> 8) + 128)
    176  1.2  msaitoh 
    177  1.2  msaitoh #ifdef DEBUG_COFF
    178  1.2  msaitoh #define DPRINTF(a)      printf a;
    179  1.2  msaitoh #else
    180  1.2  msaitoh #define DPRINTF(a)
    181  1.2  msaitoh #endif
    182  1.2  msaitoh 
    183  1.2  msaitoh #define COFF_ES_SYMNMLEN	8
    184  1.2  msaitoh #define COFF_ES_SYMENTSZ	18
    185  1.2  msaitoh 
    186  1.2  msaitoh struct external_syment {
    187  1.2  msaitoh 	union {
    188  1.2  msaitoh 		char e_name[COFF_ES_SYMNMLEN];
    189  1.2  msaitoh 		struct {
    190  1.2  msaitoh 			char e_zeroes[4];
    191  1.2  msaitoh 			char e_offset[4];
    192  1.2  msaitoh 		} e;
    193  1.2  msaitoh 	} e;
    194  1.2  msaitoh 	char e_value[4];
    195  1.2  msaitoh 	char e_scnum[2];
    196  1.2  msaitoh 	char e_type[2];
    197  1.2  msaitoh 	char e_sclass[1];
    198  1.2  msaitoh 	char e_numaux[1];
    199  1.2  msaitoh };
    200  1.2  msaitoh 
    201  1.2  msaitoh #endif /* !_SH3_COFF_MACHDEP_H_ */
    202  1.1   itojun 
    203