unwind.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #ifndef _ASM_IA64_UNWIND_H
  2. #define _ASM_IA64_UNWIND_H
  3. /*
  4. * Copyright (C) 1999-2000, 2003 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. *
  7. * A simple API for unwinding kernel stacks. This is used for
  8. * debugging and error reporting purposes. The kernel doesn't need
  9. * full-blown stack unwinding with all the bells and whitles, so there
  10. * is not much point in implementing the full IA-64 unwind API (though
  11. * it would of course be possible to implement the kernel API on top
  12. * of it).
  13. */
  14. struct task_struct; /* forward declaration */
  15. struct switch_stack; /* forward declaration */
  16. enum unw_application_register {
  17. UNW_AR_BSP,
  18. UNW_AR_BSPSTORE,
  19. UNW_AR_PFS,
  20. UNW_AR_RNAT,
  21. UNW_AR_UNAT,
  22. UNW_AR_LC,
  23. UNW_AR_EC,
  24. UNW_AR_FPSR,
  25. UNW_AR_RSC,
  26. UNW_AR_CCV,
  27. UNW_AR_CSD,
  28. UNW_AR_SSD
  29. };
  30. /*
  31. * The following declarations are private to the unwind
  32. * implementation:
  33. */
  34. struct unw_stack {
  35. unsigned long limit;
  36. unsigned long top;
  37. };
  38. #define UNW_FLAG_INTERRUPT_FRAME (1UL << 0)
  39. /*
  40. * No user of this module should every access this structure directly
  41. * as it is subject to change. It is declared here solely so we can
  42. * use automatic variables.
  43. */
  44. struct unw_frame_info {
  45. struct unw_stack regstk;
  46. struct unw_stack memstk;
  47. unsigned int flags;
  48. short hint;
  49. short prev_script;
  50. /* current frame info: */
  51. unsigned long bsp; /* backing store pointer value */
  52. unsigned long sp; /* stack pointer value */
  53. unsigned long psp; /* previous sp value */
  54. unsigned long ip; /* instruction pointer value */
  55. unsigned long pr; /* current predicate values */
  56. unsigned long *cfm_loc; /* cfm save location (or NULL) */
  57. unsigned long pt; /* struct pt_regs location */
  58. struct task_struct *task;
  59. struct switch_stack *sw;
  60. /* preserved state: */
  61. unsigned long *bsp_loc; /* previous bsp save location */
  62. unsigned long *bspstore_loc;
  63. unsigned long *pfs_loc;
  64. unsigned long *rnat_loc;
  65. unsigned long *rp_loc;
  66. unsigned long *pri_unat_loc;
  67. unsigned long *unat_loc;
  68. unsigned long *pr_loc;
  69. unsigned long *lc_loc;
  70. unsigned long *fpsr_loc;
  71. struct unw_ireg {
  72. unsigned long *loc;
  73. struct unw_ireg_nat {
  74. unsigned long type : 3; /* enum unw_nat_type */
  75. signed long off : 61; /* NaT word is at loc+nat.off */
  76. } nat;
  77. } r4, r5, r6, r7;
  78. unsigned long *b1_loc, *b2_loc, *b3_loc, *b4_loc, *b5_loc;
  79. struct ia64_fpreg *f2_loc, *f3_loc, *f4_loc, *f5_loc, *fr_loc[16];
  80. };
  81. /*
  82. * The official API follows below:
  83. */
  84. struct unw_table_entry {
  85. u64 start_offset;
  86. u64 end_offset;
  87. u64 info_offset;
  88. };
  89. /*
  90. * Initialize unwind support.
  91. */
  92. extern void unw_init (void);
  93. extern void *unw_add_unwind_table (const char *name, unsigned long segment_base, unsigned long gp,
  94. const void *table_start, const void *table_end);
  95. extern void unw_remove_unwind_table (void *handle);
  96. /*
  97. * Prepare to unwind blocked task t.
  98. */
  99. extern void unw_init_from_blocked_task (struct unw_frame_info *info, struct task_struct *t);
  100. extern void unw_init_frame_info (struct unw_frame_info *info, struct task_struct *t,
  101. struct switch_stack *sw);
  102. /*
  103. * Prepare to unwind the currently running thread.
  104. */
  105. extern void unw_init_running (void (*callback)(struct unw_frame_info *info, void *arg), void *arg);
  106. /*
  107. * Unwind to previous to frame. Returns 0 if successful, negative
  108. * number in case of an error.
  109. */
  110. extern int unw_unwind (struct unw_frame_info *info);
  111. /*
  112. * Unwind until the return pointer is in user-land (or until an error
  113. * occurs). Returns 0 if successful, negative number in case of
  114. * error.
  115. */
  116. extern int unw_unwind_to_user (struct unw_frame_info *info);
  117. #define unw_is_intr_frame(info) (((info)->flags & UNW_FLAG_INTERRUPT_FRAME) != 0)
  118. static inline int
  119. unw_get_ip (struct unw_frame_info *info, unsigned long *valp)
  120. {
  121. *valp = (info)->ip;
  122. return 0;
  123. }
  124. static inline int
  125. unw_get_sp (struct unw_frame_info *info, unsigned long *valp)
  126. {
  127. *valp = (info)->sp;
  128. return 0;
  129. }
  130. static inline int
  131. unw_get_psp (struct unw_frame_info *info, unsigned long *valp)
  132. {
  133. *valp = (info)->psp;
  134. return 0;
  135. }
  136. static inline int
  137. unw_get_bsp (struct unw_frame_info *info, unsigned long *valp)
  138. {
  139. *valp = (info)->bsp;
  140. return 0;
  141. }
  142. static inline int
  143. unw_get_cfm (struct unw_frame_info *info, unsigned long *valp)
  144. {
  145. *valp = *(info)->cfm_loc;
  146. return 0;
  147. }
  148. static inline int
  149. unw_set_cfm (struct unw_frame_info *info, unsigned long val)
  150. {
  151. *(info)->cfm_loc = val;
  152. return 0;
  153. }
  154. static inline int
  155. unw_get_rp (struct unw_frame_info *info, unsigned long *val)
  156. {
  157. if (!info->rp_loc)
  158. return -1;
  159. *val = *info->rp_loc;
  160. return 0;
  161. }
  162. extern int unw_access_gr (struct unw_frame_info *, int, unsigned long *, char *, int);
  163. extern int unw_access_br (struct unw_frame_info *, int, unsigned long *, int);
  164. extern int unw_access_fr (struct unw_frame_info *, int, struct ia64_fpreg *, int);
  165. extern int unw_access_ar (struct unw_frame_info *, int, unsigned long *, int);
  166. extern int unw_access_pr (struct unw_frame_info *, unsigned long *, int);
  167. static inline int
  168. unw_set_gr (struct unw_frame_info *i, int n, unsigned long v, char nat)
  169. {
  170. return unw_access_gr(i, n, &v, &nat, 1);
  171. }
  172. static inline int
  173. unw_set_br (struct unw_frame_info *i, int n, unsigned long v)
  174. {
  175. return unw_access_br(i, n, &v, 1);
  176. }
  177. static inline int
  178. unw_set_fr (struct unw_frame_info *i, int n, struct ia64_fpreg v)
  179. {
  180. return unw_access_fr(i, n, &v, 1);
  181. }
  182. static inline int
  183. unw_set_ar (struct unw_frame_info *i, int n, unsigned long v)
  184. {
  185. return unw_access_ar(i, n, &v, 1);
  186. }
  187. static inline int
  188. unw_set_pr (struct unw_frame_info *i, unsigned long v)
  189. {
  190. return unw_access_pr(i, &v, 1);
  191. }
  192. #define unw_get_gr(i,n,v,nat) unw_access_gr(i,n,v,nat,0)
  193. #define unw_get_br(i,n,v) unw_access_br(i,n,v,0)
  194. #define unw_get_fr(i,n,v) unw_access_fr(i,n,v,0)
  195. #define unw_get_ar(i,n,v) unw_access_ar(i,n,v,0)
  196. #define unw_get_pr(i,v) unw_access_pr(i,v,0)
  197. #endif /* _ASM_UNWIND_H */