ftrace.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2017 Andes Technology Corporation */
  3. /*
  4. * The graph frame test is not possible if CONFIG_FRAME_POINTER is not enabled.
  5. * Check arch/riscv/kernel/mcount.S for detail.
  6. */
  7. #if defined(CONFIG_FUNCTION_GRAPH_TRACER) && defined(CONFIG_FRAME_POINTER)
  8. #define HAVE_FUNCTION_GRAPH_FP_TEST
  9. #endif
  10. #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
  11. #define ARCH_SUPPORTS_FTRACE_OPS 1
  12. #ifndef __ASSEMBLY__
  13. void _mcount(void);
  14. static inline unsigned long ftrace_call_adjust(unsigned long addr)
  15. {
  16. return addr;
  17. }
  18. struct dyn_arch_ftrace {
  19. };
  20. #endif
  21. #ifdef CONFIG_DYNAMIC_FTRACE
  22. /*
  23. * A general call in RISC-V is a pair of insts:
  24. * 1) auipc: setting high-20 pc-related bits to ra register
  25. * 2) jalr: setting low-12 offset to ra, jump to ra, and set ra to
  26. * return address (original pc + 4)
  27. *
  28. * Dynamic ftrace generates probes to call sites, so we must deal with
  29. * both auipc and jalr at the same time.
  30. */
  31. #define MCOUNT_ADDR ((unsigned long)_mcount)
  32. #define JALR_SIGN_MASK (0x00000800)
  33. #define JALR_OFFSET_MASK (0x00000fff)
  34. #define AUIPC_OFFSET_MASK (0xfffff000)
  35. #define AUIPC_PAD (0x00001000)
  36. #define JALR_SHIFT 20
  37. #define JALR_BASIC (0x000080e7)
  38. #define AUIPC_BASIC (0x00000097)
  39. #define NOP4 (0x00000013)
  40. #define make_call(caller, callee, call) \
  41. do { \
  42. call[0] = to_auipc_insn((unsigned int)((unsigned long)callee - \
  43. (unsigned long)caller)); \
  44. call[1] = to_jalr_insn((unsigned int)((unsigned long)callee - \
  45. (unsigned long)caller)); \
  46. } while (0)
  47. #define to_jalr_insn(offset) \
  48. (((offset & JALR_OFFSET_MASK) << JALR_SHIFT) | JALR_BASIC)
  49. #define to_auipc_insn(offset) \
  50. ((offset & JALR_SIGN_MASK) ? \
  51. (((offset & AUIPC_OFFSET_MASK) + AUIPC_PAD) | AUIPC_BASIC) : \
  52. ((offset & AUIPC_OFFSET_MASK) | AUIPC_BASIC))
  53. /*
  54. * Let auipc+jalr be the basic *mcount unit*, so we make it 8 bytes here.
  55. */
  56. #define MCOUNT_INSN_SIZE 8
  57. #endif