-# $OpenBSD: Makefile,v 1.191 2014/07/11 21:50:28 tedu Exp $
+# $OpenBSD: Makefile,v 1.192 2014/07/12 16:25:08 guenther Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
.endif
MFILES= frame.h
-LFILES= fcntl.h syslog.h termios.h stdarg.h stdint.h varargs.h
+LFILES= endian.h fcntl.h syslog.h termios.h stdarg.h stdint.h varargs.h
DIRS= arpa protocols rpc rpcsvc
LDIRS= crypto ddb dev isofs miscfs msdosfs net netinet netinet6 \
-/* $OpenBSD: inet.h,v 1.15 2012/12/05 23:19:57 deraadt Exp $ */
+/* $OpenBSD: inet.h,v 1.16 2014/07/12 16:25:08 guenther Exp $ */
/*
* ++Copyright++ 1983, 1993
/* External definitions for functions in inet(3) */
#include <sys/types.h>
-#include <machine/endian.h>
+
+/* <sys/_endian.h> is pulled in by <sys/types.h> */
+#ifndef htons
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
#ifndef _SOCKLEN_T_DEFINED_
#define _SOCKLEN_T_DEFINED_
-/* $OpenBSD: endian.h,v 1.13 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.14 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _LITTLE_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.5 2011/03/12 22:27:48 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#ifdef __GNUC__
#define __swap32md(x) __statement({ \
- u_int32_t __swap32md_x = (x); \
+ __uint32_t __swap32md_x = (x); \
\
__asm ("bswap %0" : "+r" (__swap32md_x)); \
__swap32md_x; \
})
#define __swap64md(x) __statement({ \
- u_int64_t __swap64md_x = (x); \
+ __uint64_t __swap64md_x = (x); \
\
__asm ("bswapq %0" : "+r" (__swap64md_x)); \
__swap64md_x; \
})
#define __swap16md(x) __statement({ \
- u_int16_t __swap16md_x = (x); \
+ __uint16_t __swap16md_x = (x); \
\
__asm ("rorw $8, %w0" : "+r" (__swap16md_x)); \
__swap16md_x; \
})
/* Tell sys/endian.h we have MD variants of the swap macros. */
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.6 2011/11/08 17:06:51 deraadt Exp $ */
+/* $OpenBSD: endian.h,v 1.7 2014/07/12 16:25:08 guenther Exp $ */
#ifndef _ARM_ENDIAN_H_
#define _ARM_ENDIAN_H_
#define _BYTE_ORDER _LITTLE_ENDIAN
#define __STRICT_ALIGNMENT
-#include <sys/endian.h>
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
#endif /* _ARM_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.11 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.12 2014/07/12 16:25:08 guenther Exp $ */
/*
* Copyright (c) 1998-2004 Michael Shalayeff
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* !_MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.3 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.4 2014/07/12 16:25:08 guenther Exp $ */
/*
* Copyright (c) 2005 Michael Shalayeff
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* !_MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.17 2011/03/12 04:03:04 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.18 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#ifdef __GNUC__
#define __swap32md(x) __statement({ \
- u_int32_t __swap32md_x = (x); \
+ __uint32_t __swap32md_x = (x); \
\
__asm ("bswap %0" : "+r" (__swap32md_x)); \
__swap32md_x; \
})
#define __swap64md(x) __statement({ \
- u_int64_t __swap64md_x = (x); \
+ __uint64_t __swap64md_x = (x); \
\
- (u_int64_t)__swap32md(__swap64md_x >> 32) | \
- (u_int64_t)__swap32md(__swap64md_x & 0xffffffff) << 32; \
+ (__uint64_t)__swap32md(__swap64md_x >> 32) | \
+ (__uint64_t)__swap32md(__swap64md_x & 0xffffffff) << 32; \
})
#define __swap16md(x) __statement({ \
- u_int16_t __swap16md_x = (x); \
+ __uint16_t __swap16md_x = (x); \
\
__asm ("rorw $8, %w0" : "+r" (__swap16md_x)); \
__swap16md_x; \
})
/* Tell sys/endian.h we have MD variants of the swap macros. */
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.1 2011/07/04 23:29:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.2 2014/07/12 16:25:08 guenther Exp $ */
/*
* Written by Paul Irofti <pirofti@openbsd.org>. Public Domain.
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
+#define _BYTE_ORDER _LITTLE_ENDIAN
#define __STRICT_ALIGNMENT
-#define _BYTE_ORDER _LITTLE_ENDIAN
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.5 2011/03/23 16:54:35 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#define _M88K_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _M88K_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.8 2014/03/11 19:45:27 guenther Exp $ */
+/* $OpenBSD: endian.h,v 1.9 2014/07/12 16:25:08 guenther Exp $ */
/*
* Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com)
#error "__MIPSEL__ or __MIPSEB__ must be defined to define BYTE_ORDER!!!"
#endif
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MIPS64_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.19 2014/03/25 04:25:06 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.20 2014/07/12 16:25:09 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
__swapm32(a, v);
}
-#define MD_SWAPIO
+#define __HAVE_MD_SWAPIO
#endif /* _KERNEL */
#undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */
#define _BYTE_ORDER _BIG_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _POWERPC_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.4 2011/03/23 16:54:36 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.5 2014/07/12 16:25:09 guenther Exp $ */
/* $NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $ */
/* Written by Manuel Bouyer. Public domain */
rval; \
})
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif /* __GNUC_ */
#else
#define _BYTE_ORDER _BIG_ENDIAN
#endif
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* !_SH_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.13 2011/03/11 15:17:08 pirofti Exp $ */
+/* $OpenBSD: endian.h,v 1.14 2014/07/12 16:25:09 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#define _MACHINE_ENDIAN_H_
#define _BYTE_ORDER _BIG_ENDIAN
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.5 2014/03/25 03:53:35 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.6 2014/07/12 16:25:09 guenther Exp $ */
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
#ifdef _KERNEL
-#define ASI_P_L 0x88
+#define __ASI_P_L 0x88 /* == ASI_PRIMARY_LITTLE */
static inline __uint16_t
__mswap16(volatile __uint16_t *m)
__asm("lduha [%1] %2, %0 ! %3"
: "=r" (v)
- : "r" (m), "n" (ASI_P_L), "m" (*m));
+ : "r" (m), "n" (__ASI_P_L), "m" (*m));
return (v);
}
__asm("lduwa [%1] %2, %0 ! %3"
: "=r" (v)
- : "r" (m), "n" (ASI_P_L), "m" (*m));
+ : "r" (m), "n" (__ASI_P_L), "m" (*m));
return (v);
}
__asm("ldxa [%1] %2, %0 ! %3"
: "=r" (v)
- : "r" (m), "n" (ASI_P_L), "m" (*m));
+ : "r" (m), "n" (__ASI_P_L), "m" (*m));
return (v);
}
{
__asm("stha %1, [%2] %3 ! %0"
: "=m" (*m)
- : "r" (v), "r" (m), "n" (ASI_P_L));
+ : "r" (v), "r" (m), "n" (__ASI_P_L));
}
static inline void
{
__asm("stwa %1, [%2] %3 ! %0"
: "=m" (*m)
- : "r" (v), "r" (m), "n" (ASI_P_L));
+ : "r" (v), "r" (m), "n" (__ASI_P_L));
}
static inline void
{
__asm("stxa %1, [%2] %3 ! %0"
: "=m" (*m)
- : "r" (v), "r" (m), "n" (ASI_P_L));
+ : "r" (v), "r" (m), "n" (__ASI_P_L));
}
-#undef ASI_P_L
+#undef __ASI_P_L
-#define MD_SWAPIO
+#define __HAVE_MD_SWAPIO
#endif /* _KERNEL */
-#include <sys/endian.h>
-
#define __STRICT_ALIGNMENT
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.16 2013/07/05 21:10:50 miod Exp $ */
+/* $OpenBSD: endian.h,v 1.17 2014/07/12 16:25:09 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#define __swap64md __swap64gen
#define __swap32md(x) __statement({ \
- u_int32_t __swap32md_y, __swap32md_x = (x); \
+ __uint32_t __swap32md_y, __swap32md_x = (x); \
\
__asm ("rotl $-8, %1, %0; insv %0, $16, $8, %0; " \
"rotl $8, %1, %%r1; movb %%r1, %0" : \
})
#define __swap16md(x) __statement({ \
- u_int16_t __swap16md_y, __swap16md_x = (x); \
+ __uint16_t __swap16md_y, __swap16md_x = (x); \
\
__asm ("rotl $8, %1, %0; rotl $-8, %1, %%r1; movb %%r1, %0; " \
"movzwl %0, %0" : \
/* Tell sys/endian.h we have MD variants of the swap macros. */
#ifdef notyet
-#define MD_SWAP
+#define __HAVE_MD_SWAP
#endif
#endif /* __GNUC__ */
#define _BYTE_ORDER _LITTLE_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
+#endif
#endif /* _MACHINE_ENDIAN_H_ */
-/* $OpenBSD: in.h,v 1.108 2014/04/25 09:44:38 mpi Exp $ */
+/* $OpenBSD: in.h,v 1.109 2014/07/12 16:25:08 guenther Exp $ */
/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
#ifndef _KERNEL
#include <sys/types.h>
-#include <machine/endian.h>
+
+/* <sys/_endian.h> is pulled in by <sys/types.h> */
+#ifndef htons
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
+
#endif /* _KERNEL */
#ifndef _SA_FAMILY_T_DEFINED_
--- /dev/null
+/* $OpenBSD: _endian.h,v 1.1 2014/07/12 16:25:08 guenther Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Internal endianness macros. This pulls in <machine/endian.h> to
+ * get the correct setting direction for the platform and sets internal
+ * ('__' prefix) macros appropriately.
+ */
+
+#ifndef _SYS__ENDIAN_H_
+#define _SYS__ENDIAN_H_
+
+#include <sys/_types.h>
+
+#define __FROM_SYS__ENDIAN
+#include <machine/endian.h>
+#undef __FROM_SYS__ENDIAN
+
+#define _LITTLE_ENDIAN 1234
+#define _BIG_ENDIAN 4321
+#define _PDP_ENDIAN 3412
+
+#ifdef __GNUC__
+
+#define __swap16gen(x) __statement({ \
+ __uint16_t __swap16gen_x = (x); \
+ \
+ (__uint16_t)((__swap16gen_x & 0xff) << 8 | \
+ (__swap16gen_x & 0xff00) >> 8); \
+})
+
+#define __swap32gen(x) __statement({ \
+ __uint32_t __swap32gen_x = (x); \
+ \
+ (__uint32_t)((__swap32gen_x & 0xff) << 24 | \
+ (__swap32gen_x & 0xff00) << 8 | \
+ (__swap32gen_x & 0xff0000) >> 8 | \
+ (__swap32gen_x & 0xff000000) >> 24); \
+})
+
+#define __swap64gen(x) __statement({ \
+ __uint64_t __swap64gen_x = (x); \
+ \
+ (__uint64_t)((__swap64gen_x & 0xff) << 56 | \
+ (__swap64gen_x & 0xff00ULL) << 40 | \
+ (__swap64gen_x & 0xff0000ULL) << 24 | \
+ (__swap64gen_x & 0xff000000ULL) << 8 | \
+ (__swap64gen_x & 0xff00000000ULL) >> 8 | \
+ (__swap64gen_x & 0xff0000000000ULL) >> 24 | \
+ (__swap64gen_x & 0xff000000000000ULL) >> 40 | \
+ (__swap64gen_x & 0xff00000000000000ULL) >> 56); \
+})
+
+#else /* __GNUC__ */
+
+/* Note that these macros evaluate their arguments several times. */
+#define __swap16gen(x) \
+ (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8)
+
+#define __swap32gen(x) \
+ (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \
+ ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
+ ((__uint32_t)(x) & 0xff000000) >> 24)
+
+#define __swap64gen(x) \
+ (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \
+ ((__uint64_t)(x) & 0xff00ULL) << 40 | \
+ ((__uint64_t)(x) & 0xff0000ULL) << 24 | \
+ ((__uint64_t)(x) & 0xff000000ULL) << 8 | \
+ ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \
+ ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \
+ ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \
+ ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
+
+#endif /* __GNUC__ */
+
+/*
+ * Define __HAVE_MD_SWAP if you provide __swap{16,32}md functions/macros
+ * that are optimized for your architecture, These will be used for
+ * __swap{16,32} unless the argument is a constant and we are using GCC,
+ * where we can take advantage of the CSE phase much better by using the
+ * generic version.
+ */
+#ifdef __HAVE_MD_SWAP
+#if __GNUC__
+
+#define __swap16(x) __statement({ \
+ __uint16_t __swap16_x = (x); \
+ \
+ __builtin_constant_p(x) ? __swap16gen(__swap16_x) : \
+ __swap16md(__swap16_x); \
+})
+
+#define __swap32(x) __statement({ \
+ __uint32_t __swap32_x = (x); \
+ \
+ __builtin_constant_p(x) ? __swap32gen(__swap32_x) : \
+ __swap32md(__swap32_x); \
+})
+
+#define __swap64(x) __statement({ \
+ __uint64_t __swap64_x = (x); \
+ \
+ __builtin_constant_p(x) ? __swap64gen(__swap64_x) : \
+ __swap64md(__swap64_x); \
+})
+
+#else
+
+/* have MD macros, but not gcc */
+#define __swap16 __swap16md
+#define __swap32 __swap32md
+#define __swap64 __swap64md
+
+#endif /* __GNUC__ */
+
+#else /* __HAVE_MD_SWAP */
+#define __swap16 __swap16gen
+#define __swap32 __swap32gen
+#define __swap64 __swap64gen
+#endif /* __HAVE_MD_SWAP */
+
+#define __swap16_multi(v, n) do { \
+ __size_t __swap16_multi_n = (n); \
+ __uint16_t *__swap16_multi_v = (v); \
+ \
+ while (__swap16_multi_n) { \
+ *__swap16_multi_v = swap16(*__swap16_multi_v); \
+ __swap16_multi_v++; \
+ __swap16_multi_n--; \
+ } \
+} while (0)
+
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+
+#define _QUAD_HIGHWORD 1
+#define _QUAD_LOWWORD 0
+
+#define __htobe16 __swap16
+#define __htobe32 __swap32
+#define __htobe64 __swap64
+#define __htole16(x) ((__uint16_t)(x))
+#define __htole32(x) ((__uint32_t)(x))
+#define __htole64(x) ((__uint64_t)(x))
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __bemtoh16(_x) __mswap16(_x)
+#define __bemtoh32(_x) __mswap32(_x)
+#define __bemtoh64(_x) __mswap64(_x)
+
+#define __htobem16(_x, _v) __swapm16((_x), (_v))
+#define __htobem32(_x, _v) __swapm32((_x), (_v))
+#define __htobem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+
+#define _QUAD_HIGHWORD 0
+#define _QUAD_LOWWORD 1
+
+#define __htobe16(x) ((__uint16_t)(x))
+#define __htobe32(x) ((__uint32_t)(x))
+#define __htobe64(x) ((__uint64_t)(x))
+#define __htole16 __swap16
+#define __htole32 __swap32
+#define __htole64 __swap64
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __lemtoh16(_x) __mswap16(_x)
+#define __lemtoh32(_x) __mswap32(_x)
+#define __lemtoh64(_x) __mswap64(_x)
+
+#define __htolem16(_x, _v) __swapm16((_x), (_v))
+#define __htolem32(_x, _v) __swapm32((_x), (_v))
+#define __htolem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _BIG_ENDIAN */
+
+
+#ifdef _KERNEL
+/*
+ * Fill in the __hto[bl]em{16,32,64} and __[bl]emtoh{16,32,64} macros
+ * that haven't been defined yet
+ */
+
+#ifndef __bemtoh16
+#define __bemtoh16(_x) __htobe16(*(__uint16_t *)(_x))
+#define __bemtoh32(_x) __htobe32(*(__uint32_t *)(_x))
+#define __bemtoh64(_x) __htobe64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htobem16
+#define __htobem16(_x, _v) (*(__uint16_t *)(_x) = __htobe16(_v))
+#define __htobem32(_x, _v) (*(__uint32_t *)(_x) = __htobe32(_v))
+#define __htobem64(_x, _v) (*(__uint64_t *)(_x) = __htobe64(_v))
+#endif
+
+#ifndef __lemtoh16
+#define __lemtoh16(_x) __htole16(*(__uint16_t *)(_x))
+#define __lemtoh32(_x) __htole32(*(__uint32_t *)(_x))
+#define __lemtoh64(_x) __htole64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htolem16
+#define __htolem16(_x, _v) (*(__uint16_t *)(_x) = __htole16(_v))
+#define __htolem32(_x, _v) (*(__uint32_t *)(_x) = __htole32(_v))
+#define __htolem64(_x, _v) (*(__uint64_t *)(_x) = __htole64(_v))
+#endif
+#endif /* _KERNEL */
+
+#endif /* _SYS__ENDIAN_H_ */
-/* $OpenBSD: endian.h,v 1.22 2014/07/10 03:16:13 dlg Exp $ */
+/* $OpenBSD: endian.h,v 1.23 2014/07/12 16:25:08 guenther Exp $ */
/*-
* Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
#ifndef _SYS_ENDIAN_H_
#define _SYS_ENDIAN_H_
-#include <sys/cdefs.h>
-#include <sys/_types.h>
+#include <sys/_endian.h>
-#define _LITTLE_ENDIAN 1234
-#define _BIG_ENDIAN 4321
-#define _PDP_ENDIAN 3412
-
-#if __BSD_VISIBLE
+/* Public names */
#define LITTLE_ENDIAN _LITTLE_ENDIAN
#define BIG_ENDIAN _BIG_ENDIAN
#define PDP_ENDIAN _PDP_ENDIAN
#define BYTE_ORDER _BYTE_ORDER
-#endif
-
-#ifdef __GNUC__
-
-#define __swap16gen(x) __statement({ \
- __uint16_t __swap16gen_x = (x); \
- \
- (__uint16_t)((__swap16gen_x & 0xff) << 8 | \
- (__swap16gen_x & 0xff00) >> 8); \
-})
-
-#define __swap32gen(x) __statement({ \
- __uint32_t __swap32gen_x = (x); \
- \
- (__uint32_t)((__swap32gen_x & 0xff) << 24 | \
- (__swap32gen_x & 0xff00) << 8 | \
- (__swap32gen_x & 0xff0000) >> 8 | \
- (__swap32gen_x & 0xff000000) >> 24); \
-})
-
-#define __swap64gen(x) __statement({ \
- __uint64_t __swap64gen_x = (x); \
- \
- (__uint64_t)((__swap64gen_x & 0xff) << 56 | \
- (__swap64gen_x & 0xff00ULL) << 40 | \
- (__swap64gen_x & 0xff0000ULL) << 24 | \
- (__swap64gen_x & 0xff000000ULL) << 8 | \
- (__swap64gen_x & 0xff00000000ULL) >> 8 | \
- (__swap64gen_x & 0xff0000000000ULL) >> 24 | \
- (__swap64gen_x & 0xff000000000000ULL) >> 40 | \
- (__swap64gen_x & 0xff00000000000000ULL) >> 56); \
-})
-#else /* __GNUC__ */
-
-/* Note that these macros evaluate their arguments several times. */
-#define __swap16gen(x) \
- (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8)
-
-#define __swap32gen(x) \
- (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \
- ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
- ((__uint32_t)(x) & 0xff000000) >> 24)
-
-#define __swap64gen(x) \
- (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \
- ((__uint64_t)(x) & 0xff00ULL) << 40 | \
- ((__uint64_t)(x) & 0xff0000ULL) << 24 | \
- ((__uint64_t)(x) & 0xff000000ULL) << 8 | \
- ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \
- ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \
- ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \
- ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
-
-#endif /* __GNUC__ */
/*
- * Define MD_SWAP if you provide swap{16,32}md functions/macros that are
- * optimized for your architecture, These will be used for swap{16,32}
- * unless the argument is a constant and we are using GCC, where we can
- * take advantage of the CSE phase much better by using the generic version.
+ * These are specified to be function-like macros to match the spec
*/
-#ifdef MD_SWAP
-#if __GNUC__
-
-#define __swap16(x) __statement({ \
- __uint16_t __swap16_x = (x); \
- \
- __builtin_constant_p(x) ? __swap16gen(__swap16_x) : \
- __swap16md(__swap16_x); \
-})
-
-#define __swap32(x) __statement({ \
- __uint32_t __swap32_x = (x); \
- \
- __builtin_constant_p(x) ? __swap32gen(__swap32_x) : \
- __swap32md(__swap32_x); \
-})
-
-#define __swap64(x) __statement({ \
- __uint64_t __swap64_x = (x); \
- \
- __builtin_constant_p(x) ? __swap64gen(__swap64_x) : \
- __swap64md(__swap64_x); \
-})
+#define htobe16(x) __htobe16(x)
+#define htobe32(x) __htobe32(x)
+#define htobe64(x) __htobe64(x)
+#define htole16(x) __htole16(x)
+#define htole32(x) __htole32(x)
+#define htole64(x) __htole64(x)
+
+/* POSIX names */
+#define be16toh(x) __htobe16(x)
+#define be32toh(x) __htobe32(x)
+#define be64toh(x) __htobe64(x)
+#define le16toh(x) __htole16(x)
+#define le32toh(x) __htole32(x)
+#define le64toh(x) __htole64(x)
-#endif /* __GNUC__ */
-#else /* MD_SWAP */
-#define __swap16 __swap16gen
-#define __swap32 __swap32gen
-#define __swap64 __swap64gen
-#endif /* MD_SWAP */
+#if __BSD_VISIBLE
+#define swap16(x) __swap16(x)
+#define swap32(x) __swap32(x)
+#define swap64(x) __swap64(x)
-#define __swap16_multi(v, n) do { \
+#define swap16_multi(v, n) do { \
__size_t __swap16_multi_n = (n); \
__uint16_t *__swap16_multi_v = (v); \
\
} \
} while (0)
-#if __BSD_VISIBLE
-#define swap16 __swap16
-#define swap32 __swap32
-#define swap64 __swap64
-#define swap16_multi __swap16_multi
-
-__BEGIN_DECLS
-__uint64_t htobe64(__uint64_t);
-__uint32_t htobe32(__uint32_t);
-__uint16_t htobe16(__uint16_t);
-__uint64_t betoh64(__uint64_t);
-__uint32_t betoh32(__uint32_t);
-__uint16_t betoh16(__uint16_t);
-
-__uint64_t htole64(__uint64_t);
-__uint32_t htole32(__uint32_t);
-__uint16_t htole16(__uint16_t);
-__uint64_t letoh64(__uint64_t);
-__uint32_t letoh32(__uint32_t);
-__uint16_t letoh16(__uint16_t);
-__END_DECLS
-#endif /* __BSD_VISIBLE */
-
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-
-/* Can be overridden by machine/endian.h before inclusion of this file. */
-#ifndef _QUAD_HIGHWORD
-#define _QUAD_HIGHWORD 1
-#endif
-#ifndef _QUAD_LOWWORD
-#define _QUAD_LOWWORD 0
-#endif
-
-#if __BSD_VISIBLE
-#define htobe16 __swap16
-#define htobe32 __swap32
-#define htobe64 __swap64
-#define betoh16 __swap16
-#define betoh32 __swap32
-#define betoh64 __swap64
-
-#define htole16(x) ((__uint16_t)(x))
-#define htole32(x) ((__uint32_t)(x))
-#define htole64(x) ((__uint64_t)(x))
-#define letoh16(x) ((__uint16_t)(x))
-#define letoh32(x) ((__uint32_t)(x))
-#define letoh64(x) ((__uint64_t)(x))
-#endif /* __BSD_VISIBLE */
-
-#define htons(x) __swap16(x)
-#define htonl(x) __swap32(x)
-#define ntohs(x) __swap16(x)
-#define ntohl(x) __swap32(x)
-
-#ifdef _KERNEL
-
-#ifdef MD_SWAPIO
-
-#define bemtoh16(_x) __mswap16(_x)
-#define bemtoh32(_x) __mswap32(_x)
-#define bemtoh64(_x) __mswap64(_x)
-
-#define htobem16(_x, _v) __swapm16((_x), (_v))
-#define htobem32(_x, _v) __swapm32((_x), (_v))
-#define htobem64(_x, _v) __swapm64((_x), (_v))
-
-#else /* MD_SWAPIO */
-
-#define bemtoh16(_x) htobe16(*(__uint16_t *)(_x))
-#define bemtoh32(_x) htobe32(*(__uint32_t *)(_x))
-#define bemtoh64(_x) htobe64(*(__uint64_t *)(_x))
-
-#define htobem16(_x, _v) (*(__uint16_t *)(_x) = htobe16(_v))
-#define htobem32(_x, _v) (*(__uint32_t *)(_x) = htobe32(_v))
-#define htobem64(_x, _v) (*(__uint64_t *)(_x) = htobe64(_v))
-
-#endif /* MD_SWAPIO */
-
-#define lemtoh16(_x) (*(__uint16_t *)(_x))
-#define lemtoh32(_x) (*(__uint32_t *)(_x))
-#define lemtoh64(_x) (*(__uint64_t *)(_x))
-
-#define htolem16(_x, _v) (*(__uint16_t *)(_x) = (__uint16_t)(_v))
-#define htolem32(_x, _v) (*(__uint32_t *)(_x) = (__uint32_t)(_v))
-#define htolem64(_x, _v) (*(__uint64_t *)(_x) = (__uint64_t)(_v))
-
-#endif /* _KERNEL */
-
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
-
-#if _BYTE_ORDER == _BIG_ENDIAN
-
-/* Can be overridden by machine/endian.h before inclusion of this file. */
-#ifndef _QUAD_HIGHWORD
-#define _QUAD_HIGHWORD 0
-#endif
-#ifndef _QUAD_LOWWORD
-#define _QUAD_LOWWORD 1
+/* original BSD names */
+#define betoh16(x) __htobe16(x)
+#define betoh32(x) __htobe32(x)
+#define betoh64(x) __htobe64(x)
+#define letoh16(x) __htole16(x)
+#define letoh32(x) __htole32(x)
+#define letoh64(x) __htole64(x)
+
+#ifndef htons
+/* these were exposed here before */
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
#endif
-#if __BSD_VISIBLE
-#define htole16 __swap16
-#define htole32 __swap32
-#define htole64 __swap64
-#define letoh16 __swap16
-#define letoh32 __swap32
-#define letoh64 __swap64
-
-#define htobe16(x) ((__uint16_t)(x))
-#define htobe32(x) ((__uint32_t)(x))
-#define htobe64(x) ((__uint64_t)(x))
-#define betoh16(x) ((__uint16_t)(x))
-#define betoh32(x) ((__uint32_t)(x))
-#define betoh64(x) ((__uint64_t)(x))
-#endif /* __BSD_VISIBLE */
-
-#define htons(x) ((__uint16_t)(x))
-#define htonl(x) ((__uint32_t)(x))
-#define ntohs(x) ((__uint16_t)(x))
-#define ntohl(x) ((__uint32_t)(x))
-
-#ifdef _KERNEL
-
-#ifdef MD_SWAPIO
-
-#define lemtoh16(_x) __mswap16(_x)
-#define lemtoh32(_x) __mswap32(_x)
-#define lemtoh64(_x) __mswap64(_x)
-
-#define htolem16(_x, _v) __swapm16((_x), (_v))
-#define htolem32(_x, _v) __swapm32((_x), (_v))
-#define htolem64(_x, _v) __swapm64((_x), (_v))
-
-#else /* MD_SWAPIO */
-
-#define lemtoh16(_x) htole16(*(__uint16_t *)(_x))
-#define lemtoh32(_x) htole32(*(__uint32_t *)(_x))
-#define lemtoh64(_x) htole64(*(__uint64_t *)(_x))
-
-#define htolem16(_x, _v) (*(__uint16_t *)(_x) = htole16(_v))
-#define htolem32(_x, _v) (*(__uint32_t *)(_x) = htole32(_v))
-#define htolem64(_x, _v) (*(__uint64_t *)(_x) = htole64(_v))
-
-#endif /* MD_SWAPIO */
-
-#define bemtoh16(_x) (*(__uint16_t *)(_x))
-#define bemtoh32(_x) (*(__uint32_t *)(_x))
-#define bemtoh64(_x) (*(__uint64_t *)(_x))
-
-#define htobem16(_x, _v) (*(__uint16_t *)(_x) = (__uint16_t)(_v))
-#define htobem32(_x, _v) (*(__uint32_t *)(_x) = (__uint32_t)(_v))
-#define htobem64(_x, _v) (*(__uint64_t *)(_x) = (__uint64_t)(_v))
-
-#endif /* _KERNEL */
-
-#endif /* _BYTE_ORDER == _BIG_ENDIAN */
-
-#if __BSD_VISIBLE
+/* ancient stuff */
#define NTOHL(x) (x) = ntohl((u_int32_t)(x))
#define NTOHS(x) (x) = ntohs((u_int16_t)(x))
#define HTONL(x) (x) = htonl((u_int32_t)(x))
#define HTONS(x) (x) = htons((u_int16_t)(x))
-#endif
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+/* to/from memory conversions */
+#define bemtoh16 __bemtoh16
+#define bemtoh32 __bemtoh32
+#define bemtoh64 __bemtoh64
+#define htobem16 __htobem16
+#define htobem32 __htobem32
+#define htobem64 __htobem64
+#define lemtoh16 __lemtoh16
+#define lemtoh32 __lemtoh32
+#define lemtoh64 __lemtoh64
+#define htolem16 __htolem16
+#define htolem32 __htolem32
+#define htolem64 __htolem64
+#endif /* _KERNEL */
#endif /* _SYS_ENDIAN_H_ */
-/* $OpenBSD: types.h,v 1.40 2014/03/11 19:45:28 guenther Exp $ */
+/* $OpenBSD: types.h,v 1.41 2014/07/12 16:25:08 guenther Exp $ */
/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
/*-
#ifndef _SYS_TYPES_H_
#define _SYS_TYPES_H_
-#include <sys/_types.h>
-#include <machine/endian.h>
+#include <sys/cdefs.h>
+#if __BSD_VISIBLE
+#include <sys/endian.h>
+#else
+#include <sys/_endian.h>
+#endif
#if __BSD_VISIBLE
typedef unsigned char u_char;