1 1.1 christos /* Xtensa ELF support for BFD. 2 1.1.1.8 christos Copyright (C) 2003-2024 Free Software Foundation, Inc. 3 1.1 christos Contributed by Bob Wilson (bwilson (at) tensilica.com) at Tensilica. 4 1.1 christos 5 1.1 christos This file is part of BFD, the Binary File Descriptor library. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program; if not, write to the Free Software 19 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 20 1.1 christos USA. */ 21 1.1 christos 22 1.1 christos /* This file holds definitions specific to the Xtensa ELF ABI. */ 23 1.1 christos 24 1.1 christos #ifndef _ELF_XTENSA_H 25 1.1 christos #define _ELF_XTENSA_H 26 1.1 christos 27 1.1 christos #include "elf/reloc-macros.h" 28 1.1 christos 29 1.1.1.3 christos #ifdef __cplusplus 30 1.1.1.3 christos extern "C" { 31 1.1.1.3 christos #endif 32 1.1.1.3 christos 33 1.1 christos /* Relocations. */ 34 1.1 christos START_RELOC_NUMBERS (elf_xtensa_reloc_type) 35 1.1 christos RELOC_NUMBER (R_XTENSA_NONE, 0) 36 1.1 christos RELOC_NUMBER (R_XTENSA_32, 1) 37 1.1 christos RELOC_NUMBER (R_XTENSA_RTLD, 2) 38 1.1 christos RELOC_NUMBER (R_XTENSA_GLOB_DAT, 3) 39 1.1 christos RELOC_NUMBER (R_XTENSA_JMP_SLOT, 4) 40 1.1 christos RELOC_NUMBER (R_XTENSA_RELATIVE, 5) 41 1.1 christos RELOC_NUMBER (R_XTENSA_PLT, 6) 42 1.1 christos RELOC_NUMBER (R_XTENSA_OP0, 8) 43 1.1 christos RELOC_NUMBER (R_XTENSA_OP1, 9) 44 1.1 christos RELOC_NUMBER (R_XTENSA_OP2, 10) 45 1.1 christos RELOC_NUMBER (R_XTENSA_ASM_EXPAND, 11) 46 1.1 christos RELOC_NUMBER (R_XTENSA_ASM_SIMPLIFY, 12) 47 1.1 christos RELOC_NUMBER (R_XTENSA_32_PCREL, 14) 48 1.1 christos RELOC_NUMBER (R_XTENSA_GNU_VTINHERIT, 15) 49 1.1 christos RELOC_NUMBER (R_XTENSA_GNU_VTENTRY, 16) 50 1.1 christos RELOC_NUMBER (R_XTENSA_DIFF8, 17) 51 1.1 christos RELOC_NUMBER (R_XTENSA_DIFF16, 18) 52 1.1 christos RELOC_NUMBER (R_XTENSA_DIFF32, 19) 53 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT0_OP, 20) 54 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT1_OP, 21) 55 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT2_OP, 22) 56 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT3_OP, 23) 57 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT4_OP, 24) 58 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT5_OP, 25) 59 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT6_OP, 26) 60 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT7_OP, 27) 61 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT8_OP, 28) 62 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT9_OP, 29) 63 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT10_OP, 30) 64 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT11_OP, 31) 65 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT12_OP, 32) 66 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT13_OP, 33) 67 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT14_OP, 34) 68 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT0_ALT, 35) 69 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT1_ALT, 36) 70 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT2_ALT, 37) 71 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT3_ALT, 38) 72 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT4_ALT, 39) 73 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT5_ALT, 40) 74 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT6_ALT, 41) 75 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT7_ALT, 42) 76 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT8_ALT, 43) 77 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT9_ALT, 44) 78 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT10_ALT, 45) 79 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT11_ALT, 46) 80 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT12_ALT, 47) 81 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT13_ALT, 48) 82 1.1 christos RELOC_NUMBER (R_XTENSA_SLOT14_ALT, 49) 83 1.1 christos RELOC_NUMBER (R_XTENSA_TLSDESC_FN, 50) 84 1.1 christos RELOC_NUMBER (R_XTENSA_TLSDESC_ARG, 51) 85 1.1 christos RELOC_NUMBER (R_XTENSA_TLS_DTPOFF, 52) 86 1.1 christos RELOC_NUMBER (R_XTENSA_TLS_TPOFF, 53) 87 1.1 christos RELOC_NUMBER (R_XTENSA_TLS_FUNC, 54) 88 1.1 christos RELOC_NUMBER (R_XTENSA_TLS_ARG, 55) 89 1.1 christos RELOC_NUMBER (R_XTENSA_TLS_CALL, 56) 90 1.1.1.6 christos RELOC_NUMBER (R_XTENSA_PDIFF8, 57) 91 1.1.1.6 christos RELOC_NUMBER (R_XTENSA_PDIFF16, 58) 92 1.1.1.6 christos RELOC_NUMBER (R_XTENSA_PDIFF32, 59) 93 1.1.1.6 christos RELOC_NUMBER (R_XTENSA_NDIFF8, 60) 94 1.1.1.6 christos RELOC_NUMBER (R_XTENSA_NDIFF16, 61) 95 1.1.1.6 christos RELOC_NUMBER (R_XTENSA_NDIFF32, 62) 96 1.1 christos END_RELOC_NUMBERS (R_XTENSA_max) 97 1.1 christos 98 1.1 christos /* Processor-specific flags for the ELF header e_flags field. */ 99 1.1 christos 100 1.1 christos /* Four-bit Xtensa machine type field. */ 101 1.1 christos #define EF_XTENSA_MACH 0x0000000f 102 1.1 christos 103 1.1 christos /* Various CPU types. */ 104 1.1 christos #define E_XTENSA_MACH 0x00000000 105 1.1 christos 106 1.1 christos /* Leave bits 0xf0 alone in case we ever have more than 16 cpu types. 107 1.1 christos Highly unlikely, but what the heck. */ 108 1.1 christos 109 1.1 christos #define EF_XTENSA_XT_INSN 0x00000100 110 1.1 christos #define EF_XTENSA_XT_LIT 0x00000200 111 1.1 christos 112 1.1 christos 113 1.1 christos /* Processor-specific dynamic array tags. */ 114 1.1 christos 115 1.1 christos /* Offset of the table that records the GOT location(s). */ 116 1.1 christos #define DT_XTENSA_GOT_LOC_OFF 0x70000000 117 1.1 christos 118 1.1 christos /* Number of entries in the GOT location table. */ 119 1.1 christos #define DT_XTENSA_GOT_LOC_SZ 0x70000001 120 1.1 christos 121 1.1 christos 122 1.1 christos /* Definitions for instruction and literal property tables. The 123 1.1 christos tables for ".gnu.linkonce.*" sections are placed in the following 124 1.1 christos sections: 125 1.1 christos 126 1.1 christos instruction tables: .gnu.linkonce.x.* 127 1.1 christos literal tables: .gnu.linkonce.p.* 128 1.1 christos */ 129 1.1 christos 130 1.1 christos #define XTENSA_INSN_SEC_NAME ".xt.insn" 131 1.1 christos #define XTENSA_LIT_SEC_NAME ".xt.lit" 132 1.1 christos #define XTENSA_PROP_SEC_NAME ".xt.prop" 133 1.1 christos 134 1.1 christos typedef struct property_table_entry_t 135 1.1 christos { 136 1.1 christos bfd_vma address; 137 1.1 christos bfd_vma size; 138 1.1 christos flagword flags; 139 1.1 christos } property_table_entry; 140 1.1 christos 141 1.1 christos /* Flags in the property tables to specify whether blocks of memory are 142 1.1 christos literals, instructions, data, or unreachable. For instructions, 143 1.1 christos blocks that begin loop targets and branch targets are designated. 144 1.1 christos Blocks that do not allow density instructions, instruction reordering 145 1.1 christos or transformation are also specified. Finally, for branch targets, 146 1.1 christos branch target alignment priority is included. Alignment of the next 147 1.1 christos block is specified in the current block and the size of the current 148 1.1 christos block does not include any fill required to align to the next 149 1.1 christos block. */ 150 1.1 christos 151 1.1 christos #define XTENSA_PROP_LITERAL 0x00000001 152 1.1 christos #define XTENSA_PROP_INSN 0x00000002 153 1.1 christos #define XTENSA_PROP_DATA 0x00000004 154 1.1 christos #define XTENSA_PROP_UNREACHABLE 0x00000008 155 1.1 christos /* Instruction-only properties at beginning of code. */ 156 1.1 christos #define XTENSA_PROP_INSN_LOOP_TARGET 0x00000010 157 1.1 christos #define XTENSA_PROP_INSN_BRANCH_TARGET 0x00000020 158 1.1 christos /* Instruction-only properties about code. */ 159 1.1 christos #define XTENSA_PROP_INSN_NO_DENSITY 0x00000040 160 1.1 christos #define XTENSA_PROP_INSN_NO_REORDER 0x00000080 161 1.1 christos /* Historically, NO_TRANSFORM was a property of instructions, 162 1.1 christos but it should apply to literals under certain circumstances. */ 163 1.1 christos #define XTENSA_PROP_NO_TRANSFORM 0x00000100 164 1.1 christos 165 1.1 christos /* Branch target alignment information. This transmits information 166 1.1 christos to the linker optimization about the priority of aligning a 167 1.1 christos particular block for branch target alignment: None, low priority, 168 1.1 christos high priority, or required. These only need to be checked in 169 1.1 christos instruction blocks marked as XTENSA_PROP_INSN_BRANCH_TARGET. 170 1.1 christos Common usage is: 171 1.1 christos 172 1.1 christos switch (GET_XTENSA_PROP_BT_ALIGN(flags)) 173 1.1 christos case XTENSA_PROP_BT_ALIGN_NONE: 174 1.1 christos case XTENSA_PROP_BT_ALIGN_LOW: 175 1.1 christos case XTENSA_PROP_BT_ALIGN_HIGH: 176 1.1 christos case XTENSA_PROP_BT_ALIGN_REQUIRE: 177 1.1 christos */ 178 1.1 christos #define XTENSA_PROP_BT_ALIGN_MASK 0x00000600 179 1.1 christos 180 1.1 christos /* No branch target alignment. */ 181 1.1 christos #define XTENSA_PROP_BT_ALIGN_NONE 0x0 182 1.1 christos /* Low priority branch target alignment. */ 183 1.1 christos #define XTENSA_PROP_BT_ALIGN_LOW 0x1 184 1.1 christos /* High priority branch target alignment. */ 185 1.1 christos #define XTENSA_PROP_BT_ALIGN_HIGH 0x2 186 1.1 christos /* Required branch target alignment. */ 187 1.1 christos #define XTENSA_PROP_BT_ALIGN_REQUIRE 0x3 188 1.1 christos 189 1.1 christos #define GET_XTENSA_PROP_BT_ALIGN(flag) \ 190 1.1 christos (((unsigned)((flag) & (XTENSA_PROP_BT_ALIGN_MASK))) >> 9) 191 1.1 christos #define SET_XTENSA_PROP_BT_ALIGN(flag, align) \ 192 1.1 christos (((flag) & (~XTENSA_PROP_BT_ALIGN_MASK)) | \ 193 1.1 christos (((align) << 9) & XTENSA_PROP_BT_ALIGN_MASK)) 194 1.1 christos 195 1.1 christos /* Alignment is specified in the block BEFORE the one that needs 196 1.1 christos alignment. Up to 5 bits. Use GET_XTENSA_PROP_ALIGNMENT(flags) to 197 1.1 christos get the required alignment specified as a power of 2. Use 198 1.1 christos SET_XTENSA_PROP_ALIGNMENT(flags, pow2) to set the required 199 1.1 christos alignment. Be careful of side effects since the SET will evaluate 200 1.1 christos flags twice. Also, note that the SIZE of a block in the property 201 1.1 christos table does not include the alignment size, so the alignment fill 202 1.1 christos must be calculated to determine if two blocks are contiguous. 203 1.1 christos TEXT_ALIGN is not currently implemented but is a placeholder for a 204 1.1 christos possible future implementation. */ 205 1.1 christos 206 1.1 christos #define XTENSA_PROP_ALIGN 0x00000800 207 1.1 christos 208 1.1 christos #define XTENSA_PROP_ALIGNMENT_MASK 0x0001f000 209 1.1 christos 210 1.1 christos #define GET_XTENSA_PROP_ALIGNMENT(flag) \ 211 1.1 christos (((unsigned)((flag) & (XTENSA_PROP_ALIGNMENT_MASK))) >> 12) 212 1.1 christos #define SET_XTENSA_PROP_ALIGNMENT(flag, align) \ 213 1.1 christos (((flag) & (~XTENSA_PROP_ALIGNMENT_MASK)) | \ 214 1.1 christos (((align) << 12) & XTENSA_PROP_ALIGNMENT_MASK)) 215 1.1 christos 216 1.1 christos #define XTENSA_PROP_INSN_ABSLIT 0x00020000 217 1.1 christos 218 1.1.1.8 christos extern char *xtensa_property_section_name (asection *, const char *, bool); 219 1.1.1.5 christos extern int 220 1.1.1.5 christos xtensa_read_table_entries (bfd *abfd, 221 1.1.1.5 christos asection *section, 222 1.1.1.5 christos property_table_entry **table_p, 223 1.1.1.5 christos const char *sec_name, 224 1.1.1.7 christos bool output_addr); 225 1.1.1.5 christos extern int 226 1.1.1.5 christos xtensa_compute_fill_extra_space (property_table_entry *entry); 227 1.1.1.3 christos 228 1.1.1.6 christos extern int 229 1.1.1.6 christos xtensa_abi_choice (void); 230 1.1.1.6 christos 231 1.1.1.3 christos #ifdef __cplusplus 232 1.1.1.3 christos } 233 1.1.1.3 christos #endif 234 1.1.1.3 christos 235 1.1 christos #endif /* _ELF_XTENSA_H */ 236