1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * Descriptor parsing functions
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_utils.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #define	INCREMENT_BUF(buf) \
38*7c478bd9Sstevel@tonic-gate 		if ((buf)[0] == 0) { \
39*7c478bd9Sstevel@tonic-gate 			break; \
40*7c478bd9Sstevel@tonic-gate 		} else { \
41*7c478bd9Sstevel@tonic-gate 			(buf) += (buf)[0]; \
42*7c478bd9Sstevel@tonic-gate 		}
43*7c478bd9Sstevel@tonic-gate #define	isdigit(ch) ((ch >= '0') && (ch <= '9'))
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * ibmf_utils_unpack_data:
47*7c478bd9Sstevel@tonic-gate  *
48*7c478bd9Sstevel@tonic-gate  * parser function which takes a format string, a void pointer, and a character
49*7c478bd9Sstevel@tonic-gate  * buffer and parses the buffer according to the identifiers in the format
50*7c478bd9Sstevel@tonic-gate  * string.  Copies the data from the buffer and places into the structure,
51*7c478bd9Sstevel@tonic-gate  * taking care of byte swapping and any padding due to 64-bit Solaris.  Modified
52*7c478bd9Sstevel@tonic-gate  * from /ws/on81-gate/usr/src/uts/common/io/usb/usba/parser.c.
53*7c478bd9Sstevel@tonic-gate  *
54*7c478bd9Sstevel@tonic-gate  * The data and structure length parameters can be larger than the number of
55*7c478bd9Sstevel@tonic-gate  * bytes specified in the format.  unpack_data will use the smallest of the
56*7c478bd9Sstevel@tonic-gate  * three values, stopping when it finishes parsing the format string or reaches
57*7c478bd9Sstevel@tonic-gate  * the end of one of the two buffers.
58*7c478bd9Sstevel@tonic-gate  */
59*7c478bd9Sstevel@tonic-gate void
ibmf_utils_unpack_data(char * format,uchar_t * data,size_t datalen,void * structure,size_t structlen)60*7c478bd9Sstevel@tonic-gate ibmf_utils_unpack_data(char *format,
61*7c478bd9Sstevel@tonic-gate 	uchar_t *data,
62*7c478bd9Sstevel@tonic-gate 	size_t datalen,
63*7c478bd9Sstevel@tonic-gate 	void *structure,
64*7c478bd9Sstevel@tonic-gate 	size_t structlen)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate 	int	fmt;
67*7c478bd9Sstevel@tonic-gate 	int	multiplier = 0;
68*7c478bd9Sstevel@tonic-gate 	uchar_t	*dataend = data + datalen;
69*7c478bd9Sstevel@tonic-gate 	char	*structstart = (char *)structure;
70*7c478bd9Sstevel@tonic-gate 	void	*structend = (void *)((intptr_t)structstart + structlen);
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	while ((fmt = *format) != '\0') {
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 		if (fmt == 'c') {
75*7c478bd9Sstevel@tonic-gate 			uint8_t	*cp = (uint8_t *)structure;
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate 			/*
78*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
79*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
80*7c478bd9Sstevel@tonic-gate 			 */
81*7c478bd9Sstevel@tonic-gate 			cp = (uint8_t *)
82*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)cp + _CHAR_ALIGNMENT - 1) &
83*7c478bd9Sstevel@tonic-gate 			    ~(_CHAR_ALIGNMENT - 1));
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 			if (((data + 1) > dataend) ||
86*7c478bd9Sstevel@tonic-gate 			    ((cp + 1) > (uint8_t *)structend))
87*7c478bd9Sstevel@tonic-gate 				break;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 			*cp++ = *data++;
90*7c478bd9Sstevel@tonic-gate 			structure = (void *)cp;
91*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
92*7c478bd9Sstevel@tonic-gate 				multiplier--;
93*7c478bd9Sstevel@tonic-gate 			}
94*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
95*7c478bd9Sstevel@tonic-gate 				format++;
96*7c478bd9Sstevel@tonic-gate 			}
97*7c478bd9Sstevel@tonic-gate 		} else if (fmt == 's') {
98*7c478bd9Sstevel@tonic-gate 			uint16_t	*sp = (uint16_t *)structure;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 			/*
101*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
102*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
103*7c478bd9Sstevel@tonic-gate 			 */
104*7c478bd9Sstevel@tonic-gate 			sp = (uint16_t *)
105*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)sp + _SHORT_ALIGNMENT - 1) &
106*7c478bd9Sstevel@tonic-gate 			    ~(_SHORT_ALIGNMENT - 1));
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 			if (((data + 2) > dataend) ||
109*7c478bd9Sstevel@tonic-gate 			    ((sp + 1) > (uint16_t *)structend))
110*7c478bd9Sstevel@tonic-gate 				break;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 			*sp++ = (data[0] << 8) + data[1];
113*7c478bd9Sstevel@tonic-gate 			data += 2;
114*7c478bd9Sstevel@tonic-gate 			structure = (void *)sp;
115*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
116*7c478bd9Sstevel@tonic-gate 				multiplier--;
117*7c478bd9Sstevel@tonic-gate 			}
118*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
119*7c478bd9Sstevel@tonic-gate 				format++;
120*7c478bd9Sstevel@tonic-gate 			}
121*7c478bd9Sstevel@tonic-gate 		} else if (fmt == 'l') {
122*7c478bd9Sstevel@tonic-gate 			uint32_t 	*lp = (uint32_t *)structure;
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 			/*
125*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
126*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
127*7c478bd9Sstevel@tonic-gate 			 */
128*7c478bd9Sstevel@tonic-gate 			lp = (uint32_t *)
129*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)lp + _INT_ALIGNMENT - 1) &
130*7c478bd9Sstevel@tonic-gate 			    ~(_INT_ALIGNMENT - 1));
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 			if (((data + 4) > dataend) ||
133*7c478bd9Sstevel@tonic-gate 			    ((lp + 1) > (uint32_t *)structend))
134*7c478bd9Sstevel@tonic-gate 				break;
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 			*lp++ = ((((((uint32_t)data[0] << 8) | data[1]) << 8)
137*7c478bd9Sstevel@tonic-gate 			    | data[2]) << 8) | data[3];
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 			data += 4;
140*7c478bd9Sstevel@tonic-gate 			structure = (void *)lp;
141*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
142*7c478bd9Sstevel@tonic-gate 				multiplier--;
143*7c478bd9Sstevel@tonic-gate 			}
144*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
145*7c478bd9Sstevel@tonic-gate 				format++;
146*7c478bd9Sstevel@tonic-gate 			}
147*7c478bd9Sstevel@tonic-gate 		} else if (fmt == 'L') {
148*7c478bd9Sstevel@tonic-gate 			uint64_t	*llp = (uint64_t *)structure;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 			/*
151*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
152*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
153*7c478bd9Sstevel@tonic-gate 			 */
154*7c478bd9Sstevel@tonic-gate 			llp = (uint64_t *)
155*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)llp + _LONG_LONG_ALIGNMENT - 1) &
156*7c478bd9Sstevel@tonic-gate 			    ~(_LONG_LONG_ALIGNMENT - 1));
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate 			if (((data + 8) > dataend) ||
159*7c478bd9Sstevel@tonic-gate 			    ((llp + 1) > (uint64_t *)structend))
160*7c478bd9Sstevel@tonic-gate 				break;
161*7c478bd9Sstevel@tonic-gate 			/*
162*7c478bd9Sstevel@tonic-gate 			 * note: data[0] is cast to uint64_t so that the
163*7c478bd9Sstevel@tonic-gate 			 * compiler wouldn't treat the results of the shifts
164*7c478bd9Sstevel@tonic-gate 			 * as a 32bit quantity; we really want to get 64bits
165*7c478bd9Sstevel@tonic-gate 			 * out of this.
166*7c478bd9Sstevel@tonic-gate 			 */
167*7c478bd9Sstevel@tonic-gate 			*llp++ = ((((((((((((((uint64_t)data[0] << 8) |
168*7c478bd9Sstevel@tonic-gate 				data[1]) << 8) | data[2]) << 8) |
169*7c478bd9Sstevel@tonic-gate 				data[3]) << 8) | data[4]) << 8) |
170*7c478bd9Sstevel@tonic-gate 				data[5]) << 8) | data[6]) << 8) |
171*7c478bd9Sstevel@tonic-gate 				data[7];
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 			data += 8;
174*7c478bd9Sstevel@tonic-gate 			structure = (void *)llp;
175*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
176*7c478bd9Sstevel@tonic-gate 				multiplier--;
177*7c478bd9Sstevel@tonic-gate 			}
178*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
179*7c478bd9Sstevel@tonic-gate 				format++;
180*7c478bd9Sstevel@tonic-gate 			}
181*7c478bd9Sstevel@tonic-gate 		} else if (isdigit(fmt)) {
182*7c478bd9Sstevel@tonic-gate 			multiplier = (multiplier * 10) + (fmt - '0');
183*7c478bd9Sstevel@tonic-gate 			format++;
184*7c478bd9Sstevel@tonic-gate 		} else {
185*7c478bd9Sstevel@tonic-gate 			multiplier = 0;
186*7c478bd9Sstevel@tonic-gate 			break;
187*7c478bd9Sstevel@tonic-gate 		}
188*7c478bd9Sstevel@tonic-gate 	}
189*7c478bd9Sstevel@tonic-gate }
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate /*
192*7c478bd9Sstevel@tonic-gate  * ibmf_utils_pack_data:
193*7c478bd9Sstevel@tonic-gate  *
194*7c478bd9Sstevel@tonic-gate  * parser function which takes a format string, a void pointer, and a character
195*7c478bd9Sstevel@tonic-gate  * buffer and parses the structure according to the identifiers in the format
196*7c478bd9Sstevel@tonic-gate  * string.  Copies the data from the structure and places in the buffer, taking
197*7c478bd9Sstevel@tonic-gate  * care of byte swapping and any padding due to 64-bit Solaris.  Modified from
198*7c478bd9Sstevel@tonic-gate  * /ws/on81-gate/usr/src/uts/common/io/usb/usba/parser.c.
199*7c478bd9Sstevel@tonic-gate  *
200*7c478bd9Sstevel@tonic-gate  */
201*7c478bd9Sstevel@tonic-gate void
ibmf_utils_pack_data(char * format,void * structure,size_t structlen,uchar_t * data,size_t datalen)202*7c478bd9Sstevel@tonic-gate ibmf_utils_pack_data(char *format, void *structure,
203*7c478bd9Sstevel@tonic-gate     size_t structlen, uchar_t *data, size_t datalen)
204*7c478bd9Sstevel@tonic-gate {
205*7c478bd9Sstevel@tonic-gate 	int	fmt;
206*7c478bd9Sstevel@tonic-gate 	int	multiplier = 0;
207*7c478bd9Sstevel@tonic-gate 	uchar_t	*dataend = data + datalen;
208*7c478bd9Sstevel@tonic-gate 	char	*structend = (void *)((uchar_t *)structure + structlen);
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 	while ((fmt = *format) != '\0') {
211*7c478bd9Sstevel@tonic-gate 		if (fmt == 'c') {
212*7c478bd9Sstevel@tonic-gate 			uint8_t	*cp = (uint8_t *)structure;
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 			/*
215*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
216*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
217*7c478bd9Sstevel@tonic-gate 			 */
218*7c478bd9Sstevel@tonic-gate 			cp = (uint8_t *)
219*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)cp + _CHAR_ALIGNMENT - 1) &
220*7c478bd9Sstevel@tonic-gate 			    ~(_CHAR_ALIGNMENT - 1));
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 			if (((data + 1) > dataend) ||
223*7c478bd9Sstevel@tonic-gate 			    ((cp + 1) > (uint8_t *)structend)) {
224*7c478bd9Sstevel@tonic-gate 				break;
225*7c478bd9Sstevel@tonic-gate 			}
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 			*data++ = *cp++;
228*7c478bd9Sstevel@tonic-gate 			structure = (void *)cp;
229*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
230*7c478bd9Sstevel@tonic-gate 				multiplier--;
231*7c478bd9Sstevel@tonic-gate 			}
232*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
233*7c478bd9Sstevel@tonic-gate 				format++;
234*7c478bd9Sstevel@tonic-gate 			}
235*7c478bd9Sstevel@tonic-gate 		} else if (fmt == 's') {
236*7c478bd9Sstevel@tonic-gate 			uint16_t	*sp = (uint16_t *)structure;
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate 			/*
239*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
240*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
241*7c478bd9Sstevel@tonic-gate 			 */
242*7c478bd9Sstevel@tonic-gate 			sp = (uint16_t *)
243*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)sp + _SHORT_ALIGNMENT - 1) &
244*7c478bd9Sstevel@tonic-gate 			    ~(_SHORT_ALIGNMENT - 1));
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 			if (((data + 2) > dataend) ||
247*7c478bd9Sstevel@tonic-gate 			    ((sp + 1) > (uint16_t *)structend))
248*7c478bd9Sstevel@tonic-gate 				break;
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate 			/* do an endian-independent copy */
251*7c478bd9Sstevel@tonic-gate 			data[0] = (uchar_t)(*sp >> 8);
252*7c478bd9Sstevel@tonic-gate 			data[1] = (uchar_t)(*sp);
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 			sp++;
255*7c478bd9Sstevel@tonic-gate 			data += 2;
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 			structure = (void *)sp;
258*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
259*7c478bd9Sstevel@tonic-gate 				multiplier--;
260*7c478bd9Sstevel@tonic-gate 			}
261*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
262*7c478bd9Sstevel@tonic-gate 				format++;
263*7c478bd9Sstevel@tonic-gate 			}
264*7c478bd9Sstevel@tonic-gate 		} else if (fmt == 'l') {
265*7c478bd9Sstevel@tonic-gate 			uint32_t 	*lp = (uint32_t *)structure;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 			/*
268*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
269*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
270*7c478bd9Sstevel@tonic-gate 			 */
271*7c478bd9Sstevel@tonic-gate 			lp = (uint32_t *)
272*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)lp + _INT_ALIGNMENT - 1) &
273*7c478bd9Sstevel@tonic-gate 			    ~(_INT_ALIGNMENT - 1));
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 			if (((data + 4) > dataend) ||
276*7c478bd9Sstevel@tonic-gate 			    ((lp + 1) > (uint32_t *)structend))
277*7c478bd9Sstevel@tonic-gate 				break;
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 			/* do an endian-independent copy */
280*7c478bd9Sstevel@tonic-gate 			data[0] = (uchar_t)(*lp >> 24);
281*7c478bd9Sstevel@tonic-gate 			data[1] = (uchar_t)(*lp >> 16);
282*7c478bd9Sstevel@tonic-gate 			data[2] = (uchar_t)(*lp >> 8);
283*7c478bd9Sstevel@tonic-gate 			data[3] = (uchar_t)(*lp);
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 			lp++;
286*7c478bd9Sstevel@tonic-gate 			data += 4;
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate 			structure = (void *)lp;
289*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
290*7c478bd9Sstevel@tonic-gate 				multiplier--;
291*7c478bd9Sstevel@tonic-gate 			}
292*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
293*7c478bd9Sstevel@tonic-gate 				format++;
294*7c478bd9Sstevel@tonic-gate 			}
295*7c478bd9Sstevel@tonic-gate 		} else if (fmt == 'L') {
296*7c478bd9Sstevel@tonic-gate 			uint64_t	*llp = (uint64_t *)structure;
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 			/*
299*7c478bd9Sstevel@tonic-gate 			 * account for possible hole in structure
300*7c478bd9Sstevel@tonic-gate 			 * due to unaligned data
301*7c478bd9Sstevel@tonic-gate 			 */
302*7c478bd9Sstevel@tonic-gate 			llp = (uint64_t *)
303*7c478bd9Sstevel@tonic-gate 			    (((uintptr_t)llp + _LONG_LONG_ALIGNMENT - 1) &
304*7c478bd9Sstevel@tonic-gate 			    ~(_LONG_LONG_ALIGNMENT - 1));
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 			if (((data + 8) > dataend) ||
307*7c478bd9Sstevel@tonic-gate 			    ((llp + 1) > (uint64_t *)structend))
308*7c478bd9Sstevel@tonic-gate 				break;
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate 			/* do an endian-independent copy */
311*7c478bd9Sstevel@tonic-gate 			data[0] = (uchar_t)(*llp >> 56);
312*7c478bd9Sstevel@tonic-gate 			data[1] = (uchar_t)(*llp >> 48);
313*7c478bd9Sstevel@tonic-gate 			data[2] = (uchar_t)(*llp >> 40);
314*7c478bd9Sstevel@tonic-gate 			data[3] = (uchar_t)(*llp >> 32);
315*7c478bd9Sstevel@tonic-gate 			data[4] = (uchar_t)(*llp >> 24);
316*7c478bd9Sstevel@tonic-gate 			data[5] = (uchar_t)(*llp >> 16);
317*7c478bd9Sstevel@tonic-gate 			data[6] = (uchar_t)(*llp >> 8);
318*7c478bd9Sstevel@tonic-gate 			data[7] = (uchar_t)(*llp);
319*7c478bd9Sstevel@tonic-gate 			llp++;
320*7c478bd9Sstevel@tonic-gate 			data += 8;
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate 			structure = (void *)llp;
323*7c478bd9Sstevel@tonic-gate 			if (multiplier) {
324*7c478bd9Sstevel@tonic-gate 				multiplier--;
325*7c478bd9Sstevel@tonic-gate 			}
326*7c478bd9Sstevel@tonic-gate 			if (multiplier == 0) {
327*7c478bd9Sstevel@tonic-gate 				format++;
328*7c478bd9Sstevel@tonic-gate 			}
329*7c478bd9Sstevel@tonic-gate 		} else if (isdigit(fmt)) {
330*7c478bd9Sstevel@tonic-gate 			multiplier = (multiplier * 10) + (fmt - '0');
331*7c478bd9Sstevel@tonic-gate 			format++;
332*7c478bd9Sstevel@tonic-gate 		} else {
333*7c478bd9Sstevel@tonic-gate 			multiplier = 0;
334*7c478bd9Sstevel@tonic-gate 			break;
335*7c478bd9Sstevel@tonic-gate 		}
336*7c478bd9Sstevel@tonic-gate 	}
337*7c478bd9Sstevel@tonic-gate }
338