xref: /freebsd/sys/powerpc/include/endian.h (revision 03516cfeb01dd63a72e120acc0ad027bd5bde63a)
1fa561e1eSDavid E. O'Brien /*
2fa561e1eSDavid E. O'Brien  * Copyright (c) 1987, 1991, 1993
3fa561e1eSDavid E. O'Brien  *	The Regents of the University of California.  All rights reserved.
4fa561e1eSDavid E. O'Brien  *
5fa561e1eSDavid E. O'Brien  * Redistribution and use in source and binary forms, with or without
6fa561e1eSDavid E. O'Brien  * modification, are permitted provided that the following conditions
7fa561e1eSDavid E. O'Brien  * are met:
8fa561e1eSDavid E. O'Brien  * 1. Redistributions of source code must retain the above copyright
9fa561e1eSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer.
10fa561e1eSDavid E. O'Brien  * 2. Redistributions in binary form must reproduce the above copyright
11fa561e1eSDavid E. O'Brien  *    notice, this list of conditions and the following disclaimer in the
12fa561e1eSDavid E. O'Brien  *    documentation and/or other materials provided with the distribution.
13fa561e1eSDavid E. O'Brien  * 3. All advertising materials mentioning features or use of this software
14fa561e1eSDavid E. O'Brien  *    must display the following acknowledgement:
15fa561e1eSDavid E. O'Brien  *	This product includes software developed by the University of
16fa561e1eSDavid E. O'Brien  *	California, Berkeley and its contributors.
17fa561e1eSDavid E. O'Brien  * 4. Neither the name of the University nor the names of its contributors
18fa561e1eSDavid E. O'Brien  *    may be used to endorse or promote products derived from this software
19fa561e1eSDavid E. O'Brien  *    without specific prior written permission.
20fa561e1eSDavid E. O'Brien  *
21fa561e1eSDavid E. O'Brien  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22fa561e1eSDavid E. O'Brien  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23fa561e1eSDavid E. O'Brien  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24fa561e1eSDavid E. O'Brien  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25fa561e1eSDavid E. O'Brien  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26fa561e1eSDavid E. O'Brien  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27fa561e1eSDavid E. O'Brien  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28fa561e1eSDavid E. O'Brien  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29fa561e1eSDavid E. O'Brien  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30fa561e1eSDavid E. O'Brien  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31fa561e1eSDavid E. O'Brien  * SUCH DAMAGE.
32fa561e1eSDavid E. O'Brien  *
33fa561e1eSDavid E. O'Brien  *	@(#)endian.h	8.1 (Berkeley) 6/10/93
34fa561e1eSDavid E. O'Brien  *	$NetBSD: endian.h,v 1.7 1999/08/21 05:53:51 simonb Exp $
35fa561e1eSDavid E. O'Brien  * $FreeBSD$
36fa561e1eSDavid E. O'Brien  */
37fa561e1eSDavid E. O'Brien 
38fa561e1eSDavid E. O'Brien #ifndef _ENDIAN_H_
39fa561e1eSDavid E. O'Brien #define	_ENDIAN_H_
40fa561e1eSDavid E. O'Brien 
41fa561e1eSDavid E. O'Brien /*
42fa561e1eSDavid E. O'Brien  * Define the order of 32-bit words in 64-bit words.
43fa561e1eSDavid E. O'Brien  */
44fa561e1eSDavid E. O'Brien #define	_QUAD_HIGHWORD 0
45fa561e1eSDavid E. O'Brien #define	_QUAD_LOWWORD 1
46fa561e1eSDavid E. O'Brien 
47fa561e1eSDavid E. O'Brien #ifndef _POSIX_SOURCE
48fa561e1eSDavid E. O'Brien /*
49fa561e1eSDavid E. O'Brien  * Definitions for byte order, according to byte significance from low
50fa561e1eSDavid E. O'Brien  * address to high.
51fa561e1eSDavid E. O'Brien  */
52fa561e1eSDavid E. O'Brien #define	LITTLE_ENDIAN	1234	/* LSB first: i386, vax */
53fa561e1eSDavid E. O'Brien #define	BIG_ENDIAN	4321	/* MSB first: 68000, ibm, net */
54fa561e1eSDavid E. O'Brien #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long */
55fa561e1eSDavid E. O'Brien 
56fa561e1eSDavid E. O'Brien #define	BYTE_ORDER	BIG_ENDIAN
57fa561e1eSDavid E. O'Brien 
5803516cfeSMike Barcroft #ifndef _KERNEL
59fa561e1eSDavid E. O'Brien #include <sys/cdefs.h>
6003516cfeSMike Barcroft #endif
6103516cfeSMike Barcroft #include <machine/ansi.h>
62fa561e1eSDavid E. O'Brien 
63fa561e1eSDavid E. O'Brien __BEGIN_DECLS
6403516cfeSMike Barcroft __uint32_t	htonl __P((__uint32_t));
6503516cfeSMike Barcroft __uint16_t	htons __P((__uint16_t));
6603516cfeSMike Barcroft __uint32_t	ntohl __P((__uint32_t));
6703516cfeSMike Barcroft __uint16_t	ntohs __P((__uint16_t));
6803516cfeSMike Barcroft __uint16_t	bswap16 __P((__uint16_t));
6903516cfeSMike Barcroft __uint32_t	bswap32 __P((__uint32_t));
7003516cfeSMike Barcroft __uint64_t	bswap64 __P((__uint64_t));
71fa561e1eSDavid E. O'Brien __END_DECLS
72fa561e1eSDavid E. O'Brien 
73fa561e1eSDavid E. O'Brien /*
74fa561e1eSDavid E. O'Brien  * Macros for network/external number representation conversion.
75fa561e1eSDavid E. O'Brien  */
76fa561e1eSDavid E. O'Brien #if BYTE_ORDER == BIG_ENDIAN && !defined(lint)
77fa561e1eSDavid E. O'Brien #define	ntohl(x)	(x)
78fa561e1eSDavid E. O'Brien #define	ntohs(x)	(x)
79fa561e1eSDavid E. O'Brien #define	htonl(x)	(x)
80fa561e1eSDavid E. O'Brien #define	htons(x)	(x)
81fa561e1eSDavid E. O'Brien 
82fa561e1eSDavid E. O'Brien #define	NTOHL(x)	(x)
83fa561e1eSDavid E. O'Brien #define	NTOHS(x)	(x)
84fa561e1eSDavid E. O'Brien #define	HTONL(x)	(x)
85fa561e1eSDavid E. O'Brien #define	HTONS(x)	(x)
86fa561e1eSDavid E. O'Brien 
87fa561e1eSDavid E. O'Brien #else
88fa561e1eSDavid E. O'Brien 
8903516cfeSMike Barcroft #define	NTOHL(x)	(x) = ntohl((__uint32_t)(x))
9003516cfeSMike Barcroft #define	NTOHS(x)	(x) = ntohs((__uint16_t)(x))
9103516cfeSMike Barcroft #define	HTONL(x)	(x) = htonl((__uint32_t)(x))
9203516cfeSMike Barcroft #define	HTONS(x)	(x) = htons((__uint16_t)(x))
93fa561e1eSDavid E. O'Brien #endif
94fa561e1eSDavid E. O'Brien 
95fa561e1eSDavid E. O'Brien #endif /* !_POSIX_SOURCE */
96fa561e1eSDavid E. O'Brien #endif /* !_ENDIAN_H_ */
97