Statistics
| Branch: | Revision:

root / tcg / tcg.h @ f878d2d2

History | View | Annotate | Download (14.4 kB)

1 c896fe29 bellard
/*
2 c896fe29 bellard
 * Tiny Code Generator for QEMU
3 c896fe29 bellard
 *
4 c896fe29 bellard
 * Copyright (c) 2008 Fabrice Bellard
5 c896fe29 bellard
 *
6 c896fe29 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 c896fe29 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 c896fe29 bellard
 * in the Software without restriction, including without limitation the rights
9 c896fe29 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 c896fe29 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 c896fe29 bellard
 * furnished to do so, subject to the following conditions:
12 c896fe29 bellard
 *
13 c896fe29 bellard
 * The above copyright notice and this permission notice shall be included in
14 c896fe29 bellard
 * all copies or substantial portions of the Software.
15 c896fe29 bellard
 *
16 c896fe29 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 c896fe29 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 c896fe29 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 c896fe29 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 c896fe29 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 c896fe29 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 c896fe29 bellard
 * THE SOFTWARE.
23 c896fe29 bellard
 */
24 f8393946 aurel32
#include "qemu-common.h"
25 c896fe29 bellard
#include "tcg-target.h"
26 c896fe29 bellard
27 c896fe29 bellard
#if TCG_TARGET_REG_BITS == 32
28 c896fe29 bellard
typedef int32_t tcg_target_long;
29 c896fe29 bellard
typedef uint32_t tcg_target_ulong;
30 c896fe29 bellard
#define TCG_PRIlx PRIx32
31 c896fe29 bellard
#define TCG_PRIld PRId32
32 c896fe29 bellard
#elif TCG_TARGET_REG_BITS == 64
33 c896fe29 bellard
typedef int64_t tcg_target_long;
34 c896fe29 bellard
typedef uint64_t tcg_target_ulong;
35 c896fe29 bellard
#define TCG_PRIlx PRIx64
36 c896fe29 bellard
#define TCG_PRIld PRId64
37 c896fe29 bellard
#else
38 c896fe29 bellard
#error unsupported
39 c896fe29 bellard
#endif
40 c896fe29 bellard
41 c896fe29 bellard
#if TCG_TARGET_NB_REGS <= 32
42 c896fe29 bellard
typedef uint32_t TCGRegSet;
43 c896fe29 bellard
#elif TCG_TARGET_NB_REGS <= 64
44 c896fe29 bellard
typedef uint64_t TCGRegSet;
45 c896fe29 bellard
#else
46 c896fe29 bellard
#error unsupported
47 c896fe29 bellard
#endif
48 c896fe29 bellard
49 c896fe29 bellard
enum {
50 c896fe29 bellard
#define DEF(s, n, copy_size) INDEX_op_ ## s,
51 c896fe29 bellard
#include "tcg-opc.h"
52 c896fe29 bellard
#undef DEF
53 c896fe29 bellard
    NB_OPS,
54 c896fe29 bellard
};
55 c896fe29 bellard
56 c896fe29 bellard
#define tcg_regset_clear(d) (d) = 0
57 c896fe29 bellard
#define tcg_regset_set(d, s) (d) = (s)
58 c896fe29 bellard
#define tcg_regset_set32(d, reg, val32) (d) |= (val32) << (reg)
59 c896fe29 bellard
#define tcg_regset_set_reg(d, r) (d) |= 1 << (r)
60 c896fe29 bellard
#define tcg_regset_reset_reg(d, r) (d) &= ~(1 << (r))
61 c896fe29 bellard
#define tcg_regset_test_reg(d, r) (((d) >> (r)) & 1)
62 c896fe29 bellard
#define tcg_regset_or(d, a, b) (d) = (a) | (b)
63 c896fe29 bellard
#define tcg_regset_and(d, a, b) (d) = (a) & (b)
64 c896fe29 bellard
#define tcg_regset_andnot(d, a, b) (d) = (a) & ~(b)
65 c896fe29 bellard
#define tcg_regset_not(d, a) (d) = ~(a)
66 c896fe29 bellard
67 c896fe29 bellard
typedef struct TCGRelocation {
68 c896fe29 bellard
    struct TCGRelocation *next;
69 c896fe29 bellard
    int type;
70 c896fe29 bellard
    uint8_t *ptr;
71 c896fe29 bellard
    tcg_target_long addend;
72 c896fe29 bellard
} TCGRelocation; 
73 c896fe29 bellard
74 c896fe29 bellard
typedef struct TCGLabel {
75 c44f945a blueswir1
    int has_value;
76 c896fe29 bellard
    union {
77 c896fe29 bellard
        tcg_target_ulong value;
78 c896fe29 bellard
        TCGRelocation *first_reloc;
79 c896fe29 bellard
    } u;
80 c896fe29 bellard
} TCGLabel;
81 c896fe29 bellard
82 c896fe29 bellard
typedef struct TCGPool {
83 c896fe29 bellard
    struct TCGPool *next;
84 c44f945a blueswir1
    int size;
85 c44f945a blueswir1
    uint8_t data[0] __attribute__ ((aligned));
86 c896fe29 bellard
} TCGPool;
87 c896fe29 bellard
88 c896fe29 bellard
#define TCG_POOL_CHUNK_SIZE 32768
89 c896fe29 bellard
90 c896fe29 bellard
#define TCG_MAX_LABELS 512
91 c896fe29 bellard
92 c4071c90 blueswir1
#define TCG_MAX_TEMPS 512
93 c896fe29 bellard
94 b03cce8e bellard
/* when the size of the arguments of a called function is smaller than
95 b03cce8e bellard
   this value, they are statically allocated in the TB stack frame */
