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