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