Fix null pointer dereference in process_debug_info()
[binutils-gdb.git] / gdb / s390-tdep.c
blob519e3eb0a423342695817ff461deaa0b2850a2fc
1 /* Target-dependent code for s390.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
22 #include "ax-gdb.h"
23 #include "dwarf2/frame.h"
24 #include "elf/s390.h"
25 #include "elf-bfd.h"
26 #include "frame-base.h"
27 #include "frame-unwind.h"
28 #include "gdbarch.h"
29 #include "gdbcore.h"
30 #include "infrun.h"
31 #include "linux-tdep.h"
32 #include "objfiles.h"
33 #include "osabi.h"
34 #include "record-full.h"
35 #include "regcache.h"
36 #include "reggroups.h"
37 #include "s390-tdep.h"
38 #include "target-descriptions.h"
39 #include "trad-frame.h"
40 #include "value.h"
41 #include "inferior.h"
43 #include "features/s390-linux32.c"
44 #include "features/s390x-linux64.c"
46 /* Holds the current set of options to be passed to the disassembler. */
47 static std::string s390_disassembler_options;
49 /* Breakpoints. */
51 constexpr gdb_byte s390_break_insn[] = { 0x0, 0x1 };
53 typedef BP_MANIPULATION (s390_break_insn) s390_breakpoint;
55 /* Types. */
57 /* Implement the gdbarch type alignment method. */
59 static ULONGEST
60 s390_type_align (gdbarch *gdbarch, struct type *t)
62 t = check_typedef (t);
64 if (t->length () > 8)
66 switch (t->code ())
68 case TYPE_CODE_INT:
69 case TYPE_CODE_RANGE:
70 case TYPE_CODE_FLT:
71 case TYPE_CODE_ENUM:
72 case TYPE_CODE_CHAR:
73 case TYPE_CODE_BOOL:
74 case TYPE_CODE_DECFLOAT:
75 return 8;
77 case TYPE_CODE_ARRAY:
78 if (t->is_vector ())
79 return 8;
80 break;
83 return 0;
86 /* Decoding S/390 instructions. */
88 /* Read a single instruction from address AT. */
90 static int
91 s390_readinstruction (bfd_byte instr[], CORE_ADDR at)
93 static int s390_instrlen[] = { 2, 4, 4, 6 };
94 int instrlen;
96 if (target_read_memory (at, &instr[0], 2))
97 return -1;
98 instrlen = s390_instrlen[instr[0] >> 6];
99 if (instrlen > 2)
101 if (target_read_memory (at + 2, &instr[2], instrlen - 2))
102 return -1;
104 return instrlen;
107 /* The functions below are for recognizing and decoding S/390
108 instructions of various formats. Each of them checks whether INSN
109 is an instruction of the given format, with the specified opcodes.
110 If it is, it sets the remaining arguments to the values of the
111 instruction's fields, and returns a non-zero value; otherwise, it
112 returns zero.
114 These functions' arguments appear in the order they appear in the
115 instruction, not in the machine-language form. So, opcodes always
116 come first, even though they're sometimes scattered around the
117 instructions. And displacements appear before base and extension
118 registers, as they do in the assembly syntax, not at the end, as
119 they do in the machine language.
121 Test for RI instruction format. */
123 static int
124 is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2)
126 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
128 *r1 = (insn[1] >> 4) & 0xf;
129 /* i2 is a 16-bit signed quantity. */
130 *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000;
131 return 1;
133 else
134 return 0;
137 /* Test for RIL instruction format. See comment on is_ri for details. */
139 static int
140 is_ril (bfd_byte *insn, int op1, int op2,
141 unsigned int *r1, int *i2)
143 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
145 *r1 = (insn[1] >> 4) & 0xf;
146 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
147 no sign extension is necessary, but we don't want to assume
148 that. */
149 *i2 = (((insn[2] << 24)
150 | (insn[3] << 16)
151 | (insn[4] << 8)
152 | (insn[5])) ^ 0x80000000) - 0x80000000;
153 return 1;
155 else
156 return 0;
159 /* Test for RR instruction format. See comment on is_ri for details. */
161 static int
162 is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
164 if (insn[0] == op)
166 *r1 = (insn[1] >> 4) & 0xf;
167 *r2 = insn[1] & 0xf;
168 return 1;
170 else
171 return 0;
174 /* Test for RRE instruction format. See comment on is_ri for details. */
176 static int
177 is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
179 if (((insn[0] << 8) | insn[1]) == op)
181 /* Yes, insn[3]. insn[2] is unused in RRE format. */
182 *r1 = (insn[3] >> 4) & 0xf;
183 *r2 = insn[3] & 0xf;
184 return 1;
186 else
187 return 0;
190 /* Test for RS instruction format. See comment on is_ri for details. */
192 static int
193 is_rs (bfd_byte *insn, int op,
194 unsigned int *r1, unsigned int *r3, int *d2, unsigned int *b2)
196 if (insn[0] == op)
198 *r1 = (insn[1] >> 4) & 0xf;
199 *r3 = insn[1] & 0xf;
200 *b2 = (insn[2] >> 4) & 0xf;
201 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
202 return 1;
204 else
205 return 0;
208 /* Test for RSY instruction format. See comment on is_ri for details. */
210 static int
211 is_rsy (bfd_byte *insn, int op1, int op2,
212 unsigned int *r1, unsigned int *r3, int *d2, unsigned int *b2)
214 if (insn[0] == op1
215 && insn[5] == op2)
217 *r1 = (insn[1] >> 4) & 0xf;
218 *r3 = insn[1] & 0xf;
219 *b2 = (insn[2] >> 4) & 0xf;
220 /* The 'long displacement' is a 20-bit signed integer. */
221 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
222 ^ 0x80000) - 0x80000;
223 return 1;
225 else
226 return 0;
229 /* Test for RX instruction format. See comment on is_ri for details. */
231 static int
232 is_rx (bfd_byte *insn, int op,
233 unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2)
235 if (insn[0] == op)
237 *r1 = (insn[1] >> 4) & 0xf;
238 *x2 = insn[1] & 0xf;
239 *b2 = (insn[2] >> 4) & 0xf;
240 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
241 return 1;
243 else
244 return 0;
247 /* Test for RXY instruction format. See comment on is_ri for details. */
249 static int
250 is_rxy (bfd_byte *insn, int op1, int op2,
251 unsigned int *r1, int *d2, unsigned int *x2, unsigned int *b2)
253 if (insn[0] == op1
254 && insn[5] == op2)
256 *r1 = (insn[1] >> 4) & 0xf;
257 *x2 = insn[1] & 0xf;
258 *b2 = (insn[2] >> 4) & 0xf;
259 /* The 'long displacement' is a 20-bit signed integer. */
260 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
261 ^ 0x80000) - 0x80000;
262 return 1;
264 else
265 return 0;
268 /* A helper for s390_software_single_step, decides if an instruction
269 is a partial-execution instruction that needs to be executed until
270 completion when in record mode. If it is, returns 1 and writes
271 instruction length to a pointer. */
273 static int
274 s390_is_partial_instruction (struct gdbarch *gdbarch, CORE_ADDR loc, int *len)
276 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
277 uint16_t insn;
279 insn = read_memory_integer (loc, 2, byte_order);
281 switch (insn >> 8)
283 case 0xa8: /* MVCLE */
284 *len = 4;
285 return 1;
287 case 0xeb:
289 insn = read_memory_integer (loc + 4, 2, byte_order);
290 if ((insn & 0xff) == 0x8e)
292 /* MVCLU */
293 *len = 6;
294 return 1;
297 break;
300 switch (insn)
302 case 0xb255: /* MVST */
303 case 0xb263: /* CMPSC */
304 case 0xb2a5: /* TRE */
305 case 0xb2a6: /* CU21 */
306 case 0xb2a7: /* CU12 */
307 case 0xb9b0: /* CU14 */
308 case 0xb9b1: /* CU24 */
309 case 0xb9b2: /* CU41 */
310 case 0xb9b3: /* CU42 */
311 case 0xb92a: /* KMF */
312 case 0xb92b: /* KMO */
313 case 0xb92f: /* KMC */
314 case 0xb92d: /* KMCTR */
315 case 0xb92e: /* KM */
316 case 0xb93c: /* PPNO */
317 case 0xb990: /* TRTT */
318 case 0xb991: /* TRTO */
319 case 0xb992: /* TROT */
320 case 0xb993: /* TROO */
321 *len = 4;
322 return 1;
325 return 0;
328 /* Implement the "software_single_step" gdbarch method, needed to single step
329 through instructions like MVCLE in record mode, to make sure they are
330 executed to completion. Without that, record will save the full length
331 of destination buffer on every iteration, even though the CPU will only
332 process about 4kiB of it each time, leading to O(n**2) memory and time
333 complexity. */
335 static std::vector<CORE_ADDR>
336 s390_software_single_step (struct regcache *regcache)
338 struct gdbarch *gdbarch = regcache->arch ();
339 CORE_ADDR loc = regcache_read_pc (regcache);
340 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
341 int len;
342 uint16_t insn;
344 /* Special handling only if recording. */
345 if (!record_full_is_used ())
346 return {};
348 /* First, match a partial instruction. */
349 if (!s390_is_partial_instruction (gdbarch, loc, &len))
350 return {};
352 loc += len;
354 /* Second, look for a branch back to it. */
355 insn = read_memory_integer (loc, 2, byte_order);
356 if (insn != 0xa714) /* BRC with mask 1 */
357 return {};
359 insn = read_memory_integer (loc + 2, 2, byte_order);
360 if (insn != (uint16_t) -(len / 2))
361 return {};
363 loc += 4;
365 /* Found it, step past the whole thing. */
366 return {loc};
369 /* Displaced stepping. */
371 /* Return true if INSN is a non-branch RIL-b or RIL-c format
372 instruction. */
374 static int
375 is_non_branch_ril (gdb_byte *insn)
377 gdb_byte op1 = insn[0];
379 if (op1 == 0xc4)
381 gdb_byte op2 = insn[1] & 0x0f;
383 switch (op2)
385 case 0x02: /* llhrl */
386 case 0x04: /* lghrl */
387 case 0x05: /* lhrl */
388 case 0x06: /* llghrl */
389 case 0x07: /* sthrl */
390 case 0x08: /* lgrl */
391 case 0x0b: /* stgrl */
392 case 0x0c: /* lgfrl */
393 case 0x0d: /* lrl */
394 case 0x0e: /* llgfrl */
395 case 0x0f: /* strl */
396 return 1;
399 else if (op1 == 0xc6)
401 gdb_byte op2 = insn[1] & 0x0f;
403 switch (op2)
405 case 0x00: /* exrl */
406 case 0x02: /* pfdrl */
407 case 0x04: /* cghrl */
408 case 0x05: /* chrl */
409 case 0x06: /* clghrl */
410 case 0x07: /* clhrl */
411 case 0x08: /* cgrl */
412 case 0x0a: /* clgrl */
413 case 0x0c: /* cgfrl */
414 case 0x0d: /* crl */
415 case 0x0e: /* clgfrl */
416 case 0x0f: /* clrl */
417 return 1;
421 return 0;
424 typedef buf_displaced_step_copy_insn_closure
425 s390_displaced_step_copy_insn_closure;
427 /* Implementation of gdbarch_displaced_step_copy_insn. */
429 static displaced_step_copy_insn_closure_up
430 s390_displaced_step_copy_insn (struct gdbarch *gdbarch,
431 CORE_ADDR from, CORE_ADDR to,
432 struct regcache *regs)
434 size_t len = gdbarch_max_insn_length (gdbarch);
435 std::unique_ptr<s390_displaced_step_copy_insn_closure> closure
436 (new s390_displaced_step_copy_insn_closure (len));
437 gdb_byte *buf = closure->buf.data ();
439 read_memory (from, buf, len);
441 /* Adjust the displacement field of PC-relative RIL instructions,
442 except branches. The latter are handled in the fixup hook. */
443 if (is_non_branch_ril (buf))
445 LONGEST offset;
447 offset = extract_signed_integer (buf + 2, 4, BFD_ENDIAN_BIG);
448 offset = (from - to + offset * 2) / 2;
450 /* If the instruction is too far from the jump pad, punt. This
451 will usually happen with instructions in shared libraries.
452 We could probably support these by rewriting them to be
453 absolute or fully emulating them. */
454 if (offset < INT32_MIN || offset > INT32_MAX)
456 /* Let the core fall back to stepping over the breakpoint
457 in-line. */
458 displaced_debug_printf ("can't displaced step RIL instruction: offset "
459 "%s out of range", plongest (offset));
461 return NULL;
464 store_signed_integer (buf + 2, 4, BFD_ENDIAN_BIG, offset);
467 write_memory (to, buf, len);
469 displaced_debug_printf ("copy %s->%s: %s",
470 paddress (gdbarch, from), paddress (gdbarch, to),
471 bytes_to_string (buf, len).c_str ());
473 /* This is a work around for a problem with g++ 4.8. */
474 return displaced_step_copy_insn_closure_up (closure.release ());
477 /* Fix up the state of registers and memory after having single-stepped
478 a displaced instruction. */
480 static void
481 s390_displaced_step_fixup (struct gdbarch *gdbarch,
482 displaced_step_copy_insn_closure *closure_,
483 CORE_ADDR from, CORE_ADDR to,
484 struct regcache *regs, bool completed_p)
486 CORE_ADDR pc = regcache_read_pc (regs);
488 /* If the displaced instruction didn't complete successfully then all we
489 need to do is restore the program counter. */
490 if (!completed_p)
492 pc = from + (pc - to);
493 regcache_write_pc (regs, pc);
494 return;
497 /* Our closure is a copy of the instruction. */
498 s390_displaced_step_copy_insn_closure *closure
499 = (s390_displaced_step_copy_insn_closure *) closure_;
500 gdb_byte *insn = closure->buf.data ();
501 static int s390_instrlen[] = { 2, 4, 4, 6 };
502 int insnlen = s390_instrlen[insn[0] >> 6];
504 /* Fields for various kinds of instructions. */
505 unsigned int b2, r1, r2, x2, r3;
506 int i2, d2;
508 /* Get addressing mode bit. */
509 ULONGEST amode = 0;
510 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
512 regcache_cooked_read_unsigned (regs, S390_PSWA_REGNUM, &amode);
513 amode &= 0x80000000;
516 displaced_debug_printf ("(s390) fixup (%s, %s) pc %s len %d amode 0x%x",
517 paddress (gdbarch, from), paddress (gdbarch, to),
518 paddress (gdbarch, pc), insnlen, (int) amode);
520 /* Handle absolute branch and save instructions. */
521 int op_basr_p = is_rr (insn, op_basr, &r1, &r2);
522 if (op_basr_p
523 || is_rx (insn, op_bas, &r1, &d2, &x2, &b2))
525 /* Recompute saved return address in R1. */
526 regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
527 amode | (from + insnlen));
528 /* Update PC iff the instruction doesn't actually branch. */
529 if (op_basr_p && r2 == 0)
530 regcache_write_pc (regs, from + insnlen);
533 /* Handle absolute branch instructions. */
534 else if (is_rr (insn, op_bcr, &r1, &r2)
535 || is_rx (insn, op_bc, &r1, &d2, &x2, &b2)
536 || is_rr (insn, op_bctr, &r1, &r2)
537 || is_rre (insn, op_bctgr, &r1, &r2)
538 || is_rx (insn, op_bct, &r1, &d2, &x2, &b2)
539 || is_rxy (insn, op1_bctg, op2_brctg, &r1, &d2, &x2, &b2)
540 || is_rs (insn, op_bxh, &r1, &r3, &d2, &b2)
541 || is_rsy (insn, op1_bxhg, op2_bxhg, &r1, &r3, &d2, &b2)
542 || is_rs (insn, op_bxle, &r1, &r3, &d2, &b2)
543 || is_rsy (insn, op1_bxleg, op2_bxleg, &r1, &r3, &d2, &b2))
545 /* Update PC iff branch was *not* taken. */
546 if (pc == to + insnlen)
547 regcache_write_pc (regs, from + insnlen);
550 /* Handle PC-relative branch and save instructions. */
551 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2)
552 || is_ril (insn, op1_brasl, op2_brasl, &r1, &i2))
554 /* Update PC. */
555 regcache_write_pc (regs, pc - to + from);
556 /* Recompute saved return address in R1. */
557 regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
558 amode | (from + insnlen));
561 /* Handle LOAD ADDRESS RELATIVE LONG. */
562 else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2))
564 /* Update PC. */
565 regcache_write_pc (regs, from + insnlen);
566 /* Recompute output address in R1. */
567 regcache_cooked_write_unsigned (regs, S390_R0_REGNUM + r1,
568 from + i2 * 2);
571 /* If we executed a breakpoint instruction, point PC right back at it. */
572 else if (insn[0] == 0x0 && insn[1] == 0x1)
573 regcache_write_pc (regs, from);
575 /* For any other insn, adjust PC by negated displacement. PC then
576 points right after the original instruction, except for PC-relative
577 branches, where it points to the adjusted branch target. */
578 else
579 regcache_write_pc (regs, pc - to + from);
581 displaced_debug_printf ("(s390) pc is now %s",
582 paddress (gdbarch, regcache_read_pc (regs)));
585 /* Implement displaced_step_hw_singlestep gdbarch method. */
587 static bool
588 s390_displaced_step_hw_singlestep (struct gdbarch *gdbarch)
590 return true;
593 /* Prologue analysis. */
595 struct s390_prologue_data {
597 /* The stack. */
598 struct pv_area *stack;
600 /* The size and byte-order of a GPR or FPR. */
601 int gpr_size;
602 int fpr_size;
603 enum bfd_endian byte_order;
605 /* The general-purpose registers. */
606 pv_t gpr[S390_NUM_GPRS];
608 /* The floating-point registers. */
609 pv_t fpr[S390_NUM_FPRS];
611 /* The offset relative to the CFA where the incoming GPR N was saved
612 by the function prologue. 0 if not saved or unknown. */
613 int gpr_slot[S390_NUM_GPRS];
615 /* Likewise for FPRs. */
616 int fpr_slot[S390_NUM_FPRS];
618 /* Nonzero if the backchain was saved. This is assumed to be the
619 case when the incoming SP is saved at the current SP location. */
620 int back_chain_saved_p;
623 /* Return the effective address for an X-style instruction, like:
625 L R1, D2(X2, B2)
627 Here, X2 and B2 are registers, and D2 is a signed 20-bit
628 constant; the effective address is the sum of all three. If either
629 X2 or B2 are zero, then it doesn't contribute to the sum --- this
630 means that r0 can't be used as either X2 or B2. */
632 static pv_t
633 s390_addr (struct s390_prologue_data *data,
634 int d2, unsigned int x2, unsigned int b2)
636 pv_t result;
638 result = pv_constant (d2);
639 if (x2)
640 result = pv_add (result, data->gpr[x2]);
641 if (b2)
642 result = pv_add (result, data->gpr[b2]);
644 return result;
647 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
649 static void
650 s390_store (struct s390_prologue_data *data,
651 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size,
652 pv_t value)
654 pv_t addr = s390_addr (data, d2, x2, b2);
655 pv_t offset;
657 /* Check whether we are storing the backchain. */
658 offset = pv_subtract (data->gpr[S390_SP_REGNUM - S390_R0_REGNUM], addr);
660 if (pv_is_constant (offset) && offset.k == 0)
661 if (size == data->gpr_size
662 && pv_is_register_k (value, S390_SP_REGNUM, 0))
664 data->back_chain_saved_p = 1;
665 return;
668 /* Check whether we are storing a register into the stack. */
669 if (!data->stack->store_would_trash (addr))
670 data->stack->store (addr, size, value);
672 /* Note: If this is some store we cannot identify, you might think we
673 should forget our cached values, as any of those might have been hit.
675 However, we make the assumption that the register save areas are only
676 ever stored to once in any given function, and we do recognize these
677 stores. Thus every store we cannot recognize does not hit our data. */
680 /* Do a SIZE-byte load from D2(X2,B2). */
682 static pv_t
683 s390_load (struct s390_prologue_data *data,
684 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size)
687 pv_t addr = s390_addr (data, d2, x2, b2);
689 /* If it's a load from an in-line constant pool, then we can
690 simulate that, under the assumption that the code isn't
691 going to change between the time the processor actually
692 executed it creating the current frame, and the time when
693 we're analyzing the code to unwind past that frame. */
694 if (pv_is_constant (addr))
696 const struct target_section *secp
697 = target_section_by_addr (current_inferior ()->top_target (), addr.k);
698 if (secp != NULL
699 && (bfd_section_flags (secp->the_bfd_section) & SEC_READONLY))
700 return pv_constant (read_memory_integer (addr.k, size,
701 data->byte_order));
704 /* Check whether we are accessing one of our save slots. */
705 return data->stack->fetch (addr, size);
708 /* Function for finding saved registers in a 'struct pv_area'; we pass
709 this to pv_area::scan.
711 If VALUE is a saved register, ADDR says it was saved at a constant
712 offset from the frame base, and SIZE indicates that the whole
713 register was saved, record its offset in the reg_offset table in
714 PROLOGUE_UNTYPED. */
716 static void
717 s390_check_for_saved (void *data_untyped, pv_t addr,
718 CORE_ADDR size, pv_t value)
720 struct s390_prologue_data *data = (struct s390_prologue_data *) data_untyped;
721 int i, offset;
723 if (!pv_is_register (addr, S390_SP_REGNUM))
724 return;
726 offset = 16 * data->gpr_size + 32 - addr.k;
728 /* If we are storing the original value of a register, we want to
729 record the CFA offset. If the same register is stored multiple
730 times, the stack slot with the highest address counts. */
732 for (i = 0; i < S390_NUM_GPRS; i++)
733 if (size == data->gpr_size
734 && pv_is_register_k (value, S390_R0_REGNUM + i, 0))
735 if (data->gpr_slot[i] == 0
736 || data->gpr_slot[i] > offset)
738 data->gpr_slot[i] = offset;
739 return;
742 for (i = 0; i < S390_NUM_FPRS; i++)
743 if (size == data->fpr_size
744 && pv_is_register_k (value, S390_F0_REGNUM + i, 0))
745 if (data->fpr_slot[i] == 0
746 || data->fpr_slot[i] > offset)
748 data->fpr_slot[i] = offset;
749 return;
753 /* Analyze the prologue of the function starting at START_PC, continuing at
754 most until CURRENT_PC. Initialize DATA to hold all information we find
755 out about the state of the registers and stack slots. Return the address
756 of the instruction after the last one that changed the SP, FP, or back
757 chain; or zero on error. */
759 static CORE_ADDR
760 s390_analyze_prologue (struct gdbarch *gdbarch,
761 CORE_ADDR start_pc,
762 CORE_ADDR current_pc,
763 struct s390_prologue_data *data)
765 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
767 /* Our return value:
768 The address of the instruction after the last one that changed
769 the SP, FP, or back chain; zero if we got an error trying to
770 read memory. */
771 CORE_ADDR result = start_pc;
773 /* The current PC for our abstract interpretation. */
774 CORE_ADDR pc;
776 /* The address of the next instruction after that. */
777 CORE_ADDR next_pc;
779 pv_area stack (S390_SP_REGNUM, gdbarch_addr_bit (gdbarch));
780 scoped_restore restore_stack = make_scoped_restore (&data->stack, &stack);
782 /* Set up everything's initial value. */
784 int i;
786 /* For the purpose of prologue tracking, we consider the GPR size to
787 be equal to the ABI word size, even if it is actually larger
788 (i.e. when running a 32-bit binary under a 64-bit kernel). */
789 data->gpr_size = word_size;
790 data->fpr_size = 8;
791 data->byte_order = gdbarch_byte_order (gdbarch);
793 for (i = 0; i < S390_NUM_GPRS; i++)
794 data->gpr[i] = pv_register (S390_R0_REGNUM + i, 0);
796 for (i = 0; i < S390_NUM_FPRS; i++)
797 data->fpr[i] = pv_register (S390_F0_REGNUM + i, 0);
799 for (i = 0; i < S390_NUM_GPRS; i++)
800 data->gpr_slot[i] = 0;
802 for (i = 0; i < S390_NUM_FPRS; i++)
803 data->fpr_slot[i] = 0;
805 data->back_chain_saved_p = 0;
808 /* Start interpreting instructions, until we hit the frame's
809 current PC or the first branch instruction. */
810 for (pc = start_pc; pc > 0 && pc < current_pc; pc = next_pc)
812 bfd_byte insn[S390_MAX_INSTR_SIZE];
813 int insn_len = s390_readinstruction (insn, pc);
815 bfd_byte dummy[S390_MAX_INSTR_SIZE] = { 0 };
816 bfd_byte *insn32 = word_size == 4 ? insn : dummy;
817 bfd_byte *insn64 = word_size == 8 ? insn : dummy;
819 /* Fields for various kinds of instructions. */
820 unsigned int b2, r1, r2, x2, r3;
821 int i2, d2;
823 /* The values of SP and FP before this instruction,
824 for detecting instructions that change them. */
825 pv_t pre_insn_sp, pre_insn_fp;
826 /* Likewise for the flag whether the back chain was saved. */
827 int pre_insn_back_chain_saved_p;
829 /* If we got an error trying to read the instruction, report it. */
830 if (insn_len < 0)
832 result = 0;
833 break;
836 next_pc = pc + insn_len;
838 pre_insn_sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
839 pre_insn_fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
840 pre_insn_back_chain_saved_p = data->back_chain_saved_p;
842 /* LHI r1, i2 --- load halfword immediate. */
843 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
844 /* LGFI r1, i2 --- load fullword immediate. */
845 if (is_ri (insn32, op1_lhi, op2_lhi, &r1, &i2)
846 || is_ri (insn64, op1_lghi, op2_lghi, &r1, &i2)
847 || is_ril (insn, op1_lgfi, op2_lgfi, &r1, &i2))
848 data->gpr[r1] = pv_constant (i2);
850 /* LR r1, r2 --- load from register. */
851 /* LGR r1, r2 --- load from register (64-bit version). */
852 else if (is_rr (insn32, op_lr, &r1, &r2)
853 || is_rre (insn64, op_lgr, &r1, &r2))
854 data->gpr[r1] = data->gpr[r2];
856 /* L r1, d2(x2, b2) --- load. */
857 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
858 /* LG r1, d2(x2, b2) --- load (64-bit version). */
859 else if (is_rx (insn32, op_l, &r1, &d2, &x2, &b2)
860 || is_rxy (insn32, op1_ly, op2_ly, &r1, &d2, &x2, &b2)
861 || is_rxy (insn64, op1_lg, op2_lg, &r1, &d2, &x2, &b2))
862 data->gpr[r1] = s390_load (data, d2, x2, b2, data->gpr_size);
864 /* ST r1, d2(x2, b2) --- store. */
865 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
866 /* STG r1, d2(x2, b2) --- store (64-bit version). */
867 else if (is_rx (insn32, op_st, &r1, &d2, &x2, &b2)
868 || is_rxy (insn32, op1_sty, op2_sty, &r1, &d2, &x2, &b2)
869 || is_rxy (insn64, op1_stg, op2_stg, &r1, &d2, &x2, &b2))
870 s390_store (data, d2, x2, b2, data->gpr_size, data->gpr[r1]);
872 /* STD r1, d2(x2,b2) --- store floating-point register. */
873 else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2))
874 s390_store (data, d2, x2, b2, data->fpr_size, data->fpr[r1]);
876 /* STM r1, r3, d2(b2) --- store multiple. */
877 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement
878 version). */
879 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
880 else if (is_rs (insn32, op_stm, &r1, &r3, &d2, &b2)
881 || is_rsy (insn32, op1_stmy, op2_stmy, &r1, &r3, &d2, &b2)
882 || is_rsy (insn64, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2))
884 for (; r1 <= r3; r1++, d2 += data->gpr_size)
885 s390_store (data, d2, 0, b2, data->gpr_size, data->gpr[r1]);
888 /* AHI r1, i2 --- add halfword immediate. */
889 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
890 /* AFI r1, i2 --- add fullword immediate. */
891 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
892 else if (is_ri (insn32, op1_ahi, op2_ahi, &r1, &i2)
893 || is_ri (insn64, op1_aghi, op2_aghi, &r1, &i2)
894 || is_ril (insn32, op1_afi, op2_afi, &r1, &i2)
895 || is_ril (insn64, op1_agfi, op2_agfi, &r1, &i2))
896 data->gpr[r1] = pv_add_constant (data->gpr[r1], i2);
898 /* ALFI r1, i2 --- add logical immediate. */
899 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
900 else if (is_ril (insn32, op1_alfi, op2_alfi, &r1, &i2)
901 || is_ril (insn64, op1_algfi, op2_algfi, &r1, &i2))
902 data->gpr[r1] = pv_add_constant (data->gpr[r1],
903 (CORE_ADDR)i2 & 0xffffffff);
905 /* AR r1, r2 -- add register. */
906 /* AGR r1, r2 -- add register (64-bit version). */
907 else if (is_rr (insn32, op_ar, &r1, &r2)
908 || is_rre (insn64, op_agr, &r1, &r2))
909 data->gpr[r1] = pv_add (data->gpr[r1], data->gpr[r2]);
911 /* A r1, d2(x2, b2) -- add. */
912 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
913 /* AG r1, d2(x2, b2) -- add (64-bit version). */
914 else if (is_rx (insn32, op_a, &r1, &d2, &x2, &b2)
915 || is_rxy (insn32, op1_ay, op2_ay, &r1, &d2, &x2, &b2)
916 || is_rxy (insn64, op1_ag, op2_ag, &r1, &d2, &x2, &b2))
917 data->gpr[r1] = pv_add (data->gpr[r1],
918 s390_load (data, d2, x2, b2, data->gpr_size));
920 /* SLFI r1, i2 --- subtract logical immediate. */
921 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
922 else if (is_ril (insn32, op1_slfi, op2_slfi, &r1, &i2)
923 || is_ril (insn64, op1_slgfi, op2_slgfi, &r1, &i2))
924 data->gpr[r1] = pv_add_constant (data->gpr[r1],
925 -((CORE_ADDR)i2 & 0xffffffff));
927 /* SR r1, r2 -- subtract register. */
928 /* SGR r1, r2 -- subtract register (64-bit version). */
929 else if (is_rr (insn32, op_sr, &r1, &r2)
930 || is_rre (insn64, op_sgr, &r1, &r2))
931 data->gpr[r1] = pv_subtract (data->gpr[r1], data->gpr[r2]);
933 /* S r1, d2(x2, b2) -- subtract. */
934 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
935 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
936 else if (is_rx (insn32, op_s, &r1, &d2, &x2, &b2)
937 || is_rxy (insn32, op1_sy, op2_sy, &r1, &d2, &x2, &b2)
938 || is_rxy (insn64, op1_sg, op2_sg, &r1, &d2, &x2, &b2))
939 data->gpr[r1] = pv_subtract (data->gpr[r1],
940 s390_load (data, d2, x2, b2, data->gpr_size));
942 /* LA r1, d2(x2, b2) --- load address. */
943 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
944 else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2)
945 || is_rxy (insn, op1_lay, op2_lay, &r1, &d2, &x2, &b2))
946 data->gpr[r1] = s390_addr (data, d2, x2, b2);
948 /* LARL r1, i2 --- load address relative long. */
949 else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2))
950 data->gpr[r1] = pv_constant (pc + i2 * 2);
952 /* BASR r1, 0 --- branch and save.
953 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
954 else if (is_rr (insn, op_basr, &r1, &r2)
955 && r2 == 0)
956 data->gpr[r1] = pv_constant (next_pc);
958 /* BRAS r1, i2 --- branch relative and save. */
959 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2))
961 data->gpr[r1] = pv_constant (next_pc);
962 next_pc = pc + i2 * 2;
964 /* We'd better not interpret any backward branches. We'll
965 never terminate. */
966 if (next_pc <= pc)
967 break;
970 /* BRC/BRCL -- branch relative on condition. Ignore "branch
971 never", branch to following instruction, and "conditional
972 trap" (BRC +2). Otherwise terminate search. */
973 else if (is_ri (insn, op1_brc, op2_brc, &r1, &i2))
975 if (r1 != 0 && i2 != 1 && i2 != 2)
976 break;
978 else if (is_ril (insn, op1_brcl, op2_brcl, &r1, &i2))
980 if (r1 != 0 && i2 != 3)
981 break;
984 /* Terminate search when hitting any other branch instruction. */
985 else if (is_rr (insn, op_basr, &r1, &r2)
986 || is_rx (insn, op_bas, &r1, &d2, &x2, &b2)
987 || is_rr (insn, op_bcr, &r1, &r2)
988 || is_rx (insn, op_bc, &r1, &d2, &x2, &b2)
989 || is_ril (insn, op1_brasl, op2_brasl, &r2, &i2))
990 break;
992 else
994 /* An instruction we don't know how to simulate. The only
995 safe thing to do would be to set every value we're tracking
996 to 'unknown'. Instead, we'll be optimistic: we assume that
997 we *can* interpret every instruction that the compiler uses
998 to manipulate any of the data we're interested in here --
999 then we can just ignore anything else. */
1002 /* Record the address after the last instruction that changed
1003 the FP, SP, or backlink. Ignore instructions that changed
1004 them back to their original values --- those are probably
1005 restore instructions. (The back chain is never restored,
1006 just popped.) */
1008 pv_t sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1009 pv_t fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1011 if ((! pv_is_identical (pre_insn_sp, sp)
1012 && ! pv_is_register_k (sp, S390_SP_REGNUM, 0)
1013 && sp.kind != pvk_unknown)
1014 || (! pv_is_identical (pre_insn_fp, fp)
1015 && ! pv_is_register_k (fp, S390_FRAME_REGNUM, 0)
1016 && fp.kind != pvk_unknown)
1017 || pre_insn_back_chain_saved_p != data->back_chain_saved_p)
1018 result = next_pc;
1022 /* Record where all the registers were saved. */
1023 data->stack->scan (s390_check_for_saved, data);
1025 return result;
1028 /* Advance PC across any function entry prologue instructions to reach
1029 some "real" code. */
1031 static CORE_ADDR
1032 s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1034 struct s390_prologue_data data;
1035 CORE_ADDR skip_pc, func_addr;
1037 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
1039 CORE_ADDR post_prologue_pc
1040 = skip_prologue_using_sal (gdbarch, func_addr);
1041 if (post_prologue_pc != 0)
1042 return std::max (pc, post_prologue_pc);
1045 skip_pc = s390_analyze_prologue (gdbarch, pc, (CORE_ADDR)-1, &data);
1046 return skip_pc ? skip_pc : pc;
1049 /* Register handling. */
1051 /* ABI call-saved register information. */
1053 static int
1054 s390_register_call_saved (struct gdbarch *gdbarch, int regnum)
1056 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1058 switch (tdep->abi)
1060 case ABI_LINUX_S390:
1061 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
1062 || regnum == S390_F4_REGNUM || regnum == S390_F6_REGNUM
1063 || regnum == S390_A0_REGNUM)
1064 return 1;
1066 break;
1068 case ABI_LINUX_ZSERIES:
1069 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
1070 || (regnum >= S390_F8_REGNUM && regnum <= S390_F15_REGNUM)
1071 || (regnum >= S390_A0_REGNUM && regnum <= S390_A1_REGNUM))
1072 return 1;
1074 break;
1077 return 0;
1080 /* The "guess_tracepoint_registers" gdbarch method. */
1082 static void
1083 s390_guess_tracepoint_registers (struct gdbarch *gdbarch,
1084 struct regcache *regcache,
1085 CORE_ADDR addr)
1087 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1088 int sz = register_size (gdbarch, S390_PSWA_REGNUM);
1089 gdb_byte *reg = (gdb_byte *) alloca (sz);
1090 ULONGEST pswm, pswa;
1092 /* Set PSWA from the location and a default PSWM (the only part we're
1093 unlikely to get right is the CC). */
1094 if (tdep->abi == ABI_LINUX_S390)
1096 /* 31-bit PSWA needs high bit set (it's very unlikely the target
1097 was in 24-bit mode). */
1098 pswa = addr | 0x80000000UL;
1099 pswm = 0x070d0000UL;
1101 else
1103 pswa = addr;
1104 pswm = 0x0705000180000000ULL;
1107 store_unsigned_integer (reg, sz, gdbarch_byte_order (gdbarch), pswa);
1108 regcache->raw_supply (S390_PSWA_REGNUM, reg);
1110 store_unsigned_integer (reg, sz, gdbarch_byte_order (gdbarch), pswm);
1111 regcache->raw_supply (S390_PSWM_REGNUM, reg);
1114 /* Return the name of register REGNO. Return the empty string for
1115 registers that shouldn't be visible. */
1117 static const char *
1118 s390_register_name (struct gdbarch *gdbarch, int regnum)
1120 if (regnum >= S390_V0_LOWER_REGNUM
1121 && regnum <= S390_V15_LOWER_REGNUM)
1122 return "";
1123 return tdesc_register_name (gdbarch, regnum);
1126 /* DWARF Register Mapping. */
1128 static const short s390_dwarf_regmap[] =
1130 /* 0-15: General Purpose Registers. */
1131 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
1132 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
1133 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
1134 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
1136 /* 16-31: Floating Point Registers / Vector Registers 0-15. */
1137 S390_F0_REGNUM, S390_F2_REGNUM, S390_F4_REGNUM, S390_F6_REGNUM,
1138 S390_F1_REGNUM, S390_F3_REGNUM, S390_F5_REGNUM, S390_F7_REGNUM,
1139 S390_F8_REGNUM, S390_F10_REGNUM, S390_F12_REGNUM, S390_F14_REGNUM,
1140 S390_F9_REGNUM, S390_F11_REGNUM, S390_F13_REGNUM, S390_F15_REGNUM,
1142 /* 32-47: Control Registers (not mapped). */
1143 -1, -1, -1, -1, -1, -1, -1, -1,
1144 -1, -1, -1, -1, -1, -1, -1, -1,
1146 /* 48-63: Access Registers. */
1147 S390_A0_REGNUM, S390_A1_REGNUM, S390_A2_REGNUM, S390_A3_REGNUM,
1148 S390_A4_REGNUM, S390_A5_REGNUM, S390_A6_REGNUM, S390_A7_REGNUM,
1149 S390_A8_REGNUM, S390_A9_REGNUM, S390_A10_REGNUM, S390_A11_REGNUM,
1150 S390_A12_REGNUM, S390_A13_REGNUM, S390_A14_REGNUM, S390_A15_REGNUM,
1152 /* 64-65: Program Status Word. */
1153 S390_PSWM_REGNUM,
1154 S390_PSWA_REGNUM,
1156 /* 66-67: Reserved. */
1157 -1, -1,
1159 /* 68-83: Vector Registers 16-31. */
1160 S390_V16_REGNUM, S390_V18_REGNUM, S390_V20_REGNUM, S390_V22_REGNUM,
1161 S390_V17_REGNUM, S390_V19_REGNUM, S390_V21_REGNUM, S390_V23_REGNUM,
1162 S390_V24_REGNUM, S390_V26_REGNUM, S390_V28_REGNUM, S390_V30_REGNUM,
1163 S390_V25_REGNUM, S390_V27_REGNUM, S390_V29_REGNUM, S390_V31_REGNUM,
1165 /* End of "official" DWARF registers. The remainder of the map is
1166 for GDB internal use only. */
1168 /* GPR Lower Half Access. */
1169 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
1170 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
1171 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
1172 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
1175 enum { s390_dwarf_reg_r0l = ARRAY_SIZE (s390_dwarf_regmap) - 16 };
1177 /* Convert DWARF register number REG to the appropriate register
1178 number used by GDB. */
1180 static int
1181 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
1183 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1184 int gdb_reg = -1;
1186 /* In a 32-on-64 debug scenario, debug info refers to the full
1187 64-bit GPRs. Note that call frame information still refers to
1188 the 32-bit lower halves, because s390_adjust_frame_regnum uses
1189 special register numbers to access GPRs. */
1190 if (tdep->gpr_full_regnum != -1 && reg >= 0 && reg < 16)
1191 return tdep->gpr_full_regnum + reg;
1193 if (reg >= 0 && reg < ARRAY_SIZE (s390_dwarf_regmap))
1194 gdb_reg = s390_dwarf_regmap[reg];
1196 if (tdep->v0_full_regnum == -1)
1198 if (gdb_reg >= S390_V16_REGNUM && gdb_reg <= S390_V31_REGNUM)
1199 gdb_reg = -1;
1201 else
1203 if (gdb_reg >= S390_F0_REGNUM && gdb_reg <= S390_F15_REGNUM)
1204 gdb_reg = gdb_reg - S390_F0_REGNUM + tdep->v0_full_regnum;
1207 return gdb_reg;
1210 /* Pseudo registers. */
1212 /* Check whether REGNUM indicates a coupled general purpose register.
1213 These pseudo-registers are composed of two adjacent gprs. */
1215 static int
1216 regnum_is_gpr_full (s390_gdbarch_tdep *tdep, int regnum)
1218 return (tdep->gpr_full_regnum != -1
1219 && regnum >= tdep->gpr_full_regnum
1220 && regnum <= tdep->gpr_full_regnum + 15);
1223 /* Check whether REGNUM indicates a full vector register (v0-v15).
1224 These pseudo-registers are composed of f0-f15 and v0l-v15l. */
1226 static int
1227 regnum_is_vxr_full (s390_gdbarch_tdep *tdep, int regnum)
1229 return (tdep->v0_full_regnum != -1
1230 && regnum >= tdep->v0_full_regnum
1231 && regnum <= tdep->v0_full_regnum + 15);
1234 /* 'float' values are stored in the upper half of floating-point
1235 registers, even though we are otherwise a big-endian platform. The
1236 same applies to a 'float' value within a vector. */
1238 static value *
1239 s390_value_from_register (gdbarch *gdbarch, type *type, int regnum,
1240 const frame_info_ptr &this_frame)
1242 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1243 value *value
1244 = default_value_from_register (gdbarch, type, regnum, this_frame);
1245 check_typedef (type);
1247 if ((regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM
1248 && type->length () < 8)
1249 || regnum_is_vxr_full (tdep, regnum)
1250 || (regnum >= S390_V16_REGNUM && regnum <= S390_V31_REGNUM))
1251 value->set_offset (0);
1253 return value;
1256 /* Implement pseudo_register_name tdesc method. */
1258 static const char *
1259 s390_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
1261 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1263 if (regnum == tdep->pc_regnum)
1264 return "pc";
1266 if (regnum == tdep->cc_regnum)
1267 return "cc";
1269 if (regnum_is_gpr_full (tdep, regnum))
1271 static const char *full_name[] = {
1272 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
1273 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1275 return full_name[regnum - tdep->gpr_full_regnum];
1278 if (regnum_is_vxr_full (tdep, regnum))
1280 static const char *full_name[] = {
1281 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
1282 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15"
1284 return full_name[regnum - tdep->v0_full_regnum];
1287 internal_error (_("invalid regnum"));
1290 /* Implement pseudo_register_type tdesc method. */
1292 static struct type *
1293 s390_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
1295 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1297 if (regnum == tdep->pc_regnum)
1298 return builtin_type (gdbarch)->builtin_func_ptr;
1300 if (regnum == tdep->cc_regnum)
1301 return builtin_type (gdbarch)->builtin_int;
1303 if (regnum_is_gpr_full (tdep, regnum))
1304 return builtin_type (gdbarch)->builtin_uint64;
1306 /* For the "concatenated" vector registers use the same type as v16. */
1307 if (regnum_is_vxr_full (tdep, regnum))
1308 return tdesc_register_type (gdbarch, S390_V16_REGNUM);
1310 internal_error (_("invalid regnum"));
1313 /* Implement pseudo_register_read gdbarch method. */
1315 static enum register_status
1316 s390_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
1317 int regnum, gdb_byte *buf)
1319 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1320 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1321 int regsize = register_size (gdbarch, regnum);
1322 ULONGEST val;
1324 if (regnum == tdep->pc_regnum)
1326 enum register_status status;
1328 status = regcache->raw_read (S390_PSWA_REGNUM, &val);
1329 if (status == REG_VALID)
1331 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1332 val &= 0x7fffffff;
1333 store_unsigned_integer (buf, regsize, byte_order, val);
1335 return status;
1338 if (regnum == tdep->cc_regnum)
1340 enum register_status status;
1342 status = regcache->raw_read (S390_PSWM_REGNUM, &val);
1343 if (status == REG_VALID)
1345 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1346 val = (val >> 12) & 3;
1347 else
1348 val = (val >> 44) & 3;
1349 store_unsigned_integer (buf, regsize, byte_order, val);
1351 return status;
1354 if (regnum_is_gpr_full (tdep, regnum))
1356 enum register_status status;
1357 ULONGEST val_upper;
1359 regnum -= tdep->gpr_full_regnum;
1361 status = regcache->raw_read (S390_R0_REGNUM + regnum, &val);
1362 if (status == REG_VALID)
1363 status = regcache->raw_read (S390_R0_UPPER_REGNUM + regnum,
1364 &val_upper);
1365 if (status == REG_VALID)
1367 val |= val_upper << 32;
1368 store_unsigned_integer (buf, regsize, byte_order, val);
1370 return status;
1373 if (regnum_is_vxr_full (tdep, regnum))
1375 enum register_status status;
1377 regnum -= tdep->v0_full_regnum;
1379 status = regcache->raw_read (S390_F0_REGNUM + regnum, buf);
1380 if (status == REG_VALID)
1381 status = regcache->raw_read (S390_V0_LOWER_REGNUM + regnum, buf + 8);
1382 return status;
1385 internal_error (_("invalid regnum"));
1388 /* Implement pseudo_register_write gdbarch method. */
1390 static void
1391 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
1392 int regnum, const gdb_byte *buf)
1394 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1395 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1396 int regsize = register_size (gdbarch, regnum);
1397 ULONGEST val, psw;
1399 if (regnum == tdep->pc_regnum)
1401 val = extract_unsigned_integer (buf, regsize, byte_order);
1402 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1404 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &psw);
1405 val = (psw & 0x80000000) | (val & 0x7fffffff);
1407 regcache_raw_write_unsigned (regcache, S390_PSWA_REGNUM, val);
1408 return;
1411 if (regnum == tdep->cc_regnum)
1413 val = extract_unsigned_integer (buf, regsize, byte_order);
1414 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
1415 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1416 val = (psw & ~((ULONGEST)3 << 12)) | ((val & 3) << 12);
1417 else
1418 val = (psw & ~((ULONGEST)3 << 44)) | ((val & 3) << 44);
1419 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, val);
1420 return;
1423 if (regnum_is_gpr_full (tdep, regnum))
1425 regnum -= tdep->gpr_full_regnum;
1426 val = extract_unsigned_integer (buf, regsize, byte_order);
1427 regcache_raw_write_unsigned (regcache, S390_R0_REGNUM + regnum,
1428 val & 0xffffffff);
1429 regcache_raw_write_unsigned (regcache, S390_R0_UPPER_REGNUM + regnum,
1430 val >> 32);
1431 return;
1434 if (regnum_is_vxr_full (tdep, regnum))
1436 regnum -= tdep->v0_full_regnum;
1437 regcache->raw_write (S390_F0_REGNUM + regnum, buf);
1438 regcache->raw_write (S390_V0_LOWER_REGNUM + regnum, buf + 8);
1439 return;
1442 internal_error (_("invalid regnum"));
1445 /* Register groups. */
1447 /* Implement pseudo_register_reggroup_p tdesc method. */
1449 static int
1450 s390_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
1451 const struct reggroup *group)
1453 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1455 /* We usually save/restore the whole PSW, which includes PC and CC.
1456 However, some older gdbservers may not support saving/restoring
1457 the whole PSW yet, and will return an XML register description
1458 excluding those from the save/restore register groups. In those
1459 cases, we still need to explicitly save/restore PC and CC in order
1460 to push or pop frames. Since this doesn't hurt anything if we
1461 already save/restore the whole PSW (it's just redundant), we add
1462 PC and CC at this point unconditionally. */
1463 if (group == save_reggroup || group == restore_reggroup)
1464 return regnum == tdep->pc_regnum || regnum == tdep->cc_regnum;
1466 if (group == vector_reggroup)
1467 return regnum_is_vxr_full (tdep, regnum);
1469 if (group == general_reggroup && regnum_is_vxr_full (tdep, regnum))
1470 return 0;
1472 return default_register_reggroup_p (gdbarch, regnum, group);
1475 /* The "ax_pseudo_register_collect" gdbarch method. */
1477 static int
1478 s390_ax_pseudo_register_collect (struct gdbarch *gdbarch,
1479 struct agent_expr *ax, int regnum)
1481 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1482 if (regnum == tdep->pc_regnum)
1484 ax_reg_mask (ax, S390_PSWA_REGNUM);
1486 else if (regnum == tdep->cc_regnum)
1488 ax_reg_mask (ax, S390_PSWM_REGNUM);
1490 else if (regnum_is_gpr_full (tdep, regnum))
1492 regnum -= tdep->gpr_full_regnum;
1493 ax_reg_mask (ax, S390_R0_REGNUM + regnum);
1494 ax_reg_mask (ax, S390_R0_UPPER_REGNUM + regnum);
1496 else if (regnum_is_vxr_full (tdep, regnum))
1498 regnum -= tdep->v0_full_regnum;
1499 ax_reg_mask (ax, S390_F0_REGNUM + regnum);
1500 ax_reg_mask (ax, S390_V0_LOWER_REGNUM + regnum);
1502 else
1504 internal_error (_("invalid regnum"));
1506 return 0;
1509 /* The "ax_pseudo_register_push_stack" gdbarch method. */
1511 static int
1512 s390_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
1513 struct agent_expr *ax, int regnum)
1515 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1516 if (regnum == tdep->pc_regnum)
1518 ax_reg (ax, S390_PSWA_REGNUM);
1519 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1521 ax_zero_ext (ax, 31);
1524 else if (regnum == tdep->cc_regnum)
1526 ax_reg (ax, S390_PSWM_REGNUM);
1527 if (register_size (gdbarch, S390_PSWA_REGNUM) == 4)
1528 ax_const_l (ax, 12);
1529 else
1530 ax_const_l (ax, 44);
1531 ax_simple (ax, aop_rsh_unsigned);
1532 ax_zero_ext (ax, 2);
1534 else if (regnum_is_gpr_full (tdep, regnum))
1536 regnum -= tdep->gpr_full_regnum;
1537 ax_reg (ax, S390_R0_REGNUM + regnum);
1538 ax_reg (ax, S390_R0_UPPER_REGNUM + regnum);
1539 ax_const_l (ax, 32);
1540 ax_simple (ax, aop_lsh);
1541 ax_simple (ax, aop_bit_or);
1543 else if (regnum_is_vxr_full (tdep, regnum))
1545 /* Too large to stuff on the stack. */
1546 return 1;
1548 else
1550 internal_error (_("invalid regnum"));
1552 return 0;
1555 /* The "gen_return_address" gdbarch method. Since this is supposed to be
1556 just a best-effort method, and we don't really have the means to run
1557 the full unwinder here, just collect the link register. */
1559 static void
1560 s390_gen_return_address (struct gdbarch *gdbarch,
1561 struct agent_expr *ax, struct axs_value *value,
1562 CORE_ADDR scope)
1564 value->type = register_type (gdbarch, S390_R14_REGNUM);
1565 value->kind = axs_lvalue_register;
1566 value->u.reg = S390_R14_REGNUM;
1569 /* Address handling. */
1571 /* Implement addr_bits_remove gdbarch method.
1572 Only used for ABI_LINUX_S390. */
1574 static CORE_ADDR
1575 s390_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
1577 return addr & 0x7fffffff;
1580 /* Implement addr_class_type_flags gdbarch method.
1581 Only used for ABI_LINUX_ZSERIES. */
1583 static type_instance_flags
1584 s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
1586 if (byte_size == 4)
1587 return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
1588 else
1589 return 0;
1592 /* Implement addr_class_type_flags_to_name gdbarch method.
1593 Only used for ABI_LINUX_ZSERIES. */
1595 static const char *
1596 s390_address_class_type_flags_to_name (struct gdbarch *gdbarch,
1597 type_instance_flags type_flags)
1599 if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
1600 return "mode32";
1601 else
1602 return NULL;
1605 /* Implement addr_class_name_to_type_flags gdbarch method.
1606 Only used for ABI_LINUX_ZSERIES. */
1608 static bool
1609 s390_address_class_name_to_type_flags (struct gdbarch *gdbarch,
1610 const char *name,
1611 type_instance_flags *type_flags_ptr)
1613 if (strcmp (name, "mode32") == 0)
1615 *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
1616 return true;
1618 else
1619 return false;
1622 /* Inferior function calls. */
1624 /* Dummy function calls. */
1626 /* Unwrap any single-field structs in TYPE and return the effective
1627 "inner" type. E.g., yield "float" for all these cases:
1629 float x;
1630 struct { float x };
1631 struct { struct { float x; } x; };
1632 struct { struct { struct { float x; } x; } x; };
1634 However, if an inner type is smaller than MIN_SIZE, abort the
1635 unwrapping. */
1637 static struct type *
1638 s390_effective_inner_type (struct type *type, unsigned int min_size)
1640 while (type->code () == TYPE_CODE_STRUCT)
1642 struct type *inner = NULL;
1644 /* Find a non-static field, if any. Unless there's exactly one,
1645 abort the unwrapping. */
1646 for (int i = 0; i < type->num_fields (); i++)
1648 struct field f = type->field (i);
1650 if (f.is_static ())
1651 continue;
1652 if (inner != NULL)
1653 return type;
1654 inner = f.type ();
1657 if (inner == NULL)
1658 break;
1659 inner = check_typedef (inner);
1660 if (inner->length () < min_size)
1661 break;
1662 type = inner;
1665 return type;
1668 /* Return non-zero if TYPE should be passed like "float" or
1669 "double". */
1671 static int
1672 s390_function_arg_float (struct type *type)
1674 /* Note that long double as well as complex types are intentionally
1675 excluded. */
1676 if (type->length () > 8)
1677 return 0;
1679 /* A struct containing just a float or double is passed like a float
1680 or double. */
1681 type = s390_effective_inner_type (type, 0);
1683 return (type->code () == TYPE_CODE_FLT
1684 || type->code () == TYPE_CODE_DECFLOAT);
1687 /* Return non-zero if TYPE should be passed like a vector. */
1689 static int
1690 s390_function_arg_vector (struct type *type)
1692 if (type->length () > 16)
1693 return 0;
1695 /* Structs containing just a vector are passed like a vector. */
1696 type = s390_effective_inner_type (type, type->length ());
1698 return type->code () == TYPE_CODE_ARRAY && type->is_vector ();
1701 /* Determine whether N is a power of two. */
1703 static int
1704 is_power_of_two (unsigned int n)
1706 return n && ((n & (n - 1)) == 0);
1709 /* For an argument whose type is TYPE and which is not passed like a
1710 float or vector, return non-zero if it should be passed like "int"
1711 or "long long". */
1713 static int
1714 s390_function_arg_integer (struct type *type)
1716 enum type_code code = type->code ();
1718 if (type->length () > 8)
1719 return 0;
1721 if (code == TYPE_CODE_INT
1722 || code == TYPE_CODE_ENUM
1723 || code == TYPE_CODE_RANGE
1724 || code == TYPE_CODE_CHAR
1725 || code == TYPE_CODE_BOOL
1726 || code == TYPE_CODE_PTR
1727 || TYPE_IS_REFERENCE (type))
1728 return 1;
1730 return ((code == TYPE_CODE_UNION || code == TYPE_CODE_STRUCT)
1731 && is_power_of_two (type->length ()));
1734 /* Argument passing state: Internal data structure passed to helper
1735 routines of s390_push_dummy_call. */
1737 struct s390_arg_state
1739 /* Register cache, or NULL, if we are in "preparation mode". */
1740 struct regcache *regcache;
1741 /* Next available general/floating-point/vector register for
1742 argument passing. */
1743 int gr, fr, vr;
1744 /* Current pointer to copy area (grows downwards). */
1745 CORE_ADDR copy;
1746 /* Current pointer to parameter area (grows upwards). */
1747 CORE_ADDR argp;
1750 /* Prepare one argument ARG for a dummy call and update the argument
1751 passing state AS accordingly. If the regcache field in AS is set,
1752 operate in "write mode" and write ARG into the inferior. Otherwise
1753 run "preparation mode" and skip all updates to the inferior. */
1755 static void
1756 s390_handle_arg (struct s390_arg_state *as, struct value *arg,
1757 s390_gdbarch_tdep *tdep, int word_size,
1758 enum bfd_endian byte_order, int is_unnamed)
1760 struct type *type = check_typedef (arg->type ());
1761 unsigned int length = type->length ();
1762 int write_mode = as->regcache != NULL;
1764 if (s390_function_arg_float (type))
1766 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass
1767 arguments. The GNU/Linux for zSeries ABI uses 0, 2, 4, and
1768 6. */
1769 if (as->fr <= (tdep->abi == ABI_LINUX_S390 ? 2 : 6))
1771 /* When we store a single-precision value in an FP register,
1772 it occupies the leftmost bits. */
1773 if (write_mode)
1774 as->regcache->cooked_write_part (S390_F0_REGNUM + as->fr, 0, length,
1775 arg->contents ().data ());
1776 as->fr += 2;
1778 else
1780 /* When we store a single-precision value in a stack slot,
1781 it occupies the rightmost bits. */
1782 as->argp = align_up (as->argp + length, word_size);
1783 if (write_mode)
1784 write_memory (as->argp - length, arg->contents ().data (),
1785 length);
1788 else if (tdep->vector_abi == S390_VECTOR_ABI_128
1789 && s390_function_arg_vector (type))
1791 static const char use_vr[] = {24, 26, 28, 30, 25, 27, 29, 31};
1793 if (!is_unnamed && as->vr < ARRAY_SIZE (use_vr))
1795 int regnum = S390_V24_REGNUM + use_vr[as->vr] - 24;
1797 if (write_mode)
1798 as->regcache->cooked_write_part (regnum, 0, length,
1799 arg->contents ().data ());
1800 as->vr++;
1802 else
1804 if (write_mode)
1805 write_memory (as->argp, arg->contents ().data (), length);
1806 as->argp = align_up (as->argp + length, word_size);
1809 else if (s390_function_arg_integer (type) && length <= word_size)
1811 /* Initialize it just to avoid a GCC false warning. */
1812 ULONGEST val = 0;
1814 if (write_mode)
1816 /* Place value in least significant bits of the register or
1817 memory word and sign- or zero-extend to full word size.
1818 This also applies to a struct or union. */
1819 val = type->is_unsigned ()
1820 ? extract_unsigned_integer (arg->contents ().data (),
1821 length, byte_order)
1822 : extract_signed_integer (arg->contents ().data (),
1823 length, byte_order);
1826 if (as->gr <= 6)
1828 if (write_mode)
1829 regcache_cooked_write_unsigned (as->regcache,
1830 S390_R0_REGNUM + as->gr,
1831 val);
1832 as->gr++;
1834 else
1836 if (write_mode)
1837 write_memory_unsigned_integer (as->argp, word_size,
1838 byte_order, val);
1839 as->argp += word_size;
1842 else if (s390_function_arg_integer (type) && length == 8)
1844 if (as->gr <= 5)
1846 if (write_mode)
1848 as->regcache->cooked_write (S390_R0_REGNUM + as->gr,
1849 arg->contents ().data ());
1850 as->regcache->cooked_write
1851 (S390_R0_REGNUM + as->gr + 1,
1852 arg->contents ().data () + word_size);
1854 as->gr += 2;
1856 else
1858 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
1859 in it, then don't go back and use it again later. */
1860 as->gr = 7;
1862 if (write_mode)
1863 write_memory (as->argp, arg->contents ().data (), length);
1864 as->argp += length;
1867 else
1869 /* This argument type is never passed in registers. Place the
1870 value in the copy area and pass a pointer to it. Use 8-byte
1871 alignment as a conservative assumption. */
1872 as->copy = align_down (as->copy - length, 8);
1873 if (write_mode)
1874 write_memory (as->copy, arg->contents ().data (), length);
1876 if (as->gr <= 6)
1878 if (write_mode)
1879 regcache_cooked_write_unsigned (as->regcache,
1880 S390_R0_REGNUM + as->gr,
1881 as->copy);
1882 as->gr++;
1884 else
1886 if (write_mode)
1887 write_memory_unsigned_integer (as->argp, word_size,
1888 byte_order, as->copy);
1889 as->argp += word_size;
1894 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
1895 place to be passed to a function, as specified by the "GNU/Linux
1896 for S/390 ELF Application Binary Interface Supplement".
1898 SP is the current stack pointer. We must put arguments, links,
1899 padding, etc. whereever they belong, and return the new stack
1900 pointer value.
1902 If STRUCT_RETURN is non-zero, then the function we're calling is
1903 going to return a structure by value; STRUCT_ADDR is the address of
1904 a block we've allocated for it on the stack.
1906 Our caller has taken care of any type promotions needed to satisfy
1907 prototypes or the old K&R argument-passing rules. */
1909 static CORE_ADDR
1910 s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1911 struct regcache *regcache, CORE_ADDR bp_addr,
1912 int nargs, struct value **args, CORE_ADDR sp,
1913 function_call_return_method return_method,
1914 CORE_ADDR struct_addr)
1916 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
1917 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1918 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1919 int i;
1920 struct s390_arg_state arg_state, arg_prep;
1921 CORE_ADDR param_area_start, new_sp;
1922 struct type *ftype = check_typedef (function->type ());
1924 if (ftype->code () == TYPE_CODE_PTR)
1925 ftype = check_typedef (ftype->target_type ());
1927 arg_prep.copy = sp;
1928 arg_prep.gr = (return_method == return_method_struct) ? 3 : 2;
1929 arg_prep.fr = 0;
1930 arg_prep.vr = 0;
1931 arg_prep.argp = 0;
1932 arg_prep.regcache = NULL;
1934 /* Initialize arg_state for "preparation mode". */
1935 arg_state = arg_prep;
1937 /* Update arg_state.copy with the start of the reference-to-copy area
1938 and arg_state.argp with the size of the parameter area. */
1939 for (i = 0; i < nargs; i++)
1940 s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
1941 ftype->has_varargs () && i >= ftype->num_fields ());
1943 param_area_start = align_down (arg_state.copy - arg_state.argp, 8);
1945 /* Allocate the standard frame areas: the register save area, the
1946 word reserved for the compiler, and the back chain pointer. */
1947 new_sp = param_area_start - (16 * word_size + 32);
1949 /* Now we have the final stack pointer. Make sure we didn't
1950 underflow; on 31-bit, this would result in addresses with the
1951 high bit set, which causes confusion elsewhere. Note that if we
1952 error out here, stack and registers remain untouched. */
1953 if (gdbarch_addr_bits_remove (gdbarch, new_sp) != new_sp)
1954 error (_("Stack overflow"));
1956 /* Pass the structure return address in general register 2. */
1957 if (return_method == return_method_struct)
1958 regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM, struct_addr);
1960 /* Initialize arg_state for "write mode". */
1961 arg_state = arg_prep;
1962 arg_state.argp = param_area_start;
1963 arg_state.regcache = regcache;
1965 /* Write all parameters. */
1966 for (i = 0; i < nargs; i++)
1967 s390_handle_arg (&arg_state, args[i], tdep, word_size, byte_order,
1968 ftype->has_varargs () && i >= ftype->num_fields ());
1970 /* Store return PSWA. In 31-bit mode, keep addressing mode bit. */
1971 if (word_size == 4)
1973 ULONGEST pswa;
1974 regcache_cooked_read_unsigned (regcache, S390_PSWA_REGNUM, &pswa);
1975 bp_addr = (bp_addr & 0x7fffffff) | (pswa & 0x80000000);
1977 regcache_cooked_write_unsigned (regcache, S390_RETADDR_REGNUM, bp_addr);
1979 /* Store updated stack pointer. */
1980 regcache_cooked_write_unsigned (regcache, S390_SP_REGNUM, new_sp);
1982 /* We need to return the 'stack part' of the frame ID,
1983 which is actually the top of the register save area. */
1984 return param_area_start;
1987 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
1988 dummy frame. The frame ID's base needs to match the TOS value
1989 returned by push_dummy_call, and the PC match the dummy frame's
1990 breakpoint. */
1992 static struct frame_id
1993 s390_dummy_id (struct gdbarch *gdbarch, const frame_info_ptr &this_frame)
1995 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1996 CORE_ADDR sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
1997 sp = gdbarch_addr_bits_remove (gdbarch, sp);
1999 return frame_id_build (sp + 16*word_size + 32,
2000 get_frame_pc (this_frame));
2003 /* Implement frame_align gdbarch method. */
2005 static CORE_ADDR
2006 s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2008 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2009 always be aligned on an eight-byte boundary. */
2010 return (addr & -8);
2013 /* Helper for s390_return_value: Set or retrieve a function return
2014 value if it resides in a register. */
2016 static void
2017 s390_register_return_value (struct gdbarch *gdbarch, struct type *type,
2018 struct regcache *regcache,
2019 gdb_byte *out, const gdb_byte *in)
2021 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2022 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2023 int length = type->length ();
2024 int code = type->code ();
2026 if (code == TYPE_CODE_FLT || code == TYPE_CODE_DECFLOAT)
2028 /* Float-like value: left-aligned in f0. */
2029 if (in != NULL)
2030 regcache->cooked_write_part (S390_F0_REGNUM, 0, length, in);
2031 else
2032 regcache->cooked_read_part (S390_F0_REGNUM, 0, length, out);
2034 else if (code == TYPE_CODE_ARRAY)
2036 /* Vector: left-aligned in v24. */
2037 if (in != NULL)
2038 regcache->cooked_write_part (S390_V24_REGNUM, 0, length, in);
2039 else
2040 regcache->cooked_read_part (S390_V24_REGNUM, 0, length, out);
2042 else if (length <= word_size)
2044 /* Integer: zero- or sign-extended in r2. */
2045 if (out != NULL)
2046 regcache->cooked_read_part (S390_R2_REGNUM, word_size - length, length,
2047 out);
2048 else if (type->is_unsigned ())
2049 regcache_cooked_write_unsigned
2050 (regcache, S390_R2_REGNUM,
2051 extract_unsigned_integer (in, length, byte_order));
2052 else
2053 regcache_cooked_write_signed
2054 (regcache, S390_R2_REGNUM,
2055 extract_signed_integer (in, length, byte_order));
2057 else if (length == 2 * word_size)
2059 /* Double word: in r2 and r3. */
2060 if (in != NULL)
2062 regcache->cooked_write (S390_R2_REGNUM, in);
2063 regcache->cooked_write (S390_R3_REGNUM, in + word_size);
2065 else
2067 regcache->cooked_read (S390_R2_REGNUM, out);
2068 regcache->cooked_read (S390_R3_REGNUM, out + word_size);
2071 else
2072 internal_error (_("invalid return type"));
2075 /* Implement the 'return_value' gdbarch method. */
2077 static enum return_value_convention
2078 s390_return_value (struct gdbarch *gdbarch, struct value *function,
2079 struct type *type, struct regcache *regcache,
2080 gdb_byte *out, const gdb_byte *in)
2082 enum return_value_convention rvc;
2084 type = check_typedef (type);
2086 switch (type->code ())
2088 case TYPE_CODE_STRUCT:
2089 case TYPE_CODE_UNION:
2090 case TYPE_CODE_COMPLEX:
2091 rvc = RETURN_VALUE_STRUCT_CONVENTION;
2092 break;
2093 case TYPE_CODE_ARRAY:
2095 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2096 rvc = (tdep->vector_abi == S390_VECTOR_ABI_128
2097 && type->length () <= 16 && type->is_vector ())
2098 ? RETURN_VALUE_REGISTER_CONVENTION
2099 : RETURN_VALUE_STRUCT_CONVENTION;
2100 break;
2102 default:
2103 rvc = type->length () <= 8
2104 ? RETURN_VALUE_REGISTER_CONVENTION
2105 : RETURN_VALUE_STRUCT_CONVENTION;
2108 if (in != NULL || out != NULL)
2110 if (rvc == RETURN_VALUE_REGISTER_CONVENTION)
2111 s390_register_return_value (gdbarch, type, regcache, out, in);
2112 else if (in != NULL)
2113 error (_("Cannot set function return value."));
2114 else
2115 error (_("Function return value unknown."));
2118 return rvc;
2121 /* Frame unwinding. */
2123 /* Implement the stack_frame_destroyed_p gdbarch method. */
2125 static int
2126 s390_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
2128 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2130 /* In frameless functions, there's no frame to destroy and thus
2131 we don't care about the epilogue.
2133 In functions with frame, the epilogue sequence is a pair of
2134 a LM-type instruction that restores (amongst others) the
2135 return register %r14 and the stack pointer %r15, followed
2136 by a branch 'br %r14' --or equivalent-- that effects the
2137 actual return.
2139 In that situation, this function needs to return 'true' in
2140 exactly one case: when pc points to that branch instruction.
2142 Thus we try to disassemble the one instructions immediately
2143 preceding pc and check whether it is an LM-type instruction
2144 modifying the stack pointer.
2146 Note that disassembling backwards is not reliable, so there
2147 is a slight chance of false positives here ... */
2149 bfd_byte insn[6];
2150 unsigned int r1, r3, b2;
2151 int d2;
2153 if (word_size == 4
2154 && !target_read_memory (pc - 4, insn, 4)
2155 && is_rs (insn, op_lm, &r1, &r3, &d2, &b2)
2156 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
2157 return 1;
2159 if (word_size == 4
2160 && !target_read_memory (pc - 6, insn, 6)
2161 && is_rsy (insn, op1_lmy, op2_lmy, &r1, &r3, &d2, &b2)
2162 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
2163 return 1;
2165 if (word_size == 8
2166 && !target_read_memory (pc - 6, insn, 6)
2167 && is_rsy (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2)
2168 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
2169 return 1;
2171 return 0;
2174 /* Implement unwind_pc gdbarch method. */
2176 static CORE_ADDR
2177 s390_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame)
2179 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2180 ULONGEST pc;
2181 pc = frame_unwind_register_unsigned (next_frame, tdep->pc_regnum);
2182 return gdbarch_addr_bits_remove (gdbarch, pc);
2185 /* Implement unwind_sp gdbarch method. */
2187 static CORE_ADDR
2188 s390_unwind_sp (struct gdbarch *gdbarch, const frame_info_ptr &next_frame)
2190 ULONGEST sp;
2191 sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
2192 return gdbarch_addr_bits_remove (gdbarch, sp);
2195 /* Helper routine to unwind pseudo registers. */
2197 static struct value *
2198 s390_unwind_pseudo_register (const frame_info_ptr &this_frame, int regnum)
2200 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2201 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2202 struct type *type = register_type (gdbarch, regnum);
2204 /* Unwind PC via PSW address. */
2205 if (regnum == tdep->pc_regnum)
2207 struct value *val;
2209 val = frame_unwind_register_value (this_frame, S390_PSWA_REGNUM);
2210 if (!val->optimized_out ())
2212 LONGEST pswa = value_as_long (val);
2214 if (type->length () == 4)
2215 return value_from_pointer (type, pswa & 0x7fffffff);
2216 else
2217 return value_from_pointer (type, pswa);
2221 /* Unwind CC via PSW mask. */
2222 if (regnum == tdep->cc_regnum)
2224 struct value *val;
2226 val = frame_unwind_register_value (this_frame, S390_PSWM_REGNUM);
2227 if (!val->optimized_out ())
2229 LONGEST pswm = value_as_long (val);
2231 if (type->length () == 4)
2232 return value_from_longest (type, (pswm >> 12) & 3);
2233 else
2234 return value_from_longest (type, (pswm >> 44) & 3);
2238 /* Unwind full GPRs to show at least the lower halves (as the
2239 upper halves are undefined). */
2240 if (regnum_is_gpr_full (tdep, regnum))
2242 int reg = regnum - tdep->gpr_full_regnum;
2243 struct value *val;
2245 val = frame_unwind_register_value (this_frame, S390_R0_REGNUM + reg);
2246 if (!val->optimized_out ())
2247 return value_cast (type, val);
2250 return value::allocate_optimized_out (type);
2253 /* Translate a .eh_frame register to DWARF register, or adjust a
2254 .debug_frame register. */
2256 static int
2257 s390_adjust_frame_regnum (struct gdbarch *gdbarch, int num, int eh_frame_p)
2259 /* See s390_dwarf_reg_to_regnum for comments. */
2260 return (num >= 0 && num < 16) ? num + s390_dwarf_reg_r0l : num;
2263 /* DWARF-2 frame unwinding. */
2265 /* Function to unwind a pseudo-register in dwarf2_frame unwinder. Used by
2266 s390_dwarf2_frame_init_reg. */
2268 static struct value *
2269 s390_dwarf2_prev_register (const frame_info_ptr &this_frame, void **this_cache,
2270 int regnum)
2272 return s390_unwind_pseudo_register (this_frame, regnum);
2275 /* Implement init_reg dwarf2_frame method. */
2277 static void
2278 s390_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
2279 struct dwarf2_frame_state_reg *reg,
2280 const frame_info_ptr &this_frame)
2282 /* The condition code (and thus PSW mask) is call-clobbered. */
2283 if (regnum == S390_PSWM_REGNUM)
2284 reg->how = DWARF2_FRAME_REG_UNDEFINED;
2286 /* The PSW address unwinds to the return address. */
2287 else if (regnum == S390_PSWA_REGNUM)
2288 reg->how = DWARF2_FRAME_REG_RA;
2290 /* Fixed registers are call-saved or call-clobbered
2291 depending on the ABI in use. */
2292 else if (regnum < S390_NUM_REGS)
2294 if (s390_register_call_saved (gdbarch, regnum))
2295 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
2296 else
2297 reg->how = DWARF2_FRAME_REG_UNDEFINED;
2300 /* We install a special function to unwind pseudos. */
2301 else
2303 reg->how = DWARF2_FRAME_REG_FN;
2304 reg->loc.fn = s390_dwarf2_prev_register;
2308 /* Frame unwinding. */
2310 /* Wrapper for trad_frame_get_prev_register to allow for s390 pseudo
2311 register translation. */
2313 struct value *
2314 s390_trad_frame_prev_register (const frame_info_ptr &this_frame,
2315 trad_frame_saved_reg saved_regs[],
2316 int regnum)
2318 if (regnum < S390_NUM_REGS)
2319 return trad_frame_get_prev_register (this_frame, saved_regs, regnum);
2320 else
2321 return s390_unwind_pseudo_register (this_frame, regnum);
2324 /* Normal stack frames. */
2326 struct s390_unwind_cache {
2328 CORE_ADDR func;
2329 CORE_ADDR frame_base;
2330 CORE_ADDR local_base;
2332 trad_frame_saved_reg *saved_regs;
2335 /* Unwind THIS_FRAME and write the information into unwind cache INFO using
2336 prologue analysis. Helper for s390_frame_unwind_cache. */
2338 static int
2339 s390_prologue_frame_unwind_cache (const frame_info_ptr &this_frame,
2340 struct s390_unwind_cache *info)
2342 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2343 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2344 struct s390_prologue_data data;
2345 pv_t *fp = &data.gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
2346 pv_t *sp = &data.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
2347 int i;
2348 CORE_ADDR cfa;
2349 CORE_ADDR func;
2350 CORE_ADDR result;
2351 ULONGEST reg;
2352 CORE_ADDR prev_sp;
2353 int frame_pointer;
2354 int size;
2355 frame_info_ptr next_frame;
2357 /* Try to find the function start address. If we can't find it, we don't
2358 bother searching for it -- with modern compilers this would be mostly
2359 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
2360 or else a valid backchain ... */
2361 if (!get_frame_func_if_available (this_frame, &info->func))
2363 info->func = -1;
2364 return 0;
2366 func = info->func;
2368 /* Try to analyze the prologue. */
2369 result = s390_analyze_prologue (gdbarch, func,
2370 get_frame_pc (this_frame), &data);
2371 if (!result)
2372 return 0;
2374 /* If this was successful, we should have found the instruction that
2375 sets the stack pointer register to the previous value of the stack
2376 pointer minus the frame size. */
2377 if (!pv_is_register (*sp, S390_SP_REGNUM))
2378 return 0;
2380 /* A frame size of zero at this point can mean either a real
2381 frameless function, or else a failure to find the prologue.
2382 Perform some sanity checks to verify we really have a
2383 frameless function. */
2384 if (sp->k == 0)
2386 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
2387 size zero. This is only possible if the next frame is a sentinel
2388 frame, a dummy frame, or a signal trampoline frame. */
2389 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
2390 needed, instead the code should simpliy rely on its
2391 analysis. */
2392 next_frame = get_next_frame (this_frame);
2393 while (next_frame && get_frame_type (next_frame) == INLINE_FRAME)
2394 next_frame = get_next_frame (next_frame);
2395 if (next_frame
2396 && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME)
2397 return 0;
2399 /* If we really have a frameless function, %r14 must be valid
2400 -- in particular, it must point to a different function. */
2401 reg = get_frame_register_unsigned (this_frame, S390_RETADDR_REGNUM);
2402 reg = gdbarch_addr_bits_remove (gdbarch, reg) - 1;
2403 if (get_pc_function_start (reg) == func)
2405 /* However, there is one case where it *is* valid for %r14
2406 to point to the same function -- if this is a recursive
2407 call, and we have stopped in the prologue *before* the
2408 stack frame was allocated.
2410 Recognize this case by looking ahead a bit ... */
2412 struct s390_prologue_data data2;
2413 pv_t *sp2 = &data2.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
2415 if (!(s390_analyze_prologue (gdbarch, func, (CORE_ADDR)-1, &data2)
2416 && pv_is_register (*sp2, S390_SP_REGNUM)
2417 && sp2->k != 0))
2418 return 0;
2422 /* OK, we've found valid prologue data. */
2423 size = -sp->k;
2425 /* If the frame pointer originally also holds the same value
2426 as the stack pointer, we're probably using it. If it holds
2427 some other value -- even a constant offset -- it is most
2428 likely used as temp register. */
2429 if (pv_is_identical (*sp, *fp))
2430 frame_pointer = S390_FRAME_REGNUM;
2431 else
2432 frame_pointer = S390_SP_REGNUM;
2434 /* If we've detected a function with stack frame, we'll still have to
2435 treat it as frameless if we're currently within the function epilog
2436 code at a point where the frame pointer has already been restored.
2437 This can only happen in an innermost frame. */
2438 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
2439 instead the code should simpliy rely on its analysis. */
2440 next_frame = get_next_frame (this_frame);
2441 while (next_frame && get_frame_type (next_frame) == INLINE_FRAME)
2442 next_frame = get_next_frame (next_frame);
2443 if (size > 0
2444 && (next_frame == NULL
2445 || get_frame_type (get_next_frame (this_frame)) != NORMAL_FRAME))
2447 /* See the comment in s390_stack_frame_destroyed_p on why this is
2448 not completely reliable ... */
2449 if (s390_stack_frame_destroyed_p (gdbarch, get_frame_pc (this_frame)))
2451 memset (&data, 0, sizeof (data));
2452 size = 0;
2453 frame_pointer = S390_SP_REGNUM;
2457 /* Once we know the frame register and the frame size, we can unwind
2458 the current value of the frame register from the next frame, and
2459 add back the frame size to arrive that the previous frame's
2460 stack pointer value. */
2461 prev_sp = get_frame_register_unsigned (this_frame, frame_pointer) + size;
2462 cfa = prev_sp + 16*word_size + 32;
2464 /* Set up ABI call-saved/call-clobbered registers. */
2465 for (i = 0; i < S390_NUM_REGS; i++)
2466 if (!s390_register_call_saved (gdbarch, i))
2467 info->saved_regs[i].set_unknown ();
2469 /* CC is always call-clobbered. */
2470 info->saved_regs[S390_PSWM_REGNUM].set_unknown ();
2472 /* Record the addresses of all register spill slots the prologue parser
2473 has recognized. Consider only registers defined as call-saved by the
2474 ABI; for call-clobbered registers the parser may have recognized
2475 spurious stores. */
2477 for (i = 0; i < 16; i++)
2478 if (s390_register_call_saved (gdbarch, S390_R0_REGNUM + i)
2479 && data.gpr_slot[i] != 0)
2480 info->saved_regs[S390_R0_REGNUM + i].set_addr (cfa - data.gpr_slot[i]);
2482 for (i = 0; i < 16; i++)
2483 if (s390_register_call_saved (gdbarch, S390_F0_REGNUM + i)
2484 && data.fpr_slot[i] != 0)
2485 info->saved_regs[S390_F0_REGNUM + i].set_addr (cfa - data.fpr_slot[i]);
2487 /* Function return will set PC to %r14. */
2488 info->saved_regs[S390_PSWA_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM];
2490 /* In frameless functions, we unwind simply by moving the return
2491 address to the PC. However, if we actually stored to the
2492 save area, use that -- we might only think the function frameless
2493 because we're in the middle of the prologue ... */
2494 if (size == 0
2495 && !info->saved_regs[S390_PSWA_REGNUM].is_addr ())
2497 info->saved_regs[S390_PSWA_REGNUM].set_realreg (S390_RETADDR_REGNUM);
2500 /* Another sanity check: unless this is a frameless function,
2501 we should have found spill slots for SP and PC.
2502 If not, we cannot unwind further -- this happens e.g. in
2503 libc's thread_start routine. */
2504 if (size > 0)
2506 if (!info->saved_regs[S390_SP_REGNUM].is_addr ()
2507 || !info->saved_regs[S390_PSWA_REGNUM].is_addr ())
2508 prev_sp = -1;
2511 /* We use the current value of the frame register as local_base,
2512 and the top of the register save area as frame_base. */
2513 if (prev_sp != -1)
2515 info->frame_base = prev_sp + 16*word_size + 32;
2516 info->local_base = prev_sp - size;
2519 return 1;
2522 /* Unwind THIS_FRAME and write the information into unwind cache INFO using
2523 back chain unwinding. Helper for s390_frame_unwind_cache. */
2525 static void
2526 s390_backchain_frame_unwind_cache (const frame_info_ptr &this_frame,
2527 struct s390_unwind_cache *info)
2529 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2530 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2531 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2532 CORE_ADDR backchain;
2533 ULONGEST reg;
2534 LONGEST sp, tmp;
2535 int i;
2537 /* Set up ABI call-saved/call-clobbered registers. */
2538 for (i = 0; i < S390_NUM_REGS; i++)
2539 if (!s390_register_call_saved (gdbarch, i))
2540 info->saved_regs[i].set_unknown ();
2542 /* CC is always call-clobbered. */
2543 info->saved_regs[S390_PSWM_REGNUM].set_unknown ();
2545 /* Get the backchain. */
2546 reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
2547 if (!safe_read_memory_integer (reg, word_size, byte_order, &tmp))
2548 tmp = 0;
2549 backchain = (CORE_ADDR) tmp;
2551 /* A zero backchain terminates the frame chain. As additional
2552 sanity check, let's verify that the spill slot for SP in the
2553 save area pointed to by the backchain in fact links back to
2554 the save area. */
2555 if (backchain != 0
2556 && safe_read_memory_integer (backchain + 15*word_size,
2557 word_size, byte_order, &sp)
2558 && (CORE_ADDR)sp == backchain)
2560 /* We don't know which registers were saved, but it will have
2561 to be at least %r14 and %r15. This will allow us to continue
2562 unwinding, but other prev-frame registers may be incorrect ... */
2563 info->saved_regs[S390_SP_REGNUM].set_addr (backchain + 15*word_size);
2564 info->saved_regs[S390_RETADDR_REGNUM].set_addr (backchain + 14*word_size);
2566 /* Function return will set PC to %r14. */
2567 info->saved_regs[S390_PSWA_REGNUM]
2568 = info->saved_regs[S390_RETADDR_REGNUM];
2570 /* We use the current value of the frame register as local_base,
2571 and the top of the register save area as frame_base. */
2572 info->frame_base = backchain + 16*word_size + 32;
2573 info->local_base = reg;
2576 info->func = get_frame_pc (this_frame);
2579 /* Unwind THIS_FRAME and return the corresponding unwind cache for
2580 s390_frame_unwind and s390_frame_base. */
2582 static struct s390_unwind_cache *
2583 s390_frame_unwind_cache (const frame_info_ptr &this_frame,
2584 void **this_prologue_cache)
2586 struct s390_unwind_cache *info;
2588 if (*this_prologue_cache)
2589 return (struct s390_unwind_cache *) *this_prologue_cache;
2591 info = FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache);
2592 *this_prologue_cache = info;
2593 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2594 info->func = -1;
2595 info->frame_base = -1;
2596 info->local_base = -1;
2600 /* Try to use prologue analysis to fill the unwind cache.
2601 If this fails, fall back to reading the stack backchain. */
2602 if (!s390_prologue_frame_unwind_cache (this_frame, info))
2603 s390_backchain_frame_unwind_cache (this_frame, info);
2605 catch (const gdb_exception_error &ex)
2607 if (ex.error != NOT_AVAILABLE_ERROR)
2608 throw;
2611 return info;
2614 /* Implement this_id frame_unwind method for s390_frame_unwind. */
2616 static void
2617 s390_frame_this_id (const frame_info_ptr &this_frame,
2618 void **this_prologue_cache,
2619 struct frame_id *this_id)
2621 struct s390_unwind_cache *info
2622 = s390_frame_unwind_cache (this_frame, this_prologue_cache);
2624 if (info->frame_base == -1)
2626 if (info->func != -1)
2627 *this_id = frame_id_build_unavailable_stack (info->func);
2628 return;
2631 *this_id = frame_id_build (info->frame_base, info->func);
2634 /* Implement prev_register frame_unwind method for s390_frame_unwind. */
2636 static struct value *
2637 s390_frame_prev_register (const frame_info_ptr &this_frame,
2638 void **this_prologue_cache, int regnum)
2640 struct s390_unwind_cache *info
2641 = s390_frame_unwind_cache (this_frame, this_prologue_cache);
2643 return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum);
2646 /* Default S390 frame unwinder. */
2648 static const struct frame_unwind s390_frame_unwind = {
2649 "s390 prologue",
2650 NORMAL_FRAME,
2651 default_frame_unwind_stop_reason,
2652 s390_frame_this_id,
2653 s390_frame_prev_register,
2654 NULL,
2655 default_frame_sniffer
2658 /* Code stubs and their stack frames. For things like PLTs and NULL
2659 function calls (where there is no true frame and the return address
2660 is in the RETADDR register). */
2662 struct s390_stub_unwind_cache
2664 CORE_ADDR frame_base;
2665 trad_frame_saved_reg *saved_regs;
2668 /* Unwind THIS_FRAME and return the corresponding unwind cache for
2669 s390_stub_frame_unwind. */
2671 static struct s390_stub_unwind_cache *
2672 s390_stub_frame_unwind_cache (const frame_info_ptr &this_frame,
2673 void **this_prologue_cache)
2675 struct gdbarch *gdbarch = get_frame_arch (this_frame);
2676 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2677 struct s390_stub_unwind_cache *info;
2678 ULONGEST reg;
2680 if (*this_prologue_cache)
2681 return (struct s390_stub_unwind_cache *) *this_prologue_cache;
2683 info = FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache);
2684 *this_prologue_cache = info;
2685 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
2687 /* The return address is in register %r14. */
2688 info->saved_regs[S390_PSWA_REGNUM].set_realreg (S390_RETADDR_REGNUM);
2690 /* Retrieve stack pointer and determine our frame base. */
2691 reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
2692 info->frame_base = reg + 16*word_size + 32;
2694 return info;
2697 /* Implement this_id frame_unwind method for s390_stub_frame_unwind. */
2699 static void
2700 s390_stub_frame_this_id (const frame_info_ptr &this_frame,
2701 void **this_prologue_cache,
2702 struct frame_id *this_id)
2704 struct s390_stub_unwind_cache *info
2705 = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache);
2706 *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame));
2709 /* Implement prev_register frame_unwind method for s390_stub_frame_unwind. */
2711 static struct value *
2712 s390_stub_frame_prev_register (const frame_info_ptr &this_frame,
2713 void **this_prologue_cache, int regnum)
2715 struct s390_stub_unwind_cache *info
2716 = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache);
2717 return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum);
2720 /* Implement sniffer frame_unwind method for s390_stub_frame_unwind. */
2722 static int
2723 s390_stub_frame_sniffer (const struct frame_unwind *self,
2724 const frame_info_ptr &this_frame,
2725 void **this_prologue_cache)
2727 CORE_ADDR addr_in_block;
2728 bfd_byte insn[S390_MAX_INSTR_SIZE];
2730 /* If the current PC points to non-readable memory, we assume we
2731 have trapped due to an invalid function pointer call. We handle
2732 the non-existing current function like a PLT stub. */
2733 addr_in_block = get_frame_address_in_block (this_frame);
2734 if (in_plt_section (addr_in_block)
2735 || s390_readinstruction (insn, get_frame_pc (this_frame)) < 0)
2736 return 1;
2737 return 0;
2740 /* S390 stub frame unwinder. */
2742 static const struct frame_unwind s390_stub_frame_unwind = {
2743 "s390 stub",
2744 NORMAL_FRAME,
2745 default_frame_unwind_stop_reason,
2746 s390_stub_frame_this_id,
2747 s390_stub_frame_prev_register,
2748 NULL,
2749 s390_stub_frame_sniffer
2752 /* Frame base handling. */
2754 static CORE_ADDR
2755 s390_frame_base_address (const frame_info_ptr &this_frame, void **this_cache)
2757 struct s390_unwind_cache *info
2758 = s390_frame_unwind_cache (this_frame, this_cache);
2759 return info->frame_base;
2762 static CORE_ADDR
2763 s390_local_base_address (const frame_info_ptr &this_frame, void **this_cache)
2765 struct s390_unwind_cache *info
2766 = s390_frame_unwind_cache (this_frame, this_cache);
2767 return info->local_base;
2770 static const struct frame_base s390_frame_base = {
2771 &s390_frame_unwind,
2772 s390_frame_base_address,
2773 s390_local_base_address,
2774 s390_local_base_address
2777 /* Process record-replay */
2779 /* Takes the intermediate sum of address calculations and masks off upper
2780 bits according to current addressing mode. */
2782 static CORE_ADDR
2783 s390_record_address_mask (struct gdbarch *gdbarch, struct regcache *regcache,
2784 CORE_ADDR val)
2786 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2787 ULONGEST pswm, pswa;
2788 int am;
2789 if (tdep->abi == ABI_LINUX_S390)
2791 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &pswa);
2792 am = pswa >> 31 & 1;
2794 else
2796 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &pswm);
2797 am = pswm >> 31 & 3;
2799 switch (am)
2801 case 0:
2802 return val & 0xffffff;
2803 case 1:
2804 return val & 0x7fffffff;
2805 case 3:
2806 return val;
2807 default:
2808 gdb_printf (gdb_stdlog, "Warning: Addressing mode %d used.", am);
2809 return 0;
2813 /* Calculates memory address using pre-calculated index, raw instruction word
2814 with b and d/dl fields, and raw instruction byte with dh field. Index and
2815 dh should be set to 0 if unused. */
2817 static CORE_ADDR
2818 s390_record_calc_disp_common (struct gdbarch *gdbarch, struct regcache *regcache,
2819 ULONGEST x, uint16_t bd, int8_t dh)
2821 uint8_t rb = bd >> 12 & 0xf;
2822 int32_t d = (bd & 0xfff) | ((int32_t)dh << 12);
2823 ULONGEST b;
2824 CORE_ADDR res = d + x;
2825 if (rb)
2827 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + rb, &b);
2828 res += b;
2830 return s390_record_address_mask (gdbarch, regcache, res);
2833 /* Calculates memory address using raw x, b + d/dl, dh fields from
2834 instruction. rx and dh should be set to 0 if unused. */
2836 static CORE_ADDR
2837 s390_record_calc_disp (struct gdbarch *gdbarch, struct regcache *regcache,
2838 uint8_t rx, uint16_t bd, int8_t dh)
2840 ULONGEST x = 0;
2841 if (rx)
2842 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + rx, &x);
2843 return s390_record_calc_disp_common (gdbarch, regcache, x, bd, dh);
2846 /* Calculates memory address for VSCE[GF] instructions. */
2848 static int
2849 s390_record_calc_disp_vsce (struct gdbarch *gdbarch, struct regcache *regcache,
2850 uint8_t vx, uint8_t el, uint8_t es, uint16_t bd,
2851 int8_t dh, CORE_ADDR *res)
2853 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2854 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2855 ULONGEST x;
2856 gdb_byte buf[16];
2857 if (tdep->v0_full_regnum == -1 || el * es >= 16)
2858 return -1;
2859 if (vx < 16)
2860 regcache->cooked_read (tdep->v0_full_regnum + vx, buf);
2861 else
2862 regcache->raw_read (S390_V16_REGNUM + vx - 16, buf);
2863 x = extract_unsigned_integer (buf + el * es, es, byte_order);
2864 *res = s390_record_calc_disp_common (gdbarch, regcache, x, bd, dh);
2865 return 0;
2868 /* Calculates memory address for instructions with relative long addressing. */
2870 static CORE_ADDR
2871 s390_record_calc_rl (struct gdbarch *gdbarch, struct regcache *regcache,
2872 CORE_ADDR addr, uint16_t i1, uint16_t i2)
2874 int32_t ri = i1 << 16 | i2;
2875 return s390_record_address_mask (gdbarch, regcache, addr + (LONGEST)ri * 2);
2878 /* Population count helper. */
2880 static int s390_popcnt (unsigned int x) {
2881 int res = 0;
2882 while (x)
2884 if (x & 1)
2885 res++;
2886 x >>= 1;
2888 return res;
2891 /* Record 64-bit register. */
2893 static int
2894 s390_record_gpr_g (struct gdbarch *gdbarch, struct regcache *regcache, int i)
2896 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2897 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
2898 return -1;
2899 if (tdep->abi == ABI_LINUX_S390)
2900 if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
2901 return -1;
2902 return 0;
2905 /* Record high 32 bits of a register. */
2907 static int
2908 s390_record_gpr_h (struct gdbarch *gdbarch, struct regcache *regcache, int i)
2910 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2911 if (tdep->abi == ABI_LINUX_S390)
2913 if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i))
2914 return -1;
2916 else
2918 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
2919 return -1;
2921 return 0;
2924 /* Record vector register. */
2926 static int
2927 s390_record_vr (struct gdbarch *gdbarch, struct regcache *regcache, int i)
2929 if (i < 16)
2931 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + i))
2932 return -1;
2933 if (record_full_arch_list_add_reg (regcache, S390_V0_LOWER_REGNUM + i))
2934 return -1;
2936 else
2938 if (record_full_arch_list_add_reg (regcache, S390_V16_REGNUM + i - 16))
2939 return -1;
2941 return 0;
2944 /* Implement process_record gdbarch method. */
2946 static int
2947 s390_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
2948 CORE_ADDR addr)
2950 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
2951 uint16_t insn[3] = {0};
2952 /* Instruction as bytes. */
2953 uint8_t ibyte[6];
2954 /* Instruction as nibbles. */
2955 uint8_t inib[12];
2956 /* Instruction vector registers. */
2957 uint8_t ivec[4];
2958 CORE_ADDR oaddr, oaddr2, oaddr3;
2959 ULONGEST tmp;
2960 int i, n;
2961 /* if EX/EXRL instruction used, here's the reg parameter */
2962 int ex = -1;
2963 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2965 /* Attempting to use EX or EXRL jumps back here */
2968 /* Read instruction. */
2969 insn[0] = read_memory_unsigned_integer (addr, 2, byte_order);
2970 /* If execute was involved, do the adjustment. */
2971 if (ex != -1)
2972 insn[0] |= ex & 0xff;
2973 /* Two highest bits determine instruction size. */
2974 if (insn[0] >= 0x4000)
2975 insn[1] = read_memory_unsigned_integer (addr+2, 2, byte_order);
2976 else
2977 /* Not necessary, but avoids uninitialized variable warnings. */
2978 insn[1] = 0;
2979 if (insn[0] >= 0xc000)
2980 insn[2] = read_memory_unsigned_integer (addr+4, 2, byte_order);
2981 else
2982 insn[2] = 0;
2983 /* Split instruction into bytes and nibbles. */
2984 for (i = 0; i < 3; i++)
2986 ibyte[i*2] = insn[i] >> 8 & 0xff;
2987 ibyte[i*2+1] = insn[i] & 0xff;
2989 for (i = 0; i < 6; i++)
2991 inib[i*2] = ibyte[i] >> 4 & 0xf;
2992 inib[i*2+1] = ibyte[i] & 0xf;
2994 /* Compute vector registers, if applicable. */
2995 ivec[0] = (inib[9] >> 3 & 1) << 4 | inib[2];
2996 ivec[1] = (inib[9] >> 2 & 1) << 4 | inib[3];
2997 ivec[2] = (inib[9] >> 1 & 1) << 4 | inib[4];
2998 ivec[3] = (inib[9] >> 0 & 1) << 4 | inib[8];
3000 switch (ibyte[0])
3002 /* 0x00 undefined */
3004 case 0x01:
3005 /* E-format instruction */
3006 switch (ibyte[1])
3008 /* 0x00 undefined */
3009 /* 0x01 unsupported: PR - program return */
3010 /* 0x02 unsupported: UPT */
3011 /* 0x03 undefined */
3012 /* 0x04 privileged: PTFF - perform timing facility function */
3013 /* 0x05-0x06 undefined */
3014 /* 0x07 privileged: SCKPF - set clock programmable field */
3015 /* 0x08-0x09 undefined */
3017 case 0x0a: /* PFPO - perform floating point operation */
3018 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
3019 if (!(tmp & 0x80000000u))
3021 uint8_t ofc = tmp >> 16 & 0xff;
3022 switch (ofc)
3024 case 0x00: /* HFP32 */
3025 case 0x01: /* HFP64 */
3026 case 0x05: /* BFP32 */
3027 case 0x06: /* BFP64 */
3028 case 0x08: /* DFP32 */
3029 case 0x09: /* DFP64 */
3030 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM))
3031 return -1;
3032 break;
3033 case 0x02: /* HFP128 */
3034 case 0x07: /* BFP128 */
3035 case 0x0a: /* DFP128 */
3036 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM))
3037 return -1;
3038 if (record_full_arch_list_add_reg (regcache, S390_F2_REGNUM))
3039 return -1;
3040 break;
3041 default:
3042 gdb_printf (gdb_stdlog, "Warning: Unknown PFPO OFC %02x at %s.\n",
3043 ofc, paddress (gdbarch, addr));
3044 return -1;
3047 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3048 return -1;
3050 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
3051 return -1;
3052 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3053 return -1;
3054 break;
3056 case 0x0b: /* TAM - test address mode */
3057 case 0x0c: /* SAM24 - set address mode 24 */
3058 case 0x0d: /* SAM31 - set address mode 31 */
3059 case 0x0e: /* SAM64 - set address mode 64 */
3060 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3061 return -1;
3062 break;
3064 /* 0x0f-0xfe undefined */
3066 /* 0xff unsupported: TRAP */
3068 default:
3069 goto UNKNOWN_OP;
3071 break;
3073 /* 0x02 undefined */
3074 /* 0x03 undefined */
3076 case 0x04: /* SPM - set program mask */
3077 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3078 return -1;
3079 break;
3081 case 0x05: /* BALR - branch and link */
3082 case 0x45: /* BAL - branch and link */
3083 case 0x06: /* BCTR - branch on count */
3084 case 0x46: /* BCT - branch on count */
3085 case 0x0d: /* BASR - branch and save */
3086 case 0x4d: /* BAS - branch and save */
3087 case 0x84: /* BRXH - branch relative on index high */
3088 case 0x85: /* BRXLE - branch relative on index low or equal */
3089 case 0x86: /* BXH - branch on index high */
3090 case 0x87: /* BXLE - branch on index low or equal */
3091 /* BA[SL]* use native-size destination for linkage info, BCT*, BRX*, BX*
3092 use 32-bit destination as counter. */
3093 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3094 return -1;
3095 break;
3097 case 0x07: /* BCR - branch on condition */
3098 case 0x47: /* BC - branch on condition */
3099 /* No effect other than PC transfer. */
3100 break;
3102 /* 0x08 undefined */
3103 /* 0x09 undefined */
3105 case 0x0a:
3106 /* SVC - supervisor call */
3107 if (tdep->s390_syscall_record != NULL)
3109 if (tdep->s390_syscall_record (regcache, ibyte[1]))
3110 return -1;
3112 else
3114 gdb_printf (gdb_stderr, _("no syscall record support\n"));
3115 return -1;
3117 break;
3119 case 0x0b: /* BSM - branch and set mode */
3120 if (inib[2])
3121 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3122 return -1;
3123 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3124 return -1;
3125 break;
3127 case 0x0c: /* BASSM - branch and save and set mode */
3128 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3129 return -1;
3130 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3131 return -1;
3132 break;
3134 case 0x0e: /* MVCL - move long [interruptible] */
3135 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
3136 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3137 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[2] | 1), &tmp);
3138 tmp &= 0xffffff;
3139 if (record_full_arch_list_add_mem (oaddr, tmp))
3140 return -1;
3141 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3142 return -1;
3143 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
3144 return -1;
3145 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
3146 return -1;
3147 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
3148 return -1;
3149 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3150 return -1;
3151 break;
3153 case 0x0f: /* CLCL - compare logical long [interruptible] */
3154 case 0xa9: /* CLCLE - compare logical long extended [partial] */
3155 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3156 return -1;
3157 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
3158 return -1;
3159 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
3160 return -1;
3161 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
3162 return -1;
3163 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3164 return -1;
3165 break;
3167 case 0x10: /* LPR - load positive */
3168 case 0x11: /* LNR - load negative */
3169 case 0x12: /* LTR - load and test */
3170 case 0x13: /* LCR - load complement */
3171 case 0x14: /* NR - and */
3172 case 0x16: /* OR - or */
3173 case 0x17: /* XR - xor */
3174 case 0x1a: /* AR - add */
3175 case 0x1b: /* SR - subtract */
3176 case 0x1e: /* ALR - add logical */
3177 case 0x1f: /* SLR - subtract logical */
3178 case 0x54: /* N - and */
3179 case 0x56: /* O - or */
3180 case 0x57: /* X - xor */
3181 case 0x5a: /* A - add */
3182 case 0x5b: /* S - subtract */
3183 case 0x5e: /* AL - add logical */
3184 case 0x5f: /* SL - subtract logical */
3185 case 0x4a: /* AH - add halfword */
3186 case 0x4b: /* SH - subtract halfword */
3187 case 0x8a: /* SRA - shift right single */
3188 case 0x8b: /* SLA - shift left single */
3189 case 0xbf: /* ICM - insert characters under mask */
3190 /* 32-bit destination + flags */
3191 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3192 return -1;
3193 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3194 return -1;
3195 break;
3197 case 0x15: /* CLR - compare logical */
3198 case 0x55: /* CL - compare logical */
3199 case 0x19: /* CR - compare */
3200 case 0x29: /* CDR - compare */
3201 case 0x39: /* CER - compare */
3202 case 0x49: /* CH - compare halfword */
3203 case 0x59: /* C - compare */
3204 case 0x69: /* CD - compare */
3205 case 0x79: /* CE - compare */
3206 case 0x91: /* TM - test under mask */
3207 case 0x95: /* CLI - compare logical */
3208 case 0xbd: /* CLM - compare logical under mask */
3209 case 0xd5: /* CLC - compare logical */
3210 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3211 return -1;
3212 break;
3214 case 0x18: /* LR - load */
3215 case 0x48: /* LH - load halfword */
3216 case 0x58: /* L - load */
3217 case 0x41: /* LA - load address */
3218 case 0x43: /* IC - insert character */
3219 case 0x4c: /* MH - multiply halfword */
3220 case 0x71: /* MS - multiply single */
3221 case 0x88: /* SRL - shift right single logical */
3222 case 0x89: /* SLL - shift left single logical */
3223 /* 32-bit, 8-bit (IC), or native width (LA) destination, no flags */
3224 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3225 return -1;
3226 break;
3228 case 0x1c: /* MR - multiply */
3229 case 0x5c: /* M - multiply */
3230 case 0x1d: /* DR - divide */
3231 case 0x5d: /* D - divide */
3232 case 0x8c: /* SRDL - shift right double logical */
3233 case 0x8d: /* SLDL - shift left double logical */
3234 /* 32-bit pair destination, no flags */
3235 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3236 return -1;
3237 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
3238 return -1;
3239 break;
3241 case 0x20: /* LPDR - load positive */
3242 case 0x30: /* LPER - load positive */
3243 case 0x21: /* LNDR - load negative */
3244 case 0x31: /* LNER - load negative */
3245 case 0x22: /* LTDR - load and test */
3246 case 0x32: /* LTER - load and test */
3247 case 0x23: /* LCDR - load complement */
3248 case 0x33: /* LCER - load complement */
3249 case 0x2a: /* ADR - add */
3250 case 0x3a: /* AER - add */
3251 case 0x6a: /* AD - add */
3252 case 0x7a: /* AE - add */
3253 case 0x2b: /* SDR - subtract */
3254 case 0x3b: /* SER - subtract */
3255 case 0x6b: /* SD - subtract */
3256 case 0x7b: /* SE - subtract */
3257 case 0x2e: /* AWR - add unnormalized */
3258 case 0x3e: /* AUR - add unnormalized */
3259 case 0x6e: /* AW - add unnormalized */
3260 case 0x7e: /* AU - add unnormalized */
3261 case 0x2f: /* SWR - subtract unnormalized */
3262 case 0x3f: /* SUR - subtract unnormalized */
3263 case 0x6f: /* SW - subtract unnormalized */
3264 case 0x7f: /* SU - subtract unnormalized */
3265 /* float destination + flags */
3266 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
3267 return -1;
3268 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3269 return -1;
3270 break;
3272 case 0x24: /* HDR - halve */
3273 case 0x34: /* HER - halve */
3274 case 0x25: /* LDXR - load rounded */
3275 case 0x35: /* LEDR - load rounded */
3276 case 0x28: /* LDR - load */
3277 case 0x38: /* LER - load */
3278 case 0x68: /* LD - load */
3279 case 0x78: /* LE - load */
3280 case 0x2c: /* MDR - multiply */
3281 case 0x3c: /* MDER - multiply */
3282 case 0x6c: /* MD - multiply */
3283 case 0x7c: /* MDE - multiply */
3284 case 0x2d: /* DDR - divide */
3285 case 0x3d: /* DER - divide */
3286 case 0x6d: /* DD - divide */
3287 case 0x7d: /* DE - divide */
3288 /* float destination, no flags */
3289 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
3290 return -1;
3291 break;
3293 case 0x26: /* MXR - multiply */
3294 case 0x27: /* MXDR - multiply */
3295 case 0x67: /* MXD - multiply */
3296 /* float pair destination, no flags */
3297 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
3298 return -1;
3299 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
3300 return -1;
3301 break;
3303 case 0x36: /* AXR - add */
3304 case 0x37: /* SXR - subtract */
3305 /* float pair destination + flags */
3306 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
3307 return -1;
3308 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
3309 return -1;
3310 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3311 return -1;
3312 break;
3314 case 0x40: /* STH - store halfword */
3315 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
3316 if (record_full_arch_list_add_mem (oaddr, 2))
3317 return -1;
3318 break;
3320 case 0x42: /* STC - store character */
3321 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
3322 if (record_full_arch_list_add_mem (oaddr, 1))
3323 return -1;
3324 break;
3326 case 0x44: /* EX - execute */
3327 if (ex != -1)
3329 gdb_printf (gdb_stdlog, "Warning: Double execute at %s.\n",
3330 paddress (gdbarch, addr));
3331 return -1;
3333 addr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
3334 if (inib[2])
3336 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
3337 ex = tmp & 0xff;
3339 else
3341 ex = 0;
3343 goto ex;
3345 case 0x4e: /* CVD - convert to decimal */
3346 case 0x60: /* STD - store */
3347 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
3348 if (record_full_arch_list_add_mem (oaddr, 8))
3349 return -1;
3350 break;
3352 case 0x4f: /* CVB - convert to binary */
3353 /* 32-bit gpr destination + FPC (DXC write) */
3354 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3355 return -1;
3356 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3357 return -1;
3358 break;
3360 case 0x50: /* ST - store */
3361 case 0x70: /* STE - store */
3362 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
3363 if (record_full_arch_list_add_mem (oaddr, 4))
3364 return -1;
3365 break;
3367 case 0x51: /* LAE - load address extended */
3368 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3369 return -1;
3370 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[2]))
3371 return -1;
3372 break;
3374 /* 0x52 undefined */
3375 /* 0x53 undefined */
3377 /* 0x61-0x66 undefined */
3379 /* 0x72-0x77 undefined */
3381 /* 0x80 privileged: SSM - set system mask */
3382 /* 0x81 undefined */
3383 /* 0x82 privileged: LPSW - load PSW */
3384 /* 0x83 privileged: diagnose */
3386 case 0x8e: /* SRDA - shift right double */
3387 case 0x8f: /* SLDA - shift left double */
3388 /* 32-bit pair destination + flags */
3389 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3390 return -1;
3391 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
3392 return -1;
3393 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3394 return -1;
3395 break;
3397 case 0x90: /* STM - store multiple */
3398 case 0x9b: /* STAM - store access multiple */
3399 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3400 if (inib[2] <= inib[3])
3401 n = inib[3] - inib[2] + 1;
3402 else
3403 n = inib[3] + 0x10 - inib[2] + 1;
3404 if (record_full_arch_list_add_mem (oaddr, n * 4))
3405 return -1;
3406 break;
3408 case 0x92: /* MVI - move */
3409 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3410 if (record_full_arch_list_add_mem (oaddr, 1))
3411 return -1;
3412 break;
3414 case 0x93: /* TS - test and set */
3415 case 0x94: /* NI - and */
3416 case 0x96: /* OI - or */
3417 case 0x97: /* XI - xor */
3418 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3419 if (record_full_arch_list_add_mem (oaddr, 1))
3420 return -1;
3421 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3422 return -1;
3423 break;
3425 case 0x98: /* LM - load multiple */
3426 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
3427 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
3428 return -1;
3429 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
3430 return -1;
3431 break;
3433 /* 0x99 privileged: TRACE */
3435 case 0x9a: /* LAM - load access multiple */
3436 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
3437 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + i))
3438 return -1;
3439 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[3]))
3440 return -1;
3441 break;
3443 /* 0x9c-0x9f privileged and obsolete (old I/O) */
3444 /* 0xa0-0xa4 undefined */
3446 case 0xa5:
3447 case 0xa7:
3448 /* RI-format instruction */
3449 switch (ibyte[0] << 4 | inib[3])
3451 case 0xa50: /* IIHH - insert immediate */
3452 case 0xa51: /* IIHL - insert immediate */
3453 /* high 32-bit destination */
3454 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
3455 return -1;
3456 break;
3458 case 0xa52: /* IILH - insert immediate */
3459 case 0xa53: /* IILL - insert immediate */
3460 case 0xa75: /* BRAS - branch relative and save */
3461 case 0xa76: /* BRCT - branch relative on count */
3462 case 0xa78: /* LHI - load halfword immediate */
3463 case 0xa7c: /* MHI - multiply halfword immediate */
3464 /* 32-bit or native destination */
3465 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3466 return -1;
3467 break;
3469 case 0xa54: /* NIHH - and immediate */
3470 case 0xa55: /* NIHL - and immediate */
3471 case 0xa58: /* OIHH - or immediate */
3472 case 0xa59: /* OIHL - or immediate */
3473 /* high 32-bit destination + flags */
3474 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
3475 return -1;
3476 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3477 return -1;
3478 break;
3480 case 0xa56: /* NILH - and immediate */
3481 case 0xa57: /* NILL - and immediate */
3482 case 0xa5a: /* OILH - or immediate */
3483 case 0xa5b: /* OILL - or immediate */
3484 case 0xa7a: /* AHI - add halfword immediate */
3485 /* 32-bit destination + flags */
3486 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3487 return -1;
3488 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3489 return -1;
3490 break;
3492 case 0xa5c: /* LLIHH - load logical immediate */
3493 case 0xa5d: /* LLIHL - load logical immediate */
3494 case 0xa5e: /* LLILH - load logical immediate */
3495 case 0xa5f: /* LLILL - load logical immediate */
3496 case 0xa77: /* BRCTG - branch relative on count */
3497 case 0xa79: /* LGHI - load halfword immediate */
3498 case 0xa7d: /* MGHI - multiply halfword immediate */
3499 /* 64-bit destination */
3500 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
3501 return -1;
3502 break;
3504 case 0xa70: /* TMLH - test under mask */
3505 case 0xa71: /* TMLL - test under mask */
3506 case 0xa72: /* TMHH - test under mask */
3507 case 0xa73: /* TMHL - test under mask */
3508 case 0xa7e: /* CHI - compare halfword immediate */
3509 case 0xa7f: /* CGHI - compare halfword immediate */
3510 /* flags only */
3511 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3512 return -1;
3513 break;
3515 case 0xa74: /* BRC - branch relative on condition */
3516 /* no register change */
3517 break;
3519 case 0xa7b: /* AGHI - add halfword immediate */
3520 /* 64-bit destination + flags */
3521 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
3522 return -1;
3523 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3524 return -1;
3525 break;
3527 default:
3528 goto UNKNOWN_OP;
3530 break;
3532 /* 0xa6 undefined */
3534 case 0xa8: /* MVCLE - move long extended [partial] */
3535 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
3536 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3537 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[2] | 1), &tmp);
3538 if (record_full_arch_list_add_mem (oaddr, tmp))
3539 return -1;
3540 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
3541 return -1;
3542 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
3543 return -1;
3544 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
3545 return -1;
3546 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
3547 return -1;
3548 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3549 return -1;
3550 break;
3552 /* 0xaa-0xab undefined */
3553 /* 0xac privileged: STNSM - store then and system mask */
3554 /* 0xad privileged: STOSM - store then or system mask */
3555 /* 0xae privileged: SIGP - signal processor */
3556 /* 0xaf unsupported: MC - monitor call */
3557 /* 0xb0 undefined */
3558 /* 0xb1 privileged: LRA - load real address */
3560 case 0xb2:
3561 case 0xb3:
3562 case 0xb9:
3563 /* S/RRD/RRE/RRF/IE-format instruction */
3564 switch (insn[0])
3566 /* 0xb200-0xb204 undefined or privileged */
3568 case 0xb205: /* STCK - store clock */
3569 case 0xb27c: /* STCKF - store clock fast */
3570 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3571 if (record_full_arch_list_add_mem (oaddr, 8))
3572 return -1;
3573 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3574 return -1;
3575 break;
3577 /* 0xb206-0xb219 undefined, privileged, or unsupported */
3578 /* 0xb21a unsupported: CFC */
3579 /* 0xb21b-0xb221 undefined or privileged */
3581 case 0xb222: /* IPM - insert program mask */
3582 case 0xb24f: /* EAR - extract access */
3583 case 0xb252: /* MSR - multiply single */
3584 case 0xb2ec: /* ETND - extract transaction nesting depth */
3585 case 0xb38c: /* EFPC - extract fpc */
3586 case 0xb91f: /* LRVR - load reversed */
3587 case 0xb926: /* LBR - load byte */
3588 case 0xb927: /* LHR - load halfword */
3589 case 0xb994: /* LLCR - load logical character */
3590 case 0xb995: /* LLHR - load logical halfword */
3591 case 0xb9f2: /* LOCR - load on condition */
3592 /* 32-bit gpr destination */
3593 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3594 return -1;
3595 break;
3597 /* 0xb223-0xb22c privileged or unsupported */
3599 case 0xb22d: /* DXR - divide */
3600 case 0xb325: /* LXDR - load lengthened */
3601 case 0xb326: /* LXER - load lengthened */
3602 case 0xb336: /* SQXR - square root */
3603 case 0xb365: /* LXR - load */
3604 case 0xb367: /* FIXR - load fp integer */
3605 case 0xb376: /* LZXR - load zero */
3606 case 0xb3b6: /* CXFR - convert from fixed */
3607 case 0xb3c6: /* CXGR - convert from fixed */
3608 case 0xb3fe: /* IEXTR - insert biased exponent */
3609 /* float pair destination */
3610 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
3611 return -1;
3612 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
3613 return -1;
3614 break;
3616 /* 0xb22e-0xb240 undefined, privileged, or unsupported */
3618 case 0xb241: /* CKSM - checksum [partial] */
3619 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3620 return -1;
3621 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
3622 return -1;
3623 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
3624 return -1;
3625 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3626 return -1;
3627 break;
3629 /* 0xb242-0xb243 undefined */
3631 case 0xb244: /* SQDR - square root */
3632 case 0xb245: /* SQER - square root */
3633 case 0xb324: /* LDER - load lengthened */
3634 case 0xb337: /* MEER - multiply */
3635 case 0xb366: /* LEXR - load rounded */
3636 case 0xb370: /* LPDFR - load positive */
3637 case 0xb371: /* LNDFR - load negative */
3638 case 0xb372: /* CSDFR - copy sign */
3639 case 0xb373: /* LCDFR - load complement */
3640 case 0xb374: /* LZER - load zero */
3641 case 0xb375: /* LZDR - load zero */
3642 case 0xb377: /* FIER - load fp integer */
3643 case 0xb37f: /* FIDR - load fp integer */
3644 case 0xb3b4: /* CEFR - convert from fixed */
3645 case 0xb3b5: /* CDFR - convert from fixed */
3646 case 0xb3c1: /* LDGR - load fpr from gr */
3647 case 0xb3c4: /* CEGR - convert from fixed */
3648 case 0xb3c5: /* CDGR - convert from fixed */
3649 case 0xb3f6: /* IEDTR - insert biased exponent */
3650 /* float destination */
3651 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
3652 return -1;
3653 break;
3655 /* 0xb246-0xb24c: privileged or unsupported */
3657 case 0xb24d: /* CPYA - copy access */
3658 case 0xb24e: /* SAR - set access */
3659 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[6]))
3660 return -1;
3661 break;
3663 /* 0xb250-0xb251 undefined or privileged */
3664 /* 0xb253-0xb254 undefined or privileged */
3666 case 0xb255: /* MVST - move string [partial] */
3668 uint8_t end;
3669 gdb_byte cur;
3670 ULONGEST num = 0;
3671 /* Read ending byte. */
3672 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
3673 end = tmp & 0xff;
3674 /* Get address of second operand. */
3675 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[7], &tmp);
3676 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3677 /* Search for ending byte and compute length. */
3678 do {
3679 num++;
3680 if (target_read_memory (oaddr, &cur, 1))
3681 return -1;
3682 oaddr++;
3683 } while (cur != end);
3684 /* Get address of first operand and record it. */
3685 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
3686 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3687 if (record_full_arch_list_add_mem (oaddr, num))
3688 return -1;
3689 /* Record the registers. */
3690 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3691 return -1;
3692 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
3693 return -1;
3694 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3695 return -1;
3697 break;
3699 /* 0xb256 undefined */
3701 case 0xb257: /* CUSE - compare until substring equal [interruptible] */
3702 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3703 return -1;
3704 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
3705 return -1;
3706 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
3707 return -1;
3708 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
3709 return -1;
3710 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3711 return -1;
3712 break;
3714 /* 0xb258-0xb25c undefined, privileged, or unsupported */
3716 case 0xb25d: /* CLST - compare logical string [partial] */
3717 case 0xb25e: /* SRST - search string [partial] */
3718 case 0xb9be: /* SRSTU - search string unicode [partial] */
3719 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3720 return -1;
3721 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
3722 return -1;
3723 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3724 return -1;
3725 break;
3727 /* 0xb25f-0xb262 undefined */
3729 case 0xb263: /* CMPSC - compression call [interruptible] */
3730 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
3731 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3732 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
3733 if (record_full_arch_list_add_mem (oaddr, tmp))
3734 return -1;
3735 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3736 return -1;
3737 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
3738 return -1;
3739 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
3740 return -1;
3741 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
3742 return -1;
3743 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
3744 return -1;
3745 /* DXC may be written */
3746 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3747 return -1;
3748 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3749 return -1;
3750 break;
3752 /* 0xb264-0xb277 undefined, privileged, or unsupported */
3754 case 0xb278: /* STCKE - store clock extended */
3755 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3756 if (record_full_arch_list_add_mem (oaddr, 16))
3757 return -1;
3758 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3759 return -1;
3760 break;
3762 /* 0xb279-0xb27b undefined or unsupported */
3763 /* 0xb27d-0xb298 undefined or privileged */
3765 case 0xb299: /* SRNM - set rounding mode */
3766 case 0xb2b8: /* SRNMB - set bfp rounding mode */
3767 case 0xb2b9: /* SRNMT - set dfp rounding mode */
3768 case 0xb29d: /* LFPC - load fpc */
3769 case 0xb2bd: /* LFAS - load fpc and signal */
3770 case 0xb384: /* SFPC - set fpc */
3771 case 0xb385: /* SFASR - set fpc and signal */
3772 case 0xb960: /* CGRT - compare and trap */
3773 case 0xb961: /* CLGRT - compare logical and trap */
3774 case 0xb972: /* CRT - compare and trap */
3775 case 0xb973: /* CLRT - compare logical and trap */
3776 /* fpc only - including possible DXC write for trapping insns */
3777 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3778 return -1;
3779 break;
3781 /* 0xb29a-0xb29b undefined */
3783 case 0xb29c: /* STFPC - store fpc */
3784 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3785 if (record_full_arch_list_add_mem (oaddr, 4))
3786 return -1;
3787 break;
3789 /* 0xb29e-0xb2a4 undefined */
3791 case 0xb2a5: /* TRE - translate extended [partial] */
3792 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
3793 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3794 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
3795 if (record_full_arch_list_add_mem (oaddr, tmp))
3796 return -1;
3797 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3798 return -1;
3799 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
3800 return -1;
3801 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3802 return -1;
3803 break;
3805 case 0xb2a6: /* CU21 - convert UTF-16 to UTF-8 [partial] */
3806 case 0xb2a7: /* CU12 - convert UTF-8 to UTF-16 [partial] */
3807 case 0xb9b0: /* CU14 - convert UTF-8 to UTF-32 [partial] */
3808 case 0xb9b1: /* CU24 - convert UTF-16 to UTF-32 [partial] */
3809 case 0xb9b2: /* CU41 - convert UTF-32 to UTF-8 [partial] */
3810 case 0xb9b3: /* CU42 - convert UTF-32 to UTF-16 [partial] */
3811 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
3812 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
3813 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
3814 if (record_full_arch_list_add_mem (oaddr, tmp))
3815 return -1;
3816 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
3817 return -1;
3818 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
3819 return -1;
3820 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
3821 return -1;
3822 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
3823 return -1;
3824 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3825 return -1;
3826 break;
3828 /* 0xb2a8-0xb2af undefined */
3830 case 0xb2b0: /* STFLE - store facility list extended */
3831 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
3832 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
3833 tmp &= 0xff;
3834 if (record_full_arch_list_add_mem (oaddr, 8 * (tmp + 1)))
3835 return -1;
3836 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM))
3837 return -1;
3838 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3839 return -1;
3840 break;
3842 /* 0xb2b1-0xb2b7 undefined or privileged */
3843 /* 0xb2ba-0xb2bc undefined */
3844 /* 0xb2be-0xb2e7 undefined */
3845 /* 0xb2e9-0xb2eb undefined */
3846 /* 0xb2ed-0xb2f7 undefined */
3847 /* 0xb2f8 unsupported: TEND */
3848 /* 0xb2f9 undefined */
3850 case 0xb2e8: /* PPA - perform processor assist */
3851 case 0xb2fa: /* NIAI - next instruction access intent */
3852 /* no visible effects */
3853 break;
3855 /* 0xb2fb undefined */
3856 /* 0xb2fc unsupported: TABORT */
3857 /* 0xb2fd-0xb2fe undefined */
3858 /* 0xb2ff unsupported: TRAP */
3860 case 0xb300: /* LPEBR - load positive */
3861 case 0xb301: /* LNEBR - load negative */
3862 case 0xb303: /* LCEBR - load complement */
3863 case 0xb310: /* LPDBR - load positive */
3864 case 0xb311: /* LNDBR - load negative */
3865 case 0xb313: /* LCDBR - load complement */
3866 case 0xb350: /* TBEDR - convert hfp to bfp */
3867 case 0xb351: /* TBDR - convert hfp to bfp */
3868 case 0xb358: /* THDER - convert bfp to hfp */
3869 case 0xb359: /* THDR - convert bfp to hfp */
3870 /* float destination + flags */
3871 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
3872 return -1;
3873 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3874 return -1;
3875 break;
3877 case 0xb304: /* LDEBR - load lengthened */
3878 case 0xb30c: /* MDEBR - multiply */
3879 case 0xb30d: /* DEBR - divide */
3880 case 0xb314: /* SQEBR - square root */
3881 case 0xb315: /* SQDBR - square root */
3882 case 0xb317: /* MEEBR - multiply */
3883 case 0xb31c: /* MDBR - multiply */
3884 case 0xb31d: /* DDBR - divide */
3885 case 0xb344: /* LEDBRA - load rounded */
3886 case 0xb345: /* LDXBRA - load rounded */
3887 case 0xb346: /* LEXBRA - load rounded */
3888 case 0xb357: /* FIEBRA - load fp integer */
3889 case 0xb35f: /* FIDBRA - load fp integer */
3890 case 0xb390: /* CELFBR - convert from logical */
3891 case 0xb391: /* CDLFBR - convert from logical */
3892 case 0xb394: /* CEFBR - convert from fixed */
3893 case 0xb395: /* CDFBR - convert from fixed */
3894 case 0xb3a0: /* CELGBR - convert from logical */
3895 case 0xb3a1: /* CDLGBR - convert from logical */
3896 case 0xb3a4: /* CEGBR - convert from fixed */
3897 case 0xb3a5: /* CDGBR - convert from fixed */
3898 case 0xb3d0: /* MDTR - multiply */
3899 case 0xb3d1: /* DDTR - divide */
3900 case 0xb3d4: /* LDETR - load lengthened */
3901 case 0xb3d5: /* LEDTR - load lengthened */
3902 case 0xb3d7: /* FIDTR - load fp integer */
3903 case 0xb3dd: /* LDXTR - load lengthened */
3904 case 0xb3f1: /* CDGTR - convert from fixed */
3905 case 0xb3f2: /* CDUTR - convert from unsigned packed */
3906 case 0xb3f3: /* CDSTR - convert from signed packed */
3907 case 0xb3f5: /* QADTR - quantize */
3908 case 0xb3f7: /* RRDTR - reround */
3909 case 0xb951: /* CDFTR - convert from fixed */
3910 case 0xb952: /* CDLGTR - convert from logical */
3911 case 0xb953: /* CDLFTR - convert from logical */
3912 /* float destination + fpc */
3913 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
3914 return -1;
3915 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3916 return -1;
3917 break;
3919 case 0xb305: /* LXDBR - load lengthened */
3920 case 0xb306: /* LXEBR - load lengthened */
3921 case 0xb307: /* MXDBR - multiply */
3922 case 0xb316: /* SQXBR - square root */
3923 case 0xb34c: /* MXBR - multiply */
3924 case 0xb34d: /* DXBR - divide */
3925 case 0xb347: /* FIXBRA - load fp integer */
3926 case 0xb392: /* CXLFBR - convert from logical */
3927 case 0xb396: /* CXFBR - convert from fixed */
3928 case 0xb3a2: /* CXLGBR - convert from logical */
3929 case 0xb3a6: /* CXGBR - convert from fixed */
3930 case 0xb3d8: /* MXTR - multiply */
3931 case 0xb3d9: /* DXTR - divide */
3932 case 0xb3dc: /* LXDTR - load lengthened */
3933 case 0xb3df: /* FIXTR - load fp integer */
3934 case 0xb3f9: /* CXGTR - convert from fixed */
3935 case 0xb3fa: /* CXUTR - convert from unsigned packed */
3936 case 0xb3fb: /* CXSTR - convert from signed packed */
3937 case 0xb3fd: /* QAXTR - quantize */
3938 case 0xb3ff: /* RRXTR - reround */
3939 case 0xb959: /* CXFTR - convert from fixed */
3940 case 0xb95a: /* CXLGTR - convert from logical */
3941 case 0xb95b: /* CXLFTR - convert from logical */
3942 /* float pair destination + fpc */
3943 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
3944 return -1;
3945 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
3946 return -1;
3947 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3948 return -1;
3949 break;
3951 case 0xb308: /* KEBR - compare and signal */
3952 case 0xb309: /* CEBR - compare */
3953 case 0xb318: /* KDBR - compare and signal */
3954 case 0xb319: /* CDBR - compare */
3955 case 0xb348: /* KXBR - compare and signal */
3956 case 0xb349: /* CXBR - compare */
3957 case 0xb3e0: /* KDTR - compare and signal */
3958 case 0xb3e4: /* CDTR - compare */
3959 case 0xb3e8: /* KXTR - compare and signal */
3960 case 0xb3ec: /* CXTR - compare */
3961 /* flags + fpc only */
3962 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3963 return -1;
3964 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3965 return -1;
3966 break;
3968 case 0xb302: /* LTEBR - load and test */
3969 case 0xb312: /* LTDBR - load and test */
3970 case 0xb30a: /* AEBR - add */
3971 case 0xb30b: /* SEBR - subtract */
3972 case 0xb31a: /* ADBR - add */
3973 case 0xb31b: /* SDBR - subtract */
3974 case 0xb3d2: /* ADTR - add */
3975 case 0xb3d3: /* SDTR - subtract */
3976 case 0xb3d6: /* LTDTR - load and test */
3977 /* float destination + flags + fpc */
3978 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
3979 return -1;
3980 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
3981 return -1;
3982 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3983 return -1;
3984 break;
3986 case 0xb30e: /* MAEBR - multiply and add */
3987 case 0xb30f: /* MSEBR - multiply and subtract */
3988 case 0xb31e: /* MADBR - multiply and add */
3989 case 0xb31f: /* MSDBR - multiply and subtract */
3990 /* float destination [RRD] + fpc */
3991 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
3992 return -1;
3993 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
3994 return -1;
3995 break;
3997 /* 0xb320-0xb323 undefined */
3998 /* 0xb327-0xb32d undefined */
4000 case 0xb32e: /* MAER - multiply and add */
4001 case 0xb32f: /* MSER - multiply and subtract */
4002 case 0xb338: /* MAYLR - multiply and add unnormalized */
4003 case 0xb339: /* MYLR - multiply unnormalized */
4004 case 0xb33c: /* MAYHR - multiply and add unnormalized */
4005 case 0xb33d: /* MYHR - multiply unnormalized */
4006 case 0xb33e: /* MADR - multiply and add */
4007 case 0xb33f: /* MSDR - multiply and subtract */
4008 /* float destination [RRD] */
4009 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4010 return -1;
4011 break;
4013 /* 0xb330-0xb335 undefined */
4015 case 0xb33a: /* MAYR - multiply and add unnormalized */
4016 case 0xb33b: /* MYR - multiply unnormalized */
4017 /* float pair destination [RRD] */
4018 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4019 return -1;
4020 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[4] | 2)))
4021 return -1;
4022 break;
4024 case 0xb340: /* LPXBR - load positive */
4025 case 0xb341: /* LNXBR - load negative */
4026 case 0xb343: /* LCXBR - load complement */
4027 case 0xb360: /* LPXR - load positive */
4028 case 0xb361: /* LNXR - load negative */
4029 case 0xb362: /* LTXR - load and test */
4030 case 0xb363: /* LCXR - load complement */
4031 /* float pair destination + flags */
4032 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4033 return -1;
4034 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
4035 return -1;
4036 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4037 return -1;
4038 break;
4040 case 0xb342: /* LTXBR - load and test */
4041 case 0xb34a: /* AXBR - add */
4042 case 0xb34b: /* SXBR - subtract */
4043 case 0xb3da: /* AXTR - add */
4044 case 0xb3db: /* SXTR - subtract */
4045 case 0xb3de: /* LTXTR - load and test */
4046 /* float pair destination + flags + fpc */
4047 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4048 return -1;
4049 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[6] | 2)))
4050 return -1;
4051 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4052 return -1;
4053 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4054 return -1;
4055 break;
4057 /* 0xb34e-0xb34f undefined */
4058 /* 0xb352 undefined */
4060 case 0xb353: /* DIEBR - divide to integer */
4061 case 0xb35b: /* DIDBR - divide to integer */
4062 /* two float destinations + flags + fpc */
4063 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[4]))
4064 return -1;
4065 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[6]))
4066 return -1;
4067 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4068 return -1;
4069 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4070 return -1;
4071 break;
4073 /* 0xb354-0xb356 undefined */
4074 /* 0xb35a undefined */
4076 /* 0xb35c-0xb35e undefined */
4077 /* 0xb364 undefined */
4078 /* 0xb368 undefined */
4080 case 0xb369: /* CXR - compare */
4081 case 0xb3f4: /* CEDTR - compare biased exponent */
4082 case 0xb3fc: /* CEXTR - compare biased exponent */
4083 case 0xb920: /* CGR - compare */
4084 case 0xb921: /* CLGR - compare logical */
4085 case 0xb930: /* CGFR - compare */
4086 case 0xb931: /* CLGFR - compare logical */
4087 case 0xb9cd: /* CHHR - compare high */
4088 case 0xb9cf: /* CLHHR - compare logical high */
4089 case 0xb9dd: /* CHLR - compare high */
4090 case 0xb9df: /* CLHLR - compare logical high */
4091 /* flags only */
4092 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4093 return -1;
4094 break;
4096 /* 0xb36a-0xb36f undefined */
4097 /* 0xb377-0xb37e undefined */
4098 /* 0xb380-0xb383 undefined */
4099 /* 0xb386-0xb38b undefined */
4100 /* 0xb38d-0xb38f undefined */
4101 /* 0xb393 undefined */
4102 /* 0xb397 undefined */
4104 case 0xb398: /* CFEBR - convert to fixed */
4105 case 0xb399: /* CFDBR - convert to fixed */
4106 case 0xb39a: /* CFXBR - convert to fixed */
4107 case 0xb39c: /* CLFEBR - convert to logical */
4108 case 0xb39d: /* CLFDBR - convert to logical */
4109 case 0xb39e: /* CLFXBR - convert to logical */
4110 case 0xb941: /* CFDTR - convert to fixed */
4111 case 0xb949: /* CFXTR - convert to fixed */
4112 case 0xb943: /* CLFDTR - convert to logical */
4113 case 0xb94b: /* CLFXTR - convert to logical */
4114 /* 32-bit gpr destination + flags + fpc */
4115 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4116 return -1;
4117 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4118 return -1;
4119 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4120 return -1;
4121 break;
4123 /* 0xb39b undefined */
4124 /* 0xb39f undefined */
4126 /* 0xb3a3 undefined */
4127 /* 0xb3a7 undefined */
4129 case 0xb3a8: /* CGEBR - convert to fixed */
4130 case 0xb3a9: /* CGDBR - convert to fixed */
4131 case 0xb3aa: /* CGXBR - convert to fixed */
4132 case 0xb3ac: /* CLGEBR - convert to logical */
4133 case 0xb3ad: /* CLGDBR - convert to logical */
4134 case 0xb3ae: /* CLGXBR - convert to logical */
4135 case 0xb3e1: /* CGDTR - convert to fixed */
4136 case 0xb3e9: /* CGXTR - convert to fixed */
4137 case 0xb942: /* CLGDTR - convert to logical */
4138 case 0xb94a: /* CLGXTR - convert to logical */
4139 /* 64-bit gpr destination + flags + fpc */
4140 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
4141 return -1;
4142 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4143 return -1;
4144 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4145 return -1;
4146 break;
4148 /* 0xb3ab undefined */
4149 /* 0xb3af-0xb3b3 undefined */
4150 /* 0xb3b7 undefined */
4152 case 0xb3b8: /* CFER - convert to fixed */
4153 case 0xb3b9: /* CFDR - convert to fixed */
4154 case 0xb3ba: /* CFXR - convert to fixed */
4155 case 0xb998: /* ALCR - add logical with carry */
4156 case 0xb999: /* SLBR - subtract logical with borrow */
4157 case 0xb9f4: /* NRK - and */
4158 case 0xb9f5: /* NCRK - and with complement */
4159 case 0xb9f6: /* ORK - or */
4160 case 0xb9f7: /* XRK - xor */
4161 case 0xb9f8: /* ARK - add */
4162 case 0xb9f9: /* SRK - subtract */
4163 case 0xb9fa: /* ALRK - add logical */
4164 case 0xb9fb: /* SLRK - subtract logical */
4165 /* 32-bit gpr destination + flags */
4166 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4167 return -1;
4168 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4169 return -1;
4170 break;
4172 case 0xb3c8: /* CGER - convert to fixed */
4173 case 0xb3c9: /* CGDR - convert to fixed */
4174 case 0xb3ca: /* CGXR - convert to fixed */
4175 case 0xb900: /* LPGR - load positive */
4176 case 0xb901: /* LNGR - load negative */
4177 case 0xb902: /* LTGR - load and test */
4178 case 0xb903: /* LCGR - load complement */
4179 case 0xb908: /* AGR - add */
4180 case 0xb909: /* SGR - subtract */
4181 case 0xb90a: /* ALGR - add logical */
4182 case 0xb90b: /* SLGR - subtract logical */
4183 case 0xb910: /* LPGFR - load positive */
4184 case 0xb911: /* LNGFR - load negative */
4185 case 0xb912: /* LTGFR - load and test */
4186 case 0xb913: /* LCGFR - load complement */
4187 case 0xb918: /* AGFR - add */
4188 case 0xb919: /* SGFR - subtract */
4189 case 0xb91a: /* ALGFR - add logical */
4190 case 0xb91b: /* SLGFR - subtract logical */
4191 case 0xb964: /* NNGRK - and 64 bit */
4192 case 0xb965: /* OCGRK - or with complement 64 bit */
4193 case 0xb966: /* NOGRK - or 64 bit */
4194 case 0xb967: /* NXGRK - not exclusive or 64 bit */
4195 case 0xb974: /* NNRK - and 32 bit */
4196 case 0xb975: /* OCRK - or with complement 32 bit */
4197 case 0xb976: /* NORK - or 32 bit */
4198 case 0xb977: /* NXRK - not exclusive or 32 bit */
4199 case 0xb980: /* NGR - and */
4200 case 0xb981: /* OGR - or */
4201 case 0xb982: /* XGR - xor */
4202 case 0xb988: /* ALCGR - add logical with carry */
4203 case 0xb989: /* SLBGR - subtract logical with borrow */
4204 case 0xb9c0: /* SELFHR - select high */
4205 case 0xb9e1: /* POPCNT - population count */
4206 case 0xb9e4: /* NGRK - and */
4207 case 0xb9e5: /* NCGRK - and with complement */
4208 case 0xb9e6: /* OGRK - or */
4209 case 0xb9e7: /* XGRK - xor */
4210 case 0xb9e8: /* AGRK - add */
4211 case 0xb9e9: /* SGRK - subtract */
4212 case 0xb9ea: /* ALGRK - add logical */
4213 case 0xb9e3: /* SELGR - select 64 bit */
4214 case 0xb9eb: /* SLGRK - subtract logical */
4215 case 0xb9ed: /* MSGRKC - multiply single 64x64 -> 64 */
4216 case 0xb9f0: /* SELR - select 32 bit */
4217 case 0xb9fd: /* MSRKC - multiply single 32x32 -> 32 */
4218 /* 64-bit gpr destination + flags */
4219 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
4220 return -1;
4221 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4222 return -1;
4223 break;
4225 /* 0xb3bb-0xb3c0 undefined */
4226 /* 0xb3c2-0xb3c3 undefined */
4227 /* 0xb3c7 undefined */
4228 /* 0xb3cb-0xb3cc undefined */
4230 case 0xb3cd: /* LGDR - load gr from fpr */
4231 case 0xb3e2: /* CUDTR - convert to unsigned packed */
4232 case 0xb3e3: /* CSDTR - convert to signed packed */
4233 case 0xb3e5: /* EEDTR - extract biased exponent */
4234 case 0xb3e7: /* ESDTR - extract significance */
4235 case 0xb3ed: /* EEXTR - extract biased exponent */
4236 case 0xb3ef: /* ESXTR - extract significance */
4237 case 0xb904: /* LGR - load */
4238 case 0xb906: /* LGBR - load byte */
4239 case 0xb907: /* LGHR - load halfword */
4240 case 0xb90c: /* MSGR - multiply single */
4241 case 0xb90f: /* LRVGR - load reversed */
4242 case 0xb914: /* LGFR - load */
4243 case 0xb916: /* LLGFR - load logical */
4244 case 0xb917: /* LLGTR - load logical thirty one bits */
4245 case 0xb91c: /* MSGFR - multiply single 64<32 */
4246 case 0xb946: /* BCTGR - branch on count */
4247 case 0xb984: /* LLGCR - load logical character */
4248 case 0xb985: /* LLGHR - load logical halfword */
4249 case 0xb9e2: /* LOCGR - load on condition */
4250 /* 64-bit gpr destination */
4251 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
4252 return -1;
4253 break;
4255 /* 0xb3ce-0xb3cf undefined */
4256 /* 0xb3e6 undefined */
4258 case 0xb3ea: /* CUXTR - convert to unsigned packed */
4259 case 0xb3eb: /* CSXTR - convert to signed packed */
4260 case 0xb90d: /* DSGR - divide single */
4261 case 0xb91d: /* DSGFR - divide single */
4262 case 0xb986: /* MLGR - multiply logical */
4263 case 0xb987: /* DLGR - divide logical */
4264 case 0xb9ec: /* MGRK - multiply 64x64 -> 128 */
4265 /* 64-bit gpr pair destination */
4266 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
4267 return -1;
4268 if (s390_record_gpr_g (gdbarch, regcache, inib[6] | 1))
4269 return -1;
4270 break;
4272 /* 0xb3ee undefined */
4273 /* 0xb3f0 undefined */
4274 /* 0xb3f8 undefined */
4276 /* 0xb905 privileged */
4278 /* 0xb90e unsupported: EREGG */
4280 /* 0xb915 undefined */
4282 case 0xb91e: /* KMAC - compute message authentication code [partial] */
4283 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4284 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4285 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4286 tmp &= 0xff;
4287 switch (tmp)
4289 case 0x00: /* KMAC-Query */
4290 if (record_full_arch_list_add_mem (oaddr, 16))
4291 return -1;
4292 break;
4294 case 0x01: /* KMAC-DEA */
4295 case 0x02: /* KMAC-TDEA-128 */
4296 case 0x03: /* KMAC-TDEA-192 */
4297 case 0x09: /* KMAC-Encrypted-DEA */
4298 case 0x0a: /* KMAC-Encrypted-TDEA-128 */
4299 case 0x0b: /* KMAC-Encrypted-TDEA-192 */
4300 if (record_full_arch_list_add_mem (oaddr, 8))
4301 return -1;
4302 break;
4304 case 0x12: /* KMAC-AES-128 */
4305 case 0x13: /* KMAC-AES-192 */
4306 case 0x14: /* KMAC-AES-256 */
4307 case 0x1a: /* KMAC-Encrypted-AES-128 */
4308 case 0x1b: /* KMAC-Encrypted-AES-192 */
4309 case 0x1c: /* KMAC-Encrypted-AES-256 */
4310 if (record_full_arch_list_add_mem (oaddr, 16))
4311 return -1;
4312 break;
4314 default:
4315 gdb_printf (gdb_stdlog, "Warning: Unknown KMAC function %02x at %s.\n",
4316 (int)tmp, paddress (gdbarch, addr));
4317 return -1;
4319 if (tmp != 0)
4321 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4322 return -1;
4323 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4324 return -1;
4326 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4327 return -1;
4328 break;
4330 /* 0xb922-0xb924 undefined */
4331 /* 0xb925 privileged */
4332 /* 0xb928 privileged */
4334 case 0xb929: /* KMA - cipher message with authentication */
4335 case 0xb92a: /* KMF - cipher message with cipher feedback [partial] */
4336 case 0xb92b: /* KMO - cipher message with output feedback [partial] */
4337 case 0xb92f: /* KMC - cipher message with chaining [partial] */
4338 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4339 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4340 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4341 tmp &= 0x7f;
4342 switch (tmp)
4344 case 0x00: /* KM*-Query */
4345 if (record_full_arch_list_add_mem (oaddr, 16))
4346 return -1;
4347 break;
4349 case 0x01: /* KM*-DEA */
4350 case 0x02: /* KM*-TDEA-128 */
4351 case 0x03: /* KM*-TDEA-192 */
4352 case 0x09: /* KM*-Encrypted-DEA */
4353 case 0x0a: /* KM*-Encrypted-TDEA-128 */
4354 case 0x0b: /* KM*-Encrypted-TDEA-192 */
4355 if (record_full_arch_list_add_mem (oaddr, 8))
4356 return -1;
4357 break;
4359 case 0x12: /* KM*-AES-128 */
4360 case 0x13: /* KM*-AES-192 */
4361 case 0x14: /* KM*-AES-256 */
4362 case 0x1a: /* KM*-Encrypted-AES-128 */
4363 case 0x1b: /* KM*-Encrypted-AES-192 */
4364 case 0x1c: /* KM*-Encrypted-AES-256 */
4365 if (record_full_arch_list_add_mem (oaddr, 16))
4366 return -1;
4367 break;
4369 case 0x43: /* KMC-PRNG */
4370 /* Only valid for KMC. */
4371 if (insn[0] == 0xb92f)
4373 if (record_full_arch_list_add_mem (oaddr, 8))
4374 return -1;
4375 break;
4377 /* For other instructions... */
4378 [[fallthrough]];
4379 default:
4380 gdb_printf (gdb_stdlog, "Warning: Unknown KM* function %02x at %s.\n",
4381 (int)tmp, paddress (gdbarch, addr));
4382 return -1;
4384 if (tmp != 0)
4386 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4387 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
4388 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[7] | 1), &tmp);
4389 if (record_full_arch_list_add_mem (oaddr2, tmp))
4390 return -1;
4391 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4392 return -1;
4393 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4394 return -1;
4395 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4396 return -1;
4398 if (tmp != 0 && insn[0] == 0xb929)
4400 if (record_full_arch_list_add_reg (regcache,
4401 S390_R0_REGNUM + inib[4]))
4402 return -1;
4403 if (record_full_arch_list_add_reg (regcache,
4404 S390_R0_REGNUM + (inib[4] | 1)))
4405 return -1;
4407 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4408 return -1;
4409 break;
4411 case 0xb92c: /* PCC - perform cryptographic computation [partial] */
4412 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4413 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4414 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4415 tmp &= 0x7f;
4416 switch (tmp)
4418 case 0x00: /* PCC-Query */
4419 if (record_full_arch_list_add_mem (oaddr, 16))
4420 return -1;
4421 break;
4423 case 0x01: /* PCC-Compute-Last-Block-CMAC-Using-DEA */
4424 case 0x02: /* PCC-Compute-Last-Block-CMAC-Using-TDEA-128 */
4425 case 0x03: /* PCC-Compute-Last-Block-CMAC-Using-TDEA-192 */
4426 case 0x09: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-DEA */
4427 case 0x0a: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-TDEA-128 */
4428 case 0x0b: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-TDEA-192 */
4429 if (record_full_arch_list_add_mem (oaddr + 0x10, 8))
4430 return -1;
4431 break;
4433 case 0x12: /* PCC-Compute-Last-Block-CMAC-Using-AES-128 */
4434 case 0x13: /* PCC-Compute-Last-Block-CMAC-Using-AES-192 */
4435 case 0x14: /* PCC-Compute-Last-Block-CMAC-Using-AES-256 */
4436 case 0x1a: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-AES-128 */
4437 case 0x1b: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-AES-192 */
4438 case 0x1c: /* PCC-Compute-Last-Block-CMAC-Using-Encrypted-AES-256 */
4439 if (record_full_arch_list_add_mem (oaddr + 0x18, 16))
4440 return -1;
4441 break;
4443 case 0x32: /* PCC-Compute-XTS-Parameter-Using-AES-128 */
4444 if (record_full_arch_list_add_mem (oaddr + 0x30, 32))
4445 return -1;
4446 break;
4448 case 0x34: /* PCC-Compute-XTS-Parameter-Using-AES-256 */
4449 if (record_full_arch_list_add_mem (oaddr + 0x40, 32))
4450 return -1;
4451 break;
4453 case 0x3a: /* PCC-Compute-XTS-Parameter-Using-Encrypted-AES-128 */
4454 if (record_full_arch_list_add_mem (oaddr + 0x50, 32))
4455 return -1;
4456 break;
4458 case 0x3c: /* PCC-Compute-XTS-Parameter-Using-Encrypted-AES-256 */
4459 if (record_full_arch_list_add_mem (oaddr + 0x60, 32))
4460 return -1;
4461 break;
4463 default:
4464 gdb_printf (gdb_stdlog, "Warning: Unknown PCC function %02x at %s.\n",
4465 (int)tmp, paddress (gdbarch, addr));
4466 return -1;
4468 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4469 return -1;
4470 break;
4472 case 0xb92d: /* KMCTR - cipher message with counter [partial] */
4473 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4474 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4475 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4476 tmp &= 0x7f;
4477 switch (tmp)
4479 case 0x00: /* KMCTR-Query */
4480 if (record_full_arch_list_add_mem (oaddr, 16))
4481 return -1;
4482 break;
4484 case 0x01: /* KMCTR-DEA */
4485 case 0x02: /* KMCTR-TDEA-128 */
4486 case 0x03: /* KMCTR-TDEA-192 */
4487 case 0x09: /* KMCTR-Encrypted-DEA */
4488 case 0x0a: /* KMCTR-Encrypted-TDEA-128 */
4489 case 0x0b: /* KMCTR-Encrypted-TDEA-192 */
4490 case 0x12: /* KMCTR-AES-128 */
4491 case 0x13: /* KMCTR-AES-192 */
4492 case 0x14: /* KMCTR-AES-256 */
4493 case 0x1a: /* KMCTR-Encrypted-AES-128 */
4494 case 0x1b: /* KMCTR-Encrypted-AES-192 */
4495 case 0x1c: /* KMCTR-Encrypted-AES-256 */
4496 break;
4498 default:
4499 gdb_printf (gdb_stdlog, "Warning: Unknown KMCTR function %02x at %s.\n",
4500 (int)tmp, paddress (gdbarch, addr));
4501 return -1;
4503 if (tmp != 0)
4505 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4506 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
4507 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[7] | 1), &tmp);
4508 if (record_full_arch_list_add_mem (oaddr2, tmp))
4509 return -1;
4510 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4511 return -1;
4512 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4513 return -1;
4514 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4515 return -1;
4516 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[4]))
4517 return -1;
4519 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4520 return -1;
4521 break;
4523 case 0xb92e: /* KM - cipher message [partial] */
4524 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4525 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4526 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4527 tmp &= 0x7f;
4528 switch (tmp)
4530 case 0x00: /* KM-Query */
4531 if (record_full_arch_list_add_mem (oaddr, 16))
4532 return -1;
4533 break;
4535 case 0x01: /* KM-DEA */
4536 case 0x02: /* KM-TDEA-128 */
4537 case 0x03: /* KM-TDEA-192 */
4538 case 0x09: /* KM-Encrypted-DEA */
4539 case 0x0a: /* KM-Encrypted-TDEA-128 */
4540 case 0x0b: /* KM-Encrypted-TDEA-192 */
4541 case 0x12: /* KM-AES-128 */
4542 case 0x13: /* KM-AES-192 */
4543 case 0x14: /* KM-AES-256 */
4544 case 0x1a: /* KM-Encrypted-AES-128 */
4545 case 0x1b: /* KM-Encrypted-AES-192 */
4546 case 0x1c: /* KM-Encrypted-AES-256 */
4547 break;
4549 case 0x32: /* KM-XTS-AES-128 */
4550 if (record_full_arch_list_add_mem (oaddr + 0x10, 16))
4551 return -1;
4552 break;
4554 case 0x34: /* KM-XTS-AES-256 */
4555 if (record_full_arch_list_add_mem (oaddr + 0x20, 16))
4556 return -1;
4557 break;
4559 case 0x3a: /* KM-XTS-Encrypted-AES-128 */
4560 if (record_full_arch_list_add_mem (oaddr + 0x30, 16))
4561 return -1;
4562 break;
4564 case 0x3c: /* KM-XTS-Encrypted-AES-256 */
4565 if (record_full_arch_list_add_mem (oaddr + 0x40, 16))
4566 return -1;
4567 break;
4569 default:
4570 gdb_printf (gdb_stdlog, "Warning: Unknown KM function %02x at %s.\n",
4571 (int)tmp, paddress (gdbarch, addr));
4572 return -1;
4574 if (tmp != 0)
4576 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4577 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
4578 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[7] | 1), &tmp);
4579 if (record_full_arch_list_add_mem (oaddr2, tmp))
4580 return -1;
4581 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4582 return -1;
4583 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4584 return -1;
4585 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4586 return -1;
4588 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4589 return -1;
4590 break;
4592 /* 0xb932-0xb937 undefined */
4594 /* 0xb938 unsupported: SORTL - sort lists */
4595 /* 0xb939 unsupported: DFLTCC - deflate conversion call */
4596 /* 0xb93a unsupported: KDSA - compute dig. signature auth. */
4598 /* 0xb93b undefined */
4600 case 0xb93c: /* PPNO - perform pseudorandom number operation [partial] */
4601 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4602 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4603 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4604 tmp &= 0xff;
4605 switch (tmp)
4607 case 0x00: /* PPNO-Query */
4608 case 0x80: /* PPNO-Query */
4609 if (record_full_arch_list_add_mem (oaddr, 16))
4610 return -1;
4611 break;
4613 case 0x03: /* PPNO-SHA-512-DRNG - generate */
4614 if (record_full_arch_list_add_mem (oaddr, 240))
4615 return -1;
4616 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4617 oaddr2 = s390_record_address_mask (gdbarch, regcache, tmp);
4618 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
4619 if (record_full_arch_list_add_mem (oaddr2, tmp))
4620 return -1;
4621 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4622 return -1;
4623 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4624 return -1;
4625 break;
4627 case 0x83: /* PPNO-SHA-512-DRNG - seed */
4628 if (record_full_arch_list_add_mem (oaddr, 240))
4629 return -1;
4630 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4631 return -1;
4632 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4633 return -1;
4634 break;
4636 default:
4637 gdb_printf (gdb_stdlog, "Warning: Unknown PPNO function %02x at %s.\n",
4638 (int)tmp, paddress (gdbarch, addr));
4639 return -1;
4641 /* DXC may be written */
4642 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
4643 return -1;
4644 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4645 return -1;
4646 break;
4648 /* 0xb93d undefined */
4650 case 0xb93e: /* KIMD - compute intermediate message digest [partial] */
4651 case 0xb93f: /* KLMD - compute last message digest [partial] */
4652 regcache_raw_read_unsigned (regcache, S390_R1_REGNUM, &tmp);
4653 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4654 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
4655 tmp &= 0xff;
4656 switch (tmp)
4658 case 0x00: /* K*MD-Query */
4659 if (record_full_arch_list_add_mem (oaddr, 16))
4660 return -1;
4661 break;
4663 case 0x01: /* K*MD-SHA-1 */
4664 if (record_full_arch_list_add_mem (oaddr, 20))
4665 return -1;
4666 break;
4668 case 0x02: /* K*MD-SHA-256 */
4669 if (record_full_arch_list_add_mem (oaddr, 32))
4670 return -1;
4671 break;
4673 case 0x03: /* K*MD-SHA-512 */
4674 if (record_full_arch_list_add_mem (oaddr, 64))
4675 return -1;
4676 break;
4678 case 0x41: /* KIMD-GHASH */
4679 /* Only valid for KIMD. */
4680 if (insn[0] == 0xb93e)
4682 if (record_full_arch_list_add_mem (oaddr, 16))
4683 return -1;
4684 break;
4686 /* For KLMD... */
4687 [[fallthrough]];
4688 default:
4689 gdb_printf (gdb_stdlog, "Warning: Unknown KMAC function %02x at %s.\n",
4690 (int)tmp, paddress (gdbarch, addr));
4691 return -1;
4693 if (tmp != 0)
4695 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4696 return -1;
4697 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[7] | 1)))
4698 return -1;
4700 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4701 return -1;
4702 break;
4704 /* 0xb940 undefined */
4705 /* 0xb944-0xb945 undefined */
4706 /* 0xb947-0xb948 undefined */
4707 /* 0xb94c-0xb950 undefined */
4708 /* 0xb954-0xb958 undefined */
4709 /* 0xb95c-0xb95f undefined */
4710 /* 0xb962-0xb971 undefined */
4711 /* 0xb974-0xb97f undefined */
4713 case 0xb983: /* FLOGR - find leftmost one */
4714 /* 64-bit gpr pair destination + flags */
4715 if (s390_record_gpr_g (gdbarch, regcache, inib[6]))
4716 return -1;
4717 if (s390_record_gpr_g (gdbarch, regcache, inib[6] | 1))
4718 return -1;
4719 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4720 return -1;
4721 break;
4723 /* 0xb98a privileged */
4724 /* 0xb98b-0xb98c undefined */
4726 case 0xb98d: /* EPSW - extract psw */
4727 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4728 return -1;
4729 if (inib[7])
4730 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4731 return -1;
4732 break;
4734 /* 0xb98e-0xb98f privileged */
4736 case 0xb990: /* TRTT - translate two to two [partial] */
4737 case 0xb991: /* TRTO - translate two to one [partial] */
4738 case 0xb992: /* TROT - translate one to two [partial] */
4739 case 0xb993: /* TROO - translate one to one [partial] */
4740 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[6], &tmp);
4741 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
4742 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[6] | 1), &tmp);
4743 /* tmp is source length, we want destination length. Adjust. */
4744 if (insn[0] == 0xb991)
4745 tmp >>= 1;
4746 if (insn[0] == 0xb992)
4747 tmp <<= 1;
4748 if (record_full_arch_list_add_mem (oaddr, tmp))
4749 return -1;
4750 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4751 return -1;
4752 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4753 return -1;
4754 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4755 return -1;
4756 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4757 return -1;
4758 break;
4760 case 0xb996: /* MLR - multiply logical */
4761 case 0xb997: /* DLR - divide logical */
4762 /* 32-bit gpr pair destination */
4763 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4764 return -1;
4765 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4766 return -1;
4767 break;
4769 /* 0xb99a-0xb9af unsupported, privileged, or undefined */
4770 /* 0xb9b4-0xb9bc undefined */
4772 case 0xb9bd: /* TRTRE - translate and test reverse extended [partial] */
4773 case 0xb9bf: /* TRTE - translate and test extended [partial] */
4774 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[6]))
4775 return -1;
4776 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[6] | 1)))
4777 return -1;
4778 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[7]))
4779 return -1;
4780 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4781 return -1;
4782 break;
4784 /* 0xb9c0-0xb9c7 undefined */
4786 case 0xb9c8: /* AHHHR - add high */
4787 case 0xb9c9: /* SHHHR - subtract high */
4788 case 0xb9ca: /* ALHHHR - add logical high */
4789 case 0xb9cb: /* SLHHHR - subtract logical high */
4790 case 0xb9d8: /* AHHLR - add high */
4791 case 0xb9d9: /* SHHLR - subtract high */
4792 case 0xb9da: /* ALHHLR - add logical high */
4793 case 0xb9db: /* SLHHLR - subtract logical high */
4794 /* 32-bit high gpr destination + flags */
4795 if (s390_record_gpr_h (gdbarch, regcache, inib[6]))
4796 return -1;
4797 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4798 return -1;
4799 break;
4801 /* 0xb9cc undefined */
4802 /* 0xb9ce undefined */
4803 /* 0xb9d0-0xb9d7 undefined */
4804 /* 0xb9dc undefined */
4805 /* 0xb9de undefined */
4807 case 0xb9e0: /* LOCFHR - load high on condition */
4808 /* 32-bit high gpr destination */
4809 if (s390_record_gpr_h (gdbarch, regcache, inib[6]))
4810 return -1;
4811 break;
4813 /* 0xb9e3 undefined */
4814 /* 0xb9e5 undefined */
4815 /* 0xb9ee-0xb9f1 undefined */
4816 /* 0xb9f3 undefined */
4817 /* 0xb9f5 undefined */
4818 /* 0xb9fc undefined */
4819 /* 0xb9fe -0xb9ff undefined */
4821 default:
4822 goto UNKNOWN_OP;
4824 break;
4826 /* 0xb4-0xb5 undefined */
4827 /* 0xb6 privileged: STCTL - store control */
4828 /* 0xb7 privileged: LCTL - load control */
4829 /* 0xb8 undefined */
4831 case 0xba: /* CS - compare and swap */
4832 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4833 if (record_full_arch_list_add_mem (oaddr, 4))
4834 return -1;
4835 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4836 return -1;
4837 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4838 return -1;
4839 break;
4841 case 0xbb: /* CDS - compare double and swap */
4842 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4843 if (record_full_arch_list_add_mem (oaddr, 8))
4844 return -1;
4845 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4846 return -1;
4847 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
4848 return -1;
4849 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4850 return -1;
4851 break;
4853 /* 0xbc undefined */
4855 case 0xbe: /* STCM - store characters under mask */
4856 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
4857 if (record_full_arch_list_add_mem (oaddr, s390_popcnt (inib[3])))
4858 return -1;
4859 break;
4861 case 0xc0:
4862 case 0xc2:
4863 case 0xc4:
4864 case 0xc6:
4865 case 0xcc:
4866 /* RIL-format instruction */
4867 switch (ibyte[0] << 4 | inib[3])
4869 case 0xc00: /* LARL - load address relative long */
4870 case 0xc05: /* BRASL - branch relative and save long */
4871 case 0xc09: /* IILF - insert immediate */
4872 case 0xc21: /* MSFI - multiply single immediate */
4873 case 0xc42: /* LLHRL - load logical halfword relative long */
4874 case 0xc45: /* LHRL - load halfword relative long */
4875 case 0xc4d: /* LRL - load relative long */
4876 /* 32-bit or native gpr destination */
4877 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4878 return -1;
4879 break;
4881 case 0xc01: /* LGFI - load immediate */
4882 case 0xc0e: /* LLIHF - load logical immediate */
4883 case 0xc0f: /* LLILF - load logical immediate */
4884 case 0xc20: /* MSGFI - multiply single immediate */
4885 case 0xc44: /* LGHRL - load halfword relative long */
4886 case 0xc46: /* LLGHRL - load logical halfword relative long */
4887 case 0xc48: /* LGRL - load relative long */
4888 case 0xc4c: /* LGFRL - load relative long */
4889 case 0xc4e: /* LLGFRL - load logical relative long */
4890 /* 64-bit gpr destination */
4891 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
4892 return -1;
4893 break;
4895 /* 0xc02-0xc03 undefined */
4897 case 0xc04: /* BRCL - branch relative on condition long */
4898 case 0xc62: /* PFDRL - prefetch data relative long */
4899 break;
4901 case 0xc06: /* XIHF - xor immediate */
4902 case 0xc0a: /* NIHF - and immediate */
4903 case 0xc0c: /* OIHF - or immediate */
4904 case 0xcc8: /* AIH - add immediate high */
4905 case 0xcca: /* ALSIH - add logical with signed immediate high */
4906 /* 32-bit high gpr destination + flags */
4907 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
4908 return -1;
4909 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4910 return -1;
4911 break;
4913 case 0xc07: /* XILF - xor immediate */
4914 case 0xc0b: /* NILF - and immediate */
4915 case 0xc0d: /* OILF - or immediate */
4916 case 0xc25: /* SLFI - subtract logical immediate */
4917 case 0xc29: /* AFI - add immediate */
4918 case 0xc2b: /* ALFI - add logical immediate */
4919 /* 32-bit gpr destination + flags */
4920 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
4921 return -1;
4922 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4923 return -1;
4924 break;
4926 case 0xc08: /* IIHF - insert immediate */
4927 case 0xcc6: /* BRCTH - branch relative on count high */
4928 case 0xccb: /* ALSIHN - add logical with signed immediate high */
4929 /* 32-bit high gpr destination */
4930 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
4931 return -1;
4932 break;
4934 /* 0xc22-0xc23 undefined */
4936 case 0xc24: /* SLGFI - subtract logical immediate */
4937 case 0xc28: /* AGFI - add immediate */
4938 case 0xc2a: /* ALGFI - add logical immediate */
4939 /* 64-bit gpr destination + flags */
4940 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
4941 return -1;
4942 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4943 return -1;
4944 break;
4946 /* 0xc26-0xc27 undefined */
4948 case 0xc2c: /* CGFI - compare immediate */
4949 case 0xc2d: /* CFI - compare immediate */
4950 case 0xc2e: /* CLGFI - compare logical immediate */
4951 case 0xc2f: /* CLFI - compare logical immediate */
4952 case 0xc64: /* CGHRL - compare halfword relative long */
4953 case 0xc65: /* CHRL - compare halfword relative long */
4954 case 0xc66: /* CLGHRL - compare logical halfword relative long */
4955 case 0xc67: /* CLHRL - compare logical halfword relative long */
4956 case 0xc68: /* CGRL - compare relative long */
4957 case 0xc6a: /* CLGRL - compare logical relative long */
4958 case 0xc6c: /* CGFRL - compare relative long */
4959 case 0xc6d: /* CRL - compare relative long */
4960 case 0xc6e: /* CLGFRL - compare logical relative long */
4961 case 0xc6f: /* CLRL - compare logical relative long */
4962 case 0xccd: /* CIH - compare immediate high */
4963 case 0xccf: /* CLIH - compare logical immediate high */
4964 /* flags only */
4965 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
4966 return -1;
4967 break;
4969 /* 0xc40-0xc41 undefined */
4970 /* 0xc43 undefined */
4972 case 0xc47: /* STHRL - store halfword relative long */
4973 oaddr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
4974 if (record_full_arch_list_add_mem (oaddr, 2))
4975 return -1;
4976 break;
4978 /* 0xc49-0xc4a undefined */
4980 case 0xc4b: /* STGRL - store relative long */
4981 oaddr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
4982 if (record_full_arch_list_add_mem (oaddr, 8))
4983 return -1;
4984 break;
4986 case 0xc4f: /* STRL - store relative long */
4987 oaddr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
4988 if (record_full_arch_list_add_mem (oaddr, 4))
4989 return -1;
4990 break;
4992 case 0xc60: /* EXRL - execute relative long */
4993 if (ex != -1)
4995 gdb_printf (gdb_stdlog, "Warning: Double execute at %s.\n",
4996 paddress (gdbarch, addr));
4997 return -1;
4999 addr = s390_record_calc_rl (gdbarch, regcache, addr, insn[1], insn[2]);
5000 if (inib[2])
5002 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
5003 ex = tmp & 0xff;
5005 else
5007 ex = 0;
5009 goto ex;
5011 /* 0xc61 undefined */
5012 /* 0xc63 undefined */
5013 /* 0xc69 undefined */
5014 /* 0xc6b undefined */
5015 /* 0xcc0-0xcc5 undefined */
5016 /* 0xcc7 undefined */
5017 /* 0xcc9 undefined */
5018 /* 0xccc undefined */
5019 /* 0xcce undefined */
5021 default:
5022 goto UNKNOWN_OP;
5024 break;
5026 /* 0xc1 undefined */
5027 /* 0xc3 undefined */
5029 case 0xc5: /* BPRP - branch prediction relative preload */
5030 case 0xc7: /* BPP - branch prediction preload */
5031 /* no visible effect */
5032 break;
5034 case 0xc8:
5035 /* SSF-format instruction */
5036 switch (ibyte[0] << 4 | inib[3])
5038 /* 0xc80 unsupported */
5040 case 0xc81: /* ECTG - extract cpu time */
5041 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5042 return -1;
5043 if (s390_record_gpr_g (gdbarch, regcache, 0))
5044 return -1;
5045 if (s390_record_gpr_g (gdbarch, regcache, 1))
5046 return -1;
5047 break;
5049 case 0xc82: /* CSST - compare and swap and store */
5051 uint8_t fc, sc;
5052 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
5053 fc = tmp & 0xff;
5054 sc = tmp >> 8 & 0xff;
5056 /* First and third operands. */
5057 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5058 switch (fc)
5060 case 0x00: /* 32-bit */
5061 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5062 return -1;
5063 if (record_full_arch_list_add_mem (oaddr, 4))
5064 return -1;
5065 break;
5067 case 0x01: /* 64-bit */
5068 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5069 return -1;
5070 if (record_full_arch_list_add_mem (oaddr, 8))
5071 return -1;
5072 break;
5074 case 0x02: /* 128-bit */
5075 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5076 return -1;
5077 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
5078 return -1;
5079 if (record_full_arch_list_add_mem (oaddr, 16))
5080 return -1;
5081 break;
5083 default:
5084 gdb_printf (gdb_stdlog, "Warning: Unknown CSST FC %02x at %s.\n",
5085 fc, paddress (gdbarch, addr));
5086 return -1;
5089 /* Second operand. */
5090 oaddr2 = s390_record_calc_disp (gdbarch, regcache, 0, insn[2], 0);
5091 if (sc > 4)
5093 gdb_printf (gdb_stdlog, "Warning: Unknown CSST FC %02x at %s.\n",
5094 sc, paddress (gdbarch, addr));
5095 return -1;
5098 if (record_full_arch_list_add_mem (oaddr2, 1 << sc))
5099 return -1;
5101 /* Flags. */
5102 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5103 return -1;
5105 break;
5107 /* 0xc83 undefined */
5109 case 0xc84: /* LPD - load pair disjoint */
5110 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5111 return -1;
5112 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
5113 return -1;
5114 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5115 return -1;
5116 break;
5118 case 0xc85: /* LPDG - load pair disjoint */
5119 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5120 return -1;
5121 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
5122 return -1;
5123 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5124 return -1;
5125 break;
5127 /* 0xc86-0xc8f undefined */
5129 default:
5130 goto UNKNOWN_OP;
5132 break;
5134 /* 0xc9-0xcb undefined */
5135 /* 0xcd-0xcf undefined */
5137 case 0xd0: /* TRTR - translate and test reversed */
5138 case 0xdd: /* TRT - translate and test */
5139 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
5140 return -1;
5141 if (record_full_arch_list_add_reg (regcache, S390_R2_REGNUM))
5142 return -1;
5143 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5144 return -1;
5145 break;
5147 case 0xd1: /* MVN - move numbers */
5148 case 0xd2: /* MVC - move */
5149 case 0xd3: /* MVZ - move zones */
5150 case 0xdc: /* TR - translate */
5151 case 0xe8: /* MVCIN - move inverse */
5152 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5153 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5154 return -1;
5155 break;
5157 case 0xd4: /* NC - and */
5158 case 0xd6: /* OC - or*/
5159 case 0xd7: /* XC - xor */
5160 case 0xe2: /* UNPKU - unpack unicode */
5161 case 0xea: /* UNPKA - unpack ASCII */
5162 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5163 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5164 return -1;
5165 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5166 return -1;
5167 break;
5169 case 0xde: /* ED - edit */
5170 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5171 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5172 return -1;
5173 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5174 return -1;
5175 /* DXC may be written */
5176 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5177 return -1;
5178 break;
5180 case 0xdf: /* EDMK - edit and mark */
5181 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5182 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
5183 return -1;
5184 if (record_full_arch_list_add_reg (regcache, S390_R1_REGNUM))
5185 return -1;
5186 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5187 return -1;
5188 /* DXC may be written */
5189 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5190 return -1;
5191 break;
5193 /* 0xd8 undefined */
5194 /* 0xd9 unsupported: MVCK - move with key */
5195 /* 0xda unsupported: MVCP - move to primary */
5196 /* 0xdb unsupported: MVCS - move to secondary */
5197 /* 0xe0 undefined */
5199 case 0xe1: /* PKU - pack unicode */
5200 case 0xe9: /* PKA - pack ASCII */
5201 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5202 if (record_full_arch_list_add_mem (oaddr, 16))
5203 return -1;
5204 break;
5206 case 0xe3:
5207 case 0xe6:
5208 case 0xe7:
5209 case 0xeb:
5210 case 0xed:
5211 /* RXY/RXE/RXF/RSL/RSY/SIY/V*-format instruction */
5212 switch (ibyte[0] << 8 | ibyte[5])
5214 /* 0xe300-0xe301 undefined */
5216 case 0xe302: /* LTG - load and test */
5217 case 0xe308: /* AG - add */
5218 case 0xe309: /* SG - subtract */
5219 case 0xe30a: /* ALG - add logical */
5220 case 0xe30b: /* SLG - subtract logical */
5221 case 0xe318: /* AGF - add */
5222 case 0xe319: /* SGF - subtract */
5223 case 0xe31a: /* ALGF - add logical */
5224 case 0xe31b: /* SLGF - subtract logical */
5225 case 0xe332: /* LTGF - load and test */
5226 case 0xe380: /* NG - and */
5227 case 0xe381: /* OG - or */
5228 case 0xe382: /* XG - xor */
5229 case 0xe388: /* ALCG - add logical with carry */
5230 case 0xe389: /* SLBG - subtract logical with borrow */
5231 case 0xeb0a: /* SRAG - shift right single */
5232 case 0xeb0b: /* SLAG - shift left single */
5233 /* 64-bit gpr destination + flags */
5234 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5235 return -1;
5236 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5237 return -1;
5238 break;
5240 /* 0xe303 privileged */
5242 case 0xe304: /* LG - load */
5243 case 0xe30c: /* MSG - multiply single */
5244 case 0xe30f: /* LRVG - load reversed */
5245 case 0xe314: /* LGF - load */
5246 case 0xe315: /* LGH - load halfword */
5247 case 0xe316: /* LLGF - load logical */
5248 case 0xe317: /* LLGT - load logical thirty one bits */
5249 case 0xe31c: /* MSGF - multiply single */
5250 case 0xe32a: /* LZRG - load and zero rightmost byte */
5251 case 0xe33a: /* LLZRGF - load logical and zero rightmost byte */
5252 case 0xe33c: /* MGH - multiply halfword 64x16mem -> 64 */
5253 case 0xe346: /* BCTG - branch on count */
5254 case 0xe377: /* LGB - load byte */
5255 case 0xe390: /* LLGC - load logical character */
5256 case 0xe391: /* LLGH - load logical halfword */
5257 case 0xeb0c: /* SRLG - shift right single logical */
5258 case 0xeb0d: /* SLLG - shift left single logical */
5259 case 0xeb1c: /* RLLG - rotate left single logical */
5260 case 0xeb44: /* BXHG - branch on index high */
5261 case 0xeb45: /* BXLEG - branch on index low or equal */
5262 case 0xeb4c: /* ECAG - extract cpu attribute */
5263 case 0xebe2: /* LOCG - load on condition */
5264 /* 64-bit gpr destination */
5265 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5266 return -1;
5267 break;
5269 /* 0xe305 undefined */
5271 case 0xe306: /* CVBY - convert to binary */
5272 /* 32-bit or native gpr destination + FPC (DXC write) */
5273 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5274 return -1;
5275 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5276 return -1;
5277 break;
5279 /* 0xe307 undefined */
5281 case 0xe30d: /* DSG - divide single */
5282 case 0xe31d: /* DSGF - divide single */
5283 case 0xe384: /* MG - multiply 64x64mem -> 128 */
5284 case 0xe386: /* MLG - multiply logical */
5285 case 0xe387: /* DLG - divide logical */
5286 case 0xe38f: /* LPQ - load pair from quadword */
5287 /* 64-bit gpr pair destination */
5288 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5289 return -1;
5290 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
5291 return -1;
5292 break;
5294 case 0xe30e: /* CVBG - convert to binary */
5295 /* 64-bit gpr destination + FPC (DXC write) */
5296 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5297 return -1;
5298 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5299 return -1;
5300 break;
5302 /* 0xe310-0xe311 undefined */
5304 case 0xe312: /* LT - load and test */
5305 case 0xe338: /* AGH - add halfword to 64 bit value */
5306 case 0xe339: /* SGH - subtract halfword from 64 bit value */
5307 case 0xe353: /* MSC - multiply single 32x32mem -> 32 */
5308 case 0xe354: /* NY - and */
5309 case 0xe356: /* OY - or */
5310 case 0xe357: /* XY - xor */
5311 case 0xe35a: /* AY - add */
5312 case 0xe35b: /* SY - subtract */
5313 case 0xe35e: /* ALY - add logical */
5314 case 0xe35f: /* SLY - subtract logical */
5315 case 0xe37a: /* AHY - add halfword */
5316 case 0xe37b: /* SHY - subtract halfword */
5317 case 0xe383: /* MSGC - multiply single 64x64mem -> 64 */
5318 case 0xe398: /* ALC - add logical with carry */
5319 case 0xe399: /* SLB - subtract logical with borrow */
5320 case 0xe727: /* LCBB - load count to block boundary */
5321 case 0xeb81: /* ICMY - insert characters under mask */
5322 case 0xebdc: /* SRAK - shift left single */
5323 case 0xebdd: /* SLAK - shift left single */
5324 /* 32/64-bit gpr destination + flags */
5325 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5326 return -1;
5327 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5328 return -1;
5329 break;
5331 /* 0xe313 privileged */
5333 case 0xe31e: /* LRV - load reversed */
5334 case 0xe31f: /* LRVH - load reversed */
5335 case 0xe33b: /* LZRF - load and zero rightmost byte */
5336 case 0xe351: /* MSY - multiply single */
5337 case 0xe358: /* LY - load */
5338 case 0xe371: /* LAY - load address */
5339 case 0xe373: /* ICY - insert character */
5340 case 0xe376: /* LB - load byte */
5341 case 0xe378: /* LHY - load */
5342 case 0xe37c: /* MHY - multiply halfword */
5343 case 0xe394: /* LLC - load logical character */
5344 case 0xe395: /* LLH - load logical halfword */
5345 case 0xeb1d: /* RLL - rotate left single logical */
5346 case 0xebde: /* SRLK - shift left single logical */
5347 case 0xebdf: /* SLLK - shift left single logical */
5348 case 0xebf2: /* LOC - load on condition */
5349 /* 32-bit or native gpr destination */
5350 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5351 return -1;
5352 break;
5354 case 0xe320: /* CG - compare */
5355 case 0xe321: /* CLG - compare logical */
5356 case 0xe330: /* CGF - compare */
5357 case 0xe331: /* CLGF - compare logical */
5358 case 0xe334: /* CGH - compare halfword */
5359 case 0xe355: /* CLY - compare logical */
5360 case 0xe359: /* CY - compare */
5361 case 0xe379: /* CHY - compare halfword */
5362 case 0xe3cd: /* CHF - compare high */
5363 case 0xe3cf: /* CLHF - compare logical high */
5364 case 0xeb20: /* CLMH - compare logical under mask high */
5365 case 0xeb21: /* CLMY - compare logical under mask */
5366 case 0xeb51: /* TMY - test under mask */
5367 case 0xeb55: /* CLIY - compare logical */
5368 case 0xebc0: /* TP - test decimal */
5369 case 0xed10: /* TCEB - test data class */
5370 case 0xed11: /* TCDB - test data class */
5371 case 0xed12: /* TCXB - test data class */
5372 case 0xed50: /* TDCET - test data class */
5373 case 0xed51: /* TDGET - test data group */
5374 case 0xed54: /* TDCDT - test data class */
5375 case 0xed55: /* TDGDT - test data group */
5376 case 0xed58: /* TDCXT - test data class */
5377 case 0xed59: /* TDGXT - test data group */
5378 /* flags only */
5379 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5380 return -1;
5381 break;
5383 /* 0xe322-0xe323 undefined */
5385 case 0xe324: /* STG - store */
5386 case 0xe325: /* NTSTG - nontransactional store */
5387 case 0xe326: /* CVDY - convert to decimal */
5388 case 0xe32f: /* STRVG - store reversed */
5389 case 0xed67: /* STDY - store */
5390 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
5391 if (record_full_arch_list_add_mem (oaddr, 8))
5392 return -1;
5393 break;
5395 /* 0xe327-0xe329 undefined */
5396 /* 0xe32b-0xe32d undefined */
5398 case 0xe32e: /* CVDG - convert to decimal */
5399 case 0xe38e: /* STPQ - store pair to quadword */
5400 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
5401 if (record_full_arch_list_add_mem (oaddr, 16))
5402 return -1;
5403 break;
5405 /* 0xe333 undefined */
5406 /* 0xe335 undefined */
5408 case 0xe336: /* PFD - prefetch data */
5409 break;
5411 /* 0xe337 undefined */
5412 /* 0xe33c-0xe33d undefined */
5414 case 0xe33e: /* STRV - store reversed */
5415 case 0xe350: /* STY - store */
5416 case 0xe3cb: /* STFH - store high */
5417 case 0xed66: /* STEY - store */
5418 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
5419 if (record_full_arch_list_add_mem (oaddr, 4))
5420 return -1;
5421 break;
5423 case 0xe33f: /* STRVH - store reversed */
5424 case 0xe370: /* STHY - store halfword */
5425 case 0xe3c7: /* STHH - store halfword high */
5426 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
5427 if (record_full_arch_list_add_mem (oaddr, 2))
5428 return -1;
5429 break;
5431 /* 0xe340-0xe345 undefined */
5433 case 0xe347: /* BIC - branch indirect on condition */
5434 break;
5436 /* 0xe348-0xe34f undefined */
5437 /* 0xe352 undefined */
5439 case 0xe35c: /* MFY - multiply */
5440 case 0xe396: /* ML - multiply logical */
5441 case 0xe397: /* DL - divide logical */
5442 /* 32-bit gpr pair destination */
5443 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5444 return -1;
5445 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
5446 return -1;
5447 break;
5449 /* 0xe35d undefined */
5450 /* 0xe360-0xe36f undefined */
5452 case 0xe372: /* STCY - store character */
5453 case 0xe3c3: /* STCH - store character high */
5454 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], ibyte[4]);
5455 if (record_full_arch_list_add_mem (oaddr, 1))
5456 return -1;
5457 break;
5459 /* 0xe374 undefined */
5461 case 0xe375: /* LAEY - load address extended */
5462 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5463 return -1;
5464 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[2]))
5465 return -1;
5466 break;
5468 /* 0xe37d-0xe37f undefined */
5470 case 0xe385: /* LGAT - load and trap */
5471 case 0xe39c: /* LLGTAT - load logical thirty one bits and trap */
5472 case 0xe39d: /* LLGFAT - load logical and trap */
5473 case 0xe650: /* VCVB - vector convert to binary 32 bit*/
5474 case 0xe652: /* VCVBG - vector convert to binary 64 bit*/
5475 case 0xe721: /* VLGV - vector load gr from vr element */
5476 /* 64-bit gpr destination + fpc for possible DXC write */
5477 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5478 return -1;
5479 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5480 return -1;
5481 break;
5483 /* 0xe38a-0xe38d undefined */
5484 /* 0xe392-0xe393 undefined */
5485 /* 0xe39a-0xe39b undefined */
5486 /* 0xe39e undefined */
5488 case 0xe39f: /* LAT - load and trap */
5489 /* 32-bit gpr destination + fpc for possible DXC write */
5490 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5491 return -1;
5492 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5493 return -1;
5494 break;
5496 /* 0xe3a0-0xe3bf undefined */
5498 case 0xe3c0: /* LBH - load byte high */
5499 case 0xe3c2: /* LLCH - load logical character high */
5500 case 0xe3c4: /* LHH - load halfword high */
5501 case 0xe3c6: /* LLHH - load logical halfword high */
5502 case 0xe3ca: /* LFH - load high */
5503 case 0xebe0: /* LOCFH - load high on condition */
5504 /* 32-bit high gpr destination */
5505 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
5506 return -1;
5507 break;
5509 /* 0xe3c1 undefined */
5510 /* 0xe3c5 undefined */
5512 case 0xe3c8: /* LFHAT - load high and trap */
5513 /* 32-bit high gpr destination + fpc for possible DXC write */
5514 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
5515 return -1;
5516 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5517 return -1;
5518 break;
5520 /* 0xe3c9 undefined */
5521 /* 0xe3cc undefined */
5522 /* 0xe3ce undefined */
5523 /* 0xe3d0-0xe3ff undefined */
5525 case 0xe601: /* VLEBRH - vector load byte reversed element */
5526 case 0xe602: /* VLEBRG - vector load byte reversed element */
5527 case 0xe603: /* VLEBRF - vector load byte reversed element */
5528 case 0xe604: /* VLLEBRZ - vector load byte rev. el. and zero */
5529 case 0xe605: /* VLBRREP - vector load byte rev. el. and replicate */
5530 case 0xe606: /* VLBR - vector load byte reversed elements */
5531 case 0xe607: /* VLER - vector load elements reversed */
5532 case 0xe634: /* VPKZ - vector pack zoned */
5533 case 0xe635: /* VLRL - vector load rightmost with immed. length */
5534 case 0xe637: /* VLRLR - vector load rightmost with length */
5535 case 0xe649: /* VLIP - vector load immediate decimal */
5536 case 0xe656: /* VCLFNH - vector fp convert and lengthen from NNP high */
5537 case 0xe65e: /* VCLFNL - vector fp convert and lengthen from NNP low */
5538 case 0xe655: /* VCNF - vector fp convert to NNP */
5539 case 0xe65d: /* VCFN - vector fp convert from NNP */
5540 case 0xe674: /* VSCHP - decimal scale and convert to HFP */
5541 case 0xe675: /* VCRNF - vector fp convert and round to NNP */
5542 case 0xe67c: /* VSCSHP - decimal scale and convert and split to HFP */
5543 case 0xe67d: /* VCSPH - vector convert HFP to scaled decimal */
5544 case 0xe700: /* VLEB - vector load element */
5545 case 0xe701: /* VLEH - vector load element */
5546 case 0xe702: /* VLEG - vector load element */
5547 case 0xe703: /* VLEF - vector load element */
5548 case 0xe704: /* VLLEZ - vector load logical element and zero */
5549 case 0xe705: /* VLREP - vector load and replicate */
5550 case 0xe706: /* VL - vector load */
5551 case 0xe707: /* VLBB - vector load to block boundary */
5552 case 0xe712: /* VGEG - vector gather element */
5553 case 0xe713: /* VGEF - vector gather element */
5554 case 0xe722: /* VLVG - vector load vr element from gr */
5555 case 0xe730: /* VESL - vector element shift left */
5556 case 0xe733: /* VERLL - vector element rotate left logical */
5557 case 0xe737: /* VLL - vector load with length */
5558 case 0xe738: /* VESRL - vector element shift right logical */
5559 case 0xe73a: /* VESRA - vector element shift right arithmetic */
5560 case 0xe740: /* VLEIB - vector load element immediate */
5561 case 0xe741: /* VLEIH - vector load element immediate */
5562 case 0xe742: /* VLEIG - vector load element immediate */
5563 case 0xe743: /* VLEIF - vector load element immediate */
5564 case 0xe744: /* VGBM - vector generate byte mask */
5565 case 0xe745: /* VREPI - vector replicate immediate */
5566 case 0xe746: /* VGM - vector generate mask */
5567 case 0xe74d: /* VREP - vector replicate */
5568 case 0xe750: /* VPOPCT - vector population count */
5569 case 0xe752: /* VCTZ - vector count trailing zeros */
5570 case 0xe753: /* VCLZ - vector count leading zeros */
5571 case 0xe756: /* VLR - vector load */
5572 case 0xe75f: /* VSEG -vector sign extend to doubleword */
5573 case 0xe760: /* VMRL - vector merge low */
5574 case 0xe761: /* VMRH - vector merge high */
5575 case 0xe762: /* VLVGP - vector load vr from grs disjoint */
5576 case 0xe764: /* VSUM - vector sum across word */
5577 case 0xe765: /* VSUMG - vector sum across doubleword */
5578 case 0xe766: /* VCKSM - vector checksum */
5579 case 0xe767: /* VSUMQ - vector sum across quadword */
5580 case 0xe768: /* VN - vector and */
5581 case 0xe769: /* VNC - vector and with complement */
5582 case 0xe76a: /* VO - vector or */
5583 case 0xe76b: /* VNO - vector nor */
5584 case 0xe76c: /* VNX - vector not exclusive or */
5585 case 0xe76d: /* VX - vector xor */
5586 case 0xe76e: /* VNN - vector nand */
5587 case 0xe76f: /* VOC - vector or with complement */
5588 case 0xe770: /* VESLV - vector element shift left */
5589 case 0xe772: /* VERIM - vector element rotate and insert under mask */
5590 case 0xe773: /* VERLLV - vector element rotate left logical */
5591 case 0xe774: /* VSL - vector shift left */
5592 case 0xe775: /* VSLB - vector shift left by byte */
5593 case 0xe777: /* VSLDB - vector shift left double by byte */
5594 case 0xe778: /* VESRLV - vector element shift right logical */
5595 case 0xe77a: /* VESRAV - vector element shift right arithmetic */
5596 case 0xe77c: /* VSRL - vector shift right logical */
5597 case 0xe77d: /* VSRLB - vector shift right logical by byte */
5598 case 0xe77e: /* VSRA - vector shift right arithmetic */
5599 case 0xe77f: /* VSRAB - vector shift right arithmetic by byte */
5600 case 0xe784: /* VPDI - vector permute doubleword immediate */
5601 case 0xe785: /* VBPERM - vector bit permute */
5602 case 0xe786: /* VSLD - vector shift left double by bit */
5603 case 0xe787: /* VSRD - vector shift right double by bit */
5604 case 0xe78b: /* VSTRS - vector string search */
5605 case 0xe78c: /* VPERM - vector permute */
5606 case 0xe78d: /* VSEL - vector select */
5607 case 0xe78e: /* VFMS - vector fp multiply and subtract */
5608 case 0xe78f: /* VFMA - vector fp multiply and add */
5609 case 0xe794: /* VPK - vector pack */
5610 case 0xe79e: /* VFNMS - vector fp negative multiply and subtract */
5611 case 0xe79f: /* VFNMA - vector fp negative multiply and add */
5612 case 0xe7a1: /* VMLH - vector multiply logical high */
5613 case 0xe7a2: /* VML - vector multiply low */
5614 case 0xe7a3: /* VMH - vector multiply high */
5615 case 0xe7a4: /* VMLE - vector multiply logical even */
5616 case 0xe7a5: /* VMLO - vector multiply logical odd */
5617 case 0xe7a6: /* VME - vector multiply even */
5618 case 0xe7a7: /* VMO - vector multiply odd */
5619 case 0xe7a9: /* VMALH - vector multiply and add logical high */
5620 case 0xe7aa: /* VMAL - vector multiply and add low */
5621 case 0xe7ab: /* VMAH - vector multiply and add high */
5622 case 0xe7ac: /* VMALE - vector multiply and add logical even */
5623 case 0xe7ad: /* VMALO - vector multiply and add logical odd */
5624 case 0xe7ae: /* VMAE - vector multiply and add even */
5625 case 0xe7af: /* VMAO - vector multiply and add odd */
5626 case 0xe7b4: /* VGFM - vector Galois field multiply sum */
5627 case 0xe7b8: /* VMSL - vector multiply sum logical */
5628 case 0xe7b9: /* VACCC - vector add with carry compute carry */
5629 case 0xe7bb: /* VAC - vector add with carry */
5630 case 0xe7bc: /* VGFMA - vector Galois field multiply sum and accumulate */
5631 case 0xe7bd: /* VSBCBI - vector subtract with borrow compute borrow indication */
5632 case 0xe7bf: /* VSBI - vector subtract with borrow indication */
5633 case 0xe7c0: /* VCLFP - vector fp convert to logical */
5634 case 0xe7c1: /* VCFPL - vector fp convert from logical */
5635 case 0xe7c2: /* VCSFP - vector fp convert to fixed */
5636 case 0xe7c3: /* VCFPS - vector fp convert from fixed */
5637 case 0xe7c4: /* VLDE/VFLL - vector fp load lengthened */
5638 case 0xe7c5: /* VLED/VFLR - vector fp load rounded */
5639 case 0xe7c7: /* VFI - vector load fp integer */
5640 case 0xe7cc: /* VFPSO - vector fp perform sign operation */
5641 case 0xe7ce: /* VFSQ - vector fp square root */
5642 case 0xe7d4: /* VUPLL - vector unpack logical low */
5643 case 0xe7d6: /* VUPL - vector unpack low */
5644 case 0xe7d5: /* VUPLH - vector unpack logical high */
5645 case 0xe7d7: /* VUPH - vector unpack high */
5646 case 0xe7de: /* VLC - vector load complement */
5647 case 0xe7df: /* VLP - vector load positive */
5648 case 0xe7e2: /* VFA - vector fp subtract */
5649 case 0xe7e3: /* VFA - vector fp add */
5650 case 0xe7e5: /* VFD - vector fp divide */
5651 case 0xe7e7: /* VFM - vector fp multiply */
5652 case 0xe7ee: /* VFMIN - vector fp minimum */
5653 case 0xe7ef: /* VFMAX - vector fp maximum */
5654 case 0xe7f0: /* VAVGL - vector average logical */
5655 case 0xe7f1: /* VACC - vector add and compute carry */
5656 case 0xe7f2: /* VAVG - vector average */
5657 case 0xe7f3: /* VA - vector add */
5658 case 0xe7f5: /* VSCBI - vector subtract compute borrow indication */
5659 case 0xe7f7: /* VS - vector subtract */
5660 case 0xe7fc: /* VMNL - vector minimum logical */
5661 case 0xe7fd: /* VMXL - vector maximum logical */
5662 case 0xe7fe: /* VMN - vector minimum */
5663 case 0xe7ff: /* VMX - vector maximum */
5664 /* vector destination + FPC */
5665 if (s390_record_vr (gdbarch, regcache, ivec[0]))
5666 return -1;
5667 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5668 return -1;
5669 break;
5671 case 0xe63d: /* VSTRL - vector store rightmost with immed. length */
5672 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5673 if (record_full_arch_list_add_mem (oaddr, inib[3] + 1))
5674 return -1;
5675 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5676 return -1;
5677 break;
5679 case 0xe708: /* VSTEB - vector store element */
5680 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
5681 if (record_full_arch_list_add_mem (oaddr, 1))
5682 return -1;
5683 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5684 return -1;
5685 break;
5687 case 0xe609: /* VSTEBRH - vector store byte reversed element */
5688 case 0xe709: /* VSTEH - vector store element */
5689 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
5690 if (record_full_arch_list_add_mem (oaddr, 2))
5691 return -1;
5692 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5693 return -1;
5694 break;
5696 case 0xe60a: /* VSTEBRG - vector store byte reversed element */
5697 case 0xe70a: /* VSTEG - vector store element */
5698 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
5699 if (record_full_arch_list_add_mem (oaddr, 8))
5700 return -1;
5701 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5702 return -1;
5703 break;
5705 case 0xe60b: /* VSTEBRF - vector store byte reversed element */
5706 case 0xe70b: /* VSTEF - vector store element */
5707 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
5708 if (record_full_arch_list_add_mem (oaddr, 4))
5709 return -1;
5710 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5711 return -1;
5712 break;
5714 /* 0xe70c-0xe70d undefined */
5716 case 0xe60e: /* VSTBR - vector store byte reversed elements */
5717 case 0xe60f: /* VSTER - vector store elements reversed */
5718 case 0xe70e: /* VST - vector store */
5719 oaddr = s390_record_calc_disp (gdbarch, regcache, inib[3], insn[1], 0);
5720 if (record_full_arch_list_add_mem (oaddr, 16))
5721 return -1;
5722 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5723 return -1;
5724 break;
5726 /* 0xe70f-0xe711 undefined */
5727 /* 0xe714-0xe719 undefined */
5729 case 0xe71a: /* VSCEG - vector scatter element */
5730 if (s390_record_calc_disp_vsce (gdbarch, regcache, ivec[1], inib[8], 8, insn[1], 0, &oaddr))
5731 return -1;
5732 if (record_full_arch_list_add_mem (oaddr, 8))
5733 return -1;
5734 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5735 return -1;
5736 break;
5738 case 0xe71b: /* VSCEF - vector scatter element */
5739 if (s390_record_calc_disp_vsce (gdbarch, regcache, ivec[1], inib[8], 4, insn[1], 0, &oaddr))
5740 return -1;
5741 if (record_full_arch_list_add_mem (oaddr, 4))
5742 return -1;
5743 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5744 return -1;
5745 break;
5747 /* 0xe71c-0xe720 undefined */
5748 /* 0xe723-0xe726 undefined */
5749 /* 0xe728-0xe72f undefined */
5750 /* 0xe731-0xe732 undefined */
5751 /* 0xe734-0xe735 undefined */
5753 case 0xe736: /* VLM - vector load multiple */
5754 for (i = ivec[0]; i != ivec[1]; i++, i &= 0x1f)
5755 if (s390_record_vr (gdbarch, regcache, i))
5756 return -1;
5757 if (s390_record_vr (gdbarch, regcache, ivec[1]))
5758 return -1;
5759 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5760 return -1;
5761 break;
5763 /* 0xe739 undefined */
5764 /* 0xe73b-0xe73d undefined */
5766 case 0xe73e: /* VSTM - vector store multiple */
5767 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5768 if (ivec[0] <= ivec[1])
5769 n = ivec[1] - ivec[0] + 1;
5770 else
5771 n = ivec[1] + 0x20 - ivec[0] + 1;
5772 if (record_full_arch_list_add_mem (oaddr, n * 16))
5773 return -1;
5774 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5775 return -1;
5776 break;
5778 case 0xe63c: /* VUPKZ - vector unpack zoned */
5779 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5780 if (record_full_arch_list_add_mem (oaddr, (ibyte[1] + 1) & 31))
5781 return -1;
5782 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5783 return -1;
5784 break;
5786 case 0xe63f: /* VSTRLR - vector store rightmost with length */
5787 case 0xe73f: /* VSTL - vector store with length */
5788 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
5789 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[3], &tmp);
5790 tmp &= 0xffffffffu;
5791 if (tmp > 15)
5792 tmp = 15;
5793 if (record_full_arch_list_add_mem (oaddr, tmp + 1))
5794 return -1;
5795 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5796 return -1;
5797 break;
5799 /* 0xe747-0xe749 undefined */
5801 case 0xe651: /* VCLZDP - vector count leading zero digits */
5802 case 0xe654: /* VUPKZH - vector unpack zoned high */
5803 case 0xe658: /* VCVD - vector convert to decimal 32 bit */
5804 case 0xe659: /* VSRP - vector shift and round decimal */
5805 case 0xe65a: /* VCVDG - vector convert to decimal 64 bit*/
5806 case 0xe65b: /* VPSOP - vector perform sign operation decimal */
5807 case 0xe65c: /* VUPKZL - vector unpack zoned low */
5808 case 0xe670: /* VPKZR - vector pack zoned register */
5809 case 0xe671: /* VAP - vector add decimal */
5810 case 0xe672: /* VSRPR - vector shift and round decimal register */
5811 case 0xe673: /* VSP - vector subtract decimal */
5812 case 0xe678: /* VMP - vector multiply decimal */
5813 case 0xe679: /* VMSP - vector multiply decimal */
5814 case 0xe67a: /* VDP - vector divide decimal */
5815 case 0xe67b: /* VRP - vector remainder decimal */
5816 case 0xe67e: /* VSDP - vector shift and divide decimal */
5817 case 0xe74a: /* VFTCI - vector fp test data class immediate */
5818 case 0xe75c: /* VISTR - vector isolate string */
5819 case 0xe780: /* VFEE - vector find element equal */
5820 case 0xe781: /* VFENE - vector find element not equal */
5821 case 0xe782: /* VFA - vector find any element equal */
5822 case 0xe78a: /* VSTRC - vector string range compare */
5823 case 0xe795: /* VPKLS - vector pack logical saturate */
5824 case 0xe797: /* VPKS - vector pack saturate */
5825 case 0xe7e8: /* VFCE - vector fp compare equal */
5826 case 0xe7ea: /* VFCHE - vector fp compare high or equal */
5827 case 0xe7eb: /* VFCH - vector fp compare high */
5828 case 0xe7f8: /* VCEQ - vector compare equal */
5829 case 0xe7f9: /* VCHL - vector compare high logical */
5830 case 0xe7fb: /* VCH - vector compare high */
5831 /* vector destination + flags + FPC */
5832 if (s390_record_vr (gdbarch, regcache, ivec[0]))
5833 return -1;
5834 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5835 return -1;
5836 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5837 return -1;
5838 break;
5840 case 0xe65f: /* VTP - vector test decimal */
5841 /* flags + FPC */
5842 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5843 return -1;
5844 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5845 return -1;
5846 break;
5848 /* 0xe74b-0xe74c undefined */
5849 /* 0xe74e-0xe74f undefined */
5850 /* 0xe751 undefined */
5851 /* 0xe754-0xe755 undefined */
5852 /* 0xe757-0xe75b undefined */
5853 /* 0xe75d-0xe75e undefined */
5854 /* 0xe763 undefined */
5855 /* 0xe771 undefined */
5856 /* 0xe776 undefined */
5857 /* 0xe779 undefined */
5858 /* 0xe77b undefined */
5859 /* 0xe783 undefined */
5860 /* 0xe786-0xe789 undefined */
5861 /* 0xe78b undefined */
5862 /* 0xe790-0xe793 undefined */
5863 /* 0xe796 undefined */
5864 /* 0xe798-0xe79d undefined */
5865 /* 0xe7a0 undefined */
5866 /* 0xe7a8 undefined */
5867 /* 0xe7b0-0xe7b3 undefined */
5868 /* 0xe7b5-0xe7b7 undefined */
5869 /* 0xe7ba undefined */
5870 /* 0xe7be undefined */
5871 /* 0xe7c6 undefined */
5872 /* 0xe7c8-0xe7c9 undefined */
5874 case 0xe677: /* VCP - vector compare decimal */
5875 case 0xe7ca: /* WFK - vector fp compare and signal scalar */
5876 case 0xe7cb: /* WFC - vector fp compare scalar */
5877 case 0xe7d8: /* VTM - vector test under mask */
5878 case 0xe7d9: /* VECL - vector element compare logical */
5879 case 0xe7db: /* VEC - vector element compare */
5880 case 0xed08: /* KEB - compare and signal */
5881 case 0xed09: /* CEB - compare */
5882 case 0xed18: /* KDB - compare and signal */
5883 case 0xed19: /* CDB - compare */
5884 /* flags + fpc only */
5885 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5886 return -1;
5887 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5888 return -1;
5889 break;
5891 /* 0xe7cd undefined */
5892 /* 0xe7cf-0xe7d3 undefined */
5893 /* 0xe7da undefined */
5894 /* 0xe7dc-0xe7dd undefined */
5895 /* 0xe7e0-0xe7e1 undefined */
5896 /* 0xe7e4 undefined */
5897 /* 0xe7e6 undefined */
5898 /* 0xe7e9 undefined */
5899 /* 0xe7ec-0xe7ed undefined */
5900 /* 0xe7f4 undefined */
5901 /* 0xe7f6 undefined */
5902 /* 0xe7fa undefined */
5904 /* 0xeb00-0xeb03 undefined */
5906 case 0xeb04: /* LMG - load multiple */
5907 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
5908 if (s390_record_gpr_g (gdbarch, regcache, i))
5909 return -1;
5910 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
5911 return -1;
5912 break;
5914 /* 0xeb05-0xeb09 undefined */
5915 /* 0xeb0e undefined */
5916 /* 0xeb0f privileged: TRACG */
5917 /* 0xeb10-0xeb13 undefined */
5919 case 0xeb14: /* CSY - compare and swap */
5920 case 0xebf4: /* LAN - load and and */
5921 case 0xebf6: /* LAO - load and or */
5922 case 0xebf7: /* LAX - load and xor */
5923 case 0xebf8: /* LAA - load and add */
5924 case 0xebfa: /* LAAL - load and add logical */
5925 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
5926 if (record_full_arch_list_add_mem (oaddr, 4))
5927 return -1;
5928 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
5929 return -1;
5930 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5931 return -1;
5932 break;
5934 /* 0xeb15-0xeb1b undefined */
5935 /* 0xeb1e-0xeb1f undefined */
5936 /* 0xeb22 undefined */
5938 case 0xeb23: /* CLT - compare logical and trap */
5939 case 0xeb2b: /* CLGT - compare logical and trap */
5940 /* fpc only - including possible DXC write for trapping insns */
5941 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
5942 return -1;
5943 break;
5945 case 0xeb24: /* STMG - store multiple */
5946 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
5947 if (inib[2] <= inib[3])
5948 n = inib[3] - inib[2] + 1;
5949 else
5950 n = inib[3] + 0x10 - inib[2] + 1;
5951 if (record_full_arch_list_add_mem (oaddr, n * 8))
5952 return -1;
5953 break;
5955 /* 0xeb25 privileged */
5957 case 0xeb26: /* STMH - store multiple high */
5958 case 0xeb90: /* STMY - store multiple */
5959 case 0xeb9b: /* STAMY - store access multiple */
5960 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
5961 if (inib[2] <= inib[3])
5962 n = inib[3] - inib[2] + 1;
5963 else
5964 n = inib[3] + 0x10 - inib[2] + 1;
5965 if (record_full_arch_list_add_mem (oaddr, n * 4))
5966 return -1;
5967 break;
5969 /* 0xeb27-0xeb2a undefined */
5971 case 0xeb2c: /* STCMH - store characters under mask */
5972 case 0xeb2d: /* STCMY - store characters under mask */
5973 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
5974 if (record_full_arch_list_add_mem (oaddr, s390_popcnt (inib[3])))
5975 return -1;
5976 break;
5978 /* 0xeb2e undefined */
5979 /* 0xeb2f privileged */
5981 case 0xeb30: /* CSG - compare and swap */
5982 case 0xebe4: /* LANG - load and and */
5983 case 0xebe6: /* LAOG - load and or */
5984 case 0xebe7: /* LAXG - load and xor */
5985 case 0xebe8: /* LAAG - load and add */
5986 case 0xebea: /* LAALG - load and add logical */
5987 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
5988 if (record_full_arch_list_add_mem (oaddr, 8))
5989 return -1;
5990 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
5991 return -1;
5992 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
5993 return -1;
5994 break;
5996 case 0xeb31: /* CDSY - compare double and swap */
5997 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
5998 if (record_full_arch_list_add_mem (oaddr, 8))
5999 return -1;
6000 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6001 return -1;
6002 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6003 return -1;
6004 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6005 return -1;
6006 break;
6008 /* 0xeb32-0xeb3d undefined */
6010 case 0xeb3e: /* CDSG - compare double and swap */
6011 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6012 if (record_full_arch_list_add_mem (oaddr, 16))
6013 return -1;
6014 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6015 return -1;
6016 if (s390_record_gpr_g (gdbarch, regcache, inib[2] | 1))
6017 return -1;
6018 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6019 return -1;
6020 break;
6022 /* 0xeb3f-0xeb43 undefined */
6023 /* 0xeb46-0xeb4b undefined */
6024 /* 0xeb4d-0xeb50 undefined */
6026 case 0xeb52: /* MVIY - move */
6027 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6028 if (record_full_arch_list_add_mem (oaddr, 1))
6029 return -1;
6030 break;
6032 case 0xeb54: /* NIY - and */
6033 case 0xeb56: /* OIY - or */
6034 case 0xeb57: /* XIY - xor */
6035 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6036 if (record_full_arch_list_add_mem (oaddr, 1))
6037 return -1;
6038 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6039 return -1;
6040 break;
6042 /* 0xeb53 undefined */
6043 /* 0xeb58-0xeb69 undefined */
6045 case 0xeb6a: /* ASI - add immediate */
6046 case 0xeb6e: /* ALSI - add immediate */
6047 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6048 if (record_full_arch_list_add_mem (oaddr, 4))
6049 return -1;
6050 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6051 return -1;
6052 break;
6054 /* 0xeb6b-0xeb6d undefined */
6055 /* 0xeb6f-0xeb79 undefined */
6057 case 0xeb7a: /* AGSI - add immediate */
6058 case 0xeb7e: /* ALGSI - add immediate */
6059 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6060 if (record_full_arch_list_add_mem (oaddr, 8))
6061 return -1;
6062 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6063 return -1;
6064 break;
6066 /* 0xeb7b-0xeb7d undefined */
6067 /* 0xeb7f undefined */
6069 case 0xeb80: /* ICMH - insert characters under mask */
6070 /* 32-bit high gpr destination + flags */
6071 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
6072 return -1;
6073 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6074 return -1;
6075 break;
6077 /* 0xeb82-0xeb8d undefined */
6079 case 0xeb8e: /* MVCLU - move long unicode [partial] */
6080 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + inib[2], &tmp);
6081 oaddr = s390_record_address_mask (gdbarch, regcache, tmp);
6082 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM + (inib[2] | 1), &tmp);
6083 if (record_full_arch_list_add_mem (oaddr, tmp))
6084 return -1;
6085 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6086 return -1;
6087 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6088 return -1;
6089 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6090 return -1;
6091 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
6092 return -1;
6093 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6094 return -1;
6095 break;
6097 case 0xeb8f: /* CLCLU - compare logical long unicode [partial] */
6098 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6099 return -1;
6100 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[2] | 1)))
6101 return -1;
6102 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6103 return -1;
6104 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + (inib[3] | 1)))
6105 return -1;
6106 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6107 return -1;
6108 break;
6110 /* 0xeb91-0xeb95 undefined */
6112 case 0xeb96: /* LMH - load multiple high */
6113 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6114 if (s390_record_gpr_h (gdbarch, regcache, i))
6115 return -1;
6116 if (s390_record_gpr_h (gdbarch, regcache, inib[3]))
6117 return -1;
6118 break;
6120 /* 0xeb97 undefined */
6122 case 0xeb98: /* LMY - load multiple */
6123 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6124 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i))
6125 return -1;
6126 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6127 return -1;
6128 break;
6130 /* 0xeb99 undefined */
6132 case 0xeb9a: /* LAMY - load access multiple */
6133 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6134 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + i))
6135 return -1;
6136 if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + inib[3]))
6137 return -1;
6138 break;
6140 /* 0xeb9c-0xebbf undefined */
6141 /* 0xebc1-0xebdb undefined */
6143 case 0xebe1: /* STOCFH - store high on condition */
6144 case 0xebf3: /* STOC - store on condition */
6145 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6146 if (record_full_arch_list_add_mem (oaddr, 4))
6147 return -1;
6148 break;
6150 case 0xebe3: /* STOCG - store on condition */
6151 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], ibyte[4]);
6152 if (record_full_arch_list_add_mem (oaddr, 8))
6153 return -1;
6154 break;
6156 /* 0xebe5 undefined */
6157 /* 0xebe9 undefined */
6158 /* 0xebeb-0xebf1 undefined */
6159 /* 0xebf5 undefined */
6160 /* 0xebf9 undefined */
6161 /* 0xebfb-0xebff undefined */
6163 /* 0xed00-0xed03 undefined */
6165 case 0xed04: /* LDEB - load lengthened */
6166 case 0xed0c: /* MDEB - multiply */
6167 case 0xed0d: /* DEB - divide */
6168 case 0xed14: /* SQEB - square root */
6169 case 0xed15: /* SQDB - square root */
6170 case 0xed17: /* MEEB - multiply */
6171 case 0xed1c: /* MDB - multiply */
6172 case 0xed1d: /* DDB - divide */
6173 /* float destination + fpc */
6174 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6175 return -1;
6176 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6177 return -1;
6178 break;
6180 case 0xed05: /* LXDB - load lengthened */
6181 case 0xed06: /* LXEB - load lengthened */
6182 case 0xed07: /* MXDB - multiply */
6183 /* float pair destination + fpc */
6184 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6185 return -1;
6186 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
6187 return -1;
6188 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6189 return -1;
6190 break;
6192 case 0xed0a: /* AEB - add */
6193 case 0xed0b: /* SEB - subtract */
6194 case 0xed1a: /* ADB - add */
6195 case 0xed1b: /* SDB - subtract */
6196 /* float destination + flags + fpc */
6197 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6198 return -1;
6199 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6200 return -1;
6201 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6202 return -1;
6203 break;
6205 case 0xed0e: /* MAEB - multiply and add */
6206 case 0xed0f: /* MSEB - multiply and subtract */
6207 case 0xed1e: /* MADB - multiply and add */
6208 case 0xed1f: /* MSDB - multiply and subtract */
6209 case 0xed40: /* SLDT - shift significand left */
6210 case 0xed41: /* SRDT - shift significand right */
6211 case 0xedaa: /* CDZT - convert from zoned */
6212 case 0xedae: /* CDPT - convert from packed */
6213 /* float destination [RXF] + fpc */
6214 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
6215 return -1;
6216 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6217 return -1;
6218 break;
6220 /* 0xed13 undefined */
6221 /* 0xed16 undefined */
6222 /* 0xed20-0xed23 undefined */
6224 case 0xed24: /* LDE - load lengthened */
6225 case 0xed34: /* SQE - square root */
6226 case 0xed35: /* SQD - square root */
6227 case 0xed37: /* MEE - multiply */
6228 case 0xed64: /* LEY - load */
6229 case 0xed65: /* LDY - load */
6230 /* float destination */
6231 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6232 return -1;
6233 break;
6235 case 0xed25: /* LXD - load lengthened */
6236 case 0xed26: /* LXE - load lengthened */
6237 /* float pair destination */
6238 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[2]))
6239 return -1;
6240 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[2] | 2)))
6241 return -1;
6242 break;
6244 /* 0xed27-0xed2d undefined */
6246 case 0xed2e: /* MAE - multiply and add */
6247 case 0xed2f: /* MSE - multiply and subtract */
6248 case 0xed38: /* MAYL - multiply and add unnormalized */
6249 case 0xed39: /* MYL - multiply unnormalized */
6250 case 0xed3c: /* MAYH - multiply and add unnormalized */
6251 case 0xed3d: /* MYH - multiply unnormalized */
6252 case 0xed3e: /* MAD - multiply and add */
6253 case 0xed3f: /* MSD - multiply and subtract */
6254 /* float destination [RXF] */
6255 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
6256 return -1;
6257 break;
6259 /* 0xed30-0xed33 undefined */
6260 /* 0xed36 undefined */
6262 case 0xed3a: /* MAY - multiply and add unnormalized */
6263 case 0xed3b: /* MY - multiply unnormalized */
6264 /* float pair destination [RXF] */
6265 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
6266 return -1;
6267 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[8] | 2)))
6268 return -1;
6269 break;
6271 /* 0xed42-0xed47 undefined */
6273 case 0xed48: /* SLXT - shift significand left */
6274 case 0xed49: /* SRXT - shift significand right */
6275 case 0xedab: /* CXZT - convert from zoned */
6276 case 0xedaf: /* CXPT - convert from packed */
6277 /* float pair destination [RXF] + fpc */
6278 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + inib[8]))
6279 return -1;
6280 if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + (inib[8] | 2)))
6281 return -1;
6282 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6283 return -1;
6284 break;
6286 /* 0xed4a-0xed4f undefined */
6287 /* 0xed52-0xed53 undefined */
6288 /* 0xed56-0xed57 undefined */
6289 /* 0xed5a-0xed63 undefined */
6290 /* 0xed68-0xeda7 undefined */
6292 case 0xeda8: /* CZDT - convert to zoned */
6293 case 0xeda9: /* CZXT - convert to zoned */
6294 case 0xedac: /* CPDT - convert to packed */
6295 case 0xedad: /* CPXT - convert to packed */
6296 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6297 if (record_full_arch_list_add_mem (oaddr, ibyte[1] + 1))
6298 return -1;
6299 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6300 return -1;
6301 break;
6303 /* 0xedb0-0xedff undefined */
6305 default:
6306 goto UNKNOWN_OP;
6308 break;
6310 /* 0xe4 undefined */
6312 case 0xe5:
6313 /* SSE/SIL-format instruction */
6314 switch (insn[0])
6316 /* 0xe500-0xe509 undefined, privileged, or unsupported */
6318 case 0xe50a: /* MVCRL - move right to left */
6319 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
6320 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6321 if (record_full_arch_list_add_mem (oaddr, (tmp & 0xff) + 1))
6322 return -1;
6323 break;
6325 /* 0xe50b-0xe543 undefined, privileged, or unsupported */
6327 case 0xe544: /* MVHHI - move */
6328 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6329 if (record_full_arch_list_add_mem (oaddr, 2))
6330 return -1;
6331 break;
6333 /* 0xe545-0xe547 undefined */
6335 case 0xe548: /* MVGHI - move */
6336 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6337 if (record_full_arch_list_add_mem (oaddr, 8))
6338 return -1;
6339 break;
6341 /* 0xe549-0xe54b undefined */
6343 case 0xe54c: /* MVHI - move */
6344 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6345 if (record_full_arch_list_add_mem (oaddr, 4))
6346 return -1;
6347 break;
6349 /* 0xe54d-0xe553 undefined */
6351 case 0xe554: /* CHHSI - compare halfword immediate */
6352 case 0xe555: /* CLHHSI - compare logical immediate */
6353 case 0xe558: /* CGHSI - compare halfword immediate */
6354 case 0xe559: /* CLGHSI - compare logical immediate */
6355 case 0xe55c: /* CHSI - compare halfword immediate */
6356 case 0xe55d: /* CLFHSI - compare logical immediate */
6357 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6358 return -1;
6359 break;
6361 /* 0xe556-0xe557 undefined */
6362 /* 0xe55a-0xe55b undefined */
6363 /* 0xe55e-0xe55f undefined */
6365 case 0xe560: /* TBEGIN - transaction begin */
6366 /* The transaction will be immediately aborted after this
6367 instruction, due to single-stepping. This instruction is
6368 only supported so that the program can fail a few times
6369 and go to the non-transactional fallback. */
6370 if (inib[4])
6372 /* Transaction diagnostic block - user. */
6373 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6374 if (record_full_arch_list_add_mem (oaddr, 256))
6375 return -1;
6377 /* Transaction diagnostic block - supervisor. */
6378 if (record_full_arch_list_add_reg (regcache, S390_TDB_DWORD0_REGNUM))
6379 return -1;
6380 if (record_full_arch_list_add_reg (regcache, S390_TDB_ABORT_CODE_REGNUM))
6381 return -1;
6382 if (record_full_arch_list_add_reg (regcache, S390_TDB_CONFLICT_TOKEN_REGNUM))
6383 return -1;
6384 if (record_full_arch_list_add_reg (regcache, S390_TDB_ATIA_REGNUM))
6385 return -1;
6386 for (i = 0; i < 16; i++)
6387 if (record_full_arch_list_add_reg (regcache, S390_TDB_R0_REGNUM + i))
6388 return -1;
6389 /* And flags. */
6390 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6391 return -1;
6392 break;
6394 /* 0xe561 unsupported: TBEGINC */
6395 /* 0xe562-0xe5ff undefined */
6397 default:
6398 goto UNKNOWN_OP;
6400 break;
6402 case 0xec:
6403 /* RIE/RIS/RRS-format instruction */
6404 switch (ibyte[0] << 8 | ibyte[5])
6406 /* 0xec00-0xec41 undefined */
6408 case 0xec42: /* LOCHI - load halfword immediate on condition */
6409 case 0xec51: /* RISBLG - rotate then insert selected bits low */
6410 /* 32-bit or native gpr destination */
6411 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6412 return -1;
6413 break;
6415 /* 0xec43 undefined */
6417 case 0xec44: /* BRXHG - branch relative on index high */
6418 case 0xec45: /* BRXLG - branch relative on index low or equal */
6419 case 0xec46: /* LOCGHI - load halfword immediate on condition */
6420 case 0xec59: /* RISBGN - rotate then insert selected bits */
6421 /* 64-bit gpr destination */
6422 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6423 return -1;
6424 break;
6426 /* 0xec47-0xec4d undefined */
6428 case 0xec4e: /* LOCHHI - load halfword immediate on condition */
6429 case 0xec5d: /* RISBHG - rotate then insert selected bits high */
6430 /* 32-bit high gpr destination */
6431 if (s390_record_gpr_h (gdbarch, regcache, inib[2]))
6432 return -1;
6433 break;
6435 /* 0xec4f-0xec50 undefined */
6436 /* 0xec52-0xec53 undefined */
6438 case 0xec54: /* RNSBG - rotate then and selected bits */
6439 case 0xec55: /* RISBG - rotate then insert selected bits */
6440 case 0xec56: /* ROSBG - rotate then or selected bits */
6441 case 0xec57: /* RXSBG - rotate then xor selected bits */
6442 case 0xecd9: /* AGHIK - add immediate */
6443 case 0xecdb: /* ALGHSIK - add logical immediate */
6444 /* 64-bit gpr destination + flags */
6445 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6446 return -1;
6447 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6448 return -1;
6449 break;
6451 /* 0xec58 undefined */
6452 /* 0xec5a-0xec5c undefined */
6453 /* 0xec5e-0xec63 undefined */
6455 case 0xec64: /* CGRJ - compare and branch relative */
6456 case 0xec65: /* CLGRJ - compare logical and branch relative */
6457 case 0xec76: /* CRJ - compare and branch relative */
6458 case 0xec77: /* CLRJ - compare logical and branch relative */
6459 case 0xec7c: /* CGIJ - compare immediate and branch relative */
6460 case 0xec7d: /* CLGIJ - compare logical immediate and branch relative */
6461 case 0xec7e: /* CIJ - compare immediate and branch relative */
6462 case 0xec7f: /* CLIJ - compare logical immediate and branch relative */
6463 case 0xece4: /* CGRB - compare and branch */
6464 case 0xece5: /* CLGRB - compare logical and branch */
6465 case 0xecf6: /* CRB - compare and branch */
6466 case 0xecf7: /* CLRB - compare logical and branch */
6467 case 0xecfc: /* CGIB - compare immediate and branch */
6468 case 0xecfd: /* CLGIB - compare logical immediate and branch */
6469 case 0xecfe: /* CIB - compare immediate and branch */
6470 case 0xecff: /* CLIB - compare logical immediate and branch */
6471 break;
6473 /* 0xec66-0xec6f undefined */
6475 case 0xec70: /* CGIT - compare immediate and trap */
6476 case 0xec71: /* CLGIT - compare logical immediate and trap */
6477 case 0xec72: /* CIT - compare immediate and trap */
6478 case 0xec73: /* CLFIT - compare logical immediate and trap */
6479 /* fpc only - including possible DXC write for trapping insns */
6480 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6481 return -1;
6482 break;
6484 /* 0xec74-0xec75 undefined */
6485 /* 0xec78-0xec7b undefined */
6487 /* 0xec80-0xecd7 undefined */
6489 case 0xecd8: /* AHIK - add immediate */
6490 case 0xecda: /* ALHSIK - add logical immediate */
6491 /* 32-bit gpr destination + flags */
6492 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6493 return -1;
6494 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6495 return -1;
6496 break;
6498 /* 0xecdc-0xece3 undefined */
6499 /* 0xece6-0xecf5 undefined */
6500 /* 0xecf8-0xecfb undefined */
6502 default:
6503 goto UNKNOWN_OP;
6505 break;
6507 case 0xee: /* PLO - perform locked operation */
6508 regcache_raw_read_unsigned (regcache, S390_R0_REGNUM, &tmp);
6509 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6510 oaddr2 = s390_record_calc_disp (gdbarch, regcache, 0, insn[2], 0);
6511 if (!(tmp & 0x100))
6513 uint8_t fc = tmp & 0xff;
6514 gdb_byte buf[8];
6515 switch (fc)
6517 case 0x00: /* CL */
6518 /* op1c */
6519 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6520 return -1;
6521 /* op3 */
6522 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6523 return -1;
6524 break;
6526 case 0x01: /* CLG */
6527 /* op1c */
6528 if (record_full_arch_list_add_mem (oaddr2 + 0x08, 8))
6529 return -1;
6530 /* op3 */
6531 if (record_full_arch_list_add_mem (oaddr2 + 0x28, 8))
6532 return -1;
6533 break;
6535 case 0x02: /* CLGR */
6536 /* op1c */
6537 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6538 return -1;
6539 /* op3 */
6540 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
6541 return -1;
6542 break;
6544 case 0x03: /* CLX */
6545 /* op1c */
6546 if (record_full_arch_list_add_mem (oaddr2 + 0x00, 16))
6547 return -1;
6548 /* op3 */
6549 if (record_full_arch_list_add_mem (oaddr2 + 0x20, 16))
6550 return -1;
6551 break;
6553 case 0x08: /* DCS */
6554 /* op3c */
6555 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[3]))
6556 return -1;
6557 [[fallthrough]];
6558 case 0x0c: /* CSST */
6559 /* op4 */
6560 if (record_full_arch_list_add_mem (oaddr2, 4))
6561 return -1;
6562 goto CS;
6564 case 0x14: /* CSTST */
6565 /* op8 */
6566 if (target_read_memory (oaddr2 + 0x88, buf, 8))
6567 return -1;
6568 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6569 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6570 if (record_full_arch_list_add_mem (oaddr3, 4))
6571 return -1;
6572 [[fallthrough]];
6573 case 0x10: /* CSDST */
6574 /* op6 */
6575 if (target_read_memory (oaddr2 + 0x68, buf, 8))
6576 return -1;
6577 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6578 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6579 if (record_full_arch_list_add_mem (oaddr3, 4))
6580 return -1;
6581 /* op4 */
6582 if (target_read_memory (oaddr2 + 0x48, buf, 8))
6583 return -1;
6584 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6585 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6586 if (record_full_arch_list_add_mem (oaddr3, 4))
6587 return -1;
6588 [[fallthrough]];
6589 case 0x04: /* CS */
6591 /* op1c */
6592 if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + inib[2]))
6593 return -1;
6594 /* op2 */
6595 if (record_full_arch_list_add_mem (oaddr, 4))
6596 return -1;
6597 break;
6599 case 0x09: /* DCSG */
6600 /* op3c */
6601 if (record_full_arch_list_add_mem (oaddr2 + 0x28, 8))
6602 return -1;
6603 goto CSSTG;
6605 case 0x15: /* CSTSTG */
6606 /* op8 */
6607 if (target_read_memory (oaddr2 + 0x88, buf, 8))
6608 return -1;
6609 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6610 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6611 if (record_full_arch_list_add_mem (oaddr3, 8))
6612 return -1;
6613 [[fallthrough]];
6614 case 0x11: /* CSDSTG */
6615 /* op6 */
6616 if (target_read_memory (oaddr2 + 0x68, buf, 8))
6617 return -1;
6618 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6619 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6620 if (record_full_arch_list_add_mem (oaddr3, 8))
6621 return -1;
6622 [[fallthrough]];
6623 case 0x0d: /* CSSTG */
6624 CSSTG:
6625 /* op4 */
6626 if (target_read_memory (oaddr2 + 0x48, buf, 8))
6627 return -1;
6628 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6629 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6630 if (record_full_arch_list_add_mem (oaddr3, 8))
6631 return -1;
6632 [[fallthrough]];
6633 case 0x05: /* CSG */
6634 /* op1c */
6635 if (record_full_arch_list_add_mem (oaddr2 + 0x08, 8))
6636 return -1;
6637 /* op2 */
6638 if (record_full_arch_list_add_mem (oaddr, 8))
6639 return -1;
6640 break;
6642 case 0x0a: /* DCSGR */
6643 /* op3c */
6644 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
6645 return -1;
6646 [[fallthrough]];
6647 case 0x0e: /* CSSTGR */
6648 /* op4 */
6649 if (record_full_arch_list_add_mem (oaddr2, 8))
6650 return -1;
6651 goto CSGR;
6653 case 0x16: /* CSTSTGR */
6654 /* op8 */
6655 if (target_read_memory (oaddr2 + 0x88, buf, 8))
6656 return -1;
6657 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6658 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6659 if (record_full_arch_list_add_mem (oaddr3, 8))
6660 return -1;
6661 [[fallthrough]];
6662 case 0x12: /* CSDSTGR */
6663 /* op6 */
6664 if (target_read_memory (oaddr2 + 0x68, buf, 8))
6665 return -1;
6666 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6667 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6668 if (record_full_arch_list_add_mem (oaddr3, 8))
6669 return -1;
6670 /* op4 */
6671 if (target_read_memory (oaddr2 + 0x48, buf, 8))
6672 return -1;
6673 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6674 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6675 if (record_full_arch_list_add_mem (oaddr3, 8))
6676 return -1;
6677 [[fallthrough]];
6678 case 0x06: /* CSGR */
6679 CSGR:
6680 /* op1c */
6681 if (s390_record_gpr_g (gdbarch, regcache, inib[2]))
6682 return -1;
6683 /* op2 */
6684 if (record_full_arch_list_add_mem (oaddr, 8))
6685 return -1;
6686 break;
6688 case 0x0b: /* DCSX */
6689 /* op3c */
6690 if (record_full_arch_list_add_mem (oaddr2 + 0x20, 16))
6691 return -1;
6692 goto CSSTX;
6694 case 0x17: /* CSTSTX */
6695 /* op8 */
6696 if (target_read_memory (oaddr2 + 0x88, buf, 8))
6697 return -1;
6698 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6699 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6700 if (record_full_arch_list_add_mem (oaddr3, 16))
6701 return -1;
6702 [[fallthrough]];
6703 case 0x13: /* CSDSTX */
6704 /* op6 */
6705 if (target_read_memory (oaddr2 + 0x68, buf, 8))
6706 return -1;
6707 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6708 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6709 if (record_full_arch_list_add_mem (oaddr3, 16))
6710 return -1;
6711 [[fallthrough]];
6712 case 0x0f: /* CSSTX */
6713 CSSTX:
6714 /* op4 */
6715 if (target_read_memory (oaddr2 + 0x48, buf, 8))
6716 return -1;
6717 oaddr3 = extract_unsigned_integer (buf, 8, byte_order);
6718 oaddr3 = s390_record_address_mask (gdbarch, regcache, oaddr3);
6719 if (record_full_arch_list_add_mem (oaddr3, 16))
6720 return -1;
6721 [[fallthrough]];
6722 case 0x07: /* CSX */
6723 /* op1c */
6724 if (record_full_arch_list_add_mem (oaddr2 + 0x00, 16))
6725 return -1;
6726 /* op2 */
6727 if (record_full_arch_list_add_mem (oaddr, 16))
6728 return -1;
6729 break;
6731 default:
6732 gdb_printf (gdb_stdlog, "Warning: Unknown PLO FC %02x at %s.\n",
6733 fc, paddress (gdbarch, addr));
6734 return -1;
6737 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6738 return -1;
6739 break;
6741 case 0xef: /* LMD - load multiple disjoint */
6742 for (i = inib[2]; i != inib[3]; i++, i &= 0xf)
6743 if (s390_record_gpr_g (gdbarch, regcache, i))
6744 return -1;
6745 if (s390_record_gpr_g (gdbarch, regcache, inib[3]))
6746 return -1;
6747 break;
6749 case 0xf0: /* SRP - shift and round decimal */
6750 case 0xf8: /* ZAP - zero and add */
6751 case 0xfa: /* AP - add decimal */
6752 case 0xfb: /* SP - subtract decimal */
6753 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6754 if (record_full_arch_list_add_mem (oaddr, inib[2] + 1))
6755 return -1;
6756 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6757 return -1;
6758 /* DXC may be written */
6759 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6760 return -1;
6761 break;
6763 case 0xf1: /* MVO - move with offset */
6764 case 0xf2: /* PACK - pack */
6765 case 0xf3: /* UNPK - unpack */
6766 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6767 if (record_full_arch_list_add_mem (oaddr, inib[2] + 1))
6768 return -1;
6769 break;
6771 /* 0xf4-0xf7 undefined */
6773 case 0xf9: /* CP - compare decimal */
6774 if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM))
6775 return -1;
6776 /* DXC may be written */
6777 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6778 return -1;
6779 break;
6781 case 0xfc: /* MP - multiply decimal */
6782 case 0xfd: /* DP - divide decimal */
6783 oaddr = s390_record_calc_disp (gdbarch, regcache, 0, insn[1], 0);
6784 if (record_full_arch_list_add_mem (oaddr, inib[2] + 1))
6785 return -1;
6786 /* DXC may be written */
6787 if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM))
6788 return -1;
6789 break;
6791 /* 0xfe-0xff undefined */
6793 default:
6794 UNKNOWN_OP:
6795 gdb_printf (gdb_stdlog, "Warning: Don't know how to record %04x "
6796 "at %s.\n", insn[0], paddress (gdbarch, addr));
6797 return -1;
6800 if (record_full_arch_list_add_reg (regcache, S390_PSWA_REGNUM))
6801 return -1;
6802 if (record_full_arch_list_add_end ())
6803 return -1;
6804 return 0;
6807 /* Miscellaneous. */
6809 /* Implement gdbarch_gcc_target_options. GCC does not know "-m32" or
6810 "-mcmodel=large". */
6812 static std::string
6813 s390_gcc_target_options (struct gdbarch *gdbarch)
6815 return gdbarch_ptr_bit (gdbarch) == 64 ? "-m64" : "-m31";
6818 /* Implement gdbarch_gnu_triplet_regexp. Target triplets are "s390-*"
6819 for 31-bit and "s390x-*" for 64-bit, while the BFD arch name is
6820 always "s390". Note that an s390x compiler supports "-m31" as
6821 well. */
6823 static const char *
6824 s390_gnu_triplet_regexp (struct gdbarch *gdbarch)
6826 return "s390x?";
6829 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
6830 gdbarch.h. */
6832 static int
6833 s390_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
6835 return ((isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement
6836 or indirection. */
6837 || *s == '%' /* Register access. */
6838 || isdigit (*s)); /* Literal number. */
6841 /* gdbarch init. */
6843 /* Validate the range of registers. NAMES must be known at compile time. */
6845 #define s390_validate_reg_range(feature, tdesc_data, start, names) \
6846 do \
6848 for (int i = 0; i < ARRAY_SIZE (names); i++) \
6849 if (!tdesc_numbered_register (feature, tdesc_data, start + i, names[i])) \
6850 return false; \
6852 while (0)
6854 /* Validate the target description. Also numbers registers contained in
6855 tdesc. */
6857 static bool
6858 s390_tdesc_valid (s390_gdbarch_tdep *tdep,
6859 struct tdesc_arch_data *tdesc_data)
6861 static const char *const psw[] = {
6862 "pswm", "pswa"
6864 static const char *const gprs[] = {
6865 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
6866 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
6868 static const char *const fprs[] = {
6869 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
6870 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
6872 static const char *const acrs[] = {
6873 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
6874 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15"
6876 static const char *const gprs_lower[] = {
6877 "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l",
6878 "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l"
6880 static const char *const gprs_upper[] = {
6881 "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
6882 "r8h", "r9h", "r10h", "r11h", "r12h", "r13h", "r14h", "r15h"
6884 static const char *const tdb_regs[] = {
6885 "tdb0", "tac", "tct", "atia",
6886 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7",
6887 "tr8", "tr9", "tr10", "tr11", "tr12", "tr13", "tr14", "tr15"
6889 static const char *const vxrs_low[] = {
6890 "v0l", "v1l", "v2l", "v3l", "v4l", "v5l", "v6l", "v7l", "v8l",
6891 "v9l", "v10l", "v11l", "v12l", "v13l", "v14l", "v15l",
6893 static const char *const vxrs_high[] = {
6894 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24",
6895 "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6897 static const char *const gs_cb[] = {
6898 "gsd", "gssm", "gsepla",
6900 static const char *const gs_bc[] = {
6901 "bc_gsd", "bc_gssm", "bc_gsepla",
6904 const struct target_desc *tdesc = tdep->tdesc;
6905 const struct tdesc_feature *feature;
6907 if (!tdesc_has_registers (tdesc))
6908 return false;
6910 /* Core registers, i.e. general purpose and PSW. */
6911 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.core");
6912 if (feature == NULL)
6913 return false;
6915 s390_validate_reg_range (feature, tdesc_data, S390_PSWM_REGNUM, psw);
6917 if (tdesc_unnumbered_register (feature, "r0"))
6919 s390_validate_reg_range (feature, tdesc_data, S390_R0_REGNUM, gprs);
6921 else
6923 tdep->have_upper = true;
6924 s390_validate_reg_range (feature, tdesc_data, S390_R0_REGNUM,
6925 gprs_lower);
6926 s390_validate_reg_range (feature, tdesc_data, S390_R0_UPPER_REGNUM,
6927 gprs_upper);
6930 /* Floating point registers. */
6931 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.fpr");
6932 if (feature == NULL)
6933 return false;
6935 if (!tdesc_numbered_register (feature, tdesc_data, S390_FPC_REGNUM, "fpc"))
6936 return false;
6938 s390_validate_reg_range (feature, tdesc_data, S390_F0_REGNUM, fprs);
6940 /* Access control registers. */
6941 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.acr");
6942 if (feature == NULL)
6943 return false;
6945 s390_validate_reg_range (feature, tdesc_data, S390_A0_REGNUM, acrs);
6947 /* Optional GNU/Linux-specific "registers". */
6948 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.linux");
6949 if (feature)
6951 tdesc_numbered_register (feature, tdesc_data,
6952 S390_ORIG_R2_REGNUM, "orig_r2");
6954 if (tdesc_numbered_register (feature, tdesc_data,
6955 S390_LAST_BREAK_REGNUM, "last_break"))
6956 tdep->have_linux_v1 = true;
6958 if (tdesc_numbered_register (feature, tdesc_data,
6959 S390_SYSTEM_CALL_REGNUM, "system_call"))
6960 tdep->have_linux_v2 = true;
6962 if (tdep->have_linux_v2 && !tdep->have_linux_v1)
6963 return false;
6966 /* Transaction diagnostic block. */
6967 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.tdb");
6968 if (feature)
6970 s390_validate_reg_range (feature, tdesc_data, S390_TDB_DWORD0_REGNUM,
6971 tdb_regs);
6972 tdep->have_tdb = true;
6975 /* Vector registers. */
6976 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.vx");
6977 if (feature)
6979 s390_validate_reg_range (feature, tdesc_data, S390_V0_LOWER_REGNUM,
6980 vxrs_low);
6981 s390_validate_reg_range (feature, tdesc_data, S390_V16_REGNUM,
6982 vxrs_high);
6983 tdep->have_vx = true;
6986 /* Guarded-storage registers. */
6987 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gs");
6988 if (feature)
6990 s390_validate_reg_range (feature, tdesc_data, S390_GSD_REGNUM, gs_cb);
6991 tdep->have_gs = true;
6994 /* Guarded-storage broadcast control. */
6995 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gsbc");
6996 if (feature)
6998 if (!tdep->have_gs)
6999 return false;
7000 s390_validate_reg_range (feature, tdesc_data, S390_BC_GSD_REGNUM,
7001 gs_bc);
7004 return true;
7007 /* Allocate and initialize new gdbarch_tdep. */
7009 static s390_gdbarch_tdep_up
7010 s390_gdbarch_tdep_alloc ()
7012 s390_gdbarch_tdep_up tdep (new s390_gdbarch_tdep);
7014 tdep->tdesc = NULL;
7016 tdep->abi = ABI_NONE;
7017 tdep->vector_abi = S390_VECTOR_ABI_NONE;
7019 tdep->gpr_full_regnum = -1;
7020 tdep->v0_full_regnum = -1;
7021 tdep->pc_regnum = -1;
7022 tdep->cc_regnum = -1;
7024 tdep->have_upper = false;
7025 tdep->have_linux_v1 = false;
7026 tdep->have_linux_v2 = false;
7027 tdep->have_tdb = false;
7028 tdep->have_vx = false;
7029 tdep->have_gs = false;
7031 tdep->s390_syscall_record = NULL;
7033 return tdep;
7036 /* Set up gdbarch struct. */
7038 static struct gdbarch *
7039 s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
7041 const struct target_desc *tdesc = info.target_desc;
7042 int first_pseudo_reg, last_pseudo_reg;
7043 static const char *const stap_register_prefixes[] = { "%", NULL };
7044 static const char *const stap_register_indirection_prefixes[] = { "(",
7045 NULL };
7046 static const char *const stap_register_indirection_suffixes[] = { ")",
7047 NULL };
7049 gdbarch *gdbarch = gdbarch_alloc (&info, s390_gdbarch_tdep_alloc ());
7050 s390_gdbarch_tdep *tdep = gdbarch_tdep<s390_gdbarch_tdep> (gdbarch);
7051 tdesc_arch_data_up tdesc_data = tdesc_data_alloc ();
7052 info.tdesc_data = tdesc_data.get ();
7054 set_gdbarch_believe_pcc_promotion (gdbarch, 0);
7055 set_gdbarch_char_signed (gdbarch, 0);
7057 /* S/390 GNU/Linux uses either 64-bit or 128-bit long doubles.
7058 We can safely let them default to 128-bit, since the debug info
7059 will give the size of type actually used in each case. */
7060 set_gdbarch_long_double_bit (gdbarch, 128);
7061 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_quad);
7063 set_gdbarch_type_align (gdbarch, s390_type_align);
7065 /* Breakpoints. */
7066 /* Amount PC must be decremented by after a breakpoint. This is
7067 often the number of bytes returned by gdbarch_breakpoint_from_pc but not
7068 always. */
7069 set_gdbarch_decr_pc_after_break (gdbarch, 2);
7070 set_gdbarch_breakpoint_kind_from_pc (gdbarch, s390_breakpoint::kind_from_pc);
7071 set_gdbarch_sw_breakpoint_from_kind (gdbarch, s390_breakpoint::bp_from_kind);
7073 /* Displaced stepping. */
7074 set_gdbarch_displaced_step_copy_insn (gdbarch,
7075 s390_displaced_step_copy_insn);
7076 set_gdbarch_displaced_step_fixup (gdbarch, s390_displaced_step_fixup);
7077 set_gdbarch_displaced_step_hw_singlestep (gdbarch, s390_displaced_step_hw_singlestep);
7078 set_gdbarch_software_single_step (gdbarch, s390_software_single_step);
7079 set_gdbarch_max_insn_length (gdbarch, S390_MAX_INSTR_SIZE);
7081 /* Prologue analysis. */
7082 set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
7084 /* Register handling. */
7085 set_gdbarch_num_regs (gdbarch, S390_NUM_REGS);
7086 set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM);
7087 set_gdbarch_fp0_regnum (gdbarch, S390_F0_REGNUM);
7088 set_gdbarch_guess_tracepoint_registers (gdbarch,
7089 s390_guess_tracepoint_registers);
7090 set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
7091 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
7092 set_gdbarch_value_from_register (gdbarch, s390_value_from_register);
7094 /* Pseudo registers. */
7095 set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
7096 set_gdbarch_deprecated_pseudo_register_write (gdbarch,
7097 s390_pseudo_register_write);
7098 set_tdesc_pseudo_register_name (gdbarch, s390_pseudo_register_name);
7099 set_tdesc_pseudo_register_type (gdbarch, s390_pseudo_register_type);
7100 set_tdesc_pseudo_register_reggroup_p (gdbarch,
7101 s390_pseudo_register_reggroup_p);
7102 set_gdbarch_ax_pseudo_register_collect (gdbarch,
7103 s390_ax_pseudo_register_collect);
7104 set_gdbarch_ax_pseudo_register_push_stack
7105 (gdbarch, s390_ax_pseudo_register_push_stack);
7106 set_gdbarch_gen_return_address (gdbarch, s390_gen_return_address);
7108 /* Inferior function calls. */
7109 set_gdbarch_push_dummy_call (gdbarch, s390_push_dummy_call);
7110 set_gdbarch_dummy_id (gdbarch, s390_dummy_id);
7111 set_gdbarch_frame_align (gdbarch, s390_frame_align);
7112 set_gdbarch_return_value (gdbarch, s390_return_value);
7114 /* Frame handling. */
7115 /* Stack grows downward. */
7116 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
7117 set_gdbarch_stack_frame_destroyed_p (gdbarch, s390_stack_frame_destroyed_p);
7118 dwarf2_frame_set_init_reg (gdbarch, s390_dwarf2_frame_init_reg);
7119 dwarf2_frame_set_adjust_regnum (gdbarch, s390_adjust_frame_regnum);
7120 dwarf2_append_unwinders (gdbarch);
7121 set_gdbarch_unwind_pc (gdbarch, s390_unwind_pc);
7122 set_gdbarch_unwind_sp (gdbarch, s390_unwind_sp);
7124 switch (info.bfd_arch_info->mach)
7126 case bfd_mach_s390_31:
7127 set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
7128 break;
7130 case bfd_mach_s390_64:
7131 set_gdbarch_long_bit (gdbarch, 64);
7132 set_gdbarch_long_long_bit (gdbarch, 64);
7133 set_gdbarch_ptr_bit (gdbarch, 64);
7134 set_gdbarch_address_class_type_flags (gdbarch,
7135 s390_address_class_type_flags);
7136 set_gdbarch_address_class_type_flags_to_name (gdbarch,
7137 s390_address_class_type_flags_to_name);
7138 set_gdbarch_address_class_name_to_type_flags (gdbarch,
7139 s390_address_class_name_to_type_flags);
7140 break;
7143 /* SystemTap functions. */
7144 set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
7145 set_gdbarch_stap_register_indirection_prefixes (gdbarch,
7146 stap_register_indirection_prefixes);
7147 set_gdbarch_stap_register_indirection_suffixes (gdbarch,
7148 stap_register_indirection_suffixes);
7150 set_gdbarch_disassembler_options (gdbarch, &s390_disassembler_options);
7151 set_gdbarch_valid_disassembler_options (gdbarch,
7152 disassembler_options_s390 ());
7154 /* Process record-replay */
7155 set_gdbarch_process_record (gdbarch, s390_process_record);
7157 /* Miscellaneous. */
7158 set_gdbarch_stap_is_single_operand (gdbarch, s390_stap_is_single_operand);
7159 set_gdbarch_gcc_target_options (gdbarch, s390_gcc_target_options);
7160 set_gdbarch_gnu_triplet_regexp (gdbarch, s390_gnu_triplet_regexp);
7162 /* Initialize the OSABI. */
7163 gdbarch_init_osabi (info, gdbarch);
7165 /* Always create a default tdesc. Otherwise commands like 'set osabi'
7166 cause GDB to crash with an internal error when the user tries to set
7167 an unsupported OSABI. */
7168 if (!tdesc_has_registers (tdesc))
7170 if (info.bfd_arch_info->mach == bfd_mach_s390_31)
7171 tdesc = tdesc_s390_linux32;
7172 else
7173 tdesc = tdesc_s390x_linux64;
7175 tdep->tdesc = tdesc;
7177 /* Check any target description for validity. */
7178 if (!s390_tdesc_valid (tdep, tdesc_data.get ()))
7180 gdbarch_free (gdbarch);
7181 return NULL;
7184 /* Determine vector ABI. */
7185 #ifdef HAVE_ELF
7186 if (tdep->have_vx
7187 && info.abfd != NULL
7188 && info.abfd->format == bfd_object
7189 && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
7190 && bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
7191 Tag_GNU_S390_ABI_Vector) == 2)
7192 tdep->vector_abi = S390_VECTOR_ABI_128;
7193 #endif
7195 /* Find a candidate among extant architectures. */
7196 for (arches = gdbarch_list_lookup_by_info (arches, &info);
7197 arches != NULL;
7198 arches = gdbarch_list_lookup_by_info (arches->next, &info))
7200 s390_gdbarch_tdep *tmp
7201 = gdbarch_tdep<s390_gdbarch_tdep> (arches->gdbarch);
7203 if (!tmp)
7204 continue;
7206 /* A program can 'choose' not to use the vector registers when they
7207 are present. Leading to the same tdesc but different tdep and
7208 thereby a different gdbarch. */
7209 if (tmp->vector_abi != tdep->vector_abi)
7210 continue;
7212 gdbarch_free (gdbarch);
7213 return arches->gdbarch;
7216 tdesc_use_registers (gdbarch, tdep->tdesc, std::move (tdesc_data));
7217 set_gdbarch_register_name (gdbarch, s390_register_name);
7219 /* Assign pseudo register numbers. */
7220 first_pseudo_reg = gdbarch_num_regs (gdbarch);
7221 last_pseudo_reg = first_pseudo_reg;
7222 if (tdep->have_upper)
7224 tdep->gpr_full_regnum = last_pseudo_reg;
7225 last_pseudo_reg += 16;
7227 if (tdep->have_vx)
7229 tdep->v0_full_regnum = last_pseudo_reg;
7230 last_pseudo_reg += 16;
7232 tdep->pc_regnum = last_pseudo_reg++;
7233 tdep->cc_regnum = last_pseudo_reg++;
7234 set_gdbarch_pc_regnum (gdbarch, tdep->pc_regnum);
7235 set_gdbarch_num_pseudo_regs (gdbarch, last_pseudo_reg - first_pseudo_reg);
7237 /* Frame handling. */
7238 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
7239 frame_unwind_append_unwinder (gdbarch, &s390_stub_frame_unwind);
7240 frame_unwind_append_unwinder (gdbarch, &s390_frame_unwind);
7241 frame_base_set_default (gdbarch, &s390_frame_base);
7243 return gdbarch;
7246 void _initialize_s390_tdep ();
7247 void
7248 _initialize_s390_tdep ()
7250 /* Hook us into the gdbarch mechanism. */
7251 gdbarch_register (bfd_arch_s390, s390_gdbarch_init);
7253 initialize_tdesc_s390_linux32 ();
7254 initialize_tdesc_s390x_linux64 ();