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"
47 #include "prologue-value.h"
49 #include "s390-tdep.h"
52 /* The tdep structure. */
57 enum { ABI_LINUX_S390
, ABI_LINUX_ZSERIES
} abi
;
59 /* Core file register sets. */
60 const struct regset
*gregset
;
63 const struct regset
*fpregset
;
68 /* Register information. */
70 struct s390_register_info
76 static struct s390_register_info s390_register_info
[S390_NUM_TOTAL_REGS
] =
78 /* Program Status Word. */
79 { "pswm", &builtin_type_long
},
80 { "pswa", &builtin_type_long
},
82 /* General Purpose Registers. */
83 { "r0", &builtin_type_long
},
84 { "r1", &builtin_type_long
},
85 { "r2", &builtin_type_long
},
86 { "r3", &builtin_type_long
},
87 { "r4", &builtin_type_long
},
88 { "r5", &builtin_type_long
},
89 { "r6", &builtin_type_long
},
90 { "r7", &builtin_type_long
},
91 { "r8", &builtin_type_long
},
92 { "r9", &builtin_type_long
},
93 { "r10", &builtin_type_long
},
94 { "r11", &builtin_type_long
},
95 { "r12", &builtin_type_long
},
96 { "r13", &builtin_type_long
},
97 { "r14", &builtin_type_long
},
98 { "r15", &builtin_type_long
},
100 /* Access Registers. */
101 { "acr0", &builtin_type_int
},
102 { "acr1", &builtin_type_int
},
103 { "acr2", &builtin_type_int
},
104 { "acr3", &builtin_type_int
},
105 { "acr4", &builtin_type_int
},
106 { "acr5", &builtin_type_int
},
107 { "acr6", &builtin_type_int
},
108 { "acr7", &builtin_type_int
},
109 { "acr8", &builtin_type_int
},
110 { "acr9", &builtin_type_int
},
111 { "acr10", &builtin_type_int
},
112 { "acr11", &builtin_type_int
},
113 { "acr12", &builtin_type_int
},
114 { "acr13", &builtin_type_int
},
115 { "acr14", &builtin_type_int
},
116 { "acr15", &builtin_type_int
},
118 /* Floating Point Control Word. */
119 { "fpc", &builtin_type_int
},
121 /* Floating Point Registers. */
122 { "f0", &builtin_type_double
},
123 { "f1", &builtin_type_double
},
124 { "f2", &builtin_type_double
},
125 { "f3", &builtin_type_double
},
126 { "f4", &builtin_type_double
},
127 { "f5", &builtin_type_double
},
128 { "f6", &builtin_type_double
},
129 { "f7", &builtin_type_double
},
130 { "f8", &builtin_type_double
},
131 { "f9", &builtin_type_double
},
132 { "f10", &builtin_type_double
},
133 { "f11", &builtin_type_double
},
134 { "f12", &builtin_type_double
},
135 { "f13", &builtin_type_double
},
136 { "f14", &builtin_type_double
},
137 { "f15", &builtin_type_double
},
139 /* Pseudo registers. */
140 { "pc", &builtin_type_void_func_ptr
},
141 { "cc", &builtin_type_int
},
144 /* Return the name of register REGNUM. */
146 s390_register_name (int regnum
)
148 gdb_assert (regnum
>= 0 && regnum
< S390_NUM_TOTAL_REGS
);
149 return s390_register_info
[regnum
].name
;
152 /* Return the GDB type object for the "standard" data type of data in
155 s390_register_type (struct gdbarch
*gdbarch
, int regnum
)
157 gdb_assert (regnum
>= 0 && regnum
< S390_NUM_TOTAL_REGS
);
158 return *s390_register_info
[regnum
].type
;
161 /* DWARF Register Mapping. */
163 static int s390_dwarf_regmap
[] =
165 /* General Purpose Registers. */
166 S390_R0_REGNUM
, S390_R1_REGNUM
, S390_R2_REGNUM
, S390_R3_REGNUM
,
167 S390_R4_REGNUM
, S390_R5_REGNUM
, S390_R6_REGNUM
, S390_R7_REGNUM
,
168 S390_R8_REGNUM
, S390_R9_REGNUM
, S390_R10_REGNUM
, S390_R11_REGNUM
,
169 S390_R12_REGNUM
, S390_R13_REGNUM
, S390_R14_REGNUM
, S390_R15_REGNUM
,
171 /* Floating Point Registers. */
172 S390_F0_REGNUM
, S390_F2_REGNUM
, S390_F4_REGNUM
, S390_F6_REGNUM
,
173 S390_F1_REGNUM
, S390_F3_REGNUM
, S390_F5_REGNUM
, S390_F7_REGNUM
,
174 S390_F8_REGNUM
, S390_F10_REGNUM
, S390_F12_REGNUM
, S390_F14_REGNUM
,
175 S390_F9_REGNUM
, S390_F11_REGNUM
, S390_F13_REGNUM
, S390_F15_REGNUM
,
177 /* Control Registers (not mapped). */
178 -1, -1, -1, -1, -1, -1, -1, -1,
179 -1, -1, -1, -1, -1, -1, -1, -1,
181 /* Access Registers. */
182 S390_A0_REGNUM
, S390_A1_REGNUM
, S390_A2_REGNUM
, S390_A3_REGNUM
,
183 S390_A4_REGNUM
, S390_A5_REGNUM
, S390_A6_REGNUM
, S390_A7_REGNUM
,
184 S390_A8_REGNUM
, S390_A9_REGNUM
, S390_A10_REGNUM
, S390_A11_REGNUM
,
185 S390_A12_REGNUM
, S390_A13_REGNUM
, S390_A14_REGNUM
, S390_A15_REGNUM
,
187 /* Program Status Word. */
192 /* Convert DWARF register number REG to the appropriate register
193 number used by GDB. */
195 s390_dwarf_reg_to_regnum (int reg
)
199 if (reg
>= 0 && reg
< ARRAY_SIZE (s390_dwarf_regmap
))
200 regnum
= s390_dwarf_regmap
[reg
];
203 warning (_("Unmapped DWARF Register #%d encountered."), reg
);
208 /* Pseudo registers - PC and condition code. */
211 s390_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
212 int regnum
, gdb_byte
*buf
)
219 regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &val
);
220 store_unsigned_integer (buf
, 4, val
& 0x7fffffff);
224 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &val
);
225 store_unsigned_integer (buf
, 4, (val
>> 12) & 3);
229 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
234 s390_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
235 int regnum
, const gdb_byte
*buf
)
242 val
= extract_unsigned_integer (buf
, 4);
243 regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &psw
);
244 psw
= (psw
& 0x80000000) | (val
& 0x7fffffff);
245 regcache_raw_write_unsigned (regcache
, S390_PSWA_REGNUM
, psw
);
249 val
= extract_unsigned_integer (buf
, 4);
250 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &psw
);
251 psw
= (psw
& ~((ULONGEST
)3 << 12)) | ((val
& 3) << 12);
252 regcache_raw_write_unsigned (regcache
, S390_PSWM_REGNUM
, psw
);
256 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
261 s390x_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
262 int regnum
, gdb_byte
*buf
)
269 regcache_raw_read (regcache
, S390_PSWA_REGNUM
, buf
);
273 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &val
);
274 store_unsigned_integer (buf
, 4, (val
>> 44) & 3);
278 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
283 s390x_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
284 int regnum
, const gdb_byte
*buf
)
291 regcache_raw_write (regcache
, S390_PSWA_REGNUM
, buf
);
295 val
= extract_unsigned_integer (buf
, 4);
296 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &psw
);
297 psw
= (psw
& ~((ULONGEST
)3 << 44)) | ((val
& 3) << 44);
298 regcache_raw_write_unsigned (regcache
, S390_PSWM_REGNUM
, psw
);
302 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
306 /* 'float' values are stored in the upper half of floating-point
307 registers, even though we are otherwise a big-endian platform. */
310 s390_convert_register_p (int regno
, struct type
*type
)
312 return (regno
>= S390_F0_REGNUM
&& regno
<= S390_F15_REGNUM
)
313 && TYPE_LENGTH (type
) < 8;
317 s390_register_to_value (struct frame_info
*frame
, int regnum
,
318 struct type
*valtype
, gdb_byte
*out
)
321 int len
= TYPE_LENGTH (valtype
);
322 gdb_assert (len
< 8);
324 get_frame_register (frame
, regnum
, in
);
325 memcpy (out
, in
, len
);
329 s390_value_to_register (struct frame_info
*frame
, int regnum
,
330 struct type
*valtype
, const gdb_byte
*in
)
333 int len
= TYPE_LENGTH (valtype
);
334 gdb_assert (len
< 8);
337 memcpy (out
, in
, len
);
338 put_frame_register (frame
, regnum
, out
);
341 /* Register groups. */
344 s390_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
345 struct reggroup
*group
)
347 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
349 /* Registers displayed via 'info regs'. */
350 if (group
== general_reggroup
)
351 return (regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R15_REGNUM
)
352 || regnum
== S390_PC_REGNUM
353 || regnum
== S390_CC_REGNUM
;
355 /* Registers displayed via 'info float'. */
356 if (group
== float_reggroup
)
357 return (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
)
358 || regnum
== S390_FPC_REGNUM
;
360 /* Registers that need to be saved/restored in order to
361 push or pop frames. */
362 if (group
== save_reggroup
|| group
== restore_reggroup
)
363 return regnum
!= S390_PSWM_REGNUM
&& regnum
!= S390_PSWA_REGNUM
;
365 return default_register_reggroup_p (gdbarch
, regnum
, group
);
369 /* Core file register sets. */
371 int s390_regmap_gregset
[S390_NUM_REGS
] =
373 /* Program Status Word. */
375 /* General Purpose Registers. */
376 0x08, 0x0c, 0x10, 0x14,
377 0x18, 0x1c, 0x20, 0x24,
378 0x28, 0x2c, 0x30, 0x34,
379 0x38, 0x3c, 0x40, 0x44,
380 /* Access Registers. */
381 0x48, 0x4c, 0x50, 0x54,
382 0x58, 0x5c, 0x60, 0x64,
383 0x68, 0x6c, 0x70, 0x74,
384 0x78, 0x7c, 0x80, 0x84,
385 /* Floating Point Control Word. */
387 /* Floating Point Registers. */
388 -1, -1, -1, -1, -1, -1, -1, -1,
389 -1, -1, -1, -1, -1, -1, -1, -1,
392 int s390x_regmap_gregset
[S390_NUM_REGS
] =
395 /* General Purpose Registers. */
396 0x10, 0x18, 0x20, 0x28,
397 0x30, 0x38, 0x40, 0x48,
398 0x50, 0x58, 0x60, 0x68,
399 0x70, 0x78, 0x80, 0x88,
400 /* Access Registers. */
401 0x90, 0x94, 0x98, 0x9c,
402 0xa0, 0xa4, 0xa8, 0xac,
403 0xb0, 0xb4, 0xb8, 0xbc,
404 0xc0, 0xc4, 0xc8, 0xcc,
405 /* Floating Point Control Word. */
407 /* Floating Point Registers. */
408 -1, -1, -1, -1, -1, -1, -1, -1,
409 -1, -1, -1, -1, -1, -1, -1, -1,
412 int s390_regmap_fpregset
[S390_NUM_REGS
] =
414 /* Program Status Word. */
416 /* General Purpose Registers. */
417 -1, -1, -1, -1, -1, -1, -1, -1,
418 -1, -1, -1, -1, -1, -1, -1, -1,
419 /* Access Registers. */
420 -1, -1, -1, -1, -1, -1, -1, -1,
421 -1, -1, -1, -1, -1, -1, -1, -1,
422 /* Floating Point Control Word. */
424 /* Floating Point Registers. */
425 0x08, 0x10, 0x18, 0x20,
426 0x28, 0x30, 0x38, 0x40,
427 0x48, 0x50, 0x58, 0x60,
428 0x68, 0x70, 0x78, 0x80,
431 /* Supply register REGNUM from the register set REGSET to register cache
432 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
434 s390_supply_regset (const struct regset
*regset
, struct regcache
*regcache
,
435 int regnum
, const void *regs
, size_t len
)
437 const int *offset
= regset
->descr
;
440 for (i
= 0; i
< S390_NUM_REGS
; i
++)
442 if ((regnum
== i
|| regnum
== -1) && offset
[i
] != -1)
443 regcache_raw_supply (regcache
, i
, (const char *)regs
+ offset
[i
]);
447 static const struct regset s390_gregset
= {
452 static const struct regset s390x_gregset
= {
453 s390x_regmap_gregset
,
457 static const struct regset s390_fpregset
= {
458 s390_regmap_fpregset
,
462 /* Return the appropriate register set for the core section identified
463 by SECT_NAME and SECT_SIZE. */
464 const struct regset
*
465 s390_regset_from_core_section (struct gdbarch
*gdbarch
,
466 const char *sect_name
, size_t sect_size
)
468 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
470 if (strcmp (sect_name
, ".reg") == 0 && sect_size
== tdep
->sizeof_gregset
)
471 return tdep
->gregset
;
473 if (strcmp (sect_name
, ".reg2") == 0 && sect_size
== tdep
->sizeof_fpregset
)
474 return tdep
->fpregset
;
480 /* Decoding S/390 instructions. */
482 /* Named opcode values for the S/390 instructions we recognize. Some
483 instructions have their opcode split across two fields; those are the
484 op1_* and op2_* enums. */
487 op1_lhi
= 0xa7, op2_lhi
= 0x08,
488 op1_lghi
= 0xa7, op2_lghi
= 0x09,
489 op1_lgfi
= 0xc0, op2_lgfi
= 0x01,
493 op1_ly
= 0xe3, op2_ly
= 0x58,
494 op1_lg
= 0xe3, op2_lg
= 0x04,
496 op1_lmy
= 0xeb, op2_lmy
= 0x98,
497 op1_lmg
= 0xeb, op2_lmg
= 0x04,
499 op1_sty
= 0xe3, op2_sty
= 0x50,
500 op1_stg
= 0xe3, op2_stg
= 0x24,
503 op1_stmy
= 0xeb, op2_stmy
= 0x90,
504 op1_stmg
= 0xeb, op2_stmg
= 0x24,
505 op1_aghi
= 0xa7, op2_aghi
= 0x0b,
506 op1_ahi
= 0xa7, op2_ahi
= 0x0a,
507 op1_agfi
= 0xc2, op2_agfi
= 0x08,
508 op1_afi
= 0xc2, op2_afi
= 0x09,
509 op1_algfi
= 0xc2, op2_algfi
= 0x0a,
510 op1_alfi
= 0xc2, op2_alfi
= 0x0b,
514 op1_ay
= 0xe3, op2_ay
= 0x5a,
515 op1_ag
= 0xe3, op2_ag
= 0x08,
516 op1_slgfi
= 0xc2, op2_slgfi
= 0x04,
517 op1_slfi
= 0xc2, op2_slfi
= 0x05,
521 op1_sy
= 0xe3, op2_sy
= 0x5b,
522 op1_sg
= 0xe3, op2_sg
= 0x09,
526 op1_lay
= 0xe3, op2_lay
= 0x71,
527 op1_larl
= 0xc0, op2_larl
= 0x00,
532 op1_bras
= 0xa7, op2_bras
= 0x05,
533 op1_brasl
= 0xc0, op2_brasl
= 0x05,
534 op1_brc
= 0xa7, op2_brc
= 0x04,
535 op1_brcl
= 0xc0, op2_brcl
= 0x04,
539 /* Read a single instruction from address AT. */
541 #define S390_MAX_INSTR_SIZE 6
543 s390_readinstruction (bfd_byte instr
[], CORE_ADDR at
)
545 static int s390_instrlen
[] = { 2, 4, 4, 6 };
548 if (deprecated_read_memory_nobpt (at
, &instr
[0], 2))
550 instrlen
= s390_instrlen
[instr
[0] >> 6];
553 if (deprecated_read_memory_nobpt (at
+ 2, &instr
[2], instrlen
- 2))
560 /* The functions below are for recognizing and decoding S/390
561 instructions of various formats. Each of them checks whether INSN
562 is an instruction of the given format, with the specified opcodes.
563 If it is, it sets the remaining arguments to the values of the
564 instruction's fields, and returns a non-zero value; otherwise, it
567 These functions' arguments appear in the order they appear in the
568 instruction, not in the machine-language form. So, opcodes always
569 come first, even though they're sometimes scattered around the
570 instructions. And displacements appear before base and extension
571 registers, as they do in the assembly syntax, not at the end, as
572 they do in the machine language. */
574 is_ri (bfd_byte
*insn
, int op1
, int op2
, unsigned int *r1
, int *i2
)
576 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
578 *r1
= (insn
[1] >> 4) & 0xf;
579 /* i2 is a 16-bit signed quantity. */
580 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
589 is_ril (bfd_byte
*insn
, int op1
, int op2
,
590 unsigned int *r1
, int *i2
)
592 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
594 *r1
= (insn
[1] >> 4) & 0xf;
595 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
596 no sign extension is necessary, but we don't want to assume
598 *i2
= (((insn
[2] << 24)
601 | (insn
[5])) ^ 0x80000000) - 0x80000000;
610 is_rr (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
614 *r1
= (insn
[1] >> 4) & 0xf;
624 is_rre (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
626 if (((insn
[0] << 8) | insn
[1]) == op
)
628 /* Yes, insn[3]. insn[2] is unused in RRE format. */
629 *r1
= (insn
[3] >> 4) & 0xf;
639 is_rs (bfd_byte
*insn
, int op
,
640 unsigned int *r1
, unsigned int *r3
, unsigned int *d2
, unsigned int *b2
)
644 *r1
= (insn
[1] >> 4) & 0xf;
646 *b2
= (insn
[2] >> 4) & 0xf;
647 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
656 is_rsy (bfd_byte
*insn
, int op1
, int op2
,
657 unsigned int *r1
, unsigned int *r3
, unsigned int *d2
, unsigned int *b2
)
662 *r1
= (insn
[1] >> 4) & 0xf;
664 *b2
= (insn
[2] >> 4) & 0xf;
665 /* The 'long displacement' is a 20-bit signed integer. */
666 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
667 ^ 0x80000) - 0x80000;
676 is_rx (bfd_byte
*insn
, int op
,
677 unsigned int *r1
, unsigned int *d2
, unsigned int *x2
, unsigned int *b2
)
681 *r1
= (insn
[1] >> 4) & 0xf;
683 *b2
= (insn
[2] >> 4) & 0xf;
684 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
693 is_rxy (bfd_byte
*insn
, int op1
, int op2
,
694 unsigned int *r1
, unsigned int *d2
, unsigned int *x2
, unsigned int *b2
)
699 *r1
= (insn
[1] >> 4) & 0xf;
701 *b2
= (insn
[2] >> 4) & 0xf;
702 /* The 'long displacement' is a 20-bit signed integer. */
703 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
704 ^ 0x80000) - 0x80000;
712 /* Prologue analysis. */
714 #define S390_NUM_GPRS 16
715 #define S390_NUM_FPRS 16
717 struct s390_prologue_data
{
719 /* The size of a GPR or FPR. */
723 /* The general-purpose registers. */
724 pv_t gpr
[S390_NUM_GPRS
];
726 /* The floating-point registers. */
727 pv_t fpr
[S390_NUM_FPRS
];
729 /* The offset relative to the CFA where the incoming GPR N was saved
730 by the function prologue. 0 if not saved or unknown. */
731 int gpr_slot
[S390_NUM_GPRS
];
733 /* Likewise for FPRs. */
734 int fpr_slot
[S390_NUM_FPRS
];
736 /* Nonzero if the backchain was saved. This is assumed to be the
737 case when the incoming SP is saved at the current SP location. */
738 int back_chain_saved_p
;
741 /* Return the effective address for an X-style instruction, like:
745 Here, X2 and B2 are registers, and D2 is a signed 20-bit
746 constant; the effective address is the sum of all three. If either
747 X2 or B2 are zero, then it doesn't contribute to the sum --- this
748 means that r0 can't be used as either X2 or B2. */
750 s390_addr (struct s390_prologue_data
*data
,
751 int d2
, unsigned int x2
, unsigned int b2
)
755 result
= pv_constant (d2
);
757 result
= pv_add (result
, data
->gpr
[x2
]);
759 result
= pv_add (result
, data
->gpr
[b2
]);
764 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
766 s390_store (struct s390_prologue_data
*data
,
767 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
,
770 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
774 /* Check whether we are storing the backchain. */
775 offset
= pv_subtract (data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
], addr
);
777 if (pv_is_constant (offset
) && offset
.k
== 0)
778 if (size
== data
->gpr_size
779 && pv_is_register_k (value
, S390_SP_REGNUM
, 0))
781 data
->back_chain_saved_p
= 1;
786 /* Check whether we are storing a register into the stack. */
787 cfa
= pv_register (S390_SP_REGNUM
, 16 * data
->gpr_size
+ 32);
788 offset
= pv_subtract (cfa
, addr
);
790 if (pv_is_constant (offset
)
791 && offset
.k
< INT_MAX
&& offset
.k
> 0
792 && offset
.k
% data
->gpr_size
== 0)
794 /* If we are storing the original value of a register, we want to
795 record the CFA offset. If the same register is stored multiple
796 times, the stack slot with the highest address counts. */
798 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
799 if (size
== data
->gpr_size
800 && pv_is_register_k (value
, S390_R0_REGNUM
+ i
, 0))
801 if (data
->gpr_slot
[i
] == 0
802 || data
->gpr_slot
[i
] > offset
.k
)
804 data
->gpr_slot
[i
] = offset
.k
;
808 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
809 if (size
== data
->fpr_size
810 && pv_is_register_k (value
, S390_F0_REGNUM
+ i
, 0))
811 if (data
->fpr_slot
[i
] == 0
812 || data
->fpr_slot
[i
] > offset
.k
)
814 data
->fpr_slot
[i
] = offset
.k
;
820 /* Note: If this is some store we cannot identify, you might think we
821 should forget our cached values, as any of those might have been hit.
823 However, we make the assumption that the register save areas are only
824 ever stored to once in any given function, and we do recognize these
825 stores. Thus every store we cannot recognize does not hit our data. */
828 /* Do a SIZE-byte load from D2(X2,B2). */
830 s390_load (struct s390_prologue_data
*data
,
831 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
)
834 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
838 /* If it's a load from an in-line constant pool, then we can
839 simulate that, under the assumption that the code isn't
840 going to change between the time the processor actually
841 executed it creating the current frame, and the time when
842 we're analyzing the code to unwind past that frame. */
843 if (pv_is_constant (addr
))
845 struct section_table
*secp
;
846 secp
= target_section_by_addr (¤t_target
, addr
.k
);
848 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
850 return pv_constant (read_memory_integer (addr
.k
, size
));
853 /* Check whether we are accessing one of our save slots. */
854 cfa
= pv_register (S390_SP_REGNUM
, 16 * data
->gpr_size
+ 32);
855 offset
= pv_subtract (cfa
, addr
);
857 if (pv_is_constant (offset
)
858 && offset
.k
< INT_MAX
&& offset
.k
> 0)
860 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
861 if (offset
.k
== data
->gpr_slot
[i
])
862 return pv_register (S390_R0_REGNUM
+ i
, 0);
864 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
865 if (offset
.k
== data
->fpr_slot
[i
])
866 return pv_register (S390_F0_REGNUM
+ i
, 0);
869 /* Otherwise, we don't know the value. */
870 return pv_unknown ();
874 /* Analyze the prologue of the function starting at START_PC,
875 continuing at most until CURRENT_PC. Initialize DATA to
876 hold all information we find out about the state of the registers
877 and stack slots. Return the address of the instruction after
878 the last one that changed the SP, FP, or back chain; or zero
881 s390_analyze_prologue (struct gdbarch
*gdbarch
,
883 CORE_ADDR current_pc
,
884 struct s390_prologue_data
*data
)
886 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
889 The address of the instruction after the last one that changed
890 the SP, FP, or back chain; zero if we got an error trying to
892 CORE_ADDR result
= start_pc
;
894 /* The current PC for our abstract interpretation. */
897 /* The address of the next instruction after that. */
900 /* Set up everything's initial value. */
904 /* For the purpose of prologue tracking, we consider the GPR size to
905 be equal to the ABI word size, even if it is actually larger
906 (i.e. when running a 32-bit binary under a 64-bit kernel). */
907 data
->gpr_size
= word_size
;
910 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
911 data
->gpr
[i
] = pv_register (S390_R0_REGNUM
+ i
, 0);
913 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
914 data
->fpr
[i
] = pv_register (S390_F0_REGNUM
+ i
, 0);
916 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
917 data
->gpr_slot
[i
] = 0;
919 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
920 data
->fpr_slot
[i
] = 0;
922 data
->back_chain_saved_p
= 0;
925 /* Start interpreting instructions, until we hit the frame's
926 current PC or the first branch instruction. */
927 for (pc
= start_pc
; pc
> 0 && pc
< current_pc
; pc
= next_pc
)
929 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
930 int insn_len
= s390_readinstruction (insn
, pc
);
932 bfd_byte dummy
[S390_MAX_INSTR_SIZE
] = { 0 };
933 bfd_byte
*insn32
= word_size
== 4 ? insn
: dummy
;
934 bfd_byte
*insn64
= word_size
== 8 ? insn
: dummy
;
936 /* Fields for various kinds of instructions. */
937 unsigned int b2
, r1
, r2
, x2
, r3
;
940 /* The values of SP and FP before this instruction,
941 for detecting instructions that change them. */
942 pv_t pre_insn_sp
, pre_insn_fp
;
943 /* Likewise for the flag whether the back chain was saved. */
944 int pre_insn_back_chain_saved_p
;
946 /* If we got an error trying to read the instruction, report it. */
953 next_pc
= pc
+ insn_len
;
955 pre_insn_sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
956 pre_insn_fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
957 pre_insn_back_chain_saved_p
= data
->back_chain_saved_p
;
960 /* LHI r1, i2 --- load halfword immediate. */
961 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
962 /* LGFI r1, i2 --- load fullword immediate. */
963 if (is_ri (insn32
, op1_lhi
, op2_lhi
, &r1
, &i2
)
964 || is_ri (insn64
, op1_lghi
, op2_lghi
, &r1
, &i2
)
965 || is_ril (insn
, op1_lgfi
, op2_lgfi
, &r1
, &i2
))
966 data
->gpr
[r1
] = pv_constant (i2
);
968 /* LR r1, r2 --- load from register. */
969 /* LGR r1, r2 --- load from register (64-bit version). */
970 else if (is_rr (insn32
, op_lr
, &r1
, &r2
)
971 || is_rre (insn64
, op_lgr
, &r1
, &r2
))
972 data
->gpr
[r1
] = data
->gpr
[r2
];
974 /* L r1, d2(x2, b2) --- load. */
975 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
976 /* LG r1, d2(x2, b2) --- load (64-bit version). */
977 else if (is_rx (insn32
, op_l
, &r1
, &d2
, &x2
, &b2
)
978 || is_rxy (insn32
, op1_ly
, op2_ly
, &r1
, &d2
, &x2
, &b2
)
979 || is_rxy (insn64
, op1_lg
, op2_lg
, &r1
, &d2
, &x2
, &b2
))
980 data
->gpr
[r1
] = s390_load (data
, d2
, x2
, b2
, data
->gpr_size
);
982 /* ST r1, d2(x2, b2) --- store. */
983 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
984 /* STG r1, d2(x2, b2) --- store (64-bit version). */
985 else if (is_rx (insn32
, op_st
, &r1
, &d2
, &x2
, &b2
)
986 || is_rxy (insn32
, op1_sty
, op2_sty
, &r1
, &d2
, &x2
, &b2
)
987 || is_rxy (insn64
, op1_stg
, op2_stg
, &r1
, &d2
, &x2
, &b2
))
988 s390_store (data
, d2
, x2
, b2
, data
->gpr_size
, data
->gpr
[r1
]);
990 /* STD r1, d2(x2,b2) --- store floating-point register. */
991 else if (is_rx (insn
, op_std
, &r1
, &d2
, &x2
, &b2
))
992 s390_store (data
, d2
, x2
, b2
, data
->fpr_size
, data
->fpr
[r1
]);
994 /* STM r1, r3, d2(b2) --- store multiple. */
995 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement version). */
996 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
997 else if (is_rs (insn32
, op_stm
, &r1
, &r3
, &d2
, &b2
)
998 || is_rsy (insn32
, op1_stmy
, op2_stmy
, &r1
, &r3
, &d2
, &b2
)
999 || is_rsy (insn64
, op1_stmg
, op2_stmg
, &r1
, &r3
, &d2
, &b2
))
1001 for (; r1
<= r3
; r1
++, d2
+= data
->gpr_size
)
1002 s390_store (data
, d2
, 0, b2
, data
->gpr_size
, data
->gpr
[r1
]);
1005 /* AHI r1, i2 --- add halfword immediate. */
1006 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
1007 /* AFI r1, i2 --- add fullword immediate. */
1008 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
1009 else if (is_ri (insn32
, op1_ahi
, op2_ahi
, &r1
, &i2
)
1010 || is_ri (insn64
, op1_aghi
, op2_aghi
, &r1
, &i2
)
1011 || is_ril (insn32
, op1_afi
, op2_afi
, &r1
, &i2
)
1012 || is_ril (insn64
, op1_agfi
, op2_agfi
, &r1
, &i2
))
1013 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
], i2
);
1015 /* ALFI r1, i2 --- add logical immediate. */
1016 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
1017 else if (is_ril (insn32
, op1_alfi
, op2_alfi
, &r1
, &i2
)
1018 || is_ril (insn64
, op1_algfi
, op2_algfi
, &r1
, &i2
))
1019 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
],
1020 (CORE_ADDR
)i2
& 0xffffffff);
1022 /* AR r1, r2 -- add register. */
1023 /* AGR r1, r2 -- add register (64-bit version). */
1024 else if (is_rr (insn32
, op_ar
, &r1
, &r2
)
1025 || is_rre (insn64
, op_agr
, &r1
, &r2
))
1026 data
->gpr
[r1
] = pv_add (data
->gpr
[r1
], data
->gpr
[r2
]);
1028 /* A r1, d2(x2, b2) -- add. */
1029 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
1030 /* AG r1, d2(x2, b2) -- add (64-bit version). */
1031 else if (is_rx (insn32
, op_a
, &r1
, &d2
, &x2
, &b2
)
1032 || is_rxy (insn32
, op1_ay
, op2_ay
, &r1
, &d2
, &x2
, &b2
)
1033 || is_rxy (insn64
, op1_ag
, op2_ag
, &r1
, &d2
, &x2
, &b2
))
1034 data
->gpr
[r1
] = pv_add (data
->gpr
[r1
],
1035 s390_load (data
, d2
, x2
, b2
, data
->gpr_size
));
1037 /* SLFI r1, i2 --- subtract logical immediate. */
1038 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
1039 else if (is_ril (insn32
, op1_slfi
, op2_slfi
, &r1
, &i2
)
1040 || is_ril (insn64
, op1_slgfi
, op2_slgfi
, &r1
, &i2
))
1041 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
],
1042 -((CORE_ADDR
)i2
& 0xffffffff));
1044 /* SR r1, r2 -- subtract register. */
1045 /* SGR r1, r2 -- subtract register (64-bit version). */
1046 else if (is_rr (insn32
, op_sr
, &r1
, &r2
)
1047 || is_rre (insn64
, op_sgr
, &r1
, &r2
))
1048 data
->gpr
[r1
] = pv_subtract (data
->gpr
[r1
], data
->gpr
[r2
]);
1050 /* S r1, d2(x2, b2) -- subtract. */
1051 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
1052 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
1053 else if (is_rx (insn32
, op_s
, &r1
, &d2
, &x2
, &b2
)
1054 || is_rxy (insn32
, op1_sy
, op2_sy
, &r1
, &d2
, &x2
, &b2
)
1055 || is_rxy (insn64
, op1_sg
, op2_sg
, &r1
, &d2
, &x2
, &b2
))
1056 data
->gpr
[r1
] = pv_subtract (data
->gpr
[r1
],
1057 s390_load (data
, d2
, x2
, b2
, data
->gpr_size
));
1059 /* LA r1, d2(x2, b2) --- load address. */
1060 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
1061 else if (is_rx (insn
, op_la
, &r1
, &d2
, &x2
, &b2
)
1062 || is_rxy (insn
, op1_lay
, op2_lay
, &r1
, &d2
, &x2
, &b2
))
1063 data
->gpr
[r1
] = s390_addr (data
, d2
, x2
, b2
);
1065 /* LARL r1, i2 --- load address relative long. */
1066 else if (is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1067 data
->gpr
[r1
] = pv_constant (pc
+ i2
* 2);
1069 /* BASR r1, 0 --- branch and save.
1070 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1071 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1073 data
->gpr
[r1
] = pv_constant (next_pc
);
1075 /* BRAS r1, i2 --- branch relative and save. */
1076 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
))
1078 data
->gpr
[r1
] = pv_constant (next_pc
);
1079 next_pc
= pc
+ i2
* 2;
1081 /* We'd better not interpret any backward branches. We'll
1087 /* Terminate search when hitting any other branch instruction. */
1088 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1089 || is_rx (insn
, op_bas
, &r1
, &d2
, &x2
, &b2
)
1090 || is_rr (insn
, op_bcr
, &r1
, &r2
)
1091 || is_rx (insn
, op_bc
, &r1
, &d2
, &x2
, &b2
)
1092 || is_ri (insn
, op1_brc
, op2_brc
, &r1
, &i2
)
1093 || is_ril (insn
, op1_brcl
, op2_brcl
, &r1
, &i2
)
1094 || is_ril (insn
, op1_brasl
, op2_brasl
, &r2
, &i2
))
1098 /* An instruction we don't know how to simulate. The only
1099 safe thing to do would be to set every value we're tracking
1100 to 'unknown'. Instead, we'll be optimistic: we assume that
1101 we *can* interpret every instruction that the compiler uses
1102 to manipulate any of the data we're interested in here --
1103 then we can just ignore anything else. */
1106 /* Record the address after the last instruction that changed
1107 the FP, SP, or backlink. Ignore instructions that changed
1108 them back to their original values --- those are probably
1109 restore instructions. (The back chain is never restored,
1112 pv_t sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1113 pv_t fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1115 if ((! pv_is_identical (pre_insn_sp
, sp
)
1116 && ! pv_is_register_k (sp
, S390_SP_REGNUM
, 0)
1117 && sp
.kind
!= pvk_unknown
)
1118 || (! pv_is_identical (pre_insn_fp
, fp
)
1119 && ! pv_is_register_k (fp
, S390_FRAME_REGNUM
, 0)
1120 && fp
.kind
!= pvk_unknown
)
1121 || pre_insn_back_chain_saved_p
!= data
->back_chain_saved_p
)
1129 /* Advance PC across any function entry prologue instructions to reach
1130 some "real" code. */
1132 s390_skip_prologue (CORE_ADDR pc
)
1134 struct s390_prologue_data data
;
1136 skip_pc
= s390_analyze_prologue (current_gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
1137 return skip_pc
? skip_pc
: pc
;
1140 /* Return true if we are in the functin's epilogue, i.e. after the
1141 instruction that destroyed the function's stack frame. */
1143 s390_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1145 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1147 /* In frameless functions, there's not frame to destroy and thus
1148 we don't care about the epilogue.
1150 In functions with frame, the epilogue sequence is a pair of
1151 a LM-type instruction that restores (amongst others) the
1152 return register %r14 and the stack pointer %r15, followed
1153 by a branch 'br %r14' --or equivalent-- that effects the
1156 In that situation, this function needs to return 'true' in
1157 exactly one case: when pc points to that branch instruction.
1159 Thus we try to disassemble the one instructions immediately
1160 preceeding pc and check whether it is an LM-type instruction
1161 modifying the stack pointer.
1163 Note that disassembling backwards is not reliable, so there
1164 is a slight chance of false positives here ... */
1167 unsigned int r1
, r3
, b2
;
1171 && !deprecated_read_memory_nobpt (pc
- 4, insn
, 4)
1172 && is_rs (insn
, op_lm
, &r1
, &r3
, &d2
, &b2
)
1173 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1177 && !deprecated_read_memory_nobpt (pc
- 6, insn
, 6)
1178 && is_rsy (insn
, op1_lmy
, op2_lmy
, &r1
, &r3
, &d2
, &b2
)
1179 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1183 && !deprecated_read_memory_nobpt (pc
- 6, insn
, 6)
1184 && is_rsy (insn
, op1_lmg
, op2_lmg
, &r1
, &r3
, &d2
, &b2
)
1185 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1192 /* Normal stack frames. */
1194 struct s390_unwind_cache
{
1197 CORE_ADDR frame_base
;
1198 CORE_ADDR local_base
;
1200 struct trad_frame_saved_reg
*saved_regs
;
1204 s390_prologue_frame_unwind_cache (struct frame_info
*next_frame
,
1205 struct s390_unwind_cache
*info
)
1207 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1208 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1209 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1210 struct s390_prologue_data data
;
1211 pv_t
*fp
= &data
.gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1212 pv_t
*sp
= &data
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1222 /* Try to find the function start address. If we can't find it, we don't
1223 bother searching for it -- with modern compilers this would be mostly
1224 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1225 or else a valid backchain ... */
1226 func
= frame_func_unwind (next_frame
);
1230 /* Try to analyze the prologue. */
1231 result
= s390_analyze_prologue (gdbarch
, func
,
1232 frame_pc_unwind (next_frame
), &data
);
1236 /* If this was successful, we should have found the instruction that
1237 sets the stack pointer register to the previous value of the stack
1238 pointer minus the frame size. */
1239 if (!pv_is_register (*sp
, S390_SP_REGNUM
))
1242 /* A frame size of zero at this point can mean either a real
1243 frameless function, or else a failure to find the prologue.
1244 Perform some sanity checks to verify we really have a
1245 frameless function. */
1248 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1249 size zero. This is only possible if the next frame is a sentinel
1250 frame, a dummy frame, or a signal trampoline frame. */
1251 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1252 needed, instead the code should simpliy rely on its
1254 if (get_frame_type (next_frame
) == NORMAL_FRAME
)
1257 /* If we really have a frameless function, %r14 must be valid
1258 -- in particular, it must point to a different function. */
1259 reg
= frame_unwind_register_unsigned (next_frame
, S390_RETADDR_REGNUM
);
1260 reg
= gdbarch_addr_bits_remove (gdbarch
, reg
) - 1;
1261 if (get_pc_function_start (reg
) == func
)
1263 /* However, there is one case where it *is* valid for %r14
1264 to point to the same function -- if this is a recursive
1265 call, and we have stopped in the prologue *before* the
1266 stack frame was allocated.
1268 Recognize this case by looking ahead a bit ... */
1270 struct s390_prologue_data data2
;
1271 pv_t
*sp
= &data2
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1273 if (!(s390_analyze_prologue (gdbarch
, func
, (CORE_ADDR
)-1, &data2
)
1274 && pv_is_register (*sp
, S390_SP_REGNUM
)
1281 /* OK, we've found valid prologue data. */
1284 /* If the frame pointer originally also holds the same value
1285 as the stack pointer, we're probably using it. If it holds
1286 some other value -- even a constant offset -- it is most
1287 likely used as temp register. */
1288 if (pv_is_identical (*sp
, *fp
))
1289 frame_pointer
= S390_FRAME_REGNUM
;
1291 frame_pointer
= S390_SP_REGNUM
;
1293 /* If we've detected a function with stack frame, we'll still have to
1294 treat it as frameless if we're currently within the function epilog
1295 code at a point where the frame pointer has already been restored.
1296 This can only happen in an innermost frame. */
1297 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1298 instead the code should simpliy rely on its analysis. */
1299 if (size
> 0 && get_frame_type (next_frame
) != NORMAL_FRAME
)
1301 /* See the comment in s390_in_function_epilogue_p on why this is
1302 not completely reliable ... */
1303 if (s390_in_function_epilogue_p (gdbarch
, frame_pc_unwind (next_frame
)))
1305 memset (&data
, 0, sizeof (data
));
1307 frame_pointer
= S390_SP_REGNUM
;
1311 /* Once we know the frame register and the frame size, we can unwind
1312 the current value of the frame register from the next frame, and
1313 add back the frame size to arrive that the previous frame's
1314 stack pointer value. */
1315 prev_sp
= frame_unwind_register_unsigned (next_frame
, frame_pointer
) + size
;
1316 cfa
= prev_sp
+ 16*word_size
+ 32;
1318 /* Record the addresses of all register spill slots the prologue parser
1319 has recognized. Consider only registers defined as call-saved by the
1320 ABI; for call-clobbered registers the parser may have recognized
1323 for (i
= 6; i
<= 15; i
++)
1324 if (data
.gpr_slot
[i
] != 0)
1325 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= cfa
- data
.gpr_slot
[i
];
1329 case ABI_LINUX_S390
:
1330 if (data
.fpr_slot
[4] != 0)
1331 info
->saved_regs
[S390_F4_REGNUM
].addr
= cfa
- data
.fpr_slot
[4];
1332 if (data
.fpr_slot
[6] != 0)
1333 info
->saved_regs
[S390_F6_REGNUM
].addr
= cfa
- data
.fpr_slot
[6];
1336 case ABI_LINUX_ZSERIES
:
1337 for (i
= 8; i
<= 15; i
++)
1338 if (data
.fpr_slot
[i
] != 0)
1339 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= cfa
- data
.fpr_slot
[i
];
1343 /* Function return will set PC to %r14. */
1344 info
->saved_regs
[S390_PC_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1346 /* In frameless functions, we unwind simply by moving the return
1347 address to the PC. However, if we actually stored to the
1348 save area, use that -- we might only think the function frameless
1349 because we're in the middle of the prologue ... */
1351 && !trad_frame_addr_p (info
->saved_regs
, S390_PC_REGNUM
))
1353 info
->saved_regs
[S390_PC_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1356 /* Another sanity check: unless this is a frameless function,
1357 we should have found spill slots for SP and PC.
1358 If not, we cannot unwind further -- this happens e.g. in
1359 libc's thread_start routine. */
1362 if (!trad_frame_addr_p (info
->saved_regs
, S390_SP_REGNUM
)
1363 || !trad_frame_addr_p (info
->saved_regs
, S390_PC_REGNUM
))
1367 /* We use the current value of the frame register as local_base,
1368 and the top of the register save area as frame_base. */
1371 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1372 info
->local_base
= prev_sp
- size
;
1380 s390_backchain_frame_unwind_cache (struct frame_info
*next_frame
,
1381 struct s390_unwind_cache
*info
)
1383 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1384 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1385 CORE_ADDR backchain
;
1389 /* Get the backchain. */
1390 reg
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1391 backchain
= read_memory_unsigned_integer (reg
, word_size
);
1393 /* A zero backchain terminates the frame chain. As additional
1394 sanity check, let's verify that the spill slot for SP in the
1395 save area pointed to by the backchain in fact links back to
1398 && safe_read_memory_integer (backchain
+ 15*word_size
, word_size
, &sp
)
1399 && (CORE_ADDR
)sp
== backchain
)
1401 /* We don't know which registers were saved, but it will have
1402 to be at least %r14 and %r15. This will allow us to continue
1403 unwinding, but other prev-frame registers may be incorrect ... */
1404 info
->saved_regs
[S390_SP_REGNUM
].addr
= backchain
+ 15*word_size
;
1405 info
->saved_regs
[S390_RETADDR_REGNUM
].addr
= backchain
+ 14*word_size
;
1407 /* Function return will set PC to %r14. */
1408 info
->saved_regs
[S390_PC_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1410 /* We use the current value of the frame register as local_base,
1411 and the top of the register save area as frame_base. */
1412 info
->frame_base
= backchain
+ 16*word_size
+ 32;
1413 info
->local_base
= reg
;
1416 info
->func
= frame_pc_unwind (next_frame
);
1419 static struct s390_unwind_cache
*
1420 s390_frame_unwind_cache (struct frame_info
*next_frame
,
1421 void **this_prologue_cache
)
1423 struct s390_unwind_cache
*info
;
1424 if (*this_prologue_cache
)
1425 return *this_prologue_cache
;
1427 info
= FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache
);
1428 *this_prologue_cache
= info
;
1429 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1431 info
->frame_base
= -1;
1432 info
->local_base
= -1;
1434 /* Try to use prologue analysis to fill the unwind cache.
1435 If this fails, fall back to reading the stack backchain. */
1436 if (!s390_prologue_frame_unwind_cache (next_frame
, info
))
1437 s390_backchain_frame_unwind_cache (next_frame
, info
);
1443 s390_frame_this_id (struct frame_info
*next_frame
,
1444 void **this_prologue_cache
,
1445 struct frame_id
*this_id
)
1447 struct s390_unwind_cache
*info
1448 = s390_frame_unwind_cache (next_frame
, this_prologue_cache
);
1450 if (info
->frame_base
== -1)
1453 *this_id
= frame_id_build (info
->frame_base
, info
->func
);
1457 s390_frame_prev_register (struct frame_info
*next_frame
,
1458 void **this_prologue_cache
,
1459 int regnum
, int *optimizedp
,
1460 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1461 int *realnump
, gdb_byte
*bufferp
)
1463 struct s390_unwind_cache
*info
1464 = s390_frame_unwind_cache (next_frame
, this_prologue_cache
);
1465 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1466 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1469 static const struct frame_unwind s390_frame_unwind
= {
1472 s390_frame_prev_register
1475 static const struct frame_unwind
*
1476 s390_frame_sniffer (struct frame_info
*next_frame
)
1478 return &s390_frame_unwind
;
1482 /* Code stubs and their stack frames. For things like PLTs and NULL
1483 function calls (where there is no true frame and the return address
1484 is in the RETADDR register). */
1486 struct s390_stub_unwind_cache
1488 CORE_ADDR frame_base
;
1489 struct trad_frame_saved_reg
*saved_regs
;
1492 static struct s390_stub_unwind_cache
*
1493 s390_stub_frame_unwind_cache (struct frame_info
*next_frame
,
1494 void **this_prologue_cache
)
1496 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1497 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1498 struct s390_stub_unwind_cache
*info
;
1501 if (*this_prologue_cache
)
1502 return *this_prologue_cache
;
1504 info
= FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache
);
1505 *this_prologue_cache
= info
;
1506 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1508 /* The return address is in register %r14. */
1509 info
->saved_regs
[S390_PC_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1511 /* Retrieve stack pointer and determine our frame base. */
1512 reg
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1513 info
->frame_base
= reg
+ 16*word_size
+ 32;
1519 s390_stub_frame_this_id (struct frame_info
*next_frame
,
1520 void **this_prologue_cache
,
1521 struct frame_id
*this_id
)
1523 struct s390_stub_unwind_cache
*info
1524 = s390_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
1525 *this_id
= frame_id_build (info
->frame_base
, frame_pc_unwind (next_frame
));
1529 s390_stub_frame_prev_register (struct frame_info
*next_frame
,
1530 void **this_prologue_cache
,
1531 int regnum
, int *optimizedp
,
1532 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1533 int *realnump
, gdb_byte
*bufferp
)
1535 struct s390_stub_unwind_cache
*info
1536 = s390_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
1537 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1538 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1541 static const struct frame_unwind s390_stub_frame_unwind
= {
1543 s390_stub_frame_this_id
,
1544 s390_stub_frame_prev_register
1547 static const struct frame_unwind
*
1548 s390_stub_frame_sniffer (struct frame_info
*next_frame
)
1550 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1551 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
1553 /* If the current PC points to non-readable memory, we assume we
1554 have trapped due to an invalid function pointer call. We handle
1555 the non-existing current function like a PLT stub. */
1556 if (in_plt_section (pc
, NULL
)
1557 || s390_readinstruction (insn
, pc
) < 0)
1558 return &s390_stub_frame_unwind
;
1563 /* Signal trampoline stack frames. */
1565 struct s390_sigtramp_unwind_cache
{
1566 CORE_ADDR frame_base
;
1567 struct trad_frame_saved_reg
*saved_regs
;
1570 static struct s390_sigtramp_unwind_cache
*
1571 s390_sigtramp_frame_unwind_cache (struct frame_info
*next_frame
,
1572 void **this_prologue_cache
)
1574 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1575 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1576 struct s390_sigtramp_unwind_cache
*info
;
1577 ULONGEST this_sp
, prev_sp
;
1578 CORE_ADDR next_ra
, next_cfa
, sigreg_ptr
;
1581 if (*this_prologue_cache
)
1582 return *this_prologue_cache
;
1584 info
= FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache
);
1585 *this_prologue_cache
= info
;
1586 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1588 this_sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1589 next_ra
= frame_pc_unwind (next_frame
);
1590 next_cfa
= this_sp
+ 16*word_size
+ 32;
1592 /* New-style RT frame:
1593 retcode + alignment (8 bytes)
1595 ucontext (contains sigregs at offset 5 words) */
1596 if (next_ra
== next_cfa
)
1598 sigreg_ptr
= next_cfa
+ 8 + 128 + align_up (5*word_size
, 8);
1601 /* Old-style RT frame and all non-RT frames:
1602 old signal mask (8 bytes)
1603 pointer to sigregs */
1606 sigreg_ptr
= read_memory_unsigned_integer (next_cfa
+ 8, word_size
);
1609 /* The sigregs structure looks like this:
1618 /* Let's ignore the PSW mask, it will not be restored anyway. */
1619 sigreg_ptr
+= word_size
;
1621 /* Next comes the PSW address. */
1622 info
->saved_regs
[S390_PC_REGNUM
].addr
= sigreg_ptr
;
1623 sigreg_ptr
+= word_size
;
1625 /* Then the GPRs. */
1626 for (i
= 0; i
< 16; i
++)
1628 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= sigreg_ptr
;
1629 sigreg_ptr
+= word_size
;
1632 /* Then the ACRs. */
1633 for (i
= 0; i
< 16; i
++)
1635 info
->saved_regs
[S390_A0_REGNUM
+ i
].addr
= sigreg_ptr
;
1639 /* The floating-point control word. */
1640 info
->saved_regs
[S390_FPC_REGNUM
].addr
= sigreg_ptr
;
1643 /* And finally the FPRs. */
1644 for (i
= 0; i
< 16; i
++)
1646 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= sigreg_ptr
;
1650 /* Restore the previous frame's SP. */
1651 prev_sp
= read_memory_unsigned_integer (
1652 info
->saved_regs
[S390_SP_REGNUM
].addr
,
1655 /* Determine our frame base. */
1656 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1662 s390_sigtramp_frame_this_id (struct frame_info
*next_frame
,
1663 void **this_prologue_cache
,
1664 struct frame_id
*this_id
)
1666 struct s390_sigtramp_unwind_cache
*info
1667 = s390_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
1668 *this_id
= frame_id_build (info
->frame_base
, frame_pc_unwind (next_frame
));
1672 s390_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
1673 void **this_prologue_cache
,
1674 int regnum
, int *optimizedp
,
1675 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1676 int *realnump
, gdb_byte
*bufferp
)
1678 struct s390_sigtramp_unwind_cache
*info
1679 = s390_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
1680 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1681 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1684 static const struct frame_unwind s390_sigtramp_frame_unwind
= {
1686 s390_sigtramp_frame_this_id
,
1687 s390_sigtramp_frame_prev_register
1690 static const struct frame_unwind
*
1691 s390_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
1693 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1694 bfd_byte sigreturn
[2];
1696 if (deprecated_read_memory_nobpt (pc
, sigreturn
, 2))
1699 if (sigreturn
[0] != 0x0a /* svc */)
1702 if (sigreturn
[1] != 119 /* sigreturn */
1703 && sigreturn
[1] != 173 /* rt_sigreturn */)
1706 return &s390_sigtramp_frame_unwind
;
1710 /* Frame base handling. */
1713 s390_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
1715 struct s390_unwind_cache
*info
1716 = s390_frame_unwind_cache (next_frame
, this_cache
);
1717 return info
->frame_base
;
1721 s390_local_base_address (struct frame_info
*next_frame
, void **this_cache
)
1723 struct s390_unwind_cache
*info
1724 = s390_frame_unwind_cache (next_frame
, this_cache
);
1725 return info
->local_base
;
1728 static const struct frame_base s390_frame_base
= {
1730 s390_frame_base_address
,
1731 s390_local_base_address
,
1732 s390_local_base_address
1736 s390_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1739 pc
= frame_unwind_register_unsigned (next_frame
, S390_PC_REGNUM
);
1740 return gdbarch_addr_bits_remove (gdbarch
, pc
);
1744 s390_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1747 sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1748 return gdbarch_addr_bits_remove (gdbarch
, sp
);
1752 /* DWARF-2 frame support. */
1755 s390_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1756 struct dwarf2_frame_state_reg
*reg
,
1757 struct frame_info
*next_frame
)
1759 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1763 case ABI_LINUX_S390
:
1764 /* Call-saved registers. */
1765 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
1766 || regnum
== S390_F4_REGNUM
1767 || regnum
== S390_F6_REGNUM
)
1768 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1770 /* Call-clobbered registers. */
1771 else if ((regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R5_REGNUM
)
1772 || (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
1773 && regnum
!= S390_F4_REGNUM
&& regnum
!= S390_F6_REGNUM
))
1774 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
1776 /* The return address column. */
1777 else if (regnum
== S390_PC_REGNUM
)
1778 reg
->how
= DWARF2_FRAME_REG_RA
;
1781 case ABI_LINUX_ZSERIES
:
1782 /* Call-saved registers. */
1783 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
1784 || (regnum
>= S390_F8_REGNUM
&& regnum
<= S390_F15_REGNUM
))
1785 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1787 /* Call-clobbered registers. */
1788 else if ((regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R5_REGNUM
)
1789 || (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F7_REGNUM
))
1790 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
1792 /* The return address column. */
1793 else if (regnum
== S390_PC_REGNUM
)
1794 reg
->how
= DWARF2_FRAME_REG_RA
;
1800 /* Dummy function calls. */
1802 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
1803 "Integer-like" types are those that should be passed the way
1804 integers are: integers, enums, ranges, characters, and booleans. */
1806 is_integer_like (struct type
*type
)
1808 enum type_code code
= TYPE_CODE (type
);
1810 return (code
== TYPE_CODE_INT
1811 || code
== TYPE_CODE_ENUM
1812 || code
== TYPE_CODE_RANGE
1813 || code
== TYPE_CODE_CHAR
1814 || code
== TYPE_CODE_BOOL
);
1817 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
1818 "Pointer-like" types are those that should be passed the way
1819 pointers are: pointers and references. */
1821 is_pointer_like (struct type
*type
)
1823 enum type_code code
= TYPE_CODE (type
);
1825 return (code
== TYPE_CODE_PTR
1826 || code
== TYPE_CODE_REF
);
1830 /* Return non-zero if TYPE is a `float singleton' or `double
1831 singleton', zero otherwise.
1833 A `T singleton' is a struct type with one member, whose type is
1834 either T or a `T singleton'. So, the following are all float
1838 struct { struct { float x; } x; };
1839 struct { struct { struct { float x; } x; } x; };
1843 All such structures are passed as if they were floats or doubles,
1844 as the (revised) ABI says. */
1846 is_float_singleton (struct type
*type
)
1848 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type
) == 1)
1850 struct type
*singleton_type
= TYPE_FIELD_TYPE (type
, 0);
1851 CHECK_TYPEDEF (singleton_type
);
1853 return (TYPE_CODE (singleton_type
) == TYPE_CODE_FLT
1854 || is_float_singleton (singleton_type
));
1861 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
1862 "Struct-like" types are those that should be passed as structs are:
1865 As an odd quirk, not mentioned in the ABI, GCC passes float and
1866 double singletons as if they were a plain float, double, etc. (The
1867 corresponding union types are handled normally.) So we exclude
1868 those types here. *shrug* */
1870 is_struct_like (struct type
*type
)
1872 enum type_code code
= TYPE_CODE (type
);
1874 return (code
== TYPE_CODE_UNION
1875 || (code
== TYPE_CODE_STRUCT
&& ! is_float_singleton (type
)));
1879 /* Return non-zero if TYPE is a float-like type, zero otherwise.
1880 "Float-like" types are those that should be passed as
1881 floating-point values are.
1883 You'd think this would just be floats, doubles, long doubles, etc.
1884 But as an odd quirk, not mentioned in the ABI, GCC passes float and
1885 double singletons as if they were a plain float, double, etc. (The
1886 corresponding union types are handled normally.) So we include
1887 those types here. *shrug* */
1889 is_float_like (struct type
*type
)
1891 return (TYPE_CODE (type
) == TYPE_CODE_FLT
1892 || is_float_singleton (type
));
1897 is_power_of_two (unsigned int n
)
1899 return ((n
& (n
- 1)) == 0);
1902 /* Return non-zero if TYPE should be passed as a pointer to a copy,
1905 s390_function_arg_pass_by_reference (struct type
*type
)
1907 unsigned length
= TYPE_LENGTH (type
);
1911 /* FIXME: All complex and vector types are also returned by reference. */
1912 return is_struct_like (type
) && !is_power_of_two (length
);
1915 /* Return non-zero if TYPE should be passed in a float register
1918 s390_function_arg_float (struct type
*type
)
1920 unsigned length
= TYPE_LENGTH (type
);
1924 return is_float_like (type
);
1927 /* Return non-zero if TYPE should be passed in an integer register
1928 (or a pair of integer registers) if possible. */
1930 s390_function_arg_integer (struct type
*type
)
1932 unsigned length
= TYPE_LENGTH (type
);
1936 return is_integer_like (type
)
1937 || is_pointer_like (type
)
1938 || (is_struct_like (type
) && is_power_of_two (length
));
1941 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
1942 word as required for the ABI. */
1944 extend_simple_arg (struct value
*arg
)
1946 struct type
*type
= value_type (arg
);
1948 /* Even structs get passed in the least significant bits of the
1949 register / memory word. It's not really right to extract them as
1950 an integer, but it does take care of the extension. */
1951 if (TYPE_UNSIGNED (type
))
1952 return extract_unsigned_integer (value_contents (arg
),
1953 TYPE_LENGTH (type
));
1955 return extract_signed_integer (value_contents (arg
),
1956 TYPE_LENGTH (type
));
1960 /* Return the alignment required by TYPE. */
1962 alignment_of (struct type
*type
)
1966 if (is_integer_like (type
)
1967 || is_pointer_like (type
)
1968 || TYPE_CODE (type
) == TYPE_CODE_FLT
)
1969 alignment
= TYPE_LENGTH (type
);
1970 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1971 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
1976 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
1978 int field_alignment
= alignment_of (TYPE_FIELD_TYPE (type
, i
));
1980 if (field_alignment
> alignment
)
1981 alignment
= field_alignment
;
1987 /* Check that everything we ever return is a power of two. Lots of
1988 code doesn't want to deal with aligning things to arbitrary
1990 gdb_assert ((alignment
& (alignment
- 1)) == 0);
1996 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
1997 place to be passed to a function, as specified by the "GNU/Linux
1998 for S/390 ELF Application Binary Interface Supplement".
2000 SP is the current stack pointer. We must put arguments, links,
2001 padding, etc. whereever they belong, and return the new stack
2004 If STRUCT_RETURN is non-zero, then the function we're calling is
2005 going to return a structure by value; STRUCT_ADDR is the address of
2006 a block we've allocated for it on the stack.
2008 Our caller has taken care of any type promotions needed to satisfy
2009 prototypes or the old K&R argument-passing rules. */
2011 s390_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2012 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2013 int nargs
, struct value
**args
, CORE_ADDR sp
,
2014 int struct_return
, CORE_ADDR struct_addr
)
2016 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2017 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2021 /* If the i'th argument is passed as a reference to a copy, then
2022 copy_addr[i] is the address of the copy we made. */
2023 CORE_ADDR
*copy_addr
= alloca (nargs
* sizeof (CORE_ADDR
));
2025 /* Build the reference-to-copy area. */
2026 for (i
= 0; i
< nargs
; i
++)
2028 struct value
*arg
= args
[i
];
2029 struct type
*type
= value_type (arg
);
2030 unsigned length
= TYPE_LENGTH (type
);
2032 if (s390_function_arg_pass_by_reference (type
))
2035 sp
= align_down (sp
, alignment_of (type
));
2036 write_memory (sp
, value_contents (arg
), length
);
2041 /* Reserve space for the parameter area. As a conservative
2042 simplification, we assume that everything will be passed on the
2043 stack. Since every argument larger than 8 bytes will be
2044 passed by reference, we use this simple upper bound. */
2047 /* After all that, make sure it's still aligned on an eight-byte
2049 sp
= align_down (sp
, 8);
2051 /* Finally, place the actual parameters, working from SP towards
2052 higher addresses. The code above is supposed to reserve enough
2057 CORE_ADDR starg
= sp
;
2059 /* A struct is returned using general register 2. */
2062 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2067 for (i
= 0; i
< nargs
; i
++)
2069 struct value
*arg
= args
[i
];
2070 struct type
*type
= value_type (arg
);
2071 unsigned length
= TYPE_LENGTH (type
);
2073 if (s390_function_arg_pass_by_reference (type
))
2077 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2083 write_memory_unsigned_integer (starg
, word_size
, copy_addr
[i
]);
2087 else if (s390_function_arg_float (type
))
2089 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2090 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2091 if (fr
<= (tdep
->abi
== ABI_LINUX_S390
? 2 : 6))
2093 /* When we store a single-precision value in an FP register,
2094 it occupies the leftmost bits. */
2095 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
+ fr
,
2096 0, length
, value_contents (arg
));
2101 /* When we store a single-precision value in a stack slot,
2102 it occupies the rightmost bits. */
2103 starg
= align_up (starg
+ length
, word_size
);
2104 write_memory (starg
- length
, value_contents (arg
), length
);
2107 else if (s390_function_arg_integer (type
) && length
<= word_size
)
2111 /* Integer arguments are always extended to word size. */
2112 regcache_cooked_write_signed (regcache
, S390_R0_REGNUM
+ gr
,
2113 extend_simple_arg (arg
));
2118 /* Integer arguments are always extended to word size. */
2119 write_memory_signed_integer (starg
, word_size
,
2120 extend_simple_arg (arg
));
2124 else if (s390_function_arg_integer (type
) && length
== 2*word_size
)
2128 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
,
2129 value_contents (arg
));
2130 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
+ 1,
2131 value_contents (arg
) + word_size
);
2136 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2137 in it, then don't go back and use it again later. */
2140 write_memory (starg
, value_contents (arg
), length
);
2145 internal_error (__FILE__
, __LINE__
, _("unknown argument type"));
2149 /* Allocate the standard frame areas: the register save area, the
2150 word reserved for the compiler (which seems kind of meaningless),
2151 and the back chain pointer. */
2152 sp
-= 16*word_size
+ 32;
2154 /* Store return address. */
2155 regcache_cooked_write_unsigned (regcache
, S390_RETADDR_REGNUM
, bp_addr
);
2157 /* Store updated stack pointer. */
2158 regcache_cooked_write_unsigned (regcache
, S390_SP_REGNUM
, sp
);
2160 /* We need to return the 'stack part' of the frame ID,
2161 which is actually the top of the register save area. */
2162 return sp
+ 16*word_size
+ 32;
2165 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
2166 dummy frame. The frame ID's base needs to match the TOS value
2167 returned by push_dummy_call, and the PC match the dummy frame's
2169 static struct frame_id
2170 s390_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2172 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2173 CORE_ADDR sp
= s390_unwind_sp (gdbarch
, next_frame
);
2175 return frame_id_build (sp
+ 16*word_size
+ 32,
2176 frame_pc_unwind (next_frame
));
2180 s390_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2182 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2183 always be aligned on an eight-byte boundary. */
2188 /* Function return value access. */
2190 static enum return_value_convention
2191 s390_return_value_convention (struct gdbarch
*gdbarch
, struct type
*type
)
2193 int length
= TYPE_LENGTH (type
);
2195 return RETURN_VALUE_STRUCT_CONVENTION
;
2197 switch (TYPE_CODE (type
))
2199 case TYPE_CODE_STRUCT
:
2200 case TYPE_CODE_UNION
:
2201 case TYPE_CODE_ARRAY
:
2202 return RETURN_VALUE_STRUCT_CONVENTION
;
2205 return RETURN_VALUE_REGISTER_CONVENTION
;
2209 static enum return_value_convention
2210 s390_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
2211 struct regcache
*regcache
, gdb_byte
*out
,
2214 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2215 int length
= TYPE_LENGTH (type
);
2216 enum return_value_convention rvc
=
2217 s390_return_value_convention (gdbarch
, type
);
2222 case RETURN_VALUE_REGISTER_CONVENTION
:
2223 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2225 /* When we store a single-precision value in an FP register,
2226 it occupies the leftmost bits. */
2227 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
,
2230 else if (length
<= word_size
)
2232 /* Integer arguments are always extended to word size. */
2233 if (TYPE_UNSIGNED (type
))
2234 regcache_cooked_write_unsigned (regcache
, S390_R2_REGNUM
,
2235 extract_unsigned_integer (in
, length
));
2237 regcache_cooked_write_signed (regcache
, S390_R2_REGNUM
,
2238 extract_signed_integer (in
, length
));
2240 else if (length
== 2*word_size
)
2242 regcache_cooked_write (regcache
, S390_R2_REGNUM
, in
);
2243 regcache_cooked_write (regcache
, S390_R3_REGNUM
, in
+ word_size
);
2246 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2249 case RETURN_VALUE_STRUCT_CONVENTION
:
2250 error (_("Cannot set function return value."));
2258 case RETURN_VALUE_REGISTER_CONVENTION
:
2259 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2261 /* When we store a single-precision value in an FP register,
2262 it occupies the leftmost bits. */
2263 regcache_cooked_read_part (regcache
, S390_F0_REGNUM
,
2266 else if (length
<= word_size
)
2268 /* Integer arguments occupy the rightmost bits. */
2269 regcache_cooked_read_part (regcache
, S390_R2_REGNUM
,
2270 word_size
- length
, length
, out
);
2272 else if (length
== 2*word_size
)
2274 regcache_cooked_read (regcache
, S390_R2_REGNUM
, out
);
2275 regcache_cooked_read (regcache
, S390_R3_REGNUM
, out
+ word_size
);
2278 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2281 case RETURN_VALUE_STRUCT_CONVENTION
:
2282 error (_("Function return value unknown."));
2293 static const gdb_byte
*
2294 s390_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
2296 static const gdb_byte breakpoint
[] = { 0x0, 0x1 };
2298 *lenptr
= sizeof (breakpoint
);
2303 /* Address handling. */
2306 s390_addr_bits_remove (CORE_ADDR addr
)
2308 return addr
& 0x7fffffff;
2312 s390_address_class_type_flags (int byte_size
, int dwarf2_addr_class
)
2315 return TYPE_FLAG_ADDRESS_CLASS_1
;
2321 s390_address_class_type_flags_to_name (struct gdbarch
*gdbarch
, int type_flags
)
2323 if (type_flags
& TYPE_FLAG_ADDRESS_CLASS_1
)
2330 s390_address_class_name_to_type_flags (struct gdbarch
*gdbarch
, const char *name
,
2331 int *type_flags_ptr
)
2333 if (strcmp (name
, "mode32") == 0)
2335 *type_flags_ptr
= TYPE_FLAG_ADDRESS_CLASS_1
;
2342 /* Set up gdbarch struct. */
2344 static struct gdbarch
*
2345 s390_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2347 struct gdbarch
*gdbarch
;
2348 struct gdbarch_tdep
*tdep
;
2350 /* First see if there is already a gdbarch that can satisfy the request. */
2351 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2353 return arches
->gdbarch
;
2355 /* None found: is the request for a s390 architecture? */
2356 if (info
.bfd_arch_info
->arch
!= bfd_arch_s390
)
2357 return NULL
; /* No; then it's not for us. */
2359 /* Yes: create a new gdbarch for the specified machine type. */
2360 tdep
= XCALLOC (1, struct gdbarch_tdep
);
2361 gdbarch
= gdbarch_alloc (&info
, tdep
);
2363 set_gdbarch_believe_pcc_promotion (gdbarch
, 0);
2364 set_gdbarch_char_signed (gdbarch
, 0);
2366 /* Amount PC must be decremented by after a breakpoint. This is
2367 often the number of bytes returned by BREAKPOINT_FROM_PC but not
2369 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
2370 /* Stack grows downward. */
2371 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2372 set_gdbarch_breakpoint_from_pc (gdbarch
, s390_breakpoint_from_pc
);
2373 set_gdbarch_skip_prologue (gdbarch
, s390_skip_prologue
);
2374 set_gdbarch_in_function_epilogue_p (gdbarch
, s390_in_function_epilogue_p
);
2376 set_gdbarch_pc_regnum (gdbarch
, S390_PC_REGNUM
);
2377 set_gdbarch_sp_regnum (gdbarch
, S390_SP_REGNUM
);
2378 set_gdbarch_fp0_regnum (gdbarch
, S390_F0_REGNUM
);
2379 set_gdbarch_num_regs (gdbarch
, S390_NUM_REGS
);
2380 set_gdbarch_num_pseudo_regs (gdbarch
, S390_NUM_PSEUDO_REGS
);
2381 set_gdbarch_register_name (gdbarch
, s390_register_name
);
2382 set_gdbarch_register_type (gdbarch
, s390_register_type
);
2383 set_gdbarch_stab_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2384 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2385 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2386 set_gdbarch_convert_register_p (gdbarch
, s390_convert_register_p
);
2387 set_gdbarch_register_to_value (gdbarch
, s390_register_to_value
);
2388 set_gdbarch_value_to_register (gdbarch
, s390_value_to_register
);
2389 set_gdbarch_register_reggroup_p (gdbarch
, s390_register_reggroup_p
);
2390 set_gdbarch_regset_from_core_section (gdbarch
,
2391 s390_regset_from_core_section
);
2393 /* Inferior function calls. */
2394 set_gdbarch_push_dummy_call (gdbarch
, s390_push_dummy_call
);
2395 set_gdbarch_unwind_dummy_id (gdbarch
, s390_unwind_dummy_id
);
2396 set_gdbarch_frame_align (gdbarch
, s390_frame_align
);
2397 set_gdbarch_return_value (gdbarch
, s390_return_value
);
2399 /* Frame handling. */
2400 dwarf2_frame_set_init_reg (gdbarch
, s390_dwarf2_frame_init_reg
);
2401 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
2402 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
2403 frame_unwind_append_sniffer (gdbarch
, s390_stub_frame_sniffer
);
2404 frame_unwind_append_sniffer (gdbarch
, s390_sigtramp_frame_sniffer
);
2405 frame_unwind_append_sniffer (gdbarch
, s390_frame_sniffer
);
2406 frame_base_set_default (gdbarch
, &s390_frame_base
);
2407 set_gdbarch_unwind_pc (gdbarch
, s390_unwind_pc
);
2408 set_gdbarch_unwind_sp (gdbarch
, s390_unwind_sp
);
2410 switch (info
.bfd_arch_info
->mach
)
2412 case bfd_mach_s390_31
:
2413 tdep
->abi
= ABI_LINUX_S390
;
2415 tdep
->gregset
= &s390_gregset
;
2416 tdep
->sizeof_gregset
= s390_sizeof_gregset
;
2417 tdep
->fpregset
= &s390_fpregset
;
2418 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
2420 set_gdbarch_addr_bits_remove (gdbarch
, s390_addr_bits_remove
);
2421 set_gdbarch_pseudo_register_read (gdbarch
, s390_pseudo_register_read
);
2422 set_gdbarch_pseudo_register_write (gdbarch
, s390_pseudo_register_write
);
2423 set_solib_svr4_fetch_link_map_offsets
2424 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
2427 case bfd_mach_s390_64
:
2428 tdep
->abi
= ABI_LINUX_ZSERIES
;
2430 tdep
->gregset
= &s390x_gregset
;
2431 tdep
->sizeof_gregset
= s390x_sizeof_gregset
;
2432 tdep
->fpregset
= &s390_fpregset
;
2433 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
2435 set_gdbarch_long_bit (gdbarch
, 64);
2436 set_gdbarch_long_long_bit (gdbarch
, 64);
2437 set_gdbarch_ptr_bit (gdbarch
, 64);
2438 set_gdbarch_pseudo_register_read (gdbarch
, s390x_pseudo_register_read
);
2439 set_gdbarch_pseudo_register_write (gdbarch
, s390x_pseudo_register_write
);
2440 set_solib_svr4_fetch_link_map_offsets
2441 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
2442 set_gdbarch_address_class_type_flags (gdbarch
,
2443 s390_address_class_type_flags
);
2444 set_gdbarch_address_class_type_flags_to_name (gdbarch
,
2445 s390_address_class_type_flags_to_name
);
2446 set_gdbarch_address_class_name_to_type_flags (gdbarch
,
2447 s390_address_class_name_to_type_flags
);
2451 set_gdbarch_print_insn (gdbarch
, print_insn_s390
);
2453 /* Enable TLS support. */
2454 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
2455 svr4_fetch_objfile_link_map
);
2462 extern initialize_file_ftype _initialize_s390_tdep
; /* -Wmissing-prototypes */
2465 _initialize_s390_tdep (void)
2468 /* Hook us into the gdbarch mechanism. */
2469 register_gdbarch_init (bfd_arch_s390
, s390_gdbarch_init
);