diff options
author | tmm <tmm@FreeBSD.org> | 2002-02-27 17:16:18 +0000 |
---|---|---|
committer | tmm <tmm@FreeBSD.org> | 2002-02-27 17:16:18 +0000 |
commit | 3ed05b7b8966710c5cffbf0ba479dd2e07c91c0a (patch) | |
tree | 46353f300fd15b6b132ccde617d8726a2e38d224 /sys/ia64/include/endian.h | |
parent | e9d577adb2ffdd3b7300415775c1212a087ce0dc (diff) | |
download | FreeBSD-src-3ed05b7b8966710c5cffbf0ba479dd2e07c91c0a.zip FreeBSD-src-3ed05b7b8966710c5cffbf0ba479dd2e07c91c0a.tar.gz |
Add the following functions/macros to support byte order conversions and
device drivers for bus system with other endinesses than the CPU (using
interfaces compatible to NetBSD):
- bwap16() and bswap32(). These have optimized implementations on some
architectures; for those that don't, there exist generic implementations.
- macros to convert from a certain byte order to host byte order and vice
versa, using a naming scheme like le16toh(), htole16().
These are implemented using the bswap functions.
- stream bus space access functions, which do not perform a byte order
conversion (while the normal access functions would if the bus endianess
differs from the CPU endianess).
htons(), htonl(), ntohs() and ntohl() are implemented using the new
functions above for kernel usage. None of the above interfaces is currently
exported to user land.
Make use of the new functions in a few places where local implementations
of the same functionality existed.
Reviewed by: mike, bde
Tested on alpha by: mike
Diffstat (limited to 'sys/ia64/include/endian.h')
-rw-r--r-- | sys/ia64/include/endian.h | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/sys/ia64/include/endian.h b/sys/ia64/include/endian.h index c1efac9..fe927a2 100644 --- a/sys/ia64/include/endian.h +++ b/sys/ia64/include/endian.h @@ -59,12 +59,12 @@ #define BYTE_ORDER LITTLE_ENDIAN #endif /* !_POSIX_SOURCE */ +#ifdef _KERNEL #ifdef __GNUC__ -__BEGIN_DECLS - +#define _BSWAP64_DEFINED static __inline __uint64_t -__uint8_swap_uint64(__uint64_t __x) +__bswap64(__uint64_t __x) { __uint64_t __r; __asm __volatile("mux1 %0=%1,@rev" @@ -72,36 +72,30 @@ __uint8_swap_uint64(__uint64_t __x) return __r; } +#define _BSWAP32_DEFINED static __inline __uint32_t -__htonl(__uint32_t __x) +__bswap32(__uint32_t __x) { - return (__uint8_swap_uint64(__x) >> 32); + return (__bswap64(__x) >> 32); } +#define _BSWAP16_DEFINED static __inline __uint16_t -__htons(__uint16_t __x) +__bswap16(__uint16_t __x) { - return (__uint8_swap_uint64(__x) >> 48); + return (__bswap64(__x) >> 48); } -static __inline __uint32_t -__ntohl(__uint32_t __x) -{ - - return (__uint8_swap_uint64(__x) >> 32); -} - -static __inline __uint16_t -__ntohs(__uint16_t __x) -{ - - return (__uint8_swap_uint64(__x) >> 48); -} - -__END_DECLS - +#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 */ + #endif /* !_MACHINE_ENDIAN_H_ */ |