xref: /titanic_51/usr/src/cmd/sgs/include/conv.h (revision e1a4a99e6f424cd8d62deb51dccd37f0406e7204)
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 (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #ifndef	_CONV_H
31 #define	_CONV_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 /*
36  * Global include file for conversion library.
37  */
38 
39 #include <stdlib.h>
40 #include <libelf.h>
41 #include <dlfcn.h>
42 #include <libld.h>
43 #include <sgs.h>
44 #include <machdep.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 /*
51  * Configuration features available - maintained here (instead of debug.h)
52  * to save libconv from having to include debug.h which results in numerous
53  * "declared but not used or defined" lint errors.
54  */
55 #define	CONF_EDLIBPATH	0x000100	/* ELF default library path */
56 #define	CONF_ESLIBPATH	0x000200	/* ELF secure library path */
57 #define	CONF_ADLIBPATH	0x000400	/* AOUT default library path */
58 #define	CONF_ASLIBPATH	0x000800	/* AOUT secure library path */
59 #define	CONF_DIRCFG	0x001000	/* directory configuration available */
60 #define	CONF_OBJALT	0x002000	/* object alternatives available */
61 #define	CONF_MEMRESV	0x004000	/* memory reservation required */
62 #define	CONF_ENVS	0x008000	/* environment variables available */
63 #define	CONF_FLTR	0x010000	/* filter information available */
64 #define	CONF_FEATMSK	0xffff00
65 
66 /*
67  * Various values that can't be matched to a symbolic definition are converted
68  * to a numeric string.  Each function that may require this fallback maintains
69  * its own static string buffer, as many conversion routines may be called for
70  * one final diagnostic.  See conv_invalid_val().
71  *
72  * The string size reflects the largest possible decimal number plus a trailing
73  * null.  Typically however, values are hex with a leading "0x".
74  */
75 #if	defined(_ELF64)
76 #define	CONV_INV_STRSIZE	22
77 #else
78 #define	CONV_INV_STRSIZE	12
79 #endif
80 
81 /*
82  * Flags that alter standard formatting for conversion routines.
83  */
84 #define	CONV_FMT_DECIMAL	0x01	/* conv_invalid_val() should print */
85 					/*    integer print as decimal */
86 					/*    (default is hex) */
87 #define	CONV_FMT_SPACE		0x02	/* conv_invalid_val() should append */
88 					/*    a space after the number.  */
89 #define	CONV_FMT_ALTDUMP	0x04	/* Output strings using the versions */
90 					/*    used by the dump program. */
91 #define	CONV_FMT_ALTFILE	0x08	/* Output strings in the form used */
92 					/*    by the file(1) command */
93 #define	CONV_FMT_ALTCRLE	0x10	/* Output strings in the form used */
94 					/*    by the crle(1) command */
95 
96 /*
97  * Mask of CONV_FMT bits that reflect a desire to use alternate strings.
98  */
99 #define	CONV_FMTALTMASK (CONV_FMT_ALTDUMP|CONV_FMT_ALTFILE)
100 
101 /*
102  * The expansion of bit-field data items is driven from a value descriptor and
103  * the conv_expn_field() routine.
104  */
105 typedef struct {
106 	Xword		v_val;		/* expansion value */
107 	const char	*v_msg;		/* associated message string */
108 } Val_desc;
109 
110 /*
111  * conv_expn_field() is willing to supply default strings for the
112  * prefix, separator, and suffix arguments, if they are passed as NULL.
113  * The caller needs to know how much room to allow for these items.
114  * These values supply those sizes.
115  */
116 #define	CONV_EXPN_FIELD_DEF_PREFIX_SIZE	2	/* Default is "[ " */
117 #define	CONV_EXPN_FIELD_DEF_SEP_SIZE	1	/* Default is " " */
118 #define	CONV_EXPN_FIELD_DEF_SUFFIX_SIZE	2	/* Default is " ]" */
119 
120 
121 /*
122  * conv_expn_field() requires a large number of inputs, many of which
123  * can be NULL to accept default behavior. An argument of the following
124  * type is used to supply them.
125  */
126 typedef struct {
127 	char *buf;		/* Buffer to receive generated string */
128 	size_t bufsize;		/* sizeof(buf) */
129 	const Val_desc *vdp;	/* Array of value descriptors, giving the */
130 				/*	possible bit values, and their */
131 				/*	corresponding strings. Note that the */
132 				/*	final element must contain only NULL */
133 				/*	values. This terminates the list. */
134 	const char **lead_str;	/* NULL, or array of pointers to strings to */
135 				/*	be output at the head of the list. */
136 				/*	Last entry must be NULL. */
137 	Xword oflags;		/* Bits for which output strings are desired */
138 	Xword rflags;		/* Bits for which a numeric value should be */
139 				/*	output if vdp does not provide str. */
140 				/*	Must be a proper subset of oflags */
141 	const char *prefix;	/* NULL, or string to prefix output with */
142 				/*	If NULL, "[ " is used. */
143 	const char *sep;	/* NULL, or string to separate output items */
144 				/*	with. If NULL, " " is used. */
145 	const char *suffix;	/* NULL, or string to suffix output with */
146 				/*	If NULL, " ]" is used. */
147 } CONV_EXPN_FIELD_ARG;
148 
149 
150 /*
151  * Define all generic interfaces.
152  */
153 extern	void		conv_check_native(char **, char **);
154 extern	const char	*conv_config_feat(int);
155 extern	const char	*conv_config_obj(ushort_t);
156 extern	const char	*conv_config_upm(const char *, const char *,
157 			    const char *, size_t);
158 extern	const char	*conv_def_tag(Symref);
159 extern	const char	*conv_demangle_name(const char *);
160 extern	const char	*conv_dl_flag(int, int);
161 extern	const char	*conv_dl_mode(int, int);
162 extern	const char	*conv_dwarf_ehe(uint_t);
163 extern	const char	*conv_elfdata_type(Elf_Type);
164 extern	const char	*conv_grphdl_flags(uint_t);
165 extern	Isa_desc	*conv_isalist(void);
166 extern	const char	*conv_lddstub(int);
167 extern	const char	*conv_seg_flags(Half);
168 extern	int		conv_sys_eclass();
169 extern	Uts_desc	*conv_uts(void);
170 extern	const char	*conv_ver_flags(Half);
171 
172 /*
173  * Define all class specific routines.
174  */
175 #if	defined(_ELF64)
176 #define	conv_bnd_obj		conv64_bnd_obj
177 #define	conv_bnd_type		conv64_bnd_type
178 #define	conv_cap_tag		conv64_cap_tag
179 #define	conv_cap_val		conv64_cap_val
180 #define	conv_cap_val_hw1	conv64_cap_val_hw1
181 #define	conv_cap_val_sf1	conv64_cap_val_sf1
182 #define	conv_dyn_feature1	conv64_dyn_feature1
183 #define	conv_dyn_flag1		conv64_dyn_flag1
184 #define	conv_dyn_flag		conv64_dyn_flag
185 #define	conv_dyn_posflag1	conv64_dyn_posflag1
186 #define	conv_dyn_tag		conv64_dyn_tag
187 #define	conv_ehdr_class		conv64_ehdr_class
188 #define	conv_ehdr_data		conv64_ehdr_data
189 #define	conv_ehdr_flags		conv64_ehdr_flags
190 #define	conv_ehdr_mach		conv64_ehdr_mach
191 #define	conv_ehdr_type		conv64_ehdr_type
192 #define	conv_ehdr_vers		conv64_ehdr_vers
193 #define	conv_expn_field		conv64_expn_field
194 #define	conv_invalid_val	conv64_invalid_val
195 #define	conv_phdr_flags		conv64_phdr_flags
196 #define	conv_phdr_type		conv64_phdr_type
197 #define	conv_reject_desc	conv64_reject_desc
198 #define	conv_reloc_type		conv64_reloc_type
199 #define	conv_reloc_386_type	conv64_reloc_386_type
200 #define	conv_reloc_amd64_type	conv64_reloc_amd64_type
201 #define	conv_reloc_SPARC_type	conv64_reloc_SPARC_type
202 #define	conv_sec_flags		conv64_sec_flags
203 #define	conv_sec_info		conv64_sec_info
204 #define	conv_sec_type		conv64_sec_type
205 #define	conv_sym_info_bind	conv64_sym_info_bind
206 #define	conv_sym_info_type	conv64_sym_info_type
207 #define	conv_sym_shndx		conv64_sym_shndx
208 #define	conv_sym_other		conv64_sym_other
209 #define	conv_sym_value		conv64_sym_value
210 #define	conv_sym_SPARC_value	conv64_sym_SPARC_value
211 #else
212 #define	conv_bnd_obj		conv32_bnd_obj
213 #define	conv_bnd_type		conv32_bnd_type
214 #define	conv_cap_tag		conv32_cap_tag
215 #define	conv_cap_val		conv32_cap_val
216 #define	conv_cap_val_hw1	conv32_cap_val_hw1
217 #define	conv_cap_val_sf1	conv32_cap_val_sf1
218 #define	conv_dyn_feature1	conv32_dyn_feature1
219 #define	conv_dyn_flag1		conv32_dyn_flag1
220 #define	conv_dyn_flag		conv32_dyn_flag
221 #define	conv_dyn_posflag1	conv32_dyn_posflag1
222 #define	conv_dyn_tag		conv32_dyn_tag
223 #define	conv_ehdr_class		conv32_ehdr_class
224 #define	conv_ehdr_data		conv32_ehdr_data
225 #define	conv_ehdr_flags		conv32_ehdr_flags
226 #define	conv_ehdr_mach		conv32_ehdr_mach
227 #define	conv_ehdr_type		conv32_ehdr_type
228 #define	conv_ehdr_vers		conv32_ehdr_vers
229 #define	conv_expn_field		conv32_expn_field
230 #define	conv_invalid_val	conv32_invalid_val
231 #define	conv_phdr_flags		conv32_phdr_flags
232 #define	conv_phdr_type		conv32_phdr_type
233 #define	conv_reject_desc	conv32_reject_desc
234 #define	conv_reloc_type		conv32_reloc_type
235 #define	conv_reloc_386_type	conv32_reloc_386_type
236 #define	conv_reloc_amd64_type	conv32_reloc_amd64_type
237 #define	conv_reloc_SPARC_type	conv32_reloc_SPARC_type
238 #define	conv_sec_flags		conv32_sec_flags
239 #define	conv_sec_info		conv32_sec_info
240 #define	conv_sec_type		conv32_sec_type
241 #define	conv_sym_info_bind	conv32_sym_info_bind
242 #define	conv_sym_info_type	conv32_sym_info_type
243 #define	conv_sym_shndx		conv32_sym_shndx
244 #define	conv_sym_other		conv32_sym_other
245 #define	conv_sym_value		conv32_sym_value
246 #define	conv_sym_SPARC_value	conv32_sym_SPARC_value
247 #endif
248 
249 extern	const char	*conv_bnd_obj(uint_t);
250 extern	const char	*conv_bnd_type(uint_t);
251 extern	const char	*conv_cap_tag(Xword);
252 extern	const char	*conv_cap_val(Xword, Xword, Half);
253 extern	const char	*conv_cap_val_hw1(Xword, Half);
254 extern	const char	*conv_cap_val_sf1(Xword, Half);
255 extern	const char	*conv_dyn_flag1(Xword);
256 extern	const char	*conv_dyn_flag(Xword, int);
257 extern	const char	*conv_dyn_posflag1(Xword, int);
258 extern	const char	*conv_dyn_tag(Xword, Half, int);
259 extern	const char	*conv_dyn_feature1(Xword, int);
260 extern	const char	*conv_ehdr_class(uchar_t, int);
261 extern	const char	*conv_ehdr_data(uchar_t, int);
262 extern	const char	*conv_ehdr_flags(Half, Word);
263 extern	const char	*conv_ehdr_mach(Half, int);
264 extern	const char	*conv_ehdr_type(Half, int);
265 extern	const char	*conv_ehdr_vers(Word, int);
266 extern	int		conv_expn_field(CONV_EXPN_FIELD_ARG *);
267 extern	const char	*conv_invalid_val(char *, size_t, Xword, int);
268 extern	const char	*conv_phdr_flags(Word);
269 extern	const char	*conv_phdr_type(Half, Word);
270 extern	const char	*conv_reject_desc(Rej_desc *);
271 extern	const char	*conv_reloc_type(Half, Word, int);
272 extern	const char	*conv_reloc_386_type(Word, int);
273 extern	const char	*conv_reloc_amd64_type(Word, int);
274 extern	const char	*conv_reloc_SPARC_type(Word, int);
275 extern	const char	*conv_sec_flags(Xword);
276 extern	const char	*conv_sec_info(Word, Xword);
277 extern	const char	*conv_sec_type(Half, Word, int);
278 extern	const char	*conv_sym_info_bind(uchar_t, int);
279 extern	const char	*conv_sym_info_type(Half, uchar_t, int);
280 extern	const char	*conv_sym_shndx(Half);
281 extern	const char	*conv_sym_other(uchar_t);
282 extern	const char	*conv_sym_value(Half, uchar_t, Addr);
283 extern	const char	*conv_sym_SPARC_value(Addr, int);
284 
285 #ifdef	__cplusplus
286 }
287 #endif
288 
289 #endif /* _CONV_H */
290