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