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