]> git.saurik.com Git - apple/xnu.git/blob - bsd/ppc/endian.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / bsd / ppc / endian.h
1 /*
2 * Copyright (c) 1995 NeXT Computer, Inc. All rights reserved.
3 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 *
9 * This file contains Original Code and/or Modifications of Original Code
10 * as defined in and that are subject to the Apple Public Source License
11 * Version 2.0 (the 'License'). You may not use this file except in
12 * compliance with the License. Please obtain a copy of the License at
13 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * file.
15 *
16 * The Original Code and all software distributed under the License are
17 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
18 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
19 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
21 * Please see the License for the specific language governing rights and
22 * limitations under the License.
23 *
24 * @APPLE_LICENSE_HEADER_END@
25 */
26 /*
27 * Copyright (c) 1987, 1991, 1993
28 * The Regents of the University of California. All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)endian.h 8.1 (Berkeley) 6/10/93
59 */
60
61 #ifndef _PPC_ENDIAN_H_
62 #define _PPC_ENDIAN_H_
63
64 /*
65 * Define the order of 32-bit words in 64-bit words.
66 */
67 #define _QUAD_HIGHWORD 0
68 #define _QUAD_LOWWORD 1
69
70 #if defined(KERNEL) || !defined(_POSIX_SOURCE)
71 /*
72 * Definitions for byte order, according to byte significance from low
73 * address to high.
74 */
75 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
76 #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net, ppc */
77 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
78
79 #define BYTE_ORDER BIG_ENDIAN
80
81 #include <sys/cdefs.h>
82
83 #ifndef __ASSEMBLER__
84 __BEGIN_DECLS
85 unsigned long htonl __P((unsigned long));
86 unsigned short htons __P((unsigned short));
87 unsigned long ntohl __P((unsigned long));
88 unsigned short ntohs __P((unsigned short));
89 __END_DECLS
90 #endif /* __ASSEMBLER__ */
91
92 /*
93 * Macros for network/external number representation conversion.
94 */
95 #if BYTE_ORDER == BIG_ENDIAN && !defined(lint)
96 #define ntohl(x) (x)
97 #define ntohs(x) (x)
98 #define htonl(x) (x)
99 #define htons(x) (x)
100
101 #define NTOHL(x) (x)
102 #define NTOHS(x) (x)
103 #define HTONL(x) (x)
104 #define HTONS(x) (x)
105
106 #else
107
108 #include <machine/byte_order.h>
109
110 #define ntohl(x) NXSwapBigLongToHost(x)
111 #define ntohs(x) NXSwapBigShortToHost(x)
112 #define htonl(x) NXSwapHostLongToBig(x)
113 #define htons(x) NXSwapHostShortToBig(x)
114
115 #define NTOHL(x) (x) = ntohl((u_long)x)
116 #define NTOHS(x) (x) = ntohs((u_short)x)
117 #define HTONL(x) (x) = htonl((u_long)x)
118 #define HTONS(x) (x) = htons((u_short)x)
119 #endif
120 #endif /* defined(KERNEL) || !defined(_POSIX_SOURCE) */
121 #endif /* !_PPC_ENDIAN_H_ */