6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <msg.h>
32 #include <_elfdump.h>
33 #include <struct_layout.h>
34 #include <conv.h>
35
36
37 /*
38 * Functions for extracting and formatting numeric values from
39 * structure data.
40 */
41
42
43
44
45 /*
46 * Extract the integral field into the value union given and
103 switch (fdesc->slf_eltlen) {
104 case 1:
105 return ((Word) v.sld_ui8);
106 case 2:
107 return ((Word) v.sld_ui16);
108 case 4:
109 return ((Word) v.sld_ui32);
110 case 8:
111 return ((Word) v.sld_ui64);
112 }
113 }
114
115 /* This should not be reached */
116 assert(0);
117 return (0);
118 }
119
120
121 /*
122 * Extract the given integer field, and return its value, cast
123 * to Word. Note that this operation must not be used on values
124 * that can be negative, as information can be lost.
125 */
126 Lword
127 sl_extract_as_lword(const char *data, int do_swap, const sl_field_t *fdesc)
128 {
129 sl_data_t v;
130
131 /* Extract the value from the raw data */
132 sl_extract_num_field(data, do_swap, fdesc, &v);
133
134 if (fdesc->slf_sign) {
135 switch (fdesc->slf_eltlen) {
136 case 1:
137 return ((Lword) v.sld_i8);
138 case 2:
139 return ((Lword) v.sld_i16);
140 case 4:
141 return ((Lword) v.sld_i32);
142 case 8:
143 return ((Lword) v.sld_i64);
|
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <msg.h>
31 #include <_elfdump.h>
32 #include <struct_layout.h>
33 #include <conv.h>
34
35
36 /*
37 * Functions for extracting and formatting numeric values from
38 * structure data.
39 */
40
41
42
43
44 /*
45 * Extract the integral field into the value union given and
102 switch (fdesc->slf_eltlen) {
103 case 1:
104 return ((Word) v.sld_ui8);
105 case 2:
106 return ((Word) v.sld_ui16);
107 case 4:
108 return ((Word) v.sld_ui32);
109 case 8:
110 return ((Word) v.sld_ui64);
111 }
112 }
113
114 /* This should not be reached */
115 assert(0);
116 return (0);
117 }
118
119
120 /*
121 * Extract the given integer field, and return its value, cast
122 * to Lword. Note that this operation must not be used on values
123 * that can be negative, as information can be lost.
124 */
125 Lword
126 sl_extract_as_lword(const char *data, int do_swap, const sl_field_t *fdesc)
127 {
128 sl_data_t v;
129
130 /* Extract the value from the raw data */
131 sl_extract_num_field(data, do_swap, fdesc, &v);
132
133 if (fdesc->slf_sign) {
134 switch (fdesc->slf_eltlen) {
135 case 1:
136 return ((Lword) v.sld_i8);
137 case 2:
138 return ((Lword) v.sld_i16);
139 case 4:
140 return ((Lword) v.sld_i32);
141 case 8:
142 return ((Lword) v.sld_i64);
|