1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
4 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
5 * Copyright (C) 2012 Regents of the University of California
8 #ifndef _ASM_RISCV_ELF_H
9 #define _ASM_RISCV_ELF_H
11 #include <uapi/linux/elf.h>
12 #include <linux/compat.h>
13 #include <uapi/asm/elf.h>
14 #include <asm/auxvec.h>
15 #include <asm/byteorder.h>
16 #include <asm/cacheinfo.h>
19 * These are used to set parameters in the core dumps.
21 #define ELF_ARCH EM_RISCV
25 #define ELF_CLASS ELFCLASS64
27 #define ELF_CLASS ELFCLASS32
31 #define ELF_DATA ELFDATA2LSB
34 * This is used to ensure we don't load something for the wrong architecture.
36 #define elf_check_arch(x) (((x)->e_machine == EM_RISCV) && \
37 ((x)->e_ident[EI_CLASS] == ELF_CLASS))
39 extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
40 #define compat_elf_check_arch compat_elf_check_arch
42 #define CORE_DUMP_USE_REGSET
43 #define ELF_EXEC_PAGESIZE (PAGE_SIZE)
46 * This is the location that an ET_DYN program is loaded if exec'ed. Typical
47 * use of this is to invoke "./ld.so someprog" to test out a new version of
48 * the loader. We need to make sure that it is out of the way of the program
49 * that it will "exec", and that there is sufficient room for the brk.
51 #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
55 #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
56 0x7ff >> (PAGE_SHIFT - 12) : \
57 0x3ffff >> (PAGE_SHIFT - 12))
59 #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
63 * This yields a mask that user programs can use to figure out what
64 * instruction set this CPU supports. This could be done in user space,
65 * but it's not easy, and we've already done it here.
67 #define ELF_HWCAP (elf_hwcap)
68 extern unsigned long elf_hwcap;
71 * This yields a string that ld.so will use to load implementation
72 * specific libraries for optimization. This is more specific in
73 * intent than poking at uname or /proc/cpuinfo.
75 #define ELF_PLATFORM (NULL)
77 #define COMPAT_ELF_PLATFORM (NULL)
83 * Note that we add ulong after elf_addr_t because \
84 * casting current->mm->context.vdso triggers a cast \
85 * warning of cast from pointer to integer for \
86 * COMPAT ELFCLASS32. \
88 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
89 (elf_addr_t)(ulong)current->mm->context.vdso); \
90 NEW_AUX_ENT(AT_L1I_CACHESIZE, \
91 get_cache_size(1, CACHE_TYPE_INST)); \
92 NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
93 get_cache_geometry(1, CACHE_TYPE_INST)); \
94 NEW_AUX_ENT(AT_L1D_CACHESIZE, \
95 get_cache_size(1, CACHE_TYPE_DATA)); \
96 NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \
97 get_cache_geometry(1, CACHE_TYPE_DATA)); \
98 NEW_AUX_ENT(AT_L2_CACHESIZE, \
99 get_cache_size(2, CACHE_TYPE_UNIFIED)); \
100 NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
101 get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
103 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
105 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
107 #endif /* CONFIG_MMU */
109 #define ELF_CORE_COPY_REGS(dest, regs) \
111 *(struct user_regs_struct *)&(dest) = \
112 *(struct user_regs_struct *)regs; \
117 #define SET_PERSONALITY(ex) \
118 do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
119 set_thread_flag(TIF_32BIT); \
121 clear_thread_flag(TIF_32BIT); \
122 if (personality(current->personality) != PER_LINUX32) \
123 set_personality(PER_LINUX | \
124 (current->personality & (~PER_MASK))); \
127 #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
130 typedef compat_ulong_t compat_elf_greg_t;
131 typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
133 extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
135 #define compat_arch_setup_additional_pages \
136 compat_arch_setup_additional_pages
138 #endif /* CONFIG_COMPAT */
139 #endif /* _ASM_RISCV_ELF_H */