Home | History | Annotate | Line # | Download | only in libtos
exec_elf.h revision 1.1
      1  1.1  leo /*	$NetBSD: exec_elf.h,v 1.1 2001/10/10 14:19:51 leo Exp $	*/
      2  1.1  leo 
      3  1.1  leo /*-
      4  1.1  leo  * Copyright (c) 1994 The NetBSD Foundation, Inc.
      5  1.1  leo  * All rights reserved.
      6  1.1  leo  *
      7  1.1  leo  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  leo  * by Christos Zoulas.
      9  1.1  leo  *
     10  1.1  leo  * Redistribution and use in source and binary forms, with or without
     11  1.1  leo  * modification, are permitted provided that the following conditions
     12  1.1  leo  * are met:
     13  1.1  leo  * 1. Redistributions of source code must retain the above copyright
     14  1.1  leo  *    notice, this list of conditions and the following disclaimer.
     15  1.1  leo  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  leo  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  leo  *    documentation and/or other materials provided with the distribution.
     18  1.1  leo  * 3. All advertising materials mentioning features or use of this software
     19  1.1  leo  *    must display the following acknowledgement:
     20  1.1  leo  *	This product includes software developed by the NetBSD
     21  1.1  leo  *	Foundation, Inc. and its contributors.
     22  1.1  leo  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  leo  *    contributors may be used to endorse or promote products derived
     24  1.1  leo  *    from this software without specific prior written permission.
     25  1.1  leo  *
     26  1.1  leo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  leo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  leo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  leo  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  leo  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  leo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  leo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  leo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  leo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  leo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  leo  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  leo  */
     38  1.1  leo 
     39  1.1  leo #ifndef _SYS_EXEC_ELF_H_
     40  1.1  leo #define	_SYS_EXEC_ELF_H_
     41  1.1  leo 
     42  1.1  leo /*
     43  1.1  leo  * The current ELF ABI specification is available at:
     44  1.1  leo  *	http://www.sco.com/developer/gabi/
     45  1.1  leo  *
     46  1.1  leo  * Current header definitions are in:
     47  1.1  leo  *	http://www.sco.com/developer/gabi/latest/ch4.eheader.html
     48  1.1  leo  */
     49  1.1  leo 
     50  1.1  leo /*
     51  1.1  leo  * Leo 10/10/2001:
     52  1.1  leo  *   This is a copy of the file in sys/sys, but modified a bit to
     53  1.1  leo  *   be used in a TOS/MiNT environment. I will probably trim it down
     54  1.1  leo  *   in the near future. It is only used for loading kernels.
     55  1.1  leo  */
     56  1.1  leo #ifdef TOSTOOLS
     57  1.1  leo typedef	signed char		 __int8_t;
     58  1.1  leo typedef	unsigned char		__uint8_t;
     59  1.1  leo typedef	short int		__int16_t;
     60  1.1  leo typedef	unsigned short int     __uint16_t;
     61  1.1  leo typedef	int			__int32_t;
     62  1.1  leo typedef	unsigned int	       __uint32_t;
     63  1.1  leo typedef	long long int		__int64_t;
     64  1.1  leo typedef	unsigned long long int __uint64_t;
     65  1.1  leo #else
     66  1.1  leo #include <machine/int_types.h>
     67  1.1  leo #endif /* TOSTOOLS */
     68  1.1  leo 
     69  1.1  leo typedef	__uint8_t  	Elf_Byte;
     70  1.1  leo 
     71  1.1  leo typedef	__uint32_t	Elf32_Addr;
     72  1.1  leo #define	ELF32_FSZ_ADDR	4
     73  1.1  leo typedef	__uint32_t Elf32_Off;
     74  1.1  leo #define	ELF32_FSZ_OFF	4
     75  1.1  leo typedef	__int32_t   Elf32_Sword;
     76  1.1  leo #define	ELF32_FSZ_SWORD	4
     77  1.1  leo typedef	__uint32_t Elf32_Word;
     78  1.1  leo #define	ELF32_FSZ_WORD	4
     79  1.1  leo typedef	__uint16_t Elf32_Half;
     80  1.1  leo #define	ELF32_FSZ_HALF	2
     81  1.1  leo 
     82  1.1  leo typedef	__uint64_t	Elf64_Addr;
     83  1.1  leo #define	ELF64_FSZ_ADDR	8
     84  1.1  leo typedef	__uint64_t	Elf64_Off;
     85  1.1  leo #define	ELF64_FSZ_OFF	8
     86  1.1  leo typedef	__int32_t	Elf64_Shalf;
     87  1.1  leo #define	ELF64_FSZ_SHALF	4
     88  1.1  leo 
     89  1.1  leo #ifdef __alpha__
     90  1.1  leo typedef	__int64_t	Elf64_Sword;
     91  1.1  leo #define	ELF64_FSZ_SWORD	8
     92  1.1  leo typedef	__uint64_t	Elf64_Word;
     93  1.1  leo #define	ELF64_FSZ_WORD	8
     94  1.1  leo #else
     95  1.1  leo typedef	__int32_t	Elf64_Sword;
     96  1.1  leo #define	ELF64_FSZ_SWORD	4
     97  1.1  leo typedef	__uint32_t	Elf64_Word;
     98  1.1  leo #define	ELF64_FSZ_WORD	4
     99  1.1  leo #endif /* __alpha__ */
    100  1.1  leo 
    101  1.1  leo typedef	__int64_t	Elf64_Sxword;
    102  1.1  leo #define	ELF64_FSZ_XWORD	8
    103  1.1  leo typedef	__uint64_t	Elf64_Xword;
    104  1.1  leo #define	ELF64_FSZ_XWORD	8
    105  1.1  leo typedef	__uint32_t	Elf64_Half;
    106  1.1  leo #define	ELF64_FSZ_HALF	4
    107  1.1  leo typedef	__uint16_t	Elf64_Quarter;
    108  1.1  leo #define	ELF64_FSZ_QUARTER 2
    109  1.1  leo 
    110  1.1  leo /*
    111  1.1  leo  * ELF Header
    112  1.1  leo  */
    113  1.1  leo #define	ELF_NIDENT	16
    114  1.1  leo 
    115  1.1  leo typedef struct {
    116  1.1  leo 	unsigned char	e_ident[ELF_NIDENT];	/* Id bytes */
    117  1.1  leo 	Elf32_Half	e_type;			/* file type */
    118  1.1  leo 	Elf32_Half	e_machine;		/* machine type */
    119  1.1  leo 	Elf32_Word	e_version;		/* version number */
    120  1.1  leo 	Elf32_Addr	e_entry;		/* entry point */
    121  1.1  leo 	Elf32_Off	e_phoff;		/* Program hdr offset */
    122  1.1  leo 	Elf32_Off	e_shoff;		/* Section hdr offset */
    123  1.1  leo 	Elf32_Word	e_flags;		/* Processor flags */
    124  1.1  leo 	Elf32_Half      e_ehsize;		/* sizeof ehdr */
    125  1.1  leo 	Elf32_Half      e_phentsize;		/* Program header entry size */
    126  1.1  leo 	Elf32_Half      e_phnum;		/* Number of program headers */
    127  1.1  leo 	Elf32_Half      e_shentsize;		/* Section header entry size */
    128  1.1  leo 	Elf32_Half      e_shnum;		/* Number of section headers */
    129  1.1  leo 	Elf32_Half      e_shstrndx;		/* String table index */
    130  1.1  leo } Elf32_Ehdr;
    131  1.1  leo 
    132  1.1  leo /* e_ident offsets */
    133  1.1  leo #define	EI_MAG0		0	/* '\177' */
    134  1.1  leo #define	EI_MAG1		1	/* 'E'    */
    135  1.1  leo #define	EI_MAG2		2	/* 'L'    */
    136  1.1  leo #define	EI_MAG3		3	/* 'F'    */
    137  1.1  leo #define	EI_CLASS	4	/* File class */
    138  1.1  leo #define	EI_DATA		5	/* Data encoding */
    139  1.1  leo #define	EI_VERSION	6	/* File version */
    140  1.1  leo #define	EI_OSABI	7	/* Operating system/ABI identification */
    141  1.1  leo #define	EI_ABIVERSION	8	/* ABI version */
    142  1.1  leo #define	EI_PAD		9	/* Start of padding bytes up to EI_NIDENT*/
    143  1.1  leo 
    144  1.1  leo /* e_ident[ELFMAG0,ELFMAG3] */
    145  1.1  leo #define	ELFMAG0		0x7f
    146  1.1  leo #define	ELFMAG1		'E'
    147  1.1  leo #define	ELFMAG2		'L'
    148  1.1  leo #define	ELFMAG3		'F'
    149  1.1  leo #define	ELFMAG		"\177ELF"
    150  1.1  leo #define	SELFMAG		4
    151  1.1  leo 
    152  1.1  leo /* e_ident[EI_CLASS] */
    153  1.1  leo #define	ELFCLASSNONE	0	/* Invalid class */
    154  1.1  leo #define	ELFCLASS32	1	/* 32-bit objects */
    155  1.1  leo #define	ELFCLASS64	2	/* 64-bit objects */
    156  1.1  leo #define	ELFCLASSNUM	3
    157  1.1  leo 
    158  1.1  leo /* e_ident[EI_DATA] */
    159  1.1  leo #define	ELFDATANONE	0	/* Invalid data encoding */
    160  1.1  leo #define	ELFDATA2LSB	1	/* 2's complement values, LSB first */
    161  1.1  leo #define	ELFDATA2MSB	2	/* 2's complement values, MSB first */
    162  1.1  leo 
    163  1.1  leo /* e_ident[EI_VERSION] */
    164  1.1  leo #define	EV_NONE		0	/* Invalid version */
    165  1.1  leo #define	EV_CURRENT	1	/* Current version */
    166  1.1  leo #define	EV_NUM		2
    167  1.1  leo 
    168  1.1  leo /* e_ident[EI_OSABI] */
    169  1.1  leo #define	ELFOSABI_SYSV		0	/* UNIX System V ABI */
    170  1.1  leo #define	ELFOSABI_HPUX		1	/* HP-UX operating system */
    171  1.1  leo #define ELFOSABI_NETBSD		2	/* NetBSD */
    172  1.1  leo #define ELFOSABI_LINUX		3	/* GNU/Linux */
    173  1.1  leo #define ELFOSABI_HURD		4	/* GNU/Hurd */
    174  1.1  leo #define ELFOSABI_86OPEN		5	/* 86Open */
    175  1.1  leo #define ELFOSABI_SOLARIS	6	/* Solaris */
    176  1.1  leo #define ELFOSABI_MONTEREY	7	/* Monterey */
    177  1.1  leo #define ELFOSABI_IRIX		8	/* IRIX */
    178  1.1  leo #define ELFOSABI_FREEBSD	9	/* FreeBSD */
    179  1.1  leo #define ELFOSABI_TRU64		10	/* TRU64 UNIX */
    180  1.1  leo #define ELFOSABI_MODESTO	11	/* Novell Modesto */
    181  1.1  leo #define ELFOSABI_OPENBSD	12	/* OpenBSD */
    182  1.1  leo /* Unofficial OSABIs follow */
    183  1.1  leo #define ELFOSABI_ARM		97	/* ARM */
    184  1.1  leo #define	ELFOSABI_STANDALONE	255	/* Standalone (embedded) application */
    185  1.1  leo 
    186  1.1  leo /* e_type */
    187  1.1  leo #define	ET_NONE		0	/* No file type */
    188  1.1  leo #define	ET_REL		1	/* Relocatable file */
    189  1.1  leo #define	ET_EXEC		2	/* Executable file */
    190  1.1  leo #define	ET_DYN		3	/* Shared object file */
    191  1.1  leo #define	ET_CORE		4	/* Core file */
    192  1.1  leo #define	ET_NUM		5
    193  1.1  leo 
    194  1.1  leo #define	ET_LOOS		0xfe00	/* Operating system specific range */
    195  1.1  leo #define	ET_HIOS		0xfeff
    196  1.1  leo #define	ET_LOPROC	0xff00	/* Processor-specific range */
    197  1.1  leo #define	ET_HIPROC	0xffff
    198  1.1  leo 
    199  1.1  leo /* e_machine */
    200  1.1  leo #define	EM_NONE		0	/* No machine */
    201  1.1  leo #define	EM_M32		1	/* AT&T WE 32100 */
    202  1.1  leo #define	EM_SPARC	2	/* SPARC */
    203  1.1  leo #define	EM_386		3	/* Intel 80386 */
    204  1.1  leo #define	EM_68K		4	/* Motorola 68000 */
    205  1.1  leo #define	EM_88K		5	/* Motorola 88000 */
    206  1.1  leo #define	EM_486		6	/* Intel 80486 */
    207  1.1  leo #define	EM_860		7	/* Intel 80860 */
    208  1.1  leo #define	EM_MIPS		8	/* MIPS I Architecture */
    209  1.1  leo #define	EM_S370		9	/* Amdahl UTS on System/370 */
    210  1.1  leo #define	EM_MIPS_RS3_LE	10	/* MIPS RS3000 Little-endian */
    211  1.1  leo 			/* 11-14 - Reserved */
    212  1.1  leo #define	EM_RS6000	11	/* IBM RS/6000 XXX reserved */
    213  1.1  leo #define	EM_PARISC	15	/* Hewlett-Packard PA-RISC */
    214  1.1  leo #define	EM_NCUBE	16	/* NCube XXX reserved */
    215  1.1  leo #define	EM_VPP500	17	/* Fujitsu VPP500 */
    216  1.1  leo #define	EM_SPARC32PLUS	18	/* Enhanced instruction set SPARC */
    217  1.1  leo #define	EM_960		19	/* Intel 80960 */
    218  1.1  leo #define	EM_PPC		20	/* PowerPC */
    219  1.1  leo #define	EM_PPC64	21	/* 64-bit PowerPC */
    220  1.1  leo 			/* 22-35 - Reserved */
    221  1.1  leo #define	EM_V800		36	/* NEC V800 */
    222  1.1  leo #define	EM_FR20		37	/* Fujitsu FR20 */
    223  1.1  leo #define	EM_RH32		38	/* TRW RH-32 */
    224  1.1  leo #define	EM_RCE		39	/* Motorola RCE */
    225  1.1  leo #define	EM_ARM		40	/* Advanced RISC Machines ARM */
    226  1.1  leo #define	EM_ALPHA	41	/* DIGITAL Alpha */
    227  1.1  leo #define	EM_SH		42	/* Hitachi Super-H */
    228  1.1  leo #define	EM_SPARCV9	43	/* SPARC Version 9 */
    229  1.1  leo #define	EM_TRICORE	44	/* Siemens Tricore */
    230  1.1  leo #define	EM_ARC		45	/* Argonaut RISC Core */
    231  1.1  leo #define	EM_H8_300	46	/* Hitachi H8/300 */
    232  1.1  leo #define	EM_H8_300H	47	/* Hitachi H8/300H */
    233  1.1  leo #define	EM_H8S		48	/* Hitachi H8S */
    234  1.1  leo #define	EM_H8_500	49	/* Hitachi H8/500 */
    235  1.1  leo #define	EM_IA_64	50	/* Intel Merced Processor */
    236  1.1  leo #define	EM_MIPS_X	51	/* Stanford MIPS-X */
    237  1.1  leo #define	EM_COLDFIRE	52	/* Motorola Coldfire */
    238  1.1  leo #define	EM_68HC12	53	/* Motorola MC68HC12 */
    239  1.1  leo #define	EM_MMA		54	/* Fujitsu MMA Multimedia Accelerator */
    240  1.1  leo #define	EM_PCP		55	/* Siemens PCP */
    241  1.1  leo #define	EM_NCPU		56	/* Sony nCPU embedded RISC processor */
    242  1.1  leo #define	EM_NDR1		57	/* Denso NDR1 microprocessor */
    243  1.1  leo #define	EM_STARCORE	58	/* Motorola Star*Core processor */
    244  1.1  leo #define	EM_ME16		59	/* Toyota ME16 processor */
    245  1.1  leo #define	EM_ST100	60	/* STMicroelectronics ST100 processor */
    246  1.1  leo #define	EM_TINYJ	61	/* Advanced Logic Corp. TinyJ embedded family processor */
    247  1.1  leo #define	EM_X86_64	62	/* AMD x86-64 architecture */
    248  1.1  leo #define	EM_PDSP		63	/* Sony DSP Processor */
    249  1.1  leo 			/* 64-65 - Reserved */
    250  1.1  leo #define	EM_FX66		66	/* Siemens FX66 microcontroller */
    251  1.1  leo #define	EM_ST9PLUS	67	/* STMicroelectronics ST9+ 8/16 bit microcontroller */
    252  1.1  leo #define	EM_ST7		68	/* STMicroelectronics ST7 8-bit microcontroller */
    253  1.1  leo #define	EM_68HC16	69	/* Motorola MC68HC16 Microcontroller */
    254  1.1  leo #define	EM_68HC11	70	/* Motorola MC68HC11 Microcontroller */
    255  1.1  leo #define	EM_68HC08	71	/* Motorola MC68HC08 Microcontroller */
    256  1.1  leo #define	EM_68HC05	72	/* Motorola MC68HC05 Microcontroller */
    257  1.1  leo #define	EM_SVX		73	/* Silicon Graphics SVx */
    258  1.1  leo #define	EM_ST19		74	/* STMicroelectronics ST19 8-bit cpu */
    259  1.1  leo #define	EM_VAX		75	/* Digital VAX */
    260  1.1  leo #define	EM_CRIS		76	/* Axis Communications 32-bit embedded processor */
    261  1.1  leo #define	EM_JAVELIN	77	/* Infineon Technologies 32-bit embedded cpu */
    262  1.1  leo #define	EM_FIREPATH	78	/* Element 14 64-bit DSP processor */
    263  1.1  leo #define	EM_ZSP		79	/* LSI Logic's 16-bit DSP processor */
    264  1.1  leo #define	EM_MMIX		80	/* Donald Knuth's educational 64-bit processor */
    265  1.1  leo #define	EM_HUANY	81	/* Harvard's machine-independent format */
    266  1.1  leo #define	EM_PRISM	82	/* SiTera Prism */
    267  1.1  leo #define	EM_AVR		83	/* Atmel AVR 8-bit microcontroller */
    268  1.1  leo #define	EM_FR30		84	/* Fujitsu FR30 */
    269  1.1  leo #define	EM_D10V		85	/* Mitsubishi D10V */
    270  1.1  leo #define	EM_D30V		86	/* Mitsubishi D30V */
    271  1.1  leo #define	EM_V850		87	/* NEC v850 */
    272  1.1  leo #define	EM_M32R		88	/* Mitsubishi M32R */
    273  1.1  leo #define	EM_MN10300	89	/* Matsushita MN10300 */
    274  1.1  leo #define	EM_MN10200	90	/* Matsushita MN10200 */
    275  1.1  leo #define	EM_PJ		91	/* picoJava */
    276  1.1  leo #define	EM_OPENRISC	92	/* OpenRISC 32-bit embedded processor */
    277  1.1  leo #define	EM_ARC_A5	93	/* ARC Cores Tangent-A5 */
    278  1.1  leo #define	EM_XTENSA	94	/* Tensilica Xtensa Architecture */
    279  1.1  leo /* Unofficial machine types follow */
    280  1.1  leo #define	EM_ALPHA_EXP	36902	/* used by NetBSD/alpha; obsolete */
    281  1.1  leo #define	EM_NUM		36903
    282  1.1  leo 
    283  1.1  leo /*
    284  1.1  leo  * Program Header
    285  1.1  leo  */
    286  1.1  leo typedef struct {
    287  1.1  leo 	Elf32_Word	p_type;		/* entry type */
    288  1.1  leo 	Elf32_Off	p_offset;	/* offset */
    289  1.1  leo 	Elf32_Addr	p_vaddr;	/* virtual address */
    290  1.1  leo 	Elf32_Addr	p_paddr;	/* physical address */
    291  1.1  leo 	Elf32_Word	p_filesz;	/* file size */
    292  1.1  leo 	Elf32_Word	p_memsz;	/* memory size */
    293  1.1  leo 	Elf32_Word	p_flags;	/* flags */
    294  1.1  leo 	Elf32_Word	p_align;	/* memory & file alignment */
    295  1.1  leo } Elf32_Phdr;
    296  1.1  leo 
    297  1.1  leo /* p_type */
    298  1.1  leo #define	PT_NULL		0		/* Program header table entry unused */
    299  1.1  leo #define	PT_LOAD		1		/* Loadable program segment */
    300  1.1  leo #define	PT_DYNAMIC	2		/* Dynamic linking information */
    301  1.1  leo #define	PT_INTERP	3		/* Program interpreter */
    302  1.1  leo #define	PT_NOTE		4		/* Auxiliary information */
    303  1.1  leo #define	PT_SHLIB	5		/* Reserved, unspecified semantics */
    304  1.1  leo #define	PT_PHDR		6		/* Entry for header table itself */
    305  1.1  leo #define	PT_NUM		7
    306  1.1  leo 
    307  1.1  leo /* p_flags */
    308  1.1  leo #define	PF_R		0x4	/* Segment is readable */
    309  1.1  leo #define	PF_W		0x2	/* Segment is writable */
    310  1.1  leo #define	PF_X		0x1	/* Segment is executable */
    311  1.1  leo 
    312  1.1  leo #define	PF_MASKOS	0x0ff00000	/* Opersting system specific values */
    313  1.1  leo #define	PF_MASKPROC	0xf0000000	/* Processor-specific values */
    314  1.1  leo 
    315  1.1  leo #define	PT_LOPROC	0x70000000	/* Processor-specific range */
    316  1.1  leo #define	PT_HIPROC	0x7fffffff
    317  1.1  leo 
    318  1.1  leo #define	PT_MIPS_REGINFO	0x70000000
    319  1.1  leo 
    320  1.1  leo /*
    321  1.1  leo  * Section Headers
    322  1.1  leo  */
    323  1.1  leo typedef struct {
    324  1.1  leo 	Elf32_Word	sh_name;	/* section name (.shstrtab index) */
    325  1.1  leo 	Elf32_Word	sh_type;	/* section type */
    326  1.1  leo 	Elf32_Word	sh_flags;	/* section flags */
    327  1.1  leo 	Elf32_Addr	sh_addr;	/* virtual address */
    328  1.1  leo 	Elf32_Off	sh_offset;	/* file offset */
    329  1.1  leo 	Elf32_Word	sh_size;	/* section size */
    330  1.1  leo 	Elf32_Word	sh_link;	/* link to another */
    331  1.1  leo 	Elf32_Word	sh_info;	/* misc info */
    332  1.1  leo 	Elf32_Word	sh_addralign;	/* memory alignment */
    333  1.1  leo 	Elf32_Word	sh_entsize;	/* table entry size */
    334  1.1  leo } Elf32_Shdr;
    335  1.1  leo 
    336  1.1  leo /* sh_type */
    337  1.1  leo #define	SHT_NULL	0		/* Section header table entry unused */
    338  1.1  leo #define	SHT_PROGBITS	1		/* Program information */
    339  1.1  leo #define	SHT_SYMTAB	2		/* Symbol table */
    340  1.1  leo #define	SHT_STRTAB	3		/* String table */
    341  1.1  leo #define	SHT_RELA	4		/* Relocation information w/ addend */
    342  1.1  leo #define	SHT_HASH	5		/* Symbol hash table */
    343  1.1  leo #define	SHT_DYNAMIC	6		/* Dynamic linking information */
    344  1.1  leo #define	SHT_NOTE	7		/* Auxiliary information */
    345  1.1  leo #define	SHT_NOBITS	8		/* No space allocated in file image */
    346  1.1  leo #define	SHT_REL		9		/* Relocation information w/o addend */
    347  1.1  leo #define	SHT_SHLIB	10		/* Reserved, unspecified semantics */
    348  1.1  leo #define	SHT_DYNSYM	11		/* Symbol table for dynamic linker */
    349  1.1  leo #define	SHT_NUM		12
    350  1.1  leo 
    351  1.1  leo #define	SHT_LOOS	0x60000000	/* Operating system specific range */
    352  1.1  leo #define	SHT_HIOS	0x6fffffff
    353  1.1  leo #define	SHT_LOPROC	0x70000000	/* Processor-specific range */
    354  1.1  leo #define	SHT_HIPROC	0x7fffffff
    355  1.1  leo #define	SHT_LOUSER	0x80000000	/* Application-specific range */
    356  1.1  leo #define	SHT_HIUSER	0xffffffff
    357  1.1  leo 
    358  1.1  leo /* sh_flags */
    359  1.1  leo #define	SHF_WRITE	0x1		/* Section contains writable data */
    360  1.1  leo #define	SHF_ALLOC	0x2		/* Section occupies memory */
    361  1.1  leo #define	SHF_EXECINSTR	0x4		/* Section contains executable insns */
    362  1.1  leo 
    363  1.1  leo #define	SHF_MASKOS	0x0f000000	/* Operating system specific values */
    364  1.1  leo #define	SHF_MASKPROC	0xf0000000	/* Processor-specific values */
    365  1.1  leo 
    366  1.1  leo /*
    367  1.1  leo  * Symbol Table
    368  1.1  leo  */
    369  1.1  leo typedef struct {
    370  1.1  leo 	Elf32_Word	st_name;	/* Symbol name (.symtab index) */
    371  1.1  leo 	Elf32_Word	st_value;	/* value of symbol */
    372  1.1  leo 	Elf32_Word	st_size;	/* size of symbol */
    373  1.1  leo 	Elf_Byte	st_info;	/* type / binding attrs */
    374  1.1  leo 	Elf_Byte	st_other;	/* unused */
    375  1.1  leo 	Elf32_Half	st_shndx;	/* section index of symbol */
    376  1.1  leo } Elf32_Sym;
    377  1.1  leo 
    378  1.1  leo /* Symbol Table index of the undefined symbol */
    379  1.1  leo #define	ELF_SYM_UNDEFINED	0
    380  1.1  leo 
    381  1.1  leo /* st_info: Symbol Bindings */
    382  1.1  leo #define	STB_LOCAL		0	/* local symbol */
    383  1.1  leo #define	STB_GLOBAL		1	/* global symbol */
    384  1.1  leo #define	STB_WEAK		2	/* weakly defined global symbol */
    385  1.1  leo #define	STB_NUM			3
    386  1.1  leo 
    387  1.1  leo #define	STB_LOOS		10	/* Operating system specific range */
    388  1.1  leo #define	STB_HIOS		12
    389  1.1  leo #define	STB_LOPROC		13	/* Processor-specific range */
    390  1.1  leo #define	STB_HIPROC		15
    391  1.1  leo 
    392  1.1  leo /* st_info: Symbol Types */
    393  1.1  leo #define	STT_NOTYPE		0	/* Type not specified */
    394  1.1  leo #define	STT_OBJECT		1	/* Associated with a data object */
    395  1.1  leo #define	STT_FUNC		2	/* Associated with a function */
    396  1.1  leo #define	STT_SECTION		3	/* Associated with a section */
    397  1.1  leo #define	STT_FILE		4	/* Associated with a file name */
    398  1.1  leo #define	STT_NUM			5
    399  1.1  leo 
    400  1.1  leo #define	STT_LOOS		10	/* Operating system specific range */
    401  1.1  leo #define	STT_HIOS		12
    402  1.1  leo #define	STT_LOPROC		13	/* Processor-specific range */
    403  1.1  leo #define	STT_HIPROC		15
    404  1.1  leo 
    405  1.1  leo /* st_info utility macros */
    406  1.1  leo #define	ELF32_ST_BIND(info)		((Elf32_Word)(info) >> 4)
    407  1.1  leo #define	ELF32_ST_TYPE(info)		((Elf32_Word)(info) & 0xf)
    408  1.1  leo #define	ELF32_ST_INFO(bind,type)	((Elf_Byte)(((bind) << 4) | ((type) & 0xf)))
    409  1.1  leo 
    410  1.1  leo /*
    411  1.1  leo  * Special section indexes
    412  1.1  leo  */
    413  1.1  leo #define	SHN_UNDEF	0		/* Undefined section */
    414  1.1  leo 
    415  1.1  leo #define	SHN_LORESERVE	0xff00		/* Reserved range */
    416  1.1  leo #define	SHN_ABS		0xfff1		/*  Absolute symbols */
    417  1.1  leo #define	SHN_COMMON	0xfff2		/*  Common symbols */
    418  1.1  leo #define	SHN_HIRESERVE	0xffff
    419  1.1  leo 
    420  1.1  leo #define	SHN_LOPROC	0xff00		/* Processor-specific range */
    421  1.1  leo #define	SHN_HIPROC	0xff1f
    422  1.1  leo #define	SHN_LOOS	0xff20		/* Operating system specific range */
    423  1.1  leo #define	SHN_HIOS	0xff3f
    424  1.1  leo 
    425  1.1  leo #define	SHN_MIPS_ACOMMON 0xff00
    426  1.1  leo #define	SHN_MIPS_TEXT	0xff01
    427  1.1  leo #define	SHN_MIPS_DATA	0xff02
    428  1.1  leo #define	SHN_MIPS_SCOMMON 0xff03
    429  1.1  leo 
    430  1.1  leo /*
    431  1.1  leo  * Relocation Entries
    432  1.1  leo  */
    433  1.1  leo typedef struct {
    434  1.1  leo 	Elf32_Word	r_offset;	/* where to do it */
    435  1.1  leo 	Elf32_Word	r_info;		/* index & type of relocation */
    436  1.1  leo } Elf32_Rel;
    437  1.1  leo 
    438  1.1  leo typedef struct {
    439  1.1  leo 	Elf32_Word	r_offset;	/* where to do it */
    440  1.1  leo 	Elf32_Word	r_info;		/* index & type of relocation */
    441  1.1  leo 	Elf32_Sword	r_addend;	/* adjustment value */
    442  1.1  leo } Elf32_Rela;
    443  1.1  leo 
    444  1.1  leo /* r_info utility macros */
    445  1.1  leo #define	ELF32_R_SYM(info)	((info) >> 8)
    446  1.1  leo #define	ELF32_R_TYPE(info)	((info) & 0xff)
    447  1.1  leo #define	ELF32_R_INFO(sym, type)	(((sym) << 8) + (unsigned char)(type))
    448  1.1  leo 
    449  1.1  leo /*
    450  1.1  leo  * Dynamic Section structure array
    451  1.1  leo  */
    452  1.1  leo typedef struct {
    453  1.1  leo 	Elf32_Word	d_tag;		/* entry tag value */
    454  1.1  leo 	union {
    455  1.1  leo 	    Elf32_Addr	d_ptr;
    456  1.1  leo 	    Elf32_Word	d_val;
    457  1.1  leo 	} d_un;
    458  1.1  leo } Elf32_Dyn;
    459  1.1  leo 
    460  1.1  leo /* d_tag */
    461  1.1  leo #define	DT_NULL		0	/* Marks end of dynamic array */
    462  1.1  leo #define	DT_NEEDED	1	/* Name of needed library (DT_STRTAB offset) */
    463  1.1  leo #define	DT_PLTRELSZ	2	/* Size, in bytes, of relocations in PLT */
    464  1.1  leo #define	DT_PLTGOT	3	/* Address of PLT and/or GOT */
    465  1.1  leo #define	DT_HASH		4	/* Address of symbol hash table */
    466  1.1  leo #define	DT_STRTAB	5	/* Address of string table */
    467  1.1  leo #define	DT_SYMTAB	6	/* Address of symbol table */
    468  1.1  leo #define	DT_RELA		7	/* Address of Rela relocation table */
    469  1.1  leo #define	DT_RELASZ	8	/* Size, in bytes, of DT_RELA table */
    470  1.1  leo #define	DT_RELAENT	9	/* Size, in bytes, of one DT_RELA entry */
    471  1.1  leo #define	DT_STRSZ	10	/* Size, in bytes, of DT_STRTAB table */
    472  1.1  leo #define	DT_SYMENT	11	/* Size, in bytes, of one DT_SYMTAB entry */
    473  1.1  leo #define	DT_INIT		12	/* Address of initialization function */
    474  1.1  leo #define	DT_FINI		13	/* Address of termination function */
    475  1.1  leo #define	DT_SONAME	14	/* Shared object name (DT_STRTAB offset) */
    476  1.1  leo #define	DT_RPATH	15	/* Library search path (DT_STRTAB offset) */
    477  1.1  leo #define	DT_SYMBOLIC	16	/* Start symbol search within local object */
    478  1.1  leo #define	DT_REL		17	/* Address of Rel relocation table */
    479  1.1  leo #define	DT_RELSZ	18	/* Size, in bytes, of DT_REL table */
    480  1.1  leo #define	DT_RELENT	19	/* Size, in bytes, of one DT_REL entry */
    481  1.1  leo #define	DT_PLTREL	20 	/* Type of PLT relocation entries */
    482  1.1  leo #define	DT_DEBUG	21	/* Used for debugging; unspecified */
    483  1.1  leo #define	DT_TEXTREL	22	/* Relocations might modify non-writable seg */
    484  1.1  leo #define	DT_JMPREL	23	/* Address of relocations associated with PLT */
    485  1.1  leo #define	DT_BIND_NOW	24	/* Process all relocations at load-time */
    486  1.1  leo #define	DT_INIT_ARRAY	25	/* Address of initialization function array */
    487  1.1  leo #define	DT_FINI_ARRAY	26	/* Size, in bytes, of DT_INIT_ARRAY array */
    488  1.1  leo #define	DT_INIT_ARRAYSZ	27	/* Address of termination function array */
    489  1.1  leo #define	DT_FINI_ARRAYSZ	28	/* Size, in bytes, of DT_FINI_ARRAY array*/
    490  1.1  leo #define	DT_NUM		29
    491  1.1  leo 
    492  1.1  leo #define	DT_LOOS		0x60000000	/* Operating system specific range */
    493  1.1  leo #define	DT_HIOS		0x6fffffff
    494  1.1  leo #define	DT_LOPROC	0x70000000	/* Processor-specific range */
    495  1.1  leo #define	DT_HIPROC	0x7fffffff
    496  1.1  leo 
    497  1.1  leo /*
    498  1.1  leo  * Auxiliary Vectors
    499  1.1  leo  */
    500  1.1  leo typedef struct {
    501  1.1  leo 	Elf32_Word	a_type;				/* 32-bit id */
    502  1.1  leo 	Elf32_Word	a_v;				/* 32-bit id */
    503  1.1  leo } Aux32Info;
    504  1.1  leo 
    505  1.1  leo /* a_type */
    506  1.1  leo #define	AT_NULL		0	/* Marks end of array */
    507  1.1  leo #define	AT_IGNORE	1	/* No meaning, a_un is undefined */
    508  1.1  leo #define	AT_EXECFD	2	/* Open file descriptor of object file */
    509  1.1  leo #define	AT_PHDR		3	/* &phdr[0] */
    510  1.1  leo #define	AT_PHENT	4	/* sizeof(phdr[0]) */
    511  1.1  leo #define	AT_PHNUM	5	/* # phdr entries */
    512  1.1  leo #define	AT_PAGESZ	6	/* PAGESIZE */
    513  1.1  leo #define	AT_BASE		7	/* Interpreter base addr */
    514  1.1  leo #define	AT_FLAGS	8	/* Processor flags */
    515  1.1  leo #define	AT_ENTRY	9	/* Entry address of executable */
    516  1.1  leo #define	AT_DCACHEBSIZE	10	/* Data cache block size */
    517  1.1  leo #define	AT_ICACHEBSIZE	11	/* Instruction cache block size */
    518  1.1  leo #define	AT_UCACHEBSIZE	12	/* Unified cache block size */
    519  1.1  leo 
    520  1.1  leo 	/* Vendor specific */
    521  1.1  leo #define	AT_MIPS_NOTELF	10	/* XXX a_val != 0 -> MIPS XCOFF executable */
    522  1.1  leo 
    523  1.1  leo #define	AT_SUN_UID	2000	/* euid */
    524  1.1  leo #define	AT_SUN_RUID	2001	/* ruid */
    525  1.1  leo #define	AT_SUN_GID	2002	/* egid */
    526  1.1  leo #define	AT_SUN_RGID	2003	/* rgid */
    527  1.1  leo 
    528  1.1  leo 	/* Solaris kernel specific */
    529  1.1  leo #define	AT_SUN_LDELF	2004	/* dynamic linker's ELF header */
    530  1.1  leo #define	AT_SUN_LDSHDR	2005	/* dynamic linker's section header */
    531  1.1  leo #define	AT_SUN_LDNAME	2006	/* dynamic linker's name */
    532  1.1  leo #define	AT_SUN_LPGSIZE	2007	/* large pagesize */
    533  1.1  leo 
    534  1.1  leo 	/* Other information */
    535  1.1  leo #define	AT_SUN_PLATFORM	2008	/* sysinfo(SI_PLATFORM) */
    536  1.1  leo #define	AT_SUN_HWCAP	2009	/* process hardware capabilities */
    537  1.1  leo #define	AT_SUN_IFLUSH	2010	/* do we need to flush the instruction cache? */
    538  1.1  leo #define	AT_SUN_CPU	2011	/* cpu name */
    539  1.1  leo 	/* ibcs2 emulation band aid */
    540  1.1  leo #define	AT_SUN_EMUL_ENTRY 2012	/* coff entry point */
    541  1.1  leo #define	AT_SUN_EMUL_EXECFD 2013	/* coff file descriptor */
    542  1.1  leo 	/* Executable's fully resolved name */
    543  1.1  leo #define	AT_SUN_EXECNAME	2014
    544  1.1  leo 
    545  1.1  leo /*
    546  1.1  leo  * Note Headers
    547  1.1  leo  */
    548  1.1  leo typedef struct {
    549  1.1  leo 	Elf32_Word n_namesz;
    550  1.1  leo 	Elf32_Word n_descsz;
    551  1.1  leo 	Elf32_Word n_type;
    552  1.1  leo } Elf32_Nhdr;
    553  1.1  leo 
    554  1.1  leo #define	ELF_NOTE_TYPE_ABI_TAG		1
    555  1.1  leo 
    556  1.1  leo /* GNU-specific note name and description sizes */
    557  1.1  leo #define	ELF_NOTE_ABI_NAMESZ		4
    558  1.1  leo #define	ELF_NOTE_ABI_DESCSZ		16
    559  1.1  leo /* GNU-specific note name */
    560  1.1  leo #define	ELF_NOTE_ABI_NAME		"GNU\0"
    561  1.1  leo 
    562  1.1  leo /* GNU-specific OS/version value stuff */
    563  1.1  leo #define	ELF_NOTE_ABI_OS_LINUX		0
    564  1.1  leo #define	ELF_NOTE_ABI_OS_HURD		1
    565  1.1  leo #define	ELF_NOTE_ABI_OS_SOLARIS		2
    566  1.1  leo 
    567  1.1  leo /* NetBSD-specific note type: Emulation name.  desc is emul name string. */
    568  1.1  leo #define	ELF_NOTE_TYPE_NETBSD_TAG	1
    569  1.1  leo 
    570  1.1  leo /* NetBSD-specific note name and description sizes */
    571  1.1  leo #define	ELF_NOTE_NETBSD_NAMESZ		7
    572  1.1  leo #define	ELF_NOTE_NETBSD_DESCSZ		4
    573  1.1  leo /* NetBSD-specific note name */
    574  1.1  leo #define	ELF_NOTE_NETBSD_NAME		"NetBSD\0\0"
    575  1.1  leo 
    576  1.1  leo #if defined(ELFSIZE)
    577  1.1  leo #define	CONCAT(x,y)	__CONCAT(x,y)
    578  1.1  leo #define	ELFNAME(x)	CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
    579  1.1  leo #define	ELFNAME2(x,y)	CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
    580  1.1  leo #define	ELFNAMEEND(x)	CONCAT(x,CONCAT(_elf,ELFSIZE))
    581  1.1  leo #define	ELFDEFNNAME(x)	CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
    582  1.1  leo #endif
    583  1.1  leo 
    584  1.1  leo /*
    585  1.1  leo  * Leo: This is actually from machine/elf_machdep.h
    586  1.1  leo  */
    587  1.1  leo #define	ELF32_MACHDEP_ENDIANNESS	ELFDATA2MSB
    588  1.1  leo #define	ELF32_MACHDEP_ID_CASES						\
    589  1.1  leo 		case EM_68K:						\
    590  1.1  leo 			break;
    591  1.1  leo 
    592  1.1  leo #define	ELF64_MACHDEP_ENDIANNESS	XXX	/* break compilation */
    593  1.1  leo #define	ELF64_MACHDEP_ID_CASES						\
    594  1.1  leo 		/* no 64-bit ELF machine types supported */
    595  1.1  leo 
    596  1.1  leo #define ARCH_ELFSIZE		32	/* MD native binary size */
    597  1.1  leo 
    598  1.1  leo /* m68k relocation types */
    599  1.1  leo #define	R_68K_NONE	0
    600  1.1  leo #define	R_68K_32	1
    601  1.1  leo #define	R_68K_16	2
    602  1.1  leo #define	R_68K_8		3
    603  1.1  leo #define	R_68K_PC32	4
    604  1.1  leo #define	R_68K_PC16	5
    605  1.1  leo #define	R_68K_PC8	6
    606  1.1  leo #define	R_68K_GOT32	7
    607  1.1  leo #define	R_68K_GOT16	8
    608  1.1  leo #define	R_68K_GOT8	9
    609  1.1  leo #define	R_68K_GOT32O	10
    610  1.1  leo #define	R_68K_GOT16O	11
    611  1.1  leo #define	R_68K_GOT8O	12
    612  1.1  leo #define	R_68K_PLT32	13
    613  1.1  leo #define	R_68K_PLT16	14
    614  1.1  leo #define	R_68K_PLT8	15
    615  1.1  leo #define	R_68K_PLT32O	16
    616  1.1  leo #define	R_68K_PLT16O	17
    617  1.1  leo #define	R_68K_PLT8O	18
    618  1.1  leo #define	R_68K_COPY	19
    619  1.1  leo #define	R_68K_GLOB_DAT	20
    620  1.1  leo #define	R_68K_JMP_SLOT	21
    621  1.1  leo #define	R_68K_RELATIVE	22
    622  1.1  leo 
    623  1.1  leo #define	R_TYPE(name)	__CONCAT(R_68K_,name)
    624  1.1  leo 
    625  1.1  leo #define	Elf_Ehdr	Elf32_Ehdr
    626  1.1  leo #define	Elf_Phdr	Elf32_Phdr
    627  1.1  leo #define	Elf_Shdr	Elf32_Shdr
    628  1.1  leo #define	Elf_Sym		Elf32_Sym
    629  1.1  leo #define	Elf_Rel		Elf32_Rel
    630  1.1  leo #define	Elf_Rela	Elf32_Rela
    631  1.1  leo #define	Elf_Dyn		Elf32_Dyn
    632  1.1  leo #define	Elf_Word	Elf32_Word
    633  1.1  leo #define	Elf_Sword	Elf32_Sword
    634  1.1  leo #define	Elf_Addr	Elf32_Addr
    635  1.1  leo #define	Elf_Off		Elf32_Off
    636  1.1  leo #define	Elf_Nhdr	Elf32_Nhdr
    637  1.1  leo 
    638  1.1  leo #define	ELF_R_SYM	ELF32_R_SYM
    639  1.1  leo #define	ELF_R_TYPE	ELF32_R_TYPE
    640  1.1  leo #define	ELFCLASS	ELFCLASS32
    641  1.1  leo 
    642  1.1  leo #define	ELF_ST_BIND	ELF32_ST_BIND
    643  1.1  leo #define	ELF_ST_TYPE	ELF32_ST_TYPE
    644  1.1  leo #define	ELF_ST_INFO	ELF32_ST_INFO
    645  1.1  leo 
    646  1.1  leo #define	AuxInfo		Aux32Info
    647  1.1  leo 
    648  1.1  leo #ifdef _KERNEL
    649  1.1  leo 
    650  1.1  leo #define ELF_AUX_ENTRIES	8		/* Size of aux array passed to loader */
    651  1.1  leo #define ELF32_NO_ADDR	(~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
    652  1.1  leo #define ELF64_NO_ADDR	(~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
    653  1.1  leo 
    654  1.1  leo #if defined(ELFSIZE) && (ELFSIZE == 64)
    655  1.1  leo #define ELF_NO_ADDR	ELF64_NO_ADDR
    656  1.1  leo #elif defined(ELFSIZE) && (ELFSIZE == 32)
    657  1.1  leo #define ELF_NO_ADDR	ELF32_NO_ADDR
    658  1.1  leo #endif
    659  1.1  leo 
    660  1.1  leo #if defined(ELFSIZE)
    661  1.1  leo struct elf_args {
    662  1.1  leo         Elf_Addr  arg_entry;      /* program entry point */
    663  1.1  leo         Elf_Addr  arg_interp;     /* Interpreter load address */
    664  1.1  leo         Elf_Addr  arg_phaddr;     /* program header address */
    665  1.1  leo         Elf_Addr  arg_phentsize;  /* Size of program header */
    666  1.1  leo         Elf_Addr  arg_phnum;      /* Number of program headers */
    667  1.1  leo };
    668  1.1  leo #endif
    669  1.1  leo 
    670  1.1  leo #endif /* _KERNEL */
    671  1.1  leo 
    672  1.1  leo #endif /* !_SYS_EXEC_ELF_H_ */
    673