96 b03cce8e bellard
#define TCG_STATIC_CALL_ARGS_SIZE 128
97 b03cce8e bellard
98 c896fe29 bellard
typedef int TCGType;
99 c896fe29 bellard
100 c896fe29 bellard
#define TCG_TYPE_I32 0
101 c896fe29 bellard
#define TCG_TYPE_I64 1
102 e8996ee0 bellard
#define TCG_TYPE_COUNT 2 /* number of different types */
103 c896fe29 bellard
104 c896fe29 bellard
#if TCG_TARGET_REG_BITS == 32
105 c896fe29 bellard
#define TCG_TYPE_PTR TCG_TYPE_I32
106 c896fe29 bellard
#else
107 c896fe29 bellard
#define TCG_TYPE_PTR TCG_TYPE_I64
108 c896fe29 bellard
#endif
109 c896fe29 bellard
110 c896fe29 bellard
typedef tcg_target_ulong TCGArg;
111 c896fe29 bellard
112 ac56dd48 pbrook
/* Define a type and accessor macros for varables.  Using a struct is
113 ac56dd48 pbrook
   nice because it gives some level of type safely.  Ideally the compiler
114 ac56dd48 pbrook
   be able to see through all this.  However in practice this is not true,
115 ac56dd48 pbrook
   expecially on targets with braindamaged ABIs (e.g. i386).
116 ac56dd48 pbrook
   We use plain int by default to avoid this runtime overhead.
117 ac56dd48 pbrook
   Users of tcg_gen_* don't need to know about any of this, and should
118 a7812ae4 pbrook
   treat TCGv as an opaque type.
119 a7812ae4 pbrook
   In additon we do typechecking for different types of variables.  TCGv_i32
120 a7812ae4 pbrook
   and TCGv_i64 are 32/64-bit variables respectively.  TCGv and TCGv_ptr
121 a7812ae4 pbrook
   are aliases for target_ulong and host pointer sized values respectively.
122 a7812ae4 pbrook
 */
123 ac56dd48 pbrook
124 092c73ee Juan Quintela
#ifdef CONFIG_DEBUG_TCG
125 f8393946 aurel32
#define DEBUG_TCGV 1
126 f8393946 aurel32
#endif
127 ac56dd48 pbrook
128 ac56dd48 pbrook
#ifdef DEBUG_TCGV
129 ac56dd48 pbrook
130 ac56dd48 pbrook
typedef struct
131 ac56dd48 pbrook
{
132 a810a2de blueswir1
    int i32;
133 a7812ae4 pbrook
} TCGv_i32;
134 ac56dd48 pbrook
135 a7812ae4 pbrook
typedef struct
136 a7812ae4 pbrook
{
137 a810a2de blueswir1
    int i64;
138 a7812ae4 pbrook
} TCGv_i64;
139 a7812ae4 pbrook
140 a7812ae4 pbrook
#define MAKE_TCGV_I32(i) __extension__                  \
141 a7812ae4 pbrook
    ({ TCGv_i32 make_tcgv_tmp = {i}; make_tcgv_tmp;})
