1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 Free Software Foundation, Inc.
6 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
7 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, USA. */
27 #include "arch-utils.h"
35 #include "floatformat.h"
37 #include "trad-frame.h"
38 #include "frame-base.h"
39 #include "frame-unwind.h"
40 #include "dwarf2-frame.h"
41 #include "reggroups.h"
44 #include "gdb_assert.h"
46 #include "solib-svr4.h"
47 #include "prologue-value.h"
49 #include "s390-tdep.h"
52 /* The tdep structure. */
57 enum { ABI_LINUX_S390, ABI_LINUX_ZSERIES } abi;
59 /* Core file register sets. */
60 const struct regset *gregset;
63 const struct regset *fpregset;
68 /* Register information. */
70 struct s390_register_info
76 static struct s390_register_info s390_register_info[S390_NUM_TOTAL_REGS] =
78 /* Program Status Word. */
79 { "pswm", &builtin_type_long },
80 { "pswa", &builtin_type_long },
82 /* General Purpose Registers. */
83 { "r0", &builtin_type_long },
84 { "r1", &builtin_type_long },
85 { "r2", &builtin_type_long },
86 { "r3", &builtin_type_long },
87 { "r4", &builtin_type_long },
88 { "r5", &builtin_type_long },
89 { "r6", &builtin_type_long },
90 { "r7", &builtin_type_long },
91 { "r8", &builtin_type_long },
92 { "r9", &builtin_type_long },
93 { "r10", &builtin_type_long },
94 { "r11", &builtin_type_long },
95 { "r12", &builtin_type_long },
96 { "r13", &builtin_type_long },
97 { "r14", &builtin_type_long },
98 { "r15", &builtin_type_long },
100 /* Access Registers. */
101 { "acr0", &builtin_type_int },
102 { "acr1", &builtin_type_int },
103 { "acr2", &builtin_type_int },
104 { "acr3", &builtin_type_int },
105 { "acr4", &builtin_type_int },
106 { "acr5", &builtin_type_int },
107 { "acr6", &builtin_type_int },
108 { "acr7", &builtin_type_int },
109 { "acr8", &builtin_type_int },
110 { "acr9", &builtin_type_int },
111 { "acr10", &builtin_type_int },
112 { "acr11", &builtin_type_int },
113 { "acr12", &builtin_type_int },
114 { "acr13", &builtin_type_int },
115 { "acr14", &builtin_type_int },
116 { "acr15", &builtin_type_int },
118 /* Floating Point Control Word. */
119 { "fpc", &builtin_type_int },
121 /* Floating Point Registers. */
122 { "f0", &builtin_type_double },
123 { "f1", &builtin_type_double },
124 { "f2", &builtin_type_double },
125 { "f3", &builtin_type_double },
126 { "f4", &builtin_type_double },
127 { "f5", &builtin_type_double },
128 { "f6", &builtin_type_double },
129 { "f7", &builtin_type_double },
130 { "f8", &builtin_type_double },
131 { "f9", &builtin_type_double },
132 { "f10", &builtin_type_double },
133 { "f11", &builtin_type_double },
134 { "f12", &builtin_type_double },
135 { "f13", &builtin_type_double },
136 { "f14", &builtin_type_double },
137 { "f15", &builtin_type_double },
139 /* Pseudo registers. */
140 { "pc", &builtin_type_void_func_ptr },
141 { "cc", &builtin_type_int },
144 /* Return the name of register REGNUM. */
146 s390_register_name (int regnum)
148 gdb_assert (regnum >= 0 && regnum < S390_NUM_TOTAL_REGS);
149 return s390_register_info[regnum].name;
152 /* Return the GDB type object for the "standard" data type of data in
155 s390_register_type (struct gdbarch *gdbarch, int regnum)
157 gdb_assert (regnum >= 0 && regnum < S390_NUM_TOTAL_REGS);
158 return *s390_register_info[regnum].type;
161 /* DWARF Register Mapping. */
163 static int s390_dwarf_regmap[] =
165 /* General Purpose Registers. */
166 S390_R0_REGNUM, S390_R1_REGNUM, S390_R2_REGNUM, S390_R3_REGNUM,
167 S390_R4_REGNUM, S390_R5_REGNUM, S390_R6_REGNUM, S390_R7_REGNUM,
168 S390_R8_REGNUM, S390_R9_REGNUM, S390_R10_REGNUM, S390_R11_REGNUM,
169 S390_R12_REGNUM, S390_R13_REGNUM, S390_R14_REGNUM, S390_R15_REGNUM,
171 /* Floating Point Registers. */
172 S390_F0_REGNUM, S390_F2_REGNUM, S390_F4_REGNUM, S390_F6_REGNUM,
173 S390_F1_REGNUM, S390_F3_REGNUM, S390_F5_REGNUM, S390_F7_REGNUM,
174 S390_F8_REGNUM, S390_F10_REGNUM, S390_F12_REGNUM, S390_F14_REGNUM,
175 S390_F9_REGNUM, S390_F11_REGNUM, S390_F13_REGNUM, S390_F15_REGNUM,
177 /* Control Registers (not mapped). */
178 -1, -1, -1, -1, -1, -1, -1, -1,
179 -1, -1, -1, -1, -1, -1, -1, -1,
181 /* Access Registers. */
182 S390_A0_REGNUM, S390_A1_REGNUM, S390_A2_REGNUM, S390_A3_REGNUM,
183 S390_A4_REGNUM, S390_A5_REGNUM, S390_A6_REGNUM, S390_A7_REGNUM,
184 S390_A8_REGNUM, S390_A9_REGNUM, S390_A10_REGNUM, S390_A11_REGNUM,
185 S390_A12_REGNUM, S390_A13_REGNUM, S390_A14_REGNUM, S390_A15_REGNUM,
187 /* Program Status Word. */
192 /* Convert DWARF register number REG to the appropriate register
193 number used by GDB. */
195 s390_dwarf_reg_to_regnum (int reg)
199 if (reg >= 0 && reg < ARRAY_SIZE (s390_dwarf_regmap))
200 regnum = s390_dwarf_regmap[reg];
203 warning (_("Unmapped DWARF Register #%d encountered."), reg);
208 /* Pseudo registers - PC and condition code. */
211 s390_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
212 int regnum, gdb_byte *buf)
219 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &val);
220 store_unsigned_integer (buf, 4, val & 0x7fffffff);
224 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val);
225 store_unsigned_integer (buf, 4, (val >> 12) & 3);
229 internal_error (__FILE__, __LINE__, _("invalid regnum"));
234 s390_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
235 int regnum, const gdb_byte *buf)
242 val = extract_unsigned_integer (buf, 4);
243 regcache_raw_read_unsigned (regcache, S390_PSWA_REGNUM, &psw);
244 psw = (psw & 0x80000000) | (val & 0x7fffffff);
245 regcache_raw_write_unsigned (regcache, S390_PSWA_REGNUM, psw);
249 val = extract_unsigned_integer (buf, 4);
250 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
251 psw = (psw & ~((ULONGEST)3 << 12)) | ((val & 3) << 12);
252 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, psw);
256 internal_error (__FILE__, __LINE__, _("invalid regnum"));
261 s390x_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
262 int regnum, gdb_byte *buf)
269 regcache_raw_read (regcache, S390_PSWA_REGNUM, buf);
273 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &val);
274 store_unsigned_integer (buf, 4, (val >> 44) & 3);
278 internal_error (__FILE__, __LINE__, _("invalid regnum"));
283 s390x_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
284 int regnum, const gdb_byte *buf)
291 regcache_raw_write (regcache, S390_PSWA_REGNUM, buf);
295 val = extract_unsigned_integer (buf, 4);
296 regcache_raw_read_unsigned (regcache, S390_PSWM_REGNUM, &psw);
297 psw = (psw & ~((ULONGEST)3 << 44)) | ((val & 3) << 44);
298 regcache_raw_write_unsigned (regcache, S390_PSWM_REGNUM, psw);
302 internal_error (__FILE__, __LINE__, _("invalid regnum"));
306 /* 'float' values are stored in the upper half of floating-point
307 registers, even though we are otherwise a big-endian platform. */
309 static struct value *
310 s390_value_from_register (struct type *type, int regnum,
311 struct frame_info *frame)
313 struct value *value = default_value_from_register (type, regnum, frame);
314 int len = TYPE_LENGTH (type);
316 if (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM && len < 8)
317 set_value_offset (value, 0);
322 /* Register groups. */
325 s390_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
326 struct reggroup *group)
328 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
330 /* Registers displayed via 'info regs'. */
331 if (group == general_reggroup)
332 return (regnum >= S390_R0_REGNUM && regnum <= S390_R15_REGNUM)
333 || regnum == S390_PC_REGNUM
334 || regnum == S390_CC_REGNUM;
336 /* Registers displayed via 'info float'. */
337 if (group == float_reggroup)
338 return (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM)
339 || regnum == S390_FPC_REGNUM;
341 /* Registers that need to be saved/restored in order to
342 push or pop frames. */
343 if (group == save_reggroup || group == restore_reggroup)
344 return regnum != S390_PSWM_REGNUM && regnum != S390_PSWA_REGNUM;
346 return default_register_reggroup_p (gdbarch, regnum, group);
350 /* Core file register sets. */
352 int s390_regmap_gregset[S390_NUM_REGS] =
354 /* Program Status Word. */
356 /* General Purpose Registers. */
357 0x08, 0x0c, 0x10, 0x14,
358 0x18, 0x1c, 0x20, 0x24,
359 0x28, 0x2c, 0x30, 0x34,
360 0x38, 0x3c, 0x40, 0x44,
361 /* Access Registers. */
362 0x48, 0x4c, 0x50, 0x54,
363 0x58, 0x5c, 0x60, 0x64,
364 0x68, 0x6c, 0x70, 0x74,
365 0x78, 0x7c, 0x80, 0x84,
366 /* Floating Point Control Word. */
368 /* Floating Point Registers. */
369 -1, -1, -1, -1, -1, -1, -1, -1,
370 -1, -1, -1, -1, -1, -1, -1, -1,
373 int s390x_regmap_gregset[S390_NUM_REGS] =
376 /* General Purpose Registers. */
377 0x10, 0x18, 0x20, 0x28,
378 0x30, 0x38, 0x40, 0x48,
379 0x50, 0x58, 0x60, 0x68,
380 0x70, 0x78, 0x80, 0x88,
381 /* Access Registers. */
382 0x90, 0x94, 0x98, 0x9c,
383 0xa0, 0xa4, 0xa8, 0xac,
384 0xb0, 0xb4, 0xb8, 0xbc,
385 0xc0, 0xc4, 0xc8, 0xcc,
386 /* Floating Point Control Word. */
388 /* Floating Point Registers. */
389 -1, -1, -1, -1, -1, -1, -1, -1,
390 -1, -1, -1, -1, -1, -1, -1, -1,
393 int s390_regmap_fpregset[S390_NUM_REGS] =
395 /* Program Status Word. */
397 /* General Purpose Registers. */
398 -1, -1, -1, -1, -1, -1, -1, -1,
399 -1, -1, -1, -1, -1, -1, -1, -1,
400 /* Access Registers. */
401 -1, -1, -1, -1, -1, -1, -1, -1,
402 -1, -1, -1, -1, -1, -1, -1, -1,
403 /* Floating Point Control Word. */
405 /* Floating Point Registers. */
406 0x08, 0x10, 0x18, 0x20,
407 0x28, 0x30, 0x38, 0x40,
408 0x48, 0x50, 0x58, 0x60,
409 0x68, 0x70, 0x78, 0x80,
412 /* Supply register REGNUM from the register set REGSET to register cache
413 REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
415 s390_supply_regset (const struct regset *regset, struct regcache *regcache,
416 int regnum, const void *regs, size_t len)
418 const int *offset = regset->descr;
421 for (i = 0; i < S390_NUM_REGS; i++)
423 if ((regnum == i || regnum == -1) && offset[i] != -1)
424 regcache_raw_supply (regcache, i, (const char *)regs + offset[i]);
428 /* Collect register REGNUM from the register cache REGCACHE and store
429 it in the buffer specified by REGS and LEN as described by the
430 general-purpose register set REGSET. If REGNUM is -1, do this for
431 all registers in REGSET. */
433 s390_collect_regset (const struct regset *regset,
434 const struct regcache *regcache,
435 int regnum, void *regs, size_t len)
437 const int *offset = regset->descr;
440 for (i = 0; i < S390_NUM_REGS; i++)
442 if ((regnum == i || regnum == -1) && offset[i] != -1)
443 regcache_raw_collect (regcache, i, (char *)regs + offset[i]);
447 static const struct regset s390_gregset = {
453 static const struct regset s390x_gregset = {
454 s390x_regmap_gregset,
459 static const struct regset s390_fpregset = {
460 s390_regmap_fpregset,
465 /* Return the appropriate register set for the core section identified
466 by SECT_NAME and SECT_SIZE. */
467 const struct regset *
468 s390_regset_from_core_section (struct gdbarch *gdbarch,
469 const char *sect_name, size_t sect_size)
471 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
473 if (strcmp (sect_name, ".reg") == 0 && sect_size == tdep->sizeof_gregset)
474 return tdep->gregset;
476 if (strcmp (sect_name, ".reg2") == 0 && sect_size == tdep->sizeof_fpregset)
477 return tdep->fpregset;
483 /* Decoding S/390 instructions. */
485 /* Named opcode values for the S/390 instructions we recognize. Some
486 instructions have their opcode split across two fields; those are the
487 op1_* and op2_* enums. */
490 op1_lhi = 0xa7, op2_lhi = 0x08,
491 op1_lghi = 0xa7, op2_lghi = 0x09,
492 op1_lgfi = 0xc0, op2_lgfi = 0x01,
496 op1_ly = 0xe3, op2_ly = 0x58,
497 op1_lg = 0xe3, op2_lg = 0x04,
499 op1_lmy = 0xeb, op2_lmy = 0x98,
500 op1_lmg = 0xeb, op2_lmg = 0x04,
502 op1_sty = 0xe3, op2_sty = 0x50,
503 op1_stg = 0xe3, op2_stg = 0x24,
506 op1_stmy = 0xeb, op2_stmy = 0x90,
507 op1_stmg = 0xeb, op2_stmg = 0x24,
508 op1_aghi = 0xa7, op2_aghi = 0x0b,
509 op1_ahi = 0xa7, op2_ahi = 0x0a,
510 op1_agfi = 0xc2, op2_agfi = 0x08,
511 op1_afi = 0xc2, op2_afi = 0x09,
512 op1_algfi= 0xc2, op2_algfi= 0x0a,
513 op1_alfi = 0xc2, op2_alfi = 0x0b,
517 op1_ay = 0xe3, op2_ay = 0x5a,
518 op1_ag = 0xe3, op2_ag = 0x08,
519 op1_slgfi= 0xc2, op2_slgfi= 0x04,
520 op1_slfi = 0xc2, op2_slfi = 0x05,
524 op1_sy = 0xe3, op2_sy = 0x5b,
525 op1_sg = 0xe3, op2_sg = 0x09,
529 op1_lay = 0xe3, op2_lay = 0x71,
530 op1_larl = 0xc0, op2_larl = 0x00,
535 op1_bras = 0xa7, op2_bras = 0x05,
536 op1_brasl= 0xc0, op2_brasl= 0x05,
537 op1_brc = 0xa7, op2_brc = 0x04,
538 op1_brcl = 0xc0, op2_brcl = 0x04,
542 /* Read a single instruction from address AT. */
544 #define S390_MAX_INSTR_SIZE 6
546 s390_readinstruction (bfd_byte instr[], CORE_ADDR at)
548 static int s390_instrlen[] = { 2, 4, 4, 6 };
551 if (read_memory_nobpt (at, &instr[0], 2))
553 instrlen = s390_instrlen[instr[0] >> 6];
556 if (read_memory_nobpt (at + 2, &instr[2], instrlen - 2))
563 /* The functions below are for recognizing and decoding S/390
564 instructions of various formats. Each of them checks whether INSN
565 is an instruction of the given format, with the specified opcodes.
566 If it is, it sets the remaining arguments to the values of the
567 instruction's fields, and returns a non-zero value; otherwise, it
570 These functions' arguments appear in the order they appear in the
571 instruction, not in the machine-language form. So, opcodes always
572 come first, even though they're sometimes scattered around the
573 instructions. And displacements appear before base and extension
574 registers, as they do in the assembly syntax, not at the end, as
575 they do in the machine language. */
577 is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2)
579 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
581 *r1 = (insn[1] >> 4) & 0xf;
582 /* i2 is a 16-bit signed quantity. */
583 *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000;
592 is_ril (bfd_byte *insn, int op1, int op2,
593 unsigned int *r1, int *i2)
595 if (insn[0] == op1 && (insn[1] & 0xf) == op2)
597 *r1 = (insn[1] >> 4) & 0xf;
598 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
599 no sign extension is necessary, but we don't want to assume
601 *i2 = (((insn[2] << 24)
604 | (insn[5])) ^ 0x80000000) - 0x80000000;
613 is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
617 *r1 = (insn[1] >> 4) & 0xf;
627 is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2)
629 if (((insn[0] << 8) | insn[1]) == op)
631 /* Yes, insn[3]. insn[2] is unused in RRE format. */
632 *r1 = (insn[3] >> 4) & 0xf;
642 is_rs (bfd_byte *insn, int op,
643 unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2)
647 *r1 = (insn[1] >> 4) & 0xf;
649 *b2 = (insn[2] >> 4) & 0xf;
650 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
659 is_rsy (bfd_byte *insn, int op1, int op2,
660 unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2)
665 *r1 = (insn[1] >> 4) & 0xf;
667 *b2 = (insn[2] >> 4) & 0xf;
668 /* The 'long displacement' is a 20-bit signed integer. */
669 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
670 ^ 0x80000) - 0x80000;
679 is_rx (bfd_byte *insn, int op,
680 unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2)
684 *r1 = (insn[1] >> 4) & 0xf;
686 *b2 = (insn[2] >> 4) & 0xf;
687 *d2 = ((insn[2] & 0xf) << 8) | insn[3];
696 is_rxy (bfd_byte *insn, int op1, int op2,
697 unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2)
702 *r1 = (insn[1] >> 4) & 0xf;
704 *b2 = (insn[2] >> 4) & 0xf;
705 /* The 'long displacement' is a 20-bit signed integer. */
706 *d2 = ((((insn[2] & 0xf) << 8) | insn[3] | (insn[4] << 12))
707 ^ 0x80000) - 0x80000;
715 /* Prologue analysis. */
717 #define S390_NUM_GPRS 16
718 #define S390_NUM_FPRS 16
720 struct s390_prologue_data {
723 struct pv_area *stack;
725 /* The size of a GPR or FPR. */
729 /* The general-purpose registers. */
730 pv_t gpr[S390_NUM_GPRS];
732 /* The floating-point registers. */
733 pv_t fpr[S390_NUM_FPRS];
735 /* The offset relative to the CFA where the incoming GPR N was saved
736 by the function prologue. 0 if not saved or unknown. */
737 int gpr_slot[S390_NUM_GPRS];
739 /* Likewise for FPRs. */
740 int fpr_slot[S390_NUM_FPRS];
742 /* Nonzero if the backchain was saved. This is assumed to be the
743 case when the incoming SP is saved at the current SP location. */
744 int back_chain_saved_p;
747 /* Return the effective address for an X-style instruction, like:
751 Here, X2 and B2 are registers, and D2 is a signed 20-bit
752 constant; the effective address is the sum of all three. If either
753 X2 or B2 are zero, then it doesn't contribute to the sum --- this
754 means that r0 can't be used as either X2 or B2. */
756 s390_addr (struct s390_prologue_data *data,
757 int d2, unsigned int x2, unsigned int b2)
761 result = pv_constant (d2);
763 result = pv_add (result, data->gpr[x2]);
765 result = pv_add (result, data->gpr[b2]);
770 /* Do a SIZE-byte store of VALUE to D2(X2,B2). */
772 s390_store (struct s390_prologue_data *data,
773 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size,
776 pv_t addr = s390_addr (data, d2, x2, b2);
779 /* Check whether we are storing the backchain. */
780 offset = pv_subtract (data->gpr[S390_SP_REGNUM - S390_R0_REGNUM], addr);
782 if (pv_is_constant (offset) && offset.k == 0)
783 if (size == data->gpr_size
784 && pv_is_register_k (value, S390_SP_REGNUM, 0))
786 data->back_chain_saved_p = 1;
791 /* Check whether we are storing a register into the stack. */
792 if (!pv_area_store_would_trash (data->stack, addr))
793 pv_area_store (data->stack, addr, size, value);
796 /* Note: If this is some store we cannot identify, you might think we
797 should forget our cached values, as any of those might have been hit.
799 However, we make the assumption that the register save areas are only
800 ever stored to once in any given function, and we do recognize these
801 stores. Thus every store we cannot recognize does not hit our data. */
804 /* Do a SIZE-byte load from D2(X2,B2). */
806 s390_load (struct s390_prologue_data *data,
807 int d2, unsigned int x2, unsigned int b2, CORE_ADDR size)
810 pv_t addr = s390_addr (data, d2, x2, b2);
813 /* If it's a load from an in-line constant pool, then we can
814 simulate that, under the assumption that the code isn't
815 going to change between the time the processor actually
816 executed it creating the current frame, and the time when
817 we're analyzing the code to unwind past that frame. */
818 if (pv_is_constant (addr))
820 struct section_table *secp;
821 secp = target_section_by_addr (¤t_target, addr.k);
823 && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
825 return pv_constant (read_memory_integer (addr.k, size));
828 /* Check whether we are accessing one of our save slots. */
829 return pv_area_fetch (data->stack, addr, size);
832 /* Function for finding saved registers in a 'struct pv_area'; we pass
833 this to pv_area_scan.
835 If VALUE is a saved register, ADDR says it was saved at a constant
836 offset from the frame base, and SIZE indicates that the whole
837 register was saved, record its offset in the reg_offset table in
840 s390_check_for_saved (void *data_untyped, pv_t addr, CORE_ADDR size, pv_t value)
842 struct s390_prologue_data *data = data_untyped;
845 if (!pv_is_register (addr, S390_SP_REGNUM))
848 offset = 16 * data->gpr_size + 32 - addr.k;
850 /* If we are storing the original value of a register, we want to
851 record the CFA offset. If the same register is stored multiple
852 times, the stack slot with the highest address counts. */
854 for (i = 0; i < S390_NUM_GPRS; i++)
855 if (size == data->gpr_size
856 && pv_is_register_k (value, S390_R0_REGNUM + i, 0))
857 if (data->gpr_slot[i] == 0
858 || data->gpr_slot[i] > offset)
860 data->gpr_slot[i] = offset;
864 for (i = 0; i < S390_NUM_FPRS; i++)
865 if (size == data->fpr_size
866 && pv_is_register_k (value, S390_F0_REGNUM + i, 0))
867 if (data->fpr_slot[i] == 0
868 || data->fpr_slot[i] > offset)
870 data->fpr_slot[i] = offset;
875 /* Analyze the prologue of the function starting at START_PC,
876 continuing at most until CURRENT_PC. Initialize DATA to
877 hold all information we find out about the state of the registers
878 and stack slots. Return the address of the instruction after
879 the last one that changed the SP, FP, or back chain; or zero
882 s390_analyze_prologue (struct gdbarch *gdbarch,
884 CORE_ADDR current_pc,
885 struct s390_prologue_data *data)
887 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
890 The address of the instruction after the last one that changed
891 the SP, FP, or back chain; zero if we got an error trying to
893 CORE_ADDR result = start_pc;
895 /* The current PC for our abstract interpretation. */
898 /* The address of the next instruction after that. */
901 /* Set up everything's initial value. */
905 data->stack = make_pv_area (S390_SP_REGNUM);
907 /* For the purpose of prologue tracking, we consider the GPR size to
908 be equal to the ABI word size, even if it is actually larger
909 (i.e. when running a 32-bit binary under a 64-bit kernel). */
910 data->gpr_size = word_size;
913 for (i = 0; i < S390_NUM_GPRS; i++)
914 data->gpr[i] = pv_register (S390_R0_REGNUM + i, 0);
916 for (i = 0; i < S390_NUM_FPRS; i++)
917 data->fpr[i] = pv_register (S390_F0_REGNUM + i, 0);
919 for (i = 0; i < S390_NUM_GPRS; i++)
920 data->gpr_slot[i] = 0;
922 for (i = 0; i < S390_NUM_FPRS; i++)
923 data->fpr_slot[i] = 0;
925 data->back_chain_saved_p = 0;
928 /* Start interpreting instructions, until we hit the frame's
929 current PC or the first branch instruction. */
930 for (pc = start_pc; pc > 0 && pc < current_pc; pc = next_pc)
932 bfd_byte insn[S390_MAX_INSTR_SIZE];
933 int insn_len = s390_readinstruction (insn, pc);
935 bfd_byte dummy[S390_MAX_INSTR_SIZE] = { 0 };
936 bfd_byte *insn32 = word_size == 4 ? insn : dummy;
937 bfd_byte *insn64 = word_size == 8 ? insn : dummy;
939 /* Fields for various kinds of instructions. */
940 unsigned int b2, r1, r2, x2, r3;
943 /* The values of SP and FP before this instruction,
944 for detecting instructions that change them. */
945 pv_t pre_insn_sp, pre_insn_fp;
946 /* Likewise for the flag whether the back chain was saved. */
947 int pre_insn_back_chain_saved_p;
949 /* If we got an error trying to read the instruction, report it. */
956 next_pc = pc + insn_len;
958 pre_insn_sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
959 pre_insn_fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
960 pre_insn_back_chain_saved_p = data->back_chain_saved_p;
963 /* LHI r1, i2 --- load halfword immediate. */
964 /* LGHI r1, i2 --- load halfword immediate (64-bit version). */
965 /* LGFI r1, i2 --- load fullword immediate. */
966 if (is_ri (insn32, op1_lhi, op2_lhi, &r1, &i2)
967 || is_ri (insn64, op1_lghi, op2_lghi, &r1, &i2)
968 || is_ril (insn, op1_lgfi, op2_lgfi, &r1, &i2))
969 data->gpr[r1] = pv_constant (i2);
971 /* LR r1, r2 --- load from register. */
972 /* LGR r1, r2 --- load from register (64-bit version). */
973 else if (is_rr (insn32, op_lr, &r1, &r2)
974 || is_rre (insn64, op_lgr, &r1, &r2))
975 data->gpr[r1] = data->gpr[r2];
977 /* L r1, d2(x2, b2) --- load. */
978 /* LY r1, d2(x2, b2) --- load (long-displacement version). */
979 /* LG r1, d2(x2, b2) --- load (64-bit version). */
980 else if (is_rx (insn32, op_l, &r1, &d2, &x2, &b2)
981 || is_rxy (insn32, op1_ly, op2_ly, &r1, &d2, &x2, &b2)
982 || is_rxy (insn64, op1_lg, op2_lg, &r1, &d2, &x2, &b2))
983 data->gpr[r1] = s390_load (data, d2, x2, b2, data->gpr_size);
985 /* ST r1, d2(x2, b2) --- store. */
986 /* STY r1, d2(x2, b2) --- store (long-displacement version). */
987 /* STG r1, d2(x2, b2) --- store (64-bit version). */
988 else if (is_rx (insn32, op_st, &r1, &d2, &x2, &b2)
989 || is_rxy (insn32, op1_sty, op2_sty, &r1, &d2, &x2, &b2)
990 || is_rxy (insn64, op1_stg, op2_stg, &r1, &d2, &x2, &b2))
991 s390_store (data, d2, x2, b2, data->gpr_size, data->gpr[r1]);
993 /* STD r1, d2(x2,b2) --- store floating-point register. */
994 else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2))
995 s390_store (data, d2, x2, b2, data->fpr_size, data->fpr[r1]);
997 /* STM r1, r3, d2(b2) --- store multiple. */
998 /* STMY r1, r3, d2(b2) --- store multiple (long-displacement version). */
999 /* STMG r1, r3, d2(b2) --- store multiple (64-bit version). */
1000 else if (is_rs (insn32, op_stm, &r1, &r3, &d2, &b2)
1001 || is_rsy (insn32, op1_stmy, op2_stmy, &r1, &r3, &d2, &b2)
1002 || is_rsy (insn64, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2))
1004 for (; r1 <= r3; r1++, d2 += data->gpr_size)
1005 s390_store (data, d2, 0, b2, data->gpr_size, data->gpr[r1]);
1008 /* AHI r1, i2 --- add halfword immediate. */
1009 /* AGHI r1, i2 --- add halfword immediate (64-bit version). */
1010 /* AFI r1, i2 --- add fullword immediate. */
1011 /* AGFI r1, i2 --- add fullword immediate (64-bit version). */
1012 else if (is_ri (insn32, op1_ahi, op2_ahi, &r1, &i2)
1013 || is_ri (insn64, op1_aghi, op2_aghi, &r1, &i2)
1014 || is_ril (insn32, op1_afi, op2_afi, &r1, &i2)
1015 || is_ril (insn64, op1_agfi, op2_agfi, &r1, &i2))
1016 data->gpr[r1] = pv_add_constant (data->gpr[r1], i2);
1018 /* ALFI r1, i2 --- add logical immediate. */
1019 /* ALGFI r1, i2 --- add logical immediate (64-bit version). */
1020 else if (is_ril (insn32, op1_alfi, op2_alfi, &r1, &i2)
1021 || is_ril (insn64, op1_algfi, op2_algfi, &r1, &i2))
1022 data->gpr[r1] = pv_add_constant (data->gpr[r1],
1023 (CORE_ADDR)i2 & 0xffffffff);
1025 /* AR r1, r2 -- add register. */
1026 /* AGR r1, r2 -- add register (64-bit version). */
1027 else if (is_rr (insn32, op_ar, &r1, &r2)
1028 || is_rre (insn64, op_agr, &r1, &r2))
1029 data->gpr[r1] = pv_add (data->gpr[r1], data->gpr[r2]);
1031 /* A r1, d2(x2, b2) -- add. */
1032 /* AY r1, d2(x2, b2) -- add (long-displacement version). */
1033 /* AG r1, d2(x2, b2) -- add (64-bit version). */
1034 else if (is_rx (insn32, op_a, &r1, &d2, &x2, &b2)
1035 || is_rxy (insn32, op1_ay, op2_ay, &r1, &d2, &x2, &b2)
1036 || is_rxy (insn64, op1_ag, op2_ag, &r1, &d2, &x2, &b2))
1037 data->gpr[r1] = pv_add (data->gpr[r1],
1038 s390_load (data, d2, x2, b2, data->gpr_size));
1040 /* SLFI r1, i2 --- subtract logical immediate. */
1041 /* SLGFI r1, i2 --- subtract logical immediate (64-bit version). */
1042 else if (is_ril (insn32, op1_slfi, op2_slfi, &r1, &i2)
1043 || is_ril (insn64, op1_slgfi, op2_slgfi, &r1, &i2))
1044 data->gpr[r1] = pv_add_constant (data->gpr[r1],
1045 -((CORE_ADDR)i2 & 0xffffffff));
1047 /* SR r1, r2 -- subtract register. */
1048 /* SGR r1, r2 -- subtract register (64-bit version). */
1049 else if (is_rr (insn32, op_sr, &r1, &r2)
1050 || is_rre (insn64, op_sgr, &r1, &r2))
1051 data->gpr[r1] = pv_subtract (data->gpr[r1], data->gpr[r2]);
1053 /* S r1, d2(x2, b2) -- subtract. */
1054 /* SY r1, d2(x2, b2) -- subtract (long-displacement version). */
1055 /* SG r1, d2(x2, b2) -- subtract (64-bit version). */
1056 else if (is_rx (insn32, op_s, &r1, &d2, &x2, &b2)
1057 || is_rxy (insn32, op1_sy, op2_sy, &r1, &d2, &x2, &b2)
1058 || is_rxy (insn64, op1_sg, op2_sg, &r1, &d2, &x2, &b2))
1059 data->gpr[r1] = pv_subtract (data->gpr[r1],
1060 s390_load (data, d2, x2, b2, data->gpr_size));
1062 /* LA r1, d2(x2, b2) --- load address. */
1063 /* LAY r1, d2(x2, b2) --- load address (long-displacement version). */
1064 else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2)
1065 || is_rxy (insn, op1_lay, op2_lay, &r1, &d2, &x2, &b2))
1066 data->gpr[r1] = s390_addr (data, d2, x2, b2);
1068 /* LARL r1, i2 --- load address relative long. */
1069 else if (is_ril (insn, op1_larl, op2_larl, &r1, &i2))
1070 data->gpr[r1] = pv_constant (pc + i2 * 2);
1072 /* BASR r1, 0 --- branch and save.
1073 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1074 else if (is_rr (insn, op_basr, &r1, &r2)
1076 data->gpr[r1] = pv_constant (next_pc);
1078 /* BRAS r1, i2 --- branch relative and save. */
1079 else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2))
1081 data->gpr[r1] = pv_constant (next_pc);
1082 next_pc = pc + i2 * 2;
1084 /* We'd better not interpret any backward branches. We'll
1090 /* Terminate search when hitting any other branch instruction. */
1091 else if (is_rr (insn, op_basr, &r1, &r2)
1092 || is_rx (insn, op_bas, &r1, &d2, &x2, &b2)
1093 || is_rr (insn, op_bcr, &r1, &r2)
1094 || is_rx (insn, op_bc, &r1, &d2, &x2, &b2)
1095 || is_ri (insn, op1_brc, op2_brc, &r1, &i2)
1096 || is_ril (insn, op1_brcl, op2_brcl, &r1, &i2)
1097 || is_ril (insn, op1_brasl, op2_brasl, &r2, &i2))
1101 /* An instruction we don't know how to simulate. The only
1102 safe thing to do would be to set every value we're tracking
1103 to 'unknown'. Instead, we'll be optimistic: we assume that
1104 we *can* interpret every instruction that the compiler uses
1105 to manipulate any of the data we're interested in here --
1106 then we can just ignore anything else. */
1109 /* Record the address after the last instruction that changed
1110 the FP, SP, or backlink. Ignore instructions that changed
1111 them back to their original values --- those are probably
1112 restore instructions. (The back chain is never restored,
1115 pv_t sp = data->gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1116 pv_t fp = data->gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1118 if ((! pv_is_identical (pre_insn_sp, sp)
1119 && ! pv_is_register_k (sp, S390_SP_REGNUM, 0)
1120 && sp.kind != pvk_unknown)
1121 || (! pv_is_identical (pre_insn_fp, fp)
1122 && ! pv_is_register_k (fp, S390_FRAME_REGNUM, 0)
1123 && fp.kind != pvk_unknown)
1124 || pre_insn_back_chain_saved_p != data->back_chain_saved_p)
1129 /* Record where all the registers were saved. */
1130 pv_area_scan (data->stack, s390_check_for_saved, data);
1132 free_pv_area (data->stack);
1138 /* Advance PC across any function entry prologue instructions to reach
1139 some "real" code. */
1141 s390_skip_prologue (CORE_ADDR pc)
1143 struct s390_prologue_data data;
1145 skip_pc = s390_analyze_prologue (current_gdbarch, pc, (CORE_ADDR)-1, &data);
1146 return skip_pc ? skip_pc : pc;
1149 /* Return true if we are in the functin's epilogue, i.e. after the
1150 instruction that destroyed the function's stack frame. */
1152 s390_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
1154 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1156 /* In frameless functions, there's not frame to destroy and thus
1157 we don't care about the epilogue.
1159 In functions with frame, the epilogue sequence is a pair of
1160 a LM-type instruction that restores (amongst others) the
1161 return register %r14 and the stack pointer %r15, followed
1162 by a branch 'br %r14' --or equivalent-- that effects the
1165 In that situation, this function needs to return 'true' in
1166 exactly one case: when pc points to that branch instruction.
1168 Thus we try to disassemble the one instructions immediately
1169 preceeding pc and check whether it is an LM-type instruction
1170 modifying the stack pointer.
1172 Note that disassembling backwards is not reliable, so there
1173 is a slight chance of false positives here ... */
1176 unsigned int r1, r3, b2;
1180 && !read_memory_nobpt (pc - 4, insn, 4)
1181 && is_rs (insn, op_lm, &r1, &r3, &d2, &b2)
1182 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1186 && !read_memory_nobpt (pc - 6, insn, 6)
1187 && is_rsy (insn, op1_lmy, op2_lmy, &r1, &r3, &d2, &b2)
1188 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1192 && !read_memory_nobpt (pc - 6, insn, 6)
1193 && is_rsy (insn, op1_lmg, op2_lmg, &r1, &r3, &d2, &b2)
1194 && r3 == S390_SP_REGNUM - S390_R0_REGNUM)
1201 /* Normal stack frames. */
1203 struct s390_unwind_cache {
1206 CORE_ADDR frame_base;
1207 CORE_ADDR local_base;
1209 struct trad_frame_saved_reg *saved_regs;
1213 s390_prologue_frame_unwind_cache (struct frame_info *next_frame,
1214 struct s390_unwind_cache *info)
1216 struct gdbarch *gdbarch = get_frame_arch (next_frame);
1217 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1218 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1219 struct s390_prologue_data data;
1220 pv_t *fp = &data.gpr[S390_FRAME_REGNUM - S390_R0_REGNUM];
1221 pv_t *sp = &data.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1231 /* Try to find the function start address. If we can't find it, we don't
1232 bother searching for it -- with modern compilers this would be mostly
1233 pointless anyway. Trust that we'll either have valid DWARF-2 CFI data
1234 or else a valid backchain ... */
1235 func = frame_func_unwind (next_frame, NORMAL_FRAME);
1239 /* Try to analyze the prologue. */
1240 result = s390_analyze_prologue (gdbarch, func,
1241 frame_pc_unwind (next_frame), &data);
1245 /* If this was successful, we should have found the instruction that
1246 sets the stack pointer register to the previous value of the stack
1247 pointer minus the frame size. */
1248 if (!pv_is_register (*sp, S390_SP_REGNUM))
1251 /* A frame size of zero at this point can mean either a real
1252 frameless function, or else a failure to find the prologue.
1253 Perform some sanity checks to verify we really have a
1254 frameless function. */
1257 /* If the next frame is a NORMAL_FRAME, this frame *cannot* have frame
1258 size zero. This is only possible if the next frame is a sentinel
1259 frame, a dummy frame, or a signal trampoline frame. */
1260 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be
1261 needed, instead the code should simpliy rely on its
1263 if (get_frame_type (next_frame) == NORMAL_FRAME)
1266 /* If we really have a frameless function, %r14 must be valid
1267 -- in particular, it must point to a different function. */
1268 reg = frame_unwind_register_unsigned (next_frame, S390_RETADDR_REGNUM);
1269 reg = gdbarch_addr_bits_remove (gdbarch, reg) - 1;
1270 if (get_pc_function_start (reg) == func)
1272 /* However, there is one case where it *is* valid for %r14
1273 to point to the same function -- if this is a recursive
1274 call, and we have stopped in the prologue *before* the
1275 stack frame was allocated.
1277 Recognize this case by looking ahead a bit ... */
1279 struct s390_prologue_data data2;
1280 pv_t *sp = &data2.gpr[S390_SP_REGNUM - S390_R0_REGNUM];
1282 if (!(s390_analyze_prologue (gdbarch, func, (CORE_ADDR)-1, &data2)
1283 && pv_is_register (*sp, S390_SP_REGNUM)
1290 /* OK, we've found valid prologue data. */
1293 /* If the frame pointer originally also holds the same value
1294 as the stack pointer, we're probably using it. If it holds
1295 some other value -- even a constant offset -- it is most
1296 likely used as temp register. */
1297 if (pv_is_identical (*sp, *fp))
1298 frame_pointer = S390_FRAME_REGNUM;
1300 frame_pointer = S390_SP_REGNUM;
1302 /* If we've detected a function with stack frame, we'll still have to
1303 treat it as frameless if we're currently within the function epilog
1304 code at a point where the frame pointer has already been restored.
1305 This can only happen in an innermost frame. */
1306 /* FIXME: cagney/2004-05-01: This sanity check shouldn't be needed,
1307 instead the code should simpliy rely on its analysis. */
1308 if (size > 0 && get_frame_type (next_frame) != NORMAL_FRAME)
1310 /* See the comment in s390_in_function_epilogue_p on why this is
1311 not completely reliable ... */
1312 if (s390_in_function_epilogue_p (gdbarch, frame_pc_unwind (next_frame)))
1314 memset (&data, 0, sizeof (data));
1316 frame_pointer = S390_SP_REGNUM;
1320 /* Once we know the frame register and the frame size, we can unwind
1321 the current value of the frame register from the next frame, and
1322 add back the frame size to arrive that the previous frame's
1323 stack pointer value. */
1324 prev_sp = frame_unwind_register_unsigned (next_frame, frame_pointer) + size;
1325 cfa = prev_sp + 16*word_size + 32;
1327 /* Record the addresses of all register spill slots the prologue parser
1328 has recognized. Consider only registers defined as call-saved by the
1329 ABI; for call-clobbered registers the parser may have recognized
1332 for (i = 6; i <= 15; i++)
1333 if (data.gpr_slot[i] != 0)
1334 info->saved_regs[S390_R0_REGNUM + i].addr = cfa - data.gpr_slot[i];
1338 case ABI_LINUX_S390:
1339 if (data.fpr_slot[4] != 0)
1340 info->saved_regs[S390_F4_REGNUM].addr = cfa - data.fpr_slot[4];
1341 if (data.fpr_slot[6] != 0)
1342 info->saved_regs[S390_F6_REGNUM].addr = cfa - data.fpr_slot[6];
1345 case ABI_LINUX_ZSERIES:
1346 for (i = 8; i <= 15; i++)
1347 if (data.fpr_slot[i] != 0)
1348 info->saved_regs[S390_F0_REGNUM + i].addr = cfa - data.fpr_slot[i];
1352 /* Function return will set PC to %r14. */
1353 info->saved_regs[S390_PC_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM];
1355 /* In frameless functions, we unwind simply by moving the return
1356 address to the PC. However, if we actually stored to the
1357 save area, use that -- we might only think the function frameless
1358 because we're in the middle of the prologue ... */
1360 && !trad_frame_addr_p (info->saved_regs, S390_PC_REGNUM))
1362 info->saved_regs[S390_PC_REGNUM].realreg = S390_RETADDR_REGNUM;
1365 /* Another sanity check: unless this is a frameless function,
1366 we should have found spill slots for SP and PC.
1367 If not, we cannot unwind further -- this happens e.g. in
1368 libc's thread_start routine. */
1371 if (!trad_frame_addr_p (info->saved_regs, S390_SP_REGNUM)
1372 || !trad_frame_addr_p (info->saved_regs, S390_PC_REGNUM))
1376 /* We use the current value of the frame register as local_base,
1377 and the top of the register save area as frame_base. */
1380 info->frame_base = prev_sp + 16*word_size + 32;
1381 info->local_base = prev_sp - size;
1389 s390_backchain_frame_unwind_cache (struct frame_info *next_frame,
1390 struct s390_unwind_cache *info)
1392 struct gdbarch *gdbarch = get_frame_arch (next_frame);
1393 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1394 CORE_ADDR backchain;
1398 /* Get the backchain. */
1399 reg = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
1400 backchain = read_memory_unsigned_integer (reg, word_size);
1402 /* A zero backchain terminates the frame chain. As additional
1403 sanity check, let's verify that the spill slot for SP in the
1404 save area pointed to by the backchain in fact links back to
1407 && safe_read_memory_integer (backchain + 15*word_size, word_size, &sp)
1408 && (CORE_ADDR)sp == backchain)
1410 /* We don't know which registers were saved, but it will have
1411 to be at least %r14 and %r15. This will allow us to continue
1412 unwinding, but other prev-frame registers may be incorrect ... */
1413 info->saved_regs[S390_SP_REGNUM].addr = backchain + 15*word_size;
1414 info->saved_regs[S390_RETADDR_REGNUM].addr = backchain + 14*word_size;
1416 /* Function return will set PC to %r14. */
1417 info->saved_regs[S390_PC_REGNUM] = info->saved_regs[S390_RETADDR_REGNUM];
1419 /* We use the current value of the frame register as local_base,
1420 and the top of the register save area as frame_base. */
1421 info->frame_base = backchain + 16*word_size + 32;
1422 info->local_base = reg;
1425 info->func = frame_pc_unwind (next_frame);
1428 static struct s390_unwind_cache *
1429 s390_frame_unwind_cache (struct frame_info *next_frame,
1430 void **this_prologue_cache)
1432 struct s390_unwind_cache *info;
1433 if (*this_prologue_cache)
1434 return *this_prologue_cache;
1436 info = FRAME_OBSTACK_ZALLOC (struct s390_unwind_cache);
1437 *this_prologue_cache = info;
1438 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1440 info->frame_base = -1;
1441 info->local_base = -1;
1443 /* Try to use prologue analysis to fill the unwind cache.
1444 If this fails, fall back to reading the stack backchain. */
1445 if (!s390_prologue_frame_unwind_cache (next_frame, info))
1446 s390_backchain_frame_unwind_cache (next_frame, info);
1452 s390_frame_this_id (struct frame_info *next_frame,
1453 void **this_prologue_cache,
1454 struct frame_id *this_id)
1456 struct s390_unwind_cache *info
1457 = s390_frame_unwind_cache (next_frame, this_prologue_cache);
1459 if (info->frame_base == -1)
1462 *this_id = frame_id_build (info->frame_base, info->func);
1466 s390_frame_prev_register (struct frame_info *next_frame,
1467 void **this_prologue_cache,
1468 int regnum, int *optimizedp,
1469 enum lval_type *lvalp, CORE_ADDR *addrp,
1470 int *realnump, gdb_byte *bufferp)
1472 struct s390_unwind_cache *info
1473 = s390_frame_unwind_cache (next_frame, this_prologue_cache);
1474 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
1475 optimizedp, lvalp, addrp, realnump, bufferp);
1478 static const struct frame_unwind s390_frame_unwind = {
1481 s390_frame_prev_register
1484 static const struct frame_unwind *
1485 s390_frame_sniffer (struct frame_info *next_frame)
1487 return &s390_frame_unwind;
1491 /* Code stubs and their stack frames. For things like PLTs and NULL
1492 function calls (where there is no true frame and the return address
1493 is in the RETADDR register). */
1495 struct s390_stub_unwind_cache
1497 CORE_ADDR frame_base;
1498 struct trad_frame_saved_reg *saved_regs;
1501 static struct s390_stub_unwind_cache *
1502 s390_stub_frame_unwind_cache (struct frame_info *next_frame,
1503 void **this_prologue_cache)
1505 struct gdbarch *gdbarch = get_frame_arch (next_frame);
1506 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1507 struct s390_stub_unwind_cache *info;
1510 if (*this_prologue_cache)
1511 return *this_prologue_cache;
1513 info = FRAME_OBSTACK_ZALLOC (struct s390_stub_unwind_cache);
1514 *this_prologue_cache = info;
1515 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1517 /* The return address is in register %r14. */
1518 info->saved_regs[S390_PC_REGNUM].realreg = S390_RETADDR_REGNUM;
1520 /* Retrieve stack pointer and determine our frame base. */
1521 reg = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
1522 info->frame_base = reg + 16*word_size + 32;
1528 s390_stub_frame_this_id (struct frame_info *next_frame,
1529 void **this_prologue_cache,
1530 struct frame_id *this_id)
1532 struct s390_stub_unwind_cache *info
1533 = s390_stub_frame_unwind_cache (next_frame, this_prologue_cache);
1534 *this_id = frame_id_build (info->frame_base, frame_pc_unwind (next_frame));
1538 s390_stub_frame_prev_register (struct frame_info *next_frame,
1539 void **this_prologue_cache,
1540 int regnum, int *optimizedp,
1541 enum lval_type *lvalp, CORE_ADDR *addrp,
1542 int *realnump, gdb_byte *bufferp)
1544 struct s390_stub_unwind_cache *info
1545 = s390_stub_frame_unwind_cache (next_frame, this_prologue_cache);
1546 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
1547 optimizedp, lvalp, addrp, realnump, bufferp);
1550 static const struct frame_unwind s390_stub_frame_unwind = {
1552 s390_stub_frame_this_id,
1553 s390_stub_frame_prev_register
1556 static const struct frame_unwind *
1557 s390_stub_frame_sniffer (struct frame_info *next_frame)
1559 CORE_ADDR addr_in_block;
1560 bfd_byte insn[S390_MAX_INSTR_SIZE];
1562 /* If the current PC points to non-readable memory, we assume we
1563 have trapped due to an invalid function pointer call. We handle
1564 the non-existing current function like a PLT stub. */
1565 addr_in_block = frame_unwind_address_in_block (next_frame, NORMAL_FRAME);
1566 if (in_plt_section (addr_in_block, NULL)
1567 || s390_readinstruction (insn, frame_pc_unwind (next_frame)) < 0)
1568 return &s390_stub_frame_unwind;
1573 /* Signal trampoline stack frames. */
1575 struct s390_sigtramp_unwind_cache {
1576 CORE_ADDR frame_base;
1577 struct trad_frame_saved_reg *saved_regs;
1580 static struct s390_sigtramp_unwind_cache *
1581 s390_sigtramp_frame_unwind_cache (struct frame_info *next_frame,
1582 void **this_prologue_cache)
1584 struct gdbarch *gdbarch = get_frame_arch (next_frame);
1585 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
1586 struct s390_sigtramp_unwind_cache *info;
1587 ULONGEST this_sp, prev_sp;
1588 CORE_ADDR next_ra, next_cfa, sigreg_ptr;
1591 if (*this_prologue_cache)
1592 return *this_prologue_cache;
1594 info = FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache);
1595 *this_prologue_cache = info;
1596 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
1598 this_sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
1599 next_ra = frame_pc_unwind (next_frame);
1600 next_cfa = this_sp + 16*word_size + 32;
1602 /* New-style RT frame:
1603 retcode + alignment (8 bytes)
1605 ucontext (contains sigregs at offset 5 words) */
1606 if (next_ra == next_cfa)
1608 sigreg_ptr = next_cfa + 8 + 128 + align_up (5*word_size, 8);
1611 /* Old-style RT frame and all non-RT frames:
1612 old signal mask (8 bytes)
1613 pointer to sigregs */
1616 sigreg_ptr = read_memory_unsigned_integer (next_cfa + 8, word_size);
1619 /* The sigregs structure looks like this:
1628 /* Let's ignore the PSW mask, it will not be restored anyway. */
1629 sigreg_ptr += word_size;
1631 /* Next comes the PSW address. */
1632 info->saved_regs[S390_PC_REGNUM].addr = sigreg_ptr;
1633 sigreg_ptr += word_size;
1635 /* Then the GPRs. */
1636 for (i = 0; i < 16; i++)
1638 info->saved_regs[S390_R0_REGNUM + i].addr = sigreg_ptr;
1639 sigreg_ptr += word_size;
1642 /* Then the ACRs. */
1643 for (i = 0; i < 16; i++)
1645 info->saved_regs[S390_A0_REGNUM + i].addr = sigreg_ptr;
1649 /* The floating-point control word. */
1650 info->saved_regs[S390_FPC_REGNUM].addr = sigreg_ptr;
1653 /* And finally the FPRs. */
1654 for (i = 0; i < 16; i++)
1656 info->saved_regs[S390_F0_REGNUM + i].addr = sigreg_ptr;
1660 /* Restore the previous frame's SP. */
1661 prev_sp = read_memory_unsigned_integer (
1662 info->saved_regs[S390_SP_REGNUM].addr,
1665 /* Determine our frame base. */
1666 info->frame_base = prev_sp + 16*word_size + 32;
1672 s390_sigtramp_frame_this_id (struct frame_info *next_frame,
1673 void **this_prologue_cache,
1674 struct frame_id *this_id)
1676 struct s390_sigtramp_unwind_cache *info
1677 = s390_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache);
1678 *this_id = frame_id_build (info->frame_base, frame_pc_unwind (next_frame));
1682 s390_sigtramp_frame_prev_register (struct frame_info *next_frame,
1683 void **this_prologue_cache,
1684 int regnum, int *optimizedp,
1685 enum lval_type *lvalp, CORE_ADDR *addrp,
1686 int *realnump, gdb_byte *bufferp)
1688 struct s390_sigtramp_unwind_cache *info
1689 = s390_sigtramp_frame_unwind_cache (next_frame, this_prologue_cache);
1690 trad_frame_get_prev_register (next_frame, info->saved_regs, regnum,
1691 optimizedp, lvalp, addrp, realnump, bufferp);
1694 static const struct frame_unwind s390_sigtramp_frame_unwind = {
1696 s390_sigtramp_frame_this_id,
1697 s390_sigtramp_frame_prev_register
1700 static const struct frame_unwind *
1701 s390_sigtramp_frame_sniffer (struct frame_info *next_frame)
1703 CORE_ADDR pc = frame_pc_unwind (next_frame);
1704 bfd_byte sigreturn[2];
1706 if (read_memory_nobpt (pc, sigreturn, 2))
1709 if (sigreturn[0] != 0x0a /* svc */)
1712 if (sigreturn[1] != 119 /* sigreturn */
1713 && sigreturn[1] != 173 /* rt_sigreturn */)
1716 return &s390_sigtramp_frame_unwind;
1720 /* Frame base handling. */
1723 s390_frame_base_address (struct frame_info *next_frame, void **this_cache)
1725 struct s390_unwind_cache *info
1726 = s390_frame_unwind_cache (next_frame, this_cache);
1727 return info->frame_base;
1731 s390_local_base_address (struct frame_info *next_frame, void **this_cache)
1733 struct s390_unwind_cache *info
1734 = s390_frame_unwind_cache (next_frame, this_cache);
1735 return info->local_base;
1738 static const struct frame_base s390_frame_base = {
1740 s390_frame_base_address,
1741 s390_local_base_address,
1742 s390_local_base_address
1746 s390_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1749 pc = frame_unwind_register_unsigned (next_frame, S390_PC_REGNUM);
1750 return gdbarch_addr_bits_remove (gdbarch, pc);
1754 s390_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1757 sp = frame_unwind_register_unsigned (next_frame, S390_SP_REGNUM);
1758 return gdbarch_addr_bits_remove (gdbarch, sp);
1762 /* DWARF-2 frame support. */
1765 s390_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1766 struct dwarf2_frame_state_reg *reg,
1767 struct frame_info *next_frame)
1769 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1773 case ABI_LINUX_S390:
1774 /* Call-saved registers. */
1775 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
1776 || regnum == S390_F4_REGNUM
1777 || regnum == S390_F6_REGNUM)
1778 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1780 /* Call-clobbered registers. */
1781 else if ((regnum >= S390_R0_REGNUM && regnum <= S390_R5_REGNUM)
1782 || (regnum >= S390_F0_REGNUM && regnum <= S390_F15_REGNUM
1783 && regnum != S390_F4_REGNUM && regnum != S390_F6_REGNUM))
1784 reg->how = DWARF2_FRAME_REG_UNDEFINED;
1786 /* The return address column. */
1787 else if (regnum == S390_PC_REGNUM)
1788 reg->how = DWARF2_FRAME_REG_RA;
1791 case ABI_LINUX_ZSERIES:
1792 /* Call-saved registers. */
1793 if ((regnum >= S390_R6_REGNUM && regnum <= S390_R15_REGNUM)
1794 || (regnum >= S390_F8_REGNUM && regnum <= S390_F15_REGNUM))
1795 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1797 /* Call-clobbered registers. */
1798 else if ((regnum >= S390_R0_REGNUM && regnum <= S390_R5_REGNUM)
1799 || (regnum >= S390_F0_REGNUM && regnum <= S390_F7_REGNUM))
1800 reg->how = DWARF2_FRAME_REG_UNDEFINED;
1802 /* The return address column. */
1803 else if (regnum == S390_PC_REGNUM)
1804 reg->how = DWARF2_FRAME_REG_RA;
1810 /* Dummy function calls. */
1812 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
1813 "Integer-like" types are those that should be passed the way
1814 integers are: integers, enums, ranges, characters, and booleans. */
1816 is_integer_like (struct type *type)
1818 enum type_code code = TYPE_CODE (type);
1820 return (code == TYPE_CODE_INT
1821 || code == TYPE_CODE_ENUM
1822 || code == TYPE_CODE_RANGE
1823 || code == TYPE_CODE_CHAR
1824 || code == TYPE_CODE_BOOL);
1827 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
1828 "Pointer-like" types are those that should be passed the way
1829 pointers are: pointers and references. */
1831 is_pointer_like (struct type *type)
1833 enum type_code code = TYPE_CODE (type);
1835 return (code == TYPE_CODE_PTR
1836 || code == TYPE_CODE_REF);
1840 /* Return non-zero if TYPE is a `float singleton' or `double
1841 singleton', zero otherwise.
1843 A `T singleton' is a struct type with one member, whose type is
1844 either T or a `T singleton'. So, the following are all float
1848 struct { struct { float x; } x; };
1849 struct { struct { struct { float x; } x; } x; };
1853 All such structures are passed as if they were floats or doubles,
1854 as the (revised) ABI says. */
1856 is_float_singleton (struct type *type)
1858 if (TYPE_CODE (type) == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
1860 struct type *singleton_type = TYPE_FIELD_TYPE (type, 0);
1861 CHECK_TYPEDEF (singleton_type);
1863 return (TYPE_CODE (singleton_type) == TYPE_CODE_FLT
1864 || is_float_singleton (singleton_type));
1871 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
1872 "Struct-like" types are those that should be passed as structs are:
1875 As an odd quirk, not mentioned in the ABI, GCC passes float and
1876 double singletons as if they were a plain float, double, etc. (The
1877 corresponding union types are handled normally.) So we exclude
1878 those types here. *shrug* */
1880 is_struct_like (struct type *type)
1882 enum type_code code = TYPE_CODE (type);
1884 return (code == TYPE_CODE_UNION
1885 || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type)));
1889 /* Return non-zero if TYPE is a float-like type, zero otherwise.
1890 "Float-like" types are those that should be passed as
1891 floating-point values are.
1893 You'd think this would just be floats, doubles, long doubles, etc.
1894 But as an odd quirk, not mentioned in the ABI, GCC passes float and
1895 double singletons as if they were a plain float, double, etc. (The
1896 corresponding union types are handled normally.) So we include
1897 those types here. *shrug* */
1899 is_float_like (struct type *type)
1901 return (TYPE_CODE (type) == TYPE_CODE_FLT
1902 || is_float_singleton (type));
1907 is_power_of_two (unsigned int n)
1909 return ((n & (n - 1)) == 0);
1912 /* Return non-zero if TYPE should be passed as a pointer to a copy,
1915 s390_function_arg_pass_by_reference (struct type *type)
1917 unsigned length = TYPE_LENGTH (type);
1921 /* FIXME: All complex and vector types are also returned by reference. */
1922 return is_struct_like (type) && !is_power_of_two (length);
1925 /* Return non-zero if TYPE should be passed in a float register
1928 s390_function_arg_float (struct type *type)
1930 unsigned length = TYPE_LENGTH (type);
1934 return is_float_like (type);
1937 /* Return non-zero if TYPE should be passed in an integer register
1938 (or a pair of integer registers) if possible. */
1940 s390_function_arg_integer (struct type *type)
1942 unsigned length = TYPE_LENGTH (type);
1946 return is_integer_like (type)
1947 || is_pointer_like (type)
1948 || (is_struct_like (type) && is_power_of_two (length));
1951 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
1952 word as required for the ABI. */
1954 extend_simple_arg (struct value *arg)
1956 struct type *type = value_type (arg);
1958 /* Even structs get passed in the least significant bits of the
1959 register / memory word. It's not really right to extract them as
1960 an integer, but it does take care of the extension. */
1961 if (TYPE_UNSIGNED (type))
1962 return extract_unsigned_integer (value_contents (arg),
1963 TYPE_LENGTH (type));
1965 return extract_signed_integer (value_contents (arg),
1966 TYPE_LENGTH (type));
1970 /* Return the alignment required by TYPE. */
1972 alignment_of (struct type *type)
1976 if (is_integer_like (type)
1977 || is_pointer_like (type)
1978 || TYPE_CODE (type) == TYPE_CODE_FLT)
1979 alignment = TYPE_LENGTH (type);
1980 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1981 || TYPE_CODE (type) == TYPE_CODE_UNION)
1986 for (i = 0; i < TYPE_NFIELDS (type); i++)
1988 int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i));
1990 if (field_alignment > alignment)
1991 alignment = field_alignment;
1997 /* Check that everything we ever return is a power of two. Lots of
1998 code doesn't want to deal with aligning things to arbitrary
2000 gdb_assert ((alignment & (alignment - 1)) == 0);
2006 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2007 place to be passed to a function, as specified by the "GNU/Linux
2008 for S/390 ELF Application Binary Interface Supplement".
2010 SP is the current stack pointer. We must put arguments, links,
2011 padding, etc. whereever they belong, and return the new stack
2014 If STRUCT_RETURN is non-zero, then the function we're calling is
2015 going to return a structure by value; STRUCT_ADDR is the address of
2016 a block we've allocated for it on the stack.
2018 Our caller has taken care of any type promotions needed to satisfy
2019 prototypes or the old K&R argument-passing rules. */
2021 s390_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
2022 struct regcache *regcache, CORE_ADDR bp_addr,
2023 int nargs, struct value **args, CORE_ADDR sp,
2024 int struct_return, CORE_ADDR struct_addr)
2026 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
2027 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2031 /* If the i'th argument is passed as a reference to a copy, then
2032 copy_addr[i] is the address of the copy we made. */
2033 CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR));
2035 /* Build the reference-to-copy area. */
2036 for (i = 0; i < nargs; i++)
2038 struct value *arg = args[i];
2039 struct type *type = value_type (arg);
2040 unsigned length = TYPE_LENGTH (type);
2042 if (s390_function_arg_pass_by_reference (type))
2045 sp = align_down (sp, alignment_of (type));
2046 write_memory (sp, value_contents (arg), length);
2051 /* Reserve space for the parameter area. As a conservative
2052 simplification, we assume that everything will be passed on the
2053 stack. Since every argument larger than 8 bytes will be
2054 passed by reference, we use this simple upper bound. */
2057 /* After all that, make sure it's still aligned on an eight-byte
2059 sp = align_down (sp, 8);
2061 /* Finally, place the actual parameters, working from SP towards
2062 higher addresses. The code above is supposed to reserve enough
2067 CORE_ADDR starg = sp;
2069 /* A struct is returned using general register 2. */
2072 regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr,
2077 for (i = 0; i < nargs; i++)
2079 struct value *arg = args[i];
2080 struct type *type = value_type (arg);
2081 unsigned length = TYPE_LENGTH (type);
2083 if (s390_function_arg_pass_by_reference (type))
2087 regcache_cooked_write_unsigned (regcache, S390_R0_REGNUM + gr,
2093 write_memory_unsigned_integer (starg, word_size, copy_addr[i]);
2097 else if (s390_function_arg_float (type))
2099 /* The GNU/Linux for S/390 ABI uses FPRs 0 and 2 to pass arguments,
2100 the GNU/Linux for zSeries ABI uses 0, 2, 4, and 6. */
2101 if (fr <= (tdep->abi == ABI_LINUX_S390 ? 2 : 6))
2103 /* When we store a single-precision value in an FP register,
2104 it occupies the leftmost bits. */
2105 regcache_cooked_write_part (regcache, S390_F0_REGNUM + fr,
2106 0, length, value_contents (arg));
2111 /* When we store a single-precision value in a stack slot,
2112 it occupies the rightmost bits. */
2113 starg = align_up (starg + length, word_size);
2114 write_memory (starg - length, value_contents (arg), length);
2117 else if (s390_function_arg_integer (type) && length <= word_size)
2121 /* Integer arguments are always extended to word size. */
2122 regcache_cooked_write_signed (regcache, S390_R0_REGNUM + gr,
2123 extend_simple_arg (arg));
2128 /* Integer arguments are always extended to word size. */
2129 write_memory_signed_integer (starg, word_size,
2130 extend_simple_arg (arg));
2134 else if (s390_function_arg_integer (type) && length == 2*word_size)
2138 regcache_cooked_write (regcache, S390_R0_REGNUM + gr,
2139 value_contents (arg));
2140 regcache_cooked_write (regcache, S390_R0_REGNUM + gr + 1,
2141 value_contents (arg) + word_size);
2146 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2147 in it, then don't go back and use it again later. */
2150 write_memory (starg, value_contents (arg), length);
2155 internal_error (__FILE__, __LINE__, _("unknown argument type"));
2159 /* Allocate the standard frame areas: the register save area, the
2160 word reserved for the compiler (which seems kind of meaningless),
2161 and the back chain pointer. */
2162 sp -= 16*word_size + 32;
2164 /* Store return address. */
2165 regcache_cooked_write_unsigned (regcache, S390_RETADDR_REGNUM, bp_addr);
2167 /* Store updated stack pointer. */
2168 regcache_cooked_write_unsigned (regcache, S390_SP_REGNUM, sp);
2170 /* We need to return the 'stack part' of the frame ID,
2171 which is actually the top of the register save area. */
2172 return sp + 16*word_size + 32;
2175 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
2176 dummy frame. The frame ID's base needs to match the TOS value
2177 returned by push_dummy_call, and the PC match the dummy frame's
2179 static struct frame_id
2180 s390_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
2182 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2183 CORE_ADDR sp = s390_unwind_sp (gdbarch, next_frame);
2185 return frame_id_build (sp + 16*word_size + 32,
2186 frame_pc_unwind (next_frame));
2190 s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
2192 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2193 always be aligned on an eight-byte boundary. */
2198 /* Function return value access. */
2200 static enum return_value_convention
2201 s390_return_value_convention (struct gdbarch *gdbarch, struct type *type)
2203 int length = TYPE_LENGTH (type);
2205 return RETURN_VALUE_STRUCT_CONVENTION;
2207 switch (TYPE_CODE (type))
2209 case TYPE_CODE_STRUCT:
2210 case TYPE_CODE_UNION:
2211 case TYPE_CODE_ARRAY:
2212 return RETURN_VALUE_STRUCT_CONVENTION;
2215 return RETURN_VALUE_REGISTER_CONVENTION;
2219 static enum return_value_convention
2220 s390_return_value (struct gdbarch *gdbarch, struct type *type,
2221 struct regcache *regcache, gdb_byte *out,
2224 int word_size = gdbarch_ptr_bit (gdbarch) / 8;
2225 int length = TYPE_LENGTH (type);
2226 enum return_value_convention rvc =
2227 s390_return_value_convention (gdbarch, type);
2232 case RETURN_VALUE_REGISTER_CONVENTION:
2233 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2235 /* When we store a single-precision value in an FP register,
2236 it occupies the leftmost bits. */
2237 regcache_cooked_write_part (regcache, S390_F0_REGNUM,
2240 else if (length <= word_size)
2242 /* Integer arguments are always extended to word size. */
2243 if (TYPE_UNSIGNED (type))
2244 regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM,
2245 extract_unsigned_integer (in, length));
2247 regcache_cooked_write_signed (regcache, S390_R2_REGNUM,
2248 extract_signed_integer (in, length));
2250 else if (length == 2*word_size)
2252 regcache_cooked_write (regcache, S390_R2_REGNUM, in);
2253 regcache_cooked_write (regcache, S390_R3_REGNUM, in + word_size);
2256 internal_error (__FILE__, __LINE__, _("invalid return type"));
2259 case RETURN_VALUE_STRUCT_CONVENTION:
2260 error (_("Cannot set function return value."));
2268 case RETURN_VALUE_REGISTER_CONVENTION:
2269 if (TYPE_CODE (type) == TYPE_CODE_FLT)
2271 /* When we store a single-precision value in an FP register,
2272 it occupies the leftmost bits. */
2273 regcache_cooked_read_part (regcache, S390_F0_REGNUM,
2276 else if (length <= word_size)
2278 /* Integer arguments occupy the rightmost bits. */
2279 regcache_cooked_read_part (regcache, S390_R2_REGNUM,
2280 word_size - length, length, out);
2282 else if (length == 2*word_size)
2284 regcache_cooked_read (regcache, S390_R2_REGNUM, out);
2285 regcache_cooked_read (regcache, S390_R3_REGNUM, out + word_size);
2288 internal_error (__FILE__, __LINE__, _("invalid return type"));
2291 case RETURN_VALUE_STRUCT_CONVENTION:
2292 error (_("Function return value unknown."));
2303 static const gdb_byte *
2304 s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
2306 static const gdb_byte breakpoint[] = { 0x0, 0x1 };
2308 *lenptr = sizeof (breakpoint);
2313 /* Address handling. */
2316 s390_addr_bits_remove (CORE_ADDR addr)
2318 return addr & 0x7fffffff;
2322 s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
2325 return TYPE_FLAG_ADDRESS_CLASS_1;
2331 s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
2333 if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1)
2340 s390_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name,
2341 int *type_flags_ptr)
2343 if (strcmp (name, "mode32") == 0)
2345 *type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1;
2352 /* Set up gdbarch struct. */
2354 static struct gdbarch *
2355 s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2357 struct gdbarch *gdbarch;
2358 struct gdbarch_tdep *tdep;
2360 /* First see if there is already a gdbarch that can satisfy the request. */
2361 arches = gdbarch_list_lookup_by_info (arches, &info);
2363 return arches->gdbarch;
2365 /* None found: is the request for a s390 architecture? */
2366 if (info.bfd_arch_info->arch != bfd_arch_s390)
2367 return NULL; /* No; then it's not for us. */
2369 /* Yes: create a new gdbarch for the specified machine type. */
2370 tdep = XCALLOC (1, struct gdbarch_tdep);
2371 gdbarch = gdbarch_alloc (&info, tdep);
2373 set_gdbarch_believe_pcc_promotion (gdbarch, 0);
2374 set_gdbarch_char_signed (gdbarch, 0);
2376 /* Amount PC must be decremented by after a breakpoint. This is
2377 often the number of bytes returned by gdbarch_breakpoint_from_pc but not
2379 set_gdbarch_decr_pc_after_break (gdbarch, 2);
2380 /* Stack grows downward. */
2381 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2382 set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc);
2383 set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
2384 set_gdbarch_in_function_epilogue_p (gdbarch, s390_in_function_epilogue_p);
2386 set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM);
2387 set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM);
2388 set_gdbarch_fp0_regnum (gdbarch, S390_F0_REGNUM);
2389 set_gdbarch_num_regs (gdbarch, S390_NUM_REGS);
2390 set_gdbarch_num_pseudo_regs (gdbarch, S390_NUM_PSEUDO_REGS);
2391 set_gdbarch_register_name (gdbarch, s390_register_name);
2392 set_gdbarch_register_type (gdbarch, s390_register_type);
2393 set_gdbarch_stab_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2394 set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2395 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_dwarf_reg_to_regnum);
2396 set_gdbarch_value_from_register (gdbarch, s390_value_from_register);
2397 set_gdbarch_register_reggroup_p (gdbarch, s390_register_reggroup_p);
2398 set_gdbarch_regset_from_core_section (gdbarch,
2399 s390_regset_from_core_section);
2401 /* Inferior function calls. */
2402 set_gdbarch_push_dummy_call (gdbarch, s390_push_dummy_call);
2403 set_gdbarch_unwind_dummy_id (gdbarch, s390_unwind_dummy_id);
2404 set_gdbarch_frame_align (gdbarch, s390_frame_align);
2405 set_gdbarch_return_value (gdbarch, s390_return_value);
2407 /* Frame handling. */
2408 dwarf2_frame_set_init_reg (gdbarch, s390_dwarf2_frame_init_reg);
2409 frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
2410 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
2411 frame_unwind_append_sniffer (gdbarch, s390_stub_frame_sniffer);
2412 frame_unwind_append_sniffer (gdbarch, s390_sigtramp_frame_sniffer);
2413 frame_unwind_append_sniffer (gdbarch, s390_frame_sniffer);
2414 frame_base_set_default (gdbarch, &s390_frame_base);
2415 set_gdbarch_unwind_pc (gdbarch, s390_unwind_pc);
2416 set_gdbarch_unwind_sp (gdbarch, s390_unwind_sp);
2418 switch (info.bfd_arch_info->mach)
2420 case bfd_mach_s390_31:
2421 tdep->abi = ABI_LINUX_S390;
2423 tdep->gregset = &s390_gregset;
2424 tdep->sizeof_gregset = s390_sizeof_gregset;
2425 tdep->fpregset = &s390_fpregset;
2426 tdep->sizeof_fpregset = s390_sizeof_fpregset;
2428 set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
2429 set_gdbarch_pseudo_register_read (gdbarch, s390_pseudo_register_read);
2430 set_gdbarch_pseudo_register_write (gdbarch, s390_pseudo_register_write);
2431 set_solib_svr4_fetch_link_map_offsets
2432 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
2435 case bfd_mach_s390_64:
2436 tdep->abi = ABI_LINUX_ZSERIES;
2438 tdep->gregset = &s390x_gregset;
2439 tdep->sizeof_gregset = s390x_sizeof_gregset;
2440 tdep->fpregset = &s390_fpregset;
2441 tdep->sizeof_fpregset = s390_sizeof_fpregset;
2443 set_gdbarch_long_bit (gdbarch, 64);
2444 set_gdbarch_long_long_bit (gdbarch, 64);
2445 set_gdbarch_ptr_bit (gdbarch, 64);
2446 set_gdbarch_pseudo_register_read (gdbarch, s390x_pseudo_register_read);
2447 set_gdbarch_pseudo_register_write (gdbarch, s390x_pseudo_register_write);
2448 set_solib_svr4_fetch_link_map_offsets
2449 (gdbarch, svr4_lp64_fetch_link_map_offsets);
2450 set_gdbarch_address_class_type_flags (gdbarch,
2451 s390_address_class_type_flags);
2452 set_gdbarch_address_class_type_flags_to_name (gdbarch,
2453 s390_address_class_type_flags_to_name);
2454 set_gdbarch_address_class_name_to_type_flags (gdbarch,
2455 s390_address_class_name_to_type_flags);
2459 set_gdbarch_print_insn (gdbarch, print_insn_s390);
2461 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
2463 /* Enable TLS support. */
2464 set_gdbarch_fetch_tls_load_module_address (gdbarch,
2465 svr4_fetch_objfile_link_map);
2472 extern initialize_file_ftype _initialize_s390_tdep; /* -Wmissing-prototypes */
2475 _initialize_s390_tdep (void)
2478 /* Hook us into the gdbarch mechanism. */
2479 register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init);