]>
git.proxmox.com Git - qemu.git/blob - thunk.h
2 * Generic thunking code to convert data between host and target CPU
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifdef HAVE_BYTESWAP_H
34 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
35 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
42 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
43 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
44 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
45 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
52 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
53 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
54 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
55 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
56 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
57 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
58 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
59 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
64 #ifdef WORDS_BIGENDIAN
70 #define TARGET_LONG_BITS 32
73 #if defined(__alpha__) || defined (__ia64__)
74 #define HOST_LONG_BITS 64
76 #define HOST_LONG_BITS 32
79 #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
80 #define HOST_LONG_SIZE (TARGET_LONG_BITS / 8)
82 static inline uint16_t bswap16(uint16_t x
)
87 static inline uint32_t bswap32(uint32_t x
)
92 static inline uint64_t bswap64(uint64_t x
)
97 static inline void bswap16s(uint16_t *s
)
102 static inline void bswap32s(uint32_t *s
)
107 static inline void bswap64s(uint64_t *s
)
114 static inline uint16_t tswap16(uint16_t s
)
119 static inline uint32_t tswap32(uint32_t s
)
124 static inline uint64_t tswap64(uint64_t s
)
129 static inline void tswap16s(uint16_t *s
)
134 static inline void tswap32s(uint32_t *s
)
139 static inline void tswap64s(uint64_t *s
)
146 static inline uint16_t tswap16(uint16_t s
)
151 static inline uint32_t tswap32(uint32_t s
)
156 static inline uint64_t tswap64(uint64_t s
)
161 static inline void tswap16s(uint16_t *s
)
165 static inline void tswap32s(uint32_t *s
)
169 static inline void tswap64s(uint64_t *s
)
175 #if TARGET_LONG_SIZE == 4
176 #define tswapl(s) tswap32(s)
177 #define tswapls(s) tswap32s((uint32_t *)(s))
179 #define tswapl(s) tswap64(s)
180 #define tswapls(s) tswap64s((uint64_t *)(s))
183 #if TARGET_LONG_SIZE == 4
184 typedef int32_t target_long
;
185 typedef uint32_t target_ulong
;
186 #elif TARGET_LONG_SIZE == 8
187 typedef int64_t target_long
;
188 typedef uint64_t target_ulong
;
190 #error TARGET_LONG_SIZE undefined
193 /* types enums definitions */
195 typedef enum argtype
{
202 TYPE_PTRVOID
, /* pointer on unknown data */
210 #define MK_PTR(type) TYPE_PTR, type
211 #define MK_ARRAY(type, size) TYPE_ARRAY, size, type
212 #define MK_STRUCT(id) TYPE_STRUCT, id
214 #define THUNK_TARGET 0
218 /* standard struct handling */
219 const argtype
*field_types
;
221 int *field_offsets
[2];
222 /* special handling */
223 void (*convert
[2])(void *dst
, const void *src
);
229 /* Translation table for bitmasks... */
230 typedef struct bitmask_transtbl
{
231 unsigned int x86_mask
;
232 unsigned int x86_bits
;
233 unsigned int alpha_mask
;
234 unsigned int alpha_bits
;
237 void thunk_register_struct(int id
, const char *name
, const argtype
*types
);
238 void thunk_register_struct_direct(int id
, const char *name
, StructEntry
*se1
);
239 const argtype
*thunk_convert(void *dst
, const void *src
,
240 const argtype
*type_ptr
, int to_host
);
242 unsigned int target_to_host_bitmask(unsigned int x86_mask
,
243 bitmask_transtbl
* trans_tbl
);
244 unsigned int host_to_target_bitmask(unsigned int alpha_mask
,
245 bitmask_transtbl
* trans_tbl
);