elf.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * include/asm-xtensa/elf.h
  3. *
  4. * ELF register definitions
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2001 - 2005 Tensilica Inc.
  11. */
  12. #ifndef _XTENSA_ELF_H
  13. #define _XTENSA_ELF_H
  14. #include <asm/ptrace.h>
  15. /* Xtensa processor ELF architecture-magic number */
  16. #define EM_XTENSA 94
  17. #define EM_XTENSA_OLD 0xABC7
  18. /* Xtensa relocations defined by the ABIs */
  19. #define R_XTENSA_NONE 0
  20. #define R_XTENSA_32 1
  21. #define R_XTENSA_RTLD 2
  22. #define R_XTENSA_GLOB_DAT 3
  23. #define R_XTENSA_JMP_SLOT 4
  24. #define R_XTENSA_RELATIVE 5
  25. #define R_XTENSA_PLT 6
  26. #define R_XTENSA_OP0 8
  27. #define R_XTENSA_OP1 9
  28. #define R_XTENSA_OP2 10
  29. #define R_XTENSA_ASM_EXPAND 11
  30. #define R_XTENSA_ASM_SIMPLIFY 12
  31. #define R_XTENSA_GNU_VTINHERIT 15
  32. #define R_XTENSA_GNU_VTENTRY 16
  33. #define R_XTENSA_DIFF8 17
  34. #define R_XTENSA_DIFF16 18
  35. #define R_XTENSA_DIFF32 19
  36. #define R_XTENSA_SLOT0_OP 20
  37. #define R_XTENSA_SLOT1_OP 21
  38. #define R_XTENSA_SLOT2_OP 22
  39. #define R_XTENSA_SLOT3_OP 23
  40. #define R_XTENSA_SLOT4_OP 24
  41. #define R_XTENSA_SLOT5_OP 25
  42. #define R_XTENSA_SLOT6_OP 26
  43. #define R_XTENSA_SLOT7_OP 27
  44. #define R_XTENSA_SLOT8_OP 28
  45. #define R_XTENSA_SLOT9_OP 29
  46. #define R_XTENSA_SLOT10_OP 30
  47. #define R_XTENSA_SLOT11_OP 31
  48. #define R_XTENSA_SLOT12_OP 32
  49. #define R_XTENSA_SLOT13_OP 33
  50. #define R_XTENSA_SLOT14_OP 34
  51. #define R_XTENSA_SLOT0_ALT 35
  52. #define R_XTENSA_SLOT1_ALT 36
  53. #define R_XTENSA_SLOT2_ALT 37
  54. #define R_XTENSA_SLOT3_ALT 38
  55. #define R_XTENSA_SLOT4_ALT 39
  56. #define R_XTENSA_SLOT5_ALT 40
  57. #define R_XTENSA_SLOT6_ALT 41
  58. #define R_XTENSA_SLOT7_ALT 42
  59. #define R_XTENSA_SLOT8_ALT 43
  60. #define R_XTENSA_SLOT9_ALT 44
  61. #define R_XTENSA_SLOT10_ALT 45
  62. #define R_XTENSA_SLOT11_ALT 46
  63. #define R_XTENSA_SLOT12_ALT 47
  64. #define R_XTENSA_SLOT13_ALT 48
  65. #define R_XTENSA_SLOT14_ALT 49
  66. /* ELF register definitions. This is needed for core dump support. */
  67. /*
  68. * elf_gregset_t contains the application-level state in the following order:
  69. * Processor info: config_version, cpuxy
  70. * Processor state: pc, ps, exccause, excvaddr, wb, ws,
  71. * lbeg, lend, lcount, sar
  72. * GP regs: ar0 - arXX
  73. */
  74. typedef unsigned long elf_greg_t;
  75. typedef struct {
  76. elf_greg_t xchal_config_id0;
  77. elf_greg_t xchal_config_id1;
  78. elf_greg_t cpux;
  79. elf_greg_t cpuy;
  80. elf_greg_t pc;
  81. elf_greg_t ps;
  82. elf_greg_t exccause;
  83. elf_greg_t excvaddr;
  84. elf_greg_t windowbase;
  85. elf_greg_t windowstart;
  86. elf_greg_t lbeg;
  87. elf_greg_t lend;
  88. elf_greg_t lcount;
  89. elf_greg_t sar;
  90. elf_greg_t syscall;
  91. elf_greg_t ar[64];
  92. } xtensa_gregset_t;
  93. #define ELF_NGREG (sizeof(xtensa_gregset_t) / sizeof(elf_greg_t))
  94. typedef elf_greg_t elf_gregset_t[ELF_NGREG];
  95. /*
  96. * Compute the size of the coprocessor and extra state layout (register info)
  97. * table (in bytes).
  98. * This is actually the maximum size of the table, as opposed to the size,
  99. * which is available from the _xtensa_reginfo_table_size global variable.
  100. *
  101. * (See also arch/xtensa/kernel/coprocessor.S)
  102. *
  103. */
  104. #ifndef XCHAL_EXTRA_SA_CONTENTS_LIBDB_NUM
  105. # define XTENSA_CPE_LTABLE_SIZE 0
  106. #else
  107. # define XTENSA_CPE_SEGMENT(num) (num ? (1+num) : 0)
  108. # define XTENSA_CPE_LTABLE_ENTRIES \
  109. ( XTENSA_CPE_SEGMENT(XCHAL_EXTRA_SA_CONTENTS_LIBDB_NUM) \
  110. + XTENSA_CPE_SEGMENT(XCHAL_CP0_SA_CONTENTS_LIBDB_NUM) \
  111. + XTENSA_CPE_SEGMENT(XCHAL_CP1_SA_CONTENTS_LIBDB_NUM) \
  112. + XTENSA_CPE_SEGMENT(XCHAL_CP2_SA_CONTENTS_LIBDB_NUM) \
  113. + XTENSA_CPE_SEGMENT(XCHAL_CP3_SA_CONTENTS_LIBDB_NUM) \
  114. + XTENSA_CPE_SEGMENT(XCHAL_CP4_SA_CONTENTS_LIBDB_NUM) \
  115. + XTENSA_CPE_SEGMENT(XCHAL_CP5_SA_CONTENTS_LIBDB_NUM) \
  116. + XTENSA_CPE_SEGMENT(XCHAL_CP6_SA_CONTENTS_LIBDB_NUM) \
  117. + XTENSA_CPE_SEGMENT(XCHAL_CP7_SA_CONTENTS_LIBDB_NUM) \
  118. + 1 /* final entry */ \
  119. )
  120. # define XTENSA_CPE_LTABLE_SIZE (XTENSA_CPE_LTABLE_ENTRIES * 8)
  121. #endif
  122. /*
  123. * Instantiations of the elf_fpregset_t type contain, in most
  124. * architectures, the floating point (FPU) register set.
  125. * For Xtensa, this type is extended to contain all custom state,
  126. * ie. coprocessor and "extra" (non-coprocessor) state (including,
  127. * for example, TIE-defined states and register files; as well
  128. * as other optional processor state).
  129. * This includes FPU state if a floating-point coprocessor happens
  130. * to have been configured within the Xtensa processor.
  131. *
  132. * TOTAL_FPREGS_SIZE is the required size (without rounding)
  133. * of elf_fpregset_t. It provides space for the following:
  134. *
  135. * a) 32-bit mask of active coprocessors for this task (similar
  136. * to CPENABLE in single-threaded Xtensa processor systems)
  137. *
  138. * b) table describing the layout of custom states (ie. of
  139. * individual registers, etc) within the save areas
  140. *
  141. * c) save areas for each coprocessor and for non-coprocessor
  142. * ("extra") state
  143. *
  144. * Note that save areas may require up to 16-byte alignment when
  145. * accessed by save/restore sequences. We do not need to ensure
  146. * such alignment in an elf_fpregset_t structure because custom
  147. * state is not directly loaded/stored into it; rather, save area
  148. * contents are copied to elf_fpregset_t from the active save areas
  149. * (see 'struct task_struct' definition in processor.h for that)
  150. * using memcpy(). But we do allow space for such alignment,
  151. * to allow optimizations of layout and copying.
  152. */
  153. #if 0
  154. #define TOTAL_FPREGS_SIZE \
  155. (4 + XTENSA_CPE_LTABLE_SIZE + XTENSA_CP_EXTRA_SIZE)
  156. #define ELF_NFPREG \
  157. ((TOTAL_FPREGS_SIZE + sizeof(elf_fpreg_t) - 1) / sizeof(elf_fpreg_t))
  158. #else
  159. #define TOTAL_FPREGS_SIZE 0
  160. #define ELF_NFPREG 0
  161. #endif
  162. typedef unsigned int elf_fpreg_t;
  163. typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
  164. #define ELF_CORE_COPY_REGS(_eregs, _pregs) \
  165. xtensa_elf_core_copy_regs (&_eregs, _pregs);
  166. extern void xtensa_elf_core_copy_regs (xtensa_gregset_t *, struct pt_regs *);
  167. /*
  168. * This is used to ensure we don't load something for the wrong architecture.
  169. */
  170. #define elf_check_arch(x) ( ( (x)->e_machine == EM_XTENSA ) || \
  171. ( (x)->e_machine == EM_XTENSA_OLD ) )
  172. /*
  173. * These are used to set parameters in the core dumps.
  174. */
  175. #ifdef __XTENSA_EL__
  176. # define ELF_DATA ELFDATA2LSB
  177. #elif defined(__XTENSA_EB__)
  178. # define ELF_DATA ELFDATA2MSB
  179. #else
  180. # error processor byte order undefined!
  181. #endif
  182. #define ELF_CLASS ELFCLASS32
  183. #define ELF_ARCH EM_XTENSA
  184. #define USE_ELF_CORE_DUMP
  185. #define ELF_EXEC_PAGESIZE PAGE_SIZE
  186. /*
  187. * This is the location that an ET_DYN program is loaded if exec'ed. Typical
  188. * use of this is to invoke "./ld.so someprog" to test out a new version of
  189. * the loader. We need to make sure that it is out of the way of the program
  190. * that it will "exec", and that there is sufficient room for the brk.
  191. */
  192. #define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
  193. /*
  194. * This yields a mask that user programs can use to figure out what
  195. * instruction set this CPU supports. This could be done in user space,
  196. * but it's not easy, and we've already done it here.
  197. */
  198. #define ELF_HWCAP (0)
  199. /*
  200. * This yields a string that ld.so will use to load implementation
  201. * specific libraries for optimization. This is more specific in
  202. * intent than poking at uname or /proc/cpuinfo.
  203. * For the moment, we have only optimizations for the Intel generations,
  204. * but that could change...
  205. */
  206. #define ELF_PLATFORM (NULL)
  207. /*
  208. * The Xtensa processor ABI says that when the program starts, a2
  209. * contains a pointer to a function which might be registered using
  210. * `atexit'. This provides a mean for the dynamic linker to call
  211. * DT_FINI functions for shared libraries that have been loaded before
  212. * the code runs.
  213. *
  214. * A value of 0 tells we have no such handler.
  215. *
  216. * We might as well make sure everything else is cleared too (except
  217. * for the stack pointer in a1), just to make things more
  218. * deterministic. Also, clearing a0 terminates debugger backtraces.
  219. */
  220. #define ELF_PLAT_INIT(_r, load_addr) \
  221. do { _r->areg[0]=0; /*_r->areg[1]=0;*/ _r->areg[2]=0; _r->areg[3]=0; \
  222. _r->areg[4]=0; _r->areg[5]=0; _r->areg[6]=0; _r->areg[7]=0; \
  223. _r->areg[8]=0; _r->areg[9]=0; _r->areg[10]=0; _r->areg[11]=0; \
  224. _r->areg[12]=0; _r->areg[13]=0; _r->areg[14]=0; _r->areg[15]=0; \
  225. } while (0)
  226. #ifdef __KERNEL__
  227. #define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX_32BIT)
  228. struct task_struct;
  229. extern void do_copy_regs (xtensa_gregset_t*, struct pt_regs*,
  230. struct task_struct*);
  231. extern void do_restore_regs (xtensa_gregset_t*, struct pt_regs*,
  232. struct task_struct*);
  233. extern void do_save_fpregs (elf_fpregset_t*, struct pt_regs*,
  234. struct task_struct*);
  235. extern int do_restore_fpregs (elf_fpregset_t*, struct pt_regs*,
  236. struct task_struct*);
  237. #endif /* __KERNEL__ */
  238. #endif /* _XTENSA_ELF_H */