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