xref: /linux/arch/hexagon/kernel/stacktrace.c (revision 08dbd0f8ef8d2a02319aec1e6c2aeb084468309e)
1*08dbd0f8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
274d04d6fSRichard Kuo /*
374d04d6fSRichard Kuo  * Stacktrace support for Hexagon
474d04d6fSRichard Kuo  *
5e1858b2aSRichard Kuo  * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
674d04d6fSRichard Kuo  */
774d04d6fSRichard Kuo 
874d04d6fSRichard Kuo #include <linux/sched.h>
968db0cf1SIngo Molnar #include <linux/sched/task_stack.h>
1074d04d6fSRichard Kuo #include <linux/stacktrace.h>
1174d04d6fSRichard Kuo #include <linux/thread_info.h>
1274d04d6fSRichard Kuo #include <linux/module.h>
1374d04d6fSRichard Kuo 
1474d04d6fSRichard Kuo register unsigned long current_frame_pointer asm("r30");
1574d04d6fSRichard Kuo 
1674d04d6fSRichard Kuo struct stackframe {
1774d04d6fSRichard Kuo 	unsigned long fp;
1874d04d6fSRichard Kuo 	unsigned long rets;
1974d04d6fSRichard Kuo };
2074d04d6fSRichard Kuo 
2174d04d6fSRichard Kuo /*
2274d04d6fSRichard Kuo  * Save stack-backtrace addresses into a stack_trace buffer.
2374d04d6fSRichard Kuo  */
2474d04d6fSRichard Kuo void save_stack_trace(struct stack_trace *trace)
2574d04d6fSRichard Kuo {
2674d04d6fSRichard Kuo 	unsigned long low, high;
2774d04d6fSRichard Kuo 	unsigned long fp;
2874d04d6fSRichard Kuo 	struct stackframe *frame;
2974d04d6fSRichard Kuo 	int skip = trace->skip;
3074d04d6fSRichard Kuo 
3174d04d6fSRichard Kuo 	low = (unsigned long)task_stack_page(current);
3274d04d6fSRichard Kuo 	high = low + THREAD_SIZE;
3374d04d6fSRichard Kuo 	fp = current_frame_pointer;
3474d04d6fSRichard Kuo 
3574d04d6fSRichard Kuo 	while (fp >= low && fp <= (high - sizeof(*frame))) {
3674d04d6fSRichard Kuo 		frame = (struct stackframe *)fp;
3774d04d6fSRichard Kuo 
3874d04d6fSRichard Kuo 		if (skip) {
3974d04d6fSRichard Kuo 			skip--;
4074d04d6fSRichard Kuo 		} else {
4174d04d6fSRichard Kuo 			trace->entries[trace->nr_entries++] = frame->rets;
4274d04d6fSRichard Kuo 			if (trace->nr_entries >= trace->max_entries)
4374d04d6fSRichard Kuo 				break;
4474d04d6fSRichard Kuo 		}
4574d04d6fSRichard Kuo 
4674d04d6fSRichard Kuo 		/*
4774d04d6fSRichard Kuo 		 * The next frame must be at a higher address than the
4874d04d6fSRichard Kuo 		 * current frame.
4974d04d6fSRichard Kuo 		 */
5074d04d6fSRichard Kuo 		low = fp + sizeof(*frame);
5174d04d6fSRichard Kuo 		fp = frame->fp;
5274d04d6fSRichard Kuo 	}
5374d04d6fSRichard Kuo }
5474d04d6fSRichard Kuo EXPORT_SYMBOL_GPL(save_stack_trace);
55