ptrace.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * OpenRISC Linux
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * OpenRISC implementation:
  10. * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
  11. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  12. * et al.
  13. */
  14. #ifndef __ASM_OPENRISC_PTRACE_H
  15. #define __ASM_OPENRISC_PTRACE_H
  16. #include <asm/spr_defs.h>
  17. #include <uapi/asm/ptrace.h>
  18. #include <linux/compiler.h>
  19. /*
  20. * Make kernel PTrace/register structures opaque to userspace... userspace can
  21. * access thread state via the regset mechanism. This allows us a bit of
  22. * flexibility in how we order the registers on the stack, permitting some
  23. * optimizations like packing call-clobbered registers together so that
  24. * they share a cacheline (not done yet, though... future optimization).
  25. */
  26. #ifndef __ASSEMBLER__
  27. /*
  28. * This struct describes how the registers are laid out on the kernel stack
  29. * during a syscall or other kernel entry.
  30. *
  31. * This structure should always be cacheline aligned on the stack.
  32. * FIXME: I don't think that's the case right now. The alignment is
  33. * taken care of elsewhere... head.S, process.c, etc.
  34. */
  35. struct pt_regs {
  36. union {
  37. struct {
  38. /* Named registers */
  39. long sr; /* Stored in place of r0 */
  40. long sp; /* r1 */
  41. long gpr2;
  42. long gpr3;
  43. long gpr4;
  44. long gpr5;
  45. long gpr6;
  46. long gpr7;
  47. long gpr8;
  48. long gpr9;
  49. long gpr10;
  50. long gpr11;
  51. long gpr12;
  52. long gpr13;
  53. long gpr14;
  54. long gpr15;
  55. long gpr16;
  56. long gpr17;
  57. long gpr18;
  58. long gpr19;
  59. long gpr20;
  60. long gpr21;
  61. long gpr22;
  62. long gpr23;
  63. long gpr24;
  64. long gpr25;
  65. long gpr26;
  66. long gpr27;
  67. long gpr28;
  68. long gpr29;
  69. long gpr30;
  70. long gpr31;
  71. };
  72. struct {
  73. /* Old style */
  74. long offset[2];
  75. long gprs[30];
  76. };
  77. struct {
  78. /* New style */
  79. long gpr[32];
  80. };
  81. };
  82. long pc;
  83. /* For restarting system calls:
  84. * Set to syscall number for syscall exceptions,
  85. * -1 for all other exceptions.
  86. */
  87. long orig_gpr11; /* For restarting system calls */
  88. long dummy; /* Cheap alignment fix */
  89. long dummy2; /* Cheap alignment fix */
  90. };
  91. /* TODO: Rename this to REDZONE because that's what it is */
  92. #define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */
  93. #define MAX_REG_OFFSET offsetof(struct pt_regs, orig_gpr11)
  94. /* Helpers for working with the instruction pointer */
  95. static inline unsigned long instruction_pointer(struct pt_regs *regs)
  96. {
  97. return (unsigned long)regs->pc;
  98. }
  99. static inline void instruction_pointer_set(struct pt_regs *regs,
  100. unsigned long val)
  101. {
  102. regs->pc = val;
  103. }
  104. #define user_mode(regs) (((regs)->sr & SPR_SR_SM) == 0)
  105. #define user_stack_pointer(regs) ((unsigned long)(regs)->sp)
  106. #define profile_pc(regs) instruction_pointer(regs)
  107. /* Valid only for Kernel mode traps. */
  108. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  109. {
  110. return (unsigned long)regs->sp;
  111. }
  112. static inline long regs_return_value(struct pt_regs *regs)
  113. {
  114. return regs->gpr[11];
  115. }
  116. extern int regs_query_register_offset(const char *name);
  117. extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
  118. unsigned int n);
  119. /**
  120. * regs_get_register() - get register value from its offset
  121. * @regs: pt_regs from which register value is gotten
  122. * @offset: offset of the register.
  123. *
  124. * regs_get_register returns the value of a register whose offset from @regs.
  125. * The @offset is the offset of the register in struct pt_regs.
  126. * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
  127. */
  128. static inline unsigned long regs_get_register(struct pt_regs *regs,
  129. unsigned int offset)
  130. {
  131. if (unlikely(offset > MAX_REG_OFFSET))
  132. return 0;
  133. return *(unsigned long *)((unsigned long)regs + offset);
  134. }
  135. #endif /* __ASSEMBLER__ */
  136. /*
  137. * Offsets used by 'ptrace' system call interface.
  138. */
  139. #define PT_SR 0
  140. #define PT_SP 4
  141. #define PT_GPR2 8
  142. #define PT_GPR3 12
  143. #define PT_GPR4 16
  144. #define PT_GPR5 20
  145. #define PT_GPR6 24
  146. #define PT_GPR7 28
  147. #define PT_GPR8 32
  148. #define PT_GPR9 36
  149. #define PT_GPR10 40
  150. #define PT_GPR11 44
  151. #define PT_GPR12 48
  152. #define PT_GPR13 52
  153. #define PT_GPR14 56
  154. #define PT_GPR15 60
  155. #define PT_GPR16 64
  156. #define PT_GPR17 68
  157. #define PT_GPR18 72
  158. #define PT_GPR19 76
  159. #define PT_GPR20 80
  160. #define PT_GPR21 84
  161. #define PT_GPR22 88
  162. #define PT_GPR23 92
  163. #define PT_GPR24 96
  164. #define PT_GPR25 100
  165. #define PT_GPR26 104
  166. #define PT_GPR27 108
  167. #define PT_GPR28 112
  168. #define PT_GPR29 116
  169. #define PT_GPR30 120
  170. #define PT_GPR31 124
  171. #define PT_PC 128
  172. #define PT_ORIG_GPR11 132
  173. #endif /* __ASM_OPENRISC_PTRACE_H */