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