• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Function return value location for ARM EABI.
2    Copyright (C) 2009-2010 Red Hat, Inc.
3    This file is part of Red Hat elfutils.
4 
5    Red Hat elfutils is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by the
7    Free Software Foundation; version 2 of the License.
8 
9    Red Hat elfutils is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License along
15    with Red Hat elfutils; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
17 
18    Red Hat elfutils is an included package of the Open Invention Network.
19    An included package of the Open Invention Network is a package for which
20    Open Invention Network licensees cross-license their patents.  No patent
21    license is granted, either expressly or impliedly, by designation as an
22    included package.  Should you wish to participate in the Open Invention
23    Network licensing program, please visit www.openinventionnetwork.com
24    <http://www.openinventionnetwork.com>.  */
25 
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 #include <assert.h>
31 #include <dwarf.h>
32 
33 #define BACKEND arm_
34 #include "libebl_CPU.h"
35 
36 
37 /* r0, or pair r0, r1, or aggregate up to r0-r3.  */
38 static const Dwarf_Op loc_intreg[] =
39   {
40     { .atom = DW_OP_reg0 }, { .atom = DW_OP_piece, .number = 4 },
41     { .atom = DW_OP_reg1 }, { .atom = DW_OP_piece, .number = 4 },
42     { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 4 },
43     { .atom = DW_OP_reg3 }, { .atom = DW_OP_piece, .number = 4 },
44   };
45 #define nloc_intreg	1
46 #define nloc_intregs(n)	(2 * (n))
47 
48 /* The return value is a structure and is actually stored in stack space
49    passed in a hidden argument by the caller.  But, the compiler
50    helpfully returns the address of that space in r0.  */
51 static const Dwarf_Op loc_aggregate[] =
52   {
53     { .atom = DW_OP_breg0, .number = 0 }
54   };
55 #define nloc_aggregate 1
56 
57 
58 int
arm_return_value_location(Dwarf_Die * functypedie,const Dwarf_Op ** locp)59 arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
60 {
61   /* Start with the function's type, and get the DW_AT_type attribute,
62      which is the type of the return value.  */
63 
64   Dwarf_Attribute attr_mem;
65   Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type,
66 						&attr_mem);
67   if (attr == NULL)
68     /* The function has no return value, like a `void' function in C.  */
69     return 0;
70 
71   Dwarf_Die die_mem;
72   Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
73   int tag = dwarf_tag (typedie);
74 
75   /* Follow typedefs and qualifiers to get to the actual type.  */
76   while (tag == DW_TAG_typedef
77 	 || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
78 	 || tag == DW_TAG_restrict_type || tag == DW_TAG_mutable_type)
79     {
80       attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
81       typedie = dwarf_formref_die (attr, &die_mem);
82       tag = dwarf_tag (typedie);
83     }
84 
85   Dwarf_Word size;
86   switch (tag)
87     {
88     case -1:
89       return -1;
90 
91     case DW_TAG_subrange_type:
92       if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
93 	{
94 	  attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
95 	  typedie = dwarf_formref_die (attr, &die_mem);
96 	  tag = dwarf_tag (typedie);
97 	}
98       /* Fall through.  */
99 
100     case DW_TAG_base_type:
101     case DW_TAG_enumeration_type:
102     case DW_TAG_pointer_type:
103     case DW_TAG_ptr_to_member_type:
104       if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
105 						 &attr_mem), &size) != 0)
106 	{
107 	  if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
108 	    size = 4;
109 	  else
110 	    return -1;
111 	}
112       if (size <= 16)
113 	{
114 	intreg:
115 	  *locp = loc_intreg;
116 	  return size <= 4 ? nloc_intreg : nloc_intregs ((size + 3) / 4);
117 	}
118 
119     aggregate:
120       *locp = loc_aggregate;
121       return nloc_aggregate;
122 
123     case DW_TAG_structure_type:
124     case DW_TAG_class_type:
125     case DW_TAG_union_type:
126     case DW_TAG_array_type:
127       if (dwarf_aggregate_size (typedie, &size) == 0
128 	  && size > 0 && size <= 4)
129 	goto intreg;
130       goto aggregate;
131     }
132 
133   /* XXX We don't have a good way to return specific errors from ebl calls.
134      This value means we do not understand the type, but it is well-formed
135      DWARF and might be valid.  */
136   return -2;
137 }
138