1 1.1 christos /* NFP ELF support for BFD. 2 1.1.1.6 christos Copyright (C) 2017-2026 Free Software Foundation, Inc. 3 1.1 christos Contributed by Francois H. Theron <francois.theron (at) netronome.com> 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 Foundation, 19 1.1 christos Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #ifndef _ELF_NFP_H 22 1.1 christos #define _ELF_NFP_H 23 1.1 christos 24 1.1 christos #include "bfd.h" 25 1.1 christos #include "elf/common.h" 26 1.1 christos #include "elf/reloc-macros.h" 27 1.1.1.3 christos #include <stdint.h> 28 1.1 christos 29 1.1 christos #ifdef __cplusplus 30 1.1 christos extern "C" 31 1.1 christos { 32 1.1 christos #endif 33 1.1 christos 34 1.1 christos #define ET_NFP_PARTIAL_REL (ET_LOPROC + ET_REL) 35 1.1 christos #define ET_NFP_PARTIAL_EXEC (ET_LOPROC + ET_EXEC) 36 1.1 christos 37 1.1 christos /* NFP e_flags - chip family 38 1.1 christos Valid values for FAMILY are: 39 1.1 christos 0x3200 - NFP-32xx 40 1.1 christos 0x6000 - NFP-6xxx/NFP-4xxx. */ 41 1.1 christos #define EF_NFP_MACH(ef_nfp) (((ef_nfp) >> 8) & 0xFFFF) 42 1.1 christos #define EF_NFP_SET_MACH(nfp_fam) (((nfp_fam) & 0xFFFF) << 8) 43 1.1 christos 44 1.1 christos #define E_NFP_MACH_3200 0x3200 45 1.1 christos #define E_NFP_MACH_6000 0x6000 46 1.1 christos 47 1.1 christos #define NFP_3200_CPPTGT_MSF0 1 48 1.1 christos #define NFP_3200_CPPTGT_QDR 2 49 1.1 christos #define NFP_3200_CPPTGT_MSF1 3 50 1.1 christos #define NFP_3200_CPPTGT_HASH 4 51 1.1 christos #define NFP_3200_CPPTGT_MU 7 52 1.1 christos #define NFP_3200_CPPTGT_GS 8 53 1.1 christos #define NFP_3200_CPPTGT_PCIE 9 54 1.1 christos #define NFP_3200_CPPTGT_ARM 10 55 1.1 christos #define NFP_3200_CPPTGT_CRYPTO 12 56 1.1 christos #define NFP_3200_CPPTGT_CAP 13 57 1.1 christos #define NFP_3200_CPPTGT_CT 14 58 1.1 christos #define NFP_3200_CPPTGT_CLS 15 59 1.1 christos 60 1.1 christos #define NFP_6000_CPPTGT_NBI 1 61 1.1 christos #define NFP_6000_CPPTGT_VQDR 2 62 1.1 christos #define NFP_6000_CPPTGT_ILA 6 63 1.1 christos #define NFP_6000_CPPTGT_MU 7 64 1.1 christos #define NFP_6000_CPPTGT_PCIE 9 65 1.1 christos #define NFP_6000_CPPTGT_ARM 10 66 1.1 christos #define NFP_6000_CPPTGT_CRYPTO 12 67 1.1 christos #define NFP_6000_CPPTGT_CTXPB 14 68 1.1 christos #define NFP_6000_CPPTGT_CLS 15 69 1.1 christos 70 1.1 christos /* NFP Section types 71 1.1 christos MECONFIG - NFP-32xx only, ME CSR configurations 72 1.1 christos INITREG - A generic register initialisation section (chip or ME CSRs/GPRs) 73 1.1 christos UDEBUG - Legacy-style debug data section. */ 74 1.1 christos #define SHT_NFP_MECONFIG (SHT_LOPROC + 1) 75 1.1 christos #define SHT_NFP_INITREG (SHT_LOPROC + 2) 76 1.1 christos #define SHT_NFP_UDEBUG SHT_LOUSER 77 1.1 christos 78 1.1 christos /* NFP SECTION flags 79 1.1 christos ELF-64 sh_flags is 64-bit, but there is no info on what the upper 32 bits 80 1.1 christos are expected to be used for, it is not marked reserved either. 81 1.1 christos We'll use them for NFP-specific flags since we don't use ELF-32. 82 1.1 christos 83 1.1 christos INIT - Sections that are loaded and executed before the final text 84 1.1 christos microcode. Non-code INIT sections are loaded first, then other 85 1.1 christos memory secions, then INIT2 sections, then INIT-code sections. 86 1.1 christos INIT2 - Sections that are loaded before INIT-code sections, used for 87 1.1 christos transient configuration before executing INIT-code section 88 1.1 christos microcode. 89 1.1 christos SCS - The number of additional ME codestores being shared with the group's 90 1.1 christos base ME of the section, e.g. 0 for no SCS, 1 for dual and 3 for 91 1.1 christos quad. If this is 0 it is possible that stagger-style SCS codestore 92 1.1 christos sections are being used. For stagger-style each section is simply 93 1.1 christos loaded directly to the ME it is assigned to. If these flags are 94 1.1 christos used, virtual address space loading will be used - one large section 95 1.1 christos loaded to the group's base ME will be packed across shared MEs by 96 1.1 christos hardware. This is not available on all ME versions. 97 1.1 christos 98 1.1 christos NFP_ELF_SHF_GET_SCS (val) returns the number of additional codestores 99 1.1 christos being shared with the group's base ME, e.g. 0 for no SCS, 100 1.1 christos 1 for dual SCS, 3 for quad SCS. */ 101 1.1 christos 102 1.1 christos #define SHF_NFP_INIT 0x80000000 103 1.1 christos #define SHF_NFP_INIT2 0x40000000 104 1.1 christos #define SHF_NFP_SCS(shf) (((shf) >> 32) & 0xFF) 105 1.1.1.3 christos #define SHF_NFP_SET_SCS(v) ((uint64_t) ((v) & 0xFF) << 32) 106 1.1 christos 107 1.1 christos /* NFP Section Info 108 1.1 christos For PROGBITS and NOBITS sections: 109 1.1 christos MEMTYPE - the memory type 110 1.1 christos DOMAIN - The island ID and ME number where the data will be loaded. 111 1.1 christos For NFP-32xx, this is an island number or linear ME number. 112 1.1 christos For NFP-6xxx, DOMAIN<15:8> == island ID, DOMAIN<7:0> is 0 based 113 1.1 christos ME number (if applicable). 114 1.1 christos For INITREG sections: 115 1.1 christos ISLAND - island ID (if it's a ME target, ME numbers are in the 116 1.1 christos section data) 117 1.1 christos CPPTGT - CPP Target ID 118 1.1 christos CPPACTRD - CPP Read Action 119 1.1 christos CPPTOKRD - CPP Read Token 120 1.1 christos CPPACTWR - CPP Write Action 121 1.1 christos CPPTOKWR - CPP Write Token 122 1.1 christos ORDER - Controls the order in which the loader processes sections with 123 1.1 christos the same info fields. */ 124 1.1 christos 125 1.1 christos #define SHI_NFP_DOMAIN(shi) (((shi) >> 16) & 0xFFFF) 126 1.1 christos #define SHI_NFP_MEMTYPE(shi) ( (shi) & 0xFFFF) 127 1.1 christos #define SHI_NFP_SET_DOMAIN(v) (((v) & 0xFFFF) << 16) 128 1.1 christos #define SHI_NFP_SET_MEMTYPE(v) ( (v) & 0xFFFF) 129 1.1 christos 130 1.1 christos #define SHI_NFP_IREG_ISLAND(shi) (((shi) >> 26) & 0x3F) 131 1.1 christos #define SHI_NFP_IREG_CPPTGT(shi) (((shi) >> 22) & 0xF) 132 1.1 christos #define SHI_NFP_IREG_CPPACTRD(shi) (((shi) >> 17) & 0x1F) 133 1.1 christos #define SHI_NFP_IREG_CPPTOKRD(shi) (((shi) >> 15) & 0x3) 134 1.1 christos #define SHI_NFP_IREG_CPPACTWR(shi) (((shi) >> 10) & 0x1F) 135 1.1 christos #define SHI_NFP_IREG_CPPTOKWR(shi) (((shi) >> 8) & 0x3) 136 1.1 christos #define SHI_NFP_IREG_ORDER(shi) ( (shi) & 0xFF) 137 1.1 christos #define SHI_NFP_SET_IREG_ISLAND(v) (((v) & 0x3F) << 26) 138 1.1 christos #define SHI_NFP_SET_IREG_CPPTGT(v) (((v) & 0xF) << 22) 139 1.1 christos #define SHI_NFP_SET_IREG_CPPACTRD(v) (((v) & 0x1F) << 17) 140 1.1 christos #define SHI_NFP_SET_IREG_CPPTOKRD(v) (((v) & 0x3) << 15) 141 1.1 christos #define SHI_NFP_SET_IREG_CPPACTWR(v) (((v) & 0x1F) << 10) 142 1.1 christos #define SHI_NFP_SET_IREG_CPPTOKWR(v) (((v) & 0x3) << 8) 143 1.1 christos #define SHI_NFP_SET_IREG_ORDER(v) ( (v) & 0xFF) 144 1.1 christos 145 1.1 christos /* CtXpb/reflect_read_sig_init/reflect_write_sig_init 146 1.1 christos identifies Init-CSR sections for ME CSRs. */ 147 1.1 christos #define SHI_NFP_6000_IS_IREG_MECSR(shi) ( \ 148 1.1 christos SHI_NFP_IREG_CPPTGT (shi) == NFP_6000_CPPTGT_CTXPB \ 149 1.1 christos && SHI_NFP_IREG_CPPACTRD (shi) == 2 \ 150 1.1 christos && SHI_NFP_IREG_CPPTOKRD (shi) == 1 \ 151 1.1 christos && SHI_NFP_IREG_CPPACTWR (shi) == 3 \ 152 1.1 christos && SHI_NFP_IREG_CPPTOKWR (shi) == 1 \ 153 1.1 christos ) 154 1.1 christos 155 1.1 christos /* Transient INITREG sections will be validated against the target 156 1.1 christos but will not be kept - validate, write or read and discard. 157 1.1 christos They will still be handled last (in order). */ 158 1.1 christos #define SHI_NFP_IREG_ORDER_TRANSIENT 0xFF 159 1.1 christos 160 1.1 christos /* Below are some extra macros to translate SHI fields in more specific 161 1.1 christos contexts. 162 1.1 christos 163 1.1 christos For NFP-32xx, DOMAIN is set to a global linear ME number (0 to 39). 164 1.1 christos An NFP-32xx has 8 MEs per island and up to 5 islands. */ 165 1.1 christos 166 1.1 christos #define SHI_NFP_3200_ISLAND(shi) ((SHI_NFP_DOMAIN (shi) >> 3) & 0x7) 167 1.1 christos #define SHI_NFP_3200_MENUM(shi) ( SHI_NFP_DOMAIN (shi) & 0x7) 168 1.1 christos #define SHI_NFP_SET_3200_ISLAND(v) SHI_NFP_SET_DOMAIN (((v) & 0x7) << 3) 169 1.1 christos #define SHI_NFP_SET_3200_MENUM(v) SHI_NFP_SET_DOMAIN ( (v) & 0x7) 170 1.1 christos 171 1.1 christos #define SHI_NFP_ISLAND(shi) ((SHI_NFP_DOMAIN (shi) >> 8) & 0xFF) 172 1.1 christos #define SHI_NFP_MENUM(shi) ( SHI_NFP_DOMAIN (shi) & 0xFF) 173 1.1 christos #define SHI_NFP_SET_ISLAND(shi) SHI_NFP_SET_DOMAIN (((shi) & 0xFF) << 8) 174 1.1 christos #define SHI_NFP_SET_MENUM(shi) SHI_NFP_SET_DOMAIN ( (shi) & 0xFF) 175 1.1 christos 176 1.1 christos #define SHI_NFP_MEMTYPE_NONE 0 177 1.1 christos #define SHI_NFP_MEMTYPE_USTORE 1 178 1.1 christos #define SHI_NFP_MEMTYPE_LMEM 2 179 1.1 christos #define SHI_NFP_MEMTYPE_CLS 3 180 1.1 christos #define SHI_NFP_MEMTYPE_DRAM 4 181 1.1 christos #define SHI_NFP_MEMTYPE_MU 4 182 1.1 christos #define SHI_NFP_MEMTYPE_SRAM 5 183 1.1 christos #define SHI_NFP_MEMTYPE_GS 6 184 1.1 christos #define SHI_NFP_MEMTYPE_PPC_LMEM 7 185 1.1 christos #define SHI_NFP_MEMTYPE_PPC_SMEM 8 186 1.1 christos #define SHI_NFP_MEMTYPE_EMU_CACHE 9 187 1.1 christos 188 1.1 christos /* VTP_FORCE is for use by the NFP Linker+Loader only. */ 189 1.1 christos #define NFP_IREG_VTP_FORCE 0 190 1.1 christos #define NFP_IREG_VTP_CONST 1 191 1.1 christos #define NFP_IREG_VTP_REQUIRED 2 192 1.1 christos #define NFP_IREG_VTP_VOLATILE_INIT 3 193 1.1 christos #define NFP_IREG_VTP_VOLATILE_NOINIT 4 194 1.1 christos #define NFP_IREG_VTP_INVALID 5 195 1.1 christos 196 1.1 christos /* Init-CSR entry w0 fields: 197 1.1 christos NLW - Not Last Word 198 1.1 christos CTX - ME context number (if applicable) 199 1.1 christos VTP - Value type 200 1.1 christos COH - CPP Offset High 8 bits. */ 201 1.1 christos #define NFP_IREG_ENTRY_WO_NLW(w0) (((w0) >> 31) & 0x1) 202 1.1 christos #define NFP_IREG_ENTRY_WO_CTX(w0) (((w0) >> 28) & 0x7) 203 1.1 christos #define NFP_IREG_ENTRY_WO_VTP(w0) (((w0) >> 25) & 0x7) 204 1.1 christos #define NFP_IREG_ENTRY_WO_COH(w0) (((w0) >> 0) & 0xFF) 205 1.1 christos 206 1.1 christos typedef struct 207 1.1 christos { 208 1.1 christos uint32_t w0; 209 1.1 christos uint32_t cpp_offset_lo; 210 1.1 christos uint32_t val; 211 1.1 christos uint32_t mask; 212 1.1 christos } Elf_Nfp_InitRegEntry; 213 1.1 christos 214 1.1 christos typedef struct 215 1.1 christos { 216 1.1 christos uint32_t ctx_enables; 217 1.1 christos uint32_t entry; 218 1.1 christos uint32_t misc_control; 219 1.1 christos uint32_t reserved; 220 1.1 christos } Elf_Nfp_MeConfig; 221 1.1 christos 222 1.1 christos /* Relocations. */ 223 1.1 christos START_RELOC_NUMBERS (elf_nfp3200_reloc_type) 224 1.1 christos RELOC_NUMBER (R_NFP3200_NOTYPE, 0) 225 1.1 christos RELOC_NUMBER (R_NFP3200_W32LE, 1) 226 1.1 christos RELOC_NUMBER (R_NFP3200_SRC8_A, 2) 227 1.1 christos RELOC_NUMBER (R_NFP3200_SRC8_B, 3) 228 1.1 christos RELOC_NUMBER (R_NFP3200_IMMED8_I, 4) 229 1.1 christos RELOC_NUMBER (R_NFP3200_SC, 5) 230 1.1 christos RELOC_NUMBER (R_NFP3200_IMMED_LO16_I_A, 6) 231 1.1 christos RELOC_NUMBER (R_NFP3200_IMMED_LO16_I_B, 7) 232 1.1 christos RELOC_NUMBER (R_NFP3200_SRC7_B, 8) 233 1.1 christos RELOC_NUMBER (R_NFP3200_SRC7_A, 9) 234 1.1 christos RELOC_NUMBER (R_NFP3200_SRC8_I_B, 10) 235 1.1 christos RELOC_NUMBER (R_NFP3200_SRC8_I_A, 11) 236 1.1 christos RELOC_NUMBER (R_NFP3200_IMMED_HI16_I_A, 12) 237 1.1 christos RELOC_NUMBER (R_NFP3200_IMMED_HI16_I_B, 13) 238 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_0, 14) 239 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_1, 15) 240 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_2, 16) 241 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_3, 17) 242 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_4, 18) 243 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_5, 19) 244 1.1 christos RELOC_NUMBER (R_NFP3200_RSVD_6, 20) 245 1.1 christos RELOC_NUMBER (R_NFP3200_W64LE, 21) 246 1.1 christos RELOC_NUMBER (R_NFP3200_W32BE, 22) 247 1.1 christos RELOC_NUMBER (R_NFP3200_W64BE, 23) 248 1.1 christos RELOC_NUMBER (R_NFP3200_W32LE_AND, 24) 249 1.1 christos RELOC_NUMBER (R_NFP3200_W32BE_AND, 25) 250 1.1 christos RELOC_NUMBER (R_NFP3200_W32LE_OR, 26) 251 1.1 christos RELOC_NUMBER (R_NFP3200_W32BE_OR, 27) 252 1.1 christos RELOC_NUMBER (R_NFP3200_W64LE_AND, 28) 253 1.1 christos RELOC_NUMBER (R_NFP3200_W64BE_AND, 29) 254 1.1 christos RELOC_NUMBER (R_NFP3200_W64LE_OR, 30) 255 1.1 christos RELOC_NUMBER (R_NFP3200_W64BE_OR, 31) 256 1.1 christos END_RELOC_NUMBERS (R_NFP3200_MAX) 257 1.1 christos 258 1.1 christos START_RELOC_NUMBERS (elf_nfp_reloc_type) 259 1.1 christos RELOC_NUMBER (R_NFP_NOTYPE, 0) 260 1.1 christos RELOC_NUMBER (R_NFP_W32LE, 1) 261 1.1 christos RELOC_NUMBER (R_NFP_SRC8_A, 2) 262 1.1 christos RELOC_NUMBER (R_NFP_SRC8_B, 3) 263 1.1 christos RELOC_NUMBER (R_NFP_IMMED8_I, 4) 264 1.1 christos RELOC_NUMBER (R_NFP_SC, 5) 265 1.1 christos RELOC_NUMBER (R_NFP_IMMED_LO16_I_A, 6) 266 1.1 christos RELOC_NUMBER (R_NFP_IMMED_LO16_I_B, 7) 267 1.1 christos RELOC_NUMBER (R_NFP_SRC7_B, 8) 268 1.1 christos RELOC_NUMBER (R_NFP_SRC7_A, 9) 269 1.1 christos RELOC_NUMBER (R_NFP_SRC8_I_B, 10) 270 1.1 christos RELOC_NUMBER (R_NFP_SRC8_I_A, 11) 271 1.1 christos RELOC_NUMBER (R_NFP_IMMED_HI16_I_A, 12) 272 1.1 christos RELOC_NUMBER (R_NFP_IMMED_HI16_I_B, 13) 273 1.1 christos RELOC_NUMBER (R_NFP_W64LE, 14) 274 1.1 christos RELOC_NUMBER (R_NFP_SH_INFO, 15) 275 1.1 christos RELOC_NUMBER (R_NFP_W32BE, 16) 276 1.1 christos RELOC_NUMBER (R_NFP_W64BE, 17) 277 1.1 christos RELOC_NUMBER (R_NFP_W32_29_24, 18) 278 1.1 christos RELOC_NUMBER (R_NFP_W32LE_AND, 19) 279 1.1 christos RELOC_NUMBER (R_NFP_W32BE_AND, 20) 280 1.1 christos RELOC_NUMBER (R_NFP_W32LE_OR, 21) 281 1.1 christos RELOC_NUMBER (R_NFP_W32BE_OR, 22) 282 1.1 christos RELOC_NUMBER (R_NFP_W64LE_AND, 23) 283 1.1 christos RELOC_NUMBER (R_NFP_W64BE_AND, 24) 284 1.1 christos RELOC_NUMBER (R_NFP_W64LE_OR, 25) 285 1.1 christos RELOC_NUMBER (R_NFP_W64BE_OR, 26) 286 1.1 christos END_RELOC_NUMBERS (R_NFP_MAX) 287 1.1 christos 288 1.1 christos #ifdef __cplusplus 289 1.1 christos } 290 1.1 christos #endif 291 1.1 christos 292 1.1 christos #endif /* _ELF_NFP_H */ 293