1 #ifndef __OSDEP_H__ 2 #define __OSDEP_H__ 3 4 /* 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2, or (at 8 * your option) any later version. 9 */ 10 11 #define __LITTLE_ENDIAN /* x86 */ 12 13 /* Taken from /usr/include/linux/hfs_sysdep.h */ 14 #if defined(__BIG_ENDIAN) 15 # if !defined(__constant_htonl) 16 # define __constant_htonl(x) (x) 17 # endif 18 # if !defined(__constant_htons) 19 # define __constant_htons(x) (x) 20 # endif 21 #elif defined(__LITTLE_ENDIAN) 22 # if !defined(__constant_htonl) 23 # define __constant_htonl(x) \ 24 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \ 25 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \ 26 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \ 27 (((unsigned long int)(x) & 0xff000000U) >> 24))) 28 # endif 29 # if !defined(__constant_htons) 30 # define __constant_htons(x) \ 31 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \ 32 (((unsigned short int)(x) & 0xff00) >> 8))) 33 # endif 34 #else 35 # error "Don't know if bytes are big- or little-endian!" 36 #endif 37 38 #define ntohl(x) \ 39 (__builtin_constant_p(x) ? \ 40 __constant_htonl((x)) : \ 41 __swap32(x)) 42 #define htonl(x) \ 43 (__builtin_constant_p(x) ? \ 44 __constant_htonl((x)) : \ 45 __swap32(x)) 46 #define ntohs(x) \ 47 (__builtin_constant_p(x) ? \ 48 __constant_htons((x)) : \ 49 __swap16(x)) 50 #define htons(x) \ 51 (__builtin_constant_p(x) ? \ 52 __constant_htons((x)) : \ 53 __swap16(x)) 54 __swap32(unsigned long int x)55static inline unsigned long int __swap32(unsigned long int x) 56 { 57 __asm__("xchgb %b0,%h0\n\t" 58 "rorl $16,%0\n\t" 59 "xchgb %b0,%h0" 60 : "=q" (x) 61 : "0" (x)); 62 return x; 63 } 64 __swap16(unsigned short int x)65static inline unsigned short int __swap16(unsigned short int x) 66 { 67 __asm__("xchgb %b0,%h0" 68 : "=q" (x) 69 : "0" (x)); 70 return x; 71 } 72 73 /* Make routines available to all */ 74 #define swap32(x) __swap32(x) 75 #define swap16(x) __swap16(x) 76 77 #include "linux-asm-io.h" 78 79 typedef unsigned long Address; 80 81 /* ANSI prototyping macro */ 82 #ifdef __STDC__ 83 #define P(x) x 84 #else 85 #define P(x) () 86 #endif 87 88 #endif 89 90 /* 91 * Local variables: 92 * c-basic-offset: 8 93 * End: 94 */ 95