elf.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /*
  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. #define compat_elf_check_arch(x) ((x)->e_machine == EM_RISCV)
  32. #define CORE_DUMP_USE_REGSET
  33. #define ELF_EXEC_PAGESIZE (PAGE_SIZE)
  34. /*
  35. * This is the location that an ET_DYN program is loaded if exec'ed. Typical
  36. * use of this is to invoke "./ld.so someprog" to test out a new version of
  37. * the loader. We need to make sure that it is out of the way of the program
  38. * that it will "exec", and that there is sufficient room for the brk.
  39. */
  40. #define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
  41. /*
  42. * This yields a mask that user programs can use to figure out what
  43. * instruction set this CPU supports. This could be done in user space,
  44. * but it's not easy, and we've already done it here.
  45. */
  46. #define ELF_HWCAP (elf_hwcap)
  47. extern unsigned long elf_hwcap;
  48. /*
  49. * This yields a string that ld.so will use to load implementation
  50. * specific libraries for optimization. This is more specific in
  51. * intent than poking at uname or /proc/cpuinfo.
  52. */
  53. #define ELF_PLATFORM (NULL)
  54. #define COMPAT_ELF_PLATFORM (NULL)
  55. #ifdef CONFIG_MMU
  56. #define ARCH_DLINFO \
  57. do { \
  58. /* \
  59. * Note that we add ulong after elf_addr_t because \
  60. * casting current->mm->context.vdso triggers a cast \
  61. * warning of cast from pointer to integer for \
  62. * COMPAT ELFCLASS32. \
  63. */ \
  64. NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  65. (elf_addr_t)(ulong)current->mm->context.vdso); \
  66. NEW_AUX_ENT(AT_L1I_CACHESIZE, \
  67. get_cache_size(1, CACHE_TYPE_INST)); \
  68. NEW_AUX_ENT(AT_L1I_CACHEGEOMETRY, \
  69. get_cache_geometry(1, CACHE_TYPE_INST)); \
  70. NEW_AUX_ENT(AT_L1D_CACHESIZE, \
  71. get_cache_size(1, CACHE_TYPE_DATA)); \
  72. NEW_AUX_ENT(AT_L1D_CACHEGEOMETRY, \
  73. get_cache_geometry(1, CACHE_TYPE_DATA)); \
  74. NEW_AUX_ENT(AT_L2_CACHESIZE, \
  75. get_cache_size(2, CACHE_TYPE_UNIFIED)); \
  76. NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
  77. get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
  78. } while (0)
  79. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
  80. struct linux_binprm;
  81. extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  82. int uses_interp);
  83. #endif /* CONFIG_MMU */
  84. #define ELF_CORE_COPY_REGS(dest, regs) \
  85. do { \
  86. *(struct user_regs_struct *)&(dest) = \
  87. *(struct user_regs_struct *)regs; \
  88. } while (0);
  89. #ifdef CONFIG_COMPAT
  90. #define SET_PERSONALITY(ex) \
  91. do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
  92. set_thread_flag(TIF_32BIT); \
  93. else \
  94. clear_thread_flag(TIF_32BIT); \
  95. if (personality(current->personality) != PER_LINUX32) \
  96. set_personality(PER_LINUX | \
  97. (current->personality & (~PER_MASK))); \
  98. } while (0)
  99. #define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)
  100. /* rv32 registers */
  101. typedef compat_ulong_t compat_elf_greg_t;
  102. typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];
  103. extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
  104. int uses_interp);
  105. #define compat_arch_setup_additional_pages \
  106. compat_arch_setup_additional_pages
  107. #endif /* CONFIG_COMPAT */
  108. #endif /* _ASM_RISCV_ELF_H */