]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/munge.c
2 * Coyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <sys/cdefs.h>
30 #include <sys/types.h>
31 #include <sys/munge.h>
35 * Refer to comments in bsd/sys/munge.h
38 static inline __attribute__((always_inline
)) void
39 munge_32_to_64_unsigned(volatile uint64_t *dest
, volatile uint32_t *src
, int count
);
44 munge_32_to_64_unsigned(args
, args
, 1);
50 munge_32_to_64_unsigned(args
, args
, 2);
56 munge_32_to_64_unsigned(args
, args
, 3);
60 munge_wwww(void *args
)
62 munge_32_to_64_unsigned(args
, args
, 4);
66 munge_wwwww(void *args
)
68 munge_32_to_64_unsigned(args
, args
, 5);
72 munge_wwwwww(void *args
)
74 munge_32_to_64_unsigned(args
, args
, 6);
78 munge_wwwwwww(void *args
)
80 munge_32_to_64_unsigned(args
, args
, 7);
84 munge_wwwwwwww(void *args
)
86 munge_32_to_64_unsigned(args
, args
, 8);
92 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
93 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
95 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
96 out_args
[0] = in_args
[0];
100 munge_wwl(void *args
)
102 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
103 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
105 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
106 out_args
[1] = in_args
[1];
107 out_args
[0] = in_args
[0];
111 munge_wwlw(void *args
)
113 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
114 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
116 out_args
[3] = in_args
[4];
117 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
118 out_args
[1] = in_args
[1];
119 out_args
[0] = in_args
[0];
122 munge_wwlll(void *args
)
124 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
125 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
127 out_args
[4] = *(volatile uint64_t*)&in_args
[6];
128 out_args
[3] = *(volatile uint64_t*)&in_args
[4];
129 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
130 out_args
[1] = in_args
[1];
131 out_args
[0] = in_args
[0];
135 munge_wwllww(void *args
)
137 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
138 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
140 out_args
[5] = in_args
[7];
141 out_args
[4] = in_args
[6];
142 out_args
[3] = *(volatile uint64_t*)&in_args
[4];
143 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
144 out_args
[1] = in_args
[1];
145 out_args
[0] = in_args
[0];
149 munge_wlw(void *args
)
151 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
152 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
154 out_args
[2] = in_args
[3];
155 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
156 out_args
[0] = in_args
[0];
160 munge_wlww(void *args
)
162 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
163 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
165 out_args
[3] = in_args
[4];
166 out_args
[2] = in_args
[3];
167 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
168 out_args
[0] = in_args
[0];
172 munge_wlwwwll(void *args
)
174 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
175 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
177 out_args
[6] = *(volatile uint64_t*)&in_args
[8];
178 out_args
[5] = *(volatile uint64_t*)&in_args
[6];
179 out_args
[4] = in_args
[5];
180 out_args
[3] = in_args
[4];
181 out_args
[2] = in_args
[3];
182 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
183 out_args
[0] = in_args
[0];
187 munge_wlwwwllw(void *args
)
189 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
190 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
192 out_args
[7] = in_args
[10];
197 munge_wlwwlwlw(void *args
)
199 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
200 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
202 out_args
[7] = in_args
[10];
203 out_args
[6] = *(volatile uint64_t*)&in_args
[8];
204 out_args
[5] = in_args
[7];
205 out_args
[4] = *(volatile uint64_t*)&in_args
[5];
206 out_args
[3] = in_args
[4];
207 out_args
[2] = in_args
[3];
208 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
209 out_args
[0] = in_args
[0];
213 munge_wll(void *args
)
215 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
216 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
218 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
219 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
220 out_args
[0] = in_args
[0];
224 munge_wlll(void *args
)
226 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
227 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
229 out_args
[3] = *(volatile uint64_t*)&in_args
[5];
230 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
231 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
232 out_args
[0] = in_args
[0];
236 munge_wllll(void *args
)
238 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
239 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
241 out_args
[4] = *(volatile uint64_t*)&in_args
[7];
242 out_args
[3] = *(volatile uint64_t*)&in_args
[5];
243 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
244 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
245 out_args
[0] = in_args
[0];
249 munge_wllww(void *args
)
251 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
252 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
254 out_args
[4] = in_args
[6];
255 out_args
[3] = in_args
[5];
256 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
257 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
258 out_args
[0] = in_args
[0];
262 munge_wllwwll(void *args
)
264 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
265 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
267 out_args
[6] = *(volatile uint64_t*)&in_args
[9];
268 out_args
[5] = *(volatile uint64_t*)&in_args
[7];
269 out_args
[4] = in_args
[6];
270 out_args
[3] = in_args
[5];
271 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
272 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
273 out_args
[0] = in_args
[0];
277 munge_wwwlw(void *args
)
279 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
280 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
282 out_args
[4] = in_args
[5];
283 out_args
[3] = *(volatile uint64_t*)&in_args
[3];
284 out_args
[2] = in_args
[2];
285 out_args
[1] = in_args
[1];
286 out_args
[0] = in_args
[0];
290 munge_wwwlww(void *args
)
292 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
293 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
295 out_args
[5] = in_args
[6];
296 out_args
[4] = in_args
[5];
297 out_args
[3] = *(volatile uint64_t*)&in_args
[3];
298 out_args
[2] = in_args
[2];
299 out_args
[1] = in_args
[1];
300 out_args
[0] = in_args
[0];
304 munge_wwwl(void *args
)
306 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
307 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
309 out_args
[3] = *(volatile uint64_t*)&in_args
[3];
310 out_args
[2] = in_args
[2];
311 out_args
[1] = in_args
[1];
312 out_args
[0] = in_args
[0];
316 munge_wwwwlw(void *args
)
318 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
319 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
321 out_args
[5] = in_args
[6];
322 out_args
[4] = *(volatile uint64_t*)&in_args
[4];
323 out_args
[3] = in_args
[3];
324 out_args
[2] = in_args
[2];
325 out_args
[1] = in_args
[1];
326 out_args
[0] = in_args
[0];
330 munge_wwwwl(void *args
)
332 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
333 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
335 out_args
[4] = *(volatile uint64_t*)&in_args
[4];
336 out_args
[3] = in_args
[3];
337 out_args
[2] = in_args
[2];
338 out_args
[1] = in_args
[1];
339 out_args
[0] = in_args
[0];
343 munge_wwwwwl(void *args
)
345 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
346 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
348 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
349 out_args
[4] = in_args
[4];
350 out_args
[3] = in_args
[3];
351 out_args
[2] = in_args
[2];
352 out_args
[1] = in_args
[1];
353 out_args
[0] = in_args
[0];
357 munge_wwwwwlww(void *args
)
359 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
360 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
362 out_args
[7] = in_args
[8];
363 out_args
[6] = in_args
[7];
364 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
365 out_args
[4] = in_args
[4];
366 out_args
[3] = in_args
[3];
367 out_args
[2] = in_args
[2];
368 out_args
[1] = in_args
[1];
369 out_args
[0] = in_args
[0];
373 munge_wwwwwllw(void *args
)
375 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
376 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
378 out_args
[7] = in_args
[9];
379 out_args
[6] = *(volatile uint64_t*)&in_args
[7];
380 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
381 out_args
[4] = in_args
[4];
382 out_args
[3] = in_args
[3];
383 out_args
[2] = in_args
[2];
384 out_args
[1] = in_args
[1];
385 out_args
[0] = in_args
[0];
389 munge_wwwwwlll(void *args
)
391 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
392 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
394 out_args
[7] = *(volatile uint64_t*)&in_args
[9];
395 out_args
[6] = *(volatile uint64_t*)&in_args
[7];
396 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
397 out_args
[4] = in_args
[4];
398 out_args
[3] = in_args
[3];
399 out_args
[2] = in_args
[2];
400 out_args
[1] = in_args
[1];
401 out_args
[0] = in_args
[0];
405 munge_wwwwwwl(void *args
)
407 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
408 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
410 out_args
[6] = *(volatile uint64_t*)&in_args
[6];
411 out_args
[5] = in_args
[5];
412 out_args
[4] = in_args
[4];
413 out_args
[3] = in_args
[3];
414 out_args
[2] = in_args
[2];
415 out_args
[1] = in_args
[1];
416 out_args
[0] = in_args
[0];
420 munge_wwwwwwlw(void *args
)
422 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
423 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
425 out_args
[7] = in_args
[8];
426 out_args
[6] = *(volatile uint64_t*)&in_args
[6];
427 out_args
[5] = in_args
[5];
428 out_args
[4] = in_args
[4];
429 out_args
[3] = in_args
[3];
430 out_args
[2] = in_args
[2];
431 out_args
[1] = in_args
[1];
432 out_args
[0] = in_args
[0];
436 munge_wwwwwwll(void *args
)
438 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
439 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
441 out_args
[7] = *(volatile uint64_t*)&in_args
[8];
442 out_args
[6] = *(volatile uint64_t*)&in_args
[6];
443 out_args
[5] = in_args
[5];
444 out_args
[4] = in_args
[4];
445 out_args
[3] = in_args
[3];
446 out_args
[2] = in_args
[2];
447 out_args
[1] = in_args
[1];
448 out_args
[0] = in_args
[0];
452 munge_wsw(void *args
)
454 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
455 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
457 out_args
[2] = in_args
[2];
458 out_args
[1] = (int64_t)(int)in_args
[1]; /* Sign-extend */
459 out_args
[0] = in_args
[0];
463 munge_wws(void *args
)
465 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
466 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
468 out_args
[2] = (int64_t)(int)in_args
[2]; /* Sign-extend */
469 out_args
[1] = in_args
[1];
470 out_args
[0] = in_args
[0];
474 munge_wwws(void *args
)
476 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
477 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
479 out_args
[3] = (int64_t)(int)in_args
[3]; /* Sign-extend */
480 out_args
[2] = in_args
[2];
481 out_args
[1] = in_args
[1];
482 out_args
[0] = in_args
[0];
487 munge_wwwsw(void *args
)
489 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
490 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
492 out_args
[4] = in_args
[4];
493 out_args
[3] = (int64_t)(int)in_args
[3]; /* Sign-extend */
494 out_args
[2] = in_args
[2];
495 out_args
[1] = in_args
[1];
496 out_args
[0] = in_args
[0];
500 munge_llllll(void *args __unused
)
502 /* Nothing to do, already all 64-bit */
506 munge_ll(void *args __unused
)
508 /* Nothing to do, already all 64-bit */
512 munge_l(void *args __unused
)
514 /* Nothing to do, already all 64-bit */
520 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
521 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
523 out_args
[1] = in_args
[2];
524 out_args
[0] = *(volatile uint64_t*)&in_args
[0];
528 munge_lwww(void *args
)
530 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
531 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
533 out_args
[3] = in_args
[4];
534 out_args
[2] = in_args
[3];
535 out_args
[1] = in_args
[2];
536 out_args
[0] = *(volatile uint64_t*)&in_args
[0];
540 munge_lwwwwwww(void *args
)
542 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
543 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
545 out_args
[7] = in_args
[8];
546 out_args
[6] = in_args
[7];
547 out_args
[5] = in_args
[6];
548 out_args
[4] = in_args
[5];
549 out_args
[3] = in_args
[4];
550 out_args
[2] = in_args
[3];
551 out_args
[1] = in_args
[2];
552 out_args
[0] = *(volatile uint64_t*)&in_args
[0];
556 munge_wwlww(void *args
)
558 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
559 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
561 out_args
[4] = in_args
[5];
562 out_args
[3] = in_args
[4];
563 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
564 out_args
[1] = in_args
[1];
565 out_args
[0] = in_args
[0];
569 munge_wwlwww(void *args
)
571 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
572 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
574 out_args
[5] = in_args
[6];
575 out_args
[4] = in_args
[5];
576 out_args
[3] = in_args
[4];
577 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
578 out_args
[1] = in_args
[1];
579 out_args
[0] = in_args
[0];
583 munge_wlwwwl(void *args
)
585 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
586 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
588 out_args
[5] = *(volatile uint64_t*)&in_args
[6];
589 out_args
[4] = in_args
[5];
590 out_args
[3] = in_args
[4];
591 out_args
[2] = in_args
[3];
592 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
593 out_args
[0] = in_args
[0];
597 munge_wwlwwwl(void *args
)
599 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
600 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
602 out_args
[6] = *(volatile uint64_t*)&in_args
[7];
603 out_args
[5] = in_args
[6];
604 out_args
[4] = in_args
[5];
605 out_args
[3] = in_args
[4];
606 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
607 out_args
[1] = in_args
[1];
608 out_args
[0] = in_args
[0];
612 * Munge array of 32-bit values into an array of 64-bit values,
613 * without sign extension. Note, src and dest can be the same
614 * (copies from end of array)
616 static inline __attribute__((always_inline
)) void
617 munge_32_to_64_unsigned(volatile uint64_t *dest
, volatile uint32_t *src
, int count
)
621 for (i
= count
- 1; i
>= 0; i
--) {