00001 00038 #ifndef BYTEORDER_H_INCLUDED 00039 #define BYTEORDER_H_INCLUDED 00040 00041 #include <compiler.h> 00042 #include <types.h> 00043 00044 #include <arch/byteorder.h> 00045 00098 00099 00100 00109 00111 00112 00137 00139 00140 00165 00166 #ifndef swab32 00167 # define swab32(x) \ 00168 ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) \ 00169 | (((x) >> 8) & 0xff00) | (((x) >> 24) & 0xff)) 00170 #endif 00171 #ifndef swab16 00172 # define swab16(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)) 00173 #endif 00174 00175 #ifdef CPU_IS_BIG_ENDIAN 00176 00177 #define LE16(x) ((le16_t __force)((((x) & 0xff) << 8) \ 00178 | (((x) >> 8) & 0xff))) 00179 #define LE32(x) ((le32_t __force)((((x) & 0xff) << 24) \ 00180 | (((x) & 0xff00) << 8) \ 00181 | (((x) >> 8) & 0xff00) \ 00182 | (((x) >> 24) & 0xff))) 00183 #define BE16(x) ((be16_t __force)(x)) 00184 #define BE32(x) ((be32_t __force)(x)) 00185 00186 static inline uint16_t le16_to_cpu(le16_t x) 00187 { 00188 return swab16((uint16_t __force)x); 00189 } 00190 static inline uint32_t le32_to_cpu(le32_t x) 00191 { 00192 return swab32((uint32_t __force)x); 00193 } 00194 static inline le16_t cpu_to_le16(uint16_t x) 00195 { 00196 return (le16_t __force)swab16(x); 00197 } 00198 static inline le32_t cpu_to_le32(uint32_t x) 00199 { 00200 return (le32_t __force)swab32(x); 00201 } 00202 00203 static inline uint16_t be16_to_cpu(be16_t x) 00204 { 00205 return (uint16_t __force)x; 00206 } 00207 static inline uint32_t be32_to_cpu(be32_t x) 00208 { 00209 return (uint32_t __force)x; 00210 } 00211 static inline be16_t cpu_to_be16(uint16_t x) 00212 { 00213 return (be16_t __force)x; 00214 } 00215 static inline be32_t cpu_to_be32(uint32_t x) 00216 { 00217 return (be32_t __force)x; 00218 } 00219 00220 #else /* BIG_ENDIAN */ 00221 00222 #define LE16(x) ((le16_t __force)(x)) 00223 #define LE32(x) ((le32_t __force)(x)) 00224 #define BE16(x) ((be16_t __force)((((x) & 0xff) << 8) \ 00225 | (((x) >> 8) & 0xff))) 00226 #define BE32(x) ((be32_t __force)((((x) & 0xff) << 24) \ 00227 | (((x) & 0xff00) << 8) \ 00228 | (((x) >> 8) & 0xff00) \ 00229 | (((x) >> 24) & 0xff))) 00230 00231 static inline uint16_t le16_to_cpu(le16_t x) 00232 { 00233 return (uint16_t __force)x; 00234 } 00235 static inline uint32_t le32_to_cpu(le32_t x) 00236 { 00237 return (uint32_t __force)x; 00238 } 00239 static inline le16_t cpu_to_le16(uint16_t x) 00240 { 00241 return (le16_t __force)x; 00242 } 00243 static inline le32_t cpu_to_le32(uint32_t x) 00244 { 00245 return (le32_t __force)x; 00246 } 00247 00248 static inline uint16_t be16_to_cpu(be16_t x) 00249 { 00250 return swab16((uint16_t __force)x); 00251 } 00252 static inline uint32_t be32_to_cpu(be32_t x) 00253 { 00254 return swab32((uint32_t __force)x); 00255 } 00256 static inline be16_t cpu_to_be16(uint16_t x) 00257 { 00258 return (be16_t __force)swab16(x); 00259 } 00260 static inline be32_t cpu_to_be32(uint32_t x) 00261 { 00262 return (be32_t __force)swab32(x); 00263 } 00264 00265 #endif /* BIG_ENDIAN */ 00266 00268 00269 #endif /* BYTEORDER_H_INCLUDED */
1.6.3