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
2022static 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+ */
204209static struct pt_regs here_regs ;
205210
206211extern const char syscall_ret ;
207212extern const char ret_from_syscall ;
208213extern const char ret_from_exception ;
209214extern 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 );
0 commit comments