1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 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 6 */ 7 8 #ifndef _ASM_RISCV_ELF_H 9 #define _ASM_RISCV_ELF_H 10 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> 18 19 /* 20 * These are used to set parameters in the core dumps. 21 */ 22 #define ELF_ARCH EM_RISCV 23 24 #ifndef ELF_CLASS 25 #ifdef CONFIG_64BIT 26 #define ELF_CLASS ELFCLASS64 27 #else 28 #define ELF_CLASS ELFCLASS32 29 #endif 30 #endif 31 32 #define ELF_DATA ELFDATA2LSB 33 34 /* 35 * This is used to ensure we don't load something for the wrong architecture. 36 */ 37 #define elf_check_arch(x) (((x)->e_machine == EM_RISCV) && \ 38 ((x)->e_ident[EI_CLASS] == ELF_CLASS)) 39 40 extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); 41 #define compat_elf_check_arch compat_elf_check_arch 42 43 #define CORE_DUMP_USE_REGSET 44 #define ELF_EXEC_PAGESIZE (PAGE_SIZE) 45 46 /* 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. 51 */ 52 #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2) 53 54 #ifdef CONFIG_64BIT 55 #ifdef CONFIG_COMPAT 56 #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \ 57 0x7ff >> (PAGE_SHIFT - 12) : \ 58 0x3ffff >> (PAGE_SHIFT - 12)) 59 #else 60 #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) 61 #endif 62 #endif 63 64 /* 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. 68 */ 69 #define ELF_HWCAP riscv_get_elf_hwcap() 70 extern unsigned long elf_hwcap; 71 72 /* 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. 76 */ 77 #define ELF_PLATFORM (NULL) 78 79 #define COMPAT_ELF_PLATFORM (NULL) 80 81 #ifdef CONFIG_MMU 82 #define ARCH_DLINFO \ 83 do { \ 84 /* \ 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. \ 89 */ \ 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)); \ 108 /* \ 109 * Should always be nonzero unless there's a kernel bug. \ 110 * If we haven't determined a sensible value to give to \ 111 * userspace, omit the entry: \ 112 */ \ 113 if (likely(signal_minsigstksz)) \ 114 NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \ 115 else \ 116 NEW_AUX_ENT(AT_IGNORE, 0); \ 117 } while (0) 118 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 119 struct linux_binprm; 120 extern int arch_setup_additional_pages(struct linux_binprm *bprm, 121 int uses_interp); 122 #endif /* CONFIG_MMU */ 123 124 #define ELF_CORE_COPY_REGS(dest, regs) \ 125 do { \ 126 *(struct user_regs_struct *)&(dest) = \ 127 *(struct user_regs_struct *)regs; \ 128 } while (0); 129 130 #ifdef CONFIG_COMPAT 131 132 #define SET_PERSONALITY(ex) \ 133 do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \ 134 set_thread_flag(TIF_32BIT); \ 135 else \ 136 clear_thread_flag(TIF_32BIT); \ 137 if (personality(current->personality) != PER_LINUX32) \ 138 set_personality(PER_LINUX | \ 139 (current->personality & (~PER_MASK))); \ 140 } while (0) 141 142 #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2) 143 144 /* rv32 registers */ 145 typedef compat_ulong_t compat_elf_greg_t; 146 typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG]; 147 148 extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm, 149 int uses_interp); 150 #define compat_arch_setup_additional_pages \ 151 compat_arch_setup_additional_pages 152 153 #endif /* CONFIG_COMPAT */ 154 #endif /* _ASM_RISCV_ELF_H */ 155