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