1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 2001-2014 Free Software Foundation, Inc.
5 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "arch-utils.h"
33 #include "floatformat.h"
35 #include "trad-frame.h"
36 #include "frame-base.h"
37 #include "frame-unwind.h"
38 #include "dwarf2-frame.h"
39 #include "reggroups.h"
43 #include "solib-svr4.h"
44 #include "prologue-value.h"
45 #include "linux-tdep.h"
46 #include "s390-linux-tdep.h"
48 #include "xml-syscall.h"
50 #include "stap-probe.h"
53 #include "user-regs.h"
54 #include "cli/cli-utils.h"
56 #include "elf/common.h"
58 #include "features/s390-linux32.c"
59 #include "features/s390-linux32v1.c"
60 #include "features/s390-linux32v2.c"
61 #include "features/s390-linux64.c"
62 #include "features/s390-linux64v1.c"
63 #include "features/s390-linux64v2.c"
64 #include "features/s390-te-linux64.c"
65 #include "features/s390x-linux64.c"
66 #include "features/s390x-linux64v1.c"
67 #include "features/s390x-linux64v2.c"
68 #include "features/s390x-te-linux64.c"
70 #define XML_SYSCALL_FILENAME_S390 "syscalls/s390-linux.xml"
71 #define XML_SYSCALL_FILENAME_S390X "syscalls/s390x-linux.xml"
73 /* The tdep structure. */
78 enum { ABI_LINUX_S390
, ABI_LINUX_ZSERIES
} abi
;
80 /* Pseudo register numbers. */
85 /* Core file register sets. */
86 const struct regset
*gregset
;
89 const struct regset
*fpregset
;
98 /* ABI call-saved register information. */
101 s390_register_call_saved (struct gdbarch
*gdbarch
, int regnum
)
103 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
108 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
109 || regnum
== S390_F4_REGNUM
|| regnum
== S390_F6_REGNUM
110 || regnum
== S390_A0_REGNUM
)
115 case ABI_LINUX_ZSERIES
:
116 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
117 || (regnum
>= S390_F8_REGNUM
&& regnum
<= S390_F15_REGNUM
)
118 || (regnum
>= S390_A0_REGNUM
&& regnum
<= S390_A1_REGNUM
))
128 s390_cannot_store_register (struct gdbarch
*gdbarch
, int regnum
)
130 /* The last-break address is read-only. */
131 return regnum
== S390_LAST_BREAK_REGNUM
;
135 s390_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
137 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
138 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
140 regcache_cooked_write_unsigned (regcache
, tdep
->pc_regnum
, pc
);
142 /* Set special SYSTEM_CALL register to 0 to prevent the kernel from
143 messing with the PC we just installed, if we happen to be within
144 an interrupted system call that the kernel wants to restart.
146 Note that after we return from the dummy call, the SYSTEM_CALL and
147 ORIG_R2 registers will be automatically restored, and the kernel
148 continues to restart the system call at this point. */
149 if (register_size (gdbarch
, S390_SYSTEM_CALL_REGNUM
) > 0)
150 regcache_cooked_write_unsigned (regcache
, S390_SYSTEM_CALL_REGNUM
, 0);
154 /* DWARF Register Mapping. */
156 static const short s390_dwarf_regmap
[] =
158 /* General Purpose Registers. */
159 S390_R0_REGNUM
, S390_R1_REGNUM
, S390_R2_REGNUM
, S390_R3_REGNUM
,
160 S390_R4_REGNUM
, S390_R5_REGNUM
, S390_R6_REGNUM
, S390_R7_REGNUM
,
161 S390_R8_REGNUM
, S390_R9_REGNUM
, S390_R10_REGNUM
, S390_R11_REGNUM
,
162 S390_R12_REGNUM
, S390_R13_REGNUM
, S390_R14_REGNUM
, S390_R15_REGNUM
,
164 /* Floating Point Registers. */
165 S390_F0_REGNUM
, S390_F2_REGNUM
, S390_F4_REGNUM
, S390_F6_REGNUM
,
166 S390_F1_REGNUM
, S390_F3_REGNUM
, S390_F5_REGNUM
, S390_F7_REGNUM
,
167 S390_F8_REGNUM
, S390_F10_REGNUM
, S390_F12_REGNUM
, S390_F14_REGNUM
,
168 S390_F9_REGNUM
, S390_F11_REGNUM
, S390_F13_REGNUM
, S390_F15_REGNUM
,
170 /* Control Registers (not mapped). */
171 -1, -1, -1, -1, -1, -1, -1, -1,
172 -1, -1, -1, -1, -1, -1, -1, -1,
174 /* Access Registers. */
175 S390_A0_REGNUM
, S390_A1_REGNUM
, S390_A2_REGNUM
, S390_A3_REGNUM
,
176 S390_A4_REGNUM
, S390_A5_REGNUM
, S390_A6_REGNUM
, S390_A7_REGNUM
,
177 S390_A8_REGNUM
, S390_A9_REGNUM
, S390_A10_REGNUM
, S390_A11_REGNUM
,
178 S390_A12_REGNUM
, S390_A13_REGNUM
, S390_A14_REGNUM
, S390_A15_REGNUM
,
180 /* Program Status Word. */
184 /* GPR Lower Half Access. */
185 S390_R0_REGNUM
, S390_R1_REGNUM
, S390_R2_REGNUM
, S390_R3_REGNUM
,
186 S390_R4_REGNUM
, S390_R5_REGNUM
, S390_R6_REGNUM
, S390_R7_REGNUM
,
187 S390_R8_REGNUM
, S390_R9_REGNUM
, S390_R10_REGNUM
, S390_R11_REGNUM
,
188 S390_R12_REGNUM
, S390_R13_REGNUM
, S390_R14_REGNUM
, S390_R15_REGNUM
,
190 /* GNU/Linux-specific registers (not mapped). */
194 /* Convert DWARF register number REG to the appropriate register
195 number used by GDB. */
197 s390_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
199 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
201 /* In a 32-on-64 debug scenario, debug info refers to the full 64-bit
202 GPRs. Note that call frame information still refers to the 32-bit
203 lower halves, because s390_adjust_frame_regnum uses register numbers
204 66 .. 81 to access GPRs. */
205 if (tdep
->gpr_full_regnum
!= -1 && reg
>= 0 && reg
< 16)
206 return tdep
->gpr_full_regnum
+ reg
;
208 if (reg
>= 0 && reg
< ARRAY_SIZE (s390_dwarf_regmap
))
209 return s390_dwarf_regmap
[reg
];
211 warning (_("Unmapped DWARF Register #%d encountered."), reg
);
215 /* Translate a .eh_frame register to DWARF register, or adjust a
216 .debug_frame register. */
218 s390_adjust_frame_regnum (struct gdbarch
*gdbarch
, int num
, int eh_frame_p
)
220 /* See s390_dwarf_reg_to_regnum for comments. */
221 return (num
>= 0 && num
< 16)? num
+ 66 : num
;
225 /* Pseudo registers. */
228 regnum_is_gpr_full (struct gdbarch_tdep
*tdep
, int regnum
)
230 return (tdep
->gpr_full_regnum
!= -1
231 && regnum
>= tdep
->gpr_full_regnum
232 && regnum
<= tdep
->gpr_full_regnum
+ 15);
236 s390_pseudo_register_name (struct gdbarch
*gdbarch
, int regnum
)
238 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
240 if (regnum
== tdep
->pc_regnum
)
243 if (regnum
== tdep
->cc_regnum
)
246 if (regnum_is_gpr_full (tdep
, regnum
))
248 static const char *full_name
[] = {
249 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
250 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
252 return full_name
[regnum
- tdep
->gpr_full_regnum
];
255 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
259 s390_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
261 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
263 if (regnum
== tdep
->pc_regnum
)
264 return builtin_type (gdbarch
)->builtin_func_ptr
;
266 if (regnum
== tdep
->cc_regnum
)
267 return builtin_type (gdbarch
)->builtin_int
;
269 if (regnum_is_gpr_full (tdep
, regnum
))
270 return builtin_type (gdbarch
)->builtin_uint64
;
272 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
275 static enum register_status
276 s390_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
277 int regnum
, gdb_byte
*buf
)
279 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
280 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
281 int regsize
= register_size (gdbarch
, regnum
);
284 if (regnum
== tdep
->pc_regnum
)
286 enum register_status status
;
288 status
= regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &val
);
289 if (status
== REG_VALID
)
291 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
293 store_unsigned_integer (buf
, regsize
, byte_order
, val
);
298 if (regnum
== tdep
->cc_regnum
)
300 enum register_status status
;
302 status
= regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &val
);
303 if (status
== REG_VALID
)
305 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
306 val
= (val
>> 12) & 3;
308 val
= (val
>> 44) & 3;
309 store_unsigned_integer (buf
, regsize
, byte_order
, val
);
314 if (regnum_is_gpr_full (tdep
, regnum
))
316 enum register_status status
;
319 regnum
-= tdep
->gpr_full_regnum
;
321 status
= regcache_raw_read_unsigned (regcache
, S390_R0_REGNUM
+ regnum
, &val
);
322 if (status
== REG_VALID
)
323 status
= regcache_raw_read_unsigned (regcache
, S390_R0_UPPER_REGNUM
+ regnum
,
325 if (status
== REG_VALID
)
327 val
|= val_upper
<< 32;
328 store_unsigned_integer (buf
, regsize
, byte_order
, val
);
333 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
337 s390_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
338 int regnum
, const gdb_byte
*buf
)
340 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
341 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
342 int regsize
= register_size (gdbarch
, regnum
);
345 if (regnum
== tdep
->pc_regnum
)
347 val
= extract_unsigned_integer (buf
, regsize
, byte_order
);
348 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
350 regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &psw
);
351 val
= (psw
& 0x80000000) | (val
& 0x7fffffff);
353 regcache_raw_write_unsigned (regcache
, S390_PSWA_REGNUM
, val
);
357 if (regnum
== tdep
->cc_regnum
)
359 val
= extract_unsigned_integer (buf
, regsize
, byte_order
);
360 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &psw
);
361 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
362 val
= (psw
& ~((ULONGEST
)3 << 12)) | ((val
& 3) << 12);
364 val
= (psw
& ~((ULONGEST
)3 << 44)) | ((val
& 3) << 44);
365 regcache_raw_write_unsigned (regcache
, S390_PSWM_REGNUM
, val
);
369 if (regnum_is_gpr_full (tdep
, regnum
))
371 regnum
-= tdep
->gpr_full_regnum
;
372 val
= extract_unsigned_integer (buf
, regsize
, byte_order
);
373 regcache_raw_write_unsigned (regcache
, S390_R0_REGNUM
+ regnum
,
375 regcache_raw_write_unsigned (regcache
, S390_R0_UPPER_REGNUM
+ regnum
,
380 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
383 /* 'float' values are stored in the upper half of floating-point
384 registers, even though we are otherwise a big-endian platform. */
386 static struct value
*
387 s390_value_from_register (struct gdbarch
*gdbarch
, struct type
*type
,
388 int regnum
, struct frame_id frame_id
)
390 struct value
*value
= default_value_from_register (gdbarch
, type
,
392 check_typedef (type
);
394 if (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
395 && TYPE_LENGTH (type
) < 8)
396 set_value_offset (value
, 0);
401 /* Register groups. */
404 s390_pseudo_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
405 struct reggroup
*group
)
407 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
409 /* We usually save/restore the whole PSW, which includes PC and CC.
410 However, some older gdbservers may not support saving/restoring
411 the whole PSW yet, and will return an XML register description
412 excluding those from the save/restore register groups. In those
413 cases, we still need to explicitly save/restore PC and CC in order
414 to push or pop frames. Since this doesn't hurt anything if we
415 already save/restore the whole PSW (it's just redundant), we add
416 PC and CC at this point unconditionally. */
417 if (group
== save_reggroup
|| group
== restore_reggroup
)
418 return regnum
== tdep
->pc_regnum
|| regnum
== tdep
->cc_regnum
;
420 return default_register_reggroup_p (gdbarch
, regnum
, group
);
424 /* Maps for register sets. */
426 static const struct regcache_map_entry s390_gregmap
[] =
428 { 1, S390_PSWM_REGNUM
},
429 { 1, S390_PSWA_REGNUM
},
430 { 16, S390_R0_REGNUM
},
431 { 16, S390_A0_REGNUM
},
432 { 1, S390_ORIG_R2_REGNUM
},
436 static const struct regcache_map_entry s390_fpregmap
[] =
438 { 1, S390_FPC_REGNUM
, 8 },
439 { 16, S390_F0_REGNUM
, 8 },
443 static const struct regcache_map_entry s390_regmap_upper
[] =
445 { 16, S390_R0_UPPER_REGNUM
, 4 },
449 static const struct regcache_map_entry s390_regmap_last_break
[] =
451 { 1, REGCACHE_MAP_SKIP
, 4 },
452 { 1, S390_LAST_BREAK_REGNUM
, 4 },
456 static const struct regcache_map_entry s390x_regmap_last_break
[] =
458 { 1, S390_LAST_BREAK_REGNUM
, 8 },
462 static const struct regcache_map_entry s390_regmap_system_call
[] =
464 { 1, S390_SYSTEM_CALL_REGNUM
, 4 },
468 static const struct regcache_map_entry s390_regmap_tdb
[] =
470 { 1, S390_TDB_DWORD0_REGNUM
, 8 },
471 { 1, S390_TDB_ABORT_CODE_REGNUM
, 8 },
472 { 1, S390_TDB_CONFLICT_TOKEN_REGNUM
, 8 },
473 { 1, S390_TDB_ATIA_REGNUM
, 8 },
474 { 12, REGCACHE_MAP_SKIP
, 8 },
475 { 16, S390_TDB_R0_REGNUM
, 8 },
480 /* Supply the TDB regset. Like regcache_supply_regset, but invalidate
481 the TDB registers unless the TDB format field is valid. */
484 s390_supply_tdb_regset (const struct regset
*regset
, struct regcache
*regcache
,
485 int regnum
, const void *regs
, size_t len
)
488 enum register_status ret
;
491 regcache_supply_regset (regset
, regcache
, regnum
, regs
, len
);
492 ret
= regcache_cooked_read_unsigned (regcache
, S390_TDB_DWORD0_REGNUM
, &tdw
);
493 if (ret
!= REG_VALID
|| (tdw
>> 56) != 1)
494 regcache_supply_regset (regset
, regcache
, regnum
, NULL
, len
);
497 const struct regset s390_gregset
= {
499 regcache_supply_regset
,
500 regcache_collect_regset
503 const struct regset s390_fpregset
= {
505 regcache_supply_regset
,
506 regcache_collect_regset
509 static const struct regset s390_upper_regset
= {
511 regcache_supply_regset
,
512 regcache_collect_regset
515 const struct regset s390_last_break_regset
= {
516 s390_regmap_last_break
,
517 regcache_supply_regset
,
518 regcache_collect_regset
521 const struct regset s390x_last_break_regset
= {
522 s390x_regmap_last_break
,
523 regcache_supply_regset
,
524 regcache_collect_regset
527 const struct regset s390_system_call_regset
= {
528 s390_regmap_system_call
,
529 regcache_supply_regset
,
530 regcache_collect_regset
533 const struct regset s390_tdb_regset
= {
535 s390_supply_tdb_regset
,
536 regcache_collect_regset
539 /* Return the appropriate register set for the core section identified
540 by SECT_NAME and SECT_SIZE. */
541 static const struct regset
*
542 s390_regset_from_core_section (struct gdbarch
*gdbarch
,
543 const char *sect_name
, size_t sect_size
)
545 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
547 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= tdep
->sizeof_gregset
)
548 return tdep
->gregset
;
550 if (strcmp (sect_name
, ".reg2") == 0 && sect_size
>= tdep
->sizeof_fpregset
)
551 return tdep
->fpregset
;
553 if (strcmp (sect_name
, ".reg-s390-high-gprs") == 0 && sect_size
>= 16*4)
554 return &s390_upper_regset
;
556 if (strcmp (sect_name
, ".reg-s390-last-break") == 0 && sect_size
>= 8)
557 return (gdbarch_ptr_bit (gdbarch
) == 32
558 ? &s390_last_break_regset
: &s390x_last_break_regset
);
560 if (strcmp (sect_name
, ".reg-s390-system-call") == 0 && sect_size
>= 4)
561 return &s390_system_call_regset
;
563 if (strcmp (sect_name
, ".reg-s390-tdb") == 0 && sect_size
>= 256)
564 return &s390_tdb_regset
;
569 /* Iterate over supported core file register note sections. */
572 s390_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
573 iterate_over_regset_sections_cb
*cb
,
575 const struct regcache
*regcache
)
577 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
579 cb (".reg", tdep
->sizeof_gregset
, "general-purpose", cb_data
);
580 cb (".reg2", s390_sizeof_fpregset
, "floating-point", cb_data
);
582 if (tdep
->abi
== ABI_LINUX_S390
&& tdep
->gpr_full_regnum
!= -1)
583 cb (".reg-s390-high-gprs", 16 * 4, "s390 GPR upper halves", cb_data
);
585 if (tdep
->have_linux_v1
)
586 cb (".reg-s390-last-break", 8, "s930 last-break address", cb_data
);
588 if (tdep
->have_linux_v2
)
589 cb (".reg-s390-system-call", 4, "s390 system-call", cb_data
);
591 /* If regcache is set, we are in "write" (gcore) mode. In this
592 case, don't iterate over the TDB unless its registers are
596 || REG_VALID
== regcache_register_status (regcache
,
597 S390_TDB_DWORD0_REGNUM
)))
598 cb (".reg-s390-tdb", s390_sizeof_tdbregset
, "s390 TDB", cb_data
);
601 static const struct target_desc
*
602 s390_core_read_description (struct gdbarch
*gdbarch
,
603 struct target_ops
*target
, bfd
*abfd
)
605 asection
*high_gprs
= bfd_get_section_by_name (abfd
, ".reg-s390-high-gprs");
606 asection
*v1
= bfd_get_section_by_name (abfd
, ".reg-s390-last-break");
607 asection
*v2
= bfd_get_section_by_name (abfd
, ".reg-s390-system-call");
608 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
611 target_auxv_search (target
, AT_HWCAP
, &hwcap
);
615 switch (bfd_section_size (abfd
, section
))
617 case s390_sizeof_gregset
:
619 return ((hwcap
& HWCAP_S390_TE
) ? tdesc_s390_te_linux64
:
620 v2
? tdesc_s390_linux64v2
:
621 v1
? tdesc_s390_linux64v1
: tdesc_s390_linux64
);
623 return (v2
? tdesc_s390_linux32v2
:
624 v1
? tdesc_s390_linux32v1
: tdesc_s390_linux32
);
626 case s390x_sizeof_gregset
:
627 return ((hwcap
& HWCAP_S390_TE
) ? tdesc_s390x_te_linux64
:
628 v2
? tdesc_s390x_linux64v2
:
629 v1
? tdesc_s390x_linux64v1
: tdesc_s390x_linux64
);
637 /* Decoding S/390 instructions. */
639 /* Named opcode values for the S/390 instructions we recognize. Some
640 instructions have their opcode split across two fields; those are the
641 op1_* and op2_* enums. */
644 op1_lhi
= 0xa7, op2_lhi
= 0x08,
645 op1_lghi
= 0xa7, op2_lghi
= 0x09,
646 op1_lgfi
= 0xc0, op2_lgfi
= 0x01,
650 op1_ly
= 0xe3, op2_ly
= 0x58,
651 op1_lg
= 0xe3, op2_lg
= 0x04,
653 op1_lmy
= 0xeb, op2_lmy
= 0x98,
654 op1_lmg
= 0xeb, op2_lmg
= 0x04,
656 op1_sty
= 0xe3, op2_sty
= 0x50,
657 op1_stg
= 0xe3, op2_stg
= 0x24,
660 op1_stmy
= 0xeb, op2_stmy
= 0x90,
661 op1_stmg
= 0xeb, op2_stmg
= 0x24,
662 op1_aghi
= 0xa7, op2_aghi
= 0x0b,
663 op1_ahi
= 0xa7, op2_ahi
= 0x0a,
664 op1_agfi
= 0xc2, op2_agfi
= 0x08,
665 op1_afi
= 0xc2, op2_afi
= 0x09,
666 op1_algfi
= 0xc2, op2_algfi
= 0x0a,
667 op1_alfi
= 0xc2, op2_alfi
= 0x0b,
671 op1_ay
= 0xe3, op2_ay
= 0x5a,
672 op1_ag
= 0xe3, op2_ag
= 0x08,
673 op1_slgfi
= 0xc2, op2_slgfi
= 0x04,
674 op1_slfi
= 0xc2, op2_slfi
= 0x05,
678 op1_sy
= 0xe3, op2_sy
= 0x5b,
679 op1_sg
= 0xe3, op2_sg
= 0x09,
683 op1_lay
= 0xe3, op2_lay
= 0x71,
684 op1_larl
= 0xc0, op2_larl
= 0x00,
692 op1_bctg
= 0xe3, op2_bctg
= 0x46,
694 op1_bxhg
= 0xeb, op2_bxhg
= 0x44,
696 op1_bxleg
= 0xeb, op2_bxleg
= 0x45,
697 op1_bras
= 0xa7, op2_bras
= 0x05,
698 op1_brasl
= 0xc0, op2_brasl
= 0x05,
699 op1_brc
= 0xa7, op2_brc
= 0x04,
700 op1_brcl
= 0xc0, op2_brcl
= 0x04,
701 op1_brct
= 0xa7, op2_brct
= 0x06,
702 op1_brctg
= 0xa7, op2_brctg
= 0x07,
704 op1_brxhg
= 0xec, op2_brxhg
= 0x44,
706 op1_brxlg
= 0xec, op2_brxlg
= 0x45,
711 /* Read a single instruction from address AT. */
713 #define S390_MAX_INSTR_SIZE 6
715 s390_readinstruction (bfd_byte instr
[], CORE_ADDR at
)
717 static int s390_instrlen
[] = { 2, 4, 4, 6 };
720 if (target_read_memory (at
, &instr
[0], 2))
722 instrlen
= s390_instrlen
[instr
[0] >> 6];
725 if (target_read_memory (at
+ 2, &instr
[2], instrlen
- 2))
732 /* The functions below are for recognizing and decoding S/390
733 instructions of various formats. Each of them checks whether INSN
734 is an instruction of the given format, with the specified opcodes.
735 If it is, it sets the remaining arguments to the values of the
736 instruction's fields, and returns a non-zero value; otherwise, it
739 These functions' arguments appear in the order they appear in the
740 instruction, not in the machine-language form. So, opcodes always
741 come first, even though they're sometimes scattered around the
742 instructions. And displacements appear before base and extension
743 registers, as they do in the assembly syntax, not at the end, as
744 they do in the machine language. */
746 is_ri (bfd_byte
*insn
, int op1
, int op2
, unsigned int *r1
, int *i2
)
748 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
750 *r1
= (insn
[1] >> 4) & 0xf;
751 /* i2 is a 16-bit signed quantity. */
752 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
761 is_ril (bfd_byte
*insn
, int op1
, int op2
,
762 unsigned int *r1
, int *i2
)
764 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
766 *r1
= (insn
[1] >> 4) & 0xf;
767 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
768 no sign extension is necessary, but we don't want to assume
770 *i2
= (((insn
[2] << 24)
773 | (insn
[5])) ^ 0x80000000) - 0x80000000;
782 is_rr (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
786 *r1
= (insn
[1] >> 4) & 0xf;
796 is_rre (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
798 if (((insn
[0] << 8) | insn
[1]) == op
)
800 /* Yes, insn[3]. insn[2] is unused in RRE format. */
801 *r1
= (insn
[3] >> 4) & 0xf;
811 is_rs (bfd_byte
*insn
, int op
,
812 unsigned int *r1
, unsigned int *r3
, int *d2
, unsigned int *b2
)
816 *r1
= (insn
[1] >> 4) & 0xf;
818 *b2
= (insn
[2] >> 4) & 0xf;
819 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
828 is_rsy (bfd_byte
*insn
, int op1
, int op2
,
829 unsigned int *r1
, unsigned int *r3
, int *d2
, unsigned int *b2
)
834 *r1
= (insn
[1] >> 4) & 0xf;
836 *b2
= (insn
[2] >> 4) & 0xf;
837 /* The 'long displacement' is a 20-bit signed integer. */
838 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
839 ^ 0x80000) - 0x80000;
848 is_rsi (bfd_byte
*insn
, int op
,
849 unsigned int *r1
, unsigned int *r3
, int *i2
)
853 *r1
= (insn
[1] >> 4) & 0xf;
855 /* i2 is a 16-bit signed quantity. */
856 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
865 is_rie (bfd_byte
*insn
, int op1
, int op2
,
866 unsigned int *r1
, unsigned int *r3
, int *i2
)
871 *r1
= (insn
[1] >> 4) & 0xf;
873 /* i2 is a 16-bit signed quantity. */
874 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
883 is_rx (bfd_byte
*insn
, int op
,
884 unsigned int *r1
, int *d2
, unsigned int *x2
, unsigned int *b2
)
888 *r1
= (insn
[1] >> 4) & 0xf;
890 *b2
= (insn
[2] >> 4) & 0xf;
891 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
900 is_rxy (bfd_byte
*insn
, int op1
, int op2
,
901 unsigned int *r1
, int *d2
, unsigned int *x2
, unsigned int *b2
)
906 *r1
= (insn
[1] >> 4) & 0xf;
908 *b2
= (insn
[2] >> 4) & 0xf;
909 /* The 'long displacement' is a 20-bit signed integer. */
910 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
911 ^ 0x80000) - 0x80000;
919 /* Prologue analysis. */
921 #define S390_NUM_GPRS 16
922 #define S390_NUM_FPRS 16
924 struct s390_prologue_data
{
927 struct pv_area
*stack
;
929 /* The size and byte-order of a GPR or FPR. */
932 enum bfd_endian byte_order
;
934 /* The general-purpose registers. */
935 pv_t gpr
[S390_NUM_GPRS
];
937 /* The floating-point registers. */
938 pv_t fpr
[S390_NUM_FPRS
];
940 /* The offset relative to the CFA where the incoming GPR N was saved
941 by the function prologue. 0 if not saved or unknown. */
942 int gpr_slot
[S390_NUM_GPRS
];
944 /* Likewise for FPRs. */
945 int fpr_slot
[S390_NUM_FPRS
];
947 /* Nonzero if the backchain was saved. This is assumed to be the
948 case when the incoming SP is saved at the current SP location. */
949 int back_chain_saved_p
;
952 /* Return the effective address for an X-style instruction, like:
956 Here, X2 and B2 are registers, and D2 is a signed 20-bit
957 constant; the effective address is the sum of all three. If either
958 X2 or B2 are zero, then it doesn't contribute to the sum --- this
959 means that r0 can't be used as either X2 or B2. */
961 s390_addr (struct s390_prologue_data
*data
,
962 int d2
, unsigned int x2
, unsigned int b2
)
966 result
= pv_constant (d2
);
968 result
= pv_add (result
, data
->gpr
[x2
]);
970 result
= pv_add (result
, data
->gpr
[b2
]);
975 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
977 s390_store (struct s390_prologue_data
*data
,
978 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
,
981 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
984 /* Check whether we are storing the backchain. */
985 offset
= pv_subtract (data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
], addr
);
987 if (pv_is_constant (offset
) && offset
.k
== 0)
988 if (size
== data
->gpr_size
989 && pv_is_register_k (value
, S390_SP_REGNUM
, 0))
991 data
->back_chain_saved_p
= 1;
996 /* Check whether we are storing a register into the stack. */
997 if (!pv_area_store_would_trash (data
->stack
, addr
))
998 pv_area_store (data
->stack
, addr
, size
, value
);
1001 /* Note: If this is some store we cannot identify, you might think we
1002 should forget our cached values, as any of those might have been hit.
1004 However, we make the assumption that the register save areas are only
1005 ever stored to once in any given function, and we do recognize these
1006 stores. Thus every store we cannot recognize does not hit our data. */
1009 /* Do a SIZE-byte load from D2(X2,B2). */
1011 s390_load (struct s390_prologue_data
*data
,
1012 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
)
1015 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
1017 /* If it's a load from an in-line constant pool, then we can
1018 simulate that, under the assumption that the code isn't
1019 going to change between the time the processor actually
1020 executed it creating the current frame, and the time when
1021 we're analyzing the code to unwind past that frame. */
1022 if (pv_is_constant (addr
))
1024 struct target_section
*secp
;
1025 secp
= target_section_by_addr (¤t_target
, addr
.k
);
1027 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
1028 secp
->the_bfd_section
)
1030 return pv_constant (read_memory_integer (addr
.k
, size
,
1034 /* Check whether we are accessing one of our save slots. */
1035 return pv_area_fetch (data
->stack
, addr
, size
);
1038 /* Function for finding saved registers in a 'struct pv_area'; we pass
1039 this to pv_area_scan.
1041 If VALUE is a saved register, ADDR says it was saved at a constant
1042 offset from the frame base, and SIZE indicates that the whole
1043 register was saved, record its offset in the reg_offset table in
1044 PROLOGUE_UNTYPED. */
1046 s390_check_for_saved (void *data_untyped
, pv_t addr
,
1047 CORE_ADDR size
, pv_t value
)
1049 struct s390_prologue_data
*data
= data_untyped
;
1052 if (!pv_is_register (addr
, S390_SP_REGNUM
))
1055 offset
= 16 * data
->gpr_size
+ 32 - addr
.k
;
1057 /* If we are storing the original value of a register, we want to
1058 record the CFA offset. If the same register is stored multiple
1059 times, the stack slot with the highest address counts. */
1061 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1062 if (size
== data
->gpr_size
1063 && pv_is_register_k (value
, S390_R0_REGNUM
+ i
, 0))
1064 if (data
->gpr_slot
[i
] == 0
1065 || data
->gpr_slot
[i
] > offset
)
1067 data
->gpr_slot
[i
] = offset
;
1071 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1072 if (size
== data
->fpr_size
1073 && pv_is_register_k (value
, S390_F0_REGNUM
+ i
, 0))
1074 if (data
->fpr_slot
[i
] == 0
1075 || data
->fpr_slot
[i
] > offset
)
1077 data
->fpr_slot
[i
] = offset
;
1082 /* Analyze the prologue of the function starting at START_PC,
1083 continuing at most until CURRENT_PC. Initialize DATA to
1084 hold all information we find out about the state of the registers
1085 and stack slots. Return the address of the instruction after
1086 the last one that changed the SP, FP, or back chain; or zero
1089 s390_analyze_prologue (struct gdbarch
*gdbarch
,
1091 CORE_ADDR current_pc
,
1092 struct s390_prologue_data
*data
)
1094 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1096 /* Our return value:
1097 The address of the instruction after the last one that changed
1098 the SP, FP, or back chain; zero if we got an error trying to
1100 CORE_ADDR result
= start_pc
;
1102 /* The current PC for our abstract interpretation. */
1105 /* The address of the next instruction after that. */
1108 /* Set up everything's initial value. */
1112 data
->stack
= make_pv_area (S390_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
1114 /* For the purpose of prologue tracking, we consider the GPR size to
1115 be equal to the ABI word size, even if it is actually larger
1116 (i.e. when running a 32-bit binary under a 64-bit kernel). */
1117 data
->gpr_size
= word_size
;
1119 data
->byte_order
= gdbarch_byte_order (gdbarch
);
1121 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1122 data
->gpr
[i
] = pv_register (S390_R0_REGNUM
+ i
, 0);
1124 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1125 data
->fpr
[i
] = pv_register (S390_F0_REGNUM
+ i
, 0);
1127 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1128 data
->gpr_slot
[i
] = 0;
1130 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1131 data
->fpr_slot
[i
] = 0;
1133 data
->back_chain_saved_p
= 0;
1136 /* Start interpreting instructions, until we hit the frame's
1137 current PC or the first branch instruction. */
1138 for (pc
= start_pc
; pc
> 0 && pc
< current_pc
; pc
= next_pc
)
1140 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
1141 int insn_len
= s390_readinstruction (insn
, pc
);
1143 bfd_byte dummy
[S390_MAX_INSTR_SIZE
] = { 0 };
1144 bfd_byte
*insn32
= word_size
== 4 ? insn
: dummy
;
1145 bfd_byte
*insn64
= word_size
== 8 ? insn
: dummy
;
1147 /* Fields for various kinds of instructions. */
1148 unsigned int b2
, r1
, r2
, x2
, r3
;
1151 /* The values of SP and FP before this instruction,
1152 for detecting instructions that change them. */
1153 pv_t pre_insn_sp
, pre_insn_fp
;
1154 /* Likewise for the flag whether the back chain was saved. */
1155 int pre_insn_back_chain_saved_p
;
1157 /* If we got an error trying to read the instruction, report it. */
1164 next_pc
= pc
+ insn_len
;
1166 pre_insn_sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1167 pre_insn_fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1168 pre_insn_back_chain_saved_p
= data
->back_chain_saved_p
;
1171 /* LHI r1, i2 --- load halfword immediate. */
1172 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
1173 /* LGFI r1, i2 --- load fullword immediate. */
1174 if (is_ri (insn32
, op1_lhi
, op2_lhi
, &r1
, &i2
)
1175 || is_ri (insn64
, op1_lghi
, op2_lghi
, &r1
, &i2
)
1176 || is_ril (insn
, op1_lgfi
, op2_lgfi
, &r1
, &i2
))
1177 data
->gpr
[r1
] = pv_constant (i2
);
1179 /* LR r1, r2 --- load from register. */
1180 /* LGR r1, r2 --- load from register (64-bit version). */
1181 else if (is_rr (insn32
, op_lr
, &r1
, &r2
)
1182 || is_rre (insn64
, op_lgr
, &r1
, &r2
))
1183 data
->gpr
[r1
] = data
->gpr
[r2
];
1185 /* L r1, d2(x2, b2) --- load. */
1186 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
1187 /* LG r1, d2(x2, b2) --- load (64-bit version). */
1188 else if (is_rx (insn32
, op_l
, &r1
, &d2
, &x2
, &b2
)
1189 || is_rxy (insn32
, op1_ly
, op2_ly
, &r1
, &d2
, &x2
, &b2
)
1190 || is_rxy (insn64
, op1_lg
, op2_lg
, &r1
, &d2
, &x2
, &b2
))
1191 data
->gpr
[r1
] = s390_load (data
, d2
, x2
, b2
, data
->gpr_size
);
1193 /* ST r1, d2(x2, b2) --- store. */
1194 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
1195 /* STG r1, d2(x2, b2) --- store (64-bit version). */
1196 else if (is_rx (insn32
, op_st
, &r1
, &d2
, &x2
, &b2
)
1197 || is_rxy (insn32
, op1_sty
, op2_sty
, &r1
, &d2
, &x2
, &b2
)
1198 || is_rxy (insn64
, op1_stg
, op2_stg
, &r1
, &d2
, &x2
, &b2
))
1199 s390_store (data
, d2
, x2
, b2
, data
->gpr_size
, data
->gpr
[r1
]);
1201 /* STD r1, d2(x2,b2) --- store floating-point register. */
1202 else if (is_rx (insn
, op_std
, &r1
, &d2
, &x2
, &b2
))
1203 s390_store (data
, d2
, x2
, b2
, data
->fpr_size
, data
->fpr
[r1
]);
1205 /* STM r1, r3, d2(b2) --- store multiple. */
1206 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement
1208 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
1209 else if (is_rs (insn32
, op_stm
, &r1
, &r3
, &d2
, &b2
)
1210 || is_rsy (insn32
, op1_stmy
, op2_stmy
, &r1
, &r3
, &d2
, &b2
)
1211 || is_rsy (insn64
, op1_stmg
, op2_stmg
, &r1
, &r3
, &d2
, &b2
))
1213 for (; r1
<= r3
; r1
++, d2
+= data
->gpr_size
)
1214 s390_store (data
, d2
, 0, b2
, data
->gpr_size
, data
->gpr
[r1
]);
1217 /* AHI r1, i2 --- add halfword immediate. */
1218 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
1219 /* AFI r1, i2 --- add fullword immediate. */
1220 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
1221 else if (is_ri (insn32
, op1_ahi
, op2_ahi
, &r1
, &i2
)
1222 || is_ri (insn64
, op1_aghi
, op2_aghi
, &r1
, &i2
)
1223 || is_ril (insn32
, op1_afi
, op2_afi
, &r1
, &i2
)
1224 || is_ril (insn64
, op1_agfi
, op2_agfi
, &r1
, &i2
))
1225 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
], i2
);
1227 /* ALFI r1, i2 --- add logical immediate. */
1228 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
1229 else if (is_ril (insn32
, op1_alfi
, op2_alfi
, &r1
, &i2
)
1230 || is_ril (insn64
, op1_algfi
, op2_algfi
, &r1
, &i2
))
1231 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
],
1232 (CORE_ADDR
)i2
& 0xffffffff);
1234 /* AR r1, r2 -- add register. */
1235 /* AGR r1, r2 -- add register (64-bit version). */
1236 else if (is_rr (insn32
, op_ar
, &r1
, &r2
)
1237 || is_rre (insn64
, op_agr
, &r1
, &r2
))
1238 data
->gpr
[r1
] = pv_add (data
->gpr
[r1
], data
->gpr
[r2
]);
1240 /* A r1, d2(x2, b2) -- add. */
1241 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
1242 /* AG r1, d2(x2, b2) -- add (64-bit version). */
1243 else if (is_rx (insn32
, op_a
, &r1
, &d2
, &x2
, &b2
)
1244 || is_rxy (insn32
, op1_ay
, op2_ay
, &r1
, &d2
, &x2
, &b2
)
1245 || is_rxy (insn64
, op1_ag
, op2_ag
, &r1
, &d2
, &x2
, &b2
))
1246 data
->gpr
[r1
] = pv_add (data
->gpr
[r1
],
1247 s390_load (data
, d2
, x2
, b2
, data
->gpr_size
));
1249 /* SLFI r1, i2 --- subtract logical immediate. */
1250 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
1251 else if (is_ril (insn32
, op1_slfi
, op2_slfi
, &r1
, &i2
)
1252 || is_ril (insn64
, op1_slgfi
, op2_slgfi
, &r1
, &i2
))
1253 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
],
1254 -((CORE_ADDR
)i2
& 0xffffffff));
1256 /* SR r1, r2 -- subtract register. */
1257 /* SGR r1, r2 -- subtract register (64-bit version). */
1258 else if (is_rr (insn32
, op_sr
, &r1
, &r2
)
1259 || is_rre (insn64
, op_sgr
, &r1
, &r2
))
1260 data
->gpr
[r1
] = pv_subtract (data
->gpr
[r1
], data
->gpr
[r2
]);
1262 /* S r1, d2(x2, b2) -- subtract. */
1263 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
1264 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
1265 else if (is_rx (insn32
, op_s
, &r1
, &d2
, &x2
, &b2
)
1266 || is_rxy (insn32
, op1_sy
, op2_sy
, &r1
, &d2
, &x2
, &b2
)
1267 || is_rxy (insn64
, op1_sg
, op2_sg
, &r1
, &d2
, &x2
, &b2
))
1268 data
->gpr
[r1
] = pv_subtract (data
->gpr
[r1
],
1269 s390_load (data
, d2
, x2
, b2
, data
->gpr_size
));
1271 /* LA r1, d2(x2, b2) --- load address. */
1272 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
1273 else if (is_rx (insn
, op_la
, &r1
, &d2
, &x2
, &b2
)
1274 || is_rxy (insn
, op1_lay
, op2_lay
, &r1
, &d2
, &x2
, &b2
))
1275 data
->gpr
[r1
] = s390_addr (data
, d2
, x2
, b2
);
1277 /* LARL r1, i2 --- load address relative long. */
1278 else if (is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1279 data
->gpr
[r1
] = pv_constant (pc
+ i2
* 2);
1281 /* BASR r1, 0 --- branch and save.
1282 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1283 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1285 data
->gpr
[r1
] = pv_constant (next_pc
);
1287 /* BRAS r1, i2 --- branch relative and save. */
1288 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
))
1290 data
->gpr
[r1
] = pv_constant (next_pc
);
1291 next_pc
= pc
+ i2
* 2;
1293 /* We'd better not interpret any backward branches. We'll
1299 /* Terminate search when hitting any other branch instruction. */
1300 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1301 || is_rx (insn
, op_bas
, &r1
, &d2
, &x2
, &b2
)
1302 || is_rr (insn
, op_bcr
, &r1
, &r2
)
1303 || is_rx (insn
, op_bc
, &r1
, &d2
, &x2
, &b2
)
1304 || is_ri (insn
, op1_brc
, op2_brc
, &r1
, &i2
)
1305 || is_ril (insn
, op1_brcl
, op2_brcl
, &r1
, &i2
)
1306 || is_ril (insn
, op1_brasl
, op2_brasl
, &r2
, &i2
))
1311 /* An instruction we don't know how to simulate. The only
1312 safe thing to do would be to set every value we're tracking
1313 to 'unknown'. Instead, we'll be optimistic: we assume that
1314 we *can* interpret every instruction that the compiler uses
1315 to manipulate any of the data we're interested in here --
1316 then we can just ignore anything else. */
1319 /* Record the address after the last instruction that changed
1320 the FP, SP, or backlink. Ignore instructions that changed
1321 them back to their original values --- those are probably
1322 restore instructions. (The back chain is never restored,
1325 pv_t sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1326 pv_t fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1328 if ((! pv_is_identical (pre_insn_sp
, sp
)
1329 && ! pv_is_register_k (sp
, S390_SP_REGNUM
, 0)
1330 && sp
.kind
!= pvk_unknown
)
1331 || (! pv_is_identical (pre_insn_fp
, fp
)
1332 && ! pv_is_register_k (fp
, S390_FRAME_REGNUM
, 0)
1333 && fp
.kind
!= pvk_unknown
)
1334 || pre_insn_back_chain_saved_p
!= data
->back_chain_saved_p
)
1339 /* Record where all the registers were saved. */
1340 pv_area_scan (data
->stack
, s390_check_for_saved
, data
);
1342 free_pv_area (data
->stack
);
1348 /* Advance PC across any function entry prologue instructions to reach
1349 some "real" code. */
1351 s390_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1353 struct s390_prologue_data data
;
1355 skip_pc
= s390_analyze_prologue (gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
1356 return skip_pc
? skip_pc
: pc
;
1359 /* Return true if we are in the functin's epilogue, i.e. after the
1360 instruction that destroyed the function's stack frame. */
1362 s390_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1364 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1366 /* In frameless functions, there's not frame to destroy and thus
1367 we don't care about the epilogue.
1369 In functions with frame, the epilogue sequence is a pair of
1370 a LM-type instruction that restores (amongst others) the
1371 return register %r14 and the stack pointer %r15, followed
1372 by a branch 'br %r14' --or equivalent-- that effects the
1375 In that situation, this function needs to return 'true' in
1376 exactly one case: when pc points to that branch instruction.
1378 Thus we try to disassemble the one instructions immediately
1379 preceding pc and check whether it is an LM-type instruction
1380 modifying the stack pointer.
1382 Note that disassembling backwards is not reliable, so there
1383 is a slight chance of false positives here ... */
1386 unsigned int r1
, r3
, b2
;
1390 && !target_read_memory (pc
- 4, insn
, 4)
1391 && is_rs (insn
, op_lm
, &r1
, &r3
, &d2
, &b2
)
1392 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1396 && !target_read_memory (pc
- 6, insn
, 6)
1397 && is_rsy (insn
, op1_lmy
, op2_lmy
, &r1
, &r3
, &d2
, &b2
)
1398 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1402 && !target_read_memory (pc
- 6, insn
, 6)
1403 && is_rsy (insn
, op1_lmg
, op2_lmg
, &r1
, &r3
, &d2
, &b2
)
1404 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1410 /* Displaced stepping. */
1412 /* Fix up the state of registers and memory after having single-stepped
1413 a displaced instruction. */
1415 s390_displaced_step_fixup (struct gdbarch
*gdbarch
,
1416 struct displaced_step_closure
*closure
,
1417 CORE_ADDR from
, CORE_ADDR to
,
1418 struct regcache
*regs
)
1420 /* Since we use simple_displaced_step_copy_insn, our closure is a
1421 copy of the instruction. */
1422 gdb_byte
*insn
= (gdb_byte
*) closure
;
1423 static int s390_instrlen
[] = { 2, 4, 4, 6 };
1424 int insnlen
= s390_instrlen
[insn
[0] >> 6];
1426 /* Fields for various kinds of instructions. */
1427 unsigned int b2
, r1
, r2
, x2
, r3
;
1430 /* Get current PC and addressing mode bit. */
1431 CORE_ADDR pc
= regcache_read_pc (regs
);
1434 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
1436 regcache_cooked_read_unsigned (regs
, S390_PSWA_REGNUM
, &amode
);
1437 amode
&= 0x80000000;
1440 if (debug_displaced
)
1441 fprintf_unfiltered (gdb_stdlog
,
1442 "displaced: (s390) fixup (%s, %s) pc %s len %d amode 0x%x\n",
1443 paddress (gdbarch
, from
), paddress (gdbarch
, to
),
1444 paddress (gdbarch
, pc
), insnlen
, (int) amode
);
1446 /* Handle absolute branch and save instructions. */
1447 if (is_rr (insn
, op_basr
, &r1
, &r2
)
1448 || is_rx (insn
, op_bas
, &r1
, &d2
, &x2
, &b2
))
1450 /* Recompute saved return address in R1. */
1451 regcache_cooked_write_unsigned (regs
, S390_R0_REGNUM
+ r1
,
1452 amode
| (from
+ insnlen
));
1455 /* Handle absolute branch instructions. */
1456 else if (is_rr (insn
, op_bcr
, &r1
, &r2
)
1457 || is_rx (insn
, op_bc
, &r1
, &d2
, &x2
, &b2
)
1458 || is_rr (insn
, op_bctr
, &r1
, &r2
)
1459 || is_rre (insn
, op_bctgr
, &r1
, &r2
)
1460 || is_rx (insn
, op_bct
, &r1
, &d2
, &x2
, &b2
)
1461 || is_rxy (insn
, op1_bctg
, op2_brctg
, &r1
, &d2
, &x2
, &b2
)
1462 || is_rs (insn
, op_bxh
, &r1
, &r3
, &d2
, &b2
)
1463 || is_rsy (insn
, op1_bxhg
, op2_bxhg
, &r1
, &r3
, &d2
, &b2
)
1464 || is_rs (insn
, op_bxle
, &r1
, &r3
, &d2
, &b2
)
1465 || is_rsy (insn
, op1_bxleg
, op2_bxleg
, &r1
, &r3
, &d2
, &b2
))
1467 /* Update PC iff branch was *not* taken. */
1468 if (pc
== to
+ insnlen
)
1469 regcache_write_pc (regs
, from
+ insnlen
);
1472 /* Handle PC-relative branch and save instructions. */
1473 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
)
1474 || is_ril (insn
, op1_brasl
, op2_brasl
, &r1
, &i2
))
1477 regcache_write_pc (regs
, pc
- to
+ from
);
1478 /* Recompute saved return address in R1. */
1479 regcache_cooked_write_unsigned (regs
, S390_R0_REGNUM
+ r1
,
1480 amode
| (from
+ insnlen
));
1483 /* Handle PC-relative branch instructions. */
1484 else if (is_ri (insn
, op1_brc
, op2_brc
, &r1
, &i2
)
1485 || is_ril (insn
, op1_brcl
, op2_brcl
, &r1
, &i2
)
1486 || is_ri (insn
, op1_brct
, op2_brct
, &r1
, &i2
)
1487 || is_ri (insn
, op1_brctg
, op2_brctg
, &r1
, &i2
)
1488 || is_rsi (insn
, op_brxh
, &r1
, &r3
, &i2
)
1489 || is_rie (insn
, op1_brxhg
, op2_brxhg
, &r1
, &r3
, &i2
)
1490 || is_rsi (insn
, op_brxle
, &r1
, &r3
, &i2
)
1491 || is_rie (insn
, op1_brxlg
, op2_brxlg
, &r1
, &r3
, &i2
))
1494 regcache_write_pc (regs
, pc
- to
+ from
);
1497 /* Handle LOAD ADDRESS RELATIVE LONG. */
1498 else if (is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1501 regcache_write_pc (regs
, from
+ insnlen
);
1502 /* Recompute output address in R1. */
1503 regcache_cooked_write_unsigned (regs
, S390_R0_REGNUM
+ r1
,
1504 amode
| (from
+ i2
* 2));
1507 /* If we executed a breakpoint instruction, point PC right back at it. */
1508 else if (insn
[0] == 0x0 && insn
[1] == 0x1)
1509 regcache_write_pc (regs
, from
);
1511 /* For any other insn, PC points right after the original instruction. */
1513 regcache_write_pc (regs
, from
+ insnlen
);
1515 if (debug_displaced
)
1516 fprintf_unfiltered (gdb_stdlog
,
1517 "displaced: (s390) pc is now %s\n",
1518 paddress (gdbarch
, regcache_read_pc (regs
)));
1522 /* Helper routine to unwind pseudo registers. */
1524 static struct value
*
1525 s390_unwind_pseudo_register (struct frame_info
*this_frame
, int regnum
)
1527 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1528 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1529 struct type
*type
= register_type (gdbarch
, regnum
);
1531 /* Unwind PC via PSW address. */
1532 if (regnum
== tdep
->pc_regnum
)
1536 val
= frame_unwind_register_value (this_frame
, S390_PSWA_REGNUM
);
1537 if (!value_optimized_out (val
))
1539 LONGEST pswa
= value_as_long (val
);
1541 if (TYPE_LENGTH (type
) == 4)
1542 return value_from_pointer (type
, pswa
& 0x7fffffff);
1544 return value_from_pointer (type
, pswa
);
1548 /* Unwind CC via PSW mask. */
1549 if (regnum
== tdep
->cc_regnum
)
1553 val
= frame_unwind_register_value (this_frame
, S390_PSWM_REGNUM
);
1554 if (!value_optimized_out (val
))
1556 LONGEST pswm
= value_as_long (val
);
1558 if (TYPE_LENGTH (type
) == 4)
1559 return value_from_longest (type
, (pswm
>> 12) & 3);
1561 return value_from_longest (type
, (pswm
>> 44) & 3);
1565 /* Unwind full GPRs to show at least the lower halves (as the
1566 upper halves are undefined). */
1567 if (regnum_is_gpr_full (tdep
, regnum
))
1569 int reg
= regnum
- tdep
->gpr_full_regnum
;
1572 val
= frame_unwind_register_value (this_frame
, S390_R0_REGNUM
+ reg
);
1573 if (!value_optimized_out (val
))
1574 return value_cast (type
, val
);
1577 return allocate_optimized_out_value (type
);
1580 static struct value
*
1581 s390_trad_frame_prev_register (struct frame_info
*this_frame
,
1582 struct trad_frame_saved_reg saved_regs
[],
1585 if (regnum
< S390_NUM_REGS
)
1586 return trad_frame_get_prev_register (this_frame
, saved_regs
, regnum
);
1588 return s390_unwind_pseudo_register (this_frame
, regnum
);
1592 /* Normal stack frames. */
1594 struct s390_unwind_cache
{
1597 CORE_ADDR frame_base
;
1598 CORE_ADDR local_base
;
1600 struct trad_frame_saved_reg
*saved_regs
;
1604 s390_prologue_frame_unwind_cache (struct frame_info
*this_frame
,
1605 struct s390_unwind_cache
*info
)
1607 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1608 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1609 struct s390_prologue_data data
;
1610 pv_t
*fp
= &data
.gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1611 pv_t
*sp
= &data
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1620 struct frame_info
*next_frame
;
1622 /* Try to find the function start address. If we can't find it, we don't
1623 bother searching for it -- with modern compilers this would be mostly
1624 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1625 or else a valid backchain ... */
1626 func
= get_frame_func (this_frame
);
1630 /* Try to analyze the prologue. */
1631 result
= s390_analyze_prologue (gdbarch
, func
,
1632 get_frame_pc (this_frame
), &data
);
1636 /* If this was successful, we should have found the instruction that
1637 sets the stack pointer register to the previous value of the stack
1638 pointer minus the frame size. */
1639 if (!pv_is_register (*sp
, S390_SP_REGNUM
))
1642 /* A frame size of zero at this point can mean either a real
1643 frameless function, or else a failure to find the prologue.
1644 Perform some sanity checks to verify we really have a
1645 frameless function. */
1648 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1649 size zero. This is only possible if the next frame is a sentinel
1650 frame, a dummy frame, or a signal trampoline frame. */
1651 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1652 needed, instead the code should simpliy rely on its
1654 next_frame
= get_next_frame (this_frame
);
1655 while (next_frame
&& get_frame_type (next_frame
) == INLINE_FRAME
)
1656 next_frame
= get_next_frame (next_frame
);
1658 && get_frame_type (get_next_frame (this_frame
)) == NORMAL_FRAME
)
1661 /* If we really have a frameless function, %r14 must be valid
1662 -- in particular, it must point to a different function. */
1663 reg
= get_frame_register_unsigned (this_frame
, S390_RETADDR_REGNUM
);
1664 reg
= gdbarch_addr_bits_remove (gdbarch
, reg
) - 1;
1665 if (get_pc_function_start (reg
) == func
)
1667 /* However, there is one case where it *is* valid for %r14
1668 to point to the same function -- if this is a recursive
1669 call, and we have stopped in the prologue *before* the
1670 stack frame was allocated.
1672 Recognize this case by looking ahead a bit ... */
1674 struct s390_prologue_data data2
;
1675 pv_t
*sp
= &data2
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1677 if (!(s390_analyze_prologue (gdbarch
, func
, (CORE_ADDR
)-1, &data2
)
1678 && pv_is_register (*sp
, S390_SP_REGNUM
)
1685 /* OK, we've found valid prologue data. */
1688 /* If the frame pointer originally also holds the same value
1689 as the stack pointer, we're probably using it. If it holds
1690 some other value -- even a constant offset -- it is most
1691 likely used as temp register. */
1692 if (pv_is_identical (*sp
, *fp
))
1693 frame_pointer
= S390_FRAME_REGNUM
;
1695 frame_pointer
= S390_SP_REGNUM
;
1697 /* If we've detected a function with stack frame, we'll still have to
1698 treat it as frameless if we're currently within the function epilog
1699 code at a point where the frame pointer has already been restored.
1700 This can only happen in an innermost frame. */
1701 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1702 instead the code should simpliy rely on its analysis. */
1703 next_frame
= get_next_frame (this_frame
);
1704 while (next_frame
&& get_frame_type (next_frame
) == INLINE_FRAME
)
1705 next_frame
= get_next_frame (next_frame
);
1707 && (next_frame
== NULL
1708 || get_frame_type (get_next_frame (this_frame
)) != NORMAL_FRAME
))
1710 /* See the comment in s390_in_function_epilogue_p on why this is
1711 not completely reliable ... */
1712 if (s390_in_function_epilogue_p (gdbarch
, get_frame_pc (this_frame
)))
1714 memset (&data
, 0, sizeof (data
));
1716 frame_pointer
= S390_SP_REGNUM
;
1720 /* Once we know the frame register and the frame size, we can unwind
1721 the current value of the frame register from the next frame, and
1722 add back the frame size to arrive that the previous frame's
1723 stack pointer value. */
1724 prev_sp
= get_frame_register_unsigned (this_frame
, frame_pointer
) + size
;
1725 cfa
= prev_sp
+ 16*word_size
+ 32;
1727 /* Set up ABI call-saved/call-clobbered registers. */
1728 for (i
= 0; i
< S390_NUM_REGS
; i
++)
1729 if (!s390_register_call_saved (gdbarch
, i
))
1730 trad_frame_set_unknown (info
->saved_regs
, i
);
1732 /* CC is always call-clobbered. */
1733 trad_frame_set_unknown (info
->saved_regs
, S390_PSWM_REGNUM
);
1735 /* Record the addresses of all register spill slots the prologue parser
1736 has recognized. Consider only registers defined as call-saved by the
1737 ABI; for call-clobbered registers the parser may have recognized
1740 for (i
= 0; i
< 16; i
++)
1741 if (s390_register_call_saved (gdbarch
, S390_R0_REGNUM
+ i
)
1742 && data
.gpr_slot
[i
] != 0)
1743 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= cfa
- data
.gpr_slot
[i
];
1745 for (i
= 0; i
< 16; i
++)
1746 if (s390_register_call_saved (gdbarch
, S390_F0_REGNUM
+ i
)
1747 && data
.fpr_slot
[i
] != 0)
1748 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= cfa
- data
.fpr_slot
[i
];
1750 /* Function return will set PC to %r14. */
1751 info
->saved_regs
[S390_PSWA_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1753 /* In frameless functions, we unwind simply by moving the return
1754 address to the PC. However, if we actually stored to the
1755 save area, use that -- we might only think the function frameless
1756 because we're in the middle of the prologue ... */
1758 && !trad_frame_addr_p (info
->saved_regs
, S390_PSWA_REGNUM
))
1760 info
->saved_regs
[S390_PSWA_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1763 /* Another sanity check: unless this is a frameless function,
1764 we should have found spill slots for SP and PC.
1765 If not, we cannot unwind further -- this happens e.g. in
1766 libc's thread_start routine. */
1769 if (!trad_frame_addr_p (info
->saved_regs
, S390_SP_REGNUM
)
1770 || !trad_frame_addr_p (info
->saved_regs
, S390_PSWA_REGNUM
))
1774 /* We use the current value of the frame register as local_base,
1775 and the top of the register save area as frame_base. */
1778 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1779 info
->local_base
= prev_sp
- size
;
1787 s390_backchain_frame_unwind_cache (struct frame_info
*this_frame
,
1788 struct s390_unwind_cache
*info
)
1790 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1791 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1792 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1793 CORE_ADDR backchain
;
1798 /* Set up ABI call-saved/call-clobbered registers. */
1799 for (i
= 0; i
< S390_NUM_REGS
; i
++)
1800 if (!s390_register_call_saved (gdbarch
, i
))
1801 trad_frame_set_unknown (info
->saved_regs
, i
);
1803 /* CC is always call-clobbered. */
1804 trad_frame_set_unknown (info
->saved_regs
, S390_PSWM_REGNUM
);
1806 /* Get the backchain. */
1807 reg
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
1808 backchain
= read_memory_unsigned_integer (reg
, word_size
, byte_order
);
1810 /* A zero backchain terminates the frame chain. As additional
1811 sanity check, let's verify that the spill slot for SP in the
1812 save area pointed to by the backchain in fact links back to
1815 && safe_read_memory_integer (backchain
+ 15*word_size
,
1816 word_size
, byte_order
, &sp
)
1817 && (CORE_ADDR
)sp
== backchain
)
1819 /* We don't know which registers were saved, but it will have
1820 to be at least %r14 and %r15. This will allow us to continue
1821 unwinding, but other prev-frame registers may be incorrect ... */
1822 info
->saved_regs
[S390_SP_REGNUM
].addr
= backchain
+ 15*word_size
;
1823 info
->saved_regs
[S390_RETADDR_REGNUM
].addr
= backchain
+ 14*word_size
;
1825 /* Function return will set PC to %r14. */
1826 info
->saved_regs
[S390_PSWA_REGNUM
]
1827 = info
->saved_regs
[S390_RETADDR_REGNUM
];
1829 /* We use the current value of the frame register as local_base,
1830 and the top of the register save area as frame_base. */
1831 info
->frame_base
= backchain
+ 16*word_size
+ 32;
1832 info
->local_base
= reg
;
1835 info
->func
= get_frame_pc (this_frame
);
1838 static struct s390_unwind_cache
*
1839 s390_frame_unwind_cache (struct frame_info
*this_frame
,
1840 void **this_prologue_cache
)
1842 volatile struct gdb_exception ex
;
1843 struct s390_unwind_cache
*info
;
1845 if (*this_prologue_cache
)
1846 return *this_prologue_cache
;
1848 info
= FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache
);
1849 *this_prologue_cache
= info
;
1850 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1852 info
->frame_base
= -1;
1853 info
->local_base
= -1;
1855 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1857 /* Try to use prologue analysis to fill the unwind cache.
1858 If this fails, fall back to reading the stack backchain. */
1859 if (!s390_prologue_frame_unwind_cache (this_frame
, info
))
1860 s390_backchain_frame_unwind_cache (this_frame
, info
);
1862 if (ex
.reason
< 0 && ex
.error
!= NOT_AVAILABLE_ERROR
)
1863 throw_exception (ex
);
1869 s390_frame_this_id (struct frame_info
*this_frame
,
1870 void **this_prologue_cache
,
1871 struct frame_id
*this_id
)
1873 struct s390_unwind_cache
*info
1874 = s390_frame_unwind_cache (this_frame
, this_prologue_cache
);
1876 if (info
->frame_base
== -1)
1879 *this_id
= frame_id_build (info
->frame_base
, info
->func
);
1882 static struct value
*
1883 s390_frame_prev_register (struct frame_info
*this_frame
,
1884 void **this_prologue_cache
, int regnum
)
1886 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1887 struct s390_unwind_cache
*info
1888 = s390_frame_unwind_cache (this_frame
, this_prologue_cache
);
1890 return s390_trad_frame_prev_register (this_frame
, info
->saved_regs
, regnum
);
1893 static const struct frame_unwind s390_frame_unwind
= {
1895 default_frame_unwind_stop_reason
,
1897 s390_frame_prev_register
,
1899 default_frame_sniffer
1903 /* Code stubs and their stack frames. For things like PLTs and NULL
1904 function calls (where there is no true frame and the return address
1905 is in the RETADDR register). */
1907 struct s390_stub_unwind_cache
1909 CORE_ADDR frame_base
;
1910 struct trad_frame_saved_reg
*saved_regs
;
1913 static struct s390_stub_unwind_cache
*
1914 s390_stub_frame_unwind_cache (struct frame_info
*this_frame
,
1915 void **this_prologue_cache
)
1917 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1918 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1919 struct s390_stub_unwind_cache
*info
;
1922 if (*this_prologue_cache
)
1923 return *this_prologue_cache
;
1925 info
= FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache
);
1926 *this_prologue_cache
= info
;
1927 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1929 /* The return address is in register %r14. */
1930 info
->saved_regs
[S390_PSWA_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1932 /* Retrieve stack pointer and determine our frame base. */
1933 reg
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
1934 info
->frame_base
= reg
+ 16*word_size
+ 32;
1940 s390_stub_frame_this_id (struct frame_info
*this_frame
,
1941 void **this_prologue_cache
,
1942 struct frame_id
*this_id
)
1944 struct s390_stub_unwind_cache
*info
1945 = s390_stub_frame_unwind_cache (this_frame
, this_prologue_cache
);
1946 *this_id
= frame_id_build (info
->frame_base
, get_frame_pc (this_frame
));
1949 static struct value
*
1950 s390_stub_frame_prev_register (struct frame_info
*this_frame
,
1951 void **this_prologue_cache
, int regnum
)
1953 struct s390_stub_unwind_cache
*info
1954 = s390_stub_frame_unwind_cache (this_frame
, this_prologue_cache
);
1955 return s390_trad_frame_prev_register (this_frame
, info
->saved_regs
, regnum
);
1959 s390_stub_frame_sniffer (const struct frame_unwind
*self
,
1960 struct frame_info
*this_frame
,
1961 void **this_prologue_cache
)
1963 CORE_ADDR addr_in_block
;
1964 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
1966 /* If the current PC points to non-readable memory, we assume we
1967 have trapped due to an invalid function pointer call. We handle
1968 the non-existing current function like a PLT stub. */
1969 addr_in_block
= get_frame_address_in_block (this_frame
);
1970 if (in_plt_section (addr_in_block
)
1971 || s390_readinstruction (insn
, get_frame_pc (this_frame
)) < 0)
1976 static const struct frame_unwind s390_stub_frame_unwind
= {
1978 default_frame_unwind_stop_reason
,
1979 s390_stub_frame_this_id
,
1980 s390_stub_frame_prev_register
,
1982 s390_stub_frame_sniffer
1986 /* Signal trampoline stack frames. */
1988 struct s390_sigtramp_unwind_cache
{
1989 CORE_ADDR frame_base
;
1990 struct trad_frame_saved_reg
*saved_regs
;
1993 static struct s390_sigtramp_unwind_cache
*
1994 s390_sigtramp_frame_unwind_cache (struct frame_info
*this_frame
,
1995 void **this_prologue_cache
)
1997 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1998 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1999 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2000 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2001 struct s390_sigtramp_unwind_cache
*info
;
2002 ULONGEST this_sp
, prev_sp
;
2003 CORE_ADDR next_ra
, next_cfa
, sigreg_ptr
, sigreg_high_off
;
2006 if (*this_prologue_cache
)
2007 return *this_prologue_cache
;
2009 info
= FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache
);
2010 *this_prologue_cache
= info
;
2011 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2013 this_sp
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
2014 next_ra
= get_frame_pc (this_frame
);
2015 next_cfa
= this_sp
+ 16*word_size
+ 32;
2017 /* New-style RT frame:
2018 retcode + alignment (8 bytes)
2020 ucontext (contains sigregs at offset 5 words). */
2021 if (next_ra
== next_cfa
)
2023 sigreg_ptr
= next_cfa
+ 8 + 128 + align_up (5*word_size
, 8);
2024 /* sigregs are followed by uc_sigmask (8 bytes), then by the
2025 upper GPR halves if present. */
2026 sigreg_high_off
= 8;
2029 /* Old-style RT frame and all non-RT frames:
2030 old signal mask (8 bytes)
2031 pointer to sigregs. */
2034 sigreg_ptr
= read_memory_unsigned_integer (next_cfa
+ 8,
2035 word_size
, byte_order
);
2036 /* sigregs are followed by signo (4 bytes), then by the
2037 upper GPR halves if present. */
2038 sigreg_high_off
= 4;
2041 /* The sigregs structure looks like this:
2050 /* PSW mask and address. */
2051 info
->saved_regs
[S390_PSWM_REGNUM
].addr
= sigreg_ptr
;
2052 sigreg_ptr
+= word_size
;
2053 info
->saved_regs
[S390_PSWA_REGNUM
].addr
= sigreg_ptr
;
2054 sigreg_ptr
+= word_size
;
2056 /* Then the GPRs. */
2057 for (i
= 0; i
< 16; i
++)
2059 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= sigreg_ptr
;
2060 sigreg_ptr
+= word_size
;
2063 /* Then the ACRs. */
2064 for (i
= 0; i
< 16; i
++)
2066 info
->saved_regs
[S390_A0_REGNUM
+ i
].addr
= sigreg_ptr
;
2070 /* The floating-point control word. */
2071 info
->saved_regs
[S390_FPC_REGNUM
].addr
= sigreg_ptr
;
2074 /* And finally the FPRs. */
2075 for (i
= 0; i
< 16; i
++)
2077 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= sigreg_ptr
;
2081 /* If we have them, the GPR upper halves are appended at the end. */
2082 sigreg_ptr
+= sigreg_high_off
;
2083 if (tdep
->gpr_full_regnum
!= -1)
2084 for (i
= 0; i
< 16; i
++)
2086 info
->saved_regs
[S390_R0_UPPER_REGNUM
+ i
].addr
= sigreg_ptr
;
2090 /* Restore the previous frame's SP. */
2091 prev_sp
= read_memory_unsigned_integer (
2092 info
->saved_regs
[S390_SP_REGNUM
].addr
,
2093 word_size
, byte_order
);
2095 /* Determine our frame base. */
2096 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
2102 s390_sigtramp_frame_this_id (struct frame_info
*this_frame
,
2103 void **this_prologue_cache
,
2104 struct frame_id
*this_id
)
2106 struct s390_sigtramp_unwind_cache
*info
2107 = s390_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
2108 *this_id
= frame_id_build (info
->frame_base
, get_frame_pc (this_frame
));
2111 static struct value
*
2112 s390_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
2113 void **this_prologue_cache
, int regnum
)
2115 struct s390_sigtramp_unwind_cache
*info
2116 = s390_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
2117 return s390_trad_frame_prev_register (this_frame
, info
->saved_regs
, regnum
);
2121 s390_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
2122 struct frame_info
*this_frame
,
2123 void **this_prologue_cache
)
2125 CORE_ADDR pc
= get_frame_pc (this_frame
);
2126 bfd_byte sigreturn
[2];
2128 if (target_read_memory (pc
, sigreturn
, 2))
2131 if (sigreturn
[0] != op_svc
)
2134 if (sigreturn
[1] != 119 /* sigreturn */
2135 && sigreturn
[1] != 173 /* rt_sigreturn */)
2141 static const struct frame_unwind s390_sigtramp_frame_unwind
= {
2143 default_frame_unwind_stop_reason
,
2144 s390_sigtramp_frame_this_id
,
2145 s390_sigtramp_frame_prev_register
,
2147 s390_sigtramp_frame_sniffer
2150 /* Retrieve the syscall number at a ptrace syscall-stop. Return -1
2154 s390_linux_get_syscall_number (struct gdbarch
*gdbarch
,
2157 struct regcache
*regs
= get_thread_regcache (ptid
);
2158 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2159 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2161 ULONGEST svc_number
= -1;
2164 /* Assume that the PC points after the 2-byte SVC instruction. We
2165 don't currently support SVC via EXECUTE. */
2166 regcache_cooked_read_unsigned (regs
, tdep
->pc_regnum
, &pc
);
2168 opcode
= read_memory_unsigned_integer ((CORE_ADDR
) pc
, 1, byte_order
);
2169 if (opcode
!= op_svc
)
2172 svc_number
= read_memory_unsigned_integer ((CORE_ADDR
) pc
+ 1, 1,
2174 if (svc_number
== 0)
2175 regcache_cooked_read_unsigned (regs
, S390_R1_REGNUM
, &svc_number
);
2181 /* Frame base handling. */
2184 s390_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
2186 struct s390_unwind_cache
*info
2187 = s390_frame_unwind_cache (this_frame
, this_cache
);
2188 return info
->frame_base
;
2192 s390_local_base_address (struct frame_info
*this_frame
, void **this_cache
)
2194 struct s390_unwind_cache
*info
2195 = s390_frame_unwind_cache (this_frame
, this_cache
);
2196 return info
->local_base
;
2199 static const struct frame_base s390_frame_base
= {
2201 s390_frame_base_address
,
2202 s390_local_base_address
,
2203 s390_local_base_address
2207 s390_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2209 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2211 pc
= frame_unwind_register_unsigned (next_frame
, tdep
->pc_regnum
);
2212 return gdbarch_addr_bits_remove (gdbarch
, pc
);
2216 s390_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2219 sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
2220 return gdbarch_addr_bits_remove (gdbarch
, sp
);
2224 /* DWARF-2 frame support. */
2226 static struct value
*
2227 s390_dwarf2_prev_register (struct frame_info
*this_frame
, void **this_cache
,
2230 return s390_unwind_pseudo_register (this_frame
, regnum
);
2234 s390_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
2235 struct dwarf2_frame_state_reg
*reg
,
2236 struct frame_info
*this_frame
)
2238 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2240 /* The condition code (and thus PSW mask) is call-clobbered. */
2241 if (regnum
== S390_PSWM_REGNUM
)
2242 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
2244 /* The PSW address unwinds to the return address. */
2245 else if (regnum
== S390_PSWA_REGNUM
)
2246 reg
->how
= DWARF2_FRAME_REG_RA
;
2248 /* Fixed registers are call-saved or call-clobbered
2249 depending on the ABI in use. */
2250 else if (regnum
< S390_NUM_REGS
)
2252 if (s390_register_call_saved (gdbarch
, regnum
))
2253 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
2255 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
2258 /* We install a special function to unwind pseudos. */
2261 reg
->how
= DWARF2_FRAME_REG_FN
;
2262 reg
->loc
.fn
= s390_dwarf2_prev_register
;
2267 /* Dummy function calls. */
2269 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
2270 "Integer-like" types are those that should be passed the way
2271 integers are: integers, enums, ranges, characters, and booleans. */
2273 is_integer_like (struct type
*type
)
2275 enum type_code code
= TYPE_CODE (type
);
2277 return (code
== TYPE_CODE_INT
2278 || code
== TYPE_CODE_ENUM
2279 || code
== TYPE_CODE_RANGE
2280 || code
== TYPE_CODE_CHAR
2281 || code
== TYPE_CODE_BOOL
);
2284 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
2285 "Pointer-like" types are those that should be passed the way
2286 pointers are: pointers and references. */
2288 is_pointer_like (struct type
*type
)
2290 enum type_code code
= TYPE_CODE (type
);
2292 return (code
== TYPE_CODE_PTR
2293 || code
== TYPE_CODE_REF
);
2297 /* Return non-zero if TYPE is a `float singleton' or `double
2298 singleton', zero otherwise.
2300 A `T singleton' is a struct type with one member, whose type is
2301 either T or a `T singleton'. So, the following are all float
2305 struct { struct { float x; } x; };
2306 struct { struct { struct { float x; } x; } x; };
2310 All such structures are passed as if they were floats or doubles,
2311 as the (revised) ABI says. */
2313 is_float_singleton (struct type
*type
)
2315 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type
) == 1)
2317 struct type
*singleton_type
= TYPE_FIELD_TYPE (type
, 0);
2318 CHECK_TYPEDEF (singleton_type
);
2320 return (TYPE_CODE (singleton_type
) == TYPE_CODE_FLT
2321 || TYPE_CODE (singleton_type
) == TYPE_CODE_DECFLOAT
2322 || is_float_singleton (singleton_type
));
2329 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
2330 "Struct-like" types are those that should be passed as structs are:
2333 As an odd quirk, not mentioned in the ABI, GCC passes float and
2334 double singletons as if they were a plain float, double, etc. (The
2335 corresponding union types are handled normally.) So we exclude
2336 those types here. *shrug* */
2338 is_struct_like (struct type
*type
)
2340 enum type_code code
= TYPE_CODE (type
);
2342 return (code
== TYPE_CODE_UNION
2343 || (code
== TYPE_CODE_STRUCT
&& ! is_float_singleton (type
)));
2347 /* Return non-zero if TYPE is a float-like type, zero otherwise.
2348 "Float-like" types are those that should be passed as
2349 floating-point values are.
2351 You'd think this would just be floats, doubles, long doubles, etc.
2352 But as an odd quirk, not mentioned in the ABI, GCC passes float and
2353 double singletons as if they were a plain float, double, etc. (The
2354 corresponding union types are handled normally.) So we include
2355 those types here. *shrug* */
2357 is_float_like (struct type
*type
)
2359 return (TYPE_CODE (type
) == TYPE_CODE_FLT
2360 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
2361 || is_float_singleton (type
));
2366 is_power_of_two (unsigned int n
)
2368 return ((n
& (n
- 1)) == 0);
2371 /* Return non-zero if TYPE should be passed as a pointer to a copy,
2374 s390_function_arg_pass_by_reference (struct type
*type
)
2376 if (TYPE_LENGTH (type
) > 8)
2379 return (is_struct_like (type
) && !is_power_of_two (TYPE_LENGTH (type
)))
2380 || TYPE_CODE (type
) == TYPE_CODE_COMPLEX
2381 || (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
));
2384 /* Return non-zero if TYPE should be passed in a float register
2387 s390_function_arg_float (struct type
*type
)
2389 if (TYPE_LENGTH (type
) > 8)
2392 return is_float_like (type
);
2395 /* Return non-zero if TYPE should be passed in an integer register
2396 (or a pair of integer registers) if possible. */
2398 s390_function_arg_integer (struct type
*type
)
2400 if (TYPE_LENGTH (type
) > 8)
2403 return is_integer_like (type
)
2404 || is_pointer_like (type
)
2405 || (is_struct_like (type
) && is_power_of_two (TYPE_LENGTH (type
)));
2408 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
2409 word as required for the ABI. */
2411 extend_simple_arg (struct gdbarch
*gdbarch
, struct value
*arg
)
2413 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2414 struct type
*type
= check_typedef (value_type (arg
));
2416 /* Even structs get passed in the least significant bits of the
2417 register / memory word. It's not really right to extract them as
2418 an integer, but it does take care of the extension. */
2419 if (TYPE_UNSIGNED (type
))
2420 return extract_unsigned_integer (value_contents (arg
),
2421 TYPE_LENGTH (type
), byte_order
);
2423 return extract_signed_integer (value_contents (arg
),
2424 TYPE_LENGTH (type
), byte_order
);
2428 /* Return the alignment required by TYPE. */
2430 alignment_of (struct type
*type
)
2434 if (is_integer_like (type
)
2435 || is_pointer_like (type
)
2436 || TYPE_CODE (type
) == TYPE_CODE_FLT
2437 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
2438 alignment
= TYPE_LENGTH (type
);
2439 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
2440 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
2445 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
2448 = alignment_of (check_typedef (TYPE_FIELD_TYPE (type
, i
)));
2450 if (field_alignment
> alignment
)
2451 alignment
= field_alignment
;
2457 /* Check that everything we ever return is a power of two. Lots of
2458 code doesn't want to deal with aligning things to arbitrary
2460 gdb_assert ((alignment
& (alignment
- 1)) == 0);
2466 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2467 place to be passed to a function, as specified by the "GNU/Linux
2468 for S/390 ELF Application Binary Interface Supplement".
2470 SP is the current stack pointer. We must put arguments, links,
2471 padding, etc. whereever they belong, and return the new stack
2474 If STRUCT_RETURN is non-zero, then the function we're calling is
2475 going to return a structure by value; STRUCT_ADDR is the address of
2476 a block we've allocated for it on the stack.
2478 Our caller has taken care of any type promotions needed to satisfy
2479 prototypes or the old K&R argument-passing rules. */
2481 s390_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2482 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2483 int nargs
, struct value
**args
, CORE_ADDR sp
,
2484 int struct_return
, CORE_ADDR struct_addr
)
2486 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2487 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2488 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2491 /* If the i'th argument is passed as a reference to a copy, then
2492 copy_addr[i] is the address of the copy we made. */
2493 CORE_ADDR
*copy_addr
= alloca (nargs
* sizeof (CORE_ADDR
));
2495 /* Reserve space for the reference-to-copy area. */
2496 for (i
= 0; i
< nargs
; i
++)
2498 struct value
*arg
= args
[i
];
2499 struct type
*type
= check_typedef (value_type (arg
));
2501 if (s390_function_arg_pass_by_reference (type
))
2503 sp
-= TYPE_LENGTH (type
);
2504 sp
= align_down (sp
, alignment_of (type
));
2509 /* Reserve space for the parameter area. As a conservative
2510 simplification, we assume that everything will be passed on the
2511 stack. Since every argument larger than 8 bytes will be
2512 passed by reference, we use this simple upper bound. */
2515 /* After all that, make sure it's still aligned on an eight-byte
2517 sp
= align_down (sp
, 8);
2519 /* Allocate the standard frame areas: the register save area, the
2520 word reserved for the compiler (which seems kind of meaningless),
2521 and the back chain pointer. */
2522 sp
-= 16*word_size
+ 32;
2524 /* Now we have the final SP value. Make sure we didn't underflow;
2525 on 31-bit, this would result in addresses with the high bit set,
2526 which causes confusion elsewhere. Note that if we error out
2527 here, stack and registers remain untouched. */
2528 if (gdbarch_addr_bits_remove (gdbarch
, sp
) != sp
)
2529 error (_("Stack overflow"));
2532 /* Finally, place the actual parameters, working from SP towards
2533 higher addresses. The code above is supposed to reserve enough
2538 CORE_ADDR starg
= sp
+ 16*word_size
+ 32;
2540 /* A struct is returned using general register 2. */
2543 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2548 for (i
= 0; i
< nargs
; i
++)
2550 struct value
*arg
= args
[i
];
2551 struct type
*type
= check_typedef (value_type (arg
));
2552 unsigned length
= TYPE_LENGTH (type
);
2554 if (s390_function_arg_pass_by_reference (type
))
2556 /* Actually copy the argument contents to the stack slot
2557 that was reserved above. */
2558 write_memory (copy_addr
[i
], value_contents (arg
), length
);
2562 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2568 write_memory_unsigned_integer (starg
, word_size
, byte_order
,
2573 else if (s390_function_arg_float (type
))
2575 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2576 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2577 if (fr
<= (tdep
->abi
== ABI_LINUX_S390
? 2 : 6))
2579 /* When we store a single-precision value in an FP register,
2580 it occupies the leftmost bits. */
2581 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
+ fr
,
2582 0, length
, value_contents (arg
));
2587 /* When we store a single-precision value in a stack slot,
2588 it occupies the rightmost bits. */
2589 starg
= align_up (starg
+ length
, word_size
);
2590 write_memory (starg
- length
, value_contents (arg
), length
);
2593 else if (s390_function_arg_integer (type
) && length
<= word_size
)
2597 /* Integer arguments are always extended to word size. */
2598 regcache_cooked_write_signed (regcache
, S390_R0_REGNUM
+ gr
,
2599 extend_simple_arg (gdbarch
,
2605 /* Integer arguments are always extended to word size. */
2606 write_memory_signed_integer (starg
, word_size
, byte_order
,
2607 extend_simple_arg (gdbarch
, arg
));
2611 else if (s390_function_arg_integer (type
) && length
== 2*word_size
)
2615 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
,
2616 value_contents (arg
));
2617 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
+ 1,
2618 value_contents (arg
) + word_size
);
2623 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2624 in it, then don't go back and use it again later. */
2627 write_memory (starg
, value_contents (arg
), length
);
2632 internal_error (__FILE__
, __LINE__
, _("unknown argument type"));
2636 /* Store return PSWA. In 31-bit mode, keep addressing mode bit. */
2640 regcache_cooked_read_unsigned (regcache
, S390_PSWA_REGNUM
, &pswa
);
2641 bp_addr
= (bp_addr
& 0x7fffffff) | (pswa
& 0x80000000);
2643 regcache_cooked_write_unsigned (regcache
, S390_RETADDR_REGNUM
, bp_addr
);
2645 /* Store updated stack pointer. */
2646 regcache_cooked_write_unsigned (regcache
, S390_SP_REGNUM
, sp
);
2648 /* We need to return the 'stack part' of the frame ID,
2649 which is actually the top of the register save area. */
2650 return sp
+ 16*word_size
+ 32;
2653 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
2654 dummy frame. The frame ID's base needs to match the TOS value
2655 returned by push_dummy_call, and the PC match the dummy frame's
2657 static struct frame_id
2658 s390_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
2660 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2661 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
2662 sp
= gdbarch_addr_bits_remove (gdbarch
, sp
);
2664 return frame_id_build (sp
+ 16*word_size
+ 32,
2665 get_frame_pc (this_frame
));
2669 s390_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2671 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2672 always be aligned on an eight-byte boundary. */
2677 /* Function return value access. */
2679 static enum return_value_convention
2680 s390_return_value_convention (struct gdbarch
*gdbarch
, struct type
*type
)
2682 if (TYPE_LENGTH (type
) > 8)
2683 return RETURN_VALUE_STRUCT_CONVENTION
;
2685 switch (TYPE_CODE (type
))
2687 case TYPE_CODE_STRUCT
:
2688 case TYPE_CODE_UNION
:
2689 case TYPE_CODE_ARRAY
:
2690 case TYPE_CODE_COMPLEX
:
2691 return RETURN_VALUE_STRUCT_CONVENTION
;
2694 return RETURN_VALUE_REGISTER_CONVENTION
;
2698 static enum return_value_convention
2699 s390_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
2700 struct type
*type
, struct regcache
*regcache
,
2701 gdb_byte
*out
, const gdb_byte
*in
)
2703 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2704 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2705 enum return_value_convention rvc
;
2708 type
= check_typedef (type
);
2709 rvc
= s390_return_value_convention (gdbarch
, type
);
2710 length
= TYPE_LENGTH (type
);
2716 case RETURN_VALUE_REGISTER_CONVENTION
:
2717 if (TYPE_CODE (type
) == TYPE_CODE_FLT
2718 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
2720 /* When we store a single-precision value in an FP register,
2721 it occupies the leftmost bits. */
2722 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
,
2725 else if (length
<= word_size
)
2727 /* Integer arguments are always extended to word size. */
2728 if (TYPE_UNSIGNED (type
))
2729 regcache_cooked_write_unsigned (regcache
, S390_R2_REGNUM
,
2730 extract_unsigned_integer (in
, length
, byte_order
));
2732 regcache_cooked_write_signed (regcache
, S390_R2_REGNUM
,
2733 extract_signed_integer (in
, length
, byte_order
));
2735 else if (length
== 2*word_size
)
2737 regcache_cooked_write (regcache
, S390_R2_REGNUM
, in
);
2738 regcache_cooked_write (regcache
, S390_R3_REGNUM
, in
+ word_size
);
2741 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2744 case RETURN_VALUE_STRUCT_CONVENTION
:
2745 error (_("Cannot set function return value."));
2753 case RETURN_VALUE_REGISTER_CONVENTION
:
2754 if (TYPE_CODE (type
) == TYPE_CODE_FLT
2755 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
2757 /* When we store a single-precision value in an FP register,
2758 it occupies the leftmost bits. */
2759 regcache_cooked_read_part (regcache
, S390_F0_REGNUM
,
2762 else if (length
<= word_size
)
2764 /* Integer arguments occupy the rightmost bits. */
2765 regcache_cooked_read_part (regcache
, S390_R2_REGNUM
,
2766 word_size
- length
, length
, out
);
2768 else if (length
== 2*word_size
)
2770 regcache_cooked_read (regcache
, S390_R2_REGNUM
, out
);
2771 regcache_cooked_read (regcache
, S390_R3_REGNUM
, out
+ word_size
);
2774 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2777 case RETURN_VALUE_STRUCT_CONVENTION
:
2778 error (_("Function return value unknown."));
2789 static const gdb_byte
*
2790 s390_breakpoint_from_pc (struct gdbarch
*gdbarch
,
2791 CORE_ADDR
*pcptr
, int *lenptr
)
2793 static const gdb_byte breakpoint
[] = { 0x0, 0x1 };
2795 *lenptr
= sizeof (breakpoint
);
2800 /* Address handling. */
2803 s390_addr_bits_remove (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2805 return addr
& 0x7fffffff;
2809 s390_address_class_type_flags (int byte_size
, int dwarf2_addr_class
)
2812 return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
;
2818 s390_address_class_type_flags_to_name (struct gdbarch
*gdbarch
, int type_flags
)
2820 if (type_flags
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
)
2827 s390_address_class_name_to_type_flags (struct gdbarch
*gdbarch
,
2829 int *type_flags_ptr
)
2831 if (strcmp (name
, "mode32") == 0)
2833 *type_flags_ptr
= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
;
2840 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
2844 s390_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
2846 return ((isdigit (*s
) && s
[1] == '(' && s
[2] == '%') /* Displacement
2848 || *s
== '%' /* Register access. */
2849 || isdigit (*s
)); /* Literal number. */
2852 /* Set up gdbarch struct. */
2854 static struct gdbarch
*
2855 s390_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2857 const struct target_desc
*tdesc
= info
.target_desc
;
2858 struct tdesc_arch_data
*tdesc_data
= NULL
;
2859 struct gdbarch
*gdbarch
;
2860 struct gdbarch_tdep
*tdep
;
2863 int have_linux_v1
= 0;
2864 int have_linux_v2
= 0;
2866 int first_pseudo_reg
, last_pseudo_reg
;
2867 static const char *const stap_register_prefixes
[] = { "%", NULL
};
2868 static const char *const stap_register_indirection_prefixes
[] = { "(",
2870 static const char *const stap_register_indirection_suffixes
[] = { ")",
2873 /* Default ABI and register size. */
2874 switch (info
.bfd_arch_info
->mach
)
2876 case bfd_mach_s390_31
:
2877 tdep_abi
= ABI_LINUX_S390
;
2880 case bfd_mach_s390_64
:
2881 tdep_abi
= ABI_LINUX_ZSERIES
;
2888 /* Use default target description if none provided by the target. */
2889 if (!tdesc_has_registers (tdesc
))
2891 if (tdep_abi
== ABI_LINUX_S390
)
2892 tdesc
= tdesc_s390_linux32
;
2894 tdesc
= tdesc_s390x_linux64
;
2897 /* Check any target description for validity. */
2898 if (tdesc_has_registers (tdesc
))
2900 static const char *const gprs
[] = {
2901 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2902 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2904 static const char *const fprs
[] = {
2905 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
2906 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
2908 static const char *const acrs
[] = {
2909 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
2910 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15"
2912 static const char *const gprs_lower
[] = {
2913 "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l",
2914 "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l"
2916 static const char *const gprs_upper
[] = {
2917 "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
2918 "r8h", "r9h", "r10h", "r11h", "r12h", "r13h", "r14h", "r15h"
2920 static const char *const tdb_regs
[] = {
2921 "tdb0", "tac", "tct", "atia",
2922 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7",
2923 "tr8", "tr9", "tr10", "tr11", "tr12", "tr13", "tr14", "tr15"
2925 const struct tdesc_feature
*feature
;
2928 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.core");
2929 if (feature
== NULL
)
2932 tdesc_data
= tdesc_data_alloc ();
2934 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2935 S390_PSWM_REGNUM
, "pswm");
2936 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2937 S390_PSWA_REGNUM
, "pswa");
2939 if (tdesc_unnumbered_register (feature
, "r0"))
2941 for (i
= 0; i
< 16; i
++)
2942 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2943 S390_R0_REGNUM
+ i
, gprs
[i
]);
2949 for (i
= 0; i
< 16; i
++)
2950 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2953 for (i
= 0; i
< 16; i
++)
2954 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2955 S390_R0_UPPER_REGNUM
+ i
,
2959 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.fpr");
2960 if (feature
== NULL
)
2962 tdesc_data_cleanup (tdesc_data
);
2966 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2967 S390_FPC_REGNUM
, "fpc");
2968 for (i
= 0; i
< 16; i
++)
2969 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2970 S390_F0_REGNUM
+ i
, fprs
[i
]);
2972 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.acr");
2973 if (feature
== NULL
)
2975 tdesc_data_cleanup (tdesc_data
);
2979 for (i
= 0; i
< 16; i
++)
2980 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2981 S390_A0_REGNUM
+ i
, acrs
[i
]);
2983 /* Optional GNU/Linux-specific "registers". */
2984 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.linux");
2987 tdesc_numbered_register (feature
, tdesc_data
,
2988 S390_ORIG_R2_REGNUM
, "orig_r2");
2990 if (tdesc_numbered_register (feature
, tdesc_data
,
2991 S390_LAST_BREAK_REGNUM
, "last_break"))
2994 if (tdesc_numbered_register (feature
, tdesc_data
,
2995 S390_SYSTEM_CALL_REGNUM
, "system_call"))
2998 if (have_linux_v2
> have_linux_v1
)
3002 /* Transaction diagnostic block. */
3003 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.tdb");
3006 for (i
= 0; i
< ARRAY_SIZE (tdb_regs
); i
++)
3007 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
3008 S390_TDB_DWORD0_REGNUM
+ i
,
3015 tdesc_data_cleanup (tdesc_data
);
3020 /* Find a candidate among extant architectures. */
3021 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
3023 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
3025 tdep
= gdbarch_tdep (arches
->gdbarch
);
3028 if (tdep
->abi
!= tdep_abi
)
3030 if ((tdep
->gpr_full_regnum
!= -1) != have_upper
)
3032 if (tdesc_data
!= NULL
)
3033 tdesc_data_cleanup (tdesc_data
);
3034 return arches
->gdbarch
;
3037 /* Otherwise create a new gdbarch for the specified machine type. */
3038 tdep
= XCNEW (struct gdbarch_tdep
);
3039 tdep
->abi
= tdep_abi
;
3040 tdep
->have_linux_v1
= have_linux_v1
;
3041 tdep
->have_linux_v2
= have_linux_v2
;
3042 tdep
->have_tdb
= have_tdb
;
3043 gdbarch
= gdbarch_alloc (&info
, tdep
);
3045 set_gdbarch_believe_pcc_promotion (gdbarch
, 0);
3046 set_gdbarch_char_signed (gdbarch
, 0);
3048 /* S/390 GNU/Linux uses either 64-bit or 128-bit long doubles.
3049 We can safely let them default to 128-bit, since the debug info
3050 will give the size of type actually used in each case. */
3051 set_gdbarch_long_double_bit (gdbarch
, 128);
3052 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
3054 /* Amount PC must be decremented by after a breakpoint. This is
3055 often the number of bytes returned by gdbarch_breakpoint_from_pc but not
3057 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
3058 /* Stack grows downward. */
3059 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
3060 set_gdbarch_breakpoint_from_pc (gdbarch
, s390_breakpoint_from_pc
);
3061 set_gdbarch_skip_prologue (gdbarch
, s390_skip_prologue
);
3062 set_gdbarch_in_function_epilogue_p (gdbarch
, s390_in_function_epilogue_p
);
3064 set_gdbarch_num_regs (gdbarch
, S390_NUM_REGS
);
3065 set_gdbarch_sp_regnum (gdbarch
, S390_SP_REGNUM
);
3066 set_gdbarch_fp0_regnum (gdbarch
, S390_F0_REGNUM
);
3067 set_gdbarch_stab_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
3068 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
3069 set_gdbarch_value_from_register (gdbarch
, s390_value_from_register
);
3070 set_gdbarch_regset_from_core_section (gdbarch
,
3071 s390_regset_from_core_section
);
3072 set_gdbarch_core_read_description (gdbarch
, s390_core_read_description
);
3073 set_gdbarch_iterate_over_regset_sections (gdbarch
,
3074 s390_iterate_over_regset_sections
);
3075 set_gdbarch_cannot_store_register (gdbarch
, s390_cannot_store_register
);
3076 set_gdbarch_write_pc (gdbarch
, s390_write_pc
);
3077 set_gdbarch_pseudo_register_read (gdbarch
, s390_pseudo_register_read
);
3078 set_gdbarch_pseudo_register_write (gdbarch
, s390_pseudo_register_write
);
3079 set_tdesc_pseudo_register_name (gdbarch
, s390_pseudo_register_name
);
3080 set_tdesc_pseudo_register_type (gdbarch
, s390_pseudo_register_type
);
3081 set_tdesc_pseudo_register_reggroup_p (gdbarch
,
3082 s390_pseudo_register_reggroup_p
);
3083 tdesc_use_registers (gdbarch
, tdesc
, tdesc_data
);
3085 /* Assign pseudo register numbers. */
3086 first_pseudo_reg
= gdbarch_num_regs (gdbarch
);
3087 last_pseudo_reg
= first_pseudo_reg
;
3088 tdep
->gpr_full_regnum
= -1;
3091 tdep
->gpr_full_regnum
= last_pseudo_reg
;
3092 last_pseudo_reg
+= 16;
3094 tdep
->pc_regnum
= last_pseudo_reg
++;
3095 tdep
->cc_regnum
= last_pseudo_reg
++;
3096 set_gdbarch_pc_regnum (gdbarch
, tdep
->pc_regnum
);
3097 set_gdbarch_num_pseudo_regs (gdbarch
, last_pseudo_reg
- first_pseudo_reg
);
3099 /* Inferior function calls. */
3100 set_gdbarch_push_dummy_call (gdbarch
, s390_push_dummy_call
);
3101 set_gdbarch_dummy_id (gdbarch
, s390_dummy_id
);
3102 set_gdbarch_frame_align (gdbarch
, s390_frame_align
);
3103 set_gdbarch_return_value (gdbarch
, s390_return_value
);
3105 /* Syscall handling. */
3106 set_gdbarch_get_syscall_number (gdbarch
, s390_linux_get_syscall_number
);
3108 /* Frame handling. */
3109 dwarf2_frame_set_init_reg (gdbarch
, s390_dwarf2_frame_init_reg
);
3110 dwarf2_frame_set_adjust_regnum (gdbarch
, s390_adjust_frame_regnum
);
3111 dwarf2_append_unwinders (gdbarch
);
3112 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
3113 frame_unwind_append_unwinder (gdbarch
, &s390_stub_frame_unwind
);
3114 frame_unwind_append_unwinder (gdbarch
, &s390_sigtramp_frame_unwind
);
3115 frame_unwind_append_unwinder (gdbarch
, &s390_frame_unwind
);
3116 frame_base_set_default (gdbarch
, &s390_frame_base
);
3117 set_gdbarch_unwind_pc (gdbarch
, s390_unwind_pc
);
3118 set_gdbarch_unwind_sp (gdbarch
, s390_unwind_sp
);
3120 /* Displaced stepping. */
3121 set_gdbarch_displaced_step_copy_insn (gdbarch
,
3122 simple_displaced_step_copy_insn
);
3123 set_gdbarch_displaced_step_fixup (gdbarch
, s390_displaced_step_fixup
);
3124 set_gdbarch_displaced_step_free_closure (gdbarch
,
3125 simple_displaced_step_free_closure
);
3126 set_gdbarch_displaced_step_location (gdbarch
,
3127 displaced_step_at_entry_point
);
3128 set_gdbarch_max_insn_length (gdbarch
, S390_MAX_INSTR_SIZE
);
3130 /* Note that GNU/Linux is the only OS supported on this
3132 linux_init_abi (info
, gdbarch
);
3136 case ABI_LINUX_S390
:
3137 tdep
->gregset
= &s390_gregset
;
3138 tdep
->sizeof_gregset
= s390_sizeof_gregset
;
3139 tdep
->fpregset
= &s390_fpregset
;
3140 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
3142 set_gdbarch_addr_bits_remove (gdbarch
, s390_addr_bits_remove
);
3143 set_solib_svr4_fetch_link_map_offsets
3144 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
3146 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390
);
3149 case ABI_LINUX_ZSERIES
:
3150 tdep
->gregset
= &s390_gregset
;
3151 tdep
->sizeof_gregset
= s390x_sizeof_gregset
;
3152 tdep
->fpregset
= &s390_fpregset
;
3153 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
3155 set_gdbarch_long_bit (gdbarch
, 64);
3156 set_gdbarch_long_long_bit (gdbarch
, 64);
3157 set_gdbarch_ptr_bit (gdbarch
, 64);
3158 set_solib_svr4_fetch_link_map_offsets
3159 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
3160 set_gdbarch_address_class_type_flags (gdbarch
,
3161 s390_address_class_type_flags
);
3162 set_gdbarch_address_class_type_flags_to_name (gdbarch
,
3163 s390_address_class_type_flags_to_name
);
3164 set_gdbarch_address_class_name_to_type_flags (gdbarch
,
3165 s390_address_class_name_to_type_flags
);
3166 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390
);
3170 set_gdbarch_print_insn (gdbarch
, print_insn_s390
);
3172 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
3174 /* Enable TLS support. */
3175 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
3176 svr4_fetch_objfile_link_map
);
3178 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
3180 /* SystemTap functions. */
3181 set_gdbarch_stap_register_prefixes (gdbarch
, stap_register_prefixes
);
3182 set_gdbarch_stap_register_indirection_prefixes (gdbarch
,
3183 stap_register_indirection_prefixes
);
3184 set_gdbarch_stap_register_indirection_suffixes (gdbarch
,
3185 stap_register_indirection_suffixes
);
3186 set_gdbarch_stap_is_single_operand (gdbarch
, s390_stap_is_single_operand
);
3192 extern initialize_file_ftype _initialize_s390_tdep
; /* -Wmissing-prototypes */
3195 _initialize_s390_tdep (void)
3197 /* Hook us into the gdbarch mechanism. */
3198 register_gdbarch_init (bfd_arch_s390
, s390_gdbarch_init
);
3200 /* Initialize the GNU/Linux target descriptions. */
3201 initialize_tdesc_s390_linux32 ();
3202 initialize_tdesc_s390_linux32v1 ();
3203 initialize_tdesc_s390_linux32v2 ();
3204 initialize_tdesc_s390_linux64 ();
3205 initialize_tdesc_s390_linux64v1 ();
3206 initialize_tdesc_s390_linux64v2 ();
3207 initialize_tdesc_s390_te_linux64 ();
3208 initialize_tdesc_s390x_linux64 ();
3209 initialize_tdesc_s390x_linux64v1 ();
3210 initialize_tdesc_s390x_linux64v2 ();
3211 initialize_tdesc_s390x_te_linux64 ();