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