xref: /linux/arch/hexagon/kernel/stacktrace.c (revision 74d04d6ffd39274457eafa15022ab717e40cbc63)
1*74d04d6fSRichard Kuo /*
2*74d04d6fSRichard Kuo  * Stacktrace support for Hexagon
3*74d04d6fSRichard Kuo  *
4*74d04d6fSRichard Kuo  * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5*74d04d6fSRichard Kuo  *
6*74d04d6fSRichard Kuo  * This program is free software; you can redistribute it and/or modify
7*74d04d6fSRichard Kuo  * it under the terms of the GNU General Public License version 2 and
8*74d04d6fSRichard Kuo  * only version 2 as published by the Free Software Foundation.
9*74d04d6fSRichard Kuo  *
10*74d04d6fSRichard Kuo  * This program is distributed in the hope that it will be useful,
11*74d04d6fSRichard Kuo  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*74d04d6fSRichard Kuo  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*74d04d6fSRichard Kuo  * GNU General Public License for more details.
14*74d04d6fSRichard Kuo  *
15*74d04d6fSRichard Kuo  * You should have received a copy of the GNU General Public License
16*74d04d6fSRichard Kuo  * along with this program; if not, write to the Free Software
17*74d04d6fSRichard Kuo  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18*74d04d6fSRichard Kuo  * 02110-1301, USA.
19*74d04d6fSRichard Kuo  */
20*74d04d6fSRichard Kuo 
21*74d04d6fSRichard Kuo #include <linux/sched.h>
22*74d04d6fSRichard Kuo #include <linux/stacktrace.h>
23*74d04d6fSRichard Kuo #include <linux/thread_info.h>
24*74d04d6fSRichard Kuo #include <linux/module.h>
25*74d04d6fSRichard Kuo 
26*74d04d6fSRichard Kuo register unsigned long current_frame_pointer asm("r30");
27*74d04d6fSRichard Kuo 
28*74d04d6fSRichard Kuo struct stackframe {
29*74d04d6fSRichard Kuo 	unsigned long fp;
30*74d04d6fSRichard Kuo 	unsigned long rets;
31*74d04d6fSRichard Kuo };
32*74d04d6fSRichard Kuo 
33*74d04d6fSRichard Kuo /*
34*74d04d6fSRichard Kuo  * Save stack-backtrace addresses into a stack_trace buffer.
35*74d04d6fSRichard Kuo  */
36*74d04d6fSRichard Kuo void save_stack_trace(struct stack_trace *trace)
37*74d04d6fSRichard Kuo {
38*74d04d6fSRichard Kuo 	unsigned long low, high;
39*74d04d6fSRichard Kuo 	unsigned long fp;
40*74d04d6fSRichard Kuo 	struct stackframe *frame;
41*74d04d6fSRichard Kuo 	int skip = trace->skip;
42*74d04d6fSRichard Kuo 
43*74d04d6fSRichard Kuo 	low = (unsigned long)task_stack_page(current);
44*74d04d6fSRichard Kuo 	high = low + THREAD_SIZE;
45*74d04d6fSRichard Kuo 	fp = current_frame_pointer;
46*74d04d6fSRichard Kuo 
47*74d04d6fSRichard Kuo 	while (fp >= low && fp <= (high - sizeof(*frame))) {
48*74d04d6fSRichard Kuo 		frame = (struct stackframe *)fp;
49*74d04d6fSRichard Kuo 
50*74d04d6fSRichard Kuo 		if (skip) {
51*74d04d6fSRichard Kuo 			skip--;
52*74d04d6fSRichard Kuo 		} else {
53*74d04d6fSRichard Kuo 			trace->entries[trace->nr_entries++] = frame->rets;
54*74d04d6fSRichard Kuo 			if (trace->nr_entries >= trace->max_entries)
55*74d04d6fSRichard Kuo 				break;
56*74d04d6fSRichard Kuo 		}
57*74d04d6fSRichard Kuo 
58*74d04d6fSRichard Kuo 		/*
59*74d04d6fSRichard Kuo 		 * The next frame must be at a higher address than the
60*74d04d6fSRichard Kuo 		 * current frame.
61*74d04d6fSRichard Kuo 		 */
62*74d04d6fSRichard Kuo 		low = fp + sizeof(*frame);
63*74d04d6fSRichard Kuo 		fp = frame->fp;
64*74d04d6fSRichard Kuo 	}
65*74d04d6fSRichard Kuo }
66*74d04d6fSRichard Kuo EXPORT_SYMBOL_GPL(save_stack_trace);
67