2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2002, 2005 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>
27
# define GRUB_CPU_SIZEOF_VOID_P SIZEOF_VOID_P
28
# define GRUB_CPU_SIZEOF_LONG SIZEOF_LONG
29
# ifdef WORDS_BIGENDIAN
30
# define GRUB_CPU_WORDS_BIGENDIAN 1
32
# undef GRUB_CPU_WORDS_BIGENDIAN
34
#else /* ! GRUB_UTIL */
35
# define GRUB_CPU_SIZEOF_VOID_P GRUB_HOST_SIZEOF_VOID_P
36
# define GRUB_CPU_SIZEOF_LONG GRUB_HOST_SIZEOF_LONG
37
# ifdef GRUB_HOST_WORDS_BIGENDIAN
38
# define GRUB_CPU_WORDS_BIGENDIAN 1
40
# undef GRUB_CPU_WORDS_BIGENDIAN
42
#endif /* ! GRUB_UTIL */
44
#if GRUB_CPU_SIZEOF_VOID_P != GRUB_CPU_SIZEOF_LONG
45
# error "This architecture is not supported because sizeof(void *) != sizeof(long)"
48
#if GRUB_CPU_SIZEOF_VOID_P != 4 && GRUB_CPU_SIZEOF_VOID_P != 8
49
# error "This architecture is not supported because sizeof(void *) != 4 and sizeof(void *) != 8"
52
/* Define various wide integers. */
53
typedef signed char grub_int8_t;
54
typedef short grub_int16_t;
55
typedef int grub_int32_t;
56
#if GRUB_CPU_SIZEOF_VOID_P == 8
57
typedef long grub_int64_t;
59
typedef long long grub_int64_t;
62
typedef unsigned char grub_uint8_t;
63
typedef unsigned short grub_uint16_t;
64
typedef unsigned grub_uint32_t;
65
#if GRUB_CPU_SIZEOF_VOID_P == 8
66
typedef unsigned long grub_uint64_t;
68
typedef unsigned long long grub_uint64_t;
72
#if GRUB_HOST_SIZEOF_VOID_P == 8
73
typedef grub_uint64_t grub_host_addr_t;
74
typedef grub_uint64_t grub_host_off_t;
75
typedef grub_uint64_t grub_host_size_t;
76
typedef grub_int64_t grub_host_ssize_t;
78
typedef grub_uint32_t grub_host_addr_t;
79
typedef grub_uint32_t grub_host_off_t;
80
typedef grub_uint32_t grub_host_size_t;
81
typedef grub_int32_t grub_host_ssize_t;
84
#if GRUB_CPU_SIZEOF_VOID_P == 8
85
typedef grub_uint64_t grub_addr_t;
86
typedef grub_uint64_t grub_off_t;
87
typedef grub_uint64_t grub_size_t;
88
typedef grub_int64_t grub_ssize_t;
90
typedef grub_uint32_t grub_addr_t;
91
typedef grub_uint32_t grub_off_t;
92
typedef grub_uint32_t grub_size_t;
93
typedef grub_int32_t grub_ssize_t;
96
/* FIXME: Will be grub_uint64_t */
97
typedef unsigned long grub_disk_addr_t;
100
#define grub_swap_bytes16(x) \
102
grub_uint16_t _x = (x); \
103
(grub_uint16_t) ((_x << 8) | (_x >> 8)); \
106
#define grub_swap_bytes32(x) \
108
grub_uint32_t _x = (x); \
109
(grub_uint32_t) ((_x << 24) \
110
| ((_x & (grub_uint32_t) 0xFF00UL) << 8) \
111
| ((_x & (grub_uint32_t) 0xFF0000UL) >> 8) \
115
#define grub_swap_bytes64(x) \
117
grub_uint64_t _x = (x); \
118
(grub_uint64_t) ((_x << 56) \
119
| ((_x & (grub_uint64_t) 0xFF00ULL) << 40) \
120
| ((_x & (grub_uint64_t) 0xFF0000ULL) << 24) \
121
| ((_x & (grub_uint64_t) 0xFF000000ULL) << 8) \
122
| ((_x & (grub_uint64_t) 0xFF00000000ULL) >> 8) \
123
| ((_x & (grub_uint64_t) 0xFF0000000000ULL) >> 24) \
124
| ((_x & (grub_uint64_t) 0xFF000000000000ULL) >> 40) \
128
#ifdef GRUB_CPU_WORDS_BIGENDIAN
129
# define grub_cpu_to_le16(x) grub_swap_bytes16(x)
130
# define grub_cpu_to_le32(x) grub_swap_bytes32(x)
131
# define grub_cpu_to_le64(x) grub_swap_bytes64(x)
132
# define grub_le_to_cpu16(x) grub_swap_bytes16(x)
133
# define grub_le_to_cpu32(x) grub_swap_bytes32(x)
134
# define grub_le_to_cpu64(x) grub_swap_bytes64(x)
135
# define grub_cpu_to_be16(x) ((grub_uint16_t) (x))
136
# define grub_cpu_to_be32(x) ((grub_uint32_t) (x))
137
# define grub_cpu_to_be64(x) ((grub_uint64_t) (x))
138
# define grub_be_to_cpu16(x) ((grub_uint16_t) (x))
139
# define grub_be_to_cpu32(x) ((grub_uint32_t) (x))
140
# define grub_be_to_cpu64(x) ((grub_uint64_t) (x))
141
#else /* ! WORDS_BIGENDIAN */
142
# define grub_cpu_to_le16(x) ((grub_uint16_t) (x))
143
# define grub_cpu_to_le32(x) ((grub_uint32_t) (x))
144
# define grub_cpu_to_le64(x) ((grub_uint64_t) (x))
145
# define grub_le_to_cpu16(x) ((grub_uint16_t) (x))
146
# define grub_le_to_cpu32(x) ((grub_uint32_t) (x))
147
# define grub_le_to_cpu64(x) ((grub_uint64_t) (x))
148
# define grub_cpu_to_be16(x) grub_swap_bytes16(x)
149
# define grub_cpu_to_be32(x) grub_swap_bytes32(x)
150
# define grub_cpu_to_be64(x) grub_swap_bytes64(x)
151
# define grub_be_to_cpu16(x) grub_swap_bytes16(x)
152
# define grub_be_to_cpu32(x) grub_swap_bytes32(x)
153
# define grub_be_to_cpu64(x) grub_swap_bytes64(x)
154
#endif /* ! WORDS_BIGENDIAN */
156
#endif /* ! GRUB_TYPES_HEADER */