elf.h revision 237430
1/*	$OpenBSD: elf_abi.h,v 1.1 1998/01/28 11:14:41 pefo Exp $ */
2
3/*-
4 * Copyright (c) 1996 Per Fogelstrom
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed under OpenBSD by
17 *	Per Fogelstrom.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	JNPR: elf.h,v 1.4 2006/12/02 09:53:40 katta
34 * $FreeBSD: head/sys/mips/include/elf.h 237430 2012-06-22 06:38:31Z kib $
35 *
36 */
37
38#ifndef _MACHINE_ELF_H_
39#define	_MACHINE_ELF_H_
40
41/* Information taken from MIPS ABI supplemental */
42
43#ifndef __ELF_WORD_SIZE
44#if defined(__mips_n64)
45#define	__ELF_WORD_SIZE 64	/* Used by <sys/elf_generic.h> */
46#else
47#define	__ELF_WORD_SIZE 32	/* Used by <sys/elf_generic.h> */
48#endif
49#endif
50#include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
51#include <sys/elf64.h>	/* Definitions common to all 64 bit architectures. */
52#include <sys/elf_generic.h>
53
54#define	ELF_ARCH	EM_MIPS
55#if __ELF_WORD_SIZE == 32
56#define	ELF_ARCH32	EM_MIPS
57#endif
58#define	ELF_MACHINE_OK(x) ((x) == EM_MIPS || (x) == EM_MIPS_RS4_BE)
59
60/* Architecture dependent Segment types - p_type */
61#define	PT_MIPS_REGINFO		0x70000000 /* Register usage information */
62
63/* Architecture dependent d_tag field for Elf32_Dyn.  */
64#define	DT_MIPS_RLD_VERSION	0x70000001 /* Runtime Linker Interface ID */
65#define	DT_MIPS_TIME_STAMP	0x70000002 /* Timestamp */
66#define	DT_MIPS_ICHECKSUM	0x70000003 /* Cksum of ext str and com sizes */
67#define	DT_MIPS_IVERSION	0x70000004 /* Version string (string tbl index) */
68#define	DT_MIPS_FLAGS		0x70000005 /* Flags */
69#define	DT_MIPS_BASE_ADDRESS	0x70000006 /* Segment base address */
70#define	DT_MIPS_CONFLICT	0x70000008 /* Adr of .conflict section */
71#define	DT_MIPS_LIBLIST		0x70000009 /* Address of .liblist section */
72#define	DT_MIPS_LOCAL_GOTNO	0x7000000a /* Number of local .GOT entries */
73#define	DT_MIPS_CONFLICTNO	0x7000000b /* Number of .conflict entries */
74#define	DT_MIPS_LIBLISTNO	0x70000010 /* Number of .liblist entries */
75#define	DT_MIPS_SYMTABNO	0x70000011 /* Number of .dynsym entries */
76#define	DT_MIPS_UNREFEXTNO	0x70000012 /* First external DYNSYM */
77#define	DT_MIPS_GOTSYM		0x70000013 /* First GOT entry in .dynsym */
78#define	DT_MIPS_HIPAGENO	0x70000014 /* Number of GOT page table entries */
79#define	DT_MIPS_RLD_MAP		0x70000016 /* Address of debug map pointer */
80
81#define	DT_PROCNUM (DT_MIPS_RLD_MAP - DT_LOPROC + 1)
82
83/*
84 * Legal values for e_flags field of Elf32_Ehdr.
85 */
86#define	EF_MIPS_NOREORDER	1		/* .noreorder was used */
87#define	EF_MIPS_PIC		2		/* Contains PIC code */
88#define	EF_MIPS_CPIC		4		/* Uses PIC calling sequence */
89#define	EF_MIPS_ARCH		0xf0000000	/* MIPS architecture level */
90
91/*
92 * Mips special sections.
93 */
94#define	SHN_MIPS_ACOMMON	0xff00		/* Allocated common symbols */
95#define	SHN_MIPS_SCOMMON	0xff03		/* Small common symbols */
96#define	SHN_MIPS_SUNDEFINED	0xff04		/* Small undefined symbols */
97
98/*
99 * Legal values for sh_type field of Elf32_Shdr.
100 */
101#define	SHT_MIPS_LIBLIST	0x70000000 /* Shared objects used in link */
102#define	SHT_MIPS_CONFLICT	0x70000002 /* Conflicting symbols */
103#define	SHT_MIPS_GPTAB		0x70000003 /* Global data area sizes */
104#define	SHT_MIPS_UCODE		0x70000004 /* Reserved for SGI/MIPS compilers */
105#define	SHT_MIPS_DEBUG		0x70000005 /* MIPS ECOFF debugging information */
106#define	SHT_MIPS_REGINFO	0x70000006 /* Register usage information */
107
108/*
109 * Legal values for sh_flags field of Elf32_Shdr.
110 */
111#define	SHF_MIPS_GPREL		0x10000000 /* Must be part of global data area */
112
113/*
114 * Entries found in sections of type SHT_MIPS_GPTAB.
115 */
116typedef union {
117	struct {
118		Elf32_Word gt_current_g_value;	/* -G val used in compilation */
119		Elf32_Word gt_unused;	/* Not used */
120	} gt_header;			/* First entry in section */
121	struct {
122		Elf32_Word gt_g_value;	/* If this val were used for -G */
123		Elf32_Word gt_bytes;	/* This many bytes would be used */
124	} gt_entry;			/* Subsequent entries in section */
125} Elf32_gptab;
126typedef union {
127	struct {
128		Elf64_Word gt_current_g_value;	/* -G val used in compilation */
129		Elf64_Word gt_unused;	/* Not used */
130	} gt_header;			/* First entry in section */
131	struct {
132		Elf64_Word gt_g_value;	/* If this val were used for -G */
133		Elf64_Word gt_bytes;	/* This many bytes would be used */
134	} gt_entry;			/* Subsequent entries in section */
135} Elf64_gptab;
136
137/*
138 * Entry found in sections of type SHT_MIPS_REGINFO.
139 */
140typedef struct {
141	Elf32_Word	ri_gprmask;	/* General registers used */
142	Elf32_Word	ri_cprmask[4];	/* Coprocessor registers used */
143	Elf32_Sword	ri_gp_value;	/* $gp register value */
144} Elf32_RegInfo;
145typedef struct {
146	Elf64_Word	ri_gprmask;	/* General registers used */
147	Elf64_Word	ri_cprmask[4];	/* Coprocessor registers used */
148	Elf64_Sword	ri_gp_value;	/* $gp register value */
149} Elf64_RegInfo;
150
151
152/*
153 * Mips relocations.
154 */
155
156#define	R_MIPS_NONE	0	/* No reloc */
157#define	R_MIPS_16	1	/* Direct 16 bit */
158#define	R_MIPS_32	2	/* Direct 32 bit */
159#define	R_MIPS_REL32	3	/* PC relative 32 bit */
160#define	R_MIPS_26	4	/* Direct 26 bit shifted */
161#define	R_MIPS_HI16	5	/* High 16 bit */
162#define	R_MIPS_LO16	6	/* Low 16 bit */
163#define	R_MIPS_GPREL16	7	/* GP relative 16 bit */
164#define	R_MIPS_LITERAL	8	/* 16 bit literal entry */
165#define	R_MIPS_GOT16	9	/* 16 bit GOT entry */
166#define	R_MIPS_PC16	10	/* PC relative 16 bit */
167#define	R_MIPS_CALL16	11	/* 16 bit GOT entry for function */
168#define	R_MIPS_GPREL32	12	/* GP relative 32 bit */
169#define	R_MIPS_GOTHI16	21	/* GOT HI 16 bit */
170#define	R_MIPS_GOTLO16	22	/* GOT LO 16 bit */
171#define	R_MIPS_CALLHI16 30	/* upper 16 bit GOT entry for function */
172#define	R_MIPS_CALLLO16 31	/* lower 16 bit GOT entry for function */
173
174/*
175 * These are from the 64-bit Irix ELF ABI
176 */
177#define	R_MIPS_SHIFT5	16
178#define	R_MIPS_SHIFT6	17
179#define	R_MIPS_64	18
180#define	R_MIPS_GOT_DISP	19
181#define	R_MIPS_GOT_PAGE	20
182#define	R_MIPS_GOT_OFST	21
183#define	R_MIPS_GOT_HI16	22
184#define	R_MIPS_GOT_LO16	23
185#define	R_MIPS_SUB	24
186#define	R_MIPS_INSERT_A	25
187#define	R_MIPS_INSERT_B	26
188#define	R_MIPS_DELETE	27
189#define	R_MIPS_HIGHER	28
190#define	R_MIPS_HIGHEST	29
191#define	R_MIPS_SCN_DISP	32
192#define	R_MIPS_REL16	33
193#define	R_MIPS_ADD_IMMEDIATE 34
194#define	R_MIPS_PJUMP	35
195#define	R_MIPS_RELGOT	36
196#define	R_MIPS_JALR	37
197
198/*
199 * TLS relocations
200 */
201#define	R_MIPS_TLS_DTPMOD32	38	/* Module number 32 bit */
202#define	R_MIPS_TLS_DTPREL32	39	/* Module-relative offset 32 bit */
203#define	R_MIPS_TLS_DTPMOD64	40	/* Module number 64 bit */
204#define	R_MIPS_TLS_DTPREL64	41	/* Module-relative offset 64 bit */
205#define	R_MIPS_TLS_GD		42	/* 16 bit GOT offset for GD */
206#define	R_MIPS_TLS_LDM		43	/* 16 bit GOT offset for LDM */
207#define	R_MIPS_TLS_DTPREL_HI16	44	/* Module-relative offset, high 16 bits */
208#define	R_MIPS_TLS_DTPREL_LO16	45	/* Module-relative offset, low 16 bits */
209#define	R_MIPS_TLS_GOTTPREL	46	/* 16 bit GOT offset for IE */
210#define	R_MIPS_TLS_TPREL32	47	/* TP-relative offset, 32 bit */
211#define	R_MIPS_TLS_TPREL64	48	/* TP-relative offset, 64 bit */
212#define	R_MIPS_TLS_TPREL_HI16	49	/* TP-relative offset, high 16 bits */
213#define	R_MIPS_TLS_TPREL_LO16	50	/* TP-relative offset, low 16 bits */
214
215#define	R_MIPS_max	51
216#define	R_TYPE(name)		__CONCAT(R_MIPS_,name)
217
218/* Define "machine" characteristics */
219#if __ELF_WORD_SIZE == 32
220#define	ELF_TARG_CLASS	ELFCLASS32
221#else
222#define	ELF_TARG_CLASS	ELFCLASS64
223#endif
224#ifdef __MIPSEB__
225#define	ELF_TARG_DATA	ELFDATA2MSB
226#else
227#define ELF_TARG_DATA	ELFDATA2LSB
228#endif
229#define	ELF_TARG_MACH	EM_MIPS
230#define	ELF_TARG_VER	1
231
232/*
233 * Auxiliary vector entries for passing information to the interpreter.
234 *
235 * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
236 * but POSIX lays claim to all symbols ending with "_t".
237 */
238typedef struct {	/* Auxiliary vector entry on initial stack */
239	int	a_type;			/* Entry type. */
240	union {
241		int	a_val;		/* Integer value. */
242		void	*a_ptr;		/* Address. */
243		void	(*a_fcn)(void); /* Function pointer (not used). */
244	} a_un;
245} Elf32_Auxinfo;
246
247typedef struct {	/* Auxiliary vector entry on initial stack */
248	long	a_type;			/* Entry type. */
249	union {
250		long	a_val;		/* Integer value. */
251		void	*a_ptr;		/* Address. */
252		void	(*a_fcn)(void); /* Function pointer (not used). */
253	} a_un;
254} Elf64_Auxinfo;
255
256__ElfType(Auxinfo);
257
258/* Values for a_type. */
259#define	AT_NULL		0	/* Terminates the vector. */
260#define	AT_IGNORE	1	/* Ignored entry. */
261#define	AT_EXECFD	2	/* File descriptor of program to load. */
262#define	AT_PHDR		3	/* Program header of program already loaded. */
263#define	AT_PHENT	4	/* Size of each program header entry. */
264#define	AT_PHNUM	5	/* Number of program header entries. */
265#define	AT_PAGESZ	6	/* Page size in bytes. */
266#define	AT_BASE		7	/* Interpreter's base address. */
267#define	AT_FLAGS	8	/* Flags (unused for i386). */
268#define	AT_ENTRY	9	/* Where interpreter should transfer control. */
269#define	AT_NOTELF	10	/* Program is not ELF ?? */
270#define	AT_UID		11	/* Real uid. */
271#define	AT_EUID		12	/* Effective uid. */
272#define	AT_GID		13	/* Real gid. */
273#define	AT_EGID		14	/* Effective gid. */
274#define	AT_EXECPATH	15	/* Path to the executable. */
275#define	AT_CANARY	16	/* Canary for SSP */
276#define	AT_CANARYLEN	17	/* Length of the canary. */
277#define	AT_OSRELDATE	18	/* OSRELDATE. */
278#define	AT_NCPUS	19	/* Number of CPUs. */
279#define	AT_PAGESIZES	20	/* Pagesizes. */
280#define	AT_PAGESIZESLEN	21	/* Number of pagesizes. */
281#define	AT_TIMEKEEP	22	/* Pointer to timehands. */
282#define	AT_STACKPROT	23	/* Initial stack protection. */
283
284#define	AT_COUNT	24	/* Count of defined aux entry types. */
285
286#define	ET_DYN_LOAD_ADDR 0x0120000
287
288/*
289 * Constant to mark start of symtab/strtab saved by trampoline
290 */
291#define	SYMTAB_MAGIC	0x64656267
292
293#endif /* !_MACHINE_ELF_H_ */
294