1*7304104dSAndroid Build Coastguard Worker /* Function return value location for Linux/i386 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 i386_
37*7304104dSAndroid Build Coastguard Worker #include "libebl_CPU.h"
38*7304104dSAndroid Build Coastguard Worker
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Worker /* %eax, or pair %eax, %edx. */
41*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_intreg[] =
42*7304104dSAndroid Build Coastguard Worker {
43*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg0 }, { .atom = DW_OP_piece, .number = 4 },
44*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 4 },
45*7304104dSAndroid Build Coastguard Worker };
46*7304104dSAndroid Build Coastguard Worker #define nloc_intreg 1
47*7304104dSAndroid Build Coastguard Worker #define nloc_intregpair 4
48*7304104dSAndroid Build Coastguard Worker
49*7304104dSAndroid Build Coastguard Worker /* %st(0). */
50*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_fpreg[] =
51*7304104dSAndroid Build Coastguard Worker {
52*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg11 }
53*7304104dSAndroid Build Coastguard Worker };
54*7304104dSAndroid Build Coastguard Worker #define nloc_fpreg 1
55*7304104dSAndroid Build Coastguard Worker
56*7304104dSAndroid Build Coastguard Worker /* The return value is a structure and is actually stored in stack space
57*7304104dSAndroid Build Coastguard Worker passed in a hidden argument by the caller. But, the compiler
58*7304104dSAndroid Build Coastguard Worker helpfully returns the address of that space in %eax. */
59*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_aggregate[] =
60*7304104dSAndroid Build Coastguard Worker {
61*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_breg0, .number = 0 }
62*7304104dSAndroid Build Coastguard Worker };
63*7304104dSAndroid Build Coastguard Worker #define nloc_aggregate 1
64*7304104dSAndroid Build Coastguard Worker
65*7304104dSAndroid Build Coastguard Worker int
i386_return_value_location(Dwarf_Die * functypedie,const Dwarf_Op ** locp)66*7304104dSAndroid Build Coastguard Worker i386_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
67*7304104dSAndroid Build Coastguard Worker {
68*7304104dSAndroid Build Coastguard Worker /* Start with the function's type, and get the DW_AT_type attribute,
69*7304104dSAndroid Build Coastguard Worker which is the type of the return value. */
70*7304104dSAndroid Build Coastguard Worker Dwarf_Die die_mem, *typedie = &die_mem;
71*7304104dSAndroid Build Coastguard Worker int tag = dwarf_peeled_die_type (functypedie, typedie);
72*7304104dSAndroid Build Coastguard Worker if (tag <= 0)
73*7304104dSAndroid Build Coastguard Worker return tag;
74*7304104dSAndroid Build Coastguard Worker
75*7304104dSAndroid Build Coastguard Worker switch (tag)
76*7304104dSAndroid Build Coastguard Worker {
77*7304104dSAndroid Build Coastguard Worker case -1:
78*7304104dSAndroid Build Coastguard Worker return -1;
79*7304104dSAndroid Build Coastguard Worker
80*7304104dSAndroid Build Coastguard Worker case DW_TAG_subrange_type:
81*7304104dSAndroid Build Coastguard Worker if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
82*7304104dSAndroid Build Coastguard Worker {
83*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem, *attr;
84*7304104dSAndroid Build Coastguard Worker attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
85*7304104dSAndroid Build Coastguard Worker typedie = dwarf_formref_die (attr, &die_mem);
86*7304104dSAndroid Build Coastguard Worker tag = DWARF_TAG_OR_RETURN (typedie);
87*7304104dSAndroid Build Coastguard Worker }
88*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
89*7304104dSAndroid Build Coastguard Worker
90*7304104dSAndroid Build Coastguard Worker case DW_TAG_base_type:
91*7304104dSAndroid Build Coastguard Worker case DW_TAG_enumeration_type:
92*7304104dSAndroid Build Coastguard Worker CASE_POINTER:
93*7304104dSAndroid Build Coastguard Worker {
94*7304104dSAndroid Build Coastguard Worker Dwarf_Word size;
95*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem;
96*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
97*7304104dSAndroid Build Coastguard Worker &attr_mem), &size) != 0)
98*7304104dSAndroid Build Coastguard Worker {
99*7304104dSAndroid Build Coastguard Worker if (dwarf_is_pointer (tag))
100*7304104dSAndroid Build Coastguard Worker size = 4;
101*7304104dSAndroid Build Coastguard Worker else
102*7304104dSAndroid Build Coastguard Worker return -1;
103*7304104dSAndroid Build Coastguard Worker }
104*7304104dSAndroid Build Coastguard Worker if (tag == DW_TAG_base_type)
105*7304104dSAndroid Build Coastguard Worker {
106*7304104dSAndroid Build Coastguard Worker Dwarf_Word encoding;
107*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
108*7304104dSAndroid Build Coastguard Worker &attr_mem),
109*7304104dSAndroid Build Coastguard Worker &encoding) != 0)
110*7304104dSAndroid Build Coastguard Worker return -1;
111*7304104dSAndroid Build Coastguard Worker if (encoding == DW_ATE_float)
112*7304104dSAndroid Build Coastguard Worker {
113*7304104dSAndroid Build Coastguard Worker if (size > 16)
114*7304104dSAndroid Build Coastguard Worker return -2;
115*7304104dSAndroid Build Coastguard Worker *locp = loc_fpreg;
116*7304104dSAndroid Build Coastguard Worker return nloc_fpreg;
117*7304104dSAndroid Build Coastguard Worker }
118*7304104dSAndroid Build Coastguard Worker }
119*7304104dSAndroid Build Coastguard Worker *locp = loc_intreg;
120*7304104dSAndroid Build Coastguard Worker if (size <= 4)
121*7304104dSAndroid Build Coastguard Worker return nloc_intreg;
122*7304104dSAndroid Build Coastguard Worker if (size <= 8)
123*7304104dSAndroid Build Coastguard Worker return nloc_intregpair;
124*7304104dSAndroid Build Coastguard Worker }
125*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
126*7304104dSAndroid Build Coastguard Worker
127*7304104dSAndroid Build Coastguard Worker case DW_TAG_structure_type:
128*7304104dSAndroid Build Coastguard Worker case DW_TAG_class_type:
129*7304104dSAndroid Build Coastguard Worker case DW_TAG_union_type:
130*7304104dSAndroid Build Coastguard Worker case DW_TAG_array_type:
131*7304104dSAndroid Build Coastguard Worker *locp = loc_aggregate;
132*7304104dSAndroid Build Coastguard Worker return nloc_aggregate;
133*7304104dSAndroid Build Coastguard Worker }
134*7304104dSAndroid Build Coastguard Worker
135*7304104dSAndroid Build Coastguard Worker /* XXX We don't have a good way to return specific errors from ebl calls.
136*7304104dSAndroid Build Coastguard Worker This value means we do not understand the type, but it is well-formed
137*7304104dSAndroid Build Coastguard Worker DWARF and might be valid. */
138*7304104dSAndroid Build Coastguard Worker return -2;
139*7304104dSAndroid Build Coastguard Worker }
140