1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "arch-utils.h"
35 #include "../bfd/bfd.h"
36 #include "floatformat.h"
38 #include "reggroups.h"
41 #include "gdb_assert.h"
44 #include "s390-tdep.h"
47 /* The tdep structure. */
51 /* Core file register sets. */
52 const struct regset *gregset;
55 const struct regset *fpregset;
60 /* Register information. */
62 struct s390_register_info
68 static struct s390_register_info s390_register_info[S390_NUM_TOTAL_REGS] =
70 /* Program Status Word. */
71 { "pswm", &builtin_type_long },
72 { "pswa", &builtin_type_long },
74 /* General Purpose Registers. */
75 { "r0", &builtin_type_long },
76 { "r1", &builtin_type_long },
77 { "r2", &builtin_type_long },
78 { "r3", &builtin_type_long },
79 { "r4", &builtin_type_long },
80 { "r5", &builtin_type_long },
81 { "r6", &builtin_type_long },
82 { "r7", &builtin_type_long },
83 { "r8", &builtin_type_long },
84 { "r9", &builtin_type_long },
85 { "r10", &builtin_type_long },
86 { "r11", &builtin_type_long },
87 { "r12", &builtin_type_long },
88 { "r13", &builtin_type_long },
89 { "r14", &builtin_type_long },
90 { "r15", &builtin_type_long },
92 /* Access Registers. */
93 { "acr0", &builtin_type_int },
94 { "acr1", &builtin_type_int },
95 { "acr2", &builtin_type_int },
96 { "acr3", &builtin_type_int },
97 { "acr4", &builtin_type_int },
98 { "acr5", &builtin_type_int },
99 { "acr6", &builtin_type_int },
100 { "acr7", &builtin_type_int },
101 { "acr8", &builtin_type_int },
102 { "acr9", &builtin_type_int },
103 { "acr10", &builtin_type_int },
104 { "acr11", &builtin_type_int },
105 { "acr12", &builtin_type_int },
106 { "acr13", &builtin_type_int },
107 { "acr14", &builtin_type_int },
108 { "acr15", &builtin_type_int },
110 /* Floating Point Control Word. */
111 { "fpc", &builtin_type_int },
113 /* Floating Point Registers. */
114 { "f0", &builtin_type_double },
115 { "f1", &builtin_type_double },
116 { "f2", &builtin_type_double },
117 { "f3", &builtin_type_double },
118 { "f4", &builtin_type_double },
119 { "f5", &builtin_type_double },
120 { "f6", &builtin_type_double },
121 { "f7", &builtin_type_double },
122 { "f8", &builtin_type_double },
123 { "f9", &builtin_type_double },
124 { "f10", &builtin_type_double },
125 { "f11", &builtin_type_double },
126 { "f12", &builtin_type_double },
127 { "f13", &builtin_type_double },
128 { "f14", &builtin_type_double },
129 { "f15", &builtin_type_double },
131 /* Pseudo registers. */
132 { "pc", &builtin_type_void_func_ptr },
133 { "cc", &builtin_type_int },
136 /* Return the name of register REGNUM. */
138 s390_register_name (int regnum)
140 gdb_assert (regnum >= 0 && regnum < S390_NUM_TOTAL_REGS);
141 return s390_register_info[regnum].name;
144 /* Return the GDB type object for the "standard" data type of data in
147 s390_register_type (struct gdbarch *gdbarch, int regnum)
149 gdb_assert (regnum >= 0 && regnum < S390_NUM_TOTAL_REGS);
150 return *s390_register_info[regnum].type;
153 /* DWARF Register Mapping. */
155 static int s390_dwarf_regmap[] =
157 /* General Purpose Registers. */
158 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
159 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
160 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
161 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
163 /* Floating Point Registers. */
164 S390_F0_REGNUM, S390_F2_REGNUM, S390_F4_REGNUM, S390_F6_REGNUM,
165 S390_F1_REGNUM, S390_F3_REGNUM, S390_F5_REGNUM, S390_F7_REGNUM,
166 S390_F8_REGNUM, S390_F10_REGNUM, S390_F12_REGNUM, S390_F14_REGNUM,
167 S390_F9_REGNUM, S390_F11_REGNUM, S390_F13_REGNUM, S390_F15_REGNUM,
169 /* Control Registers (not mapped). */
170 -1, -1, -1, -1, -1, -1, -1, -1,
171 -1, -1, -1, -1, -1, -1, -1, -1,
173 /* Access Registers. */
174 S390_A0_REGNUM, S390_A1_REGNUM, S390_A2_REGNUM, S390_A3_REGNUM,
175 S390_A4_REGNUM, S390_A5_REGNUM, S390_A6_REGNUM, S390_A7_REGNUM,
176 S390_A8_REGNUM, S390_A9_REGNUM, S390_A10_REGNUM, S390_A11_REGNUM,
177 S390_A12_REGNUM, S390_A13_REGNUM, S390_A14_REGNUM, S390_A15_REGNUM,
179 /* Program Status Word. */
184 /* Convert DWARF register number REG to the appropriate register
185 number used by GDB. */
187 s390_dwarf_reg_to_regnum (int reg)
191 if (reg >= 0 || reg < ARRAY_SIZE (s390_dwarf_regmap))
192 regnum = s390_dwarf_regmap[reg];
195 warning ("Unmapped DWARF Register #%d encountered\n", reg);
200 /* Pseudo registers - PC and condition code. */
203 s390_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
204 int regnum, void *buf)
211 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &val);
212 store_unsigned_integer (buf, 4, val & 0x7fffffff);
216 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val);
217 store_unsigned_integer (buf, 4, (val >> 12) & 3);
221 internal_error (__FILE__, __LINE__, "invalid regnum");
226 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
227 int regnum, const void *buf)
234 val = extract_unsigned_integer (buf, 4);
235 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &psw);
236 psw = (psw & 0x80000000) | (val & 0x7fffffff);
237 regcache_raw_write_unsigned (regcache, S390_PSWA_REGNUM, psw);
241 val = extract_unsigned_integer (buf, 4);
242 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
243 psw = (psw & ~((ULONGEST)3 << 12)) | ((val & 3) << 12);
244 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, psw);
248 internal_error (__FILE__, __LINE__, "invalid regnum");
253 s390x_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
254 int regnum, void *buf)
261 regcache_raw_read (regcache, S390_PSWA_REGNUM, buf);
265 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val);
266 store_unsigned_integer (buf, 4, (val >> 44) & 3);
270 internal_error (__FILE__, __LINE__, "invalid regnum");
275 s390x_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
276 int regnum, const void *buf)
283 regcache_raw_write (regcache, S390_PSWA_REGNUM, buf);
287 val = extract_unsigned_integer (buf, 4);
288 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
289 psw = (psw & ~((ULONGEST)3 << 44)) | ((val & 3) << 44);
290 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, psw);
294 internal_error (__FILE__, __LINE__, "invalid regnum");
298 /* 'float' values are stored in the upper half of floating-point
299 registers, even though we are otherwise a big-endian platform. */
302 s390_convert_register_p (int regno, struct type *type)
304 return (regno >= S390_F0_REGNUM && regno <= S390_F15_REGNUM)
305 && TYPE_LENGTH (type) < 8;
309 s390_register_to_value (struct frame_info *frame, int regnum,
310 struct type *valtype, void *out)
313 int len = TYPE_LENGTH (valtype);
314 gdb_assert (len < 8);
316 get_frame_register (frame, regnum, in);
317 memcpy (out, in, len);
321 s390_value_to_register (struct frame_info *frame, int regnum,
322 struct type *valtype, const void *in)
325 int len = TYPE_LENGTH (valtype);
326 gdb_assert (len < 8);
329 memcpy (out, in, len);
330 put_frame_register (frame, regnum, out);
333 /* Register groups. */
336 s390_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
337 struct reggroup *group)
339 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
341 /* Registers displayed via 'info regs'. */
342 if (group == general_reggroup)
343 return (regnum >= S390_R0_REGNUM && regnum <= S390_R15_REGNUM)
344 || regnum == S390_PC_REGNUM
345 || regnum == S390_CC_REGNUM;
347 /* Registers displayed via 'info float'. */
348 if (group == float_reggroup)
349 return (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM)
350 || regnum == S390_FPC_REGNUM;
352 /* Registers that need to be saved/restored in order to
353 push or pop frames. */
354 if (group == save_reggroup || group == restore_reggroup)
355 return regnum != S390_PSWM_REGNUM && regnum != S390_PSWA_REGNUM;
357 return default_register_reggroup_p (gdbarch, regnum, group);
361 /* Core file register sets. */
363 int s390_regmap_gregset[S390_NUM_REGS] =
365 /* Program Status Word. */
367 /* General Purpose Registers. */
368 0x08, 0x0c, 0x10, 0x14,
369 0x18, 0x1c, 0x20, 0x24,
370 0x28, 0x2c, 0x30, 0x34,
371 0x38, 0x3c, 0x40, 0x44,
372 /* Access Registers. */
373 0x48, 0x4c, 0x50, 0x54,
374 0x58, 0x5c, 0x60, 0x64,
375 0x68, 0x6c, 0x70, 0x74,
376 0x78, 0x7c, 0x80, 0x84,
377 /* Floating Point Control Word. */
379 /* Floating Point Registers. */
380 -1, -1, -1, -1, -1, -1, -1, -1,
381 -1, -1, -1, -1, -1, -1, -1, -1,
384 int s390x_regmap_gregset[S390_NUM_REGS] =
387 /* General Purpose Registers. */
388 0x10, 0x18, 0x20, 0x28,
389 0x30, 0x38, 0x40, 0x48,
390 0x50, 0x58, 0x60, 0x68,
391 0x70, 0x78, 0x80, 0x88,
392 /* Access Registers. */
393 0x90, 0x94, 0x98, 0x9c,
394 0xa0, 0xa4, 0xa8, 0xac,
395 0xb0, 0xb4, 0xb8, 0xbc,
396 0xc0, 0xc4, 0xc8, 0xcc,
397 /* Floating Point Control Word. */
399 /* Floating Point Registers. */
400 -1, -1, -1, -1, -1, -1, -1, -1,
401 -1, -1, -1, -1, -1, -1, -1, -1,
404 int s390_regmap_fpregset[S390_NUM_REGS] =
406 /* Program Status Word. */
408 /* General Purpose Registers. */
409 -1, -1, -1, -1, -1, -1, -1, -1,
410 -1, -1, -1, -1, -1, -1, -1, -1,
411 /* Access Registers. */
412 -1, -1, -1, -1, -1, -1, -1, -1,
413 -1, -1, -1, -1, -1, -1, -1, -1,
414 /* Floating Point Control Word. */
416 /* Floating Point Registers. */
417 0x08, 0x10, 0x18, 0x20,
418 0x28, 0x30, 0x38, 0x40,
419 0x48, 0x50, 0x58, 0x60,
420 0x68, 0x70, 0x78, 0x80,
423 /* Supply register REGNUM from the register set REGSET to register cache
424 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
426 s390_supply_regset (const struct regset *regset, struct regcache *regcache,
427 int regnum, const void *regs, size_t len)
429 const int *offset = regset->descr;
432 for (i = 0; i < S390_NUM_REGS; i++)
434 if ((regnum == i || regnum == -1) && offset[i] != -1)
435 regcache_raw_supply (regcache, i, (const char *)regs + offset[i]);
439 static const struct regset s390_gregset = {
444 static const struct regset s390x_gregset = {
445 s390x_regmap_gregset,
449 static const struct regset s390_fpregset = {
450 s390_regmap_fpregset,
454 /* Return the appropriate register set for the core section identified
455 by SECT_NAME and SECT_SIZE. */
456 const struct regset *
457 s390_regset_from_core_section (struct gdbarch *gdbarch,
458 const char *sect_name, size_t sect_size)
460 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
462 if (strcmp (sect_name, ".reg") == 0 && sect_size == tdep->sizeof_gregset)
463 return tdep->gregset;
465 if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
466 return tdep->fpregset;
472 #define GDB_TARGET_IS_ESAME (TARGET_ARCHITECTURE->mach == bfd_mach_s390_64)
473 #define S390_GPR_SIZE (GDB_TARGET_IS_ESAME ? 8 : 4)
474 #define S390_FPR_SIZE (8)
475 #define S390_MAX_INSTR_SIZE (6)
476 #define S390_SYSCALL_OPCODE (0x0a)
477 #define S390_SYSCALL_SIZE (2)
478 #define S390_SIGCONTEXT_SREGS_OFFSET (8)
479 #define S390X_SIGCONTEXT_SREGS_OFFSET (8)
480 #define S390_SIGREGS_FP0_OFFSET (144)
481 #define S390X_SIGREGS_FP0_OFFSET (216)
482 #define S390_UC_MCONTEXT_OFFSET (256)
483 #define S390X_UC_MCONTEXT_OFFSET (344)
484 #define S390_STACK_FRAME_OVERHEAD 16*S390_GPR_SIZE+32
485 #define S390_STACK_PARAMETER_ALIGNMENT S390_GPR_SIZE
486 #define S390_NUM_FP_PARAMETER_REGISTERS (GDB_TARGET_IS_ESAME ? 4:2)
487 #define S390_SIGNAL_FRAMESIZE (GDB_TARGET_IS_ESAME ? 160:96)
488 #define s390_NR_sigreturn 119
489 #define s390_NR_rt_sigreturn 173
493 struct frame_extra_info
497 CORE_ADDR function_start;
498 CORE_ADDR skip_prologue_function_start;
499 CORE_ADDR saved_pc_valid;
501 CORE_ADDR sig_fixed_saved_pc_valid;
502 CORE_ADDR sig_fixed_saved_pc;
503 CORE_ADDR frame_pointer_saved_pc; /* frame pointer needed for alloca */
504 CORE_ADDR stack_bought_valid;
505 CORE_ADDR stack_bought; /* amount we decrement the stack pointer by */
506 CORE_ADDR sigcontext;
510 static CORE_ADDR s390_frame_saved_pc_nofix (struct frame_info *fi);
513 s390_readinstruction (bfd_byte instr[], CORE_ADDR at)
517 static int s390_instrlen[] = {
523 if (target_read_memory (at, &instr[0], 2))
525 instrlen = s390_instrlen[instr[0] >> 6];
528 if (target_read_memory (at + 2, &instr[2], instrlen - 2))
535 s390_memset_extra_info (struct frame_extra_info *fextra_info)
537 memset (fextra_info, 0, sizeof (struct frame_extra_info));
541 /* Prologue analysis. */
543 /* When we analyze a prologue, we're really doing 'abstract
544 interpretation' or 'pseudo-evaluation': running the function's code
545 in simulation, but using conservative approximations of the values
546 it would have when it actually runs. For example, if our function
547 starts with the instruction:
549 ahi r1, 42 # add halfword immediate 42 to r1
551 we don't know exactly what value will be in r1 after executing this
552 instruction, but we do know it'll be 42 greater than its original
555 If we then see an instruction like:
557 ahi r1, 22 # add halfword immediate 22 to r1
559 we still don't know what r1's value is, but again, we can say it is
560 now 64 greater than its original value.
562 If the next instruction were:
564 lr r2, r1 # set r2 to r1's value
566 then we can say that r2's value is now the original value of r1
569 Of course, this can only go so far before it gets unreasonable. If
570 we wanted to be able to say anything about the value of r1 after
573 xr r1, r3 # exclusive-or r1 and r3, place result in r1
575 then things would get pretty complex. But remember, we're just
576 doing a conservative approximation; if exclusive-or instructions
577 aren't relevant to prologues, we can just say r1's value is now
578 'unknown'. We can ignore things that are too complex, if that loss
579 of information is acceptable for our application.
581 Once you've reached an instruction that you don't know how to
582 simulate, you stop. Now you examine the state of the registers and
583 stack slots you've kept track of. For example:
585 - To see how large your stack frame is, just check the value of sp;
586 if it's the original value of sp minus a constant, then that
587 constant is the stack frame's size. If the sp's value has been
588 marked as 'unknown', then that means the prologue has done
589 something too complex for us to track, and we don't know the
592 - To see whether we've saved the SP in the current frame's back
593 chain slot, we just check whether the current value of the back
594 chain stack slot is the original value of the sp.
596 Sure, this takes some work. But prologue analyzers aren't
597 quick-and-simple pattern patching to recognize a few fixed prologue
598 forms any more; they're big, hairy functions. Along with inferior
599 function calls, prologue analysis accounts for a substantial
600 portion of the time needed to stabilize a GDB port. So I think
601 it's worthwhile to look for an approach that will be easier to
602 understand and maintain. In the approach used here:
604 - It's easier to see that the analyzer is correct: you just see
605 whether the analyzer properly (albiet conservatively) simulates
606 the effect of each instruction.
608 - It's easier to extend the analyzer: you can add support for new
609 instructions, and know that you haven't broken anything that
610 wasn't already broken before.
612 - It's orthogonal: to gather new information, you don't need to
613 complicate the code for each instruction. As long as your domain
614 of conservative values is already detailed enough to tell you
615 what you need, then all the existing instruction simulations are
616 already gathering the right data for you.
618 A 'struct prologue_value' is a conservative approximation of the
619 real value the register or stack slot will have. */
621 struct prologue_value {
623 /* What sort of value is this? This determines the interpretation
624 of subsequent fields. */
627 /* We don't know anything about the value. This is also used for
628 values we could have kept track of, when doing so would have
629 been too complex and we don't want to bother. The bottom of
633 /* A known constant. K is its value. */
636 /* The value that register REG originally had *UPON ENTRY TO THE
637 FUNCTION*, plus K. If K is zero, this means, obviously, just
638 the value REG had upon entry to the function. REG is a GDB
639 register number. Before we start interpreting, we initialize
640 every register R to { pv_register, R, 0 }. */
645 /* The meanings of the following fields depend on 'kind'; see the
646 comments for the specific 'kind' values. */
652 /* Set V to be unknown. */
654 pv_set_to_unknown (struct prologue_value *v)
656 v->kind = pv_unknown;
660 /* Set V to the constant K. */
662 pv_set_to_constant (struct prologue_value *v, CORE_ADDR k)
664 v->kind = pv_constant;
669 /* Set V to the original value of register REG, plus K. */
671 pv_set_to_register (struct prologue_value *v, int reg, CORE_ADDR k)
673 v->kind = pv_register;
679 /* If one of *A and *B is a constant, and the other isn't, swap the
680 pointers as necessary to ensure that *B points to the constant.
681 This can reduce the number of cases we need to analyze in the
684 pv_constant_last (struct prologue_value **a,
685 struct prologue_value **b)
687 if ((*a)->kind == pv_constant
688 && (*b)->kind != pv_constant)
690 struct prologue_value *temp = *a;
697 /* Set SUM to the sum of A and B. SUM, A, and B may point to the same
698 'struct prologue_value' object. */
700 pv_add (struct prologue_value *sum,
701 struct prologue_value *a,
702 struct prologue_value *b)
704 pv_constant_last (&a, &b);
706 /* We can handle adding constants to registers, and other constants. */
707 if (b->kind == pv_constant
708 && (a->kind == pv_register
709 || a->kind == pv_constant))
712 sum->reg = a->reg; /* not meaningful if a is pv_constant, but
714 sum->k = a->k + b->k;
717 /* Anything else we don't know how to add. We don't have a
718 representation for, say, the sum of two registers, or a multiple
719 of a register's value (adding a register to itself). */
721 sum->kind = pv_unknown;
725 /* Add the constant K to V. */
727 pv_add_constant (struct prologue_value *v, CORE_ADDR k)
729 struct prologue_value pv_k;
731 /* Rather than thinking of all the cases we can and can't handle,
732 we'll just let pv_add take care of that for us. */
733 pv_set_to_constant (&pv_k, k);
734 pv_add (v, v, &pv_k);
738 /* Subtract B from A, and put the result in DIFF.
740 This isn't quite the same as negating B and adding it to A, since
741 we don't have a representation for the negation of anything but a
742 constant. For example, we can't negate { pv_register, R1, 10 },
743 but we do know that { pv_register, R1, 10 } minus { pv_register,
744 R1, 5 } is { pv_constant, <ignored>, 5 }.
746 This means, for example, that we can subtract two stack addresses;
747 they're both relative to the original SP. Since the frame pointer
748 is set based on the SP, its value will be the original SP plus some
749 constant (probably zero), so we can use its value just fine. */
751 pv_subtract (struct prologue_value *diff,
752 struct prologue_value *a,
753 struct prologue_value *b)
755 pv_constant_last (&a, &b);
757 /* We can subtract a constant from another constant, or from a
759 if (b->kind == pv_constant
760 && (a->kind == pv_register
761 || a->kind == pv_constant))
763 diff->kind = a->kind;
764 diff->reg = a->reg; /* not always meaningful, but harmless */
765 diff->k = a->k - b->k;
768 /* We can subtract a register from itself, yielding a constant. */
769 else if (a->kind == pv_register
770 && b->kind == pv_register
773 diff->kind = pv_constant;
774 diff->k = a->k - b->k;
777 /* We don't know how to subtract anything else. */
779 diff->kind = pv_unknown;
783 /* Set AND to the logical and of A and B. */
785 pv_logical_and (struct prologue_value *and,
786 struct prologue_value *a,
787 struct prologue_value *b)
789 pv_constant_last (&a, &b);
791 /* We can 'and' two constants. */
792 if (a->kind == pv_constant
793 && b->kind == pv_constant)
795 and->kind = pv_constant;
796 and->k = a->k & b->k;
799 /* We can 'and' anything with the constant zero. */
800 else if (b->kind == pv_constant
803 and->kind = pv_constant;
807 /* We can 'and' anything with ~0. */
808 else if (b->kind == pv_constant
809 && b->k == ~ (CORE_ADDR) 0)
812 /* We can 'and' a register with itself. */
813 else if (a->kind == pv_register
814 && b->kind == pv_register
819 /* Otherwise, we don't know. */
821 pv_set_to_unknown (and);
825 /* Return non-zero iff A and B are identical expressions.
827 This is not the same as asking if the two values are equal; the
828 result of such a comparison would have to be a pv_boolean, and
829 asking whether two 'unknown' values were equal would give you
830 pv_maybe. Same for comparing, say, { pv_register, R1, 0 } and {
831 pv_register, R2, 0}. Instead, this is asking whether the two
832 representations are the same. */
834 pv_is_identical (struct prologue_value *a,
835 struct prologue_value *b)
837 if (a->kind != b->kind)
845 return (a->k == b->k);
847 return (a->reg == b->reg && a->k == b->k);
854 /* Return non-zero if A is the original value of register number R
855 plus K, zero otherwise. */
857 pv_is_register (struct prologue_value *a, int r, CORE_ADDR k)
859 return (a->kind == pv_register
865 /* A prologue-value-esque boolean type, including "maybe", when we
866 can't figure out whether something is true or not. */
874 /* Decide whether a reference to SIZE bytes at ADDR refers exactly to
875 an element of an array. The array starts at ARRAY_ADDR, and has
876 ARRAY_LEN values of ELT_SIZE bytes each. If ADDR definitely does
877 refer to an array element, set *I to the index of the referenced
878 element in the array, and return pv_definite_yes. If it definitely
879 doesn't, return pv_definite_no. If we can't tell, return pv_maybe.
881 If the reference does touch the array, but doesn't fall exactly on
882 an element boundary, or doesn't refer to the whole element, return
884 static enum pv_boolean
885 pv_is_array_ref (struct prologue_value *addr,
887 struct prologue_value *array_addr,
892 struct prologue_value offset;
894 /* Note that, since ->k is a CORE_ADDR, and CORE_ADDR is unsigned,
895 if addr is *before* the start of the array, then this isn't going
897 pv_subtract (&offset, addr, array_addr);
899 if (offset.kind == pv_constant)
901 /* This is a rather odd test. We want to know if the SIZE bytes
902 at ADDR don't overlap the array at all, so you'd expect it to
903 be an || expression: "if we're completely before || we're
904 completely after". But with unsigned arithmetic, things are
905 different: since it's a number circle, not a number line, the
906 right values for offset.k are actually one contiguous range. */
907 if (offset.k <= -size
908 && offset.k >= array_len * elt_size)
909 return pv_definite_no;
910 else if (offset.k % elt_size != 0
915 *i = offset.k / elt_size;
916 return pv_definite_yes;
925 /* Decoding S/390 instructions. */
927 /* Named opcode values for the S/390 instructions we recognize. Some
928 instructions have their opcode split across two fields; those are the
929 op1_* and op2_* enums. */
932 op1_aghi = 0xa7, op2_aghi = 0xb,
933 op1_ahi = 0xa7, op2_ahi = 0xa,
936 op1_bras = 0xa7, op2_bras = 0x5,
939 op1_larl = 0xc0, op2_larl = 0x0,
941 op1_lghi = 0xa7, op2_lghi = 0x9,
942 op1_lhi = 0xa7, op2_lhi = 0x8,
949 op1_stg = 0xe3, op2_stg = 0x24,
951 op1_stmg = 0xeb, op2_stmg = 0x24,
953 op1_lmg = 0xeb, op2_lmg = 0x04,
958 /* The functions below are for recognizing and decoding S/390
959 instructions of various formats. Each of them checks whether INSN
960 is an instruction of the given format, with the specified opcodes.
961 If it is, it sets the remaining arguments to the values of the
962 instruction's fields, and returns a non-zero value; otherwise, it
965 These functions' arguments appear in the order they appear in the
966 instruction, not in the machine-language form. So, opcodes always
967 come first, even though they're sometimes scattered around the
968 instructions. And displacements appear before base and extension
969 registers, as they do in the assembly syntax, not at the end, as
970 they do in the machine language. */
972 is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2)
974 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
976 *r1 = (insn[1] >> 4) & 0xf;
977 /* i2 is a 16-bit signed quantity. */
978 *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000;
987 is_ril (bfd_byte *insn, int op1, int op2,
988 unsigned int *r1, int *i2)
990 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
992 *r1 = (insn[1] >> 4) & 0xf;
993 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
994 no sign extension is necessary, but we don't want to assume
996 *i2 = (((insn[2] << 24)
999 | (insn[5])) ^ 0x80000000) - 0x80000000;
1008 is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
1012 *r1 = (insn[1] >> 4) & 0xf;
1013 *r2 = insn[1] & 0xf;
1022 is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
1024 if (((insn[0] << 8) | insn[1]) == op)
1026 /* Yes, insn[3]. insn[2] is unused in RRE format. */
1027 *r1 = (insn[3] >> 4) & 0xf;
1028 *r2 = insn[3] & 0xf;
1037 is_rs (bfd_byte *insn, int op,
1038 unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2)
1042 *r1 = (insn[1] >> 4) & 0xf;
1043 *r3 = insn[1] & 0xf;
1044 *b2 = (insn[2] >> 4) & 0xf;
1045 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
1054 is_rse (bfd_byte *insn, int op1, int op2,
1055 unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2)
1058 /* Yes, insn[5]. insn[4] is unused. */
1061 *r1 = (insn[1] >> 4) & 0xf;
1062 *r3 = insn[1] & 0xf;
1063 *b2 = (insn[2] >> 4) & 0xf;
1064 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
1073 is_rx (bfd_byte *insn, int op,
1074 unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2)
1078 *r1 = (insn[1] >> 4) & 0xf;
1079 *x2 = insn[1] & 0xf;
1080 *b2 = (insn[2] >> 4) & 0xf;
1081 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
1090 is_rxe (bfd_byte *insn, int op1, int op2,
1091 unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2)
1094 /* Yes, insn[5]. insn[4] is unused. */
1097 *r1 = (insn[1] >> 4) & 0xf;
1098 *x2 = insn[1] & 0xf;
1099 *b2 = (insn[2] >> 4) & 0xf;
1100 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
1108 /* Set ADDR to the effective address for an X-style instruction, like:
1112 Here, X2 and B2 are registers, and D2 is an unsigned 12-bit
1113 constant; the effective address is the sum of all three. If either
1114 X2 or B2 are zero, then it doesn't contribute to the sum --- this
1115 means that r0 can't be used as either X2 or B2.
1117 GPR is an array of general register values, indexed by GPR number,
1118 not GDB register number. */
1120 compute_x_addr (struct prologue_value *addr,
1121 struct prologue_value *gpr,
1122 unsigned int d2, unsigned int x2, unsigned int b2)
1124 /* We can't just add stuff directly in addr; it might alias some of
1125 the registers we need to read. */
1126 struct prologue_value result;
1128 pv_set_to_constant (&result, d2);
1130 pv_add (&result, &result, &gpr[x2]);
1132 pv_add (&result, &result, &gpr[b2]);
1138 /* The number of GPR and FPR spill slots in an S/390 stack frame. We
1139 track general-purpose registers r2 -- r15, and floating-point
1140 registers f0, f2, f4, and f6. */
1141 #define S390_NUM_SPILL_SLOTS (14 + 4)
1142 #define S390_NUM_GPRS 16
1143 #define S390_NUM_FPRS 16
1146 /* If the SIZE bytes at ADDR are a stack slot we're actually tracking,
1147 return pv_definite_yes and set *STACK to point to the slot. If
1148 we're sure that they are not any of our stack slots, then return
1149 pv_definite_no. Otherwise, return pv_maybe.
1150 - GPR is an array indexed by GPR number giving the current values
1151 of the general-purpose registers.
1152 - SPILL is an array tracking the spill area of the caller's frame;
1153 SPILL[i] is the i'th spill slot. The spill slots are designated
1154 for r2 -- r15, and then f0, f2, f4, and f6.
1155 - BACK_CHAIN is the value of the back chain slot; it's only valid
1156 when the current frame actually has some space for a back chain
1157 slot --- that is, when the current value of the stack pointer
1158 (according to GPR) is at least S390_STACK_FRAME_OVERHEAD bytes
1159 less than its original value. */
1160 static enum pv_boolean
1161 s390_on_stack (struct prologue_value *addr,
1163 struct prologue_value *gpr,
1164 struct prologue_value *spill,
1165 struct prologue_value *back_chain,
1166 struct prologue_value **stack)
1168 struct prologue_value gpr_spill_addr;
1169 struct prologue_value fpr_spill_addr;
1170 struct prologue_value back_chain_addr;
1174 /* Construct the addresses of the spill arrays and the back chain. */
1175 pv_set_to_register (&gpr_spill_addr, S390_SP_REGNUM, 2 * S390_GPR_SIZE);
1176 pv_set_to_register (&fpr_spill_addr, S390_SP_REGNUM, 16 * S390_GPR_SIZE);
1177 back_chain_addr = gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1179 /* We have to check for GPR and FPR references using two separate
1180 calls to pv_is_array_ref, since the GPR and FPR spill slots are
1181 different sizes. (SPILL is an array, but the thing it tracks
1182 isn't really an array.) */
1184 /* Was it a reference to the GPR spill array? */
1185 b = pv_is_array_ref (addr, size, &gpr_spill_addr, 14, S390_GPR_SIZE, &i);
1186 if (b == pv_definite_yes)
1189 return pv_definite_yes;
1194 /* Was it a reference to the FPR spill array? */
1195 b = pv_is_array_ref (addr, size, &fpr_spill_addr, 4, S390_FPR_SIZE, &i);
1196 if (b == pv_definite_yes)
1198 *stack = &spill[14 + i];
1199 return pv_definite_yes;
1204 /* Was it a reference to the back chain?
1205 This isn't quite right. We ought to check whether we have
1206 actually allocated any new frame at all. */
1207 b = pv_is_array_ref (addr, size, &back_chain_addr, 1, S390_GPR_SIZE, &i);
1208 if (b == pv_definite_yes)
1210 *stack = back_chain;
1211 return pv_definite_yes;
1216 /* All the above queries returned definite 'no's. */
1217 return pv_definite_no;
1221 /* Do a SIZE-byte store of VALUE to ADDR. GPR, SPILL, and BACK_CHAIN,
1222 and the return value are as described for s390_on_stack, above.
1223 Note that, when this returns pv_maybe, we have to assume that all
1224 of our memory now contains unknown values. */
1225 static enum pv_boolean
1226 s390_store (struct prologue_value *addr,
1228 struct prologue_value *value,
1229 struct prologue_value *gpr,
1230 struct prologue_value *spill,
1231 struct prologue_value *back_chain)
1233 struct prologue_value *stack;
1234 enum pv_boolean on_stack
1235 = s390_on_stack (addr, size, gpr, spill, back_chain, &stack);
1237 if (on_stack == pv_definite_yes)
1244 /* The current frame looks like a signal delivery frame: the first
1245 instruction is an 'svc' opcode. If the next frame is a signal
1246 handler's frame, set FI's saved register map to point into the
1247 signal context structure. */
1249 s390_get_signal_frame_info (struct frame_info *fi)
1251 struct frame_info *next_frame = get_next_frame (fi);
1254 && get_frame_extra_info (next_frame)
1255 && get_frame_extra_info (next_frame)->sigcontext)
1257 /* We're definitely backtracing from a signal handler. */
1258 CORE_ADDR *saved_regs = deprecated_get_frame_saved_regs (fi);
1259 CORE_ADDR save_reg_addr = (get_frame_extra_info (next_frame)->sigcontext
1260 + DEPRECATED_REGISTER_BYTE (S390_R0_REGNUM));
1263 for (reg = 0; reg < S390_NUM_GPRS; reg++)
1265 saved_regs[S390_R0_REGNUM + reg] = save_reg_addr;
1266 save_reg_addr += S390_GPR_SIZE;
1269 save_reg_addr = (get_frame_extra_info (next_frame)->sigcontext
1270 + (GDB_TARGET_IS_ESAME ? S390X_SIGREGS_FP0_OFFSET :
1271 S390_SIGREGS_FP0_OFFSET));
1272 for (reg = 0; reg < S390_NUM_FPRS; reg++)
1274 saved_regs[S390_F0_REGNUM + reg] = save_reg_addr;
1275 save_reg_addr += S390_FPR_SIZE;
1282 s390_get_frame_info (CORE_ADDR start_pc,
1283 struct frame_extra_info *fextra_info,
1284 struct frame_info *fi,
1285 int init_extra_info)
1287 /* Our return value:
1288 zero if we were able to read all the instructions we wanted, or
1289 -1 if we got an error trying to read memory. */
1292 /* The current PC for our abstract interpretation. */
1295 /* The address of the next instruction after that. */
1298 /* The general-purpose registers. */
1299 struct prologue_value gpr[S390_NUM_GPRS];
1301 /* The floating-point registers. */
1302 struct prologue_value fpr[S390_NUM_FPRS];
1304 /* The register spill stack slots in the caller's frame ---
1305 general-purpose registers r2 through r15, and floating-point
1306 registers. spill[i] is where gpr i+2 gets spilled;
1307 spill[(14, 15, 16, 17)] is where (f0, f2, f4, f6) get spilled. */
1308 struct prologue_value spill[S390_NUM_SPILL_SLOTS];
1310 /* The value of the back chain slot. This is only valid if the stack
1311 pointer is known to be less than its original value --- that is,
1312 if we have indeed allocated space on the stack. */
1313 struct prologue_value back_chain;
1315 /* The address of the instruction after the last one that changed
1316 the SP, FP, or back chain. */
1317 CORE_ADDR after_last_frame_setup_insn = start_pc;
1319 /* Set up everything's initial value. */
1323 for (i = 0; i < S390_NUM_GPRS; i++)
1324 pv_set_to_register (&gpr[i], S390_R0_REGNUM + i, 0);
1326 for (i = 0; i < S390_NUM_FPRS; i++)
1327 pv_set_to_register (&fpr[i], S390_F0_REGNUM + i, 0);
1329 for (i = 0; i < S390_NUM_SPILL_SLOTS; i++)
1330 pv_set_to_unknown (&spill[i]);
1332 pv_set_to_unknown (&back_chain);
1335 /* Start interpreting instructions, until we hit something we don't
1336 know how to interpret. (Ideally, we should stop at the frame's
1337 real current PC, but at the moment, our callers don't give us
1339 for (pc = start_pc; ; pc = next_pc)
1341 bfd_byte insn[S390_MAX_INSTR_SIZE];
1342 int insn_len = s390_readinstruction (insn, pc);
1344 /* Fields for various kinds of instructions. */
1345 unsigned int b2, r1, r2, d2, x2, r3;
1348 /* The values of SP, FP, and back chain before this instruction,
1349 for detecting instructions that change them. */
1350 struct prologue_value pre_insn_sp, pre_insn_fp, pre_insn_back_chain;
1352 /* If we got an error trying to read the instruction, report it. */
1359 next_pc = pc + insn_len;
1361 pre_insn_sp = gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1362 pre_insn_fp = gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1363 pre_insn_back_chain = back_chain;
1365 /* A special case, first --- only recognized as the very first
1366 instruction of the function, for signal delivery frames:
1367 SVC i --- system call */
1369 && is_rr (insn, op_svc, &r1, &r2))
1372 s390_get_signal_frame_info (fi);
1376 /* AHI r1, i2 --- add halfword immediate */
1377 else if (is_ri (insn, op1_ahi, op2_ahi, &r1, &i2))
1378 pv_add_constant (&gpr[r1], i2);
1381 /* AGHI r1, i2 --- add halfword immediate (64-bit version) */
1382 else if (GDB_TARGET_IS_ESAME
1383 && is_ri (insn, op1_aghi, op2_aghi, &r1, &i2))
1384 pv_add_constant (&gpr[r1], i2);
1386 /* AR r1, r2 -- add register */
1387 else if (is_rr (insn, op_ar, &r1, &r2))
1388 pv_add (&gpr[r1], &gpr[r1], &gpr[r2]);
1390 /* BASR r1, 0 --- branch and save
1391 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1392 else if (is_rr (insn, op_basr, &r1, &r2)
1394 pv_set_to_constant (&gpr[r1], next_pc);
1396 /* BRAS r1, i2 --- branch relative and save */
1397 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2))
1399 pv_set_to_constant (&gpr[r1], next_pc);
1400 next_pc = pc + i2 * 2;
1402 /* We'd better not interpret any backward branches. We'll
1408 /* L r1, d2(x2, b2) --- load */
1409 else if (is_rx (insn, op_l, &r1, &d2, &x2, &b2))
1411 struct prologue_value addr;
1412 struct prologue_value *stack;
1414 compute_x_addr (&addr, gpr, d2, x2, b2);
1416 /* If it's a load from an in-line constant pool, then we can
1417 simulate that, under the assumption that the code isn't
1418 going to change between the time the processor actually
1419 executed it creating the current frame, and the time when
1420 we're analyzing the code to unwind past that frame. */
1421 if (addr.kind == pv_constant
1422 && start_pc <= addr.k
1423 && addr.k < next_pc)
1424 pv_set_to_constant (&gpr[r1],
1425 read_memory_integer (addr.k, 4));
1427 /* If it's definitely a reference to something on the stack,
1429 else if (s390_on_stack (&addr, 4, gpr, spill, &back_chain, &stack)
1433 /* Otherwise, we don't know the value. */
1435 pv_set_to_unknown (&gpr[r1]);
1438 /* LA r1, d2(x2, b2) --- load address */
1439 else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2))
1440 compute_x_addr (&gpr[r1], gpr, d2, x2, b2);
1442 /* LARL r1, i2 --- load address relative long */
1443 else if (GDB_TARGET_IS_ESAME
1444 && is_ril (insn, op1_larl, op2_larl, &r1, &i2))
1445 pv_set_to_constant (&gpr[r1], pc + i2 * 2);
1447 /* LGR r1, r2 --- load from register */
1448 else if (GDB_TARGET_IS_ESAME
1449 && is_rre (insn, op_lgr, &r1, &r2))
1452 /* LHI r1, i2 --- load halfword immediate */
1453 else if (is_ri (insn, op1_lhi, op2_lhi, &r1, &i2))
1454 pv_set_to_constant (&gpr[r1], i2);
1456 /* LGHI r1, i2 --- load halfword immediate --- 64-bit version */
1457 else if (is_ri (insn, op1_lghi, op2_lghi, &r1, &i2))
1458 pv_set_to_constant (&gpr[r1], i2);
1460 /* LR r1, r2 --- load from register */
1461 else if (is_rr (insn, op_lr, &r1, &r2))
1464 /* NGR r1, r2 --- logical and --- 64-bit version */
1465 else if (GDB_TARGET_IS_ESAME
1466 && is_rre (insn, op_ngr, &r1, &r2))
1467 pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]);
1469 /* NR r1, r2 --- logical and */
1470 else if (is_rr (insn, op_nr, &r1, &r2))
1471 pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]);
1473 /* NGR r1, r2 --- logical and --- 64-bit version */
1474 else if (GDB_TARGET_IS_ESAME
1475 && is_rre (insn, op_ngr, &r1, &r2))
1476 pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]);
1478 /* NR r1, r2 --- logical and */
1479 else if (is_rr (insn, op_nr, &r1, &r2))
1480 pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]);
1482 /* S r1, d2(x2, b2) --- subtract from memory */
1483 else if (is_rx (insn, op_s, &r1, &d2, &x2, &b2))
1485 struct prologue_value addr;
1486 struct prologue_value value;
1487 struct prologue_value *stack;
1489 compute_x_addr (&addr, gpr, d2, x2, b2);
1491 /* If it's a load from an in-line constant pool, then we can
1492 simulate that, under the assumption that the code isn't
1493 going to change between the time the processor actually
1494 executed it and the time when we're analyzing it. */
1495 if (addr.kind == pv_constant
1496 && start_pc <= addr.k
1498 pv_set_to_constant (&value, read_memory_integer (addr.k, 4));
1500 /* If it's definitely a reference to something on the stack,
1501 we could do that. */
1502 else if (s390_on_stack (&addr, 4, gpr, spill, &back_chain, &stack)
1506 /* Otherwise, we don't know the value. */
1508 pv_set_to_unknown (&value);
1510 pv_subtract (&gpr[r1], &gpr[r1], &value);
1513 /* ST r1, d2(x2, b2) --- store */
1514 else if (is_rx (insn, op_st, &r1, &d2, &x2, &b2))
1516 struct prologue_value addr;
1518 compute_x_addr (&addr, gpr, d2, x2, b2);
1520 /* The below really should be '4', not 'S390_GPR_SIZE'; this
1521 instruction always stores 32 bits, regardless of the full
1523 if (s390_store (&addr, 4, &gpr[r1], gpr, spill, &back_chain)
1525 /* If we can't be sure that it's *not* a store to
1526 something we're tracing, then we would have to mark all
1527 our memory as unknown --- after all, it *could* be a
1528 store to any of them --- so we might as well just stop
1533 /* STD r1, d2(x2,b2) --- store floating-point register */
1534 else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2))
1536 struct prologue_value addr;
1538 compute_x_addr (&addr, gpr, d2, x2, b2);
1540 if (s390_store (&addr, 8, &fpr[r1], gpr, spill, &back_chain)
1542 /* If we can't be sure that it's *not* a store to
1543 something we're tracing, then we would have to mark all
1544 our memory as unknown --- after all, it *could* be a
1545 store to any of them --- so we might as well just stop
1550 /* STG r1, d2(x2, b2) --- 64-bit store */
1551 else if (GDB_TARGET_IS_ESAME
1552 && is_rxe (insn, op1_stg, op2_stg, &r1, &d2, &x2, &b2))
1554 struct prologue_value addr;
1556 compute_x_addr (&addr, gpr, d2, x2, b2);
1558 /* The below really should be '8', not 'S390_GPR_SIZE'; this
1559 instruction always stores 64 bits, regardless of the full
1561 if (s390_store (&addr, 8, &gpr[r1], gpr, spill, &back_chain)
1563 /* If we can't be sure that it's *not* a store to
1564 something we're tracing, then we would have to mark all
1565 our memory as unknown --- after all, it *could* be a
1566 store to any of them --- so we might as well just stop
1571 /* STM r1, r3, d2(b2) --- store multiple */
1572 else if (is_rs (insn, op_stm, &r1, &r3, &d2, &b2))
1576 struct prologue_value addr;
1578 for (regnum = r1, offset = 0;
1580 regnum++, offset += 4)
1582 compute_x_addr (&addr, gpr, d2 + offset, 0, b2);
1584 if (s390_store (&addr, 4, &gpr[regnum], gpr, spill, &back_chain)
1586 /* If we can't be sure that it's *not* a store to
1587 something we're tracing, then we would have to mark all
1588 our memory as unknown --- after all, it *could* be a
1589 store to any of them --- so we might as well just stop
1594 /* If we left the loop early, we should stop interpreting
1600 /* STMG r1, r3, d2(b2) --- store multiple, 64-bit */
1601 else if (GDB_TARGET_IS_ESAME
1602 && is_rse (insn, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2))
1606 struct prologue_value addr;
1608 for (regnum = r1, offset = 0;
1610 regnum++, offset += 8)
1612 compute_x_addr (&addr, gpr, d2 + offset, 0, b2);
1614 if (s390_store (&addr, 8, &gpr[regnum], gpr, spill, &back_chain)
1616 /* If we can't be sure that it's *not* a store to
1617 something we're tracing, then we would have to mark all
1618 our memory as unknown --- after all, it *could* be a
1619 store to any of them --- so we might as well just stop
1624 /* If we left the loop early, we should stop interpreting
1631 /* An instruction we don't know how to simulate. The only
1632 safe thing to do would be to set every value we're tracking
1633 to 'unknown'. Instead, we'll be optimistic: we just stop
1634 interpreting, and assume that the machine state we've got
1635 now is good enough for unwinding the stack. */
1638 /* Record the address after the last instruction that changed
1639 the FP, SP, or backlink. Ignore instructions that changed
1640 them back to their original values --- those are probably
1641 restore instructions. (The back chain is never restored,
1644 struct prologue_value *sp = &gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1645 struct prologue_value *fp = &gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1647 if ((! pv_is_identical (&pre_insn_sp, sp)
1648 && ! pv_is_register (sp, S390_SP_REGNUM, 0))
1649 || (! pv_is_identical (&pre_insn_fp, fp)
1650 && ! pv_is_register (fp, S390_FRAME_REGNUM, 0))
1651 || ! pv_is_identical (&pre_insn_back_chain, &back_chain))
1652 after_last_frame_setup_insn = next_pc;
1656 /* Okay, now gpr[], fpr[], spill[], and back_chain reflect the state
1657 of the machine as of the first instruction we couldn't interpret
1658 (hopefully the first non-prologue instruction). */
1660 /* The size of the frame, or (CORE_ADDR) -1 if we couldn't figure
1662 CORE_ADDR frame_size = -1;
1664 /* The value the SP had upon entry to the function, or
1665 (CORE_ADDR) -1 if we can't figure that out. */
1666 CORE_ADDR original_sp = -1;
1668 /* Are we using S390_FRAME_REGNUM as a frame pointer register? */
1669 int using_frame_pointer = 0;
1671 /* If S390_FRAME_REGNUM is some constant offset from the SP, then
1672 that strongly suggests that we're going to use that as our
1673 frame pointer register, not the SP. */
1675 struct prologue_value *fp = &gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1677 if (fp->kind == pv_register
1678 && fp->reg == S390_SP_REGNUM)
1679 using_frame_pointer = 1;
1682 /* If we were given a frame_info structure, we may be able to use
1683 the frame's base address to figure out the actual value of the
1685 if (fi && get_frame_base (fi))
1687 int frame_base_regno;
1688 struct prologue_value *frame_base;
1690 /* The meaning of the frame base depends on whether the
1691 function uses a frame pointer register other than the SP or
1692 not (see s390_read_fp):
1693 - If the function does use a frame pointer register other
1694 than the SP, then the frame base is that register's
1696 - If the function doesn't use a frame pointer, then the
1697 frame base is the SP itself.
1698 We're duplicating some of the logic of s390_fp_regnum here,
1699 but we don't want to call that, because it would just do
1700 exactly the same analysis we've already done above. */
1701 if (using_frame_pointer)
1702 frame_base_regno = S390_FRAME_REGNUM;
1704 frame_base_regno = S390_SP_REGNUM;
1706 frame_base = &gpr[frame_base_regno - S390_R0_REGNUM];
1708 /* We know the frame base address; if the value of whatever
1709 register it came from is a constant offset from the
1710 original SP, then we can reconstruct the original SP just
1711 by subtracting off that constant. */
1712 if (frame_base->kind == pv_register
1713 && frame_base->reg == S390_SP_REGNUM)
1714 original_sp = get_frame_base (fi) - frame_base->k;
1717 /* If the analysis said that the current SP value is the original
1718 value less some constant, then that constant is the frame size. */
1720 struct prologue_value *sp = &gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1722 if (sp->kind == pv_register
1723 && sp->reg == S390_SP_REGNUM)
1724 frame_size = -sp->k;
1727 /* If we knew other registers' current values, we could check if
1728 the analysis said any of those were related to the original SP
1729 value, too. But for now, we'll just punt. */
1731 /* If the caller passed in an 'extra info' structure, fill in the
1735 if (init_extra_info || ! fextra_info->initialised)
1737 s390_memset_extra_info (fextra_info);
1738 fextra_info->function_start = start_pc;
1739 fextra_info->initialised = 1;
1742 if (frame_size != -1)
1744 fextra_info->stack_bought_valid = 1;
1745 fextra_info->stack_bought = frame_size;
1748 /* Assume everything was okay, and indicate otherwise when we
1749 find something amiss. */
1750 fextra_info->good_prologue = 1;
1752 if (using_frame_pointer)
1753 /* Actually, nobody cares about the exact PC, so any
1754 non-zero value will do here. */
1755 fextra_info->frame_pointer_saved_pc = 1;
1757 /* If we weren't able to find the size of the frame, or find
1758 the original sp based on actual current register values,
1759 then we're not going to be able to unwind this frame.
1761 (If we're just doing prologue analysis to set a breakpoint,
1762 then frame_size might be known, but original_sp unknown; if
1763 we're analyzing a real frame which uses alloca, then
1764 original_sp might be known (from the frame pointer
1765 register), but the frame size might be unknown.) */
1766 if (original_sp == -1 && frame_size == -1)
1767 fextra_info->good_prologue = 0;
1769 if (fextra_info->good_prologue)
1770 fextra_info->skip_prologue_function_start
1771 = after_last_frame_setup_insn;
1773 /* If the prologue was too complex for us to make sense of,
1774 then perhaps it's better to just not skip anything at
1776 fextra_info->skip_prologue_function_start = start_pc;
1779 /* Indicate where registers were saved on the stack, if:
1780 - the caller seems to want to know,
1781 - the caller provided an actual SP, and
1782 - the analysis gave us enough information to actually figure it
1785 && deprecated_get_frame_saved_regs (fi)
1786 && original_sp != -1)
1789 CORE_ADDR slot_addr;
1790 CORE_ADDR *saved_regs = deprecated_get_frame_saved_regs (fi);
1792 /* Scan the spill array; if a spill slot says it holds the
1793 original value of some register, then record that slot's
1794 address as the place that register was saved.
1796 Just for kicks, note that, even if registers aren't saved
1797 in their officially-sanctioned slots, this will still work
1798 --- we know what really got put where. */
1800 /* First, the slots for r2 -- r15. */
1801 for (slot_num = 0, slot_addr = original_sp + 2 * S390_GPR_SIZE;
1803 slot_num++, slot_addr += S390_GPR_SIZE)
1805 struct prologue_value *slot = &spill[slot_num];
1807 if (slot->kind == pv_register
1809 saved_regs[slot->reg] = slot_addr;
1812 /* Then, the slots for f0, f2, f4, and f6. They're a
1814 for (slot_num = 14, slot_addr = original_sp + 16 * S390_GPR_SIZE;
1815 slot_num < S390_NUM_SPILL_SLOTS;
1816 slot_num++, slot_addr += S390_FPR_SIZE)
1818 struct prologue_value *slot = &spill[slot_num];
1820 if (slot->kind == pv_register
1822 saved_regs[slot->reg] = slot_addr;
1825 /* The stack pointer's element of saved_regs[] is special. */
1826 saved_regs[S390_SP_REGNUM] = original_sp;
1833 /* Return true if we are in the functin's epilogue, i.e. after the
1834 instruction that destroyed the function's stack frame. */
1836 s390_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
1838 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1840 /* In frameless functions, there's not frame to destroy and thus
1841 we don't care about the epilogue.
1843 In functions with frame, the epilogue sequence is a pair of
1844 a LM-type instruction that restores (amongst others) the
1845 return register %r14 and the stack pointer %r15, followed
1846 by a branch 'br %r14' --or equivalent-- that effects the
1849 In that situation, this function needs to return 'true' in
1850 exactly one case: when pc points to that branch instruction.
1852 Thus we try to disassemble the one instructions immediately
1853 preceeding pc and check whether it is an LM-type instruction
1854 modifying the stack pointer.
1856 Note that disassembling backwards is not reliable, so there
1857 is a slight chance of false positives here ... */
1860 unsigned int r1, r3, b2;
1864 && !read_memory_nobpt (pc - 4, insn, 4)
1865 && is_rs (insn, op_lm, &r1, &r3, &d2, &b2)
1866 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1870 && !read_memory_nobpt (pc - 6, insn, 6)
1871 && is_rse (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2)
1872 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1879 s390_check_function_end (CORE_ADDR pc)
1881 bfd_byte instr[S390_MAX_INSTR_SIZE];
1882 int regidx, instrlen;
1884 instrlen = s390_readinstruction (instr, pc);
1888 if (instrlen != 2 || instr[0] != 07 || (instr[1] >> 4) != 0xf)
1890 regidx = instr[1] & 0xf;
1891 /* Check for LMG or LG */
1893 s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4));
1896 if (GDB_TARGET_IS_ESAME)
1899 if (instrlen != 6 || instr[0] != 0xeb || instr[5] != 0x4)
1902 else if (instrlen != 4 || instr[0] != 0x98)
1906 if ((instr[2] >> 4) != 0xf)
1910 instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8));
1913 if (GDB_TARGET_IS_ESAME)
1916 if (instrlen != 6 || instr[0] != 0xe3 || instr[5] != 0x4)
1922 if (instrlen != 4 || instr[0] != 0x58)
1925 if (instr[2] >> 4 != 0xf)
1927 if (instr[1] >> 4 != regidx)
1933 s390_sniff_pc_function_start (CORE_ADDR pc, struct frame_info *fi)
1935 CORE_ADDR function_start, test_function_start;
1936 int loop_cnt, err, function_end;
1937 struct frame_extra_info fextra_info;
1938 function_start = get_pc_function_start (pc);
1940 if (function_start == 0)
1942 test_function_start = pc;
1943 if (test_function_start & 1)
1944 return 0; /* This has to be bogus */
1950 s390_get_frame_info (test_function_start, &fextra_info, fi, 1);
1952 test_function_start -= 2;
1953 function_end = s390_check_function_end (test_function_start);
1955 while (!(function_end == 1 || err || loop_cnt >= 4096 ||
1956 (fextra_info.good_prologue)));
1957 if (fextra_info.good_prologue)
1958 function_start = fextra_info.function_start;
1959 else if (function_end == 1)
1960 function_start = test_function_start;
1962 return function_start;
1967 s390_frameless_function_invocation (struct frame_info *fi)
1969 struct frame_extra_info fextra_info, *fextra_info_ptr;
1972 if (get_next_frame (fi) == NULL) /* no may be frameless */
1974 if (get_frame_extra_info (fi))
1975 fextra_info_ptr = get_frame_extra_info (fi);
1978 fextra_info_ptr = &fextra_info;
1979 s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi),
1980 fextra_info_ptr, fi, 1);
1982 frameless = (fextra_info_ptr->stack_bought_valid
1983 && fextra_info_ptr->stack_bought == 0);
1991 s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi,
1992 CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc)
1994 bfd_byte instr[S390_MAX_INSTR_SIZE];
1999 CORE_ADDR temp_sregs;
2001 scontext = temp_sregs = 0;
2003 instrlen = s390_readinstruction (instr, pc);
2006 if (((instrlen == S390_SYSCALL_SIZE) &&
2007 (instr[0] == S390_SYSCALL_OPCODE)) &&
2008 ((instr[1] == s390_NR_sigreturn) || (instr[1] == s390_NR_rt_sigreturn)))
2012 if (s390_frameless_function_invocation (sighandler_fi))
2013 orig_sp = get_frame_base (sighandler_fi);
2015 orig_sp = ADDR_BITS_REMOVE ((CORE_ADDR)
2016 read_memory_integer (get_frame_base (sighandler_fi),
2018 if (orig_sp && sigcaller_pc)
2020 scontext = orig_sp + S390_SIGNAL_FRAMESIZE;
2021 if (pc == scontext && instr[1] == s390_NR_rt_sigreturn)
2023 /* We got a new style rt_signal */
2024 /* get address of read ucontext->uc_mcontext */
2025 temp_sregs = orig_sp + (GDB_TARGET_IS_ESAME ?
2026 S390X_UC_MCONTEXT_OFFSET :
2027 S390_UC_MCONTEXT_OFFSET);
2031 /* read sigcontext->sregs */
2032 temp_sregs = ADDR_BITS_REMOVE ((CORE_ADDR)
2033 read_memory_integer (scontext
2035 (GDB_TARGET_IS_ESAME
2037 S390X_SIGCONTEXT_SREGS_OFFSET
2039 S390_SIGCONTEXT_SREGS_OFFSET),
2043 /* read sigregs->psw.addr */
2045 ADDR_BITS_REMOVE ((CORE_ADDR)
2046 read_memory_integer (temp_sregs +
2047 DEPRECATED_REGISTER_BYTE (S390_PSWA_REGNUM),
2054 *sregs = temp_sregs;
2059 We need to do something better here but this will keep us out of trouble
2061 For some reason the blockframe.c calls us with fi->next->fromleaf
2062 so this seems of little use to us. */
2064 s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi)
2066 CORE_ADDR sigcaller_pc;
2070 pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
2071 /* fix signal handlers */
2073 else if (get_next_frame (fi) && get_frame_pc (get_next_frame (fi)))
2074 pc = s390_frame_saved_pc_nofix (get_next_frame (fi));
2075 if (pc && get_next_frame (fi) && get_frame_base (get_next_frame (fi))
2076 && s390_is_sigreturn (pc, get_next_frame (fi), NULL, &sigcaller_pc))
2084 s390_init_extra_frame_info (int fromleaf, struct frame_info *fi)
2086 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
2087 if (get_frame_pc (fi))
2088 s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi),
2089 get_frame_extra_info (fi), fi, 1);
2091 s390_memset_extra_info (get_frame_extra_info (fi));
2094 /* If saved registers of frame FI are not known yet, read and cache them.
2095 &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL,
2096 in which case the framedata are read. */
2099 s390_frame_init_saved_regs (struct frame_info *fi)
2104 if (deprecated_get_frame_saved_regs (fi) == NULL)
2106 /* zalloc memsets the saved regs */
2107 frame_saved_regs_zalloc (fi);
2108 if (get_frame_pc (fi))
2110 quick = (get_frame_extra_info (fi)
2111 && get_frame_extra_info (fi)->initialised
2112 && get_frame_extra_info (fi)->good_prologue);
2113 s390_get_frame_info (quick
2114 ? get_frame_extra_info (fi)->function_start
2115 : s390_sniff_pc_function_start (get_frame_pc (fi), fi),
2116 get_frame_extra_info (fi), fi, !quick);
2124 s390_frame_saved_pc_nofix (struct frame_info *fi)
2126 if (get_frame_extra_info (fi) && get_frame_extra_info (fi)->saved_pc_valid)
2127 return get_frame_extra_info (fi)->saved_pc;
2129 if (deprecated_generic_find_dummy_frame (get_frame_pc (fi),
2130 get_frame_base (fi)))
2131 return deprecated_read_register_dummy (get_frame_pc (fi),
2132 get_frame_base (fi), S390_PC_REGNUM);
2134 s390_frame_init_saved_regs (fi);
2135 if (get_frame_extra_info (fi))
2137 get_frame_extra_info (fi)->saved_pc_valid = 1;
2138 if (get_frame_extra_info (fi)->good_prologue
2139 && deprecated_get_frame_saved_regs (fi)[S390_RETADDR_REGNUM])
2140 get_frame_extra_info (fi)->saved_pc
2141 = ADDR_BITS_REMOVE (read_memory_integer
2142 (deprecated_get_frame_saved_regs (fi)[S390_RETADDR_REGNUM],
2145 get_frame_extra_info (fi)->saved_pc
2146 = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
2147 return get_frame_extra_info (fi)->saved_pc;
2153 s390_frame_saved_pc (struct frame_info *fi)
2155 CORE_ADDR saved_pc = 0, sig_pc;
2157 if (get_frame_extra_info (fi)
2158 && get_frame_extra_info (fi)->sig_fixed_saved_pc_valid)
2159 return get_frame_extra_info (fi)->sig_fixed_saved_pc;
2160 saved_pc = s390_frame_saved_pc_nofix (fi);
2162 if (get_frame_extra_info (fi))
2164 get_frame_extra_info (fi)->sig_fixed_saved_pc_valid = 1;
2167 if (s390_is_sigreturn (saved_pc, fi, NULL, &sig_pc))
2170 get_frame_extra_info (fi)->sig_fixed_saved_pc = saved_pc;
2178 /* We want backtraces out of signal handlers so we don't set
2179 (get_frame_type (thisframe) == SIGTRAMP_FRAME) to 1 */
2182 s390_frame_chain (struct frame_info *thisframe)
2184 CORE_ADDR prev_fp = 0;
2186 if (deprecated_generic_find_dummy_frame (get_frame_pc (thisframe),
2187 get_frame_base (thisframe)))
2188 return deprecated_read_register_dummy (get_frame_pc (thisframe),
2189 get_frame_base (thisframe),
2194 CORE_ADDR sregs = 0;
2195 struct frame_extra_info prev_fextra_info;
2197 memset (&prev_fextra_info, 0, sizeof (prev_fextra_info));
2198 if (get_frame_pc (thisframe))
2200 CORE_ADDR saved_pc, sig_pc;
2202 saved_pc = s390_frame_saved_pc_nofix (thisframe);
2206 s390_is_sigreturn (saved_pc, thisframe, &sregs, &sig_pc)))
2208 s390_get_frame_info (s390_sniff_pc_function_start
2209 (saved_pc, NULL), &prev_fextra_info, NULL,
2215 /* read sigregs,regs.gprs[11 or 15] */
2216 prev_fp = read_memory_integer (sregs +
2217 DEPRECATED_REGISTER_BYTE (S390_R0_REGNUM +
2219 frame_pointer_saved_pc
2222 get_frame_extra_info (thisframe)->sigcontext = sregs;
2226 if (deprecated_get_frame_saved_regs (thisframe))
2230 if (prev_fextra_info.frame_pointer_saved_pc
2231 && deprecated_get_frame_saved_regs (thisframe)[S390_FRAME_REGNUM])
2232 regno = S390_FRAME_REGNUM;
2234 regno = S390_SP_REGNUM;
2236 if (deprecated_get_frame_saved_regs (thisframe)[regno])
2238 /* The SP's entry of `saved_regs' is special. */
2239 if (regno == S390_SP_REGNUM)
2240 prev_fp = deprecated_get_frame_saved_regs (thisframe)[regno];
2243 read_memory_integer (deprecated_get_frame_saved_regs (thisframe)[regno],
2249 return ADDR_BITS_REMOVE (prev_fp);
2253 Whether struct frame_extra_info is actually needed I'll have to figure
2254 out as our frames are similar to rs6000 there is a possibility
2255 i386 dosen't need it. */
2259 /* NOTE: cagney/2003-10-31: "return_value" makes
2260 "extract_struct_value_address", "extract_return_value", and
2261 "use_struct_convention" redundant. */
2263 s390_cannot_extract_struct_value_address (struct regcache *regcache)
2268 /* a given return value in `regbuf' with a type `valtype', extract and copy its
2269 value into `valbuf' */
2271 s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
2273 /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes.
2274 We need to truncate the return value into float size (4 byte) if
2276 int len = TYPE_LENGTH (valtype);
2278 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
2279 memcpy (valbuf, ®buf[DEPRECATED_REGISTER_BYTE (S390_F0_REGNUM)], len);
2283 /* return value is copied starting from r2. */
2284 if (TYPE_LENGTH (valtype) < S390_GPR_SIZE)
2285 offset = S390_GPR_SIZE - TYPE_LENGTH (valtype);
2287 regbuf + DEPRECATED_REGISTER_BYTE (S390_R0_REGNUM + 2) + offset,
2288 TYPE_LENGTH (valtype));
2294 s390_promote_integer_argument (struct type *valtype, char *valbuf,
2295 char *reg_buff, int *arglen)
2297 char *value = valbuf;
2298 int len = TYPE_LENGTH (valtype);
2300 if (len < S390_GPR_SIZE)
2302 /* We need to upgrade this value to a register to pass it correctly */
2303 int idx, diff = S390_GPR_SIZE - len, negative =
2304 (!TYPE_UNSIGNED (valtype) && value[0] & 0x80);
2305 for (idx = 0; idx < S390_GPR_SIZE; idx++)
2307 reg_buff[idx] = (idx < diff ? (negative ? 0xff : 0x0) :
2311 *arglen = S390_GPR_SIZE;
2315 if (len & (S390_GPR_SIZE - 1))
2317 fprintf_unfiltered (gdb_stderr,
2318 "s390_promote_integer_argument detected an argument not "
2319 "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE "
2320 "we might not deal with this correctly.\n");
2329 s390_store_return_value (struct type *valtype, char *valbuf)
2332 char *reg_buff = alloca (max (S390_FPR_SIZE, S390_GPR_SIZE)), *value;
2334 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
2336 if (TYPE_LENGTH (valtype) == 4
2337 || TYPE_LENGTH (valtype) == 8)
2338 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_F0_REGNUM),
2339 valbuf, TYPE_LENGTH (valtype));
2341 error ("GDB is unable to return `long double' values "
2342 "on this architecture.");
2347 s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen);
2348 /* Everything else is returned in GPR2 and up. */
2349 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_R0_REGNUM + 2),
2355 /* Not the most efficent code in the world */
2357 s390_fp_regnum (void)
2359 int regno = S390_SP_REGNUM;
2360 struct frame_extra_info fextra_info;
2362 CORE_ADDR pc = ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM));
2364 s390_get_frame_info (s390_sniff_pc_function_start (pc, NULL), &fextra_info,
2366 if (fextra_info.frame_pointer_saved_pc)
2367 regno = S390_FRAME_REGNUM;
2374 return read_register (s390_fp_regnum ());
2379 s390_pop_frame_regular (struct frame_info *frame)
2383 write_register (S390_PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
2385 /* Restore any saved registers. */
2386 if (deprecated_get_frame_saved_regs (frame))
2388 for (regnum = 0; regnum < NUM_REGS; regnum++)
2389 if (deprecated_get_frame_saved_regs (frame)[regnum] != 0)
2393 value = read_memory_unsigned_integer (deprecated_get_frame_saved_regs (frame)[regnum],
2394 DEPRECATED_REGISTER_RAW_SIZE (regnum));
2395 write_register (regnum, value);
2398 /* Actually cut back the stack. Remember that the SP's element of
2399 saved_regs is the old SP itself, not the address at which it is
2401 write_register (S390_SP_REGNUM, deprecated_get_frame_saved_regs (frame)[S390_SP_REGNUM]);
2404 /* Throw away any cached frame information. */
2405 flush_cached_frames ();
2409 /* Destroy the innermost (Top-Of-Stack) stack frame, restoring the
2410 machine state that was in effect before the frame was created.
2411 Used in the contexts of the "return" command, and of
2412 target function calls from the debugger. */
2414 s390_pop_frame (void)
2416 /* This function checks for and handles generic dummy frames, and
2417 calls back to our function for ordinary frames. */
2418 generic_pop_current_frame (s390_pop_frame_regular);
2422 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
2423 "Integer-like" types are those that should be passed the way
2424 integers are: integers, enums, ranges, characters, and booleans. */
2426 is_integer_like (struct type *type)
2428 enum type_code code = TYPE_CODE (type);
2430 return (code == TYPE_CODE_INT
2431 || code == TYPE_CODE_ENUM
2432 || code == TYPE_CODE_RANGE
2433 || code == TYPE_CODE_CHAR
2434 || code == TYPE_CODE_BOOL);
2438 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
2439 "Pointer-like" types are those that should be passed the way
2440 pointers are: pointers and references. */
2442 is_pointer_like (struct type *type)
2444 enum type_code code = TYPE_CODE (type);
2446 return (code == TYPE_CODE_PTR
2447 || code == TYPE_CODE_REF);
2451 /* Return non-zero if TYPE is a `float singleton' or `double
2452 singleton', zero otherwise.
2454 A `T singleton' is a struct type with one member, whose type is
2455 either T or a `T singleton'. So, the following are all float
2459 struct { struct { float x; } x; };
2460 struct { struct { struct { float x; } x; } x; };
2464 WHY THE HECK DO WE CARE ABOUT THIS??? Well, it turns out that GCC
2465 passes all float singletons and double singletons as if they were
2466 simply floats or doubles. This is *not* what the ABI says it
2469 is_float_singleton (struct type *type)
2471 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
2472 && TYPE_NFIELDS (type) == 1
2473 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT
2474 || is_float_singleton (TYPE_FIELD_TYPE (type, 0))));
2478 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
2479 "Struct-like" types are those that should be passed as structs are:
2482 As an odd quirk, not mentioned in the ABI, GCC passes float and
2483 double singletons as if they were a plain float, double, etc. (The
2484 corresponding union types are handled normally.) So we exclude
2485 those types here. *shrug* */
2487 is_struct_like (struct type *type)
2489 enum type_code code = TYPE_CODE (type);
2491 return (code == TYPE_CODE_UNION
2492 || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type)));
2496 /* Return non-zero if TYPE is a float-like type, zero otherwise.
2497 "Float-like" types are those that should be passed as
2498 floating-point values are.
2500 You'd think this would just be floats, doubles, long doubles, etc.
2501 But as an odd quirk, not mentioned in the ABI, GCC passes float and
2502 double singletons as if they were a plain float, double, etc. (The
2503 corresponding union types are handled normally.) So we include
2504 those types here. *shrug* */
2506 is_float_like (struct type *type)
2508 return (TYPE_CODE (type) == TYPE_CODE_FLT
2509 || is_float_singleton (type));
2513 /* Return non-zero if TYPE is considered a `DOUBLE_OR_FLOAT', as
2514 defined by the parameter passing conventions described in the
2515 "GNU/Linux for S/390 ELF Application Binary Interface Supplement".
2516 Otherwise, return zero. */
2518 is_double_or_float (struct type *type)
2520 return (is_float_like (type)
2521 && (TYPE_LENGTH (type) == 4
2522 || TYPE_LENGTH (type) == 8));
2526 /* Return non-zero if TYPE is a `DOUBLE_ARG', as defined by the
2527 parameter passing conventions described in the "GNU/Linux for S/390
2528 ELF Application Binary Interface Supplement". Return zero
2531 is_double_arg (struct type *type)
2533 unsigned length = TYPE_LENGTH (type);
2535 /* The s390x ABI doesn't handle DOUBLE_ARGS specially. */
2536 if (GDB_TARGET_IS_ESAME)
2539 return ((is_integer_like (type)
2540 || is_struct_like (type))
2545 /* Return non-zero if TYPE is considered a `SIMPLE_ARG', as defined by
2546 the parameter passing conventions described in the "GNU/Linux for
2547 S/390 ELF Application Binary Interface Supplement". Return zero
2550 is_simple_arg (struct type *type)
2552 unsigned length = TYPE_LENGTH (type);
2554 /* This is almost a direct translation of the ABI's language, except
2555 that we have to exclude 8-byte structs; those are DOUBLE_ARGs. */
2556 return ((is_integer_like (type) && length <= S390_GPR_SIZE)
2557 || is_pointer_like (type)
2558 || (is_struct_like (type) && !is_double_arg (type)));
2563 is_power_of_two (unsigned int n)
2565 return ((n & (n - 1)) == 0);
2568 /* Return non-zero if TYPE should be passed as a pointer to a copy,
2569 zero otherwise. TYPE must be a SIMPLE_ARG, as recognized by
2572 pass_by_copy_ref (struct type *type)
2574 unsigned length = TYPE_LENGTH (type);
2576 return (is_struct_like (type)
2577 && !(is_power_of_two (length) && length <= S390_GPR_SIZE));
2581 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
2582 word as required for the ABI. */
2584 extend_simple_arg (struct value *arg)
2586 struct type *type = VALUE_TYPE (arg);
2588 /* Even structs get passed in the least significant bits of the
2589 register / memory word. It's not really right to extract them as
2590 an integer, but it does take care of the extension. */
2591 if (TYPE_UNSIGNED (type))
2592 return extract_unsigned_integer (VALUE_CONTENTS (arg),
2593 TYPE_LENGTH (type));
2595 return extract_signed_integer (VALUE_CONTENTS (arg),
2596 TYPE_LENGTH (type));
2600 /* Return the alignment required by TYPE. */
2602 alignment_of (struct type *type)
2606 if (is_integer_like (type)
2607 || is_pointer_like (type)
2608 || TYPE_CODE (type) == TYPE_CODE_FLT)
2609 alignment = TYPE_LENGTH (type);
2610 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
2611 || TYPE_CODE (type) == TYPE_CODE_UNION)
2616 for (i = 0; i < TYPE_NFIELDS (type); i++)
2618 int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i));
2620 if (field_alignment > alignment)
2621 alignment = field_alignment;
2627 /* Check that everything we ever return is a power of two. Lots of
2628 code doesn't want to deal with aligning things to arbitrary
2630 gdb_assert ((alignment & (alignment - 1)) == 0);
2636 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2637 place to be passed to a function, as specified by the "GNU/Linux
2638 for S/390 ELF Application Binary Interface Supplement".
2640 SP is the current stack pointer. We must put arguments, links,
2641 padding, etc. whereever they belong, and return the new stack
2644 If STRUCT_RETURN is non-zero, then the function we're calling is
2645 going to return a structure by value; STRUCT_ADDR is the address of
2646 a block we've allocated for it on the stack.
2648 Our caller has taken care of any type promotions needed to satisfy
2649 prototypes or the old K&R argument-passing rules. */
2651 s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
2652 int struct_return, CORE_ADDR struct_addr)
2655 int pointer_size = (TARGET_PTR_BIT / TARGET_CHAR_BIT);
2657 /* The number of arguments passed by reference-to-copy. */
2660 /* If the i'th argument is passed as a reference to a copy, then
2661 copy_addr[i] is the address of the copy we made. */
2662 CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR));
2664 /* Build the reference-to-copy area. */
2666 for (i = 0; i < nargs; i++)
2668 struct value *arg = args[i];
2669 struct type *type = VALUE_TYPE (arg);
2670 unsigned length = TYPE_LENGTH (type);
2672 if (is_simple_arg (type)
2673 && pass_by_copy_ref (type))
2676 sp = align_down (sp, alignment_of (type));
2677 write_memory (sp, VALUE_CONTENTS (arg), length);
2683 /* Reserve space for the parameter area. As a conservative
2684 simplification, we assume that everything will be passed on the
2689 for (i = 0; i < nargs; i++)
2691 struct value *arg = args[i];
2692 struct type *type = VALUE_TYPE (arg);
2693 int length = TYPE_LENGTH (type);
2695 sp = align_down (sp, alignment_of (type));
2697 /* SIMPLE_ARG values get extended to S390_GPR_SIZE bytes.
2698 Assume every argument is. */
2699 if (length < S390_GPR_SIZE) length = S390_GPR_SIZE;
2704 /* Include space for any reference-to-copy pointers. */
2705 sp = align_down (sp, pointer_size);
2706 sp -= num_copies * pointer_size;
2708 /* After all that, make sure it's still aligned on an eight-byte
2710 sp = align_down (sp, 8);
2712 /* Finally, place the actual parameters, working from SP towards
2713 higher addresses. The code above is supposed to reserve enough
2718 CORE_ADDR starg = sp;
2720 /* A struct is returned using general register 2 */
2724 for (i = 0; i < nargs; i++)
2726 struct value *arg = args[i];
2727 struct type *type = VALUE_TYPE (arg);
2729 if (is_double_or_float (type)
2730 && fr <= S390_NUM_FP_PARAMETER_REGISTERS * 2 - 2)
2732 /* When we store a single-precision value in an FP register,
2733 it occupies the leftmost bits. */
2734 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_F0_REGNUM + fr),
2735 VALUE_CONTENTS (arg),
2736 TYPE_LENGTH (type));
2739 else if (is_simple_arg (type)
2742 /* Do we need to pass a pointer to our copy of this
2744 if (pass_by_copy_ref (type))
2745 write_register (S390_R0_REGNUM + gr, copy_addr[i]);
2747 write_register (S390_R0_REGNUM + gr, extend_simple_arg (arg));
2751 else if (is_double_arg (type)
2754 deprecated_write_register_gen (S390_R0_REGNUM + gr,
2755 VALUE_CONTENTS (arg));
2756 deprecated_write_register_gen (S390_R0_REGNUM + gr + 1,
2757 VALUE_CONTENTS (arg) + S390_GPR_SIZE);
2762 /* The `OTHER' case. */
2763 enum type_code code = TYPE_CODE (type);
2764 unsigned length = TYPE_LENGTH (type);
2766 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2767 in it, then don't go back and use it again later. */
2768 if (is_double_arg (type) && gr == 6)
2771 if (is_simple_arg (type))
2773 /* Simple args are always extended to
2774 S390_GPR_SIZE bytes. */
2775 starg = align_up (starg, S390_GPR_SIZE);
2777 /* Do we need to pass a pointer to our copy of this
2779 if (pass_by_copy_ref (type))
2780 write_memory_signed_integer (starg, pointer_size,
2783 /* Simple args are always extended to
2784 S390_GPR_SIZE bytes. */
2785 write_memory_signed_integer (starg, S390_GPR_SIZE,
2786 extend_simple_arg (arg));
2787 starg += S390_GPR_SIZE;
2791 /* You'd think we should say:
2792 starg = align_up (starg, alignment_of (type));
2793 Unfortunately, GCC seems to simply align the stack on
2794 a four/eight-byte boundary, even when passing doubles. */
2795 starg = align_up (starg, S390_STACK_PARAMETER_ALIGNMENT);
2796 write_memory (starg, VALUE_CONTENTS (arg), length);
2803 /* Allocate the standard frame areas: the register save area, the
2804 word reserved for the compiler (which seems kind of meaningless),
2805 and the back chain pointer. */
2806 sp -= S390_STACK_FRAME_OVERHEAD;
2808 /* Write the back chain pointer into the first word of the stack
2809 frame. This will help us get backtraces from within functions
2811 write_memory_unsigned_integer (sp, (TARGET_PTR_BIT / TARGET_CHAR_BIT),
2812 deprecated_read_fp ());
2819 s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2821 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2822 always be aligned on an eight-byte boundary. */
2828 s390_use_struct_convention (int gcc_p, struct type *value_type)
2830 enum type_code code = TYPE_CODE (value_type);
2832 return (code == TYPE_CODE_STRUCT
2833 || code == TYPE_CODE_UNION);
2837 s390_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
2839 write_register (S390_R0_REGNUM + 2, addr);
2844 static const unsigned char *
2845 s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
2847 static unsigned char breakpoint[] = { 0x0, 0x1 };
2849 *lenptr = sizeof (breakpoint);
2853 /* Advance PC across any function entry prologue instructions to reach some
2856 s390_skip_prologue (CORE_ADDR pc)
2858 struct frame_extra_info fextra_info;
2860 s390_get_frame_info (pc, &fextra_info, NULL, 1);
2861 return fextra_info.skip_prologue_function_start;
2864 /* Immediately after a function call, return the saved pc.
2865 Can't go through the frames for this because on some machines
2866 the new frame is not set up until the new function executes
2867 some instructions. */
2869 s390_saved_pc_after_call (struct frame_info *frame)
2871 return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
2875 s390_addr_bits_remove (CORE_ADDR addr)
2877 return (addr) & 0x7fffffff;
2882 s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
2884 write_register (S390_RETADDR_REGNUM, entry_point_address ());
2889 s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
2892 return TYPE_FLAG_ADDRESS_CLASS_1;
2898 s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
2900 if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1)
2907 s390_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name,
2908 int *type_flags_ptr)
2910 if (strcmp (name, "mode32") == 0)
2912 *type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1;
2919 static struct gdbarch *
2920 s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2922 static LONGEST s390_call_dummy_words[] = { 0 };
2923 struct gdbarch *gdbarch;
2924 struct gdbarch_tdep *tdep;
2927 /* First see if there is already a gdbarch that can satisfy the request. */
2928 arches = gdbarch_list_lookup_by_info (arches, &info);
2930 return arches->gdbarch;
2932 /* None found: is the request for a s390 architecture? */
2933 if (info.bfd_arch_info->arch != bfd_arch_s390)
2934 return NULL; /* No; then it's not for us. */
2936 /* Yes: create a new gdbarch for the specified machine type. */
2937 tdep = XCALLOC (1, struct gdbarch_tdep);
2938 gdbarch = gdbarch_alloc (&info, tdep);
2940 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
2941 ready to unwind the PC first (see frame.c:get_prev_frame()). */
2942 set_gdbarch_deprecated_init_frame_pc (gdbarch, deprecated_init_frame_pc_default);
2944 set_gdbarch_believe_pcc_promotion (gdbarch, 0);
2945 set_gdbarch_char_signed (gdbarch, 0);
2947 set_gdbarch_deprecated_frame_chain (gdbarch, s390_frame_chain);
2948 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, s390_frame_init_saved_regs);
2949 set_gdbarch_deprecated_store_struct_return (gdbarch, s390_store_struct_return);
2950 set_gdbarch_deprecated_extract_return_value (gdbarch, s390_extract_return_value);
2951 set_gdbarch_deprecated_store_return_value (gdbarch, s390_store_return_value);
2952 /* Amount PC must be decremented by after a breakpoint. This is
2953 often the number of bytes returned by BREAKPOINT_FROM_PC but not
2955 set_gdbarch_decr_pc_after_break (gdbarch, 2);
2956 set_gdbarch_deprecated_pop_frame (gdbarch, s390_pop_frame);
2957 /* Stack grows downward. */
2958 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2959 set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc);
2960 set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
2961 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, s390_init_extra_frame_info);
2962 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, s390_init_frame_pc_first);
2963 set_gdbarch_deprecated_target_read_fp (gdbarch, s390_read_fp);
2964 set_gdbarch_in_function_epilogue_p (gdbarch, s390_in_function_epilogue_p);
2965 /* This function that tells us whether the function invocation represented
2966 by FI does not have a frame on the stack associated with it. If it
2967 does not, FRAMELESS is set to 1, else 0. */
2968 set_gdbarch_deprecated_frameless_function_invocation (gdbarch, s390_frameless_function_invocation);
2969 /* Return saved PC from a frame */
2970 set_gdbarch_deprecated_frame_saved_pc (gdbarch, s390_frame_saved_pc);
2971 /* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and
2972 produces the frame's chain-pointer. */
2973 set_gdbarch_deprecated_frame_chain (gdbarch, s390_frame_chain);
2974 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, s390_saved_pc_after_call);
2975 set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM);
2976 set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM);
2977 set_gdbarch_deprecated_fp_regnum (gdbarch, S390_SP_REGNUM);
2978 set_gdbarch_fp0_regnum (gdbarch, S390_F0_REGNUM);
2979 set_gdbarch_num_regs (gdbarch, S390_NUM_REGS);
2980 set_gdbarch_num_pseudo_regs (gdbarch, S390_NUM_PSEUDO_REGS);
2981 set_gdbarch_use_struct_convention (gdbarch, s390_use_struct_convention);
2982 set_gdbarch_register_name (gdbarch, s390_register_name);
2983 set_gdbarch_register_type (gdbarch, s390_register_type);
2984 set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2985 set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2986 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2987 set_gdbarch_convert_register_p (gdbarch, s390_convert_register_p);
2988 set_gdbarch_register_to_value (gdbarch, s390_register_to_value);
2989 set_gdbarch_value_to_register (gdbarch, s390_value_to_register);
2990 set_gdbarch_register_reggroup_p (gdbarch, s390_register_reggroup_p);
2991 set_gdbarch_regset_from_core_section (gdbarch,
2992 s390_regset_from_core_section);
2993 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, s390_cannot_extract_struct_value_address);
2995 /* Parameters for inferior function calls. */
2996 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
2997 set_gdbarch_frame_align (gdbarch, s390_frame_align);
2998 set_gdbarch_deprecated_push_arguments (gdbarch, s390_push_arguments);
2999 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
3000 set_gdbarch_deprecated_push_return_address (gdbarch,
3001 s390_push_return_address);
3002 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (s390_call_dummy_words));
3003 set_gdbarch_deprecated_call_dummy_words (gdbarch, s390_call_dummy_words);
3005 switch (info.bfd_arch_info->mach)
3007 case bfd_mach_s390_31:
3008 tdep->gregset = &s390_gregset;
3009 tdep->sizeof_gregset = s390_sizeof_gregset;
3010 tdep->fpregset = &s390_fpregset;
3011 tdep->sizeof_fpregset = s390_sizeof_fpregset;
3013 set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
3014 set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
3015 set_gdbarch_pseudo_register_write (gdbarch, s390_pseudo_register_write);
3017 case bfd_mach_s390_64:
3018 tdep->gregset = &s390x_gregset;
3019 tdep->sizeof_gregset = s390x_sizeof_gregset;
3020 tdep->fpregset = &s390_fpregset;
3021 tdep->sizeof_fpregset = s390_sizeof_fpregset;
3023 set_gdbarch_long_bit (gdbarch, 64);
3024 set_gdbarch_long_long_bit (gdbarch, 64);
3025 set_gdbarch_ptr_bit (gdbarch, 64);
3026 set_gdbarch_pseudo_register_read (gdbarch, s390x_pseudo_register_read);
3027 set_gdbarch_pseudo_register_write (gdbarch, s390x_pseudo_register_write);
3028 set_gdbarch_address_class_type_flags (gdbarch,
3029 s390_address_class_type_flags);
3030 set_gdbarch_address_class_type_flags_to_name (gdbarch,
3031 s390_address_class_type_flags_to_name);
3032 set_gdbarch_address_class_name_to_type_flags (gdbarch,
3033 s390_address_class_name_to_type_flags);
3037 /* Should be using push_dummy_call. */
3038 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
3040 set_gdbarch_print_insn (gdbarch, print_insn_s390);
3047 extern initialize_file_ftype _initialize_s390_tdep; /* -Wmissing-prototypes */
3050 _initialize_s390_tdep (void)
3053 /* Hook us into the gdbarch mechanism. */
3054 register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init);