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
28 #if defined(WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
33 #define TARGET_LONG_BITS 32
35 #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
39 static inline uint16_t tswap16(uint16_t s)
44 static inline uint32_t tswap32(uint32_t s)
49 static inline uint64_t tswap64(uint64_t s)
54 static inline void tswap16s(uint16_t *s)
59 static inline void tswap32s(uint32_t *s)
64 static inline void tswap64s(uint64_t *s)
71 static inline uint16_t tswap16(uint16_t s)
76 static inline uint32_t tswap32(uint32_t s)
81 static inline uint64_t tswap64(uint64_t s)
86 static inline void tswap16s(uint16_t *s)
90 static inline void tswap32s(uint32_t *s)
94 static inline void tswap64s(uint64_t *s)
100 #if TARGET_LONG_SIZE == 4
101 #define tswapl(s) tswap32(s)
102 #define tswapls(s) tswap32s((uint32_t *)(s))
104 #define tswapl(s) tswap64(s)
105 #define tswapls(s) tswap64s((uint64_t *)(s))
108 #if TARGET_LONG_SIZE == 4
109 typedef int32_t target_long;
110 typedef uint32_t target_ulong;
111 #elif TARGET_LONG_SIZE == 8
112 typedef int64_t target_long;
113 typedef uint64_t target_ulong;
115 #error TARGET_LONG_SIZE undefined
118 /* types enums definitions */
120 typedef enum argtype {
127 TYPE_PTRVOID, /* pointer on unknown data */
135 #define MK_PTR(type) TYPE_PTR, type
136 #define MK_ARRAY(type, size) TYPE_ARRAY, size, type
137 #define MK_STRUCT(id) TYPE_STRUCT, id
139 #define THUNK_TARGET 0
143 /* standard struct handling */
144 const argtype *field_types;
146 int *field_offsets[2];
147 /* special handling */
148 void (*convert[2])(void *dst, const void *src);
154 /* Translation table for bitmasks... */
155 typedef struct bitmask_transtbl {
156 unsigned int x86_mask;
157 unsigned int x86_bits;
158 unsigned int alpha_mask;
159 unsigned int alpha_bits;
162 void thunk_register_struct(int id, const char *name, const argtype *types);
163 void thunk_register_struct_direct(int id, const char *name, StructEntry *se1);
164 const argtype *thunk_convert(void *dst, const void *src,
165 const argtype *type_ptr, int to_host);
166 #ifndef NO_THUNK_TYPE_SIZE
168 extern StructEntry struct_entries[];
170 static inline int thunk_type_size(const argtype *type_ptr, int is_host)
173 const StructEntry *se;
191 return HOST_LONG_SIZE;
193 return TARGET_LONG_SIZE;
198 return size * thunk_type_size(type_ptr + 2, is_host);
200 se = struct_entries + type_ptr[1];
201 return se->size[is_host];
207 static inline int thunk_type_align(const argtype *type_ptr, int is_host)
210 const StructEntry *se;
228 return HOST_LONG_SIZE;
230 return TARGET_LONG_SIZE;
234 return thunk_type_align(type_ptr + 2, is_host);
236 se = struct_entries + type_ptr[1];
237 return se->align[is_host];
243 #endif /* NO_THUNK_TYPE_SIZE */
245 unsigned int target_to_host_bitmask(unsigned int x86_mask,
246 bitmask_transtbl * trans_tbl);
247 unsigned int host_to_target_bitmask(unsigned int alpha_mask,
248 bitmask_transtbl * trans_tbl);