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 /* 2369112eddSAli Bahrami * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * String conversion routine for hardware capabilities types. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate #include <strings.h> 317c478bd9Sstevel@tonic-gate #include <stdio.h> 327c478bd9Sstevel@tonic-gate #include <elfcap.h> 337c478bd9Sstevel@tonic-gate #include "cap_msg.h" 34c13de8f6Sab196087 #include "_conv.h" 357c478bd9Sstevel@tonic-gate 364f680cc6SAli Bahrami const conv_ds_t ** 374f680cc6SAli Bahrami conv_cap_tag_strings(Conv_fmt_flags_t fmt_flags) 387c478bd9Sstevel@tonic-gate { 39*08278a5eSRod Evans #if (CA_SUNW_NUM != (CA_SUNW_ID + 1)) 4069112eddSAli Bahrami #error "CA_SUNW_NUM has grown" 4169112eddSAli Bahrami #endif 424f680cc6SAli Bahrami static const Msg tags_cf[] = { 434f680cc6SAli Bahrami MSG_CA_SUNW_NULL_CF, MSG_CA_SUNW_HW_1_CF, 44*08278a5eSRod Evans MSG_CA_SUNW_SF_1_CF, MSG_CA_SUNW_HW_2_CF, 45*08278a5eSRod Evans MSG_CA_SUNW_PLAT_CF, MSG_CA_SUNW_MACH_CF, 46*08278a5eSRod Evans MSG_CA_SUNW_ID_CF 474f680cc6SAli Bahrami }; 484f680cc6SAli Bahrami static const Msg tags_nf[] = { 494f680cc6SAli Bahrami MSG_CA_SUNW_NULL_NF, MSG_CA_SUNW_HW_1_NF, 5069112eddSAli Bahrami MSG_CA_SUNW_SF_1_NF, MSG_CA_SUNW_HW_2_NF, 51*08278a5eSRod Evans MSG_CA_SUNW_PLAT_NF, MSG_CA_SUNW_MACH_NF, 52*08278a5eSRod Evans MSG_CA_SUNW_ID_NF 534f680cc6SAli Bahrami }; 544f680cc6SAli Bahrami static const conv_ds_msg_t ds_tags_cf = { 554f680cc6SAli Bahrami CONV_DS_MSG_INIT(ELFCLASSNONE, tags_cf) }; 564f680cc6SAli Bahrami static const conv_ds_msg_t ds_tags_nf = { 574f680cc6SAli Bahrami CONV_DS_MSG_INIT(ELFCLASSNONE, tags_nf) }; 584f680cc6SAli Bahrami 594f680cc6SAli Bahrami static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_tags_cf), NULL }; 604f680cc6SAli Bahrami static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_tags_nf), NULL }; 614f680cc6SAli Bahrami 624f680cc6SAli Bahrami 634f680cc6SAli Bahrami return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ? 644f680cc6SAli Bahrami ds_nf : ds_cf); 654f680cc6SAli Bahrami } 664f680cc6SAli Bahrami 674f680cc6SAli Bahrami conv_iter_ret_t 684f680cc6SAli Bahrami conv_iter_cap_tags(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 694f680cc6SAli Bahrami void *uvalue) 704f680cc6SAli Bahrami { 714f680cc6SAli Bahrami return (conv_iter_ds(ELFOSABI_NONE, EM_NONE, 724f680cc6SAli Bahrami conv_cap_tag_strings(fmt_flags), func, uvalue)); 734f680cc6SAli Bahrami } 747c478bd9Sstevel@tonic-gate 75d29b2c44Sab196087 /* 764f680cc6SAli Bahrami * Given an array of elfcap_desc_t, and a count, call the specified 774f680cc6SAli Bahrami * iteration for each value in the array. 78d29b2c44Sab196087 */ 794f680cc6SAli Bahrami static conv_iter_ret_t 804f680cc6SAli Bahrami conv_iter_elfcap(const elfcap_desc_t *cdp, uint_t cnum, 814f680cc6SAli Bahrami Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue) 827c478bd9Sstevel@tonic-gate { 834f680cc6SAli Bahrami const char *str; 847c478bd9Sstevel@tonic-gate 854f680cc6SAli Bahrami fmt_flags = CONV_TYPE_FMT_ALT(fmt_flags); 864f680cc6SAli Bahrami 874f680cc6SAli Bahrami for (; cnum-- > 0; cdp++) { 884f680cc6SAli Bahrami /* 894f680cc6SAli Bahrami * Skip "reserved" bits. These are unassigned bits in the 904f680cc6SAli Bahrami * middle of the assigned range. 914f680cc6SAli Bahrami */ 924f680cc6SAli Bahrami if (cdp->c_val == 0) 934f680cc6SAli Bahrami continue; 944f680cc6SAli Bahrami 954f680cc6SAli Bahrami switch (fmt_flags) { 964f680cc6SAli Bahrami default: 974f680cc6SAli Bahrami str = cdp->c_full.s_str; 984f680cc6SAli Bahrami break; 994f680cc6SAli Bahrami case CONV_FMT_ALT_CFNP: 1004f680cc6SAli Bahrami str = cdp->c_uc.s_str; 1014f680cc6SAli Bahrami break; 1024f680cc6SAli Bahrami case CONV_FMT_ALT_NF: 1034f680cc6SAli Bahrami str = cdp->c_lc.s_str; 1044f680cc6SAli Bahrami break; 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1074f680cc6SAli Bahrami if ((* func)(str, cdp->c_val, uvalue) == CONV_ITER_DONE) 1084f680cc6SAli Bahrami return (CONV_ITER_DONE); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1114f680cc6SAli Bahrami return (CONV_ITER_CONT); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate 1144f680cc6SAli Bahrami /* 115*08278a5eSRod Evans * Iterate the strings for CA_SUNW_HW. 1164f680cc6SAli Bahrami */ 1174f680cc6SAli Bahrami conv_iter_ret_t 1184f680cc6SAli Bahrami conv_iter_cap_val_hw1(Half mach, Conv_fmt_flags_t fmt_flags, 1194f680cc6SAli Bahrami conv_iter_cb_t func, void *uvalue) 1207c478bd9Sstevel@tonic-gate { 1214f680cc6SAli Bahrami if ((mach == EM_386) || (mach == EM_486) || 1224f680cc6SAli Bahrami (mach == EM_AMD64) || (mach == CONV_MACH_ALL)) 1234f680cc6SAli Bahrami if (conv_iter_elfcap(elfcap_getdesc_hw1_386(), 1244f680cc6SAli Bahrami ELFCAP_NUM_HW1_386, fmt_flags, func, uvalue) == 1254f680cc6SAli Bahrami CONV_ITER_DONE) 1264f680cc6SAli Bahrami return (CONV_ITER_DONE); 1274f680cc6SAli Bahrami 1284f680cc6SAli Bahrami if ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 1294f680cc6SAli Bahrami (mach == EM_SPARCV9) || (mach == CONV_MACH_ALL)) 1304f680cc6SAli Bahrami if (conv_iter_elfcap(elfcap_getdesc_hw1_sparc(), 1314f680cc6SAli Bahrami ELFCAP_NUM_HW1_SPARC, fmt_flags, func, uvalue) == 1324f680cc6SAli Bahrami CONV_ITER_DONE) 1334f680cc6SAli Bahrami return (CONV_ITER_DONE); 1344f680cc6SAli Bahrami 1354f680cc6SAli Bahrami return (CONV_ITER_CONT); 1364f680cc6SAli Bahrami } 1374f680cc6SAli Bahrami 138*08278a5eSRod Evans conv_iter_ret_t 139*08278a5eSRod Evans /* ARGSUSED0 */ 140*08278a5eSRod Evans conv_iter_cap_val_hw2(Half mach, Conv_fmt_flags_t fmt_flags, 141*08278a5eSRod Evans conv_iter_cb_t func, void *uvalue) 142*08278a5eSRod Evans { 143*08278a5eSRod Evans return (CONV_ITER_DONE); 144*08278a5eSRod Evans } 145*08278a5eSRod Evans 1464f680cc6SAli Bahrami /* 1474f680cc6SAli Bahrami * Iterate the strings for CA_SUNW_SF1 1484f680cc6SAli Bahrami */ 1494f680cc6SAli Bahrami conv_iter_ret_t 1504f680cc6SAli Bahrami conv_iter_cap_val_sf1(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, 1514f680cc6SAli Bahrami void *uvalue) 1524f680cc6SAli Bahrami { 1534f680cc6SAli Bahrami return (conv_iter_elfcap(elfcap_getdesc_sf1(), ELFCAP_NUM_SF1, 1544f680cc6SAli Bahrami fmt_flags, func, uvalue)); 1557c478bd9Sstevel@tonic-gate } 156