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;
33 get_stack_info(state->sp, state->task, &state->stack_info);
35 if (!unwind_done(state) && !__kernel_text_address(state->pc))
36 unwind_next_frame(state);
38 EXPORT_SYMBOL_GPL(unwind_start);
40 bool unwind_next_frame(struct unwind_state *state)
42 struct stack_info *info = &state->stack_info;
45 if (unwind_done(state))
52 for (state->sp += sizeof(unsigned long);
53 state->sp < info->end;
54 state->sp += sizeof(unsigned long)) {
55 addr = *(unsigned long *)(state->sp);
57 if (__kernel_text_address(addr))
61 state->sp = info->next_sp;
63 } while (!get_stack_info(state->sp, state->task, info));
67 EXPORT_SYMBOL_GPL(unwind_next_frame);