#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/or32.h"
#include "libiberty.h"
static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
PARAMS ((bfd *, bfd_reloc_code_real_type));
static void or32_info_to_howto_rel
PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
static bfd_boolean or32_elf_object_p
PARAMS ((bfd *));
static void or32_elf_final_write_processing
PARAMS ((bfd *, bfd_boolean));
static bfd_reloc_status_type or32_elf_32_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static bfd_reloc_status_type or32_elf_16_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static bfd_reloc_status_type or32_elf_8_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static bfd_reloc_status_type or32_elf_const_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static bfd_reloc_status_type or32_elf_consth_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
static bfd_reloc_status_type or32_elf_jumptarg_reloc
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
#define USE_REL 1
static reloc_howto_type elf_or32_howto_table[] =
{
HOWTO (R_OR32_NONE,
0,
2,
32,
FALSE,
0,
complain_overflow_bitfield,
bfd_elf_generic_reloc,
"R_OR32_NONE",
FALSE,
0,
0,
FALSE),
HOWTO (R_OR32_32,
0,
2,
32,
FALSE,
0,
complain_overflow_bitfield,
or32_elf_32_reloc,
"R_OR32_32",
FALSE,
0xffffffff,
0xffffffff,
FALSE),
HOWTO (R_OR32_16,
0,
1,
16,
FALSE,
0,
complain_overflow_bitfield,
or32_elf_16_reloc,
"R_OR32_16",
FALSE,
0x0000ffff,
0x0000ffff,
FALSE),
HOWTO (R_OR32_8,
0,
0,
8,
FALSE,
0,
complain_overflow_bitfield,
or32_elf_8_reloc,
"R_OR32_8",
FALSE,
0x000000ff,
0x000000ff,
FALSE),
HOWTO (R_OR32_CONST,
0,
2,
16,
FALSE,
0,
complain_overflow_dont,
or32_elf_const_reloc,
"R_OR32_CONST",
FALSE,
0x0000ffff,
0x0000ffff,
FALSE),
HOWTO (R_OR32_CONSTH,
16,
2,
16,
TRUE,
0,
complain_overflow_dont,
or32_elf_consth_reloc,
"R_OR32_CONSTH",
FALSE,
0xffff0000,
0x0000ffff,
FALSE),
HOWTO (R_OR32_JUMPTARG,
2,
2,
28,
TRUE,
0,
complain_overflow_signed,
or32_elf_jumptarg_reloc,
"R_OR32_JUMPTARG",
FALSE,
0,
0x03ffffff,
TRUE),
HOWTO (R_OR32_GNU_VTINHERIT,
0,
2,
0,
FALSE,
0,
complain_overflow_dont,
NULL,
"R_OR32_GNU_VTINHERIT",
FALSE,
0,
0,
FALSE),
HOWTO (R_OR32_GNU_VTENTRY,
0,
2,
0,
FALSE,
0,
complain_overflow_dont,
_bfd_elf_rel_vtable_reloc_fn,
"R_OR32_GNU_VTENTRY",
FALSE,
0,
0,
FALSE),
};
struct or32_reloc_map
{
bfd_reloc_code_real_type bfd_reloc_val;
unsigned char elf_reloc_val;
};
static const struct or32_reloc_map or32_reloc_map[] =
{
{ BFD_RELOC_NONE, R_OR32_NONE },
{ BFD_RELOC_32, R_OR32_32 },
{ BFD_RELOC_16, R_OR32_16 },
{ BFD_RELOC_8, R_OR32_8 },
{ BFD_RELOC_LO16, R_OR32_CONST },
{ BFD_RELOC_HI16, R_OR32_CONSTH },
{ BFD_RELOC_32_GOT_PCREL, R_OR32_JUMPTARG },
{ BFD_RELOC_VTABLE_INHERIT, R_OR32_GNU_VTINHERIT },
{ BFD_RELOC_VTABLE_ENTRY, R_OR32_GNU_VTENTRY },
};
static reloc_howto_type *
bfd_elf32_bfd_reloc_type_lookup (abfd, code)
bfd *abfd ATTRIBUTE_UNUSED;
bfd_reloc_code_real_type code;
{
unsigned int i;
for (i = ARRAY_SIZE (or32_reloc_map); i--;)
{
if (or32_reloc_map[i].bfd_reloc_val == code)
return &elf_or32_howto_table[or32_reloc_map[i].elf_reloc_val];
}
return NULL;
}
static void
or32_info_to_howto_rel (abfd, cache_ptr, dst)
bfd *abfd ATTRIBUTE_UNUSED;
arelent *cache_ptr;
Elf_Internal_Rela *dst;
{
unsigned int r_type;
r_type = ELF32_R_TYPE (dst->r_info);
BFD_ASSERT (r_type < (unsigned int) R_OR32_max);
cache_ptr->howto = &elf_or32_howto_table[r_type];
}
static bfd_boolean
or32_elf_object_p (abfd)
bfd *abfd;
{
(void) bfd_default_set_arch_mach (abfd, bfd_arch_or32, 0);
return TRUE;
}
static void
or32_elf_final_write_processing (abfd, linker)
bfd *abfd;
bfd_boolean linker ATTRIBUTE_UNUSED;
{
int mach;
unsigned long val;
switch (mach = bfd_get_mach (abfd))
{
default:
val = 0;
return;
}
elf_elfheader (abfd)->e_flags &=~ EF_OR32_MACH;
elf_elfheader (abfd)->e_flags |= val;
}
bfd_reloc_status_type
or32_elf_32_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message ATTRIBUTE_UNUSED;
{
if (output_bfd != (bfd *) NULL)
{
unsigned long insn;
bfd_size_type addr = reloc_entry->address;
reloc_entry->address += input_section->output_offset;
insn = bfd_get_32 (abfd, (bfd_byte *) data + addr);
insn += symbol->section->output_section->vma;
insn += symbol->section->output_offset;
insn += symbol->value;
bfd_put_32 (abfd, insn, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
return bfd_reloc_continue;
}
bfd_reloc_status_type
or32_elf_16_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message ATTRIBUTE_UNUSED;
{
if (output_bfd != (bfd *) NULL)
{
unsigned short insn;
bfd_size_type addr = reloc_entry->address;
reloc_entry->address += input_section->output_offset;
insn = bfd_get_16 (abfd, (bfd_byte *) data + addr);
insn += symbol->section->output_section->vma;
insn += symbol->section->output_offset;
insn += symbol->value;
bfd_put_16 (abfd, insn, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
return bfd_reloc_continue;
}
bfd_reloc_status_type
or32_elf_8_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd ATTRIBUTE_UNUSED;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message ATTRIBUTE_UNUSED;
{
if (output_bfd != (bfd *) NULL)
{
unsigned char insn;
bfd_size_type addr = reloc_entry->address;
reloc_entry->address += input_section->output_offset;
insn = bfd_get_8 (abfd, (bfd_byte *) data + addr);
insn += symbol->section->output_section->vma;
insn += symbol->section->output_offset;
insn += symbol->value;
bfd_put_8 (abfd, insn, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
return bfd_reloc_continue;
}
struct or32_consth
{
struct or32_consth *next;
bfd_byte *addr;
bfd_vma addend;
};
static struct or32_consth *or32_consth_list;
bfd_reloc_status_type
or32_elf_consth_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd ATTRIBUTE_UNUSED;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message ATTRIBUTE_UNUSED;
{
bfd_reloc_status_type ret;
bfd_vma relocation;
struct or32_consth *n;
ret = bfd_reloc_ok;
if (bfd_is_und_section (symbol->section)
&& output_bfd == (bfd *) NULL)
ret = bfd_reloc_undefined;
if (bfd_is_com_section (symbol->section))
relocation = 0;
else
relocation = symbol->value;
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
relocation += reloc_entry->addend;
if (reloc_entry->address > input_section->_cooked_size)
return bfd_reloc_outofrange;
n = (struct or32_consth *) bfd_malloc (sizeof *n);
if (n == NULL)
return bfd_reloc_outofrange;
n->addr = (bfd_byte *) data + reloc_entry->address;
n->addend = relocation;
n->next = or32_consth_list;
or32_consth_list = n;
if (output_bfd != (bfd *) NULL)
reloc_entry->address += input_section->output_offset;
return ret;
}
bfd_reloc_status_type
or32_elf_const_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd;
arelent *reloc_entry;
asymbol *symbol;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message;
{
if (or32_consth_list != NULL)
{
struct or32_consth *l;
l = or32_consth_list;
while (l != NULL)
{
unsigned long insn;
unsigned long val;
unsigned long vallo;
struct or32_consth *next;
insn = bfd_get_32 (abfd, l->addr);
vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address)
& 0xffff);
val = ((insn & 0xffff) << 16) + vallo;
val += l->addend;
insn = (insn &~ 0xffff) | ((val >> 16) & 0xffff);
bfd_put_32 (abfd, insn, l->addr);
next = l->next;
free (l);
l = next;
}
or32_consth_list = NULL;
}
if (output_bfd != (bfd *) NULL)
{
unsigned long insn, tmp;
bfd_size_type addr = reloc_entry->address;
reloc_entry->address += input_section->output_offset;
insn = bfd_get_32 (abfd, (bfd_byte *) data + addr);
tmp = insn & 0x0000ffff;
tmp += symbol->section->output_section->vma;
tmp += symbol->section->output_offset;
tmp += symbol->value;
insn = (insn & 0xffff0000) | (tmp & 0x0000ffff);
bfd_put_32 (abfd, insn, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
input_section, output_bfd, error_message);
}
bfd_reloc_status_type
or32_elf_jumptarg_reloc (abfd, reloc_entry, symbol, data, input_section,
output_bfd, error_message)
bfd *abfd;
arelent *reloc_entry;
asymbol *symbol ATTRIBUTE_UNUSED;
PTR data;
asection *input_section;
bfd *output_bfd;
char **error_message ATTRIBUTE_UNUSED;
{
if (output_bfd != (bfd *) NULL)
{
unsigned long insn, tmp;
bfd_size_type addr = reloc_entry->address;
reloc_entry->address += input_section->output_offset;
insn = bfd_get_32 (abfd, (bfd_byte *) data + addr);
tmp = insn | 0xfc000000;
tmp -= (input_section->output_offset >> 2);
insn = (insn & 0xfc000000) | (tmp & 0x03ffffff);
bfd_put_32 (abfd, insn, (bfd_byte *) data + addr);
return bfd_reloc_ok;
}
return bfd_reloc_continue;
}
#define TARGET_LITTLE_SYM bfd_elf32_or32_little_vec
#define TARGET_LITTLE_NAME "elf32-littleor32"
#define TARGET_BIG_SYM bfd_elf32_or32_big_vec
#define TARGET_BIG_NAME "elf32-or32"
#define ELF_ARCH bfd_arch_or32
#define ELF_MACHINE_CODE EM_OR32
#define ELF_MAXPAGESIZE 0x1000
#define elf_info_to_howto 0
#define elf_info_to_howto_rel or32_info_to_howto_rel
#define elf_backend_object_p or32_elf_object_p
#define elf_backend_final_write_processing \
or32_elf_final_write_processing
#include "elf32-target.h"