]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/munge.c
xnu-4903.241.1.tar.gz
[apple/xnu.git] / bsd / dev / munge.c
CommitLineData
39236c6e
A
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
39236c6e
A
34/*
35 * Refer to comments in bsd/sys/munge.h
36 */
fe8ab488
A
37
38static inline __attribute__((always_inline)) void
39munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count);
40
39236c6e 41void
fe8ab488 42munge_w(void *args)
39236c6e
A
43{
44 munge_32_to_64_unsigned(args, args, 1);
45}
46
47void
fe8ab488 48munge_ww(void *args)
39236c6e
A
49{
50 munge_32_to_64_unsigned(args, args, 2);
51}
52
53void
fe8ab488 54munge_www(void *args)
39236c6e
A
55{
56 munge_32_to_64_unsigned(args, args, 3);
57}
58
59void
fe8ab488 60munge_wwww(void *args)
39236c6e
A
61{
62 munge_32_to_64_unsigned(args, args, 4);
63}
64
65void
fe8ab488 66munge_wwwww(void *args)
39236c6e
A
67{
68 munge_32_to_64_unsigned(args, args, 5);
69}
70
71void
fe8ab488 72munge_wwwwww(void *args)
39236c6e
A
73{
74 munge_32_to_64_unsigned(args, args, 6);
75}
76
77void
fe8ab488 78munge_wwwwwww(void *args)
39236c6e
A
79{
80 munge_32_to_64_unsigned(args, args, 7);
81}
82
83void
fe8ab488 84munge_wwwwwwww(void *args)
39236c6e
A
85{
86 munge_32_to_64_unsigned(args, args, 8);
87}
88
89void
fe8ab488 90munge_wl(void *args)
39236c6e
A
91{
92 volatile uint64_t *out_args = (volatile uint64_t*)args;
93 volatile uint32_t *in_args = (volatile uint32_t*)args;
94
3e170ce0 95 out_args[1] = *(volatile uint64_t*)&in_args[1];
39236c6e
A
96 out_args[0] = in_args[0];
97}
98
99void
fe8ab488 100munge_wwl(void *args)
39236c6e
A
101{
102 volatile uint64_t *out_args = (volatile uint64_t*)args;
103 volatile uint32_t *in_args = (volatile uint32_t*)args;
104
3e170ce0 105 out_args[2] = *(volatile uint64_t*)&in_args[2];
39236c6e
A
106 out_args[1] = in_args[1];
107 out_args[0] = in_args[0];
108}
109
110void
fe8ab488 111munge_wwlw(void *args)
39236c6e
A
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];
3e170ce0 117 out_args[2] = *(volatile uint64_t*)&in_args[2];
39236c6e
A
118 out_args[1] = in_args[1];
119 out_args[0] = in_args[0];
120}
121void
fe8ab488 122munge_wwlll(void *args)
39236c6e
A
123{
124 volatile uint64_t *out_args = (volatile uint64_t*)args;
125 volatile uint32_t *in_args = (volatile uint32_t*)args;
126
3e170ce0
A
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];
39236c6e
A
130 out_args[1] = in_args[1];
131 out_args[0] = in_args[0];
132}
133
134void
fe8ab488 135munge_wwllww(void *args)
39236c6e
A
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];
3e170ce0
A
142 out_args[3] = *(volatile uint64_t*)&in_args[4];
143 out_args[2] = *(volatile uint64_t*)&in_args[2];
39236c6e
A
144 out_args[1] = in_args[1];
145 out_args[0] = in_args[0];
146}
147
148void
fe8ab488 149munge_wlw(void *args)
39236c6e
A
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];
3e170ce0
A
155 out_args[1] = *(volatile uint64_t*)&in_args[1];
156 out_args[0] = in_args[0];
157}
158
159void
160munge_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];
39236c6e
A
168 out_args[0] = in_args[0];
169}
170
171void
fe8ab488 172munge_wlwwwll(void *args)
39236c6e
A
173{
174 volatile uint64_t *out_args = (volatile uint64_t*)args;
175 volatile uint32_t *in_args = (volatile uint32_t*)args;
176
3e170ce0
A
177 out_args[6] = *(volatile uint64_t*)&in_args[8];
178 out_args[5] = *(volatile uint64_t*)&in_args[6];
39236c6e
A
179 out_args[4] = in_args[5];
180 out_args[3] = in_args[4];
181 out_args[2] = in_args[3];
3e170ce0 182 out_args[1] = *(volatile uint64_t*)&in_args[1];
39236c6e
A
183 out_args[0] = in_args[0];
184}
185
186void
fe8ab488 187munge_wlwwwllw(void *args)
39236c6e
A
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];
fe8ab488 193 munge_wlwwwll(args);
39236c6e
A
194}
195
196void
fe8ab488 197munge_wlwwlwlw(void *args)
39236c6e
A
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];
3e170ce0 203 out_args[6] = *(volatile uint64_t*)&in_args[8];
39236c6e 204 out_args[5] = in_args[7];
3e170ce0 205 out_args[4] = *(volatile uint64_t*)&in_args[5];
39236c6e
A
206 out_args[3] = in_args[4];
207 out_args[2] = in_args[3];
3e170ce0 208 out_args[1] = *(volatile uint64_t*)&in_args[1];
39236c6e
A
209 out_args[0] = in_args[0];
210}
211
212void
fe8ab488 213munge_wll(void *args)
39236c6e
A
214{
215 volatile uint64_t *out_args = (volatile uint64_t*)args;
216 volatile uint32_t *in_args = (volatile uint32_t*)args;
217
3e170ce0
A
218 out_args[2] = *(volatile uint64_t*)&in_args[3];
219 out_args[1] = *(volatile uint64_t*)&in_args[1];
39236c6e
A
220 out_args[0] = in_args[0];
221}
222
223void
fe8ab488 224munge_wlll(void *args)
39236c6e
A
225{
226 volatile uint64_t *out_args = (volatile uint64_t*)args;
227 volatile uint32_t *in_args = (volatile uint32_t*)args;
228
3e170ce0
A
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];
a1c7dba1
A
232 out_args[0] = in_args[0];
233}
234
235void
236munge_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
3e170ce0
A
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];
39236c6e
A
245 out_args[0] = in_args[0];
246}
247
248void
fe8ab488 249munge_wllww(void *args)
39236c6e
A
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];
3e170ce0
A
256 out_args[2] = *(volatile uint64_t*)&in_args[3];
257 out_args[1] = *(volatile uint64_t*)&in_args[1];
39236c6e
A
258 out_args[0] = in_args[0];
259}
260
261void
fe8ab488 262munge_wllwwll(void *args)
39236c6e
A
263{
264 volatile uint64_t *out_args = (volatile uint64_t*)args;
265 volatile uint32_t *in_args = (volatile uint32_t*)args;
266
3e170ce0
A
267 out_args[6] = *(volatile uint64_t*)&in_args[9];
268 out_args[5] = *(volatile uint64_t*)&in_args[7];
39236c6e
A
269 out_args[4] = in_args[6];
270 out_args[3] = in_args[5];
3e170ce0
A
271 out_args[2] = *(volatile uint64_t*)&in_args[3];
272 out_args[1] = *(volatile uint64_t*)&in_args[1];
39236c6e
A
273 out_args[0] = in_args[0];
274}
275
276void
fe8ab488 277munge_wwwlw(void *args)
39236c6e
A
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];
3e170ce0 283 out_args[3] = *(volatile uint64_t*)&in_args[3];
39236c6e
A
284 out_args[2] = in_args[2];
285 out_args[1] = in_args[1];
286 out_args[0] = in_args[0];
287}
288
289void
fe8ab488 290munge_wwwlww(void *args)
39236c6e
A
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];
3e170ce0 297 out_args[3] = *(volatile uint64_t*)&in_args[3];
39236c6e
A
298 out_args[2] = in_args[2];
299 out_args[1] = in_args[1];
300 out_args[0] = in_args[0];
301}
302
303void
fe8ab488 304munge_wwwl(void *args)
39236c6e
A
305{
306 volatile uint64_t *out_args = (volatile uint64_t*)args;
307 volatile uint32_t *in_args = (volatile uint32_t*)args;
308
3e170ce0 309 out_args[3] = *(volatile uint64_t*)&in_args[3];
39236c6e
A
310 out_args[2] = in_args[2];
311 out_args[1] = in_args[1];
312 out_args[0] = in_args[0];
313}
314
315void
fe8ab488 316munge_wwwwlw(void *args)
39236c6e
A
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];
3e170ce0 322 out_args[4] = *(volatile uint64_t*)&in_args[4];
39236c6e
A
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
329void
fe8ab488 330munge_wwwwl(void *args)
39236c6e
A
331{
332 volatile uint64_t *out_args = (volatile uint64_t*)args;
333 volatile uint32_t *in_args = (volatile uint32_t*)args;
334
3e170ce0 335 out_args[4] = *(volatile uint64_t*)&in_args[4];
39236c6e
A
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
342void
fe8ab488 343munge_wwwwwl(void *args)
39236c6e
A
344{
345 volatile uint64_t *out_args = (volatile uint64_t*)args;
346 volatile uint32_t *in_args = (volatile uint32_t*)args;
347
3e170ce0 348 out_args[5] = *(volatile uint64_t*)&in_args[5];
39236c6e
A
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
356void
fe8ab488 357munge_wwwwwlww(void *args)
39236c6e
A
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];
3e170ce0 364 out_args[5] = *(volatile uint64_t*)&in_args[5];
39236c6e
A
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
372void
fe8ab488 373munge_wwwwwllw(void *args)
39236c6e
A
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];
3e170ce0
A
379 out_args[6] = *(volatile uint64_t*)&in_args[7];
380 out_args[5] = *(volatile uint64_t*)&in_args[5];
39236c6e
A
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
388void
fe8ab488 389munge_wwwwwlll(void *args)
39236c6e
A
390{
391 volatile uint64_t *out_args = (volatile uint64_t*)args;
392 volatile uint32_t *in_args = (volatile uint32_t*)args;
393
3e170ce0
A
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];
39236c6e
A
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
404void
fe8ab488 405munge_wwwwwwl(void *args)
39236c6e
A
406{
407 volatile uint64_t *out_args = (volatile uint64_t*)args;
408 volatile uint32_t *in_args = (volatile uint32_t*)args;
409
3e170ce0 410 out_args[6] = *(volatile uint64_t*)&in_args[6];
39236c6e
A
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
419void
fe8ab488 420munge_wwwwwwlw(void *args)
39236c6e
A
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];
3e170ce0 426 out_args[6] = *(volatile uint64_t*)&in_args[6];
39236c6e
A
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
435void
fe8ab488 436munge_wwwwwwll(void *args)
39236c6e
A
437{
438 volatile uint64_t *out_args = (volatile uint64_t*)args;
439 volatile uint32_t *in_args = (volatile uint32_t*)args;
440
3e170ce0
A
441 out_args[7] = *(volatile uint64_t*)&in_args[8];
442 out_args[6] = *(volatile uint64_t*)&in_args[6];
39236c6e
A
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
451void
fe8ab488 452munge_wsw(void *args)
39236c6e
A
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
462void
fe8ab488 463munge_wws(void *args)
39236c6e
A
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
473void
3e170ce0
A
474munge_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
486void
fe8ab488 487munge_wwwsw(void *args)
39236c6e
A
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
499void
fe8ab488 500munge_llllll(void *args __unused)
39236c6e
A
501{
502 /* Nothing to do, already all 64-bit */
503}
504
505void
fe8ab488 506munge_ll(void *args __unused)
39236c6e
A
507{
508 /* Nothing to do, already all 64-bit */
509}
510
511void
fe8ab488 512munge_l(void *args __unused)
39236c6e
A
513{
514 /* Nothing to do, already all 64-bit */
515}
516
517void
fe8ab488 518munge_lw(void *args)
39236c6e
A
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];
3e170ce0 524 out_args[0] = *(volatile uint64_t*)&in_args[0];
39236c6e
A
525}
526
527void
fe8ab488 528munge_lwww(void *args)
39236c6e
A
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];
3e170ce0 536 out_args[0] = *(volatile uint64_t*)&in_args[0];
39236c6e
A
537}
538
5ba3f43e
A
539void
540munge_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
39037602
A
555void
556munge_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
39236c6e 568void
fe8ab488 569munge_wwlwww(void *args)
39236c6e
A
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];
3e170ce0 577 out_args[2] = *(volatile uint64_t*)&in_args[2];
39236c6e
A
578 out_args[1] = in_args[1];
579 out_args[0] = in_args[0];
580}
581
39037602
A
582void
583munge_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
596void
597munge_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
39236c6e
A
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 */
616static inline __attribute__((always_inline)) void
617munge_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}