]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/machine/OSByteOrder.h
f22f8e9e0a3467258093419fc29c1eaa45a96c07
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
31 #ifndef _OS_OSBYTEORDERMACHINE_H
32 #define _OS_OSBYTEORDERMACHINE_H
36 #if !defined(OS_INLINE)
37 # define OS_INLINE static inline
40 /* Functions for byte reversed loads. */
53 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
54 outv
.uc
[0] = inp
->uc
[1];
55 outv
.uc
[1] = inp
->uc
[0];
70 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
71 outv
.uc
[0] = inp
->uc
[3];
72 outv
.uc
[1] = inp
->uc
[2];
73 outv
.uc
[2] = inp
->uc
[1];
74 outv
.uc
[3] = inp
->uc
[0];
89 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
90 outv
.uc
[0] = inp
->uc
[7];
91 outv
.uc
[1] = inp
->uc
[6];
92 outv
.uc
[2] = inp
->uc
[5];
93 outv
.uc
[3] = inp
->uc
[4];
94 outv
.uc
[4] = inp
->uc
[3];
95 outv
.uc
[5] = inp
->uc
[2];
96 outv
.uc
[6] = inp
->uc
[1];
97 outv
.uc
[7] = inp
->uc
[0];
101 /* Functions for byte reversed stores. */
106 volatile void * base
,
115 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
116 outp
= (union sconv
*)&data
;
117 outp
->uc
[0] = inp
->uc
[1];
118 outp
->uc
[1] = inp
->uc
[0];
124 volatile void * base
,
133 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
134 outp
= (union lconv
*)&data
;
135 outp
->uc
[0] = inp
->uc
[3];
136 outp
->uc
[1] = inp
->uc
[2];
137 outp
->uc
[2] = inp
->uc
[1];
138 outp
->uc
[3] = inp
->uc
[0];
144 volatile void * base
,
153 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
154 outp
= (union llconv
*)&data
;
155 outp
->uc
[0] = inp
->uc
[7];
156 outp
->uc
[1] = inp
->uc
[6];
157 outp
->uc
[2] = inp
->uc
[5];
158 outp
->uc
[3] = inp
->uc
[4];
159 outp
->uc
[4] = inp
->uc
[3];
160 outp
->uc
[5] = inp
->uc
[2];
161 outp
->uc
[6] = inp
->uc
[1];
162 outp
->uc
[7] = inp
->uc
[0];
165 /* Generic byte swapping functions. */
173 uint16_t temp
= data
;
174 return OSReadSwapInt16(&temp
, 0);
183 uint32_t temp
= data
;
184 return OSReadSwapInt32(&temp
, 0);
193 uint64_t temp
= data
;
194 return OSReadSwapInt64(&temp
, 0);
197 #endif /* ! _OS_OSBYTEORDERMACHINE_H */