xref: /titanic_53/usr/src/cmd/sgs/include/conv.h (revision 3244bcaa97c6de4c5692dd87485de1ef73364ab5)
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
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * 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  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
257c478bd9Sstevel@tonic-gate  *
2602ca3e02Srie  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef	_CONV_H
317c478bd9Sstevel@tonic-gate #define	_CONV_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Global include file for conversion library.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <stdlib.h>
407c478bd9Sstevel@tonic-gate #include <libelf.h>
417c478bd9Sstevel@tonic-gate #include <dlfcn.h>
427c478bd9Sstevel@tonic-gate #include <libld.h>
437c478bd9Sstevel@tonic-gate #include <sgs.h>
447c478bd9Sstevel@tonic-gate #include <machdep.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Configuration features available - maintained here (instead of debug.h)
527c478bd9Sstevel@tonic-gate  * to save libconv from having to include debug.h which results in numerous
537c478bd9Sstevel@tonic-gate  * "declared but not used or defined" lint errors.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	CONF_EDLIBPATH	0x000100	/* ELF default library path */
567c478bd9Sstevel@tonic-gate #define	CONF_ESLIBPATH	0x000200	/* ELF secure library path */
577c478bd9Sstevel@tonic-gate #define	CONF_ADLIBPATH	0x000400	/* AOUT default library path */
587c478bd9Sstevel@tonic-gate #define	CONF_ASLIBPATH	0x000800	/* AOUT secure library path */
597c478bd9Sstevel@tonic-gate #define	CONF_DIRCFG	0x001000	/* directory configuration available */
607c478bd9Sstevel@tonic-gate #define	CONF_OBJALT	0x002000	/* object alternatives available */
617c478bd9Sstevel@tonic-gate #define	CONF_MEMRESV	0x004000	/* memory reservation required */
627c478bd9Sstevel@tonic-gate #define	CONF_ENVS	0x008000	/* environment variables available */
637c478bd9Sstevel@tonic-gate #define	CONF_FLTR	0x010000	/* filter information available */
647c478bd9Sstevel@tonic-gate #define	CONF_FEATMSK	0xffff00
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
675aefb655Srie  * Various values that can't be matched to a symbolic definition are converted
685aefb655Srie  * to a numeric string.  Each function that may require this fallback maintains
695aefb655Srie  * its own static string buffer, as many conversion routines may be called for
705aefb655Srie  * one final diagnostic.  See conv_invalid_val().
715aefb655Srie  *
725aefb655Srie  * The string size reflects the largest possible decimal number plus a trailing
735aefb655Srie  * null.  Typically however, values are hex with a leading "0x".
745aefb655Srie  */
755aefb655Srie #if	defined(_ELF64)
765aefb655Srie #define	CONV_INV_STRSIZE	22
775aefb655Srie #else
785aefb655Srie #define	CONV_INV_STRSIZE	12
795aefb655Srie #endif
805aefb655Srie 
815aefb655Srie /*
822926dd2eSrie  * Some libconv routines require the caller to supply the buffer used by
832926dd2eSrie  * conv_invalid_val().
842926dd2eSrie  */
852926dd2eSrie typedef char Conv_inv_buf_t[CONV_INV_STRSIZE];
862926dd2eSrie 
872926dd2eSrie /*
88c13de8f6Sab196087  * Flags that alter standard formatting for conversion routines.
895aefb655Srie  */
90ba4e3c84Sab196087 #define	CONV_FMT_DECIMAL	0x01	/* conv_invalid_val() should print */
91c13de8f6Sab196087 					/*    integer print as decimal */
92c13de8f6Sab196087 					/*    (default is hex) */
93ba4e3c84Sab196087 #define	CONV_FMT_SPACE		0x02	/* conv_invalid_val() should append */
94c13de8f6Sab196087 					/*    a space after the number.  */
95ba4e3c84Sab196087 #define	CONV_FMT_ALTDUMP	0x04	/* Output strings using the versions */
96c13de8f6Sab196087 					/*    used by the dump program. */
97ba4e3c84Sab196087 #define	CONV_FMT_ALTFILE	0x08	/* Output strings in the form used */
98c13de8f6Sab196087 					/*    by the file(1) command */
99ba4e3c84Sab196087 #define	CONV_FMT_ALTCRLE	0x10	/* Output strings in the form used */
100ba4e3c84Sab196087 					/*    by the crle(1) command */
101c13de8f6Sab196087 
102c13de8f6Sab196087 /*
103c13de8f6Sab196087  * Mask of CONV_FMT bits that reflect a desire to use alternate strings.
104c13de8f6Sab196087  */
105c13de8f6Sab196087 #define	CONV_FMTALTMASK	(CONV_FMT_ALTDUMP | CONV_FMT_ALTFILE)
1065aefb655Srie 
1075aefb655Srie /*
1085aefb655Srie  * The expansion of bit-field data items is driven from a value descriptor and
1095aefb655Srie  * the conv_expn_field() routine.
1105aefb655Srie  */
1115aefb655Srie typedef struct {
1125aefb655Srie 	Xword		v_val;		/* expansion value */
1135aefb655Srie 	const char	*v_msg;		/* associated message string */
1145aefb655Srie } Val_desc;
1155aefb655Srie 
1165aefb655Srie /*
117ba4e3c84Sab196087  * conv_expn_field() is willing to supply default strings for the
118ba4e3c84Sab196087  * prefix, separator, and suffix arguments, if they are passed as NULL.
119ba4e3c84Sab196087  * The caller needs to know how much room to allow for these items.
120ba4e3c84Sab196087  * These values supply those sizes.
121ba4e3c84Sab196087  */
122ba4e3c84Sab196087 #define	CONV_EXPN_FIELD_DEF_PREFIX_SIZE	2	/* Default is "[ " */
123ba4e3c84Sab196087 #define	CONV_EXPN_FIELD_DEF_SEP_SIZE	1	/* Default is " " */
124ba4e3c84Sab196087 #define	CONV_EXPN_FIELD_DEF_SUFFIX_SIZE	2	/* Default is " ]" */
125ba4e3c84Sab196087 
126ba4e3c84Sab196087 /*
127ba4e3c84Sab196087  * conv_expn_field() requires a large number of inputs, many of which
128ba4e3c84Sab196087  * can be NULL to accept default behavior. An argument of the following
129ba4e3c84Sab196087  * type is used to supply them.
130ba4e3c84Sab196087  */
131ba4e3c84Sab196087 typedef struct {
132ba4e3c84Sab196087 	char *buf;		/* Buffer to receive generated string */
133ba4e3c84Sab196087 	size_t bufsize;		/* sizeof(buf) */
134ba4e3c84Sab196087 	const Val_desc *vdp;	/* Array of value descriptors, giving the */
135ba4e3c84Sab196087 				/*	possible bit values, and their */
136ba4e3c84Sab196087 				/*	corresponding strings. Note that the */
137ba4e3c84Sab196087 				/*	final element must contain only NULL */
138ba4e3c84Sab196087 				/*	values. This terminates the list. */
139ba4e3c84Sab196087 	const char **lead_str;	/* NULL, or array of pointers to strings to */
140ba4e3c84Sab196087 				/*	be output at the head of the list. */
141ba4e3c84Sab196087 				/*	Last entry must be NULL. */
142ba4e3c84Sab196087 	Xword oflags;		/* Bits for which output strings are desired */
143ba4e3c84Sab196087 	Xword rflags;		/* Bits for which a numeric value should be */
144ba4e3c84Sab196087 				/*	output if vdp does not provide str. */
145ba4e3c84Sab196087 				/*	Must be a proper subset of oflags */
146ba4e3c84Sab196087 	const char *prefix;	/* NULL, or string to prefix output with */
147ba4e3c84Sab196087 				/*	If NULL, "[ " is used. */
148ba4e3c84Sab196087 	const char *sep;	/* NULL, or string to separate output items */
149ba4e3c84Sab196087 				/*	with. If NULL, " " is used. */
150ba4e3c84Sab196087 	const char *suffix;	/* NULL, or string to suffix output with */
151ba4e3c84Sab196087 				/*	If NULL, " ]" is used. */
152ba4e3c84Sab196087 } CONV_EXPN_FIELD_ARG;
153ba4e3c84Sab196087 
154ba4e3c84Sab196087 /*
1555aefb655Srie  * Define all generic interfaces.
1567c478bd9Sstevel@tonic-gate  */
1577010c12aSrie extern	uchar_t		conv_check_native(char **, char **);
1585aefb655Srie extern	const char	*conv_config_feat(int);
1597c478bd9Sstevel@tonic-gate extern	const char	*conv_config_obj(ushort_t);
1605aefb655Srie extern	const char	*conv_config_upm(const char *, const char *,
1615aefb655Srie 			    const char *, size_t);
1625aefb655Srie extern	const char	*conv_def_tag(Symref);
1635aefb655Srie extern	const char	*conv_demangle_name(const char *);
1645aefb655Srie extern	const char	*conv_dl_flag(int, int);
1655aefb655Srie extern	const char	*conv_dl_mode(int, int);
1665aefb655Srie extern	const char	*conv_dwarf_ehe(uint_t);
1675aefb655Srie extern	const char	*conv_elfdata_type(Elf_Type);
1685aefb655Srie extern	const char	*conv_grphdl_flags(uint_t);
16902ca3e02Srie extern	const char	*conv_grpdesc_flags(uint_t);
1707c478bd9Sstevel@tonic-gate extern	Isa_desc	*conv_isalist(void);
1717c478bd9Sstevel@tonic-gate extern	const char	*conv_lddstub(int);
1725aefb655Srie extern	const char	*conv_seg_flags(Half);
1737c478bd9Sstevel@tonic-gate extern	int		conv_sys_eclass();
1747c478bd9Sstevel@tonic-gate extern	Uts_desc	*conv_uts(void);
1755aefb655Srie extern	const char	*conv_ver_flags(Half);
1765aefb655Srie 
1775aefb655Srie /*
1785aefb655Srie  * Define all class specific routines.
1795aefb655Srie  */
1805aefb655Srie #if	defined(_ELF64)
1815aefb655Srie #define	conv_bnd_obj		conv64_bnd_obj
1825aefb655Srie #define	conv_bnd_type		conv64_bnd_type
1835aefb655Srie #define	conv_cap_tag		conv64_cap_tag
1845aefb655Srie #define	conv_cap_val		conv64_cap_val
1855aefb655Srie #define	conv_cap_val_hw1	conv64_cap_val_hw1
1865aefb655Srie #define	conv_cap_val_sf1	conv64_cap_val_sf1
1875aefb655Srie #define	conv_dyn_feature1	conv64_dyn_feature1
1885aefb655Srie #define	conv_dyn_flag1		conv64_dyn_flag1
1895aefb655Srie #define	conv_dyn_flag		conv64_dyn_flag
1905aefb655Srie #define	conv_dyn_posflag1	conv64_dyn_posflag1
1915aefb655Srie #define	conv_dyn_tag		conv64_dyn_tag
1925aefb655Srie #define	conv_ehdr_class		conv64_ehdr_class
1935aefb655Srie #define	conv_ehdr_data		conv64_ehdr_data
1945aefb655Srie #define	conv_ehdr_flags		conv64_ehdr_flags
1955aefb655Srie #define	conv_ehdr_mach		conv64_ehdr_mach
196*3244bcaaSab196087 #define	conv_ehdr_osabi		conv64_ehdr_osabi
1975aefb655Srie #define	conv_ehdr_type		conv64_ehdr_type
1985aefb655Srie #define	conv_ehdr_vers		conv64_ehdr_vers
1995aefb655Srie #define	conv_expn_field		conv64_expn_field
2005aefb655Srie #define	conv_invalid_val	conv64_invalid_val
2015aefb655Srie #define	conv_phdr_flags		conv64_phdr_flags
2025aefb655Srie #define	conv_phdr_type		conv64_phdr_type
2035aefb655Srie #define	conv_reject_desc	conv64_reject_desc
2045aefb655Srie #define	conv_reloc_type		conv64_reloc_type
2055aefb655Srie #define	conv_reloc_386_type	conv64_reloc_386_type
2065aefb655Srie #define	conv_reloc_amd64_type	conv64_reloc_amd64_type
2075aefb655Srie #define	conv_reloc_SPARC_type	conv64_reloc_SPARC_type
2085aefb655Srie #define	conv_sec_flags		conv64_sec_flags
2097010c12aSrie #define	conv_sec_linkinfo	conv64_sec_linkinfo
2105aefb655Srie #define	conv_sec_type		conv64_sec_type
2115aefb655Srie #define	conv_sym_info_bind	conv64_sym_info_bind
2125aefb655Srie #define	conv_sym_info_type	conv64_sym_info_type
2135aefb655Srie #define	conv_sym_shndx		conv64_sym_shndx
2145aefb655Srie #define	conv_sym_other		conv64_sym_other
2155aefb655Srie #define	conv_sym_value		conv64_sym_value
2165aefb655Srie #define	conv_sym_SPARC_value	conv64_sym_SPARC_value
2175aefb655Srie #else
2185aefb655Srie #define	conv_bnd_obj		conv32_bnd_obj
2195aefb655Srie #define	conv_bnd_type		conv32_bnd_type
2205aefb655Srie #define	conv_cap_tag		conv32_cap_tag
2215aefb655Srie #define	conv_cap_val		conv32_cap_val
2225aefb655Srie #define	conv_cap_val_hw1	conv32_cap_val_hw1
2235aefb655Srie #define	conv_cap_val_sf1	conv32_cap_val_sf1
2245aefb655Srie #define	conv_dyn_feature1	conv32_dyn_feature1
2255aefb655Srie #define	conv_dyn_flag1		conv32_dyn_flag1
2265aefb655Srie #define	conv_dyn_flag		conv32_dyn_flag
2275aefb655Srie #define	conv_dyn_posflag1	conv32_dyn_posflag1
2285aefb655Srie #define	conv_dyn_tag		conv32_dyn_tag
2295aefb655Srie #define	conv_ehdr_class		conv32_ehdr_class
2305aefb655Srie #define	conv_ehdr_data		conv32_ehdr_data
2315aefb655Srie #define	conv_ehdr_flags		conv32_ehdr_flags
2325aefb655Srie #define	conv_ehdr_mach		conv32_ehdr_mach
233*3244bcaaSab196087 #define	conv_ehdr_osabi		conv32_ehdr_osabi
2345aefb655Srie #define	conv_ehdr_type		conv32_ehdr_type
2355aefb655Srie #define	conv_ehdr_vers		conv32_ehdr_vers
2365aefb655Srie #define	conv_expn_field		conv32_expn_field
2375aefb655Srie #define	conv_invalid_val	conv32_invalid_val
2385aefb655Srie #define	conv_phdr_flags		conv32_phdr_flags
2395aefb655Srie #define	conv_phdr_type		conv32_phdr_type
2405aefb655Srie #define	conv_reject_desc	conv32_reject_desc
2415aefb655Srie #define	conv_reloc_type		conv32_reloc_type
2425aefb655Srie #define	conv_reloc_386_type	conv32_reloc_386_type
2435aefb655Srie #define	conv_reloc_amd64_type	conv32_reloc_amd64_type
2445aefb655Srie #define	conv_reloc_SPARC_type	conv32_reloc_SPARC_type
2455aefb655Srie #define	conv_sec_flags		conv32_sec_flags
2467010c12aSrie #define	conv_sec_linkinfo	conv32_sec_linkinfo
2475aefb655Srie #define	conv_sec_type		conv32_sec_type
2485aefb655Srie #define	conv_sym_info_bind	conv32_sym_info_bind
2495aefb655Srie #define	conv_sym_info_type	conv32_sym_info_type
2505aefb655Srie #define	conv_sym_shndx		conv32_sym_shndx
2515aefb655Srie #define	conv_sym_other		conv32_sym_other
2525aefb655Srie #define	conv_sym_value		conv32_sym_value
2535aefb655Srie #define	conv_sym_SPARC_value	conv32_sym_SPARC_value
2545aefb655Srie #endif
2555aefb655Srie 
2565aefb655Srie extern	const char	*conv_bnd_obj(uint_t);
2575aefb655Srie extern	const char	*conv_bnd_type(uint_t);
2585aefb655Srie extern	const char	*conv_cap_tag(Xword);
2595aefb655Srie extern	const char	*conv_cap_val(Xword, Xword, Half);
2605aefb655Srie extern	const char	*conv_cap_val_hw1(Xword, Half);
2615aefb655Srie extern	const char	*conv_cap_val_sf1(Xword, Half);
2625aefb655Srie extern	const char	*conv_dyn_flag1(Xword);
263ba4e3c84Sab196087 extern	const char	*conv_dyn_flag(Xword, int);
264ba4e3c84Sab196087 extern	const char	*conv_dyn_posflag1(Xword, int);
265c13de8f6Sab196087 extern	const char	*conv_dyn_tag(Xword, Half, int);
266ba4e3c84Sab196087 extern	const char	*conv_dyn_feature1(Xword, int);
267c13de8f6Sab196087 extern	const char	*conv_ehdr_class(uchar_t, int);
268c13de8f6Sab196087 extern	const char	*conv_ehdr_data(uchar_t, int);
2695aefb655Srie extern	const char	*conv_ehdr_flags(Half, Word);
270c13de8f6Sab196087 extern	const char	*conv_ehdr_mach(Half, int);
271*3244bcaaSab196087 extern	const char	*conv_ehdr_osabi(uchar_t, int);
272c13de8f6Sab196087 extern	const char	*conv_ehdr_type(Half, int);
273c13de8f6Sab196087 extern	const char	*conv_ehdr_vers(Word, int);
274ba4e3c84Sab196087 extern	int		conv_expn_field(CONV_EXPN_FIELD_ARG *);
2755aefb655Srie extern	const char	*conv_invalid_val(char *, size_t, Xword, int);
2765aefb655Srie extern	const char	*conv_phdr_flags(Word);
2775aefb655Srie extern	const char	*conv_phdr_type(Half, Word);
2785aefb655Srie extern	const char	*conv_reject_desc(Rej_desc *);
279c13de8f6Sab196087 extern	const char	*conv_reloc_type(Half, Word, int);
280c13de8f6Sab196087 extern	const char	*conv_reloc_386_type(Word, int);
281c13de8f6Sab196087 extern	const char	*conv_reloc_amd64_type(Word, int);
282c13de8f6Sab196087 extern	const char	*conv_reloc_SPARC_type(Word, int);
2835aefb655Srie extern	const char	*conv_sec_flags(Xword);
2842926dd2eSrie extern	const char	*conv_sec_linkinfo(Word, Xword, Conv_inv_buf_t);
285c13de8f6Sab196087 extern	const char	*conv_sec_type(Half, Word, int);
286c13de8f6Sab196087 extern	const char	*conv_sym_info_bind(uchar_t, int);
287c13de8f6Sab196087 extern	const char	*conv_sym_info_type(Half, uchar_t, int);
2885aefb655Srie extern	const char	*conv_sym_shndx(Half);
2895aefb655Srie extern	const char	*conv_sym_other(uchar_t);
2905aefb655Srie extern	const char	*conv_sym_value(Half, uchar_t, Addr);
291c13de8f6Sab196087 extern	const char	*conv_sym_SPARC_value(Addr, int);
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate #endif
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate #endif /* _CONV_H */
298