* include/grub/types.h: Declare all byteswaps as inline functions

except compile-time ones.

	Solves variable shadowing in constructions like
	cpu_to_le (le_to_cpu(x) + 1).
This commit is contained in:
Vladimir Serbinenko 2013-12-04 08:42:35 +01:00
parent 47f88cc94e
commit 85eb579ad9
2 changed files with 30 additions and 25 deletions

View file

@ -1,3 +1,11 @@
2013-12-04 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/types.h: Declare all byteswaps as inline functions
except compile-time ones.
Solves variable shadowing in constructions like
cpu_to_le (le_to_cpu(x) + 1).
2013-12-04 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/efi/efi.c: Remove variable length arrays.

View file

@ -153,11 +153,10 @@ typedef grub_uint64_t grub_off_t;
typedef grub_uint64_t grub_disk_addr_t;
/* Byte-orders. */
#define grub_swap_bytes16(x) \
({ \
grub_uint16_t _x = (x); \
(grub_uint16_t) ((_x << 8) | (_x >> 8)); \
})
static inline grub_uint16_t grub_swap_bytes16(grub_uint16_t _x)
{
return (grub_uint16_t) ((_x << 8) | (_x >> 8));
}
#define grub_swap_bytes16_compile_time(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
#define grub_swap_bytes32_compile_time(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24))
@ -185,27 +184,25 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x)
return __builtin_bswap64(x);
}
#else /* not gcc 4.3 or newer */
#define grub_swap_bytes32(x) \
({ \
grub_uint32_t _x = (x); \
(grub_uint32_t) ((_x << 24) \
| ((_x & (grub_uint32_t) 0xFF00UL) << 8) \
| ((_x & (grub_uint32_t) 0xFF0000UL) >> 8) \
| (_x >> 24)); \
})
static inline grub_uint32_t grub_swap_bytes32(grub_uint32_t _x)
{
return ((_x << 24)
| ((_x & (grub_uint32_t) 0xFF00UL) << 8)
| ((_x & (grub_uint32_t) 0xFF0000UL) >> 8)
| (_x >> 24));
}
#define grub_swap_bytes64(x) \
({ \
grub_uint64_t _x = (x); \
(grub_uint64_t) ((_x << 56) \
| ((_x & (grub_uint64_t) 0xFF00ULL) << 40) \
| ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) \
| ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) \
| ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) \
| ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \
| ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \
| (_x >> 56)); \
})
static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t _x)
{
return ((_x << 56)
| ((_x & (grub_uint64_t) 0xFF00ULL) << 40)
| ((_x & (grub_uint64_t) 0xFF0000ULL) << 24)
| ((_x & (grub_uint64_t) 0xFF000000ULL) << 8)
| ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8)
| ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24)
| ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40)
| (_x >> 56));
}
#endif /* not gcc 4.3 or newer */
#ifdef GRUB_CPU_WORDS_BIGENDIAN