elf.h 7.1 KB

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