]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/munge.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / dev / munge.c
1 /*
2 * Coyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <sys/cdefs.h>
30 #include <sys/types.h>
31 #include <sys/munge.h>
32 #include <stdint.h>
33
34 /*
35 * Refer to comments in bsd/sys/munge.h
36 */
37
38 static inline __attribute__((always_inline)) void
39 munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count);
40
41 void
42 munge_w(void *args)
43 {
44 munge_32_to_64_unsigned(args, args, 1);
45 }
46
47 void
48 munge_ww(void *args)
49 {
50 munge_32_to_64_unsigned(args, args, 2);
51 }
52
53 void
54 munge_www(void *args)
55 {
56 munge_32_to_64_unsigned(args, args, 3);
57 }
58
59 void
60 munge_wwww(void *args)
61 {
62 munge_32_to_64_unsigned(args, args, 4);
63 }
64
65 void
66 munge_wwwww(void *args)
67 {
68 munge_32_to_64_unsigned(args, args, 5);
69 }
70
71 void
72 munge_wwwwww(void *args)
73 {
74 munge_32_to_64_unsigned(args, args, 6);
75 }
76
77 void
78 munge_wwwwwww(void *args)
79 {
80 munge_32_to_64_unsigned(args, args, 7);
81 }
82
83 void
84 munge_wwwwwwww(void *args)
85 {
86 munge_32_to_64_unsigned(args, args, 8);
87 }
88
89 void
90 munge_wl(void *args)
91 {
92 volatile uint64_t *out_args = (volatile uint64_t*)args;
93 volatile uint32_t *in_args = (volatile uint32_t*)args;
94
95 out_args[1] = *(volatile uint64_t*)&in_args[1];
96 out_args[0] = in_args[0];
97 }
98
99 void
100 munge_wwl(void *args)
101 {
102 volatile uint64_t *out_args = (volatile uint64_t*)args;
103 volatile uint32_t *in_args = (volatile uint32_t*)args;
104
105 out_args[2] = *(volatile uint64_t*)&in_args[2];
106 out_args[1] = in_args[1];
107 out_args[0] = in_args[0];
108 }
109
110 void
111 munge_wwlw(void *args)
112 {
113 volatile uint64_t *out_args = (volatile uint64_t*)args;
114 volatile uint32_t *in_args = (volatile uint32_t*)args;
115
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];
120 }
121 void
122 munge_wwlll(void *args)
123 {
124 volatile uint64_t *out_args = (volatile uint64_t*)args;
125 volatile uint32_t *in_args = (volatile uint32_t*)args;
126
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];
132 }
133
134 void
135 munge_wwllww(void *args)
136 {
137 volatile uint64_t *out_args = (volatile uint64_t*)args;
138 volatile uint32_t *in_args = (volatile uint32_t*)args;
139
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];
146 }
147
148 void
149 munge_wlw(void *args)
150 {
151 volatile uint64_t *out_args = (volatile uint64_t*)args;
152 volatile uint32_t *in_args = (volatile uint32_t*)args;
153
154 out_args[2] = in_args[3];
155 out_args[1] = *(volatile uint64_t*)&in_args[1];
156 out_args[0] = in_args[0];
157 }
158
159 void
160 munge_wlww(void *args)
161 {
162 volatile uint64_t *out_args = (volatile uint64_t*)args;
163 volatile uint32_t *in_args = (volatile uint32_t*)args;
164
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];
169 }
170
171 void
172 munge_wlwwwll(void *args)
173 {
174 volatile uint64_t *out_args = (volatile uint64_t*)args;
175 volatile uint32_t *in_args = (volatile uint32_t*)args;
176
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];
184 }
185
186 void
187 munge_wlwwwllw(void *args)
188 {
189 volatile uint64_t *out_args = (volatile uint64_t*)args;
190 volatile uint32_t *in_args = (volatile uint32_t*)args;
191
192 out_args[7] = in_args[10];
193 munge_wlwwwll(args);
194 }
195
196 void
197 munge_wlwwlwlw(void *args)
198 {
199 volatile uint64_t *out_args = (volatile uint64_t*)args;
200 volatile uint32_t *in_args = (volatile uint32_t*)args;
201
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];
210 }
211
212 void
213 munge_wll(void *args)
214 {
215 volatile uint64_t *out_args = (volatile uint64_t*)args;
216 volatile uint32_t *in_args = (volatile uint32_t*)args;
217
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];
221 }
222
223 void
224 munge_wlll(void *args)
225 {
226 volatile uint64_t *out_args = (volatile uint64_t*)args;
227 volatile uint32_t *in_args = (volatile uint32_t*)args;
228
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];
233 }
234
235 void
236 munge_wlllww(void *args)
237 {
238 volatile uint64_t *out_args = (volatile uint64_t*)args;
239 volatile uint32_t *in_args = (volatile uint32_t*)args;
240
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];
247 }
248
249 void
250 munge_wllll(void *args)
251 {
252 volatile uint64_t *out_args = (volatile uint64_t*)args;
253 volatile uint32_t *in_args = (volatile uint32_t*)args;
254
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];
260 }
261
262 void
263 munge_wllww(void *args)
264 {
265 volatile uint64_t *out_args = (volatile uint64_t*)args;
266 volatile uint32_t *in_args = (volatile uint32_t*)args;
267
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];
273 }
274
275 void
276 munge_wllwwll(void *args)
277 {
278 volatile uint64_t *out_args = (volatile uint64_t*)args;
279 volatile uint32_t *in_args = (volatile uint32_t*)args;
280
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];
288 }
289
290 void
291 munge_wwwlw(void *args)
292 {
293 volatile uint64_t *out_args = (volatile uint64_t*)args;
294 volatile uint32_t *in_args = (volatile uint32_t*)args;
295
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];
301 }
302
303 void
304 munge_wwwlww(void *args)
305 {
306 volatile uint64_t *out_args = (volatile uint64_t*)args;
307 volatile uint32_t *in_args = (volatile uint32_t*)args;
308
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];
315 }
316
317 void
318 munge_wwwlwww(void *args)
319 {
320 volatile uint64_t *out_args = (volatile uint64_t*)args;
321 volatile uint32_t *in_args = (volatile uint32_t*)args;
322
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];
330 }
331
332 void
333 munge_wwwl(void *args)
334 {
335 volatile uint64_t *out_args = (volatile uint64_t*)args;
336 volatile uint32_t *in_args = (volatile uint32_t*)args;
337
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];
342 }
343
344 void
345 munge_wwwwlw(void *args)
346 {
347 volatile uint64_t *out_args = (volatile uint64_t*)args;
348 volatile uint32_t *in_args = (volatile uint32_t*)args;
349
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];
356 }
357
358 void
359 munge_wwwwllww(void *args)
360 {
361 volatile uint64_t *out_args = (volatile uint64_t*)args;
362 volatile uint32_t *in_args = (volatile uint32_t*)args;
363
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];
372 }
373
374 void
375 munge_wwwwl(void *args)
376 {
377 volatile uint64_t *out_args = (volatile uint64_t*)args;
378 volatile uint32_t *in_args = (volatile uint32_t*)args;
379
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];
385 }
386
387 void
388 munge_wwwwwl(void *args)
389 {
390 volatile uint64_t *out_args = (volatile uint64_t*)args;
391 volatile uint32_t *in_args = (volatile uint32_t*)args;
392
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];
399 }
400
401 void
402 munge_wwwwwlww(void *args)
403 {
404 volatile uint64_t *out_args = (volatile uint64_t*)args;
405 volatile uint32_t *in_args = (volatile uint32_t*)args;
406
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];
415 }
416
417 void
418 munge_wwwwwllw(void *args)
419 {
420 volatile uint64_t *out_args = (volatile uint64_t*)args;
421 volatile uint32_t *in_args = (volatile uint32_t*)args;
422
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];
431 }
432
433 void
434 munge_wwwwwlll(void *args)
435 {
436 volatile uint64_t *out_args = (volatile uint64_t*)args;
437 volatile uint32_t *in_args = (volatile uint32_t*)args;
438
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];
447 }
448
449 void
450 munge_wwwwwwl(void *args)
451 {
452 volatile uint64_t *out_args = (volatile uint64_t*)args;
453 volatile uint32_t *in_args = (volatile uint32_t*)args;
454
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];
462 }
463
464 void
465 munge_wwwwwwlw(void *args)
466 {
467 volatile uint64_t *out_args = (volatile uint64_t*)args;
468 volatile uint32_t *in_args = (volatile uint32_t*)args;
469
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];
478 }
479
480 void
481 munge_wwwwwwll(void *args)
482 {
483 volatile uint64_t *out_args = (volatile uint64_t*)args;
484 volatile uint32_t *in_args = (volatile uint32_t*)args;
485
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];
494 }
495
496 void
497 munge_wsw(void *args)
498 {
499 volatile uint64_t *out_args = (volatile uint64_t*)args;
500 volatile uint32_t *in_args = (volatile uint32_t*)args;
501
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];
505 }
506
507 void
508 munge_wws(void *args)
509 {
510 volatile uint64_t *out_args = (volatile uint64_t*)args;
511 volatile uint32_t *in_args = (volatile uint32_t*)args;
512
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];
516 }
517
518 void
519 munge_wwws(void *args)
520 {
521 volatile uint64_t *out_args = (volatile uint64_t*)args;
522 volatile uint32_t *in_args = (volatile uint32_t*)args;
523
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];
528 }
529
530
531 void
532 munge_wwwsw(void *args)
533 {
534 volatile uint64_t *out_args = (volatile uint64_t*)args;
535 volatile uint32_t *in_args = (volatile uint32_t*)args;
536
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];
542 }
543
544 void
545 munge_llllll(void *args __unused)
546 {
547 /* Nothing to do, already all 64-bit */
548 }
549
550 void
551 munge_llll(void *args __unused)
552 {
553 /* Nothing to do, already all 64-bit */
554 }
555
556 void
557 munge_ll(void *args __unused)
558 {
559 /* Nothing to do, already all 64-bit */
560 }
561
562 void
563 munge_l(void *args __unused)
564 {
565 /* Nothing to do, already all 64-bit */
566 }
567
568 void
569 munge_lw(void *args)
570 {
571 volatile uint64_t *out_args = (volatile uint64_t*)args;
572 volatile uint32_t *in_args = (volatile uint32_t*)args;
573
574 out_args[1] = in_args[2];
575 out_args[0] = *(volatile uint64_t*)&in_args[0];
576 }
577
578 void
579 munge_lwww(void *args)
580 {
581 volatile uint64_t *out_args = (volatile uint64_t*)args;
582 volatile uint32_t *in_args = (volatile uint32_t*)args;
583
584 out_args[3] = in_args[4];
585 out_args[2] = in_args[3];
586 out_args[1] = in_args[2];
587 out_args[0] = *(volatile uint64_t*)&in_args[0];
588 }
589
590 void
591 munge_lwwwwwww(void *args)
592 {
593 volatile uint64_t *out_args = (volatile uint64_t*)args;
594 volatile uint32_t *in_args = (volatile uint32_t*)args;
595
596 out_args[7] = in_args[8];
597 out_args[6] = in_args[7];
598 out_args[5] = in_args[6];
599 out_args[4] = in_args[5];
600 out_args[3] = in_args[4];
601 out_args[2] = in_args[3];
602 out_args[1] = in_args[2];
603 out_args[0] = *(volatile uint64_t*)&in_args[0];
604 }
605
606 void
607 munge_wwlww(void *args)
608 {
609 volatile uint64_t *out_args = (volatile uint64_t*)args;
610 volatile uint32_t *in_args = (volatile uint32_t*)args;
611
612 out_args[4] = in_args[5];
613 out_args[3] = in_args[4];
614 out_args[2] = *(volatile uint64_t*)&in_args[2];
615 out_args[1] = in_args[1];
616 out_args[0] = in_args[0];
617 }
618
619 void
620 munge_wwlwww(void *args)
621 {
622 volatile uint64_t *out_args = (volatile uint64_t*)args;
623 volatile uint32_t *in_args = (volatile uint32_t*)args;
624
625 out_args[5] = in_args[6];
626 out_args[4] = in_args[5];
627 out_args[3] = in_args[4];
628 out_args[2] = *(volatile uint64_t*)&in_args[2];
629 out_args[1] = in_args[1];
630 out_args[0] = in_args[0];
631 }
632
633 void
634 munge_wlwwwl(void *args)
635 {
636 volatile uint64_t *out_args = (volatile uint64_t*)args;
637 volatile uint32_t *in_args = (volatile uint32_t*)args;
638
639 out_args[5] = *(volatile uint64_t*)&in_args[6];
640 out_args[4] = in_args[5];
641 out_args[3] = in_args[4];
642 out_args[2] = in_args[3];
643 out_args[1] = *(volatile uint64_t*)&in_args[1];
644 out_args[0] = in_args[0];
645 }
646
647 void
648 munge_wwlwwwl(void *args)
649 {
650 volatile uint64_t *out_args = (volatile uint64_t*)args;
651 volatile uint32_t *in_args = (volatile uint32_t*)args;
652
653 out_args[6] = *(volatile uint64_t*)&in_args[7];
654 out_args[5] = in_args[6];
655 out_args[4] = in_args[5];
656 out_args[3] = in_args[4];
657 out_args[2] = *(volatile uint64_t*)&in_args[2];
658 out_args[1] = in_args[1];
659 out_args[0] = in_args[0];
660 }
661
662 /*
663 * Munge array of 32-bit values into an array of 64-bit values,
664 * without sign extension. Note, src and dest can be the same
665 * (copies from end of array)
666 */
667 static inline __attribute__((always_inline)) void
668 munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count)
669 {
670 int i;
671
672 for (i = count - 1; i >= 0; i--) {
673 dest[i] = src[i];
674 }
675 }