/* Copyright (C) 2011-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
Based on work contributed by by Carl Pederson & Martin Schwidefsky.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
#ifndef dl_machine_h
#define dl_machine_h
#ifdef __tilegx__
#define ELF_MACHINE_NAME "tilegx"
#else
#define ELF_MACHINE_NAME "tilepro"
#endif
#include <sys/param.h>
#include <string.h>
#include <link.h>
#include <bits/wordsize.h>
#include <arch/icache.h>
#include <arch/opcode.h>
/* Return nonzero iff ELF header is compatible with the running host. */
static inline int
elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
{
#if defined __tilegx__
if (ehdr->e_machine != EM_TILEGX)
return 0;
# if __WORDSIZE == 32
return (ehdr->e_ident[EI_CLASS] == ELFCLASS32);
# else
return (ehdr->e_ident[EI_CLASS] == ELFCLASS64);
# endif
#elif defined __tilepro__
return ehdr->e_machine == EM_TILEPRO;
#else
# error "Unknown tile architecture."
#endif
}
/* Return the link-time address of _DYNAMIC. Conveniently, this is the
first element of the GOT. This must be inlined in a function which
uses global data. */
static inline ElfW(Addr)
elf_machine_dynamic (void)
{
ElfW(Addr) *got;
#ifdef __tilegx__
ElfW(Addr) tmp;
asm( " { lnk %0; moveli %1, hw2_last(_GLOBAL_OFFSET_TABLE_ - 1f) }\n"
"1: shl16insli %1, %1, hw1(_GLOBAL_OFFSET_TABLE_ - 1b)\n