138465Smsmith/* TILE-Gx-specific support for 32-bit ELF.
238465Smsmith   Copyright (C) 2011-2017 Free Software Foundation, Inc.
338465Smsmith
438465Smsmith   This file is part of BFD, the Binary File Descriptor library.
538465Smsmith
638465Smsmith   This program is free software; you can redistribute it and/or modify
738465Smsmith   it under the terms of the GNU General Public License as published by
838465Smsmith   the Free Software Foundation; either version 3 of the License, or
938465Smsmith   (at your option) any later version.
1038465Smsmith
1138465Smsmith   This program is distributed in the hope that it will be useful,
1238465Smsmith   but WITHOUT ANY WARRANTY; without even the implied warranty of
1338465Smsmith   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1438465Smsmith   GNU General Public License for more details.
1538465Smsmith
1638465Smsmith   You should have received a copy of the GNU General Public License
1738465Smsmith   along with this program; if not, write to the Free Software
1838465Smsmith   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1938465Smsmith   MA 02110-1301, USA.  */
2038465Smsmith
2138465Smsmith#include "sysdep.h"
2238465Smsmith#include "bfd.h"
2338465Smsmith#include "libbfd.h"
2438465Smsmith#include "elf-bfd.h"
2538465Smsmith#include "elfxx-tilegx.h"
2638764Smsmith#include "elf32-tilegx.h"
2738465Smsmith
2838465Smsmith
2938465Smsmith/* Support for core dump NOTE sections.  */
3038465Smsmith
3138465Smsmithstatic bfd_boolean
3238465Smsmithtilegx_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3338465Smsmith{
3438465Smsmith  int offset;
3538465Smsmith  size_t size;
3638465Smsmith
3738465Smsmith  if (note->descsz != TILEGX_PRSTATUS_SIZEOF)
3838465Smsmith    return FALSE;
3938465Smsmith
4038465Smsmith  /* pr_cursig */
4138465Smsmith  elf_tdata (abfd)->core->signal =
4238465Smsmith    bfd_get_16 (abfd, note->descdata + TILEGX_PRSTATUS_OFFSET_PR_CURSIG);
4338465Smsmith
4438465Smsmith  /* pr_pid */
4538465Smsmith  elf_tdata (abfd)->core->pid =
4638465Smsmith    bfd_get_32 (abfd, note->descdata + TILEGX_PRSTATUS_OFFSET_PR_PID);
4738465Smsmith
4838465Smsmith  /* pr_reg */
4938465Smsmith  offset = TILEGX_PRSTATUS_OFFSET_PR_REG;
5038465Smsmith  size   = TILEGX_GREGSET_T_SIZE;
5138465Smsmith
5238465Smsmith  /* Make a ".reg/999" section.  */
5338465Smsmith  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
5438465Smsmith					  size, note->descpos + offset);
5538465Smsmith}
5638465Smsmith
5738465Smsmithstatic bfd_boolean
5838465Smsmithtilegx_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
5938465Smsmith{
6038465Smsmith  if (note->descsz != TILEGX_PRPSINFO_SIZEOF)
6138465Smsmith    return FALSE;
6238465Smsmith
6338465Smsmith  elf_tdata (abfd)->core->program
6438465Smsmith    = _bfd_elfcore_strndup (abfd, note->descdata + TILEGX_PRPSINFO_OFFSET_PR_FNAME, 16);
6538465Smsmith  elf_tdata (abfd)->core->command
6638465Smsmith    = _bfd_elfcore_strndup (abfd, note->descdata + TILEGX_PRPSINFO_OFFSET_PR_PSARGS, ELF_PR_PSARGS_SIZE);
6738465Smsmith
6838465Smsmith
6938465Smsmith  /* Note that for some reason, a spurious space is tacked
7038465Smsmith     onto the end of the args in some (at least one anyway)
7138465Smsmith     implementations, so strip it off if it exists.  */
7238465Smsmith  {
7338465Smsmith    char *command = elf_tdata (abfd)->core->command;
7438465Smsmith    int n = strlen (command);
7538465Smsmith
7638465Smsmith    if (0 < n && command[n - 1] == ' ')
7738465Smsmith      command[n - 1] = '\0';
7838465Smsmith  }
7938465Smsmith
8038465Smsmith  return TRUE;
8138465Smsmith}
8238465Smsmith
8338465Smsmith
8438465Smsmith#define ELF_ARCH		bfd_arch_tilegx
8538465Smsmith#define ELF_TARGET_ID		TILEGX_ELF_DATA
8638465Smsmith#define ELF_MACHINE_CODE	EM_TILEGX
8738465Smsmith#define ELF_MAXPAGESIZE		0x10000
8838465Smsmith#define ELF_COMMONPAGESIZE	0x10000
8938465Smsmith
9038465Smsmith#define TARGET_BIG_SYM          tilegx_elf32_be_vec
9138465Smsmith#define TARGET_BIG_NAME         "elf32-tilegx-be"
9238465Smsmith#define TARGET_LITTLE_SYM       tilegx_elf32_le_vec
9338465Smsmith#define TARGET_LITTLE_NAME      "elf32-tilegx-le"
9438465Smsmith
9538465Smsmith#define elf_backend_reloc_type_class	     tilegx_reloc_type_class
9638465Smsmith
9738465Smsmith#define bfd_elf32_bfd_reloc_name_lookup      tilegx_reloc_name_lookup
9838465Smsmith#define bfd_elf32_bfd_link_hash_table_create tilegx_elf_link_hash_table_create
9938465Smsmith#define bfd_elf32_bfd_reloc_type_lookup	     tilegx_reloc_type_lookup
10038465Smsmith#define bfd_elf32_bfd_merge_private_bfd_data \
10138465Smsmith  _bfd_tilegx_elf_merge_private_bfd_data
10238465Smsmith
10338465Smsmith#define elf_backend_copy_indirect_symbol     tilegx_elf_copy_indirect_symbol
10438465Smsmith#define elf_backend_create_dynamic_sections  tilegx_elf_create_dynamic_sections
10538465Smsmith#define elf_backend_check_relocs	     tilegx_elf_check_relocs
10638465Smsmith#define elf_backend_adjust_dynamic_symbol    tilegx_elf_adjust_dynamic_symbol
10738465Smsmith#define elf_backend_omit_section_dynsym	     tilegx_elf_omit_section_dynsym
10838465Smsmith#define elf_backend_size_dynamic_sections    tilegx_elf_size_dynamic_sections
10938465Smsmith#define elf_backend_relocate_section	     tilegx_elf_relocate_section
11038465Smsmith#define elf_backend_finish_dynamic_symbol    tilegx_elf_finish_dynamic_symbol
11138465Smsmith#define elf_backend_finish_dynamic_sections  tilegx_elf_finish_dynamic_sections
11238465Smsmith#define elf_backend_gc_mark_hook	     tilegx_elf_gc_mark_hook
11338465Smsmith#define elf_backend_gc_sweep_hook            tilegx_elf_gc_sweep_hook
11438465Smsmith#define elf_backend_plt_sym_val		     tilegx_elf_plt_sym_val
11538465Smsmith#define elf_info_to_howto_rel                NULL
11638465Smsmith#define elf_info_to_howto                    tilegx_info_to_howto_rela
11738465Smsmith#define elf_backend_grok_prstatus            tilegx_elf_grok_prstatus
11838465Smsmith#define elf_backend_grok_psinfo              tilegx_elf_grok_psinfo
11938465Smsmith#define elf_backend_additional_program_headers tilegx_additional_program_headers
12038465Smsmith
12138465Smsmith#define elf_backend_init_index_section	_bfd_elf_init_1_index_section
12238465Smsmith
12338465Smsmith#define elf_backend_can_gc_sections 1
12438465Smsmith#define elf_backend_can_refcount 1
12538465Smsmith#define elf_backend_want_got_plt 1
12638465Smsmith#define elf_backend_plt_readonly 1
12738465Smsmith/* Align PLT mod 64 byte L2 line size. */
12838465Smsmith#define elf_backend_plt_alignment 6
12938465Smsmith#define elf_backend_want_plt_sym 1
13038465Smsmith#define elf_backend_got_header_size 4
13138465Smsmith#define elf_backend_want_dynrelro 1
13238465Smsmith#define elf_backend_rela_normal 1
13338465Smsmith#define elf_backend_default_execstack 0
13438465Smsmith
13538465Smsmith#include "elf32-target.h"
13638465Smsmith