blob: e9d7f0660f2e044643182cb2e85f9fde7dc5006b [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)) ||
David S. Miller433c5f72008-08-07 23:04:37 -070029 fp > (thread_base + THREAD_SIZE - sizeof(struct sparc_stackf)))
David S. Miller10e26722006-11-16 13:38:57 -080030 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
David S. Miller433c5f72008-08-07 23:04:37 -070035 if (((unsigned long)regs <=
36 (thread_base + THREAD_SIZE - sizeof(*regs))) &&
37 (regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
David S. Miller14d2c682008-05-21 18:15:53 -070038 if (!(regs->tstate & TSTATE_PRIV))
39 break;
David S. Miller77c664f2008-04-24 03:28:52 -070040 pc = regs->tpc;
41 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
42 } else {
David S. Miller14d2c682008-05-21 18:15:53 -070043 pc = sf->callers_pc;
44 fp = (unsigned long)sf->fp + STACK_BIAS;
David S. Miller77c664f2008-04-24 03:28:52 -070045 }
46
David S. Miller10e26722006-11-16 13:38:57 -080047 if (trace->skip > 0)
48 trace->skip--;
49 else
David S. Miller77c664f2008-04-24 03:28:52 -070050 trace->entries[trace->nr_entries++] = pc;
David S. Miller10e26722006-11-16 13:38:57 -080051 } while (trace->nr_entries < trace->max_entries);
52}
Ingo Molnar7b4c9502008-07-03 09:17:55 +020053EXPORT_SYMBOL_GPL(save_stack_trace);