1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright (c) 2018, Joyent, Inc. 25 * Copyright 2022 Oxide Computer Company 26 */ 27 28 /* 29 * String conversion routines for ELF header attributes. 30 */ 31 #include <stdio.h> 32 #include <string.h> 33 #include "_conv.h" 34 #include "elf_msg.h" 35 #include <sys/elf_SPARC.h> 36 37 38 39 static const conv_ds_t ** 40 ehdr_class_strings(Conv_fmt_flags_t fmt_flags) 41 { 42 static const Msg class_cf[] = { 43 MSG_ELFCLASSNONE_CF, MSG_ELFCLASS32_CF, MSG_ELFCLASS64_CF 44 }; 45 static const Msg class_nf[] = { 46 MSG_ELFCLASSNONE_NF, MSG_ELFCLASS32_NF, MSG_ELFCLASS64_NF 47 }; 48 static const Msg class_dump[] = { 49 MSG_ELFCLASSNONE_DMP, MSG_ELFCLASS32_DMP, MSG_ELFCLASS64_DMP 50 }; 51 52 static const conv_ds_msg_t ds_classes_cf = { 53 CONV_DS_MSG_INIT(ELFCLASSNONE, class_cf) }; 54 static const conv_ds_msg_t ds_classes_nf = { 55 CONV_DS_MSG_INIT(ELFCLASSNONE, class_nf) }; 56 static const conv_ds_msg_t ds_classes_dump = { 57 CONV_DS_MSG_INIT(ELFCLASSNONE, class_dump) }; 58 59 static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_classes_cf), NULL }; 60 static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_classes_nf), NULL }; 61 static const conv_ds_t *ds_dump[] = { 62 CONV_DS_ADDR(ds_classes_dump), NULL }; 63 64 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 65 case CONV_FMT_ALT_DUMP: 66 case CONV_FMT_ALT_FILE: 67 return (ds_dump); 68 case CONV_FMT_ALT_NF: 69 return (ds_nf); 70 } 71 72 return (ds_cf); 73 } 74 75 const char * 76 conv_ehdr_class(uchar_t class, Conv_fmt_flags_t fmt_flags, 77 Conv_inv_buf_t *inv_buf) 78 { 79 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, class, 80 ehdr_class_strings(fmt_flags), fmt_flags, inv_buf)); 81 } 82 83 conv_iter_ret_t 84 conv_iter_ehdr_class(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 85 void *uvalue) 86 { 87 return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 88 ehdr_class_strings(fmt_flags), func, uvalue)); 89 } 90 91 static const conv_ds_t ** 92 ehdr_data_strings(Conv_fmt_flags_t fmt_flags) 93 { 94 static const Msg data_cf[] = { 95 MSG_ELFDATANONE_CF, MSG_ELFDATA2LSB_CF, MSG_ELFDATA2MSB_CF 96 }; 97 static const Msg data_nf[] = { 98 MSG_ELFDATANONE_NF, MSG_ELFDATA2LSB_NF, MSG_ELFDATA2MSB_NF 99 }; 100 static const Msg data_dump[] = { 101 MSG_ELFDATANONE_DMP, MSG_ELFDATA2LSB_DMP, MSG_ELFDATA2MSB_DMP 102 }; 103 static const Msg data_file[] = { 104 MSG_ELFDATANONE_DMP, MSG_ELFDATA2LSB_FIL, MSG_ELFDATA2MSB_FIL 105 }; 106 107 108 static const conv_ds_msg_t ds_data_cf = { 109 CONV_DS_MSG_INIT(ELFCLASSNONE, data_cf) }; 110 static const conv_ds_msg_t ds_data_nf = { 111 CONV_DS_MSG_INIT(ELFCLASSNONE, data_nf) }; 112 static const conv_ds_msg_t ds_data_dump = { 113 CONV_DS_MSG_INIT(ELFCLASSNONE, data_dump) }; 114 static const conv_ds_msg_t ds_data_file = { 115 CONV_DS_MSG_INIT(ELFCLASSNONE, data_file) }; 116 117 static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_data_cf), NULL }; 118 static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_data_nf), NULL }; 119 static const conv_ds_t *ds_dump[] = { CONV_DS_ADDR(ds_data_dump), 120 NULL }; 121 static const conv_ds_t *ds_file[] = { CONV_DS_ADDR(ds_data_file), 122 NULL }; 123 124 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 125 case CONV_FMT_ALT_DUMP: 126 return (ds_dump); 127 case CONV_FMT_ALT_FILE: 128 return (ds_file); 129 case CONV_FMT_ALT_NF: 130 return (ds_nf); 131 } 132 133 return (ds_cf); 134 } 135 136 const char * 137 conv_ehdr_data(uchar_t data, Conv_fmt_flags_t fmt_flags, 138 Conv_inv_buf_t *inv_buf) 139 { 140 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, data, 141 ehdr_data_strings(fmt_flags), fmt_flags, inv_buf)); 142 } 143 144 conv_iter_ret_t 145 conv_iter_ehdr_data(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 146 void *uvalue) 147 { 148 return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 149 ehdr_data_strings(fmt_flags), func, uvalue)); 150 } 151 152 static const conv_ds_t ** 153 ehdr_mach_strings(Conv_fmt_flags_t fmt_flags) 154 { 155 156 static const Msg mach_0_11_cf[] = { 157 MSG_EM_NONE_CF, MSG_EM_M32_CF, 158 MSG_EM_SPARC_CF, MSG_EM_386_CF, 159 MSG_EM_68K_CF, MSG_EM_88K_CF, 160 MSG_EM_486_CF, MSG_EM_860_CF, 161 MSG_EM_MIPS_CF, MSG_EM_S370_CF, 162 MSG_EM_MIPS_RS3_LE_CF, MSG_EM_RS6000_CF 163 }; 164 static const Msg mach_0_11_nf[] = { 165 MSG_EM_NONE_NF, MSG_EM_M32_NF, 166 MSG_EM_SPARC_NF, MSG_EM_386_NF, 167 MSG_EM_68K_NF, MSG_EM_88K_NF, 168 MSG_EM_486_NF, MSG_EM_860_NF, 169 MSG_EM_MIPS_NF, MSG_EM_S370_NF, 170 MSG_EM_MIPS_RS3_LE_NF, MSG_EM_RS6000_NF 171 }; 172 static const Msg mach_0_11_dmp[] = { 173 MSG_EM_NONE_DMP, MSG_EM_M32_DMP, 174 MSG_EM_SPARC_DMP, MSG_EM_386_DMP, 175 MSG_EM_68K_DMP, MSG_EM_88K_DMP, 176 MSG_EM_486_DMP, MSG_EM_860_DMP, 177 MSG_EM_MIPS_DMP, MSG_EM_S370_CF, 178 MSG_EM_MIPS_RS3_LE_DMP, MSG_EM_RS6000_DMP 179 }; 180 static const conv_ds_msg_t ds_mach_0_11_cf = { 181 CONV_DS_MSG_INIT(EM_NONE, mach_0_11_cf) }; 182 static const conv_ds_msg_t ds_mach_0_11_nf = { 183 CONV_DS_MSG_INIT(EM_NONE, mach_0_11_nf) }; 184 static const conv_ds_msg_t ds_mach_0_11_dmp = { 185 CONV_DS_MSG_INIT(EM_NONE, mach_0_11_dmp) }; 186 187 188 static const Msg mach_15_22_cf[] = { 189 MSG_EM_PA_RISC_CF, MSG_EM_NCUBE_CF, 190 MSG_EM_VPP500_CF, MSG_EM_SPARC32PLUS_CF, 191 MSG_EM_960_CF, MSG_EM_PPC_CF, 192 MSG_EM_PPC64_CF, MSG_EM_S390_CF 193 }; 194 static const Msg mach_15_22_nf[] = { 195 MSG_EM_PA_RISC_NF, MSG_EM_NCUBE_NF, 196 MSG_EM_VPP500_NF, MSG_EM_SPARC32PLUS_NF, 197 MSG_EM_960_NF, MSG_EM_PPC_NF, 198 MSG_EM_PPC64_NF, MSG_EM_S390_NF 199 }; 200 static const Msg mach_15_22_dmp[] = { 201 MSG_EM_PA_RISC_DMP, MSG_EM_NCUBE_DMP, 202 MSG_EM_VPP500_DMP, MSG_EM_SPARC32PLUS_DMP, 203 MSG_EM_960_CF, MSG_EM_PPC_DMP, 204 MSG_EM_PPC64_DMP, MSG_EM_S390_CF 205 }; 206 static const conv_ds_msg_t ds_mach_15_22_cf = { 207 CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_cf) }; 208 static const conv_ds_msg_t ds_mach_15_22_nf = { 209 CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_nf) }; 210 static const conv_ds_msg_t ds_mach_15_22_dmp = { 211 CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_dmp) }; 212 213 214 static const Msg mach_36_63_cf[] = { 215 MSG_EM_V800_CF, MSG_EM_FR20_CF, 216 MSG_EM_RH32_CF, MSG_EM_RCE_CF, 217 MSG_EM_ARM_CF, MSG_EM_ALPHA_CF, 218 MSG_EM_SH_CF, MSG_EM_SPARCV9_CF, 219 MSG_EM_TRICORE_CF, MSG_EM_ARC_CF, 220 MSG_EM_H8_300_CF, MSG_EM_H8_300H_CF, 221 MSG_EM_H8S_CF, MSG_EM_H8_500_CF, 222 MSG_EM_IA_64_CF, MSG_EM_MIPS_X_CF, 223 MSG_EM_COLDFIRE_CF, MSG_EM_68HC12_CF, 224 MSG_EM_MMA_CF, MSG_EM_PCP_CF, 225 MSG_EM_NCPU_CF, MSG_EM_NDR1_CF, 226 MSG_EM_STARCORE_CF, MSG_EM_ME16_CF, 227 MSG_EM_ST100_CF, MSG_EM_TINYJ_CF, 228 MSG_EM_AMD64_CF, MSG_EM_PDSP_CF 229 }; 230 static const Msg mach_36_63_nf[] = { 231 MSG_EM_V800_NF, MSG_EM_FR20_NF, 232 MSG_EM_RH32_NF, MSG_EM_RCE_NF, 233 MSG_EM_ARM_NF, MSG_EM_ALPHA_NF, 234 MSG_EM_SH_NF, MSG_EM_SPARCV9_NF, 235 MSG_EM_TRICORE_NF, MSG_EM_ARC_NF, 236 MSG_EM_H8_300_NF, MSG_EM_H8_300H_NF, 237 MSG_EM_H8S_NF, MSG_EM_H8_500_NF, 238 MSG_EM_IA_64_NF, MSG_EM_MIPS_X_NF, 239 MSG_EM_COLDFIRE_NF, MSG_EM_68HC12_NF, 240 MSG_EM_MMA_NF, MSG_EM_PCP_NF, 241 MSG_EM_NCPU_NF, MSG_EM_NDR1_NF, 242 MSG_EM_STARCORE_NF, MSG_EM_ME16_NF, 243 MSG_EM_ST100_NF, MSG_EM_TINYJ_NF, 244 MSG_EM_AMD64_NF, MSG_EM_PDSP_NF 245 }; 246 static const Msg mach_36_63_dmp[] = { 247 MSG_EM_V800_CF, MSG_EM_FR20_CF, 248 MSG_EM_RH32_CF, MSG_EM_RCE_CF, 249 MSG_EM_ARM_DMP, MSG_EM_ALPHA_DMP, 250 MSG_EM_SH_CF, MSG_EM_SPARCV9_DMP, 251 MSG_EM_TRICORE_CF, MSG_EM_ARC_CF, 252 MSG_EM_H8_300_CF, MSG_EM_H8_300H_CF, 253 MSG_EM_H8S_CF, MSG_EM_H8_500_CF, 254 MSG_EM_IA_64_DMP, MSG_EM_MIPS_X_CF, 255 MSG_EM_COLDFIRE_CF, MSG_EM_68HC12_CF, 256 MSG_EM_MMA_CF, MSG_EM_PCP_CF, 257 MSG_EM_NCPU_CF, MSG_EM_NDR1_CF, 258 MSG_EM_STARCORE_CF, MSG_EM_ME16_CF, 259 MSG_EM_ST100_CF, MSG_EM_TINYJ_CF, 260 MSG_EM_AMD64_DMP, MSG_EM_PDSP_CF 261 }; 262 static const conv_ds_msg_t ds_mach_36_63_cf = { 263 CONV_DS_MSG_INIT(EM_V800, mach_36_63_cf) }; 264 static const conv_ds_msg_t ds_mach_36_63_nf = { 265 CONV_DS_MSG_INIT(EM_V800, mach_36_63_nf) }; 266 static const conv_ds_msg_t ds_mach_36_63_dmp = { 267 CONV_DS_MSG_INIT(EM_V800, mach_36_63_dmp) }; 268 269 270 static const Msg mach_66_120_cf[] = { 271 MSG_EM_FX66_CF, MSG_EM_ST9PLUS_CF, 272 MSG_EM_ST7_CF, MSG_EM_68HC16_CF, 273 MSG_EM_68HC11_CF, MSG_EM_68HC08_CF, 274 MSG_EM_68HC05_CF, MSG_EM_SVX_CF, 275 MSG_EM_ST19_CF, MSG_EM_VAX_CF, 276 MSG_EM_CRIS_CF, MSG_EM_JAVELIN_CF, 277 MSG_EM_FIREPATH_CF, MSG_EM_ZSP_CF, 278 MSG_EM_MMIX_CF, MSG_EM_HUANY_CF, 279 MSG_EM_PRISM_CF, MSG_EM_AVR_CF, 280 MSG_EM_FR30_CF, MSG_EM_D10V_CF, 281 MSG_EM_D30V_CF, MSG_EM_V850_CF, 282 MSG_EM_M32R_CF, MSG_EM_MN10300_CF, 283 MSG_EM_MN10200_CF, MSG_EM_PJ_CF, 284 MSG_EM_OPENRISC_CF, MSG_EM_ARC_A5_CF, 285 MSG_EM_XTENSA_CF, MSG_EM_VIDEOCORE_CF, 286 MSG_EM_TMM_GPP_CF, MSG_EM_NS32K_CF, 287 MSG_EM_TPC_CF, MSG_EM_SNP1K_CF, 288 MSG_EM_ST200_CF, MSG_EM_IP2K_CF, 289 MSG_EM_MAX_CF, MSG_EM_CR_CF, 290 MSG_EM_F2MC16_CF, MSG_EM_MSP430_CF, 291 MSG_EM_BLACKFIN_CF, MSG_EM_SE_C33_CF, 292 MSG_EM_SEP_CF, MSG_EM_ARCA_CF, 293 MSG_EM_UNICORE_CF, MSG_EM_EXCESS_CF, 294 MSG_EM_DXP_CF, MSG_EM_ALTERA_NIOS2_CF, 295 MSG_EM_CRX_CF, MSG_EM_XGATE_CF, 296 MSG_EM_C166_CF, MSG_EM_M16C_CF, 297 MSG_EM_DSPIC30F_CF, MSG_EM_CE_CF, 298 MSG_EM_M32C_CF 299 }; 300 static const Msg mach_66_120_nf[] = { 301 MSG_EM_FX66_NF, MSG_EM_ST9PLUS_NF, 302 MSG_EM_ST7_NF, MSG_EM_68HC16_NF, 303 MSG_EM_68HC11_NF, MSG_EM_68HC08_NF, 304 MSG_EM_68HC05_NF, MSG_EM_SVX_NF, 305 MSG_EM_ST19_NF, MSG_EM_VAX_NF, 306 MSG_EM_CRIS_NF, MSG_EM_JAVELIN_NF, 307 MSG_EM_FIREPATH_NF, MSG_EM_ZSP_NF, 308 MSG_EM_MMIX_NF, MSG_EM_HUANY_NF, 309 MSG_EM_PRISM_NF, MSG_EM_AVR_NF, 310 MSG_EM_FR30_NF, MSG_EM_D10V_NF, 311 MSG_EM_D30V_NF, MSG_EM_V850_NF, 312 MSG_EM_M32R_NF, MSG_EM_MN10300_NF, 313 MSG_EM_MN10200_NF, MSG_EM_PJ_NF, 314 MSG_EM_OPENRISC_NF, MSG_EM_ARC_A5_NF, 315 MSG_EM_XTENSA_NF, MSG_EM_VIDEOCORE_NF, 316 MSG_EM_TMM_GPP_NF, MSG_EM_NS32K_NF, 317 MSG_EM_TPC_NF, MSG_EM_SNP1K_NF, 318 MSG_EM_ST200_NF, MSG_EM_IP2K_NF, 319 MSG_EM_MAX_NF, MSG_EM_CR_NF, 320 MSG_EM_F2MC16_NF, MSG_EM_MSP430_NF, 321 MSG_EM_BLACKFIN_NF, MSG_EM_SE_C33_NF, 322 MSG_EM_SEP_NF, MSG_EM_ARCA_NF, 323 MSG_EM_UNICORE_NF, MSG_EM_EXCESS_NF, 324 MSG_EM_DXP_NF, MSG_EM_ALTERA_NIOS2_NF, 325 MSG_EM_CRX_NF, MSG_EM_XGATE_NF, 326 MSG_EM_C166_NF, MSG_EM_M16C_NF, 327 MSG_EM_DSPIC30F_NF, MSG_EM_CE_NF, 328 MSG_EM_TSK3000_NF, MSG_EM_RS08_NF, 329 MSG_EM_SHARC_NF, MSG_EM_ECOG2_NF, 330 MSG_EM_SCORE7_NF, MSG_EM_DSP24_NF, 331 MSG_EM_VIDEOCORE3_NF, MSG_EM_LATTICEMICO32_NF, 332 MSG_EM_SE_C17_NF, MSG_EM_TI_C6000_NF, 333 MSG_EM_TI_C2000_NF, MSG_EM_TI_C5500_NF, 334 MSG_EM_TI_ARP32_NF, MSG_EM_TI_PRU_NF 335 }; 336 static const Msg mach_66_120_dmp[] = { 337 MSG_EM_FX66_CF, MSG_EM_ST9PLUS_CF, 338 MSG_EM_ST7_CF, MSG_EM_68HC16_CF, 339 MSG_EM_68HC11_CF, MSG_EM_68HC08_CF, 340 MSG_EM_68HC05_CF, MSG_EM_SVX_CF, 341 MSG_EM_ST19_CF, MSG_EM_VAX_DMP, 342 MSG_EM_CRIS_CF, MSG_EM_JAVELIN_CF, 343 MSG_EM_FIREPATH_CF, MSG_EM_ZSP_CF, 344 MSG_EM_MMIX_CF, MSG_EM_HUANY_CF, 345 MSG_EM_PRISM_CF, MSG_EM_AVR_CF, 346 MSG_EM_FR30_CF, MSG_EM_D10V_CF, 347 MSG_EM_D30V_CF, MSG_EM_V850_CF, 348 MSG_EM_M32R_CF, MSG_EM_MN10300_CF, 349 MSG_EM_MN10200_CF, MSG_EM_PJ_CF, 350 MSG_EM_OPENRISC_CF, MSG_EM_ARC_A5_CF, 351 MSG_EM_XTENSA_CF, MSG_EM_VIDEOCORE_CF, 352 MSG_EM_TMM_GPP_CF, MSG_EM_NS32K_CF, 353 MSG_EM_TPC_CF, MSG_EM_SNP1K_CF, 354 MSG_EM_ST200_CF, MSG_EM_IP2K_CF, 355 MSG_EM_MAX_CF, MSG_EM_CR_CF, 356 MSG_EM_F2MC16_CF, MSG_EM_MSP430_CF, 357 MSG_EM_BLACKFIN_CF, MSG_EM_SE_C33_CF, 358 MSG_EM_SEP_CF, MSG_EM_ARCA_CF, 359 MSG_EM_UNICORE_CF, MSG_EM_EXCESS_CF, 360 MSG_EM_DXP_CF, MSG_EM_ALTERA_NIOS2_CF, 361 MSG_EM_CRX_CF, MSG_EM_XGATE_CF, 362 MSG_EM_C166_CF, MSG_EM_M16C_CF, 363 MSG_EM_DSPIC30F_CF, MSG_EM_CE_CF, 364 MSG_EM_M32C_CF 365 }; 366 367 static const conv_ds_msg_t ds_mach_66_120_cf = { 368 CONV_DS_MSG_INIT(EM_FX66, mach_66_120_cf) }; 369 static const conv_ds_msg_t ds_mach_66_120_nf = { 370 CONV_DS_MSG_INIT(EM_FX66, mach_66_120_nf) }; 371 static const conv_ds_msg_t ds_mach_66_120_dmp = { 372 CONV_DS_MSG_INIT(EM_FX66, mach_66_120_dmp) }; 373 374 static const Msg mach_131_144_cf[] = { 375 MSG_EM_TSK3000_CF, MSG_EM_RS08_CF, 376 MSG_EM_SHARC_CF, MSG_EM_ECOG2_CF, 377 MSG_EM_SCORE7_CF, MSG_EM_DSP24_CF, 378 MSG_EM_VIDEOCORE3_CF, MSG_EM_LATTICEMICO32_CF, 379 MSG_EM_SE_C17_CF, MSG_EM_TI_C6000_CF, 380 MSG_EM_TI_C2000_CF, MSG_EM_TI_C5500_CF, 381 MSG_EM_TI_ARP32_CF, MSG_EM_TI_PRU_CF 382 }; 383 static const Msg mach_131_144_nf[] = { 384 MSG_EM_TSK3000_NF, MSG_EM_RS08_NF, 385 MSG_EM_SHARC_NF, MSG_EM_ECOG2_NF, 386 MSG_EM_SCORE7_NF, MSG_EM_DSP24_NF, 387 MSG_EM_VIDEOCORE3_NF, MSG_EM_LATTICEMICO32_NF, 388 MSG_EM_SE_C17_NF, MSG_EM_TI_C6000_NF, 389 MSG_EM_TI_C2000_NF, MSG_EM_TI_C5500_NF, 390 MSG_EM_TI_ARP32_NF, MSG_EM_TI_PRU_NF 391 }; 392 static const Msg mach_131_144_dmp[] = { 393 MSG_EM_TSK3000_CF, MSG_EM_RS08_CF, 394 MSG_EM_SHARC_CF, MSG_EM_ECOG2_CF, 395 MSG_EM_SCORE7_CF, MSG_EM_DSP24_CF, 396 MSG_EM_VIDEOCORE3_CF, MSG_EM_LATTICEMICO32_CF, 397 MSG_EM_SE_C17_CF, MSG_EM_TI_C6000_CF, 398 MSG_EM_TI_C2000_CF, MSG_EM_TI_C5500_CF, 399 MSG_EM_TI_ARP32_CF, MSG_EM_TI_PRU_CF 400 }; 401 static const conv_ds_msg_t ds_mach_131_144_cf = { 402 CONV_DS_MSG_INIT(EM_TSK3000, mach_131_144_cf) }; 403 static const conv_ds_msg_t ds_mach_131_144_nf = { 404 CONV_DS_MSG_INIT(EM_TSK3000, mach_131_144_nf) }; 405 static const conv_ds_msg_t ds_mach_131_144_dmp = { 406 CONV_DS_MSG_INIT(EM_TSK3000, mach_131_144_dmp) }; 407 408 static const Msg mach_160_181_cf[] = { 409 MSG_EM_MMDSP_PLUS_CF, MSG_EM_CYPRESS_M8C_CF, 410 MSG_EM_R32C_CF, MSG_EM_TRIMEDIA_CF, 411 MSG_EM_QDSP6_CF, MSG_EM_8051_CF, 412 MSG_EM_STXP7X_CF, MSG_EM_NDS32_CF, 413 MSG_EM_ECOG1_CF, MSG_EM_MAXQ30_CF, 414 MSG_EM_XIMO16_CF, MSG_EM_MANIK_CF, 415 MSG_EM_CRAYNV2_CF, MSG_EM_RX_CF, 416 MSG_EM_METAG_CF, MSG_EM_MCST_ELBRUS_CF, 417 MSG_EM_ECOG16_CF, MSG_EM_CR16_CF, 418 MSG_EM_ETPU_CF, MSG_EM_SLE9X_CF, 419 MSG_EM_L10M_CF, MSG_EM_K10M_CF, 420 }; 421 static const Msg mach_160_181_nf[] = { 422 MSG_EM_MMDSP_PLUS_NF, MSG_EM_CYPRESS_M8C_NF, 423 MSG_EM_R32C_NF, MSG_EM_TRIMEDIA_NF, 424 MSG_EM_QDSP6_NF, MSG_EM_8051_NF, 425 MSG_EM_STXP7X_NF, MSG_EM_NDS32_NF, 426 MSG_EM_ECOG1_NF, MSG_EM_MAXQ30_NF, 427 MSG_EM_XIMO16_NF, MSG_EM_MANIK_NF, 428 MSG_EM_CRAYNV2_NF, MSG_EM_RX_NF, 429 MSG_EM_METAG_NF, MSG_EM_MCST_ELBRUS_NF, 430 MSG_EM_ECOG16_NF, MSG_EM_CR16_NF, 431 MSG_EM_ETPU_NF, MSG_EM_SLE9X_NF, 432 MSG_EM_L10M_NF, MSG_EM_K10M_NF, 433 }; 434 static const Msg mach_160_181_dmp[] = { 435 MSG_EM_MMDSP_PLUS_CF, MSG_EM_CYPRESS_M8C_CF, 436 MSG_EM_R32C_CF, MSG_EM_TRIMEDIA_CF, 437 MSG_EM_QDSP6_CF, MSG_EM_8051_CF, 438 MSG_EM_STXP7X_CF, MSG_EM_NDS32_CF, 439 MSG_EM_ECOG1_CF, MSG_EM_MAXQ30_CF, 440 MSG_EM_XIMO16_CF, MSG_EM_MANIK_CF, 441 MSG_EM_CRAYNV2_CF, MSG_EM_RX_CF, 442 MSG_EM_METAG_CF, MSG_EM_MCST_ELBRUS_CF, 443 MSG_EM_ECOG16_CF, MSG_EM_CR16_CF, 444 MSG_EM_ETPU_CF, MSG_EM_SLE9X_CF, 445 MSG_EM_L10M_CF, MSG_EM_K10M_CF, 446 }; 447 static const conv_ds_msg_t ds_mach_160_181_cf = { 448 CONV_DS_MSG_INIT(EM_MMDSP_PLUS, mach_160_181_cf) }; 449 static const conv_ds_msg_t ds_mach_160_181_nf = { 450 CONV_DS_MSG_INIT(EM_MMDSP_PLUS, mach_160_181_nf) }; 451 static const conv_ds_msg_t ds_mach_160_181_dmp = { 452 CONV_DS_MSG_INIT(EM_MMDSP_PLUS, mach_160_181_dmp) }; 453 454 static const Msg mach_183_cf[] = { 455 MSG_EM_AARCH64_CF 456 }; 457 static const Msg mach_183_nf[] = { 458 MSG_EM_AARCH64_NF 459 }; 460 static const Msg mach_183_dmp[] = { 461 MSG_EM_AARCH64_CF 462 }; 463 static const conv_ds_msg_t ds_mach_183_cf = { 464 CONV_DS_MSG_INIT(EM_AARCH64, mach_183_cf) }; 465 static const conv_ds_msg_t ds_mach_183_nf = { 466 CONV_DS_MSG_INIT(EM_AARCH64, mach_183_nf) }; 467 static const conv_ds_msg_t ds_mach_183_dmp = { 468 CONV_DS_MSG_INIT(EM_AARCH64, mach_183_dmp) }; 469 470 static const Msg mach_185_224_cf[] = { 471 MSG_EM_AVR32_CF, MSG_EM_STM8_CF, 472 MSG_EM_TILE64_CF, MSG_EM_TILEPRO_CF, 473 MSG_EM_MICROBLAZE_CF, MSG_EM_CUDA_CF, 474 MSG_EM_TILEGX_CF, MSG_EM_CLOUDSHIELD_CF, 475 MSG_EM_COREA_1ST_CF, MSG_EM_COREA_2ND_CF, 476 MSG_EM_ARC_COMPACT2_CF, MSG_EM_OPEN8_CF, 477 MSG_EM_RL78_CF, MSG_EM_VIDEOCORE5_CF, 478 MSG_EM_78KOR_CF, MSG_EM_56800EX_CF, 479 MSG_EM_BA1_CF, MSG_EM_BA2_CF, 480 MSG_EM_XCORE_CF, MSG_EM_MCHP_PIC_CF, 481 MSG_EM_INTEL205_CF, MSG_EM_INTEL206_CF, 482 MSG_EM_INTEL207_CF, MSG_EM_INTEL208_CF, 483 MSG_EM_INTEL209_CF, MSG_EM_KM32_CF, 484 MSG_EM_KMX32_CF, MSG_EM_KMX16_CF, 485 MSG_EM_KMX8_CF, MSG_EM_KVARC_CF, 486 MSG_EM_CDP_CF, MSG_EM_COGE_CF, 487 MSG_EM_COOL_CF, MSG_EM_NORC_CF, 488 MSG_EM_CSR_KALIMBA_CF, MSG_EM_Z80_CF, 489 MSG_EM_VISIUM_CF, MSG_EM_FT32_CF, 490 MSG_EM_MOXIE_CF, MSG_EM_AMDGPU_CF 491 }; 492 static const Msg mach_185_224_nf[] = { 493 MSG_EM_AVR32_NF, MSG_EM_STM8_NF, 494 MSG_EM_TILE64_NF, MSG_EM_TILEPRO_NF, 495 MSG_EM_MICROBLAZE_NF, MSG_EM_CUDA_NF, 496 MSG_EM_TILEGX_NF, MSG_EM_CLOUDSHIELD_NF, 497 MSG_EM_COREA_1ST_NF, MSG_EM_COREA_2ND_NF, 498 MSG_EM_ARC_COMPACT2_NF, MSG_EM_OPEN8_NF, 499 MSG_EM_RL78_NF, MSG_EM_VIDEOCORE5_NF, 500 MSG_EM_78KOR_NF, MSG_EM_56800EX_NF, 501 MSG_EM_BA1_NF, MSG_EM_BA2_NF, 502 MSG_EM_XCORE_NF, MSG_EM_MCHP_PIC_NF, 503 MSG_EM_INTEL205_NF, MSG_EM_INTEL206_NF, 504 MSG_EM_INTEL207_NF, MSG_EM_INTEL208_NF, 505 MSG_EM_INTEL209_NF, MSG_EM_KM32_NF, 506 MSG_EM_KMX32_NF, MSG_EM_KMX16_NF, 507 MSG_EM_KMX8_NF, MSG_EM_KVARC_NF, 508 MSG_EM_CDP_NF, MSG_EM_COGE_NF, 509 MSG_EM_COOL_NF, MSG_EM_NORC_NF, 510 MSG_EM_CSR_KALIMBA_NF, MSG_EM_Z80_NF, 511 MSG_EM_VISIUM_NF, MSG_EM_FT32_NF, 512 MSG_EM_MOXIE_NF, MSG_EM_AMDGPU_NF 513 }; 514 static const Msg mach_185_224_dmp[] = { 515 MSG_EM_AVR32_CF, MSG_EM_STM8_CF, 516 MSG_EM_TILE64_CF, MSG_EM_TILEPRO_CF, 517 MSG_EM_MICROBLAZE_CF, MSG_EM_CUDA_CF, 518 MSG_EM_TILEGX_CF, MSG_EM_CLOUDSHIELD_CF, 519 MSG_EM_COREA_1ST_CF, MSG_EM_COREA_2ND_CF, 520 MSG_EM_ARC_COMPACT2_CF, MSG_EM_OPEN8_CF, 521 MSG_EM_RL78_CF, MSG_EM_VIDEOCORE5_CF, 522 MSG_EM_78KOR_CF, MSG_EM_56800EX_CF, 523 MSG_EM_BA1_CF, MSG_EM_BA2_CF, 524 MSG_EM_XCORE_CF, MSG_EM_MCHP_PIC_CF, 525 MSG_EM_INTEL205_CF, MSG_EM_INTEL206_CF, 526 MSG_EM_INTEL207_CF, MSG_EM_INTEL208_CF, 527 MSG_EM_INTEL209_CF, MSG_EM_KM32_CF, 528 MSG_EM_KMX32_CF, MSG_EM_KMX16_CF, 529 MSG_EM_KMX8_CF, MSG_EM_KVARC_CF, 530 MSG_EM_CDP_CF, MSG_EM_COGE_CF, 531 MSG_EM_COOL_CF, MSG_EM_NORC_CF, 532 MSG_EM_CSR_KALIMBA_CF, MSG_EM_Z80_CF, 533 MSG_EM_VISIUM_CF, MSG_EM_FT32_CF, 534 MSG_EM_MOXIE_CF, MSG_EM_AMDGPU_CF 535 }; 536 537 static const conv_ds_msg_t ds_mach_185_224_cf = { 538 CONV_DS_MSG_INIT(EM_AVR32, mach_185_224_cf) }; 539 static const conv_ds_msg_t ds_mach_185_224_nf = { 540 CONV_DS_MSG_INIT(EM_AVR32, mach_185_224_nf) }; 541 static const conv_ds_msg_t ds_mach_185_224_dmp = { 542 CONV_DS_MSG_INIT(EM_AVR32, mach_185_224_dmp) }; 543 544 545 static const Msg mach_243_cf[] = { 546 MSG_EM_RISCV_CF, MSG_EM_LANAI_CF, 547 MSG_EM_CEVA_CF, MSG_EM_CEVA_X2_CF, 548 MSG_EM_BPF_CF, MSG_EM_GRAPHCORE_IPU_CF, 549 MSG_EM_IMG1_CF, MSG_EM_NFP_CF, 550 MSG_EM_VE_CF, MSG_EM_CSKY_CF, 551 MSG_EM_ARC_COMPACT3_64_CF, MSG_EM_MCS6502_CF, 552 MSG_EM_ARC_COMPACT3_CF, MSG_EM_KVX_CF, 553 MSG_EM_65816_CF, MSG_EM_LOONGARCH_CF, 554 MSG_EM_KF32_CF, MSG_EM_U16_U8CORE_CF, 555 MSG_EM_TACHYUM_CF, MSG_EM_56800EF_CF, 556 MSG_EM_SBF_CF, MSG_EM_AIENGINE_CF, 557 MSG_EM_SIMA_MLA_CF, MSG_EM_BANG_CF, 558 MSG_EM_LOONGGPU_CF, MSG_EM_SW64_CF, 559 MSG_EM_AIECTRLCODE_CF 560 }; 561 static const Msg mach_243_nf[] = { 562 MSG_EM_RISCV_NF, MSG_EM_LANAI_NF, 563 MSG_EM_CEVA_NF, MSG_EM_CEVA_X2_NF, 564 MSG_EM_BPF_NF, MSG_EM_GRAPHCORE_IPU_NF, 565 MSG_EM_IMG1_NF, MSG_EM_NFP_NF, 566 MSG_EM_VE_NF, MSG_EM_CSKY_NF, 567 MSG_EM_ARC_COMPACT3_64_NF, MSG_EM_MCS6502_NF, 568 MSG_EM_ARC_COMPACT3_NF, MSG_EM_KVX_NF, 569 MSG_EM_65816_NF, MSG_EM_LOONGARCH_NF, 570 MSG_EM_KF32_NF, MSG_EM_U16_U8CORE_NF, 571 MSG_EM_TACHYUM_NF, MSG_EM_56800EF_NF, 572 MSG_EM_SBF_NF, MSG_EM_AIENGINE_NF, 573 MSG_EM_SIMA_MLA_NF, MSG_EM_BANG_NF, 574 MSG_EM_LOONGGPU_NF, MSG_EM_SW64_NF, 575 MSG_EM_AIECTRLCODE_NF 576 }; 577 static const Msg mach_243_dmp[] = { 578 MSG_EM_RISCV_CF, MSG_EM_LANAI_CF, 579 MSG_EM_CEVA_CF, MSG_EM_CEVA_X2_CF, 580 MSG_EM_BPF_CF, MSG_EM_GRAPHCORE_IPU_CF, 581 MSG_EM_IMG1_CF, MSG_EM_NFP_CF, 582 MSG_EM_VE_CF, MSG_EM_CSKY_CF, 583 MSG_EM_ARC_COMPACT3_64_CF, MSG_EM_MCS6502_CF, 584 MSG_EM_ARC_COMPACT3_CF, MSG_EM_KVX_CF, 585 MSG_EM_65816_CF, MSG_EM_LOONGARCH_CF, 586 MSG_EM_KF32_CF, MSG_EM_U16_U8CORE_CF, 587 MSG_EM_TACHYUM_CF, MSG_EM_56800EF_CF, 588 MSG_EM_SBF_CF, MSG_EM_AIENGINE_CF, 589 MSG_EM_SIMA_MLA_CF, MSG_EM_BANG_CF, 590 MSG_EM_LOONGGPU_CF, MSG_EM_SW64_CF, 591 MSG_EM_AIECTRLCODE_CF 592 }; 593 594 static const conv_ds_msg_t ds_mach_243_cf = { 595 CONV_DS_MSG_INIT(EM_RISCV, mach_243_cf) }; 596 static const conv_ds_msg_t ds_mach_243_nf = { 597 CONV_DS_MSG_INIT(EM_RISCV, mach_243_nf) }; 598 static const conv_ds_msg_t ds_mach_243_dmp = { 599 CONV_DS_MSG_INIT(EM_RISCV, mach_243_dmp) }; 600 601 #if (EM_NUM != (EM_AIECTRLCODE + 1)) 602 #error "EM_NUM has grown" 603 #endif 604 /* Build NULL terminated return arrays for each string style */ 605 static const conv_ds_t *ds_cf[] = { 606 CONV_DS_ADDR(ds_mach_0_11_cf), 607 CONV_DS_ADDR(ds_mach_15_22_cf), 608 CONV_DS_ADDR(ds_mach_36_63_cf), 609 CONV_DS_ADDR(ds_mach_66_120_cf), 610 CONV_DS_ADDR(ds_mach_131_144_cf), 611 CONV_DS_ADDR(ds_mach_160_181_cf), 612 CONV_DS_ADDR(ds_mach_183_cf), 613 CONV_DS_ADDR(ds_mach_185_224_cf), 614 CONV_DS_ADDR(ds_mach_243_cf), 615 NULL 616 }; 617 static const conv_ds_t *ds_nf[] = { 618 CONV_DS_ADDR(ds_mach_0_11_nf), 619 CONV_DS_ADDR(ds_mach_15_22_nf), 620 CONV_DS_ADDR(ds_mach_36_63_nf), 621 CONV_DS_ADDR(ds_mach_66_120_nf), 622 CONV_DS_ADDR(ds_mach_131_144_nf), 623 CONV_DS_ADDR(ds_mach_160_181_nf), 624 CONV_DS_ADDR(ds_mach_183_nf), 625 CONV_DS_ADDR(ds_mach_185_224_nf), 626 CONV_DS_ADDR(ds_mach_243_nf), 627 NULL 628 }; 629 static const conv_ds_t *ds_dmp[] = { 630 CONV_DS_ADDR(ds_mach_0_11_dmp), 631 CONV_DS_ADDR(ds_mach_15_22_dmp), 632 CONV_DS_ADDR(ds_mach_36_63_dmp), 633 CONV_DS_ADDR(ds_mach_66_120_dmp), 634 CONV_DS_ADDR(ds_mach_131_144_dmp), 635 CONV_DS_ADDR(ds_mach_160_181_dmp), 636 CONV_DS_ADDR(ds_mach_183_dmp), 637 CONV_DS_ADDR(ds_mach_185_224_dmp), 638 CONV_DS_ADDR(ds_mach_243_dmp), 639 NULL 640 }; 641 642 643 /* Select the strings to use */ 644 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 645 case CONV_FMT_ALT_DUMP: 646 case CONV_FMT_ALT_FILE: 647 return (ds_dmp); 648 case CONV_FMT_ALT_NF: 649 return (ds_nf); 650 } 651 652 return (ds_cf); 653 } 654 655 const char * 656 conv_ehdr_mach(Half machine, Conv_fmt_flags_t fmt_flags, 657 Conv_inv_buf_t *inv_buf) 658 { 659 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, machine, 660 ehdr_mach_strings(fmt_flags), fmt_flags, inv_buf)); 661 } 662 663 conv_iter_ret_t 664 conv_iter_ehdr_mach(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 665 void *uvalue) 666 { 667 static const Val_desc extra_dmp_nf[] = { 668 { EM_M32, MSG_EM_M32_DMP}, 669 { EM_386, MSG_EM_386_DMP }, 670 { EM_68K, MSG_EM_68K_DMP }, 671 { EM_88K, MSG_EM_88K_DMP }, 672 { EM_486, MSG_EM_486_DMP }, 673 { EM_860, MSG_EM_860_DMP }, 674 { EM_MIPS, MSG_EM_MIPS_DMP }, 675 { EM_MIPS_RS3_LE, MSG_EM_MIPS_RS3_LE_DMP }, 676 { EM_PPC, MSG_EM_PPC_DMP }, 677 { EM_PPC64, MSG_EM_PPC64_DMP }, 678 679 { 0 } 680 }; 681 682 if (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 683 ehdr_mach_strings(fmt_flags), func, uvalue) == CONV_ITER_DONE) 684 return (CONV_ITER_DONE); 685 686 /* 687 * For the NF style, we also supply a few of the traditional 688 * dump versions for iteration, but not for display. 689 */ 690 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) 691 return (conv_iter_vd(extra_dmp_nf, func, uvalue)); 692 693 return (CONV_ITER_CONT); 694 } 695 696 697 698 static const conv_ds_t ** 699 ehdr_eident_strings(Conv_fmt_flags_t fmt_flags) 700 { 701 static const Msg eident_cf[] = { 702 MSG_EI_MAG0_CF, MSG_EI_MAG1_CF, 703 MSG_EI_MAG2_CF, MSG_EI_MAG3_CF, 704 MSG_EI_CLASS_CF, MSG_EI_DATA_CF, 705 MSG_EI_VERSION_CF, MSG_EI_OSABI_CF, 706 MSG_EI_ABIVERSION_CF 707 }; 708 static const Msg eident_nf[] = { 709 MSG_EI_MAG0_NF, MSG_EI_MAG1_NF, 710 MSG_EI_MAG2_NF, MSG_EI_MAG3_NF, 711 MSG_EI_CLASS_NF, MSG_EI_DATA_NF, 712 MSG_EI_VERSION_NF, MSG_EI_OSABI_NF, 713 MSG_EI_ABIVERSION_NF 714 }; 715 #if EI_PAD != (EI_ABIVERSION + 1) 716 error "EI_PAD has grown. Update etypes[]" 717 #endif 718 static const conv_ds_msg_t ds_eident_cf = { 719 CONV_DS_MSG_INIT(EI_MAG0, eident_cf) }; 720 static const conv_ds_msg_t ds_eident_nf = { 721 CONV_DS_MSG_INIT(EI_MAG0, eident_nf) }; 722 723 /* Build NULL terminated return arrays for each string style */ 724 static const conv_ds_t *ds_cf[] = { 725 CONV_DS_ADDR(ds_eident_cf), NULL }; 726 static const conv_ds_t *ds_nf[] = { 727 CONV_DS_ADDR(ds_eident_nf), NULL }; 728 729 /* Select the strings to use */ 730 return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CF) ? 731 ds_cf : ds_nf); 732 } 733 734 conv_iter_ret_t 735 conv_iter_ehdr_eident(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 736 void *uvalue) 737 { 738 return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 739 ehdr_eident_strings(fmt_flags), func, uvalue)); 740 } 741 742 static const conv_ds_t ** 743 ehdr_type_strings(Conv_fmt_flags_t fmt_flags) 744 { 745 #define SOL ELFOSABI_SOLARIS, EM_NONE 746 747 static const Msg type_cf[] = { 748 MSG_ET_NONE_CF, MSG_ET_REL_CF, MSG_ET_EXEC_CF, 749 MSG_ET_DYN_CF, MSG_ET_CORE_CF 750 }; 751 static const Msg type_nf[] = { 752 MSG_ET_NONE_NF, MSG_ET_REL_NF, MSG_ET_EXEC_NF, 753 MSG_ET_DYN_NF, MSG_ET_CORE_NF 754 }; 755 static const Msg type_dmp[] = { 756 MSG_ET_NONE_DMP, MSG_ET_REL_DMP, MSG_ET_EXEC_DMP, 757 MSG_ET_DYN_DMP, MSG_ET_CORE_DMP 758 }; 759 #if ET_NUM != (ET_CORE + 1) 760 error "ET_NUM has grown. Update types[]" 761 #endif 762 static const conv_ds_msg_t ds_type_cf = { 763 CONV_DS_MSG_INIT(ET_NONE, type_cf) }; 764 static const conv_ds_msg_t ds_type_nf = { 765 CONV_DS_MSG_INIT(ET_NONE, type_nf) }; 766 static const conv_ds_msg_t ds_type_dmp = { 767 CONV_DS_MSG_INIT(ET_NONE, type_dmp) }; 768 769 static const Val_desc2 type_osabi_cf[] = { 770 { ET_SUNWPSEUDO, SOL, MSG_ET_SUNWPSEUDO_CF }, 771 { 0 } 772 }; 773 static const Val_desc2 type_osabi_nf[] = { 774 { ET_SUNWPSEUDO, SOL, MSG_ET_SUNWPSEUDO_NF }, 775 { 0 } 776 }; 777 static const Val_desc2 type_osabi_dmp[] = { 778 { ET_SUNWPSEUDO, SOL, MSG_ET_SUNWPSEUDO_DMP }, 779 { 0 } 780 }; 781 #if ET_LOSUNW != ET_SUNWPSEUDO 782 error "ET_LOSUNW has grown. Update type_osabi[]" 783 #endif 784 static const conv_ds_vd2_t ds_type_osabi_cf = { 785 CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_cf }; 786 static const conv_ds_vd2_t ds_type_osabi_nf = { 787 CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_nf }; 788 static const conv_ds_vd2_t ds_type_osabi_dmp = { 789 CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_dmp }; 790 791 792 /* Build NULL terminated return arrays for each string style */ 793 static const conv_ds_t *ds_cf[] = { 794 CONV_DS_ADDR(ds_type_cf), CONV_DS_ADDR(ds_type_osabi_cf), 795 NULL }; 796 static const conv_ds_t *ds_nf[] = { 797 CONV_DS_ADDR(ds_type_nf), CONV_DS_ADDR(ds_type_osabi_nf), 798 NULL }; 799 static const conv_ds_t *ds_dmp[] = { 800 CONV_DS_ADDR(ds_type_dmp), CONV_DS_ADDR(ds_type_osabi_dmp), 801 NULL }; 802 803 /* Select the strings to use */ 804 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 805 case CONV_FMT_ALT_DUMP: 806 return (ds_dmp); 807 case CONV_FMT_ALT_NF: 808 return (ds_nf); 809 } 810 811 return (ds_cf); 812 813 #undef SOL 814 } 815 816 const char * 817 conv_ehdr_type(uchar_t osabi, Half etype, Conv_fmt_flags_t fmt_flags, 818 Conv_inv_buf_t *inv_buf) 819 { 820 return (conv_map_ds(osabi, EM_NONE, etype, 821 ehdr_type_strings(fmt_flags), fmt_flags, inv_buf)); 822 } 823 824 conv_iter_ret_t 825 conv_iter_ehdr_type(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags, 826 conv_iter_cb_t func, void *uvalue) 827 { 828 return (conv_iter_ds(osabi, EM_NONE, 829 ehdr_type_strings(fmt_flags), func, uvalue)); 830 } 831 832 static const conv_ds_t ** 833 ehdr_vers_strings(Conv_fmt_flags_t fmt_flags) 834 { 835 static const Msg versions_cf[] = { 836 MSG_EV_NONE_CF, MSG_EV_CURRENT_CF 837 }; 838 static const Msg versions_nf[] = { 839 MSG_EV_NONE_NF, MSG_EV_CURRENT_NF 840 }; 841 static const Msg versions_dmp[] = { 842 MSG_EV_NONE_DMP, MSG_EV_CURRENT_DMP 843 }; 844 #if EV_NUM != 2 845 error "EV_NUM has grown. Update versions[]" 846 #endif 847 static const conv_ds_msg_t ds_versions_cf = { 848 CONV_DS_MSG_INIT(EV_NONE, versions_cf) }; 849 static const conv_ds_msg_t ds_versions_nf = { 850 CONV_DS_MSG_INIT(EV_NONE, versions_nf) }; 851 static const conv_ds_msg_t ds_versions_dmp = { 852 CONV_DS_MSG_INIT(EV_NONE, versions_dmp) }; 853 854 /* Build NULL terminated return arrays for each string style */ 855 static const conv_ds_t *ds_cf[] = { 856 CONV_DS_ADDR(ds_versions_cf), NULL }; 857 static const conv_ds_t *ds_nf[] = { 858 CONV_DS_ADDR(ds_versions_nf), NULL }; 859 static const conv_ds_t *ds_dmp[] = { 860 CONV_DS_ADDR(ds_versions_dmp), NULL }; 861 862 /* Select the strings to use */ 863 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 864 case CONV_FMT_ALT_DUMP: 865 return (ds_dmp); 866 case CONV_FMT_ALT_NF: 867 return (ds_nf); 868 } 869 870 return (ds_cf); 871 } 872 873 const char * 874 conv_ehdr_vers(Word version, Conv_fmt_flags_t fmt_flags, 875 Conv_inv_buf_t *inv_buf) 876 { 877 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, version, 878 ehdr_vers_strings(fmt_flags), fmt_flags, inv_buf)); 879 } 880 881 conv_iter_ret_t 882 conv_iter_ehdr_vers(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 883 void *uvalue) 884 { 885 return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 886 ehdr_vers_strings(fmt_flags), func, uvalue)); 887 } 888 889 static void 890 conv_ehdr_sparc_flags_strings(Conv_fmt_flags_t fmt_flags, 891 const conv_ds_msg_t **mm_msg, const Val_desc **flag_desc) 892 { 893 #define EFLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 894 MSG_EF_SPARCV9_TSO_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 895 MSG_EF_SPARC_SUN_US1_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 896 MSG_EF_SPARC_HAL_R1_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 897 MSG_EF_SPARC_SUN_US3_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 898 CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 899 900 /* 901 * Ensure that Conv_ehdr_flags_buf_t is large enough: 902 * 903 * EFLAGSZ is the real minimum size of the buffer required by 904 * conv_ehdr_flags(). However, Conv_ehdr_flags_buf_t uses 905 * CONV_EHDR_FLAG_BUFSIZE to set the buffer size. We do things 906 * this way because the definition of EFLAGSZ uses information 907 * that is not available in the environment of other programs 908 * that include the conv.h header file. 909 */ 910 #if (CONV_EHDR_FLAGS_BUFSIZE != EFLAGSZ) && !defined(__lint) 911 #define REPORT_BUFSIZE EFLAGSZ 912 #include "report_bufsize.h" 913 #error "CONV_EHDR_FLAGS_BUFSIZE does not match EFLAGSZ" 914 #endif 915 916 static const Msg mm_flags_cf[] = { 917 MSG_EF_SPARCV9_TSO_CF, MSG_EF_SPARCV9_PSO_CF, 918 MSG_EF_SPARCV9_RMO_CF 919 }; 920 static const Msg mm_flags_nf[] = { 921 MSG_EF_SPARCV9_TSO_NF, MSG_EF_SPARCV9_PSO_NF, 922 MSG_EF_SPARCV9_RMO_NF 923 }; 924 static const conv_ds_msg_t ds_mm_flags_cf = { 925 CONV_DS_MSG_INIT(EF_SPARCV9_TSO, mm_flags_cf) }; 926 static const conv_ds_msg_t ds_mm_flags_nf = { 927 CONV_DS_MSG_INIT(EF_SPARCV9_TSO, mm_flags_nf) }; 928 929 930 static const Val_desc vda_cf[] = { 931 { EF_SPARC_32PLUS, MSG_EF_SPARC_32PLUS_CF }, 932 { EF_SPARC_SUN_US1, MSG_EF_SPARC_SUN_US1_CF }, 933 { EF_SPARC_HAL_R1, MSG_EF_SPARC_HAL_R1_CF }, 934 { EF_SPARC_SUN_US3, MSG_EF_SPARC_SUN_US3_CF }, 935 { 0 } 936 }; 937 static const Val_desc vda_nf[] = { 938 { EF_SPARC_32PLUS, MSG_EF_SPARC_32PLUS_NF }, 939 { EF_SPARC_SUN_US1, MSG_EF_SPARC_SUN_US1_NF }, 940 { EF_SPARC_HAL_R1, MSG_EF_SPARC_HAL_R1_NF }, 941 { EF_SPARC_SUN_US3, MSG_EF_SPARC_SUN_US3_NF }, 942 { 0 } 943 }; 944 945 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 946 default: 947 *mm_msg = &ds_mm_flags_cf; 948 *flag_desc = vda_cf; 949 break; 950 case CONV_FMT_ALT_NF: 951 *mm_msg = &ds_mm_flags_nf; 952 *flag_desc = vda_nf; 953 break; 954 } 955 } 956 957 /* 958 * Make a string representation of the e_flags field. 959 */ 960 const char * 961 conv_ehdr_flags(Half mach, Word flags, Conv_fmt_flags_t fmt_flags, 962 Conv_ehdr_flags_buf_t *flags_buf) 963 { 964 static const char *leading_str_arr[2]; 965 static CONV_EXPN_FIELD_ARG conv_arg = { 966 NULL, sizeof (flags_buf->buf), leading_str_arr }; 967 968 const char **lstr; 969 const conv_ds_msg_t *mm_msg; 970 const Val_desc *vdp; 971 Word mm; 972 973 /* 974 * Non-SPARC architectures presently provide no known flags. 975 */ 976 if ((mach != EM_SPARCV9) && (((mach != EM_SPARC) && 977 (mach != EM_SPARC32PLUS)) || (flags == 0))) 978 return (conv_invalid_val(&flags_buf->inv_buf, flags, 979 CONV_FMT_DECIMAL)); 980 981 conv_arg.buf = flags_buf->buf; 982 conv_ehdr_sparc_flags_strings(fmt_flags, &mm_msg, &vdp); 983 conv_arg.oflags = conv_arg.rflags = flags; 984 985 mm = flags & EF_SPARCV9_MM; 986 lstr = leading_str_arr; 987 if ((mach == EM_SPARCV9) && (mm <= mm_msg->ds_topval)) { 988 *lstr++ = MSG_ORIG(mm_msg->ds_msg[mm]); 989 conv_arg.rflags &= ~EF_SPARCV9_MM; 990 } 991 *lstr = NULL; 992 993 (void) conv_expn_field(&conv_arg, vdp, fmt_flags); 994 995 return (conv_arg.buf); 996 } 997 998 conv_iter_ret_t 999 conv_iter_ehdr_flags(Half mach, Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 1000 void *uvalue) 1001 { 1002 1003 if ((mach == EM_SPARCV9) || (mach == EM_SPARC) || 1004 (mach == EM_SPARC32PLUS) || (mach == CONV_MACH_ALL)) { 1005 const conv_ds_msg_t *ds_msg_mm; 1006 const Val_desc *vdp; 1007 1008 conv_ehdr_sparc_flags_strings(fmt_flags, &ds_msg_mm, &vdp); 1009 1010 if (mach == EM_SPARCV9) { 1011 const conv_ds_t *ds[2]; 1012 1013 ds[0] = CONV_DS_ADDR(ds_msg_mm); 1014 ds[1] = NULL; 1015 1016 if (conv_iter_ds(ELFOSABI_NONE, mach, ds, 1017 func, uvalue) == CONV_ITER_DONE) 1018 return (CONV_ITER_DONE); 1019 } 1020 1021 return (conv_iter_vd(vdp, func, uvalue)); 1022 } 1023 1024 return (CONV_ITER_CONT); 1025 } 1026 1027 static const conv_ds_t ** 1028 ehdr_osabi_strings(Conv_fmt_flags_t fmt_flags) 1029 { 1030 1031 static const Msg osabi_0_3_cf[] = { 1032 MSG_OSABI_NONE_CF, MSG_OSABI_HPUX_CF, 1033 MSG_OSABI_NETBSD_CF, MSG_OSABI_LINUX_CF 1034 }; 1035 static const Msg osabi_0_3_nf[] = { 1036 MSG_OSABI_NONE_NF, MSG_OSABI_HPUX_NF, 1037 MSG_OSABI_NETBSD_NF, MSG_OSABI_LINUX_NF 1038 }; 1039 static const Msg osabi_0_3_dmp[] = { 1040 MSG_OSABI_NONE_DMP, MSG_OSABI_HPUX_DMP, 1041 MSG_OSABI_NETBSD_DMP, MSG_OSABI_LINUX_DMP 1042 }; 1043 static const conv_ds_msg_t ds_osabi_0_3_cf = { 1044 CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_cf) }; 1045 static const conv_ds_msg_t ds_osabi_0_3_nf = { 1046 CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_nf) }; 1047 static const conv_ds_msg_t ds_osabi_0_3_dmp = { 1048 CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_dmp) }; 1049 1050 1051 static const Msg osabi_6_18_cf[] = { 1052 MSG_OSABI_SOLARIS_CF, MSG_OSABI_AIX_CF, 1053 MSG_OSABI_IRIX_CF, MSG_OSABI_FREEBSD_CF, 1054 MSG_OSABI_TRU64_CF, MSG_OSABI_MODESTO_CF, 1055 MSG_OSABI_OPENBSD_CF, MSG_OSABI_OPENVMS_CF, 1056 MSG_OSABI_NSK_CF, MSG_OSABI_AROS_CF, 1057 MSG_OSABI_FENIXOS_CF, MSG_OSABI_CLOUDABI_CF, 1058 MSG_OSABI_OPENVOS_CF 1059 }; 1060 static const Msg osabi_6_18_nf[] = { 1061 MSG_OSABI_SOLARIS_NF, MSG_OSABI_AIX_NF, 1062 MSG_OSABI_IRIX_NF, MSG_OSABI_FREEBSD_NF, 1063 MSG_OSABI_TRU64_NF, MSG_OSABI_MODESTO_NF, 1064 MSG_OSABI_OPENBSD_NF, MSG_OSABI_OPENVMS_NF, 1065 MSG_OSABI_NSK_NF, MSG_OSABI_AROS_NF, 1066 MSG_OSABI_FENIXOS_NF, MSG_OSABI_CLOUDABI_NF, 1067 MSG_OSABI_OPENVOS_NF 1068 }; 1069 static const Msg osabi_6_18_dmp[] = { 1070 MSG_OSABI_SOLARIS_DMP, MSG_OSABI_AIX_DMP, 1071 MSG_OSABI_IRIX_DMP, MSG_OSABI_FREEBSD_DMP, 1072 MSG_OSABI_TRU64_DMP, MSG_OSABI_MODESTO_DMP, 1073 MSG_OSABI_OPENBSD_DMP, MSG_OSABI_OPENVMS_DMP, 1074 MSG_OSABI_NSK_DMP, MSG_OSABI_AROS_DMP, 1075 MSG_OSABI_FENIXOS_DMP, MSG_OSABI_CLOUDABI_DMP, 1076 MSG_OSABI_OPENVOS_DMP 1077 }; 1078 static const conv_ds_msg_t ds_osabi_6_18_cf = { 1079 CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_18_cf) }; 1080 static const conv_ds_msg_t ds_osabi_6_18_nf = { 1081 CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_18_nf) }; 1082 static const conv_ds_msg_t ds_osabi_6_18_dmp = { 1083 CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_18_dmp) }; 1084 1085 1086 static const Val_desc osabi_misc_cf[] = { 1087 { ELFOSABI_ARM, MSG_OSABI_ARM_CF }, 1088 { ELFOSABI_STANDALONE, MSG_OSABI_STANDALONE_CF }, 1089 { 0 } 1090 }; 1091 static const Val_desc osabi_misc_nf[] = { 1092 { ELFOSABI_ARM, MSG_OSABI_ARM_NF }, 1093 { ELFOSABI_STANDALONE, MSG_OSABI_STANDALONE_NF }, 1094 { 0 } 1095 }; 1096 static const Val_desc osabi_misc_dmp[] = { 1097 { ELFOSABI_ARM, MSG_OSABI_ARM_DMP }, 1098 { ELFOSABI_STANDALONE, MSG_OSABI_STANDALONE_DMP }, 1099 { 0 } 1100 }; 1101 static const conv_ds_vd_t ds_osabi_misc_cf = { 1102 CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_cf }; 1103 static const conv_ds_vd_t ds_osabi_misc_nf = { 1104 CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_nf }; 1105 static const conv_ds_vd_t ds_osabi_misc_dmp = { 1106 CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_dmp }; 1107 1108 /* Build NULL terminated return arrays for each string style */ 1109 static const conv_ds_t *ds_cf[] = { 1110 CONV_DS_ADDR(ds_osabi_0_3_cf), CONV_DS_ADDR(ds_osabi_6_18_cf), 1111 CONV_DS_ADDR(ds_osabi_misc_cf), NULL }; 1112 static const conv_ds_t *ds_nf[] = { 1113 CONV_DS_ADDR(ds_osabi_0_3_nf), CONV_DS_ADDR(ds_osabi_6_18_nf), 1114 CONV_DS_ADDR(ds_osabi_misc_nf), NULL }; 1115 static const conv_ds_t *ds_dmp[] = { 1116 CONV_DS_ADDR(ds_osabi_0_3_dmp), CONV_DS_ADDR(ds_osabi_6_18_dmp), 1117 CONV_DS_ADDR(ds_osabi_misc_dmp), NULL }; 1118 1119 /* Select the strings to use */ 1120 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 1121 case CONV_FMT_ALT_DUMP: 1122 return (ds_dmp); 1123 case CONV_FMT_ALT_NF: 1124 return (ds_nf); 1125 } 1126 1127 return (ds_cf); 1128 } 1129 1130 /* 1131 * Make a string representation of the e_ident[EI_OSABI] field. 1132 */ 1133 const char * 1134 conv_ehdr_osabi(uchar_t osabi, Conv_fmt_flags_t fmt_flags, 1135 Conv_inv_buf_t *inv_buf) 1136 { 1137 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, osabi, 1138 ehdr_osabi_strings(fmt_flags), fmt_flags, inv_buf)); 1139 } 1140 1141 conv_iter_ret_t 1142 conv_iter_ehdr_osabi(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 1143 void *uvalue) 1144 { 1145 if (conv_iter_ds(ELFOSABI_NONE, EM_NONE, ehdr_osabi_strings(fmt_flags), 1146 func, uvalue) == CONV_ITER_DONE) 1147 return (CONV_ITER_DONE); 1148 1149 /* 1150 * ELFOSABI_NONE might have been better named ELFOSABI_SYSV. For the 1151 * CF and NF sytles, we supply that name for 0 in addition to NONE. 1152 */ 1153 switch (CONV_TYPE_FMT_ALT(fmt_flags)) { 1154 case CONV_FMT_ALT_CF: 1155 return ((* func)(MSG_ORIG(MSG_OSABI_SYSV_CF), 1156 ELFOSABI_NONE, uvalue)); 1157 case CONV_FMT_ALT_NF: 1158 return ((* func)(MSG_ORIG(MSG_OSABI_SYSV_NF), 1159 ELFOSABI_NONE, uvalue)); 1160 } 1161 1162 return (CONV_ITER_CONT); 1163 } 1164 1165 static const conv_ds_t ** 1166 ehdr_abivers_strings(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags) 1167 { 1168 static const Msg abiversions_cf[] = { 1169 MSG_EAV_SUNW_NONE_CF, MSG_EAV_SUNW_CURRENT_CF 1170 }; 1171 static const Msg abiversions_nf[] = { 1172 MSG_EAV_SUNW_NONE_NF, MSG_EAV_SUNW_CURRENT_NF 1173 }; 1174 #if EAV_SUNW_NUM != 2 1175 error "EAV_SUNW_NUM has grown. Update abiversions[]" 1176 #endif 1177 static const conv_ds_msg_t ds_abiversions_cf = { 1178 CONV_DS_MSG_INIT(EV_NONE, abiversions_cf) }; 1179 static const conv_ds_msg_t ds_abiversions_nf = { 1180 CONV_DS_MSG_INIT(EV_NONE, abiversions_nf) }; 1181 1182 /* Build NULL terminated return arrays for each string style */ 1183 static const conv_ds_t *ds_cf[] = { 1184 CONV_DS_ADDR(ds_abiversions_cf), NULL }; 1185 static const conv_ds_t *ds_nf[] = { 1186 CONV_DS_ADDR(ds_abiversions_nf), NULL }; 1187 1188 /* For non-Solaris OSABI, we don't have symbolic names */ 1189 static const conv_ds_t *ds_none[] = { NULL }; 1190 1191 1192 /* 1193 * Select the strings to use. This is a rare case where 1194 * we don't treat ELFOSABI_NONE and ELFOSABI_SOLARIS 1195 * as the same thing. We should never create a Solaris 1196 * object tagged as ELFOSABI_NONE for which the abiversion 1197 * is non-zero. 1198 */ 1199 if ((osabi == ELFOSABI_SOLARIS) || (osabi == CONV_OSABI_ALL)) 1200 return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ? 1201 ds_nf : ds_cf); 1202 1203 return (ds_none); 1204 } 1205 1206 const char * 1207 conv_ehdr_abivers(uchar_t osabi, Word version, Conv_fmt_flags_t fmt_flags, 1208 Conv_inv_buf_t *inv_buf) 1209 { 1210 return (conv_map_ds(osabi, EM_NONE, version, 1211 ehdr_abivers_strings(osabi, fmt_flags), fmt_flags, inv_buf)); 1212 } 1213 1214 conv_iter_ret_t 1215 conv_iter_ehdr_abivers(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags, 1216 conv_iter_cb_t func, void *uvalue) 1217 { 1218 return (conv_iter_ds(osabi, EM_NONE, 1219 ehdr_abivers_strings(osabi, fmt_flags), func, uvalue)); 1220 } 1221 1222 /* 1223 * A generic means of returning additional information for a rejected file in 1224 * terms of a string. ELFOSABI_SOLARIS is assummed. 1225 */ 1226 const char * 1227 conv_reject_desc(Rej_desc * rej, Conv_reject_desc_buf_t *reject_desc_buf, 1228 Half mach) 1229 { 1230 ushort_t type = rej->rej_type; 1231 uint_t info = rej->rej_info; 1232 1233 switch (type) { 1234 case SGS_REJ_MACH: 1235 return (conv_ehdr_mach((Half)info, 0, 1236 &reject_desc_buf->inv_buf)); 1237 case SGS_REJ_CLASS: 1238 return (conv_ehdr_class((uchar_t)info, 0, 1239 &reject_desc_buf->inv_buf)); 1240 case SGS_REJ_DATA: 1241 return (conv_ehdr_data((uchar_t)info, 0, 1242 &reject_desc_buf->inv_buf)); 1243 case SGS_REJ_TYPE: 1244 return (conv_ehdr_type(ELFOSABI_SOLARIS, (Half)info, 0, 1245 &reject_desc_buf->inv_buf)); 1246 case SGS_REJ_BADFLAG: 1247 case SGS_REJ_MISFLAG: 1248 case SGS_REJ_HAL: 1249 case SGS_REJ_US3: 1250 return (conv_ehdr_flags(mach, (Word)info, 0, 1251 &reject_desc_buf->flags_buf)); 1252 case SGS_REJ_UNKFILE: 1253 case SGS_REJ_ARCHIVE: 1254 case SGS_REJ_KMOD: 1255 return (NULL); 1256 case SGS_REJ_STR: 1257 case SGS_REJ_HWCAP_1: 1258 case SGS_REJ_SFCAP_1: 1259 case SGS_REJ_HWCAP_2: 1260 case SGS_REJ_HWCAP_3: 1261 case SGS_REJ_MACHCAP: 1262 case SGS_REJ_PLATCAP: 1263 if (rej->rej_str) 1264 return ((const char *)rej->rej_str); 1265 else 1266 return (MSG_ORIG(MSG_STR_EMPTY)); 1267 default: 1268 return (conv_invalid_val(&reject_desc_buf->inv_buf, info, 1269 CONV_FMT_DECIMAL)); 1270 } 1271 } 1272