xref: /titanic_50/usr/src/common/elfcap/elfcap.h (revision 99f63845ee65f89a523460ce4b6b0603a06eceb7)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*99f63845Sab196087  * Common Development and Distribution License (the "License").
6*99f63845Sab196087  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*99f63845Sab196087  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _ELFCAP_DOT_H
277c478bd9Sstevel@tonic-gate #define	_ELFCAP_DOT_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
38*99f63845Sab196087  * The elfcap code handles mappings to and from several string styles.
39*99f63845Sab196087  * The caller uses elfcap_style_t to specify the style to use.
40*99f63845Sab196087  */
41*99f63845Sab196087 typedef enum {
42*99f63845Sab196087 	ELFCAP_STYLE_FULL =	1,	/* Full formal name (e.g. AV_386_SSE) */
43*99f63845Sab196087 	ELFCAP_STYLE_UC = 	2,	/* Informal upper case (e.g. SSE) */
44*99f63845Sab196087 	ELFCAP_STYLE_LC = 	3	/* Informal lower case (e.g. sse) */
45*99f63845Sab196087 } elfcap_style_t;
46*99f63845Sab196087 
47*99f63845Sab196087 /*
48*99f63845Sab196087  * String descriptor: Contains the string and strlen(string). elfcap can
49*99f63845Sab196087  * be used in contexts (ld.so.1) where we do not want to make calls to
50*99f63845Sab196087  * string processing functions, so the length is calculated at compile time.
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate typedef	struct {
53*99f63845Sab196087 	const char	*s_str;
54*99f63845Sab196087 	size_t		s_len;
55*99f63845Sab196087 } elfcap_str_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
58*99f63845Sab196087  * Capabilities descriptor: This maps the integer bit value
59*99f63845Sab196087  * (c_val) to/from the various strings that represent it.
60*99f63845Sab196087  *
61*99f63845Sab196087  * c_val is normally expected to be a non-zero power of 2
62*99f63845Sab196087  * value (i.e. a single set bit). The value 0 is special, and
63*99f63845Sab196087  * used to represent a "reserved" placeholder in an array of
64*99f63845Sab196087  * capabilities. These reserved values have NULL string pointers,
65*99f63845Sab196087  * and are intended to be ignored by the processing code.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate typedef	struct {
68*99f63845Sab196087 	uint64_t	c_val;		/* Bit value */
69*99f63845Sab196087 	elfcap_str_t	c_full;		/* ELFCAP_STYLE_FULL */
70*99f63845Sab196087 	elfcap_str_t	c_uc;		/* ELFCAP_STYLE_UC */
71*99f63845Sab196087 	elfcap_str_t	c_lc;		/* ELFCAP_STYLE_LC */
72*99f63845Sab196087 } elfcap_desc_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
75*99f63845Sab196087  * Valid format values: The various formats in which a generated
76*99f63845Sab196087  * string representing bitmap values can be displayed.
77*99f63845Sab196087  *
78*99f63845Sab196087  * This must be kept in sync with the format[] array in elfcap.c.
797c478bd9Sstevel@tonic-gate  */
80*99f63845Sab196087 typedef enum {
81*99f63845Sab196087 	ELFCAP_FMT_SNGSPACE =		0,
82*99f63845Sab196087 	ELFCAP_FMT_DBLSPACE =		1,
83*99f63845Sab196087 	ELFCAP_FMT_PIPSPACE =		2
84*99f63845Sab196087 } elfcap_fmt_t;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
87*99f63845Sab196087  * Error codes:
887c478bd9Sstevel@tonic-gate  */
89*99f63845Sab196087 typedef enum {
90*99f63845Sab196087 	ELFCAP_ERR_NONE =		0,	/* no error */
91*99f63845Sab196087 	ELFCAP_ERR_BUFOVFL =		1,	/* buffer overfow */
92*99f63845Sab196087 	ELFCAP_ERR_INVFMT =		2,	/* invalid format */
93*99f63845Sab196087 	ELFCAP_ERR_UNKTAG =		3,	/* unknown capabilities tag */
94*99f63845Sab196087 	ELFCAP_ERR_UNKMACH =		4,	/* unknown machine type */
95*99f63845Sab196087 	ELFCAP_ERR_INVSTYLE =		5	/* unknown style */
96*99f63845Sab196087 } elfcap_err_t;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 
99*99f63845Sab196087 /*
100*99f63845Sab196087  * # of each type of capability known to the system. These values
101*99f63845Sab196087  * must be kept in sync with the arrays found in elfcap.c
102*99f63845Sab196087  */
103*99f63845Sab196087 #define	ELFCAP_NUM_SF1			2
104*99f63845Sab196087 #define	ELFCAP_NUM_HW1_SPARC		16
105*99f63845Sab196087 #define	ELFCAP_NUM_HW1_386		25
106*99f63845Sab196087 
107*99f63845Sab196087 
108*99f63845Sab196087 /*
109*99f63845Sab196087  * Given a capability section tag and value, call the proper underlying
110*99f63845Sab196087  * "to str" function to generate the string description.
111*99f63845Sab196087  */
112*99f63845Sab196087 extern elfcap_err_t elfcap_tag_to_str(elfcap_style_t, uint64_t,
113*99f63845Sab196087     uint64_t, char *, size_t, elfcap_fmt_t, ushort_t);
114*99f63845Sab196087 
115*99f63845Sab196087 /*
116*99f63845Sab196087  * The functions that convert from a specific capability value to
117*99f63845Sab196087  * a string representation all use the same common prototype.
118*99f63845Sab196087  */
119*99f63845Sab196087 typedef elfcap_err_t elfcap_to_str_func_t(elfcap_style_t, uint64_t, char *,
120*99f63845Sab196087     size_t, elfcap_fmt_t, ushort_t);
121*99f63845Sab196087 
122*99f63845Sab196087 extern elfcap_to_str_func_t elfcap_hw1_to_str;
123*99f63845Sab196087 extern elfcap_to_str_func_t elfcap_sf1_to_str;
124*99f63845Sab196087 
125*99f63845Sab196087 /*
126*99f63845Sab196087  * The reverse mapping: Given a string representation, turn it back into
127*99f63845Sab196087  * integer form.
128*99f63845Sab196087  */
129*99f63845Sab196087 typedef uint64_t elfcap_from_str_func_t(elfcap_style_t,
130*99f63845Sab196087     const char *, ushort_t mach);
131*99f63845Sab196087 
132*99f63845Sab196087 extern elfcap_from_str_func_t elfcap_hw1_from_str;
133*99f63845Sab196087 extern elfcap_from_str_func_t elfcap_sf1_from_str;
134*99f63845Sab196087 
135*99f63845Sab196087 /*
136*99f63845Sab196087  * These functions give access to the individual descriptor arrays.
137*99f63845Sab196087  * The caller is allowed to copy and use the string pointers contained
138*99f63845Sab196087  * in the descriptors, but must not alter them. Functions are used instead
139*99f63845Sab196087  * of making the arrays directly visible to preclude copy relocations in
140*99f63845Sab196087  * non-pic code.
141*99f63845Sab196087  */
142*99f63845Sab196087 extern const elfcap_desc_t *elfcap_getdesc_hw1_sparc(void);
143*99f63845Sab196087 extern const elfcap_desc_t *elfcap_getdesc_hw1_386(void);
144*99f63845Sab196087 extern const elfcap_desc_t *elfcap_getdesc_sf1(void);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate #endif
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #endif /* _ELFCAP_DOT_H */
151