diff options
author | Paul Mundt <lethal@linux-sh.org> | 2009-08-13 16:10:57 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-08-13 16:10:57 -0400 |
commit | 718dbf376ac39b8f8c974e9162430754dbace742 (patch) | |
tree | 145b39219d1f63c01ca704f53d8abc9b31a11469 /arch/sh | |
parent | f54aab4a7486fb7947d6d746f3423f67676811c8 (diff) | |
parent | f826466772ae52f26152287fcb2259351de78f0f (diff) |
Merge branch 'sh/dwarf-unwinder'
Diffstat (limited to 'arch/sh')
-rw-r--r-- | arch/sh/Kconfig.debug | 8 | ||||
-rw-r--r-- | arch/sh/Makefile | 4 | ||||
-rw-r--r-- | arch/sh/include/asm/dwarf.h | 402 | ||||
-rw-r--r-- | arch/sh/include/asm/entry-macros.S | 12 | ||||
-rw-r--r-- | arch/sh/include/asm/sections.h | 1 | ||||
-rw-r--r-- | arch/sh/include/asm/vmlinux.lds.h | 17 | ||||
-rw-r--r-- | arch/sh/kernel/Makefile_32 | 1 | ||||
-rw-r--r-- | arch/sh/kernel/Makefile_64 | 1 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/sh3/entry.S | 1 | ||||
-rw-r--r-- | arch/sh/kernel/dwarf.c | 901 | ||||
-rw-r--r-- | arch/sh/kernel/entry-common.S | 8 | ||||
-rw-r--r-- | arch/sh/kernel/irq.c | 4 | ||||
-rw-r--r-- | arch/sh/kernel/vmlinux.lds.S | 4 |
13 files changed, 1363 insertions, 1 deletions
diff --git a/arch/sh/Kconfig.debug b/arch/sh/Kconfig.debug index 763b792b1611..741d20fab2e1 100644 --- a/arch/sh/Kconfig.debug +++ b/arch/sh/Kconfig.debug | |||
@@ -110,6 +110,14 @@ config DUMP_CODE | |||
110 | 110 | ||
111 | Those looking for more verbose debugging output should say Y. | 111 | Those looking for more verbose debugging output should say Y. |
112 | 112 | ||
113 | config DWARF_UNWINDER | ||
114 | bool "Enable the DWARF unwinder for stacktraces" | ||
115 | select FRAME_POINTER | ||
116 | default n | ||
117 | help | ||
118 | Enabling this option will make stacktraces more accurate, at | ||
119 | the cost of an increase in overall kernel size. | ||
120 | |||
113 | config SH_NO_BSS_INIT | 121 | config SH_NO_BSS_INIT |
114 | bool "Avoid zeroing BSS (to speed-up startup on suitable platforms)" | 122 | bool "Avoid zeroing BSS (to speed-up startup on suitable platforms)" |
115 | depends on DEBUG_KERNEL | 123 | depends on DEBUG_KERNEL |
diff --git a/arch/sh/Makefile b/arch/sh/Makefile index b6ff337fd856..e26421bf9976 100644 --- a/arch/sh/Makefile +++ b/arch/sh/Makefile | |||
@@ -191,6 +191,10 @@ ifeq ($(CONFIG_MCOUNT),y) | |||
191 | KBUILD_CFLAGS += -pg | 191 | KBUILD_CFLAGS += -pg |
192 | endif | 192 | endif |
193 | 193 | ||
194 | ifeq ($(CONFIG_DWARF_UNWINDER),y) | ||
195 | KBUILD_CFLAGS += -fasynchronous-unwind-tables | ||
196 | endif | ||
197 | |||
194 | libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y) | 198 | libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y) |
195 | libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y) | 199 | libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y) |
196 | 200 | ||
diff --git a/arch/sh/include/asm/dwarf.h b/arch/sh/include/asm/dwarf.h new file mode 100644 index 000000000000..60b180728d8d --- /dev/null +++ b/arch/sh/include/asm/dwarf.h | |||
@@ -0,0 +1,402 @@ | |||
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 | |||
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 | |||
196 | #ifndef __ASSEMBLY__ | ||
197 | /* | ||
198 | * Read either the frame pointer (r14) or the stack pointer (r15). | ||
199 | * NOTE: this MUST be inlined. | ||
200 | */ | ||
201 | static __always_inline unsigned long dwarf_read_arch_reg(unsigned int reg) | ||
202 | { | ||
203 | unsigned long value; | ||
204 | |||
205 | switch (reg) { | ||
206 | case 14: | ||
207 | __asm__ __volatile__("mov r14, %0\n" : "=r" (value)); | ||
208 | break; | ||
209 | case 15: | ||
210 | __asm__ __volatile__("mov r15, %0\n" : "=r" (value)); | ||
211 | break; | ||
212 | default: | ||
213 | BUG(); | ||
214 | } | ||
215 | |||
216 | return value; | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * dwarf_cie - Common Information Entry | ||
221 | */ | ||
222 | struct dwarf_cie { | ||
223 | unsigned long length; | ||
224 | unsigned long cie_id; | ||
225 | unsigned char version; | ||
226 | const char *augmentation; | ||
227 | unsigned int code_alignment_factor; | ||
228 | int data_alignment_factor; | ||
229 | |||
230 | /* Which column in the rule table represents return addr of func. */ | ||
231 | unsigned int return_address_reg; | ||
232 | |||
233 | unsigned char *initial_instructions; | ||
234 | unsigned char *instructions_end; | ||
235 | |||
236 | unsigned char encoding; | ||
237 | |||
238 | unsigned long cie_pointer; | ||
239 | |||
240 | struct list_head link; | ||
241 | |||
242 | unsigned long flags; | ||
243 | #define DWARF_CIE_Z_AUGMENTATION (1 << 0) | ||
244 | }; | ||
245 | |||
246 | /** | ||
247 | * dwarf_fde - Frame Description Entry | ||
248 | */ | ||
249 | struct dwarf_fde { | ||
250 | unsigned long length; | ||
251 | unsigned long cie_pointer; | ||
252 | struct dwarf_cie *cie; | ||
253 | unsigned long initial_location; | ||
254 | unsigned long address_range; | ||
255 | unsigned char *instructions; | ||
256 | unsigned char *end; | ||
257 | struct list_head link; | ||
258 | }; | ||
259 | |||
260 | /** | ||
261 | * dwarf_frame - DWARF information for a frame in the call stack | ||
262 | */ | ||
263 | struct dwarf_frame { | ||
264 | struct dwarf_frame *prev, *next; | ||
265 | |||
266 | unsigned long pc; | ||
267 | |||
268 | struct dwarf_reg *regs; | ||
269 | unsigned int num_regs; /* how many regs are allocated? */ | ||
270 | |||
271 | unsigned int depth; /* what level are we in the callstack? */ | ||
272 | |||
273 | unsigned long cfa; | ||
274 | |||
275 | /* Valid when DW_FRAME_CFA_REG_OFFSET is set in flags */ | ||
276 | unsigned int cfa_register; | ||
277 | unsigned int cfa_offset; | ||
278 | |||
279 | /* Valid when DW_FRAME_CFA_REG_EXP is set in flags */ | ||
280 | unsigned char *cfa_expr; | ||
281 | unsigned int cfa_expr_len; | ||
282 | |||
283 | unsigned long flags; | ||
284 | #define DWARF_FRAME_CFA_REG_OFFSET (1 << 0) | ||
285 | #define DWARF_FRAME_CFA_REG_EXP (1 << 1) | ||
286 | |||
287 | unsigned long return_addr; | ||
288 | }; | ||
289 | |||
290 | /** | ||
291 | * dwarf_reg - DWARF register | ||
292 | * @flags: Describes how to calculate the value of this register | ||
293 | */ | ||
294 | struct dwarf_reg { | ||
295 | unsigned long addr; | ||
296 | unsigned long flags; | ||
297 | #define DWARF_REG_OFFSET (1 << 0) | ||
298 | }; | ||
299 | |||
300 | /** | ||
301 | * dwarf_stack - a DWARF stack contains a collection of DWARF frames | ||
302 | * @depth: the number of frames in the stack | ||
303 | * @level: an array of DWARF frames, indexed by stack level | ||
304 | * | ||
305 | */ | ||
306 | struct dwarf_stack { | ||
307 | unsigned int depth; | ||
308 | struct dwarf_frame **level; | ||
309 | }; | ||
310 | |||
311 | /* | ||
312 | * Call Frame instruction opcodes. | ||
313 | */ | ||
314 | #define DW_CFA_advance_loc 0x40 | ||
315 | #define DW_CFA_offset 0x80 | ||
316 | #define DW_CFA_restore 0xc0 | ||
317 | #define DW_CFA_nop 0x00 | ||
318 | #define DW_CFA_set_loc 0x01 | ||
319 | #define DW_CFA_advance_loc1 0x02 | ||
320 | #define DW_CFA_advance_loc2 0x03 | ||
321 | #define DW_CFA_advance_loc4 0x04 | ||
322 | #define DW_CFA_offset_extended 0x05 | ||
323 | #define DW_CFA_restore_extended 0x06 | ||
324 | #define DW_CFA_undefined 0x07 | ||
325 | #define DW_CFA_same_value 0x08 | ||
326 | #define DW_CFA_register 0x09 | ||
327 | #define DW_CFA_remember_state 0x0a | ||
328 | #define DW_CFA_restore_state 0x0b | ||
329 | #define DW_CFA_def_cfa 0x0c | ||
330 | #define DW_CFA_def_cfa_register 0x0d | ||
331 | #define DW_CFA_def_cfa_offset 0x0e | ||
332 | #define DW_CFA_def_cfa_expression 0x0f | ||
333 | #define DW_CFA_expression 0x10 | ||
334 | #define DW_CFA_offset_extended_sf 0x11 | ||
335 | #define DW_CFA_def_cfa_sf 0x12 | ||
336 | #define DW_CFA_def_cfa_offset_sf 0x13 | ||
337 | #define DW_CFA_val_offset 0x14 | ||
338 | #define DW_CFA_val_offset_sf 0x15 | ||
339 | #define DW_CFA_val_expression 0x16 | ||
340 | #define DW_CFA_lo_user 0x1c | ||
341 | #define DW_CFA_hi_user 0x3f | ||
342 | |||
343 | /* | ||
344 | * Some call frame instructions encode their operands in the opcode. We | ||
345 | * need some helper functions to extract both the opcode and operands | ||
346 | * from an instruction. | ||
347 | */ | ||
348 | static inline unsigned int DW_CFA_opcode(unsigned long insn) | ||
349 | { | ||
350 | return (insn & 0xc0); | ||
351 | } | ||
352 | |||
353 | static inline unsigned int DW_CFA_operand(unsigned long insn) | ||
354 | { | ||
355 | return (insn & 0x3f); | ||
356 | } | ||
357 | |||
358 | #define DW_EH_FRAME_CIE 0 /* .eh_frame CIE IDs are 0 */ | ||
359 | #define DW_CIE_ID 0xffffffff | ||
360 | #define DW64_CIE_ID 0xffffffffffffffffULL | ||
361 | |||
362 | /* | ||
363 | * DWARF FDE/CIE length field values. | ||
364 | */ | ||
365 | #define DW_EXT_LO 0xfffffff0 | ||
366 | #define DW_EXT_HI 0xffffffff | ||
367 | #define DW_EXT_DWARF64 DW_EXT_HI | ||
368 | |||
369 | extern void dwarf_unwinder_init(void); | ||
370 | |||
371 | extern struct dwarf_frame *dwarf_unwind_stack(unsigned long, | ||
372 | struct dwarf_frame *); | ||
373 | #endif /* __ASSEMBLY__ */ | ||
374 | |||
375 | #define CFI_STARTPROC .cfi_startproc | ||
376 | #define CFI_ENDPROC .cfi_endproc | ||
377 | #define CFI_DEF_CFA .cfi_def_cfa | ||
378 | #define CFI_REGISTER .cfi_register | ||
379 | #define CFI_REL_OFFSET .cfi_rel_offset | ||
380 | |||
381 | #else | ||
382 | |||
383 | /* | ||
384 | * Use the asm comment character to ignore the rest of the line. | ||
385 | */ | ||
386 | #define CFI_IGNORE ! | ||
387 | |||
388 | #define CFI_STARTPROC CFI_IGNORE | ||
389 | #define CFI_ENDPROC CFI_IGNORE | ||
390 | #define CFI_DEF_CFA CFI_IGNORE | ||
391 | #define CFI_REGISTER CFI_IGNORE | ||
392 | #define CFI_REL_OFFSET CFI_IGNORE | ||
393 | |||
394 | #ifndef __ASSEMBLY__ | ||
395 | static inline void dwarf_unwinder_init(void) | ||
396 | { | ||
397 | } | ||
398 | #endif | ||
399 | |||
400 | #endif /* CONFIG_DWARF_UNWINDER */ | ||
401 | |||
402 | #endif /* __ASM_SH_DWARF_H */ | ||
diff --git a/arch/sh/include/asm/entry-macros.S b/arch/sh/include/asm/entry-macros.S index 1bdd93891cd7..64fd0de24daf 100644 --- a/arch/sh/include/asm/entry-macros.S +++ b/arch/sh/include/asm/entry-macros.S | |||
@@ -108,3 +108,15 @@ | |||
108 | #else | 108 | #else |
109 | # define PREF(x) nop | 109 | # define PREF(x) nop |
110 | #endif | 110 | #endif |
111 | |||
112 | /* | ||
113 | * Macro for use within assembly. Because the DWARF unwinder | ||
114 | * needs to use the frame register to unwind the stack, we | ||
115 | * need to setup r14 with the value of the stack pointer as | ||
116 | * the return address is usually on the stack somewhere. | ||
117 | */ | ||
118 | .macro setup_frame_reg | ||
119 | #ifdef CONFIG_DWARF_UNWINDER | ||
120 | mov r15, r14 | ||
121 | #endif | ||
122 | .endm | ||
diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h index 01a4076a3719..a78701da775b 100644 --- a/arch/sh/include/asm/sections.h +++ b/arch/sh/include/asm/sections.h | |||
@@ -7,6 +7,7 @@ extern void __nosave_begin, __nosave_end; | |||
7 | extern long __machvec_start, __machvec_end; | 7 | extern long __machvec_start, __machvec_end; |
8 | extern char __uncached_start, __uncached_end; | 8 | extern char __uncached_start, __uncached_end; |
9 | extern char _ebss[]; | 9 | extern char _ebss[]; |
10 | extern char __start_eh_frame[], __stop_eh_frame[]; | ||
10 | 11 | ||
11 | #endif /* __ASM_SH_SECTIONS_H */ | 12 | #endif /* __ASM_SH_SECTIONS_H */ |
12 | 13 | ||
diff --git a/arch/sh/include/asm/vmlinux.lds.h b/arch/sh/include/asm/vmlinux.lds.h new file mode 100644 index 000000000000..244ec4ad9a79 --- /dev/null +++ b/arch/sh/include/asm/vmlinux.lds.h | |||
@@ -0,0 +1,17 @@ | |||
1 | #ifndef __ASM_SH_VMLINUX_LDS_H | ||
2 | #define __ASM_SH_VMLINUX_LDS_H | ||
3 | |||
4 | #include <asm-generic/vmlinux.lds.h> | ||
5 | |||
6 | #ifdef CONFIG_DWARF_UNWINDER | ||
7 | #define DWARF_EH_FRAME \ | ||
8 | .eh_frame : AT(ADDR(.eh_frame) - LOAD_OFFSET) { \ | ||
9 | VMLINUX_SYMBOL(__start_eh_frame) = .; \ | ||
10 | *(.eh_frame) \ | ||
11 | VMLINUX_SYMBOL(__stop_eh_frame) = .; \ | ||
12 | } | ||
13 | #else | ||
14 | #define DWARF_EH_FRAME | ||
15 | #endif | ||
16 | |||
17 | #endif /* __ASM_SH_VMLINUX_LDS_H */ | ||
diff --git a/arch/sh/kernel/Makefile_32 b/arch/sh/kernel/Makefile_32 index 37a3b7704fc6..f2245ebf0b31 100644 --- a/arch/sh/kernel/Makefile_32 +++ b/arch/sh/kernel/Makefile_32 | |||
@@ -33,6 +33,7 @@ obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o | |||
33 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o | 33 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o |
34 | obj-$(CONFIG_DUMP_CODE) += disassemble.o | 34 | obj-$(CONFIG_DUMP_CODE) += disassemble.o |
35 | obj-$(CONFIG_HIBERNATION) += swsusp.o | 35 | obj-$(CONFIG_HIBERNATION) += swsusp.o |
36 | obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o | ||
36 | 37 | ||
37 | obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o | 38 | obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o |
38 | 39 | ||
diff --git a/arch/sh/kernel/Makefile_64 b/arch/sh/kernel/Makefile_64 index 00b73e7598cb..639ee514266c 100644 --- a/arch/sh/kernel/Makefile_64 +++ b/arch/sh/kernel/Makefile_64 | |||
@@ -13,6 +13,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o | |||
13 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 13 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
14 | obj-$(CONFIG_IO_TRAPPED) += io_trapped.o | 14 | obj-$(CONFIG_IO_TRAPPED) += io_trapped.o |
15 | obj-$(CONFIG_GENERIC_GPIO) += gpio.o | 15 | obj-$(CONFIG_GENERIC_GPIO) += gpio.o |
16 | obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o | ||
16 | 17 | ||
17 | obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o | 18 | obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o |
18 | 19 | ||
diff --git a/arch/sh/kernel/cpu/sh3/entry.S b/arch/sh/kernel/cpu/sh3/entry.S index 3cb531f233f2..67ad6467c694 100644 --- a/arch/sh/kernel/cpu/sh3/entry.S +++ b/arch/sh/kernel/cpu/sh3/entry.S | |||
@@ -137,6 +137,7 @@ ENTRY(tlb_protection_violation_store) | |||
137 | mov #1, r5 | 137 | mov #1, r5 |
138 | 138 | ||
139 | call_dpf: | 139 | call_dpf: |
140 | setup_frame_reg | ||
140 | mov.l 1f, r0 | 141 | mov.l 1f, r0 |
141 | mov r5, r8 | 142 | mov r5, r8 |
142 | mov.l @r0, r6 | 143 | mov.l @r0, r6 |
diff --git a/arch/sh/kernel/dwarf.c b/arch/sh/kernel/dwarf.c new file mode 100644 index 000000000000..83f3cc92549f --- /dev/null +++ b/arch/sh/kernel/dwarf.c | |||
@@ -0,0 +1,901 @@ | |||
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 | * This is an implementation of a DWARF unwinder. Its main purpose is | ||
9 | * for generating stacktrace information. Based on the DWARF 3 | ||
10 | * specification from http://www.dwarfstd.org. | ||
11 | * | ||
12 | * TODO: | ||
13 | * - DWARF64 doesn't work. | ||
14 | */ | ||
15 | |||
16 | /* #define DEBUG */ | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <linux/list.h> | ||
20 | #include <linux/mm.h> | ||
21 | #include <asm/dwarf.h> | ||
22 | #include <asm/unwinder.h> | ||
23 | #include <asm/sections.h> | ||
24 | #include <asm/unaligned.h> | ||
25 | #include <asm/dwarf.h> | ||
26 | #include <asm/stacktrace.h> | ||
27 | |||
28 | static LIST_HEAD(dwarf_cie_list); | ||
29 | DEFINE_SPINLOCK(dwarf_cie_lock); | ||
30 | |||
31 | static LIST_HEAD(dwarf_fde_list); | ||
32 | DEFINE_SPINLOCK(dwarf_fde_lock); | ||
33 | |||
34 | static struct dwarf_cie *cached_cie; | ||
35 | |||
36 | /* | ||
37 | * Figure out whether we need to allocate some dwarf registers. If dwarf | ||
38 | * registers have already been allocated then we may need to realloc | ||
39 | * them. "reg" is a register number that we need to be able to access | ||
40 | * after this call. | ||
41 | * | ||
42 | * Register numbers start at zero, therefore we need to allocate space | ||
43 | * for "reg" + 1 registers. | ||
44 | */ | ||
45 | static void dwarf_frame_alloc_regs(struct dwarf_frame *frame, | ||
46 | unsigned int reg) | ||
47 | { | ||
48 | struct dwarf_reg *regs; | ||
49 | unsigned int num_regs = reg + 1; | ||
50 | size_t new_size; | ||
51 | size_t old_size; | ||
52 | |||
53 | new_size = num_regs * sizeof(*regs); | ||
54 | old_size = frame->num_regs * sizeof(*regs); | ||
55 | |||
56 | /* Fast path: don't allocate any regs if we've already got enough. */ | ||
57 | if (frame->num_regs >= num_regs) | ||
58 | return; | ||
59 | |||
60 | regs = kzalloc(new_size, GFP_KERNEL); | ||
61 | if (!regs) { | ||
62 | printk(KERN_WARNING "Unable to allocate DWARF registers\n"); | ||
63 | /* | ||
64 | * Let's just bomb hard here, we have no way to | ||
65 | * gracefully recover. | ||
66 | */ | ||
67 | BUG(); | ||
68 | } | ||
69 | |||
70 | if (frame->regs) { | ||
71 | memcpy(regs, frame->regs, old_size); | ||
72 | kfree(frame->regs); | ||
73 | } | ||
74 | |||
75 | frame->regs = regs; | ||
76 | frame->num_regs = num_regs; | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * dwarf_read_addr - read dwarf data | ||
81 | * @src: source address of data | ||
82 | * @dst: destination address to store the data to | ||
83 | * | ||
84 | * Read 'n' bytes from @src, where 'n' is the size of an address on | ||
85 | * the native machine. We return the number of bytes read, which | ||
86 | * should always be 'n'. We also have to be careful when reading | ||
87 | * from @src and writing to @dst, because they can be arbitrarily | ||
88 | * aligned. Return 'n' - the number of bytes read. | ||
89 | */ | ||
90 | static inline int dwarf_read_addr(unsigned long *src, unsigned long *dst) | ||
91 | { | ||
92 | u32 val = get_unaligned(src); | ||
93 | put_unaligned(val, dst); | ||
94 | return sizeof(unsigned long *); | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * dwarf_read_uleb128 - read unsigned LEB128 data | ||
99 | * @addr: the address where the ULEB128 data is stored | ||
100 | * @ret: address to store the result | ||
101 | * | ||
102 | * Decode an unsigned LEB128 encoded datum. The algorithm is taken | ||
103 | * from Appendix C of the DWARF 3 spec. For information on the | ||
104 | * encodings refer to section "7.6 - Variable Length Data". Return | ||
105 | * the number of bytes read. | ||
106 | */ | ||
107 | static inline unsigned long dwarf_read_uleb128(char *addr, unsigned int *ret) | ||
108 | { | ||
109 | unsigned int result; | ||
110 | unsigned char byte; | ||
111 | int shift, count; | ||
112 | |||
113 | result = 0; | ||
114 | shift = 0; | ||
115 | count = 0; | ||
116 | |||
117 | while (1) { | ||
118 | byte = __raw_readb(addr); | ||
119 | addr++; | ||
120 | count++; | ||
121 | |||
122 | result |= (byte & 0x7f) << shift; | ||
123 | shift += 7; | ||
124 | |||
125 | if (!(byte & 0x80)) | ||
126 | break; | ||
127 | } | ||
128 | |||
129 | *ret = result; | ||
130 | |||
131 | return count; | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * dwarf_read_leb128 - read signed LEB128 data | ||
136 | * @addr: the address of the LEB128 encoded data | ||
137 | * @ret: address to store the result | ||
138 | * | ||
139 | * Decode signed LEB128 data. The algorithm is taken from Appendix | ||
140 | * C of the DWARF 3 spec. Return the number of bytes read. | ||
141 | */ | ||
142 | static inline unsigned long dwarf_read_leb128(char *addr, int *ret) | ||
143 | { | ||
144 | unsigned char byte; | ||
145 | int result, shift; | ||
146 | int num_bits; | ||
147 | int count; | ||
148 | |||
149 | result = 0; | ||
150 | shift = 0; | ||
151 | count = 0; | ||
152 | |||
153 | while (1) { | ||
154 | byte = __raw_readb(addr); | ||
155 | addr++; | ||
156 | result |= (byte & 0x7f) << shift; | ||
157 | shift += 7; | ||
158 | count++; | ||
159 | |||
160 | if (!(byte & 0x80)) | ||
161 | break; | ||
162 | } | ||
163 | |||
164 | /* The number of bits in a signed integer. */ | ||
165 | num_bits = 8 * sizeof(result); | ||
166 | |||
167 | if ((shift < num_bits) && (byte & 0x40)) | ||
168 | result |= (-1 << shift); | ||
169 | |||
170 | *ret = result; | ||
171 | |||
172 | return count; | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * dwarf_read_encoded_value - return the decoded value at @addr | ||
177 | * @addr: the address of the encoded value | ||
178 | * @val: where to write the decoded value | ||
179 | * @encoding: the encoding with which we can decode @addr | ||
180 | * | ||
181 | * GCC emits encoded address in the .eh_frame FDE entries. Decode | ||
182 | * the value at @addr using @encoding. The decoded value is written | ||
183 | * to @val and the number of bytes read is returned. | ||
184 | */ | ||
185 | static int dwarf_read_encoded_value(char *addr, unsigned long *val, | ||
186 | char encoding) | ||
187 | { | ||
188 | unsigned long decoded_addr = 0; | ||
189 | int count = 0; | ||
190 | |||
191 | switch (encoding & 0x70) { | ||
192 | case DW_EH_PE_absptr: | ||
193 | break; | ||
194 | case DW_EH_PE_pcrel: | ||
195 | decoded_addr = (unsigned long)addr; | ||
196 | break; | ||
197 | default: | ||
198 | pr_debug("encoding=0x%x\n", (encoding & 0x70)); | ||
199 | BUG(); | ||
200 | } | ||
201 | |||
202 | if ((encoding & 0x07) == 0x00) | ||
203 | encoding |= DW_EH_PE_udata4; | ||
204 | |||
205 | switch (encoding & 0x0f) { | ||
206 | case DW_EH_PE_sdata4: | ||
207 | case DW_EH_PE_udata4: | ||
208 | count += 4; | ||
209 | decoded_addr += get_unaligned((u32 *)addr); | ||
210 | __raw_writel(decoded_addr, val); | ||
211 | break; | ||
212 | default: | ||
213 | pr_debug("encoding=0x%x\n", encoding); | ||
214 | BUG(); | ||
215 | } | ||
216 | |||
217 | return count; | ||
218 | } | ||
219 | |||
220 | /** | ||
221 | * dwarf_entry_len - return the length of an FDE or CIE | ||
222 | * @addr: the address of the entry | ||
223 | * @len: the length of the entry | ||
224 | * | ||
225 | * Read the initial_length field of the entry and store the size of | ||
226 | * the entry in @len. We return the number of bytes read. Return a | ||
227 | * count of 0 on error. | ||
228 | */ | ||
229 | static inline int dwarf_entry_len(char *addr, unsigned long *len) | ||
230 | { | ||
231 | u32 initial_len; | ||
232 | int count; | ||
233 | |||
234 | initial_len = get_unaligned((u32 *)addr); | ||
235 | count = 4; | ||
236 | |||
237 | /* | ||
238 | * An initial length field value in the range DW_LEN_EXT_LO - | ||
239 | * DW_LEN_EXT_HI indicates an extension, and should not be | ||
240 | * interpreted as a length. The only extension that we currently | ||
241 | * understand is the use of DWARF64 addresses. | ||
242 | */ | ||
243 | if (initial_len >= DW_EXT_LO && initial_len <= DW_EXT_HI) { | ||
244 | /* | ||
245 | * The 64-bit length field immediately follows the | ||
246 | * compulsory 32-bit length field. | ||
247 | */ | ||
248 | if (initial_len == DW_EXT_DWARF64) { | ||
249 | *len = get_unaligned((u64 *)addr + 4); | ||
250 | count = 12; | ||
251 | } else { | ||
252 | printk(KERN_WARNING "Unknown DWARF extension\n"); | ||
253 | count = 0; | ||
254 | } | ||
255 | } else | ||
256 | *len = initial_len; | ||
257 | |||
258 | return count; | ||
259 | } | ||
260 | |||
261 | /** | ||
262 | * dwarf_lookup_cie - locate the cie | ||
263 | * @cie_ptr: pointer to help with lookup | ||
264 | */ | ||
265 | static struct dwarf_cie *dwarf_lookup_cie(unsigned long cie_ptr) | ||
266 | { | ||
267 | struct dwarf_cie *cie, *n; | ||
268 | unsigned long flags; | ||
269 | |||
270 | spin_lock_irqsave(&dwarf_cie_lock, flags); | ||
271 | |||
272 | /* | ||
273 | * We've cached the last CIE we looked up because chances are | ||
274 | * that the FDE wants this CIE. | ||
275 | */ | ||
276 | if (cached_cie && cached_cie->cie_pointer == cie_ptr) { | ||
277 | cie = cached_cie; | ||
278 | goto out; | ||
279 | } | ||
280 | |||
281 | list_for_each_entry_safe(cie, n, &dwarf_cie_list, link) { | ||
282 | if (cie->cie_pointer == cie_ptr) { | ||
283 | cached_cie = cie; | ||
284 | break; | ||
285 | } | ||
286 | } | ||
287 | |||
288 | /* Couldn't find the entry in the list. */ | ||
289 | if (&cie->link == &dwarf_cie_list) | ||
290 | cie = NULL; | ||
291 | out: | ||
292 | spin_unlock_irqrestore(&dwarf_cie_lock, flags); | ||
293 | return cie; | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * dwarf_lookup_fde - locate the FDE that covers pc | ||
298 | * @pc: the program counter | ||
299 | */ | ||
300 | struct dwarf_fde *dwarf_lookup_fde(unsigned long pc) | ||
301 | { | ||
302 | unsigned long flags; | ||
303 | struct dwarf_fde *fde, *n; | ||
304 | |||
305 | spin_lock_irqsave(&dwarf_fde_lock, flags); | ||
306 | list_for_each_entry_safe(fde, n, &dwarf_fde_list, link) { | ||
307 | unsigned long start, end; | ||
308 | |||
309 | start = fde->initial_location; | ||
310 | end = fde->initial_location + fde->address_range; | ||
311 | |||
312 | if (pc >= start && pc < end) | ||
313 | break; | ||
314 | } | ||
315 | |||
316 | /* Couldn't find the entry in the list. */ | ||
317 | if (&fde->link == &dwarf_fde_list) | ||
318 | fde = NULL; | ||
319 | |||
320 | spin_unlock_irqrestore(&dwarf_fde_lock, flags); | ||
321 | |||
322 | return fde; | ||
323 | } | ||
324 | |||
325 | /** | ||
326 | * dwarf_cfa_execute_insns - execute instructions to calculate a CFA | ||
327 | * @insn_start: address of the first instruction | ||
328 | * @insn_end: address of the last instruction | ||
329 | * @cie: the CIE for this function | ||
330 | * @fde: the FDE for this function | ||
331 | * @frame: the instructions calculate the CFA for this frame | ||
332 | * @pc: the program counter of the address we're interested in | ||
333 | * @define_ra: keep executing insns until the return addr reg is defined? | ||
334 | * | ||
335 | * Execute the Call Frame instruction sequence starting at | ||
336 | * @insn_start and ending at @insn_end. The instructions describe | ||
337 | * how to calculate the Canonical Frame Address of a stackframe. | ||
338 | * Store the results in @frame. | ||
339 | */ | ||
340 | static int dwarf_cfa_execute_insns(unsigned char *insn_start, | ||
341 | unsigned char *insn_end, | ||
342 | struct dwarf_cie *cie, | ||
343 | struct dwarf_fde *fde, | ||
344 | struct dwarf_frame *frame, | ||
345 | unsigned long pc, | ||
346 | bool define_ra) | ||
347 | { | ||
348 | unsigned char insn; | ||
349 | unsigned char *current_insn; | ||
350 | unsigned int count, delta, reg, expr_len, offset; | ||
351 | bool seen_ra_reg; | ||
352 | |||
353 | current_insn = insn_start; | ||
354 | |||
355 | /* | ||
356 | * If we're executing instructions for the dwarf_unwind_stack() | ||
357 | * FDE we need to keep executing instructions until the value of | ||
358 | * DWARF_ARCH_RA_REG is defined. See the comment in | ||
359 | * dwarf_unwind_stack() for more details. | ||
360 | */ | ||
361 | if (define_ra) | ||
362 | seen_ra_reg = false; | ||
363 | else | ||
364 | seen_ra_reg = true; | ||
365 | |||
366 | while (current_insn < insn_end && (frame->pc <= pc || !seen_ra_reg) ) { | ||
367 | insn = __raw_readb(current_insn++); | ||
368 | |||
369 | if (!seen_ra_reg) { | ||
370 | if (frame->num_regs >= DWARF_ARCH_RA_REG && | ||
371 | frame->regs[DWARF_ARCH_RA_REG].flags) | ||
372 | seen_ra_reg = true; | ||
373 | } | ||
374 | |||
375 | /* | ||
376 | * Firstly, handle the opcodes that embed their operands | ||
377 | * in the instructions. | ||
378 | */ | ||
379 | switch (DW_CFA_opcode(insn)) { | ||
380 | case DW_CFA_advance_loc: | ||
381 | delta = DW_CFA_operand(insn); | ||
382 | delta *= cie->code_alignment_factor; | ||
383 | frame->pc += delta; | ||
384 | continue; | ||
385 | /* NOTREACHED */ | ||
386 | case DW_CFA_offset: | ||
387 | reg = DW_CFA_operand(insn); | ||
388 | count = dwarf_read_uleb128(current_insn, &offset); | ||
389 | current_insn += count; | ||
390 | offset *= cie->data_alignment_factor; | ||
391 | dwarf_frame_alloc_regs(frame, reg); | ||
392 | frame->regs[reg].addr = offset; | ||
393 | frame->regs[reg].flags |= DWARF_REG_OFFSET; | ||
394 | continue; | ||
395 | /* NOTREACHED */ | ||
396 | case DW_CFA_restore: | ||
397 | reg = DW_CFA_operand(insn); | ||
398 | continue; | ||
399 | /* NOTREACHED */ | ||
400 | } | ||
401 | |||
402 | /* | ||
403 | * Secondly, handle the opcodes that don't embed their | ||
404 | * operands in the instruction. | ||
405 | */ | ||
406 | switch (insn) { | ||
407 | case DW_CFA_nop: | ||
408 | continue; | ||
409 | case DW_CFA_advance_loc1: | ||
410 | delta = *current_insn++; | ||
411 | frame->pc += delta * cie->code_alignment_factor; | ||
412 | break; | ||
413 | case DW_CFA_advance_loc2: | ||
414 | delta = get_unaligned((u16 *)current_insn); | ||
415 | current_insn += 2; | ||
416 | frame->pc += delta * cie->code_alignment_factor; | ||
417 | break; | ||
418 | case DW_CFA_advance_loc4: | ||
419 | delta = get_unaligned((u32 *)current_insn); | ||
420 | current_insn += 4; | ||
421 | frame->pc += delta * cie->code_alignment_factor; | ||
422 | break; | ||
423 | case DW_CFA_offset_extended: | ||
424 | count = dwarf_read_uleb128(current_insn, ®); | ||
425 | current_insn += count; | ||
426 | count = dwarf_read_uleb128(current_insn, &offset); | ||
427 | current_insn += count; | ||
428 | offset *= cie->data_alignment_factor; | ||
429 | break; | ||
430 | case DW_CFA_restore_extended: | ||
431 | count = dwarf_read_uleb128(current_insn, ®); | ||
432 | current_insn += count; | ||
433 | break; | ||
434 | case DW_CFA_undefined: | ||
435 | count = dwarf_read_uleb128(current_insn, ®); | ||
436 | current_insn += count; | ||
437 | break; | ||
438 | case DW_CFA_def_cfa: | ||
439 | count = dwarf_read_uleb128(current_insn, | ||
440 | &frame->cfa_register); | ||
441 | current_insn += count; | ||
442 | count = dwarf_read_uleb128(current_insn, | ||
443 | &frame->cfa_offset); | ||
444 | current_insn += count; | ||
445 | |||
446 | frame->flags |= DWARF_FRAME_CFA_REG_OFFSET; | ||
447 | break; | ||
448 | case DW_CFA_def_cfa_register: | ||
449 | count = dwarf_read_uleb128(current_insn, | ||
450 | &frame->cfa_register); | ||
451 | current_insn += count; | ||
452 | frame->flags |= DWARF_FRAME_CFA_REG_OFFSET; | ||
453 | break; | ||
454 | case DW_CFA_def_cfa_offset: | ||
455 | count = dwarf_read_uleb128(current_insn, &offset); | ||
456 | current_insn += count; | ||
457 | frame->cfa_offset = offset; | ||
458 | break; | ||
459 | case DW_CFA_def_cfa_expression: | ||
460 | count = dwarf_read_uleb128(current_insn, &expr_len); | ||
461 | current_insn += count; | ||
462 | |||
463 | frame->cfa_expr = current_insn; | ||
464 | frame->cfa_expr_len = expr_len; | ||
465 | current_insn += expr_len; | ||
466 | |||
467 | frame->flags |= DWARF_FRAME_CFA_REG_EXP; | ||
468 | break; | ||
469 | case DW_CFA_offset_extended_sf: | ||
470 | count = dwarf_read_uleb128(current_insn, ®); | ||
471 | current_insn += count; | ||
472 | count = dwarf_read_leb128(current_insn, &offset); | ||
473 | current_insn += count; | ||
474 | offset *= cie->data_alignment_factor; | ||
475 | dwarf_frame_alloc_regs(frame, reg); | ||
476 | frame->regs[reg].flags |= DWARF_REG_OFFSET; | ||
477 | frame->regs[reg].addr = offset; | ||
478 | break; | ||
479 | case DW_CFA_val_offset: | ||
480 | count = dwarf_read_uleb128(current_insn, ®); | ||
481 | current_insn += count; | ||
482 | count = dwarf_read_leb128(current_insn, &offset); | ||
483 | offset *= cie->data_alignment_factor; | ||
484 | frame->regs[reg].flags |= DWARF_REG_OFFSET; | ||
485 | frame->regs[reg].addr = offset; | ||
486 | break; | ||
487 | default: | ||
488 | pr_debug("unhandled DWARF instruction 0x%x\n", insn); | ||
489 | break; | ||
490 | } | ||
491 | } | ||
492 | |||
493 | return 0; | ||
494 | } | ||
495 | |||
496 | /** | ||
497 | * dwarf_unwind_stack - recursively unwind the stack | ||
498 | * @pc: address of the function to unwind | ||
499 | * @prev: struct dwarf_frame of the previous stackframe on the callstack | ||
500 | * | ||
501 | * Return a struct dwarf_frame representing the most recent frame | ||
502 | * on the callstack. Each of the lower (older) stack frames are | ||
503 | * linked via the "prev" member. | ||
504 | */ | ||
505 | struct dwarf_frame *dwarf_unwind_stack(unsigned long pc, | ||
506 | struct dwarf_frame *prev) | ||
507 | { | ||
508 | struct dwarf_frame *frame; | ||
509 | struct dwarf_cie *cie; | ||
510 | struct dwarf_fde *fde; | ||
511 | unsigned long addr; | ||
512 | int i, offset; | ||
513 | bool define_ra = false; | ||
514 | |||
515 | /* | ||
516 | * If this is the first invocation of this recursive function we | ||
517 | * need get the contents of a physical register to get the CFA | ||
518 | * in order to begin the virtual unwinding of the stack. | ||
519 | * | ||
520 | * Setting "define_ra" to true indictates that we want | ||
521 | * dwarf_cfa_execute_insns() to continue executing instructions | ||
522 | * until we know how to calculate the value of DWARF_ARCH_RA_REG | ||
523 | * (which we need in order to kick off the whole unwinding | ||
524 | * process). | ||
525 | * | ||
526 | * NOTE: the return address is guaranteed to be setup by the | ||
527 | * time this function makes its first function call. | ||
528 | */ | ||
529 | if (!pc && !prev) { | ||
530 | pc = (unsigned long)&dwarf_unwind_stack; | ||
531 | define_ra = true; | ||
532 | } | ||
533 | |||
534 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); | ||
535 | if (!frame) | ||
536 | return NULL; | ||
537 | |||
538 | frame->prev = prev; | ||
539 | |||
540 | fde = dwarf_lookup_fde(pc); | ||
541 | if (!fde) { | ||
542 | /* | ||
543 | * This is our normal exit path - the one that stops the | ||
544 | * recursion. There's two reasons why we might exit | ||
545 | * here, | ||
546 | * | ||
547 | * a) pc has no asscociated DWARF frame info and so | ||
548 | * we don't know how to unwind this frame. This is | ||
549 | * usually the case when we're trying to unwind a | ||
550 | * frame that was called from some assembly code | ||
551 | * that has no DWARF info, e.g. syscalls. | ||
552 | * | ||
553 | * b) the DEBUG info for pc is bogus. There's | ||
554 | * really no way to distinguish this case from the | ||
555 | * case above, which sucks because we could print a | ||
556 | * warning here. | ||
557 | */ | ||
558 | return NULL; | ||
559 | } | ||
560 | |||
561 | cie = dwarf_lookup_cie(fde->cie_pointer); | ||
562 | |||
563 | frame->pc = fde->initial_location; | ||
564 | |||
565 | /* CIE initial instructions */ | ||
566 | dwarf_cfa_execute_insns(cie->initial_instructions, | ||
567 | cie->instructions_end, cie, fde, | ||
568 | frame, pc, false); | ||
569 | |||
570 | /* FDE instructions */ | ||
571 | dwarf_cfa_execute_insns(fde->instructions, fde->end, cie, | ||
572 | fde, frame, pc, define_ra); | ||
573 | |||
574 | /* Calculate the CFA */ | ||
575 | switch (frame->flags) { | ||
576 | case DWARF_FRAME_CFA_REG_OFFSET: | ||
577 | if (prev) { | ||
578 | BUG_ON(!prev->regs[frame->cfa_register].flags); | ||
579 | |||
580 | addr = prev->cfa; | ||
581 | addr += prev->regs[frame->cfa_register].addr; | ||
582 | frame->cfa = __raw_readl(addr); | ||
583 | |||
584 | } else { | ||
585 | /* | ||
586 | * Again, this is the first invocation of this | ||
587 | * recurisve function. We need to physically | ||
588 | * read the contents of a register in order to | ||
589 | * get the Canonical Frame Address for this | ||
590 | * function. | ||
591 | */ | ||
592 | frame->cfa = dwarf_read_arch_reg(frame->cfa_register); | ||
593 | } | ||
594 | |||
595 | frame->cfa += frame->cfa_offset; | ||
596 | break; | ||
597 | default: | ||
598 | BUG(); | ||
599 | } | ||
600 | |||
601 | /* If we haven't seen the return address reg, we're screwed. */ | ||
602 | BUG_ON(!frame->regs[DWARF_ARCH_RA_REG].flags); | ||
603 | |||
604 | for (i = 0; i <= frame->num_regs; i++) { | ||
605 | struct dwarf_reg *reg = &frame->regs[i]; | ||
606 | |||
607 | if (!reg->flags) | ||
608 | continue; | ||
609 | |||
610 | offset = reg->addr; | ||
611 | offset += frame->cfa; | ||
612 | } | ||
613 | |||
614 | addr = frame->cfa + frame->regs[DWARF_ARCH_RA_REG].addr; | ||
615 | frame->return_addr = __raw_readl(addr); | ||
616 | |||
617 | frame->next = dwarf_unwind_stack(frame->return_addr, frame); | ||
618 | return frame; | ||
619 | } | ||
620 | |||
621 | static int dwarf_parse_cie(void *entry, void *p, unsigned long len, | ||
622 | unsigned char *end) | ||
623 | { | ||
624 | struct dwarf_cie *cie; | ||
625 | unsigned long flags; | ||
626 | int count; | ||
627 | |||
628 | cie = kzalloc(sizeof(*cie), GFP_KERNEL); | ||
629 | if (!cie) | ||
630 | return -ENOMEM; | ||
631 | |||
632 | cie->length = len; | ||
633 | |||
634 | /* | ||
635 | * Record the offset into the .eh_frame section | ||
636 | * for this CIE. It allows this CIE to be | ||
637 | * quickly and easily looked up from the | ||
638 | * corresponding FDE. | ||
639 | */ | ||
640 | cie->cie_pointer = (unsigned long)entry; | ||
641 | |||
642 | cie->version = *(char *)p++; | ||
643 | BUG_ON(cie->version != 1); | ||
644 | |||
645 | cie->augmentation = p; | ||
646 | p += strlen(cie->augmentation) + 1; | ||
647 | |||
648 | count = dwarf_read_uleb128(p, &cie->code_alignment_factor); | ||
649 | p += count; | ||
650 | |||
651 | count = dwarf_read_leb128(p, &cie->data_alignment_factor); | ||
652 | p += count; | ||
653 | |||
654 | /* | ||
655 | * Which column in the rule table contains the | ||
656 | * return address? | ||
657 | */ | ||
658 | if (cie->version == 1) { | ||
659 | cie->return_address_reg = __raw_readb(p); | ||
660 | p++; | ||
661 | } else { | ||
662 | count = dwarf_read_uleb128(p, &cie->return_address_reg); | ||
663 | p += count; | ||
664 | } | ||
665 | |||
666 | if (cie->augmentation[0] == 'z') { | ||
667 | unsigned int length, count; | ||
668 | cie->flags |= DWARF_CIE_Z_AUGMENTATION; | ||
669 | |||
670 | count = dwarf_read_uleb128(p, &length); | ||
671 | p += count; | ||
672 | |||
673 | BUG_ON((unsigned char *)p > end); | ||
674 | |||
675 | cie->initial_instructions = p + length; | ||
676 | cie->augmentation++; | ||
677 | } | ||
678 | |||
679 | while (*cie->augmentation) { | ||
680 | /* | ||
681 | * "L" indicates a byte showing how the | ||
682 | * LSDA pointer is encoded. Skip it. | ||
683 | */ | ||
684 | if (*cie->augmentation == 'L') { | ||
685 | p++; | ||
686 | cie->augmentation++; | ||
687 | } else if (*cie->augmentation == 'R') { | ||
688 | /* | ||
689 | * "R" indicates a byte showing | ||
690 | * how FDE addresses are | ||
691 | * encoded. | ||
692 | */ | ||
693 | cie->encoding = *(char *)p++; | ||
694 | cie->augmentation++; | ||
695 | } else if (*cie->augmentation == 'P') { | ||
696 | /* | ||
697 | * "R" indicates a personality | ||
698 | * routine in the CIE | ||
699 | * augmentation. | ||
700 | */ | ||
701 | BUG(); | ||
702 | } else if (*cie->augmentation == 'S') { | ||
703 | BUG(); | ||
704 | } else { | ||
705 | /* | ||
706 | * Unknown augmentation. Assume | ||
707 | * 'z' augmentation. | ||
708 | */ | ||
709 | p = cie->initial_instructions; | ||
710 | BUG_ON(!p); | ||
711 | break; | ||
712 | } | ||
713 | } | ||
714 | |||
715 | cie->initial_instructions = p; | ||
716 | cie->instructions_end = end; | ||
717 | |||
718 | /* Add to list */ | ||
719 | spin_lock_irqsave(&dwarf_cie_lock, flags); | ||
720 | list_add_tail(&cie->link, &dwarf_cie_list); | ||
721 | spin_unlock_irqrestore(&dwarf_cie_lock, flags); | ||
722 | |||
723 | return 0; | ||
724 | } | ||
725 | |||
726 | static int dwarf_parse_fde(void *entry, u32 entry_type, | ||
727 | void *start, unsigned long len) | ||
728 | { | ||
729 | struct dwarf_fde *fde; | ||
730 | struct dwarf_cie *cie; | ||
731 | unsigned long flags; | ||
732 | int count; | ||
733 | void *p = start; | ||
734 | |||
735 | fde = kzalloc(sizeof(*fde), GFP_KERNEL); | ||
736 | if (!fde) | ||
737 | return -ENOMEM; | ||
738 | |||
739 | fde->length = len; | ||
740 | |||
741 | /* | ||
742 | * In a .eh_frame section the CIE pointer is the | ||
743 | * delta between the address within the FDE | ||
744 | */ | ||
745 | fde->cie_pointer = (unsigned long)(p - entry_type - 4); | ||
746 | |||
747 | cie = dwarf_lookup_cie(fde->cie_pointer); | ||
748 | fde->cie = cie; | ||
749 | |||
750 | if (cie->encoding) | ||
751 | count = dwarf_read_encoded_value(p, &fde->initial_location, | ||
752 | cie->encoding); | ||
753 | else | ||
754 | count = dwarf_read_addr(p, &fde->initial_location); | ||
755 | |||
756 | p += count; | ||
757 | |||
758 | if (cie->encoding) | ||
759 | count = dwarf_read_encoded_value(p, &fde->address_range, | ||
760 | cie->encoding & 0x0f); | ||
761 | else | ||
762 | count = dwarf_read_addr(p, &fde->address_range); | ||
763 | |||
764 | p += count; | ||
765 | |||
766 | if (fde->cie->flags & DWARF_CIE_Z_AUGMENTATION) { | ||
767 | unsigned int length; | ||
768 | count = dwarf_read_uleb128(p, &length); | ||
769 | p += count + length; | ||
770 | } | ||
771 | |||
772 | /* Call frame instructions. */ | ||
773 | fde->instructions = p; | ||
774 | fde->end = start + len; | ||
775 | |||
776 | /* Add to list. */ | ||
777 | spin_lock_irqsave(&dwarf_fde_lock, flags); | ||
778 | list_add_tail(&fde->link, &dwarf_fde_list); | ||
779 | spin_unlock_irqrestore(&dwarf_fde_lock, flags); | ||
780 | |||
781 | return 0; | ||
782 | } | ||
783 | |||
784 | static void dwarf_unwinder_dump(struct task_struct *task, struct pt_regs *regs, | ||
785 | unsigned long *sp, | ||
786 | const struct stacktrace_ops *ops, void *data) | ||
787 | { | ||
788 | struct dwarf_frame *frame; | ||
789 | |||
790 | frame = dwarf_unwind_stack(0, NULL); | ||
791 | |||
792 | while (frame && frame->return_addr) { | ||
793 | ops->address(data, frame->return_addr, 1); | ||
794 | frame = frame->next; | ||
795 | } | ||
796 | } | ||
797 | |||
798 | static struct unwinder dwarf_unwinder = { | ||
799 | .name = "dwarf-unwinder", | ||
800 | .dump = dwarf_unwinder_dump, | ||
801 | .rating = 150, | ||
802 | }; | ||
803 | |||
804 | static void dwarf_unwinder_cleanup(void) | ||
805 | { | ||
806 | struct dwarf_cie *cie, *m; | ||
807 | struct dwarf_fde *fde, *n; | ||
808 | unsigned long flags; | ||
809 | |||
810 | /* | ||
811 | * Deallocate all the memory allocated for the DWARF unwinder. | ||
812 | * Traverse all the FDE/CIE lists and remove and free all the | ||
813 | * memory associated with those data structures. | ||
814 | */ | ||
815 | spin_lock_irqsave(&dwarf_cie_lock, flags); | ||
816 | list_for_each_entry_safe(cie, m, &dwarf_cie_list, link) | ||
817 | kfree(cie); | ||
818 | spin_unlock_irqrestore(&dwarf_cie_lock, flags); | ||
819 | |||
820 | spin_lock_irqsave(&dwarf_fde_lock, flags); | ||
821 | list_for_each_entry_safe(fde, n, &dwarf_fde_list, link) | ||
822 | kfree(fde); | ||
823 | spin_unlock_irqrestore(&dwarf_fde_lock, flags); | ||
824 | } | ||
825 | |||
826 | /** | ||
827 | * dwarf_unwinder_init - initialise the dwarf unwinder | ||
828 | * | ||
829 | * Build the data structures describing the .dwarf_frame section to | ||
830 | * make it easier to lookup CIE and FDE entries. Because the | ||
831 | * .eh_frame section is packed as tightly as possible it is not | ||
832 | * easy to lookup the FDE for a given PC, so we build a list of FDE | ||
833 | * and CIE entries that make it easier. | ||
834 | */ | ||
835 | void dwarf_unwinder_init(void) | ||
836 | { | ||
837 | u32 entry_type; | ||
838 | void *p, *entry; | ||
839 | int count, err; | ||
840 | unsigned long len; | ||
841 | unsigned int c_entries, f_entries; | ||
842 | unsigned char *end; | ||
843 | INIT_LIST_HEAD(&dwarf_cie_list); | ||
844 | INIT_LIST_HEAD(&dwarf_fde_list); | ||
845 | |||
846 | c_entries = 0; | ||
847 | f_entries = 0; | ||
848 | entry = &__start_eh_frame; | ||
849 | |||
850 | while ((char *)entry < __stop_eh_frame) { | ||
851 | p = entry; | ||
852 | |||
853 | count = dwarf_entry_len(p, &len); | ||
854 | if (count == 0) { | ||
855 | /* | ||
856 | * We read a bogus length field value. There is | ||
857 | * nothing we can do here apart from disabling | ||
858 | * the DWARF unwinder. We can't even skip this | ||
859 | * entry and move to the next one because 'len' | ||
860 | * tells us where our next entry is. | ||
861 | */ | ||
862 | goto out; | ||
863 | } else | ||
864 | p += count; | ||
865 | |||
866 | /* initial length does not include itself */ | ||
867 | end = p + len; | ||
868 | |||
869 | entry_type = get_unaligned((u32 *)p); | ||
870 | p += 4; | ||
871 | |||
872 | if (entry_type == DW_EH_FRAME_CIE) { | ||
873 | err = dwarf_parse_cie(entry, p, len, end); | ||
874 | if (err < 0) | ||
875 | goto out; | ||
876 | else | ||
877 | c_entries++; | ||
878 | } else { | ||
879 | err = dwarf_parse_fde(entry, entry_type, p, len); | ||
880 | if (err < 0) | ||
881 | goto out; | ||
882 | else | ||
883 | f_entries++; | ||
884 | } | ||
885 | |||
886 | entry = (char *)entry + len + 4; | ||
887 | } | ||
888 | |||
889 | printk(KERN_INFO "DWARF unwinder initialised: read %u CIEs, %u FDEs\n", | ||
890 | c_entries, f_entries); | ||
891 | |||
892 | err = unwinder_register(&dwarf_unwinder); | ||
893 | if (err) | ||
894 | goto out; | ||
895 | |||
896 | return; | ||
897 | |||
898 | out: | ||
899 | printk(KERN_ERR "Failed to initialise DWARF unwinder: %d\n", err); | ||
900 | dwarf_unwinder_cleanup(); | ||
901 | } | ||
diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S index fc26ccd82789..e63178fefb9b 100644 --- a/arch/sh/kernel/entry-common.S +++ b/arch/sh/kernel/entry-common.S | |||
@@ -43,6 +43,7 @@ | |||
43 | * syscall # | 43 | * syscall # |
44 | * | 44 | * |
45 | */ | 45 | */ |
46 | #include <asm/dwarf.h> | ||
46 | 47 | ||
47 | #if defined(CONFIG_PREEMPT) | 48 | #if defined(CONFIG_PREEMPT) |
48 | # define preempt_stop() cli ; TRACE_IRQS_OFF | 49 | # define preempt_stop() cli ; TRACE_IRQS_OFF |
@@ -66,6 +67,11 @@ ENTRY(exception_error) | |||
66 | 67 | ||
67 | .align 2 | 68 | .align 2 |
68 | ret_from_exception: | 69 | ret_from_exception: |
70 | CFI_STARTPROC simple | ||
71 | CFI_DEF_CFA r14, 0 | ||
72 | CFI_REL_OFFSET 17, 64 | ||
73 | CFI_REL_OFFSET 15, 0 | ||
74 | CFI_REL_OFFSET 14, 56 | ||
69 | preempt_stop() | 75 | preempt_stop() |
70 | ENTRY(ret_from_irq) | 76 | ENTRY(ret_from_irq) |
71 | ! | 77 | ! |
@@ -240,6 +246,7 @@ debug_trap: | |||
240 | nop | 246 | nop |
241 | bra __restore_all | 247 | bra __restore_all |
242 | nop | 248 | nop |
249 | CFI_ENDPROC | ||
243 | 250 | ||
244 | .align 2 | 251 | .align 2 |
245 | 1: .long debug_trap_table | 252 | 1: .long debug_trap_table |
@@ -285,6 +292,7 @@ ret_from_fork: | |||
285 | * system calls and debug traps through their respective jump tables. | 292 | * system calls and debug traps through their respective jump tables. |
286 | */ | 293 | */ |
287 | ENTRY(system_call) | 294 | ENTRY(system_call) |
295 | setup_frame_reg | ||
288 | #if !defined(CONFIG_CPU_SH2) | 296 | #if !defined(CONFIG_CPU_SH2) |
289 | mov.l 1f, r9 | 297 | mov.l 1f, r9 |
290 | mov.l @r9, r8 ! Read from TRA (Trap Address) Register | 298 | mov.l @r9, r8 ! Read from TRA (Trap Address) Register |
diff --git a/arch/sh/kernel/irq.c b/arch/sh/kernel/irq.c index 278c68c60488..2bb43dc74f22 100644 --- a/arch/sh/kernel/irq.c +++ b/arch/sh/kernel/irq.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <asm/processor.h> | 14 | #include <asm/processor.h> |
15 | #include <asm/machvec.h> | 15 | #include <asm/machvec.h> |
16 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
17 | #include <asm/dwarf.h> | ||
17 | #include <asm/thread_info.h> | 18 | #include <asm/thread_info.h> |
18 | #include <cpu/mmu_context.h> | 19 | #include <cpu/mmu_context.h> |
19 | 20 | ||
@@ -261,6 +262,9 @@ void __init init_IRQ(void) | |||
261 | sh_mv.mv_init_irq(); | 262 | sh_mv.mv_init_irq(); |
262 | 263 | ||
263 | irq_ctx_init(smp_processor_id()); | 264 | irq_ctx_init(smp_processor_id()); |
265 | |||
266 | /* This needs to be early, but not too early.. */ | ||
267 | dwarf_unwinder_init(); | ||
264 | } | 268 | } |
265 | 269 | ||
266 | #ifdef CONFIG_SPARSE_IRQ | 270 | #ifdef CONFIG_SPARSE_IRQ |
diff --git a/arch/sh/kernel/vmlinux.lds.S b/arch/sh/kernel/vmlinux.lds.S index 80dc9f8d9412..1b7d9d541e01 100644 --- a/arch/sh/kernel/vmlinux.lds.S +++ b/arch/sh/kernel/vmlinux.lds.S | |||
@@ -12,7 +12,7 @@ OUTPUT_ARCH(sh) | |||
12 | 12 | ||
13 | #include <asm/thread_info.h> | 13 | #include <asm/thread_info.h> |
14 | #include <asm/cache.h> | 14 | #include <asm/cache.h> |
15 | #include <asm-generic/vmlinux.lds.h> | 15 | #include <asm/vmlinux.lds.h> |
16 | 16 | ||
17 | ENTRY(_start) | 17 | ENTRY(_start) |
18 | SECTIONS | 18 | SECTIONS |
@@ -70,6 +70,8 @@ SECTIONS | |||
70 | 70 | ||
71 | _edata = .; /* End of data section */ | 71 | _edata = .; /* End of data section */ |
72 | 72 | ||
73 | DWARF_EH_FRAME | ||
74 | |||
73 | . = ALIGN(PAGE_SIZE); /* Init code and data */ | 75 | . = ALIGN(PAGE_SIZE); /* Init code and data */ |
74 | __init_begin = .; | 76 | __init_begin = .; |
75 | INIT_TEXT_SECTION(PAGE_SIZE) | 77 | INIT_TEXT_SECTION(PAGE_SIZE) |