xref: /linux/arch/loongarch/include/asm/unwind.h (revision 49aef111e2dae176a7708b532118f33f24289248)
149232773SQing Zhang /* SPDX-License-Identifier: GPL-2.0 */
249232773SQing Zhang /*
349232773SQing Zhang  * Most of this ideas comes from x86.
449232773SQing Zhang  *
549232773SQing Zhang  * Copyright (C) 2022 Loongson Technology Corporation Limited
649232773SQing Zhang  */
749232773SQing Zhang #ifndef _ASM_UNWIND_H
849232773SQing Zhang #define _ASM_UNWIND_H
949232773SQing Zhang 
1049232773SQing Zhang #include <linux/sched.h>
1149232773SQing Zhang 
1249232773SQing Zhang #include <asm/stacktrace.h>
1349232773SQing Zhang 
14*49aef111SQing Zhang enum unwinder_type {
15*49aef111SQing Zhang 	UNWINDER_GUESS,
16*49aef111SQing Zhang 	UNWINDER_PROLOGUE,
17*49aef111SQing Zhang };
18*49aef111SQing Zhang 
1949232773SQing Zhang struct unwind_state {
20*49aef111SQing Zhang 	char type; /* UNWINDER_XXX */
2149232773SQing Zhang 	struct stack_info stack_info;
2249232773SQing Zhang 	struct task_struct *task;
2349232773SQing Zhang 	bool first, error;
24*49aef111SQing Zhang 	unsigned long sp, pc, ra;
2549232773SQing Zhang };
2649232773SQing Zhang 
2749232773SQing Zhang void unwind_start(struct unwind_state *state,
2849232773SQing Zhang 		  struct task_struct *task, struct pt_regs *regs);
2949232773SQing Zhang bool unwind_next_frame(struct unwind_state *state);
3049232773SQing Zhang unsigned long unwind_get_return_address(struct unwind_state *state);
3149232773SQing Zhang 
3249232773SQing Zhang static inline bool unwind_done(struct unwind_state *state)
3349232773SQing Zhang {
3449232773SQing Zhang 	return state->stack_info.type == STACK_TYPE_UNKNOWN;
3549232773SQing Zhang }
3649232773SQing Zhang 
3749232773SQing Zhang static inline bool unwind_error(struct unwind_state *state)
3849232773SQing Zhang {
3949232773SQing Zhang 	return state->error;
4049232773SQing Zhang }
4149232773SQing Zhang 
4249232773SQing Zhang #endif /* _ASM_UNWIND_H */
43