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