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 5*1618Srie * Common Development and Distribution License (the "License"). 6*1618Srie * 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 */ 21*1618Srie 220Sstevel@tonic-gate /* 23*1618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * String conversion routine for hardware capabilities types. 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate #include <strings.h> 320Sstevel@tonic-gate #include <stdio.h> 330Sstevel@tonic-gate #include <sys/machelf.h> 340Sstevel@tonic-gate #include <elfcap.h> 350Sstevel@tonic-gate #include "_conv.h" 360Sstevel@tonic-gate #include "cap_msg.h" 370Sstevel@tonic-gate 38*1618Srie static int 39*1618Srie conv_cap_1(Xword val, char *str, size_t len, Half mach, 400Sstevel@tonic-gate int (*fptr)(uint64_t, char *, size_t, int, ushort_t)) 410Sstevel@tonic-gate { 420Sstevel@tonic-gate size_t _len; 430Sstevel@tonic-gate 440Sstevel@tonic-gate _len = sprintf(str, MSG_ORIG(MSG_GBL_OSQBRKT), EC_XWORD(val)); 450Sstevel@tonic-gate 460Sstevel@tonic-gate len -= _len; 470Sstevel@tonic-gate str += _len; 480Sstevel@tonic-gate 49*1618Srie if ((*fptr)(val, str, len, CAP_FMT_DBLSPACE, mach) != 0) 50*1618Srie return (0); 510Sstevel@tonic-gate 52*1618Srie _len = strlen(str); 53*1618Srie if ((len - _len) >= MSG_GBL_CSQBRKT_SIZE) { 54*1618Srie str += _len; 55*1618Srie (void) strcpy(str, MSG_ORIG(MSG_GBL_CSQBRKT)); 560Sstevel@tonic-gate } 57*1618Srie return (1); 580Sstevel@tonic-gate } 590Sstevel@tonic-gate 60*1618Srie /* 61*1618Srie * Establish a buffer size based on the maximum number of hardware capabilities 62*1618Srie * that exist. See common/elfcap. 63*1618Srie */ 64*1618Srie #define HW1SZ 200 650Sstevel@tonic-gate 660Sstevel@tonic-gate const char * 67*1618Srie conv_cap_val_hw1(Xword val, Half mach) 680Sstevel@tonic-gate { 69*1618Srie static char string[HW1SZ]; 700Sstevel@tonic-gate 710Sstevel@tonic-gate if (val == 0) 720Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 730Sstevel@tonic-gate 74*1618Srie if (conv_cap_1(val, string, HW1SZ, mach, hwcap_1_val2str) == 0) 75*1618Srie return (conv_invalid_val(string, HW1SZ, val, 0)); 760Sstevel@tonic-gate return ((const char *)string); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate 79*1618Srie /* 80*1618Srie * Establish a buffer size based on the maximum number of software capabilities 81*1618Srie * that exist. See common/elfcap. 82*1618Srie */ 83*1618Srie #define SF1SZ 50 840Sstevel@tonic-gate 850Sstevel@tonic-gate const char * 86*1618Srie conv_cap_val_sf1(Xword val, Half mach) 870Sstevel@tonic-gate { 88*1618Srie static char string[SF1SZ]; 890Sstevel@tonic-gate 900Sstevel@tonic-gate if (val == 0) 910Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 920Sstevel@tonic-gate 93*1618Srie if (conv_cap_1(val, string, SF1SZ, mach, sfcap_1_val2str) == 0) 94*1618Srie return (conv_invalid_val(string, SF1SZ, val, 0)); 950Sstevel@tonic-gate return ((const char *)string); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate const char * 99*1618Srie conv_cap_tag(Xword tag) 1000Sstevel@tonic-gate { 101*1618Srie static char string[CONV_INV_STRSIZE]; 102*1618Srie static const Msg tags[] = { 103*1618Srie MSG_CA_SUNW_NULL, MSG_CA_SUNW_HW_1, 104*1618Srie MSG_CA_SUNW_SF_1 105*1618Srie }; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate if (tag <= CA_SUNW_SF_1) 108*1618Srie return (MSG_ORIG(tags[tag])); 1090Sstevel@tonic-gate else 110*1618Srie return (conv_invalid_val(string, CONV_INV_STRSIZE, tag, 0)); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate const char * 114*1618Srie conv_cap_val(Xword tag, Xword val, Half mach) 1150Sstevel@tonic-gate { 116*1618Srie static char string[CONV_INV_STRSIZE]; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate if (tag == CA_SUNW_HW_1) 119*1618Srie return (conv_cap_val_hw1(val, mach)); 1200Sstevel@tonic-gate else if (tag == CA_SUNW_SF_1) 121*1618Srie return (conv_cap_val_sf1(val, mach)); 1220Sstevel@tonic-gate else 123*1618Srie return (conv_invalid_val(string, CONV_INV_STRSIZE, val, 0)); 1240Sstevel@tonic-gate } 125