1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
7 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #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"
42 #include "gdb_assert.h"
44 #include "solib-svr4.h"
45 #include "prologue-value.h"
47 #include "s390-tdep.h"
50 /* The tdep structure. */
55 enum { ABI_LINUX_S390, ABI_LINUX_ZSERIES } abi;
57 /* Core file register sets. */
58 const struct regset *gregset;
61 const struct regset *fpregset;
66 /* Return the name of register REGNUM. */
68 s390_register_name (struct gdbarch *gdbarch, int regnum)
70 static const char *register_names[S390_NUM_TOTAL_REGS] =
72 /* Program Status Word. */
74 /* General Purpose Registers. */
75 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
76 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
77 /* Access Registers. */
78 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
79 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15",
80 /* Floating Point Control Word. */
82 /* Floating Point Registers. */
83 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
84 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
85 /* Pseudo registers. */
89 gdb_assert (regnum >= 0 && regnum < S390_NUM_TOTAL_REGS);
90 return register_names[regnum];
93 /* Return the GDB type object for the "standard" data type of data in
96 s390_register_type (struct gdbarch *gdbarch, int regnum)
98 if (regnum == S390_PSWM_REGNUM || regnum == S390_PSWA_REGNUM)
99 return builtin_type (gdbarch)->builtin_long;
100 if (regnum >= S390_R0_REGNUM && regnum <= S390_R15_REGNUM)
101 return builtin_type (gdbarch)->builtin_long;
102 if (regnum >= S390_A0_REGNUM && regnum <= S390_A15_REGNUM)
103 return builtin_type (gdbarch)->builtin_int;
104 if (regnum == S390_FPC_REGNUM)
105 return builtin_type (gdbarch)->builtin_int;
106 if (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM)
107 return builtin_type (gdbarch)->builtin_double;
108 if (regnum == S390_PC_REGNUM)
109 return builtin_type (gdbarch)->builtin_func_ptr;
110 if (regnum == S390_CC_REGNUM)
111 return builtin_type (gdbarch)->builtin_int;
113 internal_error (__FILE__, __LINE__, _("invalid regnum"));
116 /* DWARF Register Mapping. */
118 static int s390_dwarf_regmap[] =
120 /* General Purpose Registers. */
121 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
122 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
123 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
124 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
126 /* Floating Point Registers. */
127 S390_F0_REGNUM, S390_F2_REGNUM, S390_F4_REGNUM, S390_F6_REGNUM,
128 S390_F1_REGNUM, S390_F3_REGNUM, S390_F5_REGNUM, S390_F7_REGNUM,
129 S390_F8_REGNUM, S390_F10_REGNUM, S390_F12_REGNUM, S390_F14_REGNUM,
130 S390_F9_REGNUM, S390_F11_REGNUM, S390_F13_REGNUM, S390_F15_REGNUM,
132 /* Control Registers (not mapped). */
133 -1, -1, -1, -1, -1, -1, -1, -1,
134 -1, -1, -1, -1, -1, -1, -1, -1,
136 /* Access Registers. */
137 S390_A0_REGNUM, S390_A1_REGNUM, S390_A2_REGNUM, S390_A3_REGNUM,
138 S390_A4_REGNUM, S390_A5_REGNUM, S390_A6_REGNUM, S390_A7_REGNUM,
139 S390_A8_REGNUM, S390_A9_REGNUM, S390_A10_REGNUM, S390_A11_REGNUM,
140 S390_A12_REGNUM, S390_A13_REGNUM, S390_A14_REGNUM, S390_A15_REGNUM,
142 /* Program Status Word. */
147 /* Convert DWARF register number REG to the appropriate register
148 number used by GDB. */
150 s390_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
154 if (reg >= 0 && reg < ARRAY_SIZE (s390_dwarf_regmap))
155 regnum = s390_dwarf_regmap[reg];
158 warning (_("Unmapped DWARF Register #%d encountered."), reg);
163 /* Pseudo registers - PC and condition code. */
166 s390_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
167 int regnum, gdb_byte *buf)
174 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &val);
175 store_unsigned_integer (buf, 4, val & 0x7fffffff);
179 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val);
180 store_unsigned_integer (buf, 4, (val >> 12) & 3);
184 internal_error (__FILE__, __LINE__, _("invalid regnum"));
189 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
190 int regnum, const gdb_byte *buf)
197 val = extract_unsigned_integer (buf, 4);
198 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &psw);
199 psw = (psw & 0x80000000) | (val & 0x7fffffff);
200 regcache_raw_write_unsigned (regcache, S390_PSWA_REGNUM, psw);
204 val = extract_unsigned_integer (buf, 4);
205 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
206 psw = (psw & ~((ULONGEST)3 << 12)) | ((val & 3) << 12);
207 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, psw);
211 internal_error (__FILE__, __LINE__, _("invalid regnum"));
216 s390x_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
217 int regnum, gdb_byte *buf)
224 regcache_raw_read (regcache, S390_PSWA_REGNUM, buf);
228 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val);
229 store_unsigned_integer (buf, 4, (val >> 44) & 3);
233 internal_error (__FILE__, __LINE__, _("invalid regnum"));
238 s390x_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
239 int regnum, const gdb_byte *buf)
246 regcache_raw_write (regcache, S390_PSWA_REGNUM, buf);
250 val = extract_unsigned_integer (buf, 4);
251 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
252 psw = (psw & ~((ULONGEST)3 << 44)) | ((val & 3) << 44);
253 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, psw);
257 internal_error (__FILE__, __LINE__, _("invalid regnum"));
261 /* 'float' values are stored in the upper half of floating-point
262 registers, even though we are otherwise a big-endian platform. */
264 static struct value *
265 s390_value_from_register (struct type *type, int regnum,
266 struct frame_info *frame)
268 struct value *value = default_value_from_register (type, regnum, frame);
269 int len = TYPE_LENGTH (type);
271 if (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM && len < 8)
272 set_value_offset (value, 0);
277 /* Register groups. */
280 s390_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
281 struct reggroup *group)
283 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
285 /* Registers displayed via 'info regs'. */
286 if (group == general_reggroup)
287 return (regnum >= S390_R0_REGNUM && regnum <= S390_R15_REGNUM)
288 || regnum == S390_PC_REGNUM
289 || regnum == S390_CC_REGNUM;
291 /* Registers displayed via 'info float'. */
292 if (group == float_reggroup)
293 return (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM)
294 || regnum == S390_FPC_REGNUM;
296 /* Registers that need to be saved/restored in order to
297 push or pop frames. */
298 if (group == save_reggroup || group == restore_reggroup)
299 return regnum != S390_PSWM_REGNUM && regnum != S390_PSWA_REGNUM;
301 return default_register_reggroup_p (gdbarch, regnum, group);
305 /* Core file register sets. */
307 int s390_regmap_gregset[S390_NUM_REGS] =
309 /* Program Status Word. */
311 /* General Purpose Registers. */
312 0x08, 0x0c, 0x10, 0x14,
313 0x18, 0x1c, 0x20, 0x24,
314 0x28, 0x2c, 0x30, 0x34,
315 0x38, 0x3c, 0x40, 0x44,
316 /* Access Registers. */
317 0x48, 0x4c, 0x50, 0x54,
318 0x58, 0x5c, 0x60, 0x64,
319 0x68, 0x6c, 0x70, 0x74,
320 0x78, 0x7c, 0x80, 0x84,
321 /* Floating Point Control Word. */
323 /* Floating Point Registers. */
324 -1, -1, -1, -1, -1, -1, -1, -1,
325 -1, -1, -1, -1, -1, -1, -1, -1,
328 int s390x_regmap_gregset[S390_NUM_REGS] =
331 /* General Purpose Registers. */
332 0x10, 0x18, 0x20, 0x28,
333 0x30, 0x38, 0x40, 0x48,
334 0x50, 0x58, 0x60, 0x68,
335 0x70, 0x78, 0x80, 0x88,
336 /* Access Registers. */
337 0x90, 0x94, 0x98, 0x9c,
338 0xa0, 0xa4, 0xa8, 0xac,
339 0xb0, 0xb4, 0xb8, 0xbc,
340 0xc0, 0xc4, 0xc8, 0xcc,
341 /* Floating Point Control Word. */
343 /* Floating Point Registers. */
344 -1, -1, -1, -1, -1, -1, -1, -1,
345 -1, -1, -1, -1, -1, -1, -1, -1,
348 int s390_regmap_fpregset[S390_NUM_REGS] =
350 /* Program Status Word. */
352 /* General Purpose Registers. */
353 -1, -1, -1, -1, -1, -1, -1, -1,
354 -1, -1, -1, -1, -1, -1, -1, -1,
355 /* Access Registers. */
356 -1, -1, -1, -1, -1, -1, -1, -1,
357 -1, -1, -1, -1, -1, -1, -1, -1,
358 /* Floating Point Control Word. */
360 /* Floating Point Registers. */
361 0x08, 0x10, 0x18, 0x20,
362 0x28, 0x30, 0x38, 0x40,
363 0x48, 0x50, 0x58, 0x60,
364 0x68, 0x70, 0x78, 0x80,
367 /* Supply register REGNUM from the register set REGSET to register cache
368 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
370 s390_supply_regset (const struct regset *regset, struct regcache *regcache,
371 int regnum, const void *regs, size_t len)
373 const int *offset = regset->descr;
376 for (i = 0; i < S390_NUM_REGS; i++)
378 if ((regnum == i || regnum == -1) && offset[i] != -1)
379 regcache_raw_supply (regcache, i, (const char *)regs + offset[i]);
383 /* Collect register REGNUM from the register cache REGCACHE and store
384 it in the buffer specified by REGS and LEN as described by the
385 general-purpose register set REGSET. If REGNUM is -1, do this for
386 all registers in REGSET. */
388 s390_collect_regset (const struct regset *regset,
389 const struct regcache *regcache,
390 int regnum, void *regs, size_t len)
392 const int *offset = regset->descr;
395 for (i = 0; i < S390_NUM_REGS; i++)
397 if ((regnum == i || regnum == -1) && offset[i] != -1)
398 regcache_raw_collect (regcache, i, (char *)regs + offset[i]);
402 static const struct regset s390_gregset = {
408 static const struct regset s390x_gregset = {
409 s390x_regmap_gregset,
414 static const struct regset s390_fpregset = {
415 s390_regmap_fpregset,
420 /* Return the appropriate register set for the core section identified
421 by SECT_NAME and SECT_SIZE. */
422 static const struct regset *
423 s390_regset_from_core_section (struct gdbarch *gdbarch,
424 const char *sect_name, size_t sect_size)
426 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
428 if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset)
429 return tdep->gregset;
431 if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset)
432 return tdep->fpregset;
438 /* Decoding S/390 instructions. */
440 /* Named opcode values for the S/390 instructions we recognize. Some
441 instructions have their opcode split across two fields; those are the
442 op1_* and op2_* enums. */
445 op1_lhi = 0xa7, op2_lhi = 0x08,
446 op1_lghi = 0xa7, op2_lghi = 0x09,
447 op1_lgfi = 0xc0, op2_lgfi = 0x01,
451 op1_ly = 0xe3, op2_ly = 0x58,
452 op1_lg = 0xe3, op2_lg = 0x04,
454 op1_lmy = 0xeb, op2_lmy = 0x98,
455 op1_lmg = 0xeb, op2_lmg = 0x04,
457 op1_sty = 0xe3, op2_sty = 0x50,
458 op1_stg = 0xe3, op2_stg = 0x24,
461 op1_stmy = 0xeb, op2_stmy = 0x90,
462 op1_stmg = 0xeb, op2_stmg = 0x24,
463 op1_aghi = 0xa7, op2_aghi = 0x0b,
464 op1_ahi = 0xa7, op2_ahi = 0x0a,
465 op1_agfi = 0xc2, op2_agfi = 0x08,
466 op1_afi = 0xc2, op2_afi = 0x09,
467 op1_algfi= 0xc2, op2_algfi= 0x0a,
468 op1_alfi = 0xc2, op2_alfi = 0x0b,
472 op1_ay = 0xe3, op2_ay = 0x5a,
473 op1_ag = 0xe3, op2_ag = 0x08,
474 op1_slgfi= 0xc2, op2_slgfi= 0x04,
475 op1_slfi = 0xc2, op2_slfi = 0x05,
479 op1_sy = 0xe3, op2_sy = 0x5b,
480 op1_sg = 0xe3, op2_sg = 0x09,
484 op1_lay = 0xe3, op2_lay = 0x71,
485 op1_larl = 0xc0, op2_larl = 0x00,
490 op1_bras = 0xa7, op2_bras = 0x05,
491 op1_brasl= 0xc0, op2_brasl= 0x05,
492 op1_brc = 0xa7, op2_brc = 0x04,
493 op1_brcl = 0xc0, op2_brcl = 0x04,
497 /* Read a single instruction from address AT. */
499 #define S390_MAX_INSTR_SIZE 6
501 s390_readinstruction (bfd_byte instr[], CORE_ADDR at)
503 static int s390_instrlen[] = { 2, 4, 4, 6 };
506 if (target_read_memory (at, &instr[0], 2))
508 instrlen = s390_instrlen[instr[0] >> 6];
511 if (target_read_memory (at + 2, &instr[2], instrlen - 2))
518 /* The functions below are for recognizing and decoding S/390
519 instructions of various formats. Each of them checks whether INSN
520 is an instruction of the given format, with the specified opcodes.
521 If it is, it sets the remaining arguments to the values of the
522 instruction's fields, and returns a non-zero value; otherwise, it
525 These functions' arguments appear in the order they appear in the
526 instruction, not in the machine-language form. So, opcodes always
527 come first, even though they're sometimes scattered around the
528 instructions. And displacements appear before base and extension
529 registers, as they do in the assembly syntax, not at the end, as
530 they do in the machine language. */
532 is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2)
534 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
536 *r1 = (insn[1] >> 4) & 0xf;
537 /* i2 is a 16-bit signed quantity. */
538 *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000;
547 is_ril (bfd_byte *insn, int op1, int op2,
548 unsigned int *r1, int *i2)
550 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
552 *r1 = (insn[1] >> 4) & 0xf;
553 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
554 no sign extension is necessary, but we don't want to assume
556 *i2 = (((insn[2] << 24)
559 | (insn[5])) ^ 0x80000000) - 0x80000000;
568 is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
572 *r1 = (insn[1] >> 4) & 0xf;
582 is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
584 if (((insn[0] << 8) | insn[1]) == op)
586 /* Yes, insn[3]. insn[2] is unused in RRE format. */
587 *r1 = (insn[3] >> 4) & 0xf;
597 is_rs (bfd_byte *insn, int op,
598 unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2)
602 *r1 = (insn[1] >> 4) & 0xf;
604 *b2 = (insn[2] >> 4) & 0xf;
605 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
614 is_rsy (bfd_byte *insn, int op1, int op2,
615 unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2)
620 *r1 = (insn[1] >> 4) & 0xf;
622 *b2 = (insn[2] >> 4) & 0xf;
623 /* The 'long displacement' is a 20-bit signed integer. */
624 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
625 ^ 0x80000) - 0x80000;
634 is_rx (bfd_byte *insn, int op,
635 unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2)
639 *r1 = (insn[1] >> 4) & 0xf;
641 *b2 = (insn[2] >> 4) & 0xf;
642 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
651 is_rxy (bfd_byte *insn, int op1, int op2,
652 unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2)
657 *r1 = (insn[1] >> 4) & 0xf;
659 *b2 = (insn[2] >> 4) & 0xf;
660 /* The 'long displacement' is a 20-bit signed integer. */
661 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
662 ^ 0x80000) - 0x80000;
670 /* Prologue analysis. */
672 #define S390_NUM_GPRS 16
673 #define S390_NUM_FPRS 16
675 struct s390_prologue_data {
678 struct pv_area *stack;
680 /* The size of a GPR or FPR. */
684 /* The general-purpose registers. */
685 pv_t gpr[S390_NUM_GPRS];
687 /* The floating-point registers. */
688 pv_t fpr[S390_NUM_FPRS];
690 /* The offset relative to the CFA where the incoming GPR N was saved
691 by the function prologue. 0 if not saved or unknown. */
692 int gpr_slot[S390_NUM_GPRS];
694 /* Likewise for FPRs. */
695 int fpr_slot[S390_NUM_FPRS];
697 /* Nonzero if the backchain was saved. This is assumed to be the
698 case when the incoming SP is saved at the current SP location. */
699 int back_chain_saved_p;
702 /* Return the effective address for an X-style instruction, like:
706 Here, X2 and B2 are registers, and D2 is a signed 20-bit
707 constant; the effective address is the sum of all three. If either
708 X2 or B2 are zero, then it doesn't contribute to the sum --- this
709 means that r0 can't be used as either X2 or B2. */
711 s390_addr (struct s390_prologue_data *data,
712 int d2, unsigned int x2, unsigned int b2)
716 result = pv_constant (d2);
718 result = pv_add (result, data->gpr[x2]);
720 result = pv_add (result, data->gpr[b2]);
725 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
727 s390_store (struct s390_prologue_data *data,
728 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size,
731 pv_t addr = s390_addr (data, d2, x2, b2);
734 /* Check whether we are storing the backchain. */
735 offset = pv_subtract (data->gpr[S390_SP_REGNUM - S390_R0_REGNUM], addr);
737 if (pv_is_constant (offset) && offset.k == 0)
738 if (size == data->gpr_size
739 && pv_is_register_k (value, S390_SP_REGNUM, 0))
741 data->back_chain_saved_p = 1;
746 /* Check whether we are storing a register into the stack. */
747 if (!pv_area_store_would_trash (data->stack, addr))
748 pv_area_store (data->stack, addr, size, value);
751 /* Note: If this is some store we cannot identify, you might think we
752 should forget our cached values, as any of those might have been hit.
754 However, we make the assumption that the register save areas are only
755 ever stored to once in any given function, and we do recognize these
756 stores. Thus every store we cannot recognize does not hit our data. */
759 /* Do a SIZE-byte load from D2(X2,B2). */
761 s390_load (struct s390_prologue_data *data,
762 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size)
765 pv_t addr = s390_addr (data, d2, x2, b2);
768 /* If it's a load from an in-line constant pool, then we can
769 simulate that, under the assumption that the code isn't
770 going to change between the time the processor actually
771 executed it creating the current frame, and the time when
772 we're analyzing the code to unwind past that frame. */
773 if (pv_is_constant (addr))
775 struct target_section *secp;
776 secp = target_section_by_addr (¤t_target, addr.k);
778 && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
780 return pv_constant (read_memory_integer (addr.k, size));
783 /* Check whether we are accessing one of our save slots. */
784 return pv_area_fetch (data->stack, addr, size);
787 /* Function for finding saved registers in a 'struct pv_area'; we pass
788 this to pv_area_scan.
790 If VALUE is a saved register, ADDR says it was saved at a constant
791 offset from the frame base, and SIZE indicates that the whole
792 register was saved, record its offset in the reg_offset table in
795 s390_check_for_saved (void *data_untyped, pv_t addr, CORE_ADDR size, pv_t value)
797 struct s390_prologue_data *data = data_untyped;
800 if (!pv_is_register (addr, S390_SP_REGNUM))
803 offset = 16 * data->gpr_size + 32 - addr.k;
805 /* If we are storing the original value of a register, we want to
806 record the CFA offset. If the same register is stored multiple
807 times, the stack slot with the highest address counts. */
809 for (i = 0; i < S390_NUM_GPRS; i++)
810 if (size == data->gpr_size
811 && pv_is_register_k (value, S390_R0_REGNUM + i, 0))
812 if (data->gpr_slot[i] == 0
813 || data->gpr_slot[i] > offset)
815 data->gpr_slot[i] = offset;
819 for (i = 0; i < S390_NUM_FPRS; i++)
820 if (size == data->fpr_size
821 && pv_is_register_k (value, S390_F0_REGNUM + i, 0))
822 if (data->fpr_slot[i] == 0
823 || data->fpr_slot[i] > offset)
825 data->fpr_slot[i] = offset;
830 /* Analyze the prologue of the function starting at START_PC,
831 continuing at most until CURRENT_PC. Initialize DATA to
832 hold all information we find out about the state of the registers
833 and stack slots. Return the address of the instruction after
834 the last one that changed the SP, FP, or back chain; or zero
837 s390_analyze_prologue (struct gdbarch *gdbarch,
839 CORE_ADDR current_pc,
840 struct s390_prologue_data *data)
842 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
845 The address of the instruction after the last one that changed
846 the SP, FP, or back chain; zero if we got an error trying to
848 CORE_ADDR result = start_pc;
850 /* The current PC for our abstract interpretation. */
853 /* The address of the next instruction after that. */
856 /* Set up everything's initial value. */
860 data->stack = make_pv_area (S390_SP_REGNUM, gdbarch_addr_bit (gdbarch));
862 /* For the purpose of prologue tracking, we consider the GPR size to
863 be equal to the ABI word size, even if it is actually larger
864 (i.e. when running a 32-bit binary under a 64-bit kernel). */
865 data->gpr_size = word_size;
868 for (i = 0; i < S390_NUM_GPRS; i++)
869 data->gpr[i] = pv_register (S390_R0_REGNUM + i, 0);
871 for (i = 0; i < S390_NUM_FPRS; i++)
872 data->fpr[i] = pv_register (S390_F0_REGNUM + i, 0);
874 for (i = 0; i < S390_NUM_GPRS; i++)
875 data->gpr_slot[i] = 0;
877 for (i = 0; i < S390_NUM_FPRS; i++)
878 data->fpr_slot[i] = 0;
880 data->back_chain_saved_p = 0;
883 /* Start interpreting instructions, until we hit the frame's
884 current PC or the first branch instruction. */
885 for (pc = start_pc; pc > 0 && pc < current_pc; pc = next_pc)
887 bfd_byte insn[S390_MAX_INSTR_SIZE];
888 int insn_len = s390_readinstruction (insn, pc);
890 bfd_byte dummy[S390_MAX_INSTR_SIZE] = { 0 };
891 bfd_byte *insn32 = word_size == 4 ? insn : dummy;
892 bfd_byte *insn64 = word_size == 8 ? insn : dummy;
894 /* Fields for various kinds of instructions. */
895 unsigned int b2, r1, r2, x2, r3;
898 /* The values of SP and FP before this instruction,
899 for detecting instructions that change them. */
900 pv_t pre_insn_sp, pre_insn_fp;
901 /* Likewise for the flag whether the back chain was saved. */
902 int pre_insn_back_chain_saved_p;
904 /* If we got an error trying to read the instruction, report it. */
911 next_pc = pc + insn_len;
913 pre_insn_sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
914 pre_insn_fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
915 pre_insn_back_chain_saved_p = data->back_chain_saved_p;
918 /* LHI r1, i2 --- load halfword immediate. */
919 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
920 /* LGFI r1, i2 --- load fullword immediate. */
921 if (is_ri (insn32, op1_lhi, op2_lhi, &r1, &i2)
922 || is_ri (insn64, op1_lghi, op2_lghi, &r1, &i2)
923 || is_ril (insn, op1_lgfi, op2_lgfi, &r1, &i2))
924 data->gpr[r1] = pv_constant (i2);
926 /* LR r1, r2 --- load from register. */
927 /* LGR r1, r2 --- load from register (64-bit version). */
928 else if (is_rr (insn32, op_lr, &r1, &r2)
929 || is_rre (insn64, op_lgr, &r1, &r2))
930 data->gpr[r1] = data->gpr[r2];
932 /* L r1, d2(x2, b2) --- load. */
933 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
934 /* LG r1, d2(x2, b2) --- load (64-bit version). */
935 else if (is_rx (insn32, op_l, &r1, &d2, &x2, &b2)
936 || is_rxy (insn32, op1_ly, op2_ly, &r1, &d2, &x2, &b2)
937 || is_rxy (insn64, op1_lg, op2_lg, &r1, &d2, &x2, &b2))
938 data->gpr[r1] = s390_load (data, d2, x2, b2, data->gpr_size);
940 /* ST r1, d2(x2, b2) --- store. */
941 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
942 /* STG r1, d2(x2, b2) --- store (64-bit version). */
943 else if (is_rx (insn32, op_st, &r1, &d2, &x2, &b2)
944 || is_rxy (insn32, op1_sty, op2_sty, &r1, &d2, &x2, &b2)
945 || is_rxy (insn64, op1_stg, op2_stg, &r1, &d2, &x2, &b2))
946 s390_store (data, d2, x2, b2, data->gpr_size, data->gpr[r1]);
948 /* STD r1, d2(x2,b2) --- store floating-point register. */
949 else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2))
950 s390_store (data, d2, x2, b2, data->fpr_size, data->fpr[r1]);
952 /* STM r1, r3, d2(b2) --- store multiple. */
953 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement version). */
954 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
955 else if (is_rs (insn32, op_stm, &r1, &r3, &d2, &b2)
956 || is_rsy (insn32, op1_stmy, op2_stmy, &r1, &r3, &d2, &b2)
957 || is_rsy (insn64, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2))
959 for (; r1 <= r3; r1++, d2 += data->gpr_size)
960 s390_store (data, d2, 0, b2, data->gpr_size, data->gpr[r1]);
963 /* AHI r1, i2 --- add halfword immediate. */
964 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
965 /* AFI r1, i2 --- add fullword immediate. */
966 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
967 else if (is_ri (insn32, op1_ahi, op2_ahi, &r1, &i2)
968 || is_ri (insn64, op1_aghi, op2_aghi, &r1, &i2)
969 || is_ril (insn32, op1_afi, op2_afi, &r1, &i2)
970 || is_ril (insn64, op1_agfi, op2_agfi, &r1, &i2))
971 data->gpr[r1] = pv_add_constant (data->gpr[r1], i2);
973 /* ALFI r1, i2 --- add logical immediate. */
974 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
975 else if (is_ril (insn32, op1_alfi, op2_alfi, &r1, &i2)
976 || is_ril (insn64, op1_algfi, op2_algfi, &r1, &i2))
977 data->gpr[r1] = pv_add_constant (data->gpr[r1],
978 (CORE_ADDR)i2 & 0xffffffff);
980 /* AR r1, r2 -- add register. */
981 /* AGR r1, r2 -- add register (64-bit version). */
982 else if (is_rr (insn32, op_ar, &r1, &r2)
983 || is_rre (insn64, op_agr, &r1, &r2))
984 data->gpr[r1] = pv_add (data->gpr[r1], data->gpr[r2]);
986 /* A r1, d2(x2, b2) -- add. */
987 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
988 /* AG r1, d2(x2, b2) -- add (64-bit version). */
989 else if (is_rx (insn32, op_a, &r1, &d2, &x2, &b2)
990 || is_rxy (insn32, op1_ay, op2_ay, &r1, &d2, &x2, &b2)
991 || is_rxy (insn64, op1_ag, op2_ag, &r1, &d2, &x2, &b2))
992 data->gpr[r1] = pv_add (data->gpr[r1],
993 s390_load (data, d2, x2, b2, data->gpr_size));
995 /* SLFI r1, i2 --- subtract logical immediate. */
996 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
997 else if (is_ril (insn32, op1_slfi, op2_slfi, &r1, &i2)
998 || is_ril (insn64, op1_slgfi, op2_slgfi, &r1, &i2))
999 data->gpr[r1] = pv_add_constant (data->gpr[r1],
1000 -((CORE_ADDR)i2 & 0xffffffff));
1002 /* SR r1, r2 -- subtract register. */
1003 /* SGR r1, r2 -- subtract register (64-bit version). */
1004 else if (is_rr (insn32, op_sr, &r1, &r2)
1005 || is_rre (insn64, op_sgr, &r1, &r2))
1006 data->gpr[r1] = pv_subtract (data->gpr[r1], data->gpr[r2]);
1008 /* S r1, d2(x2, b2) -- subtract. */
1009 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
1010 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
1011 else if (is_rx (insn32, op_s, &r1, &d2, &x2, &b2)
1012 || is_rxy (insn32, op1_sy, op2_sy, &r1, &d2, &x2, &b2)
1013 || is_rxy (insn64, op1_sg, op2_sg, &r1, &d2, &x2, &b2))
1014 data->gpr[r1] = pv_subtract (data->gpr[r1],
1015 s390_load (data, d2, x2, b2, data->gpr_size));
1017 /* LA r1, d2(x2, b2) --- load address. */
1018 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
1019 else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2)
1020 || is_rxy (insn, op1_lay, op2_lay, &r1, &d2, &x2, &b2))
1021 data->gpr[r1] = s390_addr (data, d2, x2, b2);
1023 /* LARL r1, i2 --- load address relative long. */
1024 else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2))
1025 data->gpr[r1] = pv_constant (pc + i2 * 2);
1027 /* BASR r1, 0 --- branch and save.
1028 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1029 else if (is_rr (insn, op_basr, &r1, &r2)
1031 data->gpr[r1] = pv_constant (next_pc);
1033 /* BRAS r1, i2 --- branch relative and save. */
1034 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2))
1036 data->gpr[r1] = pv_constant (next_pc);
1037 next_pc = pc + i2 * 2;
1039 /* We'd better not interpret any backward branches. We'll
1045 /* Terminate search when hitting any other branch instruction. */
1046 else if (is_rr (insn, op_basr, &r1, &r2)
1047 || is_rx (insn, op_bas, &r1, &d2, &x2, &b2)
1048 || is_rr (insn, op_bcr, &r1, &r2)
1049 || is_rx (insn, op_bc, &r1, &d2, &x2, &b2)
1050 || is_ri (insn, op1_brc, op2_brc, &r1, &i2)
1051 || is_ril (insn, op1_brcl, op2_brcl, &r1, &i2)
1052 || is_ril (insn, op1_brasl, op2_brasl, &r2, &i2))
1056 /* An instruction we don't know how to simulate. The only
1057 safe thing to do would be to set every value we're tracking
1058 to 'unknown'. Instead, we'll be optimistic: we assume that
1059 we *can* interpret every instruction that the compiler uses
1060 to manipulate any of the data we're interested in here --
1061 then we can just ignore anything else. */
1064 /* Record the address after the last instruction that changed
1065 the FP, SP, or backlink. Ignore instructions that changed
1066 them back to their original values --- those are probably
1067 restore instructions. (The back chain is never restored,
1070 pv_t sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1071 pv_t fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1073 if ((! pv_is_identical (pre_insn_sp, sp)
1074 && ! pv_is_register_k (sp, S390_SP_REGNUM, 0)
1075 && sp.kind != pvk_unknown)
1076 || (! pv_is_identical (pre_insn_fp, fp)
1077 && ! pv_is_register_k (fp, S390_FRAME_REGNUM, 0)
1078 && fp.kind != pvk_unknown)
1079 || pre_insn_back_chain_saved_p != data->back_chain_saved_p)
1084 /* Record where all the registers were saved. */
1085 pv_area_scan (data->stack, s390_check_for_saved, data);
1087 free_pv_area (data->stack);
1093 /* Advance PC across any function entry prologue instructions to reach
1094 some "real" code. */
1096 s390_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1098 struct s390_prologue_data data;
1100 skip_pc = s390_analyze_prologue (gdbarch, pc, (CORE_ADDR)-1, &data);
1101 return skip_pc ? skip_pc : pc;
1104 /* Return true if we are in the functin's epilogue, i.e. after the
1105 instruction that destroyed the function's stack frame. */
1107 s390_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
1109 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1111 /* In frameless functions, there's not frame to destroy and thus
1112 we don't care about the epilogue.
1114 In functions with frame, the epilogue sequence is a pair of
1115 a LM-type instruction that restores (amongst others) the
1116 return register %r14 and the stack pointer %r15, followed
1117 by a branch 'br %r14' --or equivalent-- that effects the
1120 In that situation, this function needs to return 'true' in
1121 exactly one case: when pc points to that branch instruction.
1123 Thus we try to disassemble the one instructions immediately
1124 preceeding pc and check whether it is an LM-type instruction
1125 modifying the stack pointer.
1127 Note that disassembling backwards is not reliable, so there
1128 is a slight chance of false positives here ... */
1131 unsigned int r1, r3, b2;
1135 && !target_read_memory (pc - 4, insn, 4)
1136 && is_rs (insn, op_lm, &r1, &r3, &d2, &b2)
1137 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1141 && !target_read_memory (pc - 6, insn, 6)
1142 && is_rsy (insn, op1_lmy, op2_lmy, &r1, &r3, &d2, &b2)
1143 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1147 && !target_read_memory (pc - 6, insn, 6)
1148 && is_rsy (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2)
1149 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1156 /* Normal stack frames. */
1158 struct s390_unwind_cache {
1161 CORE_ADDR frame_base;
1162 CORE_ADDR local_base;
1164 struct trad_frame_saved_reg *saved_regs;
1168 s390_prologue_frame_unwind_cache (struct frame_info *this_frame,
1169 struct s390_unwind_cache *info)
1171 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1172 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1173 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1174 struct s390_prologue_data data;
1175 pv_t *fp = &data.gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1176 pv_t *sp = &data.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1185 struct frame_info *next_frame;
1187 /* Try to find the function start address. If we can't find it, we don't
1188 bother searching for it -- with modern compilers this would be mostly
1189 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1190 or else a valid backchain ... */
1191 func = get_frame_func (this_frame);
1195 /* Try to analyze the prologue. */
1196 result = s390_analyze_prologue (gdbarch, func,
1197 get_frame_pc (this_frame), &data);
1201 /* If this was successful, we should have found the instruction that
1202 sets the stack pointer register to the previous value of the stack
1203 pointer minus the frame size. */
1204 if (!pv_is_register (*sp, S390_SP_REGNUM))
1207 /* A frame size of zero at this point can mean either a real
1208 frameless function, or else a failure to find the prologue.
1209 Perform some sanity checks to verify we really have a
1210 frameless function. */
1213 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1214 size zero. This is only possible if the next frame is a sentinel
1215 frame, a dummy frame, or a signal trampoline frame. */
1216 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1217 needed, instead the code should simpliy rely on its
1219 next_frame = get_next_frame (this_frame);
1220 while (next_frame && get_frame_type (next_frame) == INLINE_FRAME)
1221 next_frame = get_next_frame (next_frame);
1223 && get_frame_type (get_next_frame (this_frame)) == NORMAL_FRAME)
1226 /* If we really have a frameless function, %r14 must be valid
1227 -- in particular, it must point to a different function. */
1228 reg = get_frame_register_unsigned (this_frame, S390_RETADDR_REGNUM);
1229 reg = gdbarch_addr_bits_remove (gdbarch, reg) - 1;
1230 if (get_pc_function_start (reg) == func)
1232 /* However, there is one case where it *is* valid for %r14
1233 to point to the same function -- if this is a recursive
1234 call, and we have stopped in the prologue *before* the
1235 stack frame was allocated.
1237 Recognize this case by looking ahead a bit ... */
1239 struct s390_prologue_data data2;
1240 pv_t *sp = &data2.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1242 if (!(s390_analyze_prologue (gdbarch, func, (CORE_ADDR)-1, &data2)
1243 && pv_is_register (*sp, S390_SP_REGNUM)
1250 /* OK, we've found valid prologue data. */
1253 /* If the frame pointer originally also holds the same value
1254 as the stack pointer, we're probably using it. If it holds
1255 some other value -- even a constant offset -- it is most
1256 likely used as temp register. */
1257 if (pv_is_identical (*sp, *fp))
1258 frame_pointer = S390_FRAME_REGNUM;
1260 frame_pointer = S390_SP_REGNUM;
1262 /* If we've detected a function with stack frame, we'll still have to
1263 treat it as frameless if we're currently within the function epilog
1264 code at a point where the frame pointer has already been restored.
1265 This can only happen in an innermost frame. */
1266 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1267 instead the code should simpliy rely on its analysis. */
1268 next_frame = get_next_frame (this_frame);
1269 while (next_frame && get_frame_type (next_frame) == INLINE_FRAME)
1270 next_frame = get_next_frame (next_frame);
1272 && (next_frame == NULL
1273 || get_frame_type (get_next_frame (this_frame)) != NORMAL_FRAME))
1275 /* See the comment in s390_in_function_epilogue_p on why this is
1276 not completely reliable ... */
1277 if (s390_in_function_epilogue_p (gdbarch, get_frame_pc (this_frame)))
1279 memset (&data, 0, sizeof (data));
1281 frame_pointer = S390_SP_REGNUM;
1285 /* Once we know the frame register and the frame size, we can unwind
1286 the current value of the frame register from the next frame, and
1287 add back the frame size to arrive that the previous frame's
1288 stack pointer value. */
1289 prev_sp = get_frame_register_unsigned (this_frame, frame_pointer) + size;
1290 cfa = prev_sp + 16*word_size + 32;
1292 /* Record the addresses of all register spill slots the prologue parser
1293 has recognized. Consider only registers defined as call-saved by the
1294 ABI; for call-clobbered registers the parser may have recognized
1297 for (i = 6; i <= 15; i++)
1298 if (data.gpr_slot[i] != 0)
1299 info->saved_regs[S390_R0_REGNUM + i].addr = cfa - data.gpr_slot[i];
1303 case ABI_LINUX_S390:
1304 if (data.fpr_slot[4] != 0)
1305 info->saved_regs[S390_F4_REGNUM].addr = cfa - data.fpr_slot[4];
1306 if (data.fpr_slot[6] != 0)
1307 info->saved_regs[S390_F6_REGNUM].addr = cfa - data.fpr_slot[6];
1310 case ABI_LINUX_ZSERIES:
1311 for (i = 8; i <= 15; i++)
1312 if (data.fpr_slot[i] != 0)
1313 info->saved_regs[S390_F0_REGNUM + i].addr = cfa - data.fpr_slot[i];
1317 /* Function return will set PC to %r14. */
1318 info->saved_regs[S390_PC_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM];
1320 /* In frameless functions, we unwind simply by moving the return
1321 address to the PC. However, if we actually stored to the
1322 save area, use that -- we might only think the function frameless
1323 because we're in the middle of the prologue ... */
1325 && !trad_frame_addr_p (info->saved_regs, S390_PC_REGNUM))
1327 info->saved_regs[S390_PC_REGNUM].realreg = S390_RETADDR_REGNUM;
1330 /* Another sanity check: unless this is a frameless function,
1331 we should have found spill slots for SP and PC.
1332 If not, we cannot unwind further -- this happens e.g. in
1333 libc's thread_start routine. */
1336 if (!trad_frame_addr_p (info->saved_regs, S390_SP_REGNUM)
1337 || !trad_frame_addr_p (info->saved_regs, S390_PC_REGNUM))
1341 /* We use the current value of the frame register as local_base,
1342 and the top of the register save area as frame_base. */
1345 info->frame_base = prev_sp + 16*word_size + 32;
1346 info->local_base = prev_sp - size;
1354 s390_backchain_frame_unwind_cache (struct frame_info *this_frame,
1355 struct s390_unwind_cache *info)
1357 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1358 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1359 CORE_ADDR backchain;
1363 /* Get the backchain. */
1364 reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
1365 backchain = read_memory_unsigned_integer (reg, word_size);
1367 /* A zero backchain terminates the frame chain. As additional
1368 sanity check, let's verify that the spill slot for SP in the
1369 save area pointed to by the backchain in fact links back to
1372 && safe_read_memory_integer (backchain + 15*word_size, word_size, &sp)
1373 && (CORE_ADDR)sp == backchain)
1375 /* We don't know which registers were saved, but it will have
1376 to be at least %r14 and %r15. This will allow us to continue
1377 unwinding, but other prev-frame registers may be incorrect ... */
1378 info->saved_regs[S390_SP_REGNUM].addr = backchain + 15*word_size;
1379 info->saved_regs[S390_RETADDR_REGNUM].addr = backchain + 14*word_size;
1381 /* Function return will set PC to %r14. */
1382 info->saved_regs[S390_PC_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM];
1384 /* We use the current value of the frame register as local_base,
1385 and the top of the register save area as frame_base. */
1386 info->frame_base = backchain + 16*word_size + 32;
1387 info->local_base = reg;
1390 info->func = get_frame_pc (this_frame);
1393 static struct s390_unwind_cache *
1394 s390_frame_unwind_cache (struct frame_info *this_frame,
1395 void **this_prologue_cache)
1397 struct s390_unwind_cache *info;
1398 if (*this_prologue_cache)
1399 return *this_prologue_cache;
1401 info = FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache);
1402 *this_prologue_cache = info;
1403 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1405 info->frame_base = -1;
1406 info->local_base = -1;
1408 /* Try to use prologue analysis to fill the unwind cache.
1409 If this fails, fall back to reading the stack backchain. */
1410 if (!s390_prologue_frame_unwind_cache (this_frame, info))
1411 s390_backchain_frame_unwind_cache (this_frame, info);
1417 s390_frame_this_id (struct frame_info *this_frame,
1418 void **this_prologue_cache,
1419 struct frame_id *this_id)
1421 struct s390_unwind_cache *info
1422 = s390_frame_unwind_cache (this_frame, this_prologue_cache);
1424 if (info->frame_base == -1)
1427 *this_id = frame_id_build (info->frame_base, info->func);
1430 static struct value *
1431 s390_frame_prev_register (struct frame_info *this_frame,
1432 void **this_prologue_cache, int regnum)
1434 struct s390_unwind_cache *info
1435 = s390_frame_unwind_cache (this_frame, this_prologue_cache);
1436 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
1439 static const struct frame_unwind s390_frame_unwind = {
1442 s390_frame_prev_register,
1444 default_frame_sniffer
1448 /* Code stubs and their stack frames. For things like PLTs and NULL
1449 function calls (where there is no true frame and the return address
1450 is in the RETADDR register). */
1452 struct s390_stub_unwind_cache
1454 CORE_ADDR frame_base;
1455 struct trad_frame_saved_reg *saved_regs;
1458 static struct s390_stub_unwind_cache *
1459 s390_stub_frame_unwind_cache (struct frame_info *this_frame,
1460 void **this_prologue_cache)
1462 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1463 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1464 struct s390_stub_unwind_cache *info;
1467 if (*this_prologue_cache)
1468 return *this_prologue_cache;
1470 info = FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache);
1471 *this_prologue_cache = info;
1472 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1474 /* The return address is in register %r14. */
1475 info->saved_regs[S390_PC_REGNUM].realreg = S390_RETADDR_REGNUM;
1477 /* Retrieve stack pointer and determine our frame base. */
1478 reg = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
1479 info->frame_base = reg + 16*word_size + 32;
1485 s390_stub_frame_this_id (struct frame_info *this_frame,
1486 void **this_prologue_cache,
1487 struct frame_id *this_id)
1489 struct s390_stub_unwind_cache *info
1490 = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache);
1491 *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame));
1494 static struct value *
1495 s390_stub_frame_prev_register (struct frame_info *this_frame,
1496 void **this_prologue_cache, int regnum)
1498 struct s390_stub_unwind_cache *info
1499 = s390_stub_frame_unwind_cache (this_frame, this_prologue_cache);
1500 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
1504 s390_stub_frame_sniffer (const struct frame_unwind *self,
1505 struct frame_info *this_frame,
1506 void **this_prologue_cache)
1508 CORE_ADDR addr_in_block;
1509 bfd_byte insn[S390_MAX_INSTR_SIZE];
1511 /* If the current PC points to non-readable memory, we assume we
1512 have trapped due to an invalid function pointer call. We handle
1513 the non-existing current function like a PLT stub. */
1514 addr_in_block = get_frame_address_in_block (this_frame);
1515 if (in_plt_section (addr_in_block, NULL)
1516 || s390_readinstruction (insn, get_frame_pc (this_frame)) < 0)
1521 static const struct frame_unwind s390_stub_frame_unwind = {
1523 s390_stub_frame_this_id,
1524 s390_stub_frame_prev_register,
1526 s390_stub_frame_sniffer
1530 /* Signal trampoline stack frames. */
1532 struct s390_sigtramp_unwind_cache {
1533 CORE_ADDR frame_base;
1534 struct trad_frame_saved_reg *saved_regs;
1537 static struct s390_sigtramp_unwind_cache *
1538 s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame,
1539 void **this_prologue_cache)
1541 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1542 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1543 struct s390_sigtramp_unwind_cache *info;
1544 ULONGEST this_sp, prev_sp;
1545 CORE_ADDR next_ra, next_cfa, sigreg_ptr;
1548 if (*this_prologue_cache)
1549 return *this_prologue_cache;
1551 info = FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache);
1552 *this_prologue_cache = info;
1553 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1555 this_sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
1556 next_ra = get_frame_pc (this_frame);
1557 next_cfa = this_sp + 16*word_size + 32;
1559 /* New-style RT frame:
1560 retcode + alignment (8 bytes)
1562 ucontext (contains sigregs at offset 5 words) */
1563 if (next_ra == next_cfa)
1565 sigreg_ptr = next_cfa + 8 + 128 + align_up (5*word_size, 8);
1568 /* Old-style RT frame and all non-RT frames:
1569 old signal mask (8 bytes)
1570 pointer to sigregs */
1573 sigreg_ptr = read_memory_unsigned_integer (next_cfa + 8, word_size);
1576 /* The sigregs structure looks like this:
1585 /* Let's ignore the PSW mask, it will not be restored anyway. */
1586 sigreg_ptr += word_size;
1588 /* Next comes the PSW address. */
1589 info->saved_regs[S390_PC_REGNUM].addr = sigreg_ptr;
1590 sigreg_ptr += word_size;
1592 /* Then the GPRs. */
1593 for (i = 0; i < 16; i++)
1595 info->saved_regs[S390_R0_REGNUM + i].addr = sigreg_ptr;
1596 sigreg_ptr += word_size;
1599 /* Then the ACRs. */
1600 for (i = 0; i < 16; i++)
1602 info->saved_regs[S390_A0_REGNUM + i].addr = sigreg_ptr;
1606 /* The floating-point control word. */
1607 info->saved_regs[S390_FPC_REGNUM].addr = sigreg_ptr;
1610 /* And finally the FPRs. */
1611 for (i = 0; i < 16; i++)
1613 info->saved_regs[S390_F0_REGNUM + i].addr = sigreg_ptr;
1617 /* Restore the previous frame's SP. */
1618 prev_sp = read_memory_unsigned_integer (
1619 info->saved_regs[S390_SP_REGNUM].addr,
1622 /* Determine our frame base. */
1623 info->frame_base = prev_sp + 16*word_size + 32;
1629 s390_sigtramp_frame_this_id (struct frame_info *this_frame,
1630 void **this_prologue_cache,
1631 struct frame_id *this_id)
1633 struct s390_sigtramp_unwind_cache *info
1634 = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
1635 *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame));
1638 static struct value *
1639 s390_sigtramp_frame_prev_register (struct frame_info *this_frame,
1640 void **this_prologue_cache, int regnum)
1642 struct s390_sigtramp_unwind_cache *info
1643 = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache);
1644 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
1648 s390_sigtramp_frame_sniffer (const struct frame_unwind *self,
1649 struct frame_info *this_frame,
1650 void **this_prologue_cache)
1652 CORE_ADDR pc = get_frame_pc (this_frame);
1653 bfd_byte sigreturn[2];
1655 if (target_read_memory (pc, sigreturn, 2))
1658 if (sigreturn[0] != 0x0a /* svc */)
1661 if (sigreturn[1] != 119 /* sigreturn */
1662 && sigreturn[1] != 173 /* rt_sigreturn */)
1668 static const struct frame_unwind s390_sigtramp_frame_unwind = {
1670 s390_sigtramp_frame_this_id,
1671 s390_sigtramp_frame_prev_register,
1673 s390_sigtramp_frame_sniffer
1677 /* Frame base handling. */
1680 s390_frame_base_address (struct frame_info *this_frame, void **this_cache)
1682 struct s390_unwind_cache *info
1683 = s390_frame_unwind_cache (this_frame, this_cache);
1684 return info->frame_base;
1688 s390_local_base_address (struct frame_info *this_frame, void **this_cache)
1690 struct s390_unwind_cache *info
1691 = s390_frame_unwind_cache (this_frame, this_cache);
1692 return info->local_base;
1695 static const struct frame_base s390_frame_base = {
1697 s390_frame_base_address,
1698 s390_local_base_address,
1699 s390_local_base_address
1703 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1706 pc = frame_unwind_register_unsigned (next_frame, S390_PC_REGNUM);
1707 return gdbarch_addr_bits_remove (gdbarch, pc);
1711 s390_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1714 sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
1715 return gdbarch_addr_bits_remove (gdbarch, sp);
1719 /* DWARF-2 frame support. */
1722 s390_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1723 struct dwarf2_frame_state_reg *reg,
1724 struct frame_info *this_frame)
1726 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1730 case ABI_LINUX_S390:
1731 /* Call-saved registers. */
1732 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
1733 || regnum == S390_F4_REGNUM
1734 || regnum == S390_F6_REGNUM)
1735 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1737 /* Call-clobbered registers. */
1738 else if ((regnum >= S390_R0_REGNUM && regnum <= S390_R5_REGNUM)
1739 || (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM
1740 && regnum != S390_F4_REGNUM && regnum != S390_F6_REGNUM))
1741 reg->how = DWARF2_FRAME_REG_UNDEFINED;
1743 /* The return address column. */
1744 else if (regnum == S390_PC_REGNUM)
1745 reg->how = DWARF2_FRAME_REG_RA;
1748 case ABI_LINUX_ZSERIES:
1749 /* Call-saved registers. */
1750 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
1751 || (regnum >= S390_F8_REGNUM && regnum <= S390_F15_REGNUM))
1752 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1754 /* Call-clobbered registers. */
1755 else if ((regnum >= S390_R0_REGNUM && regnum <= S390_R5_REGNUM)
1756 || (regnum >= S390_F0_REGNUM && regnum <= S390_F7_REGNUM))
1757 reg->how = DWARF2_FRAME_REG_UNDEFINED;
1759 /* The return address column. */
1760 else if (regnum == S390_PC_REGNUM)
1761 reg->how = DWARF2_FRAME_REG_RA;
1767 /* Dummy function calls. */
1769 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
1770 "Integer-like" types are those that should be passed the way
1771 integers are: integers, enums, ranges, characters, and booleans. */
1773 is_integer_like (struct type *type)
1775 enum type_code code = TYPE_CODE (type);
1777 return (code == TYPE_CODE_INT
1778 || code == TYPE_CODE_ENUM
1779 || code == TYPE_CODE_RANGE
1780 || code == TYPE_CODE_CHAR
1781 || code == TYPE_CODE_BOOL);
1784 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
1785 "Pointer-like" types are those that should be passed the way
1786 pointers are: pointers and references. */
1788 is_pointer_like (struct type *type)
1790 enum type_code code = TYPE_CODE (type);
1792 return (code == TYPE_CODE_PTR
1793 || code == TYPE_CODE_REF);
1797 /* Return non-zero if TYPE is a `float singleton' or `double
1798 singleton', zero otherwise.
1800 A `T singleton' is a struct type with one member, whose type is
1801 either T or a `T singleton'. So, the following are all float
1805 struct { struct { float x; } x; };
1806 struct { struct { struct { float x; } x; } x; };
1810 All such structures are passed as if they were floats or doubles,
1811 as the (revised) ABI says. */
1813 is_float_singleton (struct type *type)
1815 if (TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
1817 struct type *singleton_type = TYPE_FIELD_TYPE (type, 0);
1818 CHECK_TYPEDEF (singleton_type);
1820 return (TYPE_CODE (singleton_type) == TYPE_CODE_FLT
1821 || TYPE_CODE (singleton_type) == TYPE_CODE_DECFLOAT
1822 || is_float_singleton (singleton_type));
1829 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
1830 "Struct-like" types are those that should be passed as structs are:
1833 As an odd quirk, not mentioned in the ABI, GCC passes float and
1834 double singletons as if they were a plain float, double, etc. (The
1835 corresponding union types are handled normally.) So we exclude
1836 those types here. *shrug* */
1838 is_struct_like (struct type *type)
1840 enum type_code code = TYPE_CODE (type);
1842 return (code == TYPE_CODE_UNION
1843 || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type)));
1847 /* Return non-zero if TYPE is a float-like type, zero otherwise.
1848 "Float-like" types are those that should be passed as
1849 floating-point values are.
1851 You'd think this would just be floats, doubles, long doubles, etc.
1852 But as an odd quirk, not mentioned in the ABI, GCC passes float and
1853 double singletons as if they were a plain float, double, etc. (The
1854 corresponding union types are handled normally.) So we include
1855 those types here. *shrug* */
1857 is_float_like (struct type *type)
1859 return (TYPE_CODE (type) == TYPE_CODE_FLT
1860 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT
1861 || is_float_singleton (type));
1866 is_power_of_two (unsigned int n)
1868 return ((n & (n - 1)) == 0);
1871 /* Return non-zero if TYPE should be passed as a pointer to a copy,
1874 s390_function_arg_pass_by_reference (struct type *type)
1876 unsigned length = TYPE_LENGTH (type);
1880 /* FIXME: All complex and vector types are also returned by reference. */
1881 return is_struct_like (type) && !is_power_of_two (length);
1884 /* Return non-zero if TYPE should be passed in a float register
1887 s390_function_arg_float (struct type *type)
1889 unsigned length = TYPE_LENGTH (type);
1893 return is_float_like (type);
1896 /* Return non-zero if TYPE should be passed in an integer register
1897 (or a pair of integer registers) if possible. */
1899 s390_function_arg_integer (struct type *type)
1901 unsigned length = TYPE_LENGTH (type);
1905 return is_integer_like (type)
1906 || is_pointer_like (type)
1907 || (is_struct_like (type) && is_power_of_two (length));
1910 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
1911 word as required for the ABI. */
1913 extend_simple_arg (struct value *arg)
1915 struct type *type = value_type (arg);
1917 /* Even structs get passed in the least significant bits of the
1918 register / memory word. It's not really right to extract them as
1919 an integer, but it does take care of the extension. */
1920 if (TYPE_UNSIGNED (type))
1921 return extract_unsigned_integer (value_contents (arg),
1922 TYPE_LENGTH (type));
1924 return extract_signed_integer (value_contents (arg),
1925 TYPE_LENGTH (type));
1929 /* Return the alignment required by TYPE. */
1931 alignment_of (struct type *type)
1935 if (is_integer_like (type)
1936 || is_pointer_like (type)
1937 || TYPE_CODE (type) == TYPE_CODE_FLT
1938 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
1939 alignment = TYPE_LENGTH (type);
1940 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1941 || TYPE_CODE (type) == TYPE_CODE_UNION)
1946 for (i = 0; i < TYPE_NFIELDS (type); i++)
1948 int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i));
1950 if (field_alignment > alignment)
1951 alignment = field_alignment;
1957 /* Check that everything we ever return is a power of two. Lots of
1958 code doesn't want to deal with aligning things to arbitrary
1960 gdb_assert ((alignment & (alignment - 1)) == 0);
1966 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
1967 place to be passed to a function, as specified by the "GNU/Linux
1968 for S/390 ELF Application Binary Interface Supplement".
1970 SP is the current stack pointer. We must put arguments, links,
1971 padding, etc. whereever they belong, and return the new stack
1974 If STRUCT_RETURN is non-zero, then the function we're calling is
1975 going to return a structure by value; STRUCT_ADDR is the address of
1976 a block we've allocated for it on the stack.
1978 Our caller has taken care of any type promotions needed to satisfy
1979 prototypes or the old K&R argument-passing rules. */
1981 s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1982 struct regcache *regcache, CORE_ADDR bp_addr,
1983 int nargs, struct value **args, CORE_ADDR sp,
1984 int struct_return, CORE_ADDR struct_addr)
1986 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1987 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1991 /* If the i'th argument is passed as a reference to a copy, then
1992 copy_addr[i] is the address of the copy we made. */
1993 CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR));
1995 /* Build the reference-to-copy area. */
1996 for (i = 0; i < nargs; i++)
1998 struct value *arg = args[i];
1999 struct type *type = value_type (arg);
2000 unsigned length = TYPE_LENGTH (type);
2002 if (s390_function_arg_pass_by_reference (type))
2005 sp = align_down (sp, alignment_of (type));
2006 write_memory (sp, value_contents (arg), length);
2011 /* Reserve space for the parameter area. As a conservative
2012 simplification, we assume that everything will be passed on the
2013 stack. Since every argument larger than 8 bytes will be
2014 passed by reference, we use this simple upper bound. */
2017 /* After all that, make sure it's still aligned on an eight-byte
2019 sp = align_down (sp, 8);
2021 /* Finally, place the actual parameters, working from SP towards
2022 higher addresses. The code above is supposed to reserve enough
2027 CORE_ADDR starg = sp;
2029 /* A struct is returned using general register 2. */
2032 regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr,
2037 for (i = 0; i < nargs; i++)
2039 struct value *arg = args[i];
2040 struct type *type = value_type (arg);
2041 unsigned length = TYPE_LENGTH (type);
2043 if (s390_function_arg_pass_by_reference (type))
2047 regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr,
2053 write_memory_unsigned_integer (starg, word_size, copy_addr[i]);
2057 else if (s390_function_arg_float (type))
2059 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2060 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2061 if (fr <= (tdep->abi == ABI_LINUX_S390 ? 2 : 6))
2063 /* When we store a single-precision value in an FP register,
2064 it occupies the leftmost bits. */
2065 regcache_cooked_write_part (regcache, S390_F0_REGNUM + fr,
2066 0, length, value_contents (arg));
2071 /* When we store a single-precision value in a stack slot,
2072 it occupies the rightmost bits. */
2073 starg = align_up (starg + length, word_size);
2074 write_memory (starg - length, value_contents (arg), length);
2077 else if (s390_function_arg_integer (type) && length <= word_size)
2081 /* Integer arguments are always extended to word size. */
2082 regcache_cooked_write_signed (regcache, S390_R0_REGNUM + gr,
2083 extend_simple_arg (arg));
2088 /* Integer arguments are always extended to word size. */
2089 write_memory_signed_integer (starg, word_size,
2090 extend_simple_arg (arg));
2094 else if (s390_function_arg_integer (type) && length == 2*word_size)
2098 regcache_cooked_write (regcache, S390_R0_REGNUM + gr,
2099 value_contents (arg));
2100 regcache_cooked_write (regcache, S390_R0_REGNUM + gr + 1,
2101 value_contents (arg) + word_size);
2106 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2107 in it, then don't go back and use it again later. */
2110 write_memory (starg, value_contents (arg), length);
2115 internal_error (__FILE__, __LINE__, _("unknown argument type"));
2119 /* Allocate the standard frame areas: the register save area, the
2120 word reserved for the compiler (which seems kind of meaningless),
2121 and the back chain pointer. */
2122 sp -= 16*word_size + 32;
2124 /* Store return address. */
2125 regcache_cooked_write_unsigned (regcache, S390_RETADDR_REGNUM, bp_addr);
2127 /* Store updated stack pointer. */
2128 regcache_cooked_write_unsigned (regcache, S390_SP_REGNUM, sp);
2130 /* We need to return the 'stack part' of the frame ID,
2131 which is actually the top of the register save area. */
2132 return sp + 16*word_size + 32;
2135 /* Assuming THIS_FRAME is a dummy, return the frame ID of that
2136 dummy frame. The frame ID's base needs to match the TOS value
2137 returned by push_dummy_call, and the PC match the dummy frame's
2139 static struct frame_id
2140 s390_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
2142 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2143 CORE_ADDR sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM);
2144 sp = gdbarch_addr_bits_remove (gdbarch, sp);
2146 return frame_id_build (sp + 16*word_size + 32,
2147 get_frame_pc (this_frame));
2151 s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2153 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2154 always be aligned on an eight-byte boundary. */
2159 /* Function return value access. */
2161 static enum return_value_convention
2162 s390_return_value_convention (struct gdbarch *gdbarch, struct type *type)
2164 int length = TYPE_LENGTH (type);
2166 return RETURN_VALUE_STRUCT_CONVENTION;
2168 switch (TYPE_CODE (type))
2170 case TYPE_CODE_STRUCT:
2171 case TYPE_CODE_UNION:
2172 case TYPE_CODE_ARRAY:
2173 return RETURN_VALUE_STRUCT_CONVENTION;
2176 return RETURN_VALUE_REGISTER_CONVENTION;
2180 static enum return_value_convention
2181 s390_return_value (struct gdbarch *gdbarch, struct type *func_type,
2182 struct type *type, struct regcache *regcache,
2183 gdb_byte *out, const gdb_byte *in)
2185 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2186 int length = TYPE_LENGTH (type);
2187 enum return_value_convention rvc =
2188 s390_return_value_convention (gdbarch, type);
2193 case RETURN_VALUE_REGISTER_CONVENTION:
2194 if (TYPE_CODE (type) == TYPE_CODE_FLT
2195 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
2197 /* When we store a single-precision value in an FP register,
2198 it occupies the leftmost bits. */
2199 regcache_cooked_write_part (regcache, S390_F0_REGNUM,
2202 else if (length <= word_size)
2204 /* Integer arguments are always extended to word size. */
2205 if (TYPE_UNSIGNED (type))
2206 regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM,
2207 extract_unsigned_integer (in, length));
2209 regcache_cooked_write_signed (regcache, S390_R2_REGNUM,
2210 extract_signed_integer (in, length));
2212 else if (length == 2*word_size)
2214 regcache_cooked_write (regcache, S390_R2_REGNUM, in);
2215 regcache_cooked_write (regcache, S390_R3_REGNUM, in + word_size);
2218 internal_error (__FILE__, __LINE__, _("invalid return type"));
2221 case RETURN_VALUE_STRUCT_CONVENTION:
2222 error (_("Cannot set function return value."));
2230 case RETURN_VALUE_REGISTER_CONVENTION:
2231 if (TYPE_CODE (type) == TYPE_CODE_FLT
2232 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
2234 /* When we store a single-precision value in an FP register,
2235 it occupies the leftmost bits. */
2236 regcache_cooked_read_part (regcache, S390_F0_REGNUM,
2239 else if (length <= word_size)
2241 /* Integer arguments occupy the rightmost bits. */
2242 regcache_cooked_read_part (regcache, S390_R2_REGNUM,
2243 word_size - length, length, out);
2245 else if (length == 2*word_size)
2247 regcache_cooked_read (regcache, S390_R2_REGNUM, out);
2248 regcache_cooked_read (regcache, S390_R3_REGNUM, out + word_size);
2251 internal_error (__FILE__, __LINE__, _("invalid return type"));
2254 case RETURN_VALUE_STRUCT_CONVENTION:
2255 error (_("Function return value unknown."));
2266 static const gdb_byte *
2267 s390_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
2269 static const gdb_byte breakpoint[] = { 0x0, 0x1 };
2271 *lenptr = sizeof (breakpoint);
2276 /* Address handling. */
2279 s390_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
2281 return addr & 0x7fffffff;
2285 s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
2288 return TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
2294 s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
2296 if (type_flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
2303 s390_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name,
2304 int *type_flags_ptr)
2306 if (strcmp (name, "mode32") == 0)
2308 *type_flags_ptr = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1;
2315 /* Set up gdbarch struct. */
2317 static struct gdbarch *
2318 s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2320 struct gdbarch *gdbarch;
2321 struct gdbarch_tdep *tdep;
2323 /* First see if there is already a gdbarch that can satisfy the request. */
2324 arches = gdbarch_list_lookup_by_info (arches, &info);
2326 return arches->gdbarch;
2328 /* None found: is the request for a s390 architecture? */
2329 if (info.bfd_arch_info->arch != bfd_arch_s390)
2330 return NULL; /* No; then it's not for us. */
2332 /* Yes: create a new gdbarch for the specified machine type. */
2333 tdep = XCALLOC (1, struct gdbarch_tdep);
2334 gdbarch = gdbarch_alloc (&info, tdep);
2336 set_gdbarch_believe_pcc_promotion (gdbarch, 0);
2337 set_gdbarch_char_signed (gdbarch, 0);
2339 /* S/390 GNU/Linux uses either 64-bit or 128-bit long doubles.
2340 We can safely let them default to 128-bit, since the debug info
2341 will give the size of type actually used in each case. */
2342 set_gdbarch_long_double_bit (gdbarch, 128);
2343 set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad);
2345 /* Amount PC must be decremented by after a breakpoint. This is
2346 often the number of bytes returned by gdbarch_breakpoint_from_pc but not
2348 set_gdbarch_decr_pc_after_break (gdbarch, 2);
2349 /* Stack grows downward. */
2350 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2351 set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc);
2352 set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
2353 set_gdbarch_in_function_epilogue_p (gdbarch, s390_in_function_epilogue_p);
2355 set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM);
2356 set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM);
2357 set_gdbarch_fp0_regnum (gdbarch, S390_F0_REGNUM);
2358 set_gdbarch_num_regs (gdbarch, S390_NUM_REGS);
2359 set_gdbarch_num_pseudo_regs (gdbarch, S390_NUM_PSEUDO_REGS);
2360 set_gdbarch_register_name (gdbarch, s390_register_name);
2361 set_gdbarch_register_type (gdbarch, s390_register_type);
2362 set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2363 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2364 set_gdbarch_value_from_register (gdbarch, s390_value_from_register);
2365 set_gdbarch_register_reggroup_p (gdbarch, s390_register_reggroup_p);
2366 set_gdbarch_regset_from_core_section (gdbarch,
2367 s390_regset_from_core_section);
2369 /* Inferior function calls. */
2370 set_gdbarch_push_dummy_call (gdbarch, s390_push_dummy_call);
2371 set_gdbarch_dummy_id (gdbarch, s390_dummy_id);
2372 set_gdbarch_frame_align (gdbarch, s390_frame_align);
2373 set_gdbarch_return_value (gdbarch, s390_return_value);
2375 /* Frame handling. */
2376 dwarf2_frame_set_init_reg (gdbarch, s390_dwarf2_frame_init_reg);
2377 dwarf2_append_unwinders (gdbarch);
2378 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
2379 frame_unwind_append_unwinder (gdbarch, &s390_stub_frame_unwind);
2380 frame_unwind_append_unwinder (gdbarch, &s390_sigtramp_frame_unwind);
2381 frame_unwind_append_unwinder (gdbarch, &s390_frame_unwind);
2382 frame_base_set_default (gdbarch, &s390_frame_base);
2383 set_gdbarch_unwind_pc (gdbarch, s390_unwind_pc);
2384 set_gdbarch_unwind_sp (gdbarch, s390_unwind_sp);
2386 switch (info.bfd_arch_info->mach)
2388 case bfd_mach_s390_31:
2389 tdep->abi = ABI_LINUX_S390;
2391 tdep->gregset = &s390_gregset;
2392 tdep->sizeof_gregset = s390_sizeof_gregset;
2393 tdep->fpregset = &s390_fpregset;
2394 tdep->sizeof_fpregset = s390_sizeof_fpregset;
2396 set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
2397 set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
2398 set_gdbarch_pseudo_register_write (gdbarch, s390_pseudo_register_write);
2399 set_solib_svr4_fetch_link_map_offsets
2400 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
2403 case bfd_mach_s390_64:
2404 tdep->abi = ABI_LINUX_ZSERIES;
2406 tdep->gregset = &s390x_gregset;
2407 tdep->sizeof_gregset = s390x_sizeof_gregset;
2408 tdep->fpregset = &s390_fpregset;
2409 tdep->sizeof_fpregset = s390_sizeof_fpregset;
2411 set_gdbarch_long_bit (gdbarch, 64);
2412 set_gdbarch_long_long_bit (gdbarch, 64);
2413 set_gdbarch_ptr_bit (gdbarch, 64);
2414 set_gdbarch_pseudo_register_read (gdbarch, s390x_pseudo_register_read);
2415 set_gdbarch_pseudo_register_write (gdbarch, s390x_pseudo_register_write);
2416 set_solib_svr4_fetch_link_map_offsets
2417 (gdbarch, svr4_lp64_fetch_link_map_offsets);
2418 set_gdbarch_address_class_type_flags (gdbarch,
2419 s390_address_class_type_flags);
2420 set_gdbarch_address_class_type_flags_to_name (gdbarch,
2421 s390_address_class_type_flags_to_name);
2422 set_gdbarch_address_class_name_to_type_flags (gdbarch,
2423 s390_address_class_name_to_type_flags);
2427 set_gdbarch_print_insn (gdbarch, print_insn_s390);
2429 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
2431 /* Enable TLS support. */
2432 set_gdbarch_fetch_tls_load_module_address (gdbarch,
2433 svr4_fetch_objfile_link_map);
2440 extern initialize_file_ftype _initialize_s390_tdep; /* -Wmissing-prototypes */
2443 _initialize_s390_tdep (void)
2446 /* Hook us into the gdbarch mechanism. */
2447 register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init);