2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-2-Clause-NetBSD
4 * Copyright (c) 2013 M. Warner Losh. All Rights Reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 2013 The NetBSD Foundation, Inc.
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
43 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
44 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
45 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
47 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 * POSSIBILITY OF SUCH DAMAGE.
55 * See below starting with the line with $NetBSD...$ for code this applies to.
61 /* FreeBSD specific bits - derived from FreeBSD specific files and changes to old elf.h */
64 * Define __ELF_WORD_SIZE based on the ABI, if not defined yet. This sets
65 * the proper defaults when we're not trying to do 32-bit on 64-bit systems.
66 * We include both 32 and 64 bit versions so we can support multiple ABIs.
68 #ifndef __ELF_WORD_SIZE
69 #if defined(__mips_n64)
70 #define __ELF_WORD_SIZE 64
72 #define __ELF_WORD_SIZE 32
75 #include <sys/elf32.h>
76 #include <sys/elf64.h>
77 #include <sys/elf_generic.h>
79 #define ELF_ARCH EM_MIPS
80 #define ELF_ARCH32 EM_MIPS
82 #define ELF_MACHINE_OK(x) ((x) == ELF_ARCH)
84 /* Define "machine" characteristics */
85 #if __ELF_WORD_SIZE == 32
86 #define ELF_TARG_CLASS ELFCLASS32
88 #define ELF_TARG_CLASS ELFCLASS64
91 #define ELF_TARG_DATA ELFDATA2MSB
93 #define ELF_TARG_DATA ELFDATA2LSB
95 #define ELF_TARG_MACH EM_MIPS
96 #define ELF_TARG_VER 1
99 * Auxiliary vector entries for passing information to the interpreter.
101 * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
102 * but POSIX lays claim to all symbols ending with "_t".
104 typedef struct { /* Auxiliary vector entry on initial stack */
105 int a_type; /* Entry type. */
107 int a_val; /* Integer value. */
108 void *a_ptr; /* Address. */
109 void (*a_fcn)(void); /* Function pointer (not used). */
113 typedef struct { /* Auxiliary vector entry on initial stack */
114 long a_type; /* Entry type. */
116 long a_val; /* Integer value. */
117 void *a_ptr; /* Address. */
118 void (*a_fcn)(void); /* Function pointer (not used). */
124 /* Values for a_type. */
125 #define AT_NULL 0 /* Terminates the vector. */
126 #define AT_IGNORE 1 /* Ignored entry. */
127 #define AT_EXECFD 2 /* File descriptor of program to load. */
128 #define AT_PHDR 3 /* Program header of program already loaded. */
129 #define AT_PHENT 4 /* Size of each program header entry. */
130 #define AT_PHNUM 5 /* Number of program header entries. */
131 #define AT_PAGESZ 6 /* Page size in bytes. */
132 #define AT_BASE 7 /* Interpreter's base address. */
133 #define AT_FLAGS 8 /* Flags (unused for i386). */
134 #define AT_ENTRY 9 /* Where interpreter should transfer control. */
135 #define AT_NOTELF 10 /* Program is not ELF ?? */
136 #define AT_UID 11 /* Real uid. */
137 #define AT_EUID 12 /* Effective uid. */
138 #define AT_GID 13 /* Real gid. */
139 #define AT_EGID 14 /* Effective gid. */
140 #define AT_EXECPATH 15 /* Path to the executable. */
141 #define AT_CANARY 16 /* Canary for SSP */
142 #define AT_CANARYLEN 17 /* Length of the canary. */
143 #define AT_OSRELDATE 18 /* OSRELDATE. */
144 #define AT_NCPUS 19 /* Number of CPUs. */
145 #define AT_PAGESIZES 20 /* Pagesizes. */
146 #define AT_PAGESIZESLEN 21 /* Number of pagesizes. */
147 #define AT_TIMEKEEP 22 /* Pointer to timehands. */
148 #define AT_STACKPROT 23 /* Initial stack protection. */
149 #define AT_EHDRFLAGS 24 /* e_flags field from elf hdr */
150 #define AT_HWCAP 25 /* CPU feature flags. */
151 #define AT_HWCAP2 26 /* CPU feature flags 2. */
153 #define AT_COUNT 27 /* Count of defined aux entry types. */
155 #define ET_DYN_LOAD_ADDR 0x0120000
158 * Constant to mark start of symtab/strtab saved by trampoline
160 #define SYMTAB_MAGIC 0x64656267
162 /* from NetBSD's sys/mips/include/elf_machdep.h $NetBSD: elf_machdep.h,v 1.18 2013/05/23 21:39:49 christos Exp $ */
166 #define R_MIPS_NONE 0
169 #define R_MIPS_REL32 3
170 #define R_MIPS_REL R_MIPS_REL32
172 #define R_MIPS_HI16 5 /* high 16 bits of symbol value */
173 #define R_MIPS_LO16 6 /* low 16 bits of symbol value */
174 #define R_MIPS_GPREL16 7 /* GP-relative reference */
175 #define R_MIPS_LITERAL 8 /* Reference to literal section */
176 #define R_MIPS_GOT16 9 /* Reference to global offset table */
177 #define R_MIPS_GOT R_MIPS_GOT16
178 #define R_MIPS_PC16 10 /* 16 bit PC relative reference */
179 #define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */
180 #define R_MIPS_CALL R_MIPS_CALL16
181 #define R_MIPS_GPREL32 12
183 /* 13, 14, 15 are not defined at this point. */
184 #define R_MIPS_UNUSED1 13
185 #define R_MIPS_UNUSED2 14
186 #define R_MIPS_UNUSED3 15
189 * The remaining relocs are apparently part of the 64-bit Irix ELF ABI.
191 #define R_MIPS_SHIFT5 16
192 #define R_MIPS_SHIFT6 17
195 #define R_MIPS_GOT_DISP 19
196 #define R_MIPS_GOT_PAGE 20
197 #define R_MIPS_GOT_OFST 21
198 #define R_MIPS_GOT_HI16 22
199 #define R_MIPS_GOT_LO16 23
200 #define R_MIPS_SUB 24
201 #define R_MIPS_INSERT_A 25
202 #define R_MIPS_INSERT_B 26
203 #define R_MIPS_DELETE 27
204 #define R_MIPS_HIGHER 28
205 #define R_MIPS_HIGHEST 29
206 #define R_MIPS_CALL_HI16 30
207 #define R_MIPS_CALL_LO16 31
208 #define R_MIPS_SCN_DISP 32
209 #define R_MIPS_REL16 33
210 #define R_MIPS_ADD_IMMEDIATE 34
211 #define R_MIPS_PJUMP 35
212 #define R_MIPS_RELGOT 36
213 #define R_MIPS_JALR 37
214 /* TLS relocations */
216 #define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */
217 #define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */
218 #define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */
219 #define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */
220 #define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */
221 #define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */
222 #define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */
223 #define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */
224 #define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */
225 #define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */
226 #define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */
227 #define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */
228 #define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */
230 #define R_MIPS_max 51
232 #define R_TYPE(name) __CONCAT(R_MIPS_,name)
234 #define R_MIPS16_min 100
235 #define R_MIPS16_26 100
236 #define R_MIPS16_GPREL 101
237 #define R_MIPS16_GOT16 102
238 #define R_MIPS16_CALL16 103
239 #define R_MIPS16_HI16 104
240 #define R_MIPS16_LO16 105
241 #define R_MIPS16_max 106
243 #define R_MIPS_COPY 126
244 #define R_MIPS_JUMP_SLOT 127
250 #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */
251 #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */
252 #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */
253 #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */
254 #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */
255 #define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */
256 #define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */
257 #define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */
258 #define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */
260 #define EF_MIPS_ABI 0x0000f000
261 #define EF_MIPS_ABI_O32 0x00001000
262 #define EF_MIPS_ABI_O64 0x00002000
263 #define EF_MIPS_ABI_EABI32 0x00003000
264 #define EF_MIPS_ABI_EABI64 0x00004000
266 #endif /* __MIPS_ELF_H */