1*7304104dSAndroid Build Coastguard Worker /* Function return value location for Linux/m68k ABI.
2*7304104dSAndroid Build Coastguard Worker This file is part of elfutils.
3*7304104dSAndroid Build Coastguard Worker
4*7304104dSAndroid Build Coastguard Worker This file is free software; you can redistribute it and/or modify
5*7304104dSAndroid Build Coastguard Worker it under the terms of either
6*7304104dSAndroid Build Coastguard Worker
7*7304104dSAndroid Build Coastguard Worker * the GNU Lesser General Public License as published by the Free
8*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 3 of the License, or (at
9*7304104dSAndroid Build Coastguard Worker your option) any later version
10*7304104dSAndroid Build Coastguard Worker
11*7304104dSAndroid Build Coastguard Worker or
12*7304104dSAndroid Build Coastguard Worker
13*7304104dSAndroid Build Coastguard Worker * the GNU General Public License as published by the Free
14*7304104dSAndroid Build Coastguard Worker Software Foundation; either version 2 of the License, or (at
15*7304104dSAndroid Build Coastguard Worker your option) any later version
16*7304104dSAndroid Build Coastguard Worker
17*7304104dSAndroid Build Coastguard Worker or both in parallel, as here.
18*7304104dSAndroid Build Coastguard Worker
19*7304104dSAndroid Build Coastguard Worker elfutils is distributed in the hope that it will be useful, but
20*7304104dSAndroid Build Coastguard Worker WITHOUT ANY WARRANTY; without even the implied warranty of
21*7304104dSAndroid Build Coastguard Worker MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22*7304104dSAndroid Build Coastguard Worker General Public License for more details.
23*7304104dSAndroid Build Coastguard Worker
24*7304104dSAndroid Build Coastguard Worker You should have received copies of the GNU General Public License and
25*7304104dSAndroid Build Coastguard Worker the GNU Lesser General Public License along with this program. If
26*7304104dSAndroid Build Coastguard Worker not, see <http://www.gnu.org/licenses/>. */
27*7304104dSAndroid Build Coastguard Worker
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 m68k_
37*7304104dSAndroid Build Coastguard Worker #include "libebl_CPU.h"
38*7304104dSAndroid Build Coastguard Worker
39*7304104dSAndroid Build Coastguard Worker
40*7304104dSAndroid Build Coastguard Worker /* %d0, or pair %d0, %d1. */
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_reg1 }, { .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 /* %a0. */
50*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_ptrreg[] =
51*7304104dSAndroid Build Coastguard Worker {
52*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg8 }
53*7304104dSAndroid Build Coastguard Worker };
54*7304104dSAndroid Build Coastguard Worker #define nloc_ptrreg 1
55*7304104dSAndroid Build Coastguard Worker
56*7304104dSAndroid Build Coastguard Worker /* %fp0. */
57*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_fpreg[] =
58*7304104dSAndroid Build Coastguard Worker {
59*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg16 }
60*7304104dSAndroid Build Coastguard Worker };
61*7304104dSAndroid Build Coastguard Worker #define nloc_fpreg 1
62*7304104dSAndroid Build Coastguard Worker
63*7304104dSAndroid Build Coastguard Worker /* The return value is a structure and is actually stored in stack space
64*7304104dSAndroid Build Coastguard Worker passed in a hidden argument by the caller. But, the compiler
65*7304104dSAndroid Build Coastguard Worker helpfully returns the address of that space in %a0. */
66*7304104dSAndroid Build Coastguard Worker static const Dwarf_Op loc_aggregate[] =
67*7304104dSAndroid Build Coastguard Worker {
68*7304104dSAndroid Build Coastguard Worker { .atom = DW_OP_reg8 }
69*7304104dSAndroid Build Coastguard Worker };
70*7304104dSAndroid Build Coastguard Worker #define nloc_aggregate 1
71*7304104dSAndroid Build Coastguard Worker
72*7304104dSAndroid Build Coastguard Worker int
m68k_return_value_location(Dwarf_Die * functypedie,const Dwarf_Op ** locp)73*7304104dSAndroid Build Coastguard Worker m68k_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
74*7304104dSAndroid Build Coastguard Worker {
75*7304104dSAndroid Build Coastguard Worker /* Start with the function's type, and get the DW_AT_type attribute,
76*7304104dSAndroid Build Coastguard Worker which is the type of the return value. */
77*7304104dSAndroid Build Coastguard Worker Dwarf_Die die_mem, *typedie = &die_mem;
78*7304104dSAndroid Build Coastguard Worker int tag = dwarf_peeled_die_type (functypedie, typedie);
79*7304104dSAndroid Build Coastguard Worker if (tag <= 0)
80*7304104dSAndroid Build Coastguard Worker return tag;
81*7304104dSAndroid Build Coastguard Worker
82*7304104dSAndroid Build Coastguard Worker switch (tag)
83*7304104dSAndroid Build Coastguard Worker {
84*7304104dSAndroid Build Coastguard Worker case -1:
85*7304104dSAndroid Build Coastguard Worker return -1;
86*7304104dSAndroid Build Coastguard Worker
87*7304104dSAndroid Build Coastguard Worker case DW_TAG_subrange_type:
88*7304104dSAndroid Build Coastguard Worker if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
89*7304104dSAndroid Build Coastguard Worker {
90*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem, *attr;
91*7304104dSAndroid Build Coastguard Worker attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
92*7304104dSAndroid Build Coastguard Worker typedie = dwarf_formref_die (attr, &die_mem);
93*7304104dSAndroid Build Coastguard Worker tag = DWARF_TAG_OR_RETURN (typedie);
94*7304104dSAndroid Build Coastguard Worker }
95*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
96*7304104dSAndroid Build Coastguard Worker
97*7304104dSAndroid Build Coastguard Worker case DW_TAG_base_type:
98*7304104dSAndroid Build Coastguard Worker case DW_TAG_enumeration_type:
99*7304104dSAndroid Build Coastguard Worker CASE_POINTER:
100*7304104dSAndroid Build Coastguard Worker {
101*7304104dSAndroid Build Coastguard Worker Dwarf_Word size;
102*7304104dSAndroid Build Coastguard Worker Dwarf_Attribute attr_mem;
103*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
104*7304104dSAndroid Build Coastguard Worker &attr_mem), &size) != 0)
105*7304104dSAndroid Build Coastguard Worker {
106*7304104dSAndroid Build Coastguard Worker if (dwarf_is_pointer (tag))
107*7304104dSAndroid Build Coastguard Worker size = 4;
108*7304104dSAndroid Build Coastguard Worker else
109*7304104dSAndroid Build Coastguard Worker return -1;
110*7304104dSAndroid Build Coastguard Worker }
111*7304104dSAndroid Build Coastguard Worker if (tag == DW_TAG_base_type)
112*7304104dSAndroid Build Coastguard Worker {
113*7304104dSAndroid Build Coastguard Worker Dwarf_Word encoding;
114*7304104dSAndroid Build Coastguard Worker if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
115*7304104dSAndroid Build Coastguard Worker &attr_mem),
116*7304104dSAndroid Build Coastguard Worker &encoding) != 0)
117*7304104dSAndroid Build Coastguard Worker return -1;
118*7304104dSAndroid Build Coastguard Worker if (encoding == DW_ATE_float)
119*7304104dSAndroid Build Coastguard Worker {
120*7304104dSAndroid Build Coastguard Worker if (size > 12)
121*7304104dSAndroid Build Coastguard Worker return -2;
122*7304104dSAndroid Build Coastguard Worker *locp = loc_fpreg;
123*7304104dSAndroid Build Coastguard Worker return nloc_fpreg;
124*7304104dSAndroid Build Coastguard Worker }
125*7304104dSAndroid Build Coastguard Worker }
126*7304104dSAndroid Build Coastguard Worker if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
127*7304104dSAndroid Build Coastguard Worker {
128*7304104dSAndroid Build Coastguard Worker *locp = loc_ptrreg;
129*7304104dSAndroid Build Coastguard Worker return nloc_ptrreg;
130*7304104dSAndroid Build Coastguard Worker }
131*7304104dSAndroid Build Coastguard Worker *locp = loc_intreg;
132*7304104dSAndroid Build Coastguard Worker if (size <= 4)
133*7304104dSAndroid Build Coastguard Worker return nloc_intreg;
134*7304104dSAndroid Build Coastguard Worker if (size <= 8)
135*7304104dSAndroid Build Coastguard Worker return nloc_intregpair;
136*7304104dSAndroid Build Coastguard Worker }
137*7304104dSAndroid Build Coastguard Worker FALLTHROUGH;
138*7304104dSAndroid Build Coastguard Worker case DW_TAG_structure_type:
139*7304104dSAndroid Build Coastguard Worker case DW_TAG_class_type:
140*7304104dSAndroid Build Coastguard Worker case DW_TAG_union_type:
141*7304104dSAndroid Build Coastguard Worker case DW_TAG_array_type:
142*7304104dSAndroid Build Coastguard Worker *locp = loc_aggregate;
143*7304104dSAndroid Build Coastguard Worker return nloc_aggregate;
144*7304104dSAndroid Build Coastguard Worker }
145*7304104dSAndroid Build Coastguard Worker
146*7304104dSAndroid Build Coastguard Worker /* XXX We don't have a good way to return specific errors from ebl calls.
147*7304104dSAndroid Build Coastguard Worker This value means we do not understand the type, but it is well-formed
148*7304104dSAndroid Build Coastguard Worker DWARF and might be valid. */
149*7304104dSAndroid Build Coastguard Worker return -2;
150*7304104dSAndroid Build Coastguard Worker }
151