142 a7812ae4 pbrook
#define MAKE_TCGV_I64(i) __extension__                  \
143 a7812ae4 pbrook
    ({ TCGv_i64 make_tcgv_tmp = {i}; make_tcgv_tmp;})
144 a810a2de blueswir1
#define GET_TCGV_I32(t) ((t).i32)
145 a810a2de blueswir1
#define GET_TCGV_I64(t) ((t).i64)
146 ac56dd48 pbrook
#if TCG_TARGET_REG_BITS == 32
147 a7812ae4 pbrook
#define TCGV_LOW(t) MAKE_TCGV_I32(GET_TCGV_I64(t))
148 a7812ae4 pbrook
#define TCGV_HIGH(t) MAKE_TCGV_I32(GET_TCGV_I64(t) + 1)
149 ac56dd48 pbrook
#endif
150 ac56dd48 pbrook
151 ac56dd48 pbrook
#else /* !DEBUG_TCGV */
152 ac56dd48 pbrook
153 a7812ae4 pbrook
typedef int TCGv_i32;
154 a7812ae4 pbrook
typedef int TCGv_i64;
155 a7812ae4 pbrook
#define MAKE_TCGV_I32(x) (x)
156 a7812ae4 pbrook
#define MAKE_TCGV_I64(x) (x)
157 a7812ae4 pbrook
#define GET_TCGV_I32(t) (t)
158 a7812ae4 pbrook
#define GET_TCGV_I64(t) (t)
159 44e6acb0 aurel32
160 ac56dd48 pbrook
#if TCG_TARGET_REG_BITS == 32
161 a7812ae4 pbrook
#define TCGV_LOW(t) (t)
162 ac56dd48 pbrook
#define TCGV_HIGH(t) ((t) + 1)
163 ac56dd48 pbrook
#endif
164 ac56dd48 pbrook
165 ac56dd48 pbrook
#endif /* DEBUG_TCGV */
166 ac56dd48 pbrook
167 43e860ef aurel32
#define TCGV_EQUAL_I32(a, b) (GET_TCGV_I32(a) == GET_TCGV_I32(b))
168 43e860ef aurel32
#define TCGV_EQUAL_I64(a, b) (GET_TCGV_I64(a) == GET_TCGV_I64(b))
169 43e860ef aurel32
170 a50f5b91 pbrook
/* Dummy definition to avoid compiler warnings.  */
171 a7812ae4 pbrook
#define TCGV_UNUSED_I32(x) x = MAKE_TCGV_I32(-1)
172 a7812ae4 pbrook
#define TCGV_UNUSED_I64(x) x = MAKE_TCGV_I64(-1)
173 a50f5b91 pbrook
174 c896fe29 bellard
/* call flags */
175 c896fe29 bellard
#define TCG_CALL_TYPE_MASK      0x000f
176 c896fe29 bellard
#define TCG_CALL_TYPE_STD       0x0000 /* standard C call */
177 c896fe29 bellard
#define TCG_CALL_TYPE_REGPARM_1 0x0001 /* i386 style regparm call (1 reg) */
178 c896fe29 bellard
#define TCG_CALL_TYPE_REGPARM_2 0x0002 /* i386 style regparm call (2 regs) */
179 c896fe29 bellard
#define TCG_CALL_TYPE_REGPARM   0x0003 /* i386 style regparm call (3 regs) */
180 3e00b3f5 aurel32
/* A pure function only reads its arguments and TCG global variables
181 34d5a9ff aurel32
   and cannot raise exceptions. Hence a call to a pure function can be
182 c6e113f5 bellard
   safely suppressed if the return value is not used. */
