dwarf.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * Copyright (C) 2009 Matt Fleming <matt@console-pimps.org>
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. */
  9. #ifndef __ASM_SH_DWARF_H
  10. #define __ASM_SH_DWARF_H
  11. #ifdef CONFIG_DWARF_UNWINDER
  12. /*
  13. * DWARF expression operations
  14. */
  15. #define DW_OP_addr 0x03
  16. #define DW_OP_deref 0x06
  17. #define DW_OP_const1u 0x08
  18. #define DW_OP_const1s 0x09
  19. #define DW_OP_const2u 0x0a
  20. #define DW_OP_const2s 0x0b
  21. #define DW_OP_const4u 0x0c
  22. #define DW_OP_const4s 0x0d
  23. #define DW_OP_const8u 0x0e
  24. #define DW_OP_const8s 0x0f
  25. #define DW_OP_constu 0x10
  26. #define DW_OP_consts 0x11
  27. #define DW_OP_dup 0x12
  28. #define DW_OP_drop 0x13
  29. #define DW_OP_over 0x14
  30. #define DW_OP_pick 0x15
  31. #define DW_OP_swap 0x16
  32. #define DW_OP_rot 0x17
  33. #define DW_OP_xderef 0x18
  34. #define DW_OP_abs 0x19
  35. #define DW_OP_and 0x1a
  36. #define DW_OP_div 0x1b
  37. #define DW_OP_minus 0x1c
  38. #define DW_OP_mod 0x1d
  39. #define DW_OP_mul 0x1e
  40. #define DW_OP_neg 0x1f
  41. #define DW_OP_not 0x20
  42. #define DW_OP_or 0x21
  43. #define DW_OP_plus 0x22
  44. #define DW_OP_plus_uconst 0x23
  45. #define DW_OP_shl 0x24
  46. #define DW_OP_shr 0x25
  47. #define DW_OP_shra 0x26
  48. #define DW_OP_xor 0x27
  49. #define DW_OP_skip 0x2f
  50. #define DW_OP_bra 0x28
  51. #define DW_OP_eq 0x29
  52. #define DW_OP_ge 0x2a
  53. #define DW_OP_gt 0x2b
  54. #define DW_OP_le 0x2c
  55. #define DW_OP_lt 0x2d
  56. #define DW_OP_ne 0x2e
  57. #define DW_OP_lit0 0x30
  58. #define DW_OP_lit1 0x31
  59. #define DW_OP_lit2 0x32
  60. #define DW_OP_lit3 0x33
  61. #define DW_OP_lit4 0x34
  62. #define DW_OP_lit5 0x35
  63. #define DW_OP_lit6 0x36
  64. #define DW_OP_lit7 0x37
  65. #define DW_OP_lit8 0x38
  66. #define DW_OP_lit9 0x39
  67. #define DW_OP_lit10 0x3a
  68. #define DW_OP_lit11 0x3b
  69. #define DW_OP_lit12 0x3c
  70. #define DW_OP_lit13 0x3d
  71. #define DW_OP_lit14 0x3e
  72. #define DW_OP_lit15 0x3f
  73. #define DW_OP_lit16 0x40
  74. #define DW_OP_lit17 0x41
  75. #define DW_OP_lit18 0x42
  76. #define DW_OP_lit19 0x43
  77. #define DW_OP_lit20 0x44
  78. #define DW_OP_lit21 0x45
  79. #define DW_OP_lit22 0x46
  80. #define DW_OP_lit23 0x47
  81. #define DW_OP_lit24 0x48
  82. #define DW_OP_lit25 0x49
  83. #define DW_OP_lit26 0x4a
  84. #define DW_OP_lit27 0x4b
  85. #define DW_OP_lit28 0x4c
  86. #define DW_OP_lit29 0x4d
  87. #define DW_OP_lit30 0x4e
  88. #define DW_OP_lit31 0x4f
  89. #define DW_OP_reg0 0x50
  90. #define DW_OP_reg1 0x51
  91. #define DW_OP_reg2 0x52
  92. #define DW_OP_reg3 0x53
  93. #define DW_OP_reg4 0x54
  94. #define DW_OP_reg5 0x55
  95. #define DW_OP_reg6 0x56
  96. #define DW_OP_reg7 0x57
  97. #define DW_OP_reg8 0x58
  98. #define DW_OP_reg9 0x59
  99. #define DW_OP_reg10 0x5a
  100. #define DW_OP_reg11 0x5b
  101. #define DW_OP_reg12 0x5c
  102. #define DW_OP_reg13 0x5d
  103. #define DW_OP_reg14 0x5e
  104. #define DW_OP_reg15 0x5f
  105. #define DW_OP_reg16 0x60
  106. #define DW_OP_reg17 0x61
  107. #define DW_OP_reg18 0x62
  108. #define DW_OP_reg19 0x63
  109. #define DW_OP_reg20 0x64
  110. #define DW_OP_reg21 0x65
  111. #define DW_OP_reg22 0x66
  112. #define DW_OP_reg23 0x67
  113. #define DW_OP_reg24 0x68
  114. #define DW_OP_reg25 0x69
  115. #define DW_OP_reg26 0x6a
  116. #define DW_OP_reg27 0x6b
  117. #define DW_OP_reg28 0x6c
  118. #define DW_OP_reg29 0x6d
  119. #define DW_OP_reg30 0x6e
  120. #define DW_OP_reg31 0x6f
  121. #define DW_OP_breg0 0x70
  122. #define DW_OP_breg1 0x71
  123. #define DW_OP_breg2 0x72
  124. #define DW_OP_breg3 0x73
  125. #define DW_OP_breg4 0x74
  126. #define DW_OP_breg5 0x75
  127. #define DW_OP_breg6 0x76
  128. #define DW_OP_breg7 0x77
  129. #define DW_OP_breg8 0x78
  130. #define DW_OP_breg9 0x79
  131. #define DW_OP_breg10 0x7a
  132. #define DW_OP_breg11 0x7b
  133. #define DW_OP_breg12 0x7c
  134. #define DW_OP_breg13 0x7d
  135. #define DW_OP_breg14 0x7e
  136. #define DW_OP_breg15 0x7f
  137. #define DW_OP_breg16 0x80
  138. #define DW_OP_breg17 0x81
  139. #define DW_OP_breg18 0x82
  140. #define DW_OP_breg19 0x83
  141. #define DW_OP_breg20 0x84
  142. #define DW_OP_breg21 0x85
  143. #define DW_OP_breg22 0x86
  144. #define DW_OP_breg23 0x87
  145. #define DW_OP_breg24 0x88
  146. #define DW_OP_breg25 0x89
  147. #define DW_OP_breg26 0x8a
  148. #define DW_OP_breg27 0x8b
  149. #define DW_OP_breg28 0x8c
  150. #define DW_OP_breg29 0x8d
  151. #define DW_OP_breg30 0x8e
  152. #define DW_OP_breg31 0x8f
  153. #define DW_OP_regx 0x90
  154. #define DW_OP_fbreg 0x91
  155. #define DW_OP_bregx 0x92
  156. #define DW_OP_piece 0x93
  157. #define DW_OP_deref_size 0x94
  158. #define DW_OP_xderef_size 0x95
  159. #define DW_OP_nop 0x96
  160. #define DW_OP_push_object_address 0x97
  161. #define DW_OP_call2 0x98
  162. #define DW_OP_call4 0x99
  163. #define DW_OP_call_ref 0x9a
  164. #define DW_OP_form_tls_address 0x9b
  165. #define DW_OP_call_frame_cfa 0x9c
  166. #define DW_OP_bit_piece 0x9d
  167. #define DW_OP_lo_user 0xe0
  168. #define DW_OP_hi_user 0xff
  169. /*
  170. * Addresses used in FDE entries in the .eh_frame section may be encoded
  171. * using one of the following encodings.
  172. */
  173. #define DW_EH_PE_absptr 0x00
  174. #define DW_EH_PE_omit 0xff
  175. #define DW_EH_PE_uleb128 0x01
  176. #define DW_EH_PE_udata2 0x02
  177. #define DW_EH_PE_udata4 0x03
  178. #define DW_EH_PE_udata8 0x04
  179. #define DW_EH_PE_sleb128 0x09
  180. #define DW_EH_PE_sdata2 0x0a
  181. #define DW_EH_PE_sdata4 0x0b
  182. #define DW_EH_PE_sdata8 0x0c
  183. #define DW_EH_PE_signed 0x09
  184. #define DW_EH_PE_pcrel 0x10
  185. /*
  186. * The architecture-specific register number that contains the return
  187. * address in the .debug_frame table.
  188. */
  189. #define DWARF_ARCH_RA_REG 17
  190. #ifndef __ASSEMBLY__
  191. /*
  192. * Read either the frame pointer (r14) or the stack pointer (r15).
  193. * NOTE: this MUST be inlined.
  194. */
  195. static __always_inline unsigned long dwarf_read_arch_reg(unsigned int reg)
  196. {
  197. unsigned long value = 0;
  198. switch (reg) {
  199. case 14:
  200. __asm__ __volatile__("mov r14, %0\n" : "=r" (value));
  201. break;
  202. case 15:
  203. __asm__ __volatile__("mov r15, %0\n" : "=r" (value));
  204. break;
  205. default:
  206. BUG();
  207. }
  208. return value;
  209. }
  210. /**
  211. * dwarf_cie - Common Information Entry
  212. */
  213. struct dwarf_cie {
  214. unsigned long length;
  215. unsigned long cie_id;
  216. unsigned char version;
  217. const char *augmentation;
  218. unsigned int code_alignment_factor;
  219. int data_alignment_factor;
  220. /* Which column in the rule table represents return addr of func. */
  221. unsigned int return_address_reg;
  222. unsigned char *initial_instructions;
  223. unsigned char *instructions_end;
  224. unsigned char encoding;
  225. unsigned long cie_pointer;
  226. struct list_head link;
  227. unsigned long flags;
  228. #define DWARF_CIE_Z_AUGMENTATION (1 << 0)
  229. };
  230. /**
  231. * dwarf_fde - Frame Description Entry
  232. */
  233. struct dwarf_fde {
  234. unsigned long length;
  235. unsigned long cie_pointer;
  236. struct dwarf_cie *cie;
  237. unsigned long initial_location;
  238. unsigned long address_range;
  239. unsigned char *instructions;
  240. unsigned char *end;
  241. struct list_head link;
  242. };
  243. /**
  244. * dwarf_frame - DWARF information for a frame in the call stack
  245. */
  246. struct dwarf_frame {
  247. struct dwarf_frame *prev, *next;
  248. unsigned long pc;
  249. struct list_head reg_list;
  250. unsigned long cfa;
  251. /* Valid when DW_FRAME_CFA_REG_OFFSET is set in flags */
  252. unsigned int cfa_register;
  253. unsigned int cfa_offset;
  254. /* Valid when DW_FRAME_CFA_REG_EXP is set in flags */
  255. unsigned char *cfa_expr;
  256. unsigned int cfa_expr_len;
  257. unsigned long flags;
  258. #define DWARF_FRAME_CFA_REG_OFFSET (1 << 0)
  259. #define DWARF_FRAME_CFA_REG_EXP (1 << 1)
  260. unsigned long return_addr;
  261. };
  262. /**
  263. * dwarf_reg - DWARF register
  264. * @flags: Describes how to calculate the value of this register
  265. */
  266. struct dwarf_reg {
  267. struct list_head link;
  268. unsigned int number;
  269. unsigned long addr;
  270. unsigned long flags;
  271. #define DWARF_REG_OFFSET (1 << 0)
  272. #define DWARF_VAL_OFFSET (1 << 1)
  273. #define DWARF_UNDEFINED (1 << 2)
  274. };
  275. /*
  276. * Call Frame instruction opcodes.
  277. */
  278. #define DW_CFA_advance_loc 0x40
  279. #define DW_CFA_offset 0x80
  280. #define DW_CFA_restore 0xc0
  281. #define DW_CFA_nop 0x00
  282. #define DW_CFA_set_loc 0x01
  283. #define DW_CFA_advance_loc1 0x02
  284. #define DW_CFA_advance_loc2 0x03
  285. #define DW_CFA_advance_loc4 0x04
  286. #define DW_CFA_offset_extended 0x05
  287. #define DW_CFA_restore_extended 0x06
  288. #define DW_CFA_undefined 0x07
  289. #define DW_CFA_same_value 0x08
  290. #define DW_CFA_register 0x09
  291. #define DW_CFA_remember_state 0x0a
  292. #define DW_CFA_restore_state 0x0b
  293. #define DW_CFA_def_cfa 0x0c
  294. #define DW_CFA_def_cfa_register 0x0d
  295. #define DW_CFA_def_cfa_offset 0x0e
  296. #define DW_CFA_def_cfa_expression 0x0f
  297. #define DW_CFA_expression 0x10
  298. #define DW_CFA_offset_extended_sf 0x11
  299. #define DW_CFA_def_cfa_sf 0x12
  300. #define DW_CFA_def_cfa_offset_sf 0x13
  301. #define DW_CFA_val_offset 0x14
  302. #define DW_CFA_val_offset_sf 0x15
  303. #define DW_CFA_val_expression 0x16
  304. #define DW_CFA_lo_user 0x1c
  305. #define DW_CFA_hi_user 0x3f
  306. /* GNU extension opcodes */
  307. #define DW_CFA_GNU_args_size 0x2e
  308. #define DW_CFA_GNU_negative_offset_extended 0x2f
  309. /*
  310. * Some call frame instructions encode their operands in the opcode. We
  311. * need some helper functions to extract both the opcode and operands
  312. * from an instruction.
  313. */
  314. static inline unsigned int DW_CFA_opcode(unsigned long insn)
  315. {
  316. return (insn & 0xc0);
  317. }
  318. static inline unsigned int DW_CFA_operand(unsigned long insn)
  319. {
  320. return (insn & 0x3f);
  321. }
  322. #define DW_EH_FRAME_CIE 0 /* .eh_frame CIE IDs are 0 */
  323. #define DW_CIE_ID 0xffffffff
  324. #define DW64_CIE_ID 0xffffffffffffffffULL
  325. /*
  326. * DWARF FDE/CIE length field values.
  327. */
  328. #define DW_EXT_LO 0xfffffff0
  329. #define DW_EXT_HI 0xffffffff
  330. #define DW_EXT_DWARF64 DW_EXT_HI
  331. extern struct dwarf_frame *dwarf_unwind_stack(unsigned long,
  332. struct dwarf_frame *);
  333. #endif /* !__ASSEMBLY__ */
  334. #define CFI_STARTPROC .cfi_startproc
  335. #define CFI_ENDPROC .cfi_endproc
  336. #define CFI_DEF_CFA .cfi_def_cfa
  337. #define CFI_REGISTER .cfi_register
  338. #define CFI_REL_OFFSET .cfi_rel_offset
  339. #define CFI_UNDEFINED .cfi_undefined
  340. #else
  341. /*
  342. * Use the asm comment character to ignore the rest of the line.
  343. */
  344. #define CFI_IGNORE !
  345. #define CFI_STARTPROC CFI_IGNORE
  346. #define CFI_ENDPROC CFI_IGNORE
  347. #define CFI_DEF_CFA CFI_IGNORE
  348. #define CFI_REGISTER CFI_IGNORE
  349. #define CFI_REL_OFFSET CFI_IGNORE
  350. #define CFI_UNDEFINED CFI_IGNORE
  351. #ifndef __ASSEMBLY__
  352. static inline void dwarf_unwinder_init(void)
  353. {
  354. }
  355. #endif
  356. #endif /* CONFIG_DWARF_UNWINDER */
  357. #endif /* __ASM_SH_DWARF_H */