dwarf.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. #include <linux/compiler.h>
  192. #include <linux/bug.h>
  193. #include <linux/list.h>
  194. #include <linux/module.h>
  195. /*
  196. * Read either the frame pointer (r14) or the stack pointer (r15).
  197. * NOTE: this MUST be inlined.
  198. */
  199. static __always_inline unsigned long dwarf_read_arch_reg(unsigned int reg)
  200. {
  201. unsigned long value = 0;
  202. switch (reg) {
  203. case 14:
  204. __asm__ __volatile__("mov r14, %0\n" : "=r" (value));
  205. break;
  206. case 15:
  207. __asm__ __volatile__("mov r15, %0\n" : "=r" (value));
  208. break;
  209. default:
  210. BUG();
  211. }
  212. return value;
  213. }
  214. /**
  215. * dwarf_cie - Common Information Entry
  216. */
  217. struct dwarf_cie {
  218. unsigned long length;
  219. unsigned long cie_id;
  220. unsigned char version;
  221. const char *augmentation;
  222. unsigned int code_alignment_factor;
  223. int data_alignment_factor;
  224. /* Which column in the rule table represents return addr of func. */
  225. unsigned int return_address_reg;
  226. unsigned char *initial_instructions;
  227. unsigned char *instructions_end;
  228. unsigned char encoding;
  229. unsigned long cie_pointer;
  230. unsigned long flags;
  231. #define DWARF_CIE_Z_AUGMENTATION (1 << 0)
  232. /* linked-list entry if this CIE is from a module */
  233. struct list_head link;
  234. struct rb_node node;
  235. };
  236. /**
  237. * dwarf_fde - Frame Description Entry
  238. */
  239. struct dwarf_fde {
  240. unsigned long length;
  241. unsigned long cie_pointer;
  242. struct dwarf_cie *cie;
  243. unsigned long initial_location;
  244. unsigned long address_range;
  245. unsigned char *instructions;
  246. unsigned char *end;
  247. /* linked-list entry if this FDE is from a module */
  248. struct list_head link;
  249. struct rb_node node;
  250. };
  251. /**
  252. * dwarf_frame - DWARF information for a frame in the call stack
  253. */
  254. struct dwarf_frame {
  255. struct dwarf_frame *prev, *next;
  256. unsigned long pc;
  257. struct list_head reg_list;
  258. unsigned long cfa;
  259. /* Valid when DW_FRAME_CFA_REG_OFFSET is set in flags */
  260. unsigned int cfa_register;
  261. unsigned int cfa_offset;
  262. /* Valid when DW_FRAME_CFA_REG_EXP is set in flags */
  263. unsigned char *cfa_expr;
  264. unsigned int cfa_expr_len;
  265. unsigned long flags;
  266. #define DWARF_FRAME_CFA_REG_OFFSET (1 << 0)
  267. #define DWARF_FRAME_CFA_REG_EXP (1 << 1)
  268. unsigned long return_addr;
  269. };
  270. /**
  271. * dwarf_reg - DWARF register
  272. * @flags: Describes how to calculate the value of this register
  273. */
  274. struct dwarf_reg {
  275. struct list_head link;
  276. unsigned int number;
  277. unsigned long addr;
  278. unsigned long flags;
  279. #define DWARF_REG_OFFSET (1 << 0)
  280. #define DWARF_VAL_OFFSET (1 << 1)
  281. #define DWARF_UNDEFINED (1 << 2)
  282. };
  283. /*
  284. * Call Frame instruction opcodes.
  285. */
  286. #define DW_CFA_advance_loc 0x40
  287. #define DW_CFA_offset 0x80
  288. #define DW_CFA_restore 0xc0
  289. #define DW_CFA_nop 0x00
  290. #define DW_CFA_set_loc 0x01
  291. #define DW_CFA_advance_loc1 0x02
  292. #define DW_CFA_advance_loc2 0x03
  293. #define DW_CFA_advance_loc4 0x04
  294. #define DW_CFA_offset_extended 0x05
  295. #define DW_CFA_restore_extended 0x06
  296. #define DW_CFA_undefined 0x07
  297. #define DW_CFA_same_value 0x08
  298. #define DW_CFA_register 0x09
  299. #define DW_CFA_remember_state 0x0a
  300. #define DW_CFA_restore_state 0x0b
  301. #define DW_CFA_def_cfa 0x0c
  302. #define DW_CFA_def_cfa_register 0x0d
  303. #define DW_CFA_def_cfa_offset 0x0e
  304. #define DW_CFA_def_cfa_expression 0x0f
  305. #define DW_CFA_expression 0x10
  306. #define DW_CFA_offset_extended_sf 0x11
  307. #define DW_CFA_def_cfa_sf 0x12
  308. #define DW_CFA_def_cfa_offset_sf 0x13
  309. #define DW_CFA_val_offset 0x14
  310. #define DW_CFA_val_offset_sf 0x15
  311. #define DW_CFA_val_expression 0x16
  312. #define DW_CFA_lo_user 0x1c
  313. #define DW_CFA_hi_user 0x3f
  314. /* GNU extension opcodes */
  315. #define DW_CFA_GNU_args_size 0x2e
  316. #define DW_CFA_GNU_negative_offset_extended 0x2f
  317. /*
  318. * Some call frame instructions encode their operands in the opcode. We
  319. * need some helper functions to extract both the opcode and operands
  320. * from an instruction.
  321. */
  322. static inline unsigned int DW_CFA_opcode(unsigned long insn)
  323. {
  324. return (insn & 0xc0);
  325. }
  326. static inline unsigned int DW_CFA_operand(unsigned long insn)
  327. {
  328. return (insn & 0x3f);
  329. }
  330. #define DW_EH_FRAME_CIE 0 /* .eh_frame CIE IDs are 0 */
  331. #define DW_CIE_ID 0xffffffff
  332. #define DW64_CIE_ID 0xffffffffffffffffULL
  333. /*
  334. * DWARF FDE/CIE length field values.
  335. */
  336. #define DW_EXT_LO 0xfffffff0
  337. #define DW_EXT_HI 0xffffffff
  338. #define DW_EXT_DWARF64 DW_EXT_HI
  339. extern struct dwarf_frame *dwarf_unwind_stack(unsigned long,
  340. struct dwarf_frame *);
  341. extern void dwarf_free_frame(struct dwarf_frame *);
  342. extern int module_dwarf_finalize(const Elf_Ehdr *, const Elf_Shdr *,
  343. struct module *);
  344. extern void module_dwarf_cleanup(struct module *);
  345. #endif /* !__ASSEMBLY__ */
  346. #define CFI_STARTPROC .cfi_startproc
  347. #define CFI_ENDPROC .cfi_endproc
  348. #define CFI_DEF_CFA .cfi_def_cfa
  349. #define CFI_REGISTER .cfi_register
  350. #define CFI_REL_OFFSET .cfi_rel_offset
  351. #define CFI_UNDEFINED .cfi_undefined
  352. #else
  353. /*
  354. * Use the asm comment character to ignore the rest of the line.
  355. */
  356. #define CFI_IGNORE !
  357. #define CFI_STARTPROC CFI_IGNORE
  358. #define CFI_ENDPROC CFI_IGNORE
  359. #define CFI_DEF_CFA CFI_IGNORE
  360. #define CFI_REGISTER CFI_IGNORE
  361. #define CFI_REL_OFFSET CFI_IGNORE
  362. #define CFI_UNDEFINED CFI_IGNORE
  363. #ifndef __ASSEMBLY__
  364. static inline void dwarf_unwinder_init(void)
  365. {
  366. }
  367. #define module_dwarf_finalize(hdr, sechdrs, me) (0)
  368. #define module_dwarf_cleanup(mod) do { } while (0)
  369. #endif
  370. #endif /* CONFIG_DWARF_UNWINDER */
  371. #endif /* __ASM_SH_DWARF_H */