libunwind_i.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2006-2007 IBM
  3. Contributed by
  4. Corey Ashford <cjashfor@us.ibm.com>
  5. Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com>
  6. Copied from libunwind-x86_64.h, modified slightly for building
  7. frysk successfully on ppc64, by Wu Zhou <woodzltc@cn.ibm.com>
  8. Will be replaced when libunwind is ready on ppc64 platform.
  9. This file is part of libunwind.
  10. Permission is hereby granted, free of charge, to any person obtaining
  11. a copy of this software and associated documentation files (the
  12. "Software"), to deal in the Software without restriction, including
  13. without limitation the rights to use, copy, modify, merge, publish,
  14. distribute, sublicense, and/or sell copies of the Software, and to
  15. permit persons to whom the Software is furnished to do so, subject to
  16. the following conditions:
  17. The above copyright notice and this permission notice shall be
  18. included in all copies or substantial portions of the Software.
  19. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  26. #ifndef PPC32_LIBUNWIND_I_H
  27. #define PPC32_LIBUNWIND_I_H
  28. /* Target-dependent definitions that are internal to libunwind but need
  29. to be shared with target-independent code. */
  30. #include <stdlib.h>
  31. #include <libunwind.h>
  32. #include "elf32.h"
  33. #include "mempool.h"
  34. #include "dwarf.h"
  35. typedef struct
  36. {
  37. /* no ppc32-specific fast trace */
  38. }
  39. unw_tdep_frame_t;
  40. struct unw_addr_space
  41. {
  42. struct unw_accessors acc;
  43. unw_caching_policy_t caching_policy;
  44. #ifdef HAVE_ATOMIC_OPS_H
  45. AO_t cache_generation;
  46. #else
  47. uint32_t cache_generation;
  48. #endif
  49. unw_word_t dyn_generation; /* see dyn-common.h */
  50. unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
  51. struct dwarf_rs_cache global_cache;
  52. struct unw_debug_frame_list *debug_frames;
  53. int validate;
  54. };
  55. struct cursor
  56. {
  57. struct dwarf_cursor dwarf; /* must be first */
  58. /* Format of sigcontext structure and address at which it is
  59. stored: */
  60. enum
  61. {
  62. PPC_SCF_NONE, /* no signal frame encountered */
  63. PPC_SCF_LINUX_RT_SIGFRAME /* POSIX ucontext_t */
  64. }
  65. sigcontext_format;
  66. unw_word_t sigcontext_addr;
  67. };
  68. #define DWARF_GET_LOC(l) ((l).val)
  69. #ifdef UNW_LOCAL_ONLY
  70. # define DWARF_NULL_LOC DWARF_LOC (0, 0)
  71. # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
  72. # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
  73. # define DWARF_IS_REG_LOC(l) 0
  74. # define DWARF_IS_FP_LOC(l) 0
  75. # define DWARF_IS_V_LOC(l) 0
  76. # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
  77. # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  78. tdep_uc_addr((c)->as_arg, (r)), 0))
  79. # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  80. tdep_uc_addr((c)->as_arg, (r)), 0))
  81. # define DWARF_VREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
  82. tdep_uc_addr((c)->as_arg, (r)), 0))
  83. #else /* !UNW_LOCAL_ONLY */
  84. # define DWARF_LOC_TYPE_FP (1 << 0)
  85. # define DWARF_LOC_TYPE_REG (1 << 1)
  86. # define DWARF_LOC_TYPE_V (1 << 2)
  87. # define DWARF_NULL_LOC DWARF_LOC (0, 0)
  88. # define DWARF_IS_NULL_LOC(l) \
  89. ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
  90. # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
  91. # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
  92. # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
  93. # define DWARF_IS_V_LOC(l) (((l).type & DWARF_LOC_TYPE_V) != 0)
  94. # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
  95. # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
  96. # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
  97. | DWARF_LOC_TYPE_FP))
  98. # define DWARF_VREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
  99. | DWARF_LOC_TYPE_V))
  100. #endif /* !UNW_LOCAL_ONLY */
  101. static inline int
  102. dwarf_getvr (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t * val)
  103. {
  104. unw_word_t *valp = (unw_word_t *) val;
  105. unw_word_t addr;
  106. int ret;
  107. if (DWARF_IS_NULL_LOC (loc))
  108. return -UNW_EBADREG;
  109. assert (DWARF_IS_V_LOC (loc));
  110. assert (!DWARF_IS_FP_LOC (loc));
  111. if (DWARF_IS_REG_LOC (loc))
  112. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  113. val, 0, c->as_arg);
  114. addr = DWARF_GET_LOC (loc);
  115. if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, valp,
  116. 0, c->as_arg)) < 0)
  117. return ret;
  118. return (*c->as->acc.access_mem) (c->as, addr + 8, valp + 1, 0, c->as_arg);
  119. }
  120. static inline int
  121. dwarf_putvr (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
  122. {
  123. unw_word_t *valp = (unw_word_t *) & val;
  124. unw_word_t addr;
  125. int ret;
  126. if (DWARF_IS_NULL_LOC (loc))
  127. return -UNW_EBADREG;
  128. assert (DWARF_IS_V_LOC (loc));
  129. assert (!DWARF_IS_FP_LOC (loc));
  130. if (DWARF_IS_REG_LOC (loc))
  131. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  132. &val, 1, c->as_arg);
  133. addr = DWARF_GET_LOC (loc);
  134. if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, valp,
  135. 1, c->as_arg)) < 0)
  136. return ret;
  137. return (*c->as->acc.access_mem) (c->as, addr + 8, valp + 1, 1, c->as_arg);
  138. }
  139. static inline int
  140. dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t * val)
  141. {
  142. unw_word_t *valp = (unw_word_t *) val;
  143. unw_word_t addr;
  144. if (DWARF_IS_NULL_LOC (loc))
  145. return -UNW_EBADREG;
  146. assert (DWARF_IS_FP_LOC (loc));
  147. assert (!DWARF_IS_V_LOC (loc));
  148. if (DWARF_IS_REG_LOC (loc))
  149. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  150. val, 0, c->as_arg);
  151. addr = DWARF_GET_LOC (loc);
  152. return (*c->as->acc.access_mem) (c->as, addr + 0, valp, 0, c->as_arg);
  153. }
  154. static inline int
  155. dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
  156. {
  157. unw_word_t *valp = (unw_word_t *) & val;
  158. unw_word_t addr;
  159. if (DWARF_IS_NULL_LOC (loc))
  160. return -UNW_EBADREG;
  161. assert (DWARF_IS_FP_LOC (loc));
  162. assert (!DWARF_IS_V_LOC (loc));
  163. if (DWARF_IS_REG_LOC (loc))
  164. return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc),
  165. &val, 1, c->as_arg);
  166. addr = DWARF_GET_LOC (loc);
  167. return (*c->as->acc.access_mem) (c->as, addr + 0, valp, 1, c->as_arg);
  168. }
  169. static inline int
  170. dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t * val)
  171. {
  172. if (DWARF_IS_NULL_LOC (loc))
  173. return -UNW_EBADREG;
  174. /* If a code-generator were to save a value of type unw_word_t in a
  175. floating-point register, we would have to support this case. I
  176. suppose it could happen with MMX registers, but does it really
  177. happen? */
  178. assert (!DWARF_IS_FP_LOC (loc));
  179. assert (!DWARF_IS_V_LOC (loc));
  180. if (DWARF_IS_REG_LOC (loc))
  181. return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
  182. 0, c->as_arg);
  183. else
  184. return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
  185. 0, c->as_arg);
  186. }
  187. static inline int
  188. dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
  189. {
  190. if (DWARF_IS_NULL_LOC (loc))
  191. return -UNW_EBADREG;
  192. /* If a code-generator were to save a value of type unw_word_t in a
  193. floating-point register, we would have to support this case. I
  194. suppose it could happen with MMX registers, but does it really
  195. happen? */
  196. assert (!DWARF_IS_FP_LOC (loc));
  197. assert (!DWARF_IS_V_LOC (loc));
  198. if (DWARF_IS_REG_LOC (loc))
  199. return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
  200. 1, c->as_arg);
  201. else
  202. return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
  203. 1, c->as_arg);
  204. }
  205. #define tdep_getcontext_trace unw_getcontext
  206. #define tdep_needs_initialization UNW_OBJ(needs_initialization)
  207. #define tdep_init UNW_OBJ(init)
  208. /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
  209. tdep_search_unwind_table. */
  210. #define tdep_search_unwind_table dwarf_search_unwind_table
  211. #define tdep_find_unwind_table dwarf_find_unwind_table
  212. #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
  213. #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
  214. #define tdep_access_reg UNW_OBJ(access_reg)
  215. #define tdep_access_fpreg UNW_OBJ(access_fpreg)
  216. #define tdep_fetch_frame(c,ip,n) do {} while(0)
  217. #define tdep_cache_frame(c,rs) do {} while(0)
  218. #define tdep_reuse_frame(c,rs) do {} while(0)
  219. #define tdep_stash_frame(c,rs) do {} while(0)
  220. #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
  221. #define tdep_get_func_addr UNW_OBJ(get_func_addr)
  222. #ifdef UNW_LOCAL_ONLY
  223. # define tdep_find_proc_info(c,ip,n) \
  224. dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
  225. (c)->as_arg)
  226. # define tdep_put_unwind_info(as,pi,arg) \
  227. dwarf_put_unwind_info((as), (pi), (arg))
  228. #else
  229. # define tdep_find_proc_info(c,ip,n) \
  230. (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
  231. (c)->as_arg)
  232. # define tdep_put_unwind_info(as,pi,arg) \
  233. (*(as)->acc.put_unwind_info)((as), (pi), (arg))
  234. #endif
  235. extern int tdep_fetch_proc_info_post (struct dwarf_cursor *c, unw_word_t ip,
  236. int need_unwind_info);
  237. #define tdep_get_as(c) ((c)->dwarf.as)
  238. #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
  239. #define tdep_get_ip(c) ((c)->dwarf.ip)
  240. #define tdep_big_endian(as) 1
  241. extern int tdep_needs_initialization;
  242. extern void tdep_init (void);
  243. extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
  244. unw_dyn_info_t * di,
  245. unw_proc_info_t * pi,
  246. int need_unwind_info, void *arg);
  247. extern void *tdep_uc_addr (ucontext_t * uc, int reg);
  248. extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
  249. unsigned long *segbase, unsigned long *mapoff,
  250. char *path, size_t pathlen);
  251. extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
  252. unw_word_t * valp, int write);
  253. extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
  254. unw_fpreg_t * valp, int write);
  255. extern int tdep_get_func_addr (unw_addr_space_t as, unw_word_t addr,
  256. unw_word_t *entry_point);
  257. #endif /* PPC64_LIBUNWIND_I_H */