162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * ELF register definitions.. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci#ifndef _ASM_POWERPC_ELF_H 662306a36Sopenharmony_ci#define _ASM_POWERPC_ELF_H 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/sched.h> /* for task_struct */ 962306a36Sopenharmony_ci#include <asm/page.h> 1062306a36Sopenharmony_ci#include <asm/string.h> 1162306a36Sopenharmony_ci#include <uapi/asm/elf.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* 1462306a36Sopenharmony_ci * This is used to ensure we don't load something for the wrong architecture. 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH) 1762306a36Sopenharmony_ci#define compat_elf_check_arch(x) ((x)->e_machine == EM_PPC) 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define CORE_DUMP_USE_REGSET 2062306a36Sopenharmony_ci#define ELF_EXEC_PAGESIZE PAGE_SIZE 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * This is the base location for PIE (ET_DYN with INTERP) loads. On 2462306a36Sopenharmony_ci * 64-bit, this is raised to 4GB to leave the entire 32-bit address 2562306a36Sopenharmony_ci * space open for things that want to use the area for 32-bit pointers. 2662306a36Sopenharmony_ci */ 2762306a36Sopenharmony_ci#define ELF_ET_DYN_BASE (is_32bit_task() ? 0x000400000UL : \ 2862306a36Sopenharmony_ci 0x100000000UL) 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* 3362306a36Sopenharmony_ci * Our registers are always unsigned longs, whether we're a 32 bit 3462306a36Sopenharmony_ci * process or 64 bit, on either a 64 bit or 32 bit kernel. 3562306a36Sopenharmony_ci * 3662306a36Sopenharmony_ci * This macro relies on elf_regs[i] having the right type to truncate to, 3762306a36Sopenharmony_ci * either u32 or u64. It defines the body of the elf_core_copy_regs 3862306a36Sopenharmony_ci * function, either the native one with elf_gregset_t elf_regs or 3962306a36Sopenharmony_ci * the 32-bit one with elf_gregset_t32 elf_regs. 4062306a36Sopenharmony_ci */ 4162306a36Sopenharmony_ci#define PPC_ELF_CORE_COPY_REGS(elf_regs, regs) \ 4262306a36Sopenharmony_ci int i, nregs = min(sizeof(*regs) / sizeof(unsigned long), \ 4362306a36Sopenharmony_ci (size_t)ELF_NGREG); \ 4462306a36Sopenharmony_ci for (i = 0; i < nregs; i++) \ 4562306a36Sopenharmony_ci elf_regs[i] = ((unsigned long *) regs)[i]; \ 4662306a36Sopenharmony_ci memset(&elf_regs[i], 0, (ELF_NGREG - i) * sizeof(elf_regs[0])) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* Common routine for both 32-bit and 64-bit native processes */ 4962306a36Sopenharmony_cistatic inline void ppc_elf_core_copy_regs(elf_gregset_t elf_regs, 5062306a36Sopenharmony_ci struct pt_regs *regs) 5162306a36Sopenharmony_ci{ 5262306a36Sopenharmony_ci PPC_ELF_CORE_COPY_REGS(elf_regs, regs); 5362306a36Sopenharmony_ci} 5462306a36Sopenharmony_ci#define ELF_CORE_COPY_REGS(gregs, regs) ppc_elf_core_copy_regs(gregs, regs); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* ELF_HWCAP yields a mask that user programs can use to figure out what 5762306a36Sopenharmony_ci instruction set this cpu supports. This could be done in userspace, 5862306a36Sopenharmony_ci but it's not easy, and we've already done it here. */ 5962306a36Sopenharmony_ci# define ELF_HWCAP (cur_cpu_spec->cpu_user_features) 6062306a36Sopenharmony_ci# define ELF_HWCAP2 (cur_cpu_spec->cpu_user_features2) 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* This yields a string that ld.so will use to load implementation 6362306a36Sopenharmony_ci specific libraries for optimization. This is more specific in 6462306a36Sopenharmony_ci intent than poking at uname or /proc/cpuinfo. */ 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci#define ELF_PLATFORM (cur_cpu_spec->platform) 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* While ELF_PLATFORM indicates the ISA supported by the platform, it 6962306a36Sopenharmony_ci * may not accurately reflect the underlying behavior of the hardware 7062306a36Sopenharmony_ci * (as in the case of running in Power5+ compatibility mode on a 7162306a36Sopenharmony_ci * Power6 machine). ELF_BASE_PLATFORM allows ld.so to load libraries 7262306a36Sopenharmony_ci * that are tuned for the real hardware. 7362306a36Sopenharmony_ci */ 7462306a36Sopenharmony_ci#define ELF_BASE_PLATFORM (powerpc_base_platform) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#ifdef __powerpc64__ 7762306a36Sopenharmony_ci# define ELF_PLAT_INIT(_r, load_addr) do { \ 7862306a36Sopenharmony_ci _r->gpr[2] = load_addr; \ 7962306a36Sopenharmony_ci} while (0) 8062306a36Sopenharmony_ci#endif /* __powerpc64__ */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#ifdef __powerpc64__ 8362306a36Sopenharmony_ci# define SET_PERSONALITY(ex) \ 8462306a36Sopenharmony_cido { \ 8562306a36Sopenharmony_ci if (((ex).e_flags & 0x3) == 2) \ 8662306a36Sopenharmony_ci set_thread_flag(TIF_ELF2ABI); \ 8762306a36Sopenharmony_ci else \ 8862306a36Sopenharmony_ci clear_thread_flag(TIF_ELF2ABI); \ 8962306a36Sopenharmony_ci if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ 9062306a36Sopenharmony_ci set_thread_flag(TIF_32BIT); \ 9162306a36Sopenharmony_ci else \ 9262306a36Sopenharmony_ci clear_thread_flag(TIF_32BIT); \ 9362306a36Sopenharmony_ci if (personality(current->personality) != PER_LINUX32) \ 9462306a36Sopenharmony_ci set_personality(PER_LINUX | \ 9562306a36Sopenharmony_ci (current->personality & (~PER_MASK))); \ 9662306a36Sopenharmony_ci} while (0) 9762306a36Sopenharmony_ci/* 9862306a36Sopenharmony_ci * An executable for which elf_read_implies_exec() returns TRUE will 9962306a36Sopenharmony_ci * have the READ_IMPLIES_EXEC personality flag set automatically. This 10062306a36Sopenharmony_ci * is only required to work around bugs in old 32bit toolchains. Since 10162306a36Sopenharmony_ci * the 64bit ABI has never had these issues dont enable the workaround 10262306a36Sopenharmony_ci * even if we have an executable stack. 10362306a36Sopenharmony_ci */ 10462306a36Sopenharmony_ci# define elf_read_implies_exec(ex, exec_stk) (is_32bit_task() ? \ 10562306a36Sopenharmony_ci (exec_stk == EXSTACK_DEFAULT) : 0) 10662306a36Sopenharmony_ci#else 10762306a36Sopenharmony_ci# define elf_read_implies_exec(ex, exec_stk) (exec_stk == EXSTACK_DEFAULT) 10862306a36Sopenharmony_ci#endif /* __powerpc64__ */ 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciextern int dcache_bsize; 11162306a36Sopenharmony_ciextern int icache_bsize; 11262306a36Sopenharmony_ciextern int ucache_bsize; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* vDSO has arch_setup_additional_pages */ 11562306a36Sopenharmony_ci#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 11662306a36Sopenharmony_cistruct linux_binprm; 11762306a36Sopenharmony_ciextern int arch_setup_additional_pages(struct linux_binprm *bprm, 11862306a36Sopenharmony_ci int uses_interp); 11962306a36Sopenharmony_ci#define VDSO_AUX_ENT(a,b) NEW_AUX_ENT(a,b) 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/* 1GB for 64bit, 8MB for 32bit */ 12262306a36Sopenharmony_ci#define STACK_RND_MASK (is_32bit_task() ? \ 12362306a36Sopenharmony_ci (0x7ff >> (PAGE_SHIFT - 12)) : \ 12462306a36Sopenharmony_ci (0x3ffff >> (PAGE_SHIFT - 12))) 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci#ifdef CONFIG_SPU_BASE 12762306a36Sopenharmony_ci/* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */ 12862306a36Sopenharmony_ci#define NT_SPU 1 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci#define ARCH_HAVE_EXTRA_ELF_NOTES 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#endif /* CONFIG_SPU_BASE */ 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci#ifdef CONFIG_PPC64 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci#define get_cache_geometry(level) \ 13762306a36Sopenharmony_ci (ppc64_caches.level.assoc << 16 | ppc64_caches.level.line_size) 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci#define ARCH_DLINFO_CACHE_GEOMETRY \ 14062306a36Sopenharmony_ci NEW_AUX_ENT(AT_L1I_CACHESIZE, ppc64_caches.l1i.size); \ 14162306a36Sopenharmony_ci NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, get_cache_geometry(l1i)); \ 14262306a36Sopenharmony_ci NEW_AUX_ENT(AT_L1D_CACHESIZE, ppc64_caches.l1d.size); \ 14362306a36Sopenharmony_ci NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, get_cache_geometry(l1d)); \ 14462306a36Sopenharmony_ci NEW_AUX_ENT(AT_L2_CACHESIZE, ppc64_caches.l2.size); \ 14562306a36Sopenharmony_ci NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, get_cache_geometry(l2)); \ 14662306a36Sopenharmony_ci NEW_AUX_ENT(AT_L3_CACHESIZE, ppc64_caches.l3.size); \ 14762306a36Sopenharmony_ci NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, get_cache_geometry(l3)) 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci#else 15062306a36Sopenharmony_ci#define ARCH_DLINFO_CACHE_GEOMETRY 15162306a36Sopenharmony_ci#endif 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci/* 15462306a36Sopenharmony_ci * The requirements here are: 15562306a36Sopenharmony_ci * - keep the final alignment of sp (sp & 0xf) 15662306a36Sopenharmony_ci * - make sure the 32-bit value at the first 16 byte aligned position of 15762306a36Sopenharmony_ci * AUXV is greater than 16 for glibc compatibility. 15862306a36Sopenharmony_ci * AT_IGNOREPPC is used for that. 15962306a36Sopenharmony_ci * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC, 16062306a36Sopenharmony_ci * even if DLINFO_ARCH_ITEMS goes to zero or is undefined. 16162306a36Sopenharmony_ci * update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes 16262306a36Sopenharmony_ci */ 16362306a36Sopenharmony_ci#define COMMON_ARCH_DLINFO \ 16462306a36Sopenharmony_cido { \ 16562306a36Sopenharmony_ci /* Handle glibc compatibility. */ \ 16662306a36Sopenharmony_ci NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ 16762306a36Sopenharmony_ci NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ 16862306a36Sopenharmony_ci /* Cache size items */ \ 16962306a36Sopenharmony_ci NEW_AUX_ENT(AT_DCACHEBSIZE, dcache_bsize); \ 17062306a36Sopenharmony_ci NEW_AUX_ENT(AT_ICACHEBSIZE, icache_bsize); \ 17162306a36Sopenharmony_ci NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \ 17262306a36Sopenharmony_ci VDSO_AUX_ENT(AT_SYSINFO_EHDR, (unsigned long)current->mm->context.vdso);\ 17362306a36Sopenharmony_ci ARCH_DLINFO_CACHE_GEOMETRY; \ 17462306a36Sopenharmony_ci} while (0) 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci#define ARCH_DLINFO \ 17762306a36Sopenharmony_cido { \ 17862306a36Sopenharmony_ci COMMON_ARCH_DLINFO; \ 17962306a36Sopenharmony_ci NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size()); \ 18062306a36Sopenharmony_ci} while (0) 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci#define COMPAT_ARCH_DLINFO \ 18362306a36Sopenharmony_cido { \ 18462306a36Sopenharmony_ci COMMON_ARCH_DLINFO; \ 18562306a36Sopenharmony_ci NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size_compat()); \ 18662306a36Sopenharmony_ci} while (0) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci/* Relocate the kernel image to @final_address */ 18962306a36Sopenharmony_civoid relocate(unsigned long final_address); 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_cistruct func_desc { 19262306a36Sopenharmony_ci unsigned long addr; 19362306a36Sopenharmony_ci unsigned long toc; 19462306a36Sopenharmony_ci unsigned long env; 19562306a36Sopenharmony_ci}; 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci#endif /* _ASM_POWERPC_ELF_H */ 198