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, see <http://www.gnu.org/licenses/>.
24 #include "exec/user/abitypes.h"
26 /* types enums definitions */
28 typedef enum argtype
{
35 TYPE_PTRVOID
, /* pointer on unknown data */
44 #define MK_PTR(type) TYPE_PTR, type
45 #define MK_ARRAY(type, size) TYPE_ARRAY, size, type
46 #define MK_STRUCT(id) TYPE_STRUCT, id
48 #define THUNK_TARGET 0
52 /* standard struct handling */
53 const argtype
*field_types
;
55 int *field_offsets
[2];
56 /* special handling */
57 void (*convert
[2])(void *dst
, const void *src
);
63 /* Translation table for bitmasks... */
64 typedef struct bitmask_transtbl
{
65 unsigned int target_mask
;
66 unsigned int target_bits
;
67 unsigned int host_mask
;
68 unsigned int host_bits
;
71 void thunk_register_struct(int id
, const char *name
, const argtype
*types
);
72 void thunk_register_struct_direct(int id
, const char *name
,
73 const StructEntry
*se1
);
74 const argtype
*thunk_convert(void *dst
, const void *src
,
75 const argtype
*type_ptr
, int to_host
);
76 const argtype
*thunk_print(void *arg
, const argtype
*type_ptr
);
78 extern StructEntry
*struct_entries
;
80 int thunk_type_size_array(const argtype
*type_ptr
, int is_host
);
81 int thunk_type_align_array(const argtype
*type_ptr
, int is_host
);
83 static inline int thunk_type_size(const argtype
*type_ptr
, int is_host
)
86 const StructEntry
*se
;
104 return sizeof(void *);
106 return TARGET_ABI_BITS
/ 8;
111 #if defined(HOST_X86_64)
113 #elif defined(HOST_ALPHA) || defined(HOST_IA64) || defined(HOST_MIPS) || \
114 defined(HOST_PARISC) || defined(HOST_SPARC64)
116 #elif defined(HOST_PPC)
117 return sizeof(void *);
122 #if defined(TARGET_X86_64)
124 #elif defined(TARGET_ALPHA) || defined(TARGET_IA64) || defined(TARGET_MIPS) || \
125 defined(TARGET_PARISC) || defined(TARGET_SPARC64)
127 #elif defined(TARGET_PPC)
128 return TARGET_ABI_BITS
/ 8;
136 return size
* thunk_type_size_array(type_ptr
+ 2, is_host
);
138 se
= struct_entries
+ type_ptr
[1];
139 return se
->size
[is_host
];
141 g_assert_not_reached();
145 static inline int thunk_type_align(const argtype
*type_ptr
, int is_host
)
148 const StructEntry
*se
;
156 return __alignof__(short);
158 return ABI_SHORT_ALIGNMENT
;
162 return __alignof__(int);
164 return ABI_INT_ALIGNMENT
;
169 return __alignof__(long long);
171 return ABI_LLONG_ALIGNMENT
;
178 return __alignof__(long);
180 return ABI_LONG_ALIGNMENT
;
184 return thunk_type_size(type_ptr
, is_host
);
186 return thunk_type_align_array(type_ptr
+ 2, is_host
);
188 se
= struct_entries
+ type_ptr
[1];
189 return se
->align
[is_host
];
191 g_assert_not_reached();
195 unsigned int target_to_host_bitmask(unsigned int target_mask
,
196 const bitmask_transtbl
* trans_tbl
);
197 unsigned int host_to_target_bitmask(unsigned int host_mask
,
198 const bitmask_transtbl
* trans_tbl
);
200 void thunk_init(unsigned int max_structs
);