1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2022 Loongson Technology Corporation Limited
5 #include <linux/kernel.h>
7 #include <asm/unwind.h>
9 unsigned long unwind_get_return_address(struct unwind_state *state)
11 if (unwind_done(state))
13 else if (state->first)
16 return *(unsigned long *)(state->sp);
18 EXPORT_SYMBOL_GPL(unwind_get_return_address);
20 void unwind_start(struct unwind_state *state, struct task_struct *task,
23 memset(state, 0, sizeof(*state));
26 state->sp = regs->regs[3];
27 state->pc = regs->csr_era;
28 } else if (task && task != current) {
29 state->sp = thread_saved_fp(task);
30 state->pc = thread_saved_ra(task);
32 state->sp = (unsigned long)__builtin_frame_address(0);
33 state->pc = (unsigned long)__builtin_return_address(0);
39 get_stack_info(state->sp, state->task, &state->stack_info);
41 if (!unwind_done(state) && !__kernel_text_address(state->pc))
42 unwind_next_frame(state);
44 EXPORT_SYMBOL_GPL(unwind_start);
46 bool unwind_next_frame(struct unwind_state *state)
48 struct stack_info *info = &state->stack_info;
51 if (unwind_done(state))
58 for (state->sp += sizeof(unsigned long);
59 state->sp < info->end;
60 state->sp += sizeof(unsigned long)) {
61 addr = *(unsigned long *)(state->sp);
63 if (__kernel_text_address(addr))
67 state->sp = info->next_sp;
69 } while (!get_stack_info(state->sp, state->task, info));
73 EXPORT_SYMBOL_GPL(unwind_next_frame);