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/cpufeature.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_FDPIC_CORE_EFLAGS 0
45 #define ELF_EXEC_PAGESIZE (PAGE_SIZE)
48 * This is the location that an ET_DYN program is loaded if exec'ed. Typical
49 * use of this is to invoke "./ld.so someprog" to test out a new version of
50 * the loader. We need to make sure that it is out of the way of the program
51 * that it will "exec", and that there is sufficient room for the brk.
53 #define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2)
57 #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
58 0x7ff >> (PAGE_SHIFT - 12) : \
59 0x3ffff >> (PAGE_SHIFT - 12))
61 #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
66 * Provides information on the availiable set of ISA extensions to userspace,
67 * via a bitmap that coorespends to each single-letter ISA extension. This is
68 * essentially defunct, but will remain for compatibility with userspace.
70 #define ELF_HWCAP riscv_get_elf_hwcap()
71 extern unsigned long elf_hwcap;
73 #define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
75 (_r)->a1 = _exec_map_addr; \
76 (_r)->a2 = _interp_map_addr; \
77 (_r)->a3 = dynamic_addr; \
81 * This yields a string that ld.so will use to load implementation
82 * specific libraries for optimization. This is more specific in
83 * intent than poking at uname or /proc/cpuinfo.
85 #define ELF_PLATFORM (NULL)
87 #define COMPAT_ELF_PLATFORM (NULL)
92 * Note that we add ulong after elf_addr_t because \
93 * casting current->mm->context.vdso triggers a cast \
94 * warning of cast from pointer to integer for \
95 * COMPAT ELFCLASS32. \
97 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
98 (elf_addr_t)(ulong)current->mm->context.vdso); \
99 NEW_AUX_ENT(AT_L1I_CACHESIZE, \
100 get_cache_size(1, CACHE_TYPE_INST)); \
101 NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
102 get_cache_geometry(1, CACHE_TYPE_INST)); \
103 NEW_AUX_ENT(AT_L1D_CACHESIZE, \
104 get_cache_size(1, CACHE_TYPE_DATA)); \
105 NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \
106 get_cache_geometry(1, CACHE_TYPE_DATA)); \
107 NEW_AUX_ENT(AT_L2_CACHESIZE, \
108 get_cache_size(2, CACHE_TYPE_UNIFIED)); \
109 NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
110 get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
111 NEW_AUX_ENT(AT_L3_CACHESIZE, \
112 get_cache_size(3, CACHE_TYPE_UNIFIED)); \
113 NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \
114 get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \
116 * Should always be nonzero unless there's a kernel bug. \
117 * If we haven't determined a sensible value to give to \
118 * userspace, omit the entry: \
120 if (likely(signal_minsigstksz)) \
121 NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \
123 NEW_AUX_ENT(AT_IGNORE, 0); \
127 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
129 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
131 #endif /* CONFIG_MMU */
133 #define ELF_CORE_COPY_REGS(dest, regs) \
135 *(struct user_regs_struct *)&(dest) = \
136 *(struct user_regs_struct *)regs; \
141 #define SET_PERSONALITY(ex) \
142 do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
143 set_thread_flag(TIF_32BIT); \
145 clear_thread_flag(TIF_32BIT); \
146 if (personality(current->personality) != PER_LINUX32) \
147 set_personality(PER_LINUX | \
148 (current->personality & (~PER_MASK))); \
151 #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
154 typedef compat_ulong_t compat_elf_greg_t;
155 typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
157 extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
159 #define compat_arch_setup_additional_pages \
160 compat_arch_setup_additional_pages
162 #endif /* CONFIG_COMPAT */
163 #endif /* _ASM_RISCV_ELF_H */