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 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * 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 */ 211618Srie 220Sstevel@tonic-gate /* 234734Sab196087 * Copyright 2007 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> 351976Sab196087 #include "cap_msg.h" 360Sstevel@tonic-gate #include "_conv.h" 370Sstevel@tonic-gate 381618Srie static int 391618Srie conv_cap_1(Xword val, char *str, size_t len, Half mach, 40*5088Sab196087 Conv_fmt_flags_t fmt_flags, 410Sstevel@tonic-gate int (*fptr)(uint64_t, char *, size_t, int, ushort_t)) 420Sstevel@tonic-gate { 430Sstevel@tonic-gate size_t _len; 44*5088Sab196087 int do_bkt = (fmt_flags & CONV_FMT_NOBKT) == 0; 450Sstevel@tonic-gate 46*5088Sab196087 /* 47*5088Sab196087 * Note that for the purposes of this routine, I consider 48*5088Sab196087 * CONV_FMT_NOBKT to mean no brackets, or anything that 49*5088Sab196087 * is placed outside of them. We also drop the hex version 50*5088Sab196087 * of the flags that are put in front of the opening bracket. 51*5088Sab196087 */ 52*5088Sab196087 if (do_bkt) { 53*5088Sab196087 _len = sprintf(str, MSG_ORIG(MSG_GBL_OSQBRKT), EC_XWORD(val)); 54*5088Sab196087 55*5088Sab196087 len -= _len; 56*5088Sab196087 str += _len; 57*5088Sab196087 } 580Sstevel@tonic-gate 592352Sab196087 if ((*fptr)(val, str, len, CAP_FMT_SNGSPACE, mach) != 0) 601618Srie return (0); 610Sstevel@tonic-gate 62*5088Sab196087 if (do_bkt) { 63*5088Sab196087 _len = strlen(str); 64*5088Sab196087 if ((len - _len) >= MSG_GBL_CSQBRKT_SIZE) { 65*5088Sab196087 str += _len; 66*5088Sab196087 (void) strcpy(str, MSG_ORIG(MSG_GBL_CSQBRKT)); 67*5088Sab196087 } 680Sstevel@tonic-gate } 691618Srie return (1); 700Sstevel@tonic-gate } 710Sstevel@tonic-gate 720Sstevel@tonic-gate const char * 73*5088Sab196087 conv_cap_val_hw1(Xword val, Half mach, Conv_fmt_flags_t fmt_flags, 74*5088Sab196087 Conv_cap_val_hw1_buf_t *cap_val_hw1_buf) 750Sstevel@tonic-gate { 760Sstevel@tonic-gate if (val == 0) 770Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 780Sstevel@tonic-gate 794734Sab196087 if (conv_cap_1(val, cap_val_hw1_buf->buf, sizeof (cap_val_hw1_buf->buf), 80*5088Sab196087 mach, fmt_flags, hwcap_1_val2str) == 0) 814734Sab196087 return (conv_invalid_val(&cap_val_hw1_buf->inv_buf, val, 0)); 824734Sab196087 return ((const char *)cap_val_hw1_buf->buf); 830Sstevel@tonic-gate } 840Sstevel@tonic-gate 850Sstevel@tonic-gate const char * 86*5088Sab196087 conv_cap_val_sf1(Xword val, Half mach, Conv_fmt_flags_t fmt_flags, 87*5088Sab196087 Conv_cap_val_sf1_buf_t *cap_val_sf1_buf) 880Sstevel@tonic-gate { 890Sstevel@tonic-gate if (val == 0) 900Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 910Sstevel@tonic-gate 924734Sab196087 if (conv_cap_1(val, cap_val_sf1_buf->buf, sizeof (cap_val_sf1_buf->buf), 93*5088Sab196087 mach, fmt_flags, sfcap_1_val2str) == 0) 944734Sab196087 return (conv_invalid_val(&cap_val_sf1_buf->inv_buf, val, 0)); 954734Sab196087 return ((const char *)cap_val_sf1_buf->buf); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate const char * 994734Sab196087 conv_cap_tag(Xword tag, Conv_inv_buf_t *inv_buf) 1000Sstevel@tonic-gate { 1011618Srie static const Msg tags[] = { 1021618Srie MSG_CA_SUNW_NULL, MSG_CA_SUNW_HW_1, 1031618Srie MSG_CA_SUNW_SF_1 1041618Srie }; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate if (tag <= CA_SUNW_SF_1) 1071618Srie return (MSG_ORIG(tags[tag])); 1080Sstevel@tonic-gate else 1094734Sab196087 return (conv_invalid_val(inv_buf, tag, 0)); 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate const char * 1134734Sab196087 conv_cap_val(Xword tag, Xword val, Half mach, Conv_cap_val_buf_t *cap_val_buf) 1140Sstevel@tonic-gate { 1150Sstevel@tonic-gate if (tag == CA_SUNW_HW_1) 116*5088Sab196087 return (conv_cap_val_hw1(val, mach, 0, 1174734Sab196087 &cap_val_buf->cap_val_hw1_buf)); 1180Sstevel@tonic-gate else if (tag == CA_SUNW_SF_1) 119*5088Sab196087 return (conv_cap_val_sf1(val, mach, 0, 1204734Sab196087 &cap_val_buf->cap_val_sf1_buf)); 1210Sstevel@tonic-gate else 1224734Sab196087 return (conv_invalid_val(&cap_val_buf->inv_buf, val, 0)); 1230Sstevel@tonic-gate } 124