1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
4 Free Software Foundation, Inc.
6 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
7 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
27 #include "arch-utils.h"
35 #include "floatformat.h"
37 #include "trad-frame.h"
38 #include "frame-base.h"
39 #include "frame-unwind.h"
40 #include "dwarf2-frame.h"
41 #include "reggroups.h"
44 #include "gdb_assert.h"
46 #include "solib-svr4.h"
48 #include "s390-tdep.h"
51 /* The tdep structure. */
56 enum { ABI_LINUX_S390
, ABI_LINUX_ZSERIES
} abi
;
58 /* Core file register sets. */
59 const struct regset
*gregset
;
62 const struct regset
*fpregset
;
67 /* Register information. */
69 struct s390_register_info
75 static struct s390_register_info s390_register_info
[S390_NUM_TOTAL_REGS
] =
77 /* Program Status Word. */
78 { "pswm", &builtin_type_long
},
79 { "pswa", &builtin_type_long
},
81 /* General Purpose Registers. */
82 { "r0", &builtin_type_long
},
83 { "r1", &builtin_type_long
},
84 { "r2", &builtin_type_long
},
85 { "r3", &builtin_type_long
},
86 { "r4", &builtin_type_long
},
87 { "r5", &builtin_type_long
},
88 { "r6", &builtin_type_long
},
89 { "r7", &builtin_type_long
},
90 { "r8", &builtin_type_long
},
91 { "r9", &builtin_type_long
},
92 { "r10", &builtin_type_long
},
93 { "r11", &builtin_type_long
},
94 { "r12", &builtin_type_long
},
95 { "r13", &builtin_type_long
},
96 { "r14", &builtin_type_long
},
97 { "r15", &builtin_type_long
},
99 /* Access Registers. */
100 { "acr0", &builtin_type_int
},
101 { "acr1", &builtin_type_int
},
102 { "acr2", &builtin_type_int
},
103 { "acr3", &builtin_type_int
},
104 { "acr4", &builtin_type_int
},
105 { "acr5", &builtin_type_int
},
106 { "acr6", &builtin_type_int
},
107 { "acr7", &builtin_type_int
},
108 { "acr8", &builtin_type_int
},
109 { "acr9", &builtin_type_int
},
110 { "acr10", &builtin_type_int
},
111 { "acr11", &builtin_type_int
},
112 { "acr12", &builtin_type_int
},
113 { "acr13", &builtin_type_int
},
114 { "acr14", &builtin_type_int
},
115 { "acr15", &builtin_type_int
},
117 /* Floating Point Control Word. */
118 { "fpc", &builtin_type_int
},
120 /* Floating Point Registers. */
121 { "f0", &builtin_type_double
},
122 { "f1", &builtin_type_double
},
123 { "f2", &builtin_type_double
},
124 { "f3", &builtin_type_double
},
125 { "f4", &builtin_type_double
},
126 { "f5", &builtin_type_double
},
127 { "f6", &builtin_type_double
},
128 { "f7", &builtin_type_double
},
129 { "f8", &builtin_type_double
},
130 { "f9", &builtin_type_double
},
131 { "f10", &builtin_type_double
},
132 { "f11", &builtin_type_double
},
133 { "f12", &builtin_type_double
},
134 { "f13", &builtin_type_double
},
135 { "f14", &builtin_type_double
},
136 { "f15", &builtin_type_double
},
138 /* Pseudo registers. */
139 { "pc", &builtin_type_void_func_ptr
},
140 { "cc", &builtin_type_int
},
143 /* Return the name of register REGNUM. */
145 s390_register_name (int regnum
)
147 gdb_assert (regnum
>= 0 && regnum
< S390_NUM_TOTAL_REGS
);
148 return s390_register_info
[regnum
].name
;
151 /* Return the GDB type object for the "standard" data type of data in
154 s390_register_type (struct gdbarch
*gdbarch
, int regnum
)
156 gdb_assert (regnum
>= 0 && regnum
< S390_NUM_TOTAL_REGS
);
157 return *s390_register_info
[regnum
].type
;
160 /* DWARF Register Mapping. */
162 static int s390_dwarf_regmap
[] =
164 /* General Purpose Registers. */
165 S390_R0_REGNUM
, S390_R1_REGNUM
, S390_R2_REGNUM
, S390_R3_REGNUM
,
166 S390_R4_REGNUM
, S390_R5_REGNUM
, S390_R6_REGNUM
, S390_R7_REGNUM
,
167 S390_R8_REGNUM
, S390_R9_REGNUM
, S390_R10_REGNUM
, S390_R11_REGNUM
,
168 S390_R12_REGNUM
, S390_R13_REGNUM
, S390_R14_REGNUM
, S390_R15_REGNUM
,
170 /* Floating Point Registers. */
171 S390_F0_REGNUM
, S390_F2_REGNUM
, S390_F4_REGNUM
, S390_F6_REGNUM
,
172 S390_F1_REGNUM
, S390_F3_REGNUM
, S390_F5_REGNUM
, S390_F7_REGNUM
,
173 S390_F8_REGNUM
, S390_F10_REGNUM
, S390_F12_REGNUM
, S390_F14_REGNUM
,
174 S390_F9_REGNUM
, S390_F11_REGNUM
, S390_F13_REGNUM
, S390_F15_REGNUM
,
176 /* Control Registers (not mapped). */
177 -1, -1, -1, -1, -1, -1, -1, -1,
178 -1, -1, -1, -1, -1, -1, -1, -1,
180 /* Access Registers. */
181 S390_A0_REGNUM
, S390_A1_REGNUM
, S390_A2_REGNUM
, S390_A3_REGNUM
,
182 S390_A4_REGNUM
, S390_A5_REGNUM
, S390_A6_REGNUM
, S390_A7_REGNUM
,
183 S390_A8_REGNUM
, S390_A9_REGNUM
, S390_A10_REGNUM
, S390_A11_REGNUM
,
184 S390_A12_REGNUM
, S390_A13_REGNUM
, S390_A14_REGNUM
, S390_A15_REGNUM
,
186 /* Program Status Word. */
191 /* Convert DWARF register number REG to the appropriate register
192 number used by GDB. */
194 s390_dwarf_reg_to_regnum (int reg
)
198 if (reg
>= 0 && reg
< ARRAY_SIZE (s390_dwarf_regmap
))
199 regnum
= s390_dwarf_regmap
[reg
];
202 warning (_("Unmapped DWARF Register #%d encountered."), reg
);
207 /* Pseudo registers - PC and condition code. */
210 s390_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
211 int regnum
, gdb_byte
*buf
)
218 regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &val
);
219 store_unsigned_integer (buf
, 4, val
& 0x7fffffff);
223 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &val
);
224 store_unsigned_integer (buf
, 4, (val
>> 12) & 3);
228 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
233 s390_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
234 int regnum
, const gdb_byte
*buf
)
241 val
= extract_unsigned_integer (buf
, 4);
242 regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &psw
);
243 psw
= (psw
& 0x80000000) | (val
& 0x7fffffff);
244 regcache_raw_write_unsigned (regcache
, S390_PSWA_REGNUM
, psw
);
248 val
= extract_unsigned_integer (buf
, 4);
249 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &psw
);
250 psw
= (psw
& ~((ULONGEST
)3 << 12)) | ((val
& 3) << 12);
251 regcache_raw_write_unsigned (regcache
, S390_PSWM_REGNUM
, psw
);
255 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
260 s390x_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
261 int regnum
, gdb_byte
*buf
)
268 regcache_raw_read (regcache
, S390_PSWA_REGNUM
, buf
);
272 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &val
);
273 store_unsigned_integer (buf
, 4, (val
>> 44) & 3);
277 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
282 s390x_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
283 int regnum
, const gdb_byte
*buf
)
290 regcache_raw_write (regcache
, S390_PSWA_REGNUM
, buf
);
294 val
= extract_unsigned_integer (buf
, 4);
295 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &psw
);
296 psw
= (psw
& ~((ULONGEST
)3 << 44)) | ((val
& 3) << 44);
297 regcache_raw_write_unsigned (regcache
, S390_PSWM_REGNUM
, psw
);
301 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
305 /* 'float' values are stored in the upper half of floating-point
306 registers, even though we are otherwise a big-endian platform. */
309 s390_convert_register_p (int regno
, struct type
*type
)
311 return (regno
>= S390_F0_REGNUM
&& regno
<= S390_F15_REGNUM
)
312 && TYPE_LENGTH (type
) < 8;
316 s390_register_to_value (struct frame_info
*frame
, int regnum
,
317 struct type
*valtype
, gdb_byte
*out
)
320 int len
= TYPE_LENGTH (valtype
);
321 gdb_assert (len
< 8);
323 get_frame_register (frame
, regnum
, in
);
324 memcpy (out
, in
, len
);
328 s390_value_to_register (struct frame_info
*frame
, int regnum
,
329 struct type
*valtype
, const gdb_byte
*in
)
332 int len
= TYPE_LENGTH (valtype
);
333 gdb_assert (len
< 8);
336 memcpy (out
, in
, len
);
337 put_frame_register (frame
, regnum
, out
);
340 /* Register groups. */
343 s390_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
344 struct reggroup
*group
)
346 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
348 /* Registers displayed via 'info regs'. */
349 if (group
== general_reggroup
)
350 return (regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R15_REGNUM
)
351 || regnum
== S390_PC_REGNUM
352 || regnum
== S390_CC_REGNUM
;
354 /* Registers displayed via 'info float'. */
355 if (group
== float_reggroup
)
356 return (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
)
357 || regnum
== S390_FPC_REGNUM
;
359 /* Registers that need to be saved/restored in order to
360 push or pop frames. */
361 if (group
== save_reggroup
|| group
== restore_reggroup
)
362 return regnum
!= S390_PSWM_REGNUM
&& regnum
!= S390_PSWA_REGNUM
;
364 return default_register_reggroup_p (gdbarch
, regnum
, group
);
368 /* Core file register sets. */
370 int s390_regmap_gregset
[S390_NUM_REGS
] =
372 /* Program Status Word. */
374 /* General Purpose Registers. */
375 0x08, 0x0c, 0x10, 0x14,
376 0x18, 0x1c, 0x20, 0x24,
377 0x28, 0x2c, 0x30, 0x34,
378 0x38, 0x3c, 0x40, 0x44,
379 /* Access Registers. */
380 0x48, 0x4c, 0x50, 0x54,
381 0x58, 0x5c, 0x60, 0x64,
382 0x68, 0x6c, 0x70, 0x74,
383 0x78, 0x7c, 0x80, 0x84,
384 /* Floating Point Control Word. */
386 /* Floating Point Registers. */
387 -1, -1, -1, -1, -1, -1, -1, -1,
388 -1, -1, -1, -1, -1, -1, -1, -1,
391 int s390x_regmap_gregset
[S390_NUM_REGS
] =
394 /* General Purpose Registers. */
395 0x10, 0x18, 0x20, 0x28,
396 0x30, 0x38, 0x40, 0x48,
397 0x50, 0x58, 0x60, 0x68,
398 0x70, 0x78, 0x80, 0x88,
399 /* Access Registers. */
400 0x90, 0x94, 0x98, 0x9c,
401 0xa0, 0xa4, 0xa8, 0xac,
402 0xb0, 0xb4, 0xb8, 0xbc,
403 0xc0, 0xc4, 0xc8, 0xcc,
404 /* Floating Point Control Word. */
406 /* Floating Point Registers. */
407 -1, -1, -1, -1, -1, -1, -1, -1,
408 -1, -1, -1, -1, -1, -1, -1, -1,
411 int s390_regmap_fpregset
[S390_NUM_REGS
] =
413 /* Program Status Word. */
415 /* General Purpose Registers. */
416 -1, -1, -1, -1, -1, -1, -1, -1,
417 -1, -1, -1, -1, -1, -1, -1, -1,
418 /* Access Registers. */
419 -1, -1, -1, -1, -1, -1, -1, -1,
420 -1, -1, -1, -1, -1, -1, -1, -1,
421 /* Floating Point Control Word. */
423 /* Floating Point Registers. */
424 0x08, 0x10, 0x18, 0x20,
425 0x28, 0x30, 0x38, 0x40,
426 0x48, 0x50, 0x58, 0x60,
427 0x68, 0x70, 0x78, 0x80,
430 /* Supply register REGNUM from the register set REGSET to register cache
431 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
433 s390_supply_regset (const struct regset
*regset
, struct regcache
*regcache
,
434 int regnum
, const void *regs
, size_t len
)
436 const int *offset
= regset
->descr
;
439 for (i
= 0; i
< S390_NUM_REGS
; i
++)
441 if ((regnum
== i
|| regnum
== -1) && offset
[i
] != -1)
442 regcache_raw_supply (regcache
, i
, (const char *)regs
+ offset
[i
]);
446 static const struct regset s390_gregset
= {
451 static const struct regset s390x_gregset
= {
452 s390x_regmap_gregset
,
456 static const struct regset s390_fpregset
= {
457 s390_regmap_fpregset
,
461 /* Return the appropriate register set for the core section identified
462 by SECT_NAME and SECT_SIZE. */
463 const struct regset
*
464 s390_regset_from_core_section (struct gdbarch
*gdbarch
,
465 const char *sect_name
, size_t sect_size
)
467 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
469 if (strcmp (sect_name
, ".reg") == 0 && sect_size
== tdep
->sizeof_gregset
)
470 return tdep
->gregset
;
472 if (strcmp (sect_name
, ".reg2") == 0 && sect_size
== tdep
->sizeof_fpregset
)
473 return tdep
->fpregset
;
479 /* Prologue analysis. */
481 /* When we analyze a prologue, we're really doing 'abstract
482 interpretation' or 'pseudo-evaluation': running the function's code
483 in simulation, but using conservative approximations of the values
484 it would have when it actually runs. For example, if our function
485 starts with the instruction:
487 ahi r1, 42 # add halfword immediate 42 to r1
489 we don't know exactly what value will be in r1 after executing this
490 instruction, but we do know it'll be 42 greater than its original
493 If we then see an instruction like:
495 ahi r1, 22 # add halfword immediate 22 to r1
497 we still don't know what r1's value is, but again, we can say it is
498 now 64 greater than its original value.
500 If the next instruction were:
502 lr r2, r1 # set r2 to r1's value
504 then we can say that r2's value is now the original value of r1
507 Of course, this can only go so far before it gets unreasonable. If
508 we wanted to be able to say anything about the value of r1 after
511 xr r1, r3 # exclusive-or r1 and r3, place result in r1
513 then things would get pretty complex. But remember, we're just
514 doing a conservative approximation; if exclusive-or instructions
515 aren't relevant to prologues, we can just say r1's value is now
516 'unknown'. We can ignore things that are too complex, if that loss
517 of information is acceptable for our application.
519 Once you've reached an instruction that you don't know how to
520 simulate, you stop. Now you examine the state of the registers and
521 stack slots you've kept track of. For example:
523 - To see how large your stack frame is, just check the value of sp;
524 if it's the original value of sp minus a constant, then that
525 constant is the stack frame's size. If the sp's value has been
526 marked as 'unknown', then that means the prologue has done
527 something too complex for us to track, and we don't know the
530 - To see whether we've saved the SP in the current frame's back
531 chain slot, we just check whether the current value of the back
532 chain stack slot is the original value of the sp.
534 Sure, this takes some work. But prologue analyzers aren't
535 quick-and-simple pattern patching to recognize a few fixed prologue
536 forms any more; they're big, hairy functions. Along with inferior
537 function calls, prologue analysis accounts for a substantial
538 portion of the time needed to stabilize a GDB port. So I think
539 it's worthwhile to look for an approach that will be easier to
540 understand and maintain. In the approach used here:
542 - It's easier to see that the analyzer is correct: you just see
543 whether the analyzer properly (albiet conservatively) simulates
544 the effect of each instruction.
546 - It's easier to extend the analyzer: you can add support for new
547 instructions, and know that you haven't broken anything that
548 wasn't already broken before.
550 - It's orthogonal: to gather new information, you don't need to
551 complicate the code for each instruction. As long as your domain
552 of conservative values is already detailed enough to tell you
553 what you need, then all the existing instruction simulations are
554 already gathering the right data for you.
556 A 'struct prologue_value' is a conservative approximation of the
557 real value the register or stack slot will have. */
559 struct prologue_value
{
561 /* What sort of value is this? This determines the interpretation
562 of subsequent fields. */
565 /* We don't know anything about the value. This is also used for
566 values we could have kept track of, when doing so would have
567 been too complex and we don't want to bother. The bottom of
571 /* A known constant. K is its value. */
574 /* The value that register REG originally had *UPON ENTRY TO THE
575 FUNCTION*, plus K. If K is zero, this means, obviously, just
576 the value REG had upon entry to the function. REG is a GDB
577 register number. Before we start interpreting, we initialize
578 every register R to { pv_register, R, 0 }. */
583 /* The meanings of the following fields depend on 'kind'; see the
584 comments for the specific 'kind' values. */
590 /* Set V to be unknown. */
592 pv_set_to_unknown (struct prologue_value
*v
)
594 v
->kind
= pv_unknown
;
598 /* Set V to the constant K. */
600 pv_set_to_constant (struct prologue_value
*v
, CORE_ADDR k
)
602 v
->kind
= pv_constant
;
607 /* Set V to the original value of register REG, plus K. */
609 pv_set_to_register (struct prologue_value
*v
, int reg
, CORE_ADDR k
)
611 v
->kind
= pv_register
;
617 /* If one of *A and *B is a constant, and the other isn't, swap the
618 pointers as necessary to ensure that *B points to the constant.
619 This can reduce the number of cases we need to analyze in the
622 pv_constant_last (struct prologue_value
**a
,
623 struct prologue_value
**b
)
625 if ((*a
)->kind
== pv_constant
626 && (*b
)->kind
!= pv_constant
)
628 struct prologue_value
*temp
= *a
;
635 /* Set SUM to the sum of A and B. SUM, A, and B may point to the same
636 'struct prologue_value' object. */
638 pv_add (struct prologue_value
*sum
,
639 struct prologue_value
*a
,
640 struct prologue_value
*b
)
642 pv_constant_last (&a
, &b
);
644 /* We can handle adding constants to registers, and other constants. */
645 if (b
->kind
== pv_constant
646 && (a
->kind
== pv_register
647 || a
->kind
== pv_constant
))
650 sum
->reg
= a
->reg
; /* not meaningful if a is pv_constant, but
652 sum
->k
= a
->k
+ b
->k
;
655 /* Anything else we don't know how to add. We don't have a
656 representation for, say, the sum of two registers, or a multiple
657 of a register's value (adding a register to itself). */
659 sum
->kind
= pv_unknown
;
663 /* Add the constant K to V. */
665 pv_add_constant (struct prologue_value
*v
, CORE_ADDR k
)
667 struct prologue_value pv_k
;
669 /* Rather than thinking of all the cases we can and can't handle,
670 we'll just let pv_add take care of that for us. */
671 pv_set_to_constant (&pv_k
, k
);
672 pv_add (v
, v
, &pv_k
);
676 /* Subtract B from A, and put the result in DIFF.
678 This isn't quite the same as negating B and adding it to A, since
679 we don't have a representation for the negation of anything but a
680 constant. For example, we can't negate { pv_register, R1, 10 },
681 but we do know that { pv_register, R1, 10 } minus { pv_register,
682 R1, 5 } is { pv_constant, <ignored>, 5 }.
684 This means, for example, that we can subtract two stack addresses;
685 they're both relative to the original SP. Since the frame pointer
686 is set based on the SP, its value will be the original SP plus some
687 constant (probably zero), so we can use its value just fine. */
689 pv_subtract (struct prologue_value
*diff
,
690 struct prologue_value
*a
,
691 struct prologue_value
*b
)
693 pv_constant_last (&a
, &b
);
695 /* We can subtract a constant from another constant, or from a
697 if (b
->kind
== pv_constant
698 && (a
->kind
== pv_register
699 || a
->kind
== pv_constant
))
701 diff
->kind
= a
->kind
;
702 diff
->reg
= a
->reg
; /* not always meaningful, but harmless */
703 diff
->k
= a
->k
- b
->k
;
706 /* We can subtract a register from itself, yielding a constant. */
707 else if (a
->kind
== pv_register
708 && b
->kind
== pv_register
711 diff
->kind
= pv_constant
;
712 diff
->k
= a
->k
- b
->k
;
715 /* We don't know how to subtract anything else. */
717 diff
->kind
= pv_unknown
;
721 /* Set AND to the logical and of A and B. */
723 pv_logical_and (struct prologue_value
*and,
724 struct prologue_value
*a
,
725 struct prologue_value
*b
)
727 pv_constant_last (&a
, &b
);
729 /* We can 'and' two constants. */
730 if (a
->kind
== pv_constant
731 && b
->kind
== pv_constant
)
733 and->kind
= pv_constant
;
734 and->k
= a
->k
& b
->k
;
737 /* We can 'and' anything with the constant zero. */
738 else if (b
->kind
== pv_constant
741 and->kind
= pv_constant
;
745 /* We can 'and' anything with ~0. */
746 else if (b
->kind
== pv_constant
747 && b
->k
== ~ (CORE_ADDR
) 0)
750 /* We can 'and' a register with itself. */
751 else if (a
->kind
== pv_register
752 && b
->kind
== pv_register
757 /* Otherwise, we don't know. */
759 pv_set_to_unknown (and);
763 /* Return non-zero iff A and B are identical expressions.
765 This is not the same as asking if the two values are equal; the
766 result of such a comparison would have to be a pv_boolean, and
767 asking whether two 'unknown' values were equal would give you
768 pv_maybe. Same for comparing, say, { pv_register, R1, 0 } and {
769 pv_register, R2, 0}. Instead, this is asking whether the two
770 representations are the same. */
772 pv_is_identical (struct prologue_value
*a
,
773 struct prologue_value
*b
)
775 if (a
->kind
!= b
->kind
)
783 return (a
->k
== b
->k
);
785 return (a
->reg
== b
->reg
&& a
->k
== b
->k
);
792 /* Return non-zero if A is the original value of register number R
793 plus K, zero otherwise. */
795 pv_is_register (struct prologue_value
*a
, int r
, CORE_ADDR k
)
797 return (a
->kind
== pv_register
803 /* Decoding S/390 instructions. */
805 /* Named opcode values for the S/390 instructions we recognize. Some
806 instructions have their opcode split across two fields; those are the
807 op1_* and op2_* enums. */
810 op1_lhi
= 0xa7, op2_lhi
= 0x08,
811 op1_lghi
= 0xa7, op2_lghi
= 0x09,
812 op1_lgfi
= 0xc0, op2_lgfi
= 0x01,
816 op1_ly
= 0xe3, op2_ly
= 0x58,
817 op1_lg
= 0xe3, op2_lg
= 0x04,
819 op1_lmy
= 0xeb, op2_lmy
= 0x98,
820 op1_lmg
= 0xeb, op2_lmg
= 0x04,
822 op1_sty
= 0xe3, op2_sty
= 0x50,
823 op1_stg
= 0xe3, op2_stg
= 0x24,
826 op1_stmy
= 0xeb, op2_stmy
= 0x90,
827 op1_stmg
= 0xeb, op2_stmg
= 0x24,
828 op1_aghi
= 0xa7, op2_aghi
= 0x0b,
829 op1_ahi
= 0xa7, op2_ahi
= 0x0a,
830 op1_agfi
= 0xc2, op2_agfi
= 0x08,
831 op1_afi
= 0xc2, op2_afi
= 0x09,
832 op1_algfi
= 0xc2, op2_algfi
= 0x0a,
833 op1_alfi
= 0xc2, op2_alfi
= 0x0b,
837 op1_ay
= 0xe3, op2_ay
= 0x5a,
838 op1_ag
= 0xe3, op2_ag
= 0x08,
839 op1_slgfi
= 0xc2, op2_slgfi
= 0x04,
840 op1_slfi
= 0xc2, op2_slfi
= 0x05,
844 op1_sy
= 0xe3, op2_sy
= 0x5b,
845 op1_sg
= 0xe3, op2_sg
= 0x09,
849 op1_lay
= 0xe3, op2_lay
= 0x71,
850 op1_larl
= 0xc0, op2_larl
= 0x00,
855 op1_bras
= 0xa7, op2_bras
= 0x05,
856 op1_brasl
= 0xc0, op2_brasl
= 0x05,
857 op1_brc
= 0xa7, op2_brc
= 0x04,
858 op1_brcl
= 0xc0, op2_brcl
= 0x04,
862 /* Read a single instruction from address AT. */
864 #define S390_MAX_INSTR_SIZE 6
866 s390_readinstruction (bfd_byte instr
[], CORE_ADDR at
)
868 static int s390_instrlen
[] = { 2, 4, 4, 6 };
871 if (deprecated_read_memory_nobpt (at
, &instr
[0], 2))
873 instrlen
= s390_instrlen
[instr
[0] >> 6];
876 if (deprecated_read_memory_nobpt (at
+ 2, &instr
[2], instrlen
- 2))
883 /* The functions below are for recognizing and decoding S/390
884 instructions of various formats. Each of them checks whether INSN
885 is an instruction of the given format, with the specified opcodes.
886 If it is, it sets the remaining arguments to the values of the
887 instruction's fields, and returns a non-zero value; otherwise, it
890 These functions' arguments appear in the order they appear in the
891 instruction, not in the machine-language form. So, opcodes always
892 come first, even though they're sometimes scattered around the
893 instructions. And displacements appear before base and extension
894 registers, as they do in the assembly syntax, not at the end, as
895 they do in the machine language. */
897 is_ri (bfd_byte
*insn
, int op1
, int op2
, unsigned int *r1
, int *i2
)
899 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
901 *r1
= (insn
[1] >> 4) & 0xf;
902 /* i2 is a 16-bit signed quantity. */
903 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
912 is_ril (bfd_byte
*insn
, int op1
, int op2
,
913 unsigned int *r1
, int *i2
)
915 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
917 *r1
= (insn
[1] >> 4) & 0xf;
918 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
919 no sign extension is necessary, but we don't want to assume
921 *i2
= (((insn
[2] << 24)
924 | (insn
[5])) ^ 0x80000000) - 0x80000000;
933 is_rr (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
937 *r1
= (insn
[1] >> 4) & 0xf;
947 is_rre (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
949 if (((insn
[0] << 8) | insn
[1]) == op
)
951 /* Yes, insn[3]. insn[2] is unused in RRE format. */
952 *r1
= (insn
[3] >> 4) & 0xf;
962 is_rs (bfd_byte
*insn
, int op
,
963 unsigned int *r1
, unsigned int *r3
, unsigned int *d2
, unsigned int *b2
)
967 *r1
= (insn
[1] >> 4) & 0xf;
969 *b2
= (insn
[2] >> 4) & 0xf;
970 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
979 is_rsy (bfd_byte
*insn
, int op1
, int op2
,
980 unsigned int *r1
, unsigned int *r3
, unsigned int *d2
, unsigned int *b2
)
985 *r1
= (insn
[1] >> 4) & 0xf;
987 *b2
= (insn
[2] >> 4) & 0xf;
988 /* The 'long displacement' is a 20-bit signed integer. */
989 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
990 ^ 0x80000) - 0x80000;
999 is_rx (bfd_byte
*insn
, int op
,
1000 unsigned int *r1
, unsigned int *d2
, unsigned int *x2
, unsigned int *b2
)
1004 *r1
= (insn
[1] >> 4) & 0xf;
1005 *x2
= insn
[1] & 0xf;
1006 *b2
= (insn
[2] >> 4) & 0xf;
1007 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
1016 is_rxy (bfd_byte
*insn
, int op1
, int op2
,
1017 unsigned int *r1
, unsigned int *d2
, unsigned int *x2
, unsigned int *b2
)
1022 *r1
= (insn
[1] >> 4) & 0xf;
1023 *x2
= insn
[1] & 0xf;
1024 *b2
= (insn
[2] >> 4) & 0xf;
1025 /* The 'long displacement' is a 20-bit signed integer. */
1026 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
1027 ^ 0x80000) - 0x80000;
1035 /* Set ADDR to the effective address for an X-style instruction, like:
1039 Here, X2 and B2 are registers, and D2 is a signed 20-bit
1040 constant; the effective address is the sum of all three. If either
1041 X2 or B2 are zero, then it doesn't contribute to the sum --- this
1042 means that r0 can't be used as either X2 or B2.
1044 GPR is an array of general register values, indexed by GPR number,
1045 not GDB register number. */
1047 compute_x_addr (struct prologue_value
*addr
,
1048 struct prologue_value
*gpr
,
1049 int d2
, unsigned int x2
, unsigned int b2
)
1051 /* We can't just add stuff directly in addr; it might alias some of
1052 the registers we need to read. */
1053 struct prologue_value result
;
1055 pv_set_to_constant (&result
, d2
);
1057 pv_add (&result
, &result
, &gpr
[x2
]);
1059 pv_add (&result
, &result
, &gpr
[b2
]);
1065 #define S390_NUM_GPRS 16
1066 #define S390_NUM_FPRS 16
1068 struct s390_prologue_data
{
1070 /* The size of a GPR or FPR. */
1074 /* The general-purpose registers. */
1075 struct prologue_value gpr
[S390_NUM_GPRS
];
1077 /* The floating-point registers. */
1078 struct prologue_value fpr
[S390_NUM_FPRS
];
1080 /* The offset relative to the CFA where the incoming GPR N was saved
1081 by the function prologue. 0 if not saved or unknown. */
1082 int gpr_slot
[S390_NUM_GPRS
];
1084 /* Likewise for FPRs. */
1085 int fpr_slot
[S390_NUM_FPRS
];
1087 /* Nonzero if the backchain was saved. This is assumed to be the
1088 case when the incoming SP is saved at the current SP location. */
1089 int back_chain_saved_p
;
1092 /* Do a SIZE-byte store of VALUE to ADDR. */
1094 s390_store (struct prologue_value
*addr
,
1096 struct prologue_value
*value
,
1097 struct s390_prologue_data
*data
)
1099 struct prologue_value cfa
, offset
;
1102 /* Check whether we are storing the backchain. */
1103 pv_subtract (&offset
, &data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
], addr
);
1105 if (offset
.kind
== pv_constant
&& offset
.k
== 0)
1106 if (size
== data
->gpr_size
1107 && pv_is_register (value
, S390_SP_REGNUM
, 0))
1109 data
->back_chain_saved_p
= 1;
1114 /* Check whether we are storing a register into the stack. */
1115 pv_set_to_register (&cfa
, S390_SP_REGNUM
, 16 * data
->gpr_size
+ 32);
1116 pv_subtract (&offset
, &cfa
, addr
);
1118 if (offset
.kind
== pv_constant
1119 && offset
.k
< INT_MAX
&& offset
.k
> 0
1120 && offset
.k
% data
->gpr_size
== 0)
1122 /* If we are storing the original value of a register, we want to
1123 record the CFA offset. If the same register is stored multiple
1124 times, the stack slot with the highest address counts. */
1126 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1127 if (size
== data
->gpr_size
1128 && pv_is_register (value
, S390_R0_REGNUM
+ i
, 0))
1129 if (data
->gpr_slot
[i
] == 0
1130 || data
->gpr_slot
[i
] > offset
.k
)
1132 data
->gpr_slot
[i
] = offset
.k
;
1136 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1137 if (size
== data
->fpr_size
1138 && pv_is_register (value
, S390_F0_REGNUM
+ i
, 0))
1139 if (data
->fpr_slot
[i
] == 0
1140 || data
->fpr_slot
[i
] > offset
.k
)
1142 data
->fpr_slot
[i
] = offset
.k
;
1148 /* Note: If this is some store we cannot identify, you might think we
1149 should forget our cached values, as any of those might have been hit.
1151 However, we make the assumption that the register save areas are only
1152 ever stored to once in any given function, and we do recognize these
1153 stores. Thus every store we cannot recognize does not hit our data. */
1156 /* Do a SIZE-byte load from ADDR into VALUE. */
1158 s390_load (struct prologue_value
*addr
,
1160 struct prologue_value
*value
,
1161 struct s390_prologue_data
*data
)
1163 struct prologue_value cfa
, offset
;
1166 /* If it's a load from an in-line constant pool, then we can
1167 simulate that, under the assumption that the code isn't
1168 going to change between the time the processor actually
1169 executed it creating the current frame, and the time when
1170 we're analyzing the code to unwind past that frame. */
1171 if (addr
->kind
== pv_constant
)
1173 struct section_table
*secp
;
1174 secp
= target_section_by_addr (¤t_target
, addr
->k
);
1176 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
1179 pv_set_to_constant (value
, read_memory_integer (addr
->k
, size
));
1184 /* Check whether we are accessing one of our save slots. */
1185 pv_set_to_register (&cfa
, S390_SP_REGNUM
, 16 * data
->gpr_size
+ 32);
1186 pv_subtract (&offset
, &cfa
, addr
);
1188 if (offset
.kind
== pv_constant
1189 && offset
.k
< INT_MAX
&& offset
.k
> 0)
1191 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1192 if (offset
.k
== data
->gpr_slot
[i
])
1194 pv_set_to_register (value
, S390_R0_REGNUM
+ i
, 0);
1198 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1199 if (offset
.k
== data
->fpr_slot
[i
])
1201 pv_set_to_register (value
, S390_F0_REGNUM
+ i
, 0);
1206 /* Otherwise, we don't know the value. */
1207 pv_set_to_unknown (value
);
1211 /* Analyze the prologue of the function starting at START_PC,
1212 continuing at most until CURRENT_PC. Initialize DATA to
1213 hold all information we find out about the state of the registers
1214 and stack slots. Return the address of the instruction after
1215 the last one that changed the SP, FP, or back chain; or zero
1218 s390_analyze_prologue (struct gdbarch
*gdbarch
,
1220 CORE_ADDR current_pc
,
1221 struct s390_prologue_data
*data
)
1223 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1225 /* Our return value:
1226 The address of the instruction after the last one that changed
1227 the SP, FP, or back chain; zero if we got an error trying to
1229 CORE_ADDR result
= start_pc
;
1231 /* The current PC for our abstract interpretation. */
1234 /* The address of the next instruction after that. */
1237 /* Set up everything's initial value. */
1241 /* For the purpose of prologue tracking, we consider the GPR size to
1242 be equal to the ABI word size, even if it is actually larger
1243 (i.e. when running a 32-bit binary under a 64-bit kernel). */
1244 data
->gpr_size
= word_size
;
1247 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1248 pv_set_to_register (&data
->gpr
[i
], S390_R0_REGNUM
+ i
, 0);
1250 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1251 pv_set_to_register (&data
->fpr
[i
], S390_F0_REGNUM
+ i
, 0);
1253 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1254 data
->gpr_slot
[i
] = 0;
1256 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1257 data
->fpr_slot
[i
] = 0;
1259 data
->back_chain_saved_p
= 0;
1262 /* Start interpreting instructions, until we hit the frame's
1263 current PC or the first branch instruction. */
1264 for (pc
= start_pc
; pc
> 0 && pc
< current_pc
; pc
= next_pc
)
1266 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
1267 int insn_len
= s390_readinstruction (insn
, pc
);
1269 /* Fields for various kinds of instructions. */
1270 unsigned int b2
, r1
, r2
, x2
, r3
;
1273 /* The values of SP and FP before this instruction,
1274 for detecting instructions that change them. */
1275 struct prologue_value pre_insn_sp
, pre_insn_fp
;
1276 /* Likewise for the flag whether the back chain was saved. */
1277 int pre_insn_back_chain_saved_p
;
1279 /* If we got an error trying to read the instruction, report it. */
1286 next_pc
= pc
+ insn_len
;
1288 pre_insn_sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1289 pre_insn_fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1290 pre_insn_back_chain_saved_p
= data
->back_chain_saved_p
;
1292 /* LHI r1, i2 --- load halfword immediate */
1294 && is_ri (insn
, op1_lhi
, op2_lhi
, &r1
, &i2
))
1295 pv_set_to_constant (&data
->gpr
[r1
], i2
);
1297 /* LGHI r1, i2 --- load halfword immediate (64-bit version) */
1298 else if (word_size
== 8
1299 && is_ri (insn
, op1_lghi
, op2_lghi
, &r1
, &i2
))
1300 pv_set_to_constant (&data
->gpr
[r1
], i2
);
1302 /* LGFI r1, i2 --- load fullword immediate */
1303 else if (is_ril (insn
, op1_lgfi
, op2_lgfi
, &r1
, &i2
))
1304 pv_set_to_constant (&data
->gpr
[r1
], i2
);
1306 /* LR r1, r2 --- load from register */
1307 else if (word_size
== 4
1308 && is_rr (insn
, op_lr
, &r1
, &r2
))
1309 data
->gpr
[r1
] = data
->gpr
[r2
];
1311 /* LGR r1, r2 --- load from register (64-bit version) */
1312 else if (word_size
== 8
1313 && is_rre (insn
, op_lgr
, &r1
, &r2
))
1314 data
->gpr
[r1
] = data
->gpr
[r2
];
1316 /* L r1, d2(x2, b2) --- load */
1317 else if (word_size
== 4
1318 && is_rx (insn
, op_l
, &r1
, &d2
, &x2
, &b2
))
1320 struct prologue_value addr
;
1322 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1323 s390_load (&addr
, 4, &data
->gpr
[r1
], data
);
1326 /* LY r1, d2(x2, b2) --- load (long-displacement version) */
1327 else if (word_size
== 4
1328 && is_rxy (insn
, op1_ly
, op2_ly
, &r1
, &d2
, &x2
, &b2
))
1330 struct prologue_value addr
;
1332 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1333 s390_load (&addr
, 4, &data
->gpr
[r1
], data
);
1336 /* LG r1, d2(x2, b2) --- load (64-bit version) */
1337 else if (word_size
== 8
1338 && is_rxy (insn
, op1_lg
, op2_lg
, &r1
, &d2
, &x2
, &b2
))
1340 struct prologue_value addr
;
1342 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1343 s390_load (&addr
, 8, &data
->gpr
[r1
], data
);
1346 /* ST r1, d2(x2, b2) --- store */
1347 else if (word_size
== 4
1348 && is_rx (insn
, op_st
, &r1
, &d2
, &x2
, &b2
))
1350 struct prologue_value addr
;
1352 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1353 s390_store (&addr
, 4, &data
->gpr
[r1
], data
);
1356 /* STY r1, d2(x2, b2) --- store (long-displacement version) */
1357 else if (word_size
== 4
1358 && is_rxy (insn
, op1_sty
, op2_sty
, &r1
, &d2
, &x2
, &b2
))
1360 struct prologue_value addr
;
1362 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1363 s390_store (&addr
, 4, &data
->gpr
[r1
], data
);
1366 /* STG r1, d2(x2, b2) --- store (64-bit version) */
1367 else if (word_size
== 8
1368 && is_rxy (insn
, op1_stg
, op2_stg
, &r1
, &d2
, &x2
, &b2
))
1370 struct prologue_value addr
;
1372 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1373 s390_store (&addr
, 8, &data
->gpr
[r1
], data
);
1376 /* STD r1, d2(x2,b2) --- store floating-point register */
1377 else if (is_rx (insn
, op_std
, &r1
, &d2
, &x2
, &b2
))
1379 struct prologue_value addr
;
1381 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1382 s390_store (&addr
, 8, &data
->fpr
[r1
], data
);
1385 /* STM r1, r3, d2(b2) --- store multiple */
1386 else if (word_size
== 4
1387 && is_rs (insn
, op_stm
, &r1
, &r3
, &d2
, &b2
))
1391 struct prologue_value addr
;
1393 for (regnum
= r1
, offset
= 0;
1395 regnum
++, offset
+= 4)
1397 compute_x_addr (&addr
, data
->gpr
, d2
+ offset
, 0, b2
);
1398 s390_store (&addr
, 4, &data
->gpr
[regnum
], data
);
1402 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement version) */
1403 else if (word_size
== 4
1404 && is_rsy (insn
, op1_stmy
, op2_stmy
, &r1
, &r3
, &d2
, &b2
))
1408 struct prologue_value addr
;
1410 for (regnum
= r1
, offset
= 0;
1412 regnum
++, offset
+= 4)
1414 compute_x_addr (&addr
, data
->gpr
, d2
+ offset
, 0, b2
);
1415 s390_store (&addr
, 4, &data
->gpr
[regnum
], data
);
1419 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version) */
1420 else if (word_size
== 8
1421 && is_rsy (insn
, op1_stmg
, op2_stmg
, &r1
, &r3
, &d2
, &b2
))
1425 struct prologue_value addr
;
1427 for (regnum
= r1
, offset
= 0;
1429 regnum
++, offset
+= 8)
1431 compute_x_addr (&addr
, data
->gpr
, d2
+ offset
, 0, b2
);
1432 s390_store (&addr
, 8, &data
->gpr
[regnum
], data
);
1436 /* AHI r1, i2 --- add halfword immediate */
1437 else if (word_size
== 4
1438 && is_ri (insn
, op1_ahi
, op2_ahi
, &r1
, &i2
))
1439 pv_add_constant (&data
->gpr
[r1
], i2
);
1441 /* AGHI r1, i2 --- add halfword immediate (64-bit version) */
1442 else if (word_size
== 8
1443 && is_ri (insn
, op1_aghi
, op2_aghi
, &r1
, &i2
))
1444 pv_add_constant (&data
->gpr
[r1
], i2
);
1446 /* AFI r1, i2 --- add fullword immediate */
1447 else if (word_size
== 4
1448 && is_ril (insn
, op1_afi
, op2_afi
, &r1
, &i2
))
1449 pv_add_constant (&data
->gpr
[r1
], i2
);
1451 /* AGFI r1, i2 --- add fullword immediate (64-bit version) */
1452 else if (word_size
== 8
1453 && is_ril (insn
, op1_agfi
, op2_agfi
, &r1
, &i2
))
1454 pv_add_constant (&data
->gpr
[r1
], i2
);
1456 /* ALFI r1, i2 --- add logical immediate */
1457 else if (word_size
== 4
1458 && is_ril (insn
, op1_alfi
, op2_alfi
, &r1
, &i2
))
1459 pv_add_constant (&data
->gpr
[r1
], (CORE_ADDR
)i2
& 0xffffffff);
1461 /* ALGFI r1, i2 --- add logical immediate (64-bit version) */
1462 else if (word_size
== 8
1463 && is_ril (insn
, op1_algfi
, op2_algfi
, &r1
, &i2
))
1464 pv_add_constant (&data
->gpr
[r1
], (CORE_ADDR
)i2
& 0xffffffff);
1466 /* AR r1, r2 -- add register */
1467 else if (word_size
== 4
1468 && is_rr (insn
, op_ar
, &r1
, &r2
))
1469 pv_add (&data
->gpr
[r1
], &data
->gpr
[r1
], &data
->gpr
[r2
]);
1471 /* AGR r1, r2 -- add register (64-bit version) */
1472 else if (word_size
== 8
1473 && is_rre (insn
, op_agr
, &r1
, &r2
))
1474 pv_add (&data
->gpr
[r1
], &data
->gpr
[r1
], &data
->gpr
[r2
]);
1476 /* A r1, d2(x2, b2) -- add */
1477 else if (word_size
== 4
1478 && is_rx (insn
, op_a
, &r1
, &d2
, &x2
, &b2
))
1480 struct prologue_value addr
;
1481 struct prologue_value value
;
1483 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1484 s390_load (&addr
, 4, &value
, data
);
1486 pv_add (&data
->gpr
[r1
], &data
->gpr
[r1
], &value
);
1489 /* AY r1, d2(x2, b2) -- add (long-displacement version) */
1490 else if (word_size
== 4
1491 && is_rxy (insn
, op1_ay
, op2_ay
, &r1
, &d2
, &x2
, &b2
))
1493 struct prologue_value addr
;
1494 struct prologue_value value
;
1496 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1497 s390_load (&addr
, 4, &value
, data
);
1499 pv_add (&data
->gpr
[r1
], &data
->gpr
[r1
], &value
);
1502 /* AG r1, d2(x2, b2) -- add (64-bit version) */
1503 else if (word_size
== 8
1504 && is_rxy (insn
, op1_ag
, op2_ag
, &r1
, &d2
, &x2
, &b2
))
1506 struct prologue_value addr
;
1507 struct prologue_value value
;
1509 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1510 s390_load (&addr
, 8, &value
, data
);
1512 pv_add (&data
->gpr
[r1
], &data
->gpr
[r1
], &value
);
1515 /* SLFI r1, i2 --- subtract logical immediate */
1516 else if (word_size
== 4
1517 && is_ril (insn
, op1_slfi
, op2_slfi
, &r1
, &i2
))
1518 pv_add_constant (&data
->gpr
[r1
], -((CORE_ADDR
)i2
& 0xffffffff));
1520 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version) */
1521 else if (word_size
== 8
1522 && is_ril (insn
, op1_slgfi
, op2_slgfi
, &r1
, &i2
))
1523 pv_add_constant (&data
->gpr
[r1
], -((CORE_ADDR
)i2
& 0xffffffff));
1525 /* SR r1, r2 -- subtract register */
1526 else if (word_size
== 4
1527 && is_rr (insn
, op_sr
, &r1
, &r2
))
1528 pv_subtract (&data
->gpr
[r1
], &data
->gpr
[r1
], &data
->gpr
[r2
]);
1530 /* SGR r1, r2 -- subtract register (64-bit version) */
1531 else if (word_size
== 8
1532 && is_rre (insn
, op_sgr
, &r1
, &r2
))
1533 pv_subtract (&data
->gpr
[r1
], &data
->gpr
[r1
], &data
->gpr
[r2
]);
1535 /* S r1, d2(x2, b2) -- subtract */
1536 else if (word_size
== 4
1537 && is_rx (insn
, op_s
, &r1
, &d2
, &x2
, &b2
))
1539 struct prologue_value addr
;
1540 struct prologue_value value
;
1542 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1543 s390_load (&addr
, 4, &value
, data
);
1545 pv_subtract (&data
->gpr
[r1
], &data
->gpr
[r1
], &value
);
1548 /* SY r1, d2(x2, b2) -- subtract (long-displacement version) */
1549 else if (word_size
== 4
1550 && is_rxy (insn
, op1_sy
, op2_sy
, &r1
, &d2
, &x2
, &b2
))
1552 struct prologue_value addr
;
1553 struct prologue_value value
;
1555 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1556 s390_load (&addr
, 4, &value
, data
);
1558 pv_subtract (&data
->gpr
[r1
], &data
->gpr
[r1
], &value
);
1561 /* SG r1, d2(x2, b2) -- subtract (64-bit version) */
1562 else if (word_size
== 8
1563 && is_rxy (insn
, op1_sg
, op2_sg
, &r1
, &d2
, &x2
, &b2
))
1565 struct prologue_value addr
;
1566 struct prologue_value value
;
1568 compute_x_addr (&addr
, data
->gpr
, d2
, x2
, b2
);
1569 s390_load (&addr
, 8, &value
, data
);
1571 pv_subtract (&data
->gpr
[r1
], &data
->gpr
[r1
], &value
);
1574 /* NR r1, r2 --- logical and */
1575 else if (word_size
== 4
1576 && is_rr (insn
, op_nr
, &r1
, &r2
))
1577 pv_logical_and (&data
->gpr
[r1
], &data
->gpr
[r1
], &data
->gpr
[r2
]);
1579 /* NGR r1, r2 >--- logical and (64-bit version) */
1580 else if (word_size
== 8
1581 && is_rre (insn
, op_ngr
, &r1
, &r2
))
1582 pv_logical_and (&data
->gpr
[r1
], &data
->gpr
[r1
], &data
->gpr
[r2
]);
1584 /* LA r1, d2(x2, b2) --- load address */
1585 else if (is_rx (insn
, op_la
, &r1
, &d2
, &x2
, &b2
))
1586 compute_x_addr (&data
->gpr
[r1
], data
->gpr
, d2
, x2
, b2
);
1588 /* LAY r1, d2(x2, b2) --- load address (long-displacement version) */
1589 else if (is_rxy (insn
, op1_lay
, op2_lay
, &r1
, &d2
, &x2
, &b2
))
1590 compute_x_addr (&data
->gpr
[r1
], data
->gpr
, d2
, x2
, b2
);
1592 /* LARL r1, i2 --- load address relative long */
1593 else if (is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1594 pv_set_to_constant (&data
->gpr
[r1
], pc
+ i2
* 2);
1596 /* BASR r1, 0 --- branch and save
1597 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1598 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1600 pv_set_to_constant (&data
->gpr
[r1
], next_pc
);
1602 /* BRAS r1, i2 --- branch relative and save */
1603 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
))
1605 pv_set_to_constant (&data
->gpr
[r1
], next_pc
);
1606 next_pc
= pc
+ i2
* 2;
1608 /* We'd better not interpret any backward branches. We'll
1614 /* Terminate search when hitting any other branch instruction. */
1615 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1616 || is_rx (insn
, op_bas
, &r1
, &d2
, &x2
, &b2
)
1617 || is_rr (insn
, op_bcr
, &r1
, &r2
)
1618 || is_rx (insn
, op_bc
, &r1
, &d2
, &x2
, &b2
)
1619 || is_ri (insn
, op1_brc
, op2_brc
, &r1
, &i2
)
1620 || is_ril (insn
, op1_brcl
, op2_brcl
, &r1
, &i2
)
1621 || is_ril (insn
, op1_brasl
, op2_brasl
, &r2
, &i2
))
1625 /* An instruction we don't know how to simulate. The only
1626 safe thing to do would be to set every value we're tracking
1627 to 'unknown'. Instead, we'll be optimistic: we assume that
1628 we *can* interpret every instruction that the compiler uses
1629 to manipulate any of the data we're interested in here --
1630 then we can just ignore anything else. */
1633 /* Record the address after the last instruction that changed
1634 the FP, SP, or backlink. Ignore instructions that changed
1635 them back to their original values --- those are probably
1636 restore instructions. (The back chain is never restored,
1639 struct prologue_value
*sp
= &data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1640 struct prologue_value
*fp
= &data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1642 if ((! pv_is_identical (&pre_insn_sp
, sp
)
1643 && ! pv_is_register (sp
, S390_SP_REGNUM
, 0))
1644 || (! pv_is_identical (&pre_insn_fp
, fp
)
1645 && ! pv_is_register (fp
, S390_FRAME_REGNUM
, 0))
1646 || pre_insn_back_chain_saved_p
!= data
->back_chain_saved_p
)
1654 /* Advance PC across any function entry prologue instructions to reach
1655 some "real" code. */
1657 s390_skip_prologue (CORE_ADDR pc
)
1659 struct s390_prologue_data data
;
1661 skip_pc
= s390_analyze_prologue (current_gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
1662 return skip_pc
? skip_pc
: pc
;
1665 /* Return true if we are in the functin's epilogue, i.e. after the
1666 instruction that destroyed the function's stack frame. */
1668 s390_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1670 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1672 /* In frameless functions, there's not frame to destroy and thus
1673 we don't care about the epilogue.
1675 In functions with frame, the epilogue sequence is a pair of
1676 a LM-type instruction that restores (amongst others) the
1677 return register %r14 and the stack pointer %r15, followed
1678 by a branch 'br %r14' --or equivalent-- that effects the
1681 In that situation, this function needs to return 'true' in
1682 exactly one case: when pc points to that branch instruction.
1684 Thus we try to disassemble the one instructions immediately
1685 preceeding pc and check whether it is an LM-type instruction
1686 modifying the stack pointer.
1688 Note that disassembling backwards is not reliable, so there
1689 is a slight chance of false positives here ... */
1692 unsigned int r1
, r3
, b2
;
1696 && !deprecated_read_memory_nobpt (pc
- 4, insn
, 4)
1697 && is_rs (insn
, op_lm
, &r1
, &r3
, &d2
, &b2
)
1698 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1702 && !deprecated_read_memory_nobpt (pc
- 6, insn
, 6)
1703 && is_rsy (insn
, op1_lmy
, op2_lmy
, &r1
, &r3
, &d2
, &b2
)
1704 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1708 && !deprecated_read_memory_nobpt (pc
- 6, insn
, 6)
1709 && is_rsy (insn
, op1_lmg
, op2_lmg
, &r1
, &r3
, &d2
, &b2
)
1710 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1717 /* Normal stack frames. */
1719 struct s390_unwind_cache
{
1722 CORE_ADDR frame_base
;
1723 CORE_ADDR local_base
;
1725 struct trad_frame_saved_reg
*saved_regs
;
1729 s390_prologue_frame_unwind_cache (struct frame_info
*next_frame
,
1730 struct s390_unwind_cache
*info
)
1732 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1733 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1734 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1735 struct s390_prologue_data data
;
1736 struct prologue_value
*fp
= &data
.gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1737 struct prologue_value
*sp
= &data
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1747 /* Try to find the function start address. If we can't find it, we don't
1748 bother searching for it -- with modern compilers this would be mostly
1749 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1750 or else a valid backchain ... */
1751 func
= frame_func_unwind (next_frame
);
1755 /* Try to analyze the prologue. */
1756 result
= s390_analyze_prologue (gdbarch
, func
,
1757 frame_pc_unwind (next_frame
), &data
);
1761 /* If this was successful, we should have found the instruction that
1762 sets the stack pointer register to the previous value of the stack
1763 pointer minus the frame size. */
1764 if (sp
->kind
!= pv_register
|| sp
->reg
!= S390_SP_REGNUM
)
1767 /* A frame size of zero at this point can mean either a real
1768 frameless function, or else a failure to find the prologue.
1769 Perform some sanity checks to verify we really have a
1770 frameless function. */
1773 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1774 size zero. This is only possible if the next frame is a sentinel
1775 frame, a dummy frame, or a signal trampoline frame. */
1776 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1777 needed, instead the code should simpliy rely on its
1779 if (get_frame_type (next_frame
) == NORMAL_FRAME
)
1782 /* If we really have a frameless function, %r14 must be valid
1783 -- in particular, it must point to a different function. */
1784 reg
= frame_unwind_register_unsigned (next_frame
, S390_RETADDR_REGNUM
);
1785 reg
= gdbarch_addr_bits_remove (gdbarch
, reg
) - 1;
1786 if (get_pc_function_start (reg
) == func
)
1788 /* However, there is one case where it *is* valid for %r14
1789 to point to the same function -- if this is a recursive
1790 call, and we have stopped in the prologue *before* the
1791 stack frame was allocated.
1793 Recognize this case by looking ahead a bit ... */
1795 struct s390_prologue_data data2
;
1796 struct prologue_value
*sp
= &data2
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1798 if (!(s390_analyze_prologue (gdbarch
, func
, (CORE_ADDR
)-1, &data2
)
1799 && sp
->kind
== pv_register
1800 && sp
->reg
== S390_SP_REGNUM
1807 /* OK, we've found valid prologue data. */
1810 /* If the frame pointer originally also holds the same value
1811 as the stack pointer, we're probably using it. If it holds
1812 some other value -- even a constant offset -- it is most
1813 likely used as temp register. */
1814 if (pv_is_identical (sp
, fp
))
1815 frame_pointer
= S390_FRAME_REGNUM
;
1817 frame_pointer
= S390_SP_REGNUM
;
1819 /* If we've detected a function with stack frame, we'll still have to
1820 treat it as frameless if we're currently within the function epilog
1821 code at a point where the frame pointer has already been restored.
1822 This can only happen in an innermost frame. */
1823 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1824 instead the code should simpliy rely on its analysis. */
1825 if (size
> 0 && get_frame_type (next_frame
) != NORMAL_FRAME
)
1827 /* See the comment in s390_in_function_epilogue_p on why this is
1828 not completely reliable ... */
1829 if (s390_in_function_epilogue_p (gdbarch
, frame_pc_unwind (next_frame
)))
1831 memset (&data
, 0, sizeof (data
));
1833 frame_pointer
= S390_SP_REGNUM
;
1837 /* Once we know the frame register and the frame size, we can unwind
1838 the current value of the frame register from the next frame, and
1839 add back the frame size to arrive that the previous frame's
1840 stack pointer value. */
1841 prev_sp
= frame_unwind_register_unsigned (next_frame
, frame_pointer
) + size
;
1842 cfa
= prev_sp
+ 16*word_size
+ 32;
1844 /* Record the addresses of all register spill slots the prologue parser
1845 has recognized. Consider only registers defined as call-saved by the
1846 ABI; for call-clobbered registers the parser may have recognized
1849 for (i
= 6; i
<= 15; i
++)
1850 if (data
.gpr_slot
[i
] != 0)
1851 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= cfa
- data
.gpr_slot
[i
];
1855 case ABI_LINUX_S390
:
1856 if (data
.fpr_slot
[4] != 0)
1857 info
->saved_regs
[S390_F4_REGNUM
].addr
= cfa
- data
.fpr_slot
[4];
1858 if (data
.fpr_slot
[6] != 0)
1859 info
->saved_regs
[S390_F6_REGNUM
].addr
= cfa
- data
.fpr_slot
[6];
1862 case ABI_LINUX_ZSERIES
:
1863 for (i
= 8; i
<= 15; i
++)
1864 if (data
.fpr_slot
[i
] != 0)
1865 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= cfa
- data
.fpr_slot
[i
];
1869 /* Function return will set PC to %r14. */
1870 info
->saved_regs
[S390_PC_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1872 /* In frameless functions, we unwind simply by moving the return
1873 address to the PC. However, if we actually stored to the
1874 save area, use that -- we might only think the function frameless
1875 because we're in the middle of the prologue ... */
1877 && !trad_frame_addr_p (info
->saved_regs
, S390_PC_REGNUM
))
1879 info
->saved_regs
[S390_PC_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1882 /* Another sanity check: unless this is a frameless function,
1883 we should have found spill slots for SP and PC.
1884 If not, we cannot unwind further -- this happens e.g. in
1885 libc's thread_start routine. */
1888 if (!trad_frame_addr_p (info
->saved_regs
, S390_SP_REGNUM
)
1889 || !trad_frame_addr_p (info
->saved_regs
, S390_PC_REGNUM
))
1893 /* We use the current value of the frame register as local_base,
1894 and the top of the register save area as frame_base. */
1897 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1898 info
->local_base
= prev_sp
- size
;
1906 s390_backchain_frame_unwind_cache (struct frame_info
*next_frame
,
1907 struct s390_unwind_cache
*info
)
1909 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1910 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1911 CORE_ADDR backchain
;
1915 /* Get the backchain. */
1916 reg
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1917 backchain
= read_memory_unsigned_integer (reg
, word_size
);
1919 /* A zero backchain terminates the frame chain. As additional
1920 sanity check, let's verify that the spill slot for SP in the
1921 save area pointed to by the backchain in fact links back to
1924 && safe_read_memory_integer (backchain
+ 15*word_size
, word_size
, &sp
)
1925 && (CORE_ADDR
)sp
== backchain
)
1927 /* We don't know which registers were saved, but it will have
1928 to be at least %r14 and %r15. This will allow us to continue
1929 unwinding, but other prev-frame registers may be incorrect ... */
1930 info
->saved_regs
[S390_SP_REGNUM
].addr
= backchain
+ 15*word_size
;
1931 info
->saved_regs
[S390_RETADDR_REGNUM
].addr
= backchain
+ 14*word_size
;
1933 /* Function return will set PC to %r14. */
1934 info
->saved_regs
[S390_PC_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1936 /* We use the current value of the frame register as local_base,
1937 and the top of the register save area as frame_base. */
1938 info
->frame_base
= backchain
+ 16*word_size
+ 32;
1939 info
->local_base
= reg
;
1942 info
->func
= frame_pc_unwind (next_frame
);
1945 static struct s390_unwind_cache
*
1946 s390_frame_unwind_cache (struct frame_info
*next_frame
,
1947 void **this_prologue_cache
)
1949 struct s390_unwind_cache
*info
;
1950 if (*this_prologue_cache
)
1951 return *this_prologue_cache
;
1953 info
= FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache
);
1954 *this_prologue_cache
= info
;
1955 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1957 info
->frame_base
= -1;
1958 info
->local_base
= -1;
1960 /* Try to use prologue analysis to fill the unwind cache.
1961 If this fails, fall back to reading the stack backchain. */
1962 if (!s390_prologue_frame_unwind_cache (next_frame
, info
))
1963 s390_backchain_frame_unwind_cache (next_frame
, info
);
1969 s390_frame_this_id (struct frame_info
*next_frame
,
1970 void **this_prologue_cache
,
1971 struct frame_id
*this_id
)
1973 struct s390_unwind_cache
*info
1974 = s390_frame_unwind_cache (next_frame
, this_prologue_cache
);
1976 if (info
->frame_base
== -1)
1979 *this_id
= frame_id_build (info
->frame_base
, info
->func
);
1983 s390_frame_prev_register (struct frame_info
*next_frame
,
1984 void **this_prologue_cache
,
1985 int regnum
, int *optimizedp
,
1986 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1987 int *realnump
, gdb_byte
*bufferp
)
1989 struct s390_unwind_cache
*info
1990 = s390_frame_unwind_cache (next_frame
, this_prologue_cache
);
1991 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1992 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1995 static const struct frame_unwind s390_frame_unwind
= {
1998 s390_frame_prev_register
2001 static const struct frame_unwind
*
2002 s390_frame_sniffer (struct frame_info
*next_frame
)
2004 return &s390_frame_unwind
;
2008 /* Code stubs and their stack frames. For things like PLTs and NULL
2009 function calls (where there is no true frame and the return address
2010 is in the RETADDR register). */
2012 struct s390_stub_unwind_cache
2014 CORE_ADDR frame_base
;
2015 struct trad_frame_saved_reg
*saved_regs
;
2018 static struct s390_stub_unwind_cache
*
2019 s390_stub_frame_unwind_cache (struct frame_info
*next_frame
,
2020 void **this_prologue_cache
)
2022 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
2023 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2024 struct s390_stub_unwind_cache
*info
;
2027 if (*this_prologue_cache
)
2028 return *this_prologue_cache
;
2030 info
= FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache
);
2031 *this_prologue_cache
= info
;
2032 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
2034 /* The return address is in register %r14. */
2035 info
->saved_regs
[S390_PC_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
2037 /* Retrieve stack pointer and determine our frame base. */
2038 reg
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
2039 info
->frame_base
= reg
+ 16*word_size
+ 32;
2045 s390_stub_frame_this_id (struct frame_info
*next_frame
,
2046 void **this_prologue_cache
,
2047 struct frame_id
*this_id
)
2049 struct s390_stub_unwind_cache
*info
2050 = s390_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
2051 *this_id
= frame_id_build (info
->frame_base
, frame_pc_unwind (next_frame
));
2055 s390_stub_frame_prev_register (struct frame_info
*next_frame
,
2056 void **this_prologue_cache
,
2057 int regnum
, int *optimizedp
,
2058 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
2059 int *realnump
, gdb_byte
*bufferp
)
2061 struct s390_stub_unwind_cache
*info
2062 = s390_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
2063 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
2064 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
2067 static const struct frame_unwind s390_stub_frame_unwind
= {
2069 s390_stub_frame_this_id
,
2070 s390_stub_frame_prev_register
2073 static const struct frame_unwind
*
2074 s390_stub_frame_sniffer (struct frame_info
*next_frame
)
2076 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
2077 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
2079 /* If the current PC points to non-readable memory, we assume we
2080 have trapped due to an invalid function pointer call. We handle
2081 the non-existing current function like a PLT stub. */
2082 if (in_plt_section (pc
, NULL
)
2083 || s390_readinstruction (insn
, pc
) < 0)
2084 return &s390_stub_frame_unwind
;
2089 /* Signal trampoline stack frames. */
2091 struct s390_sigtramp_unwind_cache
{
2092 CORE_ADDR frame_base
;
2093 struct trad_frame_saved_reg
*saved_regs
;
2096 static struct s390_sigtramp_unwind_cache
*
2097 s390_sigtramp_frame_unwind_cache (struct frame_info
*next_frame
,
2098 void **this_prologue_cache
)
2100 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
2101 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2102 struct s390_sigtramp_unwind_cache
*info
;
2103 ULONGEST this_sp
, prev_sp
;
2104 CORE_ADDR next_ra
, next_cfa
, sigreg_ptr
;
2107 if (*this_prologue_cache
)
2108 return *this_prologue_cache
;
2110 info
= FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache
);
2111 *this_prologue_cache
= info
;
2112 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
2114 this_sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
2115 next_ra
= frame_pc_unwind (next_frame
);
2116 next_cfa
= this_sp
+ 16*word_size
+ 32;
2118 /* New-style RT frame:
2119 retcode + alignment (8 bytes)
2121 ucontext (contains sigregs at offset 5 words) */
2122 if (next_ra
== next_cfa
)
2124 sigreg_ptr
= next_cfa
+ 8 + 128 + align_up (5*word_size
, 8);
2127 /* Old-style RT frame and all non-RT frames:
2128 old signal mask (8 bytes)
2129 pointer to sigregs */
2132 sigreg_ptr
= read_memory_unsigned_integer (next_cfa
+ 8, word_size
);
2135 /* The sigregs structure looks like this:
2144 /* Let's ignore the PSW mask, it will not be restored anyway. */
2145 sigreg_ptr
+= word_size
;
2147 /* Next comes the PSW address. */
2148 info
->saved_regs
[S390_PC_REGNUM
].addr
= sigreg_ptr
;
2149 sigreg_ptr
+= word_size
;
2151 /* Then the GPRs. */
2152 for (i
= 0; i
< 16; i
++)
2154 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= sigreg_ptr
;
2155 sigreg_ptr
+= word_size
;
2158 /* Then the ACRs. */
2159 for (i
= 0; i
< 16; i
++)
2161 info
->saved_regs
[S390_A0_REGNUM
+ i
].addr
= sigreg_ptr
;
2165 /* The floating-point control word. */
2166 info
->saved_regs
[S390_FPC_REGNUM
].addr
= sigreg_ptr
;
2169 /* And finally the FPRs. */
2170 for (i
= 0; i
< 16; i
++)
2172 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= sigreg_ptr
;
2176 /* Restore the previous frame's SP. */
2177 prev_sp
= read_memory_unsigned_integer (
2178 info
->saved_regs
[S390_SP_REGNUM
].addr
,
2181 /* Determine our frame base. */
2182 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
2188 s390_sigtramp_frame_this_id (struct frame_info
*next_frame
,
2189 void **this_prologue_cache
,
2190 struct frame_id
*this_id
)
2192 struct s390_sigtramp_unwind_cache
*info
2193 = s390_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
2194 *this_id
= frame_id_build (info
->frame_base
, frame_pc_unwind (next_frame
));
2198 s390_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
2199 void **this_prologue_cache
,
2200 int regnum
, int *optimizedp
,
2201 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
2202 int *realnump
, gdb_byte
*bufferp
)
2204 struct s390_sigtramp_unwind_cache
*info
2205 = s390_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
2206 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
2207 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
2210 static const struct frame_unwind s390_sigtramp_frame_unwind
= {
2212 s390_sigtramp_frame_this_id
,
2213 s390_sigtramp_frame_prev_register
2216 static const struct frame_unwind
*
2217 s390_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
2219 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
2220 bfd_byte sigreturn
[2];
2222 if (deprecated_read_memory_nobpt (pc
, sigreturn
, 2))
2225 if (sigreturn
[0] != 0x0a /* svc */)
2228 if (sigreturn
[1] != 119 /* sigreturn */
2229 && sigreturn
[1] != 173 /* rt_sigreturn */)
2232 return &s390_sigtramp_frame_unwind
;
2236 /* Frame base handling. */
2239 s390_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
2241 struct s390_unwind_cache
*info
2242 = s390_frame_unwind_cache (next_frame
, this_cache
);
2243 return info
->frame_base
;
2247 s390_local_base_address (struct frame_info
*next_frame
, void **this_cache
)
2249 struct s390_unwind_cache
*info
2250 = s390_frame_unwind_cache (next_frame
, this_cache
);
2251 return info
->local_base
;
2254 static const struct frame_base s390_frame_base
= {
2256 s390_frame_base_address
,
2257 s390_local_base_address
,
2258 s390_local_base_address
2262 s390_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2265 pc
= frame_unwind_register_unsigned (next_frame
, S390_PC_REGNUM
);
2266 return gdbarch_addr_bits_remove (gdbarch
, pc
);
2270 s390_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2273 sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
2274 return gdbarch_addr_bits_remove (gdbarch
, sp
);
2278 /* DWARF-2 frame support. */
2281 s390_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
2282 struct dwarf2_frame_state_reg
*reg
)
2284 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2288 case ABI_LINUX_S390
:
2289 /* Call-saved registers. */
2290 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
2291 || regnum
== S390_F4_REGNUM
2292 || regnum
== S390_F6_REGNUM
)
2293 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
2295 /* Call-clobbered registers. */
2296 else if ((regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R5_REGNUM
)
2297 || (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
2298 && regnum
!= S390_F4_REGNUM
&& regnum
!= S390_F6_REGNUM
))
2299 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
2301 /* The return address column. */
2302 else if (regnum
== S390_PC_REGNUM
)
2303 reg
->how
= DWARF2_FRAME_REG_RA
;
2306 case ABI_LINUX_ZSERIES
:
2307 /* Call-saved registers. */
2308 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
2309 || (regnum
>= S390_F8_REGNUM
&& regnum
<= S390_F15_REGNUM
))
2310 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
2312 /* Call-clobbered registers. */
2313 else if ((regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R5_REGNUM
)
2314 || (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F7_REGNUM
))
2315 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
2317 /* The return address column. */
2318 else if (regnum
== S390_PC_REGNUM
)
2319 reg
->how
= DWARF2_FRAME_REG_RA
;
2325 /* Dummy function calls. */
2327 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
2328 "Integer-like" types are those that should be passed the way
2329 integers are: integers, enums, ranges, characters, and booleans. */
2331 is_integer_like (struct type
*type
)
2333 enum type_code code
= TYPE_CODE (type
);
2335 return (code
== TYPE_CODE_INT
2336 || code
== TYPE_CODE_ENUM
2337 || code
== TYPE_CODE_RANGE
2338 || code
== TYPE_CODE_CHAR
2339 || code
== TYPE_CODE_BOOL
);
2342 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
2343 "Pointer-like" types are those that should be passed the way
2344 pointers are: pointers and references. */
2346 is_pointer_like (struct type
*type
)
2348 enum type_code code
= TYPE_CODE (type
);
2350 return (code
== TYPE_CODE_PTR
2351 || code
== TYPE_CODE_REF
);
2355 /* Return non-zero if TYPE is a `float singleton' or `double
2356 singleton', zero otherwise.
2358 A `T singleton' is a struct type with one member, whose type is
2359 either T or a `T singleton'. So, the following are all float
2363 struct { struct { float x; } x; };
2364 struct { struct { struct { float x; } x; } x; };
2368 All such structures are passed as if they were floats or doubles,
2369 as the (revised) ABI says. */
2371 is_float_singleton (struct type
*type
)
2373 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type
) == 1)
2375 struct type
*singleton_type
= TYPE_FIELD_TYPE (type
, 0);
2376 CHECK_TYPEDEF (singleton_type
);
2378 return (TYPE_CODE (singleton_type
) == TYPE_CODE_FLT
2379 || is_float_singleton (singleton_type
));
2386 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
2387 "Struct-like" types are those that should be passed as structs are:
2390 As an odd quirk, not mentioned in the ABI, GCC passes float and
2391 double singletons as if they were a plain float, double, etc. (The
2392 corresponding union types are handled normally.) So we exclude
2393 those types here. *shrug* */
2395 is_struct_like (struct type
*type
)
2397 enum type_code code
= TYPE_CODE (type
);
2399 return (code
== TYPE_CODE_UNION
2400 || (code
== TYPE_CODE_STRUCT
&& ! is_float_singleton (type
)));
2404 /* Return non-zero if TYPE is a float-like type, zero otherwise.
2405 "Float-like" types are those that should be passed as
2406 floating-point values are.
2408 You'd think this would just be floats, doubles, long doubles, etc.
2409 But as an odd quirk, not mentioned in the ABI, GCC passes float and
2410 double singletons as if they were a plain float, double, etc. (The
2411 corresponding union types are handled normally.) So we include
2412 those types here. *shrug* */
2414 is_float_like (struct type
*type
)
2416 return (TYPE_CODE (type
) == TYPE_CODE_FLT
2417 || is_float_singleton (type
));
2422 is_power_of_two (unsigned int n
)
2424 return ((n
& (n
- 1)) == 0);
2427 /* Return non-zero if TYPE should be passed as a pointer to a copy,
2430 s390_function_arg_pass_by_reference (struct type
*type
)
2432 unsigned length
= TYPE_LENGTH (type
);
2436 /* FIXME: All complex and vector types are also returned by reference. */
2437 return is_struct_like (type
) && !is_power_of_two (length
);
2440 /* Return non-zero if TYPE should be passed in a float register
2443 s390_function_arg_float (struct type
*type
)
2445 unsigned length
= TYPE_LENGTH (type
);
2449 return is_float_like (type
);
2452 /* Return non-zero if TYPE should be passed in an integer register
2453 (or a pair of integer registers) if possible. */
2455 s390_function_arg_integer (struct type
*type
)
2457 unsigned length
= TYPE_LENGTH (type
);
2461 return is_integer_like (type
)
2462 || is_pointer_like (type
)
2463 || (is_struct_like (type
) && is_power_of_two (length
));
2466 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
2467 word as required for the ABI. */
2469 extend_simple_arg (struct value
*arg
)
2471 struct type
*type
= value_type (arg
);
2473 /* Even structs get passed in the least significant bits of the
2474 register / memory word. It's not really right to extract them as
2475 an integer, but it does take care of the extension. */
2476 if (TYPE_UNSIGNED (type
))
2477 return extract_unsigned_integer (value_contents (arg
),
2478 TYPE_LENGTH (type
));
2480 return extract_signed_integer (value_contents (arg
),
2481 TYPE_LENGTH (type
));
2485 /* Return the alignment required by TYPE. */
2487 alignment_of (struct type
*type
)
2491 if (is_integer_like (type
)
2492 || is_pointer_like (type
)
2493 || TYPE_CODE (type
) == TYPE_CODE_FLT
)
2494 alignment
= TYPE_LENGTH (type
);
2495 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
2496 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
2501 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
2503 int field_alignment
= alignment_of (TYPE_FIELD_TYPE (type
, i
));
2505 if (field_alignment
> alignment
)
2506 alignment
= field_alignment
;
2512 /* Check that everything we ever return is a power of two. Lots of
2513 code doesn't want to deal with aligning things to arbitrary
2515 gdb_assert ((alignment
& (alignment
- 1)) == 0);
2521 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2522 place to be passed to a function, as specified by the "GNU/Linux
2523 for S/390 ELF Application Binary Interface Supplement".
2525 SP is the current stack pointer. We must put arguments, links,
2526 padding, etc. whereever they belong, and return the new stack
2529 If STRUCT_RETURN is non-zero, then the function we're calling is
2530 going to return a structure by value; STRUCT_ADDR is the address of
2531 a block we've allocated for it on the stack.
2533 Our caller has taken care of any type promotions needed to satisfy
2534 prototypes or the old K&R argument-passing rules. */
2536 s390_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2537 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2538 int nargs
, struct value
**args
, CORE_ADDR sp
,
2539 int struct_return
, CORE_ADDR struct_addr
)
2541 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2542 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2546 /* If the i'th argument is passed as a reference to a copy, then
2547 copy_addr[i] is the address of the copy we made. */
2548 CORE_ADDR
*copy_addr
= alloca (nargs
* sizeof (CORE_ADDR
));
2550 /* Build the reference-to-copy area. */
2551 for (i
= 0; i
< nargs
; i
++)
2553 struct value
*arg
= args
[i
];
2554 struct type
*type
= value_type (arg
);
2555 unsigned length
= TYPE_LENGTH (type
);
2557 if (s390_function_arg_pass_by_reference (type
))
2560 sp
= align_down (sp
, alignment_of (type
));
2561 write_memory (sp
, value_contents (arg
), length
);
2566 /* Reserve space for the parameter area. As a conservative
2567 simplification, we assume that everything will be passed on the
2568 stack. Since every argument larger than 8 bytes will be
2569 passed by reference, we use this simple upper bound. */
2572 /* After all that, make sure it's still aligned on an eight-byte
2574 sp
= align_down (sp
, 8);
2576 /* Finally, place the actual parameters, working from SP towards
2577 higher addresses. The code above is supposed to reserve enough
2582 CORE_ADDR starg
= sp
;
2584 /* A struct is returned using general register 2. */
2587 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2592 for (i
= 0; i
< nargs
; i
++)
2594 struct value
*arg
= args
[i
];
2595 struct type
*type
= value_type (arg
);
2596 unsigned length
= TYPE_LENGTH (type
);
2598 if (s390_function_arg_pass_by_reference (type
))
2602 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2608 write_memory_unsigned_integer (starg
, word_size
, copy_addr
[i
]);
2612 else if (s390_function_arg_float (type
))
2614 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2615 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2616 if (fr
<= (tdep
->abi
== ABI_LINUX_S390
? 2 : 6))
2618 /* When we store a single-precision value in an FP register,
2619 it occupies the leftmost bits. */
2620 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
+ fr
,
2621 0, length
, value_contents (arg
));
2626 /* When we store a single-precision value in a stack slot,
2627 it occupies the rightmost bits. */
2628 starg
= align_up (starg
+ length
, word_size
);
2629 write_memory (starg
- length
, value_contents (arg
), length
);
2632 else if (s390_function_arg_integer (type
) && length
<= word_size
)
2636 /* Integer arguments are always extended to word size. */
2637 regcache_cooked_write_signed (regcache
, S390_R0_REGNUM
+ gr
,
2638 extend_simple_arg (arg
));
2643 /* Integer arguments are always extended to word size. */
2644 write_memory_signed_integer (starg
, word_size
,
2645 extend_simple_arg (arg
));
2649 else if (s390_function_arg_integer (type
) && length
== 2*word_size
)
2653 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
,
2654 value_contents (arg
));
2655 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
+ 1,
2656 value_contents (arg
) + word_size
);
2661 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2662 in it, then don't go back and use it again later. */
2665 write_memory (starg
, value_contents (arg
), length
);
2670 internal_error (__FILE__
, __LINE__
, _("unknown argument type"));
2674 /* Allocate the standard frame areas: the register save area, the
2675 word reserved for the compiler (which seems kind of meaningless),
2676 and the back chain pointer. */
2677 sp
-= 16*word_size
+ 32;
2679 /* Store return address. */
2680 regcache_cooked_write_unsigned (regcache
, S390_RETADDR_REGNUM
, bp_addr
);
2682 /* Store updated stack pointer. */
2683 regcache_cooked_write_unsigned (regcache
, S390_SP_REGNUM
, sp
);
2685 /* We need to return the 'stack part' of the frame ID,
2686 which is actually the top of the register save area. */
2687 return sp
+ 16*word_size
+ 32;
2690 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
2691 dummy frame. The frame ID's base needs to match the TOS value
2692 returned by push_dummy_call, and the PC match the dummy frame's
2694 static struct frame_id
2695 s390_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2697 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2698 CORE_ADDR sp
= s390_unwind_sp (gdbarch
, next_frame
);
2700 return frame_id_build (sp
+ 16*word_size
+ 32,
2701 frame_pc_unwind (next_frame
));
2705 s390_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2707 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2708 always be aligned on an eight-byte boundary. */
2713 /* Function return value access. */
2715 static enum return_value_convention
2716 s390_return_value_convention (struct gdbarch
*gdbarch
, struct type
*type
)
2718 int length
= TYPE_LENGTH (type
);
2720 return RETURN_VALUE_STRUCT_CONVENTION
;
2722 switch (TYPE_CODE (type
))
2724 case TYPE_CODE_STRUCT
:
2725 case TYPE_CODE_UNION
:
2726 case TYPE_CODE_ARRAY
:
2727 return RETURN_VALUE_STRUCT_CONVENTION
;
2730 return RETURN_VALUE_REGISTER_CONVENTION
;
2734 static enum return_value_convention
2735 s390_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
2736 struct regcache
*regcache
, gdb_byte
*out
,
2739 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2740 int length
= TYPE_LENGTH (type
);
2741 enum return_value_convention rvc
=
2742 s390_return_value_convention (gdbarch
, type
);
2747 case RETURN_VALUE_REGISTER_CONVENTION
:
2748 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2750 /* When we store a single-precision value in an FP register,
2751 it occupies the leftmost bits. */
2752 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
,
2755 else if (length
<= word_size
)
2757 /* Integer arguments are always extended to word size. */
2758 if (TYPE_UNSIGNED (type
))
2759 regcache_cooked_write_unsigned (regcache
, S390_R2_REGNUM
,
2760 extract_unsigned_integer (in
, length
));
2762 regcache_cooked_write_signed (regcache
, S390_R2_REGNUM
,
2763 extract_signed_integer (in
, length
));
2765 else if (length
== 2*word_size
)
2767 regcache_cooked_write (regcache
, S390_R2_REGNUM
, in
);
2768 regcache_cooked_write (regcache
, S390_R3_REGNUM
, in
+ word_size
);
2771 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2774 case RETURN_VALUE_STRUCT_CONVENTION
:
2775 error (_("Cannot set function return value."));
2783 case RETURN_VALUE_REGISTER_CONVENTION
:
2784 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2786 /* When we store a single-precision value in an FP register,
2787 it occupies the leftmost bits. */
2788 regcache_cooked_read_part (regcache
, S390_F0_REGNUM
,
2791 else if (length
<= word_size
)
2793 /* Integer arguments occupy the rightmost bits. */
2794 regcache_cooked_read_part (regcache
, S390_R2_REGNUM
,
2795 word_size
- length
, length
, out
);
2797 else if (length
== 2*word_size
)
2799 regcache_cooked_read (regcache
, S390_R2_REGNUM
, out
);
2800 regcache_cooked_read (regcache
, S390_R3_REGNUM
, out
+ word_size
);
2803 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2806 case RETURN_VALUE_STRUCT_CONVENTION
:
2807 error (_("Function return value unknown."));
2818 static const gdb_byte
*
2819 s390_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
2821 static const gdb_byte breakpoint
[] = { 0x0, 0x1 };
2823 *lenptr
= sizeof (breakpoint
);
2828 /* Address handling. */
2831 s390_addr_bits_remove (CORE_ADDR addr
)
2833 return addr
& 0x7fffffff;
2837 s390_address_class_type_flags (int byte_size
, int dwarf2_addr_class
)
2840 return TYPE_FLAG_ADDRESS_CLASS_1
;
2846 s390_address_class_type_flags_to_name (struct gdbarch
*gdbarch
, int type_flags
)
2848 if (type_flags
& TYPE_FLAG_ADDRESS_CLASS_1
)
2855 s390_address_class_name_to_type_flags (struct gdbarch
*gdbarch
, const char *name
,
2856 int *type_flags_ptr
)
2858 if (strcmp (name
, "mode32") == 0)
2860 *type_flags_ptr
= TYPE_FLAG_ADDRESS_CLASS_1
;
2867 /* Set up gdbarch struct. */
2869 static struct gdbarch
*
2870 s390_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2872 struct gdbarch
*gdbarch
;
2873 struct gdbarch_tdep
*tdep
;
2875 /* First see if there is already a gdbarch that can satisfy the request. */
2876 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2878 return arches
->gdbarch
;
2880 /* None found: is the request for a s390 architecture? */
2881 if (info
.bfd_arch_info
->arch
!= bfd_arch_s390
)
2882 return NULL
; /* No; then it's not for us. */
2884 /* Yes: create a new gdbarch for the specified machine type. */
2885 tdep
= XCALLOC (1, struct gdbarch_tdep
);
2886 gdbarch
= gdbarch_alloc (&info
, tdep
);
2888 set_gdbarch_believe_pcc_promotion (gdbarch
, 0);
2889 set_gdbarch_char_signed (gdbarch
, 0);
2891 /* Amount PC must be decremented by after a breakpoint. This is
2892 often the number of bytes returned by BREAKPOINT_FROM_PC but not
2894 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
2895 /* Stack grows downward. */
2896 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2897 set_gdbarch_breakpoint_from_pc (gdbarch
, s390_breakpoint_from_pc
);
2898 set_gdbarch_skip_prologue (gdbarch
, s390_skip_prologue
);
2899 set_gdbarch_in_function_epilogue_p (gdbarch
, s390_in_function_epilogue_p
);
2901 set_gdbarch_pc_regnum (gdbarch
, S390_PC_REGNUM
);
2902 set_gdbarch_sp_regnum (gdbarch
, S390_SP_REGNUM
);
2903 set_gdbarch_fp0_regnum (gdbarch
, S390_F0_REGNUM
);
2904 set_gdbarch_num_regs (gdbarch
, S390_NUM_REGS
);
2905 set_gdbarch_num_pseudo_regs (gdbarch
, S390_NUM_PSEUDO_REGS
);
2906 set_gdbarch_register_name (gdbarch
, s390_register_name
);
2907 set_gdbarch_register_type (gdbarch
, s390_register_type
);
2908 set_gdbarch_stab_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2909 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2910 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2911 set_gdbarch_convert_register_p (gdbarch
, s390_convert_register_p
);
2912 set_gdbarch_register_to_value (gdbarch
, s390_register_to_value
);
2913 set_gdbarch_value_to_register (gdbarch
, s390_value_to_register
);
2914 set_gdbarch_register_reggroup_p (gdbarch
, s390_register_reggroup_p
);
2915 set_gdbarch_regset_from_core_section (gdbarch
,
2916 s390_regset_from_core_section
);
2918 /* Inferior function calls. */
2919 set_gdbarch_push_dummy_call (gdbarch
, s390_push_dummy_call
);
2920 set_gdbarch_unwind_dummy_id (gdbarch
, s390_unwind_dummy_id
);
2921 set_gdbarch_frame_align (gdbarch
, s390_frame_align
);
2922 set_gdbarch_return_value (gdbarch
, s390_return_value
);
2924 /* Frame handling. */
2925 dwarf2_frame_set_init_reg (gdbarch
, s390_dwarf2_frame_init_reg
);
2926 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
2927 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
2928 frame_unwind_append_sniffer (gdbarch
, s390_stub_frame_sniffer
);
2929 frame_unwind_append_sniffer (gdbarch
, s390_sigtramp_frame_sniffer
);
2930 frame_unwind_append_sniffer (gdbarch
, s390_frame_sniffer
);
2931 frame_base_set_default (gdbarch
, &s390_frame_base
);
2932 set_gdbarch_unwind_pc (gdbarch
, s390_unwind_pc
);
2933 set_gdbarch_unwind_sp (gdbarch
, s390_unwind_sp
);
2935 switch (info
.bfd_arch_info
->mach
)
2937 case bfd_mach_s390_31
:
2938 tdep
->abi
= ABI_LINUX_S390
;
2940 tdep
->gregset
= &s390_gregset
;
2941 tdep
->sizeof_gregset
= s390_sizeof_gregset
;
2942 tdep
->fpregset
= &s390_fpregset
;
2943 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
2945 set_gdbarch_addr_bits_remove (gdbarch
, s390_addr_bits_remove
);
2946 set_gdbarch_pseudo_register_read (gdbarch
, s390_pseudo_register_read
);
2947 set_gdbarch_pseudo_register_write (gdbarch
, s390_pseudo_register_write
);
2948 set_solib_svr4_fetch_link_map_offsets
2949 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
2952 case bfd_mach_s390_64
:
2953 tdep
->abi
= ABI_LINUX_ZSERIES
;
2955 tdep
->gregset
= &s390x_gregset
;
2956 tdep
->sizeof_gregset
= s390x_sizeof_gregset
;
2957 tdep
->fpregset
= &s390_fpregset
;
2958 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
2960 set_gdbarch_long_bit (gdbarch
, 64);
2961 set_gdbarch_long_long_bit (gdbarch
, 64);
2962 set_gdbarch_ptr_bit (gdbarch
, 64);
2963 set_gdbarch_pseudo_register_read (gdbarch
, s390x_pseudo_register_read
);
2964 set_gdbarch_pseudo_register_write (gdbarch
, s390x_pseudo_register_write
);
2965 set_solib_svr4_fetch_link_map_offsets
2966 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
2967 set_gdbarch_address_class_type_flags (gdbarch
,
2968 s390_address_class_type_flags
);
2969 set_gdbarch_address_class_type_flags_to_name (gdbarch
,
2970 s390_address_class_type_flags_to_name
);
2971 set_gdbarch_address_class_name_to_type_flags (gdbarch
,
2972 s390_address_class_name_to_type_flags
);
2976 set_gdbarch_print_insn (gdbarch
, print_insn_s390
);
2978 /* Enable TLS support. */
2979 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
2980 svr4_fetch_objfile_link_map
);
2987 extern initialize_file_ftype _initialize_s390_tdep
; /* -Wmissing-prototypes */
2990 _initialize_s390_tdep (void)
2993 /* Hook us into the gdbarch mechanism. */
2994 register_gdbarch_init (bfd_arch_s390
, s390_gdbarch_init
);