18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_SH_ELF_H
38c2ecf20Sopenharmony_ci#define __ASM_SH_ELF_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/utsname.h>
68c2ecf20Sopenharmony_ci#include <asm/auxvec.h>
78c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
88c2ecf20Sopenharmony_ci#include <asm/user.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* ELF header e_flags defines */
118c2ecf20Sopenharmony_ci#define EF_SH_PIC		0x100	/* -fpic */
128c2ecf20Sopenharmony_ci#define EF_SH_FDPIC		0x8000	/* -mfdpic */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* SH (particularly SHcompact) relocation types  */
158c2ecf20Sopenharmony_ci#define	R_SH_NONE		0
168c2ecf20Sopenharmony_ci#define	R_SH_DIR32		1
178c2ecf20Sopenharmony_ci#define	R_SH_REL32		2
188c2ecf20Sopenharmony_ci#define	R_SH_DIR8WPN		3
198c2ecf20Sopenharmony_ci#define	R_SH_IND12W		4
208c2ecf20Sopenharmony_ci#define	R_SH_DIR8WPL		5
218c2ecf20Sopenharmony_ci#define	R_SH_DIR8WPZ		6
228c2ecf20Sopenharmony_ci#define	R_SH_DIR8BP		7
238c2ecf20Sopenharmony_ci#define	R_SH_DIR8W		8
248c2ecf20Sopenharmony_ci#define	R_SH_DIR8L		9
258c2ecf20Sopenharmony_ci#define	R_SH_SWITCH16		25
268c2ecf20Sopenharmony_ci#define	R_SH_SWITCH32		26
278c2ecf20Sopenharmony_ci#define	R_SH_USES		27
288c2ecf20Sopenharmony_ci#define	R_SH_COUNT		28
298c2ecf20Sopenharmony_ci#define	R_SH_ALIGN		29
308c2ecf20Sopenharmony_ci#define	R_SH_CODE		30
318c2ecf20Sopenharmony_ci#define	R_SH_DATA		31
328c2ecf20Sopenharmony_ci#define	R_SH_LABEL		32
338c2ecf20Sopenharmony_ci#define	R_SH_SWITCH8		33
348c2ecf20Sopenharmony_ci#define	R_SH_GNU_VTINHERIT	34
358c2ecf20Sopenharmony_ci#define	R_SH_GNU_VTENTRY	35
368c2ecf20Sopenharmony_ci#define	R_SH_TLS_GD_32		144
378c2ecf20Sopenharmony_ci#define	R_SH_TLS_LD_32		145
388c2ecf20Sopenharmony_ci#define	R_SH_TLS_LDO_32		146
398c2ecf20Sopenharmony_ci#define	R_SH_TLS_IE_32		147
408c2ecf20Sopenharmony_ci#define	R_SH_TLS_LE_32		148
418c2ecf20Sopenharmony_ci#define	R_SH_TLS_DTPMOD32	149
428c2ecf20Sopenharmony_ci#define	R_SH_TLS_DTPOFF32	150
438c2ecf20Sopenharmony_ci#define	R_SH_TLS_TPOFF32	151
448c2ecf20Sopenharmony_ci#define	R_SH_GOT32		160
458c2ecf20Sopenharmony_ci#define	R_SH_PLT32		161
468c2ecf20Sopenharmony_ci#define	R_SH_COPY		162
478c2ecf20Sopenharmony_ci#define	R_SH_GLOB_DAT		163
488c2ecf20Sopenharmony_ci#define	R_SH_JMP_SLOT		164
498c2ecf20Sopenharmony_ci#define	R_SH_RELATIVE		165
508c2ecf20Sopenharmony_ci#define	R_SH_GOTOFF		166
518c2ecf20Sopenharmony_ci#define	R_SH_GOTPC		167
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* FDPIC relocs */
548c2ecf20Sopenharmony_ci#define R_SH_GOT20		201
558c2ecf20Sopenharmony_ci#define R_SH_GOTOFF20		202
568c2ecf20Sopenharmony_ci#define R_SH_GOTFUNCDESC	203
578c2ecf20Sopenharmony_ci#define R_SH_GOTFUNCDESC20	204
588c2ecf20Sopenharmony_ci#define R_SH_GOTOFFFUNCDESC	205
598c2ecf20Sopenharmony_ci#define R_SH_GOTOFFFUNCDESC20	206
608c2ecf20Sopenharmony_ci#define R_SH_FUNCDESC		207
618c2ecf20Sopenharmony_ci#define R_SH_FUNCDESC_VALUE	208
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* SHmedia relocs */
648c2ecf20Sopenharmony_ci#define R_SH_IMM_LOW16		246
658c2ecf20Sopenharmony_ci#define R_SH_IMM_LOW16_PCREL	247
668c2ecf20Sopenharmony_ci#define R_SH_IMM_MEDLOW16	248
678c2ecf20Sopenharmony_ci#define R_SH_IMM_MEDLOW16_PCREL	249
688c2ecf20Sopenharmony_ci/* Keep this the last entry.  */
698c2ecf20Sopenharmony_ci#define	R_SH_NUM		256
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/*
728c2ecf20Sopenharmony_ci * ELF register definitions..
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_citypedef unsigned long elf_greg_t;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
788c2ecf20Sopenharmony_citypedef elf_greg_t elf_gregset_t[ELF_NGREG];
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_citypedef struct user_fpu_struct elf_fpregset_t;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci * These are used to set parameters in the core dumps.
848c2ecf20Sopenharmony_ci */
858c2ecf20Sopenharmony_ci#define ELF_CLASS	ELFCLASS32
868c2ecf20Sopenharmony_ci#ifdef __LITTLE_ENDIAN__
878c2ecf20Sopenharmony_ci#define ELF_DATA	ELFDATA2LSB
888c2ecf20Sopenharmony_ci#else
898c2ecf20Sopenharmony_ci#define ELF_DATA	ELFDATA2MSB
908c2ecf20Sopenharmony_ci#endif
918c2ecf20Sopenharmony_ci#define ELF_ARCH	EM_SH
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/*
948c2ecf20Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture.
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_ci#define elf_check_arch(x)		((x)->e_machine == EM_SH)
978c2ecf20Sopenharmony_ci#define elf_check_fdpic(x)		((x)->e_flags & EF_SH_FDPIC)
988c2ecf20Sopenharmony_ci#define elf_check_const_displacement(x)	((x)->e_flags & EF_SH_PIC)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * Enable dump using regset.
1028c2ecf20Sopenharmony_ci * This covers all of general/DSP/FPU regs.
1038c2ecf20Sopenharmony_ci */
1048c2ecf20Sopenharmony_ci#define CORE_DUMP_USE_REGSET
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define ELF_FDPIC_CORE_EFLAGS	EF_SH_FDPIC
1078c2ecf20Sopenharmony_ci#define ELF_EXEC_PAGESIZE	PAGE_SIZE
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
1108c2ecf20Sopenharmony_ci   use of this is to invoke "./ld.so someprog" to test out a new version of
1118c2ecf20Sopenharmony_ci   the loader.  We need to make sure that it is out of the way of the program
1128c2ecf20Sopenharmony_ci   that it will "exec", and that there is sufficient room for the brk.  */
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define ELF_ET_DYN_BASE         (2 * TASK_SIZE / 3)
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define ELF_CORE_COPY_REGS(_dest,_regs)				\
1178c2ecf20Sopenharmony_ci	memcpy((char *) &_dest, (char *) _regs,			\
1188c2ecf20Sopenharmony_ci	       sizeof(struct pt_regs));
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/* This yields a mask that user programs can use to figure out what
1218c2ecf20Sopenharmony_ci   instruction set this CPU supports.  This could be done in user space,
1228c2ecf20Sopenharmony_ci   but it's not easy, and we've already done it here.  */
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci#define ELF_HWCAP	(boot_cpu_data.flags)
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/* This yields a string that ld.so will use to load implementation
1278c2ecf20Sopenharmony_ci   specific libraries for optimization.  This is more specific in
1288c2ecf20Sopenharmony_ci   intent than poking at uname or /proc/cpuinfo.
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci   For the moment, we have only optimizations for the Intel generations,
1318c2ecf20Sopenharmony_ci   but that could change... */
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define ELF_PLATFORM	(utsname()->machine)
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define ELF_PLAT_INIT(_r, load_addr) \
1368c2ecf20Sopenharmony_ci  do { _r->regs[0]=0; _r->regs[1]=0; _r->regs[2]=0; _r->regs[3]=0; \
1378c2ecf20Sopenharmony_ci       _r->regs[4]=0; _r->regs[5]=0; _r->regs[6]=0; _r->regs[7]=0; \
1388c2ecf20Sopenharmony_ci       _r->regs[8]=0; _r->regs[9]=0; _r->regs[10]=0; _r->regs[11]=0; \
1398c2ecf20Sopenharmony_ci       _r->regs[12]=0; _r->regs[13]=0; _r->regs[14]=0; \
1408c2ecf20Sopenharmony_ci       _r->sr = SR_FD; } while (0)
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr,	\
1438c2ecf20Sopenharmony_ci			    _dynamic_addr)				\
1448c2ecf20Sopenharmony_cido {									\
1458c2ecf20Sopenharmony_ci	_r->regs[0]	= 0;						\
1468c2ecf20Sopenharmony_ci	_r->regs[1]	= 0;						\
1478c2ecf20Sopenharmony_ci	_r->regs[2]	= 0;						\
1488c2ecf20Sopenharmony_ci	_r->regs[3]	= 0;						\
1498c2ecf20Sopenharmony_ci	_r->regs[4]	= 0;						\
1508c2ecf20Sopenharmony_ci	_r->regs[5]	= 0;						\
1518c2ecf20Sopenharmony_ci	_r->regs[6]	= 0;						\
1528c2ecf20Sopenharmony_ci	_r->regs[7]	= 0;						\
1538c2ecf20Sopenharmony_ci	_r->regs[8]	= _exec_map_addr;				\
1548c2ecf20Sopenharmony_ci	_r->regs[9]	= _interp_map_addr;				\
1558c2ecf20Sopenharmony_ci	_r->regs[10]	= _dynamic_addr;				\
1568c2ecf20Sopenharmony_ci	_r->regs[11]	= 0;						\
1578c2ecf20Sopenharmony_ci	_r->regs[12]	= 0;						\
1588c2ecf20Sopenharmony_ci	_r->regs[13]	= 0;						\
1598c2ecf20Sopenharmony_ci	_r->regs[14]	= 0;						\
1608c2ecf20Sopenharmony_ci	_r->sr		= SR_FD;					\
1618c2ecf20Sopenharmony_ci} while (0)
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define SET_PERSONALITY(ex) \
1648c2ecf20Sopenharmony_ci	set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#ifdef CONFIG_VSYSCALL
1678c2ecf20Sopenharmony_ci/* vDSO has arch_setup_additional_pages */
1688c2ecf20Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1698c2ecf20Sopenharmony_cistruct linux_binprm;
1708c2ecf20Sopenharmony_ciextern int arch_setup_additional_pages(struct linux_binprm *bprm,
1718c2ecf20Sopenharmony_ci				       int uses_interp);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ciextern unsigned int vdso_enabled;
1748c2ecf20Sopenharmony_ciextern void __kernel_vsyscall;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci#define VDSO_BASE		((unsigned long)current->mm->context.vdso)
1778c2ecf20Sopenharmony_ci#define VDSO_SYM(x)		(VDSO_BASE + (unsigned long)(x))
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci#define VSYSCALL_AUX_ENT					\
1808c2ecf20Sopenharmony_ci	if (vdso_enabled)					\
1818c2ecf20Sopenharmony_ci		NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_BASE);	\
1828c2ecf20Sopenharmony_ci	else							\
1838c2ecf20Sopenharmony_ci		NEW_AUX_ENT(AT_IGNORE, 0)
1848c2ecf20Sopenharmony_ci#else
1858c2ecf20Sopenharmony_ci#define VSYSCALL_AUX_ENT	NEW_AUX_ENT(AT_IGNORE, 0)
1868c2ecf20Sopenharmony_ci#endif /* CONFIG_VSYSCALL */
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#ifdef CONFIG_SH_FPU
1898c2ecf20Sopenharmony_ci#define FPU_AUX_ENT	NEW_AUX_ENT(AT_FPUCW, FPSCR_INIT)
1908c2ecf20Sopenharmony_ci#else
1918c2ecf20Sopenharmony_ci#define FPU_AUX_ENT	NEW_AUX_ENT(AT_IGNORE, 0)
1928c2ecf20Sopenharmony_ci#endif
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ciextern int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci/* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
1978c2ecf20Sopenharmony_ci#define ARCH_DLINFO						\
1988c2ecf20Sopenharmony_cido {								\
1998c2ecf20Sopenharmony_ci	/* Optional FPU initialization */			\
2008c2ecf20Sopenharmony_ci	FPU_AUX_ENT;						\
2018c2ecf20Sopenharmony_ci								\
2028c2ecf20Sopenharmony_ci	/* Optional vsyscall entry */				\
2038c2ecf20Sopenharmony_ci	VSYSCALL_AUX_ENT;					\
2048c2ecf20Sopenharmony_ci								\
2058c2ecf20Sopenharmony_ci	/* Cache desc */					\
2068c2ecf20Sopenharmony_ci	NEW_AUX_ENT(AT_L1I_CACHESHAPE, l1i_cache_shape);	\
2078c2ecf20Sopenharmony_ci	NEW_AUX_ENT(AT_L1D_CACHESHAPE, l1d_cache_shape);	\
2088c2ecf20Sopenharmony_ci	NEW_AUX_ENT(AT_L2_CACHESHAPE, l2_cache_shape);		\
2098c2ecf20Sopenharmony_ci} while (0)
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci#endif /* __ASM_SH_ELF_H */
212