1 /* Function return value location for Linux/SH ABI.
2 Copyright (C) 2010 Red Hat, Inc.
3 This file is part of Red Hat elfutils.
4 Contributed by Matt Fleming <matt@console-pimps.org>.
6 Red Hat elfutils is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by the
8 Free Software Foundation; version 2 of the License.
10 Red Hat elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with Red Hat elfutils; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
19 Red Hat elfutils is an included package of the Open Invention Network.
20 An included package of the Open Invention Network is a package for which
21 Open Invention Network licensees cross-license their patents. No patent
22 license is granted, either expressly or impliedly, by designation as an
23 included package. Should you wish to participate in the Open Invention
24 Network licensing program, please visit www.openinventionnetwork.com
25 <http://www.openinventionnetwork.com>. */
35 #include "libebl_CPU.h"
38 /* This is the SVR4 ELF ABI convention, but AIX and Linux do not use it. */
39 #define SVR4_STRUCT_RETURN 0
42 /* r0, or pair r0, r1. */
43 static const Dwarf_Op loc_intreg[] =
45 { .atom = DW_OP_reg0 }, { .atom = DW_OP_piece, .number = 4 },
46 { .atom = DW_OP_reg1 }, { .atom = DW_OP_piece, .number = 4 },
49 #define nloc_intregpair 4
52 static const Dwarf_Op loc_fpreg[] =
54 { .atom = DW_OP_reg25 }, { .atom = DW_OP_piece, .number = 4 },
55 { .atom = DW_OP_reg26 }, { .atom = DW_OP_piece, .number = 4 },
58 #define nloc_fpregpair 2
61 sh_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
63 /* Start with the function's type, and get the DW_AT_type attribute,
64 which is the type of the return value. */
66 Dwarf_Attribute attr_mem;
67 Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type,
70 /* The function has no return value, like a `void' function in C. */
74 Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
75 int tag = dwarf_tag (typedie);
77 /* Follow typedefs and qualifiers to get to the actual type. */
78 while (tag == DW_TAG_typedef
79 || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
80 || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type)
82 attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
83 typedie = dwarf_formref_die (attr, &die_mem);
84 tag = dwarf_tag (typedie);
93 case DW_TAG_subrange_type:
94 if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
96 attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
97 typedie = dwarf_formref_die (attr, &die_mem);
98 tag = dwarf_tag (typedie);
102 case DW_TAG_base_type:
103 case DW_TAG_enumeration_type:
104 case DW_TAG_pointer_type:
105 case DW_TAG_ptr_to_member_type:
106 if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
107 &attr_mem), &size) != 0)
109 if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
116 if (tag == DW_TAG_base_type)
119 if (dwarf_formudata (dwarf_attr_integrate (typedie,
124 if (encoding == DW_ATE_float)
127 return size <= 4 ? nloc_fpreg : nloc_fpregpair;
131 return size <= 4 ? nloc_intreg : nloc_intregpair;
135 /* XXX We don't have a good way to return specific errors from ebl calls.
136 This value means we do not understand the type, but it is well-formed
137 DWARF and might be valid. */