X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..4ba76501152d51ccb5647018f3192c6096367d48:/bsd/dev/munge.c diff --git a/bsd/dev/munge.c b/bsd/dev/munge.c index 168fad929..7d2433cd1 100644 --- a/bsd/dev/munge.c +++ b/bsd/dev/munge.c @@ -2,7 +2,7 @@ * Coyright (c) 2005-2006 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ - * + * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in @@ -11,10 +11,10 @@ * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. - * + * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. - * + * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -22,7 +22,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ @@ -31,295 +31,321 @@ #include #include -static inline __attribute__((always_inline)) void -munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count); - /* * Refer to comments in bsd/sys/munge.h */ -void -munge_w(const void *arg0 __unused, void *args) + +static inline __attribute__((always_inline)) void +munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count); + +void +munge_w(void *args) { munge_32_to_64_unsigned(args, args, 1); } -void -munge_ww(const void *arg0 __unused, void *args) +void +munge_ww(void *args) { munge_32_to_64_unsigned(args, args, 2); } -void -munge_www(const void *arg0 __unused, void *args) +void +munge_www(void *args) { munge_32_to_64_unsigned(args, args, 3); } -void -munge_wwww(const void *arg0 __unused, void *args) +void +munge_wwww(void *args) { munge_32_to_64_unsigned(args, args, 4); } -void -munge_wwwww(const void *arg0 __unused, void *args) +void +munge_wwwww(void *args) { munge_32_to_64_unsigned(args, args, 5); } -void -munge_wwwwww(const void *arg0 __unused, void *args) +void +munge_wwwwww(void *args) { munge_32_to_64_unsigned(args, args, 6); } -void -munge_wwwwwww(const void *arg0 __unused, void *args) +void +munge_wwwwwww(void *args) { munge_32_to_64_unsigned(args, args, 7); } -void -munge_wwwwwwww(const void *arg0 __unused, void *args) +void +munge_wwwwwwww(void *args) { munge_32_to_64_unsigned(args, args, 8); } -void -munge_wl(const void *arg0 __unused, void *args) +void +munge_wl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwl(const void *arg0 __unused, void *args) +void +munge_wwl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[2] = *(uint64_t*)&in_args[2]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwlw(const void *arg0 __unused, void *args) +void +munge_wwlw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[3] = in_args[4]; - out_args[2] = *(uint64_t*)&in_args[2]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwlll(const void *arg0 __unused, void *args) +void +munge_wwlll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[4] = *(uint64_t*)&in_args[6]; - out_args[3] = *(uint64_t*)&in_args[4]; - out_args[2] = *(uint64_t*)&in_args[2]; + out_args[4] = *(volatile uint64_t*)&in_args[6]; + out_args[3] = *(volatile uint64_t*)&in_args[4]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } void -munge_wwllww(const void *arg0 __unused, void *args) +munge_wwllww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[5] = in_args[7]; out_args[4] = in_args[6]; - out_args[3] = *(uint64_t*)&in_args[4]; - out_args[2] = *(uint64_t*)&in_args[2]; + out_args[3] = *(volatile uint64_t*)&in_args[4]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } void -munge_wlw(const void *arg0 __unused, void *args) +munge_wlw(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[2] = in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; + out_args[0] = in_args[0]; +} + +void +munge_wlww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; + out_args[3] = in_args[4]; out_args[2] = in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } void -munge_wlwwwll(const void *arg0 __unused, void *args) +munge_wlwwwll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[6] = *(uint64_t*)&in_args[8]; - out_args[5] = *(uint64_t*)&in_args[6]; + out_args[6] = *(volatile uint64_t*)&in_args[8]; + out_args[5] = *(volatile uint64_t*)&in_args[6]; out_args[4] = in_args[5]; out_args[3] = in_args[4]; out_args[2] = in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } void -munge_wlwwwllw(const void *arg0 __unused, void *args) +munge_wlwwwllw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[7] = in_args[10]; - munge_wlwwwll(args, args); + munge_wlwwwll(args); } -void -munge_wlwwlwlw(const void *arg0 __unused, void *args) +void +munge_wlwwlwlw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[7] = in_args[10]; - out_args[6] = *(uint64_t*)&in_args[8]; + out_args[6] = *(volatile uint64_t*)&in_args[8]; out_args[5] = in_args[7]; - out_args[4] = *(uint64_t*)&in_args[5]; + out_args[4] = *(volatile uint64_t*)&in_args[5]; out_args[3] = in_args[4]; out_args[2] = in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } -void -munge_wll(const void *arg0 __unused, void *args) +void +munge_wll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[2] = *(uint64_t*)&in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[2] = *(volatile uint64_t*)&in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } -void -munge_wlll(const void *arg0 __unused, void *args) +void +munge_wlll(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[3] = *(volatile uint64_t*)&in_args[5]; + out_args[2] = *(volatile uint64_t*)&in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; + out_args[0] = in_args[0]; +} + +void +munge_wllll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[3] = *(uint64_t*)&in_args[5]; - out_args[2] = *(uint64_t*)&in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[4] = *(volatile uint64_t*)&in_args[7]; + out_args[3] = *(volatile uint64_t*)&in_args[5]; + out_args[2] = *(volatile uint64_t*)&in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } void -munge_wllww(const void *arg0 __unused, void *args) +munge_wllww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[4] = in_args[6]; out_args[3] = in_args[5]; - out_args[2] = *(uint64_t*)&in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[2] = *(volatile uint64_t*)&in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } -void -munge_wllwwll(const void *arg0 __unused, void *args) +void +munge_wllwwll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[6] = *(uint64_t*)&in_args[9]; - out_args[5] = *(uint64_t*)&in_args[7]; + out_args[6] = *(volatile uint64_t*)&in_args[9]; + out_args[5] = *(volatile uint64_t*)&in_args[7]; out_args[4] = in_args[6]; out_args[3] = in_args[5]; - out_args[2] = *(uint64_t*)&in_args[3]; - out_args[1] = *(uint64_t*)&in_args[1]; + out_args[2] = *(volatile uint64_t*)&in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwwlw(const void *arg0 __unused, void *args) +void +munge_wwwlw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[4] = in_args[5]; - out_args[3] = *(uint64_t*)&in_args[3]; + out_args[3] = *(volatile uint64_t*)&in_args[3]; out_args[2] = in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwwlww(const void *arg0 __unused, void *args) +void +munge_wwwlww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[5] = in_args[6]; out_args[4] = in_args[5]; - out_args[3] = *(uint64_t*)&in_args[3]; + out_args[3] = *(volatile uint64_t*)&in_args[3]; out_args[2] = in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } - -void -munge_wwwl(const void *arg0 __unused, void *args) + +void +munge_wwwl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[3] = *(uint64_t*)&in_args[3]; + out_args[3] = *(volatile uint64_t*)&in_args[3]; out_args[2] = in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwwwlw(const void *arg0 __unused, void *args) +void +munge_wwwwlw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[5] = in_args[6]; - out_args[4] = *(uint64_t*)&in_args[4]; + out_args[4] = *(volatile uint64_t*)&in_args[4]; out_args[3] = in_args[3]; out_args[2] = in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwwwl(const void *arg0 __unused, void *args) +void +munge_wwwwl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[4] = *(uint64_t*)&in_args[4]; + out_args[4] = *(volatile uint64_t*)&in_args[4]; out_args[3] = in_args[3]; out_args[2] = in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } -void -munge_wwwwwl(const void *arg0 __unused, void *args) +void +munge_wwwwwl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[5] = *(uint64_t*)&in_args[5]; + out_args[5] = *(volatile uint64_t*)&in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; out_args[2] = in_args[2]; @@ -327,15 +353,15 @@ munge_wwwwwl(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wwwwwlww(const void *arg0 __unused, void *args) +void +munge_wwwwwlww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[7] = in_args[8]; out_args[6] = in_args[7]; - out_args[5] = *(uint64_t*)&in_args[5]; + out_args[5] = *(volatile uint64_t*)&in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; out_args[2] = in_args[2]; @@ -343,15 +369,15 @@ munge_wwwwwlww(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wwwwwllw(const void *arg0 __unused, void *args) +void +munge_wwwwwllw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[7] = in_args[9]; - out_args[6] = *(uint64_t*)&in_args[7]; - out_args[5] = *(uint64_t*)&in_args[5]; + out_args[6] = *(volatile uint64_t*)&in_args[7]; + out_args[5] = *(volatile uint64_t*)&in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; out_args[2] = in_args[2]; @@ -359,15 +385,15 @@ munge_wwwwwllw(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wwwwwlll(const void *arg0 __unused, void *args) +void +munge_wwwwwlll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[7] = *(uint64_t*)&in_args[9]; - out_args[6] = *(uint64_t*)&in_args[7]; - out_args[5] = *(uint64_t*)&in_args[5]; + out_args[7] = *(volatile uint64_t*)&in_args[9]; + out_args[6] = *(volatile uint64_t*)&in_args[7]; + out_args[5] = *(volatile uint64_t*)&in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; out_args[2] = in_args[2]; @@ -375,13 +401,13 @@ munge_wwwwwlll(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wwwwwwl(const void *arg0 __unused, void *args) +void +munge_wwwwwwl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[6] = *(uint64_t*)&in_args[6]; + out_args[6] = *(volatile uint64_t*)&in_args[6]; out_args[5] = in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; @@ -389,15 +415,15 @@ munge_wwwwwwl(const void *arg0 __unused, void *args) out_args[1] = in_args[1]; out_args[0] = in_args[0]; } - -void -munge_wwwwwwlw(const void *arg0 __unused, void *args) + +void +munge_wwwwwwlw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; out_args[7] = in_args[8]; - out_args[6] = *(uint64_t*)&in_args[6]; + out_args[6] = *(volatile uint64_t*)&in_args[6]; out_args[5] = in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; @@ -405,15 +431,15 @@ munge_wwwwwwlw(const void *arg0 __unused, void *args) out_args[1] = in_args[1]; out_args[0] = in_args[0]; } - -void -munge_wwwwwwll(const void *arg0 __unused, void *args) + +void +munge_wwwwwwll(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[7] = *(uint64_t*)&in_args[8]; - out_args[6] = *(uint64_t*)&in_args[6]; + out_args[7] = *(volatile uint64_t*)&in_args[8]; + out_args[6] = *(volatile uint64_t*)&in_args[6]; out_args[5] = in_args[5]; out_args[4] = in_args[4]; out_args[3] = in_args[3]; @@ -422,8 +448,8 @@ munge_wwwwwwll(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wsw(const void *arg0 __unused, void *args) +void +munge_wsw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; @@ -433,8 +459,8 @@ munge_wsw(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wws(const void *arg0 __unused, void *args) +void +munge_wws(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; @@ -444,8 +470,21 @@ munge_wws(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_wwwsw(const void *arg0 __unused, void *args) +void +munge_wwws(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[3] = (int64_t)(int)in_args[3]; /* Sign-extend */ + out_args[2] = in_args[2]; + out_args[1] = in_args[1]; + out_args[0] = in_args[0]; +} + + +void +munge_wwwsw(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; @@ -457,72 +496,129 @@ munge_wwwsw(const void *arg0 __unused, void *args) out_args[0] = in_args[0]; } -void -munge_llllll(const void *arg0 __unused, void *args __unused) +void +munge_llllll(void *args __unused) { /* Nothing to do, already all 64-bit */ } -void -munge_ll(const void *arg0 __unused, void *args __unused) +void +munge_ll(void *args __unused) { /* Nothing to do, already all 64-bit */ } -void -munge_l(const void *arg0 __unused, void *args __unused) +void +munge_l(void *args __unused) { /* Nothing to do, already all 64-bit */ } -void -munge_lw(const void *arg0 __unused, void *args) +void +munge_lw(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[1] = in_args[2]; + out_args[0] = *(volatile uint64_t*)&in_args[0]; +} + +void +munge_lwww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; + out_args[3] = in_args[4]; + out_args[2] = in_args[3]; out_args[1] = in_args[2]; - out_args[0] = *(uint64_t*)&in_args[0]; + out_args[0] = *(volatile uint64_t*)&in_args[0]; } -void -munge_lwww(const void *arg0 __unused, void *args) +void +munge_lwwwwwww(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - out_args[3] = in_args[4]; + out_args[7] = in_args[8]; + out_args[6] = in_args[7]; + out_args[5] = in_args[6]; + out_args[4] = in_args[5]; + out_args[3] = in_args[4]; out_args[2] = in_args[3]; out_args[1] = in_args[2]; - out_args[0] = *(uint64_t*)&in_args[0]; + out_args[0] = *(volatile uint64_t*)&in_args[0]; +} + +void +munge_wwlww(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[4] = in_args[5]; + out_args[3] = in_args[4]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; + out_args[1] = in_args[1]; + out_args[0] = in_args[0]; +} + +void +munge_wwlwww(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[5] = in_args[6]; + out_args[4] = in_args[5]; + out_args[3] = in_args[4]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; + out_args[1] = in_args[1]; + out_args[0] = in_args[0]; +} + +void +munge_wlwwwl(void *args) +{ + volatile uint64_t *out_args = (volatile uint64_t*)args; + volatile uint32_t *in_args = (volatile uint32_t*)args; + + out_args[5] = *(volatile uint64_t*)&in_args[6]; + out_args[4] = in_args[5]; + out_args[3] = in_args[4]; + out_args[2] = in_args[3]; + out_args[1] = *(volatile uint64_t*)&in_args[1]; + out_args[0] = in_args[0]; } void -munge_wwlwww(const void *arg0 __unused, void *args) +munge_wwlwwwl(void *args) { volatile uint64_t *out_args = (volatile uint64_t*)args; volatile uint32_t *in_args = (volatile uint32_t*)args; - + + out_args[6] = *(volatile uint64_t*)&in_args[7]; out_args[5] = in_args[6]; out_args[4] = in_args[5]; out_args[3] = in_args[4]; - out_args[2] = *(uint64_t*)&in_args[2]; + out_args[2] = *(volatile uint64_t*)&in_args[2]; out_args[1] = in_args[1]; out_args[0] = in_args[0]; } /* * Munge array of 32-bit values into an array of 64-bit values, - * without sign extension. Note, src and dest can be the same + * without sign extension. Note, src and dest can be the same * (copies from end of array) */ -static inline __attribute__((always_inline)) void +static inline __attribute__((always_inline)) void munge_32_to_64_unsigned(volatile uint64_t *dest, volatile uint32_t *src, int count) { int i; for (i = count - 1; i >= 0; i--) { dest[i] = src[i]; - } + } } -