ptrace.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * S390 version
  4. * Copyright IBM Corp. 1999, 2000
  5. * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
  6. */
  7. #ifndef _S390_PTRACE_H
  8. #define _S390_PTRACE_H
  9. #include <linux/const.h>
  10. #include <uapi/asm/ptrace.h>
  11. #define PIF_SYSCALL 0 /* inside a system call */
  12. #define PIF_PER_TRAP 1 /* deliver sigtrap on return to user */
  13. #define PIF_SYSCALL_RESTART 2 /* restart the current system call */
  14. #define PIF_GUEST_FAULT 3 /* indicates program check in sie64a */
  15. #define _PIF_SYSCALL _BITUL(PIF_SYSCALL)
  16. #define _PIF_PER_TRAP _BITUL(PIF_PER_TRAP)
  17. #define _PIF_SYSCALL_RESTART _BITUL(PIF_SYSCALL_RESTART)
  18. #define _PIF_GUEST_FAULT _BITUL(PIF_GUEST_FAULT)
  19. #ifndef __ASSEMBLY__
  20. #define PSW_KERNEL_BITS (PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_ASC_HOME | \
  21. PSW_MASK_EA | PSW_MASK_BA)
  22. #define PSW_USER_BITS (PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | \
  23. PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_MCHECK | \
  24. PSW_MASK_PSTATE | PSW_ASC_PRIMARY)
  25. struct psw_bits {
  26. unsigned long : 1;
  27. unsigned long per : 1; /* PER-Mask */
  28. unsigned long : 3;
  29. unsigned long dat : 1; /* DAT Mode */
  30. unsigned long io : 1; /* Input/Output Mask */
  31. unsigned long ext : 1; /* External Mask */
  32. unsigned long key : 4; /* PSW Key */
  33. unsigned long : 1;
  34. unsigned long mcheck : 1; /* Machine-Check Mask */
  35. unsigned long wait : 1; /* Wait State */
  36. unsigned long pstate : 1; /* Problem State */
  37. unsigned long as : 2; /* Address Space Control */
  38. unsigned long cc : 2; /* Condition Code */
  39. unsigned long pm : 4; /* Program Mask */
  40. unsigned long ri : 1; /* Runtime Instrumentation */
  41. unsigned long : 6;
  42. unsigned long eaba : 2; /* Addressing Mode */
  43. unsigned long : 31;
  44. unsigned long ia : 64; /* Instruction Address */
  45. };
  46. enum {
  47. PSW_BITS_AMODE_24BIT = 0,
  48. PSW_BITS_AMODE_31BIT = 1,
  49. PSW_BITS_AMODE_64BIT = 3
  50. };
  51. enum {
  52. PSW_BITS_AS_PRIMARY = 0,
  53. PSW_BITS_AS_ACCREG = 1,
  54. PSW_BITS_AS_SECONDARY = 2,
  55. PSW_BITS_AS_HOME = 3
  56. };
  57. #define psw_bits(__psw) (*({ \
  58. typecheck(psw_t, __psw); \
  59. &(*(struct psw_bits *)(&(__psw))); \
  60. }))
  61. /*
  62. * The pt_regs struct defines the way the registers are stored on
  63. * the stack during a system call.
  64. */
  65. struct pt_regs
  66. {
  67. union {
  68. user_pt_regs user_regs;
  69. struct {
  70. unsigned long args[1];
  71. psw_t psw;
  72. unsigned long gprs[NUM_GPRS];
  73. };
  74. };
  75. unsigned long orig_gpr2;
  76. unsigned int int_code;
  77. unsigned int int_parm;
  78. unsigned long int_parm_long;
  79. unsigned long flags;
  80. };
  81. /*
  82. * Program event recording (PER) register set.
  83. */
  84. struct per_regs {
  85. unsigned long control; /* PER control bits */
  86. unsigned long start; /* PER starting address */
  87. unsigned long end; /* PER ending address */
  88. };
  89. /*
  90. * PER event contains information about the cause of the last PER exception.
  91. */
  92. struct per_event {
  93. unsigned short cause; /* PER code, ATMID and AI */
  94. unsigned long address; /* PER address */
  95. unsigned char paid; /* PER access identification */
  96. };
  97. /*
  98. * Simplified per_info structure used to decode the ptrace user space ABI.
  99. */
  100. struct per_struct_kernel {
  101. unsigned long cr9; /* PER control bits */
  102. unsigned long cr10; /* PER starting address */
  103. unsigned long cr11; /* PER ending address */
  104. unsigned long bits; /* Obsolete software bits */
  105. unsigned long starting_addr; /* User specified start address */
  106. unsigned long ending_addr; /* User specified end address */
  107. unsigned short perc_atmid; /* PER trap ATMID */
  108. unsigned long address; /* PER trap instruction address */
  109. unsigned char access_id; /* PER trap access identification */
  110. };
  111. #define PER_EVENT_MASK 0xEB000000UL
  112. #define PER_EVENT_BRANCH 0x80000000UL
  113. #define PER_EVENT_IFETCH 0x40000000UL
  114. #define PER_EVENT_STORE 0x20000000UL
  115. #define PER_EVENT_STORE_REAL 0x08000000UL
  116. #define PER_EVENT_TRANSACTION_END 0x02000000UL
  117. #define PER_EVENT_NULLIFICATION 0x01000000UL
  118. #define PER_CONTROL_MASK 0x00e00000UL
  119. #define PER_CONTROL_BRANCH_ADDRESS 0x00800000UL
  120. #define PER_CONTROL_SUSPENSION 0x00400000UL
  121. #define PER_CONTROL_ALTERATION 0x00200000UL
  122. static inline void set_pt_regs_flag(struct pt_regs *regs, int flag)
  123. {
  124. regs->flags |= (1UL << flag);
  125. }
  126. static inline void clear_pt_regs_flag(struct pt_regs *regs, int flag)
  127. {
  128. regs->flags &= ~(1UL << flag);
  129. }
  130. static inline int test_pt_regs_flag(struct pt_regs *regs, int flag)
  131. {
  132. return !!(regs->flags & (1UL << flag));
  133. }
  134. /*
  135. * These are defined as per linux/ptrace.h, which see.
  136. */
  137. #define arch_has_single_step() (1)
  138. #define arch_has_block_step() (1)
  139. #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
  140. #define instruction_pointer(regs) ((regs)->psw.addr)
  141. #define user_stack_pointer(regs)((regs)->gprs[15])
  142. #define profile_pc(regs) instruction_pointer(regs)
  143. static inline long regs_return_value(struct pt_regs *regs)
  144. {
  145. return regs->gprs[2];
  146. }
  147. static inline void instruction_pointer_set(struct pt_regs *regs,
  148. unsigned long val)
  149. {
  150. regs->psw.addr = val;
  151. }
  152. int regs_query_register_offset(const char *name);
  153. const char *regs_query_register_name(unsigned int offset);
  154. unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset);
  155. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n);
  156. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  157. {
  158. return regs->gprs[15];
  159. }
  160. #endif /* __ASSEMBLY__ */
  161. #endif /* _S390_PTRACE_H */