18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * ELF register definitions.. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_ELF_H 68c2ecf20Sopenharmony_ci#define _ASM_POWERPC_ELF_H 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/sched.h> /* for task_struct */ 98c2ecf20Sopenharmony_ci#include <asm/page.h> 108c2ecf20Sopenharmony_ci#include <asm/string.h> 118c2ecf20Sopenharmony_ci#include <uapi/asm/elf.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* 148c2ecf20Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH) 178c2ecf20Sopenharmony_ci#define compat_elf_check_arch(x) ((x)->e_machine == EM_PPC) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define CORE_DUMP_USE_REGSET 208c2ecf20Sopenharmony_ci#define ELF_EXEC_PAGESIZE PAGE_SIZE 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * This is the base location for PIE (ET_DYN with INTERP) loads. On 248c2ecf20Sopenharmony_ci * 64-bit, this is raised to 4GB to leave the entire 32-bit address 258c2ecf20Sopenharmony_ci * space open for things that want to use the area for 32-bit pointers. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci#define ELF_ET_DYN_BASE (is_32bit_task() ? 0x000400000UL : \ 288c2ecf20Sopenharmony_ci 0x100000000UL) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* 338c2ecf20Sopenharmony_ci * Our registers are always unsigned longs, whether we're a 32 bit 348c2ecf20Sopenharmony_ci * process or 64 bit, on either a 64 bit or 32 bit kernel. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * This macro relies on elf_regs[i] having the right type to truncate to, 378c2ecf20Sopenharmony_ci * either u32 or u64. It defines the body of the elf_core_copy_regs 388c2ecf20Sopenharmony_ci * function, either the native one with elf_gregset_t elf_regs or 398c2ecf20Sopenharmony_ci * the 32-bit one with elf_gregset_t32 elf_regs. 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_ci#define PPC_ELF_CORE_COPY_REGS(elf_regs, regs) \ 428c2ecf20Sopenharmony_ci int i, nregs = min(sizeof(*regs) / sizeof(unsigned long), \ 438c2ecf20Sopenharmony_ci (size_t)ELF_NGREG); \ 448c2ecf20Sopenharmony_ci for (i = 0; i < nregs; i++) \ 458c2ecf20Sopenharmony_ci elf_regs[i] = ((unsigned long *) regs)[i]; \ 468c2ecf20Sopenharmony_ci memset(&elf_regs[i], 0, (ELF_NGREG - i) * sizeof(elf_regs[0])) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* Common routine for both 32-bit and 64-bit native processes */ 498c2ecf20Sopenharmony_cistatic inline void ppc_elf_core_copy_regs(elf_gregset_t elf_regs, 508c2ecf20Sopenharmony_ci struct pt_regs *regs) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci PPC_ELF_CORE_COPY_REGS(elf_regs, regs); 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci#define ELF_CORE_COPY_REGS(gregs, regs) ppc_elf_core_copy_regs(gregs, regs); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* ELF_HWCAP yields a mask that user programs can use to figure out what 578c2ecf20Sopenharmony_ci instruction set this cpu supports. This could be done in userspace, 588c2ecf20Sopenharmony_ci but it's not easy, and we've already done it here. */ 598c2ecf20Sopenharmony_ci# define ELF_HWCAP (cur_cpu_spec->cpu_user_features) 608c2ecf20Sopenharmony_ci# define ELF_HWCAP2 (cur_cpu_spec->cpu_user_features2) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* This yields a string that ld.so will use to load implementation 638c2ecf20Sopenharmony_ci specific libraries for optimization. This is more specific in 648c2ecf20Sopenharmony_ci intent than poking at uname or /proc/cpuinfo. */ 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define ELF_PLATFORM (cur_cpu_spec->platform) 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* While ELF_PLATFORM indicates the ISA supported by the platform, it 698c2ecf20Sopenharmony_ci * may not accurately reflect the underlying behavior of the hardware 708c2ecf20Sopenharmony_ci * (as in the case of running in Power5+ compatibility mode on a 718c2ecf20Sopenharmony_ci * Power6 machine). ELF_BASE_PLATFORM allows ld.so to load libraries 728c2ecf20Sopenharmony_ci * that are tuned for the real hardware. 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ci#define ELF_BASE_PLATFORM (powerpc_base_platform) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#ifdef __powerpc64__ 778c2ecf20Sopenharmony_ci# define ELF_PLAT_INIT(_r, load_addr) do { \ 788c2ecf20Sopenharmony_ci _r->gpr[2] = load_addr; \ 798c2ecf20Sopenharmony_ci} while (0) 808c2ecf20Sopenharmony_ci#endif /* __powerpc64__ */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#ifdef __powerpc64__ 838c2ecf20Sopenharmony_ci# define SET_PERSONALITY(ex) \ 848c2ecf20Sopenharmony_cido { \ 858c2ecf20Sopenharmony_ci if (((ex).e_flags & 0x3) == 2) \ 868c2ecf20Sopenharmony_ci set_thread_flag(TIF_ELF2ABI); \ 878c2ecf20Sopenharmony_ci else \ 888c2ecf20Sopenharmony_ci clear_thread_flag(TIF_ELF2ABI); \ 898c2ecf20Sopenharmony_ci if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ 908c2ecf20Sopenharmony_ci set_thread_flag(TIF_32BIT); \ 918c2ecf20Sopenharmony_ci else \ 928c2ecf20Sopenharmony_ci clear_thread_flag(TIF_32BIT); \ 938c2ecf20Sopenharmony_ci if (personality(current->personality) != PER_LINUX32) \ 948c2ecf20Sopenharmony_ci set_personality(PER_LINUX | \ 958c2ecf20Sopenharmony_ci (current->personality & (~PER_MASK))); \ 968c2ecf20Sopenharmony_ci} while (0) 978c2ecf20Sopenharmony_ci/* 988c2ecf20Sopenharmony_ci * An executable for which elf_read_implies_exec() returns TRUE will 998c2ecf20Sopenharmony_ci * have the READ_IMPLIES_EXEC personality flag set automatically. This 1008c2ecf20Sopenharmony_ci * is only required to work around bugs in old 32bit toolchains. Since 1018c2ecf20Sopenharmony_ci * the 64bit ABI has never had these issues dont enable the workaround 1028c2ecf20Sopenharmony_ci * even if we have an executable stack. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci# define elf_read_implies_exec(ex, exec_stk) (is_32bit_task() ? \ 1058c2ecf20Sopenharmony_ci (exec_stk == EXSTACK_DEFAULT) : 0) 1068c2ecf20Sopenharmony_ci#else 1078c2ecf20Sopenharmony_ci# define elf_read_implies_exec(ex, exec_stk) (exec_stk == EXSTACK_DEFAULT) 1088c2ecf20Sopenharmony_ci#endif /* __powerpc64__ */ 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciextern int dcache_bsize; 1118c2ecf20Sopenharmony_ciextern int icache_bsize; 1128c2ecf20Sopenharmony_ciextern int ucache_bsize; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci/* vDSO has arch_setup_additional_pages */ 1158c2ecf20Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1168c2ecf20Sopenharmony_cistruct linux_binprm; 1178c2ecf20Sopenharmony_ciextern int arch_setup_additional_pages(struct linux_binprm *bprm, 1188c2ecf20Sopenharmony_ci int uses_interp); 1198c2ecf20Sopenharmony_ci#define VDSO_AUX_ENT(a,b) NEW_AUX_ENT(a,b) 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* 1GB for 64bit, 8MB for 32bit */ 1228c2ecf20Sopenharmony_ci#define STACK_RND_MASK (is_32bit_task() ? \ 1238c2ecf20Sopenharmony_ci (0x7ff >> (PAGE_SHIFT - 12)) : \ 1248c2ecf20Sopenharmony_ci (0x3ffff >> (PAGE_SHIFT - 12))) 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#ifdef CONFIG_SPU_BASE 1278c2ecf20Sopenharmony_ci/* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */ 1288c2ecf20Sopenharmony_ci#define NT_SPU 1 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define ARCH_HAVE_EXTRA_ELF_NOTES 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci#endif /* CONFIG_SPU_BASE */ 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define get_cache_geometry(level) \ 1378c2ecf20Sopenharmony_ci (ppc64_caches.level.assoc << 16 | ppc64_caches.level.line_size) 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define ARCH_DLINFO_CACHE_GEOMETRY \ 1408c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L1I_CACHESIZE, ppc64_caches.l1i.size); \ 1418c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, get_cache_geometry(l1i)); \ 1428c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L1D_CACHESIZE, ppc64_caches.l1d.size); \ 1438c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, get_cache_geometry(l1d)); \ 1448c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L2_CACHESIZE, ppc64_caches.l2.size); \ 1458c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, get_cache_geometry(l2)); \ 1468c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L3_CACHESIZE, ppc64_caches.l3.size); \ 1478c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, get_cache_geometry(l3)) 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci#else 1508c2ecf20Sopenharmony_ci#define ARCH_DLINFO_CACHE_GEOMETRY 1518c2ecf20Sopenharmony_ci#endif 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci/* 1548c2ecf20Sopenharmony_ci * The requirements here are: 1558c2ecf20Sopenharmony_ci * - keep the final alignment of sp (sp & 0xf) 1568c2ecf20Sopenharmony_ci * - make sure the 32-bit value at the first 16 byte aligned position of 1578c2ecf20Sopenharmony_ci * AUXV is greater than 16 for glibc compatibility. 1588c2ecf20Sopenharmony_ci * AT_IGNOREPPC is used for that. 1598c2ecf20Sopenharmony_ci * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC, 1608c2ecf20Sopenharmony_ci * even if DLINFO_ARCH_ITEMS goes to zero or is undefined. 1618c2ecf20Sopenharmony_ci * update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes 1628c2ecf20Sopenharmony_ci */ 1638c2ecf20Sopenharmony_ci#define ARCH_DLINFO \ 1648c2ecf20Sopenharmony_cido { \ 1658c2ecf20Sopenharmony_ci /* Handle glibc compatibility. */ \ 1668c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ 1678c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ 1688c2ecf20Sopenharmony_ci /* Cache size items */ \ 1698c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_DCACHEBSIZE, dcache_bsize); \ 1708c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_ICACHEBSIZE, icache_bsize); \ 1718c2ecf20Sopenharmony_ci NEW_AUX_ENT(AT_UCACHEBSIZE, ucache_bsize); \ 1728c2ecf20Sopenharmony_ci VDSO_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso_base); \ 1738c2ecf20Sopenharmony_ci ARCH_DLINFO_CACHE_GEOMETRY; \ 1748c2ecf20Sopenharmony_ci} while (0) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/* Relocate the kernel image to @final_address */ 1778c2ecf20Sopenharmony_civoid relocate(unsigned long final_address); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_ELF_H */ 180