]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/machine/OSByteOrder.h
05d5b6f89808ac712a05aba997f758e40eb22a8d
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
38 #ifndef _OS_OSBYTEORDERMACHINE_H
39 #define _OS_OSBYTEORDERMACHINE_H
43 #if !defined(OS_INLINE)
44 # define OS_INLINE static inline
47 /* Functions for byte reversed loads. */
60 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
61 outv
.uc
[0] = inp
->uc
[1];
62 outv
.uc
[1] = inp
->uc
[0];
77 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
78 outv
.uc
[0] = inp
->uc
[3];
79 outv
.uc
[1] = inp
->uc
[2];
80 outv
.uc
[2] = inp
->uc
[1];
81 outv
.uc
[3] = inp
->uc
[0];
96 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
97 outv
.uc
[0] = inp
->uc
[7];
98 outv
.uc
[1] = inp
->uc
[6];
99 outv
.uc
[2] = inp
->uc
[5];
100 outv
.uc
[3] = inp
->uc
[4];
101 outv
.uc
[4] = inp
->uc
[3];
102 outv
.uc
[5] = inp
->uc
[2];
103 outv
.uc
[6] = inp
->uc
[1];
104 outv
.uc
[7] = inp
->uc
[0];
108 /* Functions for byte reversed stores. */
113 volatile void * base
,
122 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
123 outp
= (union sconv
*)&data
;
124 outp
->uc
[0] = inp
->uc
[1];
125 outp
->uc
[1] = inp
->uc
[0];
131 volatile void * base
,
140 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
141 outp
= (union lconv
*)&data
;
142 outp
->uc
[0] = inp
->uc
[3];
143 outp
->uc
[1] = inp
->uc
[2];
144 outp
->uc
[2] = inp
->uc
[1];
145 outp
->uc
[3] = inp
->uc
[0];
151 volatile void * base
,
160 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
161 outp
= (union llconv
*)&data
;
162 outp
->uc
[0] = inp
->uc
[7];
163 outp
->uc
[1] = inp
->uc
[6];
164 outp
->uc
[2] = inp
->uc
[5];
165 outp
->uc
[3] = inp
->uc
[4];
166 outp
->uc
[4] = inp
->uc
[3];
167 outp
->uc
[5] = inp
->uc
[2];
168 outp
->uc
[6] = inp
->uc
[1];
169 outp
->uc
[7] = inp
->uc
[0];
172 /* Generic byte swapping functions. */
180 uint16_t temp
= data
;
181 return OSReadSwapInt16(&temp
, 0);
190 uint32_t temp
= data
;
191 return OSReadSwapInt32(&temp
, 0);
200 uint64_t temp
= data
;
201 return OSReadSwapInt64(&temp
, 0);
204 #endif /* ! _OS_OSBYTEORDERMACHINE_H */