David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 1 | #include <linux/sched.h> |
| 2 | #include <linux/stacktrace.h> |
| 3 | #include <linux/thread_info.h> |
| 4 | #include <asm/ptrace.h> |
David S. Miller | 85a7935 | 2008-03-24 20:06:24 -0700 | [diff] [blame] | 5 | #include <asm/stacktrace.h> |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 6 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 7 | void save_stack_trace(struct stack_trace *trace) |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 8 | { |
| 9 | unsigned long ksp, fp, thread_base; |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 10 | struct thread_info *tp = task_thread_info(current); |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 11 | |
David S. Miller | 85a7935 | 2008-03-24 20:06:24 -0700 | [diff] [blame] | 12 | stack_trace_flush(); |
| 13 | |
Christoph Hellwig | ab1b6f0 | 2007-05-08 00:23:29 -0700 | [diff] [blame] | 14 | __asm__ __volatile__( |
| 15 | "mov %%fp, %0" |
| 16 | : "=r" (ksp) |
| 17 | ); |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 18 | |
| 19 | fp = ksp + STACK_BIAS; |
| 20 | thread_base = (unsigned long) tp; |
| 21 | do { |
David S. Miller | 14d2c68 | 2008-05-21 18:15:53 -0700 | [diff] [blame^] | 22 | struct sparc_stackf *sf; |
David S. Miller | 77c664f | 2008-04-24 03:28:52 -0700 | [diff] [blame] | 23 | struct pt_regs *regs; |
| 24 | unsigned long pc; |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 25 | |
| 26 | /* Bogus frame pointer? */ |
| 27 | if (fp < (thread_base + sizeof(struct thread_info)) || |
| 28 | fp >= (thread_base + THREAD_SIZE)) |
| 29 | break; |
| 30 | |
David S. Miller | 14d2c68 | 2008-05-21 18:15:53 -0700 | [diff] [blame^] | 31 | sf = (struct sparc_stackf *) fp; |
| 32 | regs = (struct pt_regs *) (sf + 1); |
David S. Miller | 77c664f | 2008-04-24 03:28:52 -0700 | [diff] [blame] | 33 | |
| 34 | if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) { |
David S. Miller | 14d2c68 | 2008-05-21 18:15:53 -0700 | [diff] [blame^] | 35 | if (!(regs->tstate & TSTATE_PRIV)) |
| 36 | break; |
David S. Miller | 77c664f | 2008-04-24 03:28:52 -0700 | [diff] [blame] | 37 | pc = regs->tpc; |
| 38 | fp = regs->u_regs[UREG_I6] + STACK_BIAS; |
| 39 | } else { |
David S. Miller | 14d2c68 | 2008-05-21 18:15:53 -0700 | [diff] [blame^] | 40 | pc = sf->callers_pc; |
| 41 | fp = (unsigned long)sf->fp + STACK_BIAS; |
David S. Miller | 77c664f | 2008-04-24 03:28:52 -0700 | [diff] [blame] | 42 | } |
| 43 | |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 44 | if (trace->skip > 0) |
| 45 | trace->skip--; |
| 46 | else |
David S. Miller | 77c664f | 2008-04-24 03:28:52 -0700 | [diff] [blame] | 47 | trace->entries[trace->nr_entries++] = pc; |
David S. Miller | 10e2672 | 2006-11-16 13:38:57 -0800 | [diff] [blame] | 48 | } while (trace->nr_entries < trace->max_entries); |
| 49 | } |