]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/munge.c
xnu-2782.10.72.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
95 out_args[1] = *(uint64_t*)&in_args[1];
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
105 out_args[2] = *(uint64_t*)&in_args[2];
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];
117 out_args[2] = *(uint64_t*)&in_args[2];
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
127 out_args[4] = *(uint64_t*)&in_args[6];
128 out_args[3] = *(uint64_t*)&in_args[4];
129 out_args[2] = *(uint64_t*)&in_args[2];
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];
142 out_args[3] = *(uint64_t*)&in_args[4];
143 out_args[2] = *(uint64_t*)&in_args[2];
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];
155 out_args[1] = *(uint64_t*)&in_args[1];
156 out_args[0] = in_args[0];
157}
158
159void
fe8ab488 160munge_wlwwwll(void *args)
39236c6e
A
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[6] = *(uint64_t*)&in_args[8];
166 out_args[5] = *(uint64_t*)&in_args[6];
167 out_args[4] = in_args[5];
168 out_args[3] = in_args[4];
169 out_args[2] = in_args[3];
170 out_args[1] = *(uint64_t*)&in_args[1];
171 out_args[0] = in_args[0];
172}
173
174void
fe8ab488 175munge_wlwwwllw(void *args)
39236c6e
A
176{
177 volatile uint64_t *out_args = (volatile uint64_t*)args;
178 volatile uint32_t *in_args = (volatile uint32_t*)args;
179
180 out_args[7] = in_args[10];
fe8ab488 181 munge_wlwwwll(args);
39236c6e
A
182}
183
184void
fe8ab488 185munge_wlwwlwlw(void *args)
39236c6e
A
186{
187 volatile uint64_t *out_args = (volatile uint64_t*)args;
188 volatile uint32_t *in_args = (volatile uint32_t*)args;
189
190 out_args[7] = in_args[10];
191 out_args[6] = *(uint64_t*)&in_args[8];
192 out_args[5] = in_args[7];
193 out_args[4] = *(uint64_t*)&in_args[5];
194 out_args[3] = in_args[4];
195 out_args[2] = in_args[3];
196 out_args[1] = *(uint64_t*)&in_args[1];
197 out_args[0] = in_args[0];
198}
199
200void
fe8ab488 201munge_wll(void *args)
39236c6e
A
202{
203 volatile uint64_t *out_args = (volatile uint64_t*)args;
204 volatile uint32_t *in_args = (volatile uint32_t*)args;
205
206 out_args[2] = *(uint64_t*)&in_args[3];
207 out_args[1] = *(uint64_t*)&in_args[1];
208 out_args[0] = in_args[0];
209}
210
211void
fe8ab488 212munge_wlll(void *args)
39236c6e
A
213{
214 volatile uint64_t *out_args = (volatile uint64_t*)args;
215 volatile uint32_t *in_args = (volatile uint32_t*)args;
216
217 out_args[3] = *(uint64_t*)&in_args[5];
218 out_args[2] = *(uint64_t*)&in_args[3];
219 out_args[1] = *(uint64_t*)&in_args[1];
a1c7dba1
A
220 out_args[0] = in_args[0];
221}
222
223void
224munge_wllll(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[4] = *(uint64_t*)&in_args[7];
230 out_args[3] = *(uint64_t*)&in_args[5];
231 out_args[2] = *(uint64_t*)&in_args[3];
232 out_args[1] = *(uint64_t*)&in_args[1];
39236c6e
A
233 out_args[0] = in_args[0];
234}
235
236void
fe8ab488 237munge_wllww(void *args)
39236c6e
A
238{
239 volatile uint64_t *out_args = (volatile uint64_t*)args;
240 volatile uint32_t *in_args = (volatile uint32_t*)args;
241
242 out_args[4] = in_args[6];
243 out_args[3] = in_args[5];
244 out_args[2] = *(uint64_t*)&in_args[3];
245 out_args[1] = *(uint64_t*)&in_args[1];
246 out_args[0] = in_args[0];
247}
248
249void
fe8ab488 250munge_wllwwll(void *args)
39236c6e
A
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[6] = *(uint64_t*)&in_args[9];
256 out_args[5] = *(uint64_t*)&in_args[7];
257 out_args[4] = in_args[6];
258 out_args[3] = in_args[5];
259 out_args[2] = *(uint64_t*)&in_args[3];
260 out_args[1] = *(uint64_t*)&in_args[1];
261 out_args[0] = in_args[0];
262}
263
264void
fe8ab488 265munge_wwwlw(void *args)
39236c6e
A
266{
267 volatile uint64_t *out_args = (volatile uint64_t*)args;
268 volatile uint32_t *in_args = (volatile uint32_t*)args;
269
270 out_args[4] = in_args[5];
271 out_args[3] = *(uint64_t*)&in_args[3];
272 out_args[2] = in_args[2];
273 out_args[1] = in_args[1];
274 out_args[0] = in_args[0];
275}
276
277void
fe8ab488 278munge_wwwlww(void *args)
39236c6e
A
279{
280 volatile uint64_t *out_args = (volatile uint64_t*)args;
281 volatile uint32_t *in_args = (volatile uint32_t*)args;
282
283 out_args[5] = in_args[6];
284 out_args[4] = in_args[5];
285 out_args[3] = *(uint64_t*)&in_args[3];
286 out_args[2] = in_args[2];
287 out_args[1] = in_args[1];
288 out_args[0] = in_args[0];
289}
290
291void
fe8ab488 292munge_wwwl(void *args)
39236c6e
A
293{
294 volatile uint64_t *out_args = (volatile uint64_t*)args;
295 volatile uint32_t *in_args = (volatile uint32_t*)args;
296
297 out_args[3] = *(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
303void
fe8ab488 304munge_wwwwlw(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
309 out_args[5] = in_args[6];
310 out_args[4] = *(uint64_t*)&in_args[4];
311 out_args[3] = 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
317void
fe8ab488 318munge_wwwwl(void *args)
39236c6e
A
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[4] = *(uint64_t*)&in_args[4];
324 out_args[3] = in_args[3];
325 out_args[2] = in_args[2];
326 out_args[1] = in_args[1];
327 out_args[0] = in_args[0];
328}
329
330void
fe8ab488 331munge_wwwwwl(void *args)
39236c6e
A
332{
333 volatile uint64_t *out_args = (volatile uint64_t*)args;
334 volatile uint32_t *in_args = (volatile uint32_t*)args;
335
336 out_args[5] = *(uint64_t*)&in_args[5];
337 out_args[4] = in_args[4];
338 out_args[3] = 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
344void
fe8ab488 345munge_wwwwwlww(void *args)
39236c6e
A
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[7] = in_args[8];
351 out_args[6] = in_args[7];
352 out_args[5] = *(uint64_t*)&in_args[5];
353 out_args[4] = in_args[4];
354 out_args[3] = in_args[3];
355 out_args[2] = in_args[2];
356 out_args[1] = in_args[1];
357 out_args[0] = in_args[0];
358}
359
360void
fe8ab488 361munge_wwwwwllw(void *args)
39236c6e
A
362{
363 volatile uint64_t *out_args = (volatile uint64_t*)args;
364 volatile uint32_t *in_args = (volatile uint32_t*)args;
365
366 out_args[7] = in_args[9];
367 out_args[6] = *(uint64_t*)&in_args[7];
368 out_args[5] = *(uint64_t*)&in_args[5];
369 out_args[4] = in_args[4];
370 out_args[3] = in_args[3];
371 out_args[2] = in_args[2];
372 out_args[1] = in_args[1];
373 out_args[0] = in_args[0];
374}
375
376void
fe8ab488 377munge_wwwwwlll(void *args)
39236c6e
A
378{
379 volatile uint64_t *out_args = (volatile uint64_t*)args;
380 volatile uint32_t *in_args = (volatile uint32_t*)args;
381
382 out_args[7] = *(uint64_t*)&in_args[9];
383 out_args[6] = *(uint64_t*)&in_args[7];
384 out_args[5] = *(uint64_t*)&in_args[5];
385 out_args[4] = in_args[4];
386 out_args[3] = in_args[3];
387 out_args[2] = in_args[2];
388 out_args[1] = in_args[1];
389 out_args[0] = in_args[0];
390}
391
392void
fe8ab488 393munge_wwwwwwl(void *args)
39236c6e
A
394{
395 volatile uint64_t *out_args = (volatile uint64_t*)args;
396 volatile uint32_t *in_args = (volatile uint32_t*)args;
397
398 out_args[6] = *(uint64_t*)&in_args[6];
399 out_args[5] = in_args[5];
400 out_args[4] = in_args[4];
401 out_args[3] = in_args[3];
402 out_args[2] = in_args[2];
403 out_args[1] = in_args[1];
404 out_args[0] = in_args[0];
405}
406
407void
fe8ab488 408munge_wwwwwwlw(void *args)
39236c6e
A
409{
410 volatile uint64_t *out_args = (volatile uint64_t*)args;
411 volatile uint32_t *in_args = (volatile uint32_t*)args;
412
413 out_args[7] = in_args[8];
414 out_args[6] = *(uint64_t*)&in_args[6];
415 out_args[5] = in_args[5];
416 out_args[4] = in_args[4];
417 out_args[3] = in_args[3];
418 out_args[2] = in_args[2];
419 out_args[1] = in_args[1];
420 out_args[0] = in_args[0];
421}
422
423void
fe8ab488 424munge_wwwwwwll(void *args)
39236c6e
A
425{
426 volatile uint64_t *out_args = (volatile uint64_t*)args;
427 volatile uint32_t *in_args = (volatile uint32_t*)args;
428
429 out_args[7] = *(uint64_t*)&in_args[8];
430 out_args[6] = *(uint64_t*)&in_args[6];
431 out_args[5] = in_args[5];
432 out_args[4] = in_args[4];
433 out_args[3] = in_args[3];
434 out_args[2] = in_args[2];
435 out_args[1] = in_args[1];
436 out_args[0] = in_args[0];
437}
438
439void
fe8ab488 440munge_wsw(void *args)
39236c6e
A
441{
442 volatile uint64_t *out_args = (volatile uint64_t*)args;
443 volatile uint32_t *in_args = (volatile uint32_t*)args;
444
445 out_args[2] = in_args[2];
446 out_args[1] = (int64_t)(int)in_args[1]; /* Sign-extend */
447 out_args[0] = in_args[0];
448}
449
450void
fe8ab488 451munge_wws(void *args)
39236c6e
A
452{
453 volatile uint64_t *out_args = (volatile uint64_t*)args;
454 volatile uint32_t *in_args = (volatile uint32_t*)args;
455
456 out_args[2] = (int64_t)(int)in_args[2]; /* Sign-extend */
457 out_args[1] = in_args[1];
458 out_args[0] = in_args[0];
459}
460
461void
fe8ab488 462munge_wwwsw(void *args)
39236c6e
A
463{
464 volatile uint64_t *out_args = (volatile uint64_t*)args;
465 volatile uint32_t *in_args = (volatile uint32_t*)args;
466
467 out_args[4] = in_args[4];
468 out_args[3] = (int64_t)(int)in_args[3]; /* Sign-extend */
469 out_args[2] = in_args[2];
470 out_args[1] = in_args[1];
471 out_args[0] = in_args[0];
472}
473
474void
fe8ab488 475munge_llllll(void *args __unused)
39236c6e
A
476{
477 /* Nothing to do, already all 64-bit */
478}
479
480void
fe8ab488 481munge_ll(void *args __unused)
39236c6e
A
482{
483 /* Nothing to do, already all 64-bit */
484}
485
486void
fe8ab488 487munge_l(void *args __unused)
39236c6e
A
488{
489 /* Nothing to do, already all 64-bit */
490}
491
492void
fe8ab488 493munge_lw(void *args)
39236c6e
A
494{
495 volatile uint64_t *out_args = (volatile uint64_t*)args;
496 volatile uint32_t *in_args = (volatile uint32_t*)args;
497
498 out_args[1] = in_args[2];
499 out_args[0] = *(uint64_t*)&in_args[0];
500}
501
502void
fe8ab488 503munge_lwww(void *args)
39236c6e
A
504{
505 volatile uint64_t *out_args = (volatile uint64_t*)args;
506 volatile uint32_t *in_args = (volatile uint32_t*)args;
507
508 out_args[3] = in_args[4];
509 out_args[2] = in_args[3];
510 out_args[1] = in_args[2];
511 out_args[0] = *(uint64_t*)&in_args[0];
512}
513
514void
fe8ab488 515munge_wwlwww(void *args)
39236c6e
A
516{
517 volatile uint64_t *out_args = (volatile uint64_t*)args;
518 volatile uint32_t *in_args = (volatile uint32_t*)args;
519
520 out_args[5] = in_args[6];
521 out_args[4] = in_args[5];
522 out_args[3] = in_args[4];
523 out_args[2] = *(uint64_t*)&in_args[2];
524 out_args[1] = in_args[1];
525 out_args[0] = in_args[0];
526}
527
528/*
529 * Munge array of 32-bit values into an array of 64-bit values,
530 * without sign extension. Note, src and dest can be the same
531 * (copies from end of array)
532 */
533static inline __attribute__((always_inline)) void
534munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count)
535{
536 int i;
537
538 for (i = count - 1; i >= 0; i--) {
539 dest[i] = src[i];
540 }
541}