vaseboot/include/VasEBoot/types.h

320 lines
11 KiB
C

/*
* VasEBoot -- GRand Unified Bootloader
* Copyright (C) 2002,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* VasEBoot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VasEBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VasEBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VasEBoot_TYPES_HEADER
#define VasEBoot_TYPES_HEADER 1
#include <config.h>
#ifndef VasEBoot_UTIL
#include <VasEBoot/cpu/types.h>
#endif
#ifdef __MINGW32__
#define VasEBoot_PACKED __attribute__ ((packed,gcc_struct))
#else
#define VasEBoot_PACKED __attribute__ ((packed))
#endif
#ifdef VasEBoot_BUILD
# define VasEBoot_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P
# define VasEBoot_CPU_SIZEOF_LONG BUILD_SIZEOF_LONG
# if BUILD_WORDS_BIGENDIAN
# define VasEBoot_CPU_WORDS_BIGENDIAN 1
# else
# undef VasEBoot_CPU_WORDS_BIGENDIAN
# endif
#elif defined (VasEBoot_UTIL)
# define VasEBoot_CPU_SIZEOF_VOID_P SIZEOF_VOID_P
# define VasEBoot_CPU_SIZEOF_LONG SIZEOF_LONG
# ifdef WORDS_BIGENDIAN
# define VasEBoot_CPU_WORDS_BIGENDIAN 1
# else
# undef VasEBoot_CPU_WORDS_BIGENDIAN
# endif
#else /* ! VasEBoot_UTIL */
# define VasEBoot_CPU_SIZEOF_VOID_P VasEBoot_TARGET_SIZEOF_VOID_P
# define VasEBoot_CPU_SIZEOF_LONG VasEBoot_TARGET_SIZEOF_LONG
# ifdef VasEBoot_TARGET_WORDS_BIGENDIAN
# define VasEBoot_CPU_WORDS_BIGENDIAN 1
# else
# undef VasEBoot_CPU_WORDS_BIGENDIAN
# endif
#endif /* ! VasEBoot_UTIL */
#if VasEBoot_CPU_SIZEOF_VOID_P != 4 && VasEBoot_CPU_SIZEOF_VOID_P != 8
# error "This architecture is not supported because sizeof(void *) != 4 and sizeof(void *) != 8"
#endif
#if VasEBoot_CPU_SIZEOF_LONG != 4 && VasEBoot_CPU_SIZEOF_LONG != 8
# error "This architecture is not supported because sizeof(long) != 4 and sizeof(long) != 8"
#endif
#if !defined (VasEBoot_UTIL) && !defined (VasEBoot_TARGET_WORDSIZE)
# if VasEBoot_TARGET_SIZEOF_VOID_P == 4
# define VasEBoot_TARGET_WORDSIZE 32
# elif VasEBoot_TARGET_SIZEOF_VOID_P == 8
# define VasEBoot_TARGET_WORDSIZE 64
# endif
#endif
/* Define various wide integers. */
typedef signed char VasEBoot_int8_t;
typedef short VasEBoot_int16_t;
typedef int VasEBoot_int32_t;
#if VasEBoot_CPU_SIZEOF_LONG == 8
typedef long VasEBoot_int64_t;
#else
typedef long long VasEBoot_int64_t;
#endif
typedef unsigned char VasEBoot_uint8_t;
typedef unsigned short VasEBoot_uint16_t;
typedef unsigned VasEBoot_uint32_t;
# define PRIxVasEBoot_UINT32_T "x"
# define PRIuVasEBoot_UINT32_T "u"
#if VasEBoot_CPU_SIZEOF_LONG == 8
typedef unsigned long VasEBoot_uint64_t;
# define PRIxVasEBoot_UINT64_T "lx"
# define PRIuVasEBoot_UINT64_T "lu"
#else
typedef unsigned long long VasEBoot_uint64_t;
# define PRIxVasEBoot_UINT64_T "llx"
# define PRIuVasEBoot_UINT64_T "llu"
#endif
/* Misc types. */
#if VasEBoot_CPU_SIZEOF_VOID_P == 8
typedef VasEBoot_uint64_t VasEBoot_addr_t;
typedef VasEBoot_uint64_t VasEBoot_size_t;
typedef VasEBoot_int64_t VasEBoot_ssize_t;
# define VasEBoot_SIZE_MAX 18446744073709551615UL
# if VasEBoot_CPU_SIZEOF_LONG == 8
# define PRIxVasEBoot_SIZE "lx"
# define PRIxVasEBoot_ADDR "lx"
# define PRIuVasEBoot_SIZE "lu"
# define PRIdVasEBoot_SSIZE "ld"
# else
# define PRIxVasEBoot_SIZE "llx"
# define PRIxVasEBoot_ADDR "llx"
# define PRIuVasEBoot_SIZE "llu"
# define PRIdVasEBoot_SSIZE "lld"
# endif
#else
typedef VasEBoot_uint32_t VasEBoot_addr_t;
typedef VasEBoot_uint32_t VasEBoot_size_t;
typedef VasEBoot_int32_t VasEBoot_ssize_t;
# define VasEBoot_SIZE_MAX 4294967295UL
# define PRIxVasEBoot_SIZE "x"
# define PRIxVasEBoot_ADDR "x"
# define PRIuVasEBoot_SIZE "u"
# define PRIdVasEBoot_SSIZE "d"
#endif
#define VasEBoot_UCHAR_MAX 0xFF
#define VasEBoot_USHRT_MAX 65535
#define VasEBoot_SHRT_MAX 0x7fff
#define VasEBoot_UINT_MAX 4294967295U
#define VasEBoot_INT_MAX 0x7fffffff
#define VasEBoot_INT32_MIN (-2147483647 - 1)
#define VasEBoot_INT32_MAX 2147483647
#if VasEBoot_CPU_SIZEOF_LONG == 8
# define VasEBoot_ULONG_MAX 18446744073709551615UL
# define VasEBoot_LONG_MAX 9223372036854775807L
# define VasEBoot_LONG_MIN (-9223372036854775807L - 1)
#else
# define VasEBoot_ULONG_MAX 4294967295UL
# define VasEBoot_LONG_MAX 2147483647L
# define VasEBoot_LONG_MIN (-2147483647L - 1)
#endif
typedef VasEBoot_uint64_t VasEBoot_properly_aligned_t;
#define VasEBoot_PROPERLY_ALIGNED_ARRAY(name, size) VasEBoot_properly_aligned_t name[((size) + sizeof (VasEBoot_properly_aligned_t) - 1) / sizeof (VasEBoot_properly_aligned_t)]
/* The type for representing a file offset. */
typedef VasEBoot_uint64_t VasEBoot_off_t;
/* The type for representing a disk block address. */
typedef VasEBoot_uint64_t VasEBoot_disk_addr_t;
/* Byte-orders. */
static inline VasEBoot_uint16_t VasEBoot_swap_bytes16(VasEBoot_uint16_t _x)
{
return (VasEBoot_uint16_t) ((_x << 8) | (_x >> 8));
}
#define VasEBoot_swap_bytes16_compile_time(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
#define VasEBoot_swap_bytes32_compile_time(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000UL) >> 24))
#define VasEBoot_swap_bytes64_compile_time(x) \
({ \
VasEBoot_uint64_t _x = (x); \
(VasEBoot_uint64_t) ((_x << 56) \
| ((_x & (VasEBoot_uint64_t) 0xFF00ULL) << 40) \
| ((_x & (VasEBoot_uint64_t) 0xFF0000ULL) << 24) \
| ((_x & (VasEBoot_uint64_t) 0xFF000000ULL) << 8) \
| ((_x & (VasEBoot_uint64_t) 0xFF00000000ULL) >> 8) \
| ((_x & (VasEBoot_uint64_t) 0xFF0000000000ULL) >> 24) \
| ((_x & (VasEBoot_uint64_t) 0xFF000000000000ULL) >> 40) \
| (_x >> 56)); \
})
#if (defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 3)) || defined(__clang__)
static inline VasEBoot_uint32_t VasEBoot_swap_bytes32(VasEBoot_uint32_t x)
{
return __builtin_bswap32(x);
}
static inline VasEBoot_uint64_t VasEBoot_swap_bytes64(VasEBoot_uint64_t x)
{
return __builtin_bswap64(x);
}
#else /* not gcc 4.3 or newer */
static inline VasEBoot_uint32_t VasEBoot_swap_bytes32(VasEBoot_uint32_t _x)
{
return ((_x << 24)
| ((_x & (VasEBoot_uint32_t) 0xFF00UL) << 8)
| ((_x & (VasEBoot_uint32_t) 0xFF0000UL) >> 8)
| (_x >> 24));
}
static inline VasEBoot_uint64_t VasEBoot_swap_bytes64(VasEBoot_uint64_t _x)
{
return ((_x << 56)
| ((_x & (VasEBoot_uint64_t) 0xFF00ULL) << 40)
| ((_x & (VasEBoot_uint64_t) 0xFF0000ULL) << 24)
| ((_x & (VasEBoot_uint64_t) 0xFF000000ULL) << 8)
| ((_x & (VasEBoot_uint64_t) 0xFF00000000ULL) >> 8)
| ((_x & (VasEBoot_uint64_t) 0xFF0000000000ULL) >> 24)
| ((_x & (VasEBoot_uint64_t) 0xFF000000000000ULL) >> 40)
| (_x >> 56));
}
#endif /* not gcc 4.3 or newer */
#ifdef VasEBoot_CPU_WORDS_BIGENDIAN
# define VasEBoot_cpu_to_le16(x) VasEBoot_swap_bytes16(x)
# define VasEBoot_cpu_to_le32(x) VasEBoot_swap_bytes32(x)
# define VasEBoot_cpu_to_le64(x) VasEBoot_swap_bytes64(x)
# define VasEBoot_le_to_cpu16(x) VasEBoot_swap_bytes16(x)
# define VasEBoot_le_to_cpu32(x) VasEBoot_swap_bytes32(x)
# define VasEBoot_le_to_cpu64(x) VasEBoot_swap_bytes64(x)
# define VasEBoot_cpu_to_be16(x) ((VasEBoot_uint16_t) (x))
# define VasEBoot_cpu_to_be32(x) ((VasEBoot_uint32_t) (x))
# define VasEBoot_cpu_to_be64(x) ((VasEBoot_uint64_t) (x))
# define VasEBoot_be_to_cpu16(x) ((VasEBoot_uint16_t) (x))
# define VasEBoot_be_to_cpu32(x) ((VasEBoot_uint32_t) (x))
# define VasEBoot_be_to_cpu64(x) ((VasEBoot_uint64_t) (x))
# define VasEBoot_cpu_to_be16_compile_time(x) ((VasEBoot_uint16_t) (x))
# define VasEBoot_cpu_to_be32_compile_time(x) ((VasEBoot_uint32_t) (x))
# define VasEBoot_cpu_to_be64_compile_time(x) ((VasEBoot_uint64_t) (x))
# define VasEBoot_be_to_cpu64_compile_time(x) ((VasEBoot_uint64_t) (x))
# define VasEBoot_cpu_to_le32_compile_time(x) VasEBoot_swap_bytes32_compile_time(x)
# define VasEBoot_cpu_to_le64_compile_time(x) VasEBoot_swap_bytes64_compile_time(x)
# define VasEBoot_cpu_to_le16_compile_time(x) VasEBoot_swap_bytes16_compile_time(x)
#else /* ! WORDS_BIGENDIAN */
# define VasEBoot_cpu_to_le16(x) ((VasEBoot_uint16_t) (x))
# define VasEBoot_cpu_to_le32(x) ((VasEBoot_uint32_t) (x))
# define VasEBoot_cpu_to_le64(x) ((VasEBoot_uint64_t) (x))
# define VasEBoot_le_to_cpu16(x) ((VasEBoot_uint16_t) (x))
# define VasEBoot_le_to_cpu32(x) ((VasEBoot_uint32_t) (x))
# define VasEBoot_le_to_cpu64(x) ((VasEBoot_uint64_t) (x))
# define VasEBoot_cpu_to_be16(x) VasEBoot_swap_bytes16(x)
# define VasEBoot_cpu_to_be32(x) VasEBoot_swap_bytes32(x)
# define VasEBoot_cpu_to_be64(x) VasEBoot_swap_bytes64(x)
# define VasEBoot_be_to_cpu16(x) VasEBoot_swap_bytes16(x)
# define VasEBoot_be_to_cpu32(x) VasEBoot_swap_bytes32(x)
# define VasEBoot_be_to_cpu64(x) VasEBoot_swap_bytes64(x)
# define VasEBoot_cpu_to_be16_compile_time(x) VasEBoot_swap_bytes16_compile_time(x)
# define VasEBoot_cpu_to_be32_compile_time(x) VasEBoot_swap_bytes32_compile_time(x)
# define VasEBoot_cpu_to_be64_compile_time(x) VasEBoot_swap_bytes64_compile_time(x)
# define VasEBoot_be_to_cpu64_compile_time(x) VasEBoot_swap_bytes64_compile_time(x)
# define VasEBoot_cpu_to_le16_compile_time(x) ((VasEBoot_uint16_t) (x))
# define VasEBoot_cpu_to_le32_compile_time(x) ((VasEBoot_uint32_t) (x))
# define VasEBoot_cpu_to_le64_compile_time(x) ((VasEBoot_uint64_t) (x))
#endif /* ! WORDS_BIGENDIAN */
struct VasEBoot_unaligned_uint16
{
VasEBoot_uint16_t val;
} VasEBoot_PACKED;
struct VasEBoot_unaligned_uint32
{
VasEBoot_uint32_t val;
} VasEBoot_PACKED;
struct VasEBoot_unaligned_uint64
{
VasEBoot_uint64_t val;
} VasEBoot_PACKED;
typedef struct VasEBoot_unaligned_uint16 VasEBoot_unaligned_uint16_t;
typedef struct VasEBoot_unaligned_uint32 VasEBoot_unaligned_uint32_t;
typedef struct VasEBoot_unaligned_uint64 VasEBoot_unaligned_uint64_t;
static inline VasEBoot_uint16_t VasEBoot_get_unaligned16 (const void *ptr)
{
const struct VasEBoot_unaligned_uint16 *dd
= (const struct VasEBoot_unaligned_uint16 *) ptr;
return dd->val;
}
static inline void VasEBoot_set_unaligned16 (void *ptr, VasEBoot_uint16_t val)
{
struct VasEBoot_unaligned_uint16 *dd = (struct VasEBoot_unaligned_uint16 *) ptr;
dd->val = val;
}
static inline VasEBoot_uint32_t VasEBoot_get_unaligned32 (const void *ptr)
{
const struct VasEBoot_unaligned_uint32 *dd
= (const struct VasEBoot_unaligned_uint32 *) ptr;
return dd->val;
}
static inline void VasEBoot_set_unaligned32 (void *ptr, VasEBoot_uint32_t val)
{
struct VasEBoot_unaligned_uint32 *dd = (struct VasEBoot_unaligned_uint32 *) ptr;
dd->val = val;
}
static inline VasEBoot_uint64_t VasEBoot_get_unaligned64 (const void *ptr)
{
const struct VasEBoot_unaligned_uint64 *dd
= (const struct VasEBoot_unaligned_uint64 *) ptr;
return dd->val;
}
static inline void VasEBoot_set_unaligned64 (void *ptr, VasEBoot_uint64_t val)
{
struct VasEBoot_unaligned_uint64_t
{
VasEBoot_uint64_t d;
} VasEBoot_PACKED;
struct VasEBoot_unaligned_uint64_t *dd = (struct VasEBoot_unaligned_uint64_t *) ptr;
dd->d = val;
}
#define VasEBoot_CHAR_BIT 8
#endif /* ! VasEBoot_TYPES_HEADER */