1*7304104dSAndroid Build Coastguard Worker /* Function return value location for Linux/PPC64 ABI.
2*7304104dSAndroid Build Coastguard Worker Copyright (C) 2005-2010, 2014 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker
5*7304104dSAndroid Build Coastguard Worker This file is free software; you can redistribute it and/or modify
6*7304104dSAndroid Build Coastguard Worker it under the terms of either
7*7304104dSAndroid Build Coastguard Worker
8*7304104dSAndroid Build Coastguard Worker * the GNU Lesser General Public License as published by the Free
9*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 3 of the License, or (at
10*7304104dSAndroid Build Coastguard Worker your option) any later version
11*7304104dSAndroid Build Coastguard Worker
12*7304104dSAndroid Build Coastguard Worker or
13*7304104dSAndroid Build Coastguard Worker
14*7304104dSAndroid Build Coastguard Worker * the GNU General Public License as published by the Free
15*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 2 of the License, or (at
16*7304104dSAndroid Build Coastguard Worker your option) any later version
17*7304104dSAndroid Build Coastguard Worker
18*7304104dSAndroid Build Coastguard Worker or both in parallel, as here.
19*7304104dSAndroid Build Coastguard Worker
20*7304104dSAndroid Build Coastguard Worker elfutils is distributed in the hope that it will be useful, but
21*7304104dSAndroid Build Coastguard Worker WITHOUT ANY WARRANTY; without even the implied warranty of
22*7304104dSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23*7304104dSAndroid Build Coastguard Worker General Public License for more details.
24*7304104dSAndroid Build Coastguard Worker
25*7304104dSAndroid Build Coastguard Worker You should have received copies of the GNU General Public License and
26*7304104dSAndroid Build Coastguard Worker the GNU Lesser General Public License along with this program. If
27*7304104dSAndroid Build Coastguard Worker not, see <http://www.gnu.org/licenses/>. */
28*7304104dSAndroid Build Coastguard Worker
29*7304104dSAndroid Build Coastguard Worker #ifdef HAVE_CONFIG_H
30*7304104dSAndroid Build Coastguard Worker # include <config.h>
31*7304104dSAndroid Build Coastguard Worker #endif
32*7304104dSAndroid Build Coastguard Worker
33*7304104dSAndroid Build Coastguard Worker #include <assert.h>
34*7304104dSAndroid Build Coastguard Worker #include <dwarf.h>
35*7304104dSAndroid Build Coastguard Worker
36*7304104dSAndroid Build Coastguard Worker #define BACKEND ppc64_
37*7304104dSAndroid Build Coastguard Worker #include "libebl_CPU.h"
38*7304104dSAndroid Build Coastguard Worker
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Worker /* r3. */
41*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_intreg[] =
42*7304104dSAndroid Build Coastguard Worker {
43*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg3 }
44*7304104dSAndroid Build Coastguard Worker };
45*7304104dSAndroid Build Coastguard Worker #define nloc_intreg 1
46*7304104dSAndroid Build Coastguard Worker
47*7304104dSAndroid Build Coastguard Worker /* f1, or f1:f2, or f1:f4. */
48*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_fpreg[] =
49*7304104dSAndroid Build Coastguard Worker {
50*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_regx, .number = 33 }, { .atom = DW_OP_piece, .number = 8 },
51*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_regx, .number = 34 }, { .atom = DW_OP_piece, .number = 8 },
52*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_regx, .number = 35 }, { .atom = DW_OP_piece, .number = 8 },
53*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_regx, .number = 36 }, { .atom = DW_OP_piece, .number = 8 },
54*7304104dSAndroid Build Coastguard Worker };
55*7304104dSAndroid Build Coastguard Worker #define nloc_fpreg 1
56*7304104dSAndroid Build Coastguard Worker #define nloc_fp2regs 4
57*7304104dSAndroid Build Coastguard Worker #define nloc_fp4regs 8
58*7304104dSAndroid Build Coastguard Worker
59*7304104dSAndroid Build Coastguard Worker /* vr2. */
60*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_vmxreg[] =
61*7304104dSAndroid Build Coastguard Worker {
62*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_regx, .number = 1124 + 2 }
63*7304104dSAndroid Build Coastguard Worker };
64*7304104dSAndroid Build Coastguard Worker #define nloc_vmxreg 1
65*7304104dSAndroid Build Coastguard Worker
66*7304104dSAndroid Build Coastguard Worker /* The return value is a structure and is actually stored in stack space
67*7304104dSAndroid Build Coastguard Worker passed in a hidden argument by the caller. But, the compiler
68*7304104dSAndroid Build Coastguard Worker helpfully returns the address of that space in r3. */
69*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_aggregate[] =
70*7304104dSAndroid Build Coastguard Worker {
71*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_breg3, .number = 0 }
72*7304104dSAndroid Build Coastguard Worker };
73*7304104dSAndroid Build Coastguard Worker #define nloc_aggregate 1
74*7304104dSAndroid Build Coastguard Worker
75*7304104dSAndroid Build Coastguard Worker int
ppc64_return_value_location(Dwarf_Die * functypedie,const Dwarf_Op ** locp)76*7304104dSAndroid Build Coastguard Worker ppc64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
77*7304104dSAndroid Build Coastguard Worker {
78*7304104dSAndroid Build Coastguard Worker /* Start with the function's type, and get the DW_AT_type attribute,
79*7304104dSAndroid Build Coastguard Worker which is the type of the return value. */
80*7304104dSAndroid Build Coastguard Worker Dwarf_Die die_mem, *typedie = &die_mem;
81*7304104dSAndroid Build Coastguard Worker int tag = dwarf_peeled_die_type (functypedie, typedie);
82*7304104dSAndroid Build Coastguard Worker if (tag <= 0)
83*7304104dSAndroid Build Coastguard Worker return tag;
84*7304104dSAndroid Build Coastguard Worker
85*7304104dSAndroid Build Coastguard Worker Dwarf_Word size;
86*7304104dSAndroid Build Coastguard Worker switch (tag)
87*7304104dSAndroid Build Coastguard Worker {
88*7304104dSAndroid Build Coastguard Worker case -1:
89*7304104dSAndroid Build Coastguard Worker return -1;
90*7304104dSAndroid Build Coastguard Worker
91*7304104dSAndroid Build Coastguard Worker case DW_TAG_subrange_type:
92*7304104dSAndroid Build Coastguard Worker if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
93*7304104dSAndroid Build Coastguard Worker {
94*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem, *attr;
95*7304104dSAndroid Build Coastguard Worker attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
96*7304104dSAndroid Build Coastguard Worker typedie = dwarf_formref_die (attr, &die_mem);
97*7304104dSAndroid Build Coastguard Worker tag = DWARF_TAG_OR_RETURN (typedie);
98*7304104dSAndroid Build Coastguard Worker }
99*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
100*7304104dSAndroid Build Coastguard Worker
101*7304104dSAndroid Build Coastguard Worker case DW_TAG_base_type:
102*7304104dSAndroid Build Coastguard Worker case DW_TAG_enumeration_type:
103*7304104dSAndroid Build Coastguard Worker CASE_POINTER:
104*7304104dSAndroid Build Coastguard Worker {
105*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem;
106*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
107*7304104dSAndroid Build Coastguard Worker &attr_mem), &size) != 0)
108*7304104dSAndroid Build Coastguard Worker {
109*7304104dSAndroid Build Coastguard Worker if (dwarf_is_pointer (tag))
110*7304104dSAndroid Build Coastguard Worker size = 8;
111*7304104dSAndroid Build Coastguard Worker else
112*7304104dSAndroid Build Coastguard Worker return -1;
113*7304104dSAndroid Build Coastguard Worker }
114*7304104dSAndroid Build Coastguard Worker }
115*7304104dSAndroid Build Coastguard Worker
116*7304104dSAndroid Build Coastguard Worker if (tag == DW_TAG_base_type)
117*7304104dSAndroid Build Coastguard Worker {
118*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem;
119*7304104dSAndroid Build Coastguard Worker Dwarf_Word encoding;
120*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
121*7304104dSAndroid Build Coastguard Worker &attr_mem),
122*7304104dSAndroid Build Coastguard Worker &encoding) != 0)
123*7304104dSAndroid Build Coastguard Worker return -1;
124*7304104dSAndroid Build Coastguard Worker
125*7304104dSAndroid Build Coastguard Worker if (encoding == DW_ATE_float || encoding == DW_ATE_complex_float)
126*7304104dSAndroid Build Coastguard Worker {
127*7304104dSAndroid Build Coastguard Worker *locp = loc_fpreg;
128*7304104dSAndroid Build Coastguard Worker if (size <= 8)
129*7304104dSAndroid Build Coastguard Worker return nloc_fpreg;
130*7304104dSAndroid Build Coastguard Worker if (size <= 16)
131*7304104dSAndroid Build Coastguard Worker return nloc_fp2regs;
132*7304104dSAndroid Build Coastguard Worker if (size <= 32)
133*7304104dSAndroid Build Coastguard Worker return nloc_fp4regs;
134*7304104dSAndroid Build Coastguard Worker }
135*7304104dSAndroid Build Coastguard Worker }
136*7304104dSAndroid Build Coastguard Worker if (size <= 8)
137*7304104dSAndroid Build Coastguard Worker {
138*7304104dSAndroid Build Coastguard Worker intreg:
139*7304104dSAndroid Build Coastguard Worker *locp = loc_intreg;
140*7304104dSAndroid Build Coastguard Worker return nloc_intreg;
141*7304104dSAndroid Build Coastguard Worker }
142*7304104dSAndroid Build Coastguard Worker
143*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
144*7304104dSAndroid Build Coastguard Worker case DW_TAG_structure_type:
145*7304104dSAndroid Build Coastguard Worker case DW_TAG_class_type:
146*7304104dSAndroid Build Coastguard Worker case DW_TAG_union_type:
147*7304104dSAndroid Build Coastguard Worker aggregate:
148*7304104dSAndroid Build Coastguard Worker *locp = loc_aggregate;
149*7304104dSAndroid Build Coastguard Worker return nloc_aggregate;
150*7304104dSAndroid Build Coastguard Worker
151*7304104dSAndroid Build Coastguard Worker case DW_TAG_array_type:
152*7304104dSAndroid Build Coastguard Worker {
153*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem;
154*7304104dSAndroid Build Coastguard Worker bool is_vector;
155*7304104dSAndroid Build Coastguard Worker if (dwarf_formflag (dwarf_attr_integrate (typedie, DW_AT_GNU_vector,
156*7304104dSAndroid Build Coastguard Worker &attr_mem), &is_vector) == 0
157*7304104dSAndroid Build Coastguard Worker && is_vector)
158*7304104dSAndroid Build Coastguard Worker {
159*7304104dSAndroid Build Coastguard Worker *locp = loc_vmxreg;
160*7304104dSAndroid Build Coastguard Worker return nloc_vmxreg;
161*7304104dSAndroid Build Coastguard Worker }
162*7304104dSAndroid Build Coastguard Worker }
163*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
164*7304104dSAndroid Build Coastguard Worker
165*7304104dSAndroid Build Coastguard Worker case DW_TAG_string_type:
166*7304104dSAndroid Build Coastguard Worker if (dwarf_aggregate_size (typedie, &size) == 0 && size <= 8)
167*7304104dSAndroid Build Coastguard Worker {
168*7304104dSAndroid Build Coastguard Worker if (tag == DW_TAG_array_type)
169*7304104dSAndroid Build Coastguard Worker {
170*7304104dSAndroid Build Coastguard Worker /* Check if it's a character array. */
171*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem, *attr;
172*7304104dSAndroid Build Coastguard Worker attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
173*7304104dSAndroid Build Coastguard Worker typedie = dwarf_formref_die (attr, &die_mem);
174*7304104dSAndroid Build Coastguard Worker tag = DWARF_TAG_OR_RETURN (typedie);
175*7304104dSAndroid Build Coastguard Worker if (tag != DW_TAG_base_type)
176*7304104dSAndroid Build Coastguard Worker goto aggregate;
177*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie,
178*7304104dSAndroid Build Coastguard Worker DW_AT_byte_size,
179*7304104dSAndroid Build Coastguard Worker &attr_mem),
180*7304104dSAndroid Build Coastguard Worker &size) != 0)
181*7304104dSAndroid Build Coastguard Worker return -1;
182*7304104dSAndroid Build Coastguard Worker if (size != 1)
183*7304104dSAndroid Build Coastguard Worker goto aggregate;
184*7304104dSAndroid Build Coastguard Worker }
185*7304104dSAndroid Build Coastguard Worker goto intreg;
186*7304104dSAndroid Build Coastguard Worker }
187*7304104dSAndroid Build Coastguard Worker goto aggregate;
188*7304104dSAndroid Build Coastguard Worker }
189*7304104dSAndroid Build Coastguard Worker
190*7304104dSAndroid Build Coastguard Worker /* XXX We don't have a good way to return specific errors from ebl calls.
191*7304104dSAndroid Build Coastguard Worker This value means we do not understand the type, but it is well-formed
192*7304104dSAndroid Build Coastguard Worker DWARF and might be valid. */
193*7304104dSAndroid Build Coastguard Worker return -2;
194*7304104dSAndroid Build Coastguard Worker }
195