178344Sobrien/* NDS32-specific support for 32-bit ELF. 278344Sobrien Copyright (C) 2012-2017 Free Software Foundation, Inc. 398184Sgordon Contributed by Andes Technology Corporation. 478344Sobrien 578344Sobrien This file is part of BFD, the Binary File Descriptor library. 678344Sobrien 7208307Sdougb This program is free software; you can redistribute it and/or modify 8136224Smtm it under the terms of the GNU General Public License as published by 978344Sobrien the Free Software Foundation; either version 3 of the License, or 1078344Sobrien (at your option) any later version. 1178344Sobrien 1278344Sobrien This program is distributed in the hope that it will be useful, 1378344Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1498184Sgordon MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1578344Sobrien GNU General Public License for more details. 1678344Sobrien 1798184Sgordon You should have received a copy of the GNU General Public License 1878344Sobrien along with this program; if not, write to the Free Software 19124622Smtm Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 20124622Smtm 02110-1301, USA.*/ 21124622Smtm 22124622Smtm#ifndef ELF32_NDS32_H 23124622Smtm#define ELF32_NDS32_H 24124622Smtm 25136684Sthomas#ifdef __cplusplus 26248488Scpercivaextern "C" { 27248487Scperciva#endif 28248487Scperciva 29136901Sdes/* Relocation flags encoded in r_addend. */ 30136684Sthomas 31124622Smtm/* Relocation flags for R_NDS32_ERLAX_ENTRY. */ 3298184Sgordon 33124622Smtm/* Set if relax on this section is done or disabled. */ 34124622Smtm#define R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG (1 << 31) 35124622Smtm/* Optimize for performance. */ 36124622Smtm#define R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG (1 << 30) 3798184Sgordon/* Optimize for size. Branch destination 4-byte adjustment 38124622Smtm may be disabled. */ 39124622Smtm#define R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG (1 << 29) 4098184Sgordon/* To distinguish the assembly code generated by compiler 4198184Sgordon or written manually. */ 42124622Smtm#define R_NDS32_RELAX_ENTRY_VERBATIM_FLAG (1 << 28) 43136901Sdes/* EX9 and link-time IFC must be explicitly enabled, so we 44136901Sdes won't mess up handcraft assembly code. */ 45124622Smtm/* Enable EX9 optimization for this section. */ 46124622Smtm#define R_NDS32_RELAX_ENTRY_EX9_FLAG (1 << 2) 47136901Sdes/* Enable IFC optimization for this section. */ 48136901Sdes#define R_NDS32_RELAX_ENTRY_IFC_FLAG (1 << 3) 49136901Sdes 50136901Sdes 51136901Sdes/* Relocation flags for R_NDS32_INSN16. */ 5298184Sgordon 5398184Sgordon/* Tag the nop16 can be removed. */ 5498184Sgordon#define R_NDS32_INSN16_CONVERT_FLAG (1 << 0) 5598184Sgordon/* Convert a gp-relative access (e.g., lwi.gp) 5698184Sgordon to fp-as-gp access (lwi37.fp). 57180317Smtm This value is used by linker internally only. 58180317Smtm It's fine to change the vlaue. */ 59180317Smtm#define R_NDS32_INSN16_FP7U2_FLAG (1 << 1) 60180317Smtm 61180317Smtm/* Relocation flags for R_NDS32_RELAX_REGION_OMIT_FP_START/END. */ 62180317Smtm 63180317Smtm/* OMIT_FP_FLAG marks the region for applying fp-as-gp 64180317Smtm optimization. */ 65180317Smtm#define R_NDS32_RELAX_REGION_OMIT_FP_FLAG (1 << 0) 66180317Smtm/* NOT_OMIT_FP_FLAG is set if this region is not worth 67180317Smtm for fp-as-gp. */ 68244218Spjd#define R_NDS32_RELAX_REGION_NOT_OMIT_FP_FLAG (1 << 1) 69180318Smtm/* Suppress EX9 optimization in the region. */ 70182460Sjhb#define R_NDS32_RELAX_REGION_NO_EX9_FLAG (1 << 2) 71182460Sjhb/* A Innermost loop region. Some optimizations is suppressed 72182460Sjhb in this region due to performance drop. */ 73254992Sgavin#define R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG (1 << 4) 74179962Smtm 75197947Sdougb/* Tag range for LOADSTORE relocation. */ 76179962Smtmenum 7778344Sobrien{ 7878344Sobrien NDS32_LOADSTORE_NONE = 0x0, 7978344Sobrien NDS32_LOADSTORE_BYTE = 0x1, 8078344Sobrien NDS32_LOADSTORE_HALF = 0x2, 81 NDS32_LOADSTORE_WORD = 0x4, 82 NDS32_LOADSTORE_FLOAT_S = 0x8, 83 NDS32_LOADSTORE_FLOAT_D = 0x10, 84 NDS32_LOADSTORE_IMM = 0x20 85}; 86 87/* Relax tag for nds32_elf_relax_section, we have to specify which 88 optimization do in this round. */ 89enum 90{ 91 NDS32_RELAX_NONE_ROUND = 0, 92 NDS32_RELAX_NORMAL_ROUND, 93 NDS32_RELAX_JUMP_IFC_ROUND, 94 NDS32_RELAX_EX9_BUILD_ROUND, 95 NDS32_RELAX_EX9_REPLACE_ROUND, 96 NDS32_RELAX_EMPTY_ROUND 97}; 98 99/* Optimization status mask. */ 100#define NDS32_RELAX_JUMP_IFC_DONE (1 << 0) 101#define NDS32_RELAX_EX9_DONE (1 << 1) 102 103/* Optimization turn on mask. */ 104#define NDS32_RELAX_JUMP_IFC_ON (1 << 0) 105#define NDS32_RELAX_EX9_ON (1 << 1) 106 107extern void nds32_insertion_sort 108 (void *, size_t, size_t, int (*) (const void *, const void *)); 109 110extern int nds32_elf_ex9_init (void); 111extern int nds32_convert_32_to_16 (bfd *, uint32_t, uint16_t *, int *); 112extern int nds32_convert_16_to_32 (bfd *, uint16_t, uint32_t *); 113extern void bfd_elf32_nds32_set_target_option (struct bfd_link_info *, 114 int, int, FILE *, int, 115 int, int, int, FILE *, 116 FILE *, int, int, 117 bfd_boolean, bfd_boolean); 118 119#define nds32_elf_hash_table(info) \ 120 (elf_hash_table_id ((struct elf_link_hash_table *) ((info)->hash)) \ 121 == NDS32_ELF_DATA ? \ 122 ((struct elf_nds32_link_hash_table *) ((info)->hash)) : NULL) 123 124/* Hash table structure for target nds32. There are some members to 125 save target options passed from nds32elf.em to bfd. */ 126 127struct elf_nds32_link_hash_table 128{ 129 struct elf_link_hash_table root; 130 131 /* Short-cuts to get to dynamic linker sections. */ 132 asection *sdynbss; 133 asection *srelbss; 134 135 /* Small local sym to section mapping cache. */ 136 struct sym_cache sym_cache; 137 138 /* Target dependent options. */ 139 int relax_fp_as_gp; /* --mrelax-omit-fp */ 140 int eliminate_gc_relocs; /* --meliminate-gc-relocs */ 141 FILE *sym_ld_script; /* --mgen-symbol-ld-script=<file> */ 142 /* Disable if linking a dynamically linked executable. */ 143 int load_store_relax; 144 int target_optimize; /* Switch optimization. */ 145 int relax_status; /* Finished optimization. */ 146 int relax_round; /* Going optimization. */ 147 FILE *ex9_export_file; /* --mexport-ex9=<file> */ 148 FILE *ex9_import_file; /* --mimport-ex9=<file> */ 149 int update_ex9_table; /* --mupdate-ex9. */ 150 int ex9_limit; 151 bfd_boolean ex9_loop_aware; /* Ignore ex9 if inside a loop. */ 152 bfd_boolean ifc_loop_aware; /* Ignore ifc if inside a loop. */ 153}; 154 155#ifdef __cplusplus 156} 157#endif 158 159#endif 160