]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/machine/OSByteOrder.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
30 #ifndef _OS_OSBYTEORDERMACHINE_H
31 #define _OS_OSBYTEORDERMACHINE_H
33 #include <libkern/OSTypes.h>
35 /* Functions for byte reversed loads. */
48 inp
= (union sconv
*)((UInt8
*)base
+ offset
);
49 outv
.uc
[0] = inp
->uc
[1];
50 outv
.uc
[1] = inp
->uc
[0];
65 inp
= (union lconv
*)((UInt8
*)base
+ offset
);
66 outv
.uc
[0] = inp
->uc
[3];
67 outv
.uc
[1] = inp
->uc
[2];
68 outv
.uc
[2] = inp
->uc
[1];
69 outv
.uc
[3] = inp
->uc
[0];
84 inp
= (union llconv
*)((UInt8
*)base
+ offset
);
85 outv
.uc
[0] = inp
->uc
[7];
86 outv
.uc
[1] = inp
->uc
[6];
87 outv
.uc
[2] = inp
->uc
[5];
88 outv
.uc
[3] = inp
->uc
[4];
89 outv
.uc
[4] = inp
->uc
[3];
90 outv
.uc
[5] = inp
->uc
[2];
91 outv
.uc
[6] = inp
->uc
[1];
92 outv
.uc
[7] = inp
->uc
[0];
103 return (UInt
)OSReadSwapInt32(base
, offset
);
106 /* Functions for byte reversed stores. */
111 volatile void * base
,
120 inp
= (union sconv
*)((UInt8
*)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
*)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
*)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];
173 volatile void * base
,
178 OSWriteSwapInt32(base
, offset
, (UInt32
)data
);
181 /* Generic byte swapping functions. */
190 return OSReadSwapInt16(&temp
, 0);
200 return OSReadSwapInt32(&temp
, 0);
210 return OSReadSwapInt64(&temp
, 0);
220 return OSReadSwapInt(&temp
, 0);
223 #endif /* ! _OS_OSBYTEORDERMACHINE_H */