dwarf.h 9.7 KB

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