stacktrace.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_STACKTRACE_H
  3. #define _ASM_STACKTRACE_H
  4. #include <asm/ptrace.h>
  5. #include <asm/asm.h>
  6. #include <linux/stringify.h>
  7. #ifdef CONFIG_KALLSYMS
  8. extern int raw_show_trace;
  9. extern unsigned long unwind_stack(struct task_struct *task, unsigned long *sp,
  10. unsigned long pc, unsigned long *ra);
  11. extern unsigned long unwind_stack_by_address(unsigned long stack_page,
  12. unsigned long *sp,
  13. unsigned long pc,
  14. unsigned long *ra);
  15. #else
  16. #define raw_show_trace 1
  17. static inline unsigned long unwind_stack(struct task_struct *task,
  18. unsigned long *sp, unsigned long pc, unsigned long *ra)
  19. {
  20. return 0;
  21. }
  22. #endif
  23. #define STR_PTR_LA __stringify(PTR_LA)
  24. #define STR_LONG_S __stringify(LONG_S)
  25. #define STR_LONG_L __stringify(LONG_L)
  26. #define STR_LONGSIZE __stringify(LONGSIZE)
  27. #define STORE_ONE_REG(r) \
  28. STR_LONG_S " $" __stringify(r)",("STR_LONGSIZE"*"__stringify(r)")(%1)\n\t"
  29. static __always_inline void prepare_frametrace(struct pt_regs *regs)
  30. {
  31. #ifndef CONFIG_KALLSYMS
  32. /*
  33. * Remove any garbage that may be in regs (specially func
  34. * addresses) to avoid show_raw_backtrace() to report them
  35. */
  36. memset(regs, 0, sizeof(*regs));
  37. #endif
  38. __asm__ __volatile__(
  39. ".set push\n\t"
  40. ".set noat\n\t"
  41. /* Store $1 so we can use it */
  42. STR_LONG_S " $1,"STR_LONGSIZE"(%1)\n\t"
  43. /* Store the PC */
  44. "1: " STR_PTR_LA " $1, 1b\n\t"
  45. STR_LONG_S " $1,%0\n\t"
  46. STORE_ONE_REG(2)
  47. STORE_ONE_REG(3)
  48. STORE_ONE_REG(4)
  49. STORE_ONE_REG(5)
  50. STORE_ONE_REG(6)
  51. STORE_ONE_REG(7)
  52. STORE_ONE_REG(8)
  53. STORE_ONE_REG(9)
  54. STORE_ONE_REG(10)
  55. STORE_ONE_REG(11)
  56. STORE_ONE_REG(12)
  57. STORE_ONE_REG(13)
  58. STORE_ONE_REG(14)
  59. STORE_ONE_REG(15)
  60. STORE_ONE_REG(16)
  61. STORE_ONE_REG(17)
  62. STORE_ONE_REG(18)
  63. STORE_ONE_REG(19)
  64. STORE_ONE_REG(20)
  65. STORE_ONE_REG(21)
  66. STORE_ONE_REG(22)
  67. STORE_ONE_REG(23)
  68. STORE_ONE_REG(24)
  69. STORE_ONE_REG(25)
  70. STORE_ONE_REG(26)
  71. STORE_ONE_REG(27)
  72. STORE_ONE_REG(28)
  73. STORE_ONE_REG(29)
  74. STORE_ONE_REG(30)
  75. STORE_ONE_REG(31)
  76. /* Restore $1 */
  77. STR_LONG_L " $1,"STR_LONGSIZE"(%1)\n\t"
  78. ".set pop\n\t"
  79. : "=m" (regs->cp0_epc)
  80. : "r" (regs->regs)
  81. : "memory");
  82. }
  83. #endif /* _ASM_STACKTRACE_H */