xref: /trueos/sys/mips/include/elf.h (revision 749888363db1320e1cc3818fcd71e411c3a955ca)
1 /*
2  * Copyright (c) 2013 M. Warner Losh. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 /*-
29  * Copyright (c) 2013 The NetBSD Foundation, Inc.
30  * All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions
34  * are met:
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  * 2. Redistributions in binary form must reproduce the above copyright
38  *    notice, this list of conditions and the following disclaimer in the
39  *    documentation and/or other materials provided with the distribution.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
42  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
43  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
45  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51  * POSSIBILITY OF SUCH DAMAGE.
52  *
53  * See below starting with the line with $NetBSD...$ for code this applies to.
54  */
55 
56 #ifndef	__MIPS_ELF_H
57 #define	__MIPS_ELF_H
58 
59 /* FreeBSD specific bits - derived from FreeBSD specific files and changes to old elf.h */
60 
61 /*
62  * Define __ELF_WORD_SIZE based on the ABI, if not defined yet. This sets
63  * the proper defaults when we're not trying to do 32-bit on 64-bit systems.
64  * We include both 32 and 64 bit versions so we can support multiple ABIs.
65  */
66 #ifndef __ELF_WORD_SIZE
67 #if defined(__mips_n64)
68 #define __ELF_WORD_SIZE 64
69 #else
70 #define __ELF_WORD_SIZE 32
71 #endif
72 #endif
73 #include <sys/elf32.h>
74 #include <sys/elf64.h>
75 #include <sys/elf_generic.h>
76 
77 #define ELF_ARCH	EM_MIPS
78 #define ELF_ARCH32	EM_MIPS
79 
80 /* Define "machine" characteristics */
81 #if __ELF_WORD_SIZE == 32
82 #define	ELF_TARG_CLASS	ELFCLASS32
83 #else
84 #define	ELF_TARG_CLASS	ELFCLASS64
85 #endif
86 #ifdef __MIPSEB__
87 #define	ELF_TARG_DATA	ELFDATA2MSB
88 #else
89 #define ELF_TARG_DATA	ELFDATA2LSB
90 #endif
91 #define	ELF_TARG_MACH	EM_MIPS
92 #define	ELF_TARG_VER	1
93 
94 /*
95  * Auxiliary vector entries for passing information to the interpreter.
96  *
97  * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
98  * but POSIX lays claim to all symbols ending with "_t".
99  */
100 typedef struct {	/* Auxiliary vector entry on initial stack */
101 	int	a_type;			/* Entry type. */
102 	union {
103 		int	a_val;		/* Integer value. */
104 		void	*a_ptr;		/* Address. */
105 		void	(*a_fcn)(void); /* Function pointer (not used). */
106 	} a_un;
107 } Elf32_Auxinfo;
108 
109 typedef struct {	/* Auxiliary vector entry on initial stack */
110 	long	a_type;			/* Entry type. */
111 	union {
112 		long	a_val;		/* Integer value. */
113 		void	*a_ptr;		/* Address. */
114 		void	(*a_fcn)(void); /* Function pointer (not used). */
115 	} a_un;
116 } Elf64_Auxinfo;
117 
118 __ElfType(Auxinfo);
119 
120 /* Values for a_type. */
121 #define	AT_NULL		0	/* Terminates the vector. */
122 #define	AT_IGNORE	1	/* Ignored entry. */
123 #define	AT_EXECFD	2	/* File descriptor of program to load. */
124 #define	AT_PHDR		3	/* Program header of program already loaded. */
125 #define	AT_PHENT	4	/* Size of each program header entry. */
126 #define	AT_PHNUM	5	/* Number of program header entries. */
127 #define	AT_PAGESZ	6	/* Page size in bytes. */
128 #define	AT_BASE		7	/* Interpreter's base address. */
129 #define	AT_FLAGS	8	/* Flags (unused for i386). */
130 #define	AT_ENTRY	9	/* Where interpreter should transfer control. */
131 #define	AT_NOTELF	10	/* Program is not ELF ?? */
132 #define	AT_UID		11	/* Real uid. */
133 #define	AT_EUID		12	/* Effective uid. */
134 #define	AT_GID		13	/* Real gid. */
135 #define	AT_EGID		14	/* Effective gid. */
136 #define	AT_EXECPATH	15	/* Path to the executable. */
137 #define	AT_CANARY	16	/* Canary for SSP */
138 #define	AT_CANARYLEN	17	/* Length of the canary. */
139 #define	AT_OSRELDATE	18	/* OSRELDATE. */
140 #define	AT_NCPUS	19	/* Number of CPUs. */
141 #define	AT_PAGESIZES	20	/* Pagesizes. */
142 #define	AT_PAGESIZESLEN	21	/* Number of pagesizes. */
143 #define	AT_TIMEKEEP	22	/* Pointer to timehands. */
144 #define	AT_STACKPROT	23	/* Initial stack protection. */
145 
146 #define	AT_COUNT	24	/* Count of defined aux entry types. */
147 
148 #define	ET_DYN_LOAD_ADDR 0x0120000
149 
150 /*
151  * Constant to mark start of symtab/strtab saved by trampoline
152  */
153 #define	SYMTAB_MAGIC	0x64656267
154 
155 /* from NetBSD's sys/mips/include/elf_machdep.h $NetBSD: elf_machdep.h,v 1.18 2013/05/23 21:39:49 christos Exp $ */
156 
157 /* mips relocs. */
158 
159 #define	R_MIPS_NONE		0
160 #define	R_MIPS_16		1
161 #define	R_MIPS_32		2
162 #define	R_MIPS_REL32		3
163 #define	R_MIPS_REL		R_MIPS_REL32
164 #define	R_MIPS_26		4
165 #define	R_MIPS_HI16		5	/* high 16 bits of symbol value */
166 #define	R_MIPS_LO16		6	/* low 16 bits of symbol value */
167 #define	R_MIPS_GPREL16		7	/* GP-relative reference  */
168 #define	R_MIPS_LITERAL		8	/* Reference to literal section  */
169 #define	R_MIPS_GOT16		9	/* Reference to global offset table */
170 #define	R_MIPS_GOT		R_MIPS_GOT16
171 #define	R_MIPS_PC16		10	/* 16 bit PC relative reference */
172 #define	R_MIPS_CALL16 		11	/* 16 bit call thru glbl offset tbl */
173 #define	R_MIPS_CALL		R_MIPS_CALL16
174 #define	R_MIPS_GPREL32		12
175 
176 /* 13, 14, 15 are not defined at this point. */
177 #define	R_MIPS_UNUSED1		13
178 #define	R_MIPS_UNUSED2		14
179 #define	R_MIPS_UNUSED3		15
180 
181 /*
182  * The remaining relocs are apparently part of the 64-bit Irix ELF ABI.
183  */
184 #define	R_MIPS_SHIFT5		16
185 #define	R_MIPS_SHIFT6		17
186 
187 #define	R_MIPS_64		18
188 #define	R_MIPS_GOT_DISP		19
189 #define	R_MIPS_GOT_PAGE		20
190 #define	R_MIPS_GOT_OFST		21
191 #define	R_MIPS_GOT_HI16		22
192 #define	R_MIPS_GOT_LO16		23
193 #define	R_MIPS_SUB		24
194 #define	R_MIPS_INSERT_A		25
195 #define	R_MIPS_INSERT_B		26
196 #define	R_MIPS_DELETE		27
197 #define	R_MIPS_HIGHER		28
198 #define	R_MIPS_HIGHEST		29
199 #define	R_MIPS_CALL_HI16	30
200 #define	R_MIPS_CALL_LO16	31
201 #define	R_MIPS_SCN_DISP		32
202 #define	R_MIPS_REL16		33
203 #define	R_MIPS_ADD_IMMEDIATE	34
204 #define	R_MIPS_PJUMP		35
205 #define	R_MIPS_RELGOT		36
206 #define	R_MIPS_JALR		37
207 /* TLS relocations */
208 
209 #define	R_MIPS_TLS_DTPMOD32	38	/* Module number 32 bit */
210 #define	R_MIPS_TLS_DTPREL32	39	/* Module-relative offset 32 bit */
211 #define	R_MIPS_TLS_DTPMOD64	40	/* Module number 64 bit */
212 #define	R_MIPS_TLS_DTPREL64	41	/* Module-relative offset 64 bit */
213 #define	R_MIPS_TLS_GD		42	/* 16 bit GOT offset for GD */
214 #define	R_MIPS_TLS_LDM		43	/* 16 bit GOT offset for LDM */
215 #define	R_MIPS_TLS_DTPREL_HI16	44	/* Module-relative offset, high 16 bits */
216 #define	R_MIPS_TLS_DTPREL_LO16	45	/* Module-relative offset, low 16 bits */
217 #define	R_MIPS_TLS_GOTTPREL	46	/* 16 bit GOT offset for IE */
218 #define	R_MIPS_TLS_TPREL32	47	/* TP-relative offset, 32 bit */
219 #define	R_MIPS_TLS_TPREL64	48	/* TP-relative offset, 64 bit */
220 #define	R_MIPS_TLS_TPREL_HI16	49	/* TP-relative offset, high 16 bits */
221 #define	R_MIPS_TLS_TPREL_LO16	50	/* TP-relative offset, low 16 bits */
222 
223 #define	R_MIPS_max		51
224 
225 #define	R_TYPE(name)		__CONCAT(R_MIPS_,name)
226 
227 #define	R_MIPS16_min		100
228 #define	R_MIPS16_26		100
229 #define	R_MIPS16_GPREL		101
230 #define	R_MIPS16_GOT16		102
231 #define	R_MIPS16_CALL16		103
232 #define	R_MIPS16_HI16		104
233 #define	R_MIPS16_LO16		105
234 #define	R_MIPS16_max		106
235 
236 #define	R_MIPS_COPY		126
237 #define	R_MIPS_JUMP_SLOT	127
238 
239 /* mips dynamic tags */
240 
241 #define	DT_MIPS_RLD_VERSION	0x70000001
242 #define	DT_MIPS_TIME_STAMP	0x70000002
243 #define	DT_MIPS_ICHECKSUM	0x70000003
244 #define	DT_MIPS_IVERSION	0x70000004
245 #define	DT_MIPS_FLAGS		0x70000005
246 #define	DT_MIPS_BASE_ADDRESS	0x70000006
247 #define	DT_MIPS_CONFLICT	0x70000008
248 #define	DT_MIPS_LIBLIST		0x70000009
249 #define	DT_MIPS_CONFLICTNO	0x7000000b
250 #define	DT_MIPS_LOCAL_GOTNO	0x7000000a	/* number of local got ents */
251 #define	DT_MIPS_LIBLISTNO	0x70000010
252 #define	DT_MIPS_SYMTABNO	0x70000011	/* number of .dynsym entries */
253 #define	DT_MIPS_UNREFEXTNO	0x70000012
254 #define	DT_MIPS_GOTSYM		0x70000013	/* first dynamic sym in got */
255 #define	DT_MIPS_HIPAGENO	0x70000014
256 #define	DT_MIPS_RLD_MAP		0x70000016	/* address of loader map */
257 #define	DT_MIPS_PLTGOT		0x70000032
258 #define	DT_MIPS_RWPLT		0x70000034
259 
260 /*
261  * ELF Flags
262  */
263 #define	EF_MIPS_PIC		0x00000002	/* Contains PIC code */
264 #define	EF_MIPS_CPIC		0x00000004	/* STD PIC calling sequence */
265 #define	EF_MIPS_ABI2		0x00000020	/* N32 */
266 
267 #define	EF_MIPS_ARCH_ASE	0x0f000000	/* Architectural extensions */
268 #define	EF_MIPS_ARCH_MDMX	0x08000000	/* MDMX multimedia extension */
269 #define	EF_MIPS_ARCH_M16	0x04000000	/* MIPS-16 ISA extensions */
270 
271 #define	EF_MIPS_ARCH		0xf0000000	/* Architecture field */
272 #define	EF_MIPS_ARCH_1		0x00000000	/* -mips1 code */
273 #define	EF_MIPS_ARCH_2		0x10000000	/* -mips2 code */
274 #define	EF_MIPS_ARCH_3		0x20000000	/* -mips3 code */
275 #define	EF_MIPS_ARCH_4		0x30000000	/* -mips4 code */
276 #define	EF_MIPS_ARCH_5		0x40000000	/* -mips5 code */
277 #define	EF_MIPS_ARCH_32		0x50000000	/* -mips32 code */
278 #define	EF_MIPS_ARCH_64		0x60000000	/* -mips64 code */
279 #define	EF_MIPS_ARCH_32R2	0x70000000	/* -mips32r2 code */
280 #define	EF_MIPS_ARCH_64R2	0x80000000	/* -mips64r2 code */
281 
282 #define	EF_MIPS_ABI		0x0000f000
283 #define	EF_MIPS_ABI_O32		0x00001000
284 #define	EF_MIPS_ABI_O64		0x00002000
285 #define	EF_MIPS_ABI_EABI32	0x00003000
286 #define	EF_MIPS_ABI_EABI64	0x00004000
287 
288 #endif /* __MIPS_ELF_H */
289