]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/ppc/OSByteOrder.h
e545f5236ac368b778f45f4daa6cc9f8fbb5b2f8
2 * Copyright (c) 2000-2005 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 #ifndef _OS_OSBYTEORDERPPC_H
24 #define _OS_OSBYTEORDERPPC_H
28 #if !defined(OS_INLINE)
29 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
30 # define OS_INLINE static inline
31 # elif defined(__MWERKS__) || defined(__cplusplus)
32 # define OS_INLINE static inline
34 # define OS_INLINE static __inline__
38 /* Functions for byte reversed loads. */
43 const volatile void * base
,
48 volatile uint16_t *addr
= (volatile uint16_t *)((uintptr_t)base
+ byteOffset
);
50 __asm__ ("lhbrx %0, %2, %1"
52 : "r" (base
), "bO" (byteOffset
), "m" (*addr
));
59 const volatile void * base
,
64 volatile uint32_t *addr
= (volatile uint32_t *)((uintptr_t)base
+ byteOffset
);
66 __asm__ ("lwbrx %0, %2, %1"
68 : "r" (base
), "bO" (byteOffset
), "m" (*addr
));
75 const volatile void * base
,
79 volatile uint64_t *addr
= (volatile uint64_t *)((uintptr_t)base
+ byteOffset
);
85 __asm__ ("lwbrx %0, %3, %2\n\t"
87 : "=&r" (u
.u32
[1]), "=r" (u
.u32
[0])
88 : "r" (base
), "bO" (byteOffset
), "b" (byteOffset
+ 4), "m" (*addr
));
92 /* Functions for byte reversed stores. */
102 volatile uint16_t *addr
= (volatile uint16_t *)((uintptr_t)base
+ byteOffset
);
104 __asm__ ("sthbrx %1, %3, %2"
106 : "r" (data
), "r" (base
), "bO" (byteOffset
));
112 volatile void * base
,
113 uintptr_t byteOffset
,
117 volatile uint32_t *addr
= (volatile uint32_t *)((uintptr_t)base
+ byteOffset
);
119 __asm__ ("stwbrx %1, %3, %2"
121 : "r" (data
), "r" (base
), "bO" (byteOffset
));
127 volatile void * base
,
128 uintptr_t byteOffset
,
132 volatile uint64_t *addr
= (volatile uint64_t *)((uintptr_t)base
+ byteOffset
);
133 uint32_t hi
= data
>> 32;
134 uint32_t lo
= data
& 0xffffffff;
136 __asm__ ("stwbrx %1, %4, %3\n\t"
139 : "r" (lo
), "r" (hi
), "r" (base
), "bO" (byteOffset
), "b" (byteOffset
+ 4));
142 /* Generic byte swapping functions. */
150 return OSReadSwapInt16(&data
, 0);
159 return OSReadSwapInt32(&data
, 0);
168 return OSReadSwapInt64(&data
, 0);
171 #endif /* ! _OS_OSBYTEORDERPPC_H */