Skip to content

Commit 4945326

Browse files
committed
sh64: Convert to unwinder API.
This switches over to use the sh unwinder API which brings it all in line with the general sh routines (which we shuffle around at the same time), and lets us kill off more sh64-specific cruft. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent f936991 commit 4945326

5 files changed

Lines changed: 101 additions & 98 deletions

File tree

‎arch/sh/include/asm/kdebug.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ enum die_val {
1010
DIE_SSTEP,
1111
};
1212

13+
/* arch/sh/kernel/dumpstack.c */
1314
extern void printk_address(unsigned long address, int reliable);
15+
extern void dump_mem(const char *str, unsigned long bottom, unsigned long top);
1416

1517
#endif /* __ASM_SH_KDEBUG_H */

‎arch/sh/kernel/cpu/sh5/unwind.c‎

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <asm/ptrace.h>
1717
#include <asm/processor.h>
1818
#include <asm/io.h>
19+
#include <asm/unwinder.h>
20+
#include <asm/stacktrace.h>
1921

2022
static u8 regcache[63];
2123

@@ -199,26 +201,31 @@ static int lookup_prev_stack_frame(unsigned long fp, unsigned long pc,
199201
return 0;
200202
}
201203

202-
/* Don't put this on the stack since we'll want to call sh64_unwind
203-
* when we're close to underflowing the stack anyway. */
204+
/*
205+
* Don't put this on the stack since we'll want to call in to
206+
* sh64_unwinder_dump() when we're close to underflowing the stack
207+
* anyway.
208+
*/
204209
static struct pt_regs here_regs;
205210

206211
extern const char syscall_ret;
207212
extern const char ret_from_syscall;
208213
extern const char ret_from_exception;
209214
extern const char ret_from_irq;
210215

211-
static void sh64_unwind_inner(struct pt_regs *regs);
216+
static void sh64_unwind_inner(const struct stacktrace_ops *ops,
217+
void *data, struct pt_regs *regs);
212218

213-
static void unwind_nested (unsigned long pc, unsigned long fp)
219+
static inline void unwind_nested(const struct stacktrace_ops *ops, void *data,
220+
unsigned long pc, unsigned long fp)
214221
{
215222
if ((fp >= __MEMORY_START) &&
216-
((fp & 7) == 0)) {
217-
sh64_unwind_inner((struct pt_regs *) fp);
218-
}
223+
((fp & 7) == 0))
224+
sh64_unwind_inner(ops, data, (struct pt_regs *)fp);
219225
}
220226

