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/>.
25 /* types enums definitions */
27 typedef enum argtype
{
34 TYPE_PTRVOID
, /* pointer on unknown data */
42 #define MK_PTR(type) TYPE_PTR, type
43 #define MK_ARRAY(type, size) TYPE_ARRAY, size, type
44 #define MK_STRUCT(id) TYPE_STRUCT, id
46 #define THUNK_TARGET 0
50 /* standard struct handling */
51 const argtype
*field_types
;
53 int *field_offsets
[2];
54 /* special handling */
55 void (*convert
[2])(void *dst
, const void *src
);
61 /* Translation table for bitmasks... */
62 typedef struct bitmask_transtbl
{
63 unsigned int x86_mask
;
64 unsigned int x86_bits
;
65 unsigned int alpha_mask
;
66 unsigned int alpha_bits
;
69 void thunk_register_struct(int id
, const char *name
, const argtype
*types
);
70 void thunk_register_struct_direct(int id
, const char *name
,
71 const StructEntry
*se1
);
72 const argtype
*thunk_convert(void *dst
, const void *src
,
73 const argtype
*type_ptr
, int to_host
);
74 #ifndef NO_THUNK_TYPE_SIZE
76 extern StructEntry struct_entries
[];
78 int thunk_type_size_array(const argtype
*type_ptr
, int is_host
);
79 int thunk_type_align_array(const argtype
*type_ptr
, int is_host
);
81 static inline int thunk_type_size(const argtype
*type_ptr
, int is_host
)
84 const StructEntry
*se
;
102 return HOST_LONG_SIZE
;
104 return TARGET_ABI_BITS
/ 8;
109 return size
* thunk_type_size_array(type_ptr
+ 2, is_host
);
111 se
= struct_entries
+ type_ptr
[1];
112 return se
->size
[is_host
];
118 static inline int thunk_type_align(const argtype
*type_ptr
, int is_host
)
121 const StructEntry
*se
;
139 return HOST_LONG_SIZE
;
141 return TARGET_ABI_BITS
/ 8;
145 return thunk_type_align_array(type_ptr
+ 2, is_host
);
147 se
= struct_entries
+ type_ptr
[1];
148 return se
->align
[is_host
];
154 #endif /* NO_THUNK_TYPE_SIZE */
156 unsigned int target_to_host_bitmask(unsigned int x86_mask
,
157 const bitmask_transtbl
* trans_tbl
);
158 unsigned int host_to_target_bitmask(unsigned int alpha_mask
,
159 const bitmask_transtbl
* trans_tbl
);