]>
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_wlllww(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
[5] = in_args
[8];
242 out_args
[4] = in_args
[7];
243 out_args
[3] = *(volatile uint64_t*)&in_args
[5];
244 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
245 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
246 out_args
[0] = in_args
[0];
250 munge_wllll(void *args
)
252 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
253 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
255 out_args
[4] = *(volatile uint64_t*)&in_args
[7];
256 out_args
[3] = *(volatile uint64_t*)&in_args
[5];
257 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
258 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
259 out_args
[0] = in_args
[0];
263 munge_wllww(void *args
)
265 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
266 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
268 out_args
[4] = in_args
[6];
269 out_args
[3] = in_args
[5];
270 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
271 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
272 out_args
[0] = in_args
[0];
276 munge_wllwwll(void *args
)
278 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
279 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
281 out_args
[6] = *(volatile uint64_t*)&in_args
[9];
282 out_args
[5] = *(volatile uint64_t*)&in_args
[7];
283 out_args
[4] = in_args
[6];
284 out_args
[3] = in_args
[5];
285 out_args
[2] = *(volatile uint64_t*)&in_args
[3];
286 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
287 out_args
[0] = in_args
[0];
291 munge_wwwlw(void *args
)
293 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
294 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
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_wwwlww(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
[5] = in_args
[6];
310 out_args
[4] = in_args
[5];
311 out_args
[3] = *(volatile uint64_t*)&in_args
[3];
312 out_args
[2] = in_args
[2];
313 out_args
[1] = in_args
[1];
314 out_args
[0] = in_args
[0];
318 munge_wwwlwww(void *args
)
320 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
321 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
323 out_args
[6] = in_args
[7];
324 out_args
[5] = in_args
[6];
325 out_args
[4] = in_args
[5];
326 out_args
[3] = *(volatile uint64_t*)&in_args
[3];
327 out_args
[2] = in_args
[2];
328 out_args
[1] = in_args
[1];
329 out_args
[0] = in_args
[0];
333 munge_wwwl(void *args
)
335 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
336 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
338 out_args
[3] = *(volatile uint64_t*)&in_args
[3];
339 out_args
[2] = in_args
[2];
340 out_args
[1] = in_args
[1];
341 out_args
[0] = in_args
[0];
345 munge_wwwwlw(void *args
)
347 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
348 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
350 out_args
[5] = in_args
[6];
351 out_args
[4] = *(volatile uint64_t*)&in_args
[4];
352 out_args
[3] = in_args
[3];
353 out_args
[2] = in_args
[2];
354 out_args
[1] = in_args
[1];
355 out_args
[0] = in_args
[0];
359 munge_wwwwllww(void *args
)
361 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
362 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
364 out_args
[7] = in_args
[9];
365 out_args
[6] = in_args
[8];
366 out_args
[5] = *(volatile uint64_t*)&in_args
[6];
367 out_args
[4] = *(volatile uint64_t*)&in_args
[4];
368 out_args
[3] = in_args
[3];
369 out_args
[2] = in_args
[2];
370 out_args
[1] = in_args
[1];
371 out_args
[0] = in_args
[0];
375 munge_wwwwl(void *args
)
377 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
378 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
380 out_args
[4] = *(volatile uint64_t*)&in_args
[4];
381 out_args
[3] = in_args
[3];
382 out_args
[2] = in_args
[2];
383 out_args
[1] = in_args
[1];
384 out_args
[0] = in_args
[0];
388 munge_wwwwwl(void *args
)
390 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
391 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
393 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
394 out_args
[4] = in_args
[4];
395 out_args
[3] = in_args
[3];
396 out_args
[2] = in_args
[2];
397 out_args
[1] = in_args
[1];
398 out_args
[0] = in_args
[0];
402 munge_wwwwwlww(void *args
)
404 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
405 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
407 out_args
[7] = in_args
[8];
408 out_args
[6] = in_args
[7];
409 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
410 out_args
[4] = in_args
[4];
411 out_args
[3] = in_args
[3];
412 out_args
[2] = in_args
[2];
413 out_args
[1] = in_args
[1];
414 out_args
[0] = in_args
[0];
418 munge_wwwwwllw(void *args
)
420 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
421 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
423 out_args
[7] = in_args
[9];
424 out_args
[6] = *(volatile uint64_t*)&in_args
[7];
425 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
426 out_args
[4] = in_args
[4];
427 out_args
[3] = in_args
[3];
428 out_args
[2] = in_args
[2];
429 out_args
[1] = in_args
[1];
430 out_args
[0] = in_args
[0];
434 munge_wwwwwlll(void *args
)
436 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
437 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
439 out_args
[7] = *(volatile uint64_t*)&in_args
[9];
440 out_args
[6] = *(volatile uint64_t*)&in_args
[7];
441 out_args
[5] = *(volatile uint64_t*)&in_args
[5];
442 out_args
[4] = in_args
[4];
443 out_args
[3] = in_args
[3];
444 out_args
[2] = in_args
[2];
445 out_args
[1] = in_args
[1];
446 out_args
[0] = in_args
[0];
450 munge_wwwwwwl(void *args
)
452 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
453 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
455 out_args
[6] = *(volatile uint64_t*)&in_args
[6];
456 out_args
[5] = in_args
[5];
457 out_args
[4] = in_args
[4];
458 out_args
[3] = in_args
[3];
459 out_args
[2] = in_args
[2];
460 out_args
[1] = in_args
[1];
461 out_args
[0] = in_args
[0];
465 munge_wwwwwwlw(void *args
)
467 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
468 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
470 out_args
[7] = in_args
[8];
471 out_args
[6] = *(volatile uint64_t*)&in_args
[6];
472 out_args
[5] = in_args
[5];
473 out_args
[4] = in_args
[4];
474 out_args
[3] = in_args
[3];
475 out_args
[2] = in_args
[2];
476 out_args
[1] = in_args
[1];
477 out_args
[0] = in_args
[0];
481 munge_wwwwwwll(void *args
)
483 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
484 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
486 out_args
[7] = *(volatile uint64_t*)&in_args
[8];
487 out_args
[6] = *(volatile uint64_t*)&in_args
[6];
488 out_args
[5] = in_args
[5];
489 out_args
[4] = in_args
[4];
490 out_args
[3] = in_args
[3];
491 out_args
[2] = in_args
[2];
492 out_args
[1] = in_args
[1];
493 out_args
[0] = in_args
[0];
497 munge_wsw(void *args
)
499 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
500 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
502 out_args
[2] = in_args
[2];
503 out_args
[1] = (int64_t)(int)in_args
[1]; /* Sign-extend */
504 out_args
[0] = in_args
[0];
508 munge_wws(void *args
)
510 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
511 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
513 out_args
[2] = (int64_t)(int)in_args
[2]; /* Sign-extend */
514 out_args
[1] = in_args
[1];
515 out_args
[0] = in_args
[0];
519 munge_wwws(void *args
)
521 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
522 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
524 out_args
[3] = (int64_t)(int)in_args
[3]; /* Sign-extend */
525 out_args
[2] = in_args
[2];
526 out_args
[1] = in_args
[1];
527 out_args
[0] = in_args
[0];
532 munge_wwwsw(void *args
)
534 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
535 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
537 out_args
[4] = in_args
[4];
538 out_args
[3] = (int64_t)(int)in_args
[3]; /* Sign-extend */
539 out_args
[2] = in_args
[2];
540 out_args
[1] = in_args
[1];
541 out_args
[0] = in_args
[0];
545 munge_llllll(void *args __unused
)
547 /* Nothing to do, already all 64-bit */
551 munge_ll(void *args __unused
)
553 /* Nothing to do, already all 64-bit */
557 munge_l(void *args __unused
)
559 /* Nothing to do, already all 64-bit */
565 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
566 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
568 out_args
[1] = in_args
[2];
569 out_args
[0] = *(volatile uint64_t*)&in_args
[0];
573 munge_lwww(void *args
)
575 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
576 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
578 out_args
[3] = in_args
[4];
579 out_args
[2] = in_args
[3];
580 out_args
[1] = in_args
[2];
581 out_args
[0] = *(volatile uint64_t*)&in_args
[0];
585 munge_lwwwwwww(void *args
)
587 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
588 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
590 out_args
[7] = in_args
[8];
591 out_args
[6] = in_args
[7];
592 out_args
[5] = in_args
[6];
593 out_args
[4] = in_args
[5];
594 out_args
[3] = in_args
[4];
595 out_args
[2] = in_args
[3];
596 out_args
[1] = in_args
[2];
597 out_args
[0] = *(volatile uint64_t*)&in_args
[0];
601 munge_wwlww(void *args
)
603 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
604 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
606 out_args
[4] = in_args
[5];
607 out_args
[3] = in_args
[4];
608 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
609 out_args
[1] = in_args
[1];
610 out_args
[0] = in_args
[0];
614 munge_wwlwww(void *args
)
616 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
617 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
619 out_args
[5] = in_args
[6];
620 out_args
[4] = in_args
[5];
621 out_args
[3] = in_args
[4];
622 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
623 out_args
[1] = in_args
[1];
624 out_args
[0] = in_args
[0];
628 munge_wlwwwl(void *args
)
630 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
631 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
633 out_args
[5] = *(volatile uint64_t*)&in_args
[6];
634 out_args
[4] = in_args
[5];
635 out_args
[3] = in_args
[4];
636 out_args
[2] = in_args
[3];
637 out_args
[1] = *(volatile uint64_t*)&in_args
[1];
638 out_args
[0] = in_args
[0];
642 munge_wwlwwwl(void *args
)
644 volatile uint64_t *out_args
= (volatile uint64_t*)args
;
645 volatile uint32_t *in_args
= (volatile uint32_t*)args
;
647 out_args
[6] = *(volatile uint64_t*)&in_args
[7];
648 out_args
[5] = in_args
[6];
649 out_args
[4] = in_args
[5];
650 out_args
[3] = in_args
[4];
651 out_args
[2] = *(volatile uint64_t*)&in_args
[2];
652 out_args
[1] = in_args
[1];
653 out_args
[0] = in_args
[0];
657 * Munge array of 32-bit values into an array of 64-bit values,
658 * without sign extension. Note, src and dest can be the same
659 * (copies from end of array)
661 static inline __attribute__((always_inline
)) void
662 munge_32_to_64_unsigned(volatile uint64_t *dest
, volatile uint32_t *src
, int count
)
666 for (i
= count
- 1; i
>= 0; i
--) {