Statistics
| Branch: | Revision:

root / thunk.h @ 31e31b8a

History | View | Annotate | Download (3.5 kB)

1 31e31b8a bellard
#ifndef THUNK_H
2 31e31b8a bellard
#define THUNK_H
3 31e31b8a bellard
4 31e31b8a bellard
#include <inttypes.h>
5 31e31b8a bellard
#include <byteswap.h>
6 31e31b8a bellard
7 31e31b8a bellard
#undef WORDS_BIGENDIAN
8 31e31b8a bellard
#if __BYTE_ORDER == __BIG_ENDIAN
9 31e31b8a bellard
#define WORDS_BIGENDIAN
10 31e31b8a bellard
#endif
11 31e31b8a bellard
12 31e31b8a bellard
#ifdef WORD_BIGENDIAN
13 31e31b8a bellard
#define BSWAP_NEEDED
14 31e31b8a bellard
#endif
15 31e31b8a bellard
16 31e31b8a bellard
/* XXX: auto autoconf */
17 31e31b8a bellard
#define TARGET_I386
18 31e31b8a bellard
#define TARGET_LONG_BITS 32
19 31e31b8a bellard
20 31e31b8a bellard
21 31e31b8a bellard
#if defined(__alpha__)
22 31e31b8a bellard
#define HOST_LONG_BITS 64
23 31e31b8a bellard
#else
24 31e31b8a bellard
#define HOST_LONG_BITS 32
25 31e31b8a bellard
#endif
26 31e31b8a bellard
27 31e31b8a bellard
#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
28 31e31b8a bellard
#define HOST_LONG_SIZE (TARGET_LONG_BITS / 8)
29 31e31b8a bellard
30 31e31b8a bellard
static inline uint16_t bswap16(uint16_t x)
31 31e31b8a bellard
{
32 31e31b8a bellard
    return bswap_16(x);
33 31e31b8a bellard
}
34 31e31b8a bellard
35 31e31b8a bellard
static inline uint32_t bswap32(uint32_t x) 
36 31e31b8a bellard
{
37 31e31b8a bellard
    return bswap_32(x);
38 31e31b8a bellard
}
39 31e31b8a bellard
40 31e31b8a bellard
static inline uint64_t bswap64(uint64_t x) 
41 31e31b8a bellard
{
42 31e31b8a bellard
    return bswap_64(x);
43 31e31b8a bellard
}
44 31e31b8a bellard
45 31e31b8a bellard
static void inline bswap16s(uint16_t *s)
46 31e31b8a bellard
{
47 31e31b8a bellard
    *s = bswap16(*s);
48 31e31b8a bellard
}
49 31e31b8a bellard
50 31e31b8a bellard
static void inline bswap32s(uint32_t *s)
51 31e31b8a bellard
{
52 31e31b8a bellard
    *s = bswap32(*s);
53 31e31b8a bellard
}
54 31e31b8a bellard
55 31e31b8a bellard
static void inline bswap64s(uint64_t *s)
56 31e31b8a bellard
{
57 31e31b8a bellard
    *s = bswap64(*s);
58 31e31b8a bellard
}
59 31e31b8a bellard
60 31e31b8a bellard
#ifdef BSWAP_NEEDED
61 31e31b8a bellard
62 31e31b8a bellard
static inline uint16_t tswap16(uint16_t s)
63 31e31b8a bellard
{
64 31e31b8a bellard
    return bswap16(s);
65 31e31b8a bellard
}
66 31e31b8a bellard
67 31e31b8a bellard
static inline uint32_t tswap32(uint32_t s)
68 31e31b8a bellard
{
69 31e31b8a bellard
    return bswap32(s);
70 31e31b8a bellard
}
71 31e31b8a bellard
72 31e31b8a bellard
static inline uint64_t tswap64(uint64_t s)
73 31e31b8a bellard
{
74 31e31b8a bellard
    return bswap64(s);
75 31e31b8a bellard
}
76 31e31b8a bellard
77 31e31b8a bellard
static void inline tswap16s(uint16_t *s)
78 31e31b8a bellard
{
79 31e31b8a bellard
    *s = bswap16(*s);
80 31e31b8a bellard
}
81 31e31b8a bellard
82 31e31b8a bellard
static void inline tswap32s(uint32_t *s)
83 31e31b8a bellard
{
84 31e31b8a bellard
    *s = bswap32(*s);
85 31e31b8a bellard
}
86 31e31b8a bellard
87 31e31b8a bellard
static void inline tswap64s(uint64_t *s)
88 31e31b8a bellard
{
89 31e31b8a bellard
    *s = bswap64(*s);
90 31e31b8a bellard
}
91 31e31b8a bellard
92 31e31b8a bellard
#else
93 31e31b8a bellard
94 31e31b8a bellard
static inline uint16_t tswap16(uint16_t s)
95 31e31b8a bellard
{
96 31e31b8a bellard
    return s;
97 31e31b8a bellard
}
98 31e31b8a bellard
99 31e31b8a bellard
static inline uint32_t tswap32(uint32_t s)
100 31e31b8a bellard
{
101 31e31b8a bellard
    return s;
102 31e31b8a bellard
}
103 31e31b8a bellard
104 31e31b8a bellard
static inline uint64_t tswap64(uint64_t s)
105 31e31b8a bellard
{
106 31e31b8a bellard
    return s;
107 31e31b8a bellard
}
108 31e31b8a bellard
109 31e31b8a bellard
static void inline tswap16s(uint16_t *s)
110 31e31b8a bellard
{
111 31e31b8a bellard
}
112 31e31b8a bellard
113 31e31b8a bellard
static void inline tswap32s(uint32_t *s)
114 31e31b8a bellard
{
115 31e31b8a bellard
}
116 31e31b8a bellard
117 31e31b8a bellard
static void inline tswap64s(uint64_t *s)
118 31e31b8a bellard
{
119 31e31b8a bellard
}
120 31e31b8a bellard
121 31e31b8a bellard
#endif
122 31e31b8a bellard
123 31e31b8a bellard
#if TARGET_LONG_SIZE == 4
124 31e31b8a bellard
#define tswapl(s) tswap32(s)
125 31e31b8a bellard
#define tswapls(s) tswap32s((uint32_t *)(s))
126 31e31b8a bellard
#else
127 31e31b8a bellard
#define tswapl(s) tswap64(s)
128 31e31b8a bellard
#define tswapls(s) tswap64s((uint64_t *)(s))
129 31e31b8a bellard
#endif
130 31e31b8a bellard
131 31e31b8a bellard
#if TARGET_LONG_SIZE == 4
132 31e31b8a bellard
typedef int32_t target_long;
133 31e31b8a bellard
typedef uint32_t target_ulong;
134 31e31b8a bellard
#elif TARGET_LONG_SIZE == 8
135 31e31b8a bellard
typedef int64_t target_long;
136 31e31b8a bellard
typedef uint64_t target_ulong;
137 31e31b8a bellard
#else
138 31e31b8a bellard
#error TARGET_LONG_SIZE undefined
139 31e31b8a bellard
#endif
140 31e31b8a bellard
141 31e31b8a bellard
/* types enums definitions */
142 31e31b8a bellard
143 31e31b8a bellard
typedef enum argtype {
144 31e31b8a bellard
    TYPE_NULL,
145 31e31b8a bellard
    TYPE_CHAR,
146 31e31b8a bellard
    TYPE_SHORT,
147 31e31b8a bellard
    TYPE_INT,
148 31e31b8a bellard
    TYPE_LONG,
149 31e31b8a bellard
    TYPE_ULONG,
150 31e31b8a bellard
    TYPE_PTRVOID, /* pointer on unknown data */
151 31e31b8a bellard
    TYPE_LONGLONG,
152 31e31b8a bellard
    TYPE_ULONGLONG,
153 31e31b8a bellard
    TYPE_PTR,
154 31e31b8a bellard
    TYPE_ARRAY,
155 31e31b8a bellard
    TYPE_STRUCT,
156 31e31b8a bellard
} argtype;
157 31e31b8a bellard
158 31e31b8a bellard
#define MK_PTR(type) TYPE_PTR, type
159 31e31b8a bellard
#define MK_ARRAY(type, size) TYPE_ARRAY, size, type
160 31e31b8a bellard
#define MK_STRUCT(id) TYPE_STRUCT, id
161 31e31b8a bellard
162 31e31b8a bellard
#define THUNK_TARGET 0
163 31e31b8a bellard
#define THUNK_HOST   1
164 31e31b8a bellard
165 31e31b8a bellard
typedef struct {
166 31e31b8a bellard
    /* standard struct handling */
167 31e31b8a bellard
    const argtype *field_types;
168 31e31b8a bellard
    int nb_fields;
169 31e31b8a bellard
    int *field_offsets[2];
170 31e31b8a bellard
    /* special handling */
171 31e31b8a bellard
    void (*convert[2])(void *dst, const void *src);
172 31e31b8a bellard
    int size[2];
173 31e31b8a bellard
    int align[2];
174 31e31b8a bellard
    const char *name;
175 31e31b8a bellard
} StructEntry;
176 31e31b8a bellard
177 31e31b8a bellard
/* Translation table for bitmasks... */
178 31e31b8a bellard
typedef struct bitmask_transtbl {
179 31e31b8a bellard
        unsigned int        x86_mask;
180 31e31b8a bellard
        unsigned int        x86_bits;
181 31e31b8a bellard
        unsigned int        alpha_mask;
182 31e31b8a bellard
        unsigned int        alpha_bits;
183 31e31b8a bellard
} bitmask_transtbl;
184 31e31b8a bellard
185 31e31b8a bellard
void thunk_register_struct(int id, const char *name, const argtype *types);
186 31e31b8a bellard
void thunk_register_struct_direct(int id, const char *name, StructEntry *se1);
187 31e31b8a bellard
const argtype *thunk_convert(void *dst, const void *src, 
188 31e31b8a bellard
                             const argtype *type_ptr, int to_host);
189 31e31b8a bellard
190 31e31b8a bellard
unsigned int target_to_host_bitmask(unsigned int x86_mask, 
191 31e31b8a bellard
                                    bitmask_transtbl * trans_tbl);
192 31e31b8a bellard
unsigned int host_to_target_bitmask(unsigned int alpha_mask, 
193 31e31b8a bellard
                                    bitmask_transtbl * trans_tbl);
194 31e31b8a bellard
195 31e31b8a bellard
#endif