183 c6e113f5 bellard
#define TCG_CALL_PURE           0x0010 
184 b9c18f56 aurel32
/* A const function only reads its arguments and does not use TCG
185 3e00b3f5 aurel32
   global variables. Hence a call to such a function does not
186 3e00b3f5 aurel32
   save TCG global variables back to their canonical location. */
187 b9c18f56 aurel32
#define TCG_CALL_CONST          0x0020
188 c896fe29 bellard
189 39cf05d3 bellard
/* used to align parameters */
190 a7812ae4 pbrook
#define TCG_CALL_DUMMY_TCGV     MAKE_TCGV_I32(-1)
191 39cf05d3 bellard
#define TCG_CALL_DUMMY_ARG      ((TCGArg)(-1))
192 39cf05d3 bellard
193 c896fe29 bellard
typedef enum {
194 c896fe29 bellard
    TCG_COND_EQ,
195 c896fe29 bellard
    TCG_COND_NE,
196 c896fe29 bellard
    TCG_COND_LT,
197 c896fe29 bellard
    TCG_COND_GE,
198 c896fe29 bellard
    TCG_COND_LE,
199 c896fe29 bellard
    TCG_COND_GT,
200 c896fe29 bellard
    /* unsigned */
201 c896fe29 bellard
    TCG_COND_LTU,
202 c896fe29 bellard
    TCG_COND_GEU,
203 c896fe29 bellard
    TCG_COND_LEU,
204 c896fe29 bellard
    TCG_COND_GTU,
205 c896fe29 bellard
} TCGCond;
206 c896fe29 bellard
207 c896fe29 bellard
#define TEMP_VAL_DEAD  0
208 c896fe29 bellard
#define TEMP_VAL_REG   1
209 c896fe29 bellard
#define TEMP_VAL_MEM   2
210 c896fe29 bellard
#define TEMP_VAL_CONST 3
211 c896fe29 bellard
212 c896fe29 bellard
/* XXX: optimize memory layout */
213 c896fe29 bellard
typedef struct TCGTemp {
214 c896fe29 bellard
    TCGType base_type;
215 c896fe29 bellard
    TCGType type;
216 c896fe29 bellard
    int val_type;
217 c896fe29 bellard
    int reg;
218 c896fe29 bellard
    tcg_target_long val;
219 c896fe29 bellard
    int mem_reg;
220 c896fe29 bellard
    tcg_target_long mem_offset;
221 c896fe29 bellard
    unsigned int fixed_reg:1;
222 c896fe29 bellard
    unsigned int mem_coherent:1;
223 c896fe29 bellard
    unsigned int mem_allocated:1;
224 641d5fbe bellard
    unsigned int temp_local:1; /* If true, the temp is saved accross
225 641d5fbe bellard
                                  basic blocks. Otherwise, it is not
226 641d5fbe bellard
                                  preserved accross basic blocks. */
227 e8996ee0 bellard
    unsigned int temp_allocated:1; /* never used for code gen */
228 e8996ee0 bellard
    /* index of next free temp of same base type, -1 if end */
229 e8996ee0 bellard
    int next_free_temp;
230 c896fe29 bellard
    const char *name;
231 c896fe29 bellard
} TCGTemp;
232 c896fe29 bellard
233 c896fe29 bellard
typedef struct TCGHelperInfo {
234 4dc81f28 bellard
    tcg_target_ulong func;
235 c896fe29 bellard
    const char *name;
236 c896fe29 bellard
} TCGHelperInfo;
237 c896fe29 bellard
238 c896fe29 bellard
typedef struct TCGContext TCGContext;
239 c896fe29 bellard
240 c896fe29 bellard
struct TCGContext {
241 c896fe29 bellard
    uint8_t *pool_cur, *pool_end;
242 c896fe29 bellard
    TCGPool *pool_first, *pool_current;
243 c896fe29 bellard
    TCGLabel *labels;
244 c896fe29 bellard
    int nb_labels;
245 c896fe29 bellard
    TCGTemp *temps; /* globals first, temps after */
246 c896fe29 bellard
    int nb_globals;
247 c896fe29 bellard
    int nb_temps;
248 641d5fbe bellard
    /* index of free temps, -1 if none */
249 641d5fbe bellard
    int first_free_temp[TCG_TYPE_COUNT * 2]; 
250 c896fe29 bellard
251 c896fe29 bellard
    /* goto_tb support */
252 c896fe29 bellard
    uint8_t *code_buf;
253 c896fe29 bellard
    unsigned long *tb_next;
254 c896fe29 bellard
    uint16_t *tb_next_offset;
255 c896fe29 bellard
    uint16_t *tb_jmp_offset; /* != NULL if USE_DIRECT_JUMP */
256 c896fe29 bellard
257 641d5fbe bellard
    /* liveness analysis */
258 c896fe29 bellard
    uint16_t *op_dead_iargs; /* for each operation, each bit tells if the
259 c896fe29 bellard
                                corresponding input argument is dead */
260 641d5fbe bellard
    
261 c896fe29 bellard
    /* tells in which temporary a given register is. It does not take
262 c896fe29 bellard
       into account fixed registers */
263 c896fe29 bellard
    int reg_to_temp[TCG_TARGET_NB_REGS];
264 c896fe29 bellard
    TCGRegSet reserved_regs;
265 c896fe29 bellard
    tcg_target_long current_frame_offset;
266 c896fe29 bellard
    tcg_target_long frame_start;
267 c896fe29 bellard
    tcg_target_long frame_end;
268 c896fe29 bellard
    int frame_reg;
269 c896fe29 bellard
270 c896fe29 bellard
    uint8_t *code_ptr;
271 c896fe29 bellard
    TCGTemp static_temps[TCG_MAX_TEMPS];
272 c896fe29 bellard
273 c896fe29 bellard
    TCGHelperInfo *helpers;
274 c896fe29 bellard
    int nb_helpers;
275 c896fe29 bellard
    int allocated_helpers;
276 e8996ee0 bellard
    int helpers_sorted;
277 a23a9ec6 bellard
278 a23a9ec6 bellard
#ifdef CONFIG_PROFILER
279 a23a9ec6 bellard
    /* profiling info */
280 a23a9ec6 bellard
    int64_t tb_count1;
281 a23a9ec6 bellard
    int64_t tb_count;
282 a23a9ec6 bellard
    int64_t op_count; /* total insn count */
283 a23a9ec6 bellard
    int op_count_max; /* max insn per TB */
284 a23a9ec6 bellard
    int64_t temp_count;
285 a23a9ec6 bellard
    int temp_count_max;
286 a23a9ec6 bellard
    int64_t del_op_count;
287 a23a9ec6 bellard
    int64_t code_in_len;
288 a23a9ec6 bellard
    int64_t code_out_len;
289 a23a9ec6 bellard
    int64_t interm_time;
290 a23a9ec6 bellard
    int64_t code_time;
291 a23a9ec6 bellard
    int64_t la_time;
292 a23a9ec6 bellard
    int64_t restore_count;
293 a23a9ec6 bellard
    int64_t restore_time;
294 a23a9ec6 bellard
#endif
295 c896fe29 bellard
};
296 c896fe29 bellard
297 c896fe29 bellard
extern TCGContext tcg_ctx;
298 c896fe29 bellard
extern uint16_t *gen_opc_ptr;
299 c896fe29 bellard
extern TCGArg *gen_opparam_ptr;
300 c896fe29 bellard
extern uint16_t gen_opc_buf[];
301 c896fe29 bellard
extern TCGArg gen_opparam_buf[];
302 c896fe29 bellard
303 c896fe29 bellard
/* pool based memory allocation */
304 c896fe29 bellard
305 c896fe29 bellard
void *tcg_malloc_internal(TCGContext *s, int size);
306 c896fe29 bellard
void tcg_pool_reset(TCGContext *s);
307 c896fe29 bellard
void tcg_pool_delete(TCGContext *s);
308 c896fe29 bellard
309 c896fe29 bellard
static inline void *tcg_malloc(int size)
310 c896fe29 bellard
{
311 c896fe29 bellard
    TCGContext *s = &tcg_ctx;
312 c896fe29 bellard
    uint8_t *ptr, *ptr_end;
313 c896fe29 bellard
    size = (size + sizeof(long) - 1) & ~(sizeof(long) - 1);
314 c896fe29 bellard
    ptr = s->pool_cur;
315 c896fe29 bellard
    ptr_end = ptr + size;
316 c896fe29 bellard
    if (unlikely(ptr_end > s->pool_end)) {
317 c896fe29 bellard
        return tcg_malloc_internal(&tcg_ctx, size);
318 c896fe29 bellard
    } else {
319 c896fe29 bellard
        s->pool_cur = ptr_end;
320 c896fe29 bellard
        return ptr;
321 c896fe29 bellard
    }
322 c896fe29 bellard
}
323 c896fe29 bellard
324 c896fe29 bellard
void tcg_context_init(TCGContext *s);
325 c896fe29 bellard
void tcg_func_start(TCGContext *s);
326 c896fe29 bellard
327 54604f74 aurel32
int tcg_gen_code(TCGContext *s, uint8_t *gen_code_buf);
328 54604f74 aurel32
int tcg_gen_code_search_pc(TCGContext *s, uint8_t *gen_code_buf, long offset);
329 c896fe29 bellard
330 c896fe29 bellard
void tcg_set_frame(TCGContext *s, int reg,
331 c896fe29 bellard
                   tcg_target_long start, tcg_target_long size);
