xref: /linux/arch/hexagon/kernel/stacktrace.c (revision 68db0cf10678630d286f4bbbbdfa102951a35faa)
174d04d6fSRichard Kuo /*
274d04d6fSRichard Kuo  * Stacktrace support for Hexagon
374d04d6fSRichard Kuo  *
4e1858b2aSRichard Kuo  * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
574d04d6fSRichard Kuo  *
674d04d6fSRichard Kuo  * This program is free software; you can redistribute it and/or modify
774d04d6fSRichard Kuo  * it under the terms of the GNU General Public License version 2 and
874d04d6fSRichard Kuo  * only version 2 as published by the Free Software Foundation.
974d04d6fSRichard Kuo  *
1074d04d6fSRichard Kuo  * This program is distributed in the hope that it will be useful,
1174d04d6fSRichard Kuo  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1274d04d6fSRichard Kuo  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1374d04d6fSRichard Kuo  * GNU General Public License for more details.
1474d04d6fSRichard Kuo  *
1574d04d6fSRichard Kuo  * You should have received a copy of the GNU General Public License
1674d04d6fSRichard Kuo  * along with this program; if not, write to the Free Software
1774d04d6fSRichard Kuo  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
1874d04d6fSRichard Kuo  * 02110-1301, USA.
1974d04d6fSRichard Kuo  */
2074d04d6fSRichard Kuo 
2174d04d6fSRichard Kuo #include <linux/sched.h>
22*68db0cf1SIngo Molnar #include <linux/sched/task_stack.h>
2374d04d6fSRichard Kuo #include <linux/stacktrace.h>
2474d04d6fSRichard Kuo #include <linux/thread_info.h>
2574d04d6fSRichard Kuo #include <linux/module.h>
2674d04d6fSRichard Kuo 
2774d04d6fSRichard Kuo register unsigned long current_frame_pointer asm("r30");
2874d04d6fSRichard Kuo 
2974d04d6fSRichard Kuo struct stackframe {
3074d04d6fSRichard Kuo 	unsigned long fp;
3174d04d6fSRichard Kuo 	unsigned long rets;
3274d04d6fSRichard Kuo };
3374d04d6fSRichard Kuo 
3474d04d6fSRichard Kuo /*
3574d04d6fSRichard Kuo  * Save stack-backtrace addresses into a stack_trace buffer.
3674d04d6fSRichard Kuo  */
3774d04d6fSRichard Kuo void save_stack_trace(struct stack_trace *trace)
3874d04d6fSRichard Kuo {
3974d04d6fSRichard Kuo 	unsigned long low, high;
4074d04d6fSRichard Kuo 	unsigned long fp;
4174d04d6fSRichard Kuo 	struct stackframe *frame;
4274d04d6fSRichard Kuo 	int skip = trace->skip;
4374d04d6fSRichard Kuo 
4474d04d6fSRichard Kuo 	low = (unsigned long)task_stack_page(current);
4574d04d6fSRichard Kuo 	high = low + THREAD_SIZE;
4674d04d6fSRichard Kuo 	fp = current_frame_pointer;
4774d04d6fSRichard Kuo 
4874d04d6fSRichard Kuo 	while (fp >= low && fp <= (high - sizeof(*frame))) {
4974d04d6fSRichard Kuo 		frame = (struct stackframe *)fp;
5074d04d6fSRichard Kuo 
5174d04d6fSRichard Kuo 		if (skip) {
5274d04d6fSRichard Kuo 			skip--;
5374d04d6fSRichard Kuo 		} else {
5474d04d6fSRichard Kuo 			trace->entries[trace->nr_entries++] = frame->rets;
5574d04d6fSRichard Kuo 			if (trace->nr_entries >= trace->max_entries)
5674d04d6fSRichard Kuo 				break;
5774d04d6fSRichard Kuo 		}
5874d04d6fSRichard Kuo 
5974d04d6fSRichard Kuo 		/*
6074d04d6fSRichard Kuo 		 * The next frame must be at a higher address than the
6174d04d6fSRichard Kuo 		 * current frame.
6274d04d6fSRichard Kuo 		 */
6374d04d6fSRichard Kuo 		low = fp + sizeof(*frame);
6474d04d6fSRichard Kuo 		fp = frame->fp;
6574d04d6fSRichard Kuo 	}
6674d04d6fSRichard Kuo }
6774d04d6fSRichard Kuo EXPORT_SYMBOL_GPL(save_stack_trace);
68