elf.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2003 Matjaz Breskvar <[email protected]>
  4. * Copyright (C) 2010-2011 Jonas Bonn <[email protected]>
  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. /*
  16. * These are used to set parameters in the core dumps.
  17. */
  18. #define ELF_ARCH EM_RISCV
  19. #ifndef ELF_CLASS
  20. #ifdef CONFIG_64BIT
  21. #define ELF_CLASS ELFCLASS64
  22. #else
  23. #define ELF_CLASS ELFCLASS32
  24. #endif
  25. #endif
  26. #define ELF_DATA ELFDATA2LSB
  27. /*
  28. * This is used to ensure we don't load something for the wrong architecture.
  29. */
  30. #define elf_check_arch(x) (((x)->e_machine == EM_RISCV) && \
  31. ((x)->e_ident[EI_CLASS] == ELF_CLASS))
  32. extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
  33. #define compat_elf_check_arch compat_elf_check_arch
  34. #define CORE_DUMP_USE_REGSET
  35. #define ELF_EXEC_PAGESIZE (PAGE_SIZE)
  36. /*
  37. * This is the location that an ET_DYN program is loaded if exec'ed. Typical
  38. * use of this is to invoke "./ld.so someprog" to test out a new version of
  39. * the loader. We need to make sure that it is out of the way of the program
  40. * that it will "exec", and that there is sufficient room for the brk.
  41. */
  42. #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
  43. #ifdef CONFIG_64BIT
  44. #ifdef CONFIG_COMPAT
  45. #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
  46. 0x7ff >> (PAGE_SHIFT - 12) : \
  47. 0x3ffff >> (PAGE_SHIFT - 12))
  48. #else
  49. #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
  50. #endif
  51. #endif
  52. /*
  53. * This yields a mask that user programs can use to figure out what
  54. * instruction set this CPU supports. This could be done in user space,
  55. * but it's not easy, and we've already done it here.
  56. */
  57. #define ELF_HWCAP (elf_hwcap)
  58. extern unsigned long elf_hwcap;
  59. /*
  60. * This yields a string that ld.so will use to load implementation
  61. * specific libraries for optimization. This is more specific in
  62. * intent than poking at uname or /proc/cpuinfo.
  63. */
  64. #define ELF_PLATFORM (NULL)
  65. #define COMPAT_ELF_PLATFORM (NULL)
  66. #ifdef CONFIG_MMU
  67. #define ARCH_DLINFO \
  68. do { \
  69. /* \
  70. * Note that we add ulong after elf_addr_t because \
  71. * casting current->mm->context.vdso triggers a cast \
  72. * warning of cast from pointer to integer for \
  73. * COMPAT ELFCLASS32. \
  74. */ \
  75. NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  76. (elf_addr_t)(ulong)current->mm->context.vdso); \
  77. NEW_AUX_ENT(AT_L1I_CACHESIZE, \
  78. get_cache_size(1, CACHE_TYPE_INST)); \
  79. NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
  80. get_cache_geometry(1, CACHE_TYPE_INST)); \
  81. NEW_AUX_ENT(AT_L1D_CACHESIZE, \
  82. get_cache_size(1, CACHE_TYPE_DATA)); \
  83. NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \
  84. get_cache_geometry(1, CACHE_TYPE_DATA)); \
  85. NEW_AUX_ENT(AT_L2_CACHESIZE, \
  86. get_cache_size(2, CACHE_TYPE_UNIFIED)); \
  87. NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
  88. get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
  89. NEW_AUX_ENT(AT_L3_CACHESIZE, \
  90. get_cache_size(3, CACHE_TYPE_UNIFIED)); \
  91. NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \
  92. get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \
  93. } while (0)
  94. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
  95. struct linux_binprm;
  96. extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  97. int uses_interp);
  98. #endif /* CONFIG_MMU */
  99. #define ELF_CORE_COPY_REGS(dest, regs) \
  100. do { \
  101. *(struct user_regs_struct *)&(dest) = \
  102. *(struct user_regs_struct *)regs; \
  103. } while (0);
  104. #ifdef CONFIG_COMPAT
  105. #define SET_PERSONALITY(ex) \
  106. do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
  107. set_thread_flag(TIF_32BIT); \
  108. else \
  109. clear_thread_flag(TIF_32BIT); \
  110. if (personality(current->personality) != PER_LINUX32) \
  111. set_personality(PER_LINUX | \
  112. (current->personality & (~PER_MASK))); \
  113. } while (0)
  114. #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
  115. /* rv32 registers */
  116. typedef compat_ulong_t compat_elf_greg_t;
  117. typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
  118. extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
  119. int uses_interp);
  120. #define compat_arch_setup_additional_pages \
  121. compat_arch_setup_additional_pages
  122. #endif /* CONFIG_COMPAT */
  123. #endif /* _ASM_RISCV_ELF_H */