332 a7812ae4 pbrook
333 a7812ae4 pbrook
TCGv_i32 tcg_global_reg_new_i32(int reg, const char *name);
334 a7812ae4 pbrook
TCGv_i32 tcg_global_mem_new_i32(int reg, tcg_target_long offset,
335 a7812ae4 pbrook
                                const char *name);
336 a7812ae4 pbrook
TCGv_i32 tcg_temp_new_internal_i32(int temp_local);
337 a7812ae4 pbrook
static inline TCGv_i32 tcg_temp_new_i32(void)
338 a7812ae4 pbrook
{
339 a7812ae4 pbrook
    return tcg_temp_new_internal_i32(0);
340 a7812ae4 pbrook
}
341 a7812ae4 pbrook
static inline TCGv_i32 tcg_temp_local_new_i32(void)
342 a7812ae4 pbrook
{
343 a7812ae4 pbrook
    return tcg_temp_new_internal_i32(1);
344 a7812ae4 pbrook
}
345 a7812ae4 pbrook
void tcg_temp_free_i32(TCGv_i32 arg);
346 a7812ae4 pbrook
char *tcg_get_arg_str_i32(TCGContext *s, char *buf, int buf_size, TCGv_i32 arg);
347 a7812ae4 pbrook
348 a7812ae4 pbrook
TCGv_i64 tcg_global_reg_new_i64(int reg, const char *name);
349 a7812ae4 pbrook
TCGv_i64 tcg_global_mem_new_i64(int reg, tcg_target_long offset,
350 a7812ae4 pbrook
                                const char *name);
