blob: b3e3737750d8bfb49701a862a6c57a821303fc18 [file] [log] [blame]
David S. Miller10e26722006-11-16 13:38:57 -08001#include <linux/sched.h>
2#include <linux/stacktrace.h>
3#include <linux/thread_info.h>
Stephen Rothwella05fe032008-07-08 22:15:40 +10004#include <linux/module.h>
David S. Miller10e26722006-11-16 13:38:57 -08005#include <asm/ptrace.h>
David S. Miller85a79352008-03-24 20:06:24 -07006#include <asm/stacktrace.h>
David S. Miller10e26722006-11-16 13:38:57 -08007
Christoph Hellwigab1b6f02007-05-08 00:23:29 -07008void save_stack_trace(struct stack_trace *trace)
David S. Miller10e26722006-11-16 13:38:57 -08009{
10 unsigned long ksp, fp, thread_base;
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070011 struct thread_info *tp = task_thread_info(current);
David S. Miller10e26722006-11-16 13:38:57 -080012
David S. Miller85a79352008-03-24 20:06:24 -070013 stack_trace_flush();
14
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070015 __asm__ __volatile__(
16 "mov %%fp, %0"
17 : "=r" (ksp)
18 );
David S. Miller10e26722006-11-16 13:38:57 -080019
20 fp = ksp + STACK_BIAS;
21 thread_base = (unsigned long) tp;
22 do {
David S. Miller14d2c682008-05-21 18:15:53 -070023 struct sparc_stackf *sf;
David S. Miller77c664f2008-04-24 03:28:52 -070024 struct pt_regs *regs;
25 unsigned long pc;
David S. Miller10e26722006-11-16 13:38:57 -080026
27 /* Bogus frame pointer? */
28 if (fp < (thread_base + sizeof(struct thread_info)) ||
29 fp >= (thread_base + THREAD_SIZE))
30 break;
31
David S. Miller14d2c682008-05-21 18:15:53 -070032 sf = (struct sparc_stackf *) fp;
33 regs = (struct pt_regs *) (sf + 1);
David S. Miller77c664f2008-04-24 03:28:52 -070034
35 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
David S. Miller14d2c682008-05-21 18:15:53 -070036 if (!(regs->tstate & TSTATE_PRIV))
37 break;
David S. Miller77c664f2008-04-24 03:28:52 -070038 pc = regs->tpc;
39 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
40 } else {
David S. Miller14d2c682008-05-21 18:15:53 -070041 pc = sf->callers_pc;
42 fp = (unsigned long)sf->fp + STACK_BIAS;
David S. Miller77c664f2008-04-24 03:28:52 -070043 }
44
David S. Miller10e26722006-11-16 13:38:57 -080045 if (trace->skip > 0)
46 trace->skip--;
47 else
David S. Miller77c664f2008-04-24 03:28:52 -070048 trace->entries[trace->nr_entries++] = pc;
David S. Miller10e26722006-11-16 13:38:57 -080049 } while (trace->nr_entries < trace->max_entries);
50}
Ingo Molnar7b4c9502008-07-03 09:17:55 +020051EXPORT_SYMBOL_GPL(save_stack_trace);