unwind_i.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2000, 2002-2003 Hewlett-Packard Co
  3. * David Mosberger-Tang <davidm@hpl.hp.com>
  4. *
  5. * Kernel unwind support.
  6. */
  7. #define UNW_VER(x) ((x) >> 48)
  8. #define UNW_FLAG_MASK 0x0000ffff00000000
  9. #define UNW_FLAG_OSMASK 0x0000f00000000000
  10. #define UNW_FLAG_EHANDLER(x) ((x) & 0x0000000100000000L)
  11. #define UNW_FLAG_UHANDLER(x) ((x) & 0x0000000200000000L)
  12. #define UNW_LENGTH(x) ((x) & 0x00000000ffffffffL)
  13. enum unw_register_index {
  14. /* primary unat: */
  15. UNW_REG_PRI_UNAT_GR,
  16. UNW_REG_PRI_UNAT_MEM,
  17. /* register stack */
  18. UNW_REG_BSP, /* register stack pointer */
  19. UNW_REG_BSPSTORE,
  20. UNW_REG_PFS, /* previous function state */
  21. UNW_REG_RNAT,
  22. /* memory stack */
  23. UNW_REG_PSP, /* previous memory stack pointer */
  24. /* return pointer: */
  25. UNW_REG_RP,
  26. /* preserved registers: */
  27. UNW_REG_R4, UNW_REG_R5, UNW_REG_R6, UNW_REG_R7,
  28. UNW_REG_UNAT, UNW_REG_PR, UNW_REG_LC, UNW_REG_FPSR,
  29. UNW_REG_B1, UNW_REG_B2, UNW_REG_B3, UNW_REG_B4, UNW_REG_B5,
  30. UNW_REG_F2, UNW_REG_F3, UNW_REG_F4, UNW_REG_F5,
  31. UNW_REG_F16, UNW_REG_F17, UNW_REG_F18, UNW_REG_F19,
  32. UNW_REG_F20, UNW_REG_F21, UNW_REG_F22, UNW_REG_F23,
  33. UNW_REG_F24, UNW_REG_F25, UNW_REG_F26, UNW_REG_F27,
  34. UNW_REG_F28, UNW_REG_F29, UNW_REG_F30, UNW_REG_F31,
  35. UNW_NUM_REGS
  36. };
  37. struct unw_info_block {
  38. u64 header;
  39. u64 desc[0]; /* unwind descriptors */
  40. /* personality routine and language-specific data follow behind descriptors */
  41. };
  42. struct unw_table {
  43. struct unw_table *next; /* must be first member! */
  44. const char *name;
  45. unsigned long gp; /* global pointer for this load-module */
  46. unsigned long segment_base; /* base for offsets in the unwind table entries */
  47. unsigned long start;
  48. unsigned long end;
  49. const struct unw_table_entry *array;
  50. unsigned long length;
  51. };
  52. enum unw_where {
  53. UNW_WHERE_NONE, /* register isn't saved at all */
  54. UNW_WHERE_GR, /* register is saved in a general register */
  55. UNW_WHERE_FR, /* register is saved in a floating-point register */
  56. UNW_WHERE_BR, /* register is saved in a branch register */
  57. UNW_WHERE_SPREL, /* register is saved on memstack (sp-relative) */
  58. UNW_WHERE_PSPREL, /* register is saved on memstack (psp-relative) */
  59. /*
  60. * At the end of each prologue these locations get resolved to
  61. * UNW_WHERE_PSPREL and UNW_WHERE_GR, respectively:
  62. */
  63. UNW_WHERE_SPILL_HOME, /* register is saved in its spill home */
  64. UNW_WHERE_GR_SAVE /* register is saved in next general register */
  65. };
  66. #define UNW_WHEN_NEVER 0x7fffffff
  67. struct unw_reg_info {
  68. unsigned long val; /* save location: register number or offset */
  69. enum unw_where where; /* where the register gets saved */
  70. int when; /* when the register gets saved */
  71. };
  72. struct unw_reg_state {
  73. struct unw_reg_state *next; /* next (outer) element on state stack */
  74. struct unw_reg_info reg[UNW_NUM_REGS]; /* register save locations */
  75. };
  76. struct unw_labeled_state {
  77. struct unw_labeled_state *next; /* next labeled state (or NULL) */
  78. unsigned long label; /* label for this state */
  79. struct unw_reg_state saved_state;
  80. };
  81. struct unw_state_record {
  82. unsigned int first_region : 1; /* is this the first region? */
  83. unsigned int done : 1; /* are we done scanning descriptors? */
  84. unsigned int any_spills : 1; /* got any register spills? */
  85. unsigned int in_body : 1; /* are we inside a body (as opposed to a prologue)? */
  86. unsigned long flags; /* see UNW_FLAG_* in unwind.h */
  87. u8 *imask; /* imask of spill_mask record or NULL */
  88. unsigned long pr_val; /* predicate values */
  89. unsigned long pr_mask; /* predicate mask */
  90. long spill_offset; /* psp-relative offset for spill base */
  91. int region_start;
  92. int region_len;
  93. int epilogue_start;
  94. int epilogue_count;
  95. int when_target;
  96. u8 gr_save_loc; /* next general register to use for saving a register */
  97. u8 return_link_reg; /* branch register in which the return link is passed */
  98. struct unw_labeled_state *labeled_states; /* list of all labeled states */
  99. struct unw_reg_state curr; /* current state */
  100. };
  101. enum unw_nat_type {
  102. UNW_NAT_NONE, /* NaT not represented */
  103. UNW_NAT_VAL, /* NaT represented by NaT value (fp reg) */
  104. UNW_NAT_MEMSTK, /* NaT value is in unat word at offset OFF */
  105. UNW_NAT_REGSTK /* NaT is in rnat */
  106. };
  107. enum unw_insn_opcode {
  108. UNW_INSN_ADD, /* s[dst] += val */
  109. UNW_INSN_ADD_PSP, /* s[dst] = (s.psp + val) */
  110. UNW_INSN_ADD_SP, /* s[dst] = (s.sp + val) */
  111. UNW_INSN_MOVE, /* s[dst] = s[val] */
  112. UNW_INSN_MOVE2, /* s[dst] = s[val]; s[dst+1] = s[val+1] */
  113. UNW_INSN_MOVE_STACKED, /* s[dst] = ia64_rse_skip(*s.bsp, val) */
  114. UNW_INSN_SETNAT_MEMSTK, /* s[dst+1].nat.type = MEMSTK;
  115. s[dst+1].nat.off = *s.pri_unat - s[dst] */
  116. UNW_INSN_SETNAT_TYPE, /* s[dst+1].nat.type = val */
  117. UNW_INSN_LOAD, /* s[dst] = *s[val] */
  118. UNW_INSN_MOVE_SCRATCH, /* s[dst] = scratch reg "val" */
  119. UNW_INSN_MOVE_CONST, /* s[dst] = constant reg "val" */
  120. };
  121. struct unw_insn {
  122. unsigned int opc : 4;
  123. unsigned int dst : 9;
  124. signed int val : 19;
  125. };
  126. /*
  127. * Preserved general static registers (r4-r7) give rise to two script
  128. * instructions; everything else yields at most one instruction; at
  129. * the end of the script, the psp gets popped, accounting for one more
  130. * instruction.
  131. */
  132. #define UNW_MAX_SCRIPT_LEN (UNW_NUM_REGS + 5)
  133. struct unw_script {
  134. unsigned long ip; /* ip this script is for */
  135. unsigned long pr_mask; /* mask of predicates script depends on */
  136. unsigned long pr_val; /* predicate values this script is for */
  137. rwlock_t lock;
  138. unsigned int flags; /* see UNW_FLAG_* in unwind.h */
  139. unsigned short lru_chain; /* used for least-recently-used chain */
  140. unsigned short coll_chain; /* used for hash collisions */
  141. unsigned short hint; /* hint for next script to try (or -1) */
  142. unsigned short count; /* number of instructions in script */
  143. struct unw_insn insn[UNW_MAX_SCRIPT_LEN];
  144. };