]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/ppc/OSByteOrder.h
0d0dad59f59a83a702d149523fde1a9220663eb4
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
36 #ifndef _OS_OSBYTEORDERPPC_H
37 #define _OS_OSBYTEORDERPPC_H
41 #if !defined(OS_INLINE)
42 # define OS_INLINE static inline
45 /* Functions for byte reversed loads. */
50 const volatile void * base
,
55 __asm__
volatile("lhbrx %0, %1, %2"
57 : "b%" (base
), "r" (offset
)
65 const volatile void * base
,
70 __asm__
volatile("lwbrx %0, %1, %2"
72 : "b%" (base
), "r" (offset
)
80 const volatile void * base
,
84 const volatile uint64_t * inp
;
90 inp
= (const volatile uint64_t *)base
;
91 outv
.ul
[0] = OSReadSwapInt32(inp
, offset
+ 4);
92 outv
.ul
[1] = OSReadSwapInt32(inp
, offset
);
96 /* Functions for byte reversed stores. */
101 volatile void * base
,
106 __asm__
volatile("sthbrx %0, %1, %2"
108 : "r" (data
), "b%" (base
), "r" (offset
)
115 volatile void * base
,
120 __asm__
volatile("stwbrx %0, %1, %2"
122 : "r" (data
), "b%" (base
), "r" (offset
)
129 volatile void * base
,
134 volatile uint64_t * outp
;
135 volatile union ullc
{
140 outp
= (volatile uint64_t *)base
;
141 inp
= (volatile union ullc
*)&data
;
142 OSWriteSwapInt32(outp
, offset
, inp
->ul
[1]);
143 OSWriteSwapInt32(outp
, offset
+ 4, inp
->ul
[0]);
146 /* Generic byte swapping functions. */
154 uint16_t temp
= data
;
155 return OSReadSwapInt16(&temp
, 0);
164 uint32_t temp
= data
;
165 return OSReadSwapInt32(&temp
, 0);
174 uint64_t temp
= data
;
175 return OSReadSwapInt64(&temp
, 0);
178 #endif /* ! _OS_OSBYTEORDERPPC_H */