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>
17 #include <asm/hwcap.h>
20 * These are used to set parameters in the core dumps.
22 #define ELF_ARCH EM_RISCV
26 #define ELF_CLASS ELFCLASS64
28 #define ELF_CLASS ELFCLASS32
32 #define ELF_DATA ELFDATA2LSB
35 * This is used to ensure we don't load something for the wrong architecture.
37 #define elf_check_arch(x) (((x)->e_machine == EM_RISCV) && \
38 ((x)->e_ident[EI_CLASS] == ELF_CLASS))
40 extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
41 #define compat_elf_check_arch compat_elf_check_arch
43 #define CORE_DUMP_USE_REGSET
44 #define ELF_EXEC_PAGESIZE (PAGE_SIZE)
47 * This is the location that an ET_DYN program is loaded if exec'ed. Typical
48 * use of this is to invoke "./ld.so someprog" to test out a new version of
49 * the loader. We need to make sure that it is out of the way of the program
50 * that it will "exec", and that there is sufficient room for the brk.
52 #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
56 #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
57 0x7ff >> (PAGE_SHIFT - 12) : \
58 0x3ffff >> (PAGE_SHIFT - 12))
60 #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
65 * Provides information on the availiable set of ISA extensions to userspace,
66 * via a bitmap that coorespends to each single-letter ISA extension. This is
67 * essentially defunct, but will remain for compatibility with userspace.
69 #define ELF_HWCAP (elf_hwcap & ((1UL << RISCV_ISA_EXT_BASE) - 1))
70 extern unsigned long elf_hwcap;
73 * This yields a string that ld.so will use to load implementation
74 * specific libraries for optimization. This is more specific in
75 * intent than poking at uname or /proc/cpuinfo.
77 #define ELF_PLATFORM (NULL)
79 #define COMPAT_ELF_PLATFORM (NULL)
85 * Note that we add ulong after elf_addr_t because \
86 * casting current->mm->context.vdso triggers a cast \
87 * warning of cast from pointer to integer for \
88 * COMPAT ELFCLASS32. \
90 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
91 (elf_addr_t)(ulong)current->mm->context.vdso); \
92 NEW_AUX_ENT(AT_L1I_CACHESIZE, \
93 get_cache_size(1, CACHE_TYPE_INST)); \
94 NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
95 get_cache_geometry(1, CACHE_TYPE_INST)); \
96 NEW_AUX_ENT(AT_L1D_CACHESIZE, \
97 get_cache_size(1, CACHE_TYPE_DATA)); \
98 NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \
99 get_cache_geometry(1, CACHE_TYPE_DATA)); \
100 NEW_AUX_ENT(AT_L2_CACHESIZE, \
101 get_cache_size(2, CACHE_TYPE_UNIFIED)); \
102 NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
103 get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
104 NEW_AUX_ENT(AT_L3_CACHESIZE, \
105 get_cache_size(3, CACHE_TYPE_UNIFIED)); \
106 NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \
107 get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \
109 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
111 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
113 #endif /* CONFIG_MMU */
115 #define ELF_CORE_COPY_REGS(dest, regs) \
117 *(struct user_regs_struct *)&(dest) = \
118 *(struct user_regs_struct *)regs; \
123 #define SET_PERSONALITY(ex) \
124 do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
125 set_thread_flag(TIF_32BIT); \
127 clear_thread_flag(TIF_32BIT); \
128 if (personality(current->personality) != PER_LINUX32) \
129 set_personality(PER_LINUX | \
130 (current->personality & (~PER_MASK))); \
133 #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
136 typedef compat_ulong_t compat_elf_greg_t;
137 typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
139 extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
141 #define compat_arch_setup_additional_pages \
142 compat_arch_setup_additional_pages
144 #endif /* CONFIG_COMPAT */
145 #endif /* _ASM_RISCV_ELF_H */