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.1 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, see <http://www.gnu.org/licenses/>.
23 #ifndef CONFIG_USER_ONLY
24 #error Cannot include this header from system emulation
28 #include "user/abitypes.h"
30 /* types enums definitions */
32 typedef enum argtype
{
39 TYPE_PTRVOID
, /* pointer on unknown data */
48 #define MK_PTR(type) TYPE_PTR, type
49 #define MK_ARRAY(type, size) TYPE_ARRAY, (int)(size), type
50 #define MK_STRUCT(id) TYPE_STRUCT, id
52 #define THUNK_TARGET 0
56 /* standard struct handling */
57 const argtype
*field_types
;
59 int *field_offsets
[2];
60 /* special handling */
61 void (*convert
[2])(void *dst
, const void *src
);
62 void (*print
)(void *arg
);
68 /* Translation table for bitmasks... */
69 typedef struct bitmask_transtbl
{
70 unsigned int target_mask
;
71 unsigned int target_bits
;
72 unsigned int host_mask
;
73 unsigned int host_bits
;
76 void thunk_register_struct(int id
, const char *name
, const argtype
*types
);
77 void thunk_register_struct_direct(int id
, const char *name
,
78 const StructEntry
*se1
);
79 const argtype
*thunk_convert(void *dst
, const void *src
,
80 const argtype
*type_ptr
, int to_host
);
81 const argtype
*thunk_print(void *arg
, const argtype
*type_ptr
);
83 extern StructEntry
*struct_entries
;
85 int thunk_type_size_array(const argtype
*type_ptr
, int is_host
);
86 int thunk_type_align_array(const argtype
*type_ptr
, int is_host
);
88 static inline int thunk_type_size(const argtype
*type_ptr
, int is_host
)
91 const StructEntry
*se
;
109 return sizeof(void *);
111 return TARGET_ABI_BITS
/ 8;
116 #if defined(HOST_X86_64)
118 #elif defined(HOST_MIPS) || defined(HOST_SPARC64)
120 #elif defined(HOST_PPC)
121 return sizeof(void *);
126 #if defined(TARGET_X86_64)
128 #elif defined(TARGET_ALPHA) || defined(TARGET_IA64) || defined(TARGET_MIPS) || \
129 defined(TARGET_PARISC) || defined(TARGET_SPARC64)
131 #elif defined(TARGET_PPC)
132 return TARGET_ABI_BITS
/ 8;
140 return size
* thunk_type_size_array(type_ptr
+ 2, is_host
);
142 se
= struct_entries
+ type_ptr
[1];
143 return se
->size
[is_host
];
145 g_assert_not_reached();
149 static inline int thunk_type_align(const argtype
*type_ptr
, int is_host
)
152 const StructEntry
*se
;
160 return __alignof__(short);
162 return ABI_SHORT_ALIGNMENT
;
166 return __alignof__(int);
168 return ABI_INT_ALIGNMENT
;
173 return __alignof__(long long);
175 return ABI_LLONG_ALIGNMENT
;
182 return __alignof__(long);
184 return ABI_LONG_ALIGNMENT
;
188 return thunk_type_size(type_ptr
, is_host
);
190 return thunk_type_align_array(type_ptr
+ 2, is_host
);
192 se
= struct_entries
+ type_ptr
[1];
193 return se
->align
[is_host
];
195 g_assert_not_reached();
199 unsigned int target_to_host_bitmask_len(unsigned int target_mask
,
200 const bitmask_transtbl
*trans_tbl
,
202 unsigned int host_to_target_bitmask_len(unsigned int host_mask
,
203 const bitmask_transtbl
* trans_tbl
,
206 #define target_to_host_bitmask(M, T) \
207 target_to_host_bitmask_len(M, T, ARRAY_SIZE(T))
208 #define host_to_target_bitmask(M, T) \
209 host_to_target_bitmask_len(M, T, ARRAY_SIZE(T))
211 void thunk_init(unsigned int max_structs
);