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
;
94 /* ABI call-saved register information. */
97 s390_register_call_saved (struct gdbarch
*gdbarch
, int regnum
)
99 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
104 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
105 || regnum
== S390_F4_REGNUM
|| regnum
== S390_F6_REGNUM
106 || regnum
== S390_A0_REGNUM
)
111 case ABI_LINUX_ZSERIES
:
112 if ((regnum
>= S390_R6_REGNUM
&& regnum
<= S390_R15_REGNUM
)
113 || (regnum
>= S390_F8_REGNUM
&& regnum
<= S390_F15_REGNUM
)
114 || (regnum
>= S390_A0_REGNUM
&& regnum
<= S390_A1_REGNUM
))
124 s390_cannot_store_register (struct gdbarch
*gdbarch
, int regnum
)
126 /* The last-break address is read-only. */
127 return regnum
== S390_LAST_BREAK_REGNUM
;
131 s390_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
133 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
134 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
136 regcache_cooked_write_unsigned (regcache
, tdep
->pc_regnum
, pc
);
138 /* Set special SYSTEM_CALL register to 0 to prevent the kernel from
139 messing with the PC we just installed, if we happen to be within
140 an interrupted system call that the kernel wants to restart.
142 Note that after we return from the dummy call, the SYSTEM_CALL and
143 ORIG_R2 registers will be automatically restored, and the kernel
144 continues to restart the system call at this point. */
145 if (register_size (gdbarch
, S390_SYSTEM_CALL_REGNUM
) > 0)
146 regcache_cooked_write_unsigned (regcache
, S390_SYSTEM_CALL_REGNUM
, 0);
150 /* DWARF Register Mapping. */
152 static const short s390_dwarf_regmap
[] =
154 /* General Purpose Registers. */
155 S390_R0_REGNUM
, S390_R1_REGNUM
, S390_R2_REGNUM
, S390_R3_REGNUM
,
156 S390_R4_REGNUM
, S390_R5_REGNUM
, S390_R6_REGNUM
, S390_R7_REGNUM
,
157 S390_R8_REGNUM
, S390_R9_REGNUM
, S390_R10_REGNUM
, S390_R11_REGNUM
,
158 S390_R12_REGNUM
, S390_R13_REGNUM
, S390_R14_REGNUM
, S390_R15_REGNUM
,
160 /* Floating Point Registers. */
161 S390_F0_REGNUM
, S390_F2_REGNUM
, S390_F4_REGNUM
, S390_F6_REGNUM
,
162 S390_F1_REGNUM
, S390_F3_REGNUM
, S390_F5_REGNUM
, S390_F7_REGNUM
,
163 S390_F8_REGNUM
, S390_F10_REGNUM
, S390_F12_REGNUM
, S390_F14_REGNUM
,
164 S390_F9_REGNUM
, S390_F11_REGNUM
, S390_F13_REGNUM
, S390_F15_REGNUM
,
166 /* Control Registers (not mapped). */
167 -1, -1, -1, -1, -1, -1, -1, -1,
168 -1, -1, -1, -1, -1, -1, -1, -1,
170 /* Access Registers. */
171 S390_A0_REGNUM
, S390_A1_REGNUM
, S390_A2_REGNUM
, S390_A3_REGNUM
,
172 S390_A4_REGNUM
, S390_A5_REGNUM
, S390_A6_REGNUM
, S390_A7_REGNUM
,
173 S390_A8_REGNUM
, S390_A9_REGNUM
, S390_A10_REGNUM
, S390_A11_REGNUM
,
174 S390_A12_REGNUM
, S390_A13_REGNUM
, S390_A14_REGNUM
, S390_A15_REGNUM
,
176 /* Program Status Word. */
180 /* GPR Lower Half Access. */
181 S390_R0_REGNUM
, S390_R1_REGNUM
, S390_R2_REGNUM
, S390_R3_REGNUM
,
182 S390_R4_REGNUM
, S390_R5_REGNUM
, S390_R6_REGNUM
, S390_R7_REGNUM
,
183 S390_R8_REGNUM
, S390_R9_REGNUM
, S390_R10_REGNUM
, S390_R11_REGNUM
,
184 S390_R12_REGNUM
, S390_R13_REGNUM
, S390_R14_REGNUM
, S390_R15_REGNUM
,
186 /* GNU/Linux-specific registers (not mapped). */
190 /* Convert DWARF register number REG to the appropriate register
191 number used by GDB. */
193 s390_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int reg
)
195 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
197 /* In a 32-on-64 debug scenario, debug info refers to the full 64-bit
198 GPRs. Note that call frame information still refers to the 32-bit
199 lower halves, because s390_adjust_frame_regnum uses register numbers
200 66 .. 81 to access GPRs. */
201 if (tdep
->gpr_full_regnum
!= -1 && reg
>= 0 && reg
< 16)
202 return tdep
->gpr_full_regnum
+ reg
;
204 if (reg
>= 0 && reg
< ARRAY_SIZE (s390_dwarf_regmap
))
205 return s390_dwarf_regmap
[reg
];
207 warning (_("Unmapped DWARF Register #%d encountered."), reg
);
211 /* Translate a .eh_frame register to DWARF register, or adjust a
212 .debug_frame register. */
214 s390_adjust_frame_regnum (struct gdbarch
*gdbarch
, int num
, int eh_frame_p
)
216 /* See s390_dwarf_reg_to_regnum for comments. */
217 return (num
>= 0 && num
< 16)? num
+ 66 : num
;
221 /* Pseudo registers. */
224 regnum_is_gpr_full (struct gdbarch_tdep
*tdep
, int regnum
)
226 return (tdep
->gpr_full_regnum
!= -1
227 && regnum
>= tdep
->gpr_full_regnum
228 && regnum
<= tdep
->gpr_full_regnum
+ 15);
232 s390_pseudo_register_name (struct gdbarch
*gdbarch
, int regnum
)
234 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
236 if (regnum
== tdep
->pc_regnum
)
239 if (regnum
== tdep
->cc_regnum
)
242 if (regnum_is_gpr_full (tdep
, regnum
))
244 static const char *full_name
[] = {
245 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
246 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
248 return full_name
[regnum
- tdep
->gpr_full_regnum
];
251 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
255 s390_pseudo_register_type (struct gdbarch
*gdbarch
, int regnum
)
257 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
259 if (regnum
== tdep
->pc_regnum
)
260 return builtin_type (gdbarch
)->builtin_func_ptr
;
262 if (regnum
== tdep
->cc_regnum
)
263 return builtin_type (gdbarch
)->builtin_int
;
265 if (regnum_is_gpr_full (tdep
, regnum
))
266 return builtin_type (gdbarch
)->builtin_uint64
;
268 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
271 static enum register_status
272 s390_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
273 int regnum
, gdb_byte
*buf
)
275 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
276 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
277 int regsize
= register_size (gdbarch
, regnum
);
280 if (regnum
== tdep
->pc_regnum
)
282 enum register_status status
;
284 status
= regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &val
);
285 if (status
== REG_VALID
)
287 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
289 store_unsigned_integer (buf
, regsize
, byte_order
, val
);
294 if (regnum
== tdep
->cc_regnum
)
296 enum register_status status
;
298 status
= regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &val
);
299 if (status
== REG_VALID
)
301 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
302 val
= (val
>> 12) & 3;
304 val
= (val
>> 44) & 3;
305 store_unsigned_integer (buf
, regsize
, byte_order
, val
);
310 if (regnum_is_gpr_full (tdep
, regnum
))
312 enum register_status status
;
315 regnum
-= tdep
->gpr_full_regnum
;
317 status
= regcache_raw_read_unsigned (regcache
, S390_R0_REGNUM
+ regnum
, &val
);
318 if (status
== REG_VALID
)
319 status
= regcache_raw_read_unsigned (regcache
, S390_R0_UPPER_REGNUM
+ regnum
,
321 if (status
== REG_VALID
)
323 val
|= val_upper
<< 32;
324 store_unsigned_integer (buf
, regsize
, byte_order
, val
);
329 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
333 s390_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
334 int regnum
, const gdb_byte
*buf
)
336 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
337 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
338 int regsize
= register_size (gdbarch
, regnum
);
341 if (regnum
== tdep
->pc_regnum
)
343 val
= extract_unsigned_integer (buf
, regsize
, byte_order
);
344 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
346 regcache_raw_read_unsigned (regcache
, S390_PSWA_REGNUM
, &psw
);
347 val
= (psw
& 0x80000000) | (val
& 0x7fffffff);
349 regcache_raw_write_unsigned (regcache
, S390_PSWA_REGNUM
, val
);
353 if (regnum
== tdep
->cc_regnum
)
355 val
= extract_unsigned_integer (buf
, regsize
, byte_order
);
356 regcache_raw_read_unsigned (regcache
, S390_PSWM_REGNUM
, &psw
);
357 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
358 val
= (psw
& ~((ULONGEST
)3 << 12)) | ((val
& 3) << 12);
360 val
= (psw
& ~((ULONGEST
)3 << 44)) | ((val
& 3) << 44);
361 regcache_raw_write_unsigned (regcache
, S390_PSWM_REGNUM
, val
);
365 if (regnum_is_gpr_full (tdep
, regnum
))
367 regnum
-= tdep
->gpr_full_regnum
;
368 val
= extract_unsigned_integer (buf
, regsize
, byte_order
);
369 regcache_raw_write_unsigned (regcache
, S390_R0_REGNUM
+ regnum
,
371 regcache_raw_write_unsigned (regcache
, S390_R0_UPPER_REGNUM
+ regnum
,
376 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
379 /* 'float' values are stored in the upper half of floating-point
380 registers, even though we are otherwise a big-endian platform. */
382 static struct value
*
383 s390_value_from_register (struct gdbarch
*gdbarch
, struct type
*type
,
384 int regnum
, struct frame_id frame_id
)
386 struct value
*value
= default_value_from_register (gdbarch
, type
,
388 check_typedef (type
);
390 if (regnum
>= S390_F0_REGNUM
&& regnum
<= S390_F15_REGNUM
391 && TYPE_LENGTH (type
) < 8)
392 set_value_offset (value
, 0);
397 /* Register groups. */
400 s390_pseudo_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
401 struct reggroup
*group
)
403 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
405 /* We usually save/restore the whole PSW, which includes PC and CC.
406 However, some older gdbservers may not support saving/restoring
407 the whole PSW yet, and will return an XML register description
408 excluding those from the save/restore register groups. In those
409 cases, we still need to explicitly save/restore PC and CC in order
410 to push or pop frames. Since this doesn't hurt anything if we
411 already save/restore the whole PSW (it's just redundant), we add
412 PC and CC at this point unconditionally. */
413 if (group
== save_reggroup
|| group
== restore_reggroup
)
414 return regnum
== tdep
->pc_regnum
|| regnum
== tdep
->cc_regnum
;
416 return default_register_reggroup_p (gdbarch
, regnum
, group
);
420 /* Maps for register sets. */
422 static const struct regcache_map_entry s390_gregmap
[] =
424 { 1, S390_PSWM_REGNUM
},
425 { 1, S390_PSWA_REGNUM
},
426 { 16, S390_R0_REGNUM
},
427 { 16, S390_A0_REGNUM
},
428 { 1, S390_ORIG_R2_REGNUM
},
432 static const struct regcache_map_entry s390_fpregmap
[] =
434 { 1, S390_FPC_REGNUM
, 8 },
435 { 16, S390_F0_REGNUM
, 8 },
439 static const struct regcache_map_entry s390_regmap_upper
[] =
441 { 16, S390_R0_UPPER_REGNUM
, 4 },
445 static const struct regcache_map_entry s390_regmap_last_break
[] =
447 { 1, REGCACHE_MAP_SKIP
, 4 },
448 { 1, S390_LAST_BREAK_REGNUM
, 4 },
452 static const struct regcache_map_entry s390x_regmap_last_break
[] =
454 { 1, S390_LAST_BREAK_REGNUM
, 8 },
458 static const struct regcache_map_entry s390_regmap_system_call
[] =
460 { 1, S390_SYSTEM_CALL_REGNUM
, 4 },
464 static const struct regcache_map_entry s390_regmap_tdb
[] =
466 { 1, S390_TDB_DWORD0_REGNUM
, 8 },
467 { 1, S390_TDB_ABORT_CODE_REGNUM
, 8 },
468 { 1, S390_TDB_CONFLICT_TOKEN_REGNUM
, 8 },
469 { 1, S390_TDB_ATIA_REGNUM
, 8 },
470 { 12, REGCACHE_MAP_SKIP
, 8 },
471 { 16, S390_TDB_R0_REGNUM
, 8 },
476 /* Supply the TDB regset. Like regcache_supply_regset, but invalidate
477 the TDB registers unless the TDB format field is valid. */
480 s390_supply_tdb_regset (const struct regset
*regset
, struct regcache
*regcache
,
481 int regnum
, const void *regs
, size_t len
)
484 enum register_status ret
;
487 regcache_supply_regset (regset
, regcache
, regnum
, regs
, len
);
488 ret
= regcache_cooked_read_unsigned (regcache
, S390_TDB_DWORD0_REGNUM
, &tdw
);
489 if (ret
!= REG_VALID
|| (tdw
>> 56) != 1)
490 regcache_supply_regset (regset
, regcache
, regnum
, NULL
, len
);
493 const struct regset s390_gregset
= {
495 regcache_supply_regset
,
496 regcache_collect_regset
499 const struct regset s390_fpregset
= {
501 regcache_supply_regset
,
502 regcache_collect_regset
505 static const struct regset s390_upper_regset
= {
507 regcache_supply_regset
,
508 regcache_collect_regset
511 const struct regset s390_last_break_regset
= {
512 s390_regmap_last_break
,
513 regcache_supply_regset
,
514 regcache_collect_regset
517 const struct regset s390x_last_break_regset
= {
518 s390x_regmap_last_break
,
519 regcache_supply_regset
,
520 regcache_collect_regset
523 const struct regset s390_system_call_regset
= {
524 s390_regmap_system_call
,
525 regcache_supply_regset
,
526 regcache_collect_regset
529 const struct regset s390_tdb_regset
= {
531 s390_supply_tdb_regset
,
532 regcache_collect_regset
535 static struct core_regset_section s390_linux32_regset_sections
[] =
537 { ".reg", s390_sizeof_gregset
, "general-purpose" },
538 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
542 static struct core_regset_section s390_linux32v1_regset_sections
[] =
544 { ".reg", s390_sizeof_gregset
, "general-purpose" },
545 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
546 { ".reg-s390-last-break", 8, "s390 last-break address" },
550 static struct core_regset_section s390_linux32v2_regset_sections
[] =
552 { ".reg", s390_sizeof_gregset
, "general-purpose" },
553 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
554 { ".reg-s390-last-break", 8, "s390 last-break address" },
555 { ".reg-s390-system-call", 4, "s390 system-call" },
559 static struct core_regset_section s390_linux64_regset_sections
[] =
561 { ".reg", s390_sizeof_gregset
, "general-purpose" },
562 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
563 { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
567 static struct core_regset_section s390_linux64v1_regset_sections
[] =
569 { ".reg", s390_sizeof_gregset
, "general-purpose" },
570 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
571 { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
572 { ".reg-s390-last-break", 8, "s930 last-break address" },
576 static struct core_regset_section s390_linux64v2_regset_sections
[] =
578 { ".reg", s390_sizeof_gregset
, "general-purpose" },
579 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
580 { ".reg-s390-high-gprs", 16*4, "s390 GPR upper halves" },
581 { ".reg-s390-last-break", 8, "s930 last-break address" },
582 { ".reg-s390-system-call", 4, "s390 system-call" },
583 { ".reg-s390-tdb", s390_sizeof_tdbregset
, "s390 TDB" },
587 static struct core_regset_section s390x_linux64_regset_sections
[] =
589 { ".reg", s390x_sizeof_gregset
, "general-purpose" },
590 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
594 static struct core_regset_section s390x_linux64v1_regset_sections
[] =
596 { ".reg", s390x_sizeof_gregset
, "general-purpose" },
597 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
598 { ".reg-s390-last-break", 8, "s930 last-break address" },
602 static struct core_regset_section s390x_linux64v2_regset_sections
[] =
604 { ".reg", s390x_sizeof_gregset
, "general-purpose" },
605 { ".reg2", s390_sizeof_fpregset
, "floating-point" },
606 { ".reg-s390-last-break", 8, "s930 last-break address" },
607 { ".reg-s390-system-call", 4, "s390 system-call" },
608 { ".reg-s390-tdb", s390_sizeof_tdbregset
, "s390 TDB" },
613 /* Return the appropriate register set for the core section identified
614 by SECT_NAME and SECT_SIZE. */
615 static const struct regset
*
616 s390_regset_from_core_section (struct gdbarch
*gdbarch
,
617 const char *sect_name
, size_t sect_size
)
619 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
621 if (strcmp (sect_name
, ".reg") == 0 && sect_size
>= tdep
->sizeof_gregset
)
622 return tdep
->gregset
;
624 if (strcmp (sect_name
, ".reg2") == 0 && sect_size
>= tdep
->sizeof_fpregset
)
625 return tdep
->fpregset
;
627 if (strcmp (sect_name
, ".reg-s390-high-gprs") == 0 && sect_size
>= 16*4)
628 return &s390_upper_regset
;
630 if (strcmp (sect_name
, ".reg-s390-last-break") == 0 && sect_size
>= 8)
631 return (gdbarch_ptr_bit (gdbarch
) == 32
632 ? &s390_last_break_regset
: &s390x_last_break_regset
);
634 if (strcmp (sect_name
, ".reg-s390-system-call") == 0 && sect_size
>= 4)
635 return &s390_system_call_regset
;
637 if (strcmp (sect_name
, ".reg-s390-tdb") == 0 && sect_size
>= 256)
638 return &s390_tdb_regset
;
643 static const struct target_desc
*
644 s390_core_read_description (struct gdbarch
*gdbarch
,
645 struct target_ops
*target
, bfd
*abfd
)
647 asection
*high_gprs
= bfd_get_section_by_name (abfd
, ".reg-s390-high-gprs");
648 asection
*v1
= bfd_get_section_by_name (abfd
, ".reg-s390-last-break");
649 asection
*v2
= bfd_get_section_by_name (abfd
, ".reg-s390-system-call");
650 asection
*section
= bfd_get_section_by_name (abfd
, ".reg");
653 target_auxv_search (target
, AT_HWCAP
, &hwcap
);
657 switch (bfd_section_size (abfd
, section
))
659 case s390_sizeof_gregset
:
661 return ((hwcap
& HWCAP_S390_TE
) ? tdesc_s390_te_linux64
:
662 v2
? tdesc_s390_linux64v2
:
663 v1
? tdesc_s390_linux64v1
: tdesc_s390_linux64
);
665 return (v2
? tdesc_s390_linux32v2
:
666 v1
? tdesc_s390_linux32v1
: tdesc_s390_linux32
);
668 case s390x_sizeof_gregset
:
669 return ((hwcap
& HWCAP_S390_TE
) ? tdesc_s390x_te_linux64
:
670 v2
? tdesc_s390x_linux64v2
:
671 v1
? tdesc_s390x_linux64v1
: tdesc_s390x_linux64
);
679 /* Decoding S/390 instructions. */
681 /* Named opcode values for the S/390 instructions we recognize. Some
682 instructions have their opcode split across two fields; those are the
683 op1_* and op2_* enums. */
686 op1_lhi
= 0xa7, op2_lhi
= 0x08,
687 op1_lghi
= 0xa7, op2_lghi
= 0x09,
688 op1_lgfi
= 0xc0, op2_lgfi
= 0x01,
692 op1_ly
= 0xe3, op2_ly
= 0x58,
693 op1_lg
= 0xe3, op2_lg
= 0x04,
695 op1_lmy
= 0xeb, op2_lmy
= 0x98,
696 op1_lmg
= 0xeb, op2_lmg
= 0x04,
698 op1_sty
= 0xe3, op2_sty
= 0x50,
699 op1_stg
= 0xe3, op2_stg
= 0x24,
702 op1_stmy
= 0xeb, op2_stmy
= 0x90,
703 op1_stmg
= 0xeb, op2_stmg
= 0x24,
704 op1_aghi
= 0xa7, op2_aghi
= 0x0b,
705 op1_ahi
= 0xa7, op2_ahi
= 0x0a,
706 op1_agfi
= 0xc2, op2_agfi
= 0x08,
707 op1_afi
= 0xc2, op2_afi
= 0x09,
708 op1_algfi
= 0xc2, op2_algfi
= 0x0a,
709 op1_alfi
= 0xc2, op2_alfi
= 0x0b,
713 op1_ay
= 0xe3, op2_ay
= 0x5a,
714 op1_ag
= 0xe3, op2_ag
= 0x08,
715 op1_slgfi
= 0xc2, op2_slgfi
= 0x04,
716 op1_slfi
= 0xc2, op2_slfi
= 0x05,
720 op1_sy
= 0xe3, op2_sy
= 0x5b,
721 op1_sg
= 0xe3, op2_sg
= 0x09,
725 op1_lay
= 0xe3, op2_lay
= 0x71,
726 op1_larl
= 0xc0, op2_larl
= 0x00,
734 op1_bctg
= 0xe3, op2_bctg
= 0x46,
736 op1_bxhg
= 0xeb, op2_bxhg
= 0x44,
738 op1_bxleg
= 0xeb, op2_bxleg
= 0x45,
739 op1_bras
= 0xa7, op2_bras
= 0x05,
740 op1_brasl
= 0xc0, op2_brasl
= 0x05,
741 op1_brc
= 0xa7, op2_brc
= 0x04,
742 op1_brcl
= 0xc0, op2_brcl
= 0x04,
743 op1_brct
= 0xa7, op2_brct
= 0x06,
744 op1_brctg
= 0xa7, op2_brctg
= 0x07,
746 op1_brxhg
= 0xec, op2_brxhg
= 0x44,
748 op1_brxlg
= 0xec, op2_brxlg
= 0x45,
753 /* Read a single instruction from address AT. */
755 #define S390_MAX_INSTR_SIZE 6
757 s390_readinstruction (bfd_byte instr
[], CORE_ADDR at
)
759 static int s390_instrlen
[] = { 2, 4, 4, 6 };
762 if (target_read_memory (at
, &instr
[0], 2))
764 instrlen
= s390_instrlen
[instr
[0] >> 6];
767 if (target_read_memory (at
+ 2, &instr
[2], instrlen
- 2))
774 /* The functions below are for recognizing and decoding S/390
775 instructions of various formats. Each of them checks whether INSN
776 is an instruction of the given format, with the specified opcodes.
777 If it is, it sets the remaining arguments to the values of the
778 instruction's fields, and returns a non-zero value; otherwise, it
781 These functions' arguments appear in the order they appear in the
782 instruction, not in the machine-language form. So, opcodes always
783 come first, even though they're sometimes scattered around the
784 instructions. And displacements appear before base and extension
785 registers, as they do in the assembly syntax, not at the end, as
786 they do in the machine language. */
788 is_ri (bfd_byte
*insn
, int op1
, int op2
, unsigned int *r1
, int *i2
)
790 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
792 *r1
= (insn
[1] >> 4) & 0xf;
793 /* i2 is a 16-bit signed quantity. */
794 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
803 is_ril (bfd_byte
*insn
, int op1
, int op2
,
804 unsigned int *r1
, int *i2
)
806 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
808 *r1
= (insn
[1] >> 4) & 0xf;
809 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
810 no sign extension is necessary, but we don't want to assume
812 *i2
= (((insn
[2] << 24)
815 | (insn
[5])) ^ 0x80000000) - 0x80000000;
824 is_rr (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
828 *r1
= (insn
[1] >> 4) & 0xf;
838 is_rre (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
840 if (((insn
[0] << 8) | insn
[1]) == op
)
842 /* Yes, insn[3]. insn[2] is unused in RRE format. */
843 *r1
= (insn
[3] >> 4) & 0xf;
853 is_rs (bfd_byte
*insn
, int op
,
854 unsigned int *r1
, unsigned int *r3
, int *d2
, unsigned int *b2
)
858 *r1
= (insn
[1] >> 4) & 0xf;
860 *b2
= (insn
[2] >> 4) & 0xf;
861 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
870 is_rsy (bfd_byte
*insn
, int op1
, int op2
,
871 unsigned int *r1
, unsigned int *r3
, int *d2
, unsigned int *b2
)
876 *r1
= (insn
[1] >> 4) & 0xf;
878 *b2
= (insn
[2] >> 4) & 0xf;
879 /* The 'long displacement' is a 20-bit signed integer. */
880 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
881 ^ 0x80000) - 0x80000;
890 is_rsi (bfd_byte
*insn
, int op
,
891 unsigned int *r1
, unsigned int *r3
, int *i2
)
895 *r1
= (insn
[1] >> 4) & 0xf;
897 /* i2 is a 16-bit signed quantity. */
898 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
907 is_rie (bfd_byte
*insn
, int op1
, int op2
,
908 unsigned int *r1
, unsigned int *r3
, int *i2
)
913 *r1
= (insn
[1] >> 4) & 0xf;
915 /* i2 is a 16-bit signed quantity. */
916 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
925 is_rx (bfd_byte
*insn
, int op
,
926 unsigned int *r1
, int *d2
, unsigned int *x2
, unsigned int *b2
)
930 *r1
= (insn
[1] >> 4) & 0xf;
932 *b2
= (insn
[2] >> 4) & 0xf;
933 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
942 is_rxy (bfd_byte
*insn
, int op1
, int op2
,
943 unsigned int *r1
, int *d2
, unsigned int *x2
, unsigned int *b2
)
948 *r1
= (insn
[1] >> 4) & 0xf;
950 *b2
= (insn
[2] >> 4) & 0xf;
951 /* The 'long displacement' is a 20-bit signed integer. */
952 *d2
= ((((insn
[2] & 0xf) << 8) | insn
[3] | (insn
[4] << 12))
953 ^ 0x80000) - 0x80000;
961 /* Prologue analysis. */
963 #define S390_NUM_GPRS 16
964 #define S390_NUM_FPRS 16
966 struct s390_prologue_data
{
969 struct pv_area
*stack
;
971 /* The size and byte-order of a GPR or FPR. */
974 enum bfd_endian byte_order
;
976 /* The general-purpose registers. */
977 pv_t gpr
[S390_NUM_GPRS
];
979 /* The floating-point registers. */
980 pv_t fpr
[S390_NUM_FPRS
];
982 /* The offset relative to the CFA where the incoming GPR N was saved
983 by the function prologue. 0 if not saved or unknown. */
984 int gpr_slot
[S390_NUM_GPRS
];
986 /* Likewise for FPRs. */
987 int fpr_slot
[S390_NUM_FPRS
];
989 /* Nonzero if the backchain was saved. This is assumed to be the
990 case when the incoming SP is saved at the current SP location. */
991 int back_chain_saved_p
;
994 /* Return the effective address for an X-style instruction, like:
998 Here, X2 and B2 are registers, and D2 is a signed 20-bit
999 constant; the effective address is the sum of all three. If either
1000 X2 or B2 are zero, then it doesn't contribute to the sum --- this
1001 means that r0 can't be used as either X2 or B2. */
1003 s390_addr (struct s390_prologue_data
*data
,
1004 int d2
, unsigned int x2
, unsigned int b2
)
1008 result
= pv_constant (d2
);
1010 result
= pv_add (result
, data
->gpr
[x2
]);
1012 result
= pv_add (result
, data
->gpr
[b2
]);
1017 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
1019 s390_store (struct s390_prologue_data
*data
,
1020 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
,
1023 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
1026 /* Check whether we are storing the backchain. */
1027 offset
= pv_subtract (data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
], addr
);
1029 if (pv_is_constant (offset
) && offset
.k
== 0)
1030 if (size
== data
->gpr_size
1031 && pv_is_register_k (value
, S390_SP_REGNUM
, 0))
1033 data
->back_chain_saved_p
= 1;
1038 /* Check whether we are storing a register into the stack. */
1039 if (!pv_area_store_would_trash (data
->stack
, addr
))
1040 pv_area_store (data
->stack
, addr
, size
, value
);
1043 /* Note: If this is some store we cannot identify, you might think we
1044 should forget our cached values, as any of those might have been hit.
1046 However, we make the assumption that the register save areas are only
1047 ever stored to once in any given function, and we do recognize these
1048 stores. Thus every store we cannot recognize does not hit our data. */
1051 /* Do a SIZE-byte load from D2(X2,B2). */
1053 s390_load (struct s390_prologue_data
*data
,
1054 int d2
, unsigned int x2
, unsigned int b2
, CORE_ADDR size
)
1057 pv_t addr
= s390_addr (data
, d2
, x2
, b2
);
1059 /* If it's a load from an in-line constant pool, then we can
1060 simulate that, under the assumption that the code isn't
1061 going to change between the time the processor actually
1062 executed it creating the current frame, and the time when
1063 we're analyzing the code to unwind past that frame. */
1064 if (pv_is_constant (addr
))
1066 struct target_section
*secp
;
1067 secp
= target_section_by_addr (¤t_target
, addr
.k
);
1069 && (bfd_get_section_flags (secp
->the_bfd_section
->owner
,
1070 secp
->the_bfd_section
)
1072 return pv_constant (read_memory_integer (addr
.k
, size
,
1076 /* Check whether we are accessing one of our save slots. */
1077 return pv_area_fetch (data
->stack
, addr
, size
);
1080 /* Function for finding saved registers in a 'struct pv_area'; we pass
1081 this to pv_area_scan.
1083 If VALUE is a saved register, ADDR says it was saved at a constant
1084 offset from the frame base, and SIZE indicates that the whole
1085 register was saved, record its offset in the reg_offset table in
1086 PROLOGUE_UNTYPED. */
1088 s390_check_for_saved (void *data_untyped
, pv_t addr
,
1089 CORE_ADDR size
, pv_t value
)
1091 struct s390_prologue_data
*data
= data_untyped
;
1094 if (!pv_is_register (addr
, S390_SP_REGNUM
))
1097 offset
= 16 * data
->gpr_size
+ 32 - addr
.k
;
1099 /* If we are storing the original value of a register, we want to
1100 record the CFA offset. If the same register is stored multiple
1101 times, the stack slot with the highest address counts. */
1103 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1104 if (size
== data
->gpr_size
1105 && pv_is_register_k (value
, S390_R0_REGNUM
+ i
, 0))
1106 if (data
->gpr_slot
[i
] == 0
1107 || data
->gpr_slot
[i
] > offset
)
1109 data
->gpr_slot
[i
] = offset
;
1113 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1114 if (size
== data
->fpr_size
1115 && pv_is_register_k (value
, S390_F0_REGNUM
+ i
, 0))
1116 if (data
->fpr_slot
[i
] == 0
1117 || data
->fpr_slot
[i
] > offset
)
1119 data
->fpr_slot
[i
] = offset
;
1124 /* Analyze the prologue of the function starting at START_PC,
1125 continuing at most until CURRENT_PC. Initialize DATA to
1126 hold all information we find out about the state of the registers
1127 and stack slots. Return the address of the instruction after
1128 the last one that changed the SP, FP, or back chain; or zero
1131 s390_analyze_prologue (struct gdbarch
*gdbarch
,
1133 CORE_ADDR current_pc
,
1134 struct s390_prologue_data
*data
)
1136 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1138 /* Our return value:
1139 The address of the instruction after the last one that changed
1140 the SP, FP, or back chain; zero if we got an error trying to
1142 CORE_ADDR result
= start_pc
;
1144 /* The current PC for our abstract interpretation. */
1147 /* The address of the next instruction after that. */
1150 /* Set up everything's initial value. */
1154 data
->stack
= make_pv_area (S390_SP_REGNUM
, gdbarch_addr_bit (gdbarch
));
1156 /* For the purpose of prologue tracking, we consider the GPR size to
1157 be equal to the ABI word size, even if it is actually larger
1158 (i.e. when running a 32-bit binary under a 64-bit kernel). */
1159 data
->gpr_size
= word_size
;
1161 data
->byte_order
= gdbarch_byte_order (gdbarch
);
1163 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1164 data
->gpr
[i
] = pv_register (S390_R0_REGNUM
+ i
, 0);
1166 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1167 data
->fpr
[i
] = pv_register (S390_F0_REGNUM
+ i
, 0);
1169 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
1170 data
->gpr_slot
[i
] = 0;
1172 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
1173 data
->fpr_slot
[i
] = 0;
1175 data
->back_chain_saved_p
= 0;
1178 /* Start interpreting instructions, until we hit the frame's
1179 current PC or the first branch instruction. */
1180 for (pc
= start_pc
; pc
> 0 && pc
< current_pc
; pc
= next_pc
)
1182 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
1183 int insn_len
= s390_readinstruction (insn
, pc
);
1185 bfd_byte dummy
[S390_MAX_INSTR_SIZE
] = { 0 };
1186 bfd_byte
*insn32
= word_size
== 4 ? insn
: dummy
;
1187 bfd_byte
*insn64
= word_size
== 8 ? insn
: dummy
;
1189 /* Fields for various kinds of instructions. */
1190 unsigned int b2
, r1
, r2
, x2
, r3
;
1193 /* The values of SP and FP before this instruction,
1194 for detecting instructions that change them. */
1195 pv_t pre_insn_sp
, pre_insn_fp
;
1196 /* Likewise for the flag whether the back chain was saved. */
1197 int pre_insn_back_chain_saved_p
;
1199 /* If we got an error trying to read the instruction, report it. */
1206 next_pc
= pc
+ insn_len
;
1208 pre_insn_sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1209 pre_insn_fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1210 pre_insn_back_chain_saved_p
= data
->back_chain_saved_p
;
1213 /* LHI r1, i2 --- load halfword immediate. */
1214 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
1215 /* LGFI r1, i2 --- load fullword immediate. */
1216 if (is_ri (insn32
, op1_lhi
, op2_lhi
, &r1
, &i2
)
1217 || is_ri (insn64
, op1_lghi
, op2_lghi
, &r1
, &i2
)
1218 || is_ril (insn
, op1_lgfi
, op2_lgfi
, &r1
, &i2
))
1219 data
->gpr
[r1
] = pv_constant (i2
);
1221 /* LR r1, r2 --- load from register. */
1222 /* LGR r1, r2 --- load from register (64-bit version). */
1223 else if (is_rr (insn32
, op_lr
, &r1
, &r2
)
1224 || is_rre (insn64
, op_lgr
, &r1
, &r2
))
1225 data
->gpr
[r1
] = data
->gpr
[r2
];
1227 /* L r1, d2(x2, b2) --- load. */
1228 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
1229 /* LG r1, d2(x2, b2) --- load (64-bit version). */
1230 else if (is_rx (insn32
, op_l
, &r1
, &d2
, &x2
, &b2
)
1231 || is_rxy (insn32
, op1_ly
, op2_ly
, &r1
, &d2
, &x2
, &b2
)
1232 || is_rxy (insn64
, op1_lg
, op2_lg
, &r1
, &d2
, &x2
, &b2
))
1233 data
->gpr
[r1
] = s390_load (data
, d2
, x2
, b2
, data
->gpr_size
);
1235 /* ST r1, d2(x2, b2) --- store. */
1236 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
1237 /* STG r1, d2(x2, b2) --- store (64-bit version). */
1238 else if (is_rx (insn32
, op_st
, &r1
, &d2
, &x2
, &b2
)
1239 || is_rxy (insn32
, op1_sty
, op2_sty
, &r1
, &d2
, &x2
, &b2
)
1240 || is_rxy (insn64
, op1_stg
, op2_stg
, &r1
, &d2
, &x2
, &b2
))
1241 s390_store (data
, d2
, x2
, b2
, data
->gpr_size
, data
->gpr
[r1
]);
1243 /* STD r1, d2(x2,b2) --- store floating-point register. */
1244 else if (is_rx (insn
, op_std
, &r1
, &d2
, &x2
, &b2
))
1245 s390_store (data
, d2
, x2
, b2
, data
->fpr_size
, data
->fpr
[r1
]);
1247 /* STM r1, r3, d2(b2) --- store multiple. */
1248 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement
1250 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
1251 else if (is_rs (insn32
, op_stm
, &r1
, &r3
, &d2
, &b2
)
1252 || is_rsy (insn32
, op1_stmy
, op2_stmy
, &r1
, &r3
, &d2
, &b2
)
1253 || is_rsy (insn64
, op1_stmg
, op2_stmg
, &r1
, &r3
, &d2
, &b2
))
1255 for (; r1
<= r3
; r1
++, d2
+= data
->gpr_size
)
1256 s390_store (data
, d2
, 0, b2
, data
->gpr_size
, data
->gpr
[r1
]);
1259 /* AHI r1, i2 --- add halfword immediate. */
1260 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
1261 /* AFI r1, i2 --- add fullword immediate. */
1262 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
1263 else if (is_ri (insn32
, op1_ahi
, op2_ahi
, &r1
, &i2
)
1264 || is_ri (insn64
, op1_aghi
, op2_aghi
, &r1
, &i2
)
1265 || is_ril (insn32
, op1_afi
, op2_afi
, &r1
, &i2
)
1266 || is_ril (insn64
, op1_agfi
, op2_agfi
, &r1
, &i2
))
1267 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
], i2
);
1269 /* ALFI r1, i2 --- add logical immediate. */
1270 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
1271 else if (is_ril (insn32
, op1_alfi
, op2_alfi
, &r1
, &i2
)
1272 || is_ril (insn64
, op1_algfi
, op2_algfi
, &r1
, &i2
))
1273 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
],
1274 (CORE_ADDR
)i2
& 0xffffffff);
1276 /* AR r1, r2 -- add register. */
1277 /* AGR r1, r2 -- add register (64-bit version). */
1278 else if (is_rr (insn32
, op_ar
, &r1
, &r2
)
1279 || is_rre (insn64
, op_agr
, &r1
, &r2
))
1280 data
->gpr
[r1
] = pv_add (data
->gpr
[r1
], data
->gpr
[r2
]);
1282 /* A r1, d2(x2, b2) -- add. */
1283 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
1284 /* AG r1, d2(x2, b2) -- add (64-bit version). */
1285 else if (is_rx (insn32
, op_a
, &r1
, &d2
, &x2
, &b2
)
1286 || is_rxy (insn32
, op1_ay
, op2_ay
, &r1
, &d2
, &x2
, &b2
)
1287 || is_rxy (insn64
, op1_ag
, op2_ag
, &r1
, &d2
, &x2
, &b2
))
1288 data
->gpr
[r1
] = pv_add (data
->gpr
[r1
],
1289 s390_load (data
, d2
, x2
, b2
, data
->gpr_size
));
1291 /* SLFI r1, i2 --- subtract logical immediate. */
1292 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
1293 else if (is_ril (insn32
, op1_slfi
, op2_slfi
, &r1
, &i2
)
1294 || is_ril (insn64
, op1_slgfi
, op2_slgfi
, &r1
, &i2
))
1295 data
->gpr
[r1
] = pv_add_constant (data
->gpr
[r1
],
1296 -((CORE_ADDR
)i2
& 0xffffffff));
1298 /* SR r1, r2 -- subtract register. */
1299 /* SGR r1, r2 -- subtract register (64-bit version). */
1300 else if (is_rr (insn32
, op_sr
, &r1
, &r2
)
1301 || is_rre (insn64
, op_sgr
, &r1
, &r2
))
1302 data
->gpr
[r1
] = pv_subtract (data
->gpr
[r1
], data
->gpr
[r2
]);
1304 /* S r1, d2(x2, b2) -- subtract. */
1305 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
1306 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
1307 else if (is_rx (insn32
, op_s
, &r1
, &d2
, &x2
, &b2
)
1308 || is_rxy (insn32
, op1_sy
, op2_sy
, &r1
, &d2
, &x2
, &b2
)
1309 || is_rxy (insn64
, op1_sg
, op2_sg
, &r1
, &d2
, &x2
, &b2
))
1310 data
->gpr
[r1
] = pv_subtract (data
->gpr
[r1
],
1311 s390_load (data
, d2
, x2
, b2
, data
->gpr_size
));
1313 /* LA r1, d2(x2, b2) --- load address. */
1314 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
1315 else if (is_rx (insn
, op_la
, &r1
, &d2
, &x2
, &b2
)
1316 || is_rxy (insn
, op1_lay
, op2_lay
, &r1
, &d2
, &x2
, &b2
))
1317 data
->gpr
[r1
] = s390_addr (data
, d2
, x2
, b2
);
1319 /* LARL r1, i2 --- load address relative long. */
1320 else if (is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1321 data
->gpr
[r1
] = pv_constant (pc
+ i2
* 2);
1323 /* BASR r1, 0 --- branch and save.
1324 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1325 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1327 data
->gpr
[r1
] = pv_constant (next_pc
);
1329 /* BRAS r1, i2 --- branch relative and save. */
1330 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
))
1332 data
->gpr
[r1
] = pv_constant (next_pc
);
1333 next_pc
= pc
+ i2
* 2;
1335 /* We'd better not interpret any backward branches. We'll
1341 /* Terminate search when hitting any other branch instruction. */
1342 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1343 || is_rx (insn
, op_bas
, &r1
, &d2
, &x2
, &b2
)
1344 || is_rr (insn
, op_bcr
, &r1
, &r2
)
1345 || is_rx (insn
, op_bc
, &r1
, &d2
, &x2
, &b2
)
1346 || is_ri (insn
, op1_brc
, op2_brc
, &r1
, &i2
)
1347 || is_ril (insn
, op1_brcl
, op2_brcl
, &r1
, &i2
)
1348 || is_ril (insn
, op1_brasl
, op2_brasl
, &r2
, &i2
))
1353 /* An instruction we don't know how to simulate. The only
1354 safe thing to do would be to set every value we're tracking
1355 to 'unknown'. Instead, we'll be optimistic: we assume that
1356 we *can* interpret every instruction that the compiler uses
1357 to manipulate any of the data we're interested in here --
1358 then we can just ignore anything else. */
1361 /* Record the address after the last instruction that changed
1362 the FP, SP, or backlink. Ignore instructions that changed
1363 them back to their original values --- those are probably
1364 restore instructions. (The back chain is never restored,
1367 pv_t sp
= data
->gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1368 pv_t fp
= data
->gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1370 if ((! pv_is_identical (pre_insn_sp
, sp
)
1371 && ! pv_is_register_k (sp
, S390_SP_REGNUM
, 0)
1372 && sp
.kind
!= pvk_unknown
)
1373 || (! pv_is_identical (pre_insn_fp
, fp
)
1374 && ! pv_is_register_k (fp
, S390_FRAME_REGNUM
, 0)
1375 && fp
.kind
!= pvk_unknown
)
1376 || pre_insn_back_chain_saved_p
!= data
->back_chain_saved_p
)
1381 /* Record where all the registers were saved. */
1382 pv_area_scan (data
->stack
, s390_check_for_saved
, data
);
1384 free_pv_area (data
->stack
);
1390 /* Advance PC across any function entry prologue instructions to reach
1391 some "real" code. */
1393 s390_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1395 struct s390_prologue_data data
;
1397 skip_pc
= s390_analyze_prologue (gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
1398 return skip_pc
? skip_pc
: pc
;
1401 /* Return true if we are in the functin's epilogue, i.e. after the
1402 instruction that destroyed the function's stack frame. */
1404 s390_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1406 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1408 /* In frameless functions, there's not frame to destroy and thus
1409 we don't care about the epilogue.
1411 In functions with frame, the epilogue sequence is a pair of
1412 a LM-type instruction that restores (amongst others) the
1413 return register %r14 and the stack pointer %r15, followed
1414 by a branch 'br %r14' --or equivalent-- that effects the
1417 In that situation, this function needs to return 'true' in
1418 exactly one case: when pc points to that branch instruction.
1420 Thus we try to disassemble the one instructions immediately
1421 preceding pc and check whether it is an LM-type instruction
1422 modifying the stack pointer.
1424 Note that disassembling backwards is not reliable, so there
1425 is a slight chance of false positives here ... */
1428 unsigned int r1
, r3
, b2
;
1432 && !target_read_memory (pc
- 4, insn
, 4)
1433 && is_rs (insn
, op_lm
, &r1
, &r3
, &d2
, &b2
)
1434 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1438 && !target_read_memory (pc
- 6, insn
, 6)
1439 && is_rsy (insn
, op1_lmy
, op2_lmy
, &r1
, &r3
, &d2
, &b2
)
1440 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1444 && !target_read_memory (pc
- 6, insn
, 6)
1445 && is_rsy (insn
, op1_lmg
, op2_lmg
, &r1
, &r3
, &d2
, &b2
)
1446 && r3
== S390_SP_REGNUM
- S390_R0_REGNUM
)
1452 /* Displaced stepping. */
1454 /* Fix up the state of registers and memory after having single-stepped
1455 a displaced instruction. */
1457 s390_displaced_step_fixup (struct gdbarch
*gdbarch
,
1458 struct displaced_step_closure
*closure
,
1459 CORE_ADDR from
, CORE_ADDR to
,
1460 struct regcache
*regs
)
1462 /* Since we use simple_displaced_step_copy_insn, our closure is a
1463 copy of the instruction. */
1464 gdb_byte
*insn
= (gdb_byte
*) closure
;
1465 static int s390_instrlen
[] = { 2, 4, 4, 6 };
1466 int insnlen
= s390_instrlen
[insn
[0] >> 6];
1468 /* Fields for various kinds of instructions. */
1469 unsigned int b2
, r1
, r2
, x2
, r3
;
1472 /* Get current PC and addressing mode bit. */
1473 CORE_ADDR pc
= regcache_read_pc (regs
);
1476 if (register_size (gdbarch
, S390_PSWA_REGNUM
) == 4)
1478 regcache_cooked_read_unsigned (regs
, S390_PSWA_REGNUM
, &amode
);
1479 amode
&= 0x80000000;
1482 if (debug_displaced
)
1483 fprintf_unfiltered (gdb_stdlog
,
1484 "displaced: (s390) fixup (%s, %s) pc %s len %d amode 0x%x\n",
1485 paddress (gdbarch
, from
), paddress (gdbarch
, to
),
1486 paddress (gdbarch
, pc
), insnlen
, (int) amode
);
1488 /* Handle absolute branch and save instructions. */
1489 if (is_rr (insn
, op_basr
, &r1
, &r2
)
1490 || is_rx (insn
, op_bas
, &r1
, &d2
, &x2
, &b2
))
1492 /* Recompute saved return address in R1. */
1493 regcache_cooked_write_unsigned (regs
, S390_R0_REGNUM
+ r1
,
1494 amode
| (from
+ insnlen
));
1497 /* Handle absolute branch instructions. */
1498 else if (is_rr (insn
, op_bcr
, &r1
, &r2
)
1499 || is_rx (insn
, op_bc
, &r1
, &d2
, &x2
, &b2
)
1500 || is_rr (insn
, op_bctr
, &r1
, &r2
)
1501 || is_rre (insn
, op_bctgr
, &r1
, &r2
)
1502 || is_rx (insn
, op_bct
, &r1
, &d2
, &x2
, &b2
)
1503 || is_rxy (insn
, op1_bctg
, op2_brctg
, &r1
, &d2
, &x2
, &b2
)
1504 || is_rs (insn
, op_bxh
, &r1
, &r3
, &d2
, &b2
)
1505 || is_rsy (insn
, op1_bxhg
, op2_bxhg
, &r1
, &r3
, &d2
, &b2
)
1506 || is_rs (insn
, op_bxle
, &r1
, &r3
, &d2
, &b2
)
1507 || is_rsy (insn
, op1_bxleg
, op2_bxleg
, &r1
, &r3
, &d2
, &b2
))
1509 /* Update PC iff branch was *not* taken. */
1510 if (pc
== to
+ insnlen
)
1511 regcache_write_pc (regs
, from
+ insnlen
);
1514 /* Handle PC-relative branch and save instructions. */
1515 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
)
1516 || is_ril (insn
, op1_brasl
, op2_brasl
, &r1
, &i2
))
1519 regcache_write_pc (regs
, pc
- to
+ from
);
1520 /* Recompute saved return address in R1. */
1521 regcache_cooked_write_unsigned (regs
, S390_R0_REGNUM
+ r1
,
1522 amode
| (from
+ insnlen
));
1525 /* Handle PC-relative branch instructions. */
1526 else if (is_ri (insn
, op1_brc
, op2_brc
, &r1
, &i2
)
1527 || is_ril (insn
, op1_brcl
, op2_brcl
, &r1
, &i2
)
1528 || is_ri (insn
, op1_brct
, op2_brct
, &r1
, &i2
)
1529 || is_ri (insn
, op1_brctg
, op2_brctg
, &r1
, &i2
)
1530 || is_rsi (insn
, op_brxh
, &r1
, &r3
, &i2
)
1531 || is_rie (insn
, op1_brxhg
, op2_brxhg
, &r1
, &r3
, &i2
)
1532 || is_rsi (insn
, op_brxle
, &r1
, &r3
, &i2
)
1533 || is_rie (insn
, op1_brxlg
, op2_brxlg
, &r1
, &r3
, &i2
))
1536 regcache_write_pc (regs
, pc
- to
+ from
);
1539 /* Handle LOAD ADDRESS RELATIVE LONG. */
1540 else if (is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1543 regcache_write_pc (regs
, from
+ insnlen
);
1544 /* Recompute output address in R1. */
1545 regcache_cooked_write_unsigned (regs
, S390_R0_REGNUM
+ r1
,
1546 amode
| (from
+ i2
* 2));
1549 /* If we executed a breakpoint instruction, point PC right back at it. */
1550 else if (insn
[0] == 0x0 && insn
[1] == 0x1)
1551 regcache_write_pc (regs
, from
);
1553 /* For any other insn, PC points right after the original instruction. */
1555 regcache_write_pc (regs
, from
+ insnlen
);
1557 if (debug_displaced
)
1558 fprintf_unfiltered (gdb_stdlog
,
1559 "displaced: (s390) pc is now %s\n",
1560 paddress (gdbarch
, regcache_read_pc (regs
)));
1564 /* Helper routine to unwind pseudo registers. */
1566 static struct value
*
1567 s390_unwind_pseudo_register (struct frame_info
*this_frame
, int regnum
)
1569 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1570 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1571 struct type
*type
= register_type (gdbarch
, regnum
);
1573 /* Unwind PC via PSW address. */
1574 if (regnum
== tdep
->pc_regnum
)
1578 val
= frame_unwind_register_value (this_frame
, S390_PSWA_REGNUM
);
1579 if (!value_optimized_out (val
))
1581 LONGEST pswa
= value_as_long (val
);
1583 if (TYPE_LENGTH (type
) == 4)
1584 return value_from_pointer (type
, pswa
& 0x7fffffff);
1586 return value_from_pointer (type
, pswa
);
1590 /* Unwind CC via PSW mask. */
1591 if (regnum
== tdep
->cc_regnum
)
1595 val
= frame_unwind_register_value (this_frame
, S390_PSWM_REGNUM
);
1596 if (!value_optimized_out (val
))
1598 LONGEST pswm
= value_as_long (val
);
1600 if (TYPE_LENGTH (type
) == 4)
1601 return value_from_longest (type
, (pswm
>> 12) & 3);
1603 return value_from_longest (type
, (pswm
>> 44) & 3);
1607 /* Unwind full GPRs to show at least the lower halves (as the
1608 upper halves are undefined). */
1609 if (regnum_is_gpr_full (tdep
, regnum
))
1611 int reg
= regnum
- tdep
->gpr_full_regnum
;
1614 val
= frame_unwind_register_value (this_frame
, S390_R0_REGNUM
+ reg
);
1615 if (!value_optimized_out (val
))
1616 return value_cast (type
, val
);
1619 return allocate_optimized_out_value (type
);
1622 static struct value
*
1623 s390_trad_frame_prev_register (struct frame_info
*this_frame
,
1624 struct trad_frame_saved_reg saved_regs
[],
1627 if (regnum
< S390_NUM_REGS
)
1628 return trad_frame_get_prev_register (this_frame
, saved_regs
, regnum
);
1630 return s390_unwind_pseudo_register (this_frame
, regnum
);
1634 /* Normal stack frames. */
1636 struct s390_unwind_cache
{
1639 CORE_ADDR frame_base
;
1640 CORE_ADDR local_base
;
1642 struct trad_frame_saved_reg
*saved_regs
;
1646 s390_prologue_frame_unwind_cache (struct frame_info
*this_frame
,
1647 struct s390_unwind_cache
*info
)
1649 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1650 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1651 struct s390_prologue_data data
;
1652 pv_t
*fp
= &data
.gpr
[S390_FRAME_REGNUM
- S390_R0_REGNUM
];
1653 pv_t
*sp
= &data
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1662 struct frame_info
*next_frame
;
1664 /* Try to find the function start address. If we can't find it, we don't
1665 bother searching for it -- with modern compilers this would be mostly
1666 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1667 or else a valid backchain ... */
1668 func
= get_frame_func (this_frame
);
1672 /* Try to analyze the prologue. */
1673 result
= s390_analyze_prologue (gdbarch
, func
,
1674 get_frame_pc (this_frame
), &data
);
1678 /* If this was successful, we should have found the instruction that
1679 sets the stack pointer register to the previous value of the stack
1680 pointer minus the frame size. */
1681 if (!pv_is_register (*sp
, S390_SP_REGNUM
))
1684 /* A frame size of zero at this point can mean either a real
1685 frameless function, or else a failure to find the prologue.
1686 Perform some sanity checks to verify we really have a
1687 frameless function. */
1690 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1691 size zero. This is only possible if the next frame is a sentinel
1692 frame, a dummy frame, or a signal trampoline frame. */
1693 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1694 needed, instead the code should simpliy rely on its
1696 next_frame
= get_next_frame (this_frame
);
1697 while (next_frame
&& get_frame_type (next_frame
) == INLINE_FRAME
)
1698 next_frame
= get_next_frame (next_frame
);
1700 && get_frame_type (get_next_frame (this_frame
)) == NORMAL_FRAME
)
1703 /* If we really have a frameless function, %r14 must be valid
1704 -- in particular, it must point to a different function. */
1705 reg
= get_frame_register_unsigned (this_frame
, S390_RETADDR_REGNUM
);
1706 reg
= gdbarch_addr_bits_remove (gdbarch
, reg
) - 1;
1707 if (get_pc_function_start (reg
) == func
)
1709 /* However, there is one case where it *is* valid for %r14
1710 to point to the same function -- if this is a recursive
1711 call, and we have stopped in the prologue *before* the
1712 stack frame was allocated.
1714 Recognize this case by looking ahead a bit ... */
1716 struct s390_prologue_data data2
;
1717 pv_t
*sp
= &data2
.gpr
[S390_SP_REGNUM
- S390_R0_REGNUM
];
1719 if (!(s390_analyze_prologue (gdbarch
, func
, (CORE_ADDR
)-1, &data2
)
1720 && pv_is_register (*sp
, S390_SP_REGNUM
)
1727 /* OK, we've found valid prologue data. */
1730 /* If the frame pointer originally also holds the same value
1731 as the stack pointer, we're probably using it. If it holds
1732 some other value -- even a constant offset -- it is most
1733 likely used as temp register. */
1734 if (pv_is_identical (*sp
, *fp
))
1735 frame_pointer
= S390_FRAME_REGNUM
;
1737 frame_pointer
= S390_SP_REGNUM
;
1739 /* If we've detected a function with stack frame, we'll still have to
1740 treat it as frameless if we're currently within the function epilog
1741 code at a point where the frame pointer has already been restored.
1742 This can only happen in an innermost frame. */
1743 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1744 instead the code should simpliy rely on its analysis. */
1745 next_frame
= get_next_frame (this_frame
);
1746 while (next_frame
&& get_frame_type (next_frame
) == INLINE_FRAME
)
1747 next_frame
= get_next_frame (next_frame
);
1749 && (next_frame
== NULL
1750 || get_frame_type (get_next_frame (this_frame
)) != NORMAL_FRAME
))
1752 /* See the comment in s390_in_function_epilogue_p on why this is
1753 not completely reliable ... */
1754 if (s390_in_function_epilogue_p (gdbarch
, get_frame_pc (this_frame
)))
1756 memset (&data
, 0, sizeof (data
));
1758 frame_pointer
= S390_SP_REGNUM
;
1762 /* Once we know the frame register and the frame size, we can unwind
1763 the current value of the frame register from the next frame, and
1764 add back the frame size to arrive that the previous frame's
1765 stack pointer value. */
1766 prev_sp
= get_frame_register_unsigned (this_frame
, frame_pointer
) + size
;
1767 cfa
= prev_sp
+ 16*word_size
+ 32;
1769 /* Set up ABI call-saved/call-clobbered registers. */
1770 for (i
= 0; i
< S390_NUM_REGS
; i
++)
1771 if (!s390_register_call_saved (gdbarch
, i
))
1772 trad_frame_set_unknown (info
->saved_regs
, i
);
1774 /* CC is always call-clobbered. */
1775 trad_frame_set_unknown (info
->saved_regs
, S390_PSWM_REGNUM
);
1777 /* Record the addresses of all register spill slots the prologue parser
1778 has recognized. Consider only registers defined as call-saved by the
1779 ABI; for call-clobbered registers the parser may have recognized
1782 for (i
= 0; i
< 16; i
++)
1783 if (s390_register_call_saved (gdbarch
, S390_R0_REGNUM
+ i
)
1784 && data
.gpr_slot
[i
] != 0)
1785 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= cfa
- data
.gpr_slot
[i
];
1787 for (i
= 0; i
< 16; i
++)
1788 if (s390_register_call_saved (gdbarch
, S390_F0_REGNUM
+ i
)
1789 && data
.fpr_slot
[i
] != 0)
1790 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= cfa
- data
.fpr_slot
[i
];
1792 /* Function return will set PC to %r14. */
1793 info
->saved_regs
[S390_PSWA_REGNUM
] = info
->saved_regs
[S390_RETADDR_REGNUM
];
1795 /* In frameless functions, we unwind simply by moving the return
1796 address to the PC. However, if we actually stored to the
1797 save area, use that -- we might only think the function frameless
1798 because we're in the middle of the prologue ... */
1800 && !trad_frame_addr_p (info
->saved_regs
, S390_PSWA_REGNUM
))
1802 info
->saved_regs
[S390_PSWA_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1805 /* Another sanity check: unless this is a frameless function,
1806 we should have found spill slots for SP and PC.
1807 If not, we cannot unwind further -- this happens e.g. in
1808 libc's thread_start routine. */
1811 if (!trad_frame_addr_p (info
->saved_regs
, S390_SP_REGNUM
)
1812 || !trad_frame_addr_p (info
->saved_regs
, S390_PSWA_REGNUM
))
1816 /* We use the current value of the frame register as local_base,
1817 and the top of the register save area as frame_base. */
1820 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
1821 info
->local_base
= prev_sp
- size
;
1829 s390_backchain_frame_unwind_cache (struct frame_info
*this_frame
,
1830 struct s390_unwind_cache
*info
)
1832 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1833 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1834 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1835 CORE_ADDR backchain
;
1840 /* Set up ABI call-saved/call-clobbered registers. */
1841 for (i
= 0; i
< S390_NUM_REGS
; i
++)
1842 if (!s390_register_call_saved (gdbarch
, i
))
1843 trad_frame_set_unknown (info
->saved_regs
, i
);
1845 /* CC is always call-clobbered. */
1846 trad_frame_set_unknown (info
->saved_regs
, S390_PSWM_REGNUM
);
1848 /* Get the backchain. */
1849 reg
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
1850 backchain
= read_memory_unsigned_integer (reg
, word_size
, byte_order
);
1852 /* A zero backchain terminates the frame chain. As additional
1853 sanity check, let's verify that the spill slot for SP in the
1854 save area pointed to by the backchain in fact links back to
1857 && safe_read_memory_integer (backchain
+ 15*word_size
,
1858 word_size
, byte_order
, &sp
)
1859 && (CORE_ADDR
)sp
== backchain
)
1861 /* We don't know which registers were saved, but it will have
1862 to be at least %r14 and %r15. This will allow us to continue
1863 unwinding, but other prev-frame registers may be incorrect ... */
1864 info
->saved_regs
[S390_SP_REGNUM
].addr
= backchain
+ 15*word_size
;
1865 info
->saved_regs
[S390_RETADDR_REGNUM
].addr
= backchain
+ 14*word_size
;
1867 /* Function return will set PC to %r14. */
1868 info
->saved_regs
[S390_PSWA_REGNUM
]
1869 = info
->saved_regs
[S390_RETADDR_REGNUM
];
1871 /* We use the current value of the frame register as local_base,
1872 and the top of the register save area as frame_base. */
1873 info
->frame_base
= backchain
+ 16*word_size
+ 32;
1874 info
->local_base
= reg
;
1877 info
->func
= get_frame_pc (this_frame
);
1880 static struct s390_unwind_cache
*
1881 s390_frame_unwind_cache (struct frame_info
*this_frame
,
1882 void **this_prologue_cache
)
1884 volatile struct gdb_exception ex
;
1885 struct s390_unwind_cache
*info
;
1887 if (*this_prologue_cache
)
1888 return *this_prologue_cache
;
1890 info
= FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache
);
1891 *this_prologue_cache
= info
;
1892 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1894 info
->frame_base
= -1;
1895 info
->local_base
= -1;
1897 TRY_CATCH (ex
, RETURN_MASK_ERROR
)
1899 /* Try to use prologue analysis to fill the unwind cache.
1900 If this fails, fall back to reading the stack backchain. */
1901 if (!s390_prologue_frame_unwind_cache (this_frame
, info
))
1902 s390_backchain_frame_unwind_cache (this_frame
, info
);
1904 if (ex
.reason
< 0 && ex
.error
!= NOT_AVAILABLE_ERROR
)
1905 throw_exception (ex
);
1911 s390_frame_this_id (struct frame_info
*this_frame
,
1912 void **this_prologue_cache
,
1913 struct frame_id
*this_id
)
1915 struct s390_unwind_cache
*info
1916 = s390_frame_unwind_cache (this_frame
, this_prologue_cache
);
1918 if (info
->frame_base
== -1)
1921 *this_id
= frame_id_build (info
->frame_base
, info
->func
);
1924 static struct value
*
1925 s390_frame_prev_register (struct frame_info
*this_frame
,
1926 void **this_prologue_cache
, int regnum
)
1928 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1929 struct s390_unwind_cache
*info
1930 = s390_frame_unwind_cache (this_frame
, this_prologue_cache
);
1932 return s390_trad_frame_prev_register (this_frame
, info
->saved_regs
, regnum
);
1935 static const struct frame_unwind s390_frame_unwind
= {
1937 default_frame_unwind_stop_reason
,
1939 s390_frame_prev_register
,
1941 default_frame_sniffer
1945 /* Code stubs and their stack frames. For things like PLTs and NULL
1946 function calls (where there is no true frame and the return address
1947 is in the RETADDR register). */
1949 struct s390_stub_unwind_cache
1951 CORE_ADDR frame_base
;
1952 struct trad_frame_saved_reg
*saved_regs
;
1955 static struct s390_stub_unwind_cache
*
1956 s390_stub_frame_unwind_cache (struct frame_info
*this_frame
,
1957 void **this_prologue_cache
)
1959 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1960 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
1961 struct s390_stub_unwind_cache
*info
;
1964 if (*this_prologue_cache
)
1965 return *this_prologue_cache
;
1967 info
= FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache
);
1968 *this_prologue_cache
= info
;
1969 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
1971 /* The return address is in register %r14. */
1972 info
->saved_regs
[S390_PSWA_REGNUM
].realreg
= S390_RETADDR_REGNUM
;
1974 /* Retrieve stack pointer and determine our frame base. */
1975 reg
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
1976 info
->frame_base
= reg
+ 16*word_size
+ 32;
1982 s390_stub_frame_this_id (struct frame_info
*this_frame
,
1983 void **this_prologue_cache
,
1984 struct frame_id
*this_id
)
1986 struct s390_stub_unwind_cache
*info
1987 = s390_stub_frame_unwind_cache (this_frame
, this_prologue_cache
);
1988 *this_id
= frame_id_build (info
->frame_base
, get_frame_pc (this_frame
));
1991 static struct value
*
1992 s390_stub_frame_prev_register (struct frame_info
*this_frame
,
1993 void **this_prologue_cache
, int regnum
)
1995 struct s390_stub_unwind_cache
*info
1996 = s390_stub_frame_unwind_cache (this_frame
, this_prologue_cache
);
1997 return s390_trad_frame_prev_register (this_frame
, info
->saved_regs
, regnum
);
2001 s390_stub_frame_sniffer (const struct frame_unwind
*self
,
2002 struct frame_info
*this_frame
,
2003 void **this_prologue_cache
)
2005 CORE_ADDR addr_in_block
;
2006 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
2008 /* If the current PC points to non-readable memory, we assume we
2009 have trapped due to an invalid function pointer call. We handle
2010 the non-existing current function like a PLT stub. */
2011 addr_in_block
= get_frame_address_in_block (this_frame
);
2012 if (in_plt_section (addr_in_block
)
2013 || s390_readinstruction (insn
, get_frame_pc (this_frame
)) < 0)
2018 static const struct frame_unwind s390_stub_frame_unwind
= {
2020 default_frame_unwind_stop_reason
,
2021 s390_stub_frame_this_id
,
2022 s390_stub_frame_prev_register
,
2024 s390_stub_frame_sniffer
2028 /* Signal trampoline stack frames. */
2030 struct s390_sigtramp_unwind_cache
{
2031 CORE_ADDR frame_base
;
2032 struct trad_frame_saved_reg
*saved_regs
;
2035 static struct s390_sigtramp_unwind_cache
*
2036 s390_sigtramp_frame_unwind_cache (struct frame_info
*this_frame
,
2037 void **this_prologue_cache
)
2039 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2040 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2041 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2042 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2043 struct s390_sigtramp_unwind_cache
*info
;
2044 ULONGEST this_sp
, prev_sp
;
2045 CORE_ADDR next_ra
, next_cfa
, sigreg_ptr
, sigreg_high_off
;
2048 if (*this_prologue_cache
)
2049 return *this_prologue_cache
;
2051 info
= FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache
);
2052 *this_prologue_cache
= info
;
2053 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2055 this_sp
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
2056 next_ra
= get_frame_pc (this_frame
);
2057 next_cfa
= this_sp
+ 16*word_size
+ 32;
2059 /* New-style RT frame:
2060 retcode + alignment (8 bytes)
2062 ucontext (contains sigregs at offset 5 words). */
2063 if (next_ra
== next_cfa
)
2065 sigreg_ptr
= next_cfa
+ 8 + 128 + align_up (5*word_size
, 8);
2066 /* sigregs are followed by uc_sigmask (8 bytes), then by the
2067 upper GPR halves if present. */
2068 sigreg_high_off
= 8;
2071 /* Old-style RT frame and all non-RT frames:
2072 old signal mask (8 bytes)
2073 pointer to sigregs. */
2076 sigreg_ptr
= read_memory_unsigned_integer (next_cfa
+ 8,
2077 word_size
, byte_order
);
2078 /* sigregs are followed by signo (4 bytes), then by the
2079 upper GPR halves if present. */
2080 sigreg_high_off
= 4;
2083 /* The sigregs structure looks like this:
2092 /* PSW mask and address. */
2093 info
->saved_regs
[S390_PSWM_REGNUM
].addr
= sigreg_ptr
;
2094 sigreg_ptr
+= word_size
;
2095 info
->saved_regs
[S390_PSWA_REGNUM
].addr
= sigreg_ptr
;
2096 sigreg_ptr
+= word_size
;
2098 /* Then the GPRs. */
2099 for (i
= 0; i
< 16; i
++)
2101 info
->saved_regs
[S390_R0_REGNUM
+ i
].addr
= sigreg_ptr
;
2102 sigreg_ptr
+= word_size
;
2105 /* Then the ACRs. */
2106 for (i
= 0; i
< 16; i
++)
2108 info
->saved_regs
[S390_A0_REGNUM
+ i
].addr
= sigreg_ptr
;
2112 /* The floating-point control word. */
2113 info
->saved_regs
[S390_FPC_REGNUM
].addr
= sigreg_ptr
;
2116 /* And finally the FPRs. */
2117 for (i
= 0; i
< 16; i
++)
2119 info
->saved_regs
[S390_F0_REGNUM
+ i
].addr
= sigreg_ptr
;
2123 /* If we have them, the GPR upper halves are appended at the end. */
2124 sigreg_ptr
+= sigreg_high_off
;
2125 if (tdep
->gpr_full_regnum
!= -1)
2126 for (i
= 0; i
< 16; i
++)
2128 info
->saved_regs
[S390_R0_UPPER_REGNUM
+ i
].addr
= sigreg_ptr
;
2132 /* Restore the previous frame's SP. */
2133 prev_sp
= read_memory_unsigned_integer (
2134 info
->saved_regs
[S390_SP_REGNUM
].addr
,
2135 word_size
, byte_order
);
2137 /* Determine our frame base. */
2138 info
->frame_base
= prev_sp
+ 16*word_size
+ 32;
2144 s390_sigtramp_frame_this_id (struct frame_info
*this_frame
,
2145 void **this_prologue_cache
,
2146 struct frame_id
*this_id
)
2148 struct s390_sigtramp_unwind_cache
*info
2149 = s390_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
2150 *this_id
= frame_id_build (info
->frame_base
, get_frame_pc (this_frame
));
2153 static struct value
*
2154 s390_sigtramp_frame_prev_register (struct frame_info
*this_frame
,
2155 void **this_prologue_cache
, int regnum
)
2157 struct s390_sigtramp_unwind_cache
*info
2158 = s390_sigtramp_frame_unwind_cache (this_frame
, this_prologue_cache
);
2159 return s390_trad_frame_prev_register (this_frame
, info
->saved_regs
, regnum
);
2163 s390_sigtramp_frame_sniffer (const struct frame_unwind
*self
,
2164 struct frame_info
*this_frame
,
2165 void **this_prologue_cache
)
2167 CORE_ADDR pc
= get_frame_pc (this_frame
);
2168 bfd_byte sigreturn
[2];
2170 if (target_read_memory (pc
, sigreturn
, 2))
2173 if (sigreturn
[0] != op_svc
)
2176 if (sigreturn
[1] != 119 /* sigreturn */
2177 && sigreturn
[1] != 173 /* rt_sigreturn */)
2183 static const struct frame_unwind s390_sigtramp_frame_unwind
= {
2185 default_frame_unwind_stop_reason
,
2186 s390_sigtramp_frame_this_id
,
2187 s390_sigtramp_frame_prev_register
,
2189 s390_sigtramp_frame_sniffer
2192 /* Retrieve the syscall number at a ptrace syscall-stop. Return -1
2196 s390_linux_get_syscall_number (struct gdbarch
*gdbarch
,
2199 struct regcache
*regs
= get_thread_regcache (ptid
);
2200 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2201 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2203 ULONGEST svc_number
= -1;
2206 /* Assume that the PC points after the 2-byte SVC instruction. We
2207 don't currently support SVC via EXECUTE. */
2208 regcache_cooked_read_unsigned (regs
, tdep
->pc_regnum
, &pc
);
2210 opcode
= read_memory_unsigned_integer ((CORE_ADDR
) pc
, 1, byte_order
);
2211 if (opcode
!= op_svc
)
2214 svc_number
= read_memory_unsigned_integer ((CORE_ADDR
) pc
+ 1, 1,
2216 if (svc_number
== 0)
2217 regcache_cooked_read_unsigned (regs
, S390_R1_REGNUM
, &svc_number
);
2223 /* Frame base handling. */
2226 s390_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
2228 struct s390_unwind_cache
*info
2229 = s390_frame_unwind_cache (this_frame
, this_cache
);
2230 return info
->frame_base
;
2234 s390_local_base_address (struct frame_info
*this_frame
, void **this_cache
)
2236 struct s390_unwind_cache
*info
2237 = s390_frame_unwind_cache (this_frame
, this_cache
);
2238 return info
->local_base
;
2241 static const struct frame_base s390_frame_base
= {
2243 s390_frame_base_address
,
2244 s390_local_base_address
,
2245 s390_local_base_address
2249 s390_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2251 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2253 pc
= frame_unwind_register_unsigned (next_frame
, tdep
->pc_regnum
);
2254 return gdbarch_addr_bits_remove (gdbarch
, pc
);
2258 s390_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
2261 sp
= frame_unwind_register_unsigned (next_frame
, S390_SP_REGNUM
);
2262 return gdbarch_addr_bits_remove (gdbarch
, sp
);
2266 /* DWARF-2 frame support. */
2268 static struct value
*
2269 s390_dwarf2_prev_register (struct frame_info
*this_frame
, void **this_cache
,
2272 return s390_unwind_pseudo_register (this_frame
, regnum
);
2276 s390_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
2277 struct dwarf2_frame_state_reg
*reg
,
2278 struct frame_info
*this_frame
)
2280 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2282 /* The condition code (and thus PSW mask) is call-clobbered. */
2283 if (regnum
== S390_PSWM_REGNUM
)
2284 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
2286 /* The PSW address unwinds to the return address. */
2287 else if (regnum
== S390_PSWA_REGNUM
)
2288 reg
->how
= DWARF2_FRAME_REG_RA
;
2290 /* Fixed registers are call-saved or call-clobbered
2291 depending on the ABI in use. */
2292 else if (regnum
< S390_NUM_REGS
)
2294 if (s390_register_call_saved (gdbarch
, regnum
))
2295 reg
->how
= DWARF2_FRAME_REG_SAME_VALUE
;
2297 reg
->how
= DWARF2_FRAME_REG_UNDEFINED
;
2300 /* We install a special function to unwind pseudos. */
2303 reg
->how
= DWARF2_FRAME_REG_FN
;
2304 reg
->loc
.fn
= s390_dwarf2_prev_register
;
2309 /* Dummy function calls. */
2311 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
2312 "Integer-like" types are those that should be passed the way
2313 integers are: integers, enums, ranges, characters, and booleans. */
2315 is_integer_like (struct type
*type
)
2317 enum type_code code
= TYPE_CODE (type
);
2319 return (code
== TYPE_CODE_INT
2320 || code
== TYPE_CODE_ENUM
2321 || code
== TYPE_CODE_RANGE
2322 || code
== TYPE_CODE_CHAR
2323 || code
== TYPE_CODE_BOOL
);
2326 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
2327 "Pointer-like" types are those that should be passed the way
2328 pointers are: pointers and references. */
2330 is_pointer_like (struct type
*type
)
2332 enum type_code code
= TYPE_CODE (type
);
2334 return (code
== TYPE_CODE_PTR
2335 || code
== TYPE_CODE_REF
);
2339 /* Return non-zero if TYPE is a `float singleton' or `double
2340 singleton', zero otherwise.
2342 A `T singleton' is a struct type with one member, whose type is
2343 either T or a `T singleton'. So, the following are all float
2347 struct { struct { float x; } x; };
2348 struct { struct { struct { float x; } x; } x; };
2352 All such structures are passed as if they were floats or doubles,
2353 as the (revised) ABI says. */
2355 is_float_singleton (struct type
*type
)
2357 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& TYPE_NFIELDS (type
) == 1)
2359 struct type
*singleton_type
= TYPE_FIELD_TYPE (type
, 0);
2360 CHECK_TYPEDEF (singleton_type
);
2362 return (TYPE_CODE (singleton_type
) == TYPE_CODE_FLT
2363 || TYPE_CODE (singleton_type
) == TYPE_CODE_DECFLOAT
2364 || is_float_singleton (singleton_type
));
2371 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
2372 "Struct-like" types are those that should be passed as structs are:
2375 As an odd quirk, not mentioned in the ABI, GCC passes float and
2376 double singletons as if they were a plain float, double, etc. (The
2377 corresponding union types are handled normally.) So we exclude
2378 those types here. *shrug* */
2380 is_struct_like (struct type
*type
)
2382 enum type_code code
= TYPE_CODE (type
);
2384 return (code
== TYPE_CODE_UNION
2385 || (code
== TYPE_CODE_STRUCT
&& ! is_float_singleton (type
)));
2389 /* Return non-zero if TYPE is a float-like type, zero otherwise.
2390 "Float-like" types are those that should be passed as
2391 floating-point values are.
2393 You'd think this would just be floats, doubles, long doubles, etc.
2394 But as an odd quirk, not mentioned in the ABI, GCC passes float and
2395 double singletons as if they were a plain float, double, etc. (The
2396 corresponding union types are handled normally.) So we include
2397 those types here. *shrug* */
2399 is_float_like (struct type
*type
)
2401 return (TYPE_CODE (type
) == TYPE_CODE_FLT
2402 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
2403 || is_float_singleton (type
));
2408 is_power_of_two (unsigned int n
)
2410 return ((n
& (n
- 1)) == 0);
2413 /* Return non-zero if TYPE should be passed as a pointer to a copy,
2416 s390_function_arg_pass_by_reference (struct type
*type
)
2418 if (TYPE_LENGTH (type
) > 8)
2421 return (is_struct_like (type
) && !is_power_of_two (TYPE_LENGTH (type
)))
2422 || TYPE_CODE (type
) == TYPE_CODE_COMPLEX
2423 || (TYPE_CODE (type
) == TYPE_CODE_ARRAY
&& TYPE_VECTOR (type
));
2426 /* Return non-zero if TYPE should be passed in a float register
2429 s390_function_arg_float (struct type
*type
)
2431 if (TYPE_LENGTH (type
) > 8)
2434 return is_float_like (type
);
2437 /* Return non-zero if TYPE should be passed in an integer register
2438 (or a pair of integer registers) if possible. */
2440 s390_function_arg_integer (struct type
*type
)
2442 if (TYPE_LENGTH (type
) > 8)
2445 return is_integer_like (type
)
2446 || is_pointer_like (type
)
2447 || (is_struct_like (type
) && is_power_of_two (TYPE_LENGTH (type
)));
2450 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
2451 word as required for the ABI. */
2453 extend_simple_arg (struct gdbarch
*gdbarch
, struct value
*arg
)
2455 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2456 struct type
*type
= check_typedef (value_type (arg
));
2458 /* Even structs get passed in the least significant bits of the
2459 register / memory word. It's not really right to extract them as
2460 an integer, but it does take care of the extension. */
2461 if (TYPE_UNSIGNED (type
))
2462 return extract_unsigned_integer (value_contents (arg
),
2463 TYPE_LENGTH (type
), byte_order
);
2465 return extract_signed_integer (value_contents (arg
),
2466 TYPE_LENGTH (type
), byte_order
);
2470 /* Return the alignment required by TYPE. */
2472 alignment_of (struct type
*type
)
2476 if (is_integer_like (type
)
2477 || is_pointer_like (type
)
2478 || TYPE_CODE (type
) == TYPE_CODE_FLT
2479 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
2480 alignment
= TYPE_LENGTH (type
);
2481 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
2482 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
2487 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
2490 = alignment_of (check_typedef (TYPE_FIELD_TYPE (type
, i
)));
2492 if (field_alignment
> alignment
)
2493 alignment
= field_alignment
;
2499 /* Check that everything we ever return is a power of two. Lots of
2500 code doesn't want to deal with aligning things to arbitrary
2502 gdb_assert ((alignment
& (alignment
- 1)) == 0);
2508 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2509 place to be passed to a function, as specified by the "GNU/Linux
2510 for S/390 ELF Application Binary Interface Supplement".
2512 SP is the current stack pointer. We must put arguments, links,
2513 padding, etc. whereever they belong, and return the new stack
2516 If STRUCT_RETURN is non-zero, then the function we're calling is
2517 going to return a structure by value; STRUCT_ADDR is the address of
2518 a block we've allocated for it on the stack.
2520 Our caller has taken care of any type promotions needed to satisfy
2521 prototypes or the old K&R argument-passing rules. */
2523 s390_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
2524 struct regcache
*regcache
, CORE_ADDR bp_addr
,
2525 int nargs
, struct value
**args
, CORE_ADDR sp
,
2526 int struct_return
, CORE_ADDR struct_addr
)
2528 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
2529 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2530 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2533 /* If the i'th argument is passed as a reference to a copy, then
2534 copy_addr[i] is the address of the copy we made. */
2535 CORE_ADDR
*copy_addr
= alloca (nargs
* sizeof (CORE_ADDR
));
2537 /* Reserve space for the reference-to-copy area. */
2538 for (i
= 0; i
< nargs
; i
++)
2540 struct value
*arg
= args
[i
];
2541 struct type
*type
= check_typedef (value_type (arg
));
2543 if (s390_function_arg_pass_by_reference (type
))
2545 sp
-= TYPE_LENGTH (type
);
2546 sp
= align_down (sp
, alignment_of (type
));
2551 /* Reserve space for the parameter area. As a conservative
2552 simplification, we assume that everything will be passed on the
2553 stack. Since every argument larger than 8 bytes will be
2554 passed by reference, we use this simple upper bound. */
2557 /* After all that, make sure it's still aligned on an eight-byte
2559 sp
= align_down (sp
, 8);
2561 /* Allocate the standard frame areas: the register save area, the
2562 word reserved for the compiler (which seems kind of meaningless),
2563 and the back chain pointer. */
2564 sp
-= 16*word_size
+ 32;
2566 /* Now we have the final SP value. Make sure we didn't underflow;
2567 on 31-bit, this would result in addresses with the high bit set,
2568 which causes confusion elsewhere. Note that if we error out
2569 here, stack and registers remain untouched. */
2570 if (gdbarch_addr_bits_remove (gdbarch
, sp
) != sp
)
2571 error (_("Stack overflow"));
2574 /* Finally, place the actual parameters, working from SP towards
2575 higher addresses. The code above is supposed to reserve enough
2580 CORE_ADDR starg
= sp
+ 16*word_size
+ 32;
2582 /* A struct is returned using general register 2. */
2585 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2590 for (i
= 0; i
< nargs
; i
++)
2592 struct value
*arg
= args
[i
];
2593 struct type
*type
= check_typedef (value_type (arg
));
2594 unsigned length
= TYPE_LENGTH (type
);
2596 if (s390_function_arg_pass_by_reference (type
))
2598 /* Actually copy the argument contents to the stack slot
2599 that was reserved above. */
2600 write_memory (copy_addr
[i
], value_contents (arg
), length
);
2604 regcache_cooked_write_unsigned (regcache
, S390_R0_REGNUM
+ gr
,
2610 write_memory_unsigned_integer (starg
, word_size
, byte_order
,
2615 else if (s390_function_arg_float (type
))
2617 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2618 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2619 if (fr
<= (tdep
->abi
== ABI_LINUX_S390
? 2 : 6))
2621 /* When we store a single-precision value in an FP register,
2622 it occupies the leftmost bits. */
2623 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
+ fr
,
2624 0, length
, value_contents (arg
));
2629 /* When we store a single-precision value in a stack slot,
2630 it occupies the rightmost bits. */
2631 starg
= align_up (starg
+ length
, word_size
);
2632 write_memory (starg
- length
, value_contents (arg
), length
);
2635 else if (s390_function_arg_integer (type
) && length
<= word_size
)
2639 /* Integer arguments are always extended to word size. */
2640 regcache_cooked_write_signed (regcache
, S390_R0_REGNUM
+ gr
,
2641 extend_simple_arg (gdbarch
,
2647 /* Integer arguments are always extended to word size. */
2648 write_memory_signed_integer (starg
, word_size
, byte_order
,
2649 extend_simple_arg (gdbarch
, arg
));
2653 else if (s390_function_arg_integer (type
) && length
== 2*word_size
)
2657 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
,
2658 value_contents (arg
));
2659 regcache_cooked_write (regcache
, S390_R0_REGNUM
+ gr
+ 1,
2660 value_contents (arg
) + word_size
);
2665 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2666 in it, then don't go back and use it again later. */
2669 write_memory (starg
, value_contents (arg
), length
);
2674 internal_error (__FILE__
, __LINE__
, _("unknown argument type"));
2678 /* Store return PSWA. In 31-bit mode, keep addressing mode bit. */
2682 regcache_cooked_read_unsigned (regcache
, S390_PSWA_REGNUM
, &pswa
);
2683 bp_addr
= (bp_addr
& 0x7fffffff) | (pswa
& 0x80000000);
2685 regcache_cooked_write_unsigned (regcache
, S390_RETADDR_REGNUM
, bp_addr
);
2687 /* Store updated stack pointer. */
2688 regcache_cooked_write_unsigned (regcache
, S390_SP_REGNUM
, sp
);
2690 /* We need to return the 'stack part' of the frame ID,
2691 which is actually the top of the register save area. */
2692 return sp
+ 16*word_size
+ 32;
2695 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
2696 dummy frame. The frame ID's base needs to match the TOS value
2697 returned by push_dummy_call, and the PC match the dummy frame's
2699 static struct frame_id
2700 s390_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
2702 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2703 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, S390_SP_REGNUM
);
2704 sp
= gdbarch_addr_bits_remove (gdbarch
, sp
);
2706 return frame_id_build (sp
+ 16*word_size
+ 32,
2707 get_frame_pc (this_frame
));
2711 s390_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2713 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2714 always be aligned on an eight-byte boundary. */
2719 /* Function return value access. */
2721 static enum return_value_convention
2722 s390_return_value_convention (struct gdbarch
*gdbarch
, struct type
*type
)
2724 if (TYPE_LENGTH (type
) > 8)
2725 return RETURN_VALUE_STRUCT_CONVENTION
;
2727 switch (TYPE_CODE (type
))
2729 case TYPE_CODE_STRUCT
:
2730 case TYPE_CODE_UNION
:
2731 case TYPE_CODE_ARRAY
:
2732 case TYPE_CODE_COMPLEX
:
2733 return RETURN_VALUE_STRUCT_CONVENTION
;
2736 return RETURN_VALUE_REGISTER_CONVENTION
;
2740 static enum return_value_convention
2741 s390_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
2742 struct type
*type
, struct regcache
*regcache
,
2743 gdb_byte
*out
, const gdb_byte
*in
)
2745 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2746 int word_size
= gdbarch_ptr_bit (gdbarch
) / 8;
2747 enum return_value_convention rvc
;
2750 type
= check_typedef (type
);
2751 rvc
= s390_return_value_convention (gdbarch
, type
);
2752 length
= TYPE_LENGTH (type
);
2758 case RETURN_VALUE_REGISTER_CONVENTION
:
2759 if (TYPE_CODE (type
) == TYPE_CODE_FLT
2760 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
2762 /* When we store a single-precision value in an FP register,
2763 it occupies the leftmost bits. */
2764 regcache_cooked_write_part (regcache
, S390_F0_REGNUM
,
2767 else if (length
<= word_size
)
2769 /* Integer arguments are always extended to word size. */
2770 if (TYPE_UNSIGNED (type
))
2771 regcache_cooked_write_unsigned (regcache
, S390_R2_REGNUM
,
2772 extract_unsigned_integer (in
, length
, byte_order
));
2774 regcache_cooked_write_signed (regcache
, S390_R2_REGNUM
,
2775 extract_signed_integer (in
, length
, byte_order
));
2777 else if (length
== 2*word_size
)
2779 regcache_cooked_write (regcache
, S390_R2_REGNUM
, in
);
2780 regcache_cooked_write (regcache
, S390_R3_REGNUM
, in
+ word_size
);
2783 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2786 case RETURN_VALUE_STRUCT_CONVENTION
:
2787 error (_("Cannot set function return value."));
2795 case RETURN_VALUE_REGISTER_CONVENTION
:
2796 if (TYPE_CODE (type
) == TYPE_CODE_FLT
2797 || TYPE_CODE (type
) == TYPE_CODE_DECFLOAT
)
2799 /* When we store a single-precision value in an FP register,
2800 it occupies the leftmost bits. */
2801 regcache_cooked_read_part (regcache
, S390_F0_REGNUM
,
2804 else if (length
<= word_size
)
2806 /* Integer arguments occupy the rightmost bits. */
2807 regcache_cooked_read_part (regcache
, S390_R2_REGNUM
,
2808 word_size
- length
, length
, out
);
2810 else if (length
== 2*word_size
)
2812 regcache_cooked_read (regcache
, S390_R2_REGNUM
, out
);
2813 regcache_cooked_read (regcache
, S390_R3_REGNUM
, out
+ word_size
);
2816 internal_error (__FILE__
, __LINE__
, _("invalid return type"));
2819 case RETURN_VALUE_STRUCT_CONVENTION
:
2820 error (_("Function return value unknown."));
2831 static const gdb_byte
*
2832 s390_breakpoint_from_pc (struct gdbarch
*gdbarch
,
2833 CORE_ADDR
*pcptr
, int *lenptr
)
2835 static const gdb_byte breakpoint
[] = { 0x0, 0x1 };
2837 *lenptr
= sizeof (breakpoint
);
2842 /* Address handling. */
2845 s390_addr_bits_remove (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2847 return addr
& 0x7fffffff;
2851 s390_address_class_type_flags (int byte_size
, int dwarf2_addr_class
)
2854 return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
;
2860 s390_address_class_type_flags_to_name (struct gdbarch
*gdbarch
, int type_flags
)
2862 if (type_flags
& TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
)
2869 s390_address_class_name_to_type_flags (struct gdbarch
*gdbarch
,
2871 int *type_flags_ptr
)
2873 if (strcmp (name
, "mode32") == 0)
2875 *type_flags_ptr
= TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1
;
2882 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
2886 s390_stap_is_single_operand (struct gdbarch
*gdbarch
, const char *s
)
2888 return ((isdigit (*s
) && s
[1] == '(' && s
[2] == '%') /* Displacement
2890 || *s
== '%' /* Register access. */
2891 || isdigit (*s
)); /* Literal number. */
2894 /* Set up gdbarch struct. */
2896 static struct gdbarch
*
2897 s390_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2899 const struct target_desc
*tdesc
= info
.target_desc
;
2900 struct tdesc_arch_data
*tdesc_data
= NULL
;
2901 struct gdbarch
*gdbarch
;
2902 struct gdbarch_tdep
*tdep
;
2905 int have_linux_v1
= 0;
2906 int have_linux_v2
= 0;
2907 int first_pseudo_reg
, last_pseudo_reg
;
2908 static const char *const stap_register_prefixes
[] = { "%", NULL
};
2909 static const char *const stap_register_indirection_prefixes
[] = { "(",
2911 static const char *const stap_register_indirection_suffixes
[] = { ")",
2914 /* Default ABI and register size. */
2915 switch (info
.bfd_arch_info
->mach
)
2917 case bfd_mach_s390_31
:
2918 tdep_abi
= ABI_LINUX_S390
;
2921 case bfd_mach_s390_64
:
2922 tdep_abi
= ABI_LINUX_ZSERIES
;
2929 /* Use default target description if none provided by the target. */
2930 if (!tdesc_has_registers (tdesc
))
2932 if (tdep_abi
== ABI_LINUX_S390
)
2933 tdesc
= tdesc_s390_linux32
;
2935 tdesc
= tdesc_s390x_linux64
;
2938 /* Check any target description for validity. */
2939 if (tdesc_has_registers (tdesc
))
2941 static const char *const gprs
[] = {
2942 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
2943 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
2945 static const char *const fprs
[] = {
2946 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
2947 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
2949 static const char *const acrs
[] = {
2950 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
2951 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15"
2953 static const char *const gprs_lower
[] = {
2954 "r0l", "r1l", "r2l", "r3l", "r4l", "r5l", "r6l", "r7l",
2955 "r8l", "r9l", "r10l", "r11l", "r12l", "r13l", "r14l", "r15l"
2957 static const char *const gprs_upper
[] = {
2958 "r0h", "r1h", "r2h", "r3h", "r4h", "r5h", "r6h", "r7h",
2959 "r8h", "r9h", "r10h", "r11h", "r12h", "r13h", "r14h", "r15h"
2961 static const char *const tdb_regs
[] = {
2962 "tdb0", "tac", "tct", "atia",
2963 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7",
2964 "tr8", "tr9", "tr10", "tr11", "tr12", "tr13", "tr14", "tr15"
2966 const struct tdesc_feature
*feature
;
2969 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.core");
2970 if (feature
== NULL
)
2973 tdesc_data
= tdesc_data_alloc ();
2975 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2976 S390_PSWM_REGNUM
, "pswm");
2977 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2978 S390_PSWA_REGNUM
, "pswa");
2980 if (tdesc_unnumbered_register (feature
, "r0"))
2982 for (i
= 0; i
< 16; i
++)
2983 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2984 S390_R0_REGNUM
+ i
, gprs
[i
]);
2990 for (i
= 0; i
< 16; i
++)
2991 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2994 for (i
= 0; i
< 16; i
++)
2995 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
2996 S390_R0_UPPER_REGNUM
+ i
,
3000 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.fpr");
3001 if (feature
== NULL
)
3003 tdesc_data_cleanup (tdesc_data
);
3007 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
3008 S390_FPC_REGNUM
, "fpc");
3009 for (i
= 0; i
< 16; i
++)
3010 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
3011 S390_F0_REGNUM
+ i
, fprs
[i
]);
3013 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.acr");
3014 if (feature
== NULL
)
3016 tdesc_data_cleanup (tdesc_data
);
3020 for (i
= 0; i
< 16; i
++)
3021 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
3022 S390_A0_REGNUM
+ i
, acrs
[i
]);
3024 /* Optional GNU/Linux-specific "registers". */
3025 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.linux");
3028 tdesc_numbered_register (feature
, tdesc_data
,
3029 S390_ORIG_R2_REGNUM
, "orig_r2");
3031 if (tdesc_numbered_register (feature
, tdesc_data
,
3032 S390_LAST_BREAK_REGNUM
, "last_break"))
3035 if (tdesc_numbered_register (feature
, tdesc_data
,
3036 S390_SYSTEM_CALL_REGNUM
, "system_call"))
3039 if (have_linux_v2
> have_linux_v1
)
3043 /* Transaction diagnostic block. */
3044 feature
= tdesc_find_feature (tdesc
, "org.gnu.gdb.s390.tdb");
3047 for (i
= 0; i
< ARRAY_SIZE (tdb_regs
); i
++)
3048 valid_p
&= tdesc_numbered_register (feature
, tdesc_data
,
3049 S390_TDB_DWORD0_REGNUM
+ i
,
3055 tdesc_data_cleanup (tdesc_data
);
3060 /* Find a candidate among extant architectures. */
3061 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
3063 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
3065 tdep
= gdbarch_tdep (arches
->gdbarch
);
3068 if (tdep
->abi
!= tdep_abi
)
3070 if ((tdep
->gpr_full_regnum
!= -1) != have_upper
)
3072 if (tdesc_data
!= NULL
)
3073 tdesc_data_cleanup (tdesc_data
);
3074 return arches
->gdbarch
;
3077 /* Otherwise create a new gdbarch for the specified machine type. */
3078 tdep
= XCNEW (struct gdbarch_tdep
);
3079 tdep
->abi
= tdep_abi
;
3080 gdbarch
= gdbarch_alloc (&info
, tdep
);
3082 set_gdbarch_believe_pcc_promotion (gdbarch
, 0);
3083 set_gdbarch_char_signed (gdbarch
, 0);
3085 /* S/390 GNU/Linux uses either 64-bit or 128-bit long doubles.
3086 We can safely let them default to 128-bit, since the debug info
3087 will give the size of type actually used in each case. */
3088 set_gdbarch_long_double_bit (gdbarch
, 128);
3089 set_gdbarch_long_double_format (gdbarch
, floatformats_ia64_quad
);
3091 /* Amount PC must be decremented by after a breakpoint. This is
3092 often the number of bytes returned by gdbarch_breakpoint_from_pc but not
3094 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
3095 /* Stack grows downward. */
3096 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
3097 set_gdbarch_breakpoint_from_pc (gdbarch
, s390_breakpoint_from_pc
);
3098 set_gdbarch_skip_prologue (gdbarch
, s390_skip_prologue
);
3099 set_gdbarch_in_function_epilogue_p (gdbarch
, s390_in_function_epilogue_p
);
3101 set_gdbarch_num_regs (gdbarch
, S390_NUM_REGS
);
3102 set_gdbarch_sp_regnum (gdbarch
, S390_SP_REGNUM
);
3103 set_gdbarch_fp0_regnum (gdbarch
, S390_F0_REGNUM
);
3104 set_gdbarch_stab_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
3105 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, s390_dwarf_reg_to_regnum
);
3106 set_gdbarch_value_from_register (gdbarch
, s390_value_from_register
);
3107 set_gdbarch_regset_from_core_section (gdbarch
,
3108 s390_regset_from_core_section
);
3109 set_gdbarch_core_read_description (gdbarch
, s390_core_read_description
);
3110 set_gdbarch_cannot_store_register (gdbarch
, s390_cannot_store_register
);
3111 set_gdbarch_write_pc (gdbarch
, s390_write_pc
);
3112 set_gdbarch_pseudo_register_read (gdbarch
, s390_pseudo_register_read
);
3113 set_gdbarch_pseudo_register_write (gdbarch
, s390_pseudo_register_write
);
3114 set_tdesc_pseudo_register_name (gdbarch
, s390_pseudo_register_name
);
3115 set_tdesc_pseudo_register_type (gdbarch
, s390_pseudo_register_type
);
3116 set_tdesc_pseudo_register_reggroup_p (gdbarch
,
3117 s390_pseudo_register_reggroup_p
);
3118 tdesc_use_registers (gdbarch
, tdesc
, tdesc_data
);
3120 /* Assign pseudo register numbers. */
3121 first_pseudo_reg
= gdbarch_num_regs (gdbarch
);
3122 last_pseudo_reg
= first_pseudo_reg
;
3123 tdep
->gpr_full_regnum
= -1;
3126 tdep
->gpr_full_regnum
= last_pseudo_reg
;
3127 last_pseudo_reg
+= 16;
3129 tdep
->pc_regnum
= last_pseudo_reg
++;
3130 tdep
->cc_regnum
= last_pseudo_reg
++;
3131 set_gdbarch_pc_regnum (gdbarch
, tdep
->pc_regnum
);
3132 set_gdbarch_num_pseudo_regs (gdbarch
, last_pseudo_reg
- first_pseudo_reg
);
3134 /* Inferior function calls. */
3135 set_gdbarch_push_dummy_call (gdbarch
, s390_push_dummy_call
);
3136 set_gdbarch_dummy_id (gdbarch
, s390_dummy_id
);
3137 set_gdbarch_frame_align (gdbarch
, s390_frame_align
);
3138 set_gdbarch_return_value (gdbarch
, s390_return_value
);
3140 /* Syscall handling. */
3141 set_gdbarch_get_syscall_number (gdbarch
, s390_linux_get_syscall_number
);
3143 /* Frame handling. */
3144 dwarf2_frame_set_init_reg (gdbarch
, s390_dwarf2_frame_init_reg
);
3145 dwarf2_frame_set_adjust_regnum (gdbarch
, s390_adjust_frame_regnum
);
3146 dwarf2_append_unwinders (gdbarch
);
3147 frame_base_append_sniffer (gdbarch
, dwarf2_frame_base_sniffer
);
3148 frame_unwind_append_unwinder (gdbarch
, &s390_stub_frame_unwind
);
3149 frame_unwind_append_unwinder (gdbarch
, &s390_sigtramp_frame_unwind
);
3150 frame_unwind_append_unwinder (gdbarch
, &s390_frame_unwind
);
3151 frame_base_set_default (gdbarch
, &s390_frame_base
);
3152 set_gdbarch_unwind_pc (gdbarch
, s390_unwind_pc
);
3153 set_gdbarch_unwind_sp (gdbarch
, s390_unwind_sp
);
3155 /* Displaced stepping. */
3156 set_gdbarch_displaced_step_copy_insn (gdbarch
,
3157 simple_displaced_step_copy_insn
);
3158 set_gdbarch_displaced_step_fixup (gdbarch
, s390_displaced_step_fixup
);
3159 set_gdbarch_displaced_step_free_closure (gdbarch
,
3160 simple_displaced_step_free_closure
);
3161 set_gdbarch_displaced_step_location (gdbarch
,
3162 displaced_step_at_entry_point
);
3163 set_gdbarch_max_insn_length (gdbarch
, S390_MAX_INSTR_SIZE
);
3165 /* Note that GNU/Linux is the only OS supported on this
3167 linux_init_abi (info
, gdbarch
);
3171 case ABI_LINUX_S390
:
3172 tdep
->gregset
= &s390_gregset
;
3173 tdep
->sizeof_gregset
= s390_sizeof_gregset
;
3174 tdep
->fpregset
= &s390_fpregset
;
3175 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
3177 set_gdbarch_addr_bits_remove (gdbarch
, s390_addr_bits_remove
);
3178 set_solib_svr4_fetch_link_map_offsets
3179 (gdbarch
, svr4_ilp32_fetch_link_map_offsets
);
3181 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390
);
3186 set_gdbarch_core_regset_sections (gdbarch
,
3187 s390_linux64v2_regset_sections
);
3188 else if (have_linux_v1
)
3189 set_gdbarch_core_regset_sections (gdbarch
,
3190 s390_linux64v1_regset_sections
);
3192 set_gdbarch_core_regset_sections (gdbarch
,
3193 s390_linux64_regset_sections
);
3198 set_gdbarch_core_regset_sections (gdbarch
,
3199 s390_linux32v2_regset_sections
);
3200 else if (have_linux_v1
)
3201 set_gdbarch_core_regset_sections (gdbarch
,
3202 s390_linux32v1_regset_sections
);
3204 set_gdbarch_core_regset_sections (gdbarch
,
3205 s390_linux32_regset_sections
);
3209 case ABI_LINUX_ZSERIES
:
3210 tdep
->gregset
= &s390_gregset
;
3211 tdep
->sizeof_gregset
= s390x_sizeof_gregset
;
3212 tdep
->fpregset
= &s390_fpregset
;
3213 tdep
->sizeof_fpregset
= s390_sizeof_fpregset
;
3215 set_gdbarch_long_bit (gdbarch
, 64);
3216 set_gdbarch_long_long_bit (gdbarch
, 64);
3217 set_gdbarch_ptr_bit (gdbarch
, 64);
3218 set_solib_svr4_fetch_link_map_offsets
3219 (gdbarch
, svr4_lp64_fetch_link_map_offsets
);
3220 set_gdbarch_address_class_type_flags (gdbarch
,
3221 s390_address_class_type_flags
);
3222 set_gdbarch_address_class_type_flags_to_name (gdbarch
,
3223 s390_address_class_type_flags_to_name
);
3224 set_gdbarch_address_class_name_to_type_flags (gdbarch
,
3225 s390_address_class_name_to_type_flags
);
3227 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_S390
);
3230 set_gdbarch_core_regset_sections (gdbarch
,
3231 s390x_linux64v2_regset_sections
);
3232 else if (have_linux_v1
)
3233 set_gdbarch_core_regset_sections (gdbarch
,
3234 s390x_linux64v1_regset_sections
);
3236 set_gdbarch_core_regset_sections (gdbarch
,
3237 s390x_linux64_regset_sections
);
3241 set_gdbarch_print_insn (gdbarch
, print_insn_s390
);
3243 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
3245 /* Enable TLS support. */
3246 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
3247 svr4_fetch_objfile_link_map
);
3249 set_gdbarch_get_siginfo_type (gdbarch
, linux_get_siginfo_type
);
3251 /* SystemTap functions. */
3252 set_gdbarch_stap_register_prefixes (gdbarch
, stap_register_prefixes
);
3253 set_gdbarch_stap_register_indirection_prefixes (gdbarch
,
3254 stap_register_indirection_prefixes
);
3255 set_gdbarch_stap_register_indirection_suffixes (gdbarch
,
3256 stap_register_indirection_suffixes
);
3257 set_gdbarch_stap_is_single_operand (gdbarch
, s390_stap_is_single_operand
);
3263 extern initialize_file_ftype _initialize_s390_tdep
; /* -Wmissing-prototypes */
3266 _initialize_s390_tdep (void)
3268 /* Hook us into the gdbarch mechanism. */
3269 register_gdbarch_init (bfd_arch_s390
, s390_gdbarch_init
);
3271 /* Initialize the GNU/Linux target descriptions. */
3272 initialize_tdesc_s390_linux32 ();
3273 initialize_tdesc_s390_linux32v1 ();
3274 initialize_tdesc_s390_linux32v2 ();
3275 initialize_tdesc_s390_linux64 ();
3276 initialize_tdesc_s390_linux64v1 ();
3277 initialize_tdesc_s390_linux64v2 ();
3278 initialize_tdesc_s390_te_linux64 ();
3279 initialize_tdesc_s390x_linux64 ();
3280 initialize_tdesc_s390x_linux64v1 ();
3281 initialize_tdesc_s390x_linux64v2 ();
3282 initialize_tdesc_s390x_te_linux64 ();