]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/munge.c
xnu-6153.61.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_wllll(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[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];
246 }
247
248 void
249 munge_wllww(void *args)
250 {
251 volatile uint64_t *out_args = (volatile uint64_t*)args;
252 volatile uint32_t *in_args = (volatile uint32_t*)args;
253
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];
259 }
260
261 void
262 munge_wllwwll(void *args)
263 {
264 volatile uint64_t *out_args = (volatile uint64_t*)args;
265 volatile uint32_t *in_args = (volatile uint32_t*)args;
266
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];
274 }
275
276 void
277 munge_wwwlw(void *args)
278 {
279 volatile uint64_t *out_args = (volatile uint64_t*)args;
280 volatile uint32_t *in_args = (volatile uint32_t*)args;
281
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];
287 }
288
289 void
290 munge_wwwlww(void *args)
291 {
292 volatile uint64_t *out_args = (volatile uint64_t*)args;
293 volatile uint32_t *in_args = (volatile uint32_t*)args;
294
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];
301 }
302
303 void
304 munge_wwwl(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[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];
313 }
314
315 void
316 munge_wwwwlw(void *args)
317 {
318 volatile uint64_t *out_args = (volatile uint64_t*)args;
319 volatile uint32_t *in_args = (volatile uint32_t*)args;
320
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];
327 }
328
329 void
330 munge_wwwwl(void *args)
331 {
332 volatile uint64_t *out_args = (volatile uint64_t*)args;
333 volatile uint32_t *in_args = (volatile uint32_t*)args;
334
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];
340 }
341
342 void
343 munge_wwwwwl(void *args)
344 {
345 volatile uint64_t *out_args = (volatile uint64_t*)args;
346 volatile uint32_t *in_args = (volatile uint32_t*)args;
347
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];
354 }
355
356 void
357 munge_wwwwwlww(void *args)
358 {
359 volatile uint64_t *out_args = (volatile uint64_t*)args;
360 volatile uint32_t *in_args = (volatile uint32_t*)args;
361
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];
370 }
371
372 void
373 munge_wwwwwllw(void *args)
374 {
375 volatile uint64_t *out_args = (volatile uint64_t*)args;
376 volatile uint32_t *in_args = (volatile uint32_t*)args;
377
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];
386 }
387
388 void
389 munge_wwwwwlll(void *args)
390 {
391 volatile uint64_t *out_args = (volatile uint64_t*)args;
392 volatile uint32_t *in_args = (volatile uint32_t*)args;
393
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];
402 }
403
404 void
405 munge_wwwwwwl(void *args)
406 {
407 volatile uint64_t *out_args = (volatile uint64_t*)args;
408 volatile uint32_t *in_args = (volatile uint32_t*)args;
409
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];
417 }
418
419 void
420 munge_wwwwwwlw(void *args)
421 {
422 volatile uint64_t *out_args = (volatile uint64_t*)args;
423 volatile uint32_t *in_args = (volatile uint32_t*)args;
424
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];
433 }
434
435 void
436 munge_wwwwwwll(void *args)
437 {
438 volatile uint64_t *out_args = (volatile uint64_t*)args;
439 volatile uint32_t *in_args = (volatile uint32_t*)args;
440
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];
449 }
450
451 void
452 munge_wsw(void *args)
453 {
454 volatile uint64_t *out_args = (volatile uint64_t*)args;
455 volatile uint32_t *in_args = (volatile uint32_t*)args;
456
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];
460 }
461
462 void
463 munge_wws(void *args)
464 {
465 volatile uint64_t *out_args = (volatile uint64_t*)args;
466 volatile uint32_t *in_args = (volatile uint32_t*)args;
467
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];
471 }
472
473 void
474 munge_wwws(void *args)
475 {
476 volatile uint64_t *out_args = (volatile uint64_t*)args;
477 volatile uint32_t *in_args = (volatile uint32_t*)args;
478
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];
483 }
484
485
486 void
487 munge_wwwsw(void *args)
488 {
489 volatile uint64_t *out_args = (volatile uint64_t*)args;
490 volatile uint32_t *in_args = (volatile uint32_t*)args;
491
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];
497 }
498
499 void
500 munge_llllll(void *args __unused)
501 {
502 /* Nothing to do, already all 64-bit */
503 }
504
505 void
506 munge_ll(void *args __unused)
507 {
508 /* Nothing to do, already all 64-bit */
509 }
510
511 void
512 munge_l(void *args __unused)
513 {
514 /* Nothing to do, already all 64-bit */
515 }
516
517 void
518 munge_lw(void *args)
519 {
520 volatile uint64_t *out_args = (volatile uint64_t*)args;
521 volatile uint32_t *in_args = (volatile uint32_t*)args;
522
523 out_args[1] = in_args[2];
524 out_args[0] = *(volatile uint64_t*)&in_args[0];
525 }
526
527 void
528 munge_lwww(void *args)
529 {
530 volatile uint64_t *out_args = (volatile uint64_t*)args;
531 volatile uint32_t *in_args = (volatile uint32_t*)args;
532
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];
537 }
538
539 void
540 munge_lwwwwwww(void *args)
541 {
542 volatile uint64_t *out_args = (volatile uint64_t*)args;
543 volatile uint32_t *in_args = (volatile uint32_t*)args;
544
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];
553 }
554
555 void
556 munge_wwlww(void *args)
557 {
558 volatile uint64_t *out_args = (volatile uint64_t*)args;
559 volatile uint32_t *in_args = (volatile uint32_t*)args;
560
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];
566 }
567
568 void
569 munge_wwlwww(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[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];
580 }
581
582 void
583 munge_wlwwwl(void *args)
584 {
585 volatile uint64_t *out_args = (volatile uint64_t*)args;
586 volatile uint32_t *in_args = (volatile uint32_t*)args;
587
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];
594 }
595
596 void
597 munge_wwlwwwl(void *args)
598 {
599 volatile uint64_t *out_args = (volatile uint64_t*)args;
600 volatile uint32_t *in_args = (volatile uint32_t*)args;
601
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];
609 }
610
611 /*
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)
615 */
616 static inline __attribute__((always_inline)) void
617 munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count)
618 {
619 int i;
620
621 for (i = count - 1; i >= 0; i--) {
622 dest[i] = src[i];
623 }
624 }