108dbd0f8SThomas 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 struct stackframe { 1574d04d6fSRichard Kuo unsigned long fp; 1674d04d6fSRichard Kuo unsigned long rets; 1774d04d6fSRichard Kuo }; 1874d04d6fSRichard Kuo 1974d04d6fSRichard Kuo /* 2074d04d6fSRichard Kuo * Save stack-backtrace addresses into a stack_trace buffer. 2174d04d6fSRichard Kuo */ save_stack_trace(struct stack_trace * trace)2274d04d6fSRichard Kuovoid save_stack_trace(struct stack_trace *trace) 2374d04d6fSRichard Kuo { 2474d04d6fSRichard Kuo unsigned long low, high; 2574d04d6fSRichard Kuo unsigned long fp; 2674d04d6fSRichard Kuo struct stackframe *frame; 2774d04d6fSRichard Kuo int skip = trace->skip; 2874d04d6fSRichard Kuo 2974d04d6fSRichard Kuo low = (unsigned long)task_stack_page(current); 3074d04d6fSRichard Kuo high = low + THREAD_SIZE; 31*63e80314SNick Desaulniers fp = (unsigned long)__builtin_frame_address(0); 3274d04d6fSRichard Kuo 3374d04d6fSRichard Kuo while (fp >= low && fp <= (high - sizeof(*frame))) { 3474d04d6fSRichard Kuo frame = (struct stackframe *)fp; 3574d04d6fSRichard Kuo 3674d04d6fSRichard Kuo if (skip) { 3774d04d6fSRichard Kuo skip--; 3874d04d6fSRichard Kuo } else { 3974d04d6fSRichard Kuo trace->entries[trace->nr_entries++] = frame->rets; 4074d04d6fSRichard Kuo if (trace->nr_entries >= trace->max_entries) 4174d04d6fSRichard Kuo break; 4274d04d6fSRichard Kuo } 4374d04d6fSRichard Kuo 4474d04d6fSRichard Kuo /* 4574d04d6fSRichard Kuo * The next frame must be at a higher address than the 4674d04d6fSRichard Kuo * current frame. 4774d04d6fSRichard Kuo */ 4874d04d6fSRichard Kuo low = fp + sizeof(*frame); 4974d04d6fSRichard Kuo fp = frame->fp; 5074d04d6fSRichard Kuo } 5174d04d6fSRichard Kuo } 5274d04d6fSRichard Kuo EXPORT_SYMBOL_GPL(save_stack_trace); 53