xref: /openbmc/linux/arch/arm64/include/asm/elf.h (revision c819e2cf)
1 /*
2  * Copyright (C) 2012 ARM Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #ifndef __ASM_ELF_H
17 #define __ASM_ELF_H
18 
19 #include <asm/hwcap.h>
20 
21 /*
22  * ELF register definitions..
23  */
24 #include <asm/ptrace.h>
25 #include <asm/user.h>
26 
27 typedef unsigned long elf_greg_t;
28 
29 #define ELF_NGREG (sizeof(struct user_pt_regs) / sizeof(elf_greg_t))
30 #define ELF_CORE_COPY_REGS(dest, regs)	\
31 	*(struct user_pt_regs *)&(dest) = (regs)->user_regs;
32 
33 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
34 typedef struct user_fpsimd_state elf_fpregset_t;
35 
36 /*
37  * AArch64 static relocation types.
38  */
39 
40 /* Miscellaneous. */
41 #define R_ARM_NONE			0
42 #define R_AARCH64_NONE			256
43 
44 /* Data. */
45 #define R_AARCH64_ABS64			257
46 #define R_AARCH64_ABS32			258
47 #define R_AARCH64_ABS16			259
48 #define R_AARCH64_PREL64		260
49 #define R_AARCH64_PREL32		261
50 #define R_AARCH64_PREL16		262
51 
52 /* Instructions. */
53 #define R_AARCH64_MOVW_UABS_G0		263
54 #define R_AARCH64_MOVW_UABS_G0_NC	264
55 #define R_AARCH64_MOVW_UABS_G1		265
56 #define R_AARCH64_MOVW_UABS_G1_NC	266
57 #define R_AARCH64_MOVW_UABS_G2		267
58 #define R_AARCH64_MOVW_UABS_G2_NC	268
59 #define R_AARCH64_MOVW_UABS_G3		269
60 
61 #define R_AARCH64_MOVW_SABS_G0		270
62 #define R_AARCH64_MOVW_SABS_G1		271
63 #define R_AARCH64_MOVW_SABS_G2		272
64 
65 #define R_AARCH64_LD_PREL_LO19		273
66 #define R_AARCH64_ADR_PREL_LO21		274
67 #define R_AARCH64_ADR_PREL_PG_HI21	275
68 #define R_AARCH64_ADR_PREL_PG_HI21_NC	276
69 #define R_AARCH64_ADD_ABS_LO12_NC	277
70 #define R_AARCH64_LDST8_ABS_LO12_NC	278
71 
72 #define R_AARCH64_TSTBR14		279
73 #define R_AARCH64_CONDBR19		280
74 #define R_AARCH64_JUMP26		282
75 #define R_AARCH64_CALL26		283
76 #define R_AARCH64_LDST16_ABS_LO12_NC	284
77 #define R_AARCH64_LDST32_ABS_LO12_NC	285
78 #define R_AARCH64_LDST64_ABS_LO12_NC	286
79 #define R_AARCH64_LDST128_ABS_LO12_NC	299
80 
81 #define R_AARCH64_MOVW_PREL_G0		287
82 #define R_AARCH64_MOVW_PREL_G0_NC	288
83 #define R_AARCH64_MOVW_PREL_G1		289
84 #define R_AARCH64_MOVW_PREL_G1_NC	290
85 #define R_AARCH64_MOVW_PREL_G2		291
86 #define R_AARCH64_MOVW_PREL_G2_NC	292
87 #define R_AARCH64_MOVW_PREL_G3		293
88 
89 /*
90  * These are used to set parameters in the core dumps.
91  */
92 #define ELF_CLASS	ELFCLASS64
93 #ifdef __AARCH64EB__
94 #define ELF_DATA	ELFDATA2MSB
95 #else
96 #define ELF_DATA	ELFDATA2LSB
97 #endif
98 #define ELF_ARCH	EM_AARCH64
99 
100 /*
101  * This yields a string that ld.so will use to load implementation
102  * specific libraries for optimization.  This is more specific in
103  * intent than poking at uname or /proc/cpuinfo.
104  */
105 #define ELF_PLATFORM_SIZE	16
106 #ifdef __AARCH64EB__
107 #define ELF_PLATFORM		("aarch64_be")
108 #else
109 #define ELF_PLATFORM		("aarch64")
110 #endif
111 
112 /*
113  * This is used to ensure we don't load something for the wrong architecture.
114  */
115 #define elf_check_arch(x)		((x)->e_machine == EM_AARCH64)
116 
117 #define elf_read_implies_exec(ex,stk)	(stk != EXSTACK_DISABLE_X)
118 
119 #define CORE_DUMP_USE_REGSET
120 #define ELF_EXEC_PAGESIZE	PAGE_SIZE
121 
122 /*
123  * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
124  * use of this is to invoke "./ld.so someprog" to test out a new version of
125  * the loader.  We need to make sure that it is out of the way of the program
126  * that it will "exec", and that there is sufficient room for the brk.
127  */
128 extern unsigned long randomize_et_dyn(unsigned long base);
129 #define ELF_ET_DYN_BASE	(2 * TASK_SIZE_64 / 3)
130 
131 /*
132  * When the program starts, a1 contains a pointer to a function to be
133  * registered with atexit, as per the SVR4 ABI.  A value of 0 means we have no
134  * such handler.
135  */
136 #define ELF_PLAT_INIT(_r, load_addr)	(_r)->regs[0] = 0
137 
138 #define SET_PERSONALITY(ex)		clear_thread_flag(TIF_32BIT);
139 
140 #define ARCH_DLINFO							\
141 do {									\
142 	NEW_AUX_ENT(AT_SYSINFO_EHDR,					\
143 		    (elf_addr_t)current->mm->context.vdso);		\
144 } while (0)
145 
146 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
147 struct linux_binprm;
148 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
149 				       int uses_interp);
150 
151 /* 1GB of VA */
152 #ifdef CONFIG_COMPAT
153 #define STACK_RND_MASK			(test_thread_flag(TIF_32BIT) ? \
154 						0x7ff >> (PAGE_SHIFT - 12) : \
155 						0x3ffff >> (PAGE_SHIFT - 12))
156 #else
157 #define STACK_RND_MASK			(0x3ffff >> (PAGE_SHIFT - 12))
158 #endif
159 
160 struct mm_struct;
161 extern unsigned long arch_randomize_brk(struct mm_struct *mm);
162 #define arch_randomize_brk arch_randomize_brk
163 
164 #ifdef CONFIG_COMPAT
165 
166 #ifdef __AARCH64EB__
167 #define COMPAT_ELF_PLATFORM		("v8b")
168 #else
169 #define COMPAT_ELF_PLATFORM		("v8l")
170 #endif
171 
172 #define COMPAT_ELF_ET_DYN_BASE		(2 * TASK_SIZE_32 / 3)
173 
174 /* AArch32 registers. */
175 #define COMPAT_ELF_NGREG		18
176 typedef unsigned int			compat_elf_greg_t;
177 typedef compat_elf_greg_t		compat_elf_gregset_t[COMPAT_ELF_NGREG];
178 
179 /* AArch32 EABI. */
180 #define EF_ARM_EABI_MASK		0xff000000
181 #define compat_elf_check_arch(x)	(((x)->e_machine == EM_ARM) && \
182 					 ((x)->e_flags & EF_ARM_EABI_MASK))
183 
184 #define compat_start_thread		compat_start_thread
185 #define COMPAT_SET_PERSONALITY(ex)	set_thread_flag(TIF_32BIT);
186 #define COMPAT_ARCH_DLINFO
187 extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
188 				      int uses_interp);
189 #define compat_arch_setup_additional_pages \
190 					aarch32_setup_vectors_page
191 
192 #endif /* CONFIG_COMPAT */
193 
194 #endif
195