diff options
Diffstat (limited to 'sys/arch/i386/include')
-rw-r--r-- | sys/arch/i386/include/endian.h | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/sys/arch/i386/include/endian.h b/sys/arch/i386/include/endian.h index 056a456a205..2be9c3d4eba 100644 --- a/sys/arch/i386/include/endian.h +++ b/sys/arch/i386/include/endian.h @@ -1,3 +1,4 @@ +/* $OpenBSD: endian.h,v 1.4 1996/11/25 13:11:24 niklas Exp $ */ /* $NetBSD: endian.h,v 1.16 1995/06/01 17:19:18 mycroft Exp $ */ /* @@ -53,40 +54,40 @@ */ #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 */ +#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in int32_t */ #define BYTE_ORDER LITTLE_ENDIAN #include <sys/cdefs.h> __BEGIN_DECLS -unsigned long htonl __P((unsigned long)); -unsigned short htons __P((unsigned short)); -unsigned long ntohl __P((unsigned long)); -unsigned short ntohs __P((unsigned short)); +u_int32_t htonl __P((u_int32_t)); +u_int16_t htons __P((u_int16_t)); +u_int32_t ntohl __P((u_int32_t)); +u_int16_t ntohs __P((u_int16_t)); __END_DECLS #ifdef __GNUC__ #if defined(_KERNEL) && !defined(I386_CPU) -#define __byte_swap_long_variable(x) \ -({ register unsigned long __x = (x); \ +#define __byte_swap_int32_variable(x) \ +({ register u_int32 __x = (x); \ __asm ("bswap %1" \ : "=r" (__x) \ : "0" (__x)); \ __x; }) #else -#define __byte_swap_long_variable(x) \ -({ register unsigned long __x = (x); \ +#define __byte_swap_int32_variable(x) \ +({ register u_int32_t __x = (x); \ __asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \ : "=r" (__x) \ : "0" (__x)); \ __x; }) #endif /* _KERNEL && ... */ -#define __byte_swap_word_variable(x) \ -({ register unsigned short __x = (x); \ +#define __byte_swap_int16_variable(x) \ +({ register u_int16_t __x = (x); \ __asm ("rorw $8, %w1" \ : "=r" (__x) \ : "0" (__x)); \ @@ -94,32 +95,32 @@ __END_DECLS #ifdef __OPTIMIZE__ -#define __byte_swap_long_constant(x) \ +#define __byte_swap_int32_constant(x) \ ((((x) & 0xff000000) >> 24) | \ (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | \ (((x) & 0x000000ff) << 24)) -#define __byte_swap_word_constant(x) \ +#define __byte_swap_int16_constant(x) \ ((((x) & 0xff00) >> 8) | \ (((x) & 0x00ff) << 8)) -#define __byte_swap_long(x) \ +#define __byte_swap_int32(x) \ (__builtin_constant_p((x)) ? \ - __byte_swap_long_constant(x) : __byte_swap_long_variable(x)) -#define __byte_swap_word(x) \ + __byte_swap_int32_constant(x) : __byte_swap_int32_variable(x)) +#define __byte_swap_int16(x) \ (__builtin_constant_p((x)) ? \ - __byte_swap_word_constant(x) : __byte_swap_word_variable(x)) + __byte_swap_int16_constant(x) : __byte_swap_int16_variable(x)) #else /* __OPTIMIZE__ */ -#define __byte_swap_long(x) __byte_swap_long_variable(x) -#define __byte_swap_word(x) __byte_swap_word_variable(x) +#define __byte_swap_int32(x) __byte_swap_int32_variable(x) +#define __byte_swap_int16(x) __byte_swap_int16_variable(x) #endif /* __OPTIMIZE__ */ -#define ntohl(x) __byte_swap_long(x) -#define ntohs(x) __byte_swap_word(x) -#define htonl(x) __byte_swap_long(x) -#define htons(x) __byte_swap_word(x) +#define ntohl(x) __byte_swap_int32(x) +#define ntohs(x) __byte_swap_int16(x) +#define htonl(x) __byte_swap_int32(x) +#define htons(x) __byte_swap_int16(x) #endif /* __GNUC__ */ @@ -127,10 +128,10 @@ __END_DECLS /* * Macros for network/external number representation conversion. */ -#define NTOHL(x) (x) = ntohl((unsigned long)(x)) -#define NTOHS(x) (x) = ntohs((unsigned short)(x)) -#define HTONL(x) (x) = htonl((unsigned long)(x)) -#define HTONS(x) (x) = htons((unsigned short)(x)) +#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 /* _POSIX_SOURCE */ |