ptrace.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. unsigned long args[1];
  68. psw_t psw;
  69. unsigned long gprs[NUM_GPRS];
  70. unsigned long orig_gpr2;
  71. unsigned int int_code;
  72. unsigned int int_parm;
  73. unsigned long int_parm_long;
  74. unsigned long flags;
  75. };
  76. /*
  77. * Program event recording (PER) register set.
  78. */
  79. struct per_regs {
  80. unsigned long control; /* PER control bits */
  81. unsigned long start; /* PER starting address */
  82. unsigned long end; /* PER ending address */
  83. };
  84. /*
  85. * PER event contains information about the cause of the last PER exception.
  86. */
  87. struct per_event {
  88. unsigned short cause; /* PER code, ATMID and AI */
  89. unsigned long address; /* PER address */
  90. unsigned char paid; /* PER access identification */
  91. };
  92. /*
  93. * Simplified per_info structure used to decode the ptrace user space ABI.
  94. */
  95. struct per_struct_kernel {
  96. unsigned long cr9; /* PER control bits */
  97. unsigned long cr10; /* PER starting address */
  98. unsigned long cr11; /* PER ending address */
  99. unsigned long bits; /* Obsolete software bits */
  100. unsigned long starting_addr; /* User specified start address */
  101. unsigned long ending_addr; /* User specified end address */
  102. unsigned short perc_atmid; /* PER trap ATMID */
  103. unsigned long address; /* PER trap instruction address */
  104. unsigned char access_id; /* PER trap access identification */
  105. };
  106. #define PER_EVENT_MASK 0xEB000000UL
  107. #define PER_EVENT_BRANCH 0x80000000UL
  108. #define PER_EVENT_IFETCH 0x40000000UL
  109. #define PER_EVENT_STORE 0x20000000UL
  110. #define PER_EVENT_STORE_REAL 0x08000000UL
  111. #define PER_EVENT_TRANSACTION_END 0x02000000UL
  112. #define PER_EVENT_NULLIFICATION 0x01000000UL
  113. #define PER_CONTROL_MASK 0x00e00000UL
  114. #define PER_CONTROL_BRANCH_ADDRESS 0x00800000UL
  115. #define PER_CONTROL_SUSPENSION 0x00400000UL
  116. #define PER_CONTROL_ALTERATION 0x00200000UL
  117. static inline void set_pt_regs_flag(struct pt_regs *regs, int flag)
  118. {
  119. regs->flags |= (1UL << flag);
  120. }
  121. static inline void clear_pt_regs_flag(struct pt_regs *regs, int flag)
  122. {
  123. regs->flags &= ~(1UL << flag);
  124. }
  125. static inline int test_pt_regs_flag(struct pt_regs *regs, int flag)
  126. {
  127. return !!(regs->flags & (1UL << flag));
  128. }
  129. /*
  130. * These are defined as per linux/ptrace.h, which see.
  131. */
  132. #define arch_has_single_step() (1)
  133. #define arch_has_block_step() (1)
  134. #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
  135. #define instruction_pointer(regs) ((regs)->psw.addr)
  136. #define user_stack_pointer(regs)((regs)->gprs[15])
  137. #define profile_pc(regs) instruction_pointer(regs)
  138. static inline long regs_return_value(struct pt_regs *regs)
  139. {
  140. return regs->gprs[2];
  141. }
  142. static inline void instruction_pointer_set(struct pt_regs *regs,
  143. unsigned long val)
  144. {
  145. regs->psw.addr = val;
  146. }
  147. int regs_query_register_offset(const char *name);
  148. const char *regs_query_register_name(unsigned int offset);
  149. unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset);
  150. unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n);
  151. static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
  152. {
  153. return regs->gprs[15];
  154. }
  155. #endif /* __ASSEMBLY__ */
  156. #endif /* _S390_PTRACE_H */