elf.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #ifndef _ASM_RISCV_ELF_H
  8. #define _ASM_RISCV_ELF_H
  9. #include <uapi/linux/elf.h>
  10. #include <linux/compat.h>
  11. #include <uapi/asm/elf.h>
  12. #include <asm/auxvec.h>
  13. #include <asm/byteorder.h>
  14. #include <asm/cacheinfo.h>
  15. #include <asm/cpufeature.h>
  16. /*
  17. * These are used to set parameters in the core dumps.
  18. */
  19. #define ELF_ARCH EM_RISCV
  20. #ifndef ELF_CLASS
  21. #ifdef CONFIG_64BIT
  22. #define ELF_CLASS ELFCLASS64
  23. #else
  24. #define ELF_CLASS ELFCLASS32
  25. #endif
  26. #endif
  27. #define ELF_DATA ELFDATA2LSB
  28. /*
  29. * This is used to ensure we don't load something for the wrong architecture.
  30. */
  31. #define elf_check_arch(x) (((x)->e_machine == EM_RISCV) && \
  32. ((x)->e_ident[EI_CLASS] == ELF_CLASS))
  33. extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
  34. #define compat_elf_check_arch compat_elf_check_arch
  35. #define CORE_DUMP_USE_REGSET
  36. #define ELF_FDPIC_CORE_EFLAGS 0
  37. #define ELF_EXEC_PAGESIZE (PAGE_SIZE)
  38. /*
  39. * This is the location that an ET_DYN program is loaded if exec'ed. Typical
  40. * use of this is to invoke "./ld.so someprog" to test out a new version of
  41. * the loader. We need to make sure that it is out of the way of the program
  42. * that it will "exec", and that there is sufficient room for the brk.
  43. */
  44. #define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2)
  45. #ifdef CONFIG_64BIT
  46. #define STACK_RND_MASK (is_compat_task() ? \
  47. 0x7ff >> (PAGE_SHIFT - 12) : \
  48. 0x3ffff >> (PAGE_SHIFT - 12))
  49. #endif
  50. /*
  51. * Provides information on the availiable set of ISA extensions to userspace,
  52. * via a bitmap that coorespends to each single-letter ISA extension. This is
  53. * essentially defunct, but will remain for compatibility with userspace.
  54. */
  55. #define ELF_HWCAP riscv_get_elf_hwcap()
  56. extern unsigned long elf_hwcap;
  57. #define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
  58. do { \
  59. (_r)->a1 = _exec_map_addr; \
  60. (_r)->a2 = _interp_map_addr; \
  61. (_r)->a3 = dynamic_addr; \
  62. } while (0)
  63. /*
  64. * This yields a string that ld.so will use to load implementation
  65. * specific libraries for optimization. This is more specific in
  66. * intent than poking at uname or /proc/cpuinfo.
  67. */
  68. #define ELF_PLATFORM (NULL)
  69. #define COMPAT_ELF_PLATFORM (NULL)
  70. #define ARCH_DLINFO \
  71. do { \
  72. /* \
  73. * Note that we add ulong after elf_addr_t because \
  74. * casting current->mm->context.vdso triggers a cast \
  75. * warning of cast from pointer to integer for \
  76. * COMPAT ELFCLASS32. \
  77. */ \
  78. NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  79. (elf_addr_t)(ulong)current->mm->context.vdso); \
  80. NEW_AUX_ENT(AT_L1I_CACHESIZE, \
  81. get_cache_size(1, CACHE_TYPE_INST)); \
  82. NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
  83. get_cache_geometry(1, CACHE_TYPE_INST)); \
  84. NEW_AUX_ENT(AT_L1D_CACHESIZE, \
  85. get_cache_size(1, CACHE_TYPE_DATA)); \
  86. NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \
  87. get_cache_geometry(1, CACHE_TYPE_DATA)); \
  88. NEW_AUX_ENT(AT_L2_CACHESIZE, \
  89. get_cache_size(2, CACHE_TYPE_UNIFIED)); \
  90. NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
  91. get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
  92. NEW_AUX_ENT(AT_L3_CACHESIZE, \
  93. get_cache_size(3, CACHE_TYPE_UNIFIED)); \
  94. NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \
  95. get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \
  96. /* \
  97. * Should always be nonzero unless there's a kernel bug. \
  98. * If we haven't determined a sensible value to give to \
  99. * userspace, omit the entry: \
  100. */ \
  101. if (likely(signal_minsigstksz)) \
  102. NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \
  103. else \
  104. NEW_AUX_ENT(AT_IGNORE, 0); \
  105. } while (0)
  106. #ifdef CONFIG_MMU
  107. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
  108. struct linux_binprm;
  109. extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  110. int uses_interp);
  111. #endif /* CONFIG_MMU */
  112. #define ELF_CORE_COPY_REGS(dest, regs) \
  113. do { \
  114. *(struct user_regs_struct *)&(dest) = \
  115. *(struct user_regs_struct *)regs; \
  116. } while (0);
  117. #ifdef CONFIG_COMPAT
  118. #define SET_PERSONALITY(ex) \
  119. do { set_compat_task((ex).e_ident[EI_CLASS] == ELFCLASS32); \
  120. if (personality(current->personality) != PER_LINUX32) \
  121. set_personality(PER_LINUX | \
  122. (current->personality & (~PER_MASK))); \
  123. } while (0)
  124. #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
  125. /* rv32 registers */
  126. typedef compat_ulong_t compat_elf_greg_t;
  127. typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
  128. extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
  129. int uses_interp);
  130. #define compat_arch_setup_additional_pages \
  131. compat_arch_setup_additional_pages
  132. #endif /* CONFIG_COMPAT */
  133. #endif /* _ASM_RISCV_ELF_H */