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
{
720 struct pv_area
*stack
;
722 /* The size of a GPR or FPR. */
726 /* The general-purpose registers. */
727 pv_t gpr
[S390_NUM_GPRS
];
729 /* The floating-point registers. */
730 pv_t fpr
[S390_NUM_FPRS
];
732 /* The offset relative to the CFA where the incoming GPR N was saved
733 by the function prologue. 0 if not saved or unknown. */
734 int gpr_slot
[S390_NUM_GPRS
];
736 /* Likewise for FPRs. */
737 int fpr_slot
[S390_NUM_FPRS
];
739 /* Nonzero if the backchain was saved. This is assumed to be the
740 case when the incoming SP is saved at the current SP location. */
741 int back_chain_saved_p
;
744 /* Return the effective address for an X-style instruction, like:
748 Here, X2 and B2 are registers, and D2 is a signed 20-bit
749 constant; the effective address is the sum of all three. If either
750 X2 or B2 are zero, then it doesn't contribute to the sum --- this
751 means that r0 can't be used as either X2 or B2. */
753 s390_addr (struct s390_prologue_data
*data
,
754 int d2
, unsigned int x2
, unsigned int b2
)
758 result
= pv_constant (d2
);
760 result
= pv_add (result
, data
->gpr
[x2
]);
762 result
= pv_add (result
, data
->gpr
[b2
]);
767 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
769 s390_store (struct s390_prologue_data
*data
,
770 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
,
773 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
776 /* Check whether we are storing the backchain. */
777 offset
= pv_subtract (data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
], addr
);
779 if (pv_is_constant (offset
) && offset
.k
== 0)
780 if (size
== data
->gpr_size
781 && pv_is_register_k (value
, S390_SP_REGNUM
, 0))
783 data
->back_chain_saved_p
= 1;
788 /* Check whether we are storing a register into the stack. */
789 if (!pv_area_store_would_trash (data
->stack
, addr
))
790 pv_area_store (data
->stack
, addr
, size
, value
);
793 /* Note: If this is some store we cannot identify, you might think we
794 should forget our cached values, as any of those might have been hit.
796 However, we make the assumption that the register save areas are only
797 ever stored to once in any given function, and we do recognize these
798 stores. Thus every store we cannot recognize does not hit our data. */
801 /* Do a SIZE-byte load from D2(X2,B2). */
803 s390_load (struct s390_prologue_data
*data
,
804 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
)
807 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
810 /* If it's a load from an in-line constant pool, then we can
811 simulate that, under the assumption that the code isn't
812 going to change between the time the processor actually
813 executed it creating the current frame, and the time when
814 we're analyzing the code to unwind past that frame. */
815 if (pv_is_constant (addr
))
817 struct section_table
*secp
;
818 secp
= target_section_by_addr (¤t_target
, addr
.k
);
820 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
822 return pv_constant (read_memory_integer (addr
.k
, size
));
825 /* Check whether we are accessing one of our save slots. */
826 return pv_area_fetch (data
->stack
, addr
, size
);
829 /* Function for finding saved registers in a 'struct pv_area'; we pass
830 this to pv_area_scan.
832 If VALUE is a saved register, ADDR says it was saved at a constant
833 offset from the frame base, and SIZE indicates that the whole
834 register was saved, record its offset in the reg_offset table in
837 s390_check_for_saved (void *data_untyped
, pv_t addr
, CORE_ADDR size
, pv_t value
)
839 struct s390_prologue_data
*data
= data_untyped
;
842 if (!pv_is_register (addr
, S390_SP_REGNUM
))
845 offset
= 16 * data
->gpr_size
+ 32 - addr
.k
;
847 /* If we are storing the original value of a register, we want to
848 record the CFA offset. If the same register is stored multiple
849 times, the stack slot with the highest address counts. */
851 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
852 if (size
== data
->gpr_size
853 && pv_is_register_k (value
, S390_R0_REGNUM
+ i
, 0))
854 if (data
->gpr_slot
[i
] == 0
855 || data
->gpr_slot
[i
] > offset
)
857 data
->gpr_slot
[i
] = offset
;
861 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
862 if (size
== data
->fpr_size
863 && pv_is_register_k (value
, S390_F0_REGNUM
+ i
, 0))
864 if (data
->fpr_slot
[i
] == 0
865 || data
->fpr_slot
[i
] > offset
)
867 data
->fpr_slot
[i
] = offset
;
872 /* Analyze the prologue of the function starting at START_PC,
873 continuing at most until CURRENT_PC. Initialize DATA to
874 hold all information we find out about the state of the registers
875 and stack slots. Return the address of the instruction after
876 the last one that changed the SP, FP, or back chain; or zero
879 s390_analyze_prologue (struct gdbarch
*gdbarch
,
881 CORE_ADDR current_pc
,
882 struct s390_prologue_data
*data
)
884 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
887 The address of the instruction after the last one that changed
888 the SP, FP, or back chain; zero if we got an error trying to
890 CORE_ADDR result
= start_pc
;
892 /* The current PC for our abstract interpretation. */
895 /* The address of the next instruction after that. */
898 /* Set up everything's initial value. */
902 data
->stack
= make_pv_area (S390_SP_REGNUM
);
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
)
1126 /* Record where all the registers were saved. */
1127 pv_area_scan (data
->stack
, s390_check_for_saved
, data
);
1129 free_pv_area (data
->stack
);
1135 /* Advance PC across any function entry prologue instructions to reach
1136 some "real" code. */
1138 s390_skip_prologue (CORE_ADDR pc
)
1140 struct s390_prologue_data data
;
1142 skip_pc
= s390_analyze_prologue (current_gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
1143 return skip_pc
? skip_pc
: pc
;
1146 /* Return true if we are in the functin's epilogue, i.e. after the
1147 instruction that destroyed the function's stack frame. */
1149 s390_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1151 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1153 /* In frameless functions, there's not frame to destroy and thus
1154 we don't care about the epilogue.
1156 In functions with frame, the epilogue sequence is a pair of
1157 a LM-type instruction that restores (amongst others) the
1158 return register %r14 and the stack pointer %r15, followed
1159 by a branch 'br %r14' --or equivalent-- that effects the
1162 In that situation, this function needs to return 'true' in
1163 exactly one case: when pc points to that branch instruction.
1165 Thus we try to disassemble the one instructions immediately
1166 preceeding pc and check whether it is an LM-type instruction
1167 modifying the stack pointer.
1169 Note that disassembling backwards is not reliable, so there
1170 is a slight chance of false positives here ... */
1173 unsigned int r1
, r3
, b2
;
1177 && !deprecated_read_memory_nobpt (pc
- 4, insn
, 4)
1178 && is_rs (insn
, op_lm
, &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_lmy
, op2_lmy
, &r1
, &r3
, &d2
, &b2
)
1185 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1189 && !deprecated_read_memory_nobpt (pc
- 6, insn
, 6)
1190 && is_rsy (insn
, op1_lmg
, op2_lmg
, &r1
, &r3
, &d2
, &b2
)
1191 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1198 /* Normal stack frames. */
1200 struct s390_unwind_cache
{
1203 CORE_ADDR frame_base
;
1204 CORE_ADDR local_base
;
1206 struct trad_frame_saved_reg
*saved_regs
;
1210 s390_prologue_frame_unwind_cache (struct frame_info
*next_frame
,
1211 struct s390_unwind_cache
*info
)
1213 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1214 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1215 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1216 struct s390_prologue_data data
;
1217 pv_t
*fp
= &data
.gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1218 pv_t
*sp
= &data
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1228 /* Try to find the function start address. If we can't find it, we don't
1229 bother searching for it -- with modern compilers this would be mostly
1230 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1231 or else a valid backchain ... */
1232 func
= frame_func_unwind (next_frame
);
1236 /* Try to analyze the prologue. */
1237 result
= s390_analyze_prologue (gdbarch
, func
,
1238 frame_pc_unwind (next_frame
), &data
);
1242 /* If this was successful, we should have found the instruction that
1243 sets the stack pointer register to the previous value of the stack
1244 pointer minus the frame size. */
1245 if (!pv_is_register (*sp
, S390_SP_REGNUM
))
1248 /* A frame size of zero at this point can mean either a real
1249 frameless function, or else a failure to find the prologue.
1250 Perform some sanity checks to verify we really have a
1251 frameless function. */
1254 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1255 size zero. This is only possible if the next frame is a sentinel
1256 frame, a dummy frame, or a signal trampoline frame. */
1257 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1258 needed, instead the code should simpliy rely on its
1260 if (get_frame_type (next_frame
) == NORMAL_FRAME
)
1263 /* If we really have a frameless function, %r14 must be valid
1264 -- in particular, it must point to a different function. */
1265 reg
= frame_unwind_register_unsigned (next_frame
, S390_RETADDR_REGNUM
);
1266 reg
= gdbarch_addr_bits_remove (gdbarch
, reg
) - 1;
1267 if (get_pc_function_start (reg
) == func
)
1269 /* However, there is one case where it *is* valid for %r14
1270 to point to the same function -- if this is a recursive
1271 call, and we have stopped in the prologue *before* the
1272 stack frame was allocated.
1274 Recognize this case by looking ahead a bit ... */
1276 struct s390_prologue_data data2
;
1277 pv_t
*sp
= &data2
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1279 if (!(s390_analyze_prologue (gdbarch
, func
, (CORE_ADDR
)-1, &data2
)
1280 && pv_is_register (*sp
, S390_SP_REGNUM
)
1287 /* OK, we've found valid prologue data. */
1290 /* If the frame pointer originally also holds the same value
1291 as the stack pointer, we're probably using it. If it holds
1292 some other value -- even a constant offset -- it is most
1293 likely used as temp register. */
1294 if (pv_is_identical (*sp
, *fp
))
1295 frame_pointer
= S390_FRAME_REGNUM
;
1297 frame_pointer
= S390_SP_REGNUM
;
1299 /* If we've detected a function with stack frame, we'll still have to
1300 treat it as frameless if we're currently within the function epilog
1301 code at a point where the frame pointer has already been restored.
1302 This can only happen in an innermost frame. */
1303 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1304 instead the code should simpliy rely on its analysis. */
1305 if (size
> 0 && get_frame_type (next_frame
) != NORMAL_FRAME
)
1307 /* See the comment in s390_in_function_epilogue_p on why this is
1308 not completely reliable ... */
1309 if (s390_in_function_epilogue_p (gdbarch
, frame_pc_unwind (next_frame
)))
1311 memset (&data
, 0, sizeof (data
));
1313 frame_pointer
= S390_SP_REGNUM
;
1317 /* Once we know the frame register and the frame size, we can unwind
1318 the current value of the frame register from the next frame, and
1319 add back the frame size to arrive that the previous frame's
1320 stack pointer value. */
1321 prev_sp
= frame_unwind_register_unsigned (next_frame
, frame_pointer
) + size
;
1322 cfa
= prev_sp
+ 16*word_size
+ 32;
1324 /* Record the addresses of all register spill slots the prologue parser
1325 has recognized. Consider only registers defined as call-saved by the
1326 ABI; for call-clobbered registers the parser may have recognized
1329 for (i
= 6; i
<= 15; i
++)
1330 if (data
.gpr_slot
[i
] != 0)
1331 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= cfa
- data
.gpr_slot
[i
];
1335 case ABI_LINUX_S390
:
1336 if (data
.fpr_slot
[4] != 0)
1337 info
->saved_regs
[S390_F4_REGNUM
].addr
= cfa
- data
.fpr_slot
[4];
1338 if (data
.fpr_slot
[6] != 0)
1339 info
->saved_regs
[S390_F6_REGNUM
].addr
= cfa
- data
.fpr_slot
[6];
1342 case ABI_LINUX_ZSERIES
:
1343 for (i
= 8; i
<= 15; i
++)
1344 if (data
.fpr_slot
[i
] != 0)
1345 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= cfa
- data
.fpr_slot
[i
];
1349 /* Function return will set PC to %r14. */
1350 info
->saved_regs
[S390_PC_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1352 /* In frameless functions, we unwind simply by moving the return
1353 address to the PC. However, if we actually stored to the
1354 save area, use that -- we might only think the function frameless
1355 because we're in the middle of the prologue ... */
1357 && !trad_frame_addr_p (info
->saved_regs
, S390_PC_REGNUM
))
1359 info
->saved_regs
[S390_PC_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1362 /* Another sanity check: unless this is a frameless function,
1363 we should have found spill slots for SP and PC.
1364 If not, we cannot unwind further -- this happens e.g. in
1365 libc's thread_start routine. */
1368 if (!trad_frame_addr_p (info
->saved_regs
, S390_SP_REGNUM
)
1369 || !trad_frame_addr_p (info
->saved_regs
, S390_PC_REGNUM
))
1373 /* We use the current value of the frame register as local_base,
1374 and the top of the register save area as frame_base. */
1377 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1378 info
->local_base
= prev_sp
- size
;
1386 s390_backchain_frame_unwind_cache (struct frame_info
*next_frame
,
1387 struct s390_unwind_cache
*info
)
1389 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1390 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1391 CORE_ADDR backchain
;
1395 /* Get the backchain. */
1396 reg
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1397 backchain
= read_memory_unsigned_integer (reg
, word_size
);
1399 /* A zero backchain terminates the frame chain. As additional
1400 sanity check, let's verify that the spill slot for SP in the
1401 save area pointed to by the backchain in fact links back to
1404 && safe_read_memory_integer (backchain
+ 15*word_size
, word_size
, &sp
)
1405 && (CORE_ADDR
)sp
== backchain
)
1407 /* We don't know which registers were saved, but it will have
1408 to be at least %r14 and %r15. This will allow us to continue
1409 unwinding, but other prev-frame registers may be incorrect ... */
1410 info
->saved_regs
[S390_SP_REGNUM
].addr
= backchain
+ 15*word_size
;
1411 info
->saved_regs
[S390_RETADDR_REGNUM
].addr
= backchain
+ 14*word_size
;
1413 /* Function return will set PC to %r14. */
1414 info
->saved_regs
[S390_PC_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1416 /* We use the current value of the frame register as local_base,
1417 and the top of the register save area as frame_base. */
1418 info
->frame_base
= backchain
+ 16*word_size
+ 32;
1419 info
->local_base
= reg
;
1422 info
->func
= frame_pc_unwind (next_frame
);
1425 static struct s390_unwind_cache
*
1426 s390_frame_unwind_cache (struct frame_info
*next_frame
,
1427 void **this_prologue_cache
)
1429 struct s390_unwind_cache
*info
;
1430 if (*this_prologue_cache
)
1431 return *this_prologue_cache
;
1433 info
= FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache
);
1434 *this_prologue_cache
= info
;
1435 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1437 info
->frame_base
= -1;
1438 info
->local_base
= -1;
1440 /* Try to use prologue analysis to fill the unwind cache.
1441 If this fails, fall back to reading the stack backchain. */
1442 if (!s390_prologue_frame_unwind_cache (next_frame
, info
))
1443 s390_backchain_frame_unwind_cache (next_frame
, info
);
1449 s390_frame_this_id (struct frame_info
*next_frame
,
1450 void **this_prologue_cache
,
1451 struct frame_id
*this_id
)
1453 struct s390_unwind_cache
*info
1454 = s390_frame_unwind_cache (next_frame
, this_prologue_cache
);
1456 if (info
->frame_base
== -1)
1459 *this_id
= frame_id_build (info
->frame_base
, info
->func
);
1463 s390_frame_prev_register (struct frame_info
*next_frame
,
1464 void **this_prologue_cache
,
1465 int regnum
, int *optimizedp
,
1466 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1467 int *realnump
, gdb_byte
*bufferp
)
1469 struct s390_unwind_cache
*info
1470 = s390_frame_unwind_cache (next_frame
, this_prologue_cache
);
1471 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1472 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1475 static const struct frame_unwind s390_frame_unwind
= {
1478 s390_frame_prev_register
1481 static const struct frame_unwind
*
1482 s390_frame_sniffer (struct frame_info
*next_frame
)
1484 return &s390_frame_unwind
;
1488 /* Code stubs and their stack frames. For things like PLTs and NULL
1489 function calls (where there is no true frame and the return address
1490 is in the RETADDR register). */
1492 struct s390_stub_unwind_cache
1494 CORE_ADDR frame_base
;
1495 struct trad_frame_saved_reg
*saved_regs
;
1498 static struct s390_stub_unwind_cache
*
1499 s390_stub_frame_unwind_cache (struct frame_info
*next_frame
,
1500 void **this_prologue_cache
)
1502 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1503 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1504 struct s390_stub_unwind_cache
*info
;
1507 if (*this_prologue_cache
)
1508 return *this_prologue_cache
;
1510 info
= FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache
);
1511 *this_prologue_cache
= info
;
1512 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1514 /* The return address is in register %r14. */
1515 info
->saved_regs
[S390_PC_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1517 /* Retrieve stack pointer and determine our frame base. */
1518 reg
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1519 info
->frame_base
= reg
+ 16*word_size
+ 32;
1525 s390_stub_frame_this_id (struct frame_info
*next_frame
,
1526 void **this_prologue_cache
,
1527 struct frame_id
*this_id
)
1529 struct s390_stub_unwind_cache
*info
1530 = s390_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
1531 *this_id
= frame_id_build (info
->frame_base
, frame_pc_unwind (next_frame
));
1535 s390_stub_frame_prev_register (struct frame_info
*next_frame
,
1536 void **this_prologue_cache
,
1537 int regnum
, int *optimizedp
,
1538 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1539 int *realnump
, gdb_byte
*bufferp
)
1541 struct s390_stub_unwind_cache
*info
1542 = s390_stub_frame_unwind_cache (next_frame
, this_prologue_cache
);
1543 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1544 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1547 static const struct frame_unwind s390_stub_frame_unwind
= {
1549 s390_stub_frame_this_id
,
1550 s390_stub_frame_prev_register
1553 static const struct frame_unwind
*
1554 s390_stub_frame_sniffer (struct frame_info
*next_frame
)
1556 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1557 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
1559 /* If the current PC points to non-readable memory, we assume we
1560 have trapped due to an invalid function pointer call. We handle
1561 the non-existing current function like a PLT stub. */
1562 if (in_plt_section (pc
, NULL
)
1563 || s390_readinstruction (insn
, pc
) < 0)
1564 return &s390_stub_frame_unwind
;
1569 /* Signal trampoline stack frames. */
1571 struct s390_sigtramp_unwind_cache
{
1572 CORE_ADDR frame_base
;
1573 struct trad_frame_saved_reg
*saved_regs
;
1576 static struct s390_sigtramp_unwind_cache
*
1577 s390_sigtramp_frame_unwind_cache (struct frame_info
*next_frame
,
1578 void **this_prologue_cache
)
1580 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
1581 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1582 struct s390_sigtramp_unwind_cache
*info
;
1583 ULONGEST this_sp
, prev_sp
;
1584 CORE_ADDR next_ra
, next_cfa
, sigreg_ptr
;
1587 if (*this_prologue_cache
)
1588 return *this_prologue_cache
;
1590 info
= FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache
);
1591 *this_prologue_cache
= info
;
1592 info
->saved_regs
= trad_frame_alloc_saved_regs (next_frame
);
1594 this_sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1595 next_ra
= frame_pc_unwind (next_frame
);
1596 next_cfa
= this_sp
+ 16*word_size
+ 32;
1598 /* New-style RT frame:
1599 retcode + alignment (8 bytes)
1601 ucontext (contains sigregs at offset 5 words) */
1602 if (next_ra
== next_cfa
)
1604 sigreg_ptr
= next_cfa
+ 8 + 128 + align_up (5*word_size
, 8);
1607 /* Old-style RT frame and all non-RT frames:
1608 old signal mask (8 bytes)
1609 pointer to sigregs */
1612 sigreg_ptr
= read_memory_unsigned_integer (next_cfa
+ 8, word_size
);
1615 /* The sigregs structure looks like this:
1624 /* Let's ignore the PSW mask, it will not be restored anyway. */
1625 sigreg_ptr
+= word_size
;
1627 /* Next comes the PSW address. */
1628 info
->saved_regs
[S390_PC_REGNUM
].addr
= sigreg_ptr
;
1629 sigreg_ptr
+= word_size
;
1631 /* Then the GPRs. */
1632 for (i
= 0; i
< 16; i
++)
1634 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= sigreg_ptr
;
1635 sigreg_ptr
+= word_size
;
1638 /* Then the ACRs. */
1639 for (i
= 0; i
< 16; i
++)
1641 info
->saved_regs
[S390_A0_REGNUM
+ i
].addr
= sigreg_ptr
;
1645 /* The floating-point control word. */
1646 info
->saved_regs
[S390_FPC_REGNUM
].addr
= sigreg_ptr
;
1649 /* And finally the FPRs. */
1650 for (i
= 0; i
< 16; i
++)
1652 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= sigreg_ptr
;
1656 /* Restore the previous frame's SP. */
1657 prev_sp
= read_memory_unsigned_integer (
1658 info
->saved_regs
[S390_SP_REGNUM
].addr
,
1661 /* Determine our frame base. */
1662 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1668 s390_sigtramp_frame_this_id (struct frame_info
*next_frame
,
1669 void **this_prologue_cache
,
1670 struct frame_id
*this_id
)
1672 struct s390_sigtramp_unwind_cache
*info
1673 = s390_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
1674 *this_id
= frame_id_build (info
->frame_base
, frame_pc_unwind (next_frame
));
1678 s390_sigtramp_frame_prev_register (struct frame_info
*next_frame
,
1679 void **this_prologue_cache
,
1680 int regnum
, int *optimizedp
,
1681 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
1682 int *realnump
, gdb_byte
*bufferp
)
1684 struct s390_sigtramp_unwind_cache
*info
1685 = s390_sigtramp_frame_unwind_cache (next_frame
, this_prologue_cache
);
1686 trad_frame_get_prev_register (next_frame
, info
->saved_regs
, regnum
,
1687 optimizedp
, lvalp
, addrp
, realnump
, bufferp
);
1690 static const struct frame_unwind s390_sigtramp_frame_unwind
= {
1692 s390_sigtramp_frame_this_id
,
1693 s390_sigtramp_frame_prev_register
1696 static const struct frame_unwind
*
1697 s390_sigtramp_frame_sniffer (struct frame_info
*next_frame
)
1699 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
1700 bfd_byte sigreturn
[2];
1702 if (deprecated_read_memory_nobpt (pc
, sigreturn
, 2))
1705 if (sigreturn
[0] != 0x0a /* svc */)
1708 if (sigreturn
[1] != 119 /* sigreturn */
1709 && sigreturn
[1] != 173 /* rt_sigreturn */)
1712 return &s390_sigtramp_frame_unwind
;
1716 /* Frame base handling. */
1719 s390_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
1721 struct s390_unwind_cache
*info
1722 = s390_frame_unwind_cache (next_frame
, this_cache
);
1723 return info
->frame_base
;
1727 s390_local_base_address (struct frame_info
*next_frame
, void **this_cache
)
1729 struct s390_unwind_cache
*info
1730 = s390_frame_unwind_cache (next_frame
, this_cache
);
1731 return info
->local_base
;
1734 static const struct frame_base s390_frame_base
= {
1736 s390_frame_base_address
,
1737 s390_local_base_address
,
1738 s390_local_base_address
1742 s390_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1745 pc
= frame_unwind_register_unsigned (next_frame
, S390_PC_REGNUM
);
1746 return gdbarch_addr_bits_remove (gdbarch
, pc
);
1750 s390_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1753 sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
1754 return gdbarch_addr_bits_remove (gdbarch
, sp
);
1758 /* DWARF-2 frame support. */
1761 s390_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
1762 struct dwarf2_frame_state_reg
*reg
,
1763 struct frame_info
*next_frame
)
1765 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1769 case ABI_LINUX_S390
:
1770 /* Call-saved registers. */
1771 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
1772 || regnum
== S390_F4_REGNUM
1773 || regnum
== S390_F6_REGNUM
)
1774 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1776 /* Call-clobbered registers. */
1777 else if ((regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R5_REGNUM
)
1778 || (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
1779 && regnum
!= S390_F4_REGNUM
&& regnum
!= S390_F6_REGNUM
))
1780 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
1782 /* The return address column. */
1783 else if (regnum
== S390_PC_REGNUM
)
1784 reg
->how
= DWARF2_FRAME_REG_RA
;
1787 case ABI_LINUX_ZSERIES
:
1788 /* Call-saved registers. */
1789 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
1790 || (regnum
>= S390_F8_REGNUM
&& regnum
<= S390_F15_REGNUM
))
1791 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
1793 /* Call-clobbered registers. */
1794 else if ((regnum
>= S390_R0_REGNUM
&& regnum
<= S390_R5_REGNUM
)
1795 || (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F7_REGNUM
))
1796 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
1798 /* The return address column. */
1799 else if (regnum
== S390_PC_REGNUM
)
1800 reg
->how
= DWARF2_FRAME_REG_RA
;
1806 /* Dummy function calls. */
1808 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
1809 "Integer-like" types are those that should be passed the way
1810 integers are: integers, enums, ranges, characters, and booleans. */
1812 is_integer_like (struct type
*type
)
1814 enum type_code code
= TYPE_CODE (type
);
1816 return (code
== TYPE_CODE_INT
1817 || code
== TYPE_CODE_ENUM
1818 || code
== TYPE_CODE_RANGE
1819 || code
== TYPE_CODE_CHAR
1820 || code
== TYPE_CODE_BOOL
);
1823 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
1824 "Pointer-like" types are those that should be passed the way
1825 pointers are: pointers and references. */
1827 is_pointer_like (struct type
*type
)
1829 enum type_code code
= TYPE_CODE (type
);
1831 return (code
== TYPE_CODE_PTR
1832 || code
== TYPE_CODE_REF
);
1836 /* Return non-zero if TYPE is a `float singleton' or `double
1837 singleton', zero otherwise.
1839 A `T singleton' is a struct type with one member, whose type is
1840 either T or a `T singleton'. So, the following are all float
1844 struct { struct { float x; } x; };
1845 struct { struct { struct { float x; } x; } x; };
1849 All such structures are passed as if they were floats or doubles,
1850 as the (revised) ABI says. */
1852 is_float_singleton (struct type
*type
)
1854 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type
) == 1)
1856 struct type
*singleton_type
= TYPE_FIELD_TYPE (type
, 0);
1857 CHECK_TYPEDEF (singleton_type
);
1859 return (TYPE_CODE (singleton_type
) == TYPE_CODE_FLT
1860 || is_float_singleton (singleton_type
));
1867 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
1868 "Struct-like" types are those that should be passed as structs are:
1871 As an odd quirk, not mentioned in the ABI, GCC passes float and
1872 double singletons as if they were a plain float, double, etc. (The
1873 corresponding union types are handled normally.) So we exclude
1874 those types here. *shrug* */
1876 is_struct_like (struct type
*type
)
1878 enum type_code code
= TYPE_CODE (type
);
1880 return (code
== TYPE_CODE_UNION
1881 || (code
== TYPE_CODE_STRUCT
&& ! is_float_singleton (type
)));
1885 /* Return non-zero if TYPE is a float-like type, zero otherwise.
1886 "Float-like" types are those that should be passed as
1887 floating-point values are.
1889 You'd think this would just be floats, doubles, long doubles, etc.
1890 But as an odd quirk, not mentioned in the ABI, GCC passes float and
1891 double singletons as if they were a plain float, double, etc. (The
1892 corresponding union types are handled normally.) So we include
1893 those types here. *shrug* */
1895 is_float_like (struct type
*type
)
1897 return (TYPE_CODE (type
) == TYPE_CODE_FLT
1898 || is_float_singleton (type
));
1903 is_power_of_two (unsigned int n
)
1905 return ((n
& (n
- 1)) == 0);
1908 /* Return non-zero if TYPE should be passed as a pointer to a copy,
1911 s390_function_arg_pass_by_reference (struct type
*type
)
1913 unsigned length
= TYPE_LENGTH (type
);
1917 /* FIXME: All complex and vector types are also returned by reference. */
1918 return is_struct_like (type
) && !is_power_of_two (length
);
1921 /* Return non-zero if TYPE should be passed in a float register
1924 s390_function_arg_float (struct type
*type
)
1926 unsigned length
= TYPE_LENGTH (type
);
1930 return is_float_like (type
);
1933 /* Return non-zero if TYPE should be passed in an integer register
1934 (or a pair of integer registers) if possible. */
1936 s390_function_arg_integer (struct type
*type
)
1938 unsigned length
= TYPE_LENGTH (type
);
1942 return is_integer_like (type
)
1943 || is_pointer_like (type
)
1944 || (is_struct_like (type
) && is_power_of_two (length
));
1947 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
1948 word as required for the ABI. */
1950 extend_simple_arg (struct value
*arg
)
1952 struct type
*type
= value_type (arg
);
1954 /* Even structs get passed in the least significant bits of the
1955 register / memory word. It's not really right to extract them as
1956 an integer, but it does take care of the extension. */
1957 if (TYPE_UNSIGNED (type
))
1958 return extract_unsigned_integer (value_contents (arg
),
1959 TYPE_LENGTH (type
));
1961 return extract_signed_integer (value_contents (arg
),
1962 TYPE_LENGTH (type
));
1966 /* Return the alignment required by TYPE. */
1968 alignment_of (struct type
*type
)
1972 if (is_integer_like (type
)
1973 || is_pointer_like (type
)
1974 || TYPE_CODE (type
) == TYPE_CODE_FLT
)
1975 alignment
= TYPE_LENGTH (type
);
1976 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
1977 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
1982 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
1984 int field_alignment
= alignment_of (TYPE_FIELD_TYPE (type
, i
));
1986 if (field_alignment
> alignment
)
1987 alignment
= field_alignment
;
1993 /* Check that everything we ever return is a power of two. Lots of
1994 code doesn't want to deal with aligning things to arbitrary
1996 gdb_assert ((alignment
& (alignment
- 1)) == 0);
2002 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2003 place to be passed to a function, as specified by the "GNU/Linux
2004 for S/390 ELF Application Binary Interface Supplement".
2006 SP is the current stack pointer. We must put arguments, links,
2007 padding, etc. whereever they belong, and return the new stack
2010 If STRUCT_RETURN is non-zero, then the function we're calling is
2011 going to return a structure by value; STRUCT_ADDR is the address of
2012 a block we've allocated for it on the stack.
2014 Our caller has taken care of any type promotions needed to satisfy
2015 prototypes or the old K&R argument-passing rules. */
2017 s390_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2018 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2019 int nargs
, struct value
**args
, CORE_ADDR sp
,
2020 int struct_return
, CORE_ADDR struct_addr
)
2022 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2023 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2027 /* If the i'th argument is passed as a reference to a copy, then
2028 copy_addr[i] is the address of the copy we made. */
2029 CORE_ADDR
*copy_addr
= alloca (nargs
* sizeof (CORE_ADDR
));
2031 /* Build the reference-to-copy area. */
2032 for (i
= 0; i
< nargs
; i
++)
2034 struct value
*arg
= args
[i
];
2035 struct type
*type
= value_type (arg
);
2036 unsigned length
= TYPE_LENGTH (type
);
2038 if (s390_function_arg_pass_by_reference (type
))
2041 sp
= align_down (sp
, alignment_of (type
));
2042 write_memory (sp
, value_contents (arg
), length
);
2047 /* Reserve space for the parameter area. As a conservative
2048 simplification, we assume that everything will be passed on the
2049 stack. Since every argument larger than 8 bytes will be
2050 passed by reference, we use this simple upper bound. */
2053 /* After all that, make sure it's still aligned on an eight-byte
2055 sp
= align_down (sp
, 8);
2057 /* Finally, place the actual parameters, working from SP towards
2058 higher addresses. The code above is supposed to reserve enough
2063 CORE_ADDR starg
= sp
;
2065 /* A struct is returned using general register 2. */
2068 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2073 for (i
= 0; i
< nargs
; i
++)
2075 struct value
*arg
= args
[i
];
2076 struct type
*type
= value_type (arg
);
2077 unsigned length
= TYPE_LENGTH (type
);
2079 if (s390_function_arg_pass_by_reference (type
))
2083 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2089 write_memory_unsigned_integer (starg
, word_size
, copy_addr
[i
]);
2093 else if (s390_function_arg_float (type
))
2095 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2096 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2097 if (fr
<= (tdep
->abi
== ABI_LINUX_S390
? 2 : 6))
2099 /* When we store a single-precision value in an FP register,
2100 it occupies the leftmost bits. */
2101 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
+ fr
,
2102 0, length
, value_contents (arg
));
2107 /* When we store a single-precision value in a stack slot,
2108 it occupies the rightmost bits. */
2109 starg
= align_up (starg
+ length
, word_size
);
2110 write_memory (starg
- length
, value_contents (arg
), length
);
2113 else if (s390_function_arg_integer (type
) && length
<= word_size
)
2117 /* Integer arguments are always extended to word size. */
2118 regcache_cooked_write_signed (regcache
, S390_R0_REGNUM
+ gr
,
2119 extend_simple_arg (arg
));
2124 /* Integer arguments are always extended to word size. */
2125 write_memory_signed_integer (starg
, word_size
,
2126 extend_simple_arg (arg
));
2130 else if (s390_function_arg_integer (type
) && length
== 2*word_size
)
2134 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
,
2135 value_contents (arg
));
2136 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
+ 1,
2137 value_contents (arg
) + word_size
);
2142 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2143 in it, then don't go back and use it again later. */
2146 write_memory (starg
, value_contents (arg
), length
);
2151 internal_error (__FILE__
, __LINE__
, _("unknown argument type"));
2155 /* Allocate the standard frame areas: the register save area, the
2156 word reserved for the compiler (which seems kind of meaningless),
2157 and the back chain pointer. */
2158 sp
-= 16*word_size
+ 32;
2160 /* Store return address. */
2161 regcache_cooked_write_unsigned (regcache
, S390_RETADDR_REGNUM
, bp_addr
);
2163 /* Store updated stack pointer. */
2164 regcache_cooked_write_unsigned (regcache
, S390_SP_REGNUM
, sp
);
2166 /* We need to return the 'stack part' of the frame ID,
2167 which is actually the top of the register save area. */
2168 return sp
+ 16*word_size
+ 32;
2171 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
2172 dummy frame. The frame ID's base needs to match the TOS value
2173 returned by push_dummy_call, and the PC match the dummy frame's
2175 static struct frame_id
2176 s390_unwind_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2178 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2179 CORE_ADDR sp
= s390_unwind_sp (gdbarch
, next_frame
);
2181 return frame_id_build (sp
+ 16*word_size
+ 32,
2182 frame_pc_unwind (next_frame
));
2186 s390_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2188 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2189 always be aligned on an eight-byte boundary. */
2194 /* Function return value access. */
2196 static enum return_value_convention
2197 s390_return_value_convention (struct gdbarch
*gdbarch
, struct type
*type
)
2199 int length
= TYPE_LENGTH (type
);
2201 return RETURN_VALUE_STRUCT_CONVENTION
;
2203 switch (TYPE_CODE (type
))
2205 case TYPE_CODE_STRUCT
:
2206 case TYPE_CODE_UNION
:
2207 case TYPE_CODE_ARRAY
:
2208 return RETURN_VALUE_STRUCT_CONVENTION
;
2211 return RETURN_VALUE_REGISTER_CONVENTION
;
2215 static enum return_value_convention
2216 s390_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
2217 struct regcache
*regcache
, gdb_byte
*out
,
2220 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2221 int length
= TYPE_LENGTH (type
);
2222 enum return_value_convention rvc
=
2223 s390_return_value_convention (gdbarch
, type
);
2228 case RETURN_VALUE_REGISTER_CONVENTION
:
2229 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2231 /* When we store a single-precision value in an FP register,
2232 it occupies the leftmost bits. */
2233 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
,
2236 else if (length
<= word_size
)
2238 /* Integer arguments are always extended to word size. */
2239 if (TYPE_UNSIGNED (type
))
2240 regcache_cooked_write_unsigned (regcache
, S390_R2_REGNUM
,
2241 extract_unsigned_integer (in
, length
));
2243 regcache_cooked_write_signed (regcache
, S390_R2_REGNUM
,
2244 extract_signed_integer (in
, length
));
2246 else if (length
== 2*word_size
)
2248 regcache_cooked_write (regcache
, S390_R2_REGNUM
, in
);
2249 regcache_cooked_write (regcache
, S390_R3_REGNUM
, in
+ word_size
);
2252 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2255 case RETURN_VALUE_STRUCT_CONVENTION
:
2256 error (_("Cannot set function return value."));
2264 case RETURN_VALUE_REGISTER_CONVENTION
:
2265 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
2267 /* When we store a single-precision value in an FP register,
2268 it occupies the leftmost bits. */
2269 regcache_cooked_read_part (regcache
, S390_F0_REGNUM
,
2272 else if (length
<= word_size
)
2274 /* Integer arguments occupy the rightmost bits. */
2275 regcache_cooked_read_part (regcache
, S390_R2_REGNUM
,
2276 word_size
- length
, length
, out
);
2278 else if (length
== 2*word_size
)
2280 regcache_cooked_read (regcache
, S390_R2_REGNUM
, out
);
2281 regcache_cooked_read (regcache
, S390_R3_REGNUM
, out
+ word_size
);
2284 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2287 case RETURN_VALUE_STRUCT_CONVENTION
:
2288 error (_("Function return value unknown."));
2299 static const gdb_byte
*
2300 s390_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
2302 static const gdb_byte breakpoint
[] = { 0x0, 0x1 };
2304 *lenptr
= sizeof (breakpoint
);
2309 /* Address handling. */
2312 s390_addr_bits_remove (CORE_ADDR addr
)
2314 return addr
& 0x7fffffff;
2318 s390_address_class_type_flags (int byte_size
, int dwarf2_addr_class
)
2321 return TYPE_FLAG_ADDRESS_CLASS_1
;
2327 s390_address_class_type_flags_to_name (struct gdbarch
*gdbarch
, int type_flags
)
2329 if (type_flags
& TYPE_FLAG_ADDRESS_CLASS_1
)
2336 s390_address_class_name_to_type_flags (struct gdbarch
*gdbarch
, const char *name
,
2337 int *type_flags_ptr
)
2339 if (strcmp (name
, "mode32") == 0)
2341 *type_flags_ptr
= TYPE_FLAG_ADDRESS_CLASS_1
;
2348 /* Set up gdbarch struct. */
2350 static struct gdbarch
*
2351 s390_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2353 struct gdbarch
*gdbarch
;
2354 struct gdbarch_tdep
*tdep
;
2356 /* First see if there is already a gdbarch that can satisfy the request. */
2357 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2359 return arches
->gdbarch
;
2361 /* None found: is the request for a s390 architecture? */
2362 if (info
.bfd_arch_info
->arch
!= bfd_arch_s390
)
2363 return NULL
; /* No; then it's not for us. */
2365 /* Yes: create a new gdbarch for the specified machine type. */
2366 tdep
= XCALLOC (1, struct gdbarch_tdep
);
2367 gdbarch
= gdbarch_alloc (&info
, tdep
);
2369 set_gdbarch_believe_pcc_promotion (gdbarch
, 0);
2370 set_gdbarch_char_signed (gdbarch
, 0);
2372 /* Amount PC must be decremented by after a breakpoint. This is
2373 often the number of bytes returned by BREAKPOINT_FROM_PC but not
2375 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
2376 /* Stack grows downward. */
2377 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2378 set_gdbarch_breakpoint_from_pc (gdbarch
, s390_breakpoint_from_pc
);
2379 set_gdbarch_skip_prologue (gdbarch
, s390_skip_prologue
);
2380 set_gdbarch_in_function_epilogue_p (gdbarch
, s390_in_function_epilogue_p
);
2382 set_gdbarch_pc_regnum (gdbarch
, S390_PC_REGNUM
);
2383 set_gdbarch_sp_regnum (gdbarch
, S390_SP_REGNUM
);
2384 set_gdbarch_fp0_regnum (gdbarch
, S390_F0_REGNUM
);
2385 set_gdbarch_num_regs (gdbarch
, S390_NUM_REGS
);
2386 set_gdbarch_num_pseudo_regs (gdbarch
, S390_NUM_PSEUDO_REGS
);
2387 set_gdbarch_register_name (gdbarch
, s390_register_name
);
2388 set_gdbarch_register_type (gdbarch
, s390_register_type
);
2389 set_gdbarch_stab_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2390 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2391 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
2392 set_gdbarch_convert_register_p (gdbarch
, s390_convert_register_p
);
2393 set_gdbarch_register_to_value (gdbarch
, s390_register_to_value
);
2394 set_gdbarch_value_to_register (gdbarch
, s390_value_to_register
);
2395 set_gdbarch_register_reggroup_p (gdbarch
, s390_register_reggroup_p
);
2396 set_gdbarch_regset_from_core_section (gdbarch
,
2397 s390_regset_from_core_section
);
2399 /* Inferior function calls. */
2400 set_gdbarch_push_dummy_call (gdbarch
, s390_push_dummy_call
);
2401 set_gdbarch_unwind_dummy_id (gdbarch
, s390_unwind_dummy_id
);
2402 set_gdbarch_frame_align (gdbarch
, s390_frame_align
);
2403 set_gdbarch_return_value (gdbarch
, s390_return_value
);
2405 /* Frame handling. */
2406 dwarf2_frame_set_init_reg (gdbarch
, s390_dwarf2_frame_init_reg
);
2407 frame_unwind_append_sniffer (gdbarch
, dwarf2_frame_sniffer
);
2408 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
2409 frame_unwind_append_sniffer (gdbarch
, s390_stub_frame_sniffer
);
2410 frame_unwind_append_sniffer (gdbarch
, s390_sigtramp_frame_sniffer
);
2411 frame_unwind_append_sniffer (gdbarch
, s390_frame_sniffer
);
2412 frame_base_set_default (gdbarch
, &s390_frame_base
);
2413 set_gdbarch_unwind_pc (gdbarch
, s390_unwind_pc
);
2414 set_gdbarch_unwind_sp (gdbarch
, s390_unwind_sp
);
2416 switch (info
.bfd_arch_info
->mach
)
2418 case bfd_mach_s390_31
:
2419 tdep
->abi
= ABI_LINUX_S390
;
2421 tdep
->gregset
= &s390_gregset
;
2422 tdep
->sizeof_gregset
= s390_sizeof_gregset
;
2423 tdep
->fpregset
= &s390_fpregset
;
2424 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
2426 set_gdbarch_addr_bits_remove (gdbarch
, s390_addr_bits_remove
);
2427 set_gdbarch_pseudo_register_read (gdbarch
, s390_pseudo_register_read
);
2428 set_gdbarch_pseudo_register_write (gdbarch
, s390_pseudo_register_write
);
2429 set_solib_svr4_fetch_link_map_offsets
2430 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
2433 case bfd_mach_s390_64
:
2434 tdep
->abi
= ABI_LINUX_ZSERIES
;
2436 tdep
->gregset
= &s390x_gregset
;
2437 tdep
->sizeof_gregset
= s390x_sizeof_gregset
;
2438 tdep
->fpregset
= &s390_fpregset
;
2439 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
2441 set_gdbarch_long_bit (gdbarch
, 64);
2442 set_gdbarch_long_long_bit (gdbarch
, 64);
2443 set_gdbarch_ptr_bit (gdbarch
, 64);
2444 set_gdbarch_pseudo_register_read (gdbarch
, s390x_pseudo_register_read
);
2445 set_gdbarch_pseudo_register_write (gdbarch
, s390x_pseudo_register_write
);
2446 set_solib_svr4_fetch_link_map_offsets
2447 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
2448 set_gdbarch_address_class_type_flags (gdbarch
,
2449 s390_address_class_type_flags
);
2450 set_gdbarch_address_class_type_flags_to_name (gdbarch
,
2451 s390_address_class_type_flags_to_name
);
2452 set_gdbarch_address_class_name_to_type_flags (gdbarch
,
2453 s390_address_class_name_to_type_flags
);
2457 set_gdbarch_print_insn (gdbarch
, print_insn_s390
);
2459 /* Enable TLS support. */
2460 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
2461 svr4_fetch_objfile_link_map
);
2468 extern initialize_file_ftype _initialize_s390_tdep
; /* -Wmissing-prototypes */
2471 _initialize_s390_tdep (void)
2474 /* Hook us into the gdbarch mechanism. */
2475 register_gdbarch_init (bfd_arch_s390
, s390_gdbarch_init
);