~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to include/grub/types.h

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  GRUB  --  GRand Unified Bootloader
 
3
 *  Copyright (C) 2002, 2005  Free Software Foundation, Inc.
 
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
 
 
20
#ifndef GRUB_TYPES_HEADER
 
21
#define GRUB_TYPES_HEADER       1
 
22
 
 
23
#include <config.h>
 
24
#include <grub/cpu/types.h>
 
25
 
 
26
#ifdef GRUB_UTIL
 
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
 
31
# else
 
32
#  undef GRUB_CPU_WORDS_BIGENDIAN
 
33
# endif
 
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
 
39
# else
 
40
#  undef GRUB_CPU_WORDS_BIGENDIAN
 
41
# endif
 
42
#endif /* ! GRUB_UTIL */
 
43
 
 
44
#if GRUB_CPU_SIZEOF_VOID_P != GRUB_CPU_SIZEOF_LONG
 
45
# error "This architecture is not supported because sizeof(void *) != sizeof(long)"
 
46
#endif
 
47
 
 
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"
 
50
#endif
 
51
 
 
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;
 
58
#else
 
59
typedef long long               grub_int64_t;
 
60
#endif
 
61
 
 
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;
 
67
#else
 
68
typedef unsigned long long      grub_uint64_t;
 
69
#endif
 
70
 
 
71
/* Misc types.  */
 
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;
 
77
#else
 
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;
 
82
#endif
 
83
 
 
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;
 
89
#else
 
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;
 
94
#endif
 
95
 
 
96
/* FIXME: Will be grub_uint64_t */
 
97
typedef unsigned long   grub_disk_addr_t;
 
98
 
 
99
/* Byte-orders.  */
 
100
#define grub_swap_bytes16(x)    \
 
101
({ \
 
102
   grub_uint16_t _x = (x); \
 
103
   (grub_uint16_t) ((_x << 8) | (_x >> 8)); \
 
104
})
 
105
 
 
106
#define grub_swap_bytes32(x)    \
 
107
({ \
 
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) \
 
112
                    | (_x >> 24)); \
 
113
})
 
114
 
 
115
#define grub_swap_bytes64(x)    \
 
116
({ \
 
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) \
 
125
                    | (_x >> 56)); \
 
126
})
 
127
 
 
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 */
 
155
 
 
156
#endif /* ! GRUB_TYPES_HEADER */