351 a7812ae4 pbrook
TCGv_i64 tcg_temp_new_internal_i64(int temp_local);
352 a7812ae4 pbrook
static inline TCGv_i64 tcg_temp_new_i64(void)
353 641d5fbe bellard
{
354 a7812ae4 pbrook
    return tcg_temp_new_internal_i64(0);
355 641d5fbe bellard
}
356 a7812ae4 pbrook
static inline TCGv_i64 tcg_temp_local_new_i64(void)
357 641d5fbe bellard
{
358 a7812ae4 pbrook
    return tcg_temp_new_internal_i64(1);
359 641d5fbe bellard
}
360 a7812ae4 pbrook
void tcg_temp_free_i64(TCGv_i64 arg);
361 a7812ae4 pbrook
char *tcg_get_arg_str_i64(TCGContext *s, char *buf, int buf_size, TCGv_i64 arg);
362 a7812ae4 pbrook
363 a23a9ec6 bellard
void tcg_dump_info(FILE *f,
364 a23a9ec6 bellard
                   int (*cpu_fprintf)(FILE *f, const char *fmt, ...));
365 c896fe29 bellard
366 c896fe29 bellard
#define TCG_CT_ALIAS  0x80
367 c896fe29 bellard
#define TCG_CT_IALIAS 0x40
368 c896fe29 bellard
#define TCG_CT_REG    0x01
369 c896fe29 bellard
#define TCG_CT_CONST  0x02 /* any constant of register size */
370 c896fe29 bellard
371 c896fe29 bellard
typedef struct TCGArgConstraint {
372 5ff9d6a4 bellard
    uint16_t ct;
373 5ff9d6a4 bellard
    uint8_t alias_index;
374 c896fe29 bellard
    union {
375 c896fe29 bellard
        TCGRegSet regs;
376 c896fe29 bellard
    } u;
377 c896fe29 bellard
} TCGArgConstraint;
378 c896fe29 bellard
379 c896fe29 bellard
#define TCG_MAX_OP_ARGS 16
380 c896fe29 bellard
381 c896fe29 bellard
#define TCG_OPF_BB_END     0x01 /* instruction defines the end of a basic
382 c896fe29 bellard
                                   block */
