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