xref: /freebsd/sys/powerpc/include/elf.h (revision 17d6c636720d00f77e5d098daf4c278f89d84f7b)
1 /*-
2  * Copyright (c) 2001 David E. O'Brien
3  * Copyright (c) 1996-1997 John D. Polstra.
4  * All rights reserved.
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  *
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
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef _MACHINE_ELF_H_
31 #define	_MACHINE_ELF_H_ 1
32 
33 /*
34  * EABI ELF definitions for the PowerPC architecture.
35  * See "PowerPC Embedded Application Binary Interface, 32-Bit Impliementation"
36  * [ppc-eabi-1995-01.pdf] for details.
37  */
38 
39 #include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
40 
41 #define	__ELF_WORD_SIZE	32	/* Used by <sys/elf_generic.h> */
42 #include <sys/elf_generic.h>
43 
44 #define	ELF_ARCH	EM_PPC
45 
46 #define	ELF_MACHINE_OK(x) ((x) == EM_PPC)
47 
48 /*
49  * Auxiliary vector entries for passing information to the interpreter.
50  *
51  * The PowerPC supplement to the SVR4 ABI specification names this "auxv_t",
52  * but POSIX lays claim to all symbols ending with "_t".
53  */
54 
55 typedef struct {	/* Auxiliary vector entry on initial stack */
56 	int	a_type;			/* Entry type. */
57 	union {
58 		long	a_val;		/* Integer value. */
59 		void	*a_ptr;		/* Address. */
60 		void	(*a_fcn)(void);	/* Function pointer (not used). */
61 	} a_un;
62 } Elf32_Auxinfo;
63 
64 __ElfType(Auxinfo);
65 
66 /*
67  * Types of dynamic symbol hash table bucket and chain elements.
68  *
69  * This is inconsistent among 64 bit architectures, so a machine dependent
70  * typedef is required.
71  */
72 
73 typedef Elf32_Off Elf32_Hashelt;
74 
75 __ElfType(Hashelt);
76 
77 /* Values for a_type. */
78 #define	AT_NULL		0	/* Terminates the vector. */
79 #define	AT_IGNORE	1	/* Ignored entry. */
80 #define	AT_EXECFD	2	/* File descriptor of program to load. */
81 #define	AT_PHDR		3	/* Program header of program already loaded. */
82 #define	AT_PHENT	4	/* Size of each program header entry. */
83 #define	AT_PHNUM	5	/* Number of program header entries. */
84 #define	AT_PAGESZ	6	/* Page size in bytes. */
85 #define	AT_BASE		7	/* Interpreter's base address. */
86 #define	AT_FLAGS	8	/* Flags (unused for PowerPC). */
87 #define	AT_ENTRY	9	/* Where interpreter should transfer control. */
88 #define	AT_DCACHEBSIZE	10	/* Data cache block size for the processor. */
89 #define	AT_ICACHEBSIZE	11	/* Instruction cache block size for the uP. */
90 #define	AT_UCACHEBSIZE	12	/* Cache block size, or `0' if cache not unified. */
91 
92 #define	AT_COUNT	13	/* Count of defined aux entry types. */
93 
94 /* Used in John Polstra's testbed stuff. */
95 #define	AT_DEBUG	14	/* Debugging level. */
96 
97 /*
98  * Relocation types.
99  */
100 
101 #define	R_PPC_NONE		0	/* No relocation. */
102 #define	R_PPC_ADDR32		1
103 #define	R_PPC_ADDR24		2
104 #define	R_PPC_ADDR16		3
105 #define	R_PPC_ADDR16_LO		4
106 #define	R_PPC_ADDR16_HI		5
107 #define	R_PPC_ADDR16_HA		6
108 #define	R_PPC_ADDR14		7
109 #define	R_PPC_ADDR14_BRTAKEN	8
110 #define	R_PPC_ADDR14_BRNTAKEN	9
111 #define	R_PPC_REL24		10
112 #define	R_PPC_REL14		11
113 #define	R_PPC_REL14_BRTAKEN	12
114 #define	R_PPC_REL14_BRNTAKEN	13
115 #define	R_PPC_GOT16		14
116 #define	R_PPC_GOT16_LO		15
117 #define	R_PPC_GOT16_HI		16
118 #define	R_PPC_GOT16_HA		17
119 #define	R_PPC_PLTREL24		18
120 #define	R_PPC_COPY		19
121 #define	R_PPC_GLOB_DAT		20
122 #define	R_PPC_JMP_SLOT		21
123 #define	R_PPC_RELATIVE		22
124 #define	R_PPC_LOCAL24PC		23
125 #define	R_PPC_UADDR32		24
126 #define	R_PPC_UADDR16		25
127 #define	R_PPC_REL32		26
128 #define	R_PPC_PLT32		27
129 #define	R_PPC_PLTREL32		28
130 #define	R_PPC_PLT16_LO		29
131 #define	R_PPC_PLT16_HI		30
132 #define	R_PPC_PLT16_HA		31
133 #define	R_PPC_SDAREL16		32
134 #define	R_PPC_SECTOFF		33
135 #define	R_PPC_SECTOFF_LO	34
136 #define	R_PPC_SECTOFF_HI	35
137 #define	R_PPC_SECTOFF_HA	36
138 
139 #define	R_PPC_COUNT		37	/* Count of defined relocation types. */
140 
141 /*
142  * The remaining relocs are from the Embedded ELF ABI, and are not in the
143  *  SVR4 ELF ABI.
144  */
145 
146 #define	R_PPC_EMB_NADDR32	101
147 #define	R_PPC_EMB_NADDR16	102
148 #define	R_PPC_EMB_NADDR16_LO	103
149 #define	R_PPC_EMB_NADDR16_HI	104
150 #define	R_PPC_EMB_NADDR16_HA	105
151 #define	R_PPC_EMB_SDAI16	106
152 #define	R_PPC_EMB_SDA2I16	107
153 #define	R_PPC_EMB_SDA2REL	108
154 #define	R_PPC_EMB_SDA21		109
155 #define	R_PPC_EMB_MRKREF	110
156 #define	R_PPC_EMB_RELSEC16	111
157 #define	R_PPC_EMB_RELST_LO	112
158 #define	R_PPC_EMB_RELST_HI	113
159 #define	R_PPC_EMB_RELST_HA	114
160 #define	R_PPC_EMB_BIT_FLD	115
161 #define	R_PPC_EMB_RELSDA	116
162 
163 					/* Count of defined relocation types. */
164 #define	R_PPC_EMB_COUNT		(R_PPC_EMB_RELSDA - R_PPC_EMB_NADDR32 + 1)
165 
166 /* Define "machine" characteristics */
167 #define	ELF_TARG_CLASS	ELFCLASS32
168 #define	ELF_TARG_DATA	ELFDATA2MSB
169 #define	ELF_TARG_MACH	EM_PPC
170 #define	ELF_TARG_VER	1
171 
172 #ifdef _KERNEL
173 
174 /*
175  * On the PowerPC we load the dynamic linker where a userland call
176  * to mmap(0, ...) would put it.  The rationale behind this
177  * calculation is that it leaves room for the heap to grow to
178  * its maximum allowed size.
179  */
180 #define	ELF_RTLD_ADDR(vmspace) \
181     (round_page((vm_offset_t)(vmspace)->vm_daddr + maxdsiz))
182 
183 #endif /* _KERNEL */
184 #endif /* !_MACHINE_ELF_H_ */
185