xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/cap.c (revision 11827:d7ef53deac3f)
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 /*
2311734SAli.Bahrami@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * String conversion routine for hardware capabilities types.
290Sstevel@tonic-gate  */
300Sstevel@tonic-gate #include	<strings.h>
310Sstevel@tonic-gate #include	<stdio.h>
320Sstevel@tonic-gate #include	<elfcap.h>
331976Sab196087 #include	"cap_msg.h"
340Sstevel@tonic-gate #include	"_conv.h"
350Sstevel@tonic-gate 
369273SAli.Bahrami@Sun.COM const conv_ds_t **
conv_cap_tag_strings(Conv_fmt_flags_t fmt_flags)379273SAli.Bahrami@Sun.COM conv_cap_tag_strings(Conv_fmt_flags_t fmt_flags)
380Sstevel@tonic-gate {
39*11827SRod.Evans@Sun.COM #if	(CA_SUNW_NUM != (CA_SUNW_ID + 1))
4011734SAli.Bahrami@Sun.COM #error	"CA_SUNW_NUM has grown"
4111734SAli.Bahrami@Sun.COM #endif
429273SAli.Bahrami@Sun.COM 	static const Msg	tags_cf[] = {
439273SAli.Bahrami@Sun.COM 		MSG_CA_SUNW_NULL_CF,	MSG_CA_SUNW_HW_1_CF,
44*11827SRod.Evans@Sun.COM 		MSG_CA_SUNW_SF_1_CF,	MSG_CA_SUNW_HW_2_CF,
45*11827SRod.Evans@Sun.COM 		MSG_CA_SUNW_PLAT_CF,	MSG_CA_SUNW_MACH_CF,
46*11827SRod.Evans@Sun.COM 		MSG_CA_SUNW_ID_CF
479273SAli.Bahrami@Sun.COM 	};
489273SAli.Bahrami@Sun.COM 	static const Msg	tags_nf[] = {
499273SAli.Bahrami@Sun.COM 		MSG_CA_SUNW_NULL_NF,	MSG_CA_SUNW_HW_1_NF,
5011734SAli.Bahrami@Sun.COM 		MSG_CA_SUNW_SF_1_NF,	MSG_CA_SUNW_HW_2_NF,
51*11827SRod.Evans@Sun.COM 		MSG_CA_SUNW_PLAT_NF,	MSG_CA_SUNW_MACH_NF,
52*11827SRod.Evans@Sun.COM 		MSG_CA_SUNW_ID_NF
539273SAli.Bahrami@Sun.COM 	};
549273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_tags_cf = {
559273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, tags_cf) };
569273SAli.Bahrami@Sun.COM 	static const conv_ds_msg_t ds_tags_nf = {
579273SAli.Bahrami@Sun.COM 	    CONV_DS_MSG_INIT(ELFCLASSNONE, tags_nf) };
585088Sab196087 
599273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_tags_cf), NULL };
609273SAli.Bahrami@Sun.COM 	static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_tags_nf), NULL };
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 
639273SAli.Bahrami@Sun.COM 	return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
649273SAli.Bahrami@Sun.COM 	    ds_nf : ds_cf);
659273SAli.Bahrami@Sun.COM }
669273SAli.Bahrami@Sun.COM 
679273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_cap_tags(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)689273SAli.Bahrami@Sun.COM conv_iter_cap_tags(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
699273SAli.Bahrami@Sun.COM     void *uvalue)
709273SAli.Bahrami@Sun.COM {
719273SAli.Bahrami@Sun.COM 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
729273SAli.Bahrami@Sun.COM 	    conv_cap_tag_strings(fmt_flags), func, uvalue));
730Sstevel@tonic-gate }
740Sstevel@tonic-gate 
759273SAli.Bahrami@Sun.COM /*
769273SAli.Bahrami@Sun.COM  * Given an array of elfcap_desc_t, and a count, call the specified
779273SAli.Bahrami@Sun.COM  * iteration for each value in the array.
789273SAli.Bahrami@Sun.COM  */
799273SAli.Bahrami@Sun.COM static conv_iter_ret_t
conv_iter_elfcap(const elfcap_desc_t * cdp,uint_t cnum,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)809273SAli.Bahrami@Sun.COM conv_iter_elfcap(const elfcap_desc_t *cdp, uint_t cnum,
819273SAli.Bahrami@Sun.COM     Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue)
820Sstevel@tonic-gate {
839273SAli.Bahrami@Sun.COM 	const char	*str;
849273SAli.Bahrami@Sun.COM 
859273SAli.Bahrami@Sun.COM 	fmt_flags = CONV_TYPE_FMT_ALT(fmt_flags);
860Sstevel@tonic-gate 
879273SAli.Bahrami@Sun.COM 	for (; cnum-- > 0; cdp++) {
889273SAli.Bahrami@Sun.COM 		/*
899273SAli.Bahrami@Sun.COM 		 * Skip "reserved" bits. These are unassigned bits in the
909273SAli.Bahrami@Sun.COM 		 * middle of the assigned range.
919273SAli.Bahrami@Sun.COM 		 */
929273SAli.Bahrami@Sun.COM 		if (cdp->c_val == 0)
939273SAli.Bahrami@Sun.COM 			continue;
940Sstevel@tonic-gate 
959273SAli.Bahrami@Sun.COM 		switch (fmt_flags) {
969273SAli.Bahrami@Sun.COM 		default:
979273SAli.Bahrami@Sun.COM 			str = cdp->c_full.s_str;
989273SAli.Bahrami@Sun.COM 			break;
999273SAli.Bahrami@Sun.COM 		case CONV_FMT_ALT_CFNP:
1009273SAli.Bahrami@Sun.COM 			str = cdp->c_uc.s_str;
1019273SAli.Bahrami@Sun.COM 			break;
1029273SAli.Bahrami@Sun.COM 		case CONV_FMT_ALT_NF:
1039273SAli.Bahrami@Sun.COM 			str = cdp->c_lc.s_str;
1049273SAli.Bahrami@Sun.COM 			break;
1059273SAli.Bahrami@Sun.COM 		}
1060Sstevel@tonic-gate 
1079273SAli.Bahrami@Sun.COM 		if ((* func)(str, cdp->c_val, uvalue) == CONV_ITER_DONE)
1089273SAli.Bahrami@Sun.COM 			return (CONV_ITER_DONE);
1099273SAli.Bahrami@Sun.COM 	}
1109273SAli.Bahrami@Sun.COM 
1119273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1149273SAli.Bahrami@Sun.COM /*
115*11827SRod.Evans@Sun.COM  * Iterate the strings for CA_SUNW_HW.
1169273SAli.Bahrami@Sun.COM  */
1179273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_cap_val_hw1(Half mach,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)1189273SAli.Bahrami@Sun.COM conv_iter_cap_val_hw1(Half mach, Conv_fmt_flags_t fmt_flags,
1199273SAli.Bahrami@Sun.COM     conv_iter_cb_t func, void *uvalue)
1200Sstevel@tonic-gate {
1219273SAli.Bahrami@Sun.COM 	if ((mach == EM_386) || (mach == EM_486) ||
1229273SAli.Bahrami@Sun.COM 	    (mach == EM_AMD64) || (mach == CONV_MACH_ALL))
1239273SAli.Bahrami@Sun.COM 		if (conv_iter_elfcap(elfcap_getdesc_hw1_386(),
1249273SAli.Bahrami@Sun.COM 		    ELFCAP_NUM_HW1_386, fmt_flags, func, uvalue) ==
1259273SAli.Bahrami@Sun.COM 		    CONV_ITER_DONE)
1269273SAli.Bahrami@Sun.COM 			return (CONV_ITER_DONE);
1270Sstevel@tonic-gate 
1289273SAli.Bahrami@Sun.COM 	if ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
1299273SAli.Bahrami@Sun.COM 	    (mach == EM_SPARCV9) || (mach == CONV_MACH_ALL))
1309273SAli.Bahrami@Sun.COM 		if (conv_iter_elfcap(elfcap_getdesc_hw1_sparc(),
1319273SAli.Bahrami@Sun.COM 		    ELFCAP_NUM_HW1_SPARC, fmt_flags, func, uvalue) ==
1329273SAli.Bahrami@Sun.COM 		    CONV_ITER_DONE)
1339273SAli.Bahrami@Sun.COM 			return (CONV_ITER_DONE);
1349273SAli.Bahrami@Sun.COM 
1359273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
138*11827SRod.Evans@Sun.COM conv_iter_ret_t
139*11827SRod.Evans@Sun.COM /* ARGSUSED0 */
conv_iter_cap_val_hw2(Half mach,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)140*11827SRod.Evans@Sun.COM conv_iter_cap_val_hw2(Half mach, Conv_fmt_flags_t fmt_flags,
141*11827SRod.Evans@Sun.COM     conv_iter_cb_t func, void *uvalue)
142*11827SRod.Evans@Sun.COM {
143*11827SRod.Evans@Sun.COM 	return (CONV_ITER_DONE);
144*11827SRod.Evans@Sun.COM }
145*11827SRod.Evans@Sun.COM 
1469273SAli.Bahrami@Sun.COM /*
1479273SAli.Bahrami@Sun.COM  * Iterate the strings for CA_SUNW_SF1
1489273SAli.Bahrami@Sun.COM  */
1499273SAli.Bahrami@Sun.COM conv_iter_ret_t
conv_iter_cap_val_sf1(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)1509273SAli.Bahrami@Sun.COM conv_iter_cap_val_sf1(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
1519273SAli.Bahrami@Sun.COM     void *uvalue)
1520Sstevel@tonic-gate {
1539273SAli.Bahrami@Sun.COM 	return (conv_iter_elfcap(elfcap_getdesc_sf1(), ELFCAP_NUM_SF1,
1549273SAli.Bahrami@Sun.COM 	    fmt_flags, func, uvalue));
1550Sstevel@tonic-gate }
156