383 b03cce8e bellard
#define TCG_OPF_CALL_CLOBBER 0x02 /* instruction clobbers call registers 
384 b03cce8e bellard
                                   and potentially update globals. */
385 b03cce8e bellard
#define TCG_OPF_SIDE_EFFECTS 0x04 /* instruction has side effects : it
386 b03cce8e bellard
                                     cannot be removed if its output
387 b03cce8e bellard
                                     are not used */
388 c896fe29 bellard
389 c896fe29 bellard
typedef struct TCGOpDef {
390 c896fe29 bellard
    const char *name;
391 c896fe29 bellard
    uint8_t nb_oargs, nb_iargs, nb_cargs, nb_args;
392 c896fe29 bellard
    uint8_t flags;
393 c896fe29 bellard
    uint16_t copy_size;
394 c896fe29 bellard
    TCGArgConstraint *args_ct;
395 c896fe29 bellard
    int *sorted_args;
396 c896fe29 bellard
} TCGOpDef;
397 c896fe29 bellard
        
398 c896fe29 bellard
typedef struct TCGTargetOpDef {
399 c896fe29 bellard
    int op;
400 c896fe29 bellard
    const char *args_ct_str[TCG_MAX_OP_ARGS];
401 c896fe29 bellard
} TCGTargetOpDef;
402 c896fe29 bellard
403 c896fe29 bellard
void tcg_target_init(TCGContext *s);
404 b03cce8e bellard
void tcg_target_qemu_prologue(TCGContext *s);
405 c896fe29 bellard
406 c896fe29 bellard
#define tcg_abort() \
407 c896fe29 bellard
do {\
408 c896fe29 bellard
    fprintf(stderr, "%s:%d: tcg fatal error\n", __FILE__, __LINE__);\
409 c896fe29 bellard
    abort();\
410 c896fe29 bellard
} while (0)
411 c896fe29 bellard
412 c896fe29 bellard
void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs);
413 c896fe29 bellard
414 c896fe29 bellard
#if TCG_TARGET_REG_BITS == 32
415 c896fe29 bellard
#define tcg_const_ptr tcg_const_i32
416 c896fe29 bellard
#define tcg_add_ptr tcg_add_i32
417 c896fe29 bellard
#define tcg_sub_ptr tcg_sub_i32
418 a7812ae4 pbrook
#define TCGv_ptr TCGv_i32
419 a7812ae4 pbrook
#define GET_TCGV_PTR GET_TCGV_I32
420 a7812ae4 pbrook
#define tcg_global_reg_new_ptr tcg_global_reg_new_i32
421 a7812ae4 pbrook
#define tcg_global_mem_new_ptr tcg_global_mem_new_i32
422 a7812ae4 pbrook
#define tcg_temp_new_ptr tcg_temp_new_i32
423 a7812ae4 pbrook
#define tcg_temp_free_ptr tcg_temp_free_i32
424 c896fe29 bellard
#else
425 c896fe29 bellard
#define tcg_const_ptr tcg_const_i64
426 c896fe29 bellard
#define tcg_add_ptr tcg_add_i64
427 c896fe29 bellard
#define tcg_sub_ptr tcg_sub_i64
428 a7812ae4 pbrook
#define TCGv_ptr TCGv_i64
429 a7812ae4 pbrook
#define GET_TCGV_PTR GET_TCGV_I64
430 a7812ae4 pbrook
#define tcg_global_reg_new_ptr tcg_global_reg_new_i64
431 a7812ae4 pbrook
#define tcg_global_mem_new_ptr tcg_global_mem_new_i64
432 a7812ae4 pbrook
#define tcg_temp_new_ptr tcg_temp_new_i64
433 a7812ae4 pbrook
#define tcg_temp_free_ptr tcg_temp_free_i64
434 c896fe29 bellard
#endif
435 c896fe29 bellard
436 a7812ae4 pbrook
void tcg_gen_callN(TCGContext *s, TCGv_ptr func, unsigned int flags,
437 a7812ae4 pbrook
                   int sizemask, TCGArg ret, int nargs, TCGArg *args);
