4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * String conversion routine for hardware capabilities types.
38 conv_cap(Xword val
, char *str
, size_t len
, Half mach
,
39 Conv_fmt_flags_t fmt_flags
, elfcap_to_str_func_t
*fptr
)
42 int do_bkt
= (fmt_flags
& CONV_FMT_NOBKT
) == 0;
45 * Note that for the purposes of this routine, I consider
46 * CONV_FMT_NOBKT to mean no brackets, or anything that
47 * is placed outside of them. We also drop the hex version
48 * of the flags that are put in front of the opening bracket.
51 _len
= sprintf(str
, MSG_ORIG(MSG_GBL_OSQBRKT
), EC_XWORD(val
));
57 if ((*fptr
)(ELFCAP_STYLE_UC
, val
, str
, len
, ELFCAP_FMT_SNGSPACE
,
63 if ((len
- _len
) >= MSG_GBL_CSQBRKT_SIZE
) {
65 (void) strcpy(str
, MSG_ORIG(MSG_GBL_CSQBRKT
));
72 conv_cap_val_hw1(Xword val
, Half mach
, Conv_fmt_flags_t fmt_flags
,
73 Conv_cap_val_hw1_buf_t
*cap_val_hw1_buf
)
76 return (MSG_ORIG(MSG_GBL_ZERO
));
78 if (conv_cap(val
, cap_val_hw1_buf
->buf
, sizeof (cap_val_hw1_buf
->buf
),
79 mach
, fmt_flags
, elfcap_hw1_to_str
) == 0)
80 return (conv_invalid_val(&cap_val_hw1_buf
->inv_buf
, val
, 0));
81 return ((const char *)cap_val_hw1_buf
->buf
);
85 conv_cap_val_hw2(Xword val
, Half mach
, Conv_fmt_flags_t fmt_flags
,
86 Conv_cap_val_hw2_buf_t
*cap_val_hw2_buf
)
89 return (MSG_ORIG(MSG_GBL_ZERO
));
91 if (conv_cap(val
, cap_val_hw2_buf
->buf
, sizeof (cap_val_hw2_buf
->buf
),
92 mach
, fmt_flags
, elfcap_hw2_to_str
) == 0)
93 return (conv_invalid_val(&cap_val_hw2_buf
->inv_buf
, val
, 0));
94 return ((const char *)cap_val_hw2_buf
->buf
);
98 conv_cap_val_sf1(Xword val
, Half mach
, Conv_fmt_flags_t fmt_flags
,
99 Conv_cap_val_sf1_buf_t
*cap_val_sf1_buf
)
102 return (MSG_ORIG(MSG_GBL_ZERO
));
104 if (conv_cap(val
, cap_val_sf1_buf
->buf
, sizeof (cap_val_sf1_buf
->buf
),
105 mach
, fmt_flags
, elfcap_sf1_to_str
) == 0)
106 return (conv_invalid_val(&cap_val_sf1_buf
->inv_buf
, val
, 0));
107 return ((const char *)cap_val_sf1_buf
->buf
);
111 conv_cap_tag(Xword tag
, Conv_fmt_flags_t fmt_flags
, Conv_inv_buf_t
*inv_buf
)
115 * Valid tags all fit in 32-bits, so a value larger than that
116 * is garbage. conv_map_ds() sees 32-bit values, so test for garbage
117 * here before passing it on.
119 * Since there are no valid tags with a value > 32-bits, there
120 * is no reason to expend effort decoding the low order bits.
122 if (tag
& 0xffffffff00000000)
123 return (conv_invalid_val(inv_buf
, tag
, fmt_flags
));
126 return (conv_map_ds(ELFOSABI_NONE
, EM_NONE
, tag
,
127 conv_cap_tag_strings(fmt_flags
), fmt_flags
, inv_buf
));
131 conv_cap_val(Xword tag
, Xword val
, Half mach
, Conv_fmt_flags_t fmt_flags
,
132 Conv_cap_val_buf_t
*cap_val_buf
)
136 return (conv_cap_val_hw1(val
, mach
, fmt_flags
,
137 &cap_val_buf
->cap_val_hw1_buf
));
140 return (conv_cap_val_sf1(val
, mach
, fmt_flags
,
141 &cap_val_buf
->cap_val_sf1_buf
));
144 return (conv_cap_val_hw2(val
, mach
, fmt_flags
,
145 &cap_val_buf
->cap_val_hw2_buf
));
148 return (conv_invalid_val(&cap_val_buf
->inv_buf
, val
, 0));