#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <assert.h>
#include <dwarf.h>
#define BACKEND ppc64_
#include "libebl_CPU.h"
static const Dwarf_Op loc_intreg[] =
{
{ .atom = DW_OP_reg3 }
};
#define nloc_intreg 1
static const Dwarf_Op loc_fpreg[] =
{
{ .atom = DW_OP_regx, .number = 33 }, { .atom = DW_OP_piece, .number = 8 },
{ .atom = DW_OP_regx, .number = 34 }, { .atom = DW_OP_piece, .number = 8 },
{ .atom = DW_OP_regx, .number = 35 }, { .atom = DW_OP_piece, .number = 8 },
{ .atom = DW_OP_regx, .number = 36 }, { .atom = DW_OP_piece, .number = 8 },
};
#define nloc_fpreg 1
#define nloc_fp2regs 4
#define nloc_fp4regs 8
static const Dwarf_Op loc_vmxreg[] =
{
{ .atom = DW_OP_regx, .number = 1124 + 2 }
};
#define nloc_vmxreg 1
static const Dwarf_Op loc_aggregate[] =
{
{ .atom = DW_OP_breg3, .number = 0 }
};
#define nloc_aggregate 1
int
ppc64_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
{
Dwarf_Die die_mem, *typedie = &die_mem;
int tag = dwarf_peeled_die_type (functypedie, typedie);
if (tag <= 0)
return tag;
Dwarf_Word size;
switch (tag)
{
case -1:
return -1;
case DW_TAG_subrange_type:
if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
{
Dwarf_Attribute attr_mem, *attr;
attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
typedie = dwarf_formref_die (attr, &die_mem);
tag = DWARF_TAG_OR_RETURN (typedie);
}
FALLTHROUGH;
case DW_TAG_base_type:
case DW_TAG_enumeration_type:
CASE_POINTER:
{
Dwarf_Attribute attr_mem;
if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
&attr_mem), &size) != 0)
{
if (dwarf_is_pointer (tag))
size = 8;
else
return -1;
}
}
if (tag == DW_TAG_base_type)
{
Dwarf_Attribute attr_mem;
Dwarf_Word encoding;
if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
&attr_mem),
&encoding) != 0)
return -1;
if (encoding == DW_ATE_float || encoding == DW_ATE_complex_float)
{
*locp = loc_fpreg;
if (size <= 8)
return nloc_fpreg;
if (size <= 16)
return nloc_fp2regs;
if (size <= 32)
return nloc_fp4regs;
}
}
if (size <= 8)
{
intreg:
*locp = loc_intreg;
return nloc_intreg;
}
FALLTHROUGH;
case DW_TAG_structure_type:
case DW_TAG_class_type:
case DW_TAG_union_type:
aggregate:
*locp = loc_aggregate;
return nloc_aggregate;
case DW_TAG_array_type:
{
Dwarf_Attribute attr_mem;
bool is_vector;
if (dwarf_formflag (dwarf_attr_integrate (typedie, DW_AT_GNU_vector,
&attr_mem), &is_vector) == 0
&& is_vector)
{
*locp = loc_vmxreg;
return nloc_vmxreg;
}
}
FALLTHROUGH;
case DW_TAG_string_type:
if (dwarf_aggregate_size (typedie, &size) == 0 && size <= 8)
{
if (tag == DW_TAG_array_type)
{
Dwarf_Attribute attr_mem, *attr;
attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
typedie = dwarf_formref_die (attr, &die_mem);
tag = DWARF_TAG_OR_RETURN (typedie);
if (tag != DW_TAG_base_type)
goto aggregate;
if (dwarf_formudata (dwarf_attr_integrate (typedie,
DW_AT_byte_size,
&attr_mem),
&size) != 0)
return -1;
if (size != 1)
goto aggregate;
}
goto intreg;
}
goto aggregate;
}
return -2;
}