18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * S390 version 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Derived from "include/asm-i386/elf.h" 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __ASMS390_ELF_H 98c2ecf20Sopenharmony_ci#define __ASMS390_ELF_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* s390 relocations defined by the ABIs */ 128c2ecf20Sopenharmony_ci#define R_390_NONE 0 /* No reloc. */ 138c2ecf20Sopenharmony_ci#define R_390_8 1 /* Direct 8 bit. */ 148c2ecf20Sopenharmony_ci#define R_390_12 2 /* Direct 12 bit. */ 158c2ecf20Sopenharmony_ci#define R_390_16 3 /* Direct 16 bit. */ 168c2ecf20Sopenharmony_ci#define R_390_32 4 /* Direct 32 bit. */ 178c2ecf20Sopenharmony_ci#define R_390_PC32 5 /* PC relative 32 bit. */ 188c2ecf20Sopenharmony_ci#define R_390_GOT12 6 /* 12 bit GOT offset. */ 198c2ecf20Sopenharmony_ci#define R_390_GOT32 7 /* 32 bit GOT offset. */ 208c2ecf20Sopenharmony_ci#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */ 218c2ecf20Sopenharmony_ci#define R_390_COPY 9 /* Copy symbol at runtime. */ 228c2ecf20Sopenharmony_ci#define R_390_GLOB_DAT 10 /* Create GOT entry. */ 238c2ecf20Sopenharmony_ci#define R_390_JMP_SLOT 11 /* Create PLT entry. */ 248c2ecf20Sopenharmony_ci#define R_390_RELATIVE 12 /* Adjust by program base. */ 258c2ecf20Sopenharmony_ci#define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */ 268c2ecf20Sopenharmony_ci#define R_390_GOTPC 14 /* 32 bit PC rel. offset to GOT. */ 278c2ecf20Sopenharmony_ci#define R_390_GOT16 15 /* 16 bit GOT offset. */ 288c2ecf20Sopenharmony_ci#define R_390_PC16 16 /* PC relative 16 bit. */ 298c2ecf20Sopenharmony_ci#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */ 308c2ecf20Sopenharmony_ci#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */ 318c2ecf20Sopenharmony_ci#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */ 328c2ecf20Sopenharmony_ci#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */ 338c2ecf20Sopenharmony_ci#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */ 348c2ecf20Sopenharmony_ci#define R_390_64 22 /* Direct 64 bit. */ 358c2ecf20Sopenharmony_ci#define R_390_PC64 23 /* PC relative 64 bit. */ 368c2ecf20Sopenharmony_ci#define R_390_GOT64 24 /* 64 bit GOT offset. */ 378c2ecf20Sopenharmony_ci#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */ 388c2ecf20Sopenharmony_ci#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */ 398c2ecf20Sopenharmony_ci#define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */ 408c2ecf20Sopenharmony_ci#define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */ 418c2ecf20Sopenharmony_ci#define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */ 428c2ecf20Sopenharmony_ci#define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */ 438c2ecf20Sopenharmony_ci#define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */ 448c2ecf20Sopenharmony_ci#define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */ 458c2ecf20Sopenharmony_ci#define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */ 468c2ecf20Sopenharmony_ci#define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */ 478c2ecf20Sopenharmony_ci#define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */ 488c2ecf20Sopenharmony_ci#define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */ 498c2ecf20Sopenharmony_ci#define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */ 508c2ecf20Sopenharmony_ci#define R_390_TLS_GDCALL 38 /* Tag for function call in general 518c2ecf20Sopenharmony_ci dynamic TLS code. */ 528c2ecf20Sopenharmony_ci#define R_390_TLS_LDCALL 39 /* Tag for function call in local 538c2ecf20Sopenharmony_ci dynamic TLS code. */ 548c2ecf20Sopenharmony_ci#define R_390_TLS_GD32 40 /* Direct 32 bit for general dynamic 558c2ecf20Sopenharmony_ci thread local data. */ 568c2ecf20Sopenharmony_ci#define R_390_TLS_GD64 41 /* Direct 64 bit for general dynamic 578c2ecf20Sopenharmony_ci thread local data. */ 588c2ecf20Sopenharmony_ci#define R_390_TLS_GOTIE12 42 /* 12 bit GOT offset for static TLS 598c2ecf20Sopenharmony_ci block offset. */ 608c2ecf20Sopenharmony_ci#define R_390_TLS_GOTIE32 43 /* 32 bit GOT offset for static TLS 618c2ecf20Sopenharmony_ci block offset. */ 628c2ecf20Sopenharmony_ci#define R_390_TLS_GOTIE64 44 /* 64 bit GOT offset for static TLS 638c2ecf20Sopenharmony_ci block offset. */ 648c2ecf20Sopenharmony_ci#define R_390_TLS_LDM32 45 /* Direct 32 bit for local dynamic 658c2ecf20Sopenharmony_ci thread local data in LD code. */ 668c2ecf20Sopenharmony_ci#define R_390_TLS_LDM64 46 /* Direct 64 bit for local dynamic 678c2ecf20Sopenharmony_ci thread local data in LD code. */ 688c2ecf20Sopenharmony_ci#define R_390_TLS_IE32 47 /* 32 bit address of GOT entry for 698c2ecf20Sopenharmony_ci negated static TLS block offset. */ 708c2ecf20Sopenharmony_ci#define R_390_TLS_IE64 48 /* 64 bit address of GOT entry for 718c2ecf20Sopenharmony_ci negated static TLS block offset. */ 728c2ecf20Sopenharmony_ci#define R_390_TLS_IEENT 49 /* 32 bit rel. offset to GOT entry for 738c2ecf20Sopenharmony_ci negated static TLS block offset. */ 748c2ecf20Sopenharmony_ci#define R_390_TLS_LE32 50 /* 32 bit negated offset relative to 758c2ecf20Sopenharmony_ci static TLS block. */ 768c2ecf20Sopenharmony_ci#define R_390_TLS_LE64 51 /* 64 bit negated offset relative to 778c2ecf20Sopenharmony_ci static TLS block. */ 788c2ecf20Sopenharmony_ci#define R_390_TLS_LDO32 52 /* 32 bit offset relative to TLS 798c2ecf20Sopenharmony_ci block. */ 808c2ecf20Sopenharmony_ci#define R_390_TLS_LDO64 53 /* 64 bit offset relative to TLS 818c2ecf20Sopenharmony_ci block. */ 828c2ecf20Sopenharmony_ci#define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ 838c2ecf20Sopenharmony_ci#define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ 848c2ecf20Sopenharmony_ci#define R_390_TLS_TPOFF 56 /* Negate offset in static TLS 858c2ecf20Sopenharmony_ci block. */ 868c2ecf20Sopenharmony_ci#define R_390_20 57 /* Direct 20 bit. */ 878c2ecf20Sopenharmony_ci#define R_390_GOT20 58 /* 20 bit GOT offset. */ 888c2ecf20Sopenharmony_ci#define R_390_GOTPLT20 59 /* 20 bit offset to jump slot. */ 898c2ecf20Sopenharmony_ci#define R_390_TLS_GOTIE20 60 /* 20 bit GOT offset for static TLS 908c2ecf20Sopenharmony_ci block offset. */ 918c2ecf20Sopenharmony_ci/* Keep this the last entry. */ 928c2ecf20Sopenharmony_ci#define R_390_NUM 61 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* Bits present in AT_HWCAP. */ 958c2ecf20Sopenharmony_ci#define HWCAP_S390_ESAN3 1 968c2ecf20Sopenharmony_ci#define HWCAP_S390_ZARCH 2 978c2ecf20Sopenharmony_ci#define HWCAP_S390_STFLE 4 988c2ecf20Sopenharmony_ci#define HWCAP_S390_MSA 8 998c2ecf20Sopenharmony_ci#define HWCAP_S390_LDISP 16 1008c2ecf20Sopenharmony_ci#define HWCAP_S390_EIMM 32 1018c2ecf20Sopenharmony_ci#define HWCAP_S390_DFP 64 1028c2ecf20Sopenharmony_ci#define HWCAP_S390_HPAGE 128 1038c2ecf20Sopenharmony_ci#define HWCAP_S390_ETF3EH 256 1048c2ecf20Sopenharmony_ci#define HWCAP_S390_HIGH_GPRS 512 1058c2ecf20Sopenharmony_ci#define HWCAP_S390_TE 1024 1068c2ecf20Sopenharmony_ci#define HWCAP_S390_VXRS 2048 1078c2ecf20Sopenharmony_ci#define HWCAP_S390_VXRS_BCD 4096 1088c2ecf20Sopenharmony_ci#define HWCAP_S390_VXRS_EXT 8192 1098c2ecf20Sopenharmony_ci#define HWCAP_S390_GS 16384 1108c2ecf20Sopenharmony_ci#define HWCAP_S390_VXRS_EXT2 32768 1118c2ecf20Sopenharmony_ci#define HWCAP_S390_VXRS_PDE 65536 1128c2ecf20Sopenharmony_ci#define HWCAP_S390_SORT 131072 1138c2ecf20Sopenharmony_ci#define HWCAP_S390_DFLT 262144 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* Internal bits, not exposed via elf */ 1168c2ecf20Sopenharmony_ci#define HWCAP_INT_SIE 1UL 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci/* 1198c2ecf20Sopenharmony_ci * These are used to set parameters in the core dumps. 1208c2ecf20Sopenharmony_ci */ 1218c2ecf20Sopenharmony_ci#define ELF_CLASS ELFCLASS64 1228c2ecf20Sopenharmony_ci#define ELF_DATA ELFDATA2MSB 1238c2ecf20Sopenharmony_ci#define ELF_ARCH EM_S390 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* s390 specific phdr types */ 1268c2ecf20Sopenharmony_ci#define PT_S390_PGSTE 0x70000000 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci/* 1298c2ecf20Sopenharmony_ci * ELF register definitions.. 1308c2ecf20Sopenharmony_ci */ 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#include <linux/compat.h> 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#include <asm/ptrace.h> 1358c2ecf20Sopenharmony_ci#include <asm/syscall.h> 1368c2ecf20Sopenharmony_ci#include <asm/user.h> 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_citypedef s390_fp_regs elf_fpregset_t; 1398c2ecf20Sopenharmony_citypedef s390_regs elf_gregset_t; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_citypedef s390_fp_regs compat_elf_fpregset_t; 1428c2ecf20Sopenharmony_citypedef s390_compat_regs compat_elf_gregset_t; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#include <linux/sched/mm.h> /* for task_struct */ 1458c2ecf20Sopenharmony_ci#include <asm/mmu_context.h> 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#include <asm/vdso.h> 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ciextern unsigned int vdso_enabled; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci/* 1528c2ecf20Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture. 1538c2ecf20Sopenharmony_ci */ 1548c2ecf20Sopenharmony_ci#define elf_check_arch(x) \ 1558c2ecf20Sopenharmony_ci (((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \ 1568c2ecf20Sopenharmony_ci && (x)->e_ident[EI_CLASS] == ELF_CLASS) 1578c2ecf20Sopenharmony_ci#define compat_elf_check_arch(x) \ 1588c2ecf20Sopenharmony_ci (((x)->e_machine == EM_S390 || (x)->e_machine == EM_S390_OLD) \ 1598c2ecf20Sopenharmony_ci && (x)->e_ident[EI_CLASS] == ELF_CLASS) 1608c2ecf20Sopenharmony_ci#define compat_start_thread start_thread31 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistruct arch_elf_state { 1638c2ecf20Sopenharmony_ci int rc; 1648c2ecf20Sopenharmony_ci}; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#define INIT_ARCH_ELF_STATE { .rc = 0 } 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci#define arch_check_elf(ehdr, interp, interp_ehdr, state) (0) 1698c2ecf20Sopenharmony_ci#ifdef CONFIG_PGSTE 1708c2ecf20Sopenharmony_ci#define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) \ 1718c2ecf20Sopenharmony_ci({ \ 1728c2ecf20Sopenharmony_ci struct arch_elf_state *_state = state; \ 1738c2ecf20Sopenharmony_ci if ((phdr)->p_type == PT_S390_PGSTE && \ 1748c2ecf20Sopenharmony_ci !page_table_allocate_pgste && \ 1758c2ecf20Sopenharmony_ci !test_thread_flag(TIF_PGSTE) && \ 1768c2ecf20Sopenharmony_ci !current->mm->context.alloc_pgste) { \ 1778c2ecf20Sopenharmony_ci set_thread_flag(TIF_PGSTE); \ 1788c2ecf20Sopenharmony_ci set_pt_regs_flag(task_pt_regs(current), \ 1798c2ecf20Sopenharmony_ci PIF_SYSCALL_RESTART); \ 1808c2ecf20Sopenharmony_ci _state->rc = -EAGAIN; \ 1818c2ecf20Sopenharmony_ci } \ 1828c2ecf20Sopenharmony_ci _state->rc; \ 1838c2ecf20Sopenharmony_ci}) 1848c2ecf20Sopenharmony_ci#else 1858c2ecf20Sopenharmony_ci#define arch_elf_pt_proc(ehdr, phdr, elf, interp, state) \ 1868c2ecf20Sopenharmony_ci({ \ 1878c2ecf20Sopenharmony_ci (state)->rc; \ 1888c2ecf20Sopenharmony_ci}) 1898c2ecf20Sopenharmony_ci#endif 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci/* For SVR4/S390 the function pointer to be registered with `atexit` is 1928c2ecf20Sopenharmony_ci passed in R14. */ 1938c2ecf20Sopenharmony_ci#define ELF_PLAT_INIT(_r, load_addr) \ 1948c2ecf20Sopenharmony_ci do { \ 1958c2ecf20Sopenharmony_ci _r->gprs[14] = 0; \ 1968c2ecf20Sopenharmony_ci } while (0) 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci#define CORE_DUMP_USE_REGSET 1998c2ecf20Sopenharmony_ci#define ELF_EXEC_PAGESIZE PAGE_SIZE 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* This is the location that an ET_DYN program is loaded if exec'ed. Typical 2028c2ecf20Sopenharmony_ci use of this is to invoke "./ld.so someprog" to test out a new version of 2038c2ecf20Sopenharmony_ci the loader. We need to make sure that it is out of the way of the program 2048c2ecf20Sopenharmony_ci that it will "exec", and that there is sufficient room for the brk. 64-bit 2058c2ecf20Sopenharmony_ci tasks are aligned to 4GB. */ 2068c2ecf20Sopenharmony_ci#define ELF_ET_DYN_BASE (is_compat_task() ? \ 2078c2ecf20Sopenharmony_ci (STACK_TOP / 3 * 2) : \ 2088c2ecf20Sopenharmony_ci (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1)) 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* This yields a mask that user programs can use to figure out what 2118c2ecf20Sopenharmony_ci instruction set this CPU supports. */ 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ciextern unsigned long elf_hwcap; 2148c2ecf20Sopenharmony_ci#define ELF_HWCAP (elf_hwcap) 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* Internal hardware capabilities, not exposed via elf */ 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ciextern unsigned long int_hwcap; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci/* This yields a string that ld.so will use to load implementation 2218c2ecf20Sopenharmony_ci specific libraries for optimization. This is more specific in 2228c2ecf20Sopenharmony_ci intent than poking at uname or /proc/cpuinfo. 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci For the moment, we have only optimizations for the Intel generations, 2258c2ecf20Sopenharmony_ci but that could change... */ 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci#define ELF_PLATFORM_SIZE 8 2288c2ecf20Sopenharmony_ciextern char elf_platform[]; 2298c2ecf20Sopenharmony_ci#define ELF_PLATFORM (elf_platform) 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#ifndef CONFIG_COMPAT 2328c2ecf20Sopenharmony_ci#define SET_PERSONALITY(ex) \ 2338c2ecf20Sopenharmony_cido { \ 2348c2ecf20Sopenharmony_ci set_personality(PER_LINUX | \ 2358c2ecf20Sopenharmony_ci (current->personality & (~PER_MASK))); \ 2368c2ecf20Sopenharmony_ci current->thread.sys_call_table = \ 2378c2ecf20Sopenharmony_ci (unsigned long) &sys_call_table; \ 2388c2ecf20Sopenharmony_ci} while (0) 2398c2ecf20Sopenharmony_ci#else /* CONFIG_COMPAT */ 2408c2ecf20Sopenharmony_ci#define SET_PERSONALITY(ex) \ 2418c2ecf20Sopenharmony_cido { \ 2428c2ecf20Sopenharmony_ci if (personality(current->personality) != PER_LINUX32) \ 2438c2ecf20Sopenharmony_ci set_personality(PER_LINUX | \ 2448c2ecf20Sopenharmony_ci (current->personality & ~PER_MASK)); \ 2458c2ecf20Sopenharmony_ci if ((ex).e_ident[EI_CLASS] == ELFCLASS32) { \ 2468c2ecf20Sopenharmony_ci set_thread_flag(TIF_31BIT); \ 2478c2ecf20Sopenharmony_ci current->thread.sys_call_table = \ 2488c2ecf20Sopenharmony_ci (unsigned long) &sys_call_table_emu; \ 2498c2ecf20Sopenharmony_ci } else { \ 2508c2ecf20Sopenharmony_ci clear_thread_flag(TIF_31BIT); \ 2518c2ecf20Sopenharmony_ci current->thread.sys_call_table = \ 2528c2ecf20Sopenharmony_ci (unsigned long) &sys_call_table; \ 2538c2ecf20Sopenharmony_ci } \ 2548c2ecf20Sopenharmony_ci} while (0) 2558c2ecf20Sopenharmony_ci#endif /* CONFIG_COMPAT */ 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci/* 2588c2ecf20Sopenharmony_ci * Cache aliasing on the latest machines calls for a mapping granularity 2598c2ecf20Sopenharmony_ci * of 512KB for the anonymous mapping base. For 64-bit processes use a 2608c2ecf20Sopenharmony_ci * 512KB alignment and a randomization of up to 1GB. For 31-bit processes 2618c2ecf20Sopenharmony_ci * the virtual address space is limited, use no alignment and limit the 2628c2ecf20Sopenharmony_ci * randomization to 8MB. 2638c2ecf20Sopenharmony_ci * For the additional randomization of the program break use 32MB for 2648c2ecf20Sopenharmony_ci * 64-bit and 8MB for 31-bit. 2658c2ecf20Sopenharmony_ci */ 2668c2ecf20Sopenharmony_ci#define BRK_RND_MASK (is_compat_task() ? 0x7ffUL : 0x1fffUL) 2678c2ecf20Sopenharmony_ci#define MMAP_RND_MASK (is_compat_task() ? 0x7ffUL : 0x3ff80UL) 2688c2ecf20Sopenharmony_ci#define MMAP_ALIGN_MASK (is_compat_task() ? 0 : 0x7fUL) 2698c2ecf20Sopenharmony_ci#define STACK_RND_MASK MMAP_RND_MASK 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci/* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ 2728c2ecf20Sopenharmony_ci#define ARCH_DLINFO \ 2738c2ecf20Sopenharmony_cido { \ 2748c2ecf20Sopenharmony_ci if (vdso_enabled) \ 2758c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_SYSINFO_EHDR, \ 2768c2ecf20Sopenharmony_ci (unsigned long)current->mm->context.vdso_base); \ 2778c2ecf20Sopenharmony_ci} while (0) 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_cistruct linux_binprm; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 2828c2ecf20Sopenharmony_ciint arch_setup_additional_pages(struct linux_binprm *, int); 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci#endif 285