xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/elf.c (revision 12254:ff5bb54e2a40)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
23*12254SAli.Bahrami@Oracle.COM  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * String conversion routines for ELF header attributes.
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate #include	<stdio.h>
300Sstevel@tonic-gate #include	<string.h>
310Sstevel@tonic-gate #include	"_conv.h"
320Sstevel@tonic-gate #include	"elf_msg.h"
330Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
340Sstevel@tonic-gate 
351976Sab196087 
361976Sab196087 
379273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_class_strings(Conv_fmt_flags_t fmt_flags)389273SAli.Bahrami@Sun.COM ehdr_class_strings(Conv_fmt_flags_t fmt_flags)
399273SAli.Bahrami@Sun.COM {
409273SAli.Bahrami@Sun.COM 	static const Msg	class_cf[] = {
419273SAli.Bahrami@Sun.COM 		MSG_ELFCLASSNONE_CF, MSG_ELFCLASS32_CF, MSG_ELFCLASS64_CF
429273SAli.Bahrami@Sun.COM 	};
439273SAli.Bahrami@Sun.COM 	static const Msg	class_nf[] = {
449273SAli.Bahrami@Sun.COM 		MSG_ELFCLASSNONE_NF, MSG_ELFCLASS32_NF, MSG_ELFCLASS64_NF
459273SAli.Bahrami@Sun.COM 	};
469273SAli.Bahrami@Sun.COM 	static const Msg	class_dump[] = {
479273SAli.Bahrami@Sun.COM 		MSG_ELFCLASSNONE_DMP, MSG_ELFCLASS32_DMP, MSG_ELFCLASS64_DMP
489273SAli.Bahrami@Sun.COM 	};
491976Sab196087 
509273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_classes_cf = {
519273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, class_cf) };
529273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_classes_nf = {
539273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, class_nf) };
549273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_classes_dump = {
559273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, class_dump) };
561976Sab196087 
579273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_classes_cf), NULL };
589273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_classes_nf), NULL };
599273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_dump[] = {
609273SAli.Bahrami@Sun.COM 	    CONV_DS_ADDR(ds_classes_dump), NULL };
619273SAli.Bahrami@Sun.COM 
629273SAli.Bahrami@Sun.COM 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
639273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_DUMP:
649273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_FILE:
659273SAli.Bahrami@Sun.COM 		return (ds_dump);
669273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
679273SAli.Bahrami@Sun.COM 		return (ds_nf);
689273SAli.Bahrami@Sun.COM 	}
699273SAli.Bahrami@Sun.COM 
709273SAli.Bahrami@Sun.COM 	return (ds_cf);
719273SAli.Bahrami@Sun.COM }
721976Sab196087 
730Sstevel@tonic-gate const char *
conv_ehdr_class(uchar_t class,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)745088Sab196087 conv_ehdr_class(uchar_t class, Conv_fmt_flags_t fmt_flags,
755088Sab196087     Conv_inv_buf_t *inv_buf)
760Sstevel@tonic-gate {
779273SAli.Bahrami@Sun.COM 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, class,
789273SAli.Bahrami@Sun.COM 	    ehdr_class_strings(fmt_flags), fmt_flags, inv_buf));
799273SAli.Bahrami@Sun.COM }
809273SAli.Bahrami@Sun.COM 
819273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_class(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)829273SAli.Bahrami@Sun.COM conv_iter_ehdr_class(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
839273SAli.Bahrami@Sun.COM     void *uvalue)
849273SAli.Bahrami@Sun.COM {
859273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
869273SAli.Bahrami@Sun.COM 	    ehdr_class_strings(fmt_flags), func, uvalue));
879273SAli.Bahrami@Sun.COM }
889273SAli.Bahrami@Sun.COM 
899273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_data_strings(Conv_fmt_flags_t fmt_flags)909273SAli.Bahrami@Sun.COM ehdr_data_strings(Conv_fmt_flags_t fmt_flags)
919273SAli.Bahrami@Sun.COM {
929273SAli.Bahrami@Sun.COM 	static const Msg	data_cf[] = {
939273SAli.Bahrami@Sun.COM 		MSG_ELFDATANONE_CF, MSG_ELFDATA2LSB_CF, MSG_ELFDATA2MSB_CF
941976Sab196087 	};
959273SAli.Bahrami@Sun.COM 	static const Msg	data_nf[] = {
969273SAli.Bahrami@Sun.COM 		MSG_ELFDATANONE_NF, MSG_ELFDATA2LSB_NF, MSG_ELFDATA2MSB_NF
979273SAli.Bahrami@Sun.COM 	};
989273SAli.Bahrami@Sun.COM 	static const Msg	data_dump[] = {
999273SAli.Bahrami@Sun.COM 		MSG_ELFDATANONE_DMP, MSG_ELFDATA2LSB_DMP, MSG_ELFDATA2MSB_DMP
1009273SAli.Bahrami@Sun.COM 	};
1019273SAli.Bahrami@Sun.COM 	static const Msg	data_file[] = {
1029273SAli.Bahrami@Sun.COM 		MSG_ELFDATANONE_DMP, MSG_ELFDATA2LSB_FIL, MSG_ELFDATA2MSB_FIL
1031618Srie 	};
1040Sstevel@tonic-gate 
1059273SAli.Bahrami@Sun.COM 
1069273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_data_cf = {
1079273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_cf) };
1089273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_data_nf = {
1099273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_nf) };
1109273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_data_dump = {
1119273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_dump) };
1129273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_data_file = {
1139273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_file) };
1149273SAli.Bahrami@Sun.COM 
1159273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_data_cf), NULL };
1169273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_data_nf), NULL };
1179273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_dump[] = { CONV_DS_ADDR(ds_data_dump),
1189273SAli.Bahrami@Sun.COM 	    NULL };
1199273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_file[] = { CONV_DS_ADDR(ds_data_file),
1209273SAli.Bahrami@Sun.COM 	    NULL };
1219273SAli.Bahrami@Sun.COM 
1225088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
1235088Sab196087 	case CONV_FMT_ALT_DUMP:
1249273SAli.Bahrami@Sun.COM 		return (ds_dump);
1255088Sab196087 	case CONV_FMT_ALT_FILE:
1269273SAli.Bahrami@Sun.COM 		return (ds_file);
1279273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
1289273SAli.Bahrami@Sun.COM 		return (ds_nf);
1295088Sab196087 	}
1305088Sab196087 
1319273SAli.Bahrami@Sun.COM 	return (ds_cf);
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate const char *
conv_ehdr_data(uchar_t data,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)1355088Sab196087 conv_ehdr_data(uchar_t data, Conv_fmt_flags_t fmt_flags,
1365088Sab196087     Conv_inv_buf_t *inv_buf)
1370Sstevel@tonic-gate {
1389273SAli.Bahrami@Sun.COM 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, data,
1399273SAli.Bahrami@Sun.COM 	    ehdr_data_strings(fmt_flags), fmt_flags, inv_buf));
1409273SAli.Bahrami@Sun.COM }
1410Sstevel@tonic-gate 
1429273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_data(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)1439273SAli.Bahrami@Sun.COM conv_iter_ehdr_data(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
1449273SAli.Bahrami@Sun.COM     void *uvalue)
1459273SAli.Bahrami@Sun.COM {
1469273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
1479273SAli.Bahrami@Sun.COM 	    ehdr_data_strings(fmt_flags), func, uvalue));
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate 
1509273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_mach_strings(Conv_fmt_flags_t fmt_flags)1519273SAli.Bahrami@Sun.COM ehdr_mach_strings(Conv_fmt_flags_t fmt_flags)
1529273SAli.Bahrami@Sun.COM {
1539273SAli.Bahrami@Sun.COM 
1549273SAli.Bahrami@Sun.COM 	static const Msg mach_0_11_cf[] = {
1559273SAli.Bahrami@Sun.COM 		MSG_EM_NONE_CF,		MSG_EM_M32_CF,
1569273SAli.Bahrami@Sun.COM 		MSG_EM_SPARC_CF,	MSG_EM_386_CF,
1579273SAli.Bahrami@Sun.COM 		MSG_EM_68K_CF,		MSG_EM_88K_CF,
1589273SAli.Bahrami@Sun.COM 		MSG_EM_486_CF,		MSG_EM_860_CF,
1599273SAli.Bahrami@Sun.COM 		MSG_EM_MIPS_CF,		MSG_EM_S370_CF,
1609273SAli.Bahrami@Sun.COM 		MSG_EM_MIPS_RS3_LE_CF,	MSG_EM_RS6000_CF
1619273SAli.Bahrami@Sun.COM 	};
1629273SAli.Bahrami@Sun.COM 	static const Msg mach_0_11_nf[] = {
1639273SAli.Bahrami@Sun.COM 		MSG_EM_NONE_NF,		MSG_EM_M32_NF,
1649273SAli.Bahrami@Sun.COM 		MSG_EM_SPARC_NF,	MSG_EM_386_NF,
1659273SAli.Bahrami@Sun.COM 		MSG_EM_68K_NF,		MSG_EM_88K_NF,
1669273SAli.Bahrami@Sun.COM 		MSG_EM_486_NF,		MSG_EM_860_NF,
1679273SAli.Bahrami@Sun.COM 		MSG_EM_MIPS_NF,		MSG_EM_S370_NF,
1689273SAli.Bahrami@Sun.COM 		MSG_EM_MIPS_RS3_LE_NF,	MSG_EM_RS6000_NF
1699273SAli.Bahrami@Sun.COM 	};
1709273SAli.Bahrami@Sun.COM 	static const Msg mach_0_11_dmp[] = {
1719273SAli.Bahrami@Sun.COM 		MSG_EM_NONE_DMP,	MSG_EM_M32_DMP,
1729273SAli.Bahrami@Sun.COM 		MSG_EM_SPARC_DMP,	MSG_EM_386_DMP,
1739273SAli.Bahrami@Sun.COM 		MSG_EM_68K_DMP,		MSG_EM_88K_DMP,
1749273SAli.Bahrami@Sun.COM 		MSG_EM_486_DMP,		MSG_EM_860_DMP,
1759273SAli.Bahrami@Sun.COM 		MSG_EM_MIPS_DMP,	MSG_EM_S370_CF,
1769273SAli.Bahrami@Sun.COM 		MSG_EM_MIPS_RS3_LE_DMP,	MSG_EM_RS6000_DMP
1779273SAli.Bahrami@Sun.COM 	};
1789273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_0_11_cf = {
1799273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_NONE, mach_0_11_cf) };
1809273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_0_11_nf = {
1819273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_NONE, mach_0_11_nf) };
1829273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_0_11_dmp = {
1839273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_NONE, mach_0_11_dmp) };
1849273SAli.Bahrami@Sun.COM 
1859273SAli.Bahrami@Sun.COM 
1869273SAli.Bahrami@Sun.COM 	static const Msg mach_15_22_cf[] = {
1879273SAli.Bahrami@Sun.COM 		MSG_EM_PA_RISC_CF,	MSG_EM_NCUBE_CF,
1889273SAli.Bahrami@Sun.COM 		MSG_EM_VPP500_CF,	MSG_EM_SPARC32PLUS_CF,
1899273SAli.Bahrami@Sun.COM 		MSG_EM_960_CF,		MSG_EM_PPC_CF,
1909273SAli.Bahrami@Sun.COM 		MSG_EM_PPC64_CF,	MSG_EM_S390_CF
1919273SAli.Bahrami@Sun.COM 	};
1929273SAli.Bahrami@Sun.COM 	static const Msg mach_15_22_nf[] = {
1939273SAli.Bahrami@Sun.COM 		MSG_EM_PA_RISC_NF,	MSG_EM_NCUBE_NF,
1949273SAli.Bahrami@Sun.COM 		MSG_EM_VPP500_NF,	MSG_EM_SPARC32PLUS_NF,
1959273SAli.Bahrami@Sun.COM 		MSG_EM_960_NF,		MSG_EM_PPC_NF,
1969273SAli.Bahrami@Sun.COM 		MSG_EM_PPC64_NF,	MSG_EM_S390_NF
1979273SAli.Bahrami@Sun.COM 	};
1989273SAli.Bahrami@Sun.COM 	static const Msg mach_15_22_dmp[] = {
1999273SAli.Bahrami@Sun.COM 		MSG_EM_PA_RISC_DMP,	MSG_EM_NCUBE_DMP,
2009273SAli.Bahrami@Sun.COM 		MSG_EM_VPP500_DMP,	MSG_EM_SPARC32PLUS_DMP,
2019273SAli.Bahrami@Sun.COM 		MSG_EM_960_CF,		MSG_EM_PPC_DMP,
2029273SAli.Bahrami@Sun.COM 		MSG_EM_PPC64_DMP,	MSG_EM_S390_CF
2039273SAli.Bahrami@Sun.COM 	};
2049273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_15_22_cf = {
2059273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_cf) };
2069273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_15_22_nf = {
2079273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_nf) };
2089273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_15_22_dmp = {
2099273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_dmp) };
2109273SAli.Bahrami@Sun.COM 
2119273SAli.Bahrami@Sun.COM 
2129273SAli.Bahrami@Sun.COM 	static const Msg mach_36_63_cf[] = {
2139273SAli.Bahrami@Sun.COM 		MSG_EM_V800_CF,		MSG_EM_FR20_CF,
2149273SAli.Bahrami@Sun.COM 		MSG_EM_RH32_CF,		MSG_EM_RCE_CF,
2159273SAli.Bahrami@Sun.COM 		MSG_EM_ARM_CF,		MSG_EM_ALPHA_CF,
2169273SAli.Bahrami@Sun.COM 		MSG_EM_SH_CF,		MSG_EM_SPARCV9_CF,
2179273SAli.Bahrami@Sun.COM 		MSG_EM_TRICORE_CF,	MSG_EM_ARC_CF,
2189273SAli.Bahrami@Sun.COM 		MSG_EM_H8_300_CF,	MSG_EM_H8_300H_CF,
2199273SAli.Bahrami@Sun.COM 		MSG_EM_H8S_CF,		MSG_EM_H8_500_CF,
2209273SAli.Bahrami@Sun.COM 		MSG_EM_IA_64_CF,	MSG_EM_MIPS_X_CF,
2219273SAli.Bahrami@Sun.COM 		MSG_EM_COLDFIRE_CF,	MSG_EM_68HC12_CF,
2229273SAli.Bahrami@Sun.COM 		MSG_EM_MMA_CF,		MSG_EM_PCP_CF,
2239273SAli.Bahrami@Sun.COM 		MSG_EM_NCPU_CF,		MSG_EM_NDR1_CF,
2249273SAli.Bahrami@Sun.COM 		MSG_EM_STARCORE_CF,	MSG_EM_ME16_CF,
2259273SAli.Bahrami@Sun.COM 		MSG_EM_ST100_CF,	MSG_EM_TINYJ_CF,
2269273SAli.Bahrami@Sun.COM 		MSG_EM_AMD64_CF,	MSG_EM_PDSP_CF
2279273SAli.Bahrami@Sun.COM 	};
2289273SAli.Bahrami@Sun.COM 	static const Msg mach_36_63_nf[] = {
2299273SAli.Bahrami@Sun.COM 		MSG_EM_V800_NF,		MSG_EM_FR20_NF,
2309273SAli.Bahrami@Sun.COM 		MSG_EM_RH32_NF,		MSG_EM_RCE_NF,
2319273SAli.Bahrami@Sun.COM 		MSG_EM_ARM_NF,		MSG_EM_ALPHA_NF,
2329273SAli.Bahrami@Sun.COM 		MSG_EM_SH_NF,		MSG_EM_SPARCV9_NF,
2339273SAli.Bahrami@Sun.COM 		MSG_EM_TRICORE_NF,	MSG_EM_ARC_NF,
2349273SAli.Bahrami@Sun.COM 		MSG_EM_H8_300_NF,	MSG_EM_H8_300H_NF,
2359273SAli.Bahrami@Sun.COM 		MSG_EM_H8S_NF,		MSG_EM_H8_500_NF,
2369273SAli.Bahrami@Sun.COM 		MSG_EM_IA_64_NF,	MSG_EM_MIPS_X_NF,
2379273SAli.Bahrami@Sun.COM 		MSG_EM_COLDFIRE_NF,	MSG_EM_68HC12_NF,
2389273SAli.Bahrami@Sun.COM 		MSG_EM_MMA_NF,		MSG_EM_PCP_NF,
2399273SAli.Bahrami@Sun.COM 		MSG_EM_NCPU_NF,		MSG_EM_NDR1_NF,
2409273SAli.Bahrami@Sun.COM 		MSG_EM_STARCORE_NF,	MSG_EM_ME16_NF,
2419273SAli.Bahrami@Sun.COM 		MSG_EM_ST100_NF,	MSG_EM_TINYJ_NF,
2429273SAli.Bahrami@Sun.COM 		MSG_EM_AMD64_NF,	MSG_EM_PDSP_NF
2439273SAli.Bahrami@Sun.COM 	};
2449273SAli.Bahrami@Sun.COM 	static const Msg mach_36_63_dmp[] = {
2459273SAli.Bahrami@Sun.COM 		MSG_EM_V800_CF,		MSG_EM_FR20_CF,
2469273SAli.Bahrami@Sun.COM 		MSG_EM_RH32_CF,		MSG_EM_RCE_CF,
2479273SAli.Bahrami@Sun.COM 		MSG_EM_ARM_DMP,		MSG_EM_ALPHA_DMP,
2489273SAli.Bahrami@Sun.COM 		MSG_EM_SH_CF,		MSG_EM_SPARCV9_DMP,
2499273SAli.Bahrami@Sun.COM 		MSG_EM_TRICORE_CF,	MSG_EM_ARC_CF,
2509273SAli.Bahrami@Sun.COM 		MSG_EM_H8_300_CF,	MSG_EM_H8_300H_CF,
2519273SAli.Bahrami@Sun.COM 		MSG_EM_H8S_CF,		MSG_EM_H8_500_CF,
2529273SAli.Bahrami@Sun.COM 		MSG_EM_IA_64_DMP,	MSG_EM_MIPS_X_CF,
2539273SAli.Bahrami@Sun.COM 		MSG_EM_COLDFIRE_CF,	MSG_EM_68HC12_CF,
2549273SAli.Bahrami@Sun.COM 		MSG_EM_MMA_CF,		MSG_EM_PCP_CF,
2559273SAli.Bahrami@Sun.COM 		MSG_EM_NCPU_CF,		MSG_EM_NDR1_CF,
2569273SAli.Bahrami@Sun.COM 		MSG_EM_STARCORE_CF,	MSG_EM_ME16_CF,
2579273SAli.Bahrami@Sun.COM 		MSG_EM_ST100_CF,	MSG_EM_TINYJ_CF,
2589273SAli.Bahrami@Sun.COM 		MSG_EM_AMD64_DMP,	MSG_EM_PDSP_CF
2599273SAli.Bahrami@Sun.COM 	};
2609273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_36_63_cf = {
2619273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_V800, mach_36_63_cf) };
2629273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_36_63_nf = {
2639273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_V800, mach_36_63_nf) };
2649273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_36_63_dmp = {
2659273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_V800, mach_36_63_dmp) };
2669273SAli.Bahrami@Sun.COM 
2679273SAli.Bahrami@Sun.COM 
2689273SAli.Bahrami@Sun.COM 	static const Msg mach_66_94_cf[] = {
2699273SAli.Bahrami@Sun.COM 		MSG_EM_FX66_CF,		MSG_EM_ST9PLUS_CF,
2709273SAli.Bahrami@Sun.COM 		MSG_EM_ST7_CF,		MSG_EM_68HC16_CF,
2719273SAli.Bahrami@Sun.COM 		MSG_EM_68HC11_CF,	MSG_EM_68HC08_CF,
2729273SAli.Bahrami@Sun.COM 		MSG_EM_68HC05_CF,	MSG_EM_SVX_CF,
2739273SAli.Bahrami@Sun.COM 		MSG_EM_ST19_CF,		MSG_EM_VAX_CF,
2749273SAli.Bahrami@Sun.COM 		MSG_EM_CRIS_CF,		MSG_EM_JAVELIN_CF,
2759273SAli.Bahrami@Sun.COM 		MSG_EM_FIREPATH_CF,	MSG_EM_ZSP_CF,
2769273SAli.Bahrami@Sun.COM 		MSG_EM_MMIX_CF,		MSG_EM_HUANY_CF,
2779273SAli.Bahrami@Sun.COM 		MSG_EM_PRISM_CF,	MSG_EM_AVR_CF,
2789273SAli.Bahrami@Sun.COM 		MSG_EM_FR30_CF,		MSG_EM_D10V_CF,
2799273SAli.Bahrami@Sun.COM 		MSG_EM_D30V_CF,		MSG_EM_V850_CF,
2809273SAli.Bahrami@Sun.COM 		MSG_EM_M32R_CF,		MSG_EM_MN10300_CF,
2819273SAli.Bahrami@Sun.COM 		MSG_EM_MN10200_CF,	MSG_EM_PJ_CF,
2829273SAli.Bahrami@Sun.COM 		MSG_EM_OPENRISC_CF,	MSG_EM_ARC_A5_CF,
2839273SAli.Bahrami@Sun.COM 		MSG_EM_XTENSA_CF
2849273SAli.Bahrami@Sun.COM 	};
2859273SAli.Bahrami@Sun.COM 	static const Msg mach_66_94_nf[] = {
2869273SAli.Bahrami@Sun.COM 		MSG_EM_FX66_NF,		MSG_EM_ST9PLUS_NF,
2879273SAli.Bahrami@Sun.COM 		MSG_EM_ST7_NF,		MSG_EM_68HC16_NF,
2889273SAli.Bahrami@Sun.COM 		MSG_EM_68HC11_NF,	MSG_EM_68HC08_NF,
2899273SAli.Bahrami@Sun.COM 		MSG_EM_68HC05_NF,	MSG_EM_SVX_NF,
2909273SAli.Bahrami@Sun.COM 		MSG_EM_ST19_NF,		MSG_EM_VAX_NF,
2919273SAli.Bahrami@Sun.COM 		MSG_EM_CRIS_NF,		MSG_EM_JAVELIN_NF,
2929273SAli.Bahrami@Sun.COM 		MSG_EM_FIREPATH_NF,	MSG_EM_ZSP_NF,
2939273SAli.Bahrami@Sun.COM 		MSG_EM_MMIX_NF,		MSG_EM_HUANY_NF,
2949273SAli.Bahrami@Sun.COM 		MSG_EM_PRISM_NF,	MSG_EM_AVR_NF,
2959273SAli.Bahrami@Sun.COM 		MSG_EM_FR30_NF,		MSG_EM_D10V_NF,
2969273SAli.Bahrami@Sun.COM 		MSG_EM_D30V_NF,		MSG_EM_V850_NF,
2979273SAli.Bahrami@Sun.COM 		MSG_EM_M32R_NF,		MSG_EM_MN10300_NF,
2989273SAli.Bahrami@Sun.COM 		MSG_EM_MN10200_NF,	MSG_EM_PJ_NF,
2999273SAli.Bahrami@Sun.COM 		MSG_EM_OPENRISC_NF,	MSG_EM_ARC_A5_NF,
3009273SAli.Bahrami@Sun.COM 		MSG_EM_XTENSA_NF
3019273SAli.Bahrami@Sun.COM 	};
3029273SAli.Bahrami@Sun.COM 	static const Msg mach_66_94_dmp[] = {
3039273SAli.Bahrami@Sun.COM 		MSG_EM_FX66_CF,		MSG_EM_ST9PLUS_CF,
3049273SAli.Bahrami@Sun.COM 		MSG_EM_ST7_CF,		MSG_EM_68HC16_CF,
3059273SAli.Bahrami@Sun.COM 		MSG_EM_68HC11_CF,	MSG_EM_68HC08_CF,
3069273SAli.Bahrami@Sun.COM 		MSG_EM_68HC05_CF,	MSG_EM_SVX_CF,
3079273SAli.Bahrami@Sun.COM 		MSG_EM_ST19_CF,		MSG_EM_VAX_DMP,
3089273SAli.Bahrami@Sun.COM 		MSG_EM_CRIS_CF,		MSG_EM_JAVELIN_CF,
3099273SAli.Bahrami@Sun.COM 		MSG_EM_FIREPATH_CF,	MSG_EM_ZSP_CF,
3109273SAli.Bahrami@Sun.COM 		MSG_EM_MMIX_CF,		MSG_EM_HUANY_CF,
3119273SAli.Bahrami@Sun.COM 		MSG_EM_PRISM_CF,	MSG_EM_AVR_CF,
3129273SAli.Bahrami@Sun.COM 		MSG_EM_FR30_CF,		MSG_EM_D10V_CF,
3139273SAli.Bahrami@Sun.COM 		MSG_EM_D30V_CF,		MSG_EM_V850_CF,
3149273SAli.Bahrami@Sun.COM 		MSG_EM_M32R_CF,		MSG_EM_MN10300_CF,
3159273SAli.Bahrami@Sun.COM 		MSG_EM_MN10200_CF,	MSG_EM_PJ_CF,
3169273SAli.Bahrami@Sun.COM 		MSG_EM_OPENRISC_CF,	MSG_EM_ARC_A5_CF,
3179273SAli.Bahrami@Sun.COM 		MSG_EM_XTENSA_CF
3189273SAli.Bahrami@Sun.COM 	};
3190Sstevel@tonic-gate #if	(EM_NUM != (EM_XTENSA + 1))
3200Sstevel@tonic-gate #error	"EM_NUM has grown"
3210Sstevel@tonic-gate #endif
3229273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_66_94_cf = {
3239273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_FX66, mach_66_94_cf) };
3249273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_66_94_nf = {
3259273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_FX66, mach_66_94_nf) };
3269273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mach_66_94_dmp = {
3279273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(EM_FX66, mach_66_94_dmp) };
3289273SAli.Bahrami@Sun.COM 
3299273SAli.Bahrami@Sun.COM 
3309273SAli.Bahrami@Sun.COM 	/* Build NULL terminated return arrays for each string style */
3319273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_cf[] = {
3329273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_0_11_cf), CONV_DS_ADDR(ds_mach_15_22_cf),
3339273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_36_63_cf), CONV_DS_ADDR(ds_mach_66_94_cf),
3349273SAli.Bahrami@Sun.COM 		NULL
3359273SAli.Bahrami@Sun.COM 	};
3369273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_nf[] = {
3379273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_0_11_nf), CONV_DS_ADDR(ds_mach_15_22_nf),
3389273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_36_63_nf), CONV_DS_ADDR(ds_mach_66_94_nf),
3399273SAli.Bahrami@Sun.COM 		NULL
3409273SAli.Bahrami@Sun.COM 	};
3419273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_dmp[] = {
3429273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_0_11_dmp), CONV_DS_ADDR(ds_mach_15_22_dmp),
3439273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_36_63_dmp),
3449273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_mach_66_94_dmp), NULL
3459273SAli.Bahrami@Sun.COM 	};
3469273SAli.Bahrami@Sun.COM 
3479273SAli.Bahrami@Sun.COM 
3489273SAli.Bahrami@Sun.COM 	/* Select the strings to use */
3499273SAli.Bahrami@Sun.COM 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
3509273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_DUMP:
3519273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_FILE:
3529273SAli.Bahrami@Sun.COM 		return (ds_dmp);
3539273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
3549273SAli.Bahrami@Sun.COM 		return (ds_nf);
3559273SAli.Bahrami@Sun.COM 	}
3569273SAli.Bahrami@Sun.COM 
3579273SAli.Bahrami@Sun.COM 	return (ds_cf);
3589273SAli.Bahrami@Sun.COM }
3591618Srie 
3601618Srie const char *
conv_ehdr_mach(Half machine,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)3615088Sab196087 conv_ehdr_mach(Half machine, Conv_fmt_flags_t fmt_flags,
3625088Sab196087     Conv_inv_buf_t *inv_buf)
3631618Srie {
3649273SAli.Bahrami@Sun.COM 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, machine,
3659273SAli.Bahrami@Sun.COM 	    ehdr_mach_strings(fmt_flags), fmt_flags, inv_buf));
3669273SAli.Bahrami@Sun.COM }
3675088Sab196087 
3689273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_mach(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)3699273SAli.Bahrami@Sun.COM conv_iter_ehdr_mach(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
3709273SAli.Bahrami@Sun.COM     void *uvalue)
3719273SAli.Bahrami@Sun.COM {
3729273SAli.Bahrami@Sun.COM 	static const Val_desc extra_dmp_nf[] = {
3739273SAli.Bahrami@Sun.COM 		{ EM_M32,		MSG_EM_M32_DMP},
3749273SAli.Bahrami@Sun.COM 		{ EM_386,		MSG_EM_386_DMP },
3759273SAli.Bahrami@Sun.COM 		{ EM_68K,		MSG_EM_68K_DMP },
3769273SAli.Bahrami@Sun.COM 		{ EM_88K,		MSG_EM_88K_DMP },
3779273SAli.Bahrami@Sun.COM 		{ EM_486,		MSG_EM_486_DMP },
3789273SAli.Bahrami@Sun.COM 		{ EM_860,		MSG_EM_860_DMP },
3799273SAli.Bahrami@Sun.COM 		{ EM_MIPS,		MSG_EM_MIPS_DMP },
3809273SAli.Bahrami@Sun.COM 		{ EM_MIPS_RS3_LE,	MSG_EM_MIPS_RS3_LE_DMP },
3819273SAli.Bahrami@Sun.COM 		{ EM_PPC,		MSG_EM_PPC_DMP },
3829273SAli.Bahrami@Sun.COM 		{ EM_PPC64,		MSG_EM_PPC64_DMP },
3839273SAli.Bahrami@Sun.COM 
3849273SAli.Bahrami@Sun.COM 		{ 0 }
3859273SAli.Bahrami@Sun.COM 	};
3869273SAli.Bahrami@Sun.COM 
3879273SAli.Bahrami@Sun.COM 	if (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
3889273SAli.Bahrami@Sun.COM 	    ehdr_mach_strings(fmt_flags), func, uvalue) == CONV_ITER_DONE)
3899273SAli.Bahrami@Sun.COM 		return (CONV_ITER_DONE);
3909273SAli.Bahrami@Sun.COM 
3919273SAli.Bahrami@Sun.COM 	/*
3929273SAli.Bahrami@Sun.COM 	 * For the NF style, we also supply a few of the traditional
3939273SAli.Bahrami@Sun.COM 	 * dump versions for iteration, but not for display.
3949273SAli.Bahrami@Sun.COM 	 */
3959273SAli.Bahrami@Sun.COM 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF)
3969273SAli.Bahrami@Sun.COM 		return (conv_iter_vd(extra_dmp_nf, func, uvalue));
3979273SAli.Bahrami@Sun.COM 
3989273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate 
4011976Sab196087 
4029273SAli.Bahrami@Sun.COM 
4039273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_eident_strings(Conv_fmt_flags_t fmt_flags)4049273SAli.Bahrami@Sun.COM ehdr_eident_strings(Conv_fmt_flags_t fmt_flags)
4050Sstevel@tonic-gate {
4069273SAli.Bahrami@Sun.COM 	static const Msg	eident_cf[] = {
4079273SAli.Bahrami@Sun.COM 		MSG_EI_MAG0_CF,		MSG_EI_MAG1_CF,
4089273SAli.Bahrami@Sun.COM 		MSG_EI_MAG2_CF,		MSG_EI_MAG3_CF,
4099273SAli.Bahrami@Sun.COM 		MSG_EI_CLASS_CF,	MSG_EI_DATA_CF,
4109273SAli.Bahrami@Sun.COM 		MSG_EI_VERSION_CF,	MSG_EI_OSABI_CF,
4119273SAli.Bahrami@Sun.COM 		MSG_EI_ABIVERSION_CF
4129273SAli.Bahrami@Sun.COM 	};
4139273SAli.Bahrami@Sun.COM 	static const Msg	eident_nf[] = {
4149273SAli.Bahrami@Sun.COM 		MSG_EI_MAG0_NF,		MSG_EI_MAG1_NF,
4159273SAli.Bahrami@Sun.COM 		MSG_EI_MAG2_NF,		MSG_EI_MAG3_NF,
4169273SAli.Bahrami@Sun.COM 		MSG_EI_CLASS_NF,	MSG_EI_DATA_NF,
4179273SAli.Bahrami@Sun.COM 		MSG_EI_VERSION_NF,	MSG_EI_OSABI_NF,
4189273SAli.Bahrami@Sun.COM 		MSG_EI_ABIVERSION_NF
4199273SAli.Bahrami@Sun.COM 	};
4209273SAli.Bahrami@Sun.COM #if EI_PAD != (EI_ABIVERSION + 1)
4219273SAli.Bahrami@Sun.COM error "EI_PAD has grown. Update etypes[]"
4229273SAli.Bahrami@Sun.COM #endif
4239273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_eident_cf = {
4249273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EI_MAG0, eident_cf) };
4259273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_eident_nf = {
4269273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EI_MAG0, eident_nf) };
4279273SAli.Bahrami@Sun.COM 
4289273SAli.Bahrami@Sun.COM 	/* Build NULL terminated return arrays for each string style */
4299273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_cf[] = {
4309273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_eident_cf), NULL };
4319273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_nf[] = {
4329273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_eident_nf), NULL };
4339273SAli.Bahrami@Sun.COM 
4349273SAli.Bahrami@Sun.COM 	/* Select the strings to use */
4359273SAli.Bahrami@Sun.COM 	return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CF) ?
4369273SAli.Bahrami@Sun.COM 	    ds_cf : ds_nf);
4379273SAli.Bahrami@Sun.COM }
4389273SAli.Bahrami@Sun.COM 
4399273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_eident(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)4409273SAli.Bahrami@Sun.COM conv_iter_ehdr_eident(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
4419273SAli.Bahrami@Sun.COM     void *uvalue)
4429273SAli.Bahrami@Sun.COM {
4439273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
4449273SAli.Bahrami@Sun.COM 	    ehdr_eident_strings(fmt_flags), func, uvalue));
4459273SAli.Bahrami@Sun.COM }
4469273SAli.Bahrami@Sun.COM 
4479273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_type_strings(Conv_fmt_flags_t fmt_flags)4489273SAli.Bahrami@Sun.COM ehdr_type_strings(Conv_fmt_flags_t fmt_flags)
4499273SAli.Bahrami@Sun.COM {
4509273SAli.Bahrami@Sun.COM #define	SOL	ELFOSABI_SOLARIS, EM_NONE
4519273SAli.Bahrami@Sun.COM 
4529273SAli.Bahrami@Sun.COM 	static const Msg	type_cf[] = {
4539273SAli.Bahrami@Sun.COM 		MSG_ET_NONE_CF,		MSG_ET_REL_CF,		MSG_ET_EXEC_CF,
4549273SAli.Bahrami@Sun.COM 		MSG_ET_DYN_CF,		MSG_ET_CORE_CF
4551618Srie 	};
4569273SAli.Bahrami@Sun.COM 	static const Msg	type_nf[] = {
4579273SAli.Bahrami@Sun.COM 		MSG_ET_NONE_NF,		MSG_ET_REL_NF,		MSG_ET_EXEC_NF,
4589273SAli.Bahrami@Sun.COM 		MSG_ET_DYN_NF,		MSG_ET_CORE_NF
4599273SAli.Bahrami@Sun.COM 	};
4609273SAli.Bahrami@Sun.COM 	static const Msg	type_dmp[] = {
4619273SAli.Bahrami@Sun.COM 		MSG_ET_NONE_DMP,	MSG_ET_REL_DMP,		MSG_ET_EXEC_DMP,
4629273SAli.Bahrami@Sun.COM 		MSG_ET_DYN_DMP,		MSG_ET_CORE_DMP
4631976Sab196087 	};
4649273SAli.Bahrami@Sun.COM #if ET_NUM != (ET_CORE + 1)
4659273SAli.Bahrami@Sun.COM error "ET_NUM has grown. Update types[]"
4669273SAli.Bahrami@Sun.COM #endif
4679273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_type_cf = {
4689273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(ET_NONE, type_cf) };
4699273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_type_nf = {
4709273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(ET_NONE, type_nf) };
4719273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_type_dmp = {
4729273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(ET_NONE, type_dmp) };
4730Sstevel@tonic-gate 
4749273SAli.Bahrami@Sun.COM 	static const Val_desc2 type_osabi_cf[] = {
4759273SAli.Bahrami@Sun.COM 		{ ET_SUNWPSEUDO,	SOL,	MSG_ET_SUNWPSEUDO_CF },
4769273SAli.Bahrami@Sun.COM 		{ 0 }
4779273SAli.Bahrami@Sun.COM 	};
4789273SAli.Bahrami@Sun.COM 	static const Val_desc2 type_osabi_nf[] = {
4799273SAli.Bahrami@Sun.COM 		{ ET_SUNWPSEUDO,	SOL,	MSG_ET_SUNWPSEUDO_NF },
4809273SAli.Bahrami@Sun.COM 		{ 0 }
4819273SAli.Bahrami@Sun.COM 	};
4829273SAli.Bahrami@Sun.COM 	static const Val_desc2 type_osabi_dmp[] = {
4839273SAli.Bahrami@Sun.COM 		{ ET_SUNWPSEUDO,	SOL,	MSG_ET_SUNWPSEUDO_DMP },
4849273SAli.Bahrami@Sun.COM 		{ 0 }
4859273SAli.Bahrami@Sun.COM 	};
4869273SAli.Bahrami@Sun.COM #if ET_LOSUNW != ET_SUNWPSEUDO
4879273SAli.Bahrami@Sun.COM error "ET_LOSUNW has grown. Update type_osabi[]"
4889273SAli.Bahrami@Sun.COM #endif
4899273SAli.Bahrami@Sun.COM 	static const conv_ds_vd2_t ds_type_osabi_cf = {
4909273SAli.Bahrami@Sun.COM 	    CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_cf };
4919273SAli.Bahrami@Sun.COM 	static const conv_ds_vd2_t ds_type_osabi_nf = {
4929273SAli.Bahrami@Sun.COM 	    CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_nf };
4939273SAli.Bahrami@Sun.COM 	static const conv_ds_vd2_t ds_type_osabi_dmp = {
4949273SAli.Bahrami@Sun.COM 	    CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_dmp };
4959273SAli.Bahrami@Sun.COM 
4969273SAli.Bahrami@Sun.COM 
4979273SAli.Bahrami@Sun.COM 	/* Build NULL terminated return arrays for each string style */
4989273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_cf[] = {
4999273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_type_cf), CONV_DS_ADDR(ds_type_osabi_cf),
5009273SAli.Bahrami@Sun.COM 		NULL };
5019273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_nf[] = {
5029273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_type_nf), CONV_DS_ADDR(ds_type_osabi_nf),
5039273SAli.Bahrami@Sun.COM 		NULL };
5049273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_dmp[] = {
5059273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_type_dmp), CONV_DS_ADDR(ds_type_osabi_dmp),
5069273SAli.Bahrami@Sun.COM 		NULL };
5079273SAli.Bahrami@Sun.COM 
5089273SAli.Bahrami@Sun.COM 	/* Select the strings to use */
5099273SAli.Bahrami@Sun.COM 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
5109273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_DUMP:
5119273SAli.Bahrami@Sun.COM 		return (ds_dmp);
5129273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
5139273SAli.Bahrami@Sun.COM 		return (ds_nf);
5141976Sab196087 	}
5151976Sab196087 
5169273SAli.Bahrami@Sun.COM 	return (ds_cf);
5179273SAli.Bahrami@Sun.COM 
5189273SAli.Bahrami@Sun.COM #undef SOL
5199273SAli.Bahrami@Sun.COM }
5209273SAli.Bahrami@Sun.COM 
5219273SAli.Bahrami@Sun.COM const char *
conv_ehdr_type(uchar_t osabi,Half etype,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)5229273SAli.Bahrami@Sun.COM conv_ehdr_type(uchar_t osabi, Half etype, Conv_fmt_flags_t fmt_flags,
5239273SAli.Bahrami@Sun.COM     Conv_inv_buf_t *inv_buf)
5249273SAli.Bahrami@Sun.COM {
5259273SAli.Bahrami@Sun.COM 	return (conv_map_ds(osabi, EM_NONE, etype,
5269273SAli.Bahrami@Sun.COM 	    ehdr_type_strings(fmt_flags), fmt_flags, inv_buf));
5279273SAli.Bahrami@Sun.COM }
5289273SAli.Bahrami@Sun.COM 
5299273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_type(conv_iter_osabi_t osabi,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)5309273SAli.Bahrami@Sun.COM conv_iter_ehdr_type(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
5319273SAli.Bahrami@Sun.COM     conv_iter_cb_t func, void *uvalue)
5329273SAli.Bahrami@Sun.COM {
5339273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(osabi, EM_NONE,
5349273SAli.Bahrami@Sun.COM 	    ehdr_type_strings(fmt_flags), func, uvalue));
5359273SAli.Bahrami@Sun.COM }
5369273SAli.Bahrami@Sun.COM 
5379273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_vers_strings(Conv_fmt_flags_t fmt_flags)5389273SAli.Bahrami@Sun.COM ehdr_vers_strings(Conv_fmt_flags_t fmt_flags)
5399273SAli.Bahrami@Sun.COM {
5409273SAli.Bahrami@Sun.COM 	static const Msg	versions_cf[] = {
5419273SAli.Bahrami@Sun.COM 		MSG_EV_NONE_CF,		MSG_EV_CURRENT_CF
5429273SAli.Bahrami@Sun.COM 	};
5439273SAli.Bahrami@Sun.COM 	static const Msg	versions_nf[] = {
5449273SAli.Bahrami@Sun.COM 		MSG_EV_NONE_NF,		MSG_EV_CURRENT_NF
5459273SAli.Bahrami@Sun.COM 	};
5469273SAli.Bahrami@Sun.COM 	static const Msg	versions_dmp[] = {
5479273SAli.Bahrami@Sun.COM 		MSG_EV_NONE_DMP,	MSG_EV_CURRENT_DMP
5489273SAli.Bahrami@Sun.COM 	};
5499273SAli.Bahrami@Sun.COM #if EV_NUM != 2
5509273SAli.Bahrami@Sun.COM error "EV_NUM has grown. Update versions[]"
5519273SAli.Bahrami@Sun.COM #endif
5529273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_versions_cf = {
5539273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EV_NONE, versions_cf) };
5549273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_versions_nf = {
5559273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EV_NONE, versions_nf) };
5569273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_versions_dmp = {
5579273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EV_NONE, versions_dmp) };
5589273SAli.Bahrami@Sun.COM 
5599273SAli.Bahrami@Sun.COM 	/* Build NULL terminated return arrays for each string style */
5609273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_cf[] = {
5619273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_versions_cf), NULL };
5629273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_nf[] = {
5639273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_versions_nf), NULL };
5649273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_dmp[] = {
5659273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_versions_dmp), NULL };
5669273SAli.Bahrami@Sun.COM 
5679273SAli.Bahrami@Sun.COM 	/* Select the strings to use */
5685088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
5695088Sab196087 	case CONV_FMT_ALT_DUMP:
5709273SAli.Bahrami@Sun.COM 		return (ds_dmp);
5719273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
5729273SAli.Bahrami@Sun.COM 		return (ds_nf);
5735088Sab196087 	}
5745088Sab196087 
5759273SAli.Bahrami@Sun.COM 	return (ds_cf);
5760Sstevel@tonic-gate }
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate const char *
conv_ehdr_vers(Word version,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)5795088Sab196087 conv_ehdr_vers(Word version, Conv_fmt_flags_t fmt_flags,
5805088Sab196087     Conv_inv_buf_t *inv_buf)
5810Sstevel@tonic-gate {
5829273SAli.Bahrami@Sun.COM 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, version,
5839273SAli.Bahrami@Sun.COM 	    ehdr_vers_strings(fmt_flags), fmt_flags, inv_buf));
5849273SAli.Bahrami@Sun.COM }
5850Sstevel@tonic-gate 
5869273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_vers(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)5879273SAli.Bahrami@Sun.COM conv_iter_ehdr_vers(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
5889273SAli.Bahrami@Sun.COM     void *uvalue)
5899273SAli.Bahrami@Sun.COM {
5909273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
5919273SAli.Bahrami@Sun.COM 	    ehdr_vers_strings(fmt_flags), func, uvalue));
5920Sstevel@tonic-gate }
5930Sstevel@tonic-gate 
5949273SAli.Bahrami@Sun.COM static void
conv_ehdr_sparc_flags_strings(Conv_fmt_flags_t fmt_flags,const conv_ds_msg_t ** mm_msg,const Val_desc ** flag_desc)5959273SAli.Bahrami@Sun.COM conv_ehdr_sparc_flags_strings(Conv_fmt_flags_t fmt_flags,
5969273SAli.Bahrami@Sun.COM     const conv_ds_msg_t **mm_msg, const Val_desc **flag_desc)
5979273SAli.Bahrami@Sun.COM {
5982352Sab196087 #define	EFLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
5999273SAli.Bahrami@Sun.COM 	MSG_EF_SPARCV9_TSO_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
6009273SAli.Bahrami@Sun.COM 	MSG_EF_SPARC_SUN_US1_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
6019273SAli.Bahrami@Sun.COM 	MSG_EF_SPARC_HAL_R1_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
6029273SAli.Bahrami@Sun.COM 	MSG_EF_SPARC_SUN_US3_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
6039273SAli.Bahrami@Sun.COM 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
6044734Sab196087 
6059273SAli.Bahrami@Sun.COM 	/*
6069273SAli.Bahrami@Sun.COM 	 * Ensure that Conv_ehdr_flags_buf_t is large enough:
6079273SAli.Bahrami@Sun.COM 	 *
6089273SAli.Bahrami@Sun.COM 	 * EFLAGSZ is the real minimum size of the buffer required by
6099273SAli.Bahrami@Sun.COM 	 * conv_ehdr_flags(). However, Conv_ehdr_flags_buf_t uses
6109273SAli.Bahrami@Sun.COM 	 * CONV_EHDR_FLAG_BUFSIZE to set the buffer size. We do things
6119273SAli.Bahrami@Sun.COM 	 * this way because the definition of EFLAGSZ uses information
6129273SAli.Bahrami@Sun.COM 	 * that is not available in the environment of other programs
6139273SAli.Bahrami@Sun.COM 	 * that include the conv.h header file.
6149273SAli.Bahrami@Sun.COM 	 */
6155152Sab196087 #if (CONV_EHDR_FLAGS_BUFSIZE != EFLAGSZ) && !defined(__lint)
6165152Sab196087 #define	REPORT_BUFSIZE EFLAGSZ
6175152Sab196087 #include "report_bufsize.h"
6185152Sab196087 #error "CONV_EHDR_FLAGS_BUFSIZE does not match EFLAGSZ"
6194734Sab196087 #endif
6200Sstevel@tonic-gate 
6219273SAli.Bahrami@Sun.COM 	static const Msg mm_flags_cf[] = {
6229273SAli.Bahrami@Sun.COM 		MSG_EF_SPARCV9_TSO_CF,	MSG_EF_SPARCV9_PSO_CF,
6239273SAli.Bahrami@Sun.COM 		MSG_EF_SPARCV9_RMO_CF
6249273SAli.Bahrami@Sun.COM 	};
6259273SAli.Bahrami@Sun.COM 	static const Msg mm_flags_nf[] = {
6269273SAli.Bahrami@Sun.COM 		MSG_EF_SPARCV9_TSO_NF,	MSG_EF_SPARCV9_PSO_NF,
6279273SAli.Bahrami@Sun.COM 		MSG_EF_SPARCV9_RMO_NF
6289273SAli.Bahrami@Sun.COM 	};
6299273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mm_flags_cf = {
6309273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EF_SPARCV9_TSO, mm_flags_cf) };
6319273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_mm_flags_nf = {
6329273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EF_SPARCV9_TSO, mm_flags_nf) };
6339273SAli.Bahrami@Sun.COM 
6349273SAli.Bahrami@Sun.COM 
6359273SAli.Bahrami@Sun.COM 	static const Val_desc vda_cf[] = {
6369273SAli.Bahrami@Sun.COM 		{ EF_SPARC_32PLUS,	MSG_EF_SPARC_32PLUS_CF },
6379273SAli.Bahrami@Sun.COM 		{ EF_SPARC_SUN_US1,	MSG_EF_SPARC_SUN_US1_CF },
6389273SAli.Bahrami@Sun.COM 		{ EF_SPARC_HAL_R1,	MSG_EF_SPARC_HAL_R1_CF },
6399273SAli.Bahrami@Sun.COM 		{ EF_SPARC_SUN_US3,	MSG_EF_SPARC_SUN_US3_CF },
6409273SAli.Bahrami@Sun.COM 		{ 0 }
6419273SAli.Bahrami@Sun.COM 	};
6429273SAli.Bahrami@Sun.COM 	static const Val_desc vda_nf[] = {
6439273SAli.Bahrami@Sun.COM 		{ EF_SPARC_32PLUS,	MSG_EF_SPARC_32PLUS_NF },
6449273SAli.Bahrami@Sun.COM 		{ EF_SPARC_SUN_US1,	MSG_EF_SPARC_SUN_US1_NF },
6459273SAli.Bahrami@Sun.COM 		{ EF_SPARC_HAL_R1,	MSG_EF_SPARC_HAL_R1_NF },
6469273SAli.Bahrami@Sun.COM 		{ EF_SPARC_SUN_US3,	MSG_EF_SPARC_SUN_US3_NF },
6479273SAli.Bahrami@Sun.COM 		{ 0 }
6489273SAli.Bahrami@Sun.COM 	};
6499273SAli.Bahrami@Sun.COM 
6509273SAli.Bahrami@Sun.COM 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
6519273SAli.Bahrami@Sun.COM 	default:
6529273SAli.Bahrami@Sun.COM 		*mm_msg = &ds_mm_flags_cf;
6539273SAli.Bahrami@Sun.COM 		*flag_desc = vda_cf;
6549273SAli.Bahrami@Sun.COM 		break;
6559273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
6569273SAli.Bahrami@Sun.COM 		*mm_msg = &ds_mm_flags_nf;
6579273SAli.Bahrami@Sun.COM 		*flag_desc = vda_nf;
6589273SAli.Bahrami@Sun.COM 		break;
6599273SAli.Bahrami@Sun.COM 	}
6609273SAli.Bahrami@Sun.COM }
6619273SAli.Bahrami@Sun.COM 
6620Sstevel@tonic-gate /*
6631618Srie  * Make a string representation of the e_flags field.
6640Sstevel@tonic-gate  */
6650Sstevel@tonic-gate const char *
conv_ehdr_flags(Half mach,Word flags,Conv_fmt_flags_t fmt_flags,Conv_ehdr_flags_buf_t * flags_buf)6665088Sab196087 conv_ehdr_flags(Half mach, Word flags, Conv_fmt_flags_t fmt_flags,
6675088Sab196087     Conv_ehdr_flags_buf_t *flags_buf)
6680Sstevel@tonic-gate {
6692352Sab196087 	static const char *leading_str_arr[2];
6704734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
6719273SAli.Bahrami@Sun.COM 	    NULL, sizeof (flags_buf->buf), leading_str_arr };
6722352Sab196087 
6739273SAli.Bahrami@Sun.COM 	const char **lstr;
6749273SAli.Bahrami@Sun.COM 	const conv_ds_msg_t	*mm_msg;
6759273SAli.Bahrami@Sun.COM 	const Val_desc		*vdp;
6769273SAli.Bahrami@Sun.COM 	Word			mm;
6774734Sab196087 
6780Sstevel@tonic-gate 	/*
6791618Srie 	 * Non-SPARC architectures presently provide no known flags.
6800Sstevel@tonic-gate 	 */
6819273SAli.Bahrami@Sun.COM 	if ((mach != EM_SPARCV9) && (((mach != EM_SPARC) &&
6829273SAli.Bahrami@Sun.COM 	    (mach != EM_SPARC32PLUS)) || (flags == 0)))
6839273SAli.Bahrami@Sun.COM 		return (conv_invalid_val(&flags_buf->inv_buf, flags,
6849273SAli.Bahrami@Sun.COM 		    CONV_FMT_DECIMAL));
6859273SAli.Bahrami@Sun.COM 
6869273SAli.Bahrami@Sun.COM 	conv_arg.buf = flags_buf->buf;
6879273SAli.Bahrami@Sun.COM 	conv_ehdr_sparc_flags_strings(fmt_flags, &mm_msg, &vdp);
6889273SAli.Bahrami@Sun.COM 	conv_arg.oflags = conv_arg.rflags = flags;
6899273SAli.Bahrami@Sun.COM 
6909273SAli.Bahrami@Sun.COM 	mm = flags & EF_SPARCV9_MM;
6919273SAli.Bahrami@Sun.COM 	lstr = leading_str_arr;
6929273SAli.Bahrami@Sun.COM 	if ((mach == EM_SPARCV9) && (mm <= mm_msg->ds_topval)) {
6939273SAli.Bahrami@Sun.COM 		*lstr++ = MSG_ORIG(mm_msg->ds_msg[mm]);
6949273SAli.Bahrami@Sun.COM 		conv_arg.rflags &= ~EF_SPARCV9_MM;
6959273SAli.Bahrami@Sun.COM 	}
6969273SAli.Bahrami@Sun.COM 	*lstr = NULL;
6979273SAli.Bahrami@Sun.COM 
6989273SAli.Bahrami@Sun.COM 	(void) conv_expn_field(&conv_arg, vdp, fmt_flags);
6999273SAli.Bahrami@Sun.COM 
7009273SAli.Bahrami@Sun.COM 	return (conv_arg.buf);
7019273SAli.Bahrami@Sun.COM }
7020Sstevel@tonic-gate 
7039273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_flags(Half mach,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)7049273SAli.Bahrami@Sun.COM conv_iter_ehdr_flags(Half mach, Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
7059273SAli.Bahrami@Sun.COM     void *uvalue)
7069273SAli.Bahrami@Sun.COM {
7079273SAli.Bahrami@Sun.COM 
7089273SAli.Bahrami@Sun.COM 	if ((mach == EM_SPARCV9) || (mach == EM_SPARC) ||
7099273SAli.Bahrami@Sun.COM 	    (mach == EM_SPARC32PLUS) || (mach == CONV_MACH_ALL)) {
7109273SAli.Bahrami@Sun.COM 		const conv_ds_msg_t	*ds_msg_mm;
7119273SAli.Bahrami@Sun.COM 		const Val_desc		*vdp;
7129273SAli.Bahrami@Sun.COM 
7139273SAli.Bahrami@Sun.COM 		conv_ehdr_sparc_flags_strings(fmt_flags, &ds_msg_mm, &vdp);
7149273SAli.Bahrami@Sun.COM 
7159273SAli.Bahrami@Sun.COM 		if (mach == EM_SPARCV9) {
7169273SAli.Bahrami@Sun.COM 			const conv_ds_t *ds[2];
7179273SAli.Bahrami@Sun.COM 
7189273SAli.Bahrami@Sun.COM 			ds[0] = CONV_DS_ADDR(ds_msg_mm);
7199273SAli.Bahrami@Sun.COM 			ds[1] = NULL;
7209273SAli.Bahrami@Sun.COM 
7219273SAli.Bahrami@Sun.COM 			if (conv_iter_ds(ELFOSABI_NONE, mach, ds,
7229273SAli.Bahrami@Sun.COM 			    func, uvalue) == CONV_ITER_DONE)
7239273SAli.Bahrami@Sun.COM 				return (CONV_ITER_DONE);
7240Sstevel@tonic-gate 		}
7250Sstevel@tonic-gate 
7269273SAli.Bahrami@Sun.COM 		return (conv_iter_vd(vdp, func, uvalue));
7271618Srie 	}
7284734Sab196087 
7299273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
7309273SAli.Bahrami@Sun.COM }
7319273SAli.Bahrami@Sun.COM 
7329273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_osabi_strings(Conv_fmt_flags_t fmt_flags)7339273SAli.Bahrami@Sun.COM ehdr_osabi_strings(Conv_fmt_flags_t fmt_flags)
7349273SAli.Bahrami@Sun.COM {
7359273SAli.Bahrami@Sun.COM 
7369273SAli.Bahrami@Sun.COM 	static const Msg osabi_0_3_cf[] = {
7379273SAli.Bahrami@Sun.COM 		MSG_OSABI_NONE_CF,	MSG_OSABI_HPUX_CF,
7389273SAli.Bahrami@Sun.COM 		MSG_OSABI_NETBSD_CF,	MSG_OSABI_LINUX_CF
7399273SAli.Bahrami@Sun.COM 	};
7409273SAli.Bahrami@Sun.COM 	static const Msg osabi_0_3_nf[] = {
7419273SAli.Bahrami@Sun.COM 		MSG_OSABI_NONE_NF,	MSG_OSABI_HPUX_NF,
7429273SAli.Bahrami@Sun.COM 		MSG_OSABI_NETBSD_NF,	MSG_OSABI_LINUX_NF
7439273SAli.Bahrami@Sun.COM 	};
7449273SAli.Bahrami@Sun.COM 	static const Msg osabi_0_3_dmp[] = {
7459273SAli.Bahrami@Sun.COM 		MSG_OSABI_NONE_DMP,	MSG_OSABI_HPUX_DMP,
7469273SAli.Bahrami@Sun.COM 		MSG_OSABI_NETBSD_DMP,	MSG_OSABI_LINUX_DMP
7479273SAli.Bahrami@Sun.COM 	};
7489273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_osabi_0_3_cf = {
7499273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_cf) };
7509273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_osabi_0_3_nf = {
7519273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_nf) };
7529273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_osabi_0_3_dmp = {
7539273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_dmp) };
7549273SAli.Bahrami@Sun.COM 
7559273SAli.Bahrami@Sun.COM 
7569273SAli.Bahrami@Sun.COM 	static const Msg osabi_6_15_cf[] = {
7579273SAli.Bahrami@Sun.COM 		MSG_OSABI_SOLARIS_CF,	MSG_OSABI_AIX_CF,
7589273SAli.Bahrami@Sun.COM 		MSG_OSABI_IRIX_CF,	MSG_OSABI_FREEBSD_CF,
7599273SAli.Bahrami@Sun.COM 		MSG_OSABI_TRU64_CF,	MSG_OSABI_MODESTO_CF,
7609273SAli.Bahrami@Sun.COM 		MSG_OSABI_OPENBSD_CF,	MSG_OSABI_OPENVMS_CF,
7619273SAli.Bahrami@Sun.COM 		MSG_OSABI_NSK_CF,	MSG_OSABI_AROS_CF
7629273SAli.Bahrami@Sun.COM 	};
7639273SAli.Bahrami@Sun.COM 	static const Msg osabi_6_15_nf[] = {
7649273SAli.Bahrami@Sun.COM 		MSG_OSABI_SOLARIS_NF,	MSG_OSABI_AIX_NF,
7659273SAli.Bahrami@Sun.COM 		MSG_OSABI_IRIX_NF,	MSG_OSABI_FREEBSD_NF,
7669273SAli.Bahrami@Sun.COM 		MSG_OSABI_TRU64_NF,	MSG_OSABI_MODESTO_NF,
7679273SAli.Bahrami@Sun.COM 		MSG_OSABI_OPENBSD_NF,	MSG_OSABI_OPENVMS_NF,
7689273SAli.Bahrami@Sun.COM 		MSG_OSABI_NSK_NF,	MSG_OSABI_AROS_NF
7699273SAli.Bahrami@Sun.COM 	};
7709273SAli.Bahrami@Sun.COM 	static const Msg osabi_6_15_dmp[] = {
7719273SAli.Bahrami@Sun.COM 		MSG_OSABI_SOLARIS_DMP,	MSG_OSABI_AIX_DMP,
7729273SAli.Bahrami@Sun.COM 		MSG_OSABI_IRIX_DMP,	MSG_OSABI_FREEBSD_DMP,
7739273SAli.Bahrami@Sun.COM 		MSG_OSABI_TRU64_DMP,	MSG_OSABI_MODESTO_DMP,
7749273SAli.Bahrami@Sun.COM 		MSG_OSABI_OPENBSD_DMP,	MSG_OSABI_OPENVMS_DMP,
7759273SAli.Bahrami@Sun.COM 		MSG_OSABI_NSK_DMP,	MSG_OSABI_AROS_DMP
7769273SAli.Bahrami@Sun.COM 	};
7779273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_osabi_6_15_cf = {
7789273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_15_cf) };
7799273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_osabi_6_15_nf = {
7809273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_15_nf) };
7819273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_osabi_6_15_dmp = {
7829273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_15_dmp) };
7839273SAli.Bahrami@Sun.COM 
7849273SAli.Bahrami@Sun.COM 
7859273SAli.Bahrami@Sun.COM 	static const Val_desc osabi_misc_cf[] = {
7869273SAli.Bahrami@Sun.COM 		{ ELFOSABI_ARM,			MSG_OSABI_ARM_CF },
7879273SAli.Bahrami@Sun.COM 		{ ELFOSABI_STANDALONE,		MSG_OSABI_STANDALONE_CF },
7889273SAli.Bahrami@Sun.COM 		{ 0 }
7899273SAli.Bahrami@Sun.COM 	};
7909273SAli.Bahrami@Sun.COM 	static const Val_desc osabi_misc_nf[] = {
7919273SAli.Bahrami@Sun.COM 		{ ELFOSABI_ARM,			MSG_OSABI_ARM_NF },
7929273SAli.Bahrami@Sun.COM 		{ ELFOSABI_STANDALONE,		MSG_OSABI_STANDALONE_NF },
7939273SAli.Bahrami@Sun.COM 		{ 0 }
7949273SAli.Bahrami@Sun.COM 	};
7959273SAli.Bahrami@Sun.COM 	static const Val_desc osabi_misc_dmp[] = {
7969273SAli.Bahrami@Sun.COM 		{ ELFOSABI_ARM,			MSG_OSABI_ARM_DMP },
7979273SAli.Bahrami@Sun.COM 		{ ELFOSABI_STANDALONE,		MSG_OSABI_STANDALONE_DMP },
7989273SAli.Bahrami@Sun.COM 		{ 0 }
7999273SAli.Bahrami@Sun.COM 	};
8009273SAli.Bahrami@Sun.COM 	static const conv_ds_vd_t ds_osabi_misc_cf = {
8019273SAli.Bahrami@Sun.COM 	    CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_cf };
8029273SAli.Bahrami@Sun.COM 	static const conv_ds_vd_t ds_osabi_misc_nf = {
8039273SAli.Bahrami@Sun.COM 	    CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_nf };
8049273SAli.Bahrami@Sun.COM 	static const conv_ds_vd_t ds_osabi_misc_dmp = {
8059273SAli.Bahrami@Sun.COM 	    CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_dmp };
8069273SAli.Bahrami@Sun.COM 
8079273SAli.Bahrami@Sun.COM 	/* Build NULL terminated return arrays for each string style */
8089273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_cf[] = {
8099273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_osabi_0_3_cf), CONV_DS_ADDR(ds_osabi_6_15_cf),
8109273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_osabi_misc_cf), NULL };
8119273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_nf[] = {
8129273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_osabi_0_3_nf), CONV_DS_ADDR(ds_osabi_6_15_nf),
8139273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_osabi_misc_nf), NULL };
8149273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_dmp[] = {
8159273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_osabi_0_3_dmp), CONV_DS_ADDR(ds_osabi_6_15_dmp),
8169273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_osabi_misc_dmp), NULL };
8179273SAli.Bahrami@Sun.COM 
8189273SAli.Bahrami@Sun.COM 	/* Select the strings to use */
8199273SAli.Bahrami@Sun.COM 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
8209273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_DUMP:
8219273SAli.Bahrami@Sun.COM 		return (ds_dmp);
8229273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
8239273SAli.Bahrami@Sun.COM 		return (ds_nf);
8249273SAli.Bahrami@Sun.COM 	}
8259273SAli.Bahrami@Sun.COM 
8269273SAli.Bahrami@Sun.COM 	return (ds_cf);
8270Sstevel@tonic-gate }
8280Sstevel@tonic-gate 
8290Sstevel@tonic-gate /*
8303850Sab196087  * Make a string representation of the e_ident[EI_OSABI] field.
8313850Sab196087  */
8323850Sab196087 const char *
conv_ehdr_osabi(uchar_t osabi,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)8335088Sab196087 conv_ehdr_osabi(uchar_t osabi, Conv_fmt_flags_t fmt_flags,
8345088Sab196087     Conv_inv_buf_t *inv_buf)
8353850Sab196087 {
8369273SAli.Bahrami@Sun.COM 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, osabi,
8379273SAli.Bahrami@Sun.COM 	    ehdr_osabi_strings(fmt_flags), fmt_flags, inv_buf));
8389273SAli.Bahrami@Sun.COM }
8393850Sab196087 
8409273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_osabi(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)8419273SAli.Bahrami@Sun.COM conv_iter_ehdr_osabi(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
8429273SAli.Bahrami@Sun.COM     void *uvalue)
8439273SAli.Bahrami@Sun.COM {
8449273SAli.Bahrami@Sun.COM 	if (conv_iter_ds(ELFOSABI_NONE, EM_NONE, ehdr_osabi_strings(fmt_flags),
8459273SAli.Bahrami@Sun.COM 	    func, uvalue) == CONV_ITER_DONE)
8469273SAli.Bahrami@Sun.COM 		return (CONV_ITER_DONE);
8473850Sab196087 
8489273SAli.Bahrami@Sun.COM 	/*
8499273SAli.Bahrami@Sun.COM 	 * ELFOSABI_NONE might have been better named ELFOSABI_SYSV. For the
8509273SAli.Bahrami@Sun.COM 	 * CF and NF sytles, we supply that name for 0 in addition to NONE.
8519273SAli.Bahrami@Sun.COM 	 */
8529273SAli.Bahrami@Sun.COM 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
8539273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_CF:
8549273SAli.Bahrami@Sun.COM 		return ((* func)(MSG_ORIG(MSG_OSABI_SYSV_CF),
8559273SAli.Bahrami@Sun.COM 		    ELFOSABI_NONE, uvalue));
8569273SAli.Bahrami@Sun.COM 	case CONV_FMT_ALT_NF:
8579273SAli.Bahrami@Sun.COM 		return ((* func)(MSG_ORIG(MSG_OSABI_SYSV_NF),
8589273SAli.Bahrami@Sun.COM 		    ELFOSABI_NONE, uvalue));
8593850Sab196087 	}
8603850Sab196087 
8619273SAli.Bahrami@Sun.COM 		return (CONV_ITER_CONT);
8629273SAli.Bahrami@Sun.COM }
8639273SAli.Bahrami@Sun.COM 
8649273SAli.Bahrami@Sun.COM static const conv_ds_t **
ehdr_abivers_strings(conv_iter_osabi_t osabi,Conv_fmt_flags_t fmt_flags)8659273SAli.Bahrami@Sun.COM ehdr_abivers_strings(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags)
8669273SAli.Bahrami@Sun.COM {
8679273SAli.Bahrami@Sun.COM 	static const Msg	abiversions_cf[] = {
8689273SAli.Bahrami@Sun.COM 		MSG_EAV_SUNW_NONE_CF,	MSG_EAV_SUNW_CURRENT_CF
8699273SAli.Bahrami@Sun.COM 	};
8709273SAli.Bahrami@Sun.COM 	static const Msg	abiversions_nf[] = {
8719273SAli.Bahrami@Sun.COM 		MSG_EAV_SUNW_NONE_NF,	MSG_EAV_SUNW_CURRENT_NF
8729273SAli.Bahrami@Sun.COM 	};
8739273SAli.Bahrami@Sun.COM #if EAV_SUNW_NUM != 2
8749273SAli.Bahrami@Sun.COM error "EAV_SUNW_NUM has grown. Update abiversions[]"
8759273SAli.Bahrami@Sun.COM #endif
8769273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_abiversions_cf = {
8779273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EV_NONE, abiversions_cf) };
8789273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_abiversions_nf = {
8799273SAli.Bahrami@Sun.COM 		CONV_DS_MSG_INIT(EV_NONE, abiversions_nf) };
8809273SAli.Bahrami@Sun.COM 
8819273SAli.Bahrami@Sun.COM 	/* Build NULL terminated return arrays for each string style */
8829273SAli.Bahrami@Sun.COM 	static const const conv_ds_t	*ds_cf[] = {
8839273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_abiversions_cf), NULL };
8849273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_nf[] = {
8859273SAli.Bahrami@Sun.COM 		CONV_DS_ADDR(ds_abiversions_nf), NULL };
8869273SAli.Bahrami@Sun.COM 
8879273SAli.Bahrami@Sun.COM 	/* For non-Solaris OSABI, we don't have symbolic names */
8889273SAli.Bahrami@Sun.COM 	static const conv_ds_t	*ds_none[] = { NULL };
8899273SAli.Bahrami@Sun.COM 
8909273SAli.Bahrami@Sun.COM 
8919273SAli.Bahrami@Sun.COM 	/*
8929273SAli.Bahrami@Sun.COM 	 * Select the strings to use. This is a rare case where
8939273SAli.Bahrami@Sun.COM 	 * we don't treat ELFOSABI_NONE and ELFOSABI_SOLARIS
8949273SAli.Bahrami@Sun.COM 	 * as the same thing. We should never create a Solaris
8959273SAli.Bahrami@Sun.COM 	 * object tagged as ELFOSABI_NONE for which the abiversion
8969273SAli.Bahrami@Sun.COM 	 * is non-zero.
8979273SAli.Bahrami@Sun.COM 	 */
8989273SAli.Bahrami@Sun.COM 	if ((osabi == ELFOSABI_SOLARIS) || (osabi == CONV_OSABI_ALL))
8999273SAli.Bahrami@Sun.COM 		return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
9009273SAli.Bahrami@Sun.COM 		    ds_nf : ds_cf);
9019273SAli.Bahrami@Sun.COM 
9029273SAli.Bahrami@Sun.COM 	return (ds_none);
9039273SAli.Bahrami@Sun.COM }
9049273SAli.Bahrami@Sun.COM 
9059273SAli.Bahrami@Sun.COM const char *
conv_ehdr_abivers(uchar_t osabi,Word version,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)9069273SAli.Bahrami@Sun.COM conv_ehdr_abivers(uchar_t osabi, Word version, Conv_fmt_flags_t fmt_flags,
9079273SAli.Bahrami@Sun.COM     Conv_inv_buf_t *inv_buf)
9089273SAli.Bahrami@Sun.COM {
9099273SAli.Bahrami@Sun.COM 	return (conv_map_ds(osabi, EM_NONE, version,
9109273SAli.Bahrami@Sun.COM 	    ehdr_abivers_strings(osabi, fmt_flags), fmt_flags, inv_buf));
9119273SAli.Bahrami@Sun.COM }
9129273SAli.Bahrami@Sun.COM 
9139273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_ehdr_abivers(conv_iter_osabi_t osabi,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)9149273SAli.Bahrami@Sun.COM conv_iter_ehdr_abivers(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
9159273SAli.Bahrami@Sun.COM     conv_iter_cb_t func, void *uvalue)
9169273SAli.Bahrami@Sun.COM {
9179273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(osabi, EM_NONE,
9189273SAli.Bahrami@Sun.COM 	    ehdr_abivers_strings(osabi, fmt_flags), func, uvalue));
9193850Sab196087 }
9203850Sab196087 
9213850Sab196087 /*
9220Sstevel@tonic-gate  * A generic means of returning additional information for a rejected file in
9239273SAli.Bahrami@Sun.COM  * terms of a string. ELFOSABI_SOLARIS is assummed.
9240Sstevel@tonic-gate  */
9250Sstevel@tonic-gate const char *
conv_reject_desc(Rej_desc * rej,Conv_reject_desc_buf_t * reject_desc_buf,Half mach)9266206Sab196087 conv_reject_desc(Rej_desc * rej, Conv_reject_desc_buf_t *reject_desc_buf,
9276206Sab196087     Half mach)
9280Sstevel@tonic-gate {
9294734Sab196087 	ushort_t	type = rej->rej_type;
9304734Sab196087 	uint_t		info = rej->rej_info;
9310Sstevel@tonic-gate 
9327833SRod.Evans@Sun.COM 	switch (type) {
9337833SRod.Evans@Sun.COM 	case SGS_REJ_MACH:
9344734Sab196087 		return (conv_ehdr_mach((Half)info, 0,
9354734Sab196087 		    &reject_desc_buf->inv_buf));
9367833SRod.Evans@Sun.COM 	case SGS_REJ_CLASS:
9374734Sab196087 		return (conv_ehdr_class((uchar_t)info, 0,
9384734Sab196087 		    &reject_desc_buf->inv_buf));
9397833SRod.Evans@Sun.COM 	case SGS_REJ_DATA:
9404734Sab196087 		return (conv_ehdr_data((uchar_t)info, 0,
9414734Sab196087 		    &reject_desc_buf->inv_buf));
9427833SRod.Evans@Sun.COM 	case SGS_REJ_TYPE:
9439273SAli.Bahrami@Sun.COM 		return (conv_ehdr_type(ELFOSABI_SOLARIS, (Half)info, 0,
9444734Sab196087 		    &reject_desc_buf->inv_buf));
9457833SRod.Evans@Sun.COM 	case SGS_REJ_BADFLAG:
9467833SRod.Evans@Sun.COM 	case SGS_REJ_MISFLAG:
9477833SRod.Evans@Sun.COM 	case SGS_REJ_HAL:
9487833SRod.Evans@Sun.COM 	case SGS_REJ_US3:
9496206Sab196087 		return (conv_ehdr_flags(mach, (Word)info, 0,
9504734Sab196087 		    &reject_desc_buf->flags_buf));
9517833SRod.Evans@Sun.COM 	case SGS_REJ_UNKFILE:
952*12254SAli.Bahrami@Oracle.COM 	case SGS_REJ_ARCHIVE:
953*12254SAli.Bahrami@Oracle.COM 		return (NULL);
9547833SRod.Evans@Sun.COM 	case SGS_REJ_STR:
9557833SRod.Evans@Sun.COM 	case SGS_REJ_HWCAP_1:
9567833SRod.Evans@Sun.COM 	case SGS_REJ_SFCAP_1:
95711827SRod.Evans@Sun.COM 	case SGS_REJ_HWCAP_2:
95811827SRod.Evans@Sun.COM 	case SGS_REJ_MACHCAP:
95911827SRod.Evans@Sun.COM 	case SGS_REJ_PLATCAP:
9600Sstevel@tonic-gate 		if (rej->rej_str)
9610Sstevel@tonic-gate 			return ((const char *)rej->rej_str);
9620Sstevel@tonic-gate 		else
9630Sstevel@tonic-gate 			return (MSG_ORIG(MSG_STR_EMPTY));
9647833SRod.Evans@Sun.COM 	default:
9654734Sab196087 		return (conv_invalid_val(&reject_desc_buf->inv_buf, info,
9661976Sab196087 		    CONV_FMT_DECIMAL));
9677833SRod.Evans@Sun.COM 	}
9680Sstevel@tonic-gate }
969