blob: a927d46a05a3833d16dce4e4537be55b51e93f85 [file] [log] [blame]
Roland McGrath321327a2006-01-13 00:51:21 +00001/* Function return value location for S/390 ABI.
Petr Machataba9e5152014-06-20 22:59:43 +02002 Copyright (C) 2006, 2007, 2014 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Roland McGrath321327a2006-01-13 00:51:21 +00004
Mark Wielaardde2ed972012-06-05 17:15:16 +02005 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
Roland McGrath321327a2006-01-13 00:51:21 +00007
Mark Wielaardde2ed972012-06-05 17:15:16 +02008 * the GNU Lesser General Public License as published by the Free
9 Software Foundation; either version 3 of the License, or (at
10 your option) any later version
11
12 or
13
14 * the GNU General Public License as published by the Free
15 Software Foundation; either version 2 of the License, or (at
16 your option) any later version
17
18 or both in parallel, as here.
19
20 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000021 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
Mark Wielaardde2ed972012-06-05 17:15:16 +020025 You should have received copies of the GNU General Public License and
26 the GNU Lesser General Public License along with this program. If
27 not, see <http://www.gnu.org/licenses/>. */
Roland McGrath321327a2006-01-13 00:51:21 +000028
29#ifdef HAVE_CONFIG_H
30# include <config.h>
31#endif
32
33#include <assert.h>
34#include <dwarf.h>
35
36#define BACKEND s390_
37#include "libebl_CPU.h"
38
39
40/* %r2, or pair %r2, %r3. */
41static const Dwarf_Op loc_intreg[] =
42 {
43 { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 4 },
44 { .atom = DW_OP_reg3 }, { .atom = DW_OP_piece, .number = 4 },
45 };
46#define nloc_intreg 1
47#define nloc_intregpair 4
48
49/* %f0. */
50static const Dwarf_Op loc_fpreg[] =
51 {
52 { .atom = DW_OP_reg16 },
53 };
54#define nloc_fpreg 1
55
56/* The return value is a structure and is actually stored in stack space
57 passed in a hidden argument by the caller. But, the compiler
58 helpfully returns the address of that space in %r2. */
59static const Dwarf_Op loc_aggregate[] =
60 {
61 { .atom = DW_OP_breg2, .number = 0 }
62 };
63#define nloc_aggregate 1
64
65
66int
67s390_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
68{
69 /* Start with the function's type, and get the DW_AT_type attribute,
70 which is the type of the return value. */
Petr Machataba9e5152014-06-20 22:59:43 +020071 Dwarf_Die die_mem, *typedie = &die_mem;
72 int tag = dwarf_peeled_die_type (functypedie, typedie);
73 if (tag <= 0)
74 return tag;
Roland McGrath321327a2006-01-13 00:51:21 +000075
76 Dwarf_Word size;
77 switch (tag)
78 {
79 case -1:
80 return -1;
81
82 case DW_TAG_subrange_type:
Roland McGrathc76f0b02007-09-27 07:31:33 +000083 if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
Roland McGrath321327a2006-01-13 00:51:21 +000084 {
Petr Machataba9e5152014-06-20 22:59:43 +020085 Dwarf_Attribute attr_mem, *attr;
Roland McGrath321327a2006-01-13 00:51:21 +000086 attr = dwarf_attr (typedie, DW_AT_type, &attr_mem);
87 typedie = dwarf_formref_die (attr, &die_mem);
Mark Wielaard1d5037f2013-02-06 13:15:10 +010088 tag = DWARF_TAG_OR_RETURN (typedie);
Roland McGrath321327a2006-01-13 00:51:21 +000089 }
90 /* Fall through. */
91
92 case DW_TAG_base_type:
93 case DW_TAG_enumeration_type:
94 case DW_TAG_pointer_type:
95 case DW_TAG_ptr_to_member_type:
96 {
97 Dwarf_Die cudie;
98 uint8_t asize;
99 if (dwarf_diecu (typedie, &cudie, &asize, NULL) == NULL)
100 return -1;
101
Petr Machataba9e5152014-06-20 22:59:43 +0200102 Dwarf_Attribute attr_mem;
Roland McGrath321327a2006-01-13 00:51:21 +0000103 if (dwarf_formudata (dwarf_attr (typedie, DW_AT_byte_size,
104 &attr_mem), &size) != 0)
105 {
106 if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
107 size = asize;
108 else
109 return -1;
110 }
111 if (tag == DW_TAG_base_type)
112 {
113 Dwarf_Word encoding;
Roland McGrathc76f0b02007-09-27 07:31:33 +0000114 if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
115 &attr_mem),
116 &encoding) != 0)
Roland McGrath321327a2006-01-13 00:51:21 +0000117 return -1;
118 if (encoding == DW_ATE_float && size <= 8)
119 {
120 *locp = loc_fpreg;
121 return nloc_fpreg;
122 }
123 }
124 if (size <= 8)
125 {
126 *locp = loc_intreg;
127 return size <= asize ? nloc_intreg : nloc_intregpair;
128 }
129 }
130 /* Fall through. */
131
132 case DW_TAG_structure_type:
133 case DW_TAG_class_type:
134 case DW_TAG_union_type:
135 case DW_TAG_array_type:
136 *locp = loc_aggregate;
137 return nloc_aggregate;
138 }
139
140 /* XXX We don't have a good way to return specific errors from ebl calls.
141 This value means we do not understand the type, but it is well-formed
142 DWARF and might be valid. */
143 return -2;
144}