]>
Commit | Line | Data |
---|---|---|
6a161fa9 | 1 | /* |
4b13b216 | 2 | * GRUB -- GRand Unified Bootloader |
b977bf01 | 3 | * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc. |
6a161fa9 | 4 | * |
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. | |
9 | * | |
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. | |
14 | * | |
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. | |
18 | */ | |
19 | ||
4b13b216 | 20 | #ifndef GRUB_TYPES_HEADER |
21 | #define GRUB_TYPES_HEADER 1 | |
6a161fa9 | 22 | |
23 | #include <config.h> | |
4b13b216 | 24 | #include <grub/cpu/types.h> |
6a161fa9 | 25 | |
2166cc83 | 26 | #define __unused __attribute__ ((unused)) |
27 | ||
4b13b216 | 28 | #ifdef GRUB_UTIL |
29 | # define GRUB_CPU_SIZEOF_VOID_P SIZEOF_VOID_P | |
30 | # define GRUB_CPU_SIZEOF_LONG SIZEOF_LONG | |
6a161fa9 | 31 | # ifdef WORDS_BIGENDIAN |
4b13b216 | 32 | # define GRUB_CPU_WORDS_BIGENDIAN 1 |
6a161fa9 | 33 | # else |
4b13b216 | 34 | # undef GRUB_CPU_WORDS_BIGENDIAN |
6a161fa9 | 35 | # endif |
4b13b216 | 36 | #else /* ! GRUB_UTIL */ |
b977bf01 | 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 | |
4b13b216 | 40 | # define GRUB_CPU_WORDS_BIGENDIAN 1 |
6a161fa9 | 41 | # else |
4b13b216 | 42 | # undef GRUB_CPU_WORDS_BIGENDIAN |
6a161fa9 | 43 | # endif |
4b13b216 | 44 | #endif /* ! GRUB_UTIL */ |
6a161fa9 | 45 | |
4b13b216 | 46 | #if GRUB_CPU_SIZEOF_VOID_P != GRUB_CPU_SIZEOF_LONG |
6a161fa9 | 47 | # error "This architecture is not supported because sizeof(void *) != sizeof(long)" |
48 | #endif | |
49 | ||
4b13b216 | 50 | #if GRUB_CPU_SIZEOF_VOID_P != 4 && GRUB_CPU_SIZEOF_VOID_P != 8 |
6a161fa9 | 51 | # error "This architecture is not supported because sizeof(void *) != 4 and sizeof(void *) != 8" |
52 | #endif | |
53 | ||
54 | /* Define various wide integers. */ | |
4b13b216 | 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; | |
6a161fa9 | 60 | #else |
4b13b216 | 61 | typedef long long grub_int64_t; |
6a161fa9 | 62 | #endif |
63 | ||
4b13b216 | 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; | |
6a161fa9 | 69 | #else |
4b13b216 | 70 | typedef unsigned long long grub_uint64_t; |
6a161fa9 | 71 | #endif |
72 | ||
73 | /* Misc types. */ | |
b786f3b5 | 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; | |
59b8208a | 79 | #else |
b786f3b5 | 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; | |
59b8208a | 84 | #endif |
85 | ||
86 | #if GRUB_CPU_SIZEOF_VOID_P == 8 | |
4b13b216 | 87 | typedef grub_uint64_t grub_addr_t; |
4b13b216 | 88 | typedef grub_uint64_t grub_size_t; |
89 | typedef grub_int64_t grub_ssize_t; | |
6a161fa9 | 90 | #else |
4b13b216 | 91 | typedef grub_uint32_t grub_addr_t; |
4b13b216 | 92 | typedef grub_uint32_t grub_size_t; |
93 | typedef grub_int32_t grub_ssize_t; | |
6a161fa9 | 94 | #endif |
95 | ||
524a1e6a | 96 | /* The type for representing a file offset. */ |
97 | typedef grub_uint64_t grub_off_t; | |
98 | ||
99 | /* The type for representing a disk block address. */ | |
100 | typedef grub_uint64_t grub_disk_addr_t; | |
7f67dc13 | 101 | |
6a161fa9 | 102 | /* Byte-orders. */ |
4b13b216 | 103 | #define grub_swap_bytes16(x) \ |
6a161fa9 | 104 | ({ \ |
4b13b216 | 105 | grub_uint16_t _x = (x); \ |
106 | (grub_uint16_t) ((_x << 8) | (_x >> 8)); \ | |
6a161fa9 | 107 | }) |
108 | ||
4b13b216 | 109 | #define grub_swap_bytes32(x) \ |
6a161fa9 | 110 | ({ \ |
4b13b216 | 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) \ | |
6a161fa9 | 115 | | (_x >> 24)); \ |
116 | }) | |
117 | ||
4b13b216 | 118 | #define grub_swap_bytes64(x) \ |
6a161fa9 | 119 | ({ \ |
4b13b216 | 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) \ | |
6a161fa9 | 128 | | (_x >> 56)); \ |
129 | }) | |
130 | ||
4b13b216 | 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)) | |
6a161fa9 | 144 | #else /* ! WORDS_BIGENDIAN */ |
4b13b216 | 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) | |
6a161fa9 | 157 | #endif /* ! WORDS_BIGENDIAN */ |
158 | ||
4b13b216 | 159 | #endif /* ! GRUB_TYPES_HEADER */ |