Changeset 169 for trunk/src/emx/include/386/endian.h
- Timestamp:
- May 18, 2003, 6:53:22 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/include/386/endian.h
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r168 r169 32 32 * 33 33 * from: @(#)endian.h 7.8 (Berkeley) 4/3/91 34 * $Id: endian.h,v 1.9 1994/02/12 07:23:49 cgd Exp $ 34 * $FreeBSD: src/sys/i386/include/endian.h,v 1.35 2002/09/23 04:32:16 mike Exp $ 35 * 36 * bird: this is a bit mixed up. with 1.18 too. 35 37 */ 36 38 37 39 #ifndef _MACHINE_ENDIAN_H_ 38 40 #define _MACHINE_ENDIAN_H_ 41 39 42 40 43 /* … … 44 47 #define _QUAD_LOWWORD 0 45 48 46 47 #ifndef _POSIX_SOURCE48 49 /* 49 50 * Definitions for byte order, according to byte significance from low 50 51 * address to high. 51 52 */ 52 #define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */53 #define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */54 #define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */53 #define _LITTLE_ENDIAN 1234 /* LSB first: i386, vax */ 54 #define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */ 55 #define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */ 55 56 56 #define BYTE_ORDER LITTLE_ENDIAN57 #define _BYTE_ORDER LITTLE_ENDIAN 57 58 58 unsigned long htonl(unsigned long); 59 unsigned short htons(unsigned short); 60 unsigned long ntohl(unsigned long); 61 unsigned short ntohs(unsigned short); 59 /* 60 * Deprecated variants that don't have enough underscores to be useful in more 61 * strict namespaces. 62 */ 63 #if __BSD_VISIBLE 64 #define LITTLE_ENDIAN _LITTLE_ENDIAN 65 #define BIG_ENDIAN _BIG_ENDIAN 66 #define PDP_ENDIAN _PDP_ENDIAN 67 #define BYTE_ORDER _BYTE_ORDER 68 #endif 62 69 63 #ifndef __EMX__ 70 #include <sys/cdefs.h> 71 64 72 65 73 #ifdef __GNUC__ 66 74 67 #if __GNUC__ >= 2 75 #define __word_swap_int(x) \ 76 __extension__ ({ register __uint32_t __X = (x); \ 77 __asm ("rorl $16, %0" : "+r" (__X)); \ 78 __X; }) 68 79 69 #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU)) 70 #define __byte_swap_long(x) \ 71 ({ register unsigned long __x = (x); \ 72 asm ("bswap %1" \ 73 : "=q" (__x) \ 74 : "0" (__x)); \ 75 __x; }) 80 #if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU) 81 82 #define __byte_swap_int(x) \ 83 __extension__ ({ register __uint32_t __X = (x); \ 84 __asm ("bswap %0" : "+r" (__X)); \ 85 __X; }) 76 86 #else 77 #define __byte_swap_long(x) \ 78 ({ register unsigned long __x = (x); \ 79 asm ("xchgb %h1, %b1\n\trorl $16, %1\n\txchgb %h1, %b1" \ 80 : "=q" (__x) \ 81 : "0" (__x)); \ 82 __x; }) 83 #endif /* KERNEL && ... */ 87 88 #define __byte_swap_int(x) \ 89 __extension__ ({ register __uint32_t __X = (x); \ 90 __asm ("xchgb %h0, %b0\n\trorl $16, %0\n\txchgb %h0, %b0" \ 91 : "+q" (__X)); \ 92 __X; }) 93 #endif 94 84 95 #define __byte_swap_word(x) \ 85 ({ register unsigned short __x = (x); \ 86 asm ("xchgb %h1, %b1" \ 87 : "=q" (__x) \ 88 : "0" (__x)); \ 89 __x; }) 96 __extension__ ({ register __uint16_t __X = (x); \ 97 __asm ("xchgb %h0, %b0" : "+q" (__X)); \ 98 __X; }) 90 99 91 #else /* __GNUC__ >= 2 */ 100 static __inline __uint64_t 101 __bswap64(__uint64_t _x) 102 { 103 return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) | 104 ((_x >> 8) & 0xff000000) | ((_x << 8) & ((__uint64_t)0xff << 32)) | 105 ((_x << 24) & ((__uint64_t)0xff << 40)) | 106 ((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56))); 107 } 92 108 93 #if defined(KERNEL) && ((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU)) 94 #define __byte_swap_long(x) \ 95 ({ register unsigned long __x = (x); \ 96 asm ("bswap %1" \ 97 : "=r" (__x) \ 98 : "0" (__x)); \ 99 __x; }) 100 #else 101 #define __byte_swap_long(x) \ 102 ({ register u_long __x = (x); \ 103 asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \ 104 : "=r" (__x) \ 105 : "0" (__x)); \ 106 __x; }) 107 #endif /* KERNEL && ... */ 108 #define __byte_swap_word(x) \ 109 ({ register u_short __x = (x); \ 110 asm ("rorw $8, %w1" \ 111 : "=r" (__x) \ 112 : "0" (__x)); \ 113 __x; }) 109 static __inline __uint32_t 110 __bswap32(__uint32_t _x) 111 { 114 112 115 #endif /* __GNUC__ >= 2 */ 113 return (__byte_swap_int(_x)); 114 } 116 115 117 #define ntohl(x) __byte_swap_long(x) 118 #define ntohs(x) __byte_swap_word(x) 119 #define htonl(x) __byte_swap_long(x) 120 #define htons(x) __byte_swap_word(x) 116 static __inline __uint16_t 117 __bswap16(__uint16_t _x) 118 { 121 119 122 #endif /* __GNUC__ */ 120 return (__byte_swap_word(_x)); 121 } 123 122 124 #endif /* not __EMX__ */ 123 #define __htonl(x) __bswap32(x) 124 #define __htons(x) __bswap16(x) 125 #define __ntohl(x) __bswap32(x) 126 #define __ntohs(x) __bswap16(x) 127 128 #else /* !__GNUC__ */ 129 130 /* 131 * No optimizations are available for this compiler. Fall back to 132 * non-optimized functions by defining the constant usually used to prevent 133 * redefinition. 134 */ 135 #define _BYTEORDER_FUNC_DEFINED 136 137 #endif /* __GNUC__ */ 138 139 140 /* For toolkit compatibility we must do this stuff here. 141 * Not sure how correct this is now. And mixing 4 versions 142 * of (Free)BSD doesn't help.... 143 */ 144 #ifndef _POSIX_SOURCE 145 146 #ifndef _KERNEL 147 #include <sys/cdefs.h> 148 #endif 149 150 __BEGIN_DECLS 151 unsigned long _System htonl __P((unsigned long)); 152 unsigned short _System htons __P((unsigned short)); 153 unsigned long _System ntohl __P((unsigned long)); 154 unsigned short _System ntohs __P((unsigned short)); 155 __END_DECLS 156 157 #ifndef _BYTEORDER_FUNC_DEFINED 158 #define _BYTEORDER_FUNC_DEFINED 159 #define htonl(x) __htonl(x) 160 #define htons(x) __htons(x) 161 #define ntohl(x) __ntohl(x) 162 #define ntohs(x) __ntohs(x) 163 #endif 125 164 126 165 /* 127 166 * Macros for network/external number representation conversion. 128 167 */ 129 #define NTOHL(x) (x) = ntohl((u_long)x)130 #define NTOHS(x) (x) = ntohs((u_short)x)131 #define HTONL(x) (x) = htonl((u_long)x)132 #define HTONS(x) (x) = htons((u_short)x)168 #define NTOHL(x) ((x) = ntohl((u_long)(x))) 169 #define NTOHS(x) ((x) = ntohs((u_short)(x))) 170 #define HTONL(x) ((x) = htonl((u_long)(x))) 171 #define HTONS(x) ((x) = htons((u_short)(x))) 133 172 134 #endif /* _POSIX_SOURCE */ 173 #endif /*!_POSIX_SOURCE*/ 174 135 175 136 176 #endif /* _MACHINE_ENDIAN_H_ */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.