blob: 4e21d4a57d3b3f2ea536ed5707d61fbf6bc94181 [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
David S. Miller4f70f7a2008-08-12 18:33:56 -07008#include "kstack.h"
9
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070010void save_stack_trace(struct stack_trace *trace)
David S. Miller10e26722006-11-16 13:38:57 -080011{
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070012 struct thread_info *tp = task_thread_info(current);
David S. Miller6f63e782008-08-13 17:17:52 -070013 unsigned long ksp, fp;
David S. Miller10e26722006-11-16 13:38:57 -080014
David S. Miller85a79352008-03-24 20:06:24 -070015 stack_trace_flush();
16
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070017 __asm__ __volatile__(
18 "mov %%fp, %0"
19 : "=r" (ksp)
20 );
David S. Miller10e26722006-11-16 13:38:57 -080021
22 fp = ksp + STACK_BIAS;
David S. Miller10e26722006-11-16 13:38:57 -080023 do {
David S. Miller14d2c682008-05-21 18:15:53 -070024 struct sparc_stackf *sf;
David S. Miller77c664f2008-04-24 03:28:52 -070025 struct pt_regs *regs;
26 unsigned long pc;
David S. Miller10e26722006-11-16 13:38:57 -080027
David S. Miller4f70f7a2008-08-12 18:33:56 -070028 if (!kstack_valid(tp, fp))
David S. Miller10e26722006-11-16 13:38:57 -080029 break;
30
David S. Miller14d2c682008-05-21 18:15:53 -070031 sf = (struct sparc_stackf *) fp;
32 regs = (struct pt_regs *) (sf + 1);
David S. Miller77c664f2008-04-24 03:28:52 -070033
David S. Miller4f70f7a2008-08-12 18:33:56 -070034 if (kstack_is_trap_frame(tp, regs)) {
David S. Miller14d2c682008-05-21 18:15:53 -070035 if (!(regs->tstate & TSTATE_PRIV))
36 break;
David S. Miller77c664f2008-04-24 03:28:52 -070037 pc = regs->tpc;
38 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
39 } else {
David S. Miller14d2c682008-05-21 18:15:53 -070040 pc = sf->callers_pc;
41 fp = (unsigned long)sf->fp + STACK_BIAS;
David S. Miller77c664f2008-04-24 03:28:52 -070042 }
43
David S. Miller10e26722006-11-16 13:38:57 -080044 if (trace->skip > 0)
45 trace->skip--;
46 else
David S. Miller77c664f2008-04-24 03:28:52 -070047 trace->entries[trace->nr_entries++] = pc;
David S. Miller10e26722006-11-16 13:38:57 -080048 } while (trace->nr_entries < trace->max_entries);
49}
Ingo Molnar7b4c9502008-07-03 09:17:55 +020050EXPORT_SYMBOL_GPL(save_stack_trace);