diff options
-rw-r--r-- | include/arpa/inet.h | 26 | ||||
-rw-r--r-- | lib/libstand/stand.h | 16 | ||||
-rw-r--r-- | sys/alpha/include/endian.h | 22 | ||||
-rw-r--r-- | sys/i386/include/endian.h | 62 | ||||
-rw-r--r-- | sys/ia64/include/endian.h | 17 | ||||
-rw-r--r-- | sys/netinet/in.h | 17 | ||||
-rw-r--r-- | sys/powerpc/include/endian.h | 36 | ||||
-rw-r--r-- | sys/sparc64/include/endian.h | 36 | ||||
-rw-r--r-- | sys/sys/param.h | 57 |
9 files changed, 189 insertions, 100 deletions
diff --git a/include/arpa/inet.h b/include/arpa/inet.h index 3ac128d..9c9554e 100644 --- a/include/arpa/inet.h +++ b/include/arpa/inet.h @@ -115,23 +115,19 @@ struct in_addr { #define inet_nsap_ntoa __inet_nsap_ntoa #endif /* !_POSIX_SOURCE */ -#ifndef _BYTEORDER_FUNC_DEFINED -#define _BYTEORDER_FUNC_DEFINED -#define htonl(x) __htonl(x) -#define htons(x) __htons(x) -#define ntohl(x) __ntohl(x) -#define ntohs(x) __ntohs(x) +__BEGIN_DECLS +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +__uint32_t htonl __P((__uint32_t)); +__uint16_t htons __P((__uint16_t)); +__uint32_t ntohl __P((__uint32_t)); +__uint16_t ntohs __P((__uint16_t)); #endif -__BEGIN_DECLS -__uint32_t htonl(__uint32_t); -__uint16_t htons(__uint16_t); in_addr_t inet_addr __P((const char *)); char *inet_ntoa __P((struct in_addr)); const char *inet_ntop __P((int, const void *, char *, socklen_t)); int inet_pton __P((int, const char *, void *)); -__uint32_t ntohl(__uint32_t); -__uint16_t ntohs(__uint16_t); /* Nonstandard functions. */ #ifndef _POSIX_SOURCE @@ -150,4 +146,12 @@ char *inet_nsap_ntoa __P((int, const unsigned char *, char *)); #endif /* !_POSIX_SOURCE */ __END_DECLS +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif + #endif /* !_ARPA_INET_H_ */ diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h index e3570f9..fcbb2e8 100644 --- a/lib/libstand/stand.h +++ b/lib/libstand/stand.h @@ -374,15 +374,21 @@ extern struct devsw *devsw[]; /* * Expose byteorder(3) functions. */ -#define htonl(x) __htonl(x) -#define htons(x) __htons(x) -#define ntohl(x) __ntohl(x) -#define ntohs(x) __ntohs(x) - +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED extern uint32_t htonl(uint32_t); extern uint16_t htons(uint16_t); extern uint32_t ntohl(uint32_t); extern uint16_t ntohs(uint16_t); +#endif + +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif #if 0 diff --git a/sys/alpha/include/endian.h b/sys/alpha/include/endian.h index 28f7dd0..6781ceda 100644 --- a/sys/alpha/include/endian.h +++ b/sys/alpha/include/endian.h @@ -46,11 +46,11 @@ #define _QUAD_HIGHWORD 1 #define _QUAD_LOWWORD 0 +#ifndef _POSIX_SOURCE /* * Definitions for byte order, according to byte significance from low * address to high. */ -#ifndef _POSIX_SOURCE #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ @@ -58,10 +58,18 @@ #define BYTE_ORDER LITTLE_ENDIAN #endif /* !_POSIX_SOURCE */ -#ifdef _KERNEL #ifdef __GNUC__ -#define _BSWAP32_DEFINED +static __inline __uint64_t +__bswap64(__uint64_t _x) +{ + + return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | + ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | + ((_x << 24) & ((__uint64_t)0xff << 40)) | + ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); +} + static __inline __uint32_t __bswap32(__uint32_t __x) { @@ -81,7 +89,6 @@ __bswap32(__uint32_t __x) return (__r); } -#define _BSWAP16_DEFINED static __inline __uint16_t __bswap16(__uint16_t __x) { @@ -95,8 +102,11 @@ __bswap16(__uint16_t __x) return (__r); } -#endif /* _KERNEL */ - #endif /* __GNUC__ */ +#define __htonl(x) __bswap32(x) +#define __htons(x) __bswap16(x) +#define __ntohl(x) __bswap32(x) +#define __ntohs(x) __bswap16(x) + #endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h index 4076422..115511f 100644 --- a/sys/i386/include/endian.h +++ b/sys/i386/include/endian.h @@ -46,11 +46,11 @@ #define _QUAD_HIGHWORD 1 #define _QUAD_LOWWORD 0 +#ifndef _POSIX_SOURCE /* * Definitions for byte order, according to byte significance from low * address to high. */ -#ifndef _POSIX_SOURCE #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ @@ -58,35 +58,61 @@ #define BYTE_ORDER LITTLE_ENDIAN #endif /* ! _POSIX_SOURCE */ -#ifdef _KERNEL #ifdef __GNUC__ -#define _BSWAP32_DEFINED -static __inline __uint32_t -__bswap32(__uint32_t __x) -{ +#define __word_swap_int(x) \ +__extension__ ({ register __uint32_t __X = (x); \ + __asm ("rorl $16, %0" : "+r" (__X)); \ + __X; }) + #if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU) - __asm ("bswap %0" : "+r" (__x)); + +#define __byte_swap_int(x) \ +__extension__ ({ register __uint32_t __X = (x); \ + __asm ("bswap %0" : "+r" (__X)); \ + __X; }) #else - __asm ("xchgb %h0, %b0\n\t" - "rorl $16, %0\n\t" - "xchgb %h0, %b0" - : "+q" (__x)); + +#define __byte_swap_int(x) \ +__extension__ ({ register __uint32_t __X = (x); \ + __asm ("xchgb %h0, %b0\n\trorl $16, %0\n\txchgb %h0, %b0" \ + : "+q" (__X)); \ + __X; }) #endif - return __x; + +#define __byte_swap_word(x) \ +__extension__ ({ register __uint16_t __X = (x); \ + __asm ("xchgb %h0, %b0" : "+q" (__X)); \ + __X; }) + +static __inline __uint64_t +__bswap64(__uint64_t _x) +{ + return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | + ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | + ((_x << 24) & ((__uint64_t)0xff << 40)) | + ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); } -#define _BSWAP16_DEFINED -static __inline __uint16_t -__bswap16(__uint16_t __x) +static __inline __uint32_t +__bswap32(__uint32_t _x) { - __asm ("xchgb %h0, %b0" : "+q" (__x)); - return __x; + return (__byte_swap_int(_x)); } -#endif /* _KERNEL */ +static __inline __uint16_t +__bswap16(__uint16_t _x) +{ + + return (__byte_swap_word(_x)); +} #endif /* __GNUC__ */ +#define __htonl(x) __bswap32(x) +#define __htons(x) __bswap16(x) +#define __ntohl(x) __bswap32(x) +#define __ntohs(x) __bswap16(x) + #endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/sys/ia64/include/endian.h b/sys/ia64/include/endian.h index fe927a2..826fa54 100644 --- a/sys/ia64/include/endian.h +++ b/sys/ia64/include/endian.h @@ -47,11 +47,11 @@ #define _QUAD_HIGHWORD 1 #define _QUAD_LOWWORD 0 +#ifndef _POSIX_SOURCE /* * Definitions for byte order, according to byte significance from low * address to high. */ -#ifndef _POSIX_SOURCE #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ @@ -59,10 +59,8 @@ #define BYTE_ORDER LITTLE_ENDIAN #endif /* !_POSIX_SOURCE */ -#ifdef _KERNEL #ifdef __GNUC__ -#define _BSWAP64_DEFINED static __inline __uint64_t __bswap64(__uint64_t __x) { @@ -72,7 +70,6 @@ __bswap64(__uint64_t __x) return __r; } -#define _BSWAP32_DEFINED static __inline __uint32_t __bswap32(__uint32_t __x) { @@ -80,7 +77,6 @@ __bswap32(__uint32_t __x) return (__bswap64(__x) >> 32); } -#define _BSWAP16_DEFINED static __inline __uint16_t __bswap16(__uint16_t __x) { @@ -88,14 +84,11 @@ __bswap16(__uint16_t __x) return (__bswap64(__x) >> 48); } -#else /* !__GNUC__ */ -/* XXX: use the libkern versions for now; these might go away soon. */ -#define _BSWAP16_DEFINED -__uint16_t __bswap16(__uint16_t); -#define _BSWAP32_DEFINED -__uint32_t __bswap32(__uint32_t); #endif /* __GNUC__ */ -#endif /* _KERNEL */ +#define __htonl(x) __bswap32(x) +#define __htons(x) __bswap16(x) +#define __ntohl(x) __bswap32(x) +#define __ntohs(x) __bswap16(x) #endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/sys/netinet/in.h b/sys/netinet/in.h index cfd55ca..819a827 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -498,6 +498,16 @@ char *inet_ntoa_r __P((struct in_addr ina, char *buf)); /* in libkern */ #else /* !_KERNEL */ +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +__BEGIN_DECLS +__uint32_t htonl __P((__uint32_t)); +__uint16_t htons __P((__uint16_t)); +__uint32_t ntohl __P((__uint32_t)); +__uint16_t ntohs __P((__uint16_t)); +__END_DECLS +#endif + #ifndef _BYTEORDER_FUNC_DEFINED #define _BYTEORDER_FUNC_DEFINED #define htonl(x) __htonl(x) @@ -506,13 +516,6 @@ char *inet_ntoa_r __P((struct in_addr ina, char *buf)); /* in libkern */ #define ntohs(x) __ntohs(x) #endif -__BEGIN_DECLS -__uint32_t htonl __P((__uint32_t)); -__uint16_t htons __P((__uint16_t)); -__uint32_t ntohl __P((__uint32_t)); -__uint16_t ntohs __P((__uint16_t)); -__END_DECLS - #endif /* _KERNEL */ #endif diff --git a/sys/powerpc/include/endian.h b/sys/powerpc/include/endian.h index 4acd586..4bccc4e 100644 --- a/sys/powerpc/include/endian.h +++ b/sys/powerpc/include/endian.h @@ -58,8 +58,38 @@ #define BYTE_ORDER BIG_ENDIAN #endif /* !_POSIX_SOURCE */ -#ifndef _KERNEL -#include <sys/cdefs.h> -#endif /* _KERNEL */ +#ifdef __GNUC__ + +static __inline __uint16_t +__bswap16(__uint16_t _x) +{ + + return ((_x >> 8) | ((_x << 8) & 0xff00)); +} + +static __inline __uint32_t +__bswap32(__uint32_t _x) +{ + + return ((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) | + ((_x << 24) & 0xff000000)); +} + +static __inline __uint64_t +__bswap64(__uint64_t _x) +{ + + return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | + ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | + ((_x << 24) & ((__uint64_t)0xff << 40)) | + ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); +} + +#endif /* __GNUC__ */ + +#define __htonl(x) ((__uint32_t)(x)) +#define __htons(x) ((__uint16_t)(x)) +#define __ntohl(x) ((__uint32_t)(x)) +#define __ntohs(x) ((__uint16_t)(x)) #endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/sys/sparc64/include/endian.h b/sys/sparc64/include/endian.h index fc51c7e..b3f27d8 100644 --- a/sys/sparc64/include/endian.h +++ b/sys/sparc64/include/endian.h @@ -45,11 +45,11 @@ #define _QUAD_HIGHWORD 0 #define _QUAD_LOWWORD 1 +#ifndef _POSIX_SOURCE /* * Definitions for byte order, according to byte significance from low * address to high. */ -#ifndef _POSIX_SOURCE #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ @@ -57,4 +57,38 @@ #define BYTE_ORDER BIG_ENDIAN #endif /* !_POSIX_SOURCE */ +#ifdef __GNUC__ + +static __inline __uint16_t +__bswap16(__uint16_t _x) +{ + + return ((_x >> 8) | ((_x << 8) & 0xff00)); +} + +static __inline __uint32_t +__bswap32(__uint32_t _x) +{ + + return ((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) | + ((_x << 24) & 0xff000000)); +} + +static __inline __uint64_t +__bswap64(__uint64_t _x) +{ + + return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | + ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | + ((_x << 24) & ((__uint64_t)0xff << 40)) | + ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); +} + +#endif /* __GNUC__ */ + +#define __htonl(x) ((__uint32_t)(x)) +#define __htons(x) ((__uint16_t)(x)) +#define __ntohl(x) ((__uint32_t)(x)) +#define __ntohs(x) ((__uint16_t)(x)) + #endif /* !_MACHINE_ENDIAN_H_ */ diff --git a/sys/sys/param.h b/sys/sys/param.h index d954ed1..6799984 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -188,43 +188,31 @@ #define MAX(a,b) (((a)>(b))?(a):(b)) #endif -#ifdef _KERNEL /* - * Extended byte order support functions, for kernel use only currently. - * First, generic implementation of the byte swapping functions for those - * architectures that do not have optimized variants of each. + * Basic byte order function prototypes for non-inline functions. + * + * XXX temporarily exposed to userland for bogus software. */ -#ifndef _BSWAP16_DEFINED -#define _BSWAP16_DEFINED -static __inline __uint16_t -__bswap16(__uint16_t x) -{ - return ((x >> 8) | ((x << 8) & 0xff00U)); -} +#ifndef _BYTEORDER_PROTOTYPED +#define _BYTEORDER_PROTOTYPED +__BEGIN_DECLS +__uint32_t htonl __P((__uint32_t)); +__uint16_t htons __P((__uint16_t)); +__uint32_t ntohl __P((__uint32_t)); +__uint16_t ntohs __P((__uint16_t)); +__END_DECLS #endif -#ifndef _BSWAP32_DEFINED -#define _BSWAP32_DEFINED -static __inline __uint32_t -__bswap32(__uint32_t x) -{ - return ((x >> 24) | ((x >> 8) & 0xff00U) | ((x << 8) & 0xff0000U) | - ((x << 24) & 0xff000000U)); -} -#endif - -#ifndef _BSWAP64_DEFINED -#define _BSWAP64_DEFINED -static __inline __uint64_t -__bswap64(__uint64_t x) -{ - return ((x >> 56) | ((x >> 40) & 0xff00UL) | ((x >> 24) & 0xff0000UL) | - ((x >> 8) & 0xff000000UL) | ((x << 8) & 0xff00000000UL) | - ((x << 24) & 0xff0000000000UL) | ((x << 40) & 0xff000000000000UL) | - ((x << 56))); -} -#endif +/* XXX temporarily exposed to userland for bogus software. */ +#ifndef _BYTEORDER_FUNC_DEFINED +#define _BYTEORDER_FUNC_DEFINED +#define htonl(x) __htonl(x) +#define htons(x) __htons(x) +#define ntohl(x) __ntohl(x) +#define ntohs(x) __ntohs(x) +#endif /* !_BYTEORDER_FUNC_DEFINED */ +#ifdef _KERNEL #define bswap16(x) __bswap16(x) #define bswap32(x) __bswap32(x) #define bswap64(x) __bswap64(x) @@ -259,11 +247,6 @@ __bswap64(__uint64_t x) #define le64toh(x) bswap64((x)) #endif /* BYTE_ORDER */ -#define htonl(x) htobe32((x)) -#define htons(x) htobe16((x)) -#define ntohl(x) be32toh((x)) -#define ntohs(x) be16toh((x)) - #endif /* _KERNEL */ /* |