xref: /openbmc/linux/arch/mips/include/asm/stacktrace.h (revision 799a545b)
1 #ifndef _ASM_STACKTRACE_H
2 #define _ASM_STACKTRACE_H
3 
4 #include <asm/ptrace.h>
5 
6 #ifdef CONFIG_KALLSYMS
7 extern int raw_show_trace;
8 extern unsigned long unwind_stack(struct task_struct *task, unsigned long *sp,
9 				  unsigned long pc, unsigned long *ra);
10 extern unsigned long unwind_stack_by_address(unsigned long stack_page,
11 					     unsigned long *sp,
12 					     unsigned long pc,
13 					     unsigned long *ra);
14 #else
15 #define raw_show_trace 1
16 static inline unsigned long unwind_stack(struct task_struct *task,
17 	unsigned long *sp, unsigned long pc, unsigned long *ra)
18 {
19 	return 0;
20 }
21 #endif
22 
23 static __always_inline void prepare_frametrace(struct pt_regs *regs)
24 {
25 #ifndef CONFIG_KALLSYMS
26 	/*
27 	 * Remove any garbage that may be in regs (specially func
28 	 * addresses) to avoid show_raw_backtrace() to report them
29 	 */
30 	memset(regs, 0, sizeof(*regs));
31 #endif
32 	__asm__ __volatile__(
33 		".set push\n\t"
34 		".set noat\n\t"
35 #ifdef CONFIG_64BIT
36 		"1: dla $1, 1b\n\t"
37 		"sd $1, %0\n\t"
38 		"sd $29, %1\n\t"
39 		"sd $31, %2\n\t"
40 #else
41 		"1: la $1, 1b\n\t"
42 		"sw $1, %0\n\t"
43 		"sw $29, %1\n\t"
44 		"sw $31, %2\n\t"
45 #endif
46 		".set pop\n\t"
47 		: "=m" (regs->cp0_epc),
48 		"=m" (regs->regs[29]), "=m" (regs->regs[31])
49 		: : "memory");
50 }
51 
52 #endif /* _ASM_STACKTRACE_H */
53