blob: 01b52f561af49f86a0bb5e0f1513af60fe9aaef4 [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>
4#include <asm/ptrace.h>
David S. Miller85a79352008-03-24 20:06:24 -07005#include <asm/stacktrace.h>
David S. Miller10e26722006-11-16 13:38:57 -08006
Christoph Hellwigab1b6f02007-05-08 00:23:29 -07007void save_stack_trace(struct stack_trace *trace)
David S. Miller10e26722006-11-16 13:38:57 -08008{
9 unsigned long ksp, fp, thread_base;
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070010 struct thread_info *tp = task_thread_info(current);
David S. Miller10e26722006-11-16 13:38:57 -080011
David S. Miller85a79352008-03-24 20:06:24 -070012 stack_trace_flush();
13
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070014 __asm__ __volatile__(
15 "mov %%fp, %0"
16 : "=r" (ksp)
17 );
David S. Miller10e26722006-11-16 13:38:57 -080018
19 fp = ksp + STACK_BIAS;
20 thread_base = (unsigned long) tp;
21 do {
22 struct reg_window *rw;
David S. Miller77c664f2008-04-24 03:28:52 -070023 struct pt_regs *regs;
24 unsigned long pc;
David S. Miller10e26722006-11-16 13:38:57 -080025
26 /* Bogus frame pointer? */
27 if (fp < (thread_base + sizeof(struct thread_info)) ||
28 fp >= (thread_base + THREAD_SIZE))
29 break;
30
31 rw = (struct reg_window *) fp;
David S. Miller77c664f2008-04-24 03:28:52 -070032 regs = (struct pt_regs *) (rw + 1);
33
34 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
35 pc = regs->tpc;
36 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
37 } else {
38 pc = rw->ins[7];
39 fp = rw->ins[6] + STACK_BIAS;
40 }
41
David S. Miller10e26722006-11-16 13:38:57 -080042 if (trace->skip > 0)
43 trace->skip--;
44 else
David S. Miller77c664f2008-04-24 03:28:52 -070045 trace->entries[trace->nr_entries++] = pc;
David S. Miller10e26722006-11-16 13:38:57 -080046 } while (trace->nr_entries < trace->max_entries);
47}