xref: /onnv-gate/usr/src/common/elfcap/elfcap.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate /* LINTLIBRARY */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate  * String conversion routine for hardware capabilities types.
32*0Sstevel@tonic-gate  */
33*0Sstevel@tonic-gate #include	<strings.h>
34*0Sstevel@tonic-gate #include	<stdio.h>
35*0Sstevel@tonic-gate #include	<ctype.h>
36*0Sstevel@tonic-gate #include	<limits.h>
37*0Sstevel@tonic-gate #include	<sys/machelf.h>
38*0Sstevel@tonic-gate #include	<sys/elf.h>
39*0Sstevel@tonic-gate #include	<sys/auxv_SPARC.h>
40*0Sstevel@tonic-gate #include	<sys/auxv_386.h>
41*0Sstevel@tonic-gate #include	<elfcap.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  * Define separators for val2str processing.
45*0Sstevel@tonic-gate  */
46*0Sstevel@tonic-gate static const Fmt_desc format[] = {
47*0Sstevel@tonic-gate 	{" ",	1 },
48*0Sstevel@tonic-gate 	{"  ",	2 },
49*0Sstevel@tonic-gate 	{" | ",	3 }
50*0Sstevel@tonic-gate };
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate /*
53*0Sstevel@tonic-gate  * Define all known capabilities as both lower and upper case strings.  This
54*0Sstevel@tonic-gate  * duplication is necessary, rather than have one string and use something
55*0Sstevel@tonic-gate  * like toupper(), as a client such as ld.so.1 doesn't need the overhead of
56*0Sstevel@tonic-gate  * dragging in the internationalization support of toupper().  The Intel 3DNow
57*0Sstevel@tonic-gate  * flags are a slightly odd convention too.
58*0Sstevel@tonic-gate  *
59*0Sstevel@tonic-gate  * Define all known software capabilities.
60*0Sstevel@tonic-gate  */
61*0Sstevel@tonic-gate #ifdef	CAP_UPPERCASE
62*0Sstevel@tonic-gate static const char Sf1_fpknwn[] =	"FPKNWN";
63*0Sstevel@tonic-gate static const char Sf1_fpused[] =	"FPUSED";
64*0Sstevel@tonic-gate #elif	CAP_LOWERCASE
65*0Sstevel@tonic-gate static const char Sf1_fpknwn[] =	"fpknwn";
66*0Sstevel@tonic-gate static const char Sf1_fpused[] =	"fpused";
67*0Sstevel@tonic-gate #else
68*0Sstevel@tonic-gate #error	"Software Capabilities - what case do you want?"
69*0Sstevel@tonic-gate #endif
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /*
72*0Sstevel@tonic-gate  * Order the software capabilities to match their numeric value.  See SF1_SUNW_
73*0Sstevel@tonic-gate  * values in sys/elf.h.
74*0Sstevel@tonic-gate  */
75*0Sstevel@tonic-gate static const Cap_desc sf1[] = {
76*0Sstevel@tonic-gate 	{ SF1_SUNW_FPKNWN,	Sf1_fpknwn,	(sizeof (Sf1_fpknwn) - 1) },
77*0Sstevel@tonic-gate 	{ SF1_SUNW_FPUSED,	Sf1_fpused,	(sizeof (Sf1_fpused) - 1) }
78*0Sstevel@tonic-gate };
79*0Sstevel@tonic-gate static const uint_t sf1_num = sizeof (sf1) / sizeof (Cap_desc);
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate /*
82*0Sstevel@tonic-gate  * Define all known SPARC hardware capabilities.
83*0Sstevel@tonic-gate  */
84*0Sstevel@tonic-gate #ifdef	CAP_UPPERCASE
85*0Sstevel@tonic-gate static const char Hw1_s_mul32[] =	"MUL32";
86*0Sstevel@tonic-gate static const char Hw1_s_div32[] =	"DIV32";
87*0Sstevel@tonic-gate static const char Hw1_s_fsmuld[] =	"FSMULD";
88*0Sstevel@tonic-gate static const char Hw1_s_v8plus[] =	"V8PLUS";
89*0Sstevel@tonic-gate static const char Hw1_s_popc[] =	"POPC";
90*0Sstevel@tonic-gate static const char Hw1_s_vis[] =		"VIS";
91*0Sstevel@tonic-gate static const char Hw1_s_vis2[] =	"VIS2";
92*0Sstevel@tonic-gate static const char Hw1_s_asi_blk_init[] =	"ASI_BLK_INIT";
93*0Sstevel@tonic-gate #elif	CAP_LOWERCASE
94*0Sstevel@tonic-gate static const char Hw1_s_mul32[] =	"mul32";
95*0Sstevel@tonic-gate static const char Hw1_s_div32[] =	"div32";
96*0Sstevel@tonic-gate static const char Hw1_s_fsmuld[] =	"fsmuld";
97*0Sstevel@tonic-gate static const char Hw1_s_v8plus[] =	"v8plus";
98*0Sstevel@tonic-gate static const char Hw1_s_popc[] =	"popc";
99*0Sstevel@tonic-gate static const char Hw1_s_vis[] =		"vis";
100*0Sstevel@tonic-gate static const char Hw1_s_vis2[] =	"vis2";
101*0Sstevel@tonic-gate static const char Hw1_s_asi_blk_init[] =	"asi_blk_init";
102*0Sstevel@tonic-gate #else
103*0Sstevel@tonic-gate #error	"Hardware Capabilities (sparc) - what case do you want?"
104*0Sstevel@tonic-gate #endif
105*0Sstevel@tonic-gate 
106*0Sstevel@tonic-gate /*
107*0Sstevel@tonic-gate  * Order the SPARC hardware capabilities to match their numeric value.  See
108*0Sstevel@tonic-gate  * AV_SPARC_ values in sys/auxv_SPARC.h.
109*0Sstevel@tonic-gate  */
110*0Sstevel@tonic-gate static const Cap_desc hw1_s[] = {
111*0Sstevel@tonic-gate 	{ AV_SPARC_MUL32,	Hw1_s_mul32,	sizeof (Hw1_s_mul32) - 1 },
112*0Sstevel@tonic-gate 	{ AV_SPARC_DIV32,	Hw1_s_div32,	sizeof (Hw1_s_div32) - 1 },
113*0Sstevel@tonic-gate 	{ AV_SPARC_FSMULD,	Hw1_s_fsmuld,	sizeof (Hw1_s_fsmuld) - 1 },
114*0Sstevel@tonic-gate 	{ AV_SPARC_V8PLUS,	Hw1_s_v8plus,	sizeof (Hw1_s_v8plus) - 1 },
115*0Sstevel@tonic-gate 	{ AV_SPARC_POPC,	Hw1_s_popc,	sizeof (Hw1_s_popc) - 1 },
116*0Sstevel@tonic-gate 	{ AV_SPARC_VIS,		Hw1_s_vis,	sizeof (Hw1_s_vis) - 1 },
117*0Sstevel@tonic-gate 	{ AV_SPARC_VIS2,	Hw1_s_vis2,	sizeof (Hw1_s_vis2) - 1 },
118*0Sstevel@tonic-gate 	{ AV_SPARC_ASI_BLK_INIT,	Hw1_s_asi_blk_init,
119*0Sstevel@tonic-gate 		sizeof (Hw1_s_asi_blk_init) - 1 }
120*0Sstevel@tonic-gate };
121*0Sstevel@tonic-gate static const uint_t hw1_s_num = sizeof (hw1_s) / sizeof (Cap_desc);
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate /*
124*0Sstevel@tonic-gate  * Define all known Intel hardware capabilities.
125*0Sstevel@tonic-gate  */
126*0Sstevel@tonic-gate #ifdef	CAP_UPPERCASE
127*0Sstevel@tonic-gate static const char Hw1_i_fpu[] =		"FPU";
128*0Sstevel@tonic-gate static const char Hw1_i_tsc[] =		"TSC";
129*0Sstevel@tonic-gate static const char Hw1_i_cx8[] =		"CX8";
130*0Sstevel@tonic-gate static const char Hw1_i_sep[] =		"SEP";
131*0Sstevel@tonic-gate static const char Hw1_i_amd_sysc[] =	"AMD_SYSC";
132*0Sstevel@tonic-gate static const char Hw1_i_cmov[] =	"CMOV";
133*0Sstevel@tonic-gate static const char Hw1_i_mmx[] =		"MMX";
134*0Sstevel@tonic-gate static const char Hw1_i_amd_mmx[] =	"AMD_MMX";
135*0Sstevel@tonic-gate static const char Hw1_i_amd_3dnow[] =	"AMD_3DNow";
136*0Sstevel@tonic-gate static const char Hw1_i_amd_3dnowx[] =	"AMD_3DNowx";
137*0Sstevel@tonic-gate static const char Hw1_i_fxsr[] =	"FXSR";
138*0Sstevel@tonic-gate static const char Hw1_i_sse[] =		"SSE";
139*0Sstevel@tonic-gate static const char Hw1_i_sse2[] =	"SSE2";
140*0Sstevel@tonic-gate static const char Hw1_i_pause[] =	"PAUSE";
141*0Sstevel@tonic-gate static const char Hw1_i_sse3[] =	"SSE3";
142*0Sstevel@tonic-gate static const char Hw1_i_mon[] =		"MON";
143*0Sstevel@tonic-gate static const char Hw1_i_cx16[] =	"CX16";
144*0Sstevel@tonic-gate #elif	CAP_LOWERCASE
145*0Sstevel@tonic-gate static const char Hw1_i_fpu[] =		"fpu";
146*0Sstevel@tonic-gate static const char Hw1_i_tsc[] =		"tsc";
147*0Sstevel@tonic-gate static const char Hw1_i_cx8[] =		"cx8";
148*0Sstevel@tonic-gate static const char Hw1_i_sep[] =		"sep";
149*0Sstevel@tonic-gate static const char Hw1_i_amd_sysc[] =	"amd_sysc";
150*0Sstevel@tonic-gate static const char Hw1_i_cmov[] =	"cmov";
151*0Sstevel@tonic-gate static const char Hw1_i_mmx[] =		"mmx";
152*0Sstevel@tonic-gate static const char Hw1_i_amd_mmx[] =	"amd_mmx";
153*0Sstevel@tonic-gate static const char Hw1_i_amd_3dnow[] =	"amd_3dnow";
154*0Sstevel@tonic-gate static const char Hw1_i_amd_3dnowx[] =	"amd_3dnowx";
155*0Sstevel@tonic-gate static const char Hw1_i_fxsr[] =	"fxsr";
156*0Sstevel@tonic-gate static const char Hw1_i_sse[] =		"sse";
157*0Sstevel@tonic-gate static const char Hw1_i_sse2[] =	"sse2";
158*0Sstevel@tonic-gate static const char Hw1_i_pause[] =	"pause";
159*0Sstevel@tonic-gate static const char Hw1_i_sse3[] =	"sse3";
160*0Sstevel@tonic-gate static const char Hw1_i_mon[] =		"mon";
161*0Sstevel@tonic-gate static const char Hw1_i_cx16[] =	"cx16";
162*0Sstevel@tonic-gate #else
163*0Sstevel@tonic-gate #error	"Hardware Capabilities (intel) - what case do you want?"
164*0Sstevel@tonic-gate #endif
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate /*
167*0Sstevel@tonic-gate  * Order the Intel hardware capabilities to match their numeric value.  See
168*0Sstevel@tonic-gate  * AV_386_ values in sys/auxv_386.h.
169*0Sstevel@tonic-gate  */
170*0Sstevel@tonic-gate static const Cap_desc hw1_i[] = {
171*0Sstevel@tonic-gate 	{ AV_386_FPU,		Hw1_i_fpu,	sizeof (Hw1_i_fpu) - 1 },
172*0Sstevel@tonic-gate 	{ AV_386_TSC,		Hw1_i_tsc,	sizeof (Hw1_i_tsc) - 1 },
173*0Sstevel@tonic-gate 	{ AV_386_CX8,		Hw1_i_cx8,	sizeof (Hw1_i_cx8) - 1 },
174*0Sstevel@tonic-gate 	{ AV_386_SEP,		Hw1_i_sep,	sizeof (Hw1_i_sep) - 1 },
175*0Sstevel@tonic-gate 	{ AV_386_AMD_SYSC,	Hw1_i_amd_sysc,	sizeof (Hw1_i_amd_sysc) - 1 },
176*0Sstevel@tonic-gate 	{ AV_386_CMOV,		Hw1_i_cmov,	sizeof (Hw1_i_cmov) - 1 },
177*0Sstevel@tonic-gate 	{ AV_386_MMX,		Hw1_i_mmx,	sizeof (Hw1_i_mmx) - 1 },
178*0Sstevel@tonic-gate 	{ AV_386_AMD_MMX,	Hw1_i_amd_mmx,	sizeof (Hw1_i_amd_mmx) - 1 },
179*0Sstevel@tonic-gate 	{ AV_386_AMD_3DNow,	Hw1_i_amd_3dnow,
180*0Sstevel@tonic-gate 						sizeof (Hw1_i_amd_3dnow) - 1 },
181*0Sstevel@tonic-gate 	{ AV_386_AMD_3DNowx,	Hw1_i_amd_3dnowx,
182*0Sstevel@tonic-gate 						sizeof (Hw1_i_amd_3dnowx) - 1 },
183*0Sstevel@tonic-gate 	{ AV_386_FXSR,		Hw1_i_fxsr,	sizeof (Hw1_i_fxsr) - 1 },
184*0Sstevel@tonic-gate 	{ AV_386_SSE,		Hw1_i_sse,	sizeof (Hw1_i_sse) - 1 },
185*0Sstevel@tonic-gate 	{ AV_386_SSE2,		Hw1_i_sse2,	sizeof (Hw1_i_sse2) - 1 },
186*0Sstevel@tonic-gate 	{ AV_386_PAUSE,		Hw1_i_pause,	sizeof (Hw1_i_pause) - 1 },
187*0Sstevel@tonic-gate 	{ AV_386_SSE3,		Hw1_i_sse3,	sizeof (Hw1_i_sse3) - 1 },
188*0Sstevel@tonic-gate 	{ AV_386_MON,		Hw1_i_mon,	sizeof (Hw1_i_mon) - 1 },
189*0Sstevel@tonic-gate 	{ AV_386_CX16,		Hw1_i_cx16,	sizeof (Hw1_i_cx16) - 1 }
190*0Sstevel@tonic-gate };
191*0Sstevel@tonic-gate static const uint_t hw1_i_num = sizeof (hw1_i) / sizeof (Cap_desc);
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate /*
194*0Sstevel@tonic-gate  * Concatenate a token to the string buffer.  This can be a capailities token
195*0Sstevel@tonic-gate  * or a separator token.
196*0Sstevel@tonic-gate  */
197*0Sstevel@tonic-gate static int
198*0Sstevel@tonic-gate token(char **ostr, size_t *olen, const char *nstr, size_t nlen)
199*0Sstevel@tonic-gate {
200*0Sstevel@tonic-gate 	if (*olen < nlen)
201*0Sstevel@tonic-gate 		return (CAP_ERR_BUFOVFL);
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 	(void) strcat(*ostr, nstr);
204*0Sstevel@tonic-gate 	*ostr += nlen;
205*0Sstevel@tonic-gate 	*olen -= nlen;
206*0Sstevel@tonic-gate 
207*0Sstevel@tonic-gate 	return (0);
208*0Sstevel@tonic-gate }
209*0Sstevel@tonic-gate 
210*0Sstevel@tonic-gate /*
211*0Sstevel@tonic-gate  * Expand a capabilities value into the strings defined in the associated
212*0Sstevel@tonic-gate  * capabilities descriptor.
213*0Sstevel@tonic-gate  */
214*0Sstevel@tonic-gate static int
215*0Sstevel@tonic-gate expand(uint64_t val, const Cap_desc *cdp, uint_t cnum, char *str, size_t slen,
216*0Sstevel@tonic-gate     int fmt)
217*0Sstevel@tonic-gate {
218*0Sstevel@tonic-gate 	uint_t	cnt, mask;
219*0Sstevel@tonic-gate 	int	follow = 0, err;
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate 	if (val == 0)
222*0Sstevel@tonic-gate 		return (0);
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate 	for (cnt = WORD_BIT, mask = 0x80000000; cnt; cnt--,
225*0Sstevel@tonic-gate 	    (mask = mask >> 1)) {
226*0Sstevel@tonic-gate 		if ((val & mask) && (cnt <= cnum) && cdp[cnt - 1].c_val) {
227*0Sstevel@tonic-gate 			if (follow++ && ((err = token(&str, &slen,
228*0Sstevel@tonic-gate 			    format[fmt].f_str, format[fmt].f_len)) != 0))
229*0Sstevel@tonic-gate 				return (err);
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate 			if ((err = token(&str, &slen, cdp[cnt - 1].c_str,
232*0Sstevel@tonic-gate 			    cdp[cnt - 1].c_len)) != 0)
233*0Sstevel@tonic-gate 				return (err);
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate 			val = val & ~mask;
236*0Sstevel@tonic-gate 		}
237*0Sstevel@tonic-gate 	}
238*0Sstevel@tonic-gate 
239*0Sstevel@tonic-gate 	/*
240*0Sstevel@tonic-gate 	 * If there are any unknown bits remaining display the numeric value.
241*0Sstevel@tonic-gate 	 */
242*0Sstevel@tonic-gate 	if (val) {
243*0Sstevel@tonic-gate 		if (follow && ((err = token(&str, &slen, format[fmt].f_str,
244*0Sstevel@tonic-gate 		    format[fmt].f_len)) != 0))
245*0Sstevel@tonic-gate 			return (err);
246*0Sstevel@tonic-gate 
247*0Sstevel@tonic-gate 		(void) snprintf(str, slen, "0x%llx", val);
248*0Sstevel@tonic-gate 	}
249*0Sstevel@tonic-gate 	return (0);
250*0Sstevel@tonic-gate }
251*0Sstevel@tonic-gate 
252*0Sstevel@tonic-gate /*
253*0Sstevel@tonic-gate  * Expand a CA_SUNW_HW_1 value.
254*0Sstevel@tonic-gate  */
255*0Sstevel@tonic-gate int
256*0Sstevel@tonic-gate hwcap_1_val2str(uint64_t val, char *str, size_t len, int fmt, ushort_t mach)
257*0Sstevel@tonic-gate {
258*0Sstevel@tonic-gate 	/*
259*0Sstevel@tonic-gate 	 * Initialize the string buffer, and validate the format request.
260*0Sstevel@tonic-gate 	 */
261*0Sstevel@tonic-gate 	*str = '\0';
262*0Sstevel@tonic-gate 	if (fmt > CAP_MAX_TYPE)
263*0Sstevel@tonic-gate 		return (CAP_ERR_INVFMT);
264*0Sstevel@tonic-gate 
265*0Sstevel@tonic-gate 	if ((mach == EM_386) || (mach == EM_IA_64) || (mach == EM_AMD64))
266*0Sstevel@tonic-gate 		return (expand(val, &hw1_i[0], hw1_i_num, str, len, fmt));
267*0Sstevel@tonic-gate 
268*0Sstevel@tonic-gate 	if ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
269*0Sstevel@tonic-gate 	    (mach == EM_SPARCV9))
270*0Sstevel@tonic-gate 		return (expand(val, &hw1_s[0], hw1_s_num, str, len, fmt));
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate 	return (CAP_ERR_UNKMACH);
273*0Sstevel@tonic-gate }
274*0Sstevel@tonic-gate 
275*0Sstevel@tonic-gate /*
276*0Sstevel@tonic-gate  * Expand a CA_SUNW_SF_1 value.  Note, that at present these capabilities are
277*0Sstevel@tonic-gate  * common across all platforms.  The use of "mach" is therefore redundant, but
278*0Sstevel@tonic-gate  * is retained for compatibility with the interface of hwcap_1_val2str(), and
279*0Sstevel@tonic-gate  * possible future expansion.
280*0Sstevel@tonic-gate  */
281*0Sstevel@tonic-gate int
282*0Sstevel@tonic-gate /* ARGSUSED4 */
283*0Sstevel@tonic-gate sfcap_1_val2str(uint64_t val, char *str, size_t len, int fmt, ushort_t mach)
284*0Sstevel@tonic-gate {
285*0Sstevel@tonic-gate 	/*
286*0Sstevel@tonic-gate 	 * Initialize the string buffer, and validate the format request.
287*0Sstevel@tonic-gate 	 */
288*0Sstevel@tonic-gate 	*str = '\0';
289*0Sstevel@tonic-gate 	if (fmt > CAP_MAX_TYPE)
290*0Sstevel@tonic-gate 		return (CAP_ERR_INVFMT);
291*0Sstevel@tonic-gate 
292*0Sstevel@tonic-gate 	return (expand(val, &sf1[0], sf1_num, str, len, fmt));
293*0Sstevel@tonic-gate }
294*0Sstevel@tonic-gate 
295*0Sstevel@tonic-gate /*
296*0Sstevel@tonic-gate  * Determine capability type from the capability tag.
297*0Sstevel@tonic-gate  */
298*0Sstevel@tonic-gate int
299*0Sstevel@tonic-gate cap_val2str(uint64_t tag, uint64_t val, char *str, size_t len, int fmt,
300*0Sstevel@tonic-gate     ushort_t mach)
301*0Sstevel@tonic-gate {
302*0Sstevel@tonic-gate 	if (tag == CA_SUNW_HW_1)
303*0Sstevel@tonic-gate 		return (hwcap_1_val2str(val, str, len, fmt, mach));
304*0Sstevel@tonic-gate 	if (tag == CA_SUNW_SF_1)
305*0Sstevel@tonic-gate 		return (sfcap_1_val2str(val, str, len, fmt, mach));
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate 	return (CAP_ERR_UNKTAG);
308*0Sstevel@tonic-gate }
309*0Sstevel@tonic-gate 
310*0Sstevel@tonic-gate /*
311*0Sstevel@tonic-gate  * Determine a capabilities value from a capabilities string.
312*0Sstevel@tonic-gate  */
313*0Sstevel@tonic-gate static uint64_t
314*0Sstevel@tonic-gate value(const char *str, const Cap_desc *cdp, uint_t cnum)
315*0Sstevel@tonic-gate {
316*0Sstevel@tonic-gate 	uint_t	num;
317*0Sstevel@tonic-gate 
318*0Sstevel@tonic-gate 	for (num = 0; num < cnum; num++) {
319*0Sstevel@tonic-gate 		if (strcmp(str, cdp[num].c_str) == 0)
320*0Sstevel@tonic-gate 			return (cdp[num].c_val);
321*0Sstevel@tonic-gate 	}
322*0Sstevel@tonic-gate 	return (0);
323*0Sstevel@tonic-gate }
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate uint64_t
326*0Sstevel@tonic-gate sfcap_1_str2val(const char *str, ushort_t mach)
327*0Sstevel@tonic-gate {
328*0Sstevel@tonic-gate 	return (value(str, &sf1[0], sf1_num));
329*0Sstevel@tonic-gate }
330*0Sstevel@tonic-gate 
331*0Sstevel@tonic-gate uint64_t
332*0Sstevel@tonic-gate hwcap_1_str2val(const char *str, ushort_t mach)
333*0Sstevel@tonic-gate {
334*0Sstevel@tonic-gate 	if ((mach == EM_386) || (mach == EM_IA_64) || (mach == EM_AMD64))
335*0Sstevel@tonic-gate 		return (value(str, &hw1_i[0], hw1_i_num));
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate 	if ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
338*0Sstevel@tonic-gate 	    (mach == EM_SPARCV9))
339*0Sstevel@tonic-gate 		return (value(str, &hw1_s[0], hw1_s_num));
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate 	return (0);
342*0Sstevel@tonic-gate }
343