2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef GRUB_TYPES_HEADER
21 #define GRUB_TYPES_HEADER 1
24 #include <grub/cpu/types.h>
26 #define __unused __attribute__ ((unused))
29 # define GRUB_CPU_SIZEOF_VOID_P SIZEOF_VOID_P
30 # define GRUB_CPU_SIZEOF_LONG SIZEOF_LONG
31 # ifdef WORDS_BIGENDIAN
32 # define GRUB_CPU_WORDS_BIGENDIAN 1
34 # undef GRUB_CPU_WORDS_BIGENDIAN
36 #else /* ! GRUB_UTIL */
37 # define GRUB_CPU_SIZEOF_VOID_P GRUB_TARGET_SIZEOF_VOID_P
38 # define GRUB_CPU_SIZEOF_LONG GRUB_TARGET_SIZEOF_LONG
39 # ifdef GRUB_TARGET_WORDS_BIGENDIAN
40 # define GRUB_CPU_WORDS_BIGENDIAN 1
42 # undef GRUB_CPU_WORDS_BIGENDIAN
44 #endif /* ! GRUB_UTIL */
46 #if GRUB_CPU_SIZEOF_VOID_P != GRUB_CPU_SIZEOF_LONG
47 # error "This architecture is not supported because sizeof(void *) != sizeof(long)"
50 #if GRUB_CPU_SIZEOF_VOID_P != 4 && GRUB_CPU_SIZEOF_VOID_P != 8
51 # error "This architecture is not supported because sizeof(void *) != 4 and sizeof(void *) != 8"
54 /* Define various wide integers. */
55 typedef signed char grub_int8_t
;
56 typedef short grub_int16_t
;
57 typedef int grub_int32_t
;
58 #if GRUB_CPU_SIZEOF_VOID_P == 8
59 typedef long grub_int64_t
;
61 typedef long long grub_int64_t
;
64 typedef unsigned char grub_uint8_t
;
65 typedef unsigned short grub_uint16_t
;
66 typedef unsigned grub_uint32_t
;
67 #if GRUB_CPU_SIZEOF_VOID_P == 8
68 typedef unsigned long grub_uint64_t
;
70 typedef unsigned long long grub_uint64_t
;
74 #if GRUB_TARGET_SIZEOF_VOID_P == 8
75 typedef grub_uint64_t grub_target_addr_t
;
76 typedef grub_uint64_t grub_target_off_t
;
77 typedef grub_uint64_t grub_target_size_t
;
78 typedef grub_int64_t grub_target_ssize_t
;
80 typedef grub_uint32_t grub_target_addr_t
;
81 typedef grub_uint32_t grub_target_off_t
;
82 typedef grub_uint32_t grub_target_size_t
;
83 typedef grub_int32_t grub_target_ssize_t
;
86 #if GRUB_CPU_SIZEOF_VOID_P == 8
87 typedef grub_uint64_t grub_addr_t
;
88 typedef grub_uint64_t grub_size_t
;
89 typedef grub_int64_t grub_ssize_t
;
91 typedef grub_uint32_t grub_addr_t
;
92 typedef grub_uint32_t grub_size_t
;
93 typedef grub_int32_t grub_ssize_t
;
96 /* The type for representing a file offset. */
97 typedef grub_uint64_t grub_off_t
;
99 /* The type for representing a disk block address. */
100 typedef grub_uint64_t grub_disk_addr_t
;
103 #define grub_swap_bytes16(x) \
105 grub_uint16_t _x = (x); \
106 (grub_uint16_t) ((_x << 8) | (_x >> 8)); \
109 #define grub_swap_bytes32(x) \
111 grub_uint32_t _x = (x); \
112 (grub_uint32_t) ((_x << 24) \
113 | ((_x & (grub_uint32_t) 0xFF00UL) << 8) \
114 | ((_x & (grub_uint32_t) 0xFF0000UL) >> 8) \
118 #define grub_swap_bytes64(x) \
120 grub_uint64_t _x = (x); \
121 (grub_uint64_t) ((_x << 56) \
122 | ((_x & (grub_uint64_t) 0xFF00ULL) << 40) \
123 | ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) \
124 | ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) \
125 | ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) \
126 | ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \
127 | ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \
131 #ifdef GRUB_CPU_WORDS_BIGENDIAN
132 # define grub_cpu_to_le16(x) grub_swap_bytes16(x)
133 # define grub_cpu_to_le32(x) grub_swap_bytes32(x)
134 # define grub_cpu_to_le64(x) grub_swap_bytes64(x)
135 # define grub_le_to_cpu16(x) grub_swap_bytes16(x)
136 # define grub_le_to_cpu32(x) grub_swap_bytes32(x)
137 # define grub_le_to_cpu64(x) grub_swap_bytes64(x)
138 # define grub_cpu_to_be16(x) ((grub_uint16_t) (x))
139 # define grub_cpu_to_be32(x) ((grub_uint32_t) (x))
140 # define grub_cpu_to_be64(x) ((grub_uint64_t) (x))
141 # define grub_be_to_cpu16(x) ((grub_uint16_t) (x))
142 # define grub_be_to_cpu32(x) ((grub_uint32_t) (x))
143 # define grub_be_to_cpu64(x) ((grub_uint64_t) (x))
144 #else /* ! WORDS_BIGENDIAN */
145 # define grub_cpu_to_le16(x) ((grub_uint16_t) (x))
146 # define grub_cpu_to_le32(x) ((grub_uint32_t) (x))
147 # define grub_cpu_to_le64(x) ((grub_uint64_t) (x))
148 # define grub_le_to_cpu16(x) ((grub_uint16_t) (x))
149 # define grub_le_to_cpu32(x) ((grub_uint32_t) (x))
150 # define grub_le_to_cpu64(x) ((grub_uint64_t) (x))
151 # define grub_cpu_to_be16(x) grub_swap_bytes16(x)
152 # define grub_cpu_to_be32(x) grub_swap_bytes32(x)
153 # define grub_cpu_to_be64(x) grub_swap_bytes64(x)
154 # define grub_be_to_cpu16(x) grub_swap_bytes16(x)
155 # define grub_be_to_cpu32(x) grub_swap_bytes32(x)
156 # define grub_be_to_cpu64(x) grub_swap_bytes64(x)
157 #endif /* ! WORDS_BIGENDIAN */
159 #endif /* ! GRUB_TYPES_HEADER */