]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/endian.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / ppc / endian.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 *
28 */
29
30#ifndef _MACHINE_ENDIAN_H_
31#define _MACHINE_ENDIAN_H_
32
33/*
34 * Definitions for byte order,
35 * according to byte significance from low address to high.
36 */
37#define LITTLE_ENDIAN 1234 /* least-significant byte first (vax) */
38#define BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
39#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
40
41#if _BIG_ENDIAN /* Predefined by compiler */
42#define BYTE_ORDER BIG_ENDIAN /* byte order we use on ppc */
43#define ENDIAN BIG
44#else
45#error code has not been ported to little endian targets yet
46#endif
47
48/*
49 * Macros for network/external number representation conversion.
50 */
51#if BYTE_ORDER == BIG_ENDIAN && !defined(lint)
52#define ntohl(x) (x)
53#define ntohs(x) (x)
54#define htonl(x) (x)
55#define htons(x) (x)
56
57static __inline__ unsigned int byte_reverse_word(unsigned int word);
58static __inline__ unsigned int byte_reverse_word(unsigned int word) {
59 unsigned int result;
60 __asm__ volatile("lwbrx %0, 0, %1" : "=r" (result) : "r" (&word));
61 return result;
62}
63
64/* The above function is commutative, so we can use it for
65 * translations in both directions (to/from little endianness)
66 * Note that htolx and ltohx are probably identical, they are
67 * included for completeness.
68 */
69#define htoll(x) byte_reverse_word(x)
70#define htols(x) (byte_reverse_word(x) >> 16)
71#define ltohl(x) htoll(x)
72#define ltohs(x) htols(x)
73
74#define htobl(x) (x)
75#define htobs(x) (x)
76#define btohl(x) (x)
77#define btohs(x) (x)
78
79#else
80unsigned short ntohs(), htons();
81unsigned long ntohl(), htonl();
82#endif
83
84/* This defines the order of elements in a bitfield,
85 * it is principally used by the SCSI subsystem in
86 * the definitions of mapped registers
87 */
88#define BYTE_MSF 1
89
90#endif /* _MACHINE_ENDIAN_H_ */