8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sgs / libconv / common / cap_machelf.c
blobd572e29409972835c0cdfe8a1655f4c6efa577d8
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * String conversion routine for hardware capabilities types.
30 #include <strings.h>
31 #include <stdio.h>
32 #include <_machelf.h>
33 #include <elfcap.h>
34 #include "cap_msg.h"
35 #include "_conv.h"
37 static int
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)
41 size_t _len;
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.
50 if (do_bkt) {
51 _len = sprintf(str, MSG_ORIG(MSG_GBL_OSQBRKT), EC_XWORD(val));
53 len -= _len;
54 str += _len;
57 if ((*fptr)(ELFCAP_STYLE_UC, val, str, len, ELFCAP_FMT_SNGSPACE,
58 mach) != 0)
59 return (0);
61 if (do_bkt) {
62 _len = strlen(str);
63 if ((len - _len) >= MSG_GBL_CSQBRKT_SIZE) {
64 str += _len;
65 (void) strcpy(str, MSG_ORIG(MSG_GBL_CSQBRKT));
68 return (1);
71 const char *
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)
75 if (val == 0)
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);
84 const char *
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)
88 if (val == 0)
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);
97 const char *
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)
101 if (val == 0)
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);
110 const char *
111 conv_cap_tag(Xword tag, Conv_fmt_flags_t fmt_flags, Conv_inv_buf_t *inv_buf)
113 #ifdef _ELF64
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));
124 #endif
126 return (conv_map_ds(ELFOSABI_NONE, EM_NONE, tag,
127 conv_cap_tag_strings(fmt_flags), fmt_flags, inv_buf));
130 const char *
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)
134 switch (tag) {
135 case CA_SUNW_HW_1:
136 return (conv_cap_val_hw1(val, mach, fmt_flags,
137 &cap_val_buf->cap_val_hw1_buf));
139 case CA_SUNW_SF_1:
140 return (conv_cap_val_sf1(val, mach, fmt_flags,
141 &cap_val_buf->cap_val_sf1_buf));
143 case CA_SUNW_HW_2:
144 return (conv_cap_val_hw2(val, mach, fmt_flags,
145 &cap_val_buf->cap_val_hw2_buf));
147 default:
148 return (conv_invalid_val(&cap_val_buf->inv_buf, val, 0));