e107af8b07dcdc110cabcced61ee6146db3b8295
[deliverable/binutils-gdb.git] / gdb / s390-linux-tdep.c
1 /* Target-dependent code for GDB, the GNU debugger.
2
3 Copyright (C) 2001-2018 Free Software Foundation, Inc.
4
5 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23 #include "defs.h"
24 #include "arch-utils.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "infrun.h"
28 #include "symtab.h"
29 #include "target.h"
30 #include "gdbcore.h"
31 #include "gdbcmd.h"
32 #include "objfiles.h"
33 #include "regcache.h"
34 #include "trad-frame.h"
35 #include "frame-base.h"
36 #include "frame-unwind.h"
37 #include "dwarf2-frame.h"
38 #include "reggroups.h"
39 #include "regset.h"
40 #include "value.h"
41 #include "dis-asm.h"
42 #include "solib-svr4.h"
43 #include "prologue-value.h"
44 #include "linux-tdep.h"
45 #include "s390-linux-tdep.h"
46 #include "linux-record.h"
47 #include "record-full.h"
48 #include "auxv.h"
49 #include "xml-syscall.h"
50
51 #include "stap-probe.h"
52 #include "ax.h"
53 #include "ax-gdb.h"
54 #include "user-regs.h"
55 #include "cli/cli-utils.h"
56 #include <ctype.h>
57 #include "elf/common.h"
58 #include "elf/s390.h"
59 #include "elf-bfd.h"
60 #include <algorithm>
61
62 #include "features/s390-linux32.c"
63 #include "features/s390-linux32v1.c"
64 #include "features/s390-linux32v2.c"
65 #include "features/s390-linux64.c"
66 #include "features/s390-linux64v1.c"
67 #include "features/s390-linux64v2.c"
68 #include "features/s390-te-linux64.c"
69 #include "features/s390-vx-linux64.c"
70 #include "features/s390-tevx-linux64.c"
71 #include "features/s390-gs-linux64.c"
72 #include "features/s390x-linux64.c"
73 #include "features/s390x-linux64v1.c"
74 #include "features/s390x-linux64v2.c"
75 #include "features/s390x-te-linux64.c"
76 #include "features/s390x-vx-linux64.c"
77 #include "features/s390x-tevx-linux64.c"
78 #include "features/s390x-gs-linux64.c"
79
80 #define XML_SYSCALL_FILENAME_S390 "syscalls/s390-linux.xml"
81 #define XML_SYSCALL_FILENAME_S390X "syscalls/s390x-linux.xml"
82
83 /* Holds the current set of options to be passed to the disassembler. */
84 static char *s390_disassembler_options;
85
86 enum s390_abi_kind
87 {
88 ABI_NONE,
89 ABI_LINUX_S390,
90 ABI_LINUX_ZSERIES
91 };
92
93 enum s390_vector_abi_kind
94 {
95 S390_VECTOR_ABI_NONE,
96 S390_VECTOR_ABI_128
97 };
98
99 /* The tdep structure. */
100
101 struct gdbarch_tdep
102 {
103 /* ABI version. */
104 enum s390_abi_kind abi;
105
106 /* Vector ABI. */
107 enum s390_vector_abi_kind vector_abi;
108
109 /* Pseudo register numbers. */
110 int gpr_full_regnum;
111 int pc_regnum;
112 int cc_regnum;
113 int v0_full_regnum;
114
115 bool have_upper;
116 int have_linux_v1;
117 int have_linux_v2;
118 int have_tdb;
119 bool have_vx;
120 bool have_gs;
121 };
122
123
124 /* ABI call-saved register information. */
125
126 static int
127 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
128 {
129 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
130
131 switch (tdep->abi)
132 {
133 case ABI_LINUX_S390:
134 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
135 || regnum == S390_F4_REGNUM || regnum == S390_F6_REGNUM
136 || regnum == S390_A0_REGNUM)
137 return 1;
138
139 break;
140
141 case ABI_LINUX_ZSERIES:
142 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
143 || (regnum >= S390_F8_REGNUM && regnum <= S390_F15_REGNUM)
144 || (regnum >= S390_A0_REGNUM && regnum <= S390_A1_REGNUM))
145 return 1;
146
147 break;
148 }
149
150 return 0;
151 }
152
153 static int
154 s390_cannot_store_register (struct gdbarch *gdbarch, int regnum)
155 {
156 /* The last-break address is read-only. */
157 return regnum == S390_LAST_BREAK_REGNUM;
158 }
159
160 static void
161 s390_write_pc (struct regcache *regcache, CORE_ADDR pc)
162 {
163 struct gdbarch *gdbarch = regcache->arch ();
164 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
165
166 regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc);
167
168 /* Set special SYSTEM_CALL register to 0 to prevent the kernel from
169 messing with the PC we just installed, if we happen to be within
170 an interrupted system call that the kernel wants to restart.
171
172 Note that after we return from the dummy call, the SYSTEM_CALL and
173 ORIG_R2 registers will be automatically restored, and the kernel
174 continues to restart the system call at this point. */
175 if (register_size (gdbarch, S390_SYSTEM_CALL_REGNUM) > 0)
176 regcache_cooked_write_unsigned (regcache, S390_SYSTEM_CALL_REGNUM, 0);
177 }
178
179 /* The "guess_tracepoint_registers" gdbarch method. */
180
181 static void
182 s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
183 struct regcache *regcache,
184 CORE_ADDR addr)
185 {
186 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
187 int sz = register_size (gdbarch, S390_PSWA_REGNUM);
188 gdb_byte *reg = (gdb_byte *) alloca (sz);
189 ULONGEST pswm, pswa;
190
191 /* Set PSWA from the location and a default PSWM (the only part we're
192 unlikely to get right is the CC). */
193 if (tdep->abi == ABI_LINUX_S390)
194 {
195 /* 31-bit PSWA needs high bit set (it's very unlikely the target
196 was in 24-bit mode). */
197 pswa = addr | 0x80000000UL;
198 pswm = 0x070d0000UL;
199 }
200 else
201 {
202 pswa = addr;
203 pswm = 0x0705000180000000ULL;
204 }
205
206 store_unsigned_integer (reg, sz, gdbarch_byte_order (gdbarch), pswa);
207 regcache_raw_supply (regcache, S390_PSWA_REGNUM, reg);
208
209 store_unsigned_integer (reg, sz, gdbarch_byte_order (gdbarch), pswm);
210 regcache_raw_supply (regcache, S390_PSWM_REGNUM, reg);
211 }
212
213
214 /* DWARF Register Mapping. */
215
216 static const short s390_dwarf_regmap[] =
217 {
218 /* 0-15: General Purpose Registers. */
219 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
220 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
221 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
222 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
223
224 /* 16-31: Floating Point Registers / Vector Registers 0-15. */
225 S390_F0_REGNUM, S390_F2_REGNUM, S390_F4_REGNUM, S390_F6_REGNUM,
226 S390_F1_REGNUM, S390_F3_REGNUM, S390_F5_REGNUM, S390_F7_REGNUM,
227 S390_F8_REGNUM, S390_F10_REGNUM, S390_F12_REGNUM, S390_F14_REGNUM,
228 S390_F9_REGNUM, S390_F11_REGNUM, S390_F13_REGNUM, S390_F15_REGNUM,
229
230 /* 32-47: Control Registers (not mapped). */
231 -1, -1, -1, -1, -1, -1, -1, -1,
232 -1, -1, -1, -1, -1, -1, -1, -1,
233
234 /* 48-63: Access Registers. */
235 S390_A0_REGNUM, S390_A1_REGNUM, S390_A2_REGNUM, S390_A3_REGNUM,
236 S390_A4_REGNUM, S390_A5_REGNUM, S390_A6_REGNUM, S390_A7_REGNUM,
237 S390_A8_REGNUM, S390_A9_REGNUM, S390_A10_REGNUM, S390_A11_REGNUM,
238 S390_A12_REGNUM, S390_A13_REGNUM, S390_A14_REGNUM, S390_A15_REGNUM,
239
240 /* 64-65: Program Status Word. */
241 S390_PSWM_REGNUM,
242 S390_PSWA_REGNUM,
243
244 /* 66-67: Reserved. */
245 -1, -1,
246
247 /* 68-83: Vector Registers 16-31. */
248 S390_V16_REGNUM, S390_V18_REGNUM, S390_V20_REGNUM, S390_V22_REGNUM,
249 S390_V17_REGNUM, S390_V19_REGNUM, S390_V21_REGNUM, S390_V23_REGNUM,
250 S390_V24_REGNUM, S390_V26_REGNUM, S390_V28_REGNUM, S390_V30_REGNUM,
251 S390_V25_REGNUM, S390_V27_REGNUM, S390_V29_REGNUM, S390_V31_REGNUM,
252
253 /* End of "official" DWARF registers. The remainder of the map is
254 for GDB internal use only. */
255
256 /* GPR Lower Half Access. */
257 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
258 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
259 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
260 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
261 };
262
263 enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
264
265 /* Convert DWARF register number REG to the appropriate register
266 number used by GDB. */
267 static int
268 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
269 {
270 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
271 int gdb_reg = -1;
272
273 /* In a 32-on-64 debug scenario, debug info refers to the full
274 64-bit GPRs. Note that call frame information still refers to
275 the 32-bit lower halves, because s390_adjust_frame_regnum uses
276 special register numbers to access GPRs. */
277 if (tdep->gpr_full_regnum != -1 && reg >= 0 && reg < 16)
278 return tdep->gpr_full_regnum + reg;
279
280 if (reg >= 0 && reg < ARRAY_SIZE (s390_dwarf_regmap))
281 gdb_reg = s390_dwarf_regmap[reg];
282
283 if (tdep->v0_full_regnum == -1)
284 {
285 if (gdb_reg >= S390_V16_REGNUM && gdb_reg <= S390_V31_REGNUM)
286 gdb_reg = -1;
287 }
288 else
289 {
290 if (gdb_reg >= S390_F0_REGNUM && gdb_reg <= S390_F15_REGNUM)
291 gdb_reg = gdb_reg - S390_F0_REGNUM + tdep->v0_full_regnum;
292 }
293
294 return gdb_reg;
295 }
296
297 /* Translate a .eh_frame register to DWARF register, or adjust a
298 .debug_frame register. */
299 static int
300 s390_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p)
301 {
302 /* See s390_dwarf_reg_to_regnum for comments. */
303 return (num >= 0 && num < 16) ? num + s390_dwarf_reg_r0l : num;
304 }
305
306
307 /* Pseudo registers. */
308
309 static int
310 regnum_is_gpr_full (struct gdbarch_tdep *tdep, int regnum)
311 {
312 return (tdep->gpr_full_regnum != -1
313 && regnum >= tdep->gpr_full_regnum
314 && regnum <= tdep->gpr_full_regnum + 15);
315 }
316
317 /* Check whether REGNUM indicates a full vector register (v0-v15).
318 These pseudo-registers are composed of f0-f15 and v0l-v15l. */
319
320 static int
321 regnum_is_vxr_full (struct gdbarch_tdep *tdep, int regnum)
322 {
323 return (tdep->v0_full_regnum != -1
324 && regnum >= tdep->v0_full_regnum
325 && regnum <= tdep->v0_full_regnum + 15);
326 }
327
328 /* Return the name of register REGNO. Return the empty string for
329 registers that shouldn't be visible. */
330
331 static const char *
332 s390_register_name (struct gdbarch *gdbarch, int regnum)
333 {
334 if (regnum >= S390_V0_LOWER_REGNUM
335 && regnum <= S390_V15_LOWER_REGNUM)
336 return "";
337 return tdesc_register_name (gdbarch, regnum);
338 }
339
340 static const char *
341 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
342 {
343 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
344
345 if (regnum == tdep->pc_regnum)
346 return "pc";
347
348 if (regnum == tdep->cc_regnum)
349 return "cc";
350
351 if (regnum_is_gpr_full (tdep, regnum))
352 {
353 static const char *full_name[] = {
354 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
355 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
356 };
357 return full_name[regnum - tdep->gpr_full_regnum];
358 }
359
360 if (regnum_is_vxr_full (tdep, regnum))
361 {
362 static const char *full_name[] = {
363 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
364 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15"
365 };
366 return full_name[regnum - tdep->v0_full_regnum];
367 }
368
369 internal_error (__FILE__, __LINE__, _("invalid regnum"));
370 }
371
372 static struct type *
373 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
374 {
375 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
376
377 if (regnum == tdep->pc_regnum)
378 return builtin_type (gdbarch)->builtin_func_ptr;
379
380 if (regnum == tdep->cc_regnum)
381 return builtin_type (gdbarch)->builtin_int;
382
383 if (regnum_is_gpr_full (tdep, regnum))
384 return builtin_type (gdbarch)->builtin_uint64;
385
386 if (regnum_is_vxr_full (tdep, regnum))
387 return tdesc_find_type (gdbarch, "vec128");
388
389 internal_error (__FILE__, __LINE__, _("invalid regnum"));
390 }
391
392 static enum register_status
393 s390_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
394 int regnum, gdb_byte *buf)
395 {
396 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
397 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
398 int regsize = register_size (gdbarch, regnum);
399 ULONGEST val;
400
401 if (regnum == tdep->pc_regnum)
402 {
403 enum register_status status;
404
405 status = regcache->raw_read (S390_PSWA_REGNUM, &val);
406 if (status == REG_VALID)
407 {
408 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
409 val &= 0x7fffffff;
410 store_unsigned_integer (buf, regsize, byte_order, val);
411 }
412 return status;
413 }
414
415 if (regnum == tdep->cc_regnum)
416 {
417 enum register_status status;
418
419 status = regcache->raw_read (S390_PSWM_REGNUM, &val);
420 if (status == REG_VALID)
421 {
422 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
423 val = (val >> 12) & 3;
424 else
425 val = (val >> 44) & 3;
426 store_unsigned_integer (buf, regsize, byte_order, val);
427 }
428 return status;
429 }
430
431 if (regnum_is_gpr_full (tdep, regnum))
432 {
433 enum register_status status;
434 ULONGEST val_upper;
435
436 regnum -= tdep->gpr_full_regnum;
437
438 status = regcache->raw_read (S390_R0_REGNUM + regnum, &val);
439 if (status == REG_VALID)
440 status = regcache->raw_read (S390_R0_UPPER_REGNUM + regnum,
441 &val_upper);
442 if (status == REG_VALID)
443 {
444 val |= val_upper << 32;
445 store_unsigned_integer (buf, regsize, byte_order, val);
446 }
447 return status;
448 }
449
450 if (regnum_is_vxr_full (tdep, regnum))
451 {
452 enum register_status status;
453
454 regnum -= tdep->v0_full_regnum;
455
456 status = regcache->raw_read (S390_F0_REGNUM + regnum, buf);
457 if (status == REG_VALID)
458 status = regcache->raw_read (S390_V0_LOWER_REGNUM + regnum, buf + 8);
459 return status;
460 }
461
462 internal_error (__FILE__, __LINE__, _("invalid regnum"));
463 }
464
465 static void
466 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
467 int regnum, const gdb_byte *buf)
468 {
469 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
470 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
471 int regsize = register_size (gdbarch, regnum);
472 ULONGEST val, psw;
473
474 if (regnum == tdep->pc_regnum)
475 {
476 val = extract_unsigned_integer (buf, regsize, byte_order);
477 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
478 {
479 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &psw);
480 val = (psw & 0x80000000) | (val & 0x7fffffff);
481 }
482 regcache_raw_write_unsigned (regcache, S390_PSWA_REGNUM, val);
483 return;
484 }
485
486 if (regnum == tdep->cc_regnum)
487 {
488 val = extract_unsigned_integer (buf, regsize, byte_order);
489 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
490 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
491 val = (psw & ~((ULONGEST)3 << 12)) | ((val & 3) << 12);
492 else
493 val = (psw & ~((ULONGEST)3 << 44)) | ((val & 3) << 44);
494 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, val);
495 return;
496 }
497
498 if (regnum_is_gpr_full (tdep, regnum))
499 {
500 regnum -= tdep->gpr_full_regnum;
501 val = extract_unsigned_integer (buf, regsize, byte_order);
502 regcache_raw_write_unsigned (regcache, S390_R0_REGNUM + regnum,
503 val & 0xffffffff);
504 regcache_raw_write_unsigned (regcache, S390_R0_UPPER_REGNUM + regnum,
505 val >> 32);
506 return;
507 }
508
509 if (regnum_is_vxr_full (tdep, regnum))
510 {
511 regnum -= tdep->v0_full_regnum;
512 regcache_raw_write (regcache, S390_F0_REGNUM + regnum, buf);
513 regcache_raw_write (regcache, S390_V0_LOWER_REGNUM + regnum, buf + 8);
514 return;
515 }
516
517 internal_error (__FILE__, __LINE__, _("invalid regnum"));
518 }
519
520 /* 'float' values are stored in the upper half of floating-point
521 registers, even though we are otherwise a big-endian platform. The
522 same applies to a 'float' value within a vector. */
523
524 static struct value *
525 s390_value_from_register (struct gdbarch *gdbarch, struct type *type,
526 int regnum, struct frame_id frame_id)
527 {
528 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
529 struct value *value = default_value_from_register (gdbarch, type,
530 regnum, frame_id);
531 check_typedef (type);
532
533 if ((regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM
534 && TYPE_LENGTH (type) < 8)
535 || regnum_is_vxr_full (tdep, regnum)
536 || (regnum >= S390_V16_REGNUM && regnum <= S390_V31_REGNUM))
537 set_value_offset (value, 0);
538
539 return value;
540 }
541
542 /* Register groups. */
543
544 static int
545 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
546 struct reggroup *group)
547 {
548 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
549
550 /* We usually save/restore the whole PSW, which includes PC and CC.
551 However, some older gdbservers may not support saving/restoring
552 the whole PSW yet, and will return an XML register description
553 excluding those from the save/restore register groups. In those
554 cases, we still need to explicitly save/restore PC and CC in order
555 to push or pop frames. Since this doesn't hurt anything if we
556 already save/restore the whole PSW (it's just redundant), we add
557 PC and CC at this point unconditionally. */
558 if (group == save_reggroup || group == restore_reggroup)
559 return regnum == tdep->pc_regnum || regnum == tdep->cc_regnum;
560
561 if (group == vector_reggroup)
562 return regnum_is_vxr_full (tdep, regnum);
563
564 if (group == general_reggroup && regnum_is_vxr_full (tdep, regnum))
565 return 0;
566
567 return default_register_reggroup_p (gdbarch, regnum, group);
568 }
569
570 /* The "ax_pseudo_register_collect" gdbarch method. */
571
572 static int
573 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
574 struct agent_expr *ax, int regnum)
575 {
576 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
577 if (regnum == tdep->pc_regnum)
578 {
579 ax_reg_mask (ax, S390_PSWA_REGNUM);
580 }
581 else if (regnum == tdep->cc_regnum)
582 {
583 ax_reg_mask (ax, S390_PSWM_REGNUM);
584 }
585 else if (regnum_is_gpr_full (tdep, regnum))
586 {
587 regnum -= tdep->gpr_full_regnum;
588 ax_reg_mask (ax, S390_R0_REGNUM + regnum);
589 ax_reg_mask (ax, S390_R0_UPPER_REGNUM + regnum);
590 }
591 else if (regnum_is_vxr_full (tdep, regnum))
592 {
593 regnum -= tdep->v0_full_regnum;
594 ax_reg_mask (ax, S390_F0_REGNUM + regnum);
595 ax_reg_mask (ax, S390_V0_LOWER_REGNUM + regnum);
596 }
597 else
598 {
599 internal_error (__FILE__, __LINE__, _("invalid regnum"));
600 }
601 return 0;
602 }
603
604 /* The "ax_pseudo_register_push_stack" gdbarch method. */
605
606 static int
607 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
608 struct agent_expr *ax, int regnum)
609 {
610 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
611 if (regnum == tdep->pc_regnum)
612 {
613 ax_reg (ax, S390_PSWA_REGNUM);
614 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
615 {
616 ax_zero_ext (ax, 31);
617 }
618 }
619 else if (regnum == tdep->cc_regnum)
620 {
621 ax_reg (ax, S390_PSWM_REGNUM);
622 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
623 ax_const_l (ax, 12);
624 else
625 ax_const_l (ax, 44);
626 ax_simple (ax, aop_rsh_unsigned);
627 ax_zero_ext (ax, 2);
628 }
629 else if (regnum_is_gpr_full (tdep, regnum))
630 {
631 regnum -= tdep->gpr_full_regnum;
632 ax_reg (ax, S390_R0_REGNUM + regnum);
633 ax_reg (ax, S390_R0_UPPER_REGNUM + regnum);
634 ax_const_l (ax, 32);
635 ax_simple (ax, aop_lsh);
636 ax_simple (ax, aop_bit_or);
637 }
638 else if (regnum_is_vxr_full (tdep, regnum))
639 {
640 /* Too large to stuff on the stack. */
641 return 1;
642 }
643 else
644 {
645 internal_error (__FILE__, __LINE__, _("invalid regnum"));
646 }
647 return 0;
648 }
649
650 /* The "gen_return_address" gdbarch method. Since this is supposed to be
651 just a best-effort method, and we don't really have the means to run
652 the full unwinder here, just collect the link register. */
653
654 static void
655 s390_gen_return_address (struct gdbarch *gdbarch,
656 struct agent_expr *ax, struct axs_value *value,
657 CORE_ADDR scope)
658 {
659 value->type = register_type (gdbarch, S390_R14_REGNUM);
660 value->kind = axs_lvalue_register;
661 value->u.reg = S390_R14_REGNUM;
662 }
663
664
665 /* A helper for s390_software_single_step, decides if an instruction
666 is a partial-execution instruction that needs to be executed until
667 completion when in record mode. If it is, returns 1 and writes
668 instruction length to a pointer. */
669
670 static int
671 s390_is_partial_instruction (struct gdbarch *gdbarch, CORE_ADDR loc, int *len)
672 {
673 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
674 uint16_t insn;
675
676 insn = read_memory_integer (loc, 2, byte_order);
677
678 switch (insn >> 8)
679 {
680 case 0xa8: /* MVCLE */
681 *len = 4;
682 return 1;
683
684 case 0xeb:
685 {
686 insn = read_memory_integer (loc + 4, 2, byte_order);
687 if ((insn & 0xff) == 0x8e)
688 {
689 /* MVCLU */
690 *len = 6;
691 return 1;
692 }
693 }
694 break;
695 }
696
697 switch (insn)
698 {
699 case 0xb255: /* MVST */
700 case 0xb263: /* CMPSC */
701 case 0xb2a5: /* TRE */
702 case 0xb2a6: /* CU21 */
703 case 0xb2a7: /* CU12 */
704 case 0xb9b0: /* CU14 */
705 case 0xb9b1: /* CU24 */
706 case 0xb9b2: /* CU41 */
707 case 0xb9b3: /* CU42 */
708 case 0xb92a: /* KMF */
709 case 0xb92b: /* KMO */
710 case 0xb92f: /* KMC */
711 case 0xb92d: /* KMCTR */
712 case 0xb92e: /* KM */
713 case 0xb93c: /* PPNO */
714 case 0xb990: /* TRTT */
715 case 0xb991: /* TRTO */
716 case 0xb992: /* TROT */
717 case 0xb993: /* TROO */
718 *len = 4;
719 return 1;
720 }
721
722 return 0;
723 }
724
725 /* Implement the "software_single_step" gdbarch method, needed to single step
726 through instructions like MVCLE in record mode, to make sure they are
727 executed to completion. Without that, record will save the full length
728 of destination buffer on every iteration, even though the CPU will only
729 process about 4kiB of it each time, leading to O(n**2) memory and time
730 complexity. */
731
732 static std::vector<CORE_ADDR>
733 s390_software_single_step (struct regcache *regcache)
734 {
735 struct gdbarch *gdbarch = regcache->arch ();
736 CORE_ADDR loc = regcache_read_pc (regcache);
737 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
738 int len;
739 uint16_t insn;
740
741 /* Special handling only if recording. */
742 if (!record_full_is_used ())
743 return {};
744
745 /* First, match a partial instruction. */
746 if (!s390_is_partial_instruction (gdbarch, loc, &len))
747 return {};
748
749 loc += len;
750
751 /* Second, look for a branch back to it. */
752 insn = read_memory_integer (loc, 2, byte_order);
753 if (insn != 0xa714) /* BRC with mask 1 */
754 return {};
755
756 insn = read_memory_integer (loc + 2, 2, byte_order);
757 if (insn != (uint16_t) -(len / 2))
758 return {};
759
760 loc += 4;
761
762 /* Found it, step past the whole thing. */
763 return {loc};
764 }
765
766 static int
767 s390_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
768 struct displaced_step_closure *closure)
769 {
770 return 1;
771 }
772
773
774 /* Maps for register sets. */
775
776 static const struct regcache_map_entry s390_gregmap[] =
777 {
778 { 1, S390_PSWM_REGNUM },
779 { 1, S390_PSWA_REGNUM },
780 { 16, S390_R0_REGNUM },
781 { 16, S390_A0_REGNUM },
782 { 1, S390_ORIG_R2_REGNUM },
783 { 0 }
784 };
785
786 static const struct regcache_map_entry s390_fpregmap[] =
787 {
788 { 1, S390_FPC_REGNUM, 8 },
789 { 16, S390_F0_REGNUM, 8 },
790 { 0 }
791 };
792
793 static const struct regcache_map_entry s390_regmap_upper[] =
794 {
795 { 16, S390_R0_UPPER_REGNUM, 4 },
796 { 0 }
797 };
798
799 static const struct regcache_map_entry s390_regmap_last_break[] =
800 {
801 { 1, REGCACHE_MAP_SKIP, 4 },
802 { 1, S390_LAST_BREAK_REGNUM, 4 },
803 { 0 }
804 };
805
806 static const struct regcache_map_entry s390x_regmap_last_break[] =
807 {
808 { 1, S390_LAST_BREAK_REGNUM, 8 },
809 { 0 }
810 };
811
812 static const struct regcache_map_entry s390_regmap_system_call[] =
813 {
814 { 1, S390_SYSTEM_CALL_REGNUM, 4 },
815 { 0 }
816 };
817
818 static const struct regcache_map_entry s390_regmap_tdb[] =
819 {
820 { 1, S390_TDB_DWORD0_REGNUM, 8 },
821 { 1, S390_TDB_ABORT_CODE_REGNUM, 8 },
822 { 1, S390_TDB_CONFLICT_TOKEN_REGNUM, 8 },
823 { 1, S390_TDB_ATIA_REGNUM, 8 },
824 { 12, REGCACHE_MAP_SKIP, 8 },
825 { 16, S390_TDB_R0_REGNUM, 8 },
826 { 0 }
827 };
828
829 static const struct regcache_map_entry s390_regmap_vxrs_low[] =
830 {
831 { 16, S390_V0_LOWER_REGNUM, 8 },
832 { 0 }
833 };
834
835 static const struct regcache_map_entry s390_regmap_vxrs_high[] =
836 {
837 { 16, S390_V16_REGNUM, 16 },
838 { 0 }
839 };
840
841 static const struct regcache_map_entry s390_regmap_gs[] =
842 {
843 { 1, REGCACHE_MAP_SKIP, 8 },
844 { 1, S390_GSD_REGNUM, 8 },
845 { 1, S390_GSSM_REGNUM, 8 },
846 { 1, S390_GSEPLA_REGNUM, 8 },
847 { 0 }
848 };
849
850 static const struct regcache_map_entry s390_regmap_gsbc[] =
851 {
852 { 1, REGCACHE_MAP_SKIP, 8 },
853 { 1, S390_BC_GSD_REGNUM, 8 },
854 { 1, S390_BC_GSSM_REGNUM, 8 },
855 { 1, S390_BC_GSEPLA_REGNUM, 8 },
856 { 0 }
857 };
858
859
860 /* Supply the TDB regset. Like regcache_supply_regset, but invalidate
861 the TDB registers unless the TDB format field is valid. */
862
863 static void
864 s390_supply_tdb_regset (const struct regset *regset, struct regcache *regcache,
865 int regnum, const void *regs, size_t len)
866 {
867 ULONGEST tdw;
868 enum register_status ret;
869
870 regcache_supply_regset (regset, regcache, regnum, regs, len);
871 ret = regcache_cooked_read_unsigned (regcache, S390_TDB_DWORD0_REGNUM, &tdw);
872 if (ret != REG_VALID || (tdw >> 56) != 1)
873 regcache_supply_regset (regset, regcache, regnum, NULL, len);
874 }
875
876 const struct regset s390_gregset = {
877 s390_gregmap,
878 regcache_supply_regset,
879 regcache_collect_regset
880 };
881
882 const struct regset s390_fpregset = {
883 s390_fpregmap,
884 regcache_supply_regset,
885 regcache_collect_regset
886 };
887
888 static const struct regset s390_upper_regset = {
889 s390_regmap_upper,
890 regcache_supply_regset,
891 regcache_collect_regset
892 };
893
894 const struct regset s390_last_break_regset = {
895 s390_regmap_last_break,
896 regcache_supply_regset,
897 regcache_collect_regset
898 };
899
900 const struct regset s390x_last_break_regset = {
901 s390x_regmap_last_break,
902 regcache_supply_regset,
903 regcache_collect_regset
904 };
905
906 const struct regset s390_system_call_regset = {
907 s390_regmap_system_call,
908 regcache_supply_regset,
909 regcache_collect_regset
910 };
911
912 const struct regset s390_tdb_regset = {
913 s390_regmap_tdb,
914 s390_supply_tdb_regset,
915 regcache_collect_regset
916 };
917
918 const struct regset s390_vxrs_low_regset = {
919 s390_regmap_vxrs_low,
920 regcache_supply_regset,
921 regcache_collect_regset
922 };
923
924 const struct regset s390_vxrs_high_regset = {
925 s390_regmap_vxrs_high,
926 regcache_supply_regset,
927 regcache_collect_regset
928 };
929
930 const struct regset s390_gs_regset = {
931 s390_regmap_gs,
932 regcache_supply_regset,
933 regcache_collect_regset
934 };
935
936 const struct regset s390_gsbc_regset = {
937 s390_regmap_gsbc,
938 regcache_supply_regset,
939 regcache_collect_regset
940 };
941
942 /* Iterate over supported core file register note sections. */
943
944 static void
945 s390_iterate_over_regset_sections (struct gdbarch *gdbarch,
946 iterate_over_regset_sections_cb *cb,
947 void *cb_data,
948 const struct regcache *regcache)
949 {
950 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
951 const int gregset_size = (tdep->abi == ABI_LINUX_S390 ?
952 s390_sizeof_gregset : s390x_sizeof_gregset);
953
954 cb (".reg", gregset_size, &s390_gregset, NULL, cb_data);
955 cb (".reg2", s390_sizeof_fpregset, &s390_fpregset, NULL, cb_data);
956
957 if (tdep->abi == ABI_LINUX_S390 && tdep->gpr_full_regnum != -1)
958 cb (".reg-s390-high-gprs", 16 * 4, &s390_upper_regset,
959 "s390 GPR upper halves", cb_data);
960
961 if (tdep->have_linux_v1)
962 cb (".reg-s390-last-break", 8,
963 (gdbarch_ptr_bit (gdbarch) == 32
964 ? &s390_last_break_regset : &s390x_last_break_regset),
965 "s390 last-break address", cb_data);
966
967 if (tdep->have_linux_v2)
968 cb (".reg-s390-system-call", 4, &s390_system_call_regset,
969 "s390 system-call", cb_data);
970
971 /* If regcache is set, we are in "write" (gcore) mode. In this
972 case, don't iterate over the TDB unless its registers are
973 available. */
974 if (tdep->have_tdb
975 && (regcache == NULL
976 || REG_VALID == regcache_register_status (regcache,
977 S390_TDB_DWORD0_REGNUM)))
978 cb (".reg-s390-tdb", s390_sizeof_tdbregset, &s390_tdb_regset,
979 "s390 TDB", cb_data);
980
981 if (tdep->v0_full_regnum != -1)
982 {
983 cb (".reg-s390-vxrs-low", 16 * 8, &s390_vxrs_low_regset,
984 "s390 vector registers 0-15 lower half", cb_data);
985 cb (".reg-s390-vxrs-high", 16 * 16, &s390_vxrs_high_regset,
986 "s390 vector registers 16-31", cb_data);
987 }
988
989 /* Iterate over the guarded-storage regsets if in "read" mode, or if
990 their registers are available. */
991 if (tdep->have_gs)
992 {
993 if (regcache == NULL
994 || REG_VALID == regcache_register_status (regcache,
995 S390_GSD_REGNUM))
996 cb (".reg-s390-gs-cb", 4 * 8, &s390_gs_regset,
997 "s390 guarded-storage registers", cb_data);
998
999 if (regcache == NULL
1000 || REG_VALID == regcache_register_status (regcache,
1001 S390_BC_GSD_REGNUM))
1002 cb (".reg-s390-gs-bc", 4 * 8, &s390_gsbc_regset,
1003 "s390 guarded-storage broadcast control", cb_data);
1004 }
1005 }
1006
1007 static const struct target_desc *
1008 s390_core_read_description (struct gdbarch *gdbarch,
1009 struct target_ops *target, bfd *abfd)
1010 {
1011 asection *section = bfd_get_section_by_name (abfd, ".reg");
1012 CORE_ADDR hwcap = 0;
1013 bool high_gprs, v1, v2, te, vx, gs;
1014
1015 target_auxv_search (target, AT_HWCAP, &hwcap);
1016 if (!section)
1017 return NULL;
1018
1019 high_gprs = (bfd_get_section_by_name (abfd, ".reg-s390-high-gprs")
1020 != NULL);
1021 v1 = (bfd_get_section_by_name (abfd, ".reg-s390-last-break") != NULL);
1022 v2 = (bfd_get_section_by_name (abfd, ".reg-s390-system-call") != NULL);
1023 vx = (hwcap & HWCAP_S390_VX);
1024 te = (hwcap & HWCAP_S390_TE);
1025 gs = (hwcap & HWCAP_S390_GS);
1026
1027 switch (bfd_section_size (abfd, section))
1028 {
1029 case s390_sizeof_gregset:
1030 if (high_gprs)
1031 return (gs ? tdesc_s390_gs_linux64 :
1032 te && vx ? tdesc_s390_tevx_linux64 :
1033 vx ? tdesc_s390_vx_linux64 :
1034 te ? tdesc_s390_te_linux64 :
1035 v2 ? tdesc_s390_linux64v2 :
1036 v1 ? tdesc_s390_linux64v1 : tdesc_s390_linux64);
1037 else
1038 return (v2 ? tdesc_s390_linux32v2 :
1039 v1 ? tdesc_s390_linux32v1 : tdesc_s390_linux32);
1040
1041 case s390x_sizeof_gregset:
1042 return (gs ? tdesc_s390x_gs_linux64 :
1043 te && vx ? tdesc_s390x_tevx_linux64 :
1044 vx ? tdesc_s390x_vx_linux64 :
1045 te ? tdesc_s390x_te_linux64 :
1046 v2 ? tdesc_s390x_linux64v2 :
1047 v1 ? tdesc_s390x_linux64v1 : tdesc_s390x_linux64);
1048
1049 default:
1050 return NULL;
1051 }
1052 }
1053
1054
1055 /* Decoding S/390 instructions. */
1056
1057 /* Named opcode values for the S/390 instructions we recognize. Some
1058 instructions have their opcode split across two fields; those are the
1059 op1_* and op2_* enums. */
1060 enum
1061 {
1062 op1_lhi = 0xa7, op2_lhi = 0x08,
1063 op1_lghi = 0xa7, op2_lghi = 0x09,
1064 op1_lgfi = 0xc0, op2_lgfi = 0x01,
1065 op_lr = 0x18,
1066 op_lgr = 0xb904,
1067 op_l = 0x58,
1068 op1_ly = 0xe3, op2_ly = 0x58,
1069 op1_lg = 0xe3, op2_lg = 0x04,
1070 op_lm = 0x98,
1071 op1_lmy = 0xeb, op2_lmy = 0x98,
1072 op1_lmg = 0xeb, op2_lmg = 0x04,
1073 op_st = 0x50,
1074 op1_sty = 0xe3, op2_sty = 0x50,
1075 op1_stg = 0xe3, op2_stg = 0x24,
1076 op_std = 0x60,
1077 op_stm = 0x90,
1078 op1_stmy = 0xeb, op2_stmy = 0x90,
1079 op1_stmg = 0xeb, op2_stmg = 0x24,
1080 op1_aghi = 0xa7, op2_aghi = 0x0b,
1081 op1_ahi = 0xa7, op2_ahi = 0x0a,
1082 op1_agfi = 0xc2, op2_agfi = 0x08,
1083 op1_afi = 0xc2, op2_afi = 0x09,
1084 op1_algfi= 0xc2, op2_algfi= 0x0a,
1085 op1_alfi = 0xc2, op2_alfi = 0x0b,
1086 op_ar = 0x1a,
1087 op_agr = 0xb908,
1088 op_a = 0x5a,
1089 op1_ay = 0xe3, op2_ay = 0x5a,
1090 op1_ag = 0xe3, op2_ag = 0x08,
1091 op1_slgfi= 0xc2, op2_slgfi= 0x04,
1092 op1_slfi = 0xc2, op2_slfi = 0x05,
1093 op_sr = 0x1b,
1094 op_sgr = 0xb909,
1095 op_s = 0x5b,
1096 op1_sy = 0xe3, op2_sy = 0x5b,
1097 op1_sg = 0xe3, op2_sg = 0x09,
1098 op_nr = 0x14,
1099 op_ngr = 0xb980,
1100 op_la = 0x41,
1101 op1_lay = 0xe3, op2_lay = 0x71,
1102 op1_larl = 0xc0, op2_larl = 0x00,
1103 op_basr = 0x0d,
1104 op_bas = 0x4d,
1105 op_bcr = 0x07,
1106 op_bc = 0x0d,
1107 op_bctr = 0x06,
1108 op_bctgr = 0xb946,
1109 op_bct = 0x46,
1110 op1_bctg = 0xe3, op2_bctg = 0x46,
1111 op_bxh = 0x86,
1112 op1_bxhg = 0xeb, op2_bxhg = 0x44,
1113 op_bxle = 0x87,
1114 op1_bxleg= 0xeb, op2_bxleg= 0x45,
1115 op1_bras = 0xa7, op2_bras = 0x05,
1116 op1_brasl= 0xc0, op2_brasl= 0x05,
1117 op1_brc = 0xa7, op2_brc = 0x04,
1118 op1_brcl = 0xc0, op2_brcl = 0x04,
1119 op1_brct = 0xa7, op2_brct = 0x06,
1120 op1_brctg= 0xa7, op2_brctg= 0x07,
1121 op_brxh = 0x84,
1122 op1_brxhg= 0xec, op2_brxhg= 0x44,
1123 op_brxle = 0x85,
1124 op1_brxlg= 0xec, op2_brxlg= 0x45,
1125 op_svc = 0x0a,
1126 };
1127
1128
1129 /* Read a single instruction from address AT. */
1130
1131 #define S390_MAX_INSTR_SIZE 6
1132 static int
1133 s390_readinstruction (bfd_byte instr[], CORE_ADDR at)
1134 {
1135 static int s390_instrlen[] = { 2, 4, 4, 6 };
1136 int instrlen;
1137
1138 if (target_read_memory (at, &instr[0], 2))
1139 return -1;
1140 instrlen = s390_instrlen[instr[0] >> 6];
1141 if (instrlen > 2)
1142 {
1143 if (target_read_memory (at + 2, &instr[2], instrlen - 2))
1144 return -1;
1145 }
1146 return instrlen;
1147 }
1148
1149
1150 /* The functions below are for recognizing and decoding S/390
1151 instructions of various formats. Each of them checks whether INSN
1152 is an instruction of the given format, with the specified opcodes.
1153 If it is, it sets the remaining arguments to the values of the
1154 instruction's fields, and returns a non-zero value; otherwise, it
1155 returns zero.
1156
1157 These functions' arguments appear in the order they appear in the
1158 instruction, not in the machine-language form. So, opcodes always
1159 come first, even though they're sometimes scattered around the
1160 instructions. And displacements appear before base and extension
1161 registers, as they do in the assembly syntax, not at the end, as
1162 they do in the machine language. */
1163 static int
1164 is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2)
1165 {
1166 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
1167 {
1168 *r1 = (insn[1] >> 4) & 0xf;
1169 /* i2 is a 16-bit signed quantity. */
1170 *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000;
1171 return 1;
1172 }
1173 else
1174 return 0;
1175 }
1176
1177
1178 static int
1179 is_ril (bfd_byte *insn, int op1, int op2,
1180 unsigned int *r1, int *i2)
1181 {
1182 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
1183 {
1184 *r1 = (insn[1] >> 4) & 0xf;
1185 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
1186 no sign extension is necessary, but we don't want to assume
1187 that. */
1188 *i2 = (((insn[2] << 24)
1189 | (insn[3] << 16)
1190 | (insn[4] << 8)
1191 | (insn[5])) ^ 0x80000000) - 0x80000000;
1192 return 1;
1193 }
1194 else
1195 return 0;
1196 }
1197
1198
1199 static int
1200 is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
1201 {
1202 if (insn[0] == op)
1203 {
1204 *r1 = (insn[1] >> 4) & 0xf;
1205 *r2 = insn[1] & 0xf;
1206 return 1;
1207 }
1208 else
1209 return 0;
1210 }
1211
1212
1213 static int
1214 is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
1215 {
1216 if (((insn[0] << 8) | insn[1]) == op)
1217 {
1218 /* Yes, insn[3]. insn[2] is unused in RRE format. */
1219 *r1 = (insn[3] >> 4) & 0xf;
1220 *r2 = insn[3] & 0xf;
1221 return 1;
1222 }
1223 else
1224 return 0;
1225 }
1226
1227
1228 static int
1229 is_rs (bfd_byte *insn, int op,
1230 unsigned int *r1, unsigned int *r3, int *d2, unsigned int *b2)
1231 {
1232 if (insn[0] == op)
1233 {
1234 *r1 = (insn[1] >> 4) & 0xf;
1235 *r3 = insn[1] & 0xf;
1236 *b2 = (insn[2] >> 4) & 0xf;
1237 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
1238 return 1;
1239 }
1240 else
1241 return 0;
1242 }
1243
1244
1245 static int
1246 is_rsy (bfd_byte *insn, int op1, int op2,
1247 unsigned int *r1, unsigned int *r3, int *d2, unsigned int *b2)
1248 {
1249 if (insn[0] == op1
1250 && insn[5] == op2)
1251 {
1252 *r1 = (insn[1] >> 4) & 0xf;
1253 *r3 = insn[1] & 0xf;
1254 *b2 = (insn[2] >> 4) & 0xf;
1255 /* The 'long displacement' is a 20-bit signed integer. */
1256 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
1257 ^ 0x80000) - 0x80000;
1258 return 1;
1259 }
1260 else
1261 return 0;
1262 }
1263
1264
1265 static int
1266 is_rx (bfd_byte *insn, int op,
1267 unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2)
1268 {
1269 if (insn[0] == op)
1270 {
1271 *r1 = (insn[1] >> 4) & 0xf;
1272 *x2 = insn[1] & 0xf;
1273 *b2 = (insn[2] >> 4) & 0xf;
1274 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
1275 return 1;
1276 }
1277 else
1278 return 0;
1279 }
1280
1281
1282 static int
1283 is_rxy (bfd_byte *insn, int op1, int op2,
1284 unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2)
1285 {
1286 if (insn[0] == op1
1287 && insn[5] == op2)
1288 {
1289 *r1 = (insn[1] >> 4) & 0xf;
1290 *x2 = insn[1] & 0xf;
1291 *b2 = (insn[2] >> 4) & 0xf;
1292 /* The 'long displacement' is a 20-bit signed integer. */
1293 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
1294 ^ 0x80000) - 0x80000;
1295 return 1;
1296 }
1297 else
1298 return 0;
1299 }
1300
1301
1302 /* Prologue analysis. */
1303
1304 #define S390_NUM_GPRS 16
1305 #define S390_NUM_FPRS 16
1306
1307 struct s390_prologue_data {
1308
1309 /* The stack. */
1310 struct pv_area *stack;
1311
1312 /* The size and byte-order of a GPR or FPR. */
1313 int gpr_size;
1314 int fpr_size;
1315 enum bfd_endian byte_order;
1316
1317 /* The general-purpose registers. */
1318 pv_t gpr[S390_NUM_GPRS];
1319
1320 /* The floating-point registers. */
1321 pv_t fpr[S390_NUM_FPRS];
1322
1323 /* The offset relative to the CFA where the incoming GPR N was saved
1324 by the function prologue. 0 if not saved or unknown. */
1325 int gpr_slot[S390_NUM_GPRS];
1326
1327 /* Likewise for FPRs. */
1328 int fpr_slot[S390_NUM_FPRS];
1329
1330 /* Nonzero if the backchain was saved. This is assumed to be the
1331 case when the incoming SP is saved at the current SP location. */
1332 int back_chain_saved_p;
1333 };
1334
1335 /* Return the effective address for an X-style instruction, like:
1336
1337 L R1, D2(X2, B2)
1338
1339 Here, X2 and B2 are registers, and D2 is a signed 20-bit
1340 constant; the effective address is the sum of all three. If either
1341 X2 or B2 are zero, then it doesn't contribute to the sum --- this
1342 means that r0 can't be used as either X2 or B2. */
1343 static pv_t
1344 s390_addr (struct s390_prologue_data *data,
1345 int d2, unsigned int x2, unsigned int b2)
1346 {
1347 pv_t result;
1348
1349 result = pv_constant (d2);
1350 if (x2)
1351 result = pv_add (result, data->gpr[x2]);
1352 if (b2)
1353 result = pv_add (result, data->gpr[b2]);
1354
1355 return result;
1356 }
1357
1358 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
1359 static void
1360 s390_store (struct s390_prologue_data *data,
1361 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size,
1362 pv_t value)
1363 {
1364 pv_t addr = s390_addr (data, d2, x2, b2);
1365 pv_t offset;
1366
1367 /* Check whether we are storing the backchain. */
1368 offset = pv_subtract (data->gpr[S390_SP_REGNUM - S390_R0_REGNUM], addr);
1369
1370 if (pv_is_constant (offset) && offset.k == 0)
1371 if (size == data->gpr_size
1372 && pv_is_register_k (value, S390_SP_REGNUM, 0))
1373 {
1374 data->back_chain_saved_p = 1;
1375 return;
1376 }
1377
1378
1379 /* Check whether we are storing a register into the stack. */
1380 if (!data->stack->store_would_trash (addr))
1381 data->stack->store (addr, size, value);
1382
1383
1384 /* Note: If this is some store we cannot identify, you might think we
1385 should forget our cached values, as any of those might have been hit.
1386
1387 However, we make the assumption that the register save areas are only
1388 ever stored to once in any given function, and we do recognize these
1389 stores. Thus every store we cannot recognize does not hit our data. */
1390 }
1391
1392 /* Do a SIZE-byte load from D2(X2,B2). */
1393 static pv_t
1394 s390_load (struct s390_prologue_data *data,
1395 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size)
1396
1397 {
1398 pv_t addr = s390_addr (data, d2, x2, b2);
1399
1400 /* If it's a load from an in-line constant pool, then we can
1401 simulate that, under the assumption that the code isn't
1402 going to change between the time the processor actually
1403 executed it creating the current frame, and the time when
1404 we're analyzing the code to unwind past that frame. */
1405 if (pv_is_constant (addr))
1406 {
1407 struct target_section *secp;
1408 secp = target_section_by_addr (&current_target, addr.k);
1409 if (secp != NULL
1410 && (bfd_get_section_flags (secp->the_bfd_section->owner,
1411 secp->the_bfd_section)
1412 & SEC_READONLY))
1413 return pv_constant (read_memory_integer (addr.k, size,
1414 data->byte_order));
1415 }
1416
1417 /* Check whether we are accessing one of our save slots. */
1418 return data->stack->fetch (addr, size);
1419 }
1420
1421 /* Function for finding saved registers in a 'struct pv_area'; we pass
1422 this to pv_area::scan.
1423
1424 If VALUE is a saved register, ADDR says it was saved at a constant
1425 offset from the frame base, and SIZE indicates that the whole
1426 register was saved, record its offset in the reg_offset table in
1427 PROLOGUE_UNTYPED. */
1428 static void
1429 s390_check_for_saved (void *data_untyped, pv_t addr,
1430 CORE_ADDR size, pv_t value)
1431 {
1432 struct s390_prologue_data *data = (struct s390_prologue_data *) data_untyped;
1433 int i, offset;
1434
1435 if (!pv_is_register (addr, S390_SP_REGNUM))
1436 return;
1437
1438 offset = 16 * data->gpr_size + 32 - addr.k;
1439
1440 /* If we are storing the original value of a register, we want to
1441 record the CFA offset. If the same register is stored multiple
1442 times, the stack slot with the highest address counts. */
1443
1444 for (i = 0; i < S390_NUM_GPRS; i++)
1445 if (size == data->gpr_size
1446 && pv_is_register_k (value, S390_R0_REGNUM + i, 0))
1447 if (data->gpr_slot[i] == 0
1448 || data->gpr_slot[i] > offset)
1449 {
1450 data->gpr_slot[i] = offset;
1451 return;
1452 }
1453
1454 for (i = 0; i < S390_NUM_FPRS; i++)
1455 if (size == data->fpr_size
1456 && pv_is_register_k (value, S390_F0_REGNUM + i, 0))
1457 if (data->fpr_slot[i] == 0
1458 || data->fpr_slot[i] > offset)
1459 {
1460 data->fpr_slot[i] = offset;
1461 return;
1462 }
1463 }
1464
1465 /* Analyze the prologue of the function starting at START_PC,
1466 continuing at most until CURRENT_PC. Initialize DATA to
1467 hold all information we find out about the state of the registers
1468 and stack slots. Return the address of the instruction after
1469 the last one that changed the SP, FP, or back chain; or zero
1470 on error. */
1471 static CORE_ADDR
1472 s390_analyze_prologue (struct gdbarch *gdbarch,
1473 CORE_ADDR start_pc,
1474 CORE_ADDR current_pc,
1475 struct s390_prologue_data *data)
1476 {
1477 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1478
1479 /* Our return value:
1480 The address of the instruction after the last one that changed
1481 the SP, FP, or back chain; zero if we got an error trying to
1482 read memory. */
1483 CORE_ADDR result = start_pc;
1484
1485 /* The current PC for our abstract interpretation. */
1486 CORE_ADDR pc;
1487
1488 /* The address of the next instruction after that. */
1489 CORE_ADDR next_pc;
1490
1491 pv_area stack (S390_SP_REGNUM, gdbarch_addr_bit (gdbarch));
1492 scoped_restore restore_stack = make_scoped_restore (&data->stack, &stack);
1493
1494 /* Set up everything's initial value. */
1495 {
1496 int i;
1497
1498 /* For the purpose of prologue tracking, we consider the GPR size to
1499 be equal to the ABI word size, even if it is actually larger
1500 (i.e. when running a 32-bit binary under a 64-bit kernel). */
1501 data->gpr_size = word_size;
1502 data->fpr_size = 8;
1503 data->byte_order = gdbarch_byte_order (gdbarch);
1504
1505 for (i = 0; i < S390_NUM_GPRS; i++)
1506 data->gpr[i] = pv_register (S390_R0_REGNUM + i, 0);
1507
1508 for (i = 0; i < S390_NUM_FPRS; i++)
1509 data->fpr[i] = pv_register (S390_F0_REGNUM + i, 0);
1510
1511 for (i = 0; i < S390_NUM_GPRS; i++)
1512 data->gpr_slot[i] = 0;
1513
1514 for (i = 0; i < S390_NUM_FPRS; i++)
1515 data->fpr_slot[i] = 0;
1516
1517 data->back_chain_saved_p = 0;
1518 }
1519
1520 /* Start interpreting instructions, until we hit the frame's
1521 current PC or the first branch instruction. */
1522 for (pc = start_pc; pc > 0 && pc < current_pc; pc = next_pc)
1523 {
1524 bfd_byte insn[S390_MAX_INSTR_SIZE];
1525 int insn_len = s390_readinstruction (insn, pc);
1526
1527 bfd_byte dummy[S390_MAX_INSTR_SIZE] = { 0 };
1528 bfd_byte *insn32 = word_size == 4 ? insn : dummy;
1529 bfd_byte *insn64 = word_size == 8 ? insn : dummy;
1530
1531 /* Fields for various kinds of instructions. */
1532 unsigned int b2, r1, r2, x2, r3;
1533 int i2, d2;
1534
1535 /* The values of SP and FP before this instruction,
1536 for detecting instructions that change them. */
1537 pv_t pre_insn_sp, pre_insn_fp;
1538 /* Likewise for the flag whether the back chain was saved. */
1539 int pre_insn_back_chain_saved_p;
1540
1541 /* If we got an error trying to read the instruction, report it. */
1542 if (insn_len < 0)
1543 {
1544 result = 0;
1545 break;
1546 }
1547
1548 next_pc = pc + insn_len;
1549
1550 pre_insn_sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1551 pre_insn_fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1552 pre_insn_back_chain_saved_p = data->back_chain_saved_p;
1553
1554
1555 /* LHI r1, i2 --- load halfword immediate. */
1556 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
1557 /* LGFI r1, i2 --- load fullword immediate. */
1558 if (is_ri (insn32, op1_lhi, op2_lhi, &r1, &i2)
1559 || is_ri (insn64, op1_lghi, op2_lghi, &r1, &i2)
1560 || is_ril (insn, op1_lgfi, op2_lgfi, &r1, &i2))
1561 data->gpr[r1] = pv_constant (i2);
1562
1563 /* LR r1, r2 --- load from register. */
1564 /* LGR r1, r2 --- load from register (64-bit version). */
1565 else if (is_rr (insn32, op_lr, &r1, &r2)
1566 || is_rre (insn64, op_lgr, &r1, &r2))
1567 data->gpr[r1] = data->gpr[r2];
1568
1569 /* L r1, d2(x2, b2) --- load. */
1570 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
1571 /* LG r1, d2(x2, b2) --- load (64-bit version). */
1572 else if (is_rx (insn32, op_l, &r1, &d2, &x2, &b2)
1573 || is_rxy (insn32, op1_ly, op2_ly, &r1, &d2, &x2, &b2)
1574 || is_rxy (insn64, op1_lg, op2_lg, &r1, &d2, &x2, &b2))
1575 data->gpr[r1] = s390_load (data, d2, x2, b2, data->gpr_size);
1576
1577 /* ST r1, d2(x2, b2) --- store. */
1578 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
1579 /* STG r1, d2(x2, b2) --- store (64-bit version). */
1580 else if (is_rx (insn32, op_st, &r1, &d2, &x2, &b2)
1581 || is_rxy (insn32, op1_sty, op2_sty, &r1, &d2, &x2, &b2)
1582 || is_rxy (insn64, op1_stg, op2_stg, &r1, &d2, &x2, &b2))
1583 s390_store (data, d2, x2, b2, data->gpr_size, data->gpr[r1]);
1584
1585 /* STD r1, d2(x2,b2) --- store floating-point register. */
1586 else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2))
1587 s390_store (data, d2, x2, b2, data->fpr_size, data->fpr[r1]);
1588
1589 /* STM r1, r3, d2(b2) --- store multiple. */
1590 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement
1591 version). */
1592 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
1593 else if (is_rs (insn32, op_stm, &r1, &r3, &d2, &b2)
1594 || is_rsy (insn32, op1_stmy, op2_stmy, &r1, &r3, &d2, &b2)
1595 || is_rsy (insn64, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2))
1596 {
1597 for (; r1 <= r3; r1++, d2 += data->gpr_size)
1598 s390_store (data, d2, 0, b2, data->gpr_size, data->gpr[r1]);
1599 }
1600
1601 /* AHI r1, i2 --- add halfword immediate. */
1602 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
1603 /* AFI r1, i2 --- add fullword immediate. */
1604 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
1605 else if (is_ri (insn32, op1_ahi, op2_ahi, &r1, &i2)
1606 || is_ri (insn64, op1_aghi, op2_aghi, &r1, &i2)
1607 || is_ril (insn32, op1_afi, op2_afi, &r1, &i2)
1608 || is_ril (insn64, op1_agfi, op2_agfi, &r1, &i2))
1609 data->gpr[r1] = pv_add_constant (data->gpr[r1], i2);
1610
1611 /* ALFI r1, i2 --- add logical immediate. */
1612 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
1613 else if (is_ril (insn32, op1_alfi, op2_alfi, &r1, &i2)
1614 || is_ril (insn64, op1_algfi, op2_algfi, &r1, &i2))
1615 data->gpr[r1] = pv_add_constant (data->gpr[r1],
1616 (CORE_ADDR)i2 & 0xffffffff);
1617
1618 /* AR r1, r2 -- add register. */
1619 /* AGR r1, r2 -- add register (64-bit version). */
1620 else if (is_rr (insn32, op_ar, &r1, &r2)
1621 || is_rre (insn64, op_agr, &r1, &r2))
1622 data->gpr[r1] = pv_add (data->gpr[r1], data->gpr[r2]);
1623
1624 /* A r1, d2(x2, b2) -- add. */
1625 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
1626 /* AG r1, d2(x2, b2) -- add (64-bit version). */
1627 else if (is_rx (insn32, op_a, &r1, &d2, &x2, &b2)
1628 || is_rxy (insn32, op1_ay, op2_ay, &r1, &d2, &x2, &b2)
1629 || is_rxy (insn64, op1_ag, op2_ag, &r1, &d2, &x2, &b2))
1630 data->gpr[r1] = pv_add (data->gpr[r1],
1631 s390_load (data, d2, x2, b2, data->gpr_size));
1632
1633 /* SLFI r1, i2 --- subtract logical immediate. */
1634 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
1635 else if (is_ril (insn32, op1_slfi, op2_slfi, &r1, &i2)
1636 || is_ril (insn64, op1_slgfi, op2_slgfi, &r1, &i2))
1637 data->gpr[r1] = pv_add_constant (data->gpr[r1],
1638 -((CORE_ADDR)i2 & 0xffffffff));
1639
1640 /* SR r1, r2 -- subtract register. */
1641 /* SGR r1, r2 -- subtract register (64-bit version). */
1642 else if (is_rr (insn32, op_sr, &r1, &r2)
1643 || is_rre (insn64, op_sgr, &r1, &r2))
1644 data->gpr[r1] = pv_subtract (data->gpr[r1], data->gpr[r2]);
1645
1646 /* S r1, d2(x2, b2) -- subtract. */
1647 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
1648 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
1649 else if (is_rx (insn32, op_s, &r1, &d2, &x2, &b2)
1650 || is_rxy (insn32, op1_sy, op2_sy, &r1, &d2, &x2, &b2)
1651 || is_rxy (insn64, op1_sg, op2_sg, &r1, &d2, &x2, &b2))
1652 data->gpr[r1] = pv_subtract (data->gpr[r1],
1653 s390_load (data, d2, x2, b2, data->gpr_size));
1654
1655 /* LA r1, d2(x2, b2) --- load address. */
1656 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
1657 else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2)
1658 || is_rxy (insn, op1_lay, op2_lay, &r1, &d2, &x2, &b2))
1659 data->gpr[r1] = s390_addr (data, d2, x2, b2);
1660
1661 /* LARL r1, i2 --- load address relative long. */
1662 else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2))
1663 data->gpr[r1] = pv_constant (pc + i2 * 2);
1664
1665 /* BASR r1, 0 --- branch and save.
1666 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1667 else if (is_rr (insn, op_basr, &r1, &r2)
1668 && r2 == 0)
1669 data->gpr[r1] = pv_constant (next_pc);
1670
1671 /* BRAS r1, i2 --- branch relative and save. */
1672 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2))
1673 {
1674 data->gpr[r1] = pv_constant (next_pc);
1675 next_pc = pc + i2 * 2;
1676
1677 /* We'd better not interpret any backward branches. We'll
1678 never terminate. */
1679 if (next_pc <= pc)
1680 break;
1681 }
1682
1683 /* BRC/BRCL -- branch relative on condition. Ignore "branch
1684 never", branch to following instruction, and "conditional
1685 trap" (BRC +2). Otherwise terminate search. */
1686 else if (is_ri (insn, op1_brc, op2_brc, &r1, &i2))
1687 {
1688 if (r1 != 0 && i2 != 1 && i2 != 2)
1689 break;
1690 }
1691 else if (is_ril (insn, op1_brcl, op2_brcl, &r1, &i2))
1692 {
1693 if (r1 != 0 && i2 != 3)
1694 break;
1695 }
1696
1697 /* Terminate search when hitting any other branch instruction. */
1698 else if (is_rr (insn, op_basr, &r1, &r2)
1699 || is_rx (insn, op_bas, &r1, &d2, &x2, &b2)
1700 || is_rr (insn, op_bcr, &r1, &r2)
1701 || is_rx (insn, op_bc, &r1, &d2, &x2, &b2)
1702 || is_ril (insn, op1_brasl, op2_brasl, &r2, &i2))
1703 break;
1704
1705 else
1706 {
1707 /* An instruction we don't know how to simulate. The only
1708 safe thing to do would be to set every value we're tracking
1709 to 'unknown'. Instead, we'll be optimistic: we assume that
1710 we *can* interpret every instruction that the compiler uses
1711 to manipulate any of the data we're interested in here --
1712 then we can just ignore anything else. */
1713 }
1714
1715 /* Record the address after the last instruction that changed
1716 the FP, SP, or backlink. Ignore instructions that changed
1717 them back to their original values --- those are probably
1718 restore instructions. (The back chain is never restored,
1719 just popped.) */
1720 {
1721 pv_t sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1722 pv_t fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1723
1724 if ((! pv_is_identical (pre_insn_sp, sp)
1725 && ! pv_is_register_k (sp, S390_SP_REGNUM, 0)
1726 && sp.kind != pvk_unknown)
1727 || (! pv_is_identical (pre_insn_fp, fp)
1728 && ! pv_is_register_k (fp, S390_FRAME_REGNUM, 0)
1729 && fp.kind != pvk_unknown)
1730 || pre_insn_back_chain_saved_p != data->back_chain_saved_p)
1731 result = next_pc;
1732 }
1733 }
1734
1735 /* Record where all the registers were saved. */
1736 data->stack->scan (s390_check_for_saved, data);
1737
1738 return result;
1739 }
1740
1741 /* Advance PC across any function entry prologue instructions to reach
1742 some "real" code. */
1743 static CORE_ADDR
1744 s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1745 {
1746 struct s390_prologue_data data;
1747 CORE_ADDR skip_pc, func_addr;
1748
1749 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
1750 {
1751 CORE_ADDR post_prologue_pc
1752 = skip_prologue_using_sal (gdbarch, func_addr);
1753 if (post_prologue_pc != 0)
1754 return std::max (pc, post_prologue_pc);
1755 }
1756
1757 skip_pc = s390_analyze_prologue (gdbarch, pc, (CORE_ADDR)-1, &data);
1758 return skip_pc ? skip_pc : pc;
1759 }
1760
1761 /* Implmement the stack_frame_destroyed_p gdbarch method. */
1762 static int
1763 s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
1764 {
1765 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1766
1767 /* In frameless functions, there's not frame to destroy and thus
1768 we don't care about the epilogue.
1769
1770 In functions with frame, the epilogue sequence is a pair of
1771 a LM-type instruction that restores (amongst others) the
1772 return register %r14 and the stack pointer %r15, followed
1773 by a branch 'br %r14' --or equivalent-- that effects the
1774 actual return.
1775
1776 In that situation, this function needs to return 'true' in
1777 exactly one case: when pc points to that branch instruction.
1778
1779 Thus we try to disassemble the one instructions immediately
1780 preceding pc and check whether it is an LM-type instruction
1781 modifying the stack pointer.
1782
1783 Note that disassembling backwards is not reliable, so there
1784 is a slight chance of false positives here ... */
1785
1786 bfd_byte insn[6];
1787 unsigned int r1, r3, b2;
1788 int d2;
1789
1790 if (word_size == 4
1791 && !target_read_memory (pc - 4, insn, 4)
1792 && is_rs (insn, op_lm, &r1, &r3, &d2, &b2)
1793 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1794 return 1;
1795
1796 if (word_size == 4
1797 && !target_read_memory (pc - 6, insn, 6)
1798 && is_rsy (insn, op1_lmy, op2_lmy, &r1, &r3, &d2, &b2)
1799 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1800 return 1;
1801
1802 if (word_size == 8
1803 && !target_read_memory (pc - 6, insn, 6)
1804 && is_rsy (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2)
1805 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1806 return 1;
1807
1808 return 0;
1809 }
1810
1811 /* Displaced stepping. */
1812
1813 /* Return true if INSN is a non-branch RIL-b or RIL-c format
1814 instruction. */
1815
1816 static int
1817 is_non_branch_ril (gdb_byte *insn)
1818 {
1819 gdb_byte op1 = insn[0];
1820
1821 if (op1 == 0xc4)
1822 {
1823 gdb_byte op2 = insn[1] & 0x0f;
1824
1825 switch (op2)
1826 {
1827 case 0x02: /* llhrl */
1828 case 0x04: /* lghrl */
1829 case 0x05: /* lhrl */
1830 case 0x06: /* llghrl */
1831 case 0x07: /* sthrl */
1832 case 0x08: /* lgrl */
1833 case 0x0b: /* stgrl */
1834 case 0x0c: /* lgfrl */
1835 case 0x0d: /* lrl */
1836 case 0x0e: /* llgfrl */
1837 case 0x0f: /* strl */
1838 return 1;
1839 }
1840 }
1841 else if (op1 == 0xc6)
1842 {
1843 gdb_byte op2 = insn[1] & 0x0f;
1844
1845 switch (op2)
1846 {
1847 case 0x00: /* exrl */
1848 case 0x02: /* pfdrl */
1849 case 0x04: /* cghrl */
1850 case 0x05: /* chrl */
1851 case 0x06: /* clghrl */
1852 case 0x07: /* clhrl */
1853 case 0x08: /* cgrl */
1854 case 0x0a: /* clgrl */
1855 case 0x0c: /* cgfrl */
1856 case 0x0d: /* crl */
1857 case 0x0e: /* clgfrl */
1858 case 0x0f: /* clrl */
1859 return 1;
1860 }
1861 }
1862
1863 return 0;
1864 }
1865
1866 typedef buf_displaced_step_closure s390_displaced_step_closure;
1867
1868 /* Implementation of gdbarch_displaced_step_copy_insn. */
1869
1870 static struct displaced_step_closure *
1871 s390_displaced_step_copy_insn (struct gdbarch *gdbarch,
1872 CORE_ADDR from, CORE_ADDR to,
1873 struct regcache *regs)
1874 {
1875 size_t len = gdbarch_max_insn_length (gdbarch);
1876 std::unique_ptr<s390_displaced_step_closure> closure
1877 (new s390_displaced_step_closure (len));
1878 gdb_byte *buf = closure->buf.data ();
1879
1880 read_memory (from, buf, len);
1881
1882 /* Adjust the displacement field of PC-relative RIL instructions,
1883 except branches. The latter are handled in the fixup hook. */
1884 if (is_non_branch_ril (buf))
1885 {
1886 LONGEST offset;
1887
1888 offset = extract_signed_integer (buf + 2, 4, BFD_ENDIAN_BIG);
1889 offset = (from - to + offset * 2) / 2;
1890
1891 /* If the instruction is too far from the jump pad, punt. This
1892 will usually happen with instructions in shared libraries.
1893 We could probably support these by rewriting them to be
1894 absolute or fully emulating them. */
1895 if (offset < INT32_MIN || offset > INT32_MAX)
1896 {
1897 /* Let the core fall back to stepping over the breakpoint
1898 in-line. */
1899 if (debug_displaced)
1900 {
1901 fprintf_unfiltered (gdb_stdlog,
1902 "displaced: can't displaced step "
1903 "RIL instruction: offset %s out of range\n",
1904 plongest (offset));
1905 }
1906
1907 return NULL;
1908 }
1909
1910 store_signed_integer (buf + 2, 4, BFD_ENDIAN_BIG, offset);
1911 }
1912
1913 write_memory (to, buf, len);
1914
1915 if (debug_displaced)
1916 {
1917 fprintf_unfiltered (gdb_stdlog, "displaced: copy %s->%s: ",
1918 paddress (gdbarch, from), paddress (gdbarch, to));
1919 displaced_step_dump_bytes (gdb_stdlog, buf, len);
1920 }
1921
1922 return closure.release ();
1923 }
1924
1925 /* Fix up the state of registers and memory after having single-stepped
1926 a displaced instruction. */
1927 static void
1928 s390_displaced_step_fixup (struct gdbarch *gdbarch,
1929 struct displaced_step_closure *closure_,
1930 CORE_ADDR from, CORE_ADDR to,
1931 struct regcache *regs)
1932 {
1933 /* Our closure is a copy of the instruction. */
1934 s390_displaced_step_closure *closure
1935 = (s390_displaced_step_closure *) closure_;
1936 gdb_byte *insn = closure->buf.data ();
1937 static int s390_instrlen[] = { 2, 4, 4, 6 };
1938 int insnlen = s390_instrlen[insn[0] >> 6];
1939
1940 /* Fields for various kinds of instructions. */
1941 unsigned int b2, r1, r2, x2, r3;
1942 int i2, d2;
1943
1944 /* Get current PC and addressing mode bit. */
1945 CORE_ADDR pc = regcache_read_pc (regs);
1946 ULONGEST amode = 0;
1947
1948 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1949 {
1950 regcache_cooked_read_unsigned (regs, S390_PSWA_REGNUM, &amode);
1951 amode &= 0x80000000;
1952 }
1953
1954 if (debug_displaced)
1955 fprintf_unfiltered (gdb_stdlog,
1956 "displaced: (s390) fixup (%s, %s) pc %s len %d amode 0x%x\n",
1957 paddress (gdbarch, from), paddress (gdbarch, to),
1958 paddress (gdbarch, pc), insnlen, (int) amode);
1959
1960 /* Handle absolute branch and save instructions. */
1961 if (is_rr (insn, op_basr, &r1, &r2)
1962 || is_rx (insn, op_bas, &r1, &d2, &x2, &b2))
1963 {
1964 /* Recompute saved return address in R1. */
1965 regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
1966 amode | (from + insnlen));
1967 }
1968
1969 /* Handle absolute branch instructions. */
1970 else if (is_rr (insn, op_bcr, &r1, &r2)
1971 || is_rx (insn, op_bc, &r1, &d2, &x2, &b2)
1972 || is_rr (insn, op_bctr, &r1, &r2)
1973 || is_rre (insn, op_bctgr, &r1, &r2)
1974 || is_rx (insn, op_bct, &r1, &d2, &x2, &b2)
1975 || is_rxy (insn, op1_bctg, op2_brctg, &r1, &d2, &x2, &b2)
1976 || is_rs (insn, op_bxh, &r1, &r3, &d2, &b2)
1977 || is_rsy (insn, op1_bxhg, op2_bxhg, &r1, &r3, &d2, &b2)
1978 || is_rs (insn, op_bxle, &r1, &r3, &d2, &b2)
1979 || is_rsy (insn, op1_bxleg, op2_bxleg, &r1, &r3, &d2, &b2))
1980 {
1981 /* Update PC iff branch was *not* taken. */
1982 if (pc == to + insnlen)
1983 regcache_write_pc (regs, from + insnlen);
1984 }
1985
1986 /* Handle PC-relative branch and save instructions. */
1987 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2)
1988 || is_ril (insn, op1_brasl, op2_brasl, &r1, &i2))
1989 {
1990 /* Update PC. */
1991 regcache_write_pc (regs, pc - to + from);
1992 /* Recompute saved return address in R1. */
1993 regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
1994 amode | (from + insnlen));
1995 }
1996
1997 /* Handle LOAD ADDRESS RELATIVE LONG. */
1998 else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2))
1999 {
2000 /* Update PC. */
2001 regcache_write_pc (regs, from + insnlen);
2002 /* Recompute output address in R1. */
2003 regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
2004 amode | (from + i2 * 2));
2005 }
2006
2007 /* If we executed a breakpoint instruction, point PC right back at it. */
2008 else if (insn[0] == 0x0 && insn[1] == 0x1)
2009 regcache_write_pc (regs, from);
2010
2011 /* For any other insn, adjust PC by negated displacement. PC then
2012 points right after the original instruction, except for PC-relative
2013 branches, where it points to the adjusted branch target. */
2014 else
2015 regcache_write_pc (regs, pc - to + from);
2016
2017 if (debug_displaced)
2018 fprintf_unfiltered (gdb_stdlog,
2019 "displaced: (s390) pc is now %s\n",
2020 paddress (gdbarch, regcache_read_pc (regs)));
2021 }
2022
2023
2024 /* Helper routine to unwind pseudo registers. */
2025
2026 static struct value *
2027 s390_unwind_pseudo_register (struct frame_info *this_frame, int regnum)
2028 {
2029 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2030 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2031 struct type *type = register_type (gdbarch, regnum);
2032
2033 /* Unwind PC via PSW address. */
2034 if (regnum == tdep->pc_regnum)
2035 {
2036 struct value *val;
2037
2038 val = frame_unwind_register_value (this_frame, S390_PSWA_REGNUM);
2039 if (!value_optimized_out (val))
2040 {
2041 LONGEST pswa = value_as_long (val);
2042
2043 if (TYPE_LENGTH (type) == 4)
2044 return value_from_pointer (type, pswa & 0x7fffffff);
2045 else
2046 return value_from_pointer (type, pswa);
2047 }
2048 }
2049
2050 /* Unwind CC via PSW mask. */
2051 if (regnum == tdep->cc_regnum)
2052 {
2053 struct value *val;
2054
2055 val = frame_unwind_register_value (this_frame, S390_PSWM_REGNUM);
2056 if (!value_optimized_out (val))
2057 {
2058 LONGEST pswm = value_as_long (val);
2059
2060 if (TYPE_LENGTH (type) == 4)
2061 return value_from_longest (type, (pswm >> 12) & 3);
2062 else
2063 return value_from_longest (type, (pswm >> 44) & 3);
2064 }
2065 }
2066
2067 /* Unwind full GPRs to show at least the lower halves (as the
2068 upper halves are undefined). */
2069 if (regnum_is_gpr_full (tdep, regnum))
2070 {
2071 int reg = regnum - tdep->gpr_full_regnum;
2072 struct value *val;
2073
2074 val = frame_unwind_register_value (this_frame, S390_R0_REGNUM + reg);
2075 if (!value_optimized_out (val))
2076 return value_cast (type, val);
2077 }
2078
2079 return allocate_optimized_out_value (type);
2080 }
2081
2082 static struct value *
2083 s390_trad_frame_prev_register (struct frame_info *this_frame,
2084 struct trad_frame_saved_reg saved_regs[],
2085 int regnum)
2086 {
2087 if (regnum < S390_NUM_REGS)
2088 return trad_frame_get_prev_register (this_frame, saved_regs, regnum);
2089 else
2090 return s390_unwind_pseudo_register (this_frame, regnum);
2091 }
2092
2093
2094 /* Normal stack frames. */
2095
2096 struct s390_unwind_cache {
2097
2098 CORE_ADDR func;
2099 CORE_ADDR frame_base;
2100 CORE_ADDR local_base;
2101
2102 struct trad_frame_saved_reg *saved_regs;
2103 };
2104
2105 static int
2106 s390_prologue_frame_unwind_cache (struct frame_info *this_frame,
2107 struct s390_unwind_cache *info)
2108 {
2109 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2110 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2111 struct s390_prologue_data data;
2112 pv_t *fp = &data.gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
2113 pv_t *sp = &data.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
2114 int i;
2115 CORE_ADDR cfa;
2116 CORE_ADDR func;
2117 CORE_ADDR result;
2118 ULONGEST reg;
2119 CORE_ADDR prev_sp;
2120 int frame_pointer;
2121 int size;
2122 struct frame_info *next_frame;
2123
2124 /* Try to find the function start address. If we can't find it, we don't
2125 bother searching for it -- with modern compilers this would be mostly
2126 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
2127 or else a valid backchain ... */
2128 if (!get_frame_func_if_available (this_frame, &info->func))
2129 {
2130 info->func = -1;
2131 return 0;
2132 }
2133 func = info->func;
2134
2135 /* Try to analyze the prologue. */
2136 result = s390_analyze_prologue (gdbarch, func,
2137 get_frame_pc (this_frame), &data);
2138 if (!result)
2139 return 0;
2140
2141 /* If this was successful, we should have found the instruction that
2142 sets the stack pointer register to the previous value of the stack
2143 pointer minus the frame size. */
2144 if (!pv_is_register (*sp, S390_SP_REGNUM))
2145 return 0;
2146
2147 /* A frame size of zero at this point can mean either a real
2148 frameless function, or else a failure to find the prologue.
2149 Perform some sanity checks to verify we really have a
2150 frameless function. */
2151 if (sp->k == 0)
2152 {
2153 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
2154 size zero. This is only possible if the next frame is a sentinel
2155 frame, a dummy frame, or a signal trampoline frame. */
2156 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
2157 needed, instead the code should simpliy rely on its
2158 analysis. */
2159 next_frame = get_next_frame (this_frame);
2160 while (next_frame && get_frame_type (next_frame) == INLINE_FRAME)
2161 next_frame = get_next_frame (next_frame);
2162 if (next_frame
2163 && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME)
2164 return 0;
2165
2166 /* If we really have a frameless function, %r14 must be valid
2167 -- in particular, it must point to a different function. */
2168 reg = get_frame_register_unsigned (this_frame, S390_RETADDR_REGNUM);
2169 reg = gdbarch_addr_bits_remove (gdbarch, reg) - 1;
2170 if (get_pc_function_start (reg) == func)
2171 {
2172 /* However, there is one case where it *is* valid for %r14
2173 to point to the same function -- if this is a recursive
2174 call, and we have stopped in the prologue *before* the
2175 stack frame was allocated.
2176
2177 Recognize this case by looking ahead a bit ... */
2178
2179 struct s390_prologue_data data2;
2180 pv_t *sp = &data2.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
2181
2182 if (!(s390_analyze_prologue (gdbarch, func, (CORE_ADDR)-1, &data2)
2183 && pv_is_register (*sp, S390_SP_REGNUM)
2184 && sp->k != 0))
2185 return 0;
2186 }
2187 }
2188
2189
2190 /* OK, we've found valid prologue data. */
2191 size = -sp->k;
2192
2193 /* If the frame pointer originally also holds the same value
2194 as the stack pointer, we're probably using it. If it holds
2195 some other value -- even a constant offset -- it is most
2196 likely used as temp register. */
2197 if (pv_is_identical (*sp, *fp))
2198 frame_pointer = S390_FRAME_REGNUM;
2199 else
2200 frame_pointer = S390_SP_REGNUM;
2201
2202 /* If we've detected a function with stack frame, we'll still have to
2203 treat it as frameless if we're currently within the function epilog
2204 code at a point where the frame pointer has already been restored.
2205 This can only happen in an innermost frame. */
2206 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
2207 instead the code should simpliy rely on its analysis. */
2208 next_frame = get_next_frame (this_frame);
2209 while (next_frame && get_frame_type (next_frame) == INLINE_FRAME)
2210 next_frame = get_next_frame (next_frame);
2211 if (size > 0
2212 && (next_frame == NULL
2213 || get_frame_type (get_next_frame (this_frame)) != NORMAL_FRAME))
2214 {
2215 /* See the comment in s390_stack_frame_destroyed_p on why this is
2216 not completely reliable ... */
2217 if (s390_stack_frame_destroyed_p (gdbarch, get_frame_pc (this_frame)))
2218 {
2219 memset (&data, 0, sizeof (data));
2220 size = 0;
2221 frame_pointer = S390_SP_REGNUM;
2222 }
2223 }
2224
2225 /* Once we know the frame register and the frame size, we can unwind
2226 the current value of the frame register from the next frame, and
2227 add back the frame size to arrive that the previous frame's
2228 stack pointer value. */
2229 prev_sp = get_frame_register_unsigned (this_frame, frame_pointer) + size;
2230 cfa = prev_sp + 16*word_size + 32;
2231
2232 /* Set up ABI call-saved/call-clobbered registers. */
2233 for (i = 0; i < S390_NUM_REGS; i++)
2234 if (!s390_register_call_saved (gdbarch, i))
2235 trad_frame_set_unknown (info->saved_regs, i);
2236
2237 /* CC is always call-clobbered. */
2238 trad_frame_set_unknown (info->saved_regs, S390_PSWM_REGNUM);
2239
2240 /* Record the addresses of all register spill slots the prologue parser
2241 has recognized. Consider only registers defined as call-saved by the
2242 ABI; for call-clobbered registers the parser may have recognized
2243 spurious stores. */
2244
2245 for (i = 0; i < 16; i++)
2246 if (s390_register_call_saved (gdbarch, S390_R0_REGNUM + i)
2247 && data.gpr_slot[i] != 0)
2248 info->saved_regs[S390_R0_REGNUM + i].addr = cfa - data.gpr_slot[i];
2249
2250 for (i = 0; i < 16; i++)
2251 if (s390_register_call_saved (gdbarch, S390_F0_REGNUM + i)
2252 && data.fpr_slot[i] != 0)
2253 info->saved_regs[S390_F0_REGNUM + i].addr = cfa - data.fpr_slot[i];
2254
2255 /* Function return will set PC to %r14. */
2256 info->saved_regs[S390_PSWA_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM];
2257
2258 /* In frameless functions, we unwind simply by moving the return
2259 address to the PC. However, if we actually stored to the
2260 save area, use that -- we might only think the function frameless
2261 because we're in the middle of the prologue ... */
2262 if (size == 0
2263 && !trad_frame_addr_p (info->saved_regs, S390_PSWA_REGNUM))
2264 {
2265 info->saved_regs[S390_PSWA_REGNUM].realreg = S390_RETADDR_REGNUM;
2266 }
2267
2268 /* Another sanity check: unless this is a frameless function,
2269 we should have found spill slots for SP and PC.
2270 If not, we cannot unwind further -- this happens e.g. in
2271 libc's thread_start routine. */
2272 if (size > 0)
2273 {
2274 if (!trad_frame_addr_p (info->saved_regs, S390_SP_REGNUM)
2275 || !trad_frame_addr_p (info->saved_regs, S390_PSWA_REGNUM))
2276 prev_sp = -1;
2277 }
2278
2279 /* We use the current value of the frame register as local_base,
2280 and the top of the register save area as frame_base. */
2281 if (prev_sp != -1)
2282 {
2283 info->frame_base = prev_sp + 16*word_size + 32;
2284 info->local_base = prev_sp - size;
2285 }
2286
2287 return 1;
2288 }
2289
2290 static void
2291 s390_backchain_frame_unwind_cache (struct frame_info *this_frame,
2292 struct s390_unwind_cache *info)
2293 {
2294 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2295 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2296 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2297 CORE_ADDR backchain;
2298 ULONGEST reg;
2299 LONGEST sp, tmp;
2300 int i;
2301
2302 /* Set up ABI call-saved/call-clobbered registers. */
2303 for (i = 0; i < S390_NUM_REGS; i++)
2304 if (!s390_register_call_saved (gdbarch, i))
2305 trad_frame_set_unknown (info->saved_regs, i);
2306
2307 /* CC is always call-clobbered. */
2308 trad_frame_set_unknown (info->saved_regs, S390_PSWM_REGNUM);
2309
2310 /* Get the backchain. */
2311 reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
2312 if (!safe_read_memory_integer (reg, word_size, byte_order, &tmp))
2313 tmp = 0;
2314 backchain = (CORE_ADDR) tmp;
2315
2316 /* A zero backchain terminates the frame chain. As additional
2317 sanity check, let's verify that the spill slot for SP in the
2318 save area pointed to by the backchain in fact links back to
2319 the save area. */
2320 if (backchain != 0
2321 && safe_read_memory_integer (backchain + 15*word_size,
2322 word_size, byte_order, &sp)
2323 && (CORE_ADDR)sp == backchain)
2324 {
2325 /* We don't know which registers were saved, but it will have
2326 to be at least %r14 and %r15. This will allow us to continue
2327 unwinding, but other prev-frame registers may be incorrect ... */
2328 info->saved_regs[S390_SP_REGNUM].addr = backchain + 15*word_size;
2329 info->saved_regs[S390_RETADDR_REGNUM].addr = backchain + 14*word_size;
2330
2331 /* Function return will set PC to %r14. */
2332 info->saved_regs[S390_PSWA_REGNUM]
2333 = info->saved_regs[S390_RETADDR_REGNUM];
2334
2335 /* We use the current value of the frame register as local_base,
2336 and the top of the register save area as frame_base. */
2337 info->frame_base = backchain + 16*word_size + 32;
2338 info->local_base = reg;
2339 }
2340
2341 info->func = get_frame_pc (this_frame);
2342 }
2343
2344 static struct s390_unwind_cache *
2345 s390_frame_unwind_cache (struct frame_info *this_frame,
2346 void **this_prologue_cache)
2347 {
2348 struct s390_unwind_cache *info;
2349
2350 if (*this_prologue_cache)
2351 return (struct s390_unwind_cache *) *this_prologue_cache;
2352
2353 info = FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache);
2354 *this_prologue_cache = info;
2355 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2356 info->func = -1;
2357 info->frame_base = -1;
2358 info->local_base = -1;
2359
2360 TRY
2361 {
2362 /* Try to use prologue analysis to fill the unwind cache.
2363 If this fails, fall back to reading the stack backchain. */
2364 if (!s390_prologue_frame_unwind_cache (this_frame, info))
2365 s390_backchain_frame_unwind_cache (this_frame, info);
2366 }
2367 CATCH (ex, RETURN_MASK_ERROR)
2368 {
2369 if (ex.error != NOT_AVAILABLE_ERROR)
2370 throw_exception (ex);
2371 }
2372 END_CATCH
2373
2374 return info;
2375 }
2376
2377 static void
2378 s390_frame_this_id (struct frame_info *this_frame,
2379 void **this_prologue_cache,
2380 struct frame_id *this_id)
2381 {
2382 struct s390_unwind_cache *info
2383 = s390_frame_unwind_cache (this_frame, this_prologue_cache);
2384
2385 if (info->frame_base == -1)
2386 {
2387 if (info->func != -1)
2388 *this_id = frame_id_build_unavailable_stack (info->func);
2389 return;
2390 }
2391
2392 *this_id = frame_id_build (info->frame_base, info->func);
2393 }
2394
2395 static struct value *
2396 s390_frame_prev_register (struct frame_info *this_frame,
2397 void **this_prologue_cache, int regnum)
2398 {
2399 struct s390_unwind_cache *info
2400 = s390_frame_unwind_cache (this_frame, this_prologue_cache);
2401
2402 return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum);
2403 }
2404
2405 static const struct frame_unwind s390_frame_unwind = {
2406 NORMAL_FRAME,
2407 default_frame_unwind_stop_reason,
2408 s390_frame_this_id,
2409 s390_frame_prev_register,
2410 NULL,
2411 default_frame_sniffer
2412 };
2413
2414
2415 /* Code stubs and their stack frames. For things like PLTs and NULL
2416 function calls (where there is no true frame and the return address
2417 is in the RETADDR register). */
2418
2419 struct s390_stub_unwind_cache
2420 {
2421 CORE_ADDR frame_base;
2422 struct trad_frame_saved_reg *saved_regs;
2423 };
2424
2425 static struct s390_stub_unwind_cache *
2426 s390_stub_frame_unwind_cache (struct frame_info *this_frame,
2427 void **this_prologue_cache)
2428 {
2429 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2430 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2431 struct s390_stub_unwind_cache *info;
2432 ULONGEST reg;
2433
2434 if (*this_prologue_cache)
2435 return (struct s390_stub_unwind_cache *) *this_prologue_cache;
2436
2437 info = FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache);
2438 *this_prologue_cache = info;
2439 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2440
2441 /* The return address is in register %r14. */
2442 info->saved_regs[S390_PSWA_REGNUM].realreg = S390_RETADDR_REGNUM;
2443
2444 /* Retrieve stack pointer and determine our frame base. */
2445 reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
2446 info->frame_base = reg + 16*word_size + 32;
2447
2448 return info;
2449 }
2450
2451 static void
2452 s390_stub_frame_this_id (struct frame_info *this_frame,
2453 void **this_prologue_cache,
2454 struct frame_id *this_id)
2455 {
2456 struct s390_stub_unwind_cache *info
2457 = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache);
2458 *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame));
2459 }
2460
2461 static struct value *
2462 s390_stub_frame_prev_register (struct frame_info *this_frame,
2463 void **this_prologue_cache, int regnum)
2464 {
2465 struct s390_stub_unwind_cache *info
2466 = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache);
2467 return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum);
2468 }
2469
2470 static int
2471 s390_stub_frame_sniffer (const struct frame_unwind *self,
2472 struct frame_info *this_frame,
2473 void **this_prologue_cache)
2474 {
2475 CORE_ADDR addr_in_block;
2476 bfd_byte insn[S390_MAX_INSTR_SIZE];
2477
2478 /* If the current PC points to non-readable memory, we assume we
2479 have trapped due to an invalid function pointer call. We handle
2480 the non-existing current function like a PLT stub. */
2481 addr_in_block = get_frame_address_in_block (this_frame);
2482 if (in_plt_section (addr_in_block)
2483 || s390_readinstruction (insn, get_frame_pc (this_frame)) < 0)
2484 return 1;
2485 return 0;
2486 }
2487
2488 static const struct frame_unwind s390_stub_frame_unwind = {
2489 NORMAL_FRAME,
2490 default_frame_unwind_stop_reason,
2491 s390_stub_frame_this_id,
2492 s390_stub_frame_prev_register,
2493 NULL,
2494 s390_stub_frame_sniffer
2495 };
2496
2497
2498 /* Signal trampoline stack frames. */
2499
2500 struct s390_sigtramp_unwind_cache {
2501 CORE_ADDR frame_base;
2502 struct trad_frame_saved_reg *saved_regs;
2503 };
2504
2505 static struct s390_sigtramp_unwind_cache *
2506 s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
2507 void **this_prologue_cache)
2508 {
2509 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2510 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2511 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2512 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2513 struct s390_sigtramp_unwind_cache *info;
2514 ULONGEST this_sp, prev_sp;
2515 CORE_ADDR next_ra, next_cfa, sigreg_ptr, sigreg_high_off;
2516 int i;
2517
2518 if (*this_prologue_cache)
2519 return (struct s390_sigtramp_unwind_cache *) *this_prologue_cache;
2520
2521 info = FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache);
2522 *this_prologue_cache = info;
2523 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2524
2525 this_sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
2526 next_ra = get_frame_pc (this_frame);
2527 next_cfa = this_sp + 16*word_size + 32;
2528
2529 /* New-style RT frame:
2530 retcode + alignment (8 bytes)
2531 siginfo (128 bytes)
2532 ucontext (contains sigregs at offset 5 words). */
2533 if (next_ra == next_cfa)
2534 {
2535 sigreg_ptr = next_cfa + 8 + 128 + align_up (5*word_size, 8);
2536 /* sigregs are followed by uc_sigmask (8 bytes), then by the
2537 upper GPR halves if present. */
2538 sigreg_high_off = 8;
2539 }
2540
2541 /* Old-style RT frame and all non-RT frames:
2542 old signal mask (8 bytes)
2543 pointer to sigregs. */
2544 else
2545 {
2546 sigreg_ptr = read_memory_unsigned_integer (next_cfa + 8,
2547 word_size, byte_order);
2548 /* sigregs are followed by signo (4 bytes), then by the
2549 upper GPR halves if present. */
2550 sigreg_high_off = 4;
2551 }
2552
2553 /* The sigregs structure looks like this:
2554 long psw_mask;
2555 long psw_addr;
2556 long gprs[16];
2557 int acrs[16];
2558 int fpc;
2559 int __pad;
2560 double fprs[16]; */
2561
2562 /* PSW mask and address. */
2563 info->saved_regs[S390_PSWM_REGNUM].addr = sigreg_ptr;
2564 sigreg_ptr += word_size;
2565 info->saved_regs[S390_PSWA_REGNUM].addr = sigreg_ptr;
2566 sigreg_ptr += word_size;
2567
2568 /* Then the GPRs. */
2569 for (i = 0; i < 16; i++)
2570 {
2571 info->saved_regs[S390_R0_REGNUM + i].addr = sigreg_ptr;
2572 sigreg_ptr += word_size;
2573 }
2574
2575 /* Then the ACRs. */
2576 for (i = 0; i < 16; i++)
2577 {
2578 info->saved_regs[S390_A0_REGNUM + i].addr = sigreg_ptr;
2579 sigreg_ptr += 4;
2580 }
2581
2582 /* The floating-point control word. */
2583 info->saved_regs[S390_FPC_REGNUM].addr = sigreg_ptr;
2584 sigreg_ptr += 8;
2585
2586 /* And finally the FPRs. */
2587 for (i = 0; i < 16; i++)
2588 {
2589 info->saved_regs[S390_F0_REGNUM + i].addr = sigreg_ptr;
2590 sigreg_ptr += 8;
2591 }
2592
2593 /* If we have them, the GPR upper halves are appended at the end. */
2594 sigreg_ptr += sigreg_high_off;
2595 if (tdep->gpr_full_regnum != -1)
2596 for (i = 0; i < 16; i++)
2597 {
2598 info->saved_regs[S390_R0_UPPER_REGNUM + i].addr = sigreg_ptr;
2599 sigreg_ptr += 4;
2600 }
2601
2602 /* Restore the previous frame's SP. */
2603 prev_sp = read_memory_unsigned_integer (
2604 info->saved_regs[S390_SP_REGNUM].addr,
2605 word_size, byte_order);
2606
2607 /* Determine our frame base. */
2608 info->frame_base = prev_sp + 16*word_size + 32;
2609
2610 return info;
2611 }
2612
2613 static void
2614 s390_sigtramp_frame_this_id (struct frame_info *this_frame,
2615 void **this_prologue_cache,
2616 struct frame_id *this_id)
2617 {
2618 struct s390_sigtramp_unwind_cache *info
2619 = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
2620 *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame));
2621 }
2622
2623 static struct value *
2624 s390_sigtramp_frame_prev_register (struct frame_info *this_frame,
2625 void **this_prologue_cache, int regnum)
2626 {
2627 struct s390_sigtramp_unwind_cache *info
2628 = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
2629 return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum);
2630 }
2631
2632 static int
2633 s390_sigtramp_frame_sniffer (const struct frame_unwind *self,
2634 struct frame_info *this_frame,
2635 void **this_prologue_cache)
2636 {
2637 CORE_ADDR pc = get_frame_pc (this_frame);
2638 bfd_byte sigreturn[2];
2639
2640 if (target_read_memory (pc, sigreturn, 2))
2641 return 0;
2642
2643 if (sigreturn[0] != op_svc)
2644 return 0;
2645
2646 if (sigreturn[1] != 119 /* sigreturn */
2647 && sigreturn[1] != 173 /* rt_sigreturn */)
2648 return 0;
2649
2650 return 1;
2651 }
2652
2653 static const struct frame_unwind s390_sigtramp_frame_unwind = {
2654 SIGTRAMP_FRAME,
2655 default_frame_unwind_stop_reason,
2656 s390_sigtramp_frame_this_id,
2657 s390_sigtramp_frame_prev_register,
2658 NULL,
2659 s390_sigtramp_frame_sniffer
2660 };
2661
2662 /* Retrieve the syscall number at a ptrace syscall-stop. Return -1
2663 upon error. */
2664
2665 static LONGEST
2666 s390_linux_get_syscall_number (struct gdbarch *gdbarch,
2667 ptid_t ptid)
2668 {
2669 struct regcache *regs = get_thread_regcache (ptid);
2670 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2671 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2672 ULONGEST pc;
2673 ULONGEST svc_number = -1;
2674 unsigned opcode;
2675
2676 /* Assume that the PC points after the 2-byte SVC instruction. We
2677 don't currently support SVC via EXECUTE. */
2678 regcache_cooked_read_unsigned (regs, tdep->pc_regnum, &pc);
2679 pc -= 2;
2680 opcode = read_memory_unsigned_integer ((CORE_ADDR) pc, 1, byte_order);
2681 if (opcode != op_svc)
2682 return -1;
2683
2684 svc_number = read_memory_unsigned_integer ((CORE_ADDR) pc + 1, 1,
2685 byte_order);
2686 if (svc_number == 0)
2687 regcache_cooked_read_unsigned (regs, S390_R1_REGNUM, &svc_number);
2688
2689 return svc_number;
2690 }
2691
2692 /* Process record-replay */
2693
2694 static struct linux_record_tdep s390_linux_record_tdep;
2695 static struct linux_record_tdep s390x_linux_record_tdep;
2696
2697 /* Record all registers but PC register for process-record. */
2698
2699 static int
2700 s390_all_but_pc_registers_record (struct regcache *regcache)
2701 {
2702 struct gdbarch *gdbarch = regcache->arch ();
2703 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2704 int i;
2705
2706 for (i = 0; i < 16; i++)
2707 {
2708 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
2709 return -1;
2710 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + i))
2711 return -1;
2712 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + i))
2713 return -1;
2714 if (tdep->gpr_full_regnum != -1)
2715 if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
2716 return -1;
2717 if (tdep->v0_full_regnum != -1)
2718 {
2719 if (record_full_arch_list_add_reg (regcache, S390_V0_LOWER_REGNUM + i))
2720 return -1;
2721 if (record_full_arch_list_add_reg (regcache, S390_V16_REGNUM + i))
2722 return -1;
2723 }
2724 }
2725 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
2726 return -1;
2727 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
2728 return -1;
2729
2730 return 0;
2731 }
2732
2733 static enum gdb_syscall
2734 s390_canonicalize_syscall (int syscall, enum s390_abi_kind abi)
2735 {
2736 switch (syscall)
2737 {
2738 /* s390 syscall numbers < 222 are mostly the same as x86, so just list
2739 the exceptions. */
2740 case 0:
2741 return gdb_sys_no_syscall;
2742 case 7:
2743 return gdb_sys_restart_syscall;
2744 /* These syscalls work only on 31-bit. */
2745 case 13: /* time */
2746 case 16: /* lchown[16] */
2747 case 23: /* setuid[16] */
2748 case 24: /* getuid[16] */
2749 case 25: /* stime */
2750 case 46: /* setgid[16] */
2751 case 47: /* getgid[16] */
2752 case 49: /* seteuid[16] */
2753 case 50: /* getegid[16] */
2754 case 70: /* setreuid[16] */
2755 case 71: /* setregid[16] */
2756 case 76: /* [old_]getrlimit */
2757 case 80: /* getgroups[16] */
2758 case 81: /* setgroups[16] */
2759 case 95: /* fchown[16] */
2760 case 101: /* ioperm */
2761 case 138: /* setfsuid[16] */
2762 case 139: /* setfsgid[16] */
2763 case 140: /* _llseek */
2764 case 164: /* setresuid[16] */
2765 case 165: /* getresuid[16] */
2766 case 170: /* setresgid[16] */
2767 case 171: /* getresgid[16] */
2768 case 182: /* chown[16] */
2769 case 192: /* mmap2 */
2770 case 193: /* truncate64 */
2771 case 194: /* ftruncate64 */
2772 case 195: /* stat64 */
2773 case 196: /* lstat64 */
2774 case 197: /* fstat64 */
2775 case 221: /* fcntl64 */
2776 if (abi == ABI_LINUX_S390)
2777 return (enum gdb_syscall) syscall;
2778 return gdb_sys_no_syscall;
2779 /* These syscalls don't exist on s390. */
2780 case 17: /* break */
2781 case 18: /* oldstat */
2782 case 28: /* oldfstat */
2783 case 31: /* stty */
2784 case 32: /* gtty */
2785 case 35: /* ftime */
2786 case 44: /* prof */
2787 case 53: /* lock */
2788 case 56: /* mpx */
2789 case 58: /* ulimit */
2790 case 59: /* oldolduname */
2791 case 68: /* sgetmask */
2792 case 69: /* ssetmask */
2793 case 82: /* [old_]select */
2794 case 84: /* oldlstat */
2795 case 98: /* profil */
2796 case 109: /* olduname */
2797 case 113: /* vm86old */
2798 case 123: /* modify_ldt */
2799 case 166: /* vm86 */
2800 return gdb_sys_no_syscall;
2801 case 110:
2802 return gdb_sys_lookup_dcookie;
2803 /* Here come the differences. */
2804 case 222:
2805 return gdb_sys_readahead;
2806 case 223:
2807 if (abi == ABI_LINUX_S390)
2808 return gdb_sys_sendfile64;
2809 return gdb_sys_no_syscall;
2810 /* 224-235 handled below */
2811 case 236:
2812 return gdb_sys_gettid;
2813 case 237:
2814 return gdb_sys_tkill;
2815 case 238:
2816 return gdb_sys_futex;
2817 case 239:
2818 return gdb_sys_sched_setaffinity;
2819 case 240:
2820 return gdb_sys_sched_getaffinity;
2821 case 241:
2822 return gdb_sys_tgkill;
2823 /* 242 reserved */
2824 case 243:
2825 return gdb_sys_io_setup;
2826 case 244:
2827 return gdb_sys_io_destroy;
2828 case 245:
2829 return gdb_sys_io_getevents;
2830 case 246:
2831 return gdb_sys_io_submit;
2832 case 247:
2833 return gdb_sys_io_cancel;
2834 case 248:
2835 return gdb_sys_exit_group;
2836 case 249:
2837 return gdb_sys_epoll_create;
2838 case 250:
2839 return gdb_sys_epoll_ctl;
2840 case 251:
2841 return gdb_sys_epoll_wait;
2842 case 252:
2843 return gdb_sys_set_tid_address;
2844 case 253:
2845 return gdb_sys_fadvise64;
2846 /* 254-262 handled below */
2847 /* 263 reserved */
2848 case 264:
2849 if (abi == ABI_LINUX_S390)
2850 return gdb_sys_fadvise64_64;
2851 return gdb_sys_no_syscall;
2852 case 265:
2853 return gdb_sys_statfs64;
2854 case 266:
2855 return gdb_sys_fstatfs64;
2856 case 267:
2857 return gdb_sys_remap_file_pages;
2858 /* 268-270 reserved */
2859 /* 271-277 handled below */
2860 case 278:
2861 return gdb_sys_add_key;
2862 case 279:
2863 return gdb_sys_request_key;
2864 case 280:
2865 return gdb_sys_keyctl;
2866 case 281:
2867 return gdb_sys_waitid;
2868 /* 282-312 handled below */
2869 case 293:
2870 if (abi == ABI_LINUX_S390)
2871 return gdb_sys_fstatat64;
2872 return gdb_sys_newfstatat;
2873 /* 313+ not yet supported */
2874 default:
2875 {
2876 int ret;
2877
2878 /* Most "old" syscalls copied from i386. */
2879 if (syscall <= 221)
2880 ret = syscall;
2881 /* xattr syscalls. */
2882 else if (syscall >= 224 && syscall <= 235)
2883 ret = syscall + 2;
2884 /* timer syscalls. */
2885 else if (syscall >= 254 && syscall <= 262)
2886 ret = syscall + 5;
2887 /* mq_* and kexec_load */
2888 else if (syscall >= 271 && syscall <= 277)
2889 ret = syscall + 6;
2890 /* ioprio_set .. epoll_pwait */
2891 else if (syscall >= 282 && syscall <= 312)
2892 ret = syscall + 7;
2893 else
2894 ret = gdb_sys_no_syscall;
2895
2896 return (enum gdb_syscall) ret;
2897 }
2898 }
2899 }
2900
2901 static int
2902 s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native)
2903 {
2904 struct gdbarch *gdbarch = regcache->arch ();
2905 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2906 int ret;
2907 enum gdb_syscall syscall_gdb;
2908
2909 /* On s390, syscall number can be passed either as immediate field of svc
2910 instruction, or in %r1 (with svc 0). */
2911 if (syscall_native == 0)
2912 regcache_raw_read_signed (regcache, S390_R1_REGNUM, &syscall_native);
2913
2914 syscall_gdb = s390_canonicalize_syscall (syscall_native, tdep->abi);
2915
2916 if (syscall_gdb < 0)
2917 {
2918 printf_unfiltered (_("Process record and replay target doesn't "
2919 "support syscall number %s\n"),
2920 plongest (syscall_native));
2921 return -1;
2922 }
2923
2924 if (syscall_gdb == gdb_sys_sigreturn
2925 || syscall_gdb == gdb_sys_rt_sigreturn)
2926 {
2927 if (s390_all_but_pc_registers_record (regcache))
2928 return -1;
2929 return 0;
2930 }
2931
2932 if (tdep->abi == ABI_LINUX_ZSERIES)
2933 ret = record_linux_system_call (syscall_gdb, regcache,
2934 &s390x_linux_record_tdep);
2935 else
2936 ret = record_linux_system_call (syscall_gdb, regcache,
2937 &s390_linux_record_tdep);
2938
2939 if (ret)
2940 return ret;
2941
2942 /* Record the return value of the system call. */
2943 if (record_full_arch_list_add_reg (regcache, S390_R2_REGNUM))
2944 return -1;
2945
2946 return 0;
2947 }
2948
2949 static int
2950 s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
2951 enum gdb_signal signal)
2952 {
2953 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2954 /* There are two kinds of signal frames on s390. rt_sigframe is always
2955 the larger one, so don't even bother with sigframe. */
2956 const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ?
2957 160 + 8 + 128 + 1024 : 96 + 8 + 128 + 1000);
2958 ULONGEST sp;
2959 int i;
2960
2961 for (i = 0; i < 16; i++)
2962 {
2963 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
2964 return -1;
2965 if (tdep->gpr_full_regnum != -1)
2966 if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
2967 return -1;
2968 }
2969 if (record_full_arch_list_add_reg (regcache, S390_PSWA_REGNUM))
2970 return -1;
2971 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
2972 return -1;
2973
2974 /* Record the change in the stack.
2975 frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
2976 regcache_raw_read_unsigned (regcache, S390_SP_REGNUM, &sp);
2977 sp -= sizeof_rt_sigframe;
2978
2979 if (record_full_arch_list_add_mem (sp, sizeof_rt_sigframe))
2980 return -1;
2981
2982 if (record_full_arch_list_add_end ())
2983 return -1;
2984
2985 return 0;
2986 }
2987
2988 /* Frame base handling. */
2989
2990 static CORE_ADDR
2991 s390_frame_base_address (struct frame_info *this_frame, void **this_cache)
2992 {
2993 struct s390_unwind_cache *info
2994 = s390_frame_unwind_cache (this_frame, this_cache);
2995 return info->frame_base;
2996 }
2997
2998 static CORE_ADDR
2999 s390_local_base_address (struct frame_info *this_frame, void **this_cache)
3000 {
3001 struct s390_unwind_cache *info
3002 = s390_frame_unwind_cache (this_frame, this_cache);
3003 return info->local_base;
3004 }
3005
3006 static const struct frame_base s390_frame_base = {
3007 &s390_frame_unwind,
3008 s390_frame_base_address,
3009 s390_local_base_address,
3010 s390_local_base_address
3011 };
3012
3013 static CORE_ADDR
3014 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
3015 {
3016 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3017 ULONGEST pc;
3018 pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
3019 return gdbarch_addr_bits_remove (gdbarch, pc);
3020 }
3021
3022 static CORE_ADDR
3023 s390_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
3024 {
3025 ULONGEST sp;
3026 sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
3027 return gdbarch_addr_bits_remove (gdbarch, sp);
3028 }
3029
3030
3031 /* DWARF-2 frame support. */
3032
3033 static struct value *
3034 s390_dwarf2_prev_register (struct frame_info *this_frame, void **this_cache,
3035 int regnum)
3036 {
3037 return s390_unwind_pseudo_register (this_frame, regnum);
3038 }
3039
3040 static void
3041 s390_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
3042 struct dwarf2_frame_state_reg *reg,
3043 struct frame_info *this_frame)
3044 {
3045 /* The condition code (and thus PSW mask) is call-clobbered. */
3046 if (regnum == S390_PSWM_REGNUM)
3047 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3048
3049 /* The PSW address unwinds to the return address. */
3050 else if (regnum == S390_PSWA_REGNUM)
3051 reg->how = DWARF2_FRAME_REG_RA;
3052
3053 /* Fixed registers are call-saved or call-clobbered
3054 depending on the ABI in use. */
3055 else if (regnum < S390_NUM_REGS)
3056 {
3057 if (s390_register_call_saved (gdbarch, regnum))
3058 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
3059 else
3060 reg->how = DWARF2_FRAME_REG_UNDEFINED;
3061 }
3062
3063 /* We install a special function to unwind pseudos. */
3064 else
3065 {
3066 reg->how = DWARF2_FRAME_REG_FN;
3067 reg->loc.fn = s390_dwarf2_prev_register;
3068 }
3069 }
3070
3071
3072 /* Dummy function calls. */
3073
3074 /* Unwrap any single-field structs in TYPE and return the effective
3075 "inner" type. E.g., yield "float" for all these cases:
3076
3077 float x;
3078 struct { float x };
3079 struct { struct { float x; } x; };
3080 struct { struct { struct { float x; } x; } x; };
3081
3082 However, if an inner type is smaller than MIN_SIZE, abort the
3083 unwrapping. */
3084
3085 static struct type *
3086 s390_effective_inner_type (struct type *type, unsigned int min_size)
3087 {
3088 while (TYPE_CODE (type) == TYPE_CODE_STRUCT
3089 && TYPE_NFIELDS (type) == 1)
3090 {
3091 struct type *inner = check_typedef (TYPE_FIELD_TYPE (type, 0));
3092
3093 if (TYPE_LENGTH (inner) < min_size)
3094 break;
3095 type = inner;
3096 }
3097
3098 return type;
3099 }
3100
3101 /* Return non-zero if TYPE should be passed like "float" or
3102 "double". */
3103
3104 static int
3105 s390_function_arg_float (struct type *type)
3106 {
3107 /* Note that long double as well as complex types are intentionally
3108 excluded. */
3109 if (TYPE_LENGTH (type) > 8)
3110 return 0;
3111
3112 /* A struct containing just a float or double is passed like a float
3113 or double. */
3114 type = s390_effective_inner_type (type, 0);
3115
3116 return (TYPE_CODE (type) == TYPE_CODE_FLT
3117 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT);
3118 }
3119
3120 /* Return non-zero if TYPE should be passed like a vector. */
3121
3122 static int
3123 s390_function_arg_vector (struct type *type)
3124 {
3125 if (TYPE_LENGTH (type) > 16)
3126 return 0;
3127
3128 /* Structs containing just a vector are passed like a vector. */
3129 type = s390_effective_inner_type (type, TYPE_LENGTH (type));
3130
3131 return TYPE_CODE (type) == TYPE_CODE_ARRAY && TYPE_VECTOR (type);
3132 }
3133
3134 /* Determine whether N is a power of two. */
3135
3136 static int
3137 is_power_of_two (unsigned int n)
3138 {
3139 return n && ((n & (n - 1)) == 0);
3140 }
3141
3142 /* For an argument whose type is TYPE and which is not passed like a
3143 float or vector, return non-zero if it should be passed like "int"
3144 or "long long". */
3145
3146 static int
3147 s390_function_arg_integer (struct type *type)
3148 {
3149 enum type_code code = TYPE_CODE (type);
3150
3151 if (TYPE_LENGTH (type) > 8)
3152 return 0;
3153
3154 if (code == TYPE_CODE_INT
3155 || code == TYPE_CODE_ENUM
3156 || code == TYPE_CODE_RANGE
3157 || code == TYPE_CODE_CHAR
3158 || code == TYPE_CODE_BOOL
3159 || code == TYPE_CODE_PTR
3160 || TYPE_IS_REFERENCE (type))
3161 return 1;
3162
3163 return ((code == TYPE_CODE_UNION || code == TYPE_CODE_STRUCT)
3164 && is_power_of_two (TYPE_LENGTH (type)));
3165 }
3166
3167 /* Argument passing state: Internal data structure passed to helper
3168 routines of s390_push_dummy_call. */
3169
3170 struct s390_arg_state
3171 {
3172 /* Register cache, or NULL, if we are in "preparation mode". */
3173 struct regcache *regcache;
3174 /* Next available general/floating-point/vector register for
3175 argument passing. */
3176 int gr, fr, vr;
3177 /* Current pointer to copy area (grows downwards). */
3178 CORE_ADDR copy;
3179 /* Current pointer to parameter area (grows upwards). */
3180 CORE_ADDR argp;
3181 };
3182
3183 /* Prepare one argument ARG for a dummy call and update the argument
3184 passing state AS accordingly. If the regcache field in AS is set,
3185 operate in "write mode" and write ARG into the inferior. Otherwise
3186 run "preparation mode" and skip all updates to the inferior. */
3187
3188 static void
3189 s390_handle_arg (struct s390_arg_state *as, struct value *arg,
3190 struct gdbarch_tdep *tdep, int word_size,
3191 enum bfd_endian byte_order, int is_unnamed)
3192 {
3193 struct type *type = check_typedef (value_type (arg));
3194 unsigned int length = TYPE_LENGTH (type);
3195 int write_mode = as->regcache != NULL;
3196
3197 if (s390_function_arg_float (type))
3198 {
3199 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass
3200 arguments. The GNU/Linux for zSeries ABI uses 0, 2, 4, and
3201 6. */
3202 if (as->fr <= (tdep->abi == ABI_LINUX_S390 ? 2 : 6))
3203 {
3204 /* When we store a single-precision value in an FP register,
3205 it occupies the leftmost bits. */
3206 if (write_mode)
3207 regcache_cooked_write_part (as->regcache,
3208 S390_F0_REGNUM + as->fr,
3209 0, length,
3210 value_contents (arg));
3211 as->fr += 2;
3212 }
3213 else
3214 {
3215 /* When we store a single-precision value in a stack slot,
3216 it occupies the rightmost bits. */
3217 as->argp = align_up (as->argp + length, word_size);
3218 if (write_mode)
3219 write_memory (as->argp - length, value_contents (arg),
3220 length);
3221 }
3222 }
3223 else if (tdep->vector_abi == S390_VECTOR_ABI_128
3224 && s390_function_arg_vector (type))
3225 {
3226 static const char use_vr[] = {24, 26, 28, 30, 25, 27, 29, 31};
3227
3228 if (!is_unnamed && as->vr < ARRAY_SIZE (use_vr))
3229 {
3230 int regnum = S390_V24_REGNUM + use_vr[as->vr] - 24;
3231
3232 if (write_mode)
3233 regcache_cooked_write_part (as->regcache, regnum,
3234 0, length,
3235 value_contents (arg));
3236 as->vr++;
3237 }
3238 else
3239 {
3240 if (write_mode)
3241 write_memory (as->argp, value_contents (arg), length);
3242 as->argp = align_up (as->argp + length, word_size);
3243 }
3244 }
3245 else if (s390_function_arg_integer (type) && length <= word_size)
3246 {
3247 /* Initialize it just to avoid a GCC false warning. */
3248 ULONGEST val = 0;
3249
3250 if (write_mode)
3251 {
3252 /* Place value in least significant bits of the register or
3253 memory word and sign- or zero-extend to full word size.
3254 This also applies to a struct or union. */
3255 val = TYPE_UNSIGNED (type)
3256 ? extract_unsigned_integer (value_contents (arg),
3257 length, byte_order)
3258 : extract_signed_integer (value_contents (arg),
3259 length, byte_order);
3260 }
3261
3262 if (as->gr <= 6)
3263 {
3264 if (write_mode)
3265 regcache_cooked_write_unsigned (as->regcache,
3266 S390_R0_REGNUM + as->gr,
3267 val);
3268 as->gr++;
3269 }
3270 else
3271 {
3272 if (write_mode)
3273 write_memory_unsigned_integer (as->argp, word_size,
3274 byte_order, val);
3275 as->argp += word_size;
3276 }
3277 }
3278 else if (s390_function_arg_integer (type) && length == 8)
3279 {
3280 if (as->gr <= 5)
3281 {
3282 if (write_mode)
3283 {
3284 regcache_cooked_write (as->regcache,
3285 S390_R0_REGNUM + as->gr,
3286 value_contents (arg));
3287 regcache_cooked_write (as->regcache,
3288 S390_R0_REGNUM + as->gr + 1,
3289 value_contents (arg) + word_size);
3290 }
3291 as->gr += 2;
3292 }
3293 else
3294 {
3295 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
3296 in it, then don't go back and use it again later. */
3297 as->gr = 7;
3298
3299 if (write_mode)
3300 write_memory (as->argp, value_contents (arg), length);
3301 as->argp += length;
3302 }
3303 }
3304 else
3305 {
3306 /* This argument type is never passed in registers. Place the
3307 value in the copy area and pass a pointer to it. Use 8-byte
3308 alignment as a conservative assumption. */
3309 as->copy = align_down (as->copy - length, 8);
3310 if (write_mode)
3311 write_memory (as->copy, value_contents (arg), length);
3312
3313 if (as->gr <= 6)
3314 {
3315 if (write_mode)
3316 regcache_cooked_write_unsigned (as->regcache,
3317 S390_R0_REGNUM + as->gr,
3318 as->copy);
3319 as->gr++;
3320 }
3321 else
3322 {
3323 if (write_mode)
3324 write_memory_unsigned_integer (as->argp, word_size,
3325 byte_order, as->copy);
3326 as->argp += word_size;
3327 }
3328 }
3329 }
3330
3331 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
3332 place to be passed to a function, as specified by the "GNU/Linux
3333 for S/390 ELF Application Binary Interface Supplement".
3334
3335 SP is the current stack pointer. We must put arguments, links,
3336 padding, etc. whereever they belong, and return the new stack
3337 pointer value.
3338
3339 If STRUCT_RETURN is non-zero, then the function we're calling is
3340 going to return a structure by value; STRUCT_ADDR is the address of
3341 a block we've allocated for it on the stack.
3342
3343 Our caller has taken care of any type promotions needed to satisfy
3344 prototypes or the old K&R argument-passing rules. */
3345
3346 static CORE_ADDR
3347 s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
3348 struct regcache *regcache, CORE_ADDR bp_addr,
3349 int nargs, struct value **args, CORE_ADDR sp,
3350 int struct_return, CORE_ADDR struct_addr)
3351 {
3352 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3353 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
3354 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3355 int i;
3356 struct s390_arg_state arg_state, arg_prep;
3357 CORE_ADDR param_area_start, new_sp;
3358 struct type *ftype = check_typedef (value_type (function));
3359
3360 if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
3361 ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
3362
3363 arg_prep.copy = sp;
3364 arg_prep.gr = struct_return ? 3 : 2;
3365 arg_prep.fr = 0;
3366 arg_prep.vr = 0;
3367 arg_prep.argp = 0;
3368 arg_prep.regcache = NULL;
3369
3370 /* Initialize arg_state for "preparation mode". */
3371 arg_state = arg_prep;
3372
3373 /* Update arg_state.copy with the start of the reference-to-copy area
3374 and arg_state.argp with the size of the parameter area. */
3375 for (i = 0; i < nargs; i++)
3376 s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
3377 TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
3378
3379 param_area_start = align_down (arg_state.copy - arg_state.argp, 8);
3380
3381 /* Allocate the standard frame areas: the register save area, the
3382 word reserved for the compiler, and the back chain pointer. */
3383 new_sp = param_area_start - (16 * word_size + 32);
3384
3385 /* Now we have the final stack pointer. Make sure we didn't
3386 underflow; on 31-bit, this would result in addresses with the
3387 high bit set, which causes confusion elsewhere. Note that if we
3388 error out here, stack and registers remain untouched. */
3389 if (gdbarch_addr_bits_remove (gdbarch, new_sp) != new_sp)
3390 error (_("Stack overflow"));
3391
3392 /* Pass the structure return address in general register 2. */
3393 if (struct_return)
3394 regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM, struct_addr);
3395
3396 /* Initialize arg_state for "write mode". */
3397 arg_state = arg_prep;
3398 arg_state.argp = param_area_start;
3399 arg_state.regcache = regcache;
3400
3401 /* Write all parameters. */
3402 for (i = 0; i < nargs; i++)
3403 s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
3404 TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
3405
3406 /* Store return PSWA. In 31-bit mode, keep addressing mode bit. */
3407 if (word_size == 4)
3408 {
3409 ULONGEST pswa;
3410 regcache_cooked_read_unsigned (regcache, S390_PSWA_REGNUM, &pswa);
3411 bp_addr = (bp_addr & 0x7fffffff) | (pswa & 0x80000000);
3412 }
3413 regcache_cooked_write_unsigned (regcache, S390_RETADDR_REGNUM, bp_addr);
3414
3415 /* Store updated stack pointer. */
3416 regcache_cooked_write_unsigned (regcache, S390_SP_REGNUM, new_sp);
3417
3418 /* We need to return the 'stack part' of the frame ID,
3419 which is actually the top of the register save area. */
3420 return param_area_start;
3421 }
3422
3423 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
3424 dummy frame. The frame ID's base needs to match the TOS value
3425 returned by push_dummy_call, and the PC match the dummy frame's
3426 breakpoint. */
3427 static struct frame_id
3428 s390_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
3429 {
3430 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
3431 CORE_ADDR sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
3432 sp = gdbarch_addr_bits_remove (gdbarch, sp);
3433
3434 return frame_id_build (sp + 16*word_size + 32,
3435 get_frame_pc (this_frame));
3436 }
3437
3438 static CORE_ADDR
3439 s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
3440 {
3441 /* Both the 32- and 64-bit ABI's say that the stack pointer should
3442 always be aligned on an eight-byte boundary. */
3443 return (addr & -8);
3444 }
3445
3446
3447 /* Helper for s390_return_value: Set or retrieve a function return
3448 value if it resides in a register. */
3449
3450 static void
3451 s390_register_return_value (struct gdbarch *gdbarch, struct type *type,
3452 struct regcache *regcache,
3453 gdb_byte *out, const gdb_byte *in)
3454 {
3455 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3456 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
3457 int length = TYPE_LENGTH (type);
3458 int code = TYPE_CODE (type);
3459
3460 if (code == TYPE_CODE_FLT || code == TYPE_CODE_DECFLOAT)
3461 {
3462 /* Float-like value: left-aligned in f0. */
3463 if (in != NULL)
3464 regcache_cooked_write_part (regcache, S390_F0_REGNUM,
3465 0, length, in);
3466 else
3467 regcache_cooked_read_part (regcache, S390_F0_REGNUM,
3468 0, length, out);
3469 }
3470 else if (code == TYPE_CODE_ARRAY)
3471 {
3472 /* Vector: left-aligned in v24. */
3473 if (in != NULL)
3474 regcache_cooked_write_part (regcache, S390_V24_REGNUM,
3475 0, length, in);
3476 else
3477 regcache_cooked_read_part (regcache, S390_V24_REGNUM,
3478 0, length, out);
3479 }
3480 else if (length <= word_size)
3481 {
3482 /* Integer: zero- or sign-extended in r2. */
3483 if (out != NULL)
3484 regcache_cooked_read_part (regcache, S390_R2_REGNUM,
3485 word_size - length, length, out);
3486 else if (TYPE_UNSIGNED (type))
3487 regcache_cooked_write_unsigned
3488 (regcache, S390_R2_REGNUM,
3489 extract_unsigned_integer (in, length, byte_order));
3490 else
3491 regcache_cooked_write_signed
3492 (regcache, S390_R2_REGNUM,
3493 extract_signed_integer (in, length, byte_order));
3494 }
3495 else if (length == 2 * word_size)
3496 {
3497 /* Double word: in r2 and r3. */
3498 if (in != NULL)
3499 {
3500 regcache_cooked_write (regcache, S390_R2_REGNUM, in);
3501 regcache_cooked_write (regcache, S390_R3_REGNUM,
3502 in + word_size);
3503 }
3504 else
3505 {
3506 regcache_cooked_read (regcache, S390_R2_REGNUM, out);
3507 regcache_cooked_read (regcache, S390_R3_REGNUM,
3508 out + word_size);
3509 }
3510 }
3511 else
3512 internal_error (__FILE__, __LINE__, _("invalid return type"));
3513 }
3514
3515
3516 /* Implement the 'return_value' gdbarch method. */
3517
3518 static enum return_value_convention
3519 s390_return_value (struct gdbarch *gdbarch, struct value *function,
3520 struct type *type, struct regcache *regcache,
3521 gdb_byte *out, const gdb_byte *in)
3522 {
3523 enum return_value_convention rvc;
3524
3525 type = check_typedef (type);
3526
3527 switch (TYPE_CODE (type))
3528 {
3529 case TYPE_CODE_STRUCT:
3530 case TYPE_CODE_UNION:
3531 case TYPE_CODE_COMPLEX:
3532 rvc = RETURN_VALUE_STRUCT_CONVENTION;
3533 break;
3534 case TYPE_CODE_ARRAY:
3535 rvc = (gdbarch_tdep (gdbarch)->vector_abi == S390_VECTOR_ABI_128
3536 && TYPE_LENGTH (type) <= 16 && TYPE_VECTOR (type))
3537 ? RETURN_VALUE_REGISTER_CONVENTION
3538 : RETURN_VALUE_STRUCT_CONVENTION;
3539 break;
3540 default:
3541 rvc = TYPE_LENGTH (type) <= 8
3542 ? RETURN_VALUE_REGISTER_CONVENTION
3543 : RETURN_VALUE_STRUCT_CONVENTION;
3544 }
3545
3546 if (in != NULL || out != NULL)
3547 {
3548 if (rvc == RETURN_VALUE_REGISTER_CONVENTION)
3549 s390_register_return_value (gdbarch, type, regcache, out, in);
3550 else if (in != NULL)
3551 error (_("Cannot set function return value."));
3552 else
3553 error (_("Function return value unknown."));
3554 }
3555
3556 return rvc;
3557 }
3558
3559
3560 /* Breakpoints. */
3561 constexpr gdb_byte s390_break_insn[] = { 0x0, 0x1 };
3562
3563 typedef BP_MANIPULATION (s390_break_insn) s390_breakpoint;
3564
3565 /* Address handling. */
3566
3567 static CORE_ADDR
3568 s390_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
3569 {
3570 return addr & 0x7fffffff;
3571 }
3572
3573 static int
3574 s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
3575 {
3576 if (byte_size == 4)
3577 return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
3578 else
3579 return 0;
3580 }
3581
3582 static const char *
3583 s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
3584 {
3585 if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
3586 return "mode32";
3587 else
3588 return NULL;
3589 }
3590
3591 static int
3592 s390_address_class_name_to_type_flags (struct gdbarch *gdbarch,
3593 const char *name,
3594 int *type_flags_ptr)
3595 {
3596 if (strcmp (name, "mode32") == 0)
3597 {
3598 *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
3599 return 1;
3600 }
3601 else
3602 return 0;
3603 }
3604
3605 /* Implement gdbarch_gcc_target_options. GCC does not know "-m32" or
3606 "-mcmodel=large". */
3607
3608 static char *
3609 s390_gcc_target_options (struct gdbarch *gdbarch)
3610 {
3611 return xstrdup (gdbarch_ptr_bit (gdbarch) == 64 ? "-m64" : "-m31");
3612 }
3613
3614 /* Implement gdbarch_gnu_triplet_regexp. Target triplets are "s390-*"
3615 for 31-bit and "s390x-*" for 64-bit, while the BFD arch name is
3616 always "s390". Note that an s390x compiler supports "-m31" as
3617 well. */
3618
3619 static const char *
3620 s390_gnu_triplet_regexp (struct gdbarch *gdbarch)
3621 {
3622 return "s390x?";
3623 }
3624
3625 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
3626 gdbarch.h. */
3627
3628 static int
3629 s390_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
3630 {
3631 return ((isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement
3632 or indirection. */
3633 || *s == '%' /* Register access. */
3634 || isdigit (*s)); /* Literal number. */
3635 }
3636
3637 /* Process record and replay helpers. */
3638
3639 /* Takes the intermediate sum of address calculations and masks off upper
3640 bits according to current addressing mode. */
3641
3642 static CORE_ADDR
3643 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
3644 CORE_ADDR val) {
3645 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3646 ULONGEST pswm, pswa;
3647 int am;
3648 if (tdep->abi == ABI_LINUX_S390)
3649 {
3650 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &pswa);
3651 am = pswa >> 31 & 1;
3652 }
3653 else
3654 {
3655 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &pswm);
3656 am = pswm >> 31 & 3;
3657 }
3658 switch (am)
3659 {
3660 case 0:
3661 return val & 0xffffff;
3662 case 1:
3663 return val & 0x7fffffff;
3664 case 3:
3665 return val;
3666 default:
3667 fprintf_unfiltered (gdb_stdlog, "Warning: Addressing mode %d used.", am);
3668 return 0;
3669 }
3670 }
3671
3672 /* Calculates memory address using pre-calculated index, raw instruction word
3673 with b and d/dl fields, and raw instruction byte with dh field. Index and
3674 dh should be set to 0 if unused. */
3675
3676 static CORE_ADDR
3677 s390_record_calc_disp_common (struct gdbarch *gdbarch, struct regcache *regcache,
3678 ULONGEST x, uint16_t bd, int8_t dh)
3679 {
3680 uint8_t rb = bd >> 12 & 0xf;
3681 int32_t d = (bd & 0xfff) | ((int32_t)dh << 12);
3682 ULONGEST b;
3683 CORE_ADDR res = d + x;
3684 if (rb)
3685 {
3686 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + rb, &b);
3687 res += b;
3688 }
3689 return s390_record_address_mask (gdbarch, regcache, res);
3690 }
3691
3692 /* Calculates memory address using raw x, b + d/dl, dh fields from
3693 instruction. rx and dh should be set to 0 if unused. */
3694
3695 static CORE_ADDR
3696 s390_record_calc_disp (struct gdbarch *gdbarch, struct regcache *regcache,
3697 uint8_t rx, uint16_t bd, int8_t dh)
3698 {
3699 ULONGEST x = 0;
3700 if (rx)
3701 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + rx, &x);
3702 return s390_record_calc_disp_common (gdbarch, regcache, x, bd, dh);
3703 }
3704
3705 /* Calculates memory address for VSCE[GF] instructions. */
3706
3707 static int
3708 s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
3709 uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
3710 int8_t dh, CORE_ADDR *res)
3711 {
3712 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3713 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3714 ULONGEST x;
3715 gdb_byte buf[16];
3716 if (tdep->v0_full_regnum == -1 || el * es >= 16)
3717 return -1;
3718 if (vx < 16)
3719 regcache_cooked_read (regcache, tdep->v0_full_regnum + vx, buf);
3720 else
3721 regcache_raw_read (regcache, S390_V16_REGNUM + vx - 16, buf);
3722 x = extract_unsigned_integer (buf + el * es, es, byte_order);
3723 *res = s390_record_calc_disp_common (gdbarch, regcache, x, bd, dh);
3724 return 0;
3725 }
3726
3727 /* Calculates memory address for instructions with relative long addressing. */
3728
3729 static CORE_ADDR
3730 s390_record_calc_rl (struct gdbarch *gdbarch, struct regcache *regcache,
3731 CORE_ADDR addr, uint16_t i1, uint16_t i2)
3732 {
3733 int32_t ri = i1 << 16 | i2;
3734 return s390_record_address_mask (gdbarch, regcache, addr + (LONGEST)ri * 2);
3735 }
3736
3737 /* Population count helper. */
3738
3739 static int s390_popcnt (unsigned int x) {
3740 int res = 0;
3741 while (x)
3742 {
3743 if (x & 1)
3744 res++;
3745 x >>= 1;
3746 }
3747 return res;
3748 }
3749
3750 /* Record 64-bit register. */
3751
3752 static int
3753 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
3754 {
3755 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3756 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
3757 return -1;
3758 if (tdep->abi == ABI_LINUX_S390)
3759 if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
3760 return -1;
3761 return 0;
3762 }
3763
3764 /* Record high 32 bits of a register. */
3765
3766 static int
3767 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
3768 {
3769 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3770 if (tdep->abi == ABI_LINUX_S390)
3771 {
3772 if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
3773 return -1;
3774 }
3775 else
3776 {
3777 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
3778 return -1;
3779 }
3780 return 0;
3781 }
3782
3783 /* Record vector register. */
3784
3785 static int
3786 s390_record_vr (struct gdbarch *gdbarch, struct regcache *regcache, int i)
3787 {
3788 if (i < 16)
3789 {
3790 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + i))
3791 return -1;
3792 if (record_full_arch_list_add_reg (regcache, S390_V0_LOWER_REGNUM + i))
3793 return -1;
3794 }
3795 else
3796 {
3797 if (record_full_arch_list_add_reg (regcache, S390_V16_REGNUM + i - 16))
3798 return -1;
3799 }
3800 return 0;
3801 }
3802
3803 static int
3804 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
3805 CORE_ADDR addr)
3806 {
3807 uint16_t insn[3] = {0};
3808 /* Instruction as bytes. */
3809 uint8_t ibyte[6];
3810 /* Instruction as nibbles. */
3811 uint8_t inib[12];
3812 /* Instruction vector registers. */
3813 uint8_t ivec[4];
3814 CORE_ADDR oaddr, oaddr2, oaddr3;
3815 ULONGEST tmp;
3816 int i, n;
3817 /* if EX/EXRL instruction used, here's the reg parameter */
3818 int ex = -1;
3819 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
3820
3821 /* Attempting to use EX or EXRL jumps back here */
3822 ex:
3823
3824 /* Read instruction. */
3825 insn[0] = read_memory_unsigned_integer (addr, 2, byte_order);
3826 /* If execute was involved, do the adjustment. */
3827 if (ex != -1)
3828 insn[0] |= ex & 0xff;
3829 /* Two highest bits determine instruction size. */
3830 if (insn[0] >= 0x4000)
3831 insn[1] = read_memory_unsigned_integer (addr+2, 2, byte_order);
3832 else
3833 /* Not necessary, but avoids uninitialized variable warnings. */
3834 insn[1] = 0;
3835 if (insn[0] >= 0xc000)
3836 insn[2] = read_memory_unsigned_integer (addr+4, 2, byte_order);
3837 else
3838 insn[2] = 0;
3839 /* Split instruction into bytes and nibbles. */
3840 for (i = 0; i < 3; i++)
3841 {
3842 ibyte[i*2] = insn[i] >> 8 & 0xff;
3843 ibyte[i*2+1] = insn[i] & 0xff;
3844 }
3845 for (i = 0; i < 6; i++)
3846 {
3847 inib[i*2] = ibyte[i] >> 4 & 0xf;
3848 inib[i*2+1] = ibyte[i] & 0xf;
3849 }
3850 /* Compute vector registers, if applicable. */
3851 ivec[0] = (inib[9] >> 3 & 1) << 4 | inib[2];
3852 ivec[1] = (inib[9] >> 2 & 1) << 4 | inib[3];
3853 ivec[2] = (inib[9] >> 1 & 1) << 4 | inib[4];
3854 ivec[3] = (inib[9] >> 0 & 1) << 4 | inib[8];
3855
3856 switch (ibyte[0])
3857 {
3858 /* 0x00 undefined */
3859
3860 case 0x01:
3861 /* E-format instruction */
3862 switch (ibyte[1])
3863 {
3864 /* 0x00 undefined */
3865 /* 0x01 unsupported: PR - program return */
3866 /* 0x02 unsupported: UPT */
3867 /* 0x03 undefined */
3868 /* 0x04 privileged: PTFF - perform timing facility function */
3869 /* 0x05-0x06 undefined */
3870 /* 0x07 privileged: SCKPF - set clock programmable field */
3871 /* 0x08-0x09 undefined */
3872
3873 case 0x0a: /* PFPO - perform floating point operation */
3874 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
3875 if (!(tmp & 0x80000000u))
3876 {
3877 uint8_t ofc = tmp >> 16 & 0xff;
3878 switch (ofc)
3879 {
3880 case 0x00: /* HFP32 */
3881 case 0x01: /* HFP64 */
3882 case 0x05: /* BFP32 */
3883 case 0x06: /* BFP64 */
3884 case 0x08: /* DFP32 */
3885 case 0x09: /* DFP64 */
3886 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM))
3887 return -1;
3888 break;
3889 case 0x02: /* HFP128 */
3890 case 0x07: /* BFP128 */
3891 case 0x0a: /* DFP128 */
3892 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM))
3893 return -1;
3894 if (record_full_arch_list_add_reg (regcache, S390_F2_REGNUM))
3895 return -1;
3896 break;
3897 default:
3898 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown PFPO OFC %02x at %s.\n",
3899 ofc, paddress (gdbarch, addr));
3900 return -1;
3901 }
3902
3903 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3904 return -1;
3905 }
3906 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
3907 return -1;
3908 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3909 return -1;
3910 break;
3911
3912 case 0x0b: /* TAM - test address mode */
3913 case 0x0c: /* SAM24 - set address mode 24 */
3914 case 0x0d: /* SAM31 - set address mode 31 */
3915 case 0x0e: /* SAM64 - set address mode 64 */
3916 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3917 return -1;
3918 break;
3919
3920 /* 0x0f-0xfe undefined */
3921
3922 /* 0xff unsupported: TRAP */
3923
3924 default:
3925 goto UNKNOWN_OP;
3926 }
3927 break;
3928
3929 /* 0x02 undefined */
3930 /* 0x03 undefined */
3931
3932 case 0x04: /* SPM - set program mask */
3933 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3934 return -1;
3935 break;
3936
3937 case 0x05: /* BALR - branch and link */
3938 case 0x45: /* BAL - branch and link */
3939 case 0x06: /* BCTR - branch on count */
3940 case 0x46: /* BCT - branch on count */
3941 case 0x0d: /* BASR - branch and save */
3942 case 0x4d: /* BAS - branch and save */
3943 case 0x84: /* BRXH - branch relative on index high */
3944 case 0x85: /* BRXLE - branch relative on index low or equal */
3945 case 0x86: /* BXH - branch on index high */
3946 case 0x87: /* BXLE - branch on index low or equal */
3947 /* BA[SL]* use native-size destination for linkage info, BCT*, BRX*, BX*
3948 use 32-bit destination as counter. */
3949 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3950 return -1;
3951 break;
3952
3953 case 0x07: /* BCR - branch on condition */
3954 case 0x47: /* BC - branch on condition */
3955 /* No effect other than PC transfer. */
3956 break;
3957
3958 /* 0x08 undefined */
3959 /* 0x09 undefined */
3960
3961 case 0x0a:
3962 /* SVC - supervisor call */
3963 if (s390_linux_syscall_record (regcache, ibyte[1]))
3964 return -1;
3965 break;
3966
3967 case 0x0b: /* BSM - branch and set mode */
3968 if (inib[2])
3969 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3970 return -1;
3971 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3972 return -1;
3973 break;
3974
3975 case 0x0c: /* BASSM - branch and save and set mode */
3976 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3977 return -1;
3978 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3979 return -1;
3980 break;
3981
3982 case 0x0e: /* MVCL - move long [interruptible] */
3983 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
3984 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3985 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[2] | 1), &tmp);
3986 tmp &= 0xffffff;
3987 if (record_full_arch_list_add_mem (oaddr, tmp))
3988 return -1;
3989 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3990 return -1;
3991 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
3992 return -1;
3993 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
3994 return -1;
3995 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
3996 return -1;
3997 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3998 return -1;
3999 break;
4000
4001 case 0x0f: /* CLCL - compare logical long [interruptible] */
4002 case 0xa9: /* CLCLE - compare logical long extended [partial] */
4003 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4004 return -1;
4005 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
4006 return -1;
4007 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
4008 return -1;
4009 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
4010 return -1;
4011 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4012 return -1;
4013 break;
4014
4015 case 0x10: /* LPR - load positive */
4016 case 0x11: /* LNR - load negative */
4017 case 0x12: /* LTR - load and test */
4018 case 0x13: /* LCR - load complement */
4019 case 0x14: /* NR - and */
4020 case 0x16: /* OR - or */
4021 case 0x17: /* XR - xor */
4022 case 0x1a: /* AR - add */
4023 case 0x1b: /* SR - subtract */
4024 case 0x1e: /* ALR - add logical */
4025 case 0x1f: /* SLR - subtract logical */
4026 case 0x54: /* N - and */
4027 case 0x56: /* O - or */
4028 case 0x57: /* X - xor */
4029 case 0x5a: /* A - add */
4030 case 0x5b: /* S - subtract */
4031 case 0x5e: /* AL - add logical */
4032 case 0x5f: /* SL - subtract logical */
4033 case 0x4a: /* AH - add halfword */
4034 case 0x4b: /* SH - subtract halfword */
4035 case 0x8a: /* SRA - shift right single */
4036 case 0x8b: /* SLA - shift left single */
4037 case 0xbf: /* ICM - insert characters under mask */
4038 /* 32-bit destination + flags */
4039 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4040 return -1;
4041 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4042 return -1;
4043 break;
4044
4045 case 0x15: /* CLR - compare logical */
4046 case 0x55: /* CL - compare logical */
4047 case 0x19: /* CR - compare */
4048 case 0x29: /* CDR - compare */
4049 case 0x39: /* CER - compare */
4050 case 0x49: /* CH - compare halfword */
4051 case 0x59: /* C - compare */
4052 case 0x69: /* CD - compare */
4053 case 0x79: /* CE - compare */
4054 case 0x91: /* TM - test under mask */
4055 case 0x95: /* CLI - compare logical */
4056 case 0xbd: /* CLM - compare logical under mask */
4057 case 0xd5: /* CLC - compare logical */
4058 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4059 return -1;
4060 break;
4061
4062 case 0x18: /* LR - load */
4063 case 0x48: /* LH - load halfword */
4064 case 0x58: /* L - load */
4065 case 0x41: /* LA - load address */
4066 case 0x43: /* IC - insert character */
4067 case 0x4c: /* MH - multiply halfword */
4068 case 0x71: /* MS - multiply single */
4069 case 0x88: /* SRL - shift right single logical */
4070 case 0x89: /* SLL - shift left single logical */
4071 /* 32-bit, 8-bit (IC), or native width (LA) destination, no flags */
4072 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4073 return -1;
4074 break;
4075
4076 case 0x1c: /* MR - multiply */
4077 case 0x5c: /* M - multiply */
4078 case 0x1d: /* DR - divide */
4079 case 0x5d: /* D - divide */
4080 case 0x8c: /* SRDL - shift right double logical */
4081 case 0x8d: /* SLDL - shift left double logical */
4082 /* 32-bit pair destination, no flags */
4083 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4084 return -1;
4085 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
4086 return -1;
4087 break;
4088
4089 case 0x20: /* LPDR - load positive */
4090 case 0x30: /* LPER - load positive */
4091 case 0x21: /* LNDR - load negative */
4092 case 0x31: /* LNER - load negative */
4093 case 0x22: /* LTDR - load and test */
4094 case 0x32: /* LTER - load and test */
4095 case 0x23: /* LCDR - load complement */
4096 case 0x33: /* LCER - load complement */
4097 case 0x2a: /* ADR - add */
4098 case 0x3a: /* AER - add */
4099 case 0x6a: /* AD - add */
4100 case 0x7a: /* AE - add */
4101 case 0x2b: /* SDR - subtract */
4102 case 0x3b: /* SER - subtract */
4103 case 0x6b: /* SD - subtract */
4104 case 0x7b: /* SE - subtract */
4105 case 0x2e: /* AWR - add unnormalized */
4106 case 0x3e: /* AUR - add unnormalized */
4107 case 0x6e: /* AW - add unnormalized */
4108 case 0x7e: /* AU - add unnormalized */
4109 case 0x2f: /* SWR - subtract unnormalized */
4110 case 0x3f: /* SUR - subtract unnormalized */
4111 case 0x6f: /* SW - subtract unnormalized */
4112 case 0x7f: /* SU - subtract unnormalized */
4113 /* float destination + flags */
4114 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
4115 return -1;
4116 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4117 return -1;
4118 break;
4119
4120 case 0x24: /* HDR - halve */
4121 case 0x34: /* HER - halve */
4122 case 0x25: /* LDXR - load rounded */
4123 case 0x35: /* LEDR - load rounded */
4124 case 0x28: /* LDR - load */
4125 case 0x38: /* LER - load */
4126 case 0x68: /* LD - load */
4127 case 0x78: /* LE - load */
4128 case 0x2c: /* MDR - multiply */
4129 case 0x3c: /* MDER - multiply */
4130 case 0x6c: /* MD - multiply */
4131 case 0x7c: /* MDE - multiply */
4132 case 0x2d: /* DDR - divide */
4133 case 0x3d: /* DER - divide */
4134 case 0x6d: /* DD - divide */
4135 case 0x7d: /* DE - divide */
4136 /* float destination, no flags */
4137 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
4138 return -1;
4139 break;
4140
4141 case 0x26: /* MXR - multiply */
4142 case 0x27: /* MXDR - multiply */
4143 case 0x67: /* MXD - multiply */
4144 /* float pair destination, no flags */
4145 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
4146 return -1;
4147 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
4148 return -1;
4149 break;
4150
4151 case 0x36: /* AXR - add */
4152 case 0x37: /* SXR - subtract */
4153 /* float pair destination + flags */
4154 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
4155 return -1;
4156 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
4157 return -1;
4158 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4159 return -1;
4160 break;
4161
4162 case 0x40: /* STH - store halfword */
4163 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
4164 if (record_full_arch_list_add_mem (oaddr, 2))
4165 return -1;
4166 break;
4167
4168 case 0x42: /* STC - store character */
4169 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
4170 if (record_full_arch_list_add_mem (oaddr, 1))
4171 return -1;
4172 break;
4173
4174 case 0x44: /* EX - execute */
4175 if (ex != -1)
4176 {
4177 fprintf_unfiltered (gdb_stdlog, "Warning: Double execute at %s.\n",
4178 paddress (gdbarch, addr));
4179 return -1;
4180 }
4181 addr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
4182 if (inib[2])
4183 {
4184 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
4185 ex = tmp & 0xff;
4186 }
4187 else
4188 {
4189 ex = 0;
4190 }
4191 goto ex;
4192
4193 case 0x4e: /* CVD - convert to decimal */
4194 case 0x60: /* STD - store */
4195 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
4196 if (record_full_arch_list_add_mem (oaddr, 8))
4197 return -1;
4198 break;
4199
4200 case 0x4f: /* CVB - convert to binary */
4201 /* 32-bit gpr destination + FPC (DXC write) */
4202 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4203 return -1;
4204 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4205 return -1;
4206 break;
4207
4208 case 0x50: /* ST - store */
4209 case 0x70: /* STE - store */
4210 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
4211 if (record_full_arch_list_add_mem (oaddr, 4))
4212 return -1;
4213 break;
4214
4215 case 0x51: /* LAE - load address extended */
4216 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4217 return -1;
4218 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[2]))
4219 return -1;
4220 break;
4221
4222 /* 0x52 undefined */
4223 /* 0x53 undefined */
4224
4225 /* 0x61-0x66 undefined */
4226
4227 /* 0x72-0x77 undefined */
4228
4229 /* 0x80 privileged: SSM - set system mask */
4230 /* 0x81 undefined */
4231 /* 0x82 privileged: LPSW - load PSW */
4232 /* 0x83 privileged: diagnose */
4233
4234 case 0x8e: /* SRDA - shift right double */
4235 case 0x8f: /* SLDA - shift left double */
4236 /* 32-bit pair destination + flags */
4237 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4238 return -1;
4239 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
4240 return -1;
4241 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4242 return -1;
4243 break;
4244
4245 case 0x90: /* STM - store multiple */
4246 case 0x9b: /* STAM - store access multiple */
4247 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4248 if (inib[2] <= inib[3])
4249 n = inib[3] - inib[2] + 1;
4250 else
4251 n = inib[3] + 0x10 - inib[2] + 1;
4252 if (record_full_arch_list_add_mem (oaddr, n * 4))
4253 return -1;
4254 break;
4255
4256 case 0x92: /* MVI - move */
4257 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4258 if (record_full_arch_list_add_mem (oaddr, 1))
4259 return -1;
4260 break;
4261
4262 case 0x93: /* TS - test and set */
4263 case 0x94: /* NI - and */
4264 case 0x96: /* OI - or */
4265 case 0x97: /* XI - xor */
4266 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4267 if (record_full_arch_list_add_mem (oaddr, 1))
4268 return -1;
4269 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4270 return -1;
4271 break;
4272
4273 case 0x98: /* LM - load multiple */
4274 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
4275 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
4276 return -1;
4277 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
4278 return -1;
4279 break;
4280
4281 /* 0x99 privileged: TRACE */
4282
4283 case 0x9a: /* LAM - load access multiple */
4284 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
4285 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + i))
4286 return -1;
4287 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[3]))
4288 return -1;
4289 break;
4290
4291 /* 0x9c-0x9f privileged and obsolete (old I/O) */
4292 /* 0xa0-0xa4 undefined */
4293
4294 case 0xa5:
4295 case 0xa7:
4296 /* RI-format instruction */
4297 switch (ibyte[0] << 4 | inib[3])
4298 {
4299 case 0xa50: /* IIHH - insert immediate */
4300 case 0xa51: /* IIHL - insert immediate */
4301 /* high 32-bit destination */
4302 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
4303 return -1;
4304 break;
4305
4306 case 0xa52: /* IILH - insert immediate */
4307 case 0xa53: /* IILL - insert immediate */
4308 case 0xa75: /* BRAS - branch relative and save */
4309 case 0xa76: /* BRCT - branch relative on count */
4310 case 0xa78: /* LHI - load halfword immediate */
4311 case 0xa7c: /* MHI - multiply halfword immediate */
4312 /* 32-bit or native destination */
4313 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4314 return -1;
4315 break;
4316
4317 case 0xa54: /* NIHH - and immediate */
4318 case 0xa55: /* NIHL - and immediate */
4319 case 0xa58: /* OIHH - or immediate */
4320 case 0xa59: /* OIHL - or immediate */
4321 /* high 32-bit destination + flags */
4322 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
4323 return -1;
4324 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4325 return -1;
4326 break;
4327
4328 case 0xa56: /* NILH - and immediate */
4329 case 0xa57: /* NILL - and immediate */
4330 case 0xa5a: /* OILH - or immediate */
4331 case 0xa5b: /* OILL - or immediate */
4332 case 0xa7a: /* AHI - add halfword immediate */
4333 /* 32-bit destination + flags */
4334 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4335 return -1;
4336 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4337 return -1;
4338 break;
4339
4340 case 0xa5c: /* LLIHH - load logical immediate */
4341 case 0xa5d: /* LLIHL - load logical immediate */
4342 case 0xa5e: /* LLILH - load logical immediate */
4343 case 0xa5f: /* LLILL - load logical immediate */
4344 case 0xa77: /* BRCTG - branch relative on count */
4345 case 0xa79: /* LGHI - load halfword immediate */
4346 case 0xa7d: /* MGHI - multiply halfword immediate */
4347 /* 64-bit destination */
4348 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
4349 return -1;
4350 break;
4351
4352 case 0xa70: /* TMLH - test under mask */
4353 case 0xa71: /* TMLL - test under mask */
4354 case 0xa72: /* TMHH - test under mask */
4355 case 0xa73: /* TMHL - test under mask */
4356 case 0xa7e: /* CHI - compare halfword immediate */
4357 case 0xa7f: /* CGHI - compare halfword immediate */
4358 /* flags only */
4359 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4360 return -1;
4361 break;
4362
4363 case 0xa74: /* BRC - branch relative on condition */
4364 /* no register change */
4365 break;
4366
4367 case 0xa7b: /* AGHI - add halfword immediate */
4368 /* 64-bit destination + flags */
4369 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
4370 return -1;
4371 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4372 return -1;
4373 break;
4374
4375 default:
4376 goto UNKNOWN_OP;
4377 }
4378 break;
4379
4380 /* 0xa6 undefined */
4381
4382 case 0xa8: /* MVCLE - move long extended [partial] */
4383 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
4384 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4385 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[2] | 1), &tmp);
4386 if (record_full_arch_list_add_mem (oaddr, tmp))
4387 return -1;
4388 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4389 return -1;
4390 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
4391 return -1;
4392 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
4393 return -1;
4394 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
4395 return -1;
4396 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4397 return -1;
4398 break;
4399
4400 /* 0xaa-0xab undefined */
4401 /* 0xac privileged: STNSM - store then and system mask */
4402 /* 0xad privileged: STOSM - store then or system mask */
4403 /* 0xae privileged: SIGP - signal processor */
4404 /* 0xaf unsupported: MC - monitor call */
4405 /* 0xb0 undefined */
4406 /* 0xb1 privileged: LRA - load real address */
4407
4408 case 0xb2:
4409 case 0xb3:
4410 case 0xb9:
4411 /* S/RRD/RRE/RRF/IE-format instruction */
4412 switch (insn[0])
4413 {
4414 /* 0xb200-0xb204 undefined or privileged */
4415
4416 case 0xb205: /* STCK - store clock */
4417 case 0xb27c: /* STCKF - store clock fast */
4418 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4419 if (record_full_arch_list_add_mem (oaddr, 8))
4420 return -1;
4421 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4422 return -1;
4423 break;
4424
4425 /* 0xb206-0xb219 undefined, privileged, or unsupported */
4426 /* 0xb21a unsupported: CFC */
4427 /* 0xb21b-0xb221 undefined or privileged */
4428
4429 case 0xb222: /* IPM - insert program mask */
4430 case 0xb24f: /* EAR - extract access */
4431 case 0xb252: /* MSR - multiply single */
4432 case 0xb2ec: /* ETND - extract transaction nesting depth */
4433 case 0xb38c: /* EFPC - extract fpc */
4434 case 0xb91f: /* LRVR - load reversed */
4435 case 0xb926: /* LBR - load byte */
4436 case 0xb927: /* LHR - load halfword */
4437 case 0xb994: /* LLCR - load logical character */
4438 case 0xb995: /* LLHR - load logical halfword */
4439 case 0xb9f2: /* LOCR - load on condition */
4440 /* 32-bit gpr destination */
4441 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4442 return -1;
4443 break;
4444
4445 /* 0xb223-0xb22c privileged or unsupported */
4446
4447 case 0xb22d: /* DXR - divide */
4448 case 0xb325: /* LXDR - load lengthened */
4449 case 0xb326: /* LXER - load lengthened */
4450 case 0xb336: /* SQXR - square root */
4451 case 0xb365: /* LXR - load */
4452 case 0xb367: /* FIXR - load fp integer */
4453 case 0xb376: /* LZXR - load zero */
4454 case 0xb3b6: /* CXFR - convert from fixed */
4455 case 0xb3c6: /* CXGR - convert from fixed */
4456 case 0xb3fe: /* IEXTR - insert biased exponent */
4457 /* float pair destination */
4458 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4459 return -1;
4460 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
4461 return -1;
4462 break;
4463
4464 /* 0xb22e-0xb240 undefined, privileged, or unsupported */
4465
4466 case 0xb241: /* CKSM - checksum [partial] */
4467 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4468 return -1;
4469 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4470 return -1;
4471 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4472 return -1;
4473 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4474 return -1;
4475 break;
4476
4477 /* 0xb242-0xb243 undefined */
4478
4479 case 0xb244: /* SQDR - square root */
4480 case 0xb245: /* SQER - square root */
4481 case 0xb324: /* LDER - load lengthened */
4482 case 0xb337: /* MEER - multiply */
4483 case 0xb366: /* LEXR - load rounded */
4484 case 0xb370: /* LPDFR - load positive */
4485 case 0xb371: /* LNDFR - load negative */
4486 case 0xb372: /* CSDFR - copy sign */
4487 case 0xb373: /* LCDFR - load complement */
4488 case 0xb374: /* LZER - load zero */
4489 case 0xb375: /* LZDR - load zero */
4490 case 0xb377: /* FIER - load fp integer */
4491 case 0xb37f: /* FIDR - load fp integer */
4492 case 0xb3b4: /* CEFR - convert from fixed */
4493 case 0xb3b5: /* CDFR - convert from fixed */
4494 case 0xb3c1: /* LDGR - load fpr from gr */
4495 case 0xb3c4: /* CEGR - convert from fixed */
4496 case 0xb3c5: /* CDGR - convert from fixed */
4497 case 0xb3f6: /* IEDTR - insert biased exponent */
4498 /* float destination */
4499 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4500 return -1;
4501 break;
4502
4503 /* 0xb246-0xb24c: privileged or unsupported */
4504
4505 case 0xb24d: /* CPYA - copy access */
4506 case 0xb24e: /* SAR - set access */
4507 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[6]))
4508 return -1;
4509 break;
4510
4511 /* 0xb250-0xb251 undefined or privileged */
4512 /* 0xb253-0xb254 undefined or privileged */
4513
4514 case 0xb255: /* MVST - move string [partial] */
4515 {
4516 uint8_t end;
4517 gdb_byte cur;
4518 ULONGEST num = 0;
4519 /* Read ending byte. */
4520 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4521 end = tmp & 0xff;
4522 /* Get address of second operand. */
4523 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[7], &tmp);
4524 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4525 /* Search for ending byte and compute length. */
4526 do {
4527 num++;
4528 if (target_read_memory (oaddr, &cur, 1))
4529 return -1;
4530 oaddr++;
4531 } while (cur != end);
4532 /* Get address of first operand and record it. */
4533 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4534 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4535 if (record_full_arch_list_add_mem (oaddr, num))
4536 return -1;
4537 /* Record the registers. */
4538 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4539 return -1;
4540 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4541 return -1;
4542 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4543 return -1;
4544 }
4545 break;
4546
4547 /* 0xb256 undefined */
4548
4549 case 0xb257: /* CUSE - compare until substring equal [interruptible] */
4550 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4551 return -1;
4552 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4553 return -1;
4554 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4555 return -1;
4556 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4557 return -1;
4558 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4559 return -1;
4560 break;
4561
4562 /* 0xb258-0xb25c undefined, privileged, or unsupported */
4563
4564 case 0xb25d: /* CLST - compare logical string [partial] */
4565 case 0xb25e: /* SRST - search string [partial] */
4566 case 0xb9be: /* SRSTU - search string unicode [partial] */
4567 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4568 return -1;
4569 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4570 return -1;
4571 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4572 return -1;
4573 break;
4574
4575 /* 0xb25f-0xb262 undefined */
4576
4577 case 0xb263: /* CMPSC - compression call [interruptible] */
4578 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4579 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4580 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
4581 if (record_full_arch_list_add_mem (oaddr, tmp))
4582 return -1;
4583 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4584 return -1;
4585 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4586 return -1;
4587 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4588 return -1;
4589 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4590 return -1;
4591 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
4592 return -1;
4593 /* DXC may be written */
4594 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4595 return -1;
4596 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4597 return -1;
4598 break;
4599
4600 /* 0xb264-0xb277 undefined, privileged, or unsupported */
4601
4602 case 0xb278: /* STCKE - store clock extended */
4603 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4604 if (record_full_arch_list_add_mem (oaddr, 16))
4605 return -1;
4606 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4607 return -1;
4608 break;
4609
4610 /* 0xb279-0xb27b undefined or unsupported */
4611 /* 0xb27d-0xb298 undefined or privileged */
4612
4613 case 0xb299: /* SRNM - set rounding mode */
4614 case 0xb2b8: /* SRNMB - set bfp rounding mode */
4615 case 0xb2b9: /* SRNMT - set dfp rounding mode */
4616 case 0xb29d: /* LFPC - load fpc */
4617 case 0xb2bd: /* LFAS - load fpc and signal */
4618 case 0xb384: /* SFPC - set fpc */
4619 case 0xb385: /* SFASR - set fpc and signal */
4620 case 0xb960: /* CGRT - compare and trap */
4621 case 0xb961: /* CLGRT - compare logical and trap */
4622 case 0xb972: /* CRT - compare and trap */
4623 case 0xb973: /* CLRT - compare logical and trap */
4624 /* fpc only - including possible DXC write for trapping insns */
4625 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4626 return -1;
4627 break;
4628
4629 /* 0xb29a-0xb29b undefined */
4630
4631 case 0xb29c: /* STFPC - store fpc */
4632 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4633 if (record_full_arch_list_add_mem (oaddr, 4))
4634 return -1;
4635 break;
4636
4637 /* 0xb29e-0xb2a4 undefined */
4638
4639 case 0xb2a5: /* TRE - translate extended [partial] */
4640 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4641 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4642 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
4643 if (record_full_arch_list_add_mem (oaddr, tmp))
4644 return -1;
4645 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4646 return -1;
4647 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4648 return -1;
4649 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4650 return -1;
4651 break;
4652
4653 case 0xb2a6: /* CU21 - convert UTF-16 to UTF-8 [partial] */
4654 case 0xb2a7: /* CU12 - convert UTF-8 to UTF-16 [partial] */
4655 case 0xb9b0: /* CU14 - convert UTF-8 to UTF-32 [partial] */
4656 case 0xb9b1: /* CU24 - convert UTF-16 to UTF-32 [partial] */
4657 case 0xb9b2: /* CU41 - convert UTF-32 to UTF-8 [partial] */
4658 case 0xb9b3: /* CU42 - convert UTF-32 to UTF-16 [partial] */
4659 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4660 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4661 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
4662 if (record_full_arch_list_add_mem (oaddr, tmp))
4663 return -1;
4664 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4665 return -1;
4666 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4667 return -1;
4668 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4669 return -1;
4670 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4671 return -1;
4672 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4673 return -1;
4674 break;
4675
4676 /* 0xb2a8-0xb2af undefined */
4677
4678 case 0xb2b0: /* STFLE - store facility list extended */
4679 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4680 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4681 tmp &= 0xff;
4682 if (record_full_arch_list_add_mem (oaddr, 8 * (tmp + 1)))
4683 return -1;
4684 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM))
4685 return -1;
4686 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4687 return -1;
4688 break;
4689
4690 /* 0xb2b1-0xb2b7 undefined or privileged */
4691 /* 0xb2ba-0xb2bc undefined */
4692 /* 0xb2be-0xb2e7 undefined */
4693 /* 0xb2e9-0xb2eb undefined */
4694 /* 0xb2ed-0xb2f7 undefined */
4695 /* 0xb2f8 unsupported: TEND */
4696 /* 0xb2f9 undefined */
4697
4698 case 0xb2e8: /* PPA - perform processor assist */
4699 case 0xb2fa: /* NIAI - next instruction access intent */
4700 /* no visible effects */
4701 break;
4702
4703 /* 0xb2fb undefined */
4704 /* 0xb2fc unsupported: TABORT */
4705 /* 0xb2fd-0xb2fe undefined */
4706 /* 0xb2ff unsupported: TRAP */
4707
4708 case 0xb300: /* LPEBR - load positive */
4709 case 0xb301: /* LNEBR - load negative */
4710 case 0xb303: /* LCEBR - load complement */
4711 case 0xb310: /* LPDBR - load positive */
4712 case 0xb311: /* LNDBR - load negative */
4713 case 0xb313: /* LCDBR - load complement */
4714 case 0xb350: /* TBEDR - convert hfp to bfp */
4715 case 0xb351: /* TBDR - convert hfp to bfp */
4716 case 0xb358: /* THDER - convert bfp to hfp */
4717 case 0xb359: /* THDR - convert bfp to hfp */
4718 /* float destination + flags */
4719 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4720 return -1;
4721 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4722 return -1;
4723 break;
4724
4725 case 0xb304: /* LDEBR - load lengthened */
4726 case 0xb30c: /* MDEBR - multiply */
4727 case 0xb30d: /* DEBR - divide */
4728 case 0xb314: /* SQEBR - square root */
4729 case 0xb315: /* SQDBR - square root */
4730 case 0xb317: /* MEEBR - multiply */
4731 case 0xb31c: /* MDBR - multiply */
4732 case 0xb31d: /* DDBR - divide */
4733 case 0xb344: /* LEDBRA - load rounded */
4734 case 0xb345: /* LDXBRA - load rounded */
4735 case 0xb346: /* LEXBRA - load rounded */
4736 case 0xb357: /* FIEBRA - load fp integer */
4737 case 0xb35f: /* FIDBRA - load fp integer */
4738 case 0xb390: /* CELFBR - convert from logical */
4739 case 0xb391: /* CDLFBR - convert from logical */
4740 case 0xb394: /* CEFBR - convert from fixed */
4741 case 0xb395: /* CDFBR - convert from fixed */
4742 case 0xb3a0: /* CELGBR - convert from logical */
4743 case 0xb3a1: /* CDLGBR - convert from logical */
4744 case 0xb3a4: /* CEGBR - convert from fixed */
4745 case 0xb3a5: /* CDGBR - convert from fixed */
4746 case 0xb3d0: /* MDTR - multiply */
4747 case 0xb3d1: /* DDTR - divide */
4748 case 0xb3d4: /* LDETR - load lengthened */
4749 case 0xb3d5: /* LEDTR - load lengthened */
4750 case 0xb3d7: /* FIDTR - load fp integer */
4751 case 0xb3dd: /* LDXTR - load lengthened */
4752 case 0xb3f1: /* CDGTR - convert from fixed */
4753 case 0xb3f2: /* CDUTR - convert from unsigned packed */
4754 case 0xb3f3: /* CDSTR - convert from signed packed */
4755 case 0xb3f5: /* QADTR - quantize */
4756 case 0xb3f7: /* RRDTR - reround */
4757 case 0xb951: /* CDFTR - convert from fixed */
4758 case 0xb952: /* CDLGTR - convert from logical */
4759 case 0xb953: /* CDLFTR - convert from logical */
4760 /* float destination + fpc */
4761 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4762 return -1;
4763 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4764 return -1;
4765 break;
4766
4767 case 0xb305: /* LXDBR - load lengthened */
4768 case 0xb306: /* LXEBR - load lengthened */
4769 case 0xb307: /* MXDBR - multiply */
4770 case 0xb316: /* SQXBR - square root */
4771 case 0xb34c: /* MXBR - multiply */
4772 case 0xb34d: /* DXBR - divide */
4773 case 0xb347: /* FIXBRA - load fp integer */
4774 case 0xb392: /* CXLFBR - convert from logical */
4775 case 0xb396: /* CXFBR - convert from fixed */
4776 case 0xb3a2: /* CXLGBR - convert from logical */
4777 case 0xb3a6: /* CXGBR - convert from fixed */
4778 case 0xb3d8: /* MXTR - multiply */
4779 case 0xb3d9: /* DXTR - divide */
4780 case 0xb3dc: /* LXDTR - load lengthened */
4781 case 0xb3df: /* FIXTR - load fp integer */
4782 case 0xb3f9: /* CXGTR - convert from fixed */
4783 case 0xb3fa: /* CXUTR - convert from unsigned packed */
4784 case 0xb3fb: /* CXSTR - convert from signed packed */
4785 case 0xb3fd: /* QAXTR - quantize */
4786 case 0xb3ff: /* RRXTR - reround */
4787 case 0xb959: /* CXFTR - convert from fixed */
4788 case 0xb95a: /* CXLGTR - convert from logical */
4789 case 0xb95b: /* CXLFTR - convert from logical */
4790 /* float pair destination + fpc */
4791 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4792 return -1;
4793 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
4794 return -1;
4795 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4796 return -1;
4797 break;
4798
4799 case 0xb308: /* KEBR - compare and signal */
4800 case 0xb309: /* CEBR - compare */
4801 case 0xb318: /* KDBR - compare and signal */
4802 case 0xb319: /* CDBR - compare */
4803 case 0xb348: /* KXBR - compare and signal */
4804 case 0xb349: /* CXBR - compare */
4805 case 0xb3e0: /* KDTR - compare and signal */
4806 case 0xb3e4: /* CDTR - compare */
4807 case 0xb3e8: /* KXTR - compare and signal */
4808 case 0xb3ec: /* CXTR - compare */
4809 /* flags + fpc only */
4810 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4811 return -1;
4812 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4813 return -1;
4814 break;
4815
4816 case 0xb302: /* LTEBR - load and test */
4817 case 0xb312: /* LTDBR - load and test */
4818 case 0xb30a: /* AEBR - add */
4819 case 0xb30b: /* SEBR - subtract */
4820 case 0xb31a: /* ADBR - add */
4821 case 0xb31b: /* SDBR - subtract */
4822 case 0xb3d2: /* ADTR - add */
4823 case 0xb3d3: /* SDTR - subtract */
4824 case 0xb3d6: /* LTDTR - load and test */
4825 /* float destination + flags + fpc */
4826 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4827 return -1;
4828 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4829 return -1;
4830 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4831 return -1;
4832 break;
4833
4834 case 0xb30e: /* MAEBR - multiply and add */
4835 case 0xb30f: /* MSEBR - multiply and subtract */
4836 case 0xb31e: /* MADBR - multiply and add */
4837 case 0xb31f: /* MSDBR - multiply and subtract */
4838 /* float destination [RRD] + fpc */
4839 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4840 return -1;
4841 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4842 return -1;
4843 break;
4844
4845 /* 0xb320-0xb323 undefined */
4846 /* 0xb327-0xb32d undefined */
4847
4848 case 0xb32e: /* MAER - multiply and add */
4849 case 0xb32f: /* MSER - multiply and subtract */
4850 case 0xb338: /* MAYLR - multiply and add unnormalized */
4851 case 0xb339: /* MYLR - multiply unnormalized */
4852 case 0xb33c: /* MAYHR - multiply and add unnormalized */
4853 case 0xb33d: /* MYHR - multiply unnormalized */
4854 case 0xb33e: /* MADR - multiply and add */
4855 case 0xb33f: /* MSDR - multiply and subtract */
4856 /* float destination [RRD] */
4857 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4858 return -1;
4859 break;
4860
4861 /* 0xb330-0xb335 undefined */
4862
4863 case 0xb33a: /* MAYR - multiply and add unnormalized */
4864 case 0xb33b: /* MYR - multiply unnormalized */
4865 /* float pair destination [RRD] */
4866 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4867 return -1;
4868 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[4] | 2)))
4869 return -1;
4870 break;
4871
4872 case 0xb340: /* LPXBR - load positive */
4873 case 0xb341: /* LNXBR - load negative */
4874 case 0xb343: /* LCXBR - load complement */
4875 case 0xb360: /* LPXR - load positive */
4876 case 0xb361: /* LNXR - load negative */
4877 case 0xb362: /* LTXR - load and test */
4878 case 0xb363: /* LCXR - load complement */
4879 /* float pair destination + flags */
4880 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4881 return -1;
4882 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
4883 return -1;
4884 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4885 return -1;
4886 break;
4887
4888 case 0xb342: /* LTXBR - load and test */
4889 case 0xb34a: /* AXBR - add */
4890 case 0xb34b: /* SXBR - subtract */
4891 case 0xb3da: /* AXTR - add */
4892 case 0xb3db: /* SXTR - subtract */
4893 case 0xb3de: /* LTXTR - load and test */
4894 /* float pair destination + flags + fpc */
4895 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4896 return -1;
4897 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
4898 return -1;
4899 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4900 return -1;
4901 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4902 return -1;
4903 break;
4904
4905 /* 0xb34e-0xb34f undefined */
4906 /* 0xb352 undefined */
4907
4908 case 0xb353: /* DIEBR - divide to integer */
4909 case 0xb35b: /* DIDBR - divide to integer */
4910 /* two float destinations + flags + fpc */
4911 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4912 return -1;
4913 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4914 return -1;
4915 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4916 return -1;
4917 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4918 return -1;
4919 break;
4920
4921 /* 0xb354-0xb356 undefined */
4922 /* 0xb35a undefined */
4923
4924 /* 0xb35c-0xb35e undefined */
4925 /* 0xb364 undefined */
4926 /* 0xb368 undefined */
4927
4928 case 0xb369: /* CXR - compare */
4929 case 0xb3f4: /* CEDTR - compare biased exponent */
4930 case 0xb3fc: /* CEXTR - compare biased exponent */
4931 case 0xb920: /* CGR - compare */
4932 case 0xb921: /* CLGR - compare logical */
4933 case 0xb930: /* CGFR - compare */
4934 case 0xb931: /* CLGFR - compare logical */
4935 case 0xb9cd: /* CHHR - compare high */
4936 case 0xb9cf: /* CLHHR - compare logical high */
4937 case 0xb9dd: /* CHLR - compare high */
4938 case 0xb9df: /* CLHLR - compare logical high */
4939 /* flags only */
4940 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4941 return -1;
4942 break;
4943
4944 /* 0xb36a-0xb36f undefined */
4945 /* 0xb377-0xb37e undefined */
4946 /* 0xb380-0xb383 undefined */
4947 /* 0xb386-0xb38b undefined */
4948 /* 0xb38d-0xb38f undefined */
4949 /* 0xb393 undefined */
4950 /* 0xb397 undefined */
4951
4952 case 0xb398: /* CFEBR - convert to fixed */
4953 case 0xb399: /* CFDBR - convert to fixed */
4954 case 0xb39a: /* CFXBR - convert to fixed */
4955 case 0xb39c: /* CLFEBR - convert to logical */
4956 case 0xb39d: /* CLFDBR - convert to logical */
4957 case 0xb39e: /* CLFXBR - convert to logical */
4958 case 0xb941: /* CFDTR - convert to fixed */
4959 case 0xb949: /* CFXTR - convert to fixed */
4960 case 0xb943: /* CLFDTR - convert to logical */
4961 case 0xb94b: /* CLFXTR - convert to logical */
4962 /* 32-bit gpr destination + flags + fpc */
4963 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4964 return -1;
4965 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4966 return -1;
4967 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4968 return -1;
4969 break;
4970
4971 /* 0xb39b undefined */
4972 /* 0xb39f undefined */
4973
4974 /* 0xb3a3 undefined */
4975 /* 0xb3a7 undefined */
4976
4977 case 0xb3a8: /* CGEBR - convert to fixed */
4978 case 0xb3a9: /* CGDBR - convert to fixed */
4979 case 0xb3aa: /* CGXBR - convert to fixed */
4980 case 0xb3ac: /* CLGEBR - convert to logical */
4981 case 0xb3ad: /* CLGDBR - convert to logical */
4982 case 0xb3ae: /* CLGXBR - convert to logical */
4983 case 0xb3e1: /* CGDTR - convert to fixed */
4984 case 0xb3e9: /* CGXTR - convert to fixed */
4985 case 0xb942: /* CLGDTR - convert to logical */
4986 case 0xb94a: /* CLGXTR - convert to logical */
4987 /* 64-bit gpr destination + flags + fpc */
4988 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
4989 return -1;
4990 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4991 return -1;
4992 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4993 return -1;
4994 break;
4995
4996 /* 0xb3ab undefined */
4997 /* 0xb3af-0xb3b3 undefined */
4998 /* 0xb3b7 undefined */
4999
5000 case 0xb3b8: /* CFER - convert to fixed */
5001 case 0xb3b9: /* CFDR - convert to fixed */
5002 case 0xb3ba: /* CFXR - convert to fixed */
5003 case 0xb998: /* ALCR - add logical with carry */
5004 case 0xb999: /* SLBR - subtract logical with borrow */
5005 case 0xb9f4: /* NRK - and */
5006 case 0xb9f6: /* ORK - or */
5007 case 0xb9f7: /* XRK - xor */
5008 case 0xb9f8: /* ARK - add */
5009 case 0xb9f9: /* SRK - subtract */
5010 case 0xb9fa: /* ALRK - add logical */
5011 case 0xb9fb: /* SLRK - subtract logical */
5012 /* 32-bit gpr destination + flags */
5013 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5014 return -1;
5015 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5016 return -1;
5017 break;
5018
5019 case 0xb3c8: /* CGER - convert to fixed */
5020 case 0xb3c9: /* CGDR - convert to fixed */
5021 case 0xb3ca: /* CGXR - convert to fixed */
5022 case 0xb900: /* LPGR - load positive */
5023 case 0xb901: /* LNGR - load negative */
5024 case 0xb902: /* LTGR - load and test */
5025 case 0xb903: /* LCGR - load complement */
5026 case 0xb908: /* AGR - add */
5027 case 0xb909: /* SGR - subtract */
5028 case 0xb90a: /* ALGR - add logical */
5029 case 0xb90b: /* SLGR - subtract logical */
5030 case 0xb910: /* LPGFR - load positive */
5031 case 0xb911: /* LNGFR - load negative */
5032 case 0xb912: /* LTGFR - load and test */
5033 case 0xb913: /* LCGFR - load complement */
5034 case 0xb918: /* AGFR - add */
5035 case 0xb919: /* SGFR - subtract */
5036 case 0xb91a: /* ALGFR - add logical */
5037 case 0xb91b: /* SLGFR - subtract logical */
5038 case 0xb980: /* NGR - and */
5039 case 0xb981: /* OGR - or */
5040 case 0xb982: /* XGR - xor */
5041 case 0xb988: /* ALCGR - add logical with carry */
5042 case 0xb989: /* SLBGR - subtract logical with borrow */
5043 case 0xb9e1: /* POPCNT - population count */
5044 case 0xb9e4: /* NGRK - and */
5045 case 0xb9e6: /* OGRK - or */
5046 case 0xb9e7: /* XGRK - xor */
5047 case 0xb9e8: /* AGRK - add */
5048 case 0xb9e9: /* SGRK - subtract */
5049 case 0xb9ea: /* ALGRK - add logical */
5050 case 0xb9eb: /* SLGRK - subtract logical */
5051 case 0xb9ed: /* MSGRKC - multiply single 64x64 -> 64 */
5052 case 0xb9fd: /* MSRKC - multiply single 32x32 -> 32 */
5053 /* 64-bit gpr destination + flags */
5054 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
5055 return -1;
5056 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5057 return -1;
5058 break;
5059
5060 /* 0xb3bb-0xb3c0 undefined */
5061 /* 0xb3c2-0xb3c3 undefined */
5062 /* 0xb3c7 undefined */
5063 /* 0xb3cb-0xb3cc undefined */
5064
5065 case 0xb3cd: /* LGDR - load gr from fpr */
5066 case 0xb3e2: /* CUDTR - convert to unsigned packed */
5067 case 0xb3e3: /* CSDTR - convert to signed packed */
5068 case 0xb3e5: /* EEDTR - extract biased exponent */
5069 case 0xb3e7: /* ESDTR - extract significance */
5070 case 0xb3ed: /* EEXTR - extract biased exponent */
5071 case 0xb3ef: /* ESXTR - extract significance */
5072 case 0xb904: /* LGR - load */
5073 case 0xb906: /* LGBR - load byte */
5074 case 0xb907: /* LGHR - load halfword */
5075 case 0xb90c: /* MSGR - multiply single */
5076 case 0xb90f: /* LRVGR - load reversed */
5077 case 0xb914: /* LGFR - load */
5078 case 0xb916: /* LLGFR - load logical */
5079 case 0xb917: /* LLGTR - load logical thirty one bits */
5080 case 0xb91c: /* MSGFR - multiply single 64<32 */
5081 case 0xb946: /* BCTGR - branch on count */
5082 case 0xb984: /* LLGCR - load logical character */
5083 case 0xb985: /* LLGHR - load logical halfword */
5084 case 0xb9e2: /* LOCGR - load on condition */
5085 /* 64-bit gpr destination */
5086 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
5087 return -1;
5088 break;
5089
5090 /* 0xb3ce-0xb3cf undefined */
5091 /* 0xb3e6 undefined */
5092
5093 case 0xb3ea: /* CUXTR - convert to unsigned packed */
5094 case 0xb3eb: /* CSXTR - convert to signed packed */
5095 case 0xb90d: /* DSGR - divide single */
5096 case 0xb91d: /* DSGFR - divide single */
5097 case 0xb986: /* MLGR - multiply logical */
5098 case 0xb987: /* DLGR - divide logical */
5099 case 0xb9ec: /* MGRK - multiply 64x64 -> 128 */
5100 /* 64-bit gpr pair destination */
5101 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
5102 return -1;
5103 if (s390_record_gpr_g (gdbarch, regcache, inib[6] | 1))
5104 return -1;
5105 break;
5106
5107 /* 0xb3ee undefined */
5108 /* 0xb3f0 undefined */
5109 /* 0xb3f8 undefined */
5110
5111 /* 0xb905 privileged */
5112
5113 /* 0xb90e unsupported: EREGG */
5114
5115 /* 0xb915 undefined */
5116
5117 case 0xb91e: /* KMAC - compute message authentication code [partial] */
5118 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5119 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5120 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5121 tmp &= 0xff;
5122 switch (tmp)
5123 {
5124 case 0x00: /* KMAC-Query */
5125 if (record_full_arch_list_add_mem (oaddr, 16))
5126 return -1;
5127 break;
5128
5129 case 0x01: /* KMAC-DEA */
5130 case 0x02: /* KMAC-TDEA-128 */
5131 case 0x03: /* KMAC-TDEA-192 */
5132 case 0x09: /* KMAC-Encrypted-DEA */
5133 case 0x0a: /* KMAC-Encrypted-TDEA-128 */
5134 case 0x0b: /* KMAC-Encrypted-TDEA-192 */
5135 if (record_full_arch_list_add_mem (oaddr, 8))
5136 return -1;
5137 break;
5138
5139 case 0x12: /* KMAC-AES-128 */
5140 case 0x13: /* KMAC-AES-192 */
5141 case 0x14: /* KMAC-AES-256 */
5142 case 0x1a: /* KMAC-Encrypted-AES-128 */
5143 case 0x1b: /* KMAC-Encrypted-AES-192 */
5144 case 0x1c: /* KMAC-Encrypted-AES-256 */
5145 if (record_full_arch_list_add_mem (oaddr, 16))
5146 return -1;
5147 break;
5148
5149 default:
5150 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown KMAC function %02x at %s.\n",
5151 (int)tmp, paddress (gdbarch, addr));
5152 return -1;
5153 }
5154 if (tmp != 0)
5155 {
5156 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5157 return -1;
5158 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
5159 return -1;
5160 }
5161 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5162 return -1;
5163 break;
5164
5165 /* 0xb922-0xb924 undefined */
5166 /* 0xb925 privileged */
5167 /* 0xb928 privileged */
5168
5169 case 0xb929: /* KMA - cipher message with authentication */
5170 case 0xb92a: /* KMF - cipher message with cipher feedback [partial] */
5171 case 0xb92b: /* KMO - cipher message with output feedback [partial] */
5172 case 0xb92f: /* KMC - cipher message with chaining [partial] */
5173 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5174 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5175 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5176 tmp &= 0x7f;
5177 switch (tmp)
5178 {
5179 case 0x00: /* KM*-Query */
5180 if (record_full_arch_list_add_mem (oaddr, 16))
5181 return -1;
5182 break;
5183
5184 case 0x01: /* KM*-DEA */
5185 case 0x02: /* KM*-TDEA-128 */
5186 case 0x03: /* KM*-TDEA-192 */
5187 case 0x09: /* KM*-Encrypted-DEA */
5188 case 0x0a: /* KM*-Encrypted-TDEA-128 */
5189 case 0x0b: /* KM*-Encrypted-TDEA-192 */
5190 if (record_full_arch_list_add_mem (oaddr, 8))
5191 return -1;
5192 break;
5193
5194 case 0x12: /* KM*-AES-128 */
5195 case 0x13: /* KM*-AES-192 */
5196 case 0x14: /* KM*-AES-256 */
5197 case 0x1a: /* KM*-Encrypted-AES-128 */
5198 case 0x1b: /* KM*-Encrypted-AES-192 */
5199 case 0x1c: /* KM*-Encrypted-AES-256 */
5200 if (record_full_arch_list_add_mem (oaddr, 16))
5201 return -1;
5202 break;
5203
5204 case 0x43: /* KMC-PRNG */
5205 /* Only valid for KMC. */
5206 if (insn[0] == 0xb92f)
5207 {
5208 if (record_full_arch_list_add_mem (oaddr, 8))
5209 return -1;
5210 break;
5211 }
5212 /* For other instructions, fallthru. */
5213 default:
5214 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown KM* function %02x at %s.\n",
5215 (int)tmp, paddress (gdbarch, addr));
5216 return -1;
5217 }
5218 if (tmp != 0)
5219 {
5220 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
5221 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
5222 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[7] | 1), &tmp);
5223 if (record_full_arch_list_add_mem (oaddr2, tmp))
5224 return -1;
5225 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5226 return -1;
5227 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5228 return -1;
5229 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
5230 return -1;
5231 }
5232 if (tmp != 0 && insn[0] == 0xb929)
5233 {
5234 if (record_full_arch_list_add_reg (regcache,
5235 S390_R0_REGNUM + inib[4]))
5236 return -1;
5237 if (record_full_arch_list_add_reg (regcache,
5238 S390_R0_REGNUM + (inib[4] | 1)))
5239 return -1;
5240 }
5241 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5242 return -1;
5243 break;
5244
5245 case 0xb92c: /* PCC - perform cryptographic computation [partial] */
5246 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5247 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5248 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5249 tmp &= 0x7f;
5250 switch (tmp)
5251 {
5252 case 0x00: /* PCC-Query */
5253 if (record_full_arch_list_add_mem (oaddr, 16))
5254 return -1;
5255 break;
5256
5257 case 0x01: /* PCC-Compute-Last-Block-CMAC-Using-DEA */
5258 case 0x02: /* PCC-Compute-Last-Block-CMAC-Using-TDEA-128 */
5259 case 0x03: /* PCC-Compute-Last-Block-CMAC-Using-TDEA-192 */
5260 case 0x09: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-DEA */
5261 case 0x0a: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-TDEA-128 */
5262 case 0x0b: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-TDEA-192 */
5263 if (record_full_arch_list_add_mem (oaddr + 0x10, 8))
5264 return -1;
5265 break;
5266
5267 case 0x12: /* PCC-Compute-Last-Block-CMAC-Using-AES-128 */
5268 case 0x13: /* PCC-Compute-Last-Block-CMAC-Using-AES-192 */
5269 case 0x14: /* PCC-Compute-Last-Block-CMAC-Using-AES-256 */
5270 case 0x1a: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-AES-128 */
5271 case 0x1b: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-AES-192 */
5272 case 0x1c: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-AES-256 */
5273 if (record_full_arch_list_add_mem (oaddr + 0x18, 16))
5274 return -1;
5275 break;
5276
5277 case 0x32: /* PCC-Compute-XTS-Parameter-Using-AES-128 */
5278 if (record_full_arch_list_add_mem (oaddr + 0x30, 32))
5279 return -1;
5280 break;
5281
5282 case 0x34: /* PCC-Compute-XTS-Parameter-Using-AES-256 */
5283 if (record_full_arch_list_add_mem (oaddr + 0x40, 32))
5284 return -1;
5285 break;
5286
5287 case 0x3a: /* PCC-Compute-XTS-Parameter-Using-Encrypted-AES-128 */
5288 if (record_full_arch_list_add_mem (oaddr + 0x50, 32))
5289 return -1;
5290 break;
5291
5292 case 0x3c: /* PCC-Compute-XTS-Parameter-Using-Encrypted-AES-256 */
5293 if (record_full_arch_list_add_mem (oaddr + 0x60, 32))
5294 return -1;
5295 break;
5296
5297 default:
5298 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown PCC function %02x at %s.\n",
5299 (int)tmp, paddress (gdbarch, addr));
5300 return -1;
5301 }
5302 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5303 return -1;
5304 break;
5305
5306 case 0xb92d: /* KMCTR - cipher message with counter [partial] */
5307 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5308 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5309 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5310 tmp &= 0x7f;
5311 switch (tmp)
5312 {
5313 case 0x00: /* KMCTR-Query */
5314 if (record_full_arch_list_add_mem (oaddr, 16))
5315 return -1;
5316 break;
5317
5318 case 0x01: /* KMCTR-DEA */
5319 case 0x02: /* KMCTR-TDEA-128 */
5320 case 0x03: /* KMCTR-TDEA-192 */
5321 case 0x09: /* KMCTR-Encrypted-DEA */
5322 case 0x0a: /* KMCTR-Encrypted-TDEA-128 */
5323 case 0x0b: /* KMCTR-Encrypted-TDEA-192 */
5324 case 0x12: /* KMCTR-AES-128 */
5325 case 0x13: /* KMCTR-AES-192 */
5326 case 0x14: /* KMCTR-AES-256 */
5327 case 0x1a: /* KMCTR-Encrypted-AES-128 */
5328 case 0x1b: /* KMCTR-Encrypted-AES-192 */
5329 case 0x1c: /* KMCTR-Encrypted-AES-256 */
5330 break;
5331
5332 default:
5333 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown KMCTR function %02x at %s.\n",
5334 (int)tmp, paddress (gdbarch, addr));
5335 return -1;
5336 }
5337 if (tmp != 0)
5338 {
5339 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
5340 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
5341 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[7] | 1), &tmp);
5342 if (record_full_arch_list_add_mem (oaddr2, tmp))
5343 return -1;
5344 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5345 return -1;
5346 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5347 return -1;
5348 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
5349 return -1;
5350 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[4]))
5351 return -1;
5352 }
5353 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5354 return -1;
5355 break;
5356
5357 case 0xb92e: /* KM - cipher message [partial] */
5358 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5359 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5360 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5361 tmp &= 0x7f;
5362 switch (tmp)
5363 {
5364 case 0x00: /* KM-Query */
5365 if (record_full_arch_list_add_mem (oaddr, 16))
5366 return -1;
5367 break;
5368
5369 case 0x01: /* KM-DEA */
5370 case 0x02: /* KM-TDEA-128 */
5371 case 0x03: /* KM-TDEA-192 */
5372 case 0x09: /* KM-Encrypted-DEA */
5373 case 0x0a: /* KM-Encrypted-TDEA-128 */
5374 case 0x0b: /* KM-Encrypted-TDEA-192 */
5375 case 0x12: /* KM-AES-128 */
5376 case 0x13: /* KM-AES-192 */
5377 case 0x14: /* KM-AES-256 */
5378 case 0x1a: /* KM-Encrypted-AES-128 */
5379 case 0x1b: /* KM-Encrypted-AES-192 */
5380 case 0x1c: /* KM-Encrypted-AES-256 */
5381 break;
5382
5383 case 0x32: /* KM-XTS-AES-128 */
5384 if (record_full_arch_list_add_mem (oaddr + 0x10, 16))
5385 return -1;
5386 break;
5387
5388 case 0x34: /* KM-XTS-AES-256 */
5389 if (record_full_arch_list_add_mem (oaddr + 0x20, 16))
5390 return -1;
5391 break;
5392
5393 case 0x3a: /* KM-XTS-Encrypted-AES-128 */
5394 if (record_full_arch_list_add_mem (oaddr + 0x30, 16))
5395 return -1;
5396 break;
5397
5398 case 0x3c: /* KM-XTS-Encrypted-AES-256 */
5399 if (record_full_arch_list_add_mem (oaddr + 0x40, 16))
5400 return -1;
5401 break;
5402
5403 default:
5404 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown KM function %02x at %s.\n",
5405 (int)tmp, paddress (gdbarch, addr));
5406 return -1;
5407 }
5408 if (tmp != 0)
5409 {
5410 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
5411 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
5412 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[7] | 1), &tmp);
5413 if (record_full_arch_list_add_mem (oaddr2, tmp))
5414 return -1;
5415 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5416 return -1;
5417 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5418 return -1;
5419 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
5420 return -1;
5421 }
5422 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5423 return -1;
5424 break;
5425
5426 /* 0xb932-0xb93b undefined */
5427
5428 case 0xb93c: /* PPNO - perform pseudorandom number operation [partial] */
5429 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5430 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5431 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5432 tmp &= 0xff;
5433 switch (tmp)
5434 {
5435 case 0x00: /* PPNO-Query */
5436 case 0x80: /* PPNO-Query */
5437 if (record_full_arch_list_add_mem (oaddr, 16))
5438 return -1;
5439 break;
5440
5441 case 0x03: /* PPNO-SHA-512-DRNG - generate */
5442 if (record_full_arch_list_add_mem (oaddr, 240))
5443 return -1;
5444 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
5445 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
5446 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
5447 if (record_full_arch_list_add_mem (oaddr2, tmp))
5448 return -1;
5449 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5450 return -1;
5451 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
5452 return -1;
5453 break;
5454
5455 case 0x83: /* PPNO-SHA-512-DRNG - seed */
5456 if (record_full_arch_list_add_mem (oaddr, 240))
5457 return -1;
5458 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5459 return -1;
5460 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
5461 return -1;
5462 break;
5463
5464 default:
5465 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown PPNO function %02x at %s.\n",
5466 (int)tmp, paddress (gdbarch, addr));
5467 return -1;
5468 }
5469 /* DXC may be written */
5470 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5471 return -1;
5472 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5473 return -1;
5474 break;
5475
5476 /* 0xb93d undefined */
5477
5478 case 0xb93e: /* KIMD - compute intermediate message digest [partial] */
5479 case 0xb93f: /* KLMD - compute last message digest [partial] */
5480 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
5481 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5482 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5483 tmp &= 0xff;
5484 switch (tmp)
5485 {
5486 case 0x00: /* K*MD-Query */
5487 if (record_full_arch_list_add_mem (oaddr, 16))
5488 return -1;
5489 break;
5490
5491 case 0x01: /* K*MD-SHA-1 */
5492 if (record_full_arch_list_add_mem (oaddr, 20))
5493 return -1;
5494 break;
5495
5496 case 0x02: /* K*MD-SHA-256 */
5497 if (record_full_arch_list_add_mem (oaddr, 32))
5498 return -1;
5499 break;
5500
5501 case 0x03: /* K*MD-SHA-512 */
5502 if (record_full_arch_list_add_mem (oaddr, 64))
5503 return -1;
5504 break;
5505
5506 case 0x41: /* KIMD-GHASH */
5507 /* Only valid for KIMD. */
5508 if (insn[0] == 0xb93e)
5509 {
5510 if (record_full_arch_list_add_mem (oaddr, 16))
5511 return -1;
5512 break;
5513 }
5514 /* For KLMD, fallthru. */
5515 default:
5516 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown KMAC function %02x at %s.\n",
5517 (int)tmp, paddress (gdbarch, addr));
5518 return -1;
5519 }
5520 if (tmp != 0)
5521 {
5522 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5523 return -1;
5524 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
5525 return -1;
5526 }
5527 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5528 return -1;
5529 break;
5530
5531 /* 0xb940 undefined */
5532 /* 0xb944-0xb945 undefined */
5533 /* 0xb947-0xb948 undefined */
5534 /* 0xb94c-0xb950 undefined */
5535 /* 0xb954-0xb958 undefined */
5536 /* 0xb95c-0xb95f undefined */
5537 /* 0xb962-0xb971 undefined */
5538 /* 0xb974-0xb97f undefined */
5539
5540 case 0xb983: /* FLOGR - find leftmost one */
5541 /* 64-bit gpr pair destination + flags */
5542 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
5543 return -1;
5544 if (s390_record_gpr_g (gdbarch, regcache, inib[6] | 1))
5545 return -1;
5546 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5547 return -1;
5548 break;
5549
5550 /* 0xb98a privileged */
5551 /* 0xb98b-0xb98c undefined */
5552
5553 case 0xb98d: /* EPSW - extract psw */
5554 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5555 return -1;
5556 if (inib[7])
5557 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5558 return -1;
5559 break;
5560
5561 /* 0xb98e-0xb98f privileged */
5562
5563 case 0xb990: /* TRTT - translate two to two [partial] */
5564 case 0xb991: /* TRTO - translate two to one [partial] */
5565 case 0xb992: /* TROT - translate one to two [partial] */
5566 case 0xb993: /* TROO - translate one to one [partial] */
5567 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
5568 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
5569 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
5570 /* tmp is source length, we want destination length. Adjust. */
5571 if (insn[0] == 0xb991)
5572 tmp >>= 1;
5573 if (insn[0] == 0xb992)
5574 tmp <<= 1;
5575 if (record_full_arch_list_add_mem (oaddr, tmp))
5576 return -1;
5577 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5578 return -1;
5579 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
5580 return -1;
5581 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5582 return -1;
5583 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5584 return -1;
5585 break;
5586
5587 case 0xb996: /* MLR - multiply logical */
5588 case 0xb997: /* DLR - divide logical */
5589 /* 32-bit gpr pair destination */
5590 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5591 return -1;
5592 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
5593 return -1;
5594 break;
5595
5596 /* 0xb99a-0xb9af unsupported, privileged, or undefined */
5597 /* 0xb9b4-0xb9bc undefined */
5598
5599 case 0xb9bd: /* TRTRE - translate and test reverse extended [partial] */
5600 case 0xb9bf: /* TRTE - translate and test extended [partial] */
5601 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
5602 return -1;
5603 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
5604 return -1;
5605 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
5606 return -1;
5607 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5608 return -1;
5609 break;
5610
5611 /* 0xb9c0-0xb9c7 undefined */
5612
5613 case 0xb9c8: /* AHHHR - add high */
5614 case 0xb9c9: /* SHHHR - subtract high */
5615 case 0xb9ca: /* ALHHHR - add logical high */
5616 case 0xb9cb: /* SLHHHR - subtract logical high */
5617 case 0xb9d8: /* AHHLR - add high */
5618 case 0xb9d9: /* SHHLR - subtract high */
5619 case 0xb9da: /* ALHHLR - add logical high */
5620 case 0xb9db: /* SLHHLR - subtract logical high */
5621 /* 32-bit high gpr destination + flags */
5622 if (s390_record_gpr_h (gdbarch, regcache, inib[6]))
5623 return -1;
5624 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5625 return -1;
5626 break;
5627
5628 /* 0xb9cc undefined */
5629 /* 0xb9ce undefined */
5630 /* 0xb9d0-0xb9d7 undefined */
5631 /* 0xb9dc undefined */
5632 /* 0xb9de undefined */
5633
5634 case 0xb9e0: /* LOCFHR - load high on condition */
5635 /* 32-bit high gpr destination */
5636 if (s390_record_gpr_h (gdbarch, regcache, inib[6]))
5637 return -1;
5638 break;
5639
5640 /* 0xb9e3 undefined */
5641 /* 0xb9e5 undefined */
5642 /* 0xb9ee-0xb9f1 undefined */
5643 /* 0xb9f3 undefined */
5644 /* 0xb9f5 undefined */
5645 /* 0xb9fc undefined */
5646 /* 0xb9fe -0xb9ff undefined */
5647
5648 default:
5649 goto UNKNOWN_OP;
5650 }
5651 break;
5652
5653 /* 0xb4-0xb5 undefined */
5654 /* 0xb6 privileged: STCTL - store control */
5655 /* 0xb7 privileged: LCTL - load control */
5656 /* 0xb8 undefined */
5657
5658 case 0xba: /* CS - compare and swap */
5659 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5660 if (record_full_arch_list_add_mem (oaddr, 4))
5661 return -1;
5662 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5663 return -1;
5664 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5665 return -1;
5666 break;
5667
5668 case 0xbb: /* CDS - compare double and swap */
5669 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5670 if (record_full_arch_list_add_mem (oaddr, 8))
5671 return -1;
5672 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5673 return -1;
5674 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
5675 return -1;
5676 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5677 return -1;
5678 break;
5679
5680 /* 0xbc undefined */
5681
5682 case 0xbe: /* STCM - store characters under mask */
5683 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5684 if (record_full_arch_list_add_mem (oaddr, s390_popcnt (inib[3])))
5685 return -1;
5686 break;
5687
5688 case 0xc0:
5689 case 0xc2:
5690 case 0xc4:
5691 case 0xc6:
5692 case 0xcc:
5693 /* RIL-format instruction */
5694 switch (ibyte[0] << 4 | inib[3])
5695 {
5696 case 0xc00: /* LARL - load address relative long */
5697 case 0xc05: /* BRASL - branch relative and save long */
5698 case 0xc09: /* IILF - insert immediate */
5699 case 0xc21: /* MSFI - multiply single immediate */
5700 case 0xc42: /* LLHRL - load logical halfword relative long */
5701 case 0xc45: /* LHRL - load halfword relative long */
5702 case 0xc4d: /* LRL - load relative long */
5703 /* 32-bit or native gpr destination */
5704 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5705 return -1;
5706 break;
5707
5708 case 0xc01: /* LGFI - load immediate */
5709 case 0xc0e: /* LLIHF - load logical immediate */
5710 case 0xc0f: /* LLILF - load logical immediate */
5711 case 0xc20: /* MSGFI - multiply single immediate */
5712 case 0xc44: /* LGHRL - load halfword relative long */
5713 case 0xc46: /* LLGHRL - load logical halfword relative long */
5714 case 0xc48: /* LGRL - load relative long */
5715 case 0xc4c: /* LGFRL - load relative long */
5716 case 0xc4e: /* LLGFRL - load logical relative long */
5717 /* 64-bit gpr destination */
5718 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5719 return -1;
5720 break;
5721
5722 /* 0xc02-0xc03 undefined */
5723
5724 case 0xc04: /* BRCL - branch relative on condition long */
5725 case 0xc62: /* PFDRL - prefetch data relative long */
5726 break;
5727
5728 case 0xc06: /* XIHF - xor immediate */
5729 case 0xc0a: /* NIHF - and immediate */
5730 case 0xc0c: /* OIHF - or immediate */
5731 case 0xcc8: /* AIH - add immediate high */
5732 case 0xcca: /* ALSIH - add logical with signed immediate high */
5733 /* 32-bit high gpr destination + flags */
5734 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
5735 return -1;
5736 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5737 return -1;
5738 break;
5739
5740 case 0xc07: /* XILF - xor immediate */
5741 case 0xc0b: /* NILF - and immediate */
5742 case 0xc0d: /* OILF - or immediate */
5743 case 0xc25: /* SLFI - subtract logical immediate */
5744 case 0xc29: /* AFI - add immediate */
5745 case 0xc2b: /* ALFI - add logical immediate */
5746 /* 32-bit gpr destination + flags */
5747 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5748 return -1;
5749 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5750 return -1;
5751 break;
5752
5753 case 0xc08: /* IIHF - insert immediate */
5754 case 0xcc6: /* BRCTH - branch relative on count high */
5755 case 0xccb: /* ALSIHN - add logical with signed immediate high */
5756 /* 32-bit high gpr destination */
5757 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
5758 return -1;
5759 break;
5760
5761 /* 0xc22-0xc23 undefined */
5762
5763 case 0xc24: /* SLGFI - subtract logical immediate */
5764 case 0xc28: /* AGFI - add immediate */
5765 case 0xc2a: /* ALGFI - add logical immediate */
5766 /* 64-bit gpr destination + flags */
5767 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5768 return -1;
5769 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5770 return -1;
5771 break;
5772
5773 /* 0xc26-0xc27 undefined */
5774
5775 case 0xc2c: /* CGFI - compare immediate */
5776 case 0xc2d: /* CFI - compare immediate */
5777 case 0xc2e: /* CLGFI - compare logical immediate */
5778 case 0xc2f: /* CLFI - compare logical immediate */
5779 case 0xc64: /* CGHRL - compare halfword relative long */
5780 case 0xc65: /* CHRL - compare halfword relative long */
5781 case 0xc66: /* CLGHRL - compare logical halfword relative long */
5782 case 0xc67: /* CLHRL - compare logical halfword relative long */
5783 case 0xc68: /* CGRL - compare relative long */
5784 case 0xc6a: /* CLGRL - compare logical relative long */
5785 case 0xc6c: /* CGFRL - compare relative long */
5786 case 0xc6d: /* CRL - compare relative long */
5787 case 0xc6e: /* CLGFRL - compare logical relative long */
5788 case 0xc6f: /* CLRL - compare logical relative long */
5789 case 0xccd: /* CIH - compare immediate high */
5790 case 0xccf: /* CLIH - compare logical immediate high */
5791 /* flags only */
5792 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5793 return -1;
5794 break;
5795
5796 /* 0xc40-0xc41 undefined */
5797 /* 0xc43 undefined */
5798
5799 case 0xc47: /* STHRL - store halfword relative long */
5800 oaddr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
5801 if (record_full_arch_list_add_mem (oaddr, 2))
5802 return -1;
5803 break;
5804
5805 /* 0xc49-0xc4a undefined */
5806
5807 case 0xc4b: /* STGRL - store relative long */
5808 oaddr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
5809 if (record_full_arch_list_add_mem (oaddr, 8))
5810 return -1;
5811 break;
5812
5813 case 0xc4f: /* STRL - store relative long */
5814 oaddr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
5815 if (record_full_arch_list_add_mem (oaddr, 4))
5816 return -1;
5817 break;
5818
5819 case 0xc60: /* EXRL - execute relative long */
5820 if (ex != -1)
5821 {
5822 fprintf_unfiltered (gdb_stdlog, "Warning: Double execute at %s.\n",
5823 paddress (gdbarch, addr));
5824 return -1;
5825 }
5826 addr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
5827 if (inib[2])
5828 {
5829 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
5830 ex = tmp & 0xff;
5831 }
5832 else
5833 {
5834 ex = 0;
5835 }
5836 goto ex;
5837
5838 /* 0xc61 undefined */
5839 /* 0xc63 undefined */
5840 /* 0xc69 undefined */
5841 /* 0xc6b undefined */
5842 /* 0xcc0-0xcc5 undefined */
5843 /* 0xcc7 undefined */
5844 /* 0xcc9 undefined */
5845 /* 0xccc undefined */
5846 /* 0xcce undefined */
5847
5848 default:
5849 goto UNKNOWN_OP;
5850 }
5851 break;
5852
5853 /* 0xc1 undefined */
5854 /* 0xc3 undefined */
5855
5856 case 0xc5: /* BPRP - branch prediction relative preload */
5857 case 0xc7: /* BPP - branch prediction preload */
5858 /* no visible effect */
5859 break;
5860
5861 case 0xc8:
5862 /* SSF-format instruction */
5863 switch (ibyte[0] << 4 | inib[3])
5864 {
5865 /* 0xc80 unsupported */
5866
5867 case 0xc81: /* ECTG - extract cpu time */
5868 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5869 return -1;
5870 if (s390_record_gpr_g (gdbarch, regcache, 0))
5871 return -1;
5872 if (s390_record_gpr_g (gdbarch, regcache, 1))
5873 return -1;
5874 break;
5875
5876 case 0xc82: /* CSST - compare and swap and store */
5877 {
5878 uint8_t fc, sc;
5879 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5880 fc = tmp & 0xff;
5881 sc = tmp >> 8 & 0xff;
5882
5883 /* First and third operands. */
5884 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5885 switch (fc)
5886 {
5887 case 0x00: /* 32-bit */
5888 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5889 return -1;
5890 if (record_full_arch_list_add_mem (oaddr, 4))
5891 return -1;
5892 break;
5893
5894 case 0x01: /* 64-bit */
5895 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5896 return -1;
5897 if (record_full_arch_list_add_mem (oaddr, 8))
5898 return -1;
5899 break;
5900
5901 case 0x02: /* 128-bit */
5902 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5903 return -1;
5904 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
5905 return -1;
5906 if (record_full_arch_list_add_mem (oaddr, 16))
5907 return -1;
5908 break;
5909
5910 default:
5911 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown CSST FC %02x at %s.\n",
5912 fc, paddress (gdbarch, addr));
5913 return -1;
5914 }
5915
5916 /* Second operand. */
5917 oaddr2 = s390_record_calc_disp (gdbarch, regcache, 0, insn[2], 0);
5918 if (sc > 4)
5919 {
5920 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown CSST FC %02x at %s.\n",
5921 sc, paddress (gdbarch, addr));
5922 return -1;
5923 }
5924
5925 if (record_full_arch_list_add_mem (oaddr2, 1 << sc))
5926 return -1;
5927
5928 /* Flags. */
5929 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5930 return -1;
5931 }
5932 break;
5933
5934 /* 0xc83 undefined */
5935
5936 case 0xc84: /* LPD - load pair disjoint */
5937 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5938 return -1;
5939 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
5940 return -1;
5941 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5942 return -1;
5943 break;
5944
5945 case 0xc85: /* LPDG - load pair disjoint */
5946 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5947 return -1;
5948 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
5949 return -1;
5950 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5951 return -1;
5952 break;
5953
5954 /* 0xc86-0xc8f undefined */
5955
5956 default:
5957 goto UNKNOWN_OP;
5958 }
5959 break;
5960
5961 /* 0xc9-0xcb undefined */
5962 /* 0xcd-0xcf undefined */
5963
5964 case 0xd0: /* TRTR - translate and test reversed */
5965 case 0xdd: /* TRT - translate and test */
5966 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
5967 return -1;
5968 if (record_full_arch_list_add_reg (regcache, S390_R2_REGNUM))
5969 return -1;
5970 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5971 return -1;
5972 break;
5973
5974 case 0xd1: /* MVN - move numbers */
5975 case 0xd2: /* MVC - move */
5976 case 0xd3: /* MVZ - move zones */
5977 case 0xdc: /* TR - translate */
5978 case 0xe8: /* MVCIN - move inverse */
5979 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5980 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5981 return -1;
5982 break;
5983
5984 case 0xd4: /* NC - and */
5985 case 0xd6: /* OC - or*/
5986 case 0xd7: /* XC - xor */
5987 case 0xe2: /* UNPKU - unpack unicode */
5988 case 0xea: /* UNPKA - unpack ASCII */
5989 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5990 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5991 return -1;
5992 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5993 return -1;
5994 break;
5995
5996 case 0xde: /* ED - edit */
5997 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5998 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5999 return -1;
6000 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6001 return -1;
6002 /* DXC may be written */
6003 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6004 return -1;
6005 break;
6006
6007 case 0xdf: /* EDMK - edit and mark */
6008 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6009 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
6010 return -1;
6011 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
6012 return -1;
6013 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6014 return -1;
6015 /* DXC may be written */
6016 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6017 return -1;
6018 break;
6019
6020 /* 0xd8 undefined */
6021 /* 0xd9 unsupported: MVCK - move with key */
6022 /* 0xda unsupported: MVCP - move to primary */
6023 /* 0xdb unsupported: MVCS - move to secondary */
6024 /* 0xe0 undefined */
6025
6026 case 0xe1: /* PKU - pack unicode */
6027 case 0xe9: /* PKA - pack ASCII */
6028 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6029 if (record_full_arch_list_add_mem (oaddr, 16))
6030 return -1;
6031 break;
6032
6033 case 0xe3:
6034 case 0xe6:
6035 case 0xe7:
6036 case 0xeb:
6037 case 0xed:
6038 /* RXY/RXE/RXF/RSL/RSY/SIY/V*-format instruction */
6039 switch (ibyte[0] << 8 | ibyte[5])
6040 {
6041 /* 0xe300-0xe301 undefined */
6042
6043 case 0xe302: /* LTG - load and test */
6044 case 0xe308: /* AG - add */
6045 case 0xe309: /* SG - subtract */
6046 case 0xe30a: /* ALG - add logical */
6047 case 0xe30b: /* SLG - subtract logical */
6048 case 0xe318: /* AGF - add */
6049 case 0xe319: /* SGF - subtract */
6050 case 0xe31a: /* ALGF - add logical */
6051 case 0xe31b: /* SLGF - subtract logical */
6052 case 0xe332: /* LTGF - load and test */
6053 case 0xe380: /* NG - and */
6054 case 0xe381: /* OG - or */
6055 case 0xe382: /* XG - xor */
6056 case 0xe388: /* ALCG - add logical with carry */
6057 case 0xe389: /* SLBG - subtract logical with borrow */
6058 case 0xeb0a: /* SRAG - shift right single */
6059 case 0xeb0b: /* SLAG - shift left single */
6060 /* 64-bit gpr destination + flags */
6061 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6062 return -1;
6063 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6064 return -1;
6065 break;
6066
6067 /* 0xe303 privileged */
6068
6069 case 0xe304: /* LG - load */
6070 case 0xe30c: /* MSG - multiply single */
6071 case 0xe30f: /* LRVG - load reversed */
6072 case 0xe314: /* LGF - load */
6073 case 0xe315: /* LGH - load halfword */
6074 case 0xe316: /* LLGF - load logical */
6075 case 0xe317: /* LLGT - load logical thirty one bits */
6076 case 0xe31c: /* MSGF - multiply single */
6077 case 0xe32a: /* LZRG - load and zero rightmost byte */
6078 case 0xe33a: /* LLZRGF - load logical and zero rightmost byte */
6079 case 0xe33c: /* MGH - multiply halfword 64x16mem -> 64 */
6080 case 0xe346: /* BCTG - branch on count */
6081 case 0xe377: /* LGB - load byte */
6082 case 0xe390: /* LLGC - load logical character */
6083 case 0xe391: /* LLGH - load logical halfword */
6084 case 0xeb0c: /* SRLG - shift right single logical */
6085 case 0xeb0d: /* SLLG - shift left single logical */
6086 case 0xeb1c: /* RLLG - rotate left single logical */
6087 case 0xeb44: /* BXHG - branch on index high */
6088 case 0xeb45: /* BXLEG - branch on index low or equal */
6089 case 0xeb4c: /* ECAG - extract cpu attribute */
6090 case 0xebe2: /* LOCG - load on condition */
6091 /* 64-bit gpr destination */
6092 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6093 return -1;
6094 break;
6095
6096 /* 0xe305 undefined */
6097
6098 case 0xe306: /* CVBY - convert to binary */
6099 /* 32-bit or native gpr destination + FPC (DXC write) */
6100 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6101 return -1;
6102 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6103 return -1;
6104 break;
6105
6106 /* 0xe307 undefined */
6107
6108 case 0xe30d: /* DSG - divide single */
6109 case 0xe31d: /* DSGF - divide single */
6110 case 0xe384: /* MG - multiply 64x64mem -> 128 */
6111 case 0xe386: /* MLG - multiply logical */
6112 case 0xe387: /* DLG - divide logical */
6113 case 0xe38f: /* LPQ - load pair from quadword */
6114 /* 64-bit gpr pair destination */
6115 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6116 return -1;
6117 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
6118 return -1;
6119 break;
6120
6121 case 0xe30e: /* CVBG - convert to binary */
6122 /* 64-bit gpr destination + FPC (DXC write) */
6123 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6124 return -1;
6125 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6126 return -1;
6127 break;
6128
6129 /* 0xe310-0xe311 undefined */
6130
6131 case 0xe312: /* LT - load and test */
6132 case 0xe338: /* AGH - add halfword to 64 bit value */
6133 case 0xe339: /* SGH - subtract halfword from 64 bit value */
6134 case 0xe353: /* MSC - multiply single 32x32mem -> 32 */
6135 case 0xe354: /* NY - and */
6136 case 0xe356: /* OY - or */
6137 case 0xe357: /* XY - xor */
6138 case 0xe35a: /* AY - add */
6139 case 0xe35b: /* SY - subtract */
6140 case 0xe35e: /* ALY - add logical */
6141 case 0xe35f: /* SLY - subtract logical */
6142 case 0xe37a: /* AHY - add halfword */
6143 case 0xe37b: /* SHY - subtract halfword */
6144 case 0xe383: /* MSGC - multiply single 64x64mem -> 64 */
6145 case 0xe398: /* ALC - add logical with carry */
6146 case 0xe399: /* SLB - subtract logical with borrow */
6147 case 0xe727: /* LCBB - load count to block bounduary */
6148 case 0xeb81: /* ICMY - insert characters under mask */
6149 case 0xebdc: /* SRAK - shift left single */
6150 case 0xebdd: /* SLAK - shift left single */
6151 /* 32/64-bit gpr destination + flags */
6152 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6153 return -1;
6154 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6155 return -1;
6156 break;
6157
6158 /* 0xe313 privileged */
6159
6160 case 0xe31e: /* LRV - load reversed */
6161 case 0xe31f: /* LRVH - load reversed */
6162 case 0xe33b: /* LZRF - load and zero rightmost byte */
6163 case 0xe351: /* MSY - multiply single */
6164 case 0xe358: /* LY - load */
6165 case 0xe371: /* LAY - load address */
6166 case 0xe373: /* ICY - insert character */
6167 case 0xe376: /* LB - load byte */
6168 case 0xe378: /* LHY - load */
6169 case 0xe37c: /* MHY - multiply halfword */
6170 case 0xe394: /* LLC - load logical character */
6171 case 0xe395: /* LLH - load logical halfword */
6172 case 0xeb1d: /* RLL - rotate left single logical */
6173 case 0xebde: /* SRLK - shift left single logical */
6174 case 0xebdf: /* SLLK - shift left single logical */
6175 case 0xebf2: /* LOC - load on condition */
6176 /* 32-bit or native gpr destination */
6177 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6178 return -1;
6179 break;
6180
6181 case 0xe320: /* CG - compare */
6182 case 0xe321: /* CLG - compare logical */
6183 case 0xe330: /* CGF - compare */
6184 case 0xe331: /* CLGF - compare logical */
6185 case 0xe334: /* CGH - compare halfword */
6186 case 0xe355: /* CLY - compare logical */
6187 case 0xe359: /* CY - compare */
6188 case 0xe379: /* CHY - compare halfword */
6189 case 0xe3cd: /* CHF - compare high */
6190 case 0xe3cf: /* CLHF - compare logical high */
6191 case 0xeb20: /* CLMH - compare logical under mask high */
6192 case 0xeb21: /* CLMY - compare logical under mask */
6193 case 0xeb51: /* TMY - test under mask */
6194 case 0xeb55: /* CLIY - compare logical */
6195 case 0xebc0: /* TP - test decimal */
6196 case 0xed10: /* TCEB - test data class */
6197 case 0xed11: /* TCDB - test data class */
6198 case 0xed12: /* TCXB - test data class */
6199 case 0xed50: /* TDCET - test data class */
6200 case 0xed51: /* TDGET - test data group */
6201 case 0xed54: /* TDCDT - test data class */
6202 case 0xed55: /* TDGDT - test data group */
6203 case 0xed58: /* TDCXT - test data class */
6204 case 0xed59: /* TDGXT - test data group */
6205 /* flags only */
6206 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6207 return -1;
6208 break;
6209
6210 /* 0xe322-0xe323 undefined */
6211
6212 case 0xe324: /* STG - store */
6213 case 0xe325: /* NTSTG - nontransactional store */
6214 case 0xe326: /* CVDY - convert to decimal */
6215 case 0xe32f: /* STRVG - store reversed */
6216 case 0xebe3: /* STOCG - store on condition */
6217 case 0xed67: /* STDY - store */
6218 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
6219 if (record_full_arch_list_add_mem (oaddr, 8))
6220 return -1;
6221 break;
6222
6223 /* 0xe327-0xe329 undefined */
6224 /* 0xe32b-0xe32d undefined */
6225
6226 case 0xe32e: /* CVDG - convert to decimal */
6227 case 0xe38e: /* STPQ - store pair to quadword */
6228 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
6229 if (record_full_arch_list_add_mem (oaddr, 16))
6230 return -1;
6231 break;
6232
6233 /* 0xe333 undefined */
6234 /* 0xe335 undefined */
6235
6236 case 0xe336: /* PFD - prefetch data */
6237 break;
6238
6239 /* 0xe337 undefined */
6240 /* 0xe33c-0xe33d undefined */
6241
6242 case 0xe33e: /* STRV - store reversed */
6243 case 0xe350: /* STY - store */
6244 case 0xe3cb: /* STFH - store high */
6245 case 0xebe1: /* STOCFH - store high on condition */
6246 case 0xebf3: /* STOC - store on condition */
6247 case 0xed66: /* STEY - store */
6248 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
6249 if (record_full_arch_list_add_mem (oaddr, 4))
6250 return -1;
6251 break;
6252
6253 case 0xe33f: /* STRVH - store reversed */
6254 case 0xe370: /* STHY - store halfword */
6255 case 0xe3c7: /* STHH - store halfword high */
6256 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
6257 if (record_full_arch_list_add_mem (oaddr, 2))
6258 return -1;
6259 break;
6260
6261 /* 0xe340-0xe345 undefined */
6262
6263 case 0xe347: /* BIC - branch indirect on condition */
6264 break;
6265
6266 /* 0xe348-0xe34f undefined */
6267 /* 0xe352 undefined */
6268
6269 case 0xe35c: /* MFY - multiply */
6270 case 0xe396: /* ML - multiply logical */
6271 case 0xe397: /* DL - divide logical */
6272 /* 32-bit gpr pair destination */
6273 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6274 return -1;
6275 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6276 return -1;
6277 break;
6278
6279 /* 0xe35d undefined */
6280 /* 0xe360-0xe36f undefined */
6281
6282 case 0xe372: /* STCY - store character */
6283 case 0xe3c3: /* STCH - store character high */
6284 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
6285 if (record_full_arch_list_add_mem (oaddr, 1))
6286 return -1;
6287 break;
6288
6289 /* 0xe374 undefined */
6290
6291 case 0xe375: /* LAEY - load address extended */
6292 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6293 return -1;
6294 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[2]))
6295 return -1;
6296 break;
6297
6298 /* 0xe37d-0xe37f undefined */
6299
6300 case 0xe385: /* LGAT - load and trap */
6301 case 0xe39c: /* LLGTAT - load logical thirty one bits and trap */
6302 case 0xe39d: /* LLGFAT - load logical and trap */
6303 case 0xe650: /* VCVB - vector convert to binary 32 bit*/
6304 case 0xe652: /* VCVBG - vector convert to binary 64 bit*/
6305 case 0xe721: /* VLGV - vector load gr from vr element */
6306 /* 64-bit gpr destination + fpc for possible DXC write */
6307 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6308 return -1;
6309 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6310 return -1;
6311 break;
6312
6313 /* 0xe38a-0xe38d undefined */
6314 /* 0xe392-0xe393 undefined */
6315 /* 0xe39a-0xe39b undefined */
6316 /* 0xe39e undefined */
6317
6318 case 0xe39f: /* LAT - load and trap */
6319 /* 32-bit gpr destination + fpc for possible DXC write */
6320 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6321 return -1;
6322 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6323 return -1;
6324 break;
6325
6326 /* 0xe3a0-0xe3bf undefined */
6327
6328 case 0xe3c0: /* LBH - load byte high */
6329 case 0xe3c2: /* LLCH - load logical character high */
6330 case 0xe3c4: /* LHH - load halfword high */
6331 case 0xe3c6: /* LLHH - load logical halfword high */
6332 case 0xe3ca: /* LFH - load high */
6333 case 0xebe0: /* LOCFH - load high on condition */
6334 /* 32-bit high gpr destination */
6335 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
6336 return -1;
6337 break;
6338
6339 /* 0xe3c1 undefined */
6340 /* 0xe3c5 undefined */
6341
6342 case 0xe3c8: /* LFHAT - load high and trap */
6343 /* 32-bit high gpr destination + fpc for possible DXC write */
6344 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
6345 return -1;
6346 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6347 return -1;
6348 break;
6349
6350 /* 0xe3c9 undefined */
6351 /* 0xe3cc undefined */
6352 /* 0xe3ce undefined */
6353 /* 0xe3d0-0xe3ff undefined */
6354
6355 case 0xe634: /* VPKZ - vector pack zoned */
6356 case 0xe635: /* VLRL - vector load rightmost with immed. length */
6357 case 0xe637: /* VLRLR - vector load rightmost with length */
6358 case 0xe649: /* VLIP - vector load immediate decimal */
6359 case 0xe700: /* VLEB - vector load element */
6360 case 0xe701: /* VLEH - vector load element */
6361 case 0xe702: /* VLEG - vector load element */
6362 case 0xe703: /* VLEF - vector load element */
6363 case 0xe704: /* VLLEZ - vector load logical element and zero */
6364 case 0xe705: /* VLREP - vector load and replicate */
6365 case 0xe706: /* VL - vector load */
6366 case 0xe707: /* VLBB - vector load to block bounduary */
6367 case 0xe712: /* VGEG - vector gather element */
6368 case 0xe713: /* VGEF - vector gather element */
6369 case 0xe722: /* VLVG - vector load vr element from gr */
6370 case 0xe730: /* VESL - vector element shift left */
6371 case 0xe733: /* VERLL - vector element rotate left logical */
6372 case 0xe737: /* VLL - vector load with length */
6373 case 0xe738: /* VESRL - vector element shift right logical */
6374 case 0xe73a: /* VESRA - vector element shift right arithmetic */
6375 case 0xe740: /* VLEIB - vector load element immediate */
6376 case 0xe741: /* VLEIH - vector load element immediate */
6377 case 0xe742: /* VLEIG - vector load element immediate */
6378 case 0xe743: /* VLEIF - vector load element immediate */
6379 case 0xe744: /* VGBM - vector generate byte mask */
6380 case 0xe745: /* VREPI - vector replicate immediate */
6381 case 0xe746: /* VGM - vector generate mask */
6382 case 0xe74d: /* VREP - vector replicate */
6383 case 0xe750: /* VPOPCT - vector population count */
6384 case 0xe752: /* VCTZ - vector count trailing zeros */
6385 case 0xe753: /* VCLZ - vector count leading zeros */
6386 case 0xe756: /* VLR - vector load */
6387 case 0xe75f: /* VSEG -vector sign extend to doubleword */
6388 case 0xe760: /* VMRL - vector merge low */
6389 case 0xe761: /* VMRH - vector merge high */
6390 case 0xe762: /* VLVGP - vector load vr from grs disjoint */
6391 case 0xe764: /* VSUM - vector sum across word */
6392 case 0xe765: /* VSUMG - vector sum across doubleword */
6393 case 0xe766: /* VCKSM - vector checksum */
6394 case 0xe767: /* VSUMQ - vector sum across quadword */
6395 case 0xe768: /* VN - vector and */
6396 case 0xe769: /* VNC - vector and with complement */
6397 case 0xe76a: /* VO - vector or */
6398 case 0xe76b: /* VNO - vector nor */
6399 case 0xe76c: /* VNX - vector not exclusive or */
6400 case 0xe76d: /* VX - vector xor */
6401 case 0xe76e: /* VNN - vector nand */
6402 case 0xe76f: /* VOC - vector or with complement */
6403 case 0xe770: /* VESLV - vector element shift left */
6404 case 0xe772: /* VERIM - vector element rotate and insert under mask */
6405 case 0xe773: /* VERLLV - vector element rotate left logical */
6406 case 0xe774: /* VSL - vector shift left */
6407 case 0xe775: /* VSLB - vector shift left by byte */
6408 case 0xe777: /* VSLDB - vector shift left double by byte */
6409 case 0xe778: /* VESRLV - vector element shift right logical */
6410 case 0xe77a: /* VESRAV - vector element shift right arithmetic */
6411 case 0xe77c: /* VSRL - vector shift right logical */
6412 case 0xe77d: /* VSRLB - vector shift right logical by byte */
6413 case 0xe77e: /* VSRA - vector shift right arithmetic */
6414 case 0xe77f: /* VSRAB - vector shift right arithmetic by byte */
6415 case 0xe784: /* VPDI - vector permute doubleword immediate */
6416 case 0xe785: /* VBPERM - vector bit permute */
6417 case 0xe78c: /* VPERM - vector permute */
6418 case 0xe78d: /* VSEL - vector select */
6419 case 0xe78e: /* VFMS - vector fp multiply and subtract */
6420 case 0xe78f: /* VFMA - vector fp multiply and add */
6421 case 0xe794: /* VPK - vector pack */
6422 case 0xe79e: /* VFNMS - vector fp negative multiply and subtract */
6423 case 0xe79f: /* VFNMA - vector fp negative multiply and add */
6424 case 0xe7a1: /* VMLH - vector multiply logical high */
6425 case 0xe7a2: /* VML - vector multiply low */
6426 case 0xe7a3: /* VMH - vector multiply high */
6427 case 0xe7a4: /* VMLE - vector multiply logical even */
6428 case 0xe7a5: /* VMLO - vector multiply logical odd */
6429 case 0xe7a6: /* VME - vector multiply even */
6430 case 0xe7a7: /* VMO - vector multiply odd */
6431 case 0xe7a9: /* VMALH - vector multiply and add logical high */
6432 case 0xe7aa: /* VMAL - vector multiply and add low */
6433 case 0xe7ab: /* VMAH - vector multiply and add high */
6434 case 0xe7ac: /* VMALE - vector multiply and add logical even */
6435 case 0xe7ad: /* VMALO - vector multiply and add logical odd */
6436 case 0xe7ae: /* VMAE - vector multiply and add even */
6437 case 0xe7af: /* VMAO - vector multiply and add odd */
6438 case 0xe7b4: /* VGFM - vector Galois field multiply sum */
6439 case 0xe7b8: /* VMSL - vector multiply sum logical */
6440 case 0xe7b9: /* VACCC - vector add with carry compute carry */
6441 case 0xe7bb: /* VAC - vector add with carry */
6442 case 0xe7bc: /* VGFMA - vector Galois field multiply sum and accumulate */
6443 case 0xe7bd: /* VSBCBI - vector subtract with borrow compute borrow indication */
6444 case 0xe7bf: /* VSBI - vector subtract with borrow indication */
6445 case 0xe7c0: /* VCLGD - vector convert to logical 64-bit */
6446 case 0xe7c1: /* VCDLG - vector convert from logical 64-bit */
6447 case 0xe7c2: /* VCGD - vector convert to fixed 64-bit */
6448 case 0xe7c3: /* VCDG - vector convert from fixed 64-bit */
6449 case 0xe7c4: /* VLDE/VFLL - vector fp load lengthened */
6450 case 0xe7c5: /* VLED/VFLR - vector fp load rounded */
6451 case 0xe7c7: /* VFI - vector load fp integer */
6452 case 0xe7cc: /* VFPSO - vector fp perform sign operation */
6453 case 0xe7ce: /* VFSQ - vector fp square root */
6454 case 0xe7d4: /* VUPLL - vector unpack logical low */
6455 case 0xe7d6: /* VUPL - vector unpack low */
6456 case 0xe7d5: /* VUPLH - vector unpack logical high */
6457 case 0xe7d7: /* VUPH - vector unpack high */
6458 case 0xe7de: /* VLC - vector load complement */
6459 case 0xe7df: /* VLP - vector load positive */
6460 case 0xe7e2: /* VFA - vector fp subtract */
6461 case 0xe7e3: /* VFA - vector fp add */
6462 case 0xe7e5: /* VFD - vector fp divide */
6463 case 0xe7e7: /* VFM - vector fp multiply */
6464 case 0xe7ee: /* VFMIN - vector fp minimum */
6465 case 0xe7ef: /* VFMAX - vector fp maximum */
6466 case 0xe7f0: /* VAVGL - vector average logical */
6467 case 0xe7f1: /* VACC - vector add and compute carry */
6468 case 0xe7f2: /* VAVG - vector average */
6469 case 0xe7f3: /* VA - vector add */
6470 case 0xe7f5: /* VSCBI - vector subtract compute borrow indication */
6471 case 0xe7f7: /* VS - vector subtract */
6472 case 0xe7fc: /* VMNL - vector minimum logical */
6473 case 0xe7fd: /* VMXL - vector maximum logical */
6474 case 0xe7fe: /* VMN - vector minimum */
6475 case 0xe7ff: /* VMX - vector maximum */
6476 /* vector destination + FPC */
6477 if (s390_record_vr (gdbarch, regcache, ivec[0]))
6478 return -1;
6479 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6480 return -1;
6481 break;
6482
6483 case 0xe63d: /* VSTRL - vector store rightmost with immed. length */
6484 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6485 if (record_full_arch_list_add_mem (oaddr, inib[3] + 1))
6486 return -1;
6487 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6488 return -1;
6489 break;
6490
6491 case 0xe708: /* VSTEB - vector store element */
6492 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
6493 if (record_full_arch_list_add_mem (oaddr, 1))
6494 return -1;
6495 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6496 return -1;
6497 break;
6498
6499 case 0xe709: /* VSTEH - vector store element */
6500 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
6501 if (record_full_arch_list_add_mem (oaddr, 2))
6502 return -1;
6503 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6504 return -1;
6505 break;
6506
6507 case 0xe70a: /* VSTEG - vector store element */
6508 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
6509 if (record_full_arch_list_add_mem (oaddr, 8))
6510 return -1;
6511 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6512 return -1;
6513 break;
6514
6515 case 0xe70b: /* VSTEF - vector store element */
6516 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
6517 if (record_full_arch_list_add_mem (oaddr, 4))
6518 return -1;
6519 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6520 return -1;
6521 break;
6522
6523 /* 0xe70c-0xe70d undefined */
6524
6525 case 0xe70e: /* VST - vector store */
6526 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
6527 if (record_full_arch_list_add_mem (oaddr, 16))
6528 return -1;
6529 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6530 return -1;
6531 break;
6532
6533 /* 0xe70f-0xe711 undefined */
6534 /* 0xe714-0xe719 undefined */
6535
6536 case 0xe71a: /* VSCEG - vector scatter element */
6537 if (s390_record_calc_disp_vsce (gdbarch, regcache, ivec[1], inib[8], 8, insn[1], 0, &oaddr))
6538 return -1;
6539 if (record_full_arch_list_add_mem (oaddr, 8))
6540 return -1;
6541 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6542 return -1;
6543 break;
6544
6545 case 0xe71b: /* VSCEF - vector scatter element */
6546 if (s390_record_calc_disp_vsce (gdbarch, regcache, ivec[1], inib[8], 4, insn[1], 0, &oaddr))
6547 return -1;
6548 if (record_full_arch_list_add_mem (oaddr, 4))
6549 return -1;
6550 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6551 return -1;
6552 break;
6553
6554 /* 0xe71c-0xe720 undefined */
6555 /* 0xe723-0xe726 undefined */
6556 /* 0xe728-0xe72f undefined */
6557 /* 0xe731-0xe732 undefined */
6558 /* 0xe734-0xe735 undefined */
6559
6560 case 0xe736: /* VLM - vector load multiple */
6561 for (i = ivec[0]; i != ivec[1]; i++, i &= 0x1f)
6562 if (s390_record_vr (gdbarch, regcache, i))
6563 return -1;
6564 if (s390_record_vr (gdbarch, regcache, ivec[1]))
6565 return -1;
6566 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6567 return -1;
6568 break;
6569
6570 /* 0xe739 undefined */
6571 /* 0xe73b-0xe73d undefined */
6572
6573 case 0xe73e: /* VSTM - vector store multiple */
6574 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6575 if (ivec[0] <= ivec[1])
6576 n = ivec[1] - ivec[0] + 1;
6577 else
6578 n = ivec[1] + 0x20 - ivec[0] + 1;
6579 if (record_full_arch_list_add_mem (oaddr, n * 16))
6580 return -1;
6581 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6582 return -1;
6583 break;
6584
6585 case 0xe63c: /* VUPKZ - vector unpack zoned */
6586 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6587 if (record_full_arch_list_add_mem (oaddr, (ibyte[1] + 1) & 31))
6588 return -1;
6589 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6590 return -1;
6591 break;
6592
6593 case 0xe63f: /* VSTRLR - vector store rightmost with length */
6594 case 0xe73f: /* VSTL - vector store with length */
6595 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6596 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[3], &tmp);
6597 tmp &= 0xffffffffu;
6598 if (tmp > 15)
6599 tmp = 15;
6600 if (record_full_arch_list_add_mem (oaddr, tmp + 1))
6601 return -1;
6602 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6603 return -1;
6604 break;
6605
6606 /* 0xe747-0xe749 undefined */
6607
6608 case 0xe658: /* VCVD - vector convert to decimal 32 bit */
6609 case 0xe659: /* VSRP - vector shift and round decimal */
6610 case 0xe65a: /* VCVDG - vector convert to decimal 64 bit*/
6611 case 0xe65b: /* VPSOP - vector perform sign operation decimal */
6612 case 0xe671: /* VAP - vector add decimal */
6613 case 0xe673: /* VSP - vector subtract decimal */
6614 case 0xe678: /* VMP - vector multiply decimal */
6615 case 0xe679: /* VMSP - vector multiply decimal */
6616 case 0xe67a: /* VDP - vector divide decimal */
6617 case 0xe67b: /* VRP - vector remainder decimal */
6618 case 0xe67e: /* VSDP - vector shift and divide decimal */
6619 case 0xe74a: /* VFTCI - vector fp test data class immediate */
6620 case 0xe75c: /* VISTR - vector isolate string */
6621 case 0xe780: /* VFEE - vector find element equal */
6622 case 0xe781: /* VFENE - vector find element not equal */
6623 case 0xe782: /* VFA - vector find any element equal */
6624 case 0xe78a: /* VSTRC - vector string range compare */
6625 case 0xe795: /* VPKLS - vector pack logical saturate */
6626 case 0xe797: /* VPKS - vector pack saturate */
6627 case 0xe7e8: /* VFCE - vector fp compare equal */
6628 case 0xe7ea: /* VFCHE - vector fp compare high or equal */
6629 case 0xe7eb: /* VFCH - vector fp compare high */
6630 case 0xe7f8: /* VCEQ - vector compare equal */
6631 case 0xe7f9: /* VCHL - vector compare high logical */
6632 case 0xe7fb: /* VCH - vector compare high */
6633 /* vector destination + flags + FPC */
6634 if (s390_record_vr (gdbarch, regcache, ivec[0]))
6635 return -1;
6636 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6637 return -1;
6638 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6639 return -1;
6640 break;
6641
6642 case 0xe65f: /* VTP - vector test decimal */
6643 /* flags + FPC */
6644 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6645 return -1;
6646 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6647 return -1;
6648 break;
6649
6650 /* 0xe74b-0xe74c undefined */
6651 /* 0xe74e-0xe74f undefined */
6652 /* 0xe751 undefined */
6653 /* 0xe754-0xe755 undefined */
6654 /* 0xe757-0xe75b undefined */
6655 /* 0xe75d-0xe75e undefined */
6656 /* 0xe763 undefined */
6657 /* 0xe771 undefined */
6658 /* 0xe776 undefined */
6659 /* 0xe779 undefined */
6660 /* 0xe77b undefined */
6661 /* 0xe783 undefined */
6662 /* 0xe786-0xe789 undefined */
6663 /* 0xe78b undefined */
6664 /* 0xe790-0xe793 undefined */
6665 /* 0xe796 undefined */
6666 /* 0xe798-0xe79d undefined */
6667 /* 0xe7a0 undefined */
6668 /* 0xe7a8 undefined */
6669 /* 0xe7b0-0xe7b3 undefined */
6670 /* 0xe7b5-0xe7b7 undefined */
6671 /* 0xe7ba undefined */
6672 /* 0xe7be undefined */
6673 /* 0xe7c6 undefined */
6674 /* 0xe7c8-0xe7c9 undefined */
6675
6676 case 0xe677: /* VCP - vector compare decimal */
6677 case 0xe7ca: /* WFK - vector fp compare and signal scalar */
6678 case 0xe7cb: /* WFC - vector fp compare scalar */
6679 case 0xe7d8: /* VTM - vector test under mask */
6680 case 0xe7d9: /* VECL - vector element compare logical */
6681 case 0xe7db: /* VEC - vector element compare */
6682 case 0xed08: /* KEB - compare and signal */
6683 case 0xed09: /* CEB - compare */
6684 case 0xed18: /* KDB - compare and signal */
6685 case 0xed19: /* CDB - compare */
6686 /* flags + fpc only */
6687 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6688 return -1;
6689 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6690 return -1;
6691 break;
6692
6693 /* 0xe7cd undefined */
6694 /* 0xe7cf-0xe7d3 undefined */
6695 /* 0xe7da undefined */
6696 /* 0xe7dc-0xe7dd undefined */
6697 /* 0xe7e0-0xe7e1 undefined */
6698 /* 0xe7e4 undefined */
6699 /* 0xe7e6 undefined */
6700 /* 0xe7e9 undefined */
6701 /* 0xe7ec-0xe7ed undefined */
6702 /* 0xe7f4 undefined */
6703 /* 0xe7f6 undefined */
6704 /* 0xe7fa undefined */
6705
6706 /* 0xeb00-0xeb03 undefined */
6707
6708 case 0xeb04: /* LMG - load multiple */
6709 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6710 if (s390_record_gpr_g (gdbarch, regcache, i))
6711 return -1;
6712 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
6713 return -1;
6714 break;
6715
6716 /* 0xeb05-0xeb09 undefined */
6717 /* 0xeb0e undefined */
6718 /* 0xeb0f privileged: TRACG */
6719 /* 0xeb10-0xeb13 undefined */
6720
6721 case 0xeb14: /* CSY - compare and swap */
6722 case 0xebf4: /* LAN - load and and */
6723 case 0xebf6: /* LAO - load and or */
6724 case 0xebf7: /* LAX - load and xor */
6725 case 0xebf8: /* LAA - load and add */
6726 case 0xebfa: /* LAAL - load and add logical */
6727 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6728 if (record_full_arch_list_add_mem (oaddr, 4))
6729 return -1;
6730 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6731 return -1;
6732 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6733 return -1;
6734 break;
6735
6736 /* 0xeb15-0xeb1b undefined */
6737 /* 0xeb1e-0xeb1f undefined */
6738 /* 0xeb22 undefined */
6739
6740 case 0xeb23: /* CLT - compare logical and trap */
6741 case 0xeb2b: /* CLGT - compare logical and trap */
6742 /* fpc only - including possible DXC write for trapping insns */
6743 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6744 return -1;
6745 break;
6746
6747 case 0xeb24: /* STMG - store multiple */
6748 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6749 if (inib[2] <= inib[3])
6750 n = inib[3] - inib[2] + 1;
6751 else
6752 n = inib[3] + 0x10 - inib[2] + 1;
6753 if (record_full_arch_list_add_mem (oaddr, n * 8))
6754 return -1;
6755 break;
6756
6757 /* 0xeb25 privileged */
6758
6759 case 0xeb26: /* STMH - store multiple high */
6760 case 0xeb90: /* STMY - store multiple */
6761 case 0xeb9b: /* STAMY - store access multiple */
6762 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6763 if (inib[2] <= inib[3])
6764 n = inib[3] - inib[2] + 1;
6765 else
6766 n = inib[3] + 0x10 - inib[2] + 1;
6767 if (record_full_arch_list_add_mem (oaddr, n * 4))
6768 return -1;
6769 break;
6770
6771 /* 0xeb27-0xeb2a undefined */
6772
6773 case 0xeb2c: /* STCMH - store characters under mask */
6774 case 0xeb2d: /* STCMY - store characters under mask */
6775 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6776 if (record_full_arch_list_add_mem (oaddr, s390_popcnt (inib[3])))
6777 return -1;
6778 break;
6779
6780 /* 0xeb2e undefined */
6781 /* 0xeb2f privileged */
6782
6783 case 0xeb30: /* CSG - compare and swap */
6784 case 0xebe4: /* LANG - load and and */
6785 case 0xebe6: /* LAOG - load and or */
6786 case 0xebe7: /* LAXG - load and xor */
6787 case 0xebe8: /* LAAG - load and add */
6788 case 0xebea: /* LAALG - load and add logical */
6789 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6790 if (record_full_arch_list_add_mem (oaddr, 8))
6791 return -1;
6792 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6793 return -1;
6794 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6795 return -1;
6796 break;
6797
6798 case 0xeb31: /* CDSY - compare double and swap */
6799 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6800 if (record_full_arch_list_add_mem (oaddr, 8))
6801 return -1;
6802 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6803 return -1;
6804 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6805 return -1;
6806 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6807 return -1;
6808 break;
6809
6810 /* 0xeb32-0xeb3d undefined */
6811
6812 case 0xeb3e: /* CDSG - compare double and swap */
6813 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6814 if (record_full_arch_list_add_mem (oaddr, 16))
6815 return -1;
6816 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6817 return -1;
6818 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
6819 return -1;
6820 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6821 return -1;
6822 break;
6823
6824 /* 0xeb3f-0xeb43 undefined */
6825 /* 0xeb46-0xeb4b undefined */
6826 /* 0xeb4d-0xeb50 undefined */
6827
6828 case 0xeb52: /* MVIY - move */
6829 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6830 if (record_full_arch_list_add_mem (oaddr, 1))
6831 return -1;
6832 break;
6833
6834 case 0xeb54: /* NIY - and */
6835 case 0xeb56: /* OIY - or */
6836 case 0xeb57: /* XIY - xor */
6837 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6838 if (record_full_arch_list_add_mem (oaddr, 1))
6839 return -1;
6840 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6841 return -1;
6842 break;
6843
6844 /* 0xeb53 undefined */
6845 /* 0xeb58-0xeb69 undefined */
6846
6847 case 0xeb6a: /* ASI - add immediate */
6848 case 0xeb6e: /* ALSI - add immediate */
6849 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6850 if (record_full_arch_list_add_mem (oaddr, 4))
6851 return -1;
6852 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6853 return -1;
6854 break;
6855
6856 /* 0xeb6b-0xeb6d undefined */
6857 /* 0xeb6f-0xeb79 undefined */
6858
6859 case 0xeb7a: /* AGSI - add immediate */
6860 case 0xeb7e: /* ALGSI - add immediate */
6861 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6862 if (record_full_arch_list_add_mem (oaddr, 8))
6863 return -1;
6864 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6865 return -1;
6866 break;
6867
6868 /* 0xeb7b-0xeb7d undefined */
6869 /* 0xeb7f undefined */
6870
6871 case 0xeb80: /* ICMH - insert characters under mask */
6872 /* 32-bit high gpr destination + flags */
6873 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
6874 return -1;
6875 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6876 return -1;
6877 break;
6878
6879 /* 0xeb82-0xeb8d undefined */
6880
6881 case 0xeb8e: /* MVCLU - move long unicode [partial] */
6882 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
6883 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
6884 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[2] | 1), &tmp);
6885 if (record_full_arch_list_add_mem (oaddr, tmp))
6886 return -1;
6887 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6888 return -1;
6889 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6890 return -1;
6891 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6892 return -1;
6893 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
6894 return -1;
6895 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6896 return -1;
6897 break;
6898
6899 case 0xeb8f: /* CLCLU - compare logical long unicode [partial] */
6900 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6901 return -1;
6902 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6903 return -1;
6904 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6905 return -1;
6906 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
6907 return -1;
6908 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6909 return -1;
6910 break;
6911
6912 /* 0xeb91-0xeb95 undefined */
6913
6914 case 0xeb96: /* LMH - load multiple high */
6915 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6916 if (s390_record_gpr_h (gdbarch, regcache, i))
6917 return -1;
6918 if (s390_record_gpr_h (gdbarch, regcache, inib[3]))
6919 return -1;
6920 break;
6921
6922 /* 0xeb97 undefined */
6923
6924 case 0xeb98: /* LMY - load multiple */
6925 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6926 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
6927 return -1;
6928 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6929 return -1;
6930 break;
6931
6932 /* 0xeb99 undefined */
6933
6934 case 0xeb9a: /* LAMY - load access multiple */
6935 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6936 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + i))
6937 return -1;
6938 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[3]))
6939 return -1;
6940 break;
6941
6942 /* 0xeb9c-0xebbf undefined */
6943 /* 0xebc1-0xebdb undefined */
6944 /* 0xebe5 undefined */
6945 /* 0xebe9 undefined */
6946 /* 0xebeb-0xebf1 undefined */
6947 /* 0xebf5 undefined */
6948 /* 0xebf9 undefined */
6949 /* 0xebfb-0xebff undefined */
6950
6951 /* 0xed00-0xed03 undefined */
6952
6953 case 0xed04: /* LDEB - load lengthened */
6954 case 0xed0c: /* MDEB - multiply */
6955 case 0xed0d: /* DEB - divide */
6956 case 0xed14: /* SQEB - square root */
6957 case 0xed15: /* SQDB - square root */
6958 case 0xed17: /* MEEB - multiply */
6959 case 0xed1c: /* MDB - multiply */
6960 case 0xed1d: /* DDB - divide */
6961 /* float destination + fpc */
6962 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6963 return -1;
6964 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6965 return -1;
6966 break;
6967
6968 case 0xed05: /* LXDB - load lengthened */
6969 case 0xed06: /* LXEB - load lengthened */
6970 case 0xed07: /* MXDB - multiply */
6971 /* float pair destination + fpc */
6972 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6973 return -1;
6974 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
6975 return -1;
6976 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6977 return -1;
6978 break;
6979
6980 case 0xed0a: /* AEB - add */
6981 case 0xed0b: /* SEB - subtract */
6982 case 0xed1a: /* ADB - add */
6983 case 0xed1b: /* SDB - subtract */
6984 /* float destination + flags + fpc */
6985 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6986 return -1;
6987 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6988 return -1;
6989 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6990 return -1;
6991 break;
6992
6993 case 0xed0e: /* MAEB - multiply and add */
6994 case 0xed0f: /* MSEB - multiply and subtract */
6995 case 0xed1e: /* MADB - multiply and add */
6996 case 0xed1f: /* MSDB - multiply and subtract */
6997 case 0xed40: /* SLDT - shift significand left */
6998 case 0xed41: /* SRDT - shift significand right */
6999 case 0xedaa: /* CDZT - convert from zoned */
7000 case 0xedae: /* CDPT - convert from packed */
7001 /* float destination [RXF] + fpc */
7002 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
7003 return -1;
7004 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
7005 return -1;
7006 break;
7007
7008 /* 0xed13 undefined */
7009 /* 0xed16 undefined */
7010 /* 0xed20-0xed23 undefined */
7011
7012 case 0xed24: /* LDE - load lengthened */
7013 case 0xed34: /* SQE - square root */
7014 case 0xed35: /* SQD - square root */
7015 case 0xed37: /* MEE - multiply */
7016 case 0xed64: /* LEY - load */
7017 case 0xed65: /* LDY - load */
7018 /* float destination */
7019 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
7020 return -1;
7021 break;
7022
7023 case 0xed25: /* LXD - load lengthened */
7024 case 0xed26: /* LXE - load lengthened */
7025 /* float pair destination */
7026 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
7027 return -1;
7028 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
7029 return -1;
7030 break;
7031
7032 /* 0xed27-0xed2d undefined */
7033
7034 case 0xed2e: /* MAE - multiply and add */
7035 case 0xed2f: /* MSE - multiply and subtract */
7036 case 0xed38: /* MAYL - multiply and add unnormalized */
7037 case 0xed39: /* MYL - multiply unnormalized */
7038 case 0xed3c: /* MAYH - multiply and add unnormalized */
7039 case 0xed3d: /* MYH - multiply unnormalized */
7040 case 0xed3e: /* MAD - multiply and add */
7041 case 0xed3f: /* MSD - multiply and subtract */
7042 /* float destination [RXF] */
7043 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
7044 return -1;
7045 break;
7046
7047 /* 0xed30-0xed33 undefined */
7048 /* 0xed36 undefined */
7049
7050 case 0xed3a: /* MAY - multiply and add unnormalized */
7051 case 0xed3b: /* MY - multiply unnormalized */
7052 /* float pair destination [RXF] */
7053 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
7054 return -1;
7055 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[8] | 2)))
7056 return -1;
7057 break;
7058
7059 /* 0xed42-0xed47 undefind */
7060
7061 case 0xed48: /* SLXT - shift significand left */
7062 case 0xed49: /* SRXT - shift significand right */
7063 case 0xedab: /* CXZT - convert from zoned */
7064 case 0xedaf: /* CXPT - convert from packed */
7065 /* float pair destination [RXF] + fpc */
7066 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
7067 return -1;
7068 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[8] | 2)))
7069 return -1;
7070 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
7071 return -1;
7072 break;
7073
7074 /* 0xed4a-0xed4f undefind */
7075 /* 0xed52-0xed53 undefind */
7076 /* 0xed56-0xed57 undefind */
7077 /* 0xed5a-0xed63 undefind */
7078 /* 0xed68-0xeda7 undefined */
7079
7080 case 0xeda8: /* CZDT - convert to zoned */
7081 case 0xeda9: /* CZXT - convert to zoned */
7082 case 0xedac: /* CPDT - convert to packed */
7083 case 0xedad: /* CPXT - convert to packed */
7084 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7085 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
7086 return -1;
7087 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7088 return -1;
7089 break;
7090
7091 /* 0xedb0-0xedff undefined */
7092
7093 default:
7094 goto UNKNOWN_OP;
7095 }
7096 break;
7097
7098 /* 0xe4 undefined */
7099
7100 case 0xe5:
7101 /* SSE/SIL-format instruction */
7102 switch (insn[0])
7103 {
7104 /* 0xe500-0xe543 undefined, privileged, or unsupported */
7105
7106 case 0xe544: /* MVHHI - move */
7107 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7108 if (record_full_arch_list_add_mem (oaddr, 2))
7109 return -1;
7110 break;
7111
7112 /* 0xe545-0xe547 undefined */
7113
7114 case 0xe548: /* MVGHI - move */
7115 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7116 if (record_full_arch_list_add_mem (oaddr, 8))
7117 return -1;
7118 break;
7119
7120 /* 0xe549-0xe54b undefined */
7121
7122 case 0xe54c: /* MVHI - move */
7123 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7124 if (record_full_arch_list_add_mem (oaddr, 4))
7125 return -1;
7126 break;
7127
7128 /* 0xe54d-0xe553 undefined */
7129
7130 case 0xe554: /* CHHSI - compare halfword immediate */
7131 case 0xe555: /* CLHHSI - compare logical immediate */
7132 case 0xe558: /* CGHSI - compare halfword immediate */
7133 case 0xe559: /* CLGHSI - compare logical immediate */
7134 case 0xe55c: /* CHSI - compare halfword immediate */
7135 case 0xe55d: /* CLFHSI - compare logical immediate */
7136 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7137 return -1;
7138 break;
7139
7140 /* 0xe556-0xe557 undefined */
7141 /* 0xe55a-0xe55b undefined */
7142 /* 0xe55e-0xe55f undefined */
7143
7144 case 0xe560: /* TBEGIN - transaction begin */
7145 /* The transaction will be immediately aborted after this
7146 instruction, due to single-stepping. This instruction is
7147 only supported so that the program can fail a few times
7148 and go to the non-transactional fallback. */
7149 if (inib[4])
7150 {
7151 /* Transaction diagnostic block - user. */
7152 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7153 if (record_full_arch_list_add_mem (oaddr, 256))
7154 return -1;
7155 }
7156 /* Transaction diagnostic block - supervisor. */
7157 if (record_full_arch_list_add_reg (regcache, S390_TDB_DWORD0_REGNUM))
7158 return -1;
7159 if (record_full_arch_list_add_reg (regcache, S390_TDB_ABORT_CODE_REGNUM))
7160 return -1;
7161 if (record_full_arch_list_add_reg (regcache, S390_TDB_CONFLICT_TOKEN_REGNUM))
7162 return -1;
7163 if (record_full_arch_list_add_reg (regcache, S390_TDB_ATIA_REGNUM))
7164 return -1;
7165 for (i = 0; i < 16; i++)
7166 if (record_full_arch_list_add_reg (regcache, S390_TDB_R0_REGNUM + i))
7167 return -1;
7168 /* And flags. */
7169 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7170 return -1;
7171 break;
7172
7173 /* 0xe561 unsupported: TBEGINC */
7174 /* 0xe562-0xe5ff undefined */
7175
7176 default:
7177 goto UNKNOWN_OP;
7178 }
7179 break;
7180
7181 case 0xec:
7182 /* RIE/RIS/RRS-format instruction */
7183 switch (ibyte[0] << 8 | ibyte[5])
7184 {
7185 /* 0xec00-0xec41 undefined */
7186
7187 case 0xec42: /* LOCHI - load halfword immediate on condition */
7188 case 0xec51: /* RISBLG - rotate then insert selected bits low */
7189 /* 32-bit or native gpr destination */
7190 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
7191 return -1;
7192 break;
7193
7194 /* 0xec43 undefined */
7195
7196 case 0xec44: /* BRXHG - branch relative on index high */
7197 case 0xec45: /* BRXLG - branch relative on index low or equal */
7198 case 0xec46: /* LOCGHI - load halfword immediate on condition */
7199 case 0xec59: /* RISBGN - rotate then insert selected bits */
7200 /* 64-bit gpr destination */
7201 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
7202 return -1;
7203 break;
7204
7205 /* 0xec47-0xec4d undefined */
7206
7207 case 0xec4e: /* LOCHHI - load halfword immediate on condition */
7208 case 0xec5d: /* RISBHG - rotate then insert selected bits high */
7209 /* 32-bit high gpr destination */
7210 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
7211 return -1;
7212 break;
7213
7214 /* 0xec4f-0xec50 undefined */
7215 /* 0xec52-0xec53 undefined */
7216
7217 case 0xec54: /* RNSBG - rotate then and selected bits */
7218 case 0xec55: /* RISBG - rotate then insert selected bits */
7219 case 0xec56: /* ROSBG - rotate then or selected bits */
7220 case 0xec57: /* RXSBG - rotate then xor selected bits */
7221 case 0xecd9: /* AGHIK - add immediate */
7222 case 0xecdb: /* ALGHSIK - add logical immediate */
7223 /* 64-bit gpr destination + flags */
7224 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
7225 return -1;
7226 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7227 return -1;
7228 break;
7229
7230 /* 0xec58 undefined */
7231 /* 0xec5a-0xec5c undefined */
7232 /* 0xec5e-0xec63 undefined */
7233
7234 case 0xec64: /* CGRJ - compare and branch relative */
7235 case 0xec65: /* CLGRJ - compare logical and branch relative */
7236 case 0xec76: /* CRJ - compare and branch relative */
7237 case 0xec77: /* CLRJ - compare logical and branch relative */
7238 case 0xec7c: /* CGIJ - compare immediate and branch relative */
7239 case 0xec7d: /* CLGIJ - compare logical immediate and branch relative */
7240 case 0xec7e: /* CIJ - compare immediate and branch relative */
7241 case 0xec7f: /* CLIJ - compare logical immediate and branch relative */
7242 case 0xece4: /* CGRB - compare and branch */
7243 case 0xece5: /* CLGRB - compare logical and branch */
7244 case 0xecf6: /* CRB - compare and branch */
7245 case 0xecf7: /* CLRB - compare logical and branch */
7246 case 0xecfc: /* CGIB - compare immediate and branch */
7247 case 0xecfd: /* CLGIB - compare logical immediate and branch */
7248 case 0xecfe: /* CIB - compare immediate and branch */
7249 case 0xecff: /* CLIB - compare logical immediate and branch */
7250 break;
7251
7252 /* 0xec66-0xec6f undefined */
7253
7254 case 0xec70: /* CGIT - compare immediate and trap */
7255 case 0xec71: /* CLGIT - compare logical immediate and trap */
7256 case 0xec72: /* CIT - compare immediate and trap */
7257 case 0xec73: /* CLFIT - compare logical immediate and trap */
7258 /* fpc only - including possible DXC write for trapping insns */
7259 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
7260 return -1;
7261 break;
7262
7263 /* 0xec74-0xec75 undefined */
7264 /* 0xec78-0xec7b undefined */
7265
7266 /* 0xec80-0xecd7 undefined */
7267
7268 case 0xecd8: /* AHIK - add immediate */
7269 case 0xecda: /* ALHSIK - add logical immediate */
7270 /* 32-bit gpr destination + flags */
7271 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
7272 return -1;
7273 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7274 return -1;
7275 break;
7276
7277 /* 0xecdc-0xece3 undefined */
7278 /* 0xece6-0xecf5 undefined */
7279 /* 0xecf8-0xecfb undefined */
7280
7281 default:
7282 goto UNKNOWN_OP;
7283 }
7284 break;
7285
7286 case 0xee: /* PLO - perform locked operation */
7287 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
7288 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7289 oaddr2 = s390_record_calc_disp (gdbarch, regcache, 0, insn[2], 0);
7290 if (!(tmp & 0x100))
7291 {
7292 uint8_t fc = tmp & 0xff;
7293 gdb_byte buf[8];
7294 switch (fc)
7295 {
7296 case 0x00: /* CL */
7297 /* op1c */
7298 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
7299 return -1;
7300 /* op3 */
7301 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
7302 return -1;
7303 break;
7304
7305 case 0x01: /* CLG */
7306 /* op1c */
7307 if (record_full_arch_list_add_mem (oaddr2 + 0x08, 8))
7308 return -1;
7309 /* op3 */
7310 if (record_full_arch_list_add_mem (oaddr2 + 0x28, 8))
7311 return -1;
7312 break;
7313
7314 case 0x02: /* CLGR */
7315 /* op1c */
7316 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
7317 return -1;
7318 /* op3 */
7319 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
7320 return -1;
7321 break;
7322
7323 case 0x03: /* CLX */
7324 /* op1c */
7325 if (record_full_arch_list_add_mem (oaddr2 + 0x00, 16))
7326 return -1;
7327 /* op3 */
7328 if (record_full_arch_list_add_mem (oaddr2 + 0x20, 16))
7329 return -1;
7330 break;
7331
7332 case 0x08: /* DCS */
7333 /* op3c */
7334 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
7335 return -1;
7336 /* fallthru */
7337 case 0x0c: /* CSST */
7338 /* op4 */
7339 if (record_full_arch_list_add_mem (oaddr2, 4))
7340 return -1;
7341 goto CS;
7342
7343 case 0x14: /* CSTST */
7344 /* op8 */
7345 if (target_read_memory (oaddr2 + 0x88, buf, 8))
7346 return -1;
7347 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7348 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7349 if (record_full_arch_list_add_mem (oaddr3, 4))
7350 return -1;
7351 /* fallthru */
7352 case 0x10: /* CSDST */
7353 /* op6 */
7354 if (target_read_memory (oaddr2 + 0x68, buf, 8))
7355 return -1;
7356 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7357 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7358 if (record_full_arch_list_add_mem (oaddr3, 4))
7359 return -1;
7360 /* op4 */
7361 if (target_read_memory (oaddr2 + 0x48, buf, 8))
7362 return -1;
7363 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7364 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7365 if (record_full_arch_list_add_mem (oaddr3, 4))
7366 return -1;
7367 /* fallthru */
7368 case 0x04: /* CS */
7369 CS:
7370 /* op1c */
7371 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
7372 return -1;
7373 /* op2 */
7374 if (record_full_arch_list_add_mem (oaddr, 4))
7375 return -1;
7376 break;
7377
7378 case 0x09: /* DCSG */
7379 /* op3c */
7380 if (record_full_arch_list_add_mem (oaddr2 + 0x28, 8))
7381 return -1;
7382 goto CSSTG;
7383
7384 case 0x15: /* CSTSTG */
7385 /* op8 */
7386 if (target_read_memory (oaddr2 + 0x88, buf, 8))
7387 return -1;
7388 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7389 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7390 if (record_full_arch_list_add_mem (oaddr3, 8))
7391 return -1;
7392 /* fallthru */
7393 case 0x11: /* CSDSTG */
7394 /* op6 */
7395 if (target_read_memory (oaddr2 + 0x68, buf, 8))
7396 return -1;
7397 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7398 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7399 if (record_full_arch_list_add_mem (oaddr3, 8))
7400 return -1;
7401 /* fallthru */
7402 case 0x0d: /* CSSTG */
7403 CSSTG:
7404 /* op4 */
7405 if (target_read_memory (oaddr2 + 0x48, buf, 8))
7406 return -1;
7407 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7408 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7409 if (record_full_arch_list_add_mem (oaddr3, 8))
7410 return -1;
7411 /* fallthru */
7412 case 0x05: /* CSG */
7413 /* op1c */
7414 if (record_full_arch_list_add_mem (oaddr2 + 0x08, 8))
7415 return -1;
7416 /* op2 */
7417 if (record_full_arch_list_add_mem (oaddr, 8))
7418 return -1;
7419 break;
7420
7421 case 0x0a: /* DCSGR */
7422 /* op3c */
7423 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
7424 return -1;
7425 /* fallthru */
7426 case 0x0e: /* CSSTGR */
7427 /* op4 */
7428 if (record_full_arch_list_add_mem (oaddr2, 8))
7429 return -1;
7430 goto CSGR;
7431
7432 case 0x16: /* CSTSTGR */
7433 /* op8 */
7434 if (target_read_memory (oaddr2 + 0x88, buf, 8))
7435 return -1;
7436 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7437 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7438 if (record_full_arch_list_add_mem (oaddr3, 8))
7439 return -1;
7440 /* fallthru */
7441 case 0x12: /* CSDSTGR */
7442 /* op6 */
7443 if (target_read_memory (oaddr2 + 0x68, buf, 8))
7444 return -1;
7445 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7446 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7447 if (record_full_arch_list_add_mem (oaddr3, 8))
7448 return -1;
7449 /* op4 */
7450 if (target_read_memory (oaddr2 + 0x48, buf, 8))
7451 return -1;
7452 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7453 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7454 if (record_full_arch_list_add_mem (oaddr3, 8))
7455 return -1;
7456 /* fallthru */
7457 case 0x06: /* CSGR */
7458 CSGR:
7459 /* op1c */
7460 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
7461 return -1;
7462 /* op2 */
7463 if (record_full_arch_list_add_mem (oaddr, 8))
7464 return -1;
7465 break;
7466
7467 case 0x0b: /* DCSX */
7468 /* op3c */
7469 if (record_full_arch_list_add_mem (oaddr2 + 0x20, 16))
7470 return -1;
7471 goto CSSTX;
7472
7473 case 0x17: /* CSTSTX */
7474 /* op8 */
7475 if (target_read_memory (oaddr2 + 0x88, buf, 8))
7476 return -1;
7477 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7478 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7479 if (record_full_arch_list_add_mem (oaddr3, 16))
7480 return -1;
7481 /* fallthru */
7482 case 0x13: /* CSDSTX */
7483 /* op6 */
7484 if (target_read_memory (oaddr2 + 0x68, buf, 8))
7485 return -1;
7486 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7487 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7488 if (record_full_arch_list_add_mem (oaddr3, 16))
7489 return -1;
7490 /* fallthru */
7491 case 0x0f: /* CSSTX */
7492 CSSTX:
7493 /* op4 */
7494 if (target_read_memory (oaddr2 + 0x48, buf, 8))
7495 return -1;
7496 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
7497 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
7498 if (record_full_arch_list_add_mem (oaddr3, 16))
7499 return -1;
7500 /* fallthru */
7501 case 0x07: /* CSX */
7502 /* op1c */
7503 if (record_full_arch_list_add_mem (oaddr2 + 0x00, 16))
7504 return -1;
7505 /* op2 */
7506 if (record_full_arch_list_add_mem (oaddr, 16))
7507 return -1;
7508 break;
7509
7510 default:
7511 fprintf_unfiltered (gdb_stdlog, "Warning: Unknown PLO FC %02x at %s.\n",
7512 fc, paddress (gdbarch, addr));
7513 return -1;
7514 }
7515 }
7516 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7517 return -1;
7518 break;
7519
7520 case 0xef: /* LMD - load multiple disjoint */
7521 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
7522 if (s390_record_gpr_g (gdbarch, regcache, i))
7523 return -1;
7524 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
7525 return -1;
7526 break;
7527
7528 case 0xf0: /* SRP - shift and round decimal */
7529 case 0xf8: /* ZAP - zero and add */
7530 case 0xfa: /* AP - add decimal */
7531 case 0xfb: /* SP - subtract decimal */
7532 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7533 if (record_full_arch_list_add_mem (oaddr, inib[2] + 1))
7534 return -1;
7535 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7536 return -1;
7537 /* DXC may be written */
7538 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
7539 return -1;
7540 break;
7541
7542 case 0xf1: /* MVO - move with offset */
7543 case 0xf2: /* PACK - pack */
7544 case 0xf3: /* UNPK - unpack */
7545 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7546 if (record_full_arch_list_add_mem (oaddr, inib[2] + 1))
7547 return -1;
7548 break;
7549
7550 /* 0xf4-0xf7 undefined */
7551
7552 case 0xf9: /* CP - compare decimal */
7553 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
7554 return -1;
7555 /* DXC may be written */
7556 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
7557 return -1;
7558 break;
7559
7560 case 0xfc: /* MP - multiply decimal */
7561 case 0xfd: /* DP - divide decimal */
7562 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
7563 if (record_full_arch_list_add_mem (oaddr, inib[2] + 1))
7564 return -1;
7565 /* DXC may be written */
7566 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
7567 return -1;
7568 break;
7569
7570 /* 0xfe-0xff undefined */
7571
7572 default:
7573 UNKNOWN_OP:
7574 fprintf_unfiltered (gdb_stdlog, "Warning: Don't know how to record %04x "
7575 "at %s.\n", insn[0], paddress (gdbarch, addr));
7576 return -1;
7577 }
7578
7579 if (record_full_arch_list_add_reg (regcache, S390_PSWA_REGNUM))
7580 return -1;
7581 if (record_full_arch_list_add_end ())
7582 return -1;
7583 return 0;
7584 }
7585
7586 /* Initialize linux_record_tdep if not initialized yet. */
7587
7588 static void
7589 s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
7590 enum s390_abi_kind abi)
7591 {
7592 /* These values are the size of the type that will be used in a system
7593 call. They are obtained from Linux Kernel source. */
7594
7595 if (abi == ABI_LINUX_ZSERIES)
7596 {
7597 record_tdep->size_pointer = 8;
7598 /* no _old_kernel_stat */
7599 record_tdep->size_tms = 32;
7600 record_tdep->size_loff_t = 8;
7601 record_tdep->size_flock = 32;
7602 record_tdep->size_ustat = 32;
7603 record_tdep->size_old_sigaction = 32;
7604 record_tdep->size_old_sigset_t = 8;
7605 record_tdep->size_rlimit = 16;
7606 record_tdep->size_rusage = 144;
7607 record_tdep->size_timeval = 16;
7608 record_tdep->size_timezone = 8;
7609 /* old_[ug]id_t never used */
7610 record_tdep->size_fd_set = 128;
7611 record_tdep->size_old_dirent = 280;
7612 record_tdep->size_statfs = 88;
7613 record_tdep->size_statfs64 = 88;
7614 record_tdep->size_sockaddr = 16;
7615 record_tdep->size_int = 4;
7616 record_tdep->size_long = 8;
7617 record_tdep->size_ulong = 8;
7618 record_tdep->size_msghdr = 56;
7619 record_tdep->size_itimerval = 32;
7620 record_tdep->size_stat = 144;
7621 /* old_utsname unused */
7622 record_tdep->size_sysinfo = 112;
7623 record_tdep->size_msqid_ds = 120;
7624 record_tdep->size_shmid_ds = 112;
7625 record_tdep->size_new_utsname = 390;
7626 record_tdep->size_timex = 208;
7627 record_tdep->size_mem_dqinfo = 24;
7628 record_tdep->size_if_dqblk = 72;
7629 record_tdep->size_fs_quota_stat = 80;
7630 record_tdep->size_timespec = 16;
7631 record_tdep->size_pollfd = 8;
7632 record_tdep->size_NFS_FHSIZE = 32;
7633 record_tdep->size_knfsd_fh = 132;
7634 record_tdep->size_TASK_COMM_LEN = 16;
7635 record_tdep->size_sigaction = 32;
7636 record_tdep->size_sigset_t = 8;
7637 record_tdep->size_siginfo_t = 128;
7638 record_tdep->size_cap_user_data_t = 12;
7639 record_tdep->size_stack_t = 24;
7640 record_tdep->size_off_t = 8;
7641 /* stat64 unused */
7642 record_tdep->size_gid_t = 4;
7643 record_tdep->size_uid_t = 4;
7644 record_tdep->size_PAGE_SIZE = 0x1000; /* 4KB */
7645 record_tdep->size_flock64 = 32;
7646 record_tdep->size_io_event = 32;
7647 record_tdep->size_iocb = 64;
7648 record_tdep->size_epoll_event = 16;
7649 record_tdep->size_itimerspec = 32;
7650 record_tdep->size_mq_attr = 64;
7651 record_tdep->size_termios = 36;
7652 record_tdep->size_termios2 = 44;
7653 record_tdep->size_pid_t = 4;
7654 record_tdep->size_winsize = 8;
7655 record_tdep->size_serial_struct = 72;
7656 record_tdep->size_serial_icounter_struct = 80;
7657 record_tdep->size_size_t = 8;
7658 record_tdep->size_iovec = 16;
7659 record_tdep->size_time_t = 8;
7660 }
7661 else if (abi == ABI_LINUX_S390)
7662 {
7663 record_tdep->size_pointer = 4;
7664 record_tdep->size__old_kernel_stat = 32;
7665 record_tdep->size_tms = 16;
7666 record_tdep->size_loff_t = 8;
7667 record_tdep->size_flock = 16;
7668 record_tdep->size_ustat = 20;
7669 record_tdep->size_old_sigaction = 16;
7670 record_tdep->size_old_sigset_t = 4;
7671 record_tdep->size_rlimit = 8;
7672 record_tdep->size_rusage = 72;
7673 record_tdep->size_timeval = 8;
7674 record_tdep->size_timezone = 8;
7675 record_tdep->size_old_gid_t = 2;
7676 record_tdep->size_old_uid_t = 2;
7677 record_tdep->size_fd_set = 128;
7678 record_tdep->size_old_dirent = 268;
7679 record_tdep->size_statfs = 64;
7680 record_tdep->size_statfs64 = 88;
7681 record_tdep->size_sockaddr = 16;
7682 record_tdep->size_int = 4;
7683 record_tdep->size_long = 4;
7684 record_tdep->size_ulong = 4;
7685 record_tdep->size_msghdr = 28;
7686 record_tdep->size_itimerval = 16;
7687 record_tdep->size_stat = 64;
7688 /* old_utsname unused */
7689 record_tdep->size_sysinfo = 64;
7690 record_tdep->size_msqid_ds = 88;
7691 record_tdep->size_shmid_ds = 84;
7692 record_tdep->size_new_utsname = 390;
7693 record_tdep->size_timex = 128;
7694 record_tdep->size_mem_dqinfo = 24;
7695 record_tdep->size_if_dqblk = 72;
7696 record_tdep->size_fs_quota_stat = 80;
7697 record_tdep->size_timespec = 8;
7698 record_tdep->size_pollfd = 8;
7699 record_tdep->size_NFS_FHSIZE = 32;
7700 record_tdep->size_knfsd_fh = 132;
7701 record_tdep->size_TASK_COMM_LEN = 16;
7702 record_tdep->size_sigaction = 20;
7703 record_tdep->size_sigset_t = 8;
7704 record_tdep->size_siginfo_t = 128;
7705 record_tdep->size_cap_user_data_t = 12;
7706 record_tdep->size_stack_t = 12;
7707 record_tdep->size_off_t = 4;
7708 record_tdep->size_stat64 = 104;
7709 record_tdep->size_gid_t = 4;
7710 record_tdep->size_uid_t = 4;
7711 record_tdep->size_PAGE_SIZE = 0x1000; /* 4KB */
7712 record_tdep->size_flock64 = 32;
7713 record_tdep->size_io_event = 32;
7714 record_tdep->size_iocb = 64;
7715 record_tdep->size_epoll_event = 16;
7716 record_tdep->size_itimerspec = 16;
7717 record_tdep->size_mq_attr = 32;
7718 record_tdep->size_termios = 36;
7719 record_tdep->size_termios2 = 44;
7720 record_tdep->size_pid_t = 4;
7721 record_tdep->size_winsize = 8;
7722 record_tdep->size_serial_struct = 60;
7723 record_tdep->size_serial_icounter_struct = 80;
7724 record_tdep->size_size_t = 4;
7725 record_tdep->size_iovec = 8;
7726 record_tdep->size_time_t = 4;
7727 }
7728
7729 /* These values are the second argument of system call "sys_fcntl"
7730 and "sys_fcntl64". They are obtained from Linux Kernel source. */
7731 record_tdep->fcntl_F_GETLK = 5;
7732 record_tdep->fcntl_F_GETLK64 = 12;
7733 record_tdep->fcntl_F_SETLK64 = 13;
7734 record_tdep->fcntl_F_SETLKW64 = 14;
7735
7736 record_tdep->arg1 = S390_R2_REGNUM;
7737 record_tdep->arg2 = S390_R3_REGNUM;
7738 record_tdep->arg3 = S390_R4_REGNUM;
7739 record_tdep->arg4 = S390_R5_REGNUM;
7740 record_tdep->arg5 = S390_R6_REGNUM;
7741
7742 /* These values are the second argument of system call "sys_ioctl".
7743 They are obtained from Linux Kernel source.
7744 See arch/s390/include/uapi/asm/ioctls.h. */
7745
7746 record_tdep->ioctl_TCGETS = 0x5401;
7747 record_tdep->ioctl_TCSETS = 0x5402;
7748 record_tdep->ioctl_TCSETSW = 0x5403;
7749 record_tdep->ioctl_TCSETSF = 0x5404;
7750 record_tdep->ioctl_TCGETA = 0x5405;
7751 record_tdep->ioctl_TCSETA = 0x5406;
7752 record_tdep->ioctl_TCSETAW = 0x5407;
7753 record_tdep->ioctl_TCSETAF = 0x5408;
7754 record_tdep->ioctl_TCSBRK = 0x5409;
7755 record_tdep->ioctl_TCXONC = 0x540a;
7756 record_tdep->ioctl_TCFLSH = 0x540b;
7757 record_tdep->ioctl_TIOCEXCL = 0x540c;
7758 record_tdep->ioctl_TIOCNXCL = 0x540d;
7759 record_tdep->ioctl_TIOCSCTTY = 0x540e;
7760 record_tdep->ioctl_TIOCGPGRP = 0x540f;
7761 record_tdep->ioctl_TIOCSPGRP = 0x5410;
7762 record_tdep->ioctl_TIOCOUTQ = 0x5411;
7763 record_tdep->ioctl_TIOCSTI = 0x5412;
7764 record_tdep->ioctl_TIOCGWINSZ = 0x5413;
7765 record_tdep->ioctl_TIOCSWINSZ = 0x5414;
7766 record_tdep->ioctl_TIOCMGET = 0x5415;
7767 record_tdep->ioctl_TIOCMBIS = 0x5416;
7768 record_tdep->ioctl_TIOCMBIC = 0x5417;
7769 record_tdep->ioctl_TIOCMSET = 0x5418;
7770 record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
7771 record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
7772 record_tdep->ioctl_FIONREAD = 0x541b;
7773 record_tdep->ioctl_TIOCINQ = 0x541b; /* alias */
7774 record_tdep->ioctl_TIOCLINUX = 0x541c;
7775 record_tdep->ioctl_TIOCCONS = 0x541d;
7776 record_tdep->ioctl_TIOCGSERIAL = 0x541e;
7777 record_tdep->ioctl_TIOCSSERIAL = 0x541f;
7778 record_tdep->ioctl_TIOCPKT = 0x5420;
7779 record_tdep->ioctl_FIONBIO = 0x5421;
7780 record_tdep->ioctl_TIOCNOTTY = 0x5422;
7781 record_tdep->ioctl_TIOCSETD = 0x5423;
7782 record_tdep->ioctl_TIOCGETD = 0x5424;
7783 record_tdep->ioctl_TCSBRKP = 0x5425;
7784 record_tdep->ioctl_TIOCSBRK = 0x5427;
7785 record_tdep->ioctl_TIOCCBRK = 0x5428;
7786 record_tdep->ioctl_TIOCGSID = 0x5429;
7787 record_tdep->ioctl_TCGETS2 = 0x802c542a;
7788 record_tdep->ioctl_TCSETS2 = 0x402c542b;
7789 record_tdep->ioctl_TCSETSW2 = 0x402c542c;
7790 record_tdep->ioctl_TCSETSF2 = 0x402c542d;
7791 record_tdep->ioctl_TIOCGPTN = 0x80045430;
7792 record_tdep->ioctl_TIOCSPTLCK = 0x40045431;
7793 record_tdep->ioctl_FIONCLEX = 0x5450;
7794 record_tdep->ioctl_FIOCLEX = 0x5451;
7795 record_tdep->ioctl_FIOASYNC = 0x5452;
7796 record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
7797 record_tdep->ioctl_TIOCSERGWILD = 0x5454;
7798 record_tdep->ioctl_TIOCSERSWILD = 0x5455;
7799 record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
7800 record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
7801 record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
7802 record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
7803 record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
7804 record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
7805 record_tdep->ioctl_TIOCMIWAIT = 0x545c;
7806 record_tdep->ioctl_TIOCGICOUNT = 0x545d;
7807 record_tdep->ioctl_FIOQSIZE = 0x545e;
7808 }
7809
7810 /* Allocate and initialize new gdbarch_tdep. Caller is responsible to free
7811 memory after use. */
7812
7813 static struct gdbarch_tdep *
7814 s390_gdbarch_tdep_alloc ()
7815 {
7816 struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep);
7817
7818 tdep->abi = ABI_NONE;
7819 tdep->vector_abi = S390_VECTOR_ABI_NONE;
7820
7821 tdep->gpr_full_regnum = -1;
7822 tdep->v0_full_regnum = -1;
7823 tdep->pc_regnum = -1;
7824 tdep->cc_regnum = -1;
7825
7826 tdep->have_upper = false;
7827 tdep->have_linux_v1 = 0;
7828 tdep->have_linux_v2 = 0;
7829 tdep->have_tdb = 0;
7830 tdep->have_vx = false;
7831 tdep->have_gs = false;
7832
7833 return tdep;
7834 }
7835
7836 /* Set up gdbarch struct. */
7837
7838 static struct gdbarch *
7839 s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
7840 {
7841 const struct target_desc *tdesc = info.target_desc;
7842 struct tdesc_arch_data *tdesc_data = NULL;
7843 int first_pseudo_reg, last_pseudo_reg;
7844 static const char *const stap_register_prefixes[] = { "%", NULL };
7845 static const char *const stap_register_indirection_prefixes[] = { "(",
7846 NULL };
7847 static const char *const stap_register_indirection_suffixes[] = { ")",
7848 NULL };
7849
7850 struct gdbarch_tdep *tdep = s390_gdbarch_tdep_alloc ();
7851 struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep);
7852
7853 /* Default ABI and register size. */
7854 switch (info.bfd_arch_info->mach)
7855 {
7856 case bfd_mach_s390_31:
7857 tdep->abi = ABI_LINUX_S390;
7858 break;
7859
7860 case bfd_mach_s390_64:
7861 tdep->abi = ABI_LINUX_ZSERIES;
7862 break;
7863
7864 default:
7865 xfree (tdep);
7866 gdbarch_free (gdbarch);
7867 return NULL;
7868 }
7869
7870 /* Use default target description if none provided by the target. */
7871 if (!tdesc_has_registers (tdesc))
7872 {
7873 if (tdep->abi == ABI_LINUX_S390)
7874 tdesc = tdesc_s390_linux32;
7875 else
7876 tdesc = tdesc_s390x_linux64;
7877 }
7878
7879 /* Check any target description for validity. */
7880 if (tdesc_has_registers (tdesc))
7881 {
7882 static const char *const gprs[] = {
7883 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
7884 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
7885 };
7886 static const char *const fprs[] = {
7887 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
7888 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
7889 };
7890 static const char *const acrs[] = {
7891 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
7892 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15"
7893 };
7894 static const char *const gprs_lower[] = {
7895 "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l",
7896 "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l"
7897 };
7898 static const char *const gprs_upper[] = {
7899 "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
7900 "r8h", "r9h", "r10h", "r11h", "r12h", "r13h", "r14h", "r15h"
7901 };
7902 static const char *const tdb_regs[] = {
7903 "tdb0", "tac", "tct", "atia",
7904 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7",
7905 "tr8", "tr9", "tr10", "tr11", "tr12", "tr13", "tr14", "tr15"
7906 };
7907 static const char *const vxrs_low[] = {
7908 "v0l", "v1l", "v2l", "v3l", "v4l", "v5l", "v6l", "v7l", "v8l",
7909 "v9l", "v10l", "v11l", "v12l", "v13l", "v14l", "v15l",
7910 };
7911 static const char *const vxrs_high[] = {
7912 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24",
7913 "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7914 };
7915 static const char *const gs_cb[] = {
7916 "gsd", "gssm", "gsepla",
7917 };
7918 static const char *const gs_bc[] = {
7919 "bc_gsd", "bc_gssm", "bc_gsepla",
7920 };
7921 const struct tdesc_feature *feature;
7922 int i, valid_p = 1;
7923
7924 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.core");
7925 if (feature == NULL)
7926 {
7927 xfree (tdep);
7928 gdbarch_free (gdbarch);
7929 return NULL;
7930 }
7931
7932 tdesc_data = tdesc_data_alloc ();
7933
7934 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7935 S390_PSWM_REGNUM, "pswm");
7936 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7937 S390_PSWA_REGNUM, "pswa");
7938
7939 if (tdesc_unnumbered_register (feature, "r0"))
7940 {
7941 for (i = 0; i < 16; i++)
7942 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7943 S390_R0_REGNUM + i, gprs[i]);
7944 }
7945 else
7946 {
7947 tdep->have_upper = true;
7948
7949 for (i = 0; i < 16; i++)
7950 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7951 S390_R0_REGNUM + i,
7952 gprs_lower[i]);
7953 for (i = 0; i < 16; i++)
7954 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7955 S390_R0_UPPER_REGNUM + i,
7956 gprs_upper[i]);
7957 }
7958
7959 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.fpr");
7960 if (feature == NULL)
7961 {
7962 tdesc_data_cleanup (tdesc_data);
7963 xfree (tdep);
7964 gdbarch_free (gdbarch);
7965 return NULL;
7966 }
7967
7968 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7969 S390_FPC_REGNUM, "fpc");
7970 for (i = 0; i < 16; i++)
7971 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7972 S390_F0_REGNUM + i, fprs[i]);
7973
7974 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.acr");
7975 if (feature == NULL)
7976 {
7977 tdesc_data_cleanup (tdesc_data);
7978 xfree (tdep);
7979 gdbarch_free (gdbarch);
7980 return NULL;
7981 }
7982
7983 for (i = 0; i < 16; i++)
7984 valid_p &= tdesc_numbered_register (feature, tdesc_data,
7985 S390_A0_REGNUM + i, acrs[i]);
7986
7987 /* Optional GNU/Linux-specific "registers". */
7988 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.linux");
7989 if (feature)
7990 {
7991 tdesc_numbered_register (feature, tdesc_data,
7992 S390_ORIG_R2_REGNUM, "orig_r2");
7993
7994 if (tdesc_numbered_register (feature, tdesc_data,
7995 S390_LAST_BREAK_REGNUM, "last_break"))
7996 tdep->have_linux_v1 = 1;
7997
7998 if (tdesc_numbered_register (feature, tdesc_data,
7999 S390_SYSTEM_CALL_REGNUM, "system_call"))
8000 tdep->have_linux_v2 = 1;
8001
8002 if (tdep->have_linux_v2 > tdep->have_linux_v1)
8003 valid_p = 0;
8004 }
8005
8006 /* Transaction diagnostic block. */
8007 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.tdb");
8008 if (feature)
8009 {
8010 for (i = 0; i < ARRAY_SIZE (tdb_regs); i++)
8011 valid_p &= tdesc_numbered_register (feature, tdesc_data,
8012 S390_TDB_DWORD0_REGNUM + i,
8013 tdb_regs[i]);
8014 tdep->have_tdb = 1;
8015 }
8016
8017 /* Vector registers. */
8018 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.vx");
8019 if (feature)
8020 {
8021 for (i = 0; i < 16; i++)
8022 valid_p &= tdesc_numbered_register (feature, tdesc_data,
8023 S390_V0_LOWER_REGNUM + i,
8024 vxrs_low[i]);
8025 for (i = 0; i < 16; i++)
8026 valid_p &= tdesc_numbered_register (feature, tdesc_data,
8027 S390_V16_REGNUM + i,
8028 vxrs_high[i]);
8029 tdep->have_vx = true;
8030 }
8031
8032 /* Guarded-storage registers. */
8033 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gs");
8034 if (feature)
8035 {
8036 for (i = 0; i < 3; i++)
8037 valid_p &= tdesc_numbered_register (feature, tdesc_data,
8038 S390_GSD_REGNUM + i,
8039 gs_cb[i]);
8040 tdep->have_gs = true;
8041 }
8042
8043 /* Guarded-storage broadcast control. */
8044 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gsbc");
8045 if (feature)
8046 {
8047 valid_p &= tdep->have_gs;
8048
8049 for (i = 0; i < 3; i++)
8050 valid_p &= tdesc_numbered_register (feature, tdesc_data,
8051 S390_BC_GSD_REGNUM + i,
8052 gs_bc[i]);
8053 }
8054
8055 if (!valid_p)
8056 {
8057 tdesc_data_cleanup (tdesc_data);
8058 xfree (tdep);
8059 gdbarch_free (gdbarch);
8060 return NULL;
8061 }
8062 }
8063
8064 /* Determine vector ABI. */
8065 #ifdef HAVE_ELF
8066 if (tdep->have_vx
8067 && info.abfd != NULL
8068 && info.abfd->format == bfd_object
8069 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
8070 && bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
8071 Tag_GNU_S390_ABI_Vector) == 2)
8072 tdep->vector_abi = S390_VECTOR_ABI_128;
8073 #endif
8074
8075 /* Find a candidate among extant architectures. */
8076 for (arches = gdbarch_list_lookup_by_info (arches, &info);
8077 arches != NULL;
8078 arches = gdbarch_list_lookup_by_info (arches->next, &info))
8079 {
8080 struct gdbarch_tdep *tmp = gdbarch_tdep (arches->gdbarch);
8081 if (!tmp)
8082 continue;
8083 /* A program can 'choose' not to use the vector registers when they
8084 are present. Leading to the same tdesc but different tdep and
8085 thereby a different gdbarch. */
8086 if (tmp->vector_abi != tdep->vector_abi)
8087 continue;
8088 if (tdesc_data != NULL)
8089 tdesc_data_cleanup (tdesc_data);
8090 xfree (tdep);
8091 gdbarch_free (gdbarch);
8092 return arches->gdbarch;
8093 }
8094
8095 set_gdbarch_believe_pcc_promotion (gdbarch, 0);
8096 set_gdbarch_char_signed (gdbarch, 0);
8097
8098 /* S/390 GNU/Linux uses either 64-bit or 128-bit long doubles.
8099 We can safely let them default to 128-bit, since the debug info
8100 will give the size of type actually used in each case. */
8101 set_gdbarch_long_double_bit (gdbarch, 128);
8102 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
8103
8104 /* Amount PC must be decremented by after a breakpoint. This is
8105 often the number of bytes returned by gdbarch_breakpoint_from_pc but not
8106 always. */
8107 set_gdbarch_decr_pc_after_break (gdbarch, 2);
8108 /* Stack grows downward. */
8109 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
8110 set_gdbarch_breakpoint_kind_from_pc (gdbarch, s390_breakpoint::kind_from_pc);
8111 set_gdbarch_sw_breakpoint_from_kind (gdbarch, s390_breakpoint::bp_from_kind);
8112 set_gdbarch_software_single_step (gdbarch, s390_software_single_step);
8113 set_gdbarch_displaced_step_hw_singlestep (gdbarch, s390_displaced_step_hw_singlestep);
8114 set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
8115 set_gdbarch_stack_frame_destroyed_p (gdbarch, s390_stack_frame_destroyed_p);
8116
8117 set_gdbarch_num_regs (gdbarch, S390_NUM_REGS);
8118 set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM);
8119 set_gdbarch_fp0_regnum (gdbarch, S390_F0_REGNUM);
8120 set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
8121 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
8122 set_gdbarch_value_from_register (gdbarch, s390_value_from_register);
8123 set_gdbarch_core_read_description (gdbarch, s390_core_read_description);
8124 set_gdbarch_iterate_over_regset_sections (gdbarch,
8125 s390_iterate_over_regset_sections);
8126 set_gdbarch_cannot_store_register (gdbarch, s390_cannot_store_register);
8127 set_gdbarch_write_pc (gdbarch, s390_write_pc);
8128 set_gdbarch_guess_tracepoint_registers (gdbarch, s390_guess_tracepoint_registers);
8129 set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
8130 set_gdbarch_pseudo_register_write (gdbarch, s390_pseudo_register_write);
8131 set_tdesc_pseudo_register_name (gdbarch, s390_pseudo_register_name);
8132 set_tdesc_pseudo_register_type (gdbarch, s390_pseudo_register_type);
8133 set_tdesc_pseudo_register_reggroup_p (gdbarch,
8134 s390_pseudo_register_reggroup_p);
8135 set_gdbarch_ax_pseudo_register_collect (gdbarch,
8136 s390_ax_pseudo_register_collect);
8137 set_gdbarch_ax_pseudo_register_push_stack
8138 (gdbarch, s390_ax_pseudo_register_push_stack);
8139 set_gdbarch_gen_return_address (gdbarch, s390_gen_return_address);
8140 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
8141 set_gdbarch_register_name (gdbarch, s390_register_name);
8142
8143 /* Assign pseudo register numbers. */
8144 first_pseudo_reg = gdbarch_num_regs (gdbarch);
8145 last_pseudo_reg = first_pseudo_reg;
8146 if (tdep->have_upper)
8147 {
8148 tdep->gpr_full_regnum = last_pseudo_reg;
8149 last_pseudo_reg += 16;
8150 }
8151 if (tdep->have_vx)
8152 {
8153 tdep->v0_full_regnum = last_pseudo_reg;
8154 last_pseudo_reg += 16;
8155 }
8156 tdep->pc_regnum = last_pseudo_reg++;
8157 tdep->cc_regnum = last_pseudo_reg++;
8158 set_gdbarch_pc_regnum (gdbarch, tdep->pc_regnum);
8159 set_gdbarch_num_pseudo_regs (gdbarch, last_pseudo_reg - first_pseudo_reg);
8160
8161 /* Inferior function calls. */
8162 set_gdbarch_push_dummy_call (gdbarch, s390_push_dummy_call);
8163 set_gdbarch_dummy_id (gdbarch, s390_dummy_id);
8164 set_gdbarch_frame_align (gdbarch, s390_frame_align);
8165 set_gdbarch_return_value (gdbarch, s390_return_value);
8166
8167 /* Syscall handling. */
8168 set_gdbarch_get_syscall_number (gdbarch, s390_linux_get_syscall_number);
8169
8170 /* Frame handling. */
8171 dwarf2_frame_set_init_reg (gdbarch, s390_dwarf2_frame_init_reg);
8172 dwarf2_frame_set_adjust_regnum (gdbarch, s390_adjust_frame_regnum);
8173 dwarf2_append_unwinders (gdbarch);
8174 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
8175 frame_unwind_append_unwinder (gdbarch, &s390_stub_frame_unwind);
8176 frame_unwind_append_unwinder (gdbarch, &s390_sigtramp_frame_unwind);
8177 frame_unwind_append_unwinder (gdbarch, &s390_frame_unwind);
8178 frame_base_set_default (gdbarch, &s390_frame_base);
8179 set_gdbarch_unwind_pc (gdbarch, s390_unwind_pc);
8180 set_gdbarch_unwind_sp (gdbarch, s390_unwind_sp);
8181
8182 /* Displaced stepping. */
8183 set_gdbarch_displaced_step_copy_insn (gdbarch,
8184 s390_displaced_step_copy_insn);
8185 set_gdbarch_displaced_step_fixup (gdbarch, s390_displaced_step_fixup);
8186 set_gdbarch_displaced_step_location (gdbarch, linux_displaced_step_location);
8187 set_gdbarch_max_insn_length (gdbarch, S390_MAX_INSTR_SIZE);
8188
8189 /* Note that GNU/Linux is the only OS supported on this
8190 platform. */
8191 linux_init_abi (info, gdbarch);
8192
8193 switch (tdep->abi)
8194 {
8195 case ABI_LINUX_S390:
8196 set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
8197 set_solib_svr4_fetch_link_map_offsets
8198 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
8199
8200 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_S390);
8201 break;
8202
8203 case ABI_LINUX_ZSERIES:
8204 set_gdbarch_long_bit (gdbarch, 64);
8205 set_gdbarch_long_long_bit (gdbarch, 64);
8206 set_gdbarch_ptr_bit (gdbarch, 64);
8207 set_solib_svr4_fetch_link_map_offsets
8208 (gdbarch, svr4_lp64_fetch_link_map_offsets);
8209 set_gdbarch_address_class_type_flags (gdbarch,
8210 s390_address_class_type_flags);
8211 set_gdbarch_address_class_type_flags_to_name (gdbarch,
8212 s390_address_class_type_flags_to_name);
8213 set_gdbarch_address_class_name_to_type_flags (gdbarch,
8214 s390_address_class_name_to_type_flags);
8215 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_S390X);
8216 break;
8217 }
8218
8219 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
8220
8221 /* Enable TLS support. */
8222 set_gdbarch_fetch_tls_load_module_address (gdbarch,
8223 svr4_fetch_objfile_link_map);
8224
8225 /* SystemTap functions. */
8226 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
8227 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
8228 stap_register_indirection_prefixes);
8229 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
8230 stap_register_indirection_suffixes);
8231 set_gdbarch_stap_is_single_operand (gdbarch, s390_stap_is_single_operand);
8232 set_gdbarch_gcc_target_options (gdbarch, s390_gcc_target_options);
8233 set_gdbarch_gnu_triplet_regexp (gdbarch, s390_gnu_triplet_regexp);
8234
8235 /* Support reverse debugging. */
8236
8237 set_gdbarch_process_record (gdbarch, s390_process_record);
8238 set_gdbarch_process_record_signal (gdbarch, s390_linux_record_signal);
8239
8240 s390_init_linux_record_tdep (&s390_linux_record_tdep, ABI_LINUX_S390);
8241 s390_init_linux_record_tdep (&s390x_linux_record_tdep, ABI_LINUX_ZSERIES);
8242
8243 set_gdbarch_disassembler_options (gdbarch, &s390_disassembler_options);
8244 set_gdbarch_valid_disassembler_options (gdbarch,
8245 disassembler_options_s390 ());
8246
8247 return gdbarch;
8248 }
8249
8250 void
8251 _initialize_s390_tdep (void)
8252 {
8253 /* Hook us into the gdbarch mechanism. */
8254 register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init);
8255
8256 /* Initialize the GNU/Linux target descriptions. */
8257 initialize_tdesc_s390_linux32 ();
8258 initialize_tdesc_s390_linux32v1 ();
8259 initialize_tdesc_s390_linux32v2 ();
8260 initialize_tdesc_s390_linux64 ();
8261 initialize_tdesc_s390_linux64v1 ();
8262 initialize_tdesc_s390_linux64v2 ();
8263 initialize_tdesc_s390_te_linux64 ();
8264 initialize_tdesc_s390_vx_linux64 ();
8265 initialize_tdesc_s390_tevx_linux64 ();
8266 initialize_tdesc_s390_gs_linux64 ();
8267 initialize_tdesc_s390x_linux64 ();
8268 initialize_tdesc_s390x_linux64v1 ();
8269 initialize_tdesc_s390x_linux64v2 ();
8270 initialize_tdesc_s390x_te_linux64 ();
8271 initialize_tdesc_s390x_vx_linux64 ();
8272 initialize_tdesc_s390x_tevx_linux64 ();
8273 initialize_tdesc_s390x_gs_linux64 ();
8274 }
This page took 0.50754 seconds and 4 git commands to generate.