xref: /openbmc/linux/arch/s390/include/asm/elf.h (revision 0ad53fe3)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  S390 version
4  *
5  *  Derived from "include/asm-i386/elf.h"
6  */
7 
8 #ifndef __ASMS390_ELF_H
9 #define __ASMS390_ELF_H
10 
11 /* s390 relocations defined by the ABIs */
12 #define R_390_NONE		0	/* No reloc.  */
13 #define R_390_8			1	/* Direct 8 bit.  */
14 #define R_390_12		2	/* Direct 12 bit.  */
15 #define R_390_16		3	/* Direct 16 bit.  */
16 #define R_390_32		4	/* Direct 32 bit.  */
17 #define R_390_PC32		5	/* PC relative 32 bit.	*/
18 #define R_390_GOT12		6	/* 12 bit GOT offset.  */
19 #define R_390_GOT32		7	/* 32 bit GOT offset.  */
20 #define R_390_PLT32		8	/* 32 bit PC relative PLT address.  */
21 #define R_390_COPY		9	/* Copy symbol at runtime.  */
22 #define R_390_GLOB_DAT		10	/* Create GOT entry.  */
23 #define R_390_JMP_SLOT		11	/* Create PLT entry.  */
24 #define R_390_RELATIVE		12	/* Adjust by program base.  */
25 #define R_390_GOTOFF32		13	/* 32 bit offset to GOT.	 */
26 #define R_390_GOTPC		14	/* 32 bit PC rel. offset to GOT.  */
27 #define R_390_GOT16		15	/* 16 bit GOT offset.  */
28 #define R_390_PC16		16	/* PC relative 16 bit.	*/
29 #define R_390_PC16DBL		17	/* PC relative 16 bit shifted by 1.  */
30 #define R_390_PLT16DBL		18	/* 16 bit PC rel. PLT shifted by 1.  */
31 #define R_390_PC32DBL		19	/* PC relative 32 bit shifted by 1.  */
32 #define R_390_PLT32DBL		20	/* 32 bit PC rel. PLT shifted by 1.  */
33 #define R_390_GOTPCDBL		21	/* 32 bit PC rel. GOT shifted by 1.  */
34 #define R_390_64		22	/* Direct 64 bit.  */
35 #define R_390_PC64		23	/* PC relative 64 bit.	*/
36 #define R_390_GOT64		24	/* 64 bit GOT offset.  */
37 #define R_390_PLT64		25	/* 64 bit PC relative PLT address.  */
38 #define R_390_GOTENT		26	/* 32 bit PC rel. to GOT entry >> 1. */
39 #define R_390_GOTOFF16		27	/* 16 bit offset to GOT. */
40 #define R_390_GOTOFF64		28	/* 64 bit offset to GOT. */
41 #define R_390_GOTPLT12		29	/* 12 bit offset to jump slot.	*/
42 #define R_390_GOTPLT16		30	/* 16 bit offset to jump slot.	*/
43 #define R_390_GOTPLT32		31	/* 32 bit offset to jump slot.	*/
44 #define R_390_GOTPLT64		32	/* 64 bit offset to jump slot.	*/
45 #define R_390_GOTPLTENT		33	/* 32 bit rel. offset to jump slot.  */
46 #define R_390_PLTOFF16		34	/* 16 bit offset from GOT to PLT. */
47 #define R_390_PLTOFF32		35	/* 32 bit offset from GOT to PLT. */
48 #define R_390_PLTOFF64		36	/* 16 bit offset from GOT to PLT. */
49 #define R_390_TLS_LOAD		37	/* Tag for load insn in TLS code. */
50 #define R_390_TLS_GDCALL	38	/* Tag for function call in general
51                                            dynamic TLS code.  */
52 #define R_390_TLS_LDCALL	39	/* Tag for function call in local
53                                            dynamic TLS code.  */
54 #define R_390_TLS_GD32		40	/* Direct 32 bit for general dynamic
55                                            thread local data.  */
56 #define R_390_TLS_GD64		41	/* Direct 64 bit for general dynamic
57                                            thread local data.  */
58 #define R_390_TLS_GOTIE12	42	/* 12 bit GOT offset for static TLS
59                                            block offset.  */
60 #define R_390_TLS_GOTIE32	43	/* 32 bit GOT offset for static TLS
61                                            block offset.  */
62 #define R_390_TLS_GOTIE64	44	/* 64 bit GOT offset for static TLS
63                                            block offset.  */
64 #define R_390_TLS_LDM32		45	/* Direct 32 bit for local dynamic
65                                            thread local data in LD code.  */
66 #define R_390_TLS_LDM64		46	/* Direct 64 bit for local dynamic
67                                            thread local data in LD code.  */
68 #define R_390_TLS_IE32		47	/* 32 bit address of GOT entry for
69                                            negated static TLS block offset.  */
70 #define R_390_TLS_IE64		48	/* 64 bit address of GOT entry for
71                                            negated static TLS block offset.  */
72 #define R_390_TLS_IEENT		49	/* 32 bit rel. offset to GOT entry for
73                                            negated static TLS block offset.  */
74 #define R_390_TLS_LE32		50	/* 32 bit negated offset relative to
75                                            static TLS block.  */
76 #define R_390_TLS_LE64		51	/* 64 bit negated offset relative to
77                                            static TLS block.  */
78 #define R_390_TLS_LDO32		52	/* 32 bit offset relative to TLS
79                                            block.  */
80 #define R_390_TLS_LDO64		53	/* 64 bit offset relative to TLS
81                                            block.  */
82 #define R_390_TLS_DTPMOD	54	/* ID of module containing symbol.  */
83 #define R_390_TLS_DTPOFF	55	/* Offset in TLS block.  */
84 #define R_390_TLS_TPOFF		56	/* Negate offset in static TLS
85                                            block.  */
86 #define R_390_20		57	/* Direct 20 bit.  */
87 #define R_390_GOT20		58	/* 20 bit GOT offset.  */
88 #define R_390_GOTPLT20		59	/* 20 bit offset to jump slot.  */
89 #define R_390_TLS_GOTIE20	60	/* 20 bit GOT offset for static TLS
90 					   block offset.  */
91 /* Keep this the last entry.  */
92 #define R_390_NUM	61
93 
94 enum {
95 	HWCAP_NR_ESAN3		= 0,
96 	HWCAP_NR_ZARCH		= 1,
97 	HWCAP_NR_STFLE		= 2,
98 	HWCAP_NR_MSA		= 3,
99 	HWCAP_NR_LDISP		= 4,
100 	HWCAP_NR_EIMM		= 5,
101 	HWCAP_NR_DFP		= 6,
102 	HWCAP_NR_HPAGE		= 7,
103 	HWCAP_NR_ETF3EH		= 8,
104 	HWCAP_NR_HIGH_GPRS	= 9,
105 	HWCAP_NR_TE		= 10,
106 	HWCAP_NR_VXRS		= 11,
107 	HWCAP_NR_VXRS_BCD	= 12,
108 	HWCAP_NR_VXRS_EXT	= 13,
109 	HWCAP_NR_GS		= 14,
110 	HWCAP_NR_VXRS_EXT2	= 15,
111 	HWCAP_NR_VXRS_PDE	= 16,
112 	HWCAP_NR_SORT		= 17,
113 	HWCAP_NR_DFLT		= 18,
114 	HWCAP_NR_VXRS_PDE2	= 19,
115 	HWCAP_NR_NNPA		= 20,
116 	HWCAP_NR_PCI_MIO	= 21,
117 	HWCAP_NR_SIE		= 22,
118 	HWCAP_NR_MAX
119 };
120 
121 /* Bits present in AT_HWCAP. */
122 #define HWCAP_ESAN3		BIT(HWCAP_NR_ESAN3)
123 #define HWCAP_ZARCH		BIT(HWCAP_NR_ZARCH)
124 #define HWCAP_STFLE		BIT(HWCAP_NR_STFLE)
125 #define HWCAP_MSA		BIT(HWCAP_NR_MSA)
126 #define HWCAP_LDISP		BIT(HWCAP_NR_LDISP)
127 #define HWCAP_EIMM		BIT(HWCAP_NR_EIMM)
128 #define HWCAP_DFP		BIT(HWCAP_NR_DFP)
129 #define HWCAP_HPAGE		BIT(HWCAP_NR_HPAGE)
130 #define HWCAP_ETF3EH		BIT(HWCAP_NR_ETF3EH)
131 #define HWCAP_HIGH_GPRS		BIT(HWCAP_NR_HIGH_GPRS)
132 #define HWCAP_TE		BIT(HWCAP_NR_TE)
133 #define HWCAP_VXRS		BIT(HWCAP_NR_VXRS)
134 #define HWCAP_VXRS_BCD		BIT(HWCAP_NR_VXRS_BCD)
135 #define HWCAP_VXRS_EXT		BIT(HWCAP_NR_VXRS_EXT)
136 #define HWCAP_GS		BIT(HWCAP_NR_GS)
137 #define HWCAP_VXRS_EXT2		BIT(HWCAP_NR_VXRS_EXT2)
138 #define HWCAP_VXRS_PDE		BIT(HWCAP_NR_VXRS_PDE)
139 #define HWCAP_SORT		BIT(HWCAP_NR_SORT)
140 #define HWCAP_DFLT		BIT(HWCAP_NR_DFLT)
141 #define HWCAP_VXRS_PDE2		BIT(HWCAP_NR_VXRS_PDE2)
142 #define HWCAP_NNPA		BIT(HWCAP_NR_NNPA)
143 #define HWCAP_PCI_MIO		BIT(HWCAP_NR_PCI_MIO)
144 #define HWCAP_SIE		BIT(HWCAP_NR_SIE)
145 
146 /*
147  * These are used to set parameters in the core dumps.
148  */
149 #define ELF_CLASS	ELFCLASS64
150 #define ELF_DATA	ELFDATA2MSB
151 #define ELF_ARCH	EM_S390
152 
153 /* s390 specific phdr types */
154 #define PT_S390_PGSTE	0x70000000
155 
156 /*
157  * ELF register definitions..
158  */
159 
160 #include <linux/compat.h>
161 
162 #include <asm/ptrace.h>
163 #include <asm/syscall.h>
164 #include <asm/user.h>
165 
166 typedef s390_fp_regs elf_fpregset_t;
167 typedef s390_regs elf_gregset_t;
168 
169 typedef s390_fp_regs compat_elf_fpregset_t;
170 typedef s390_compat_regs compat_elf_gregset_t;
171 
172 #include <linux/sched/mm.h>	/* for task_struct */
173 #include <asm/mmu_context.h>
174 
175 /*
176  * This is used to ensure we don't load something for the wrong architecture.
177  */
178 #define elf_check_arch(x) \
179 	(((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \
180          && (x)->e_ident[EI_CLASS] == ELF_CLASS)
181 #define compat_elf_check_arch(x) \
182 	(((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \
183 	 && (x)->e_ident[EI_CLASS] == ELF_CLASS)
184 #define compat_start_thread	start_thread31
185 
186 struct arch_elf_state {
187 	int rc;
188 };
189 
190 #define INIT_ARCH_ELF_STATE { .rc = 0 }
191 
192 #define arch_check_elf(ehdr, interp, interp_ehdr, state) (0)
193 #ifdef CONFIG_PGSTE
194 #define arch_elf_pt_proc(ehdr, phdr, elf, interp, state)	\
195 ({								\
196 	struct arch_elf_state *_state = state;			\
197 	if ((phdr)->p_type == PT_S390_PGSTE &&			\
198 	    !page_table_allocate_pgste &&			\
199 	    !test_thread_flag(TIF_PGSTE) &&			\
200 	    !current->mm->context.alloc_pgste) {		\
201 		set_thread_flag(TIF_PGSTE);			\
202 		set_pt_regs_flag(task_pt_regs(current),		\
203 				 PIF_EXECVE_PGSTE_RESTART);	\
204 		_state->rc = -EAGAIN;				\
205 	}							\
206 	_state->rc;						\
207 })
208 #else
209 #define arch_elf_pt_proc(ehdr, phdr, elf, interp, state)	\
210 ({								\
211 	(state)->rc;						\
212 })
213 #endif
214 
215 /* For SVR4/S390 the function pointer to be registered with `atexit` is
216    passed in R14. */
217 #define ELF_PLAT_INIT(_r, load_addr) \
218 	do { \
219 		_r->gprs[14] = 0; \
220 	} while (0)
221 
222 #define CORE_DUMP_USE_REGSET
223 #define ELF_EXEC_PAGESIZE	PAGE_SIZE
224 
225 /* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
226    use of this is to invoke "./ld.so someprog" to test out a new version of
227    the loader.  We need to make sure that it is out of the way of the program
228    that it will "exec", and that there is sufficient room for the brk. 64-bit
229    tasks are aligned to 4GB. */
230 #define ELF_ET_DYN_BASE (is_compat_task() ? \
231 				(STACK_TOP / 3 * 2) : \
232 				(STACK_TOP / 3 * 2) & ~((1UL << 32) - 1))
233 
234 /* This yields a mask that user programs can use to figure out what
235    instruction set this CPU supports. */
236 
237 extern unsigned long elf_hwcap;
238 #define ELF_HWCAP (elf_hwcap)
239 
240 /* This yields a string that ld.so will use to load implementation
241    specific libraries for optimization.  This is more specific in
242    intent than poking at uname or /proc/cpuinfo.
243 
244    For the moment, we have only optimizations for the Intel generations,
245    but that could change... */
246 
247 #define ELF_PLATFORM_SIZE 8
248 extern char elf_platform[];
249 #define ELF_PLATFORM (elf_platform)
250 
251 #ifndef CONFIG_COMPAT
252 #define SET_PERSONALITY(ex) \
253 do {								\
254 	set_personality(PER_LINUX |				\
255 		(current->personality & (~PER_MASK)));		\
256 	current->thread.sys_call_table = sys_call_table;	\
257 } while (0)
258 #else /* CONFIG_COMPAT */
259 #define SET_PERSONALITY(ex)					\
260 do {								\
261 	if (personality(current->personality) != PER_LINUX32)	\
262 		set_personality(PER_LINUX |			\
263 			(current->personality & ~PER_MASK));	\
264 	if ((ex).e_ident[EI_CLASS] == ELFCLASS32) {		\
265 		set_thread_flag(TIF_31BIT);			\
266 		current->thread.sys_call_table =		\
267 			sys_call_table_emu;			\
268 	} else {						\
269 		clear_thread_flag(TIF_31BIT);			\
270 		current->thread.sys_call_table =		\
271 			sys_call_table;				\
272 	}							\
273 } while (0)
274 #endif /* CONFIG_COMPAT */
275 
276 /*
277  * Cache aliasing on the latest machines calls for a mapping granularity
278  * of 512KB for the anonymous mapping base. For 64-bit processes use a
279  * 512KB alignment and a randomization of up to 1GB. For 31-bit processes
280  * the virtual address space is limited, use no alignment and limit the
281  * randomization to 8MB.
282  * For the additional randomization of the program break use 32MB for
283  * 64-bit and 8MB for 31-bit.
284  */
285 #define BRK_RND_MASK	(is_compat_task() ? 0x7ffUL : 0x1fffUL)
286 #define MMAP_RND_MASK	(is_compat_task() ? 0x7ffUL : 0x3ff80UL)
287 #define MMAP_ALIGN_MASK	(is_compat_task() ? 0 : 0x7fUL)
288 #define STACK_RND_MASK	MMAP_RND_MASK
289 
290 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
291 #define ARCH_DLINFO							\
292 do {									\
293 	NEW_AUX_ENT(AT_SYSINFO_EHDR,					\
294 		    (unsigned long)current->mm->context.vdso_base);	\
295 } while (0)
296 
297 struct linux_binprm;
298 
299 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
300 int arch_setup_additional_pages(struct linux_binprm *, int);
301 
302 #endif
303