1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 1996-1997 John D. Polstra. 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _MACHINE_ELF_H_ 30 #define _MACHINE_ELF_H_ 1 31 32 #if defined(__i386__) || defined(_MACHINE_ELF_WANT_32BIT) 33 /* ELF definitions for the i386 architecture. */ 34 #include <sys/elf32.h> /* Definitions common to all 32 bit architectures. */ 35 #if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64 36 /* Definitions common to all 64 bit architectures. */ 37 #include <sys/elf64.h> 38 #endif 39 40 #ifndef __ELF_WORD_SIZE 41 #define __ELF_WORD_SIZE 32 /* Used by <sys/elf_generic.h> */ 42 #endif 43 44 #include <sys/elf_generic.h> 45 46 #define ELF_ARCH EM_386 47 48 #define ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486) 49 50 /* 51 * Auxiliary vector entries for passing information to the interpreter. 52 * 53 * The i386 supplement to the SVR4 ABI specification names this "auxv_t", 54 * but POSIX lays claim to all symbols ending with "_t". 55 */ 56 57 typedef struct { /* Auxiliary vector entry on initial stack */ 58 int a_type; /* Entry type. */ 59 union { 60 long a_val; /* Integer value. */ 61 void *a_ptr; /* Address. */ 62 void (*a_fcn)(void); /* Function pointer (not used). */ 63 } a_un; 64 } Elf32_Auxinfo; 65 66 #if __ELF_WORD_SIZE == 64 67 /* Fake for amd64 loader support */ 68 typedef struct { 69 int fake; 70 } Elf64_Auxinfo; 71 #endif 72 73 __ElfType(Auxinfo); 74 75 /* 76 * Relocation types. 77 */ 78 79 #define R_386_COUNT 38 /* Count of defined relocation types. */ 80 81 /* Define "machine" characteristics */ 82 #define ELF_TARG_CLASS ELFCLASS32 83 #define ELF_TARG_DATA ELFDATA2LSB 84 #define ELF_TARG_MACH EM_386 85 #define ELF_TARG_VER 1 86 87 #define ET_DYN_LOAD_ADDR 0x00002000 88 89 #elif defined(__amd64__) 90 91 /* 92 * ELF definitions for the AMD64 architecture. 93 */ 94 95 #ifndef __ELF_WORD_SIZE 96 #define __ELF_WORD_SIZE 64 /* Used by <sys/elf_generic.h> */ 97 #endif 98 #include <sys/elf32.h> /* Definitions common to all 32 bit architectures. */ 99 #include <sys/elf64.h> /* Definitions common to all 64 bit architectures. */ 100 #include <sys/elf_generic.h> 101 102 #define ELF_ARCH EM_X86_64 103 #define ELF_ARCH32 EM_386 104 105 #define ELF_MACHINE_OK(x) ((x) == EM_X86_64) 106 107 /* 108 * Auxiliary vector entries for passing information to the interpreter. 109 * 110 * The i386 supplement to the SVR4 ABI specification names this "auxv_t", 111 * but POSIX lays claim to all symbols ending with "_t". 112 */ 113 typedef struct { /* Auxiliary vector entry on initial stack */ 114 int a_type; /* Entry type. */ 115 union { 116 int a_val; /* Integer value. */ 117 } a_un; 118 } Elf32_Auxinfo; 119 120 typedef struct { /* Auxiliary vector entry on initial stack */ 121 long a_type; /* Entry type. */ 122 union { 123 long a_val; /* Integer value. */ 124 void *a_ptr; /* Address. */ 125 void (*a_fcn)(void); /* Function pointer (not used). */ 126 } a_un; 127 } Elf64_Auxinfo; 128 129 __ElfType(Auxinfo); 130 131 /* 132 * Relocation types. 133 */ 134 135 #define R_X86_64_COUNT 24 /* Count of defined relocation types. */ 136 137 /* Define "machine" characteristics */ 138 #if __ELF_WORD_SIZE == 32 139 #define ELF_TARG_CLASS ELFCLASS32 140 #else 141 #define ELF_TARG_CLASS ELFCLASS64 142 #endif 143 #define ELF_TARG_DATA ELFDATA2LSB 144 #define ELF_TARG_MACH EM_X86_64 145 #define ELF_TARG_VER 1 146 147 #if __ELF_WORD_SIZE == 32 148 #define ET_DYN_LOAD_ADDR 0x00002000 149 #else 150 #define ET_DYN_LOAD_ADDR 0x01021000 151 #endif 152 153 #endif /* __i386__, __amd64__ */ 154 155 #endif /* !_MACHINE_ELF_H_ */ 156