blob: 237e7f8a40ac6f0bd3e161aca622b06ebd96366f [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{
12 unsigned long ksp, fp, thread_base;
Christoph Hellwigab1b6f02007-05-08 00:23:29 -070013 struct thread_info *tp = task_thread_info(current);
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;
23 thread_base = (unsigned long) tp;
24 do {
David S. Miller14d2c682008-05-21 18:15:53 -070025 struct sparc_stackf *sf;
David S. Miller77c664f2008-04-24 03:28:52 -070026 struct pt_regs *regs;
27 unsigned long pc;
David S. Miller10e26722006-11-16 13:38:57 -080028
David S. Miller4f70f7a2008-08-12 18:33:56 -070029 if (!kstack_valid(tp, fp))
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. Miller4f70f7a2008-08-12 18:33:56 -070035 if (kstack_is_trap_frame(tp, regs)) {
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);