]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/machine/OSByteOrder.h
ac25ccee88a286075b04851f55aec27fb361497b
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
36 #ifndef _OS_OSBYTEORDERMACHINE_H
37 #define _OS_OSBYTEORDERMACHINE_H
41 #if !defined(OS_INLINE)
42 # define OS_INLINE static inline
45 /* Functions for byte reversed loads. */
58 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
59 outv
.uc
[0] = inp
->uc
[1];
60 outv
.uc
[1] = inp
->uc
[0];
75 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
76 outv
.uc
[0] = inp
->uc
[3];
77 outv
.uc
[1] = inp
->uc
[2];
78 outv
.uc
[2] = inp
->uc
[1];
79 outv
.uc
[3] = inp
->uc
[0];
94 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
95 outv
.uc
[0] = inp
->uc
[7];
96 outv
.uc
[1] = inp
->uc
[6];
97 outv
.uc
[2] = inp
->uc
[5];
98 outv
.uc
[3] = inp
->uc
[4];
99 outv
.uc
[4] = inp
->uc
[3];
100 outv
.uc
[5] = inp
->uc
[2];
101 outv
.uc
[6] = inp
->uc
[1];
102 outv
.uc
[7] = inp
->uc
[0];
106 /* Functions for byte reversed stores. */
111 volatile void * base
,
120 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
121 outp
= (union sconv
*)&data
;
122 outp
->uc
[0] = inp
->uc
[1];
123 outp
->uc
[1] = inp
->uc
[0];
129 volatile void * base
,
138 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
139 outp
= (union lconv
*)&data
;
140 outp
->uc
[0] = inp
->uc
[3];
141 outp
->uc
[1] = inp
->uc
[2];
142 outp
->uc
[2] = inp
->uc
[1];
143 outp
->uc
[3] = inp
->uc
[0];
149 volatile void * base
,
158 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
159 outp
= (union llconv
*)&data
;
160 outp
->uc
[0] = inp
->uc
[7];
161 outp
->uc
[1] = inp
->uc
[6];
162 outp
->uc
[2] = inp
->uc
[5];
163 outp
->uc
[3] = inp
->uc
[4];
164 outp
->uc
[4] = inp
->uc
[3];
165 outp
->uc
[5] = inp
->uc
[2];
166 outp
->uc
[6] = inp
->uc
[1];
167 outp
->uc
[7] = inp
->uc
[0];
170 /* Generic byte swapping functions. */
178 uint16_t temp
= data
;
179 return OSReadSwapInt16(&temp
, 0);
188 uint32_t temp
= data
;
189 return OSReadSwapInt32(&temp
, 0);
198 uint64_t temp
= data
;
199 return OSReadSwapInt64(&temp
, 0);
202 #endif /* ! _OS_OSBYTEORDERMACHINE_H */