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