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