10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55565Sab196087 * Common Development and Distribution License (the "License"). 65565Sab196087 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 217833SRod.Evans@Sun.COM 220Sstevel@tonic-gate /* 23*11734SAli.Bahrami@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _ELFCAP_DOT_H 280Sstevel@tonic-gate #define _ELFCAP_DOT_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <sys/types.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* 37*11734SAli.Bahrami@Sun.COM * Type used to represent capability bitmasks. This 32-bit type cannot be 38*11734SAli.Bahrami@Sun.COM * widened without breaking the ability to use them in ELFCLASS32 objects. 39*11734SAli.Bahrami@Sun.COM */ 40*11734SAli.Bahrami@Sun.COM typedef uint32_t elfcap_mask_t; 41*11734SAli.Bahrami@Sun.COM 42*11734SAli.Bahrami@Sun.COM /* 435565Sab196087 * The elfcap code handles mappings to and from several string styles. 445565Sab196087 * The caller uses elfcap_style_t to specify the style to use. 45*11734SAli.Bahrami@Sun.COM * 46*11734SAli.Bahrami@Sun.COM * The bottom 16 bits are used to represent styles, and the upper 16 47*11734SAli.Bahrami@Sun.COM * bits are used for flags to modify default behavior. 485565Sab196087 */ 49*11734SAli.Bahrami@Sun.COM #define ELFCAP_STYLE_MASK(_style) (_style & 0xff) 50*11734SAli.Bahrami@Sun.COM 515565Sab196087 typedef enum { 525565Sab196087 ELFCAP_STYLE_FULL = 1, /* Full formal name (e.g. AV_386_SSE) */ 535565Sab196087 ELFCAP_STYLE_UC = 2, /* Informal upper case (e.g. SSE) */ 54*11734SAli.Bahrami@Sun.COM ELFCAP_STYLE_LC = 3, /* Informal lower case (e.g. sse) */ 55*11734SAli.Bahrami@Sun.COM 56*11734SAli.Bahrami@Sun.COM ELFCAP_STYLE_F_ICMP = 0x0100 /* Use case insensitive strcmp */ 575565Sab196087 } elfcap_style_t; 585565Sab196087 595565Sab196087 /* 605565Sab196087 * String descriptor: Contains the string and strlen(string). elfcap can 615565Sab196087 * be used in contexts (ld.so.1) where we do not want to make calls to 625565Sab196087 * string processing functions, so the length is calculated at compile time. 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate typedef struct { 655565Sab196087 const char *s_str; 665565Sab196087 size_t s_len; 675565Sab196087 } elfcap_str_t; 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 705565Sab196087 * Capabilities descriptor: This maps the integer bit value 715565Sab196087 * (c_val) to/from the various strings that represent it. 725565Sab196087 * 735565Sab196087 * c_val is normally expected to be a non-zero power of 2 745565Sab196087 * value (i.e. a single set bit). The value 0 is special, and 755565Sab196087 * used to represent a "reserved" placeholder in an array of 765565Sab196087 * capabilities. These reserved values have NULL string pointers, 775565Sab196087 * and are intended to be ignored by the processing code. 780Sstevel@tonic-gate */ 795565Sab196087 typedef struct { 80*11734SAli.Bahrami@Sun.COM elfcap_mask_t c_val; /* Bit value */ 815565Sab196087 elfcap_str_t c_full; /* ELFCAP_STYLE_FULL */ 825565Sab196087 elfcap_str_t c_uc; /* ELFCAP_STYLE_UC */ 835565Sab196087 elfcap_str_t c_lc; /* ELFCAP_STYLE_LC */ 845565Sab196087 } elfcap_desc_t; 855565Sab196087 865565Sab196087 /* 875565Sab196087 * Valid format values: The various formats in which a generated 885565Sab196087 * string representing bitmap values can be displayed. 895565Sab196087 * 905565Sab196087 * This must be kept in sync with the format[] array in elfcap.c. 915565Sab196087 */ 925565Sab196087 typedef enum { 935565Sab196087 ELFCAP_FMT_SNGSPACE = 0, 945565Sab196087 ELFCAP_FMT_DBLSPACE = 1, 955565Sab196087 ELFCAP_FMT_PIPSPACE = 2 965565Sab196087 } elfcap_fmt_t; 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 995565Sab196087 * Error codes: 1000Sstevel@tonic-gate */ 1015565Sab196087 typedef enum { 1025565Sab196087 ELFCAP_ERR_NONE = 0, /* no error */ 1035565Sab196087 ELFCAP_ERR_BUFOVFL = 1, /* buffer overfow */ 1045565Sab196087 ELFCAP_ERR_INVFMT = 2, /* invalid format */ 1055565Sab196087 ELFCAP_ERR_UNKTAG = 3, /* unknown capabilities tag */ 1065565Sab196087 ELFCAP_ERR_UNKMACH = 4, /* unknown machine type */ 1075565Sab196087 ELFCAP_ERR_INVSTYLE = 5 /* unknown style */ 1085565Sab196087 } elfcap_err_t; 1095565Sab196087 1100Sstevel@tonic-gate 1115565Sab196087 /* 1125565Sab196087 * # of each type of capability known to the system. These values 1139878SAli.Bahrami@Sun.COM * must be kept in sync with the arrays found in elfcap.c. 1145565Sab196087 */ 1157833SRod.Evans@Sun.COM #define ELFCAP_NUM_SF1 3 1169202SJason.Beloro@Sun.COM #define ELFCAP_NUM_HW1_SPARC 17 1179370SKuriakose.Kuruvilla@Sun.COM #define ELFCAP_NUM_HW1_386 28 1185565Sab196087 1195565Sab196087 1205565Sab196087 /* 1215565Sab196087 * Given a capability section tag and value, call the proper underlying 1225565Sab196087 * "to str" function to generate the string description. 1235565Sab196087 */ 1245565Sab196087 extern elfcap_err_t elfcap_tag_to_str(elfcap_style_t, uint64_t, 125*11734SAli.Bahrami@Sun.COM elfcap_mask_t, char *, size_t, elfcap_fmt_t, ushort_t); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* 1285565Sab196087 * The functions that convert from a specific capability value to 1295565Sab196087 * a string representation all use the same common prototype. 1300Sstevel@tonic-gate */ 131*11734SAli.Bahrami@Sun.COM typedef elfcap_err_t elfcap_to_str_func_t(elfcap_style_t, elfcap_mask_t, char *, 1325565Sab196087 size_t, elfcap_fmt_t, ushort_t); 1335565Sab196087 1345565Sab196087 extern elfcap_to_str_func_t elfcap_hw1_to_str; 135*11734SAli.Bahrami@Sun.COM extern elfcap_to_str_func_t elfcap_hw2_to_str; 1365565Sab196087 extern elfcap_to_str_func_t elfcap_sf1_to_str; 1370Sstevel@tonic-gate 1385565Sab196087 /* 1395565Sab196087 * The reverse mapping: Given a string representation, turn it back into 1405565Sab196087 * integer form. 1415565Sab196087 */ 142*11734SAli.Bahrami@Sun.COM typedef elfcap_mask_t elfcap_from_str_func_t(elfcap_style_t, 1435565Sab196087 const char *, ushort_t mach); 1440Sstevel@tonic-gate 145*11734SAli.Bahrami@Sun.COM /* 146*11734SAli.Bahrami@Sun.COM * Given a capability section tag and string, call the proper underlying 147*11734SAli.Bahrami@Sun.COM * "from str" function to generate the numeric value. 148*11734SAli.Bahrami@Sun.COM */ 149*11734SAli.Bahrami@Sun.COM extern elfcap_mask_t elfcap_tag_from_str(elfcap_style_t, uint64_t, 150*11734SAli.Bahrami@Sun.COM const char *, ushort_t); 151*11734SAli.Bahrami@Sun.COM 1525565Sab196087 extern elfcap_from_str_func_t elfcap_hw1_from_str; 153*11734SAli.Bahrami@Sun.COM extern elfcap_from_str_func_t elfcap_hw2_from_str; 1545565Sab196087 extern elfcap_from_str_func_t elfcap_sf1_from_str; 1555565Sab196087 1565565Sab196087 /* 1575565Sab196087 * These functions give access to the individual descriptor arrays. 1585565Sab196087 * The caller is allowed to copy and use the string pointers contained 1595565Sab196087 * in the descriptors, but must not alter them. Functions are used instead 1605565Sab196087 * of making the arrays directly visible to preclude copy relocations in 1615565Sab196087 * non-pic code. 1625565Sab196087 */ 1635565Sab196087 extern const elfcap_desc_t *elfcap_getdesc_hw1_sparc(void); 1645565Sab196087 extern const elfcap_desc_t *elfcap_getdesc_hw1_386(void); 1655565Sab196087 extern const elfcap_desc_t *elfcap_getdesc_sf1(void); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate #ifdef __cplusplus 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate #endif 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #endif /* _ELFCAP_DOT_H */ 172