xref: /freebsd/sys/x86/include/elf.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
131a53cd0SKonstantin Belousov /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3ebf5747bSPedro F. Giffuni  *
431a53cd0SKonstantin Belousov  * Copyright (c) 1996-1997 John D. Polstra.
531a53cd0SKonstantin Belousov  * All rights reserved.
631a53cd0SKonstantin Belousov  *
731a53cd0SKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
831a53cd0SKonstantin Belousov  * modification, are permitted provided that the following conditions
931a53cd0SKonstantin Belousov  * are met:
1031a53cd0SKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
1131a53cd0SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
1231a53cd0SKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
1331a53cd0SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
1431a53cd0SKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
1531a53cd0SKonstantin Belousov  *
1631a53cd0SKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1731a53cd0SKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1831a53cd0SKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1931a53cd0SKonstantin Belousov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2031a53cd0SKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2131a53cd0SKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2231a53cd0SKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2331a53cd0SKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2431a53cd0SKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2531a53cd0SKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2631a53cd0SKonstantin Belousov  * SUCH DAMAGE.
2731a53cd0SKonstantin Belousov  */
2831a53cd0SKonstantin Belousov 
2931a53cd0SKonstantin Belousov #ifndef _MACHINE_ELF_H_
3031a53cd0SKonstantin Belousov #define	_MACHINE_ELF_H_ 1
3131a53cd0SKonstantin Belousov 
3231a53cd0SKonstantin Belousov #if defined(__i386__) || defined(_MACHINE_ELF_WANT_32BIT)
3382914538SKonstantin Belousov /* ELF definitions for the i386 architecture. */
3431a53cd0SKonstantin Belousov #include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
3531a53cd0SKonstantin Belousov #if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64
3682914538SKonstantin Belousov /* Definitions common to all 64 bit architectures. */
3782914538SKonstantin Belousov #include <sys/elf64.h>
3831a53cd0SKonstantin Belousov #endif
3931a53cd0SKonstantin Belousov 
4031a53cd0SKonstantin Belousov #ifndef __ELF_WORD_SIZE
4131a53cd0SKonstantin Belousov #define	__ELF_WORD_SIZE	32	/* Used by <sys/elf_generic.h> */
4231a53cd0SKonstantin Belousov #endif
4331a53cd0SKonstantin Belousov 
4431a53cd0SKonstantin Belousov #include <sys/elf_generic.h>
4531a53cd0SKonstantin Belousov 
4631a53cd0SKonstantin Belousov #define	ELF_ARCH	EM_386
4731a53cd0SKonstantin Belousov 
4831a53cd0SKonstantin Belousov #define	ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486)
4931a53cd0SKonstantin Belousov 
5031a53cd0SKonstantin Belousov /*
5131a53cd0SKonstantin Belousov  * Auxiliary vector entries for passing information to the interpreter.
5231a53cd0SKonstantin Belousov  *
5331a53cd0SKonstantin Belousov  * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
5431a53cd0SKonstantin Belousov  * but POSIX lays claim to all symbols ending with "_t".
5531a53cd0SKonstantin Belousov  */
5631a53cd0SKonstantin Belousov 
5731a53cd0SKonstantin Belousov typedef struct {	/* Auxiliary vector entry on initial stack */
5831a53cd0SKonstantin Belousov 	int	a_type;			/* Entry type. */
5931a53cd0SKonstantin Belousov 	union {
6031a53cd0SKonstantin Belousov 		long	a_val;		/* Integer value. */
6131a53cd0SKonstantin Belousov 		void	*a_ptr;		/* Address. */
6231a53cd0SKonstantin Belousov 		void	(*a_fcn)(void);	/* Function pointer (not used). */
6331a53cd0SKonstantin Belousov 	} a_un;
6431a53cd0SKonstantin Belousov } Elf32_Auxinfo;
6531a53cd0SKonstantin Belousov 
6631a53cd0SKonstantin Belousov #if __ELF_WORD_SIZE == 64
6731a53cd0SKonstantin Belousov /* Fake for amd64 loader support */
6831a53cd0SKonstantin Belousov typedef struct {
6931a53cd0SKonstantin Belousov 	int fake;
7031a53cd0SKonstantin Belousov } Elf64_Auxinfo;
7131a53cd0SKonstantin Belousov #endif
7231a53cd0SKonstantin Belousov 
7331a53cd0SKonstantin Belousov __ElfType(Auxinfo);
7431a53cd0SKonstantin Belousov 
7531a53cd0SKonstantin Belousov /*
7631a53cd0SKonstantin Belousov  * Relocation types.
7731a53cd0SKonstantin Belousov  */
7831a53cd0SKonstantin Belousov 
7931a53cd0SKonstantin Belousov #define	R_386_COUNT	38	/* Count of defined relocation types. */
8031a53cd0SKonstantin Belousov 
8131a53cd0SKonstantin Belousov /* Define "machine" characteristics */
8231a53cd0SKonstantin Belousov #define	ELF_TARG_CLASS	ELFCLASS32
8331a53cd0SKonstantin Belousov #define	ELF_TARG_DATA	ELFDATA2LSB
8431a53cd0SKonstantin Belousov #define	ELF_TARG_MACH	EM_386
8531a53cd0SKonstantin Belousov #define	ELF_TARG_VER	1
8631a53cd0SKonstantin Belousov 
875f00525dSKonstantin Belousov #define	ET_DYN_LOAD_ADDR 0x00002000
8831a53cd0SKonstantin Belousov 
8931a53cd0SKonstantin Belousov #elif defined(__amd64__)
9031a53cd0SKonstantin Belousov 
9131a53cd0SKonstantin Belousov /*
9231a53cd0SKonstantin Belousov  * ELF definitions for the AMD64 architecture.
9331a53cd0SKonstantin Belousov  */
9431a53cd0SKonstantin Belousov 
9531a53cd0SKonstantin Belousov #ifndef __ELF_WORD_SIZE
9631a53cd0SKonstantin Belousov #define	__ELF_WORD_SIZE	64	/* Used by <sys/elf_generic.h> */
9731a53cd0SKonstantin Belousov #endif
9831a53cd0SKonstantin Belousov #include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
9931a53cd0SKonstantin Belousov #include <sys/elf64.h>	/* Definitions common to all 64 bit architectures. */
10031a53cd0SKonstantin Belousov #include <sys/elf_generic.h>
10131a53cd0SKonstantin Belousov 
10231a53cd0SKonstantin Belousov #define	ELF_ARCH	EM_X86_64
10331a53cd0SKonstantin Belousov #define	ELF_ARCH32	EM_386
10431a53cd0SKonstantin Belousov 
10531a53cd0SKonstantin Belousov #define	ELF_MACHINE_OK(x) ((x) == EM_X86_64)
10631a53cd0SKonstantin Belousov 
10731a53cd0SKonstantin Belousov /*
10831a53cd0SKonstantin Belousov  * Auxiliary vector entries for passing information to the interpreter.
10931a53cd0SKonstantin Belousov  *
11031a53cd0SKonstantin Belousov  * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
11131a53cd0SKonstantin Belousov  * but POSIX lays claim to all symbols ending with "_t".
11231a53cd0SKonstantin Belousov  */
11331a53cd0SKonstantin Belousov typedef struct {	/* Auxiliary vector entry on initial stack */
11431a53cd0SKonstantin Belousov 	int	a_type;			/* Entry type. */
11531a53cd0SKonstantin Belousov 	union {
11631a53cd0SKonstantin Belousov 		int	a_val;		/* Integer value. */
11731a53cd0SKonstantin Belousov 	} a_un;
11831a53cd0SKonstantin Belousov } Elf32_Auxinfo;
11931a53cd0SKonstantin Belousov 
12031a53cd0SKonstantin Belousov typedef struct {	/* Auxiliary vector entry on initial stack */
12131a53cd0SKonstantin Belousov 	long	a_type;			/* Entry type. */
12231a53cd0SKonstantin Belousov 	union {
12331a53cd0SKonstantin Belousov 		long	a_val;		/* Integer value. */
12431a53cd0SKonstantin Belousov 		void	*a_ptr;		/* Address. */
12531a53cd0SKonstantin Belousov 		void	(*a_fcn)(void);	/* Function pointer (not used). */
12631a53cd0SKonstantin Belousov 	} a_un;
12731a53cd0SKonstantin Belousov } Elf64_Auxinfo;
12831a53cd0SKonstantin Belousov 
12931a53cd0SKonstantin Belousov __ElfType(Auxinfo);
13031a53cd0SKonstantin Belousov 
13131a53cd0SKonstantin Belousov /*
13231a53cd0SKonstantin Belousov  * Relocation types.
13331a53cd0SKonstantin Belousov  */
13431a53cd0SKonstantin Belousov 
13531a53cd0SKonstantin Belousov #define	R_X86_64_COUNT	24	/* Count of defined relocation types. */
13631a53cd0SKonstantin Belousov 
13731a53cd0SKonstantin Belousov /* Define "machine" characteristics */
13831a53cd0SKonstantin Belousov #if __ELF_WORD_SIZE == 32
13931a53cd0SKonstantin Belousov #define ELF_TARG_CLASS  ELFCLASS32
14031a53cd0SKonstantin Belousov #else
14131a53cd0SKonstantin Belousov #define ELF_TARG_CLASS  ELFCLASS64
14231a53cd0SKonstantin Belousov #endif
14331a53cd0SKonstantin Belousov #define	ELF_TARG_DATA	ELFDATA2LSB
14431a53cd0SKonstantin Belousov #define	ELF_TARG_MACH	EM_X86_64
14531a53cd0SKonstantin Belousov #define	ELF_TARG_VER	1
14631a53cd0SKonstantin Belousov 
14731a53cd0SKonstantin Belousov #if __ELF_WORD_SIZE == 32
1485f00525dSKonstantin Belousov #define	ET_DYN_LOAD_ADDR 0x00002000
14931a53cd0SKonstantin Belousov #else
15031a53cd0SKonstantin Belousov #define	ET_DYN_LOAD_ADDR 0x01021000
15131a53cd0SKonstantin Belousov #endif
15231a53cd0SKonstantin Belousov 
15331a53cd0SKonstantin Belousov #endif /* __i386__, __amd64__ */
15431a53cd0SKonstantin Belousov 
15531a53cd0SKonstantin Belousov #endif /* !_MACHINE_ELF_H_ */
156