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)
34 static inline uint16_t tswap16(uint16_t s
)
39 static inline uint32_t tswap32(uint32_t s
)
44 static inline uint64_t tswap64(uint64_t s
)
49 static inline void tswap16s(uint16_t *s
)
54 static inline void tswap32s(uint32_t *s
)
59 static inline void tswap64s(uint64_t *s
)
66 static inline uint16_t tswap16(uint16_t s
)
71 static inline uint32_t tswap32(uint32_t s
)
76 static inline uint64_t tswap64(uint64_t s
)
81 static inline void tswap16s(uint16_t *s
)
85 static inline void tswap32s(uint32_t *s
)
89 static inline void tswap64s(uint64_t *s
)
95 #if TARGET_LONG_SIZE == 4
96 #define tswapl(s) tswap32(s)
97 #define tswapls(s) tswap32s((uint32_t *)(s))
99 #define tswapl(s) tswap64(s)
100 #define tswapls(s) tswap64s((uint64_t *)(s))
103 /* types enums definitions */
105 typedef enum argtype
{
112 TYPE_PTRVOID
, /* pointer on unknown data */
120 #define MK_PTR(type) TYPE_PTR, type
121 #define MK_ARRAY(type, size) TYPE_ARRAY, size, type
122 #define MK_STRUCT(id) TYPE_STRUCT, id
124 #define THUNK_TARGET 0
128 /* standard struct handling */
129 const argtype
*field_types
;
131 int *field_offsets
[2];
132 /* special handling */
133 void (*convert
[2])(void *dst
, const void *src
);
139 /* Translation table for bitmasks... */
140 typedef struct bitmask_transtbl
{
141 unsigned int x86_mask
;
142 unsigned int x86_bits
;
143 unsigned int alpha_mask
;
144 unsigned int alpha_bits
;
147 void thunk_register_struct(int id
, const char *name
, const argtype
*types
);
148 void thunk_register_struct_direct(int id
, const char *name
, StructEntry
*se1
);
149 const argtype
*thunk_convert(void *dst
, const void *src
,
150 const argtype
*type_ptr
, int to_host
);
151 #ifndef NO_THUNK_TYPE_SIZE
153 extern StructEntry struct_entries
[];
155 static inline int thunk_type_size(const argtype
*type_ptr
, int is_host
)
158 const StructEntry
*se
;
176 return HOST_LONG_SIZE
;
178 return TARGET_LONG_SIZE
;
183 return size
* thunk_type_size(type_ptr
+ 2, is_host
);
185 se
= struct_entries
+ type_ptr
[1];
186 return se
->size
[is_host
];
192 static inline int thunk_type_align(const argtype
*type_ptr
, int is_host
)
195 const StructEntry
*se
;
213 return HOST_LONG_SIZE
;
215 return TARGET_LONG_SIZE
;
219 return thunk_type_align(type_ptr
+ 2, is_host
);
221 se
= struct_entries
+ type_ptr
[1];
222 return se
->align
[is_host
];
228 #endif /* NO_THUNK_TYPE_SIZE */
230 unsigned int target_to_host_bitmask(unsigned int x86_mask
,
231 bitmask_transtbl
* trans_tbl
);
232 unsigned int host_to_target_bitmask(unsigned int alpha_mask
,
233 bitmask_transtbl
* trans_tbl
);