1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
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
8#ifndef _S390_PTRACE_H
9#define _S390_PTRACE_H
10
11#include <linux/const.h>
12
13/*
14 * Offsets in the user_regs_struct. They are used for the ptrace
15 * system call and in entry.S
16 */
17#define PT_PSWMASK 0x00
18#define PT_PSWADDR 0x08
19#define PT_GPR0 0x10
20#define PT_GPR1 0x18
21#define PT_GPR2 0x20
22#define PT_GPR3 0x28
23#define PT_GPR4 0x30
24#define PT_GPR5 0x38
25#define PT_GPR6 0x40
26#define PT_GPR7 0x48
27#define PT_GPR8 0x50
28#define PT_GPR9 0x58
29#define PT_GPR10 0x60
30#define PT_GPR11 0x68
31#define PT_GPR12 0x70
32#define PT_GPR13 0x78
33#define PT_GPR14 0x80
34#define PT_GPR15 0x88
35#define PT_ACR0 0x90
36#define PT_ACR1 0x94
37#define PT_ACR2 0x98
38#define PT_ACR3 0x9C
39#define PT_ACR4 0xA0
40#define PT_ACR5 0xA4
41#define PT_ACR6 0xA8
42#define PT_ACR7 0xAC
43#define PT_ACR8 0xB0
44#define PT_ACR9 0xB4
45#define PT_ACR10 0xB8
46#define PT_ACR11 0xBC
47#define PT_ACR12 0xC0
48#define PT_ACR13 0xC4
49#define PT_ACR14 0xC8
50#define PT_ACR15 0xCC
51#define PT_ORIGGPR2 0xD0
52#define PT_FPC 0xD8
53#define PT_FPR0 0xE0
54#define PT_FPR1 0xE8
55#define PT_FPR2 0xF0
56#define PT_FPR3 0xF8
57#define PT_FPR4 0x100
58#define PT_FPR5 0x108
59#define PT_FPR6 0x110
60#define PT_FPR7 0x118
61#define PT_FPR8 0x120
62#define PT_FPR9 0x128
63#define PT_FPR10 0x130
64#define PT_FPR11 0x138
65#define PT_FPR12 0x140
66#define PT_FPR13 0x148
67#define PT_FPR14 0x150
68#define PT_FPR15 0x158
69#define PT_CR_9 0x160
70#define PT_CR_10 0x168
71#define PT_CR_11 0x170
72#define PT_IEEE_IP 0x1A8
73#define PT_LASTOFF PT_IEEE_IP
74#define PT_ENDREGS 0x1B0-1
75
76#define GPR_SIZE 8
77#define CR_SIZE 8
78
79#define STACK_FRAME_OVERHEAD 160 /* size of minimum stack frame */
80
81#define PSW_MASK_PER _AC(0x4000000000000000, UL)
82#define PSW_MASK_DAT _AC(0x0400000000000000, UL)
83#define PSW_MASK_IO _AC(0x0200000000000000, UL)
84#define PSW_MASK_EXT _AC(0x0100000000000000, UL)
85#define PSW_MASK_BASE _AC(0x0000000000000000, UL)
86#define PSW_MASK_KEY _AC(0x00F0000000000000, UL)
87#define PSW_MASK_MCHECK _AC(0x0004000000000000, UL)
88#define PSW_MASK_WAIT _AC(0x0002000000000000, UL)
89#define PSW_MASK_PSTATE _AC(0x0001000000000000, UL)
90#define PSW_MASK_ASC _AC(0x0000C00000000000, UL)
91#define PSW_MASK_CC _AC(0x0000300000000000, UL)
92#define PSW_MASK_PM _AC(0x00000F0000000000, UL)
93#define PSW_MASK_RI _AC(0x0000008000000000, UL)
94#define PSW_MASK_EA _AC(0x0000000100000000, UL)
95#define PSW_MASK_BA _AC(0x0000000080000000, UL)
96
97#define PSW_MASK_USER _AC(0x0000FF0180000000, UL)
98
99#define PSW_ADDR_AMODE _AC(0x0000000000000000, UL)
100#define PSW_ADDR_INSN _AC(0xFFFFFFFFFFFFFFFF, UL)
101
102#define PSW_ASC_PRIMARY _AC(0x0000000000000000, UL)
103#define PSW_ASC_ACCREG _AC(0x0000400000000000, UL)
104#define PSW_ASC_SECONDARY _AC(0x0000800000000000, UL)
105#define PSW_ASC_HOME _AC(0x0000C00000000000, UL)
106
107#define NUM_GPRS 16
108#define NUM_FPRS 16
109#define NUM_CRS 16
110#define NUM_ACRS 16
111
112#define NUM_CR_WORDS 3
113
114#define FPR_SIZE 8
115#define FPC_SIZE 4
116#define FPC_PAD_SIZE 4 /* gcc insists on aligning the fpregs */
117#define ACR_SIZE 4
118
119
120#define PTRACE_OLDSETOPTIONS 21
121#define PTRACE_SYSEMU 31
122#define PTRACE_SYSEMU_SINGLESTEP 32
123
124#ifndef __ASSEMBLER__
125#include <linux/stddef.h>
126#include <linux/types.h>
127
128typedef union {
129 float f;
130 double d;
131 __u64 ui;
132 struct
133 {
134 __u32 hi;
135 __u32 lo;
136 } fp;
137} freg_t;
138
139typedef struct {
140 __u32 fpc;
141 __u32 pad;
142 freg_t fprs[NUM_FPRS];
143} s390_fp_regs;
144
145#define FPC_EXCEPTION_MASK 0xF8000000
146#define FPC_FLAGS_MASK 0x00F80000
147#define FPC_DXC_MASK 0x0000FF00
148#define FPC_RM_MASK 0x00000003
149
150/* this typedef defines how a Program Status Word looks like */
151typedef struct {
152 unsigned long mask;
153 unsigned long addr;
154} __attribute__ ((aligned(8))) psw_t;
155
156/*
157 * The s390_regs structure is used to define the elf_gregset_t.
158 */
159typedef struct {
160 psw_t psw;
161 unsigned long gprs[NUM_GPRS];
162 unsigned int acrs[NUM_ACRS];
163 unsigned long orig_gpr2;
164} s390_regs;
165
166/*
167 * The user_pt_regs structure exports the beginning of
168 * the in-kernel pt_regs structure to user space.
169 */
170typedef struct {
171 unsigned long args[1];
172 psw_t psw;
173 unsigned long gprs[NUM_GPRS];
174} user_pt_regs;
175
176/*
177 * Now for the user space program event recording (trace) definitions.
178 * The following structures are used only for the ptrace interface, don't
179 * touch or even look at it if you don't want to modify the user-space
180 * ptrace interface. In particular stay away from it for in-kernel PER.
181 */
182typedef struct {
183 unsigned long cr[NUM_CR_WORDS];
184} per_cr_words;
185
186#define PER_EM_MASK 0xE8000000UL
187
188typedef struct {
189 unsigned : 32;
190 unsigned em_branching : 1;
191 unsigned em_instruction_fetch : 1;
192 /*
193 * Switching on storage alteration automatically fixes
194 * the storage alteration event bit in the users std.
195 */
196 unsigned em_storage_alteration : 1;
197 unsigned em_gpr_alt_unused : 1;
198 unsigned em_store_real_address : 1;
199 unsigned : 3;
200 unsigned branch_addr_ctl : 1;
201 unsigned : 1;
202 unsigned storage_alt_space_ctl : 1;
203 unsigned : 21;
204 unsigned long starting_addr;
205 unsigned long ending_addr;
206} per_cr_bits;
207
208typedef struct {
209 unsigned short perc_atmid;
210 unsigned long address;
211 unsigned char access_id;
212} per_lowcore_words;
213
214typedef struct {
215 unsigned perc_branching : 1;
216 unsigned perc_instruction_fetch : 1;
217 unsigned perc_storage_alteration : 1;
218 unsigned perc_gpr_alt_unused : 1;
219 unsigned perc_store_real_address : 1;
220 unsigned : 3;
221 unsigned atmid_psw_bit_31 : 1;
222 unsigned atmid_validity_bit : 1;
223 unsigned atmid_psw_bit_32 : 1;
224 unsigned atmid_psw_bit_5 : 1;
225 unsigned atmid_psw_bit_16 : 1;
226 unsigned atmid_psw_bit_17 : 1;
227 unsigned si : 2;
228 unsigned long address;
229 unsigned : 4;
230 unsigned access_id : 4;
231} per_lowcore_bits;
232
233typedef struct {
234 union {
235 per_cr_words words;
236 per_cr_bits bits;
237 } control_regs;
238 /*
239 * The single_step and instruction_fetch bits are obsolete,
240 * the kernel always sets them to zero. To enable single
241 * stepping use ptrace(PTRACE_SINGLESTEP) instead.
242 */
243 unsigned single_step : 1;
244 unsigned instruction_fetch : 1;
245 unsigned : 30;
246 /*
247 * These addresses are copied into cr10 & cr11 if single
248 * stepping is switched off
249 */
250 unsigned long starting_addr;
251 unsigned long ending_addr;
252 union {
253 per_lowcore_words words;
254 per_lowcore_bits bits;
255 } lowcore;
256} per_struct;
257
258typedef struct {
259 unsigned int len;
260 unsigned long kernel_addr;
261 unsigned long process_addr;
262} ptrace_area;
263
264/*
265 * S/390 specific non posix ptrace requests. I chose unusual values so
266 * they are unlikely to clash with future ptrace definitions.
267 */
268#define PTRACE_PEEKUSR_AREA 0x5000
269#define PTRACE_POKEUSR_AREA 0x5001
270#define PTRACE_PEEKTEXT_AREA 0x5002
271#define PTRACE_PEEKDATA_AREA 0x5003
272#define PTRACE_POKETEXT_AREA 0x5004
273#define PTRACE_POKEDATA_AREA 0x5005
274#define PTRACE_GET_LAST_BREAK 0x5006
275#define PTRACE_PEEK_SYSTEM_CALL 0x5007
276#define PTRACE_POKE_SYSTEM_CALL 0x5008
277#define PTRACE_ENABLE_TE 0x5009
278#define PTRACE_DISABLE_TE 0x5010
279#define PTRACE_TE_ABORT_RAND 0x5011
280
281/*
282 * The numbers chosen here are somewhat arbitrary but absolutely MUST
283 * not overlap with any of the number assigned in <linux/ptrace.h>.
284 */
285#define PTRACE_SINGLEBLOCK 12 /* resume execution until next branch */
286
287/*
288 * PT_PROT definition is loosely based on hppa bsd definition in
289 * gdb/hppab-nat.c
290 */
291#define PTRACE_PROT 21
292
293typedef enum {
294 ptprot_set_access_watchpoint,
295 ptprot_set_write_watchpoint,
296 ptprot_disable_watchpoint
297} ptprot_flags;
298
299typedef struct {
300 unsigned long lowaddr;
301 unsigned long hiaddr;
302 ptprot_flags prot;
303} ptprot_area;
304
305/* Sequence of bytes for breakpoint illegal instruction. */
306#define S390_BREAKPOINT {0x0,0x1}
307#define S390_BREAKPOINT_U16 ((__u16)0x0001)
308#define S390_SYSCALL_OPCODE ((__u16)0x0a00)
309#define S390_SYSCALL_SIZE 2
310
311/*
312 * The user_regs_struct defines the way the user registers are
313 * store on the stack for signal handling.
314 */
315struct user_regs_struct {
316 psw_t psw;
317 unsigned long gprs[NUM_GPRS];
318 unsigned int acrs[NUM_ACRS];
319 unsigned long orig_gpr2;
320 s390_fp_regs fp_regs;
321 /*
322 * These per registers are in here so that gdb can modify them
323 * itself as there is no "official" ptrace interface for hardware
324 * watchpoints. This is the way intel does it.
325 */
326 per_struct per_info;
327 unsigned long ieee_instruction_pointer; /* obsolete, always 0 */
328};
329
330#endif /* __ASSEMBLER__ */
331
332#endif /* _S390_PTRACE_H */