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 /* 23*4734Sab196087 * 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, 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 492352Sab196087 if ((*fptr)(val, str, len, CAP_FMT_SNGSPACE, mach) != 0) 501618Srie return (0); 510Sstevel@tonic-gate 521618Srie _len = strlen(str); 531618Srie if ((len - _len) >= MSG_GBL_CSQBRKT_SIZE) { 541618Srie str += _len; 551618Srie (void) strcpy(str, MSG_ORIG(MSG_GBL_CSQBRKT)); 560Sstevel@tonic-gate } 571618Srie return (1); 580Sstevel@tonic-gate } 590Sstevel@tonic-gate 600Sstevel@tonic-gate const char * 61*4734Sab196087 conv_cap_val_hw1(Xword val, Half mach, Conv_cap_val_hw1_buf_t *cap_val_hw1_buf) 620Sstevel@tonic-gate { 630Sstevel@tonic-gate if (val == 0) 640Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 650Sstevel@tonic-gate 66*4734Sab196087 if (conv_cap_1(val, cap_val_hw1_buf->buf, sizeof (cap_val_hw1_buf->buf), 67*4734Sab196087 mach, hwcap_1_val2str) == 0) 68*4734Sab196087 return (conv_invalid_val(&cap_val_hw1_buf->inv_buf, val, 0)); 69*4734Sab196087 return ((const char *)cap_val_hw1_buf->buf); 700Sstevel@tonic-gate } 710Sstevel@tonic-gate 720Sstevel@tonic-gate const char * 73*4734Sab196087 conv_cap_val_sf1(Xword val, Half mach, Conv_cap_val_sf1_buf_t *cap_val_sf1_buf) 740Sstevel@tonic-gate { 750Sstevel@tonic-gate if (val == 0) 760Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 770Sstevel@tonic-gate 78*4734Sab196087 if (conv_cap_1(val, cap_val_sf1_buf->buf, sizeof (cap_val_sf1_buf->buf), 79*4734Sab196087 mach, sfcap_1_val2str) == 0) 80*4734Sab196087 return (conv_invalid_val(&cap_val_sf1_buf->inv_buf, val, 0)); 81*4734Sab196087 return ((const char *)cap_val_sf1_buf->buf); 820Sstevel@tonic-gate } 830Sstevel@tonic-gate 840Sstevel@tonic-gate const char * 85*4734Sab196087 conv_cap_tag(Xword tag, Conv_inv_buf_t *inv_buf) 860Sstevel@tonic-gate { 871618Srie static const Msg tags[] = { 881618Srie MSG_CA_SUNW_NULL, MSG_CA_SUNW_HW_1, 891618Srie MSG_CA_SUNW_SF_1 901618Srie }; 910Sstevel@tonic-gate 920Sstevel@tonic-gate if (tag <= CA_SUNW_SF_1) 931618Srie return (MSG_ORIG(tags[tag])); 940Sstevel@tonic-gate else 95*4734Sab196087 return (conv_invalid_val(inv_buf, tag, 0)); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate const char * 99*4734Sab196087 conv_cap_val(Xword tag, Xword val, Half mach, Conv_cap_val_buf_t *cap_val_buf) 1000Sstevel@tonic-gate { 1010Sstevel@tonic-gate if (tag == CA_SUNW_HW_1) 102*4734Sab196087 return (conv_cap_val_hw1(val, mach, 103*4734Sab196087 &cap_val_buf->cap_val_hw1_buf)); 1040Sstevel@tonic-gate else if (tag == CA_SUNW_SF_1) 105*4734Sab196087 return (conv_cap_val_sf1(val, mach, 106*4734Sab196087 &cap_val_buf->cap_val_sf1_buf)); 1070Sstevel@tonic-gate else 108*4734Sab196087 return (conv_invalid_val(&cap_val_buf->inv_buf, val, 0)); 1090Sstevel@tonic-gate } 110