ptrace.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 Regents of the University of California
  4. */
  5. #ifndef _ASM_RISCV_PTRACE_H
  6. #define _ASM_RISCV_PTRACE_H
  7. #include <uapi/asm/ptrace.h>
  8. #include <asm/csr.h>
  9. #include <linux/compiler.h>
  10. #ifndef __ASSEMBLY__
  11. struct pt_regs {
  12. unsigned long epc;
  13. unsigned long ra;
  14. unsigned long sp;
  15. unsigned long gp;
  16. unsigned long tp;
  17. unsigned long t0;
  18. unsigned long t1;
  19. unsigned long t2;
  20. unsigned long s0;
  21. unsigned long s1;
  22. unsigned long a0;
  23. unsigned long a1;
  24. unsigned long a2;
  25. unsigned long a3;
  26. unsigned long a4;
  27. unsigned long a5;
  28. unsigned long a6;
  29. unsigned long a7;
  30. unsigned long s2;
  31. unsigned long s3;
  32. unsigned long s4;
  33. unsigned long s5;
  34. unsigned long s6;
  35. unsigned long s7;
  36. unsigned long s8;
  37. unsigned long s9;
  38. unsigned long s10;
  39. unsigned long s11;
  40. unsigned long t3;
  41. unsigned long t4;
  42. unsigned long t5;
  43. unsigned long t6;
  44. /* Supervisor/Machine CSRs */
  45. unsigned long status;
  46. unsigned long badaddr;
  47. unsigned long cause;
  48. /* a0 value before the syscall */
  49. unsigned long orig_a0;
  50. };
  51. #ifdef CONFIG_64BIT
  52. #define REG_FMT "%016lx"
  53. #else
  54. #define REG_FMT "%08lx"
  55. #endif
  56. #define user_mode(regs) (((regs)->status & SR_PP) == 0)
  57. #define MAX_REG_OFFSET offsetof(struct pt_regs, orig_a0)
  58. /* Helpers for working with the instruction pointer */
  59. static inline unsigned long instruction_pointer(struct pt_regs *regs)
  60. {
  61. return regs->epc;
  62. }
  63. static inline void instruction_pointer_set(struct pt_regs *regs,
  64. unsigned long val)
  65. {
  66. regs->epc = val;
  67. }
  68. #define profile_pc(regs) instruction_pointer(regs)
  69. /* Helpers for working with the user stack pointer */
  70. static inline unsigned long user_stack_pointer(struct pt_regs *regs)
  71. {
  72. return regs->sp;
  73. }
  74. static inline void user_stack_pointer_set(struct pt_regs *regs,
  75. unsigned long val)
  76. {
  77. regs->sp = val;
  78. }
  79. /* Valid only for Kernel mode traps. */
  80. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  81. {
  82. return regs->sp;
  83. }
  84. /* Helpers for working with the frame pointer */
  85. static inline unsigned long frame_pointer(struct pt_regs *regs)
  86. {
  87. return regs->s0;
  88. }
  89. static inline void frame_pointer_set(struct pt_regs *regs,
  90. unsigned long val)
  91. {
  92. regs->s0 = val;
  93. }
  94. static inline unsigned long regs_return_value(struct pt_regs *regs)
  95. {
  96. return regs->a0;
  97. }
  98. static inline void regs_set_return_value(struct pt_regs *regs,
  99. unsigned long val)
  100. {
  101. regs->a0 = val;
  102. }
  103. extern int regs_query_register_offset(const char *name);
  104. extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  105. unsigned int n);
  106. /**
  107. * regs_get_register() - get register value from its offset
  108. * @regs: pt_regs from which register value is gotten
  109. * @offset: offset of the register.
  110. *
  111. * regs_get_register returns the value of a register whose offset from @regs.
  112. * The @offset is the offset of the register in struct pt_regs.
  113. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  114. */
  115. static inline unsigned long regs_get_register(struct pt_regs *regs,
  116. unsigned int offset)
  117. {
  118. if (unlikely(offset > MAX_REG_OFFSET))
  119. return 0;
  120. return *(unsigned long *)((unsigned long)regs + offset);
  121. }
  122. #endif /* __ASSEMBLY__ */
  123. #endif /* _ASM_RISCV_PTRACE_H */