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