Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_STACKTRACE_H
0003 #define _ASM_STACKTRACE_H
0004 
0005 #include <asm/ptrace.h>
0006 #include <asm/asm.h>
0007 #include <linux/stringify.h>
0008 
0009 #ifdef CONFIG_KALLSYMS
0010 extern int raw_show_trace;
0011 extern unsigned long unwind_stack(struct task_struct *task, unsigned long *sp,
0012                   unsigned long pc, unsigned long *ra);
0013 extern unsigned long unwind_stack_by_address(unsigned long stack_page,
0014                          unsigned long *sp,
0015                          unsigned long pc,
0016                          unsigned long *ra);
0017 #else
0018 #define raw_show_trace 1
0019 static inline unsigned long unwind_stack(struct task_struct *task,
0020     unsigned long *sp, unsigned long pc, unsigned long *ra)
0021 {
0022     return 0;
0023 }
0024 #endif
0025 
0026 #define STR_PTR_LA    __stringify(PTR_LA)
0027 #define STR_LONG_S    __stringify(LONG_S)
0028 #define STR_LONG_L    __stringify(LONG_L)
0029 #define STR_LONGSIZE  __stringify(LONGSIZE)
0030 
0031 #define STORE_ONE_REG(r) \
0032     STR_LONG_S   " $" __stringify(r)",("STR_LONGSIZE"*"__stringify(r)")(%1)\n\t"
0033 
0034 static __always_inline void prepare_frametrace(struct pt_regs *regs)
0035 {
0036 #ifndef CONFIG_KALLSYMS
0037     /*
0038      * Remove any garbage that may be in regs (specially func
0039      * addresses) to avoid show_raw_backtrace() to report them
0040      */
0041     memset(regs, 0, sizeof(*regs));
0042 #endif
0043     __asm__ __volatile__(
0044         ".set push\n\t"
0045         ".set noat\n\t"
0046         /* Store $1 so we can use it */
0047         STR_LONG_S " $1,"STR_LONGSIZE"(%1)\n\t"
0048         /* Store the PC */
0049         "1: " STR_PTR_LA " $1, 1b\n\t"
0050         STR_LONG_S " $1,%0\n\t"
0051         STORE_ONE_REG(2)
0052         STORE_ONE_REG(3)
0053         STORE_ONE_REG(4)
0054         STORE_ONE_REG(5)
0055         STORE_ONE_REG(6)
0056         STORE_ONE_REG(7)
0057         STORE_ONE_REG(8)
0058         STORE_ONE_REG(9)
0059         STORE_ONE_REG(10)
0060         STORE_ONE_REG(11)
0061         STORE_ONE_REG(12)
0062         STORE_ONE_REG(13)
0063         STORE_ONE_REG(14)
0064         STORE_ONE_REG(15)
0065         STORE_ONE_REG(16)
0066         STORE_ONE_REG(17)
0067         STORE_ONE_REG(18)
0068         STORE_ONE_REG(19)
0069         STORE_ONE_REG(20)
0070         STORE_ONE_REG(21)
0071         STORE_ONE_REG(22)
0072         STORE_ONE_REG(23)
0073         STORE_ONE_REG(24)
0074         STORE_ONE_REG(25)
0075         STORE_ONE_REG(26)
0076         STORE_ONE_REG(27)
0077         STORE_ONE_REG(28)
0078         STORE_ONE_REG(29)
0079         STORE_ONE_REG(30)
0080         STORE_ONE_REG(31)
0081         /* Restore $1 */
0082         STR_LONG_L " $1,"STR_LONGSIZE"(%1)\n\t"
0083         ".set pop\n\t"
0084         : "=m" (regs->cp0_epc)
0085         : "r" (regs->regs)
0086         : "memory");
0087 }
0088 
0089 #endif /* _ASM_STACKTRACE_H */