221-
static void sh64_unwind_inner(struct pt_regs *regs)
227+
static void sh64_unwind_inner(const struct stacktrace_ops *ops,
228+
void *data, struct pt_regs *regs)
222229
{
223230
unsigned long pc, fp;
224231
int ofs = 0;
@@ -232,29 +239,29 @@ static void sh64_unwind_inner(struct pt_regs *regs)
232239
int cond;
233240
unsigned long next_fp, next_pc;
234241

235-
if (pc == ((unsigned long) &syscall_ret & ~1)) {
242+
if (pc == ((unsigned long)&syscall_ret & ~1)) {
236243
printk("SYSCALL\n");
237-
unwind_nested(pc,fp);
244+
unwind_nested(ops, data, pc, fp);
238245
return;
239246
}
240247

241-
if (pc == ((unsigned long) &ret_from_syscall & ~1)) {
248+
if (pc == ((unsigned long)&ret_from_syscall & ~1)) {
242249
printk("SYSCALL (PREEMPTED)\n");
243-
unwind_nested(pc,fp);
250+
unwind_nested(ops, data, pc, fp);
244251
return;
245252
}
246253

247254
/* In this case, the PC is discovered by lookup_prev_stack_frame but
248255
it has 4 taken off it to look like the 'caller' */
249-
if (pc == ((unsigned long) &ret_from_exception & ~1)) {
256+
if (pc == ((unsigned long)&ret_from_exception & ~1)) {
250257
printk("EXCEPTION\n");
251-
unwind_nested(pc,fp);
258+
unwind_nested(ops, data, pc, fp);
252259
return;
253260
}
254261

255-
if (pc == ((unsigned long) &ret_from_irq & ~1)) {
262+
if (pc == ((unsigned long)&ret_from_irq & ~1)) {
256263
printk("IRQ\n");
257-
unwind_nested(pc,fp);
264+
unwind_nested(ops, data, pc, fp);
258265
return;
259266
}
260267

@@ -263,8 +270,7 @@ static void sh64_unwind_inner(struct pt_regs *regs)
263270

264271
pc -= ofs;
265272

266-
printk("[<%08lx>] ", pc);
267-
print_symbol("%s\n", pc);
273+
ops->address(data, pc, 1);
268274

269275
if (first_pass) {
270276
/* If the innermost frame is a leaf function, it's
@@ -287,10 +293,13 @@ static void sh64_unwind_inner(struct pt_regs *regs)
287293
}
288294

289295
printk("\n");
290-
291296
}
292297

293-
void sh64_unwind(struct pt_regs *regs)
298+
static void sh64_unwinder_dump(struct task_struct *task,
299+
struct pt_regs *regs,
300+
unsigned long *sp,
301+
const struct stacktrace_ops *ops,
302+
void *data)
294303
{
295304
if (!regs) {
296305
/*
@@ -320,7 +329,17 @@ void sh64_unwind(struct pt_regs *regs)
320329
);
321330
}
322331

323-
printk("\nCall Trace:\n");
324-
sh64_unwind_inner(regs);
332+
sh64_unwind_inner(ops, data, regs);
325333
}
326334

335+
static struct unwinder sh64_unwinder = {
336+
.name = "sh64-unwinder",
337+
.dump = sh64_unwinder_dump,
338+
.rating = 150,
339+
};
340+
341+
static int __init sh64_unwinder_init(void)
342+
{
343+
return unwinder_register(&sh64_unwinder);
344+
}
345+
early_initcall(sh64_unwinder_init);

‎arch/sh/kernel/dumpstack.c‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,48 @@
22
* Copyright (C) 1991, 1992 Linus Torvalds
33
* Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
44
* Copyright (C) 2009 Matt Fleming
5+
* Copyright (C) 2002 - 2012 Paul Mundt
6+
*
7+
* This file is subject to the terms and conditions of the GNU General Public
8+
* License. See the file "COPYING" in the main directory of this archive
9+
* for more details.
510
*/
611
#include <linux/kallsyms.h>
712
#include <linux/ftrace.h>
813
#include <linux/debug_locks.h>
14+
#include <linux/kdebug.h>
15+
#include <linux/export.h>
16+
#include <linux/uaccess.h>
917
#include <asm/unwinder.h>
1018
#include <asm/stacktrace.h>
1119

20+
void dump_mem(const char *str, unsigned long bottom, unsigned long top)
21+
{
22+
unsigned long p;
23+
int i;
24+
25+
printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
26+
27+
for (p = bottom & ~31; p < top; ) {
28+
printk("%04lx: ", p & 0xffff);
29+
30+
for (i = 0; i < 8; i++, p += 4) {
31+
unsigned int val;
32+
33+
if (p < bottom || p >= top)
34+
printk(" ");
35+
else {
36+
if (__get_user(val, (unsigned int __user *)p)) {
37+
printk("\n");
38+
return;
39+
}
40+
printk("%08x ", val);
41+
}
42+
}
43+
printk("\n");
44+
}
45+
}
46+
1247
void printk_address(unsigned long address, int reliable)
1348
{
1449
printk(" [<%p>] %s%pS\n", (void *) address,
@@ -106,3 +141,26 @@ void show_trace(struct task_struct *tsk, unsigned long *sp,
106141

107142
debug_show_held_locks(tsk);
108143
}
144+
145+
void show_stack(struct task_struct *tsk, unsigned long *sp)
146+
{
147+
unsigned long stack;
148+
149+
if (!tsk)
150+
tsk = current;
151+
if (tsk == current)
152+
sp = (unsigned long *)current_stack_pointer;
153+
else
154+
sp = (unsigned long *)tsk->thread.sp;
155+
156+
stack = (unsigned long)sp;
157+
dump_mem("Stack: ", stack, THREAD_SIZE +
158+
(unsigned long)task_stack_page(tsk));
159+
show_trace(tsk, sp, NULL);
160+
}
161+
162+
void dump_stack(void)
163+
{
164+
show_stack(NULL, NULL);
165+
}
166+
EXPORT_SYMBOL(dump_stack);

‎arch/sh/kernel/traps_32.c‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,6 @@
4848
#define TRAP_ILLEGAL_SLOT_INST 13
4949
#endif
5050

51-
static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
52-
{
53-
unsigned long p;
54-
int i;
55-
56-
printk("%s(0x%08lx to 0x%08lx)\n", str, bottom, top);
57-
58-
for (p = bottom & ~31; p < top; ) {
59-
printk("%04lx: ", p & 0xffff);
60-
61-
for (i = 0; i < 8; i++, p += 4) {
62-
unsigned int val;
63-
64-
if (p < bottom || p >= top)
65-
printk(" ");
66-
else {
67-
if (__get_user(val, (unsigned int __user *)p)) {
68-
printk("\n");
69-
return;
70-
}
71-
printk("%08x ", val);
72-
}
73-
}
74-
printk("\n");
75-
}
76-
}
77-
7851
static DEFINE_SPINLOCK(die_lock);
7952

8053
void die(const char * str, struct pt_regs * regs, long err)
@@ -900,26 +873,3 @@ void __init trap_init(void)
900873
set_exception_table_vec(TRAP_UBC, breakpoint_trap_handler);
901874
#endif
902875
}
903-
904-
void show_stack(struct task_struct *tsk, unsigned long *sp)
905-
{
906-
unsigned long stack;
907-
908-
if (!tsk)
909-
tsk = current;
910-
if (tsk == current)
911-
sp = (unsigned long *)current_stack_pointer;
912-
else
913-
sp = (unsigned long *)tsk->thread.sp;
914-
915-
stack = (unsigned long)sp;
916-
dump_mem("Stack: ", stack, THREAD_SIZE +
917-
(unsigned long)task_stack_page(tsk));
918-
show_trace(tsk, sp, NULL);
919-
}
920-
921-
void dump_stack(void)
922-
{
923-
show_stack(NULL, NULL);
924-
}
925-
EXPORT_SYMBOL(dump_stack);

‎arch/sh/kernel/traps_64.c‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,32 +253,6 @@ int do_unknown_trapa(unsigned long scId, struct pt_regs *regs)
253253
return -ENOSYS;
254254
}
255255

256-
void show_stack(struct task_struct *tsk, unsigned long *sp)
257-
{
258-
#ifdef CONFIG_KALLSYMS
259-
extern void sh64_unwind(struct pt_regs *regs);
260-
struct pt_regs *regs;
261-
262-
regs = tsk ? tsk->thread.kregs : NULL;
263-
264-
sh64_unwind(regs);
265-
#else
266-
printk(KERN_ERR "Can't backtrace on sh64 without CONFIG_KALLSYMS\n");
267-
#endif
268-
}
269-
270-
void show_task(unsigned long *sp)
271-
{
272-
show_stack(NULL, sp);
273-
}
274-
275-
void dump_stack(void)
276-
{
277-
show_task(NULL);
278-
}
279-
/* Needed by any user of WARN_ON in view of the defn in include/asm-sh/bug.h */
280-
EXPORT_SYMBOL(dump_stack);
281-
282256
static void do_unhandled_exception(int trapnr, int signr, char *str, char *fn_name,
283257
unsigned long error_code, struct pt_regs *regs, struct task_struct *tsk)
284258
{

0 commit comments

Comments
 (0)