Commit 3431395696562c63d7bcec10e1307ef6feac31aa
1 parent
01ffc75b
fixed endianness
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
39 additions
and
1 deletions
thunk.h
| @@ -2,14 +2,52 @@ | @@ -2,14 +2,52 @@ | ||
| 2 | #define THUNK_H | 2 | #define THUNK_H |
| 3 | 3 | ||
| 4 | #include <inttypes.h> | 4 | #include <inttypes.h> |
| 5 | +#include <endian.h> | ||
| 6 | + | ||
| 7 | +#ifdef HAVE_BYTESWAP_H | ||
| 5 | #include <byteswap.h> | 8 | #include <byteswap.h> |
| 9 | +#else | ||
| 10 | + | ||
| 11 | +#define bswap_16(x) \ | ||
| 12 | +({ \ | ||
| 13 | + uint16_t __x = (x); \ | ||
| 14 | + ((uint16_t)( \ | ||
| 15 | + (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \ | ||
| 16 | + (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \ | ||
| 17 | +}) | ||
| 18 | + | ||
| 19 | +#define bswap_32(x) \ | ||
| 20 | +({ \ | ||
| 21 | + uint32_t __x = (x); \ | ||
| 22 | + ((uint32_t)( \ | ||
| 23 | + (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ | ||
| 24 | + (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ | ||
| 25 | + (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ | ||
| 26 | + (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \ | ||
| 27 | +}) | ||
| 28 | + | ||
| 29 | +#define bswap_64(x) \ | ||
| 30 | +({ \ | ||
| 31 | + __u64 __x = (x); \ | ||
| 32 | + ((__u64)( \ | ||
| 33 | + (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \ | ||
| 34 | + (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \ | ||
| 35 | + (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \ | ||
| 36 | + (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \ | ||
| 37 | + (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \ | ||
| 38 | + (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \ | ||
| 39 | + (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \ | ||
| 40 | + (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \ | ||
| 41 | +}) | ||
| 42 | + | ||
| 43 | +#endif | ||
| 6 | 44 | ||
| 7 | #undef WORDS_BIGENDIAN | 45 | #undef WORDS_BIGENDIAN |
| 8 | #if __BYTE_ORDER == __BIG_ENDIAN | 46 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 9 | #define WORDS_BIGENDIAN | 47 | #define WORDS_BIGENDIAN |
| 10 | #endif | 48 | #endif |
| 11 | 49 | ||
| 12 | -#ifdef WORD_BIGENDIAN | 50 | +#ifdef WORDS_BIGENDIAN |
| 13 | #define BSWAP_NEEDED | 51 | #define BSWAP_NEEDED |
| 14 | #endif | 52 | #endif |
| 15 | 53 |