]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/machine/OSByteOrder.h
2 * Copyright (c) 2000-2003 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
35 #if !defined(OS_INLINE)
36 # define OS_INLINE static inline
39 /* Functions for byte reversed loads. */
52 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
53 outv
.uc
[0] = inp
->uc
[1];
54 outv
.uc
[1] = inp
->uc
[0];
69 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
70 outv
.uc
[0] = inp
->uc
[3];
71 outv
.uc
[1] = inp
->uc
[2];
72 outv
.uc
[2] = inp
->uc
[1];
73 outv
.uc
[3] = inp
->uc
[0];
88 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
89 outv
.uc
[0] = inp
->uc
[7];
90 outv
.uc
[1] = inp
->uc
[6];
91 outv
.uc
[2] = inp
->uc
[5];
92 outv
.uc
[3] = inp
->uc
[4];
93 outv
.uc
[4] = inp
->uc
[3];
94 outv
.uc
[5] = inp
->uc
[2];
95 outv
.uc
[6] = inp
->uc
[1];
96 outv
.uc
[7] = inp
->uc
[0];
100 /* Functions for byte reversed stores. */
105 volatile void * base
,
114 inp
= (union sconv
*)((uint8_t *)base
+ offset
);
115 outp
= (union sconv
*)&data
;
116 outp
->uc
[0] = inp
->uc
[1];
117 outp
->uc
[1] = inp
->uc
[0];
123 volatile void * base
,
132 inp
= (union lconv
*)((uint8_t *)base
+ offset
);
133 outp
= (union lconv
*)&data
;
134 outp
->uc
[0] = inp
->uc
[3];
135 outp
->uc
[1] = inp
->uc
[2];
136 outp
->uc
[2] = inp
->uc
[1];
137 outp
->uc
[3] = inp
->uc
[0];
143 volatile void * base
,
152 inp
= (union llconv
*)((uint8_t *)base
+ offset
);
153 outp
= (union llconv
*)&data
;
154 outp
->uc
[0] = inp
->uc
[7];
155 outp
->uc
[1] = inp
->uc
[6];
156 outp
->uc
[2] = inp
->uc
[5];
157 outp
->uc
[3] = inp
->uc
[4];
158 outp
->uc
[4] = inp
->uc
[3];
159 outp
->uc
[5] = inp
->uc
[2];
160 outp
->uc
[6] = inp
->uc
[1];
161 outp
->uc
[7] = inp
->uc
[0];
164 /* Generic byte swapping functions. */
172 uint16_t temp
= data
;
173 return OSReadSwapInt16(&temp
, 0);
182 uint32_t temp
= data
;
183 return OSReadSwapInt32(&temp
, 0);
192 uint64_t temp
= data
;
193 return OSReadSwapInt64(&temp
, 0);
196 #endif /* ! _OS_OSBYTEORDERMACHINE_H */