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 10 #include <linux/bits.h> 11 #include <uapi/asm/ptrace.h> 12 #include <asm/tpi.h> 13 14 #define PIF_SYSCALL 0 /* inside a system call */ 15 #define PIF_EXECVE_PGSTE_RESTART 1 /* restart execve for PGSTE binaries */ 16 #define PIF_SYSCALL_RET_SET 2 /* return value was set via ptrace */ 17 #define PIF_GUEST_FAULT 3 /* indicates program check in sie64a */ 18 #define PIF_FTRACE_FULL_REGS 4 /* all register contents valid (ftrace) */ 19 20 #define _PIF_SYSCALL BIT(PIF_SYSCALL) 21 #define _PIF_EXECVE_PGSTE_RESTART BIT(PIF_EXECVE_PGSTE_RESTART) 22 #define _PIF_SYSCALL_RET_SET BIT(PIF_SYSCALL_RET_SET) 23 #define _PIF_GUEST_FAULT BIT(PIF_GUEST_FAULT) 24 #define _PIF_FTRACE_FULL_REGS BIT(PIF_FTRACE_FULL_REGS) 25 26 #ifndef __ASSEMBLY__ 27 28 #define PSW_KERNEL_BITS (PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_ASC_HOME | \ 29 PSW_MASK_EA | PSW_MASK_BA) 30 #define PSW_USER_BITS (PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | \ 31 PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_MCHECK | \ 32 PSW_MASK_PSTATE | PSW_ASC_PRIMARY) 33 34 struct psw_bits { 35 unsigned long : 1; 36 unsigned long per : 1; /* PER-Mask */ 37 unsigned long : 3; 38 unsigned long dat : 1; /* DAT Mode */ 39 unsigned long io : 1; /* Input/Output Mask */ 40 unsigned long ext : 1; /* External Mask */ 41 unsigned long key : 4; /* PSW Key */ 42 unsigned long : 1; 43 unsigned long mcheck : 1; /* Machine-Check Mask */ 44 unsigned long wait : 1; /* Wait State */ 45 unsigned long pstate : 1; /* Problem State */ 46 unsigned long as : 2; /* Address Space Control */ 47 unsigned long cc : 2; /* Condition Code */ 48 unsigned long pm : 4; /* Program Mask */ 49 unsigned long ri : 1; /* Runtime Instrumentation */ 50 unsigned long : 6; 51 unsigned long eaba : 2; /* Addressing Mode */ 52 unsigned long : 31; 53 unsigned long ia : 64; /* Instruction Address */ 54 }; 55 56 enum { 57 PSW_BITS_AMODE_24BIT = 0, 58 PSW_BITS_AMODE_31BIT = 1, 59 PSW_BITS_AMODE_64BIT = 3 60 }; 61 62 enum { 63 PSW_BITS_AS_PRIMARY = 0, 64 PSW_BITS_AS_ACCREG = 1, 65 PSW_BITS_AS_SECONDARY = 2, 66 PSW_BITS_AS_HOME = 3 67 }; 68 69 #define psw_bits(__psw) (*({ \ 70 typecheck(psw_t, __psw); \ 71 &(*(struct psw_bits *)(&(__psw))); \ 72 })) 73 74 #define PGM_INT_CODE_MASK 0x7f 75 #define PGM_INT_CODE_PER 0x80 76 77 /* 78 * The pt_regs struct defines the way the registers are stored on 79 * the stack during a system call. 80 */ 81 struct pt_regs { 82 union { 83 user_pt_regs user_regs; 84 struct { 85 unsigned long args[1]; 86 psw_t psw; 87 unsigned long gprs[NUM_GPRS]; 88 }; 89 }; 90 unsigned long orig_gpr2; 91 union { 92 struct { 93 unsigned int int_code; 94 unsigned int int_parm; 95 unsigned long int_parm_long; 96 }; 97 struct tpi_info tpi_info; 98 }; 99 unsigned long flags; 100 unsigned long cr1; 101 unsigned long last_break; 102 }; 103 104 /* 105 * Program event recording (PER) register set. 106 */ 107 struct per_regs { 108 unsigned long control; /* PER control bits */ 109 unsigned long start; /* PER starting address */ 110 unsigned long end; /* PER ending address */ 111 }; 112 113 /* 114 * PER event contains information about the cause of the last PER exception. 115 */ 116 struct per_event { 117 unsigned short cause; /* PER code, ATMID and AI */ 118 unsigned long address; /* PER address */ 119 unsigned char paid; /* PER access identification */ 120 }; 121 122 /* 123 * Simplified per_info structure used to decode the ptrace user space ABI. 124 */ 125 struct per_struct_kernel { 126 unsigned long cr9; /* PER control bits */ 127 unsigned long cr10; /* PER starting address */ 128 unsigned long cr11; /* PER ending address */ 129 unsigned long bits; /* Obsolete software bits */ 130 unsigned long starting_addr; /* User specified start address */ 131 unsigned long ending_addr; /* User specified end address */ 132 unsigned short perc_atmid; /* PER trap ATMID */ 133 unsigned long address; /* PER trap instruction address */ 134 unsigned char access_id; /* PER trap access identification */ 135 }; 136 137 #define PER_EVENT_MASK 0xEB000000UL 138 139 #define PER_EVENT_BRANCH 0x80000000UL 140 #define PER_EVENT_IFETCH 0x40000000UL 141 #define PER_EVENT_STORE 0x20000000UL 142 #define PER_EVENT_STORE_REAL 0x08000000UL 143 #define PER_EVENT_TRANSACTION_END 0x02000000UL 144 #define PER_EVENT_NULLIFICATION 0x01000000UL 145 146 #define PER_CONTROL_MASK 0x00e00000UL 147 148 #define PER_CONTROL_BRANCH_ADDRESS 0x00800000UL 149 #define PER_CONTROL_SUSPENSION 0x00400000UL 150 #define PER_CONTROL_ALTERATION 0x00200000UL 151 152 static inline void set_pt_regs_flag(struct pt_regs *regs, int flag) 153 { 154 regs->flags |= (1UL << flag); 155 } 156 157 static inline void clear_pt_regs_flag(struct pt_regs *regs, int flag) 158 { 159 regs->flags &= ~(1UL << flag); 160 } 161 162 static inline int test_pt_regs_flag(struct pt_regs *regs, int flag) 163 { 164 return !!(regs->flags & (1UL << flag)); 165 } 166 167 static inline int test_and_clear_pt_regs_flag(struct pt_regs *regs, int flag) 168 { 169 int ret = test_pt_regs_flag(regs, flag); 170 171 clear_pt_regs_flag(regs, flag); 172 return ret; 173 } 174 175 /* 176 * These are defined as per linux/ptrace.h, which see. 177 */ 178 #define arch_has_single_step() (1) 179 #define arch_has_block_step() (1) 180 181 #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0) 182 #define instruction_pointer(regs) ((regs)->psw.addr) 183 #define user_stack_pointer(regs)((regs)->gprs[15]) 184 #define profile_pc(regs) instruction_pointer(regs) 185 186 static inline long regs_return_value(struct pt_regs *regs) 187 { 188 return regs->gprs[2]; 189 } 190 191 static inline void instruction_pointer_set(struct pt_regs *regs, 192 unsigned long val) 193 { 194 regs->psw.addr = val; 195 } 196 197 int regs_query_register_offset(const char *name); 198 const char *regs_query_register_name(unsigned int offset); 199 unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset); 200 unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n); 201 202 /** 203 * regs_get_kernel_argument() - get Nth function argument in kernel 204 * @regs: pt_regs of that context 205 * @n: function argument number (start from 0) 206 * 207 * regs_get_kernel_argument() returns @n th argument of the function call. 208 */ 209 static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs, 210 unsigned int n) 211 { 212 unsigned int argoffset = STACK_FRAME_OVERHEAD / sizeof(long); 213 214 #define NR_REG_ARGUMENTS 5 215 if (n < NR_REG_ARGUMENTS) 216 return regs_get_register(regs, 2 + n); 217 n -= NR_REG_ARGUMENTS; 218 return regs_get_kernel_stack_nth(regs, argoffset + n); 219 } 220 221 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs) 222 { 223 return regs->gprs[15]; 224 } 225 226 static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) 227 { 228 regs->gprs[2] = rc; 229 } 230 231 #endif /* __ASSEMBLY__ */ 232 #endif /* _S390_PTRACE_H */ 233