438 a7812ae4 pbrook
439 a7812ae4 pbrook
void tcg_gen_shifti_i64(TCGv_i64 ret, TCGv_i64 arg1,
440 a7812ae4 pbrook
                        int c, int right, int arith);
441 a7812ae4 pbrook
442 a7812ae4 pbrook
/* only used for debugging purposes */
443 a7812ae4 pbrook
void tcg_register_helper(void *func, const char *name);
444 a7812ae4 pbrook
const char *tcg_helper_get_name(TCGContext *s, void *func);
445 a7812ae4 pbrook
void tcg_dump_ops(TCGContext *s, FILE *outfile);
446 a7812ae4 pbrook
447 a7812ae4 pbrook
void dump_ops(const uint16_t *opc_buf, const TCGArg *opparam_buf);
448 a7812ae4 pbrook
TCGv_i32 tcg_const_i32(int32_t val);
449 a7812ae4 pbrook
TCGv_i64 tcg_const_i64(int64_t val);
450 a7812ae4 pbrook
TCGv_i32 tcg_const_local_i32(int32_t val);
451 a7812ae4 pbrook
TCGv_i64 tcg_const_local_i64(int64_t val);
452 a7812ae4 pbrook
453 c896fe29 bellard
void tcg_out_reloc(TCGContext *s, uint8_t *code_ptr, int type, 
454 c896fe29 bellard
                   int label_index, long addend);
455 c896fe29 bellard
const TCGArg *tcg_gen_code_op(TCGContext *s, int opc, const TCGArg *args1,
456 c896fe29 bellard
                              unsigned int dead_iargs);
457 c896fe29 bellard
458 c896fe29 bellard
/* tcg-runtime.c */
459 c896fe29 bellard
int64_t tcg_helper_shl_i64(int64_t arg1, int64_t arg2);
460 c896fe29 bellard
int64_t tcg_helper_shr_i64(int64_t arg1, int64_t arg2);
461 c896fe29 bellard
int64_t tcg_helper_sar_i64(int64_t arg1, int64_t arg2);
462 c896fe29 bellard
int64_t tcg_helper_div_i64(int64_t arg1, int64_t arg2);
463 c896fe29 bellard
int64_t tcg_helper_rem_i64(int64_t arg1, int64_t arg2);
464 c896fe29 bellard
uint64_t tcg_helper_divu_i64(uint64_t arg1, uint64_t arg2);
465 c896fe29 bellard
uint64_t tcg_helper_remu_i64(uint64_t arg1, uint64_t arg2);
466 b03cce8e bellard
467 b03cce8e bellard
extern uint8_t code_gen_prologue[];
468 e58ffeb3 malc
#if defined(_ARCH_PPC) && !defined(_ARCH_PPC64)
469 932a6909 bellard
#define tcg_qemu_tb_exec(tb_ptr) \
470 932a6909 bellard
    ((long REGPARM __attribute__ ((longcall)) (*)(void *))code_gen_prologue)(tb_ptr)
471 932a6909 bellard
#else
472 b03cce8e bellard
#define tcg_qemu_tb_exec(tb_ptr) ((long REGPARM (*)(void *))code_gen_prologue)(tb_ptr)
473 932a6909